Merge jdk7u2-b21 into jdk7u4-b200
diff --git a/.hgtags-top-repo b/.hgtags-top-repo
index c73aec4..3960979 100644
--- a/.hgtags-top-repo
+++ b/.hgtags-top-repo
@@ -140,3 +140,4 @@
 be12d8ef36d1d75fe6476d61f921036ba49186b4 jdk7u2-b11
 b2deaf5bde5ec455a06786e8e2aea2e673be13aa jdk7u2-b12
 c95558e566ac3605c480a3d070b1102088dab07f jdk7u2-b13
+e30fd289f0019700575593ee4e1635fbc5c9a484 jdk7u2-b21
diff --git a/corba/.hgtags b/corba/.hgtags
index d1b7c8e..8d43c97 100644
--- a/corba/.hgtags
+++ b/corba/.hgtags
@@ -140,3 +140,4 @@
 82330ae1ba8b29384644db0e3385cab88aae59c2 jdk7u2-b11
 56b02f8ef70391a67c9fa71157a8faafbdff4b74 jdk7u2-b12
 456ff1f14b14ef8cfe47cef95c8094f8443fa092 jdk7u2-b13
+62b846b0c3259cae732e75df50a1b180a2541178 jdk7u2-b21
diff --git a/corba/make/common/Defs-bsd.gmk b/corba/make/common/Defs-bsd.gmk
new file mode 100644
index 0000000..44b5011
--- /dev/null
+++ b/corba/make/common/Defs-bsd.gmk
@@ -0,0 +1,46 @@
+#
+# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# Makefile to specify compiler flags for programs and libraries
+# targeted to BSD.  Should not contain any rules.
+#
+
+# Warning: the following variables are overriden by Defs.gmk. Set
+# values will be silently ignored:
+#   CFLAGS        (set $(OTHER_CFLAGS) instead)
+#   CPPFLAGS      (set $(OTHER_CPPFLAGS) instead)
+#   CXXFLAGS      (set $(OTHER_CXXFLAGS) instead)
+#   LDFLAGS       (set $(OTHER_LDFAGS) instead)
+#   LDLIBS        (set $(EXTRA_LIBS) instead)
+#   LDLIBS_COMMON (set $(EXTRA_LIBS) instead)
+
+# Get shared JDK settings
+include $(BUILDDIR)/common/shared/Defs.gmk
+
+ifndef PLATFORM_SRC
+  PLATFORM_SRC = $(TOPDIR)/src/solaris
+endif # PLATFORM_SRC
+
diff --git a/corba/make/common/Defs.gmk b/corba/make/common/Defs.gmk
index ade12fb..a760b3a 100644
--- a/corba/make/common/Defs.gmk
+++ b/corba/make/common/Defs.gmk
@@ -53,6 +53,28 @@
 
 _OUTPUTDIR=$(TOPDIR)/build/$(PLATFORM)-$(ARCH)
 
+ifneq ($(PLATFORM), windows)
+  ifdef ALT_X11_PATH
+    X11_PATH = $(ALT_X11_PATH)
+  else
+    X11_PATH = /usr/X11R6
+  endif
+
+  ifdef ALT_PACKAGE_PATH
+    PACKAGE_PATH = $(ALT_PACKAGE_PATH)
+  else
+    ifeq ($(PLATFORM), linux)
+      PACKAGE_PATH = /usr
+    else
+      ifeq ($(OS_VENDOR), Apple)
+        PACKAGE_PATH = /opt/local
+      else
+        PACKAGE_PATH = /usr/local
+      endif
+    endif
+  endif
+endif
+
 #
 # Get platform definitions
 #
@@ -101,10 +123,10 @@
 
 # An attempt is made to generate unique enough directories for the
 # generated files to not have name collisisons. Most build units
-# defines PRODUCT (except Release.gmk), but then they may or may 
-# not define PACKAGE, THREADIR (only HPI uses this), PROGRAM, and 
-# LIBRARY. This code chunk attempts to generate a unique 
-# OBJDIR/CLASSHDRDIR for each build unit based on which of those 
+# defines PRODUCT (except Release.gmk), but then they may or may
+# not define PACKAGE, THREADIR (only HPI uses this), PROGRAM, and
+# LIBRARY. This code chunk attempts to generate a unique
+# OBJDIR/CLASSHDRDIR for each build unit based on which of those
 # values are set within each build unit.
 
 UNIQUE_LOCATION_STRING = tmp
@@ -133,7 +155,7 @@
   UNIQUE_LOCATION_STRING += /$(THREADDIR)
 endif
 
-# the use of += above makes a space separated list which we need to 
+# the use of += above makes a space separated list which we need to
 # remove for filespecs.
 #
 NULLSTRING :=
@@ -176,9 +198,9 @@
 # Classpath seen by javac (different from the one seen by the VM
 # running javac), and useful variables.
 #
-SOURCEPATH	= $(VPATH.java)
-PKG		= $(shell $(EXPR) $(PACKAGE) : '\([a-z]*\)')
-PKGDIR		= $(subst .,/,$(PACKAGE))
+SOURCEPATH      = $(VPATH.java)
+PKG             = $(shell $(EXPR) $(PACKAGE) : '\([a-z]*\)')
+PKGDIR          = $(subst .,/,$(PACKAGE))
 
 #
 # The java/javac/jdk variables (JAVAC_CMD, JAVA_CMD, etc.)
diff --git a/corba/make/common/shared/Defs-bsd.gmk b/corba/make/common/shared/Defs-bsd.gmk
new file mode 100644
index 0000000..2869149
--- /dev/null
+++ b/corba/make/common/shared/Defs-bsd.gmk
@@ -0,0 +1,131 @@
+#
+# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# Definitions for Bsd.
+#
+
+# Default for COMPILER_WARNINGS_FATAL on Bsd (C & C++ compiler warnings)
+ifndef COMPILER_WARNINGS_FATAL
+  COMPILER_WARNINGS_FATAL=false
+endif
+
+# Bsd should use parallel compilation for best build times
+ifndef COMPILE_APPROACH
+  COMPILE_APPROACH = parallel
+endif
+
+# Indication that we are doing an incremental build.
+#    This may trigger the creation of make depend files.
+ifndef INCREMENTAL_BUILD
+  INCREMENTAL_BUILD = false
+endif
+
+# FullPath just makes sure it never ends with a / and no duplicates
+define FullPath
+$(shell cd $1 2> $(DEV_NULL) && pwd)
+endef
+
+# OptFullPath: Absolute path name of a dir that might not initially exist.
+define OptFullPath
+$(shell if [ "$1" != "" -a -d "$1" ]; then (cd $1 && pwd); else echo "$1"; fi)
+endef
+
+# Location on system where jdk installs might be
+USRJDKINSTANCES_PATH =$(PACKAGE_PATH)
+
+# UNIXCOMMAND_PATH: path to where the most common Unix commands are.
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_UNIXCOMMAND_PATH)" "undefined"
+  UNIXCOMMAND_PATH :=$(call PrefixPath,$(ALT_UNIXCOMMAND_PATH))
+else
+  UNIXCOMMAND_PATH  = /bin/
+endif
+
+# USRBIN_PATH: path to where the most common Unix commands are.
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_USRBIN_PATH)" "undefined"
+  USRBIN_PATH :=$(call PrefixPath,$(ALT_USRBIN_PATH))
+else
+  USRBIN_PATH  = /usr/bin/
+endif
+
+# UNIXCCS_PATH: path to where the Solaris ported UNIX commands can be found
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_UNIXCCS_PATH)" "undefined"
+  UNIXCCS_PATH :=$(call PrefixPath,$(ALT_UNIXCCS_PATH))
+else
+  UNIXCCS_PATH = /usr/ccs/bin/
+endif
+
+# SLASH_JAVA: location of all network accessable files
+ifdef ALT_SLASH_JAVA
+  SLASH_JAVA  :=$(ALT_SLASH_JAVA)
+else
+  SLASH_JAVA  := $(call DirExists,/java,/java,/NOT-SET)
+endif
+
+# JDK_DEVTOOLS_DIR: common path for all the java devtools
+ifdef ALT_JDK_DEVTOOLS_DIR
+  JDK_DEVTOOLS_DIR  =$(ALT_JDK_DEVTOOLS_DIR)
+else
+  JDK_DEVTOOLS_DIR =$(SLASH_JAVA)/devtools
+endif
+
+# DEVTOOLS_PATH: for other tools required for building (such as zip, etc.)
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_DEVTOOLS_PATH)" "undefined"
+  DEVTOOLS_PATH :=$(call PrefixPath,$(ALT_DEVTOOLS_PATH))
+else
+  DEVTOOLS_PATH =$(PACKAGE_PATH)/bin/
+endif
+
+# _BOOTDIR1: First choice for a Bootstrap JDK, previous released JDK.
+# _BOOTDIR2: Second choice
+ifndef ALT_BOOTDIR
+  _BOOTDIR1  =$(SLASH_JAVA)/re/jdk/$(PREVIOUS_JDK_VERSION)/archive/fcs/binaries/$(PLATFORM)-$(ARCH)
+  _BOOTDIR2  =$(USRJDKINSTANCES_PATH)/jdk$(PREVIOUS_JDK_VERSION)
+endif
+
+# Import JDK images allow for partial builds, components not built are
+#    imported (or copied from) these import areas when needed.
+
+# BUILD_JDK_IMPORT_PATH: location of JDK install trees to import for
+#   multiple platforms, e.g. windows-i586, solaris-sparc, bsd-586, etc.
+ifdef ALT_BUILD_JDK_IMPORT_PATH
+  BUILD_JDK_IMPORT_PATH  :=$(call FullPath,$(ALT_BUILD_JDK_IMPORT_PATH))
+else
+  BUILD_JDK_IMPORT_PATH   = $(PROMOTED_BUILD_BINARIES)
+endif
+BUILD_JDK_IMPORT_PATH:=$(call AltCheckValue,BUILD_JDK_IMPORT_PATH)
+
+# JDK_IMPORT_PATH: location of JDK install tree (this version) to import
+ifdef ALT_JDK_IMPORT_PATH
+  JDK_IMPORT_PATH  :=$(call FullPath,$(ALT_JDK_IMPORT_PATH))
+else
+  JDK_IMPORT_PATH   = $(BUILD_JDK_IMPORT_PATH)/$(PLATFORM)-$(ARCH)$(_JDK_IMPORT_VARIANT)
+endif
+JDK_IMPORT_PATH:=$(call AltCheckValue,JDK_IMPORT_PATH)
+
diff --git a/corba/make/common/shared/Defs-utils.gmk b/corba/make/common/shared/Defs-utils.gmk
index f8dc58c..40bf468 100644
--- a/corba/make/common/shared/Defs-utils.gmk
+++ b/corba/make/common/shared/Defs-utils.gmk
@@ -31,7 +31,7 @@
 # These input UTILS_* variables can be defined at anytime, ideally once.
 #         Unix Commands: Normally /bin/, /usr/bin/. or C:/mksnt/mksnt/
 #            UTILS_COMMAND_PATH
-#         /usr/bin/ 
+#         /usr/bin/
 #            UTILS_USR_BIN_PATH
 #         /usr/ccs/bin/ (sccs, m4, lex, yacc, as, ar, strip, mcs)
 #            UTILS_CCS_BIN_PATH
@@ -53,6 +53,13 @@
   UTILS_DEVTOOL_PATH=$(USRBIN_PATH)
 endif
 
+ifeq ($(PLATFORM),bsd)
+  UTILS_COMMAND_PATH=$(UNIXCOMMAND_PATH)
+  UTILS_USR_BIN_PATH=$(USRBIN_PATH)
+  UTILS_CCS_BIN_PATH=$(USRBIN_PATH)
+  UTILS_DEVTOOL_PATH=$(DEVTOOLS_PATH)
+endif
+
 ifeq ($(PLATFORM),solaris)
   UTILS_COMMAND_PATH=$(UNIXCOMMAND_PATH)
   UTILS_USR_BIN_PATH=$(UNIXCOMMAND_PATH)
@@ -166,15 +173,15 @@
   # Also, some distribution (Ubuntu, Debian, others?) place the rpm command
   # itself in /usr/bin rather than it's traditional home in /bin.
   RPM=$(firstword $(wildcard $(UTILS_COMMAND_PATH)rpm) \
-		  $(wildcard $(UTILS_USR_BIN_PATH)rpm))
+                  $(wildcard $(UTILS_USR_BIN_PATH)rpm))
   RPMBUILD=$(firstword $(wildcard $(UTILS_COMMAND_PATH)rpmbuild) \
-		       $(wildcard $(UTILS_USR_BIN_PATH)rpmbuild) \
-		       $(wildcard $(UTILS_COMMAND_PATH)rpm) \
-		       $(wildcard $(UTILS_USR_BIN_PATH)rpm))
+                       $(wildcard $(UTILS_USR_BIN_PATH)rpmbuild) \
+                       $(wildcard $(UTILS_COMMAND_PATH)rpm) \
+                       $(wildcard $(UTILS_USR_BIN_PATH)rpm))
   # Most Linux distros have "sort" in /bin.  Ubuntu, Debian and perhaps
   # others have it in /usr/bin.
   SORT=$(firstword $(wildcard $(UTILS_COMMAND_PATH)sort) \
-		   $(wildcard $(UTILS_USR_BIN_PATH)sort))
+                   $(wildcard $(UTILS_USR_BIN_PATH)sort))
   NAWK           = $(USRBIN_PATH)gawk
   # Intrinsic unix command, with backslash-escaped character interpretation
   ECHO           = /bin/echo -e
@@ -198,3 +205,34 @@
   ECHO           = /usr/bin/echo
 endif
 
+# BSD specific
+ifeq ($(PLATFORM),bsd)
+  BASENAME     = $(UTILS_USR_BIN_PATH)basename
+  EGREP        = $(UTILS_USR_BIN_PATH)egrep
+  EXPR         = $(UTILS_COMMAND_PATH)expr
+  FMT          = $(UTILS_USR_BIN_PATH)fmt
+  GREP         = $(UTILS_USR_BIN_PATH)grep
+  GUNZIP       = $(UTILS_USR_BIN_PATH)gunzip
+  ID           = $(UTILS_USR_BIN_PATH)id
+  MSGFMT       = $(UTILS_DEVTOOL_PATH)msgfmt
+  SED          = $(UTILS_USR_BIN_PATH)sed
+  SORT         = $(UTILS_USR_BIN_PATH)sort
+  TEST         = $(UTILS_COMMAND_PATH)test
+  TOUCH        = $(UTILS_USR_BIN_PATH)touch
+  TRUE         = $(UTILS_USR_BIN_PATH)true
+  UNAME        = $(UTILS_USR_BIN_PATH)uname
+  # BSD OS_VENDOR specific
+  ifeq ($(OS_VENDOR), Apple)
+    NAWK       = $(UTILS_USR_BIN_PATH)awk
+    UNZIPSFX   = $(UTILS_USR_BIN_PATH)unzipsfx
+    ZIPEXE     = $(UTILS_USR_BIN_PATH)zip
+  else
+    UNZIP      = $(UTILS_DEVTOOL_PATH)unzip
+  endif
+  ifeq ($(OS_VENDOR), OpenBSD)
+    NAWK       = $(UTILS_USR_BIN_PATH)awk
+  else
+    CPIO       = $(UTILS_USR_BIN_PATH)cpio
+    TAR        = $(UTILS_USR_BIN_PATH)tar
+  endif
+endif
diff --git a/corba/make/common/shared/Platform.gmk b/corba/make/common/shared/Platform.gmk
index 07d0b50..fbb2dba 100644
--- a/corba/make/common/shared/Platform.gmk
+++ b/corba/make/common/shared/Platform.gmk
@@ -62,8 +62,8 @@
 #     CLASSPATH_SEPARATOR         separator in classpath, ; or :
 #     BUNDLE_FILE_SUFFIX          suffix for bundles: .tar or .tar.gz
 #     ISA_DIR                     solaris only: /sparcv9 or /amd64
-#     REQUIRED_WINDOWS_NAME       windows only: basic name of windows 
-#     REQUIRED_WINDOWS_VERSION    windows only: specific version of windows 
+#     REQUIRED_WINDOWS_NAME       windows only: basic name of windows
+#     REQUIRED_WINDOWS_VERSION    windows only: specific version of windows
 #     USING_CYGWIN                windows only: true or false
 #     WINDOWS_NT_VERSION_STRING   windows only: long version name
 #     REQUIRED_OS_VERSION         required OS version, e.g. 5.10, 2.4
@@ -135,7 +135,7 @@
   BUNDLE_FILE_SUFFIX=.tar
   # Required Solaris version
   REQUIRED_OS_VERSION = 5.10
-  # Minimum disk space needed as determined by running 'du -sk' on 
+  # Minimum disk space needed as determined by running 'du -sk' on
   #    a fully built workspace.
   ifeq ($(ARCH_FAMILY), sparc)
     REQUIRED_FREE_SPACE=1300000
@@ -207,7 +207,7 @@
 
   # Suffix for file bundles used in previous release
   BUNDLE_FILE_SUFFIX=.tar.gz
-  # Minimum disk space needed as determined by running 'du -sk' on 
+  # Minimum disk space needed as determined by running 'du -sk' on
   #    a fully built workspace.
   REQUIRED_FREE_SPACE=1460000
   LINUX_VERSION_INFO = /etc/redhat-release
@@ -231,6 +231,98 @@
   MB_OF_MEMORY := $(shell free -m | fgrep Mem: | sed -e 's@\ \ *@ @g' | cut -d' ' -f2)
 endif
 
+ifeq ($(SYSTEM_UNAME), FreeBSD)
+  PLATFORM = bsd
+  OS_NAME = freebsd
+  OS_VENDOR = FreeBSD
+  REQUIRED_OS_VERSION = 6.0
+endif
+
+ifeq ($(SYSTEM_UNAME), Darwin)
+  PLATFORM = bsd
+  OS_NAME = darwin
+  OS_VENDOR = Apple
+  REQUIRED_OS_VERSION = 8.0
+endif
+
+ifeq ($(SYSTEM_UNAME), NetBSD)
+  PLATFORM = bsd
+  OS_NAME = netbsd
+  OS_VENDOR = NetBSD
+  REQUIRED_OS_VERSION = 3.0
+endif
+
+ifeq ($(SYSTEM_UNAME), OpenBSD)
+  PLATFORM = bsd
+  OS_NAME = openbsd
+  OS_VENDOR = OpenBSD
+  REQUIRED_OS_VERSION = 4.9
+endif
+
+# Platform settings specific to BSD
+ifeq ($(PLATFORM), bsd)
+  OS_VERSION := $(shell uname -r)
+  # Arch and OS name/version
+  mach := $(shell uname -m)
+  archExpr = case "$(mach)" in \
+                i[3-9]86) \
+                    echo i586 \
+                    ;; \
+                sparc64) \
+                    echo sparcv9 \
+                    ;; \
+                sparc*) \
+                    echo sparc \
+                    ;; \
+                x86_64) \
+                    echo amd64 \
+                    ;; \
+                "Power Macintosh") \
+                    echo ppc \
+                    ;; \
+                *) \
+                    echo $(mach) \
+                    ;; \
+      esac
+  ARCH        := $(shell $(archExpr) )
+  ARCH_FAMILY := $(ARCH)
+
+  # Darwin x86 builds are i386/amd64 universal.
+  ifeq ($(SYSTEM_UNAME), Darwin)
+    ifneq ($(ARCH), ppc)
+      ARCH=universal
+    endif
+  endif
+
+  # i586, sparc, and ppc are 32 bit, amd64 and sparc64 are 64
+  ifneq (,$(findstring $(ARCH), i586 sparc ppc universal))
+    ARCH_DATA_MODEL=32
+  else
+    ARCH_DATA_MODEL=64
+  endif
+
+  ifeq ($(ARCH), i586)
+    LIBARCH = i386
+  else
+    LIBARCH = $(ARCH)
+  endif
+
+  # Value of Java os.arch property
+  ARCHPROP  = $(LIBARCH)
+
+  # Suffix for file bundles used in previous release
+  BUNDLE_FILE_SUFFIX=.tar.gz
+  # Minimum disk space needed as determined by running 'du -sk' on
+  #    a fully built workspace.
+  REQUIRED_FREE_SPACE=1500000
+  # How much RAM does this machine have:
+  ifeq ($(OS_VENDOR), OpenBSD)
+    MB_OF_MEMORY=$(shell sysctl -n hw.physmem | awk '{print int($$NF / 1048576); }' )
+  else
+    MB_OF_MEMORY=$(shell (sysctl -n hw.physmem64 2> /dev/null || sysctl -n hw.physmem) | awk '{print int($$NF / 1048576); }' )
+  endif
+endif
+
 # Windows with and without CYGWIN will be slightly different
 ifeq ($(SYSTEM_UNAME), Windows_NT)
   PLATFORM = windows
@@ -327,7 +419,7 @@
   endif
   # Suffix for file bundles used in previous release
   BUNDLE_FILE_SUFFIX=.tar
-  # Minimum disk space needed as determined by running 'du -sk' on 
+  # Minimum disk space needed as determined by running 'du -sk' on
   #    a fully built workspace.
   REQUIRED_FREE_SPACE=500000
   # How much RAM does this machine have:
@@ -335,8 +427,8 @@
     MB_OF_MEMORY := $(shell \
       if [ -f "C:/cygwin/bin/free.exe" ] ; then \
         ( C:/cygwin/bin/bash.exe -c "C:/cygwin/bin/free.exe -m" ) | \
-	  grep Mem: | \
-	  sed -e 's@\ \ *@ @g' | cut -d' ' -f2 ; \
+          grep Mem: | \
+          sed -e 's@\ \ *@ @g' | cut -d' ' -f2 ; \
       else \
         echo "512"; \
       fi)
@@ -392,7 +484,7 @@
   # Where is unwanted output to be delivered?
   DEV_NULL = /dev/null
   export DEV_NULL
-  # Character used between entries in classpath 
+  # Character used between entries in classpath
   CLASSPATH_SEPARATOR = :
   # User name determination (set _USER)
   ifndef USER
diff --git a/corba/make/jprt.properties b/corba/make/jprt.properties
index c95c9d0..537c099 100644
--- a/corba/make/jprt.properties
+++ b/corba/make/jprt.properties
@@ -25,12 +25,24 @@
 
 # Properties for jprt
 
-# Use whatever release that the submitted job requests
-jprt.tools.default.release=${jprt.submit.release}
+# Locked down to jdk7
+jprt.tools.default.release=jdk7
 
 # The different build flavors we want, we override here so we just get these 2
 jprt.build.flavors=product,fastdebug
 
+# Standard list of jprt build targets for this source tree
+jprt.build.targets=                                             \
+    solaris_sparc_5.10-{product|fastdebug},                     \
+    solaris_sparcv9_5.10-{product|fastdebug},                   \
+    solaris_i586_5.10-{product|fastdebug},                      \
+    solaris_x64_5.10-{product|fastdebug},                       \
+    linux_i586_2.6-{product|fastdebug},                         \
+    linux_x64_2.6-{product|fastdebug},                          \
+    macosx_x64_10.7-{product|fastdebug},                        \
+    windows_i586_5.1-{product|fastdebug},                       \
+    windows_x64_5.2-{product|fastdebug}
+
 # Directories to be excluded from the source bundles
 jprt.bundle.exclude.src.dirs=build dist webrev
 
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream.java b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream.java
index 9d33708..2202014 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -423,6 +423,13 @@
         impl.setByteBufferWithInfo(bbwi);
     }
 
+    /**
+     * return true if our ByteBuffer is sharing/equal to bb
+     */
+    protected final boolean isSharing(ByteBuffer bb) {
+        return (getByteBuffer() ==  bb);
+    }
+
     public final int getBufferLength() {
         return impl.getBufferLength();
     }
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream_1_0.java b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream_1_0.java
index 2ecf0dd..d17d6f3 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream_1_0.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream_1_0.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2412,7 +2412,6 @@
 
         if (bbwi != null && getByteBuffer() != null)
         {
-            int bbHash = System.identityHashCode(bbwi.byteBuffer);
             MessageMediator messageMediator = parent.getMessageMediator();
             if (messageMediator != null)
             {
@@ -2420,19 +2419,12 @@
                              (CDROutputObject)messageMediator.getOutputObject();
                 if (outputObj != null)
                 {
-                    ByteBuffer outputBb = outputObj.getByteBuffer();
-
-                    int oBbHash = 0;
-                    if (outputBb != null)
+                    if (outputObj.isSharing(getByteBuffer()))
                     {
-                        oBbHash = System.identityHashCode(outputBb);
-                        if (bbHash == oBbHash)  // shared?
-                        {
-                            // Set OutputStream's ByteBuffer and bbwi to null
-                            // so its ByteBuffer cannot be released to the pool
-                            outputObj.setByteBuffer(null);
-                            outputObj.setByteBufferWithInfo(null);
-                        }
+                        // Set OutputStream's ByteBuffer and bbwi to null
+                        // so its ByteBuffer cannot be released to the pool
+                        outputObj.setByteBuffer(null);
+                        outputObj.setByteBufferWithInfo(null);
                     }
                 }
             }
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream.java b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream.java
index 7ea49ea..2275dc5 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -357,6 +357,13 @@
         impl.setByteBuffer(byteBuffer);
     }
 
+    /**
+     * return true if our ByteBuffer is sharing/equal to bb
+     */
+    protected final boolean isSharing(ByteBuffer bb) {
+        return (getByteBuffer() ==  bb);
+    }
+
     public final boolean isLittleEndian() {
         return impl.isLittleEndian();
     }
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream_1_0.java b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream_1_0.java
index f8741c2..25e1528 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream_1_0.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream_1_0.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1902,7 +1902,6 @@
 
         if (getByteBufferWithInfo() != null && getByteBuffer() != null)
         {
-            int bbHash = System.identityHashCode(bbwi.byteBuffer);
             MessageMediator messageMediator = parent.getMessageMediator();
             if (messageMediator != null)
             {
@@ -1910,19 +1909,12 @@
                                (CDRInputObject)messageMediator.getInputObject();
                 if (inputObj != null)
                 {
-                    ByteBuffer inputBb = inputObj.getByteBuffer();
-
-                    int iBbHash = 0;
-                    if (inputBb != null)
+                    if (inputObj.isSharing(getByteBuffer()))
                     {
-                        iBbHash = System.identityHashCode(inputBb);
-                        if (bbHash == iBbHash)  // shared?
-                        {
-                            // Set InputStream's ByteBuffer and bbwi to null
-                            // so its ByteBuffer cannot be released to the pool
-                            inputObj.setByteBuffer(null);
-                            inputObj.setByteBufferWithInfo(null);
-                        }
+                        // Set InputStream's ByteBuffer and bbwi to null
+                        // so its ByteBuffer cannot be released to the pool
+                        inputObj.setByteBuffer(null);
+                        inputObj.setByteBufferWithInfo(null);
                     }
                 }
             }
diff --git a/hotspot/.hgignore b/hotspot/.hgignore
index 4824708..c652de1 100644
--- a/hotspot/.hgignore
+++ b/hotspot/.hgignore
@@ -6,3 +6,4 @@
 ^src/share/tools/IdealGraphVisualizer/build/
 ^src/share/tools/IdealGraphVisualizer/dist/
 ^.hgtip
+.DS_Store
diff --git a/hotspot/.hgtags b/hotspot/.hgtags
index 0e888a6..76e00e1 100644
--- a/hotspot/.hgtags
+++ b/hotspot/.hgtags
@@ -188,6 +188,8 @@
 3a2fb61165dfc72e398179a2796d740c8da5b8c0 jdk8-b03
 0fa3ace511fe98fe948e751531f3e2b7c60c8376 jdk8-b04
 dce7d24674f4d0bed00de24f00119057fdce7cfb jdk8-b05
+0db80d8e77fccddf5e6fa49963226b54ac7d0f62 jdk8-b06
+3f0cf875af83f55ec5e1a5cea80455315f9322a2 jdk8-b07
 0cc8a70952c368e06de2adab1f2649a408f5e577 hs22-b01
 7c29742c41b44fb0cd5a13c7ac8834f3f2ca649e hs22-b02
 3a2fb61165dfc72e398179a2796d740c8da5b8c0 hs22-b03
@@ -199,11 +201,18 @@
 513a84dd0f8b56dc0836b4e0bdd5dd0a778fc634 hs22-b05
 650d15d8f37255d3b805aa00c5bd1c30984b203d hs22-b06
 8035e71ac3f6c8a453f7e9483e7144731388b14e jdk7u2-b08
-cd3d4ec354fd040c1f47614991b3fe6d5cc5e9da hs22-b07
-b93bc193d73bd4d07150a3e8f85a8ca4bb18157c jdk7u2-b09
-623aec2a90f721fd0de9877bf7be8624874fd557 hs22-b08
-482e282037d780ca48a0eaaa4015b8ae20f0e0a9 jdk7u2-b11
-c8abdaa56b471195aefbac6ee385d7d35b8aec74 hs22-b09
-4061b13e3e6be63b6f157ef773f374f2355fdb48 jdk7u2-b12
-3ba0bb2e7c8ddac172f5b995aae57329cdd2dafa hs22-b10
-f17fe2f4b6aacc19cbb8ee39476f2f13a1c4d3cd jdk7u2-b13
+da883b9e6d3788057f9577e72712998ed82c9b7e hs23-b01
+49ed7eacfd16616166ff066493143889741097af jdk8-b08
+7c20d272643f47195478708eff593a9cce40fec4 jdk8-b09
+e4f412d2b75d2c797acff965aa2c420e3d358f09 hs23-b02
+d815de2e85e511b7deab2a83cf80c0224d011da9 jdk8-b10
+4d3850d9d326ac3a9bee2d867727e954322d014e hs23-b03
+7e508fbcb95078cc7513e2af93463c0e2616eea4 jdk7u4-b01
+4538caeef7b6cbd4302bebced805d65e68ccf301 jdk8-b11
+6534482ff68ad79066dfe15dfb6d8905f09681bd hs23-b04
+1d3900713a67a0a39faf4e12c9c158d55aebef87 jdk8-b12
+3e609627e780736f372eb14d29bb9b5e53b21fbf hs23-b05
+b92ca8e229d29004f840c67e620833d23a346761 jdk8-b13
+088d09a130ff02d8f5f05e92256baabe412f0439 jdk8-b14
+6c2a55d4902f202e1c2de1df17b7da083a2c31e8 hs23-b06
+35aadd2e739b7231dd4c2a26d9fc24b286afc576 jdk7u4-b03
diff --git a/hotspot/THIRD_PARTY_README b/hotspot/THIRD_PARTY_README
index 77e3510..ee5463a 100644
--- a/hotspot/THIRD_PARTY_README
+++ b/hotspot/THIRD_PARTY_README
@@ -216,16 +216,15 @@
 is included with JRE 7, JDK 7, and OpenJDK 7.
 
 You are receiving a copy of the Elliptic Curve Cryptography library in source
-form with the JDK 7 and OpenJDK7 source distributions, and as object code in
-the JRE 7 & JDK 7 runtimes.
+form with the JDK 7 source distribution and object code in the JRE 7 & JDK 7
+runtime.
 
-In the case of the JRE 7 & JDK 7 runtimes, the terms of the Oracle license do
-NOT apply to the Elliptic Curve Cryptography library; it is licensed under the
-following license, separately from Oracle's JDK & JRE.  If you do not wish to
-install the Elliptic Curve Cryptography library, you may delete the library
-named libsunec.so (on Solaris and Linux systems) or sunec.dll (on Windows
-systems) from the JRE bin directory reserved for native libraries.
-
+The terms of the Oracle license do NOT apply to the Elliptic Curve
+Cryptography library program; it is licensed under the following license,
+separately from the Oracle programs you receive. If you do not wish to install
+this program, you may delete the library named libsunec.so (on Solaris and
+Linux systems) or sunec.dll (on Windows systems) from the JRE bin directory
+reserved for native libraries.
 
 --- begin of LICENSE ---
 
@@ -1001,7 +1000,7 @@
 
 -------------------------------------------------------------------------------
 
-%% This notice is provided with respect to libpng 1.5.4, which is 
+%% This notice is provided with respect to libpng 1.2.18, which is 
 included with JRE 7, JDK 7, and OpenJDK 7.
 
 --- begin of LICENSE ---
@@ -1015,10 +1014,8 @@
 If you modify libpng you may insert additional notices immediately following
 this sentence.
 
-This code is released under the libpng license.
-
-libpng versions 1.2.6, August 15, 2004, through 1.5.4, July 7, 2011, are
-Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
+libpng versions 1.2.6, August 15, 2004, through 1.2.18, May 15, 2007, are
+Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.2.5
 with the following individual added to the list of Contributing Authors
 
@@ -1115,7 +1112,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-July 7, 2011
+May 15, 2007
 
 --- end of LICENSE ---
 
diff --git a/hotspot/agent/make/Makefile b/hotspot/agent/make/Makefile
index c38c786..fd54993 100644
--- a/hotspot/agent/make/Makefile
+++ b/hotspot/agent/make/Makefile
@@ -53,6 +53,9 @@
 sun.jvm.hotspot.compiler \
 sun.jvm.hotspot.debugger \
 sun.jvm.hotspot.debugger.amd64 \
+sun.jvm.hotspot.debugger.bsd \
+sun.jvm.hotspot.debugger.bsd.amd64 \
+sun.jvm.hotspot.debugger.bsd.x86 \
 sun.jvm.hotspot.debugger.cdbg \
 sun.jvm.hotspot.debugger.cdbg.basic \
 sun.jvm.hotspot.debugger.cdbg.basic.amd64 \
@@ -94,6 +97,9 @@
 sun.jvm.hotspot.prims \
 sun.jvm.hotspot.runtime \
 sun.jvm.hotspot.runtime.amd64 \
+sun.jvm.hotspot.runtime.bsd \
+sun.jvm.hotspot.runtime.bsd_amd64 \
+sun.jvm.hotspot.runtime.bsd_x86 \
 sun.jvm.hotspot.runtime.ia64 \
 sun.jvm.hotspot.runtime.linux \
 sun.jvm.hotspot.runtime.linux_amd64 \
@@ -144,6 +150,9 @@
 sun/jvm/hotspot/compiler/*.java \
 sun/jvm/hotspot/debugger/*.java \
 sun/jvm/hotspot/debugger/amd64/*.java \
+sun/jvm/hotspot/debugger/bsd/*.java \
+sun/jvm/hotspot/debugger/bsd/amd64/*.java \
+sun/jvm/hotspot/debugger/bsd/x86/*.java \
 sun/jvm/hotspot/debugger/cdbg/*.java \
 sun/jvm/hotspot/debugger/cdbg/basic/*.java \
 sun/jvm/hotspot/debugger/cdbg/basic/amd64/*.java \
@@ -180,6 +189,9 @@
 sun/jvm/hotspot/prims/*.java \
 sun/jvm/hotspot/runtime/*.java \
 sun/jvm/hotspot/runtime/amd64/*.java \
+sun/jvm/hotspot/runtime/bsd/*.java \
+sun/jvm/hotspot/runtime/bsd_amd64/*.java \
+sun/jvm/hotspot/runtime/bsd_x86/*.java \
 sun/jvm/hotspot/runtime/ia64/*.java \
 sun/jvm/hotspot/runtime/linux/*.java \
 sun/jvm/hotspot/runtime/linux_amd64/*.java \
diff --git a/hotspot/agent/src/os/bsd/BsdDebuggerLocal.c b/hotspot/agent/src/os/bsd/BsdDebuggerLocal.c
new file mode 100644
index 0000000..85b07f7
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/BsdDebuggerLocal.c
@@ -0,0 +1,413 @@
+/*
+ * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <stdlib.h>
+#include <jni.h>
+#include "libproc.h"
+
+#if defined(x86_64) && !defined(amd64)
+#define amd64 1
+#endif
+
+#ifdef i386
+#include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
+#endif
+
+#ifdef amd64
+#include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
+#endif
+
+#if defined(sparc) || defined(sparcv9)
+#include "sun_jvm_hotspot_debugger_sparc_SPARCThreadContext.h"
+#endif
+
+static jfieldID p_ps_prochandle_ID = 0;
+static jfieldID threadList_ID = 0;
+static jfieldID loadObjectList_ID = 0;
+
+static jmethodID createClosestSymbol_ID = 0;
+static jmethodID createLoadObject_ID = 0;
+static jmethodID getThreadForThreadId_ID = 0;
+static jmethodID listAdd_ID = 0;
+
+#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
+#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
+#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
+#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
+
+static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
+  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
+}
+
+static struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) {
+  jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID);
+  return (struct ps_prochandle*)(intptr_t)ptr;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    init0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0
+  (JNIEnv *env, jclass cls) {
+  jclass listClass;
+
+  if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
+     THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
+  }
+
+  // fields we use
+  p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J");
+  CHECK_EXCEPTION;
+  threadList_ID = (*env)->GetFieldID(env, cls, "threadList", "Ljava/util/List;");
+  CHECK_EXCEPTION;
+  loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;");
+  CHECK_EXCEPTION;
+
+  // methods we use
+  createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol",
+                    "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
+  CHECK_EXCEPTION;
+  createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject",
+                    "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
+  CHECK_EXCEPTION;
+  getThreadForThreadId_ID = (*env)->GetMethodID(env, cls, "getThreadForThreadId",
+                                                     "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;");
+  CHECK_EXCEPTION;
+  // java.util.List method we call
+  listClass = (*env)->FindClass(env, "java/util/List");
+  CHECK_EXCEPTION;
+  listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
+  CHECK_EXCEPTION;
+}
+
+JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
+  (JNIEnv *env, jclass cls)
+{
+#ifdef _LP64
+ return 8;
+#else
+ return 4;
+#endif
+
+}
+
+
+static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
+  int n = 0, i = 0;
+
+  // add threads
+  n = get_num_threads(ph);
+  for (i = 0; i < n; i++) {
+    jobject thread;
+    jobject threadList;
+    lwpid_t lwpid;
+
+    lwpid = get_lwp_id(ph, i);
+    thread = (*env)->CallObjectMethod(env, this_obj, getThreadForThreadId_ID,
+                                      (jlong)lwpid);
+    CHECK_EXCEPTION;
+    threadList = (*env)->GetObjectField(env, this_obj, threadList_ID);
+    CHECK_EXCEPTION;
+    (*env)->CallBooleanMethod(env, threadList, listAdd_ID, thread);
+    CHECK_EXCEPTION;
+  }
+
+  // add load objects
+  n = get_num_libs(ph);
+  for (i = 0; i < n; i++) {
+     uintptr_t base;
+     const char* name;
+     jobject loadObject;
+     jobject loadObjectList;
+
+     base = get_lib_base(ph, i);
+     name = get_lib_name(ph, i);
+     loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID,
+                                   (*env)->NewStringUTF(env, name), (jlong)0, (jlong)base);
+     CHECK_EXCEPTION;
+     loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
+     CHECK_EXCEPTION;
+     (*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject);
+     CHECK_EXCEPTION;
+  }
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I
+  (JNIEnv *env, jobject this_obj, jint jpid) {
+
+  struct ps_prochandle* ph;
+  if ( (ph = Pgrab(jpid)) == NULL) {
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
+  }
+  (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
+  fillThreadsAndLoadObjects(env, this_obj, ph);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
+  (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
+  const char *execName_cstr;
+  const char *coreName_cstr;
+  jboolean isCopy;
+  struct ps_prochandle* ph;
+
+  execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy);
+  CHECK_EXCEPTION;
+  coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy);
+  CHECK_EXCEPTION;
+
+  if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) {
+    (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
+    (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
+  }
+  (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
+  (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
+  (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
+  fillThreadsAndLoadObjects(env, this_obj, ph);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    detach0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0
+  (JNIEnv *env, jobject this_obj) {
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+  if (ph != NULL) {
+     Prelease(ph);
+  }
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByName0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0
+  (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
+  const char *objectName_cstr, *symbolName_cstr;
+  jlong addr;
+  jboolean isCopy;
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+
+  objectName_cstr = NULL;
+  if (objectName != NULL) {
+    objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy);
+    CHECK_EXCEPTION_(0);
+  }
+  symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy);
+  CHECK_EXCEPTION_(0);
+
+  addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr);
+
+  if (objectName_cstr != NULL) {
+    (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr);
+  }
+  (*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr);
+  return addr;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByAddress0
+ * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
+ */
+JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
+  (JNIEnv *env, jobject this_obj, jlong addr) {
+  uintptr_t offset;
+  const char* sym = NULL;
+
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+  sym = symbol_for_pc(ph, (uintptr_t) addr, &offset);
+  if (sym == NULL) return 0;
+  return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID,
+                          (*env)->NewStringUTF(env, sym), (jlong)offset);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    readBytesFromProcess0
+ * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
+ */
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0
+  (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
+
+  jboolean isCopy;
+  jbyteArray array;
+  jbyte *bufPtr;
+  ps_err_e err;
+
+  array = (*env)->NewByteArray(env, numBytes);
+  CHECK_EXCEPTION_(0);
+  bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
+  CHECK_EXCEPTION_(0);
+
+  err = ps_pread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
+  (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
+  return (err == PS_OK)? array : 0;
+}
+
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
+  (JNIEnv *env, jobject this_obj, jint lwp_id) {
+
+  struct reg gregs;
+  jboolean isCopy;
+  jlongArray array;
+  jlong *regs;
+
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+  if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
+     THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0);
+  }
+
+#undef NPRGREG
+#ifdef i386
+#define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
+#endif
+#ifdef ia64
+#define NPRGREG IA64_REG_COUNT
+#endif
+#ifdef amd64
+#define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
+#endif
+#if defined(sparc) || defined(sparcv9)
+#define NPRGREG sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_NPRGREG
+#endif
+
+  array = (*env)->NewLongArray(env, NPRGREG);
+  CHECK_EXCEPTION_(0);
+  regs = (*env)->GetLongArrayElements(env, array, &isCopy);
+
+#undef REG_INDEX
+
+#ifdef i386
+#define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
+
+  regs[REG_INDEX(GS)]  = (uintptr_t) gregs.r_gs;
+  regs[REG_INDEX(FS)]  = (uintptr_t) gregs.r_fs;
+  regs[REG_INDEX(ES)]  = (uintptr_t) gregs.r_es;
+  regs[REG_INDEX(DS)]  = (uintptr_t) gregs.r_ds;
+  regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi;
+  regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi;
+  regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp;
+  regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp;
+  regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx;
+  regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx;
+  regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx;
+  regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax;
+  regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip;
+  regs[REG_INDEX(CS)]  = (uintptr_t) gregs.r_cs;
+  regs[REG_INDEX(SS)]  = (uintptr_t) gregs.r_ss;
+
+#endif /* i386 */
+
+#if ia64
+  regs = (*env)->GetLongArrayElements(env, array, &isCopy);
+  int i;
+  for (i = 0; i < NPRGREG; i++ ) {
+    regs[i] = 0xDEADDEAD;
+  }
+#endif /* ia64 */
+
+#ifdef amd64
+#define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
+
+  regs[REG_INDEX(R15)] = gregs.r_r15;
+  regs[REG_INDEX(R14)] = gregs.r_r14;
+  regs[REG_INDEX(R13)] = gregs.r_r13;
+  regs[REG_INDEX(R12)] = gregs.r_r12;
+  regs[REG_INDEX(RBP)] = gregs.r_rbp;
+  regs[REG_INDEX(RBX)] = gregs.r_rbx;
+  regs[REG_INDEX(R11)] = gregs.r_r11;
+  regs[REG_INDEX(R10)] = gregs.r_r10;
+  regs[REG_INDEX(R9)] = gregs.r_r9;
+  regs[REG_INDEX(R8)] = gregs.r_r8;
+  regs[REG_INDEX(RAX)] = gregs.r_rax;
+  regs[REG_INDEX(RCX)] = gregs.r_rcx;
+  regs[REG_INDEX(RDX)] = gregs.r_rdx;
+  regs[REG_INDEX(RSI)] = gregs.r_rsi;
+  regs[REG_INDEX(RDI)] = gregs.r_rdi;
+  regs[REG_INDEX(RIP)] = gregs.r_rip;
+  regs[REG_INDEX(CS)] = gregs.r_cs;
+  regs[REG_INDEX(RSP)] = gregs.r_rsp;
+  regs[REG_INDEX(SS)] = gregs.r_ss;
+//  regs[REG_INDEX(FSBASE)] = gregs.fs_base;
+//  regs[REG_INDEX(GSBASE)] = gregs.gs_base;
+//  regs[REG_INDEX(DS)] = gregs.ds;
+//  regs[REG_INDEX(ES)] = gregs.es;
+//  regs[REG_INDEX(FS)] = gregs.fs;
+//  regs[REG_INDEX(GS)] = gregs.gs;
+
+#endif /* amd64 */
+
+#if defined(sparc) || defined(sparcv9)
+
+#define REG_INDEX(reg) sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_##reg
+
+#ifdef _LP64
+  regs[REG_INDEX(R_PSR)] = gregs.tstate;
+  regs[REG_INDEX(R_PC)]  = gregs.tpc;
+  regs[REG_INDEX(R_nPC)] = gregs.tnpc;
+  regs[REG_INDEX(R_Y)]   = gregs.y;
+#else
+  regs[REG_INDEX(R_PSR)] = gregs.psr;
+  regs[REG_INDEX(R_PC)]  = gregs.pc;
+  regs[REG_INDEX(R_nPC)] = gregs.npc;
+  regs[REG_INDEX(R_Y)]   = gregs.y;
+#endif
+  regs[REG_INDEX(R_G0)]  =            0 ;
+  regs[REG_INDEX(R_G1)]  = gregs.u_regs[0];
+  regs[REG_INDEX(R_G2)]  = gregs.u_regs[1];
+  regs[REG_INDEX(R_G3)]  = gregs.u_regs[2];
+  regs[REG_INDEX(R_G4)]  = gregs.u_regs[3];
+  regs[REG_INDEX(R_G5)]  = gregs.u_regs[4];
+  regs[REG_INDEX(R_G6)]  = gregs.u_regs[5];
+  regs[REG_INDEX(R_G7)]  = gregs.u_regs[6];
+  regs[REG_INDEX(R_O0)]  = gregs.u_regs[7];
+  regs[REG_INDEX(R_O1)]  = gregs.u_regs[8];
+  regs[REG_INDEX(R_O2)]  = gregs.u_regs[ 9];
+  regs[REG_INDEX(R_O3)]  = gregs.u_regs[10];
+  regs[REG_INDEX(R_O4)]  = gregs.u_regs[11];
+  regs[REG_INDEX(R_O5)]  = gregs.u_regs[12];
+  regs[REG_INDEX(R_O6)]  = gregs.u_regs[13];
+  regs[REG_INDEX(R_O7)]  = gregs.u_regs[14];
+#endif /* sparc */
+
+
+  (*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT);
+  return array;
+}
diff --git a/hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m b/hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m
new file mode 100644
index 0000000..04eaf94
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m
@@ -0,0 +1,406 @@
+/*
+ * Copyright (c) 2002, 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <objc/objc-runtime.h>
+#import <Foundation/Foundation.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#include <JavaVM/jni.h>
+
+#import <mach/mach.h>
+#import <mach/mach_types.h>
+#import <sys/sysctl.h>
+#import <stdlib.h>
+
+jboolean debug = JNI_FALSE;
+
+static jfieldID symbolicatorID = 0; // set in _init0
+static jfieldID taskID = 0; // set in _init0
+
+static void putSymbolicator(JNIEnv *env, jobject this_obj, id symbolicator) {
+  (*env)->SetLongField(env, this_obj, symbolicatorID, (jlong)(intptr_t)symbolicator);
+}
+
+static id getSymbolicator(JNIEnv *env, jobject this_obj) {
+  jlong ptr = (*env)->GetLongField(env, this_obj, symbolicatorID);
+  return (id)(intptr_t)ptr;
+}
+
+static void putTask(JNIEnv *env, jobject this_obj, task_t task) {
+  (*env)->SetLongField(env, this_obj, taskID, (jlong)task);
+}
+
+static task_t getTask(JNIEnv *env, jobject this_obj) {
+  jlong ptr = (*env)->GetLongField(env, this_obj, taskID);
+  return (task_t)ptr;
+}
+
+#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
+#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
+#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
+#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
+
+static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
+  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
+}
+
+#if defined(__i386__)
+    #define hsdb_thread_state_t     x86_thread_state32_t
+    #define hsdb_float_state_t      x86_float_state32_t
+    #define HSDB_THREAD_STATE       x86_THREAD_STATE32
+    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE32
+    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
+    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE32_COUNT
+#elif defined(__x86_64__)
+    #define hsdb_thread_state_t     x86_thread_state64_t
+    #define hsdb_float_state_t      x86_float_state64_t
+    #define HSDB_THREAD_STATE       x86_THREAD_STATE64
+    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE64
+    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
+    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE64_COUNT
+#else
+    #error "Unsupported architecture"
+#endif
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    init0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0(JNIEnv *env, jclass cls) {
+  symbolicatorID = (*env)->GetFieldID(env, cls, "symbolicator", "J");
+  taskID = (*env)->GetFieldID(env, cls, "task", "J");
+  CHECK_EXCEPTION;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByName0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
+  jlong address = 0;
+
+JNF_COCOA_ENTER(env);
+  NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
+
+  if (debug) {
+    printf("lookupInProcess called for %s\n", [symbolNameString UTF8String]);
+  }
+
+  id symbolicator = getSymbolicator(env, this_obj);
+  if (symbolicator != nil) {
+    uint64_t (*dynamicCall)(id, SEL, NSString *) = (uint64_t (*)(id, SEL, NSString *))&objc_msgSend;
+    address = (jlong) dynamicCall(symbolicator, @selector(addressForSymbol:), symbolNameString);
+  }
+
+  if (debug) {
+    printf("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
+  }
+JNF_COCOA_EXIT(env);
+
+  return address;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    readBytesFromProcess0
+ * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
+ */
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0(JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
+  if (debug) printf("readBytesFromProcess called. addr = %llx numBytes = %lld\n", addr, numBytes);
+
+  // must allocate storage instead of using former parameter buf
+  jboolean isCopy;
+  jbyteArray array;
+  jbyte *bufPtr;
+
+  array = (*env)->NewByteArray(env, numBytes);
+  CHECK_EXCEPTION_(0);
+
+  unsigned long alignedAddress;
+  unsigned long alignedLength;
+  kern_return_t result;
+  vm_offset_t *pages;
+  int *mapped;
+  long pageCount;
+  uint byteCount;
+  int i;
+  unsigned long remaining;
+
+  alignedAddress = trunc_page(addr);
+  if (addr != alignedAddress) {
+    alignedLength += addr - alignedAddress;
+  }
+  alignedLength = round_page(numBytes);
+  pageCount = alignedLength/vm_page_size;
+
+  // Allocate storage for pages and flags.
+  pages = malloc(pageCount * sizeof(vm_offset_t));
+  mapped = calloc(pageCount, sizeof(int));
+
+  task_t gTask = getTask(env, this_obj);
+  // Try to read each of the pages.
+  for (i = 0; i < pageCount; i++) {
+    result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size, 
+		     &pages[i], &byteCount);
+    mapped[i] = (result == KERN_SUCCESS); 
+    // assume all failures are unmapped pages
+  }
+
+  if (debug) fprintf(stderr, "%ld pages\n", pageCount);
+	
+  remaining = numBytes;
+	
+  for (i = 0; i < pageCount; i++) {
+    unsigned long len = vm_page_size;
+    unsigned long start = 0;
+
+    if (i == 0) {
+      start = addr - alignedAddress;
+      len = vm_page_size - start;
+    }
+
+    if (i == (pageCount - 1)) {
+      len = remaining;
+    }
+
+    if (mapped[i]) {
+      if (debug) fprintf(stderr, "page %d mapped (len %ld start %ld)\n", i, len, start);
+      (*env)->SetByteArrayRegion(env, array, 0, len, ((jbyte *) pages[i] + start));
+      vm_deallocate(mach_task_self(), pages[i], vm_page_size);
+    }
+
+    remaining -= len;
+  }
+
+  free (pages);
+  free (mapped);
+  return array;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
+ * Method:    getThreadIntegerRegisterSet0
+ * Signature: (I)[J
+ */
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0(JNIEnv *env, jobject this_obj, jint lwp_id) {
+  if (debug)
+    printf("getThreadRegisterSet0 called\n");
+
+  kern_return_t result;
+  thread_t tid;
+  mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT;
+  hsdb_thread_state_t state;
+  unsigned int *r;
+  int i;
+  jlongArray registerArray;
+  jlong *primitiveArray;
+
+  tid = lwp_id;
+
+  result = thread_get_state(tid, HSDB_THREAD_STATE, (thread_state_t)&state, &count);
+
+  if (result != KERN_SUCCESS) {
+    if (debug)
+      printf("getregs: thread_get_state(%d) failed (%d)\n", tid, result);
+    return NULL;
+  }
+
+  // 40 32-bit registers on ppc, 16 on x86. 
+  // Output order is the same as the order in the ppc_thread_state/i386_thread_state struct.
+#if defined(__i386__)
+	r = (unsigned int *)&state;
+	registerArray = (*env)->NewLongArray(env, 8);
+	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
+	primitiveArray[0] = r[0];  // eax
+	primitiveArray[1] = r[2];  // ecx
+	primitiveArray[2] = r[3];  // edx
+	primitiveArray[3] = r[1];  // ebx
+	primitiveArray[4] = r[7];  // esp
+	primitiveArray[5] = r[6];  // ebp
+	primitiveArray[6] = r[5];  // esi
+	primitiveArray[7] = r[4];  // edi
+	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
+#elif defined(__x86_64__)
+	/* From AMD64ThreadContext.java
+	   public static final int R15 = 0;
+	   public static final int R14 = 1;
+	   public static final int R13 = 2;
+	   public static final int R12 = 3;
+	   public static final int R11 = 4;
+	   public static final int R10 = 5;
+	   public static final int R9  = 6;
+	   public static final int R8  = 7;
+	   public static final int RDI = 8;
+	   public static final int RSI = 9;
+	   public static final int RBP = 10;
+	   public static final int RBX = 11;
+	   public static final int RDX = 12;
+	   public static final int RCX = 13;
+	   public static final int RAX = 14;
+	   public static final int TRAPNO = 15;
+	   public static final int ERR = 16;
+	   public static final int RIP = 17;
+	   public static final int CS = 18;
+	   public static final int RFL = 19;
+	   public static final int RSP = 20;
+	   public static final int SS = 21;
+	   public static final int FS = 22;
+	   public static final int GS = 23;
+	   public static final int ES = 24;
+	   public static final int DS = 25;
+	   public static final int FSBASE = 26;
+	   public static final int GSBASE = 27;
+	 */
+	// 64 bit
+	if (debug) printf("Getting threads for a 64-bit process\n");
+	registerArray = (*env)->NewLongArray(env, 28);
+	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
+
+	primitiveArray[0] = state.__r15;
+	primitiveArray[1] = state.__r14;
+	primitiveArray[2] = state.__r13;
+	primitiveArray[3] = state.__r12;
+	primitiveArray[4] = state.__r11;
+	primitiveArray[5] = state.__r10;
+	primitiveArray[6] = state.__r9;
+	primitiveArray[7] = state.__r8;
+	primitiveArray[8] = state.__rdi;
+	primitiveArray[9] = state.__rsi;
+	primitiveArray[10] = state.__rbp;
+	primitiveArray[11] = state.__rbx;
+	primitiveArray[12] = state.__rdx;
+	primitiveArray[13] = state.__rcx;
+	primitiveArray[14] = state.__rax;
+	primitiveArray[15] = 0;             // trapno ?
+	primitiveArray[16] = 0;             // err ?
+	primitiveArray[17] = state.__rip;
+	primitiveArray[18] = state.__cs;
+	primitiveArray[19] = state.__rflags;
+	primitiveArray[20] = state.__rsp;
+	primitiveArray[21] = 0;            // We don't have SS
+	primitiveArray[22] = state.__fs;
+	primitiveArray[23] = state.__gs;
+	primitiveArray[24] = 0;
+	primitiveArray[25] = 0;
+	primitiveArray[26] = 0;
+	primitiveArray[27] = 0;
+
+	if (debug) printf("set registers\n");
+
+	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
+#else
+#error Unsupported architecture
+#endif
+
+  return registerArray;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
+ * Method:    translateTID0
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(JNIEnv *env, jobject this_obj, jint tid) {
+  if (debug)
+    printf("translateTID0 called on tid = 0x%x\n", (int)tid);
+
+  kern_return_t result;
+  thread_t foreign_tid, usable_tid;
+  mach_msg_type_name_t type;
+    
+  foreign_tid = tid;
+    
+  task_t gTask = getTask(env, this_obj);
+  result = mach_port_extract_right(gTask, foreign_tid, 
+				   MACH_MSG_TYPE_COPY_SEND, 
+				   &usable_tid, &type);
+  if (result != KERN_SUCCESS)
+    return -1;
+    
+  if (debug)
+    printf("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
+    
+  return (jint) usable_tid;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(JNIEnv *env, jobject this_obj, jint jpid) {
+JNF_COCOA_ENTER(env);
+  if (getenv("JAVA_SAPROC_DEBUG") != NULL)
+    debug = JNI_TRUE;
+  else
+    debug = JNI_FALSE;
+  if (debug) printf("attach0 called for jpid=%d\n", (int)jpid);
+
+  kern_return_t result;
+  task_t gTask = 0;
+  result = task_for_pid(mach_task_self(), jpid, &gTask);
+  if (result != KERN_SUCCESS) {
+    fprintf(stderr, "attach: task_for_pid(%d) failed (%d)\n", (int)jpid, result);
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
+  }
+  putTask(env, this_obj, gTask);
+
+  id symbolicator = nil;
+  id jrsSymbolicator = objc_lookUpClass("JRSSymbolicator");
+  if (jrsSymbolicator != nil) {
+    id (*dynamicCall)(id, SEL, pid_t) = (id (*)(id, SEL, pid_t))&objc_msgSend;
+    symbolicator = dynamicCall(jrsSymbolicator, @selector(symbolicatorForPid:), (pid_t)jpid);
+  }
+  if (symbolicator != nil) {
+    CFRetain(symbolicator); // pin symbolicator while in java heap
+  }
+
+  putSymbolicator(env, this_obj, symbolicator);
+  if (symbolicator == nil) {
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
+  }
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    detach0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0(JNIEnv *env, jobject this_obj) {
+JNF_COCOA_ENTER(env);
+  if (debug) printf("detach0 called\n");
+
+  task_t gTask = getTask(env, this_obj);
+  mach_port_deallocate(mach_task_self(), gTask);
+  id symbolicator = getSymbolicator(env, this_obj);
+  if (symbolicator != nil) {
+    CFRelease(symbolicator);
+  }
+JNF_COCOA_EXIT(env);
+}
diff --git a/hotspot/agent/src/os/bsd/Makefile b/hotspot/agent/src/os/bsd/Makefile
new file mode 100644
index 0000000..90085c6
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/Makefile
@@ -0,0 +1,77 @@
+#
+# Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+ARCH := $(shell if ([ `uname -m` = "ia64" ])  ; then echo ia64 ; elif ([ `uname -m` = "amd64" ]) ; then echo amd64; elif ([ `uname -m` = "sparc64" ]) ; then echo sparc; else echo i386 ; fi )
+GCC      = gcc
+
+JAVAH    = ${JAVA_HOME}/bin/javah
+
+SOURCES  = salibelf.c   \
+        symtab.c        \
+	libproc_impl.c  \
+	ps_proc.c       \
+	ps_core.c       \
+	BsdDebuggerLocal.c
+
+INCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/$(shell uname -s | tr "[:upper:]" "[:lower:]")
+
+OBJS     = $(SOURCES:.c=.o)
+
+LIBS     = -lutil -lthread_db
+
+CFLAGS   = -c -fPIC -g -Wall -D_ALLBSD_SOURCE -D_GNU_SOURCE -D$(ARCH) $(INCLUDES)
+
+LIBSA = $(ARCH)/libsaproc.so
+
+all: $(LIBSA)
+
+BsdDebuggerLocal.o: BsdDebuggerLocal.c
+	$(JAVAH) -jni -classpath ../../../../../build/bsd-i586/hotspot/outputdir/bsd_i486_compiler2/generated/saclasses  \
+		sun.jvm.hotspot.debugger.x86.X86ThreadContext \
+		sun.jvm.hotspot.debugger.amd64.AMD64ThreadContext
+	$(GCC) $(CFLAGS) $<
+
+.c.obj:
+	$(GCC) $(CFLAGS)
+
+ifndef LDNOMAP
+  LFLAGS_LIBSA = -Xlinker --version-script=mapfile
+endif
+
+$(LIBSA): $(OBJS) mapfile
+	if [ ! -d $(ARCH) ] ; then mkdir $(ARCH) ; fi
+	$(GCC) -shared $(LFLAGS_LIBSA) -o $(LIBSA) $(OBJS) $(LIBS)
+
+test.o: $(LIBSA) test.c
+	$(GCC) -c -o test.o -g -D_GNU_SOURCE -D$(ARCH) $(INCLUDES) test.c
+
+test: test.o
+	$(GCC) -o test test.o -L$(ARCH) -lsaproc $(LIBS)
+
+clean:
+	rm -f $(LIBSA)
+	rm -f $(OBJS)
+	rm -f test.o
+	-rmdir $(ARCH)
+
diff --git a/hotspot/agent/src/os/bsd/StubDebuggerLocal.c b/hotspot/agent/src/os/bsd/StubDebuggerLocal.c
new file mode 100644
index 0000000..bce0bab
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/StubDebuggerLocal.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <stdlib.h>
+#include <jni.h>
+
+#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
+#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
+#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
+#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
+
+static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
+  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    init0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0
+  (JNIEnv *env, jclass cls) {
+}
+
+JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
+  (JNIEnv *env, jclass cls)
+{
+#ifdef _LP64
+ return 8;
+#else
+ return 4;
+#endif
+
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I
+  (JNIEnv *env, jobject this_obj, jint jpid) {
+
+  THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
+  (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
+  THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    detach0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0
+  (JNIEnv *env, jobject this_obj) {
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByName0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0
+  (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
+  return 0;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByAddress0
+ * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
+ */
+JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
+  (JNIEnv *env, jobject this_obj, jlong addr) {
+  return 0;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    readBytesFromProcess0
+ * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
+ */
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0
+  (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
+  return 0;
+}
+
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
+  (JNIEnv *env, jobject this_obj, jint lwp_id) {
+  return 0;
+}
diff --git a/hotspot/agent/src/os/bsd/elfmacros.h b/hotspot/agent/src/os/bsd/elfmacros.h
new file mode 100644
index 0000000..0d089c2
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/elfmacros.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef _ELFMACROS_H_
+#define _ELFMACROS_H_
+
+#define ELF_NHDR        Elf_Note
+
+#if defined(_LP64)
+#define ELF_EHDR        Elf64_Ehdr
+#define ELF_SHDR        Elf64_Shdr
+#define ELF_PHDR        Elf64_Phdr
+#define ELF_SYM         Elf64_Sym
+#define ELF_DYN         Elf64_Dyn
+#define ELF_ADDR        Elf64_Addr
+
+#ifndef ELF_ST_TYPE
+#define ELF_ST_TYPE     ELF64_ST_TYPE
+#endif
+
+#else
+
+#define ELF_EHDR        Elf32_Ehdr
+#define ELF_SHDR        Elf32_Shdr
+#define ELF_PHDR        Elf32_Phdr
+#define ELF_SYM         Elf32_Sym
+#define ELF_DYN         Elf32_Dyn
+#define ELF_ADDR        Elf32_Addr
+
+#ifndef ELF_ST_TYPE
+#define ELF_ST_TYPE     ELF32_ST_TYPE
+#endif
+
+#endif
+
+
+#endif /* _ELFMACROS_H_ */
diff --git a/hotspot/agent/src/os/bsd/libproc.h b/hotspot/agent/src/os/bsd/libproc.h
new file mode 100644
index 0000000..74bb84c
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/libproc.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef _LIBPROC_H_
+#define _LIBPROC_H_
+
+#include <unistd.h>
+#include <stdint.h>
+#include <machine/reg.h>
+#include <proc_service.h>
+
+#if defined(sparc) || defined(sparcv9)
+/*
+  If _LP64 is defined ptrace.h should be taken from /usr/include/asm-sparc64
+  otherwise it should be from /usr/include/asm-sparc
+  These two files define pt_regs structure differently
+*/
+#ifdef _LP64
+#include "asm-sparc64/ptrace.h"
+#else
+#include "asm-sparc/ptrace.h"
+#endif
+
+#endif //sparc or sparcv9
+
+/************************************************************************************
+
+0. This is very minimal subset of Solaris libproc just enough for current application.
+Please note that the bulk of the functionality is from proc_service interface. This
+adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
+file by this interface.
+
+1. pthread_id is unique. We store this in OSThread::_pthread_id in JVM code.
+
+2. All threads see the same pid when they call getpid().
+We used to save the result of ::getpid() call in OSThread::_thread_id.
+Because gettid returns actual pid of thread (lwp id), this is
+unique again. We therefore use OSThread::_thread_id as unique identifier.
+
+3. There is a unique LWP id under both thread libraries. libthread_db  maps pthread_id
+to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
+lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
+unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
+only for processes. For core dumps, we don't use libthread_db at all (like gdb).
+
+4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
+ptrace call, we refer to lwp_id of the thread.
+
+5. for core file, we parse ELF files and read data from them. For processes we  use
+combination of ptrace and /proc calls.
+
+*************************************************************************************/
+
+// This C bool type must be int for compatibility with BSD calls and
+// it would be a mistake to equivalence it to C++ bool on many platforms
+
+typedef int bool;
+#define true  1
+#define false 0
+
+struct ps_prochandle;
+
+// attach to a process
+struct ps_prochandle* Pgrab(pid_t pid);
+
+// attach to a core dump
+struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
+
+// release a process or core
+void Prelease(struct ps_prochandle* ph);
+
+// functions not directly available in Solaris libproc
+
+// initialize libproc (call this only once per app)
+// pass true to make library verbose
+bool init_libproc(bool verbose);
+
+// get number of threads
+int get_num_threads(struct ps_prochandle* ph);
+
+// get lwp_id of n'th thread
+lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
+
+// get regs for a given lwp
+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct reg* regs);
+
+// get number of shared objects
+int get_num_libs(struct ps_prochandle* ph);
+
+// get name of n'th lib
+const char* get_lib_name(struct ps_prochandle* ph, int index);
+
+// get base of lib
+uintptr_t get_lib_base(struct ps_prochandle* ph, int index);
+
+// returns true if given library is found in lib list
+bool find_lib(struct ps_prochandle* ph, const char *lib_name);
+
+// symbol lookup
+uintptr_t lookup_symbol(struct ps_prochandle* ph,  const char* object_name,
+                       const char* sym_name);
+
+// address->nearest symbol lookup. return NULL for no symbol
+const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);
+
+#endif //__LIBPROC_H_
diff --git a/hotspot/agent/src/os/bsd/libproc_impl.c b/hotspot/agent/src/os/bsd/libproc_impl.c
new file mode 100644
index 0000000..4f2d282
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/libproc_impl.c
@@ -0,0 +1,452 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <thread_db.h>
+#include "libproc_impl.h"
+
+static const char* alt_root = NULL;
+static int alt_root_len = -1;
+
+#define SA_ALTROOT "SA_ALTROOT"
+
+static void init_alt_root() {
+   if (alt_root_len == -1) {
+      alt_root = getenv(SA_ALTROOT);
+      if (alt_root) {
+         alt_root_len = strlen(alt_root);
+      } else {
+         alt_root_len = 0;
+      }
+   }
+}
+
+int pathmap_open(const char* name) {
+   int fd;
+   char alt_path[PATH_MAX + 1];
+
+   init_alt_root();
+   fd = open(name, O_RDONLY);
+   if (fd >= 0) {
+      return fd;
+   }
+
+   if (alt_root_len > 0) {
+      strcpy(alt_path, alt_root);
+      strcat(alt_path, name);
+      fd = open(alt_path, O_RDONLY);
+      if (fd >= 0) {
+         print_debug("path %s substituted for %s\n", alt_path, name);
+         return fd;
+      }
+
+      if (strrchr(name, '/')) {
+         strcpy(alt_path, alt_root);
+         strcat(alt_path, strrchr(name, '/'));
+         fd = open(alt_path, O_RDONLY);
+         if (fd >= 0) {
+            print_debug("path %s substituted for %s\n", alt_path, name);
+            return fd;
+         }
+      }
+   }
+
+   return -1;
+}
+
+static bool _libsaproc_debug;
+
+void print_debug(const char* format,...) {
+   if (_libsaproc_debug) {
+     va_list alist;
+
+     va_start(alist, format);
+     fputs("libsaproc DEBUG: ", stderr);
+     vfprintf(stderr, format, alist);
+     va_end(alist);
+   }
+}
+
+bool is_debug() {
+   return _libsaproc_debug;
+}
+
+// initialize libproc
+bool init_libproc(bool debug) {
+   // init debug mode
+   _libsaproc_debug = debug;
+
+   // initialize the thread_db library
+   if (td_init() != TD_OK) {
+     print_debug("libthread_db's td_init failed\n");
+     return false;
+   }
+
+   return true;
+}
+
+static void destroy_lib_info(struct ps_prochandle* ph) {
+   lib_info* lib = ph->libs;
+   while (lib) {
+     lib_info *next = lib->next;
+     if (lib->symtab) {
+        destroy_symtab(lib->symtab);
+     }
+     free(lib);
+     lib = next;
+   }
+}
+
+static void destroy_thread_info(struct ps_prochandle* ph) {
+   thread_info* thr = ph->threads;
+   while (thr) {
+     thread_info *next = thr->next;
+     free(thr);
+     thr = next;
+   }
+}
+
+// ps_prochandle cleanup
+
+// ps_prochandle cleanup
+void Prelease(struct ps_prochandle* ph) {
+   // do the "derived class" clean-up first
+   ph->ops->release(ph);
+   destroy_lib_info(ph);
+   destroy_thread_info(ph);
+   free(ph);
+}
+
+lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base) {
+   return add_lib_info_fd(ph, libname, -1, base);
+}
+
+lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
+   lib_info* newlib;
+
+   if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
+      print_debug("can't allocate memory for lib_info\n");
+      return NULL;
+   }
+
+   strncpy(newlib->name, libname, sizeof(newlib->name));
+   newlib->base = base;
+
+   if (fd == -1) {
+      if ( (newlib->fd = pathmap_open(newlib->name)) < 0) {
+         print_debug("can't open shared object %s\n", newlib->name);
+         free(newlib);
+         return NULL;
+      }
+   } else {
+      newlib->fd = fd;
+   }
+
+   // check whether we have got an ELF file. /proc/<pid>/map
+   // gives out all file mappings and not just shared objects
+   if (is_elf_file(newlib->fd) == false) {
+      close(newlib->fd);
+      free(newlib);
+      return NULL;
+   }
+
+   newlib->symtab = build_symtab(newlib->fd);
+   if (newlib->symtab == NULL) {
+      print_debug("symbol table build failed for %s\n", newlib->name);
+   }
+   else {
+      print_debug("built symbol table for %s\n", newlib->name);
+   }
+
+   // even if symbol table building fails, we add the lib_info.
+   // This is because we may need to read from the ELF file for core file
+   // address read functionality. lookup_symbol checks for NULL symtab.
+   if (ph->libs) {
+      ph->lib_tail->next = newlib;
+      ph->lib_tail = newlib;
+   }  else {
+      ph->libs = ph->lib_tail = newlib;
+   }
+   ph->num_libs++;
+
+   return newlib;
+}
+
+// lookup for a specific symbol
+uintptr_t lookup_symbol(struct ps_prochandle* ph,  const char* object_name,
+                       const char* sym_name) {
+   // ignore object_name. search in all libraries
+   // FIXME: what should we do with object_name?? The library names are obtained
+   // by parsing /proc/<pid>/maps, which may not be the same as object_name.
+   // What we need is a utility to map object_name to real file name, something
+   // dlopen() does by looking at LD_LIBRARY_PATH and /etc/ld.so.cache. For
+   // now, we just ignore object_name and do a global search for the symbol.
+
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (lib->symtab) {
+         uintptr_t res = search_symbol(lib->symtab, lib->base, sym_name, NULL);
+         if (res) return res;
+      }
+      lib = lib->next;
+   }
+
+   print_debug("lookup failed for symbol '%s' in obj '%s'\n",
+                          sym_name, object_name);
+   return (uintptr_t) NULL;
+}
+
+
+const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset) {
+   const char* res = NULL;
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (lib->symtab && addr >= lib->base) {
+         res = nearest_symbol(lib->symtab, addr - lib->base, poffset);
+         if (res) return res;
+      }
+      lib = lib->next;
+   }
+   return NULL;
+}
+
+// add a thread to ps_prochandle
+thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
+   thread_info* newthr;
+   if ( (newthr = (thread_info*) calloc(1, sizeof(thread_info))) == NULL) {
+      print_debug("can't allocate memory for thread_info\n");
+      return NULL;
+   }
+
+   // initialize thread info
+   newthr->pthread_id = pthread_id;
+   newthr->lwp_id = lwp_id;
+
+   // add new thread to the list
+   newthr->next = ph->threads;
+   ph->threads = newthr;
+   ph->num_threads++;
+   return newthr;
+}
+
+
+// struct used for client data from thread_db callback
+struct thread_db_client_data {
+   struct ps_prochandle* ph;
+   thread_info_callback callback;
+};
+
+// callback function for libthread_db
+static int thread_db_callback(const td_thrhandle_t *th_p, void *data) {
+  struct thread_db_client_data* ptr = (struct thread_db_client_data*) data;
+  td_thrinfo_t ti;
+  td_err_e err;
+
+  memset(&ti, 0, sizeof(ti));
+  err = td_thr_get_info(th_p, &ti);
+  if (err != TD_OK) {
+    print_debug("libthread_db : td_thr_get_info failed, can't get thread info\n");
+    return err;
+  }
+
+  print_debug("thread_db : pthread %d (lwp %d)\n", ti.ti_tid, ti.ti_lid);
+
+  if (ptr->callback(ptr->ph, (pthread_t)ti.ti_tid, ti.ti_lid) != true)
+    return TD_ERR;
+
+  return TD_OK;
+}
+
+// read thread_info using libthread_db
+bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb) {
+  struct thread_db_client_data mydata;
+  td_thragent_t* thread_agent = NULL;
+  if (td_ta_new(ph, &thread_agent) != TD_OK) {
+     print_debug("can't create libthread_db agent\n");
+     return false;
+  }
+
+  mydata.ph = ph;
+  mydata.callback = cb;
+
+  // we use libthread_db iterator to iterate thru list of threads.
+  if (td_ta_thr_iter(thread_agent, thread_db_callback, &mydata,
+                 TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY,
+                 TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS) != TD_OK) {
+     td_ta_delete(thread_agent);
+     return false;
+  }
+
+  // delete thread agent
+  td_ta_delete(thread_agent);
+  return true;
+}
+
+
+// get number of threads
+int get_num_threads(struct ps_prochandle* ph) {
+   return ph->num_threads;
+}
+
+// get lwp_id of n'th thread
+lwpid_t get_lwp_id(struct ps_prochandle* ph, int index) {
+   int count = 0;
+   thread_info* thr = ph->threads;
+   while (thr) {
+      if (count == index) {
+         return thr->lwp_id;
+      }
+      count++;
+      thr = thr->next;
+   }
+   return -1;
+}
+
+// get regs for a given lwp
+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs) {
+  return ph->ops->get_lwp_regs(ph, lwp_id, regs);
+}
+
+// get number of shared objects
+int get_num_libs(struct ps_prochandle* ph) {
+   return ph->num_libs;
+}
+
+// get name of n'th solib
+const char* get_lib_name(struct ps_prochandle* ph, int index) {
+   int count = 0;
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (count == index) {
+         return lib->name;
+      }
+      count++;
+      lib = lib->next;
+   }
+   return NULL;
+}
+
+// get base address of a lib
+uintptr_t get_lib_base(struct ps_prochandle* ph, int index) {
+   int count = 0;
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (count == index) {
+         return lib->base;
+      }
+      count++;
+      lib = lib->next;
+   }
+   return (uintptr_t)NULL;
+}
+
+bool find_lib(struct ps_prochandle* ph, const char *lib_name) {
+  lib_info *p = ph->libs;
+  while (p) {
+    if (strcmp(p->name, lib_name) == 0) {
+      return true;
+    }
+    p = p->next;
+  }
+  return false;
+}
+
+//--------------------------------------------------------------------------
+// proc service functions
+
+// ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
+// of the load object object_name in the target process identified by ph.
+// It returns the symbol's value as an address in the target process in
+// *sym_addr.
+
+ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
+                    const char *sym_name, psaddr_t *sym_addr) {
+  *sym_addr = (psaddr_t) lookup_symbol(ph, object_name, sym_name);
+  return (*sym_addr ? PS_OK : PS_NOSYM);
+}
+
+// read "size" bytes info "buf" from address "addr"
+ps_err_e ps_pread(struct ps_prochandle *ph, psaddr_t  addr,
+                  void *buf, size_t size) {
+  return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
+}
+
+// write "size" bytes of data to debuggee at address "addr"
+ps_err_e ps_pwrite(struct ps_prochandle *ph, psaddr_t addr,
+                   const void *buf, size_t size) {
+  return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
+}
+
+// fill in ptrace_lwpinfo for lid
+ps_err_e ps_linfo(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+  return ph->ops->get_lwp_info(ph, lwp_id, linfo)? PS_OK: PS_ERR;
+}
+
+// needed for when libthread_db is compiled with TD_DEBUG defined
+void
+ps_plog (const char *format, ...)
+{
+  va_list alist;
+
+  va_start(alist, format);
+  vfprintf(stderr, format, alist);
+  va_end(alist);
+}
+
+// ------------------------------------------------------------------------
+// Functions below this point are not yet implemented. They are here only
+// to make the linker happy.
+
+ps_err_e ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lid, const prfpregset_t *fpregs) {
+  print_debug("ps_lsetfpregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_lsetregs(struct ps_prochandle *ph, lwpid_t lid, const prgregset_t gregset) {
+  print_debug("ps_lsetregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e  ps_lgetfpregs(struct  ps_prochandle  *ph,  lwpid_t lid, prfpregset_t *fpregs) {
+  print_debug("ps_lgetfpregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t lid, prgregset_t gregset) {
+  print_debug("ps_lgetfpregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_lstop(struct ps_prochandle *ph, lwpid_t lid) {
+  print_debug("ps_lstop not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_pcontinue(struct ps_prochandle *ph) {
+  print_debug("ps_pcontinue not implemented\n");
+  return PS_OK;
+}
diff --git a/hotspot/agent/src/os/bsd/libproc_impl.h b/hotspot/agent/src/os/bsd/libproc_impl.h
new file mode 100644
index 0000000..8b9d233
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/libproc_impl.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef _LIBPROC_IMPL_H_
+#define _LIBPROC_IMPL_H_
+
+#include <unistd.h>
+#include <limits.h>
+#include "libproc.h"
+#include "symtab.h"
+
+// data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
+
+#define BUF_SIZE     (PATH_MAX + NAME_MAX + 1)
+
+// list of shared objects
+typedef struct lib_info {
+  char             name[BUF_SIZE];
+  uintptr_t        base;
+  struct symtab*   symtab;
+  int              fd;        // file descriptor for lib
+  struct lib_info* next;
+} lib_info;
+
+// list of threads
+typedef struct thread_info {
+   lwpid_t                  lwp_id;
+   pthread_t                pthread_id; // not used cores, always -1
+   struct reg               regs;       // not for process, core uses for caching regset
+   struct thread_info*      next;
+} thread_info;
+
+// list of virtual memory maps
+typedef struct map_info {
+   int              fd;       // file descriptor
+   off_t            offset;   // file offset of this mapping
+   uintptr_t        vaddr;    // starting virtual address
+   size_t           memsz;    // size of the mapping
+   struct map_info* next;
+} map_info;
+
+// vtable for ps_prochandle
+typedef struct ps_prochandle_ops {
+   // "derived class" clean-up
+   void (*release)(struct ps_prochandle* ph);
+   // read from debuggee
+   bool (*p_pread)(struct ps_prochandle *ph,
+            uintptr_t addr, char *buf, size_t size);
+   // write into debuggee
+   bool (*p_pwrite)(struct ps_prochandle *ph,
+            uintptr_t addr, const char *buf , size_t size);
+   // get integer regset of a thread
+   bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs);
+   // get info on thread
+   bool (*get_lwp_info)(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo);
+} ps_prochandle_ops;
+
+// the ps_prochandle
+
+struct core_data {
+   int                core_fd;   // file descriptor of core file
+   int                exec_fd;   // file descriptor of exec file
+   int                interp_fd; // file descriptor of interpreter (ld-elf.so.1)
+   // part of the class sharing workaround
+   int                classes_jsa_fd; // file descriptor of class share archive
+   uintptr_t          dynamic_addr;  // address of dynamic section of a.out
+   uintptr_t          ld_base_addr;  // base address of ld.so
+   size_t             num_maps;  // number of maps.
+   map_info*          maps;      // maps in a linked list
+   // part of the class sharing workaround
+   map_info*          class_share_maps;// class share maps in a linked list
+   map_info**         map_array; // sorted (by vaddr) array of map_info pointers
+};
+
+struct ps_prochandle {
+   ps_prochandle_ops* ops;       // vtable ptr
+   pid_t              pid;
+   int                num_libs;
+   lib_info*          libs;      // head of lib list
+   lib_info*          lib_tail;  // tail of lib list - to append at the end
+   int                num_threads;
+   thread_info*       threads;   // head of thread list
+   struct core_data*  core;      // data only used for core dumps, NULL for process
+};
+
+int pathmap_open(const char* name);
+
+void print_debug(const char* format,...);
+bool is_debug();
+
+typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
+
+// reads thread info using libthread_db and calls above callback for each thread
+bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);
+
+// adds a new shared object to lib list, returns NULL on failure
+lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
+
+// adds a new shared object to lib list, supply open lib file descriptor as well
+lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
+                          uintptr_t base);
+
+// adds a new thread to threads list, returns NULL on failure
+thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
+
+// a test for ELF signature without using libelf
+bool is_elf_file(int fd);
+
+#endif //_LIBPROC_IMPL_H_
diff --git a/hotspot/agent/src/os/bsd/mapfile b/hotspot/agent/src/os/bsd/mapfile
new file mode 100644
index 0000000..36b4334
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/mapfile
@@ -0,0 +1,66 @@
+#
+
+#
+# Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Define public interface.
+
+SUNWprivate_1.1 {
+        global:
+
+		# native methods of BsdDebuggerLocal class
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0;
+	
+		# proc_service.h functions - to be used by libthread_db
+		ps_getpid;
+		ps_pglobal_lookup;
+		ps_pread;
+		ps_pwrite;
+		ps_lsetfpregs;
+		ps_lsetregs;
+		ps_lgetfpregs;
+		ps_lgetregs;
+		ps_lcontinue;
+		ps_lgetxmmregs;
+		ps_lsetxmmregs;
+		ps_lstop;
+		ps_linfo;
+
+                # used by attach test program
+                init_libproc;
+                Pgrab;
+                Pgrab_core;
+                Prelease;
+	
+	local:
+		*;
+};
diff --git a/hotspot/agent/src/os/bsd/ps_core.c b/hotspot/agent/src/os/bsd/ps_core.c
new file mode 100644
index 0000000..4e2049b
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/ps_core.c
@@ -0,0 +1,1023 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <jni.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <elf.h>
+#include <link.h>
+#include "libproc_impl.h"
+#include "salibelf.h"
+
+// This file has the libproc implementation to read core files.
+// For live processes, refer to ps_proc.c. Portions of this is adapted
+// /modelled after Solaris libproc.so (in particular Pcore.c)
+
+//----------------------------------------------------------------------
+// ps_prochandle cleanup helper functions
+
+// close all file descriptors
+static void close_elf_files(struct ps_prochandle* ph) {
+   lib_info* lib = NULL;
+
+   // close core file descriptor
+   if (ph->core->core_fd >= 0)
+     close(ph->core->core_fd);
+
+   // close exec file descriptor
+   if (ph->core->exec_fd >= 0)
+     close(ph->core->exec_fd);
+
+   // close interp file descriptor
+   if (ph->core->interp_fd >= 0)
+     close(ph->core->interp_fd);
+
+   // close class share archive file
+   if (ph->core->classes_jsa_fd >= 0)
+     close(ph->core->classes_jsa_fd);
+
+   // close all library file descriptors
+   lib = ph->libs;
+   while (lib) {
+      int fd = lib->fd;
+      if (fd >= 0 && fd != ph->core->exec_fd) close(fd);
+      lib = lib->next;
+   }
+}
+
+// clean all map_info stuff
+static void destroy_map_info(struct ps_prochandle* ph) {
+  map_info* map = ph->core->maps;
+  while (map) {
+     map_info* next = map->next;
+     free(map);
+     map = next;
+  }
+
+  if (ph->core->map_array) {
+     free(ph->core->map_array);
+  }
+
+  // Part of the class sharing workaround
+  map = ph->core->class_share_maps;
+  while (map) {
+     map_info* next = map->next;
+     free(map);
+     map = next;
+  }
+}
+
+// ps_prochandle operations
+static void core_release(struct ps_prochandle* ph) {
+   if (ph->core) {
+      close_elf_files(ph);
+      destroy_map_info(ph);
+      free(ph->core);
+   }
+}
+
+static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t memsz) {
+   map_info* map;
+   if ( (map = (map_info*) calloc(1, sizeof(map_info))) == NULL) {
+      print_debug("can't allocate memory for map_info\n");
+      return NULL;
+   }
+
+   // initialize map
+   map->fd     = fd;
+   map->offset = offset;
+   map->vaddr  = vaddr;
+   map->memsz  = memsz;
+   return map;
+}
+
+// add map info with given fd, offset, vaddr and memsz
+static map_info* add_map_info(struct ps_prochandle* ph, int fd, off_t offset,
+                             uintptr_t vaddr, size_t memsz) {
+   map_info* map;
+   if ((map = allocate_init_map(fd, offset, vaddr, memsz)) == NULL) {
+      return NULL;
+   }
+
+   // add this to map list
+   map->next  = ph->core->maps;
+   ph->core->maps   = map;
+   ph->core->num_maps++;
+
+   return map;
+}
+
+// Part of the class sharing workaround
+static map_info* add_class_share_map_info(struct ps_prochandle* ph, off_t offset,
+                             uintptr_t vaddr, size_t memsz) {
+   map_info* map;
+   if ((map = allocate_init_map(ph->core->classes_jsa_fd,
+                                offset, vaddr, memsz)) == NULL) {
+      return NULL;
+   }
+
+   map->next = ph->core->class_share_maps;
+   ph->core->class_share_maps = map;
+   return map;
+}
+
+// Return the map_info for the given virtual address.  We keep a sorted
+// array of pointers in ph->map_array, so we can binary search.
+static map_info* core_lookup(struct ps_prochandle *ph, uintptr_t addr)
+{
+   int mid, lo = 0, hi = ph->core->num_maps - 1;
+   map_info *mp;
+
+   while (hi - lo > 1) {
+     mid = (lo + hi) / 2;
+      if (addr >= ph->core->map_array[mid]->vaddr)
+         lo = mid;
+      else
+         hi = mid;
+   }
+
+   if (addr < ph->core->map_array[hi]->vaddr)
+      mp = ph->core->map_array[lo];
+   else
+      mp = ph->core->map_array[hi];
+
+   if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz)
+      return (mp);
+
+
+   // Part of the class sharing workaround
+   // Unfortunately, we have no way of detecting -Xshare state.
+   // Check out the share maps atlast, if we don't find anywhere.
+   // This is done this way so to avoid reading share pages
+   // ahead of other normal maps. For eg. with -Xshare:off we don't
+   // want to prefer class sharing data to data from core.
+   mp = ph->core->class_share_maps;
+   if (mp) {
+      print_debug("can't locate map_info at 0x%lx, trying class share maps\n",
+             addr);
+   }
+   while (mp) {
+      if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz) {
+         print_debug("located map_info at 0x%lx from class share maps\n",
+                  addr);
+         return (mp);
+      }
+      mp = mp->next;
+   }
+
+   print_debug("can't locate map_info at 0x%lx\n", addr);
+   return (NULL);
+}
+
+//---------------------------------------------------------------
+// Part of the class sharing workaround:
+//
+// With class sharing, pages are mapped from classes[_g].jsa file.
+// The read-only class sharing pages are mapped as MAP_SHARED,
+// PROT_READ pages. These pages are not dumped into core dump.
+// With this workaround, these pages are read from classes[_g].jsa.
+
+// FIXME: !HACK ALERT!
+// The format of sharing achive file header is needed to read shared heap
+// file mappings. For now, I am hard coding portion of FileMapHeader here.
+// Refer to filemap.hpp.
+
+// FileMapHeader describes the shared space data in the file to be
+// mapped.  This structure gets written to a file.  It is not a class,
+// so that the compilers don't add any compiler-private data to it.
+
+// Refer to CompactingPermGenGen::n_regions in compactingPermGenGen.hpp
+#define NUM_SHARED_MAPS 4
+
+// Refer to FileMapInfo::_current_version in filemap.hpp
+#define CURRENT_ARCHIVE_VERSION 1
+
+struct FileMapHeader {
+  int   _magic;              // identify file type.
+  int   _version;            // (from enum, above.)
+  size_t _alignment;         // how shared archive should be aligned
+
+  struct space_info {
+    int    _file_offset;     // sizeof(this) rounded to vm page size
+    char*  _base;            // copy-on-write base address
+    size_t _capacity;        // for validity checking
+    size_t _used;            // for setting space top on read
+
+    // 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with
+    // the C type matching the C++ bool type on any given platform. For
+    // Hotspot on BSD we assume the corresponding C type is char but
+    // licensees on BSD versions may need to adjust the type of these fields.
+    char   _read_only;       // read only space?
+    char   _allow_exec;      // executable code in space?
+
+  } _space[NUM_SHARED_MAPS]; // was _space[CompactingPermGenGen::n_regions];
+
+  // Ignore the rest of the FileMapHeader. We don't need those fields here.
+};
+
+static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) {
+   jboolean i;
+   if (ps_pread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
+      *pvalue = i;
+      return true;
+   } else {
+      return false;
+   }
+}
+
+static bool read_pointer(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* pvalue) {
+   uintptr_t uip;
+   if (ps_pread(ph, (psaddr_t) addr, &uip, sizeof(uip)) == PS_OK) {
+      *pvalue = uip;
+      return true;
+   } else {
+      return false;
+   }
+}
+
+// used to read strings from debuggee
+static bool read_string(struct ps_prochandle* ph, uintptr_t addr, char* buf, size_t size) {
+   size_t i = 0;
+   char  c = ' ';
+
+   while (c != '\0') {
+     if (ps_pread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK)
+         return false;
+      if (i < size - 1)
+         buf[i] = c;
+      else // smaller buffer
+         return false;
+      i++; addr++;
+   }
+
+   buf[i] = '\0';
+   return true;
+}
+
+#define USE_SHARED_SPACES_SYM "UseSharedSpaces"
+// mangled name of Arguments::SharedArchivePath
+#define SHARED_ARCHIVE_PATH_SYM "_ZN9Arguments17SharedArchivePathE"
+
+static bool init_classsharing_workaround(struct ps_prochandle* ph) {
+   lib_info* lib = ph->libs;
+   while (lib != NULL) {
+      // we are iterating over shared objects from the core dump. look for
+      // libjvm[_g].so.
+      const char *jvm_name = 0;
+      if ((jvm_name = strstr(lib->name, "/libjvm.so")) != 0 ||
+          (jvm_name = strstr(lib->name, "/libjvm_g.so")) != 0) {
+         char classes_jsa[PATH_MAX];
+         struct FileMapHeader header;
+         size_t n = 0;
+         int fd = -1, m = 0;
+         uintptr_t base = 0, useSharedSpacesAddr = 0;
+         uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0;
+         jboolean useSharedSpaces = 0;
+
+         memset(classes_jsa, 0, sizeof(classes_jsa));
+         jvm_name = lib->name;
+         useSharedSpacesAddr = lookup_symbol(ph, jvm_name, USE_SHARED_SPACES_SYM);
+         if (useSharedSpacesAddr == 0) {
+            print_debug("can't lookup 'UseSharedSpaces' flag\n");
+            return false;
+         }
+
+         // Hotspot vm types are not exported to build this library. So
+         // using equivalent type jboolean to read the value of
+         // UseSharedSpaces which is same as hotspot type "bool".
+         if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) {
+            print_debug("can't read the value of 'UseSharedSpaces' flag\n");
+            return false;
+         }
+
+         if ((int)useSharedSpaces == 0) {
+            print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n");
+            return true;
+         }
+
+         sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM);
+         if (sharedArchivePathAddrAddr == 0) {
+            print_debug("can't lookup shared archive path symbol\n");
+            return false;
+         }
+
+         if (read_pointer(ph, sharedArchivePathAddrAddr, &sharedArchivePathAddr) != true) {
+            print_debug("can't read shared archive path pointer\n");
+            return false;
+         }
+
+         if (read_string(ph, sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
+            print_debug("can't read shared archive path value\n");
+            return false;
+         }
+
+         print_debug("looking for %s\n", classes_jsa);
+         // open the class sharing archive file
+         fd = pathmap_open(classes_jsa);
+         if (fd < 0) {
+            print_debug("can't open %s!\n", classes_jsa);
+            ph->core->classes_jsa_fd = -1;
+            return false;
+         } else {
+            print_debug("opened %s\n", classes_jsa);
+         }
+
+         // read FileMapHeader from the file
+         memset(&header, 0, sizeof(struct FileMapHeader));
+         if ((n = read(fd, &header, sizeof(struct FileMapHeader)))
+              != sizeof(struct FileMapHeader)) {
+            print_debug("can't read shared archive file map header from %s\n", classes_jsa);
+            close(fd);
+            return false;
+         }
+
+         // check file magic
+         if (header._magic != 0xf00baba2) {
+            print_debug("%s has bad shared archive file magic number 0x%x, expecing 0xf00baba2\n",
+                        classes_jsa, header._magic);
+            close(fd);
+            return false;
+         }
+
+         // check version
+         if (header._version != CURRENT_ARCHIVE_VERSION) {
+            print_debug("%s has wrong shared archive file version %d, expecting %d\n",
+                        classes_jsa, header._version, CURRENT_ARCHIVE_VERSION);
+            close(fd);
+            return false;
+         }
+
+         ph->core->classes_jsa_fd = fd;
+         // add read-only maps from classes[_g].jsa to the list of maps
+         for (m = 0; m < NUM_SHARED_MAPS; m++) {
+            if (header._space[m]._read_only) {
+               base = (uintptr_t) header._space[m]._base;
+               // no need to worry about the fractional pages at-the-end.
+               // possible fractional pages are handled by core_read_data.
+               add_class_share_map_info(ph, (off_t) header._space[m]._file_offset,
+                         base, (size_t) header._space[m]._used);
+               print_debug("added a share archive map at 0x%lx\n", base);
+            }
+         }
+         return true;
+      }
+      lib = lib->next;
+   }
+   return true;
+}
+
+
+//---------------------------------------------------------------------------
+// functions to handle map_info
+
+// Order mappings based on virtual address.  We use this function as the
+// callback for sorting the array of map_info pointers.
+static int core_cmp_mapping(const void *lhsp, const void *rhsp)
+{
+   const map_info *lhs = *((const map_info **)lhsp);
+   const map_info *rhs = *((const map_info **)rhsp);
+
+   if (lhs->vaddr == rhs->vaddr)
+      return (0);
+
+   return (lhs->vaddr < rhs->vaddr ? -1 : 1);
+}
+
+// we sort map_info by starting virtual address so that we can do
+// binary search to read from an address.
+static bool sort_map_array(struct ps_prochandle* ph) {
+   size_t num_maps = ph->core->num_maps;
+   map_info* map = ph->core->maps;
+   int i = 0;
+
+   // allocate map_array
+   map_info** array;
+   if ( (array = (map_info**) malloc(sizeof(map_info*) * num_maps)) == NULL) {
+      print_debug("can't allocate memory for map array\n");
+      return false;
+   }
+
+   // add maps to array
+   while (map) {
+      array[i] = map;
+      i++;
+      map = map->next;
+   }
+
+   // sort is called twice. If this is second time, clear map array
+   if (ph->core->map_array) free(ph->core->map_array);
+   ph->core->map_array = array;
+   // sort the map_info array by base virtual address.
+   qsort(ph->core->map_array, ph->core->num_maps, sizeof (map_info*),
+            core_cmp_mapping);
+
+   // print map
+   if (is_debug()) {
+      int j = 0;
+      print_debug("---- sorted virtual address map ----\n");
+      for (j = 0; j < ph->core->num_maps; j++) {
+        print_debug("base = 0x%lx\tsize = %d\n", ph->core->map_array[j]->vaddr,
+                                         ph->core->map_array[j]->memsz);
+      }
+   }
+
+   return true;
+}
+
+#ifndef MIN
+#define MIN(x, y) (((x) < (y))? (x): (y))
+#endif
+
+static bool core_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) {
+   ssize_t resid = size;
+   int page_size=sysconf(_SC_PAGE_SIZE);
+   while (resid != 0) {
+      map_info *mp = core_lookup(ph, addr);
+      uintptr_t mapoff;
+      ssize_t len, rem;
+      off_t off;
+      int fd;
+
+      if (mp == NULL)
+         break;  /* No mapping for this address */
+
+      fd = mp->fd;
+      mapoff = addr - mp->vaddr;
+      len = MIN(resid, mp->memsz - mapoff);
+      off = mp->offset + mapoff;
+
+      if ((len = pread(fd, buf, len, off)) <= 0)
+         break;
+
+      resid -= len;
+      addr += len;
+      buf = (char *)buf + len;
+
+      // mappings always start at page boundary. But, may end in fractional
+      // page. fill zeros for possible fractional page at the end of a mapping.
+      rem = mp->memsz % page_size;
+      if (rem > 0) {
+         rem = page_size - rem;
+         len = MIN(resid, rem);
+         resid -= len;
+         addr += len;
+         // we are not assuming 'buf' to be zero initialized.
+         memset(buf, 0, len);
+         buf += len;
+      }
+   }
+
+   if (resid) {
+      print_debug("core read failed for %d byte(s) @ 0x%lx (%d more bytes)\n",
+              size, addr, resid);
+      return false;
+   } else {
+      return true;
+   }
+}
+
+// null implementation for write
+static bool core_write_data(struct ps_prochandle* ph,
+                             uintptr_t addr, const char *buf , size_t size) {
+   return false;
+}
+
+static bool core_get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id,
+                          struct reg* regs) {
+   // for core we have cached the lwp regs from NOTE section
+   thread_info* thr = ph->threads;
+   while (thr) {
+     if (thr->lwp_id == lwp_id) {
+       memcpy(regs, &thr->regs, sizeof(struct reg));
+       return true;
+     }
+     thr = thr->next;
+   }
+   return false;
+}
+
+static bool core_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+   print_debug("core_get_lwp_info not implemented\n");
+   return false;
+}
+
+static ps_prochandle_ops core_ops = {
+   .release=  core_release,
+   .p_pread=  core_read_data,
+   .p_pwrite= core_write_data,
+   .get_lwp_regs= core_get_lwp_regs,
+   .get_lwp_info= core_get_lwp_info
+};
+
+// read regs and create thread from NT_PRSTATUS entries from core file
+static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size_t nbytes) {
+   // we have to read prstatus_t from buf
+   // assert(nbytes == sizeof(prstaus_t), "size mismatch on prstatus_t");
+   prstatus_t* prstat = (prstatus_t*) buf;
+   thread_info* newthr;
+   print_debug("got integer regset for lwp %d\n", prstat->pr_pid);
+   // we set pthread_t to -1 for core dump
+   if((newthr = add_thread_info(ph, (pthread_t) -1,  prstat->pr_pid)) == NULL)
+      return false;
+
+   // copy regs
+   memcpy(&newthr->regs, &prstat->pr_reg, sizeof(struct reg));
+
+   if (is_debug()) {
+      print_debug("integer regset\n");
+#ifdef i386
+      // print the regset
+      print_debug("\teax = 0x%x\n", newthr->regs.r_eax);
+      print_debug("\tebx = 0x%x\n", newthr->regs.r_ebx);
+      print_debug("\tecx = 0x%x\n", newthr->regs.r_ecx);
+      print_debug("\tedx = 0x%x\n", newthr->regs.r_edx);
+      print_debug("\tesp = 0x%x\n", newthr->regs.r_esp);
+      print_debug("\tebp = 0x%x\n", newthr->regs.r_ebp);
+      print_debug("\tesi = 0x%x\n", newthr->regs.r_esi);
+      print_debug("\tedi = 0x%x\n", newthr->regs.r_edi);
+      print_debug("\teip = 0x%x\n", newthr->regs.r_eip);
+#endif
+
+#if defined(amd64) || defined(x86_64)
+      // print the regset
+      print_debug("\tr15 = 0x%lx\n", newthr->regs.r_r15);
+      print_debug("\tr14 = 0x%lx\n", newthr->regs.r_r14);
+      print_debug("\tr13 = 0x%lx\n", newthr->regs.r_r13);
+      print_debug("\tr12 = 0x%lx\n", newthr->regs.r_r12);
+      print_debug("\trbp = 0x%lx\n", newthr->regs.r_rbp);
+      print_debug("\trbx = 0x%lx\n", newthr->regs.r_rbx);
+      print_debug("\tr11 = 0x%lx\n", newthr->regs.r_r11);
+      print_debug("\tr10 = 0x%lx\n", newthr->regs.r_r10);
+      print_debug("\tr9 = 0x%lx\n", newthr->regs.r_r9);
+      print_debug("\tr8 = 0x%lx\n", newthr->regs.r_r8);
+      print_debug("\trax = 0x%lx\n", newthr->regs.r_rax);
+      print_debug("\trcx = 0x%lx\n", newthr->regs.r_rcx);
+      print_debug("\trdx = 0x%lx\n", newthr->regs.r_rdx);
+      print_debug("\trsi = 0x%lx\n", newthr->regs.r_rsi);
+      print_debug("\trdi = 0x%lx\n", newthr->regs.r_rdi);
+      //print_debug("\torig_rax = 0x%lx\n", newthr->regs.orig_rax);
+      print_debug("\trip = 0x%lx\n", newthr->regs.r_rip);
+      print_debug("\tcs = 0x%lx\n", newthr->regs.r_cs);
+      //print_debug("\teflags = 0x%lx\n", newthr->regs.eflags);
+      print_debug("\trsp = 0x%lx\n", newthr->regs.r_rsp);
+      print_debug("\tss = 0x%lx\n", newthr->regs.r_ss);
+      //print_debug("\tfs_base = 0x%lx\n", newthr->regs.fs_base);
+      //print_debug("\tgs_base = 0x%lx\n", newthr->regs.gs_base);
+      //print_debug("\tds = 0x%lx\n", newthr->regs.ds);
+      //print_debug("\tes = 0x%lx\n", newthr->regs.es);
+      //print_debug("\tfs = 0x%lx\n", newthr->regs.fs);
+      //print_debug("\tgs = 0x%lx\n", newthr->regs.gs);
+#endif
+   }
+
+   return true;
+}
+
+#define ROUNDUP(x, y)  ((((x)+((y)-1))/(y))*(y))
+
+// read NT_PRSTATUS entries from core NOTE segment
+static bool core_handle_note(struct ps_prochandle* ph, ELF_PHDR* note_phdr) {
+   char* buf = NULL;
+   char* p = NULL;
+   size_t size = note_phdr->p_filesz;
+
+   // we are interested in just prstatus entries. we will ignore the rest.
+   // Advance the seek pointer to the start of the PT_NOTE data
+   if (lseek(ph->core->core_fd, note_phdr->p_offset, SEEK_SET) == (off_t)-1) {
+      print_debug("failed to lseek to PT_NOTE data\n");
+      return false;
+   }
+
+   // Now process the PT_NOTE structures.  Each one is preceded by
+   // an Elf{32/64}_Nhdr structure describing its type and size.
+   if ( (buf = (char*) malloc(size)) == NULL) {
+      print_debug("can't allocate memory for reading core notes\n");
+      goto err;
+   }
+
+   // read notes into buffer
+   if (read(ph->core->core_fd, buf, size) != size) {
+      print_debug("failed to read notes, core file must have been truncated\n");
+      goto err;
+   }
+
+   p = buf;
+   while (p < buf + size) {
+      ELF_NHDR* notep = (ELF_NHDR*) p;
+      char* descdata  = p + sizeof(ELF_NHDR) + ROUNDUP(notep->n_namesz, 4);
+      print_debug("Note header with n_type = %d and n_descsz = %u\n",
+                                   notep->n_type, notep->n_descsz);
+
+      if (notep->n_type == NT_PRSTATUS) {
+         if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true)
+            return false;
+      }
+      p = descdata + ROUNDUP(notep->n_descsz, 4);
+   }
+
+   free(buf);
+   return true;
+
+err:
+   if (buf) free(buf);
+   return false;
+}
+
+// read all segments from core file
+static bool read_core_segments(struct ps_prochandle* ph, ELF_EHDR* core_ehdr) {
+   int i = 0;
+   ELF_PHDR* phbuf = NULL;
+   ELF_PHDR* core_php = NULL;
+
+   if ((phbuf =  read_program_header_table(ph->core->core_fd, core_ehdr)) == NULL)
+      return false;
+
+   /*
+    * Now iterate through the program headers in the core file.
+    * We're interested in two types of Phdrs: PT_NOTE (which
+    * contains a set of saved /proc structures), and PT_LOAD (which
+    * represents a memory mapping from the process's address space).
+    *
+    * Difference b/w Solaris PT_NOTE and BSD PT_NOTE:
+    *
+    *     In Solaris there are two PT_NOTE segments the first PT_NOTE (if present)
+    *     contains /proc structs in the pre-2.6 unstructured /proc format. the last
+    *     PT_NOTE has data in new /proc format.
+    *
+    *     In Solaris, there is only one pstatus (process status). pstatus contains
+    *     integer register set among other stuff. For each LWP, we have one lwpstatus
+    *     entry that has integer regset for that LWP.
+    *
+    *     Linux threads are actually 'clone'd processes. To support core analysis
+    *     of "multithreaded" process, Linux creates more than one pstatus (called
+    *     "prstatus") entry in PT_NOTE. Each prstatus entry has integer regset for one
+    *     "thread". Please refer to Linux kernel src file 'fs/binfmt_elf.c', in particular
+    *     function "elf_core_dump".
+    */
+
+    for (core_php = phbuf, i = 0; i < core_ehdr->e_phnum; i++) {
+      switch (core_php->p_type) {
+         case PT_NOTE:
+            if (core_handle_note(ph, core_php) != true) goto err;
+            break;
+
+         case PT_LOAD: {
+            if (core_php->p_filesz != 0) {
+               if (add_map_info(ph, ph->core->core_fd, core_php->p_offset,
+                  core_php->p_vaddr, core_php->p_filesz) == NULL) goto err;
+            }
+            break;
+         }
+      }
+
+      core_php++;
+   }
+
+   free(phbuf);
+   return true;
+err:
+   free(phbuf);
+   return false;
+}
+
+// read segments of a shared object
+static bool read_lib_segments(struct ps_prochandle* ph, int lib_fd, ELF_EHDR* lib_ehdr, uintptr_t lib_base) {
+   int i = 0;
+   ELF_PHDR* phbuf;
+   ELF_PHDR* lib_php = NULL;
+
+   if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL)
+      return false;
+
+   // we want to process only PT_LOAD segments that are not writable.
+   // i.e., text segments. The read/write/exec (data) segments would
+   // have been already added from core file segments.
+   for (lib_php = phbuf, i = 0; i < lib_ehdr->e_phnum; i++) {
+      if ((lib_php->p_type == PT_LOAD) && !(lib_php->p_flags & PF_W) && (lib_php->p_filesz != 0)) {
+         if (add_map_info(ph, lib_fd, lib_php->p_offset, lib_php->p_vaddr + lib_base, lib_php->p_filesz) == NULL)
+            goto err;
+      }
+      lib_php++;
+   }
+
+   free(phbuf);
+   return true;
+err:
+   free(phbuf);
+   return false;
+}
+
+// process segments from interpreter (ld-elf.so.1)
+static bool read_interp_segments(struct ps_prochandle* ph) {
+   ELF_EHDR interp_ehdr;
+
+   if (read_elf_header(ph->core->interp_fd, &interp_ehdr) != true) {
+       print_debug("interpreter is not a valid ELF file\n");
+       return false;
+   }
+
+   if (read_lib_segments(ph, ph->core->interp_fd, &interp_ehdr, ph->core->ld_base_addr) != true) {
+       print_debug("can't read segments of interpreter\n");
+       return false;
+   }
+
+   return true;
+}
+
+// process segments of a a.out
+static bool read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
+   int i = 0;
+   ELF_PHDR* phbuf = NULL;
+   ELF_PHDR* exec_php = NULL;
+
+   if ((phbuf = read_program_header_table(ph->core->exec_fd, exec_ehdr)) == NULL)
+      return false;
+
+   for (exec_php = phbuf, i = 0; i < exec_ehdr->e_phnum; i++) {
+      switch (exec_php->p_type) {
+
+         // add mappings for PT_LOAD segments
+         case PT_LOAD: {
+            // add only non-writable segments of non-zero filesz
+            if (!(exec_php->p_flags & PF_W) && exec_php->p_filesz != 0) {
+               if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz) == NULL) goto err;
+            }
+            break;
+         }
+
+         // read the interpreter and it's segments
+         case PT_INTERP: {
+            char interp_name[BUF_SIZE];
+
+            pread(ph->core->exec_fd, interp_name, MIN(exec_php->p_filesz, BUF_SIZE), exec_php->p_offset);
+            print_debug("ELF interpreter %s\n", interp_name);
+            // read interpreter segments as well
+            if ((ph->core->interp_fd = pathmap_open(interp_name)) < 0) {
+               print_debug("can't open runtime loader\n");
+               goto err;
+            }
+            break;
+         }
+
+         // from PT_DYNAMIC we want to read address of first link_map addr
+         case PT_DYNAMIC: {
+            ph->core->dynamic_addr = exec_php->p_vaddr;
+            print_debug("address of _DYNAMIC is 0x%lx\n", ph->core->dynamic_addr);
+            break;
+         }
+
+      } // switch
+      exec_php++;
+   } // for
+
+   free(phbuf);
+   return true;
+err:
+   free(phbuf);
+   return false;
+}
+
+
+#define FIRST_LINK_MAP_OFFSET offsetof(struct r_debug,  r_map)
+#define LD_BASE_OFFSET        offsetof(struct r_debug,  r_ldbase)
+#define LINK_MAP_ADDR_OFFSET  offsetof(struct link_map, l_addr)
+#define LINK_MAP_NAME_OFFSET  offsetof(struct link_map, l_name)
+#define LINK_MAP_NEXT_OFFSET  offsetof(struct link_map, l_next)
+
+// read shared library info from runtime linker's data structures.
+// This work is done by librtlb_db in Solaris
+static bool read_shared_lib_info(struct ps_prochandle* ph) {
+   uintptr_t addr = ph->core->dynamic_addr;
+   uintptr_t debug_base;
+   uintptr_t first_link_map_addr;
+   uintptr_t ld_base_addr;
+   uintptr_t link_map_addr;
+   uintptr_t lib_base_diff;
+   uintptr_t lib_base;
+   uintptr_t lib_name_addr;
+   char lib_name[BUF_SIZE];
+   ELF_DYN dyn;
+   ELF_EHDR elf_ehdr;
+   int lib_fd;
+
+   // _DYNAMIC has information of the form
+   //         [tag] [data] [tag] [data] .....
+   // Both tag and data are pointer sized.
+   // We look for dynamic info with DT_DEBUG. This has shared object info.
+   // refer to struct r_debug in link.h
+
+   dyn.d_tag = DT_NULL;
+   while (dyn.d_tag != DT_DEBUG) {
+      if (ps_pread(ph, (psaddr_t) addr, &dyn, sizeof(ELF_DYN)) != PS_OK) {
+         print_debug("can't read debug info from _DYNAMIC\n");
+         return false;
+      }
+      addr += sizeof(ELF_DYN);
+   }
+
+   // we have got Dyn entry with DT_DEBUG
+   debug_base = dyn.d_un.d_ptr;
+   // at debug_base we have struct r_debug. This has first link map in r_map field
+   if (ps_pread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
+                 &first_link_map_addr, sizeof(uintptr_t)) != PS_OK) {
+      print_debug("can't read first link map address\n");
+      return false;
+   }
+
+   // read ld_base address from struct r_debug
+   // XXX: There is no r_ldbase member on BSD
+/*
+   if (ps_pread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
+                 sizeof(uintptr_t)) != PS_OK) {
+      print_debug("can't read ld base address\n");
+      return false;
+   }
+   ph->core->ld_base_addr = ld_base_addr;
+*/
+   ph->core->ld_base_addr = 0;
+
+   print_debug("interpreter base address is 0x%lx\n", ld_base_addr);
+
+   // now read segments from interp (i.e ld-elf.so.1)
+   if (read_interp_segments(ph) != true)
+      return false;
+
+   // after adding interpreter (ld.so) mappings sort again
+   if (sort_map_array(ph) != true)
+      return false;
+
+   print_debug("first link map is at 0x%lx\n", first_link_map_addr);
+
+   link_map_addr = first_link_map_addr;
+   while (link_map_addr != 0) {
+      // read library base address of the .so. Note that even though <sys/link.h> calls
+      // link_map->l_addr as "base address",  this is * not * really base virtual
+      // address of the shared object. This is actually the difference b/w the virtual
+      // address mentioned in shared object and the actual virtual base where runtime
+      // linker loaded it. We use "base diff" in read_lib_segments call below.
+
+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_ADDR_OFFSET,
+                   &lib_base_diff, sizeof(uintptr_t)) != PS_OK) {
+         print_debug("can't read shared object base address diff\n");
+         return false;
+      }
+
+      // read address of the name
+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NAME_OFFSET,
+                    &lib_name_addr, sizeof(uintptr_t)) != PS_OK) {
+         print_debug("can't read address of shared object name\n");
+         return false;
+      }
+
+      // read name of the shared object
+      if (read_string(ph, (uintptr_t) lib_name_addr, lib_name, sizeof(lib_name)) != true) {
+         print_debug("can't read shared object name\n");
+         return false;
+      }
+
+      if (lib_name[0] != '\0') {
+         // ignore empty lib names
+         lib_fd = pathmap_open(lib_name);
+
+         if (lib_fd < 0) {
+            print_debug("can't open shared object %s\n", lib_name);
+            // continue with other libraries...
+         } else {
+            if (read_elf_header(lib_fd, &elf_ehdr)) {
+               lib_base = lib_base_diff + find_base_address(lib_fd, &elf_ehdr);
+               print_debug("reading library %s @ 0x%lx [ 0x%lx ]\n",
+                           lib_name, lib_base, lib_base_diff);
+               // while adding library mappings we need to use "base difference".
+               if (! read_lib_segments(ph, lib_fd, &elf_ehdr, lib_base_diff)) {
+                  print_debug("can't read shared object's segments\n");
+                  close(lib_fd);
+                  return false;
+               }
+               add_lib_info_fd(ph, lib_name, lib_fd, lib_base);
+               // Map info is added for the library (lib_name) so
+               // we need to re-sort it before calling the p_pdread.
+               if (sort_map_array(ph) != true)
+                  return false;
+            } else {
+               print_debug("can't read ELF header for shared object %s\n", lib_name);
+               close(lib_fd);
+               // continue with other libraries...
+            }
+         }
+      }
+
+      // read next link_map address
+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
+                        &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
+         print_debug("can't read next link in link_map\n");
+         return false;
+      }
+   }
+
+   return true;
+}
+
+// the one and only one exposed stuff from this file
+struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {
+   ELF_EHDR core_ehdr;
+   ELF_EHDR exec_ehdr;
+
+   struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
+   if (ph == NULL) {
+      print_debug("can't allocate ps_prochandle\n");
+      return NULL;
+   }
+
+   if ((ph->core = (struct core_data*) calloc(1, sizeof(struct core_data))) == NULL) {
+      free(ph);
+      print_debug("can't allocate ps_prochandle\n");
+      return NULL;
+   }
+
+   // initialize ph
+   ph->ops = &core_ops;
+   ph->core->core_fd   = -1;
+   ph->core->exec_fd   = -1;
+   ph->core->interp_fd = -1;
+
+   // open the core file
+   if ((ph->core->core_fd = open(core_file, O_RDONLY)) < 0) {
+      print_debug("can't open core file\n");
+      goto err;
+   }
+
+   // read core file ELF header
+   if (read_elf_header(ph->core->core_fd, &core_ehdr) != true || core_ehdr.e_type != ET_CORE) {
+      print_debug("core file is not a valid ELF ET_CORE file\n");
+      goto err;
+   }
+
+   if ((ph->core->exec_fd = open(exec_file, O_RDONLY)) < 0) {
+      print_debug("can't open executable file\n");
+      goto err;
+   }
+
+   if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true || exec_ehdr.e_type != ET_EXEC) {
+      print_debug("executable file is not a valid ELF ET_EXEC file\n");
+      goto err;
+   }
+
+   // process core file segments
+   if (read_core_segments(ph, &core_ehdr) != true)
+      goto err;
+
+   // process exec file segments
+   if (read_exec_segments(ph, &exec_ehdr) != true)
+      goto err;
+
+   // exec file is also treated like a shared object for symbol search
+   if (add_lib_info_fd(ph, exec_file, ph->core->exec_fd,
+                       (uintptr_t)0 + find_base_address(ph->core->exec_fd, &exec_ehdr)) == NULL)
+      goto err;
+
+   // allocate and sort maps into map_array, we need to do this
+   // here because read_shared_lib_info needs to read from debuggee
+   // address space
+   if (sort_map_array(ph) != true)
+      goto err;
+
+   if (read_shared_lib_info(ph) != true)
+      goto err;
+
+   // sort again because we have added more mappings from shared objects
+   if (sort_map_array(ph) != true)
+      goto err;
+
+   if (init_classsharing_workaround(ph) != true)
+      goto err;
+
+   return ph;
+
+err:
+   Prelease(ph);
+   return NULL;
+}
diff --git a/hotspot/agent/src/os/bsd/ps_proc.c b/hotspot/agent/src/os/bsd/ps_proc.c
new file mode 100644
index 0000000..f8957c0
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/ps_proc.c
@@ -0,0 +1,444 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/ptrace.h>
+#include <sys/param.h>
+#include <sys/user.h>
+#include <elf.h>
+#include <sys/elf_common.h>
+#include <sys/link_elf.h>
+#include <libutil.h>
+#include "libproc_impl.h"
+#include "elfmacros.h"
+
+// This file has the libproc implementation specific to live process
+// For core files, refer to ps_core.c
+
+static inline uintptr_t align(uintptr_t ptr, size_t size) {
+  return (ptr & ~(size - 1));
+}
+
+// ---------------------------------------------
+// ptrace functions
+// ---------------------------------------------
+
+// read "size" bytes of data from "addr" within the target process.
+// unlike the standard ptrace() function, process_read_data() can handle
+// unaligned address - alignment check, if required, should be done
+// before calling process_read_data.
+
+static bool process_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) {
+  int rslt;
+  size_t i, words;
+  uintptr_t end_addr = addr + size;
+  uintptr_t aligned_addr = align(addr, sizeof(int));
+
+  if (aligned_addr != addr) {
+    char *ptr = (char *)&rslt;
+    errno = 0;
+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
+    if (errno) {
+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
+      return false;
+    }
+    for (; aligned_addr != addr; aligned_addr++, ptr++);
+    for (; ((intptr_t)aligned_addr % sizeof(int)) && aligned_addr < end_addr;
+        aligned_addr++)
+       *(buf++) = *(ptr++);
+  }
+
+  words = (end_addr - aligned_addr) / sizeof(int);
+
+  // assert((intptr_t)aligned_addr % sizeof(int) == 0);
+  for (i = 0; i < words; i++) {
+    errno = 0;
+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
+    if (errno) {
+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
+      return false;
+    }
+    *(int *)buf = rslt;
+    buf += sizeof(int);
+    aligned_addr += sizeof(int);
+  }
+
+  if (aligned_addr != end_addr) {
+    char *ptr = (char *)&rslt;
+    errno = 0;
+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
+    if (errno) {
+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
+      return false;
+    }
+    for (; aligned_addr != end_addr; aligned_addr++)
+       *(buf++) = *(ptr++);
+  }
+  return true;
+}
+
+// null implementation for write
+static bool process_write_data(struct ps_prochandle* ph,
+                             uintptr_t addr, const char *buf , size_t size) {
+  return false;
+}
+
+// "user" should be a pointer to a reg
+static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct reg *user) {
+  // we have already attached to all thread 'pid's, just use ptrace call
+  // to get regset now. Note that we don't cache regset upfront for processes.
+ if (ptrace(PT_GETREGS, pid, (caddr_t) user, 0) < 0) {
+   print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp %d\n", pid);
+   return false;
+ }
+ return true;
+}
+
+// fill in ptrace_lwpinfo for lid
+static bool process_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+  errno = 0;
+  ptrace(PT_LWPINFO, lwp_id, linfo, sizeof(struct ptrace_lwpinfo));
+
+  return (errno == 0)? true: false;
+}
+
+// attach to a process/thread specified by "pid"
+static bool ptrace_attach(pid_t pid) {
+  if (ptrace(PT_ATTACH, pid, NULL, 0) < 0) {
+    print_debug("ptrace(PTRACE_ATTACH, ..) failed for %d\n", pid);
+    return false;
+  } else {
+    int ret;
+    int status;
+    do {
+      // Wait for debuggee to stop.
+      ret = waitpid(pid, &status, 0);
+      if (ret >= 0) {
+        if (WIFSTOPPED(status)) {
+          // Debuggee stopped.
+          return true;
+        } else {
+          print_debug("waitpid(): Child process exited/terminated (status = 0x%x)\n", status);
+          return false;
+        }
+      } else {
+        switch (errno) {
+          case EINTR:
+            continue;
+            break;
+          case ECHILD:
+            print_debug("waitpid() failed. Child process pid (%d) does not exist \n", pid);
+            break;
+          case EINVAL:
+            print_debug("waitpid() failed. Invalid options argument.\n");
+            break;
+          default:
+            print_debug("waitpid() failed. Unexpected error %d\n",errno);
+        }
+        return false;
+      }
+    } while(true);
+  }
+}
+
+// -------------------------------------------------------
+// functions for obtaining library information
+// -------------------------------------------------------
+
+// callback for read_thread_info
+static bool add_new_thread(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
+  return add_thread_info(ph, pthread_id, lwp_id) != NULL;
+}
+
+#if defined(__FreeBSD__) && __FreeBSD_version < 701000
+/*
+ * TEXT_START_ADDR from binutils/ld/emulparams/<arch_spec>.sh
+ * Not the most robust but good enough.
+ */
+
+#if defined(amd64) || defined(x86_64)
+#define TEXT_START_ADDR 0x400000
+#elif defined(i386)
+#define TEXT_START_ADDR 0x8048000
+#else
+#error TEXT_START_ADDR not defined
+#endif
+
+#define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
+
+uintptr_t linkmap_addr(struct ps_prochandle *ph) {
+  uintptr_t ehdr_addr, phdr_addr, dyn_addr, dmap_addr, lmap_addr;
+  ELF_EHDR ehdr;
+  ELF_PHDR *phdrs, *phdr;
+  ELF_DYN *dyns, *dyn;
+  struct r_debug dmap;
+  unsigned long hdrs_size;
+  unsigned int i;
+
+  /* read ELF_EHDR at TEXT_START_ADDR and validate */
+
+  ehdr_addr = (uintptr_t)TEXT_START_ADDR;
+
+  if (process_read_data(ph, ehdr_addr, (char *)&ehdr, sizeof(ehdr)) != true) {
+    print_debug("process_read_data failed for ehdr_addr %p\n", ehdr_addr);
+    return (0);
+  }
+
+  if (!IS_ELF(ehdr) ||
+        ehdr.e_ident[EI_CLASS] != ELF_TARG_CLASS ||
+        ehdr.e_ident[EI_DATA] != ELF_TARG_DATA ||
+        ehdr.e_ident[EI_VERSION] != EV_CURRENT ||
+        ehdr.e_phentsize != sizeof(ELF_PHDR) ||
+        ehdr.e_version != ELF_TARG_VER ||
+        ehdr.e_machine != ELF_TARG_MACH) {
+    print_debug("not an ELF_EHDR at %p\n", ehdr_addr);
+    return (0);
+  }
+
+  /* allocate space for all ELF_PHDR's and read */
+
+  phdr_addr = ehdr_addr + ehdr.e_phoff;
+  hdrs_size = ehdr.e_phnum * sizeof(ELF_PHDR);
+
+  if ((phdrs = malloc(hdrs_size)) == NULL)
+    return (0);
+
+  if (process_read_data(ph, phdr_addr, (char *)phdrs, hdrs_size) != true) {
+    print_debug("process_read_data failed for phdr_addr %p\n", phdr_addr);
+    return (0);
+  }
+
+  /* find PT_DYNAMIC section */
+
+  for (i = 0, phdr = phdrs; i < ehdr.e_phnum; i++, phdr++) {
+    if (phdr->p_type == PT_DYNAMIC)
+      break;
+  }
+
+  if (i >= ehdr.e_phnum) {
+    print_debug("PT_DYNAMIC section not found!\n");
+    free(phdrs);
+    return (0);
+  }
+
+  /* allocate space and read in ELF_DYN headers */
+
+  dyn_addr = phdr->p_vaddr;
+  hdrs_size = phdr->p_memsz;
+  free(phdrs);
+
+  if ((dyns = malloc(hdrs_size)) == NULL)
+    return (0);
+
+  if (process_read_data(ph, dyn_addr, (char *)dyns, hdrs_size) != true) {
+    print_debug("process_read_data failed for dyn_addr %p\n", dyn_addr);
+    free(dyns);
+    return (0);
+  }
+
+  /* find DT_DEBUG */
+
+  dyn = dyns;
+  while (dyn->d_tag != DT_DEBUG && dyn->d_tag != DT_NULL) {
+    dyn++;
+  }
+
+  if (dyn->d_tag != DT_DEBUG) {
+    print_debug("failed to find DT_DEBUG\n");
+    free(dyns);
+    return (0);
+  }
+
+  /* read struct r_debug into dmap */
+
+  dmap_addr = (uintptr_t)dyn->d_un.d_ptr;
+  free(dyns);
+
+  if (process_read_data(ph, dmap_addr, (char *)&dmap, sizeof(dmap)) != true) {
+    print_debug("process_read_data failed for dmap_addr %p\n", dmap_addr);
+    return (0);
+  }
+
+  lmap_addr = (uintptr_t)dmap.r_map;
+
+  return (lmap_addr);
+}
+#endif // __FreeBSD__ && __FreeBSD_version < 701000
+
+static bool read_lib_info(struct ps_prochandle* ph) {
+#if defined(__FreeBSD__) && __FreeBSD_version >= 701000
+  struct kinfo_vmentry *freep, *kve;
+  int i, cnt;
+
+  freep = kinfo_getvmmap(ph->pid, &cnt);
+  if (freep == NULL) {
+      print_debug("can't get vm map for pid\n", ph->pid);
+      return false;
+  }
+
+  for (i = 0; i < cnt; i++) {
+    kve = &freep[i];
+    if ((kve->kve_flags & KVME_FLAG_COW) &&
+        kve->kve_path != NULL &&
+        strlen(kve->kve_path) > 0) {
+
+      if (find_lib(ph, kve->kve_path) == false) {
+        lib_info* lib;
+        if ((lib = add_lib_info(ph, kve->kve_path,
+                                (uintptr_t) kve->kve_start)) == NULL)
+          continue; // ignore, add_lib_info prints error
+
+        // we don't need to keep the library open, symtab is already
+        // built. Only for core dump we need to keep the fd open.
+        close(lib->fd);
+        lib->fd = -1;
+      }
+    }
+  }
+
+  free(freep);
+
+  return true;
+#else
+  char *l_name;
+  struct link_map *lmap;
+  uintptr_t lmap_addr;
+
+  if ((l_name = malloc(BUF_SIZE)) == NULL)
+    return false;
+
+  if ((lmap = malloc(sizeof(*lmap))) == NULL) {
+    free(l_name);
+    return false;
+  }
+
+  lmap_addr = linkmap_addr(ph);
+
+  if (lmap_addr == 0) {
+    free(l_name);
+    free(lmap);
+    return false;
+  }
+
+  do {
+    if (process_read_data(ph, lmap_addr, (char *)lmap, sizeof(*lmap)) != true) {
+      print_debug("process_read_data failed for lmap_addr %p\n", lmap_addr);
+      free (l_name);
+      free (lmap);
+      return false;
+    }
+
+    if (process_read_data(ph, (uintptr_t)lmap->l_name, l_name,
+        BUF_SIZE) != true) {
+      print_debug("process_read_data failed for lmap->l_name %p\n",
+          lmap->l_name);
+      free (l_name);
+      free (lmap);
+      return false;
+    }
+
+    if (find_lib(ph, l_name) == false) {
+      lib_info* lib;
+      if ((lib = add_lib_info(ph, l_name,
+                              (uintptr_t) lmap->l_addr)) == NULL)
+        continue; // ignore, add_lib_info prints error
+
+      // we don't need to keep the library open, symtab is already
+      // built. Only for core dump we need to keep the fd open.
+      close(lib->fd);
+      lib->fd = -1;
+    }
+    lmap_addr = (uintptr_t)lmap->l_next;
+  } while (lmap->l_next != NULL);
+
+  free (l_name);
+  free (lmap);
+
+  return true;
+#endif
+}
+
+// detach a given pid
+static bool ptrace_detach(pid_t pid) {
+  if (pid && ptrace(PT_DETACH, pid, (caddr_t)1, 0) < 0) {
+    print_debug("ptrace(PTRACE_DETACH, ..) failed for %d\n", pid);
+    return false;
+  } else {
+    return true;
+  }
+}
+
+static void process_cleanup(struct ps_prochandle* ph) {
+  ptrace_detach(ph->pid);
+}
+
+static ps_prochandle_ops process_ops = {
+  .release=  process_cleanup,
+  .p_pread=  process_read_data,
+  .p_pwrite= process_write_data,
+  .get_lwp_regs= process_get_lwp_regs,
+  .get_lwp_info= process_get_lwp_info
+};
+
+// attach to the process. One and only one exposed stuff
+struct ps_prochandle* Pgrab(pid_t pid) {
+  struct ps_prochandle* ph = NULL;
+  thread_info* thr = NULL;
+
+  if ( (ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle))) == NULL) {
+     print_debug("can't allocate memory for ps_prochandle\n");
+     return NULL;
+  }
+
+  if (ptrace_attach(pid) != true) {
+     free(ph);
+     return NULL;
+  }
+
+  // initialize ps_prochandle
+  ph->pid = pid;
+
+  // initialize vtable
+  ph->ops = &process_ops;
+
+  // read library info and symbol tables, must do this before attaching threads,
+  // as the symbols in the pthread library will be used to figure out
+  // the list of threads within the same process.
+  if (read_lib_info(ph) != true) {
+     ptrace_detach(pid);
+     free(ph);
+     return NULL;
+  }
+
+  // read thread info
+  read_thread_info(ph, add_new_thread);
+
+  return ph;
+}
diff --git a/hotspot/agent/src/os/bsd/salibelf.c b/hotspot/agent/src/os/bsd/salibelf.c
new file mode 100644
index 0000000..4c860a0
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/salibelf.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "salibelf.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+extern void print_debug(const char*,...);
+
+// ELF file parsing helpers. Note that we do *not* use libelf here.
+int read_elf_header(int fd, ELF_EHDR* ehdr) {
+   if (pread(fd, ehdr, sizeof (ELF_EHDR), 0) != sizeof (ELF_EHDR) ||
+            memcmp(&ehdr->e_ident[EI_MAG0], ELFMAG, SELFMAG) != 0 ||
+            ehdr->e_version != EV_CURRENT) {
+        return 0;
+   }
+   return 1;
+}
+
+bool is_elf_file(int fd) {
+   ELF_EHDR ehdr;
+   return read_elf_header(fd, &ehdr);
+}
+
+// read program header table of an ELF file
+ELF_PHDR* read_program_header_table(int fd, ELF_EHDR* hdr) {
+   ELF_PHDR* phbuf = 0;
+   // allocate memory for program header table
+   size_t nbytes = hdr->e_phnum * hdr->e_phentsize;
+
+   if ((phbuf = (ELF_PHDR*) malloc(nbytes)) == NULL) {
+      print_debug("can't allocate memory for reading program header table\n");
+      return NULL;
+   }
+
+   if (pread(fd, phbuf, nbytes, hdr->e_phoff) != nbytes) {
+      print_debug("ELF file is truncated! can't read program header table\n");
+      free(phbuf);
+      return NULL;
+   }
+
+   return phbuf;
+}
+
+// read section header table of an ELF file
+ELF_SHDR* read_section_header_table(int fd, ELF_EHDR* hdr) {
+   ELF_SHDR* shbuf = 0;
+   // allocate memory for section header table
+   size_t nbytes = hdr->e_shnum * hdr->e_shentsize;
+
+   if ((shbuf = (ELF_SHDR*) malloc(nbytes)) == NULL) {
+      print_debug("can't allocate memory for reading section header table\n");
+      return NULL;
+   }
+
+   if (pread(fd, shbuf, nbytes, hdr->e_shoff) != nbytes) {
+      print_debug("ELF file is truncated! can't read section header table\n");
+      free(shbuf);
+      return NULL;
+   }
+
+   return shbuf;
+}
+
+// read a particular section's data
+void* read_section_data(int fd, ELF_EHDR* ehdr, ELF_SHDR* shdr) {
+  void *buf = NULL;
+  if (shdr->sh_type == SHT_NOBITS || shdr->sh_size == 0) {
+     return buf;
+  }
+  if ((buf = calloc(shdr->sh_size, 1)) == NULL) {
+     print_debug("can't allocate memory for reading section data\n");
+     return NULL;
+  }
+  if (pread(fd, buf, shdr->sh_size, shdr->sh_offset) != shdr->sh_size) {
+     free(buf);
+     print_debug("section data read failed\n");
+     return NULL;
+  }
+  return buf;
+}
+
+uintptr_t find_base_address(int fd, ELF_EHDR* ehdr) {
+  uintptr_t baseaddr = (uintptr_t)-1;
+  int cnt;
+  ELF_PHDR *phbuf, *phdr;
+
+  // read program header table
+  if ((phbuf = read_program_header_table(fd, ehdr)) == NULL) {
+    goto quit;
+  }
+
+  // the base address of a shared object is the lowest vaddr of
+  // its loadable segments (PT_LOAD)
+  for (phdr = phbuf, cnt = 0; cnt < ehdr->e_phnum; cnt++, phdr++) {
+    if (phdr->p_type == PT_LOAD && phdr->p_vaddr < baseaddr) {
+      baseaddr = phdr->p_vaddr;
+    }
+  }
+
+quit:
+  if (phbuf) free(phbuf);
+  return baseaddr;
+}
diff --git a/hotspot/agent/src/os/bsd/salibelf.h b/hotspot/agent/src/os/bsd/salibelf.h
new file mode 100644
index 0000000..957694b
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/salibelf.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef _SALIBELF_H_
+#define _SALIBELF_H_
+
+#include <elf.h>
+#include "elfmacros.h"
+#include "libproc_impl.h"
+
+// read ELF file header.
+int read_elf_header(int fd, ELF_EHDR* ehdr);
+
+// is given file descriptor corresponds to an ELF file?
+bool is_elf_file(int fd);
+
+// read program header table of an ELF file. caller has to
+// free the result pointer after use. NULL on failure.
+ELF_PHDR* read_program_header_table(int fd, ELF_EHDR* hdr);
+
+// read section header table of an ELF file. caller has to
+// free the result pointer after use. NULL on failure.
+ELF_SHDR* read_section_header_table(int fd, ELF_EHDR* hdr);
+
+// read a particular section's data. caller has to free the
+// result pointer after use. NULL on failure.
+void* read_section_data(int fd, ELF_EHDR* ehdr, ELF_SHDR* shdr);
+
+// find the base address at which the library wants to load itself
+uintptr_t find_base_address(int fd, ELF_EHDR* ehdr);
+#endif /* _SALIBELF_H_ */
diff --git a/hotspot/agent/src/os/bsd/symtab.c b/hotspot/agent/src/os/bsd/symtab.c
new file mode 100644
index 0000000..9a9fbd2
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/symtab.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <unistd.h>
+#include <search.h>
+#include <stdlib.h>
+#include <string.h>
+#include <db.h>
+#include <fcntl.h>
+#include "symtab.h"
+#include "salibelf.h"
+
+
+// ----------------------------------------------------
+// functions for symbol lookups
+// ----------------------------------------------------
+
+struct elf_section {
+  ELF_SHDR   *c_shdr;
+  void       *c_data;
+};
+
+struct elf_symbol {
+  char *name;
+  uintptr_t offset;
+  uintptr_t size;
+};
+
+typedef struct symtab {
+  char *strs;
+  size_t num_symbols;
+  struct elf_symbol *symbols;
+  DB* hash_table;
+} symtab_t;
+
+// read symbol table from given fd.
+struct symtab* build_symtab(int fd) {
+  ELF_EHDR ehdr;
+  struct symtab* symtab = NULL;
+
+  // Reading of elf header
+  struct elf_section *scn_cache = NULL;
+  int cnt = 0;
+  ELF_SHDR* shbuf = NULL;
+  ELF_SHDR* cursct = NULL;
+  ELF_PHDR* phbuf = NULL;
+  int symtab_found = 0;
+  int dynsym_found = 0;
+  uint32_t symsection = SHT_SYMTAB;
+
+  uintptr_t baseaddr = (uintptr_t)-1;
+
+  lseek(fd, (off_t)0L, SEEK_SET);
+  if (! read_elf_header(fd, &ehdr)) {
+    // not an elf
+    return NULL;
+  }
+
+  // read ELF header
+  if ((shbuf = read_section_header_table(fd, &ehdr)) == NULL) {
+    goto quit;
+  }
+
+  baseaddr = find_base_address(fd, &ehdr);
+
+  scn_cache = calloc(ehdr.e_shnum, sizeof(*scn_cache));
+  if (scn_cache == NULL) {
+    goto quit;
+  }
+
+  for (cursct = shbuf, cnt = 0; cnt < ehdr.e_shnum; cnt++) {
+    scn_cache[cnt].c_shdr = cursct;
+    if (cursct->sh_type == SHT_SYMTAB ||
+        cursct->sh_type == SHT_STRTAB ||
+        cursct->sh_type == SHT_DYNSYM) {
+      if ( (scn_cache[cnt].c_data = read_section_data(fd, &ehdr, cursct)) == NULL) {
+         goto quit;
+      }
+    }
+
+    if (cursct->sh_type == SHT_SYMTAB)
+       symtab_found++;
+
+    if (cursct->sh_type == SHT_DYNSYM)
+       dynsym_found++;
+
+    cursct++;
+  }
+
+  if (!symtab_found && dynsym_found)
+     symsection = SHT_DYNSYM;
+
+  for (cnt = 1; cnt < ehdr.e_shnum; cnt++) {
+    ELF_SHDR *shdr = scn_cache[cnt].c_shdr;
+
+    if (shdr->sh_type == symsection) {
+      ELF_SYM  *syms;
+      int j, n;
+      size_t size;
+
+      // FIXME: there could be multiple data buffers associated with the
+      // same ELF section. Here we can handle only one buffer. See man page
+      // for elf_getdata on Solaris.
+
+      // guarantee(symtab == NULL, "multiple symtab");
+      symtab = calloc(1, sizeof(*symtab));
+      if (symtab == NULL) {
+         goto quit;
+      }
+      // the symbol table
+      syms = (ELF_SYM *)scn_cache[cnt].c_data;
+
+      // number of symbols
+      n = shdr->sh_size / shdr->sh_entsize;
+
+      // create hash table, we use berkeley db to
+      // manipulate the hash table.
+      symtab->hash_table = dbopen(NULL, O_CREAT | O_RDWR, 0600, DB_HASH, NULL);
+      // guarantee(symtab->hash_table, "unexpected failure: dbopen");
+      if (symtab->hash_table == NULL)
+        goto bad;
+
+      // shdr->sh_link points to the section that contains the actual strings
+      // for symbol names. the st_name field in ELF_SYM is just the
+      // string table index. we make a copy of the string table so the
+      // strings will not be destroyed by elf_end.
+      size = scn_cache[shdr->sh_link].c_shdr->sh_size;
+      symtab->strs = malloc(size);
+      if (symtab->strs == NULL)
+        goto bad;
+      memcpy(symtab->strs, scn_cache[shdr->sh_link].c_data, size);
+
+      // allocate memory for storing symbol offset and size;
+      symtab->num_symbols = n;
+      symtab->symbols = calloc(n , sizeof(*symtab->symbols));
+      if (symtab->symbols == NULL)
+        goto bad;
+
+      // copy symbols info our symtab and enter them info the hash table
+      for (j = 0; j < n; j++, syms++) {
+        DBT key, value;
+        char *sym_name = symtab->strs + syms->st_name;
+
+        // skip non-object and non-function symbols
+        int st_type = ELF_ST_TYPE(syms->st_info);
+        if ( st_type != STT_FUNC && st_type != STT_OBJECT)
+           continue;
+        // skip empty strings and undefined symbols
+        if (*sym_name == '\0' || syms->st_shndx == SHN_UNDEF) continue;
+
+        symtab->symbols[j].name   = sym_name;
+        symtab->symbols[j].offset = syms->st_value - baseaddr;
+        symtab->symbols[j].size   = syms->st_size;
+
+        key.data = sym_name;
+        key.size = strlen(sym_name) + 1;
+        value.data = &(symtab->symbols[j]);
+        value.size = sizeof(void *);
+        (*symtab->hash_table->put)(symtab->hash_table, &key, &value, 0);
+      }
+    }
+  }
+  goto quit;
+
+bad:
+  destroy_symtab(symtab);
+  symtab = NULL;
+
+quit:
+  if (shbuf) free(shbuf);
+  if (phbuf) free(phbuf);
+  if (scn_cache) {
+    for (cnt = 0; cnt < ehdr.e_shnum; cnt++) {
+      if (scn_cache[cnt].c_data != NULL) {
+        free(scn_cache[cnt].c_data);
+      }
+    }
+    free(scn_cache);
+  }
+  return symtab;
+}
+
+void destroy_symtab(struct symtab* symtab) {
+  if (!symtab) return;
+  if (symtab->strs) free(symtab->strs);
+  if (symtab->symbols) free(symtab->symbols);
+  if (symtab->hash_table) {
+    (*symtab->hash_table->close)(symtab->hash_table);
+  }
+  free(symtab);
+}
+
+uintptr_t search_symbol(struct symtab* symtab, uintptr_t base,
+                      const char *sym_name, int *sym_size) {
+  DBT key, value;
+  int ret;
+
+  // library does not have symbol table
+  if (!symtab || !symtab->hash_table)
+     return 0;
+
+  key.data = (char*)(uintptr_t)sym_name;
+  key.size = strlen(sym_name) + 1;
+  ret = (*symtab->hash_table->get)(symtab->hash_table, &key, &value, 0);
+  if (ret == 0) {
+    struct elf_symbol *sym = value.data;
+    uintptr_t rslt = (uintptr_t) ((char*)base + sym->offset);
+    if (sym_size) *sym_size = sym->size;
+    return rslt;
+  }
+
+  return 0;
+}
+
+const char* nearest_symbol(struct symtab* symtab, uintptr_t offset,
+                           uintptr_t* poffset) {
+  int n = 0;
+  if (!symtab) return NULL;
+  for (; n < symtab->num_symbols; n++) {
+    struct elf_symbol* sym = &(symtab->symbols[n]);
+    if (sym->name != NULL &&
+      offset >= sym->offset && offset < sym->offset + sym->size) {
+      if (poffset) *poffset = (offset - sym->offset);
+      return sym->name;
+    }
+  }
+  return NULL;
+}
diff --git a/hotspot/agent/src/os/bsd/symtab.h b/hotspot/agent/src/os/bsd/symtab.h
new file mode 100644
index 0000000..9b7eef7
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/symtab.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef _SYMTAB_H_
+#define _SYMTAB_H_
+
+#include <stdint.h>
+
+// interface to manage ELF symbol tables
+
+struct symtab;
+
+// build symbol table for a given ELF file descriptor
+struct symtab* build_symtab(int fd);
+
+// destroy the symbol table
+void destroy_symtab(struct symtab* symtab);
+
+// search for symbol in the given symbol table. Adds offset
+// to the base uintptr_t supplied. Returns NULL if not found.
+uintptr_t search_symbol(struct symtab* symtab, uintptr_t base,
+                      const char *sym_name, int *sym_size);
+
+// look for nearest symbol for a given offset (not address - base
+// subtraction done by caller
+const char* nearest_symbol(struct symtab* symtab, uintptr_t offset,
+                      uintptr_t* poffset);
+
+#endif /*_SYMTAB_H_*/
diff --git a/hotspot/agent/src/os/bsd/test.c b/hotspot/agent/src/os/bsd/test.c
new file mode 100644
index 0000000..3659542
--- /dev/null
+++ b/hotspot/agent/src/os/bsd/test.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "libproc.h"
+
+int main(int argc, char** argv) {
+   struct ps_prochandle* ph;
+
+   init_libproc(true);
+   switch (argc) {
+      case 2: {
+         // process
+         ph = Pgrab(atoi(argv[1]));
+         break;
+      }
+
+      case 3: {
+        // core
+        ph = Pgrab_core(argv[1], argv[2]);
+        break;
+      }
+
+      default: {
+        fprintf(stderr, "usage %s <pid> or %s <exec file> <core file>\n", argv[0], argv[0]);
+        return 1;
+      }
+   }
+
+   if (ph) {
+      Prelease(ph);
+      return 0;
+   } else {
+      printf("can't connect to debuggee\n");
+      return 1;
+   }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/BsdVtblAccess.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/BsdVtblAccess.java
new file mode 100644
index 0000000..ed68875
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/BsdVtblAccess.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.types.*;
+import sun.jvm.hotspot.types.basic.*;
+
+public class BsdVtblAccess extends BasicVtblAccess {
+  private String vt;
+
+  public BsdVtblAccess(SymbolLookup symbolLookup,
+                         String[] dllNames) {
+    super(symbolLookup, dllNames);
+
+    if (symbolLookup.lookup("libjvm.so", "__vt_10JavaThread") != null ||
+        symbolLookup.lookup("libjvm_g.so", "__vt_10JavaThread") != null) {
+       // old C++ ABI
+       vt = "__vt_";
+    } else {
+       // new C++ ABI
+       vt = "_ZTV";
+    }
+  }
+
+  protected String vtblSymbolForType(Type type) {
+    return vt + type.getName().length() + type;
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java
index 0b655b8..233bc17 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java
@@ -28,6 +28,7 @@
 import java.net.*;
 import java.rmi.*;
 import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
 import sun.jvm.hotspot.debugger.proc.*;
 import sun.jvm.hotspot.debugger.remote.*;
 import sun.jvm.hotspot.debugger.windbg.*;
@@ -335,6 +336,8 @@
                 setupDebuggerWin32();
             } else if (os.equals("linux")) {
                 setupDebuggerLinux();
+            } else if (os.equals("bsd")) {
+                setupDebuggerBsd();
             } else {
                 // Add support for more operating systems here
                 throw new DebuggerException("Operating system " + os + " not yet supported");
@@ -390,6 +393,10 @@
                 db = new HotSpotTypeDataBase(machDesc,
                 new LinuxVtblAccess(debugger, jvmLibNames),
                 debugger, jvmLibNames);
+            } else if (os.equals("bsd")) {
+                db = new HotSpotTypeDataBase(machDesc,
+                new BsdVtblAccess(debugger, jvmLibNames),
+                debugger, jvmLibNames);
             } else {
                 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess yet)");
             }
@@ -477,6 +484,8 @@
             setupJVMLibNamesWin32();
         } else if (os.equals("linux")) {
             setupJVMLibNamesLinux();
+        } else if (os.equals("bsd")) {
+            setupJVMLibNamesBsd();
         } else {
             throw new RuntimeException("Unknown OS type");
         }
@@ -554,6 +563,31 @@
         jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so" };
     }
 
+    //
+    // BSD
+    //
+
+    private void setupDebuggerBsd() {
+        setupJVMLibNamesBsd();
+
+        if (cpu.equals("x86")) {
+            machDesc = new MachineDescriptionIntelX86();
+        } else if (cpu.equals("amd64")) {
+            machDesc = new MachineDescriptionAMD64();
+        } else {
+            throw new DebuggerException("BSD only supported on x86/amd64");
+        }
+
+        BsdDebuggerLocal dbg = new BsdDebuggerLocal(machDesc, !isServer);
+        debugger = dbg;
+
+        attachDebugger();
+    }
+
+    private void setupJVMLibNamesBsd() {
+        jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so" };
+    }
+
     /** Convenience routine which should be called by per-platform
       debugger setup. Should not be called when startupMode is
       REMOTE_MODE. */
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java
index 8a5abc8..bb0a444 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java
@@ -29,6 +29,7 @@
 import java.rmi.*;
 import sun.jvm.hotspot.*;
 import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
 import sun.jvm.hotspot.debugger.proc.*;
 import sun.jvm.hotspot.debugger.cdbg.*;
 import sun.jvm.hotspot.debugger.windbg.*;
@@ -514,6 +515,8 @@
                 setupDebuggerWin32();
             } else if (os.equals("linux")) {
                 setupDebuggerLinux();
+            } else if (os.equals("bsd")) {
+                setupDebuggerBsd();
             } else {
                 // Add support for more operating systems here
                 throw new DebuggerException("Operating system " + os + " not yet supported");
@@ -565,6 +568,9 @@
             } else if (os.equals("linux")) {
                 db = new HotSpotTypeDataBase(machDesc, new LinuxVtblAccess(debugger, jvmLibNames),
                 debugger, jvmLibNames);
+            } else if (os.equals("bsd")) {
+                db = new HotSpotTypeDataBase(machDesc, new BsdVtblAccess(debugger, jvmLibNames),
+                debugger, jvmLibNames);
             } else {
                 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess implemented yet)");
             }
@@ -666,6 +672,8 @@
             setupJVMLibNamesWin32();
         } else if (os.equals("linux")) {
             setupJVMLibNamesLinux();
+        } else if (os.equals("bsd")) {
+            setupJVMLibNamesBsd();
         } else {
             throw new RuntimeException("Unknown OS type");
         }
@@ -745,6 +753,34 @@
         setupJVMLibNamesSolaris();
     }
 
+    //
+    // BSD
+    //
+
+    private void setupDebuggerBsd() {
+        setupJVMLibNamesBsd();
+
+        if (cpu.equals("x86")) {
+            machDesc = new MachineDescriptionIntelX86();
+        } else if (cpu.equals("amd64")) {
+            machDesc = new MachineDescriptionAMD64();
+        } else {
+            throw new DebuggerException("Bsd only supported on x86/amd64");
+        }
+
+        // Note we do not use a cache for the local debugger in server
+        // mode; it will be taken care of on the client side (once remote
+        // debugging is implemented).
+
+        debugger = new BsdDebuggerLocal(machDesc, !isServer);
+        attachDebugger();
+    }
+
+    private void setupJVMLibNamesBsd() {
+        // same as solaris
+        setupJVMLibNamesSolaris();
+    }
+
     /** Convenience routine which should be called by per-platform
       debugger setup. Should not be called when startupMode is
       REMOTE_MODE. */
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java
new file mode 100644
index 0000000..de707f0
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java
@@ -0,0 +1,399 @@
+/*
+ * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+
+class BsdAddress implements Address {
+    protected BsdDebugger debugger;
+    protected long addr;
+
+    BsdAddress(BsdDebugger debugger, long addr) {
+        this.debugger = debugger;
+        this.addr = addr;
+    }
+
+    //
+    // Basic Java routines
+    //
+
+    public boolean equals(Object arg) {
+        if (arg == null) {
+            return false;
+        }
+
+        if (!(arg instanceof BsdAddress)) {
+            return false;
+        }
+
+        return (addr == ((BsdAddress) arg).addr);
+    }
+
+    public int hashCode() {
+        // FIXME: suggestions on a better hash code?
+        return (int) addr;
+    }
+
+    public String toString() {
+        return debugger.addressValueToString(addr);
+    }
+
+    //
+    // C/C++-related routines
+    //
+
+    public long getCIntegerAt(long offset, long numBytes, boolean isUnsigned)
+            throws UnalignedAddressException, UnmappedAddressException {
+        return debugger.readCInteger(addr + offset, numBytes, isUnsigned);
+    }
+
+    public Address getAddressAt(long offset)
+            throws UnalignedAddressException, UnmappedAddressException {
+        return debugger.readAddress(addr + offset);
+    }
+
+    public Address getCompOopAddressAt(long offset)
+            throws UnalignedAddressException, UnmappedAddressException {
+        return debugger.readCompOopAddress(addr + offset);
+    }
+
+    //
+    // Java-related routines
+    //
+
+  public boolean getJBooleanAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJBoolean(addr + offset);
+  }
+
+  public byte getJByteAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJByte(addr + offset);
+  }
+
+  public char getJCharAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJChar(addr + offset);
+  }
+
+  public double getJDoubleAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJDouble(addr + offset);
+  }
+
+  public float getJFloatAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJFloat(addr + offset);
+  }
+
+  public int getJIntAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJInt(addr + offset);
+  }
+
+  public long getJLongAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJLong(addr + offset);
+  }
+
+  public short getJShortAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJShort(addr + offset);
+  }
+
+  public OopHandle getOopHandleAt(long offset)
+    throws UnalignedAddressException, UnmappedAddressException, NotInHeapException {
+    return debugger.readOopHandle(addr + offset);
+  }
+
+  public OopHandle getCompOopHandleAt(long offset)
+    throws UnalignedAddressException, UnmappedAddressException, NotInHeapException {
+    return debugger.readCompOopHandle(addr + offset);
+  }
+
+  // Mutators -- not implemented for now (FIXME)
+  public void setCIntegerAt(long offset, long numBytes, long value) {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void setAddressAt(long offset, Address value) {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJBooleanAt      (long offset, boolean value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJByteAt         (long offset, byte value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJCharAt         (long offset, char value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJDoubleAt       (long offset, double value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJFloatAt        (long offset, float value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJIntAt          (long offset, int value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJLongAt         (long offset, long value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJShortAt        (long offset, short value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setOopHandleAt     (long offset, OopHandle value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+
+  //
+  // Arithmetic operations -- necessary evil.
+  //
+
+  public Address    addOffsetTo       (long offset) throws UnsupportedOperationException {
+    long value = addr + offset;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+  public OopHandle  addOffsetToAsOopHandle(long offset) throws UnsupportedOperationException {
+    long value = addr + offset;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdOopHandle(debugger, value);
+  }
+
+  /** (FIXME: any signed/unsigned issues? Should this work for
+      OopHandles?) */
+  public long       minus(Address arg) {
+    if (arg == null) {
+      return addr;
+    }
+    return addr - ((BsdAddress) arg).addr;
+  }
+
+  // Two's complement representation.
+  // All negative numbers are larger than positive numbers.
+  // Numbers with the same sign can be compared normally.
+  // Test harness is below in main().
+
+  public boolean    lessThan          (Address a) {
+    if (a == null) {
+      return false;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return true;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return false;
+    }
+    return (addr < arg.addr);
+  }
+
+  public boolean    lessThanOrEqual   (Address a) {
+    if (a == null) {
+      return false;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return true;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return false;
+    }
+    return (addr <= arg.addr);
+  }
+
+  public boolean    greaterThan       (Address a) {
+    if (a == null) {
+      return true;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return false;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return true;
+    }
+    return (addr > arg.addr);
+  }
+
+  public boolean    greaterThanOrEqual(Address a) {
+    if (a == null) {
+      return true;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return false;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return true;
+    }
+    return (addr >= arg.addr);
+  }
+
+  public Address    andWithMask(long mask) throws UnsupportedOperationException {
+    long value = addr & mask;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+  public Address    orWithMask(long mask) throws UnsupportedOperationException {
+    long value = addr | mask;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+  public Address    xorWithMask(long mask) throws UnsupportedOperationException {
+    long value = addr ^ mask;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+
+  //--------------------------------------------------------------------------------
+  // Internals only below this point
+  //
+
+  long getValue() {
+    return addr;
+  }
+
+
+  private static void check(boolean arg, String failMessage) {
+    if (!arg) {
+      System.err.println(failMessage + ": FAILED");
+      System.exit(1);
+    }
+  }
+
+  // Test harness
+  public static void main(String[] args) {
+    // p/n indicates whether the interior address is really positive
+    // or negative. In unsigned terms, p1 < p2 < n1 < n2.
+
+    BsdAddress p1 = new BsdAddress(null, 0x7FFFFFFFFFFFFFF0L);
+    BsdAddress p2 = (BsdAddress) p1.addOffsetTo(10);
+    BsdAddress n1 = (BsdAddress) p2.addOffsetTo(10);
+    BsdAddress n2 = (BsdAddress) n1.addOffsetTo(10);
+
+    // lessThan positive tests
+    check(p1.lessThan(p2), "lessThan 1");
+    check(p1.lessThan(n1), "lessThan 2");
+    check(p1.lessThan(n2), "lessThan 3");
+    check(p2.lessThan(n1), "lessThan 4");
+    check(p2.lessThan(n2), "lessThan 5");
+    check(n1.lessThan(n2), "lessThan 6");
+
+    // lessThan negative tests
+    check(!p1.lessThan(p1), "lessThan 7");
+    check(!p2.lessThan(p2), "lessThan 8");
+    check(!n1.lessThan(n1), "lessThan 9");
+    check(!n2.lessThan(n2), "lessThan 10");
+
+    check(!p2.lessThan(p1), "lessThan 11");
+    check(!n1.lessThan(p1), "lessThan 12");
+    check(!n2.lessThan(p1), "lessThan 13");
+    check(!n1.lessThan(p2), "lessThan 14");
+    check(!n2.lessThan(p2), "lessThan 15");
+    check(!n2.lessThan(n1), "lessThan 16");
+
+    // lessThanOrEqual positive tests
+    check(p1.lessThanOrEqual(p1), "lessThanOrEqual 1");
+    check(p2.lessThanOrEqual(p2), "lessThanOrEqual 2");
+    check(n1.lessThanOrEqual(n1), "lessThanOrEqual 3");
+    check(n2.lessThanOrEqual(n2), "lessThanOrEqual 4");
+
+    check(p1.lessThanOrEqual(p2), "lessThanOrEqual 5");
+    check(p1.lessThanOrEqual(n1), "lessThanOrEqual 6");
+    check(p1.lessThanOrEqual(n2), "lessThanOrEqual 7");
+    check(p2.lessThanOrEqual(n1), "lessThanOrEqual 8");
+    check(p2.lessThanOrEqual(n2), "lessThanOrEqual 9");
+    check(n1.lessThanOrEqual(n2), "lessThanOrEqual 10");
+
+    // lessThanOrEqual negative tests
+    check(!p2.lessThanOrEqual(p1), "lessThanOrEqual 11");
+    check(!n1.lessThanOrEqual(p1), "lessThanOrEqual 12");
+    check(!n2.lessThanOrEqual(p1), "lessThanOrEqual 13");
+    check(!n1.lessThanOrEqual(p2), "lessThanOrEqual 14");
+    check(!n2.lessThanOrEqual(p2), "lessThanOrEqual 15");
+    check(!n2.lessThanOrEqual(n1), "lessThanOrEqual 16");
+
+    // greaterThan positive tests
+    check(n2.greaterThan(p1), "greaterThan 1");
+    check(n2.greaterThan(p2), "greaterThan 2");
+    check(n2.greaterThan(n1), "greaterThan 3");
+    check(n1.greaterThan(p1), "greaterThan 4");
+    check(n1.greaterThan(p2), "greaterThan 5");
+    check(p2.greaterThan(p1), "greaterThan 6");
+
+    // greaterThan negative tests
+    check(!p1.greaterThan(p1), "greaterThan 7");
+    check(!p2.greaterThan(p2), "greaterThan 8");
+    check(!n1.greaterThan(n1), "greaterThan 9");
+    check(!n2.greaterThan(n2), "greaterThan 10");
+
+    check(!p1.greaterThan(n2), "greaterThan 11");
+    check(!p2.greaterThan(n2), "greaterThan 12");
+    check(!n1.greaterThan(n2), "greaterThan 13");
+    check(!p1.greaterThan(n1), "greaterThan 14");
+    check(!p2.greaterThan(n1), "greaterThan 15");
+    check(!p1.greaterThan(p2), "greaterThan 16");
+
+    // greaterThanOrEqual positive tests
+    check(p1.greaterThanOrEqual(p1), "greaterThanOrEqual 1");
+    check(p2.greaterThanOrEqual(p2), "greaterThanOrEqual 2");
+    check(n1.greaterThanOrEqual(n1), "greaterThanOrEqual 3");
+    check(n2.greaterThanOrEqual(n2), "greaterThanOrEqual 4");
+
+    check(n2.greaterThanOrEqual(p1), "greaterThanOrEqual 5");
+    check(n2.greaterThanOrEqual(p2), "greaterThanOrEqual 6");
+    check(n2.greaterThanOrEqual(n1), "greaterThanOrEqual 7");
+    check(n1.greaterThanOrEqual(p1), "greaterThanOrEqual 8");
+    check(n1.greaterThanOrEqual(p2), "greaterThanOrEqual 9");
+    check(p2.greaterThanOrEqual(p1), "greaterThanOrEqual 10");
+
+    // greaterThanOrEqual negative tests
+    check(!p1.greaterThanOrEqual(n2), "greaterThanOrEqual 11");
+    check(!p2.greaterThanOrEqual(n2), "greaterThanOrEqual 12");
+    check(!n1.greaterThanOrEqual(n2), "greaterThanOrEqual 13");
+    check(!p1.greaterThanOrEqual(n1), "greaterThanOrEqual 14");
+    check(!p2.greaterThanOrEqual(n1), "greaterThanOrEqual 15");
+    check(!p1.greaterThanOrEqual(p2), "greaterThanOrEqual 16");
+
+    System.err.println("BsdAddress: all tests passed successfully.");
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java
new file mode 100644
index 0000000..92f7bbf
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import java.io.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.debugger.amd64.*;
+import sun.jvm.hotspot.debugger.bsd.x86.*;
+import sun.jvm.hotspot.debugger.bsd.amd64.*;
+import sun.jvm.hotspot.utilities.*;
+
+class BsdCDebugger implements CDebugger {
+  private BsdDebugger dbg;
+
+  BsdCDebugger(BsdDebugger dbg) {
+    this.dbg = dbg;
+  }
+
+  public List getThreadList() throws DebuggerException {
+    return dbg.getThreadList();
+  }
+
+  public List/*<LoadObject>*/ getLoadObjectList() throws DebuggerException {
+    return dbg.getLoadObjectList();
+  }
+
+  public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {
+    if (pc == null) {
+      return null;
+    }
+    List objs = getLoadObjectList();
+    Object[] arr = objs.toArray();
+    // load objects are sorted by base address, do binary search
+    int mid  = -1;
+    int low  = 0;
+    int high = arr.length - 1;
+
+    while (low <= high) {
+       mid = (low + high) >> 1;
+       LoadObject midVal = (LoadObject) arr[mid];
+       long cmp = pc.minus(midVal.getBase());
+       if (cmp < 0) {
+          high = mid - 1;
+       } else if (cmp > 0) {
+          long size = midVal.getSize();
+          if (cmp >= size) {
+             low = mid + 1;
+          } else {
+             return (LoadObject) arr[mid];
+          }
+       } else { // match found
+          return (LoadObject) arr[mid];
+       }
+    }
+    // no match found.
+    return null;
+  }
+
+  public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {
+    String cpu = dbg.getCPU();
+    if (cpu.equals("x86")) {
+       X86ThreadContext context = (X86ThreadContext) thread.getContext();
+       Address ebp = context.getRegisterAsAddress(X86ThreadContext.EBP);
+       if (ebp == null) return null;
+       Address pc  = context.getRegisterAsAddress(X86ThreadContext.EIP);
+       if (pc == null) return null;
+       return new BsdX86CFrame(dbg, ebp, pc);
+    } else if (cpu.equals("amd64")) {
+       AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
+       Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
+       if (rbp == null) return null;
+       Address pc  = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
+       if (pc == null) return null;
+       return new BsdAMD64CFrame(dbg, rbp, pc);
+    } else {
+       throw new DebuggerException(cpu + " is not yet supported");
+    }
+  }
+
+  public String getNameOfFile(String fileName) {
+    return new File(fileName).getName();
+  }
+
+  public ProcessControl getProcessControl() throws DebuggerException {
+    // FIXME: after stabs parser
+    return null;
+  }
+
+  public boolean canDemangle() {
+    return false;
+  }
+
+  public String demangle(String sym) {
+    throw new UnsupportedOperationException();
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java
new file mode 100644
index 0000000..a708a75
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import java.util.List;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+
+/** An extension of the JVMDebugger interface with a few additions to
+    support 32-bit vs. 64-bit debugging as well as features required
+    by the architecture-specific subpackages. */
+
+public interface BsdDebugger extends JVMDebugger {
+  public String       addressValueToString(long address) throws DebuggerException;
+  public boolean      readJBoolean(long address) throws DebuggerException;
+  public byte         readJByte(long address) throws DebuggerException;
+  public char         readJChar(long address) throws DebuggerException;
+  public double       readJDouble(long address) throws DebuggerException;
+  public float        readJFloat(long address) throws DebuggerException;
+  public int          readJInt(long address) throws DebuggerException;
+  public long         readJLong(long address) throws DebuggerException;
+  public short        readJShort(long address) throws DebuggerException;
+  public long         readCInteger(long address, long numBytes, boolean isUnsigned)
+    throws DebuggerException;
+  public BsdAddress readAddress(long address) throws DebuggerException;
+  public BsdAddress readCompOopAddress(long address) throws DebuggerException;
+  public BsdOopHandle readOopHandle(long address) throws DebuggerException;
+  public BsdOopHandle readCompOopHandle(long address) throws DebuggerException;
+  public long[]       getThreadIntegerRegisterSet(int lwp_id) throws DebuggerException;
+  public long         getAddressValue(Address addr) throws DebuggerException;
+  public Address      newAddress(long value) throws DebuggerException;
+
+  // For BsdCDebugger
+  public List         getThreadList();
+  public List         getLoadObjectList();
+  public ClosestSymbol lookup(long address);
+
+  // NOTE: this interface implicitly contains the following methods:
+  // From the Debugger interface via JVMDebugger
+  //   public void attach(int processID) throws DebuggerException;
+  //   public void attach(String executableName, String coreFileName) throws DebuggerException;
+  //   public boolean detach();
+  //   public Address parseAddress(String addressString) throws NumberFormatException;
+  //   public String getOS();
+  //   public String getCPU();
+  // From the SymbolLookup interface via Debugger and JVMDebugger
+  //   public Address lookup(String objectName, String symbol);
+  //   public OopHandle lookupOop(String objectName, String symbol);
+  // From the JVMDebugger interface
+  //   public void configureJavaPrimitiveTypeSizes(long jbooleanSize,
+  //                                               long jbyteSize,
+  //                                               long jcharSize,
+  //                                               long jdoubleSize,
+  //                                               long jfloatSize,
+  //                                               long jintSize,
+  //                                               long jlongSize,
+  //                                               long jshortSize);
+  // From the ThreadAccess interface via Debugger and JVMDebugger
+  //   public ThreadProxy getThreadForIdentifierAddress(Address addr);
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java
new file mode 100644
index 0000000..13785ef
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java
@@ -0,0 +1,597 @@
+/*
+ * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.utilities.*;
+import java.lang.reflect.*;
+
+/** <P> An implementation of the JVMDebugger interface. The basic debug
+    facilities are implemented through ptrace interface in the JNI code
+    (libsaproc.so). Library maps and symbol table management are done in
+    JNI. </P>
+
+    <P> <B>NOTE</B> that since we have the notion of fetching "Java
+    primitive types" from the remote process (which might have
+    different sizes than we expect) we have a bootstrapping
+    problem. We need to know the sizes of these types before we can
+    fetch them. The current implementation solves this problem by
+    requiring that it be configured with these type sizes before they
+    can be fetched. The readJ(Type) routines here will throw a
+    RuntimeException if they are called before the debugger is
+    configured with the Java primitive type sizes. </P> */
+
+public class BsdDebuggerLocal extends DebuggerBase implements BsdDebugger {
+    private boolean useGCC32ABI;
+    private boolean attached;
+    private long    p_ps_prochandle; // native debugger handle
+    private long    symbolicator; // macosx symbolicator handle
+    private long    task; // macosx task handle
+    private boolean isCore;
+
+    // CDebugger support
+    private BsdCDebugger cdbg;
+
+    // threadList and loadObjectList are filled by attach0 method
+    private List threadList;
+    private List loadObjectList;
+
+    // called by native method lookupByAddress0
+    private ClosestSymbol createClosestSymbol(String name, long offset) {
+       return new ClosestSymbol(name, offset);
+    }
+
+    // called by native method attach0
+    private LoadObject createLoadObject(String fileName, long textsize,
+                                        long base) {
+       File f = new File(fileName);
+       Address baseAddr = newAddress(base);
+       return new SharedObject(this, fileName, f.length(), baseAddr);
+    }
+
+    // native methods
+
+    private native static void init0()
+                                throws DebuggerException;
+    private native void attach0(int pid)
+                                throws DebuggerException;
+    private native void attach0(String execName, String coreName)
+                                throws DebuggerException;
+    private native void detach0()
+                                throws DebuggerException;
+    private native long lookupByName0(String objectName, String symbol)
+                                throws DebuggerException;
+    private native ClosestSymbol lookupByAddress0(long address)
+                                throws DebuggerException;
+    private native long[] getThreadIntegerRegisterSet0(int lwp_id)
+                                throws DebuggerException;
+    private native byte[] readBytesFromProcess0(long address, long numBytes)
+                                throws DebuggerException;
+    public native static int  getAddressSize() ;
+
+    // Note on Bsd threads are really processes. When target process is
+    // attached by a serviceability agent thread, only that thread can do
+    // ptrace operations on the target. This is because from kernel's point
+    // view, other threads are just separate processes and they are not
+    // attached to the target. When they attempt to make ptrace calls,
+    // an ESRCH error will be returned as kernel believes target is not
+    // being traced by the caller.
+    // To work around the problem, we use a worker thread here to handle
+    // all JNI functions that are making ptrace calls.
+
+    interface WorkerThreadTask {
+       public void doit(BsdDebuggerLocal debugger) throws DebuggerException;
+    }
+
+    class BsdDebuggerLocalWorkerThread extends Thread {
+       BsdDebuggerLocal debugger;
+       WorkerThreadTask task;
+       DebuggerException lastException;
+
+       public BsdDebuggerLocalWorkerThread(BsdDebuggerLocal debugger) {
+         this.debugger = debugger;
+         setDaemon(true);
+       }
+
+       public void run() {
+          synchronized (workerThread) {
+             for (;;) {
+                if (task != null) {
+                   lastException = null;
+                   try {
+                      task.doit(debugger);
+                   } catch (DebuggerException exp) {
+                      lastException = exp;
+                   }
+                   task = null;
+                   workerThread.notifyAll();
+                }
+
+                try {
+                   workerThread.wait();
+                } catch (InterruptedException x) {}
+             }
+          }
+       }
+
+       public WorkerThreadTask execute(WorkerThreadTask task) throws DebuggerException {
+          synchronized (workerThread) {
+             this.task = task;
+             workerThread.notifyAll();
+             while (this.task != null) {
+                try {
+                   workerThread.wait();
+                } catch (InterruptedException x) {}
+             }
+             if (lastException != null) {
+                throw new DebuggerException(lastException);
+             } else {
+                return task;
+             }
+          }
+       }
+    }
+
+    private BsdDebuggerLocalWorkerThread workerThread = null;
+
+    //----------------------------------------------------------------------
+    // Implementation of Debugger interface
+    //
+
+    /** <P> machDesc may not be null. </P>
+
+    <P> useCache should be set to true if debugging is being done
+    locally, and to false if the debugger is being created for the
+    purpose of supporting remote debugging. </P> */
+    public BsdDebuggerLocal(MachineDescription machDesc,
+                              boolean useCache) throws DebuggerException {
+        this.machDesc = machDesc;
+        utils = new DebuggerUtilities(machDesc.getAddressSize(),
+                                      machDesc.isBigEndian()) {
+           public void checkAlignment(long address, long alignment) {
+             // Need to override default checkAlignment because we need to
+             // relax alignment constraints on Bsd/x86
+             if ( (address % alignment != 0)
+                &&(alignment != 8 || address % 4 != 0)) {
+                throw new UnalignedAddressException(
+                        "Trying to read at address: "
+                      + addressValueToString(address)
+                      + " with alignment: " + alignment,
+                        address);
+             }
+           }
+        };
+
+        if (useCache) {
+            // FIXME: re-test necessity of cache on Bsd, where data
+            // fetching is faster
+            // Cache portion of the remote process's address space.
+            // Fetching data over the socket connection to dbx is slow.
+            // Might be faster if we were using a binary protocol to talk to
+            // dbx, but would have to test. For now, this cache works best
+            // if it covers the entire heap of the remote process. FIXME: at
+            // least should make this tunable from the outside, i.e., via
+            // the UI. This is a cache of 4096 4K pages, or 16 MB. The page
+            // size must be adjusted to be the hardware's page size.
+            // (FIXME: should pick this up from the debugger.)
+            if (getCPU().equals("ia64")) {
+              initCache(16384, parseCacheNumPagesProperty(1024));
+            } else {
+              initCache(4096, parseCacheNumPagesProperty(4096));
+            }
+        }
+
+        workerThread = new BsdDebuggerLocalWorkerThread(this);
+        workerThread.start();
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public boolean hasProcessList() throws DebuggerException {
+        return false;
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public List getProcessList() throws DebuggerException {
+        throw new DebuggerException("getProcessList not implemented yet");
+    }
+
+    private void checkAttached() throws DebuggerException {
+        if (attached) {
+            if (isCore) {
+                throw new DebuggerException("attached to a core dump already");
+            } else {
+                throw new DebuggerException("attached to a process already");
+            }
+        }
+    }
+
+    private void requireAttach() {
+        if (! attached) {
+            throw new RuntimeException("not attached to a process or a core!");
+        }
+    }
+
+    /* called from attach methods */
+    private void findABIVersion() throws DebuggerException {
+        if (lookupByName0("libjvm.so", "__vt_10JavaThread") != 0 ||
+            lookupByName0("libjvm_g.so", "__vt_10JavaThread") != 0) {
+            // old C++ ABI
+            useGCC32ABI = false;
+        } else {
+            // new C++ ABI
+            useGCC32ABI = true;
+        }
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public synchronized void attach(int processID) throws DebuggerException {
+        checkAttached();
+        threadList = new ArrayList();
+        loadObjectList = new ArrayList();
+        class AttachTask implements WorkerThreadTask {
+           int pid;
+           public void doit(BsdDebuggerLocal debugger) {
+              debugger.attach0(pid);
+              debugger.attached = true;
+              debugger.isCore = false;
+              findABIVersion();
+           }
+        }
+
+        AttachTask task = new AttachTask();
+        task.pid = processID;
+        workerThread.execute(task);
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public synchronized void attach(String execName, String coreName) {
+        checkAttached();
+        threadList = new ArrayList();
+        loadObjectList = new ArrayList();
+        attach0(execName, coreName);
+        attached = true;
+        isCore = true;
+        findABIVersion();
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public synchronized boolean detach() {
+        if (!attached) {
+            return false;
+        }
+
+        threadList = null;
+        loadObjectList = null;
+
+        if (isCore) {
+            detach0();
+            attached = false;
+            return true;
+        } else {
+            class DetachTask implements WorkerThreadTask {
+                boolean result = false;
+
+                public void doit(BsdDebuggerLocal debugger) {
+                    debugger.detach0();
+                    debugger.attached = false;
+                    result = true;
+                }
+            }
+
+            DetachTask task = new DetachTask();
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public Address parseAddress(String addressString)
+            throws NumberFormatException {
+        long addr = utils.scanAddress(addressString);
+        if (addr == 0) {
+            return null;
+        }
+        return new BsdAddress(this, addr);
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public String getOS() {
+        return PlatformInfo.getOS();
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public String getCPU() {
+        return PlatformInfo.getCPU();
+    }
+
+    public boolean hasConsole() throws DebuggerException {
+        return false;
+    }
+
+    public String consoleExecuteCommand(String cmd) throws DebuggerException {
+        throw new DebuggerException("No debugger console available on Bsd");
+    }
+
+    public String getConsolePrompt() throws DebuggerException {
+        return null;
+    }
+
+    /* called from lookup */
+    private long handleGCC32ABI(long addr, String symbol) throws DebuggerException {
+        if (useGCC32ABI && symbol.startsWith("_ZTV")) {
+            return addr + (2 * machDesc.getAddressSize());
+        } else {
+            return addr;
+        }
+    }
+
+    /** From the SymbolLookup interface via Debugger and JVMDebugger */
+    public synchronized Address lookup(String objectName, String symbol) {
+        requireAttach();
+        if (!attached) {
+            return null;
+        }
+
+        if (isCore) {
+            long addr = lookupByName0(objectName, symbol);
+            return (addr == 0)? null : new BsdAddress(this, handleGCC32ABI(addr, symbol));
+        } else {
+            class LookupByNameTask implements WorkerThreadTask {
+                String objectName, symbol;
+                Address result;
+
+                public void doit(BsdDebuggerLocal debugger) {
+                    long addr = debugger.lookupByName0(objectName, symbol);
+                    result = (addr == 0 ? null : new BsdAddress(debugger, handleGCC32ABI(addr, symbol)));
+                }
+            }
+
+            LookupByNameTask task = new LookupByNameTask();
+            task.objectName = objectName;
+            task.symbol = symbol;
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    /** From the SymbolLookup interface via Debugger and JVMDebugger */
+    public synchronized OopHandle lookupOop(String objectName, String symbol) {
+        Address addr = lookup(objectName, symbol);
+        if (addr == null) {
+            return null;
+        }
+        return addr.addOffsetToAsOopHandle(0);
+    }
+
+    /** From the Debugger interface */
+    public MachineDescription getMachineDescription() {
+        return machDesc;
+    }
+
+    //----------------------------------------------------------------------
+    // Implementation of ThreadAccess interface
+    //
+
+    /** From the ThreadAccess interface via Debugger and JVMDebugger */
+    public ThreadProxy getThreadForIdentifierAddress(Address addr) {
+        return new BsdThread(this, addr);
+    }
+
+    /** From the ThreadAccess interface via Debugger and JVMDebugger */
+    public ThreadProxy getThreadForThreadId(long id) {
+        return new BsdThread(this, id);
+    }
+
+    //----------------------------------------------------------------------
+    // Internal routines (for implementation of BsdAddress).
+    // These must not be called until the MachineDescription has been set up.
+    //
+
+    /** From the BsdDebugger interface */
+    public String addressValueToString(long address) {
+        return utils.addressValueToString(address);
+    }
+
+    /** From the BsdDebugger interface */
+    public BsdAddress readAddress(long address)
+            throws UnmappedAddressException, UnalignedAddressException {
+        long value = readAddressValue(address);
+        return (value == 0 ? null : new BsdAddress(this, value));
+    }
+    public BsdAddress readCompOopAddress(long address)
+            throws UnmappedAddressException, UnalignedAddressException {
+        long value = readCompOopAddressValue(address);
+        return (value == 0 ? null : new BsdAddress(this, value));
+    }
+
+    /** From the BsdDebugger interface */
+    public BsdOopHandle readOopHandle(long address)
+            throws UnmappedAddressException, UnalignedAddressException,
+                NotInHeapException {
+        long value = readAddressValue(address);
+        return (value == 0 ? null : new BsdOopHandle(this, value));
+    }
+    public BsdOopHandle readCompOopHandle(long address)
+            throws UnmappedAddressException, UnalignedAddressException,
+                NotInHeapException {
+        long value = readCompOopAddressValue(address);
+        return (value == 0 ? null : new BsdOopHandle(this, value));
+    }
+
+    //----------------------------------------------------------------------
+    // Thread context access
+    //
+
+    public synchronized long[] getThreadIntegerRegisterSet(int lwp_id)
+                                            throws DebuggerException {
+        requireAttach();
+        if (isCore) {
+            return getThreadIntegerRegisterSet0(lwp_id);
+        } else {
+            class GetThreadIntegerRegisterSetTask implements WorkerThreadTask {
+                int lwp_id;
+                long[] result;
+                public void doit(BsdDebuggerLocal debugger) {
+                    result = debugger.getThreadIntegerRegisterSet0(lwp_id);
+                }
+            }
+
+            GetThreadIntegerRegisterSetTask task = new GetThreadIntegerRegisterSetTask();
+            task.lwp_id = lwp_id;
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    /** Need to override this to relax alignment checks on x86. */
+    public long readCInteger(long address, long numBytes, boolean isUnsigned)
+        throws UnmappedAddressException, UnalignedAddressException {
+        // Only slightly relaxed semantics -- this is a hack, but is
+        // necessary on x86 where it seems the compiler is
+        // putting some global 64-bit data on 32-bit boundaries
+        if (numBytes == 8) {
+            utils.checkAlignment(address, 4);
+        } else {
+            utils.checkAlignment(address, numBytes);
+        }
+        byte[] data = readBytes(address, numBytes);
+        return utils.dataToCInteger(data, isUnsigned);
+    }
+
+    // Overridden from DebuggerBase because we need to relax alignment
+    // constraints on x86
+    public long readJLong(long address)
+        throws UnmappedAddressException, UnalignedAddressException {
+        utils.checkAlignment(address, jintSize);
+        byte[] data = readBytes(address, jlongSize);
+        return utils.dataToJLong(data, jlongSize);
+    }
+
+    //----------------------------------------------------------------------
+    // Address access. Can not be package private, but should only be
+    // accessed by the architecture-specific subpackages.
+
+    /** From the BsdDebugger interface */
+    public long getAddressValue(Address addr) {
+      if (addr == null) return 0;
+      return ((BsdAddress) addr).getValue();
+    }
+
+    /** From the BsdDebugger interface */
+    public Address newAddress(long value) {
+      if (value == 0) return null;
+      return new BsdAddress(this, value);
+    }
+
+    /** From the BsdCDebugger interface */
+    public List/*<ThreadProxy>*/ getThreadList() {
+      requireAttach();
+      return threadList;
+    }
+
+    /** From the BsdCDebugger interface */
+    public List/*<LoadObject>*/ getLoadObjectList() {
+      requireAttach();
+      return loadObjectList;
+    }
+
+    /** From the BsdCDebugger interface */
+    public synchronized ClosestSymbol lookup(long addr) {
+       requireAttach();
+       if (isCore) {
+          return lookupByAddress0(addr);
+       } else {
+          class LookupByAddressTask implements WorkerThreadTask {
+             long addr;
+             ClosestSymbol result;
+
+             public void doit(BsdDebuggerLocal debugger) {
+                 result = debugger.lookupByAddress0(addr);
+             }
+          }
+
+          LookupByAddressTask task = new LookupByAddressTask();
+          task.addr = addr;
+          workerThread.execute(task);
+          return task.result;
+       }
+    }
+
+    public CDebugger getCDebugger() {
+      if (cdbg == null) {
+         String cpu = getCPU();
+         if (cpu.equals("ia64") ) {
+            // IA-64 is not supported because of stack-walking issues
+            return null;
+         }
+         cdbg = new BsdCDebugger(this);
+      }
+      return cdbg;
+    }
+
+    /** This reads bytes from the remote process. */
+    public synchronized ReadResult readBytesFromProcess(long address,
+            long numBytes) throws UnmappedAddressException, DebuggerException {
+        requireAttach();
+        if (isCore) {
+            byte[] res = readBytesFromProcess0(address, numBytes);
+            return (res != null)? new ReadResult(res) : new ReadResult(address);
+        } else {
+            class ReadBytesFromProcessTask implements WorkerThreadTask {
+                long address, numBytes;
+                ReadResult result;
+                public void doit(BsdDebuggerLocal debugger) {
+                    byte[] res = debugger.readBytesFromProcess0(address, numBytes);
+                    if (res != null)
+                        result = new ReadResult(res);
+                    else
+                        result = new ReadResult(address);
+                }
+            }
+
+            ReadBytesFromProcessTask task = new ReadBytesFromProcessTask();
+            task.address = address;
+            task.numBytes = numBytes;
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    public void writeBytesToProcess(long address, long numBytes, byte[] data)
+        throws UnmappedAddressException, DebuggerException {
+        // FIXME
+        throw new DebuggerException("Unimplemented");
+    }
+
+    static {
+        System.loadLibrary("saproc");
+        init0();
+    }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdOopHandle.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdOopHandle.java
new file mode 100644
index 0000000..9df0e2f
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdOopHandle.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+
+class BsdOopHandle extends BsdAddress implements OopHandle {
+  BsdOopHandle(BsdDebugger debugger, long addr) {
+    super(debugger, addr);
+  }
+
+  public boolean equals(Object arg) {
+    if (arg == null) {
+      return false;
+    }
+
+    if (!(arg instanceof BsdOopHandle)) {
+      return false;
+    }
+
+    return (addr == ((BsdAddress) arg).addr);
+  }
+
+  public Address    addOffsetTo       (long offset) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("addOffsetTo not applicable to OopHandles (interior object pointers not allowed)");
+  }
+
+  public Address    andWithMask(long mask) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("andWithMask not applicable to OopHandles (i.e., anything but C addresses)");
+  }
+
+  public Address    orWithMask(long mask) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("orWithMask not applicable to OopHandles (i.e., anything but C addresses)");
+  }
+
+  public Address    xorWithMask(long mask) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("xorWithMask not applicable to OopHandles (i.e., anything but C addresses)");
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java
new file mode 100644
index 0000000..b7c507c
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+
+class BsdThread implements ThreadProxy {
+    private BsdDebugger debugger;
+    private int           lwp_id;
+
+    /** The address argument must be the address of the _thread_id in the
+        OSThread. It's value is result ::gettid() call. */
+    BsdThread(BsdDebugger debugger, Address addr) {
+        this.debugger = debugger;
+        // FIXME: size of data fetched here should be configurable.
+        // However, making it so would produce a dependency on the "types"
+        // package from the debugger package, which is not desired.
+        this.lwp_id = (int) addr.getCIntegerAt(0, 4, true);
+    }
+
+    BsdThread(BsdDebugger debugger, long id) {
+        this.debugger = debugger;
+        this.lwp_id = (int) id;
+    }
+
+    public boolean equals(Object obj) {
+        if ((obj == null) || !(obj instanceof BsdThread)) {
+            return false;
+        }
+
+        return (((BsdThread) obj).lwp_id == lwp_id);
+    }
+
+    public int hashCode() {
+        return lwp_id;
+    }
+
+    public String toString() {
+        return Integer.toString(lwp_id);
+    }
+
+    public ThreadContext getContext() throws IllegalThreadStateException {
+        long[] data = debugger.getThreadIntegerRegisterSet(lwp_id);
+        ThreadContext context = BsdThreadContextFactory.createThreadContext(debugger);
+        for (int i = 0; i < data.length; i++) {
+            context.setRegister(i, data[i]);
+        }
+        return context;
+    }
+
+    public boolean canSetContext() throws DebuggerException {
+        return false;
+    }
+
+    public void setContext(ThreadContext context)
+      throws IllegalThreadStateException, DebuggerException {
+        throw new DebuggerException("Unimplemented");
+    }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThreadContextFactory.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThreadContextFactory.java
new file mode 100644
index 0000000..8c13ada
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThreadContextFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.amd64.*;
+import sun.jvm.hotspot.debugger.bsd.x86.*;
+
+class BsdThreadContextFactory {
+   static ThreadContext createThreadContext(BsdDebugger dbg) {
+      String cpu = dbg.getCPU();
+      if (cpu.equals("x86")) {
+         return new BsdX86ThreadContext(dbg);
+      } else if (cpu.equals("amd64")) {
+         return new BsdAMD64ThreadContext(dbg);
+      } else {
+         throw new RuntimeException("cpu " + cpu + " is not yet supported");
+      }
+   }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/SharedObject.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/SharedObject.java
new file mode 100644
index 0000000..2f72f7d
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/SharedObject.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.posix.*;
+
+/** A Object can represent either a .so or an a.out file. */
+
+class SharedObject extends DSO {
+  SharedObject(BsdDebugger dbg, String filename, long size, Address relocation) {
+    super(filename, size, relocation);
+    this.dbg     = dbg;
+  }
+
+  protected Address newAddress(long address) {
+    return dbg.newAddress(address);
+  }
+
+  protected long getAddressValue(Address addr) {
+    return dbg.getAddressValue(addr);
+  }
+
+  private BsdDebugger   dbg;
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64CFrame.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64CFrame.java
new file mode 100644
index 0000000..b27a539
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64CFrame.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd.amd64;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.cdbg.basic.*;
+
+final public class BsdAMD64CFrame extends BasicCFrame {
+   public BsdAMD64CFrame(BsdDebugger dbg, Address rbp, Address rip) {
+      super(dbg.getCDebugger());
+      this.rbp = rbp;
+      this.rip = rip;
+      this.dbg = dbg;
+   }
+
+   // override base class impl to avoid ELF parsing
+   public ClosestSymbol closestSymbolToPC() {
+      // try native lookup in debugger.
+      return dbg.lookup(dbg.getAddressValue(pc()));
+   }
+
+   public Address pc() {
+      return rip;
+   }
+
+   public Address localVariableBase() {
+      return rbp;
+   }
+
+   public CFrame sender() {
+      if (rbp == null) {
+        return null;
+      }
+
+      Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE);
+      if (nextRBP == null) {
+        return null;
+      }
+      Address nextPC  = rbp.getAddressAt( 1 * ADDRESS_SIZE);
+      if (nextPC == null) {
+        return null;
+      }
+      return new BsdAMD64CFrame(dbg, nextRBP, nextPC);
+   }
+
+   // package/class internals only
+   private static final int ADDRESS_SIZE = 8;
+   private Address rip;
+   private Address rbp;
+   private BsdDebugger dbg;
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64ThreadContext.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64ThreadContext.java
new file mode 100644
index 0000000..a9ebf83
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64ThreadContext.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd.amd64;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.amd64.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+
+public class BsdAMD64ThreadContext extends AMD64ThreadContext {
+  private BsdDebugger debugger;
+
+  public BsdAMD64ThreadContext(BsdDebugger debugger) {
+    super();
+    this.debugger = debugger;
+  }
+
+  public void setRegisterAsAddress(int index, Address value) {
+    setRegister(index, debugger.getAddressValue(value));
+  }
+
+  public Address getRegisterAsAddress(int index) {
+    return debugger.newAddress(getRegister(index));
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86CFrame.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86CFrame.java
new file mode 100644
index 0000000..40292b9
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86CFrame.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd.x86;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.cdbg.basic.*;
+
+final public class BsdX86CFrame extends BasicCFrame {
+   // package/class internals only
+   public BsdX86CFrame(BsdDebugger dbg, Address ebp, Address pc) {
+      super(dbg.getCDebugger());
+      this.ebp = ebp;
+      this.pc = pc;
+      this.dbg = dbg;
+   }
+
+   // override base class impl to avoid ELF parsing
+   public ClosestSymbol closestSymbolToPC() {
+      // try native lookup in debugger.
+      return dbg.lookup(dbg.getAddressValue(pc()));
+   }
+
+   public Address pc() {
+      return pc;
+   }
+
+   public Address localVariableBase() {
+      return ebp;
+   }
+
+   public CFrame sender() {
+      if (ebp == null) {
+        return null;
+      }
+
+      Address nextEBP = ebp.getAddressAt( 0 * ADDRESS_SIZE);
+      if (nextEBP == null) {
+        return null;
+      }
+      Address nextPC  = ebp.getAddressAt( 1 * ADDRESS_SIZE);
+      if (nextPC == null) {
+        return null;
+      }
+      return new BsdX86CFrame(dbg, nextEBP, nextPC);
+   }
+
+   private static final int ADDRESS_SIZE = 4;
+   private Address pc;
+   private Address ebp;
+   private BsdDebugger dbg;
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86ThreadContext.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86ThreadContext.java
new file mode 100644
index 0000000..8eaca2b
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86ThreadContext.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.debugger.bsd.x86;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+
+public class BsdX86ThreadContext extends X86ThreadContext {
+  private BsdDebugger debugger;
+
+  public BsdX86ThreadContext(BsdDebugger debugger) {
+    super();
+    this.debugger = debugger;
+  }
+
+  public void setRegisterAsAddress(int index, Address value) {
+    setRegister(index, debugger.getAddressValue(value));
+  }
+
+  public Address getRegisterAsAddress(int index) {
+    return debugger.newAddress(getRegister(index));
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java
index d90d08b..44ce898 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java
@@ -37,6 +37,8 @@
 import sun.jvm.hotspot.runtime.linux_ia64.LinuxIA64JavaThreadPDAccess;
 import sun.jvm.hotspot.runtime.linux_amd64.LinuxAMD64JavaThreadPDAccess;
 import sun.jvm.hotspot.runtime.linux_sparc.LinuxSPARCJavaThreadPDAccess;
+import sun.jvm.hotspot.runtime.bsd_x86.BsdX86JavaThreadPDAccess;
+import sun.jvm.hotspot.runtime.bsd_amd64.BsdAMD64JavaThreadPDAccess;
 import sun.jvm.hotspot.utilities.*;
 
 public class Threads {
@@ -90,7 +92,12 @@
             } else if (cpu.equals("sparc")) {
                 access = new LinuxSPARCJavaThreadPDAccess();
             }
-
+        } else if (os.equals("bsd")) {
+            if (cpu.equals("x86")) {
+                access = new BsdX86JavaThreadPDAccess();
+            } else if (cpu.equals("amd64")) {
+                access = new BsdAMD64JavaThreadPDAccess();
+            }
         }
 
         if (access == null) {
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd/BsdSignals.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd/BsdSignals.java
new file mode 100644
index 0000000..6887c47
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd/BsdSignals.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.runtime.bsd;
+
+public class BsdSignals {
+  private static String[] signalNames = {
+    "",           /* No signal 0 */
+    "SIGHUP",     /* hangup */
+    "SIGINT",     /* interrupt */
+    "SIGQUIT",    /* quit */
+    "SIGILL",     /* illegal instr. (not reset when caught) */
+    "SIGTRAP",    /* trace trap (not reset when caught) */
+    "SIGABRT",    /* abort() */
+    "SIGEMT",     /* EMT instruction */
+    "SIGFPE",     /* floating point exception */
+    "SIGKILL",    /* kill (cannot be caught or ignored) */
+    "SIGBUS",     /* bus error */
+    "SIGSEGV",    /* segmentation violation */
+    "SIGSYS",     /* non-existent system call invoked */
+    "SIGPIPE",    /* write on a pipe with no one to read it */
+    "SIGALRM",    /* alarm clock */
+    "SIGTERM",    /* software termination signal from kill */
+    "SIGURG",     /* urgent condition on IO channel */
+    "SIGSTOP",    /* sendable stop signal not from tty */
+    "SIGTSTP",    /* stop signal from tty */
+    "SIGCONT",    /* continue a stopped process */
+    "SIGCHLD",    /* to parent on child stop or exit */
+    "SIGTTIN",    /* to readers pgrp upon background tty read */
+    "SIGTTOU",    /* like TTIN if (tp->t_local&LTOSTOP) */
+    "SIGIO",      /* input/output possible signal */
+    "SIGXCPU",    /* exceeded CPU time limit */
+    "SIGXFSZ",    /* exceeded file size limit */
+    "SIGVTALRM",  /* virtual time alarm */
+    "SIGPROF",    /* profiling time alarm */
+    "SIGWINCH",   /* window size changes */
+    "SIGINFO",    /* information request */
+    "SIGUSR1",    /* user defined signal 1 */
+    "SIGUSR2"     /* user defined signal 2 */
+  };
+
+  public static String getSignalName(int sigNum) {
+    if ((sigNum <= 0) || (sigNum >= signalNames.length)) {
+      // Probably best to fail in a non-destructive way
+      return "<Error: Illegal signal number " + sigNum + ">";
+    }
+    return signalNames[sigNum];
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java
new file mode 100644
index 0000000..c0de138
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.runtime.bsd_amd64;
+
+import java.io.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.amd64.*;
+import sun.jvm.hotspot.runtime.*;
+import sun.jvm.hotspot.runtime.amd64.*;
+import sun.jvm.hotspot.runtime.x86.*;
+import sun.jvm.hotspot.types.*;
+import sun.jvm.hotspot.utilities.*;
+
+public class BsdAMD64JavaThreadPDAccess implements JavaThreadPDAccess {
+  private static AddressField  lastJavaFPField;
+  private static AddressField  osThreadField;
+
+  // Field from OSThread
+  private static CIntegerField osThreadThreadIDField;
+
+  // This is currently unneeded but is being kept in case we change
+  // the currentFrameGuess algorithm
+  private static final long GUESS_SCAN_RANGE = 128 * 1024;
+
+  static {
+    VM.registerVMInitializedObserver(new Observer() {
+        public void update(Observable o, Object data) {
+          initialize(VM.getVM().getTypeDataBase());
+        }
+      });
+  }
+
+  private static synchronized void initialize(TypeDataBase db) {
+    Type type = db.lookupType("JavaThread");
+    osThreadField           = type.getAddressField("_osthread");
+
+    Type anchorType = db.lookupType("JavaFrameAnchor");
+    lastJavaFPField         = anchorType.getAddressField("_last_Java_fp");
+
+    Type osThreadType = db.lookupType("OSThread");
+    osThreadThreadIDField   = osThreadType.getCIntegerField("_thread_id");
+  }
+
+  public    Address getLastJavaFP(Address addr) {
+    return lastJavaFPField.getValue(addr.addOffsetTo(sun.jvm.hotspot.runtime.JavaThread.getAnchorField().getOffset()));
+  }
+
+  public    Address getLastJavaPC(Address addr) {
+    return null;
+  }
+
+  public    Address getBaseOfStackPointer(Address addr) {
+    return null;
+  }
+
+  public    Frame getLastFramePD(JavaThread thread, Address addr) {
+    Address fp = thread.getLastJavaFP();
+    if (fp == null) {
+      return null; // no information
+    }
+    return new X86Frame(thread.getLastJavaSP(), fp);
+  }
+
+  public    RegisterMap newRegisterMap(JavaThread thread, boolean updateMap) {
+    return new X86RegisterMap(thread, updateMap);
+  }
+
+  public    Frame getCurrentFrameGuess(JavaThread thread, Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    AMD64ThreadContext context = (AMD64ThreadContext) t.getContext();
+    AMD64CurrentFrameGuess guesser = new AMD64CurrentFrameGuess(context, thread);
+    if (!guesser.run(GUESS_SCAN_RANGE)) {
+      return null;
+    }
+    if (guesser.getPC() == null) {
+      return new X86Frame(guesser.getSP(), guesser.getFP());
+    } else {
+      return new X86Frame(guesser.getSP(), guesser.getFP(), guesser.getPC());
+    }
+  }
+
+  public    void printThreadIDOn(Address addr, PrintStream tty) {
+    tty.print(getThreadProxy(addr));
+  }
+
+  public    void printInfoOn(Address threadAddr, PrintStream tty) {
+    tty.print("Thread id: ");
+    printThreadIDOn(threadAddr, tty);
+//    tty.println("\nPostJavaState: " + getPostJavaState(threadAddr));
+  }
+
+  public    Address getLastSP(Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    AMD64ThreadContext context = (AMD64ThreadContext) t.getContext();
+    return context.getRegisterAsAddress(AMD64ThreadContext.RSP);
+  }
+
+  public    ThreadProxy getThreadProxy(Address addr) {
+    // Addr is the address of the JavaThread.
+    // Fetch the OSThread (for now and for simplicity, not making a
+    // separate "OSThread" class in this package)
+    Address osThreadAddr = osThreadField.getValue(addr);
+    // Get the address of the _thread_id from the OSThread
+    Address threadIdAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());
+
+    JVMDebugger debugger = VM.getVM().getDebugger();
+    return debugger.getThreadForIdentifierAddress(threadIdAddr);
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdSignals.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdSignals.java
new file mode 100644
index 0000000..703a097
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdSignals.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.runtime.bsd_x86;
+
+public class BsdSignals {
+  private static String[] signalNames = {
+    "",           /* No signal 0 */
+    "SIGHUP",     /* hangup */
+    "SIGINT",     /* interrupt */
+    "SIGQUIT",    /* quit */
+    "SIGILL",     /* illegal instr. (not reset when caught) */
+    "SIGTRAP",    /* trace trap (not reset when caught) */
+    "SIGABRT",    /* abort() */
+    "SIGEMT",     /* EMT instruction */
+    "SIGFPE",     /* floating point exception */
+    "SIGKILL",    /* kill (cannot be caught or ignored) */
+    "SIGBUS",     /* bus error */
+    "SIGSEGV",    /* segmentation violation */
+    "SIGSYS",     /* non-existent system call invoked */
+    "SIGPIPE",    /* write on a pipe with no one to read it */
+    "SIGALRM",    /* alarm clock */
+    "SIGTERM",    /* software termination signal from kill */
+    "SIGURG",     /* urgent condition on IO channel */
+    "SIGSTOP",    /* sendable stop signal not from tty */
+    "SIGTSTP",    /* stop signal from tty */
+    "SIGCONT",    /* continue a stopped process */
+    "SIGCHLD",    /* to parent on child stop or exit */
+    "SIGTTIN",    /* to readers pgrp upon background tty read */
+    "SIGTTOU",    /* like TTIN if (tp->t_local&LTOSTOP) */
+    "SIGIO",      /* input/output possible signal */
+    "SIGXCPU",    /* exceeded CPU time limit */
+    "SIGXFSZ",    /* exceeded file size limit */
+    "SIGVTALRM",  /* virtual time alarm */
+    "SIGPROF",    /* profiling time alarm */
+    "SIGWINCH",   /* window size changes */
+    "SIGINFO",    /* information request */
+    "SIGUSR1",    /* user defined signal 1 */
+    "SIGUSR2"     /* user defined signal 2 */
+  };
+
+  public static String getSignalName(int sigNum) {
+    if ((sigNum <= 0) || (sigNum >= signalNames.length)) {
+      // Probably best to fail in a non-destructive way
+      return "<Error: Illegal signal number " + sigNum + ">";
+    }
+    return signalNames[sigNum];
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdX86JavaThreadPDAccess.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdX86JavaThreadPDAccess.java
new file mode 100644
index 0000000..a32f0be
--- /dev/null
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdX86JavaThreadPDAccess.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.runtime.bsd_x86;
+
+import java.io.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.runtime.*;
+import sun.jvm.hotspot.runtime.x86.*;
+import sun.jvm.hotspot.types.*;
+import sun.jvm.hotspot.utilities.*;
+
+public class BsdX86JavaThreadPDAccess implements JavaThreadPDAccess {
+  private static AddressField  lastJavaFPField;
+  private static AddressField  osThreadField;
+
+  // Field from OSThread
+  private static CIntegerField osThreadThreadIDField;
+
+  // This is currently unneeded but is being kept in case we change
+  // the currentFrameGuess algorithm
+  private static final long GUESS_SCAN_RANGE = 128 * 1024;
+
+  static {
+    VM.registerVMInitializedObserver(new Observer() {
+        public void update(Observable o, Object data) {
+          initialize(VM.getVM().getTypeDataBase());
+        }
+      });
+  }
+
+  private static synchronized void initialize(TypeDataBase db) {
+    Type type = db.lookupType("JavaThread");
+    osThreadField           = type.getAddressField("_osthread");
+
+    Type anchorType = db.lookupType("JavaFrameAnchor");
+    lastJavaFPField         = anchorType.getAddressField("_last_Java_fp");
+
+    Type osThreadType = db.lookupType("OSThread");
+    osThreadThreadIDField   = osThreadType.getCIntegerField("_thread_id");
+  }
+
+  public    Address getLastJavaFP(Address addr) {
+    return lastJavaFPField.getValue(addr.addOffsetTo(sun.jvm.hotspot.runtime.JavaThread.getAnchorField().getOffset()));
+  }
+
+  public    Address getLastJavaPC(Address addr) {
+    return null;
+  }
+
+  public    Address getBaseOfStackPointer(Address addr) {
+    return null;
+  }
+
+  public    Frame getLastFramePD(JavaThread thread, Address addr) {
+    Address fp = thread.getLastJavaFP();
+    if (fp == null) {
+      return null; // no information
+    }
+    return new X86Frame(thread.getLastJavaSP(), fp);
+  }
+
+  public    RegisterMap newRegisterMap(JavaThread thread, boolean updateMap) {
+    return new X86RegisterMap(thread, updateMap);
+  }
+
+  public    Frame getCurrentFrameGuess(JavaThread thread, Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    X86ThreadContext context = (X86ThreadContext) t.getContext();
+    X86CurrentFrameGuess guesser = new X86CurrentFrameGuess(context, thread);
+    if (!guesser.run(GUESS_SCAN_RANGE)) {
+      return null;
+    }
+    if (guesser.getPC() == null) {
+      return new X86Frame(guesser.getSP(), guesser.getFP());
+    } else {
+      return new X86Frame(guesser.getSP(), guesser.getFP(), guesser.getPC());
+    }
+  }
+
+  public    void printThreadIDOn(Address addr, PrintStream tty) {
+    tty.print(getThreadProxy(addr));
+  }
+
+  public    void printInfoOn(Address threadAddr, PrintStream tty) {
+    tty.print("Thread id: ");
+    printThreadIDOn(threadAddr, tty);
+//    tty.println("\nPostJavaState: " + getPostJavaState(threadAddr));
+  }
+
+  public    Address getLastSP(Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    X86ThreadContext context = (X86ThreadContext) t.getContext();
+    return context.getRegisterAsAddress(X86ThreadContext.ESP);
+  }
+
+  public    ThreadProxy getThreadProxy(Address addr) {
+    // Addr is the address of the JavaThread.
+    // Fetch the OSThread (for now and for simplicity, not making a
+    // separate "OSThread" class in this package)
+    Address osThreadAddr = osThreadField.getValue(addr);
+    // Get the address of the _thread_id from the OSThread
+    Address threadIdAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());
+
+    JVMDebugger debugger = VM.getVM().getDebugger();
+    return debugger.getThreadForIdentifierAddress(threadIdAddr);
+  }
+}
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/sparc/SPARCFrame.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/sparc/SPARCFrame.java
index 3d55dab..c756ec8 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/sparc/SPARCFrame.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/sparc/SPARCFrame.java
@@ -956,7 +956,7 @@
     map.makeIntegerRegsUnsaved();
     map.shiftWindow(sp, youngerSP);
     boolean thisFrameAdjustedStack = true;  // I5_savedSP is live in this RF
-    return new SPARCFrame(sp, youngerSP, thisFrameAdjustedStack);
+    return new SPARCFrame(biasSP(sp), biasSP(youngerSP), thisFrameAdjustedStack);
   }
 
   private Frame senderForEntryFrame(RegisterMap regMap) {
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
index bbeab88..bcfc015 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
@@ -30,6 +30,7 @@
 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
 import sun.jvm.hotspot.gc_implementation.shared.*;
 import sun.jvm.hotspot.memory.*;
+import sun.jvm.hotspot.oops.*;
 import sun.jvm.hotspot.runtime.*;
 
 public class HeapSummary extends Tool {
@@ -134,6 +135,9 @@
       } else {
          throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
       }
+
+      System.out.println();
+      printInternStringStatistics();
    }
 
    // Helper methods
@@ -248,4 +252,41 @@
          return -1;
       }
    }
+
+   private void printInternStringStatistics() {
+      class StringStat implements StringTable.StringVisitor {
+         private int count;
+         private long size;
+         private OopField stringValueField;
+
+         StringStat() {
+            VM vm = VM.getVM();
+            SystemDictionary sysDict = vm.getSystemDictionary();
+            InstanceKlass strKlass = sysDict.getStringKlass();
+            // String has a field named 'value' of type 'char[]'.
+            stringValueField = (OopField) strKlass.findField("value", "[C");
+         }
+
+         private long stringSize(Instance instance) {
+            // We include String content in size calculation.
+            return instance.getObjectSize() +
+                   stringValueField.getValue(instance).getObjectSize();
+         }
+
+         public void visit(Instance str) {
+            count++;
+            size += stringSize(str);
+         }
+
+         public void print() {
+            System.out.println(count +
+                  " interned Strings occupying " + size + " bytes.");
+         }
+      }
+
+      StringStat stat = new StringStat();
+      StringTable strTable = VM.getVM().getStringTable();
+      strTable.stringsDo(stat);
+      stat.print();
+   }
 }
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/PermStat.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/PermStat.java
index 8f34967..375a58f 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/PermStat.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/PermStat.java
@@ -63,47 +63,9 @@
    }
 
    public void run() {
-      printInternStringStatistics();
       printClassLoaderStatistics();
    }
 
-   private void printInternStringStatistics() {
-      class StringStat implements StringTable.StringVisitor {
-         private int count;
-         private long size;
-         private OopField stringValueField;
-
-         StringStat() {
-            VM vm = VM.getVM();
-            SystemDictionary sysDict = vm.getSystemDictionary();
-            InstanceKlass strKlass = sysDict.getStringKlass();
-            // String has a field named 'value' of type 'char[]'.
-            stringValueField = (OopField) strKlass.findField("value", "[C");
-         }
-
-         private long stringSize(Instance instance) {
-            // We include String content in size calculation.
-            return instance.getObjectSize() +
-                   stringValueField.getValue(instance).getObjectSize();
-         }
-
-         public void visit(Instance str) {
-            count++;
-            size += stringSize(str);
-         }
-
-         public void print() {
-            System.out.println(count +
-                  " intern Strings occupying " + size + " bytes.");
-         }
-      }
-
-      StringStat stat = new StringStat();
-      StringTable strTable = VM.getVM().getStringTable();
-      strTable.stringsDo(stat);
-      stat.print();
-   }
-
    private void printClassLoaderStatistics() {
       final PrintStream out = System.out;
       final PrintStream err = System.err;
diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java
index 5e749b3..eff3405 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java
@@ -37,6 +37,14 @@
       return "solaris";
     } else if (os.equals("Linux")) {
       return "linux";
+    } else if (os.equals("FreeBSD")) {
+      return "bsd";
+    } else if (os.equals("NetBSD")) {
+      return "bsd";
+    } else if (os.equals("OpenBSD")) {
+      return "bsd";
+    } else if (os.equals("Darwin") || os.startsWith("Mac OS X")) {
+      return "bsd";
     } else if (os.startsWith("Windows")) {
       return "win32";
     } else {
diff --git a/hotspot/make/Makefile b/hotspot/make/Makefile
index dd20eee..5bef049 100644
--- a/hotspot/make/Makefile
+++ b/hotspot/make/Makefile
@@ -323,28 +323,28 @@
 ifneq ($(OSNAME),windows)
   ifeq ($(ZERO_BUILD), true)
     ifeq ($(SHARK_BUILD), true)
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(SHARK_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(SHARK_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/%.so:       $(SHARK_DIR)/%.so
+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(SHARK_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
     else
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(ZERO_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(ZERO_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/%.so:       $(ZERO_DIR)/%.so
+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(ZERO_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
     endif
   else
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(C1_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(C1_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(C2_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(C2_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_CLIENT_DIR)/%.so:       $(C1_DIR)/%.so
+$(EXPORT_CLIENT_DIR)/%.$(LIBRARY_SUFFIX):       $(C1_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_CLIENT_DIR)/64/%.so:    $(C1_DIR)/%.so
+$(EXPORT_CLIENT_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C1_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/%.so:       $(C2_DIR)/%.so
+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(C2_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/64/%.so:    $(C2_DIR)/%.so
+$(EXPORT_SERVER_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C2_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
 
 # Debug info for shared library
@@ -471,6 +471,36 @@
 	   ($(CD) $(JDK_IMAGE_DIR)/debug && $(TAR) -xf -) ; \
 	fi
 
+# macosx universal builds
+
+ifeq ($(MACOSX_UNIVERSAL), true)
+$(UNIVERSAL_LIPO_LIST):
+	lipo -create -output $@ $(EXPORT_JRE_LIB_DIR)/{i386,amd64}/$(subst $(EXPORT_JRE_LIB_DIR)/,,$@)
+
+$(UNIVERSAL_COPY_LIST):
+	$(CP) $(EXPORT_JRE_LIB_DIR)/i386/$(subst $(EXPORT_JRE_LIB_DIR)/,,$@) $@
+
+universalize: $(UNIVERSAL_LIPO_LIST) $(UNIVERSAL_COPY_LIST)
+endif
+
+universal_product:
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=32 MACOSX_UNIVERSAL=true all_product
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=64 MACOSX_UNIVERSAL=true all_product
+	$(MKDIR) -p $(EXPORT_JRE_LIB_DIR)/{client,server}
+	$(QUIETLY) $(MAKE) MACOSX_UNIVERSAL=true universalize
+
+universal_fastdebug:
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=32 MACOSX_UNIVERSAL=true all_fastdebug
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=64 MACOSX_UNIVERSAL=true all_fastdebug
+	$(MKDIR) -p $(EXPORT_JRE_LIB_DIR)/{client,server}
+	$(QUIETLY) $(MAKE) MACOSX_UNIVERSAL=true universalize
+
+universal_debug:
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=32 MACOSX_UNIVERSAL=true all_debug
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=64 MACOSX_UNIVERSAL=true all_debug
+	$(MKDIR) -p $(EXPORT_JRE_LIB_DIR)/{client,server}
+	$(QUIETLY) $(MAKE) MACOSX_UNIVERSAL=true universalize
+
 #
 # Check target
 #
@@ -599,5 +629,6 @@
 	export_product export_fastdebug export_debug export_optimized \
 	export_jdk_product export_jdk_fastdebug export_jdk_debug \
 	create_jdk copy_jdk update_jdk test_jdk \
-	copy_product_jdk copy_fastdebug_jdk copy_debug_jdk
+	copy_product_jdk copy_fastdebug_jdk copy_debug_jdk universalize \
+	universal_product
 
diff --git a/hotspot/make/bsd/Makefile b/hotspot/make/bsd/Makefile
new file mode 100644
index 0000000..cef9d7c
--- /dev/null
+++ b/hotspot/make/bsd/Makefile
@@ -0,0 +1,371 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+#
+
+# This makefile creates a build tree and lights off a build.
+# You can go back into the build tree and perform rebuilds or
+# incremental builds as desired. Be sure to reestablish
+# environment variable settings for LD_LIBRARY_PATH and JAVA_HOME.
+
+# The make process now relies on java and javac. These can be
+# specified either implicitly on the PATH, by setting the
+# (JDK-inherited) ALT_BOOTDIR environment variable to full path to a
+# JDK in which bin/java and bin/javac are present and working (e.g.,
+# /usr/local/java/jdk1.3/solaris), or via the (JDK-inherited)
+# default BOOTDIR path value. Note that one of ALT_BOOTDIR
+# or BOOTDIR has to be set. We do *not* search javac, javah, rmic etc.
+# from the PATH.
+#
+# One can set ALT_BOOTDIR or BOOTDIR to point to a jdk that runs on
+# an architecture that differs from the target architecture, as long
+# as the bootstrap jdk runs under the same flavor of OS as the target
+# (i.e., if the target is linux, point to a jdk that runs on a linux
+# box).  In order to use such a bootstrap jdk, set the make variable
+# REMOTE to the desired remote command mechanism, e.g.,
+#
+#    make REMOTE="rsh -l me myotherlinuxbox"
+
+# Along with VM, Serviceability Agent (SA) is built for SA/JDI binding.
+# JDI binding on SA produces two binaries:
+#  1. sa-jdi.jar       - This is build before building libjvm[_g].so
+#                        Please refer to ./makefiles/sa.make
+#  2. libsa[_g].so     - Native library for SA - This is built after
+#                        libjsig[_g].so (signal interposition library)
+#                        Please refer to ./makefiles/vm.make
+# If $(GAMMADIR)/agent dir is not present, SA components are not built.
+
+ifeq ($(GAMMADIR),)
+include ../../make/defs.make
+else
+include $(GAMMADIR)/make/defs.make
+endif
+include $(GAMMADIR)/make/$(OSNAME)/makefiles/rules.make
+
+ifndef CC_INTERP
+  ifndef FORCE_TIERED
+    FORCE_TIERED=1
+  endif
+endif
+
+ifdef LP64
+  ifeq ("$(filter $(LP64_ARCH),$(BUILDARCH))","")
+    _JUNK_ := $(shell echo >&2 \
+       $(OSNAME) $(ARCH) "*** ERROR: this platform does not support 64-bit compilers!")
+	@exit 1
+  endif
+endif
+
+# we need to set up LP64 correctly to satisfy sanity checks in adlc
+ifneq ("$(filter $(LP64_ARCH),$(BUILDARCH))","")
+  MFLAGS += " LP64=1 "
+endif
+
+# pass USE_SUNCC further, through MFLAGS
+ifdef USE_SUNCC
+  MFLAGS += " USE_SUNCC=1 "
+endif
+
+# The following renders pathnames in generated Makefiles valid on
+# machines other than the machine containing the build tree.
+#
+# For example, let's say my build tree lives on /files12 on
+# exact.east.sun.com.  This logic will cause GAMMADIR to begin with
+# /net/exact/files12/...
+#
+# We only do this on SunOS variants, for a couple of reasons:
+#  * It is extremely rare that source trees exist on other systems
+#  * It has been claimed that the Linux automounter is flakey, so
+#    changing GAMMADIR in a way that exercises the automounter could
+#    prove to be a source of unreliability in the build process.
+# Obviously, this Makefile is only relevant on SunOS boxes to begin
+# with, but the SunOS conditionalization will make it easier to
+# combine Makefiles in the future (assuming we ever do that).
+
+ifeq ($(OSNAME),solaris)
+
+  #   prepend current directory to relative pathnames.
+  NEW_GAMMADIR :=                                    \
+    $(shell echo $(GAMMADIR) |                       \
+      sed -e "s=^\([^/].*\)=$(shell pwd)/\1="        \
+     )
+  unexport NEW_GAMMADIR
+
+  # If NEW_GAMMADIR doesn't already start with "/net/":
+  ifeq ($(strip $(filter /net/%,$(NEW_GAMMADIR))),)
+    #   prepend /net/$(HOST)
+    #   remove /net/$(HOST) if name already began with /home/
+    #   remove /net/$(HOST) if name already began with /java/
+    #   remove /net/$(HOST) if name already began with /lab/
+    NEW_GAMMADIR :=                                     \
+         $(shell echo $(NEW_GAMMADIR) |                 \
+                 sed -e "s=^\(.*\)=/net/$(HOST)\1="     \
+                     -e "s=^/net/$(HOST)/home/=/home/=" \
+                     -e "s=^/net/$(HOST)/java/=/java/=" \
+                     -e "s=^/net/$(HOST)/lab/=/lab/="   \
+          )
+    # Don't use the new value for GAMMADIR unless a file with the new
+    # name actually exists.
+    ifneq ($(wildcard $(NEW_GAMMADIR)),)
+      GAMMADIR := $(NEW_GAMMADIR)
+    endif
+  endif
+
+endif
+
+# BUILDARCH is set to "zero" for Zero builds.  VARIANTARCH
+# is used to give the build directories meaningful names.
+VARIANTARCH = $(subst i386,i486,$(ZERO_LIBARCH))
+
+# There is a (semi-) regular correspondence between make targets and actions:
+#
+#       Target          Tree Type       Build Dir
+#
+#       debug           compiler2       <os>_<arch>_compiler2/debug
+#       fastdebug       compiler2       <os>_<arch>_compiler2/fastdebug
+#       jvmg            compiler2       <os>_<arch>_compiler2/jvmg
+#       optimized       compiler2       <os>_<arch>_compiler2/optimized
+#       profiled        compiler2       <os>_<arch>_compiler2/profiled
+#       product         compiler2       <os>_<arch>_compiler2/product
+#
+#       debug1          compiler1       <os>_<arch>_compiler1/debug
+#       fastdebug1      compiler1       <os>_<arch>_compiler1/fastdebug
+#       jvmg1           compiler1       <os>_<arch>_compiler1/jvmg
+#       optimized1      compiler1       <os>_<arch>_compiler1/optimized
+#       profiled1       compiler1       <os>_<arch>_compiler1/profiled
+#       product1        compiler1       <os>_<arch>_compiler1/product
+#
+#       debugcore       core            <os>_<arch>_core/debug
+#       fastdebugcore   core            <os>_<arch>_core/fastdebug
+#       jvmgcore        core            <os>_<arch>_core/jvmg
+#       optimizedcore   core            <os>_<arch>_core/optimized
+#       profiledcore    core            <os>_<arch>_core/profiled
+#       productcore     core            <os>_<arch>_core/product
+#
+#       debugzero       zero            <os>_<arch>_zero/debug
+#       fastdebugzero   zero            <os>_<arch>_zero/fastdebug
+#       jvmgzero        zero            <os>_<arch>_zero/jvmg
+#       optimizedzero   zero            <os>_<arch>_zero/optimized
+#       profiledzero    zero            <os>_<arch>_zero/profiled
+#       productzero     zero            <os>_<arch>_zero/product
+#
+#       debugshark      shark           <os>_<arch>_shark/debug
+#       fastdebugshark  shark           <os>_<arch>_shark/fastdebug
+#       jvmgshark       shark           <os>_<arch>_shark/jvmg
+#       optimizedshark  shark           <os>_<arch>_shark/optimized
+#       profiledshark   shark           <os>_<arch>_shark/profiled
+#       productshark    shark           <os>_<arch>_shark/product
+#
+# What you get with each target:
+#
+# debug*     - "thin" libjvm_g - debug info linked into the gamma_g launcher
+# fastdebug* - optimized compile, but with asserts enabled
+# jvmg*      - "fat" libjvm_g - debug info linked into libjvm_g.so
+# optimized* - optimized compile, no asserts
+# profiled*  - gprof
+# product*   - the shippable thing:  optimized compile, no asserts, -DPRODUCT
+
+# This target list needs to be coordinated with the usage message
+# in the build.sh script:
+TARGETS           = debug jvmg fastdebug optimized profiled product
+
+ifeq ($(ZERO_BUILD), true)
+  SUBDIR_DOCS     = $(OSNAME)_$(VARIANTARCH)_docs
+else
+  SUBDIR_DOCS     = $(OSNAME)_$(BUILDARCH)_docs
+endif
+SUBDIRS_C1        = $(addprefix $(OSNAME)_$(BUILDARCH)_compiler1/,$(TARGETS))
+SUBDIRS_C2        = $(addprefix $(OSNAME)_$(BUILDARCH)_compiler2/,$(TARGETS))
+SUBDIRS_TIERED    = $(addprefix $(OSNAME)_$(BUILDARCH)_tiered/,$(TARGETS))
+SUBDIRS_CORE      = $(addprefix $(OSNAME)_$(BUILDARCH)_core/,$(TARGETS))
+SUBDIRS_ZERO      = $(addprefix $(OSNAME)_$(VARIANTARCH)_zero/,$(TARGETS))
+SUBDIRS_SHARK     = $(addprefix $(OSNAME)_$(VARIANTARCH)_shark/,$(TARGETS))
+
+TARGETS_C2        = $(TARGETS)
+TARGETS_C1        = $(addsuffix 1,$(TARGETS))
+TARGETS_TIERED    = $(addsuffix tiered,$(TARGETS))
+TARGETS_CORE      = $(addsuffix core,$(TARGETS))
+TARGETS_ZERO      = $(addsuffix zero,$(TARGETS))
+TARGETS_SHARK     = $(addsuffix shark,$(TARGETS))
+
+BUILDTREE_MAKE    = $(GAMMADIR)/make/$(OSNAME)/makefiles/buildtree.make
+BUILDTREE_VARS    = GAMMADIR=$(GAMMADIR) OS_FAMILY=$(OSNAME) SRCARCH=$(SRCARCH) BUILDARCH=$(BUILDARCH) LIBARCH=$(LIBARCH)
+BUILDTREE_VARS   += HOTSPOT_RELEASE_VERSION=$(HOTSPOT_RELEASE_VERSION) HOTSPOT_BUILD_VERSION=$(HOTSPOT_BUILD_VERSION) JRE_RELEASE_VERSION=$(JRE_RELEASE_VERSION)
+
+BUILDTREE         = $(MAKE) -f $(BUILDTREE_MAKE) $(BUILDTREE_VARS)
+
+#-------------------------------------------------------------------------------
+
+# Could make everything by default, but that would take a while.
+all:
+	@echo "Try '$(MAKE) <target> ...'  where <target> is one or more of"
+	@echo "  $(TARGETS_C2)"
+	@echo "  $(TARGETS_C1)"
+	@echo "  $(TARGETS_CORE)"
+	@echo "  $(TARGETS_ZERO)"
+	@echo "  $(TARGETS_SHARK)"
+
+checks: check_os_version check_j2se_version
+
+# We do not want people accidentally building on old systems (e.g. Linux 2.2.x,
+# Solaris 2.5.1, 2.6).
+# Disable this check by setting DISABLE_HOTSPOT_OS_VERSION_CHECK=ok.
+
+#SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7%
+DISABLE_HOTSPOT_OS_VERSION_CHECK = ok
+OS_VERSION := $(shell uname -r)
+EMPTY_IF_NOT_SUPPORTED = $(filter $(SUPPORTED_OS_VERSION),$(OS_VERSION))
+
+check_os_version:
+ifeq ($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),)
+	$(QUIETLY) >&2 echo "*** This OS is not supported:" `uname -a`; exit 1;
+endif
+
+# jvmti.make requires XSLT (J2SE 1.4.x or newer):
+XSLT_CHECK	= $(REMOTE) $(RUN.JAVAP) javax.xml.transform.TransformerFactory
+# If not found then fail fast.
+check_j2se_version:
+	$(QUIETLY) $(XSLT_CHECK) > /dev/null 2>&1; \
+	if [ $$? -ne 0 ]; then \
+	  $(REMOTE) $(RUN.JAVA) -version; \
+	  echo "*** An XSLT processor (J2SE 1.4.x or newer) is required" \
+	  "to bootstrap this build" 1>&2; \
+	  exit 1; \
+	fi
+
+$(SUBDIRS_TIERED): $(BUILDTREE_MAKE)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=tiered
+
+$(SUBDIRS_C2): $(BUILDTREE_MAKE)
+ifeq ($(FORCE_TIERED),1)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+		$(BUILDTREE) VARIANT=tiered FORCE_TIERED=1
+else
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+		$(BUILDTREE) VARIANT=compiler2
+endif
+
+$(SUBDIRS_C1): $(BUILDTREE_MAKE)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=compiler1
+
+$(SUBDIRS_CORE): $(BUILDTREE_MAKE)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=core
+
+$(SUBDIRS_ZERO): $(BUILDTREE_MAKE) platform_zero
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=zero VARIANTARCH=$(VARIANTARCH)
+
+$(SUBDIRS_SHARK): $(BUILDTREE_MAKE) platform_zero
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=shark VARIANTARCH=$(VARIANTARCH)
+
+platform_zero: $(GAMMADIR)/make/$(OSNAME)/platform_zero.in
+	$(SED) 's/@ZERO_ARCHDEF@/$(ZERO_ARCHDEF)/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+
+# Define INSTALL=y at command line to automatically copy JVM into JAVA_HOME
+
+$(TARGETS_C2):  $(SUBDIRS_C2)
+	cd $(OSNAME)_$(BUILDARCH)_compiler2/$@ && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_compiler2/$@ && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_compiler2/$@ && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_TIERED):  $(SUBDIRS_TIERED)
+	cd $(OSNAME)_$(BUILDARCH)_tiered/$(patsubst %tiered,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_tiered/$(patsubst %tiered,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_tiered/$(patsubst %tiered,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_C1):  $(SUBDIRS_C1)
+	cd $(OSNAME)_$(BUILDARCH)_compiler1/$(patsubst %1,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_compiler1/$(patsubst %1,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_compiler1/$(patsubst %1,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_CORE):  $(SUBDIRS_CORE)
+	cd $(OSNAME)_$(BUILDARCH)_core/$(patsubst %core,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_core/$(patsubst %core,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_core/$(patsubst %core,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_ZERO):  $(SUBDIRS_ZERO)
+	cd $(OSNAME)_$(VARIANTARCH)_zero/$(patsubst %zero,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(VARIANTARCH)_zero/$(patsubst %zero,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(VARIANTARCH)_zero/$(patsubst %zero,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_SHARK):  $(SUBDIRS_SHARK)
+	cd $(OSNAME)_$(VARIANTARCH)_shark/$(patsubst %shark,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(VARIANTARCH)_shark/$(patsubst %shark,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(VARIANTARCH)_shark/$(patsubst %shark,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+# Just build the tree, and nothing else:
+tree:      $(SUBDIRS_C2)
+tree1:     $(SUBDIRS_C1)
+treecore:  $(SUBDIRS_CORE)
+treezero:  $(SUBDIRS_ZERO)
+treeshark: $(SUBDIRS_SHARK)
+
+# Doc target.  This is the same for all build options.
+#     Hence create a docs directory beside ...$(ARCH)_[...]
+docs: checks
+	$(QUIETLY) mkdir -p $(SUBDIR_DOCS)
+	$(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/makefiles/jvmti.make $(MFLAGS) $(BUILDTREE_VARS) JvmtiOutDir=$(SUBDIR_DOCS) jvmtidocs
+
+# Synonyms for win32-like targets.
+compiler2:  jvmg product
+
+compiler1:  jvmg1 product1
+
+core: jvmgcore productcore
+
+zero: jvmgzero productzero
+
+shark: jvmgshark productshark
+
+clean_docs:
+	rm -rf $(SUBDIR_DOCS)
+
+clean_compiler1 clean_compiler2 clean_core clean_zero clean_shark:
+	rm -rf $(OSNAME)_$(BUILDARCH)_$(subst clean_,,$@)
+
+clean:  clean_compiler2 clean_compiler1 clean_core clean_zero clean_shark clean_docs
+
+include $(GAMMADIR)/make/cscope.make
+
+#-------------------------------------------------------------------------------
+
+.PHONY: $(TARGETS_C2) $(TARGETS_C1) $(TARGETS_CORE) $(TARGETS_ZERO) $(TARGETS_SHARK)
+.PHONY: tree tree1 treecore treezero treeshark
+.PHONY: all compiler1 compiler2 core zero shark
+.PHONY: clean clean_compiler1 clean_compiler2 clean_core clean_zero clean_shark docs clean_docs
+.PHONY: checks check_os_version check_j2se_version
diff --git a/hotspot/make/bsd/README b/hotspot/make/bsd/README
new file mode 100644
index 0000000..d3efaf8
--- /dev/null
+++ b/hotspot/make/bsd/README
@@ -0,0 +1,26 @@
+Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+  
+This code is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 only, as
+published by the Free Software Foundation.
+  
+This code is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+version 2 for more details (a copy is included in the LICENSE file that
+accompanied this code).
+ 
+You should have received a copy of the GNU General Public License version
+2 along with this work; if not, write to the Free Software Foundation,
+Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  
+Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+or visit www.oracle.com if you need additional information or have any
+questions.
+
+________________________________________________________________________
+
+Please refer to the comments in the Makefile in this directory
+for instructions how to build the Solaris versions.
+
diff --git a/hotspot/make/bsd/adlc_updater b/hotspot/make/bsd/adlc_updater
new file mode 100644
index 0000000..6d31b79
--- /dev/null
+++ b/hotspot/make/bsd/adlc_updater
@@ -0,0 +1,20 @@
+#! /bin/sh
+#
+# This file is used by adlc.make to selectively update generated
+# adlc files. Because source and target diretories are relative
+# paths, this file is copied to the target build directory before
+# use.
+#
+# adlc-updater <file> <source-dir> <target-dir>
+#
+fix_lines() {
+  # repair bare #line directives in $1 to refer to $2
+  awk < $1 > $1+ '
+    /^#line 999999$/ {print "#line " (NR+1) " \"" F2 "\""; next}
+    {print}
+  ' F2=$2
+  mv $1+ $1
+}
+fix_lines $2/$1 $3/$1
+[ -f $3/$1 ] && cmp -s $2/$1 $3/$1 || \
+( [ -f $3/$1 ] && echo Updating $3/$1 ; touch $2/made-change ; mv $2/$1 $3/$1 )
diff --git a/hotspot/make/bsd/build.sh b/hotspot/make/bsd/build.sh
new file mode 100644
index 0000000..ddb07e5
--- /dev/null
+++ b/hotspot/make/bsd/build.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Make sure the variable JAVA_HOME is set before running this script.
+
+set -u
+
+
+if [ $# != 2 ]; then 
+    echo "Usage : $0 Build_Options Location"
+    echo "Build Options : debug or optimized or basicdebug or basic or clean"
+    echo "Location : specify any workspace which has gamma sources"
+    exit 1
+fi
+
+# Just in case:
+case ${JAVA_HOME} in
+/*) true;;
+?*) JAVA_HOME=`( cd $JAVA_HOME; pwd )`;;
+esac
+
+case `uname -m` in
+  i386|i486|i586|i686)
+    mach=i386
+    ;;
+  *)
+    echo "Unsupported machine: " `uname -m`
+    exit 1
+    ;;
+esac
+
+if [ "${JAVA_HOME}" = ""  -o  ! -d "${JAVA_HOME}" -o ! -d ${JAVA_HOME}/jre/lib/${mach} ]; then
+    echo "JAVA_HOME needs to be set to a valid JDK path"
+    echo "ksh : export JAVA_HOME=/net/tetrasparc/export/gobi/JDK1.2_fcs_V/bsd"
+    echo "csh : setenv JAVA_HOME /net/tetrasparc/export/gobi/JDK1.2_fcs_V/bsd"
+    exit 1
+fi
+
+
+LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/`uname -p`:\
+${JAVA_HOME}/jre/lib/`uname -p`/native_threads:${LD_LIBRARY_PATH-.}
+
+# This is necessary as long as we are using the old launcher
+# with the new distribution format:
+CLASSPATH=${JAVA_HOME}/jre/lib/rt.jar:${CLASSPATH-.}
+
+
+for gm in gmake gnumake
+do
+  if [ "${GNUMAKE-}" != "" ]; then break; fi
+  ($gm --version >/dev/null) 2>/dev/null && GNUMAKE=$gm
+done
+: ${GNUMAKE:?'Cannot locate the gnumake program.  Stop.'}
+
+
+echo "### ENVIRONMENT SETTINGS:"
+export JAVA_HOME		; echo "JAVA_HOME=$JAVA_HOME"
+export LD_LIBRARY_PATH		; echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
+export CLASSPATH		; echo "CLASSPATH=$CLASSPATH"
+export GNUMAKE			; echo "GNUMAKE=$GNUMAKE"
+echo "###"
+
+Build_Options=$1
+Location=$2
+
+case ${Location} in
+/*) true;;
+?*) Location=`(cd ${Location}; pwd)`;;
+esac
+
+echo \
+${GNUMAKE} -f ${Location}/make/bsd/Makefile $Build_Options GAMMADIR=${Location}
+${GNUMAKE} -f ${Location}/make/bsd/Makefile $Build_Options GAMMADIR=${Location}
diff --git a/hotspot/make/bsd/makefiles/adjust-mflags.sh b/hotspot/make/bsd/makefiles/adjust-mflags.sh
new file mode 100644
index 0000000..484fa85
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/adjust-mflags.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# This script is used only from top.make.
+# The macro $(MFLAGS-adjusted) calls this script to
+# adjust the "-j" arguments to take into account
+# the HOTSPOT_BUILD_JOBS variable.  The default
+# handling of the "-j" argument by gnumake does
+# not meet our needs, so we must adjust it ourselves.
+
+# This argument adjustment applies to two recursive
+# calls to "$(MAKE) $(MFLAGS-adjusted)" in top.make.
+# One invokes adlc.make, and the other invokes vm.make.
+# The adjustment propagates the desired concurrency
+# level down to the sub-make (of the adlc or vm).
+# The default behavior of gnumake is to run all
+# sub-makes without concurrency ("-j1").
+
+# Also, we use a make variable rather than an explicit
+# "-j<N>" argument to control this setting, so that
+# the concurrency setting (which must be tuned separately
+# for each MP system) can be set via an environment variable.
+# The recommended setting is 1.5x to 2x the number of available
+# CPUs on the MP system, which is large enough to keep the CPUs
+# busy (even though some jobs may be I/O bound) but not too large,
+# we may presume, to overflow the system's swap space.
+
+set -eu
+
+default_build_jobs=4
+
+case $# in
+[12])	true;;
+*)	>&2 echo "Usage: $0 ${MFLAGS} ${HOTSPOT_BUILD_JOBS}"; exit 2;;
+esac
+
+MFLAGS=$1
+HOTSPOT_BUILD_JOBS=${2-}
+
+# Normalize any -jN argument to the form " -j${HBJ}"
+MFLAGS=`
+	echo "$MFLAGS" \
+	| sed '
+		s/^-/ -/
+		s/ -\([^ 	][^ 	]*\)j/ -\1 -j/
+		s/ -j[0-9][0-9]*/ -j/
+		s/ -j\([^ 	]\)/ -j -\1/
+		s/ -j/ -j'${HOTSPOT_BUILD_JOBS:-${default_build_jobs}}'/
+	' `
+
+case ${HOTSPOT_BUILD_JOBS} in \
+
+'') case ${MFLAGS} in
+    *\ -j*)
+	>&2 echo "# Note: -jN is ineffective for setting parallelism in this makefile." 
+	>&2 echo "# please set HOTSPOT_BUILD_JOBS=${default_build_jobs} in the command line or environment."
+    esac;;
+
+?*) case ${MFLAGS} in
+     *\ -j*) true;;
+     *)      MFLAGS="-j${HOTSPOT_BUILD_JOBS} ${MFLAGS}";;
+    esac;;
+esac
+
+echo "${MFLAGS}"
diff --git a/hotspot/make/bsd/makefiles/adlc.make b/hotspot/make/bsd/makefiles/adlc.make
new file mode 100644
index 0000000..69797ab
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/adlc.make
@@ -0,0 +1,228 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# This makefile (adlc.make) is included from the adlc.make in the
+# build directories.
+# It knows how to compile, link, and run the adlc.
+
+include $(GAMMADIR)/make/$(Platform_os_family)/makefiles/rules.make
+
+# #########################################################################
+
+# OUTDIR must be the same as AD_Dir = $(GENERATED)/adfiles in top.make:
+GENERATED = ../generated
+OUTDIR  = $(GENERATED)/adfiles
+
+ARCH = $(Platform_arch)
+OS = $(Platform_os_family)
+
+SOURCE.AD = $(OUTDIR)/$(OS)_$(Platform_arch_model).ad 
+
+SOURCES.AD = \
+  $(call altsrc-replace,$(HS_COMMON_SRC)/cpu/$(ARCH)/vm/$(Platform_arch_model).ad) \
+  $(call altsrc-replace,$(HS_COMMON_SRC)/os_cpu/$(OS)_$(ARCH)/vm/$(OS)_$(Platform_arch_model).ad)
+
+EXEC	= $(OUTDIR)/adlc
+
+# set VPATH so make knows where to look for source files
+Src_Dirs_V += $(GAMMADIR)/src/share/vm/adlc
+VPATH += $(Src_Dirs_V:%=%:)
+
+# set INCLUDES for C preprocessor
+Src_Dirs_I += $(GAMMADIR)/src/share/vm/adlc $(GENERATED)
+INCLUDES += $(Src_Dirs_I:%=-I%)
+
+# set flags for adlc compilation
+CPPFLAGS = $(SYSDEFS) $(INCLUDES)
+
+# Force assertions on.
+CPPFLAGS += -DASSERT
+
+# CFLAGS_WARN holds compiler options to suppress/enable warnings.
+# Compiler warnings are treated as errors
+ifneq ($(COMPILER_WARNINGS_FATAL),false)
+  CFLAGS_WARN = -Werror
+endif
+CFLAGS += $(CFLAGS_WARN)
+
+OBJECTNAMES = \
+	adlparse.o \
+	archDesc.o \
+	arena.o \
+	dfa.o \
+	dict2.o \
+	filebuff.o \
+	forms.o \
+	formsopt.o \
+	formssel.o \
+	main.o \
+	adlc-opcodes.o \
+	output_c.o \
+	output_h.o \
+
+OBJECTS = $(OBJECTNAMES:%=$(OUTDIR)/%)
+
+GENERATEDNAMES = \
+        ad_$(Platform_arch_model).cpp \
+        ad_$(Platform_arch_model).hpp \
+        ad_$(Platform_arch_model)_clone.cpp \
+        ad_$(Platform_arch_model)_expand.cpp \
+        ad_$(Platform_arch_model)_format.cpp \
+        ad_$(Platform_arch_model)_gen.cpp \
+        ad_$(Platform_arch_model)_misc.cpp \
+        ad_$(Platform_arch_model)_peephole.cpp \
+        ad_$(Platform_arch_model)_pipeline.cpp \
+        adGlobals_$(Platform_arch_model).hpp \
+        dfa_$(Platform_arch_model).cpp \
+
+GENERATEDFILES = $(GENERATEDNAMES:%=$(OUTDIR)/%)
+
+# #########################################################################
+
+all: $(EXEC)
+
+$(EXEC) : $(OBJECTS)
+	@echo Making adlc
+	$(QUIETLY) $(HOST.LINK_NOPROF.CC) -o $(EXEC) $(OBJECTS)
+
+# Random dependencies:
+$(OBJECTS): opcodes.hpp classes.hpp adlc.hpp adlcVMDeps.hpp adlparse.hpp archDesc.hpp arena.hpp dict2.hpp filebuff.hpp forms.hpp formsopt.hpp formssel.hpp
+
+# The source files refer to ostream.h, which sparcworks calls iostream.h
+$(OBJECTS): ostream.h
+
+ostream.h :
+	@echo >$@ '#include <iostream.h>'
+
+dump:
+	: OUTDIR=$(OUTDIR)
+	: OBJECTS=$(OBJECTS)
+	: products = $(GENERATEDFILES)
+
+all: $(GENERATEDFILES)
+
+$(GENERATEDFILES): refresh_adfiles
+
+# Get a unique temporary directory name, so multiple makes can run in parallel.
+# Note that product files are updated via "mv", which is atomic.
+TEMPDIR := $(OUTDIR)/mktmp$(shell echo $$$$)
+
+# Debuggable by default
+CFLAGS += -g
+
+# Pass -D flags into ADLC.
+ADLCFLAGS += $(SYSDEFS)
+
+# Note "+="; it is a hook so flags.make can add more flags, like -g or -DFOO.
+ADLCFLAGS += -q -T
+
+# Normally, debugging is done directly on the ad_<arch>*.cpp files.
+# But -g will put #line directives in those files pointing back to <arch>.ad.
+# Some builds of gcc 3.2 have a bug that gets tickled by the extra #line directives
+# so skip it for 3.2 and ealier.
+ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
+ADLCFLAGS += -g
+endif
+
+ifdef LP64
+ADLCFLAGS += -D_LP64
+else
+ADLCFLAGS += -U_LP64
+endif
+
+#
+# adlc_updater is a simple sh script, under sccs control. It is
+# used to selectively update generated adlc files. This should
+# provide a nice compilation speed improvement.
+#
+ADLC_UPDATER_DIRECTORY = $(GAMMADIR)/make/$(OS)
+ADLC_UPDATER = adlc_updater
+$(ADLC_UPDATER): $(ADLC_UPDATER_DIRECTORY)/$(ADLC_UPDATER)
+	$(QUIETLY) cp $< $@; chmod +x $@
+
+# This action refreshes all generated adlc files simultaneously.
+# The way it works is this:
+# 1) create a scratch directory to work in.
+# 2) if the current working directory does not have $(ADLC_UPDATER), copy it.
+# 3) run the compiled adlc executable. This will create new adlc files in the scratch directory.
+# 4) call $(ADLC_UPDATER) on each generated adlc file. It will selectively update changed or missing files.
+# 5) If we actually updated any files, echo a notice.
+#
+refresh_adfiles: $(EXEC) $(SOURCE.AD) $(ADLC_UPDATER)
+	@rm -rf $(TEMPDIR); mkdir $(TEMPDIR)
+	$(QUIETLY) $(EXEC) $(ADLCFLAGS) $(SOURCE.AD) \
+ -c$(TEMPDIR)/ad_$(Platform_arch_model).cpp -h$(TEMPDIR)/ad_$(Platform_arch_model).hpp -a$(TEMPDIR)/dfa_$(Platform_arch_model).cpp -v$(TEMPDIR)/adGlobals_$(Platform_arch_model).hpp \
+	    || { rm -rf $(TEMPDIR); exit 1; }
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model).cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model).hpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_clone.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_expand.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_format.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_gen.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_misc.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_peephole.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_pipeline.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) adGlobals_$(Platform_arch_model).hpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) dfa_$(Platform_arch_model).cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) [ -f $(TEMPDIR)/made-change ] \
+		|| echo "Rescanned $(SOURCE.AD) but encountered no changes."
+	$(QUIETLY) rm -rf $(TEMPDIR)
+
+
+# #########################################################################
+
+$(SOURCE.AD): $(SOURCES.AD)
+	$(QUIETLY) $(PROCESS_AD_FILES) $(SOURCES.AD) > $(SOURCE.AD)
+
+#PROCESS_AD_FILES = cat
+# Pass through #line directives, in case user enables -g option above:
+PROCESS_AD_FILES = awk '{ \
+    if (CUR_FN != FILENAME) { CUR_FN=FILENAME; NR_BASE=NR-1; need_lineno=1 } \
+    if (need_lineno && $$0 !~ /\/\//) \
+      { print "\n\n\#line " (NR-NR_BASE) " \"" FILENAME "\""; need_lineno=0 }; \
+    print }'
+
+$(OUTDIR)/%.o: %.cpp
+	@echo Compiling $<
+	$(QUIETLY) $(REMOVE_TARGET)
+	$(QUIETLY) $(HOST.COMPILE.CC) -o $@ $< $(COMPILE_DONE)
+
+# Some object files are given a prefix, to disambiguate
+# them from objects of the same name built for the VM.
+$(OUTDIR)/adlc-%.o: %.cpp
+	@echo Compiling $<
+	$(QUIETLY) $(REMOVE_TARGET)
+	$(QUIETLY) $(HOST.COMPILE.CC) -o $@ $< $(COMPILE_DONE)
+
+# #########################################################################
+
+clean	:
+	rm $(OBJECTS)
+
+cleanall :
+	rm $(OBJECTS) $(EXEC)
+
+# #########################################################################
+
+.PHONY: all dump refresh_adfiles clean cleanall
diff --git a/hotspot/make/bsd/makefiles/amd64.make b/hotspot/make/bsd/makefiles/amd64.make
new file mode 100644
index 0000000..ecdac17
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/amd64.make
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# The copied fdlibm routines in sharedRuntimeTrig.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrig.o = $(OPT_CFLAGS/NOOPT)
+# The copied fdlibm routines in sharedRuntimeTrans.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrans.o = $(OPT_CFLAGS/NOOPT)
+# Must also specify if CPU is little endian
+CFLAGS += -DVM_LITTLE_ENDIAN
+
+CFLAGS += -D_LP64=1
+
+# The serviceability agent relies on frame pointer (%rbp) to walk thread stack
+ifndef USE_SUNCC
+  CFLAGS += -fno-omit-frame-pointer
+endif
+
+OPT_CFLAGS/compactingPermGenGen.o = -O1
diff --git a/hotspot/make/bsd/makefiles/arm.make b/hotspot/make/bsd/makefiles/arm.make
new file mode 100644
index 0000000..e22d5c3
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/arm.make
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+Obj_Files += bsd_arm.o
+
+LIBS += $(EXT_LIBS_PATH)/sflt_glibc.a 
+
+CFLAGS += -DVM_LITTLE_ENDIAN
diff --git a/hotspot/make/bsd/makefiles/build_vm_def.sh b/hotspot/make/bsd/makefiles/build_vm_def.sh
new file mode 100644
index 0000000..fb9a0d5
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/build_vm_def.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# If we're cross compiling use that path for nm
+if [ "$CROSS_COMPILE_ARCH" != "" ]; then 
+NM=$ALT_COMPILER_PATH/nm
+else
+NM=nm
+fi
+
+$NM --defined-only $* | awk '
+   { if ($3 ~ /^_ZTV/ || $3 ~ /^gHotSpotVM/) print "\t" $3 ";" }
+   '
diff --git a/hotspot/make/bsd/makefiles/buildtree.make b/hotspot/make/bsd/makefiles/buildtree.make
new file mode 100644
index 0000000..f412310
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/buildtree.make
@@ -0,0 +1,432 @@
+#
+# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Usage:
+#
+# $(MAKE) -f buildtree.make SRCARCH=srcarch BUILDARCH=buildarch LIBARCH=libarch
+#         GAMMADIR=dir OS_FAMILY=os VARIANT=variant
+#
+# The macros ARCH, GAMMADIR, OS_FAMILY and VARIANT must be defined in the
+# environment or on the command-line:
+#
+# ARCH		- sparc, i486, ... HotSpot cpu and os_cpu source directory
+# BUILDARCH     - build directory
+# LIBARCH       - the corresponding directory in JDK/JRE
+# GAMMADIR	- top of workspace
+# OS_FAMILY	- operating system
+# VARIANT	- core, compiler1, compiler2, or tiered
+# HOTSPOT_RELEASE_VERSION - <major>.<minor>-b<nn> (11.0-b07)
+# HOTSPOT_BUILD_VERSION   - internal, internal-$(USER_RELEASE_SUFFIX) or empty
+# JRE_RELEASE_VERSION     - <major>.<minor>.<micro> (1.7.0)
+#
+# Builds the directory trees with makefiles plus some convenience files in
+# each directory:
+#
+# Makefile	- for "make foo"
+# flags.make	- with macro settings
+# vm.make	- to support making "$(MAKE) -v vm.make" in makefiles
+# adlc.make	- 
+# jvmti.make	- generate JVMTI bindings from the spec (JSR-163)
+# sa.make	- generate SA jar file and natives
+# env.[ck]sh	- environment settings
+# test_gamma	- script to run the Queens program
+# 
+# The makefiles are split this way so that "make foo" will run faster by not
+# having to read the dependency files for the vm.
+
+include $(GAMMADIR)/make/scm.make
+include $(GAMMADIR)/make/altsrc.make
+
+
+# 'gmake MAKE_VERBOSE=y' or 'gmake QUIETLY=' gives all the gory details.
+QUIETLY$(MAKE_VERBOSE)	= @
+
+# For now, until the compiler is less wobbly:
+TESTFLAGS	= -Xbatch -showversion
+
+ifeq ($(ZERO_BUILD), true)
+  PLATFORM_FILE = $(shell dirname $(shell dirname $(shell pwd)))/platform_zero
+else
+  ifdef USE_SUNCC
+    PLATFORM_FILE = $(GAMMADIR)/make/$(OS_FAMILY)/platform_$(BUILDARCH).suncc
+  else
+    PLATFORM_FILE = $(GAMMADIR)/make/$(OS_FAMILY)/platform_$(BUILDARCH)
+  endif
+endif
+
+# Allow overriding of the arch part of the directory but default
+# to BUILDARCH if nothing is specified
+ifeq ($(VARIANTARCH),)
+  VARIANTARCH=$(BUILDARCH)
+endif
+
+ifdef FORCE_TIERED
+ifeq		($(VARIANT),tiered)
+PLATFORM_DIR	= $(OS_FAMILY)_$(VARIANTARCH)_compiler2
+else
+PLATFORM_DIR	= $(OS_FAMILY)_$(VARIANTARCH)_$(VARIANT)
+endif
+else
+PLATFORM_DIR    = $(OS_FAMILY)_$(VARIANTARCH)_$(VARIANT)
+endif
+
+#
+# We do two levels of exclusion in the shared directory.
+# TOPLEVEL excludes are pruned, they are not recursively searched,
+# but lower level directories can be named without fear of collision.
+# ALWAYS excludes are excluded at any level in the directory tree.
+#
+
+ALWAYS_EXCLUDE_DIRS     = $(SCM_DIRS)
+
+ifeq		($(VARIANT),tiered)
+TOPLEVEL_EXCLUDE_DIRS	= $(ALWAYS_EXCLUDE_DIRS) -o -name adlc -o -name agent
+else
+ifeq		($(VARIANT),compiler2)
+TOPLEVEL_EXCLUDE_DIRS	= $(ALWAYS_EXCLUDE_DIRS) -o -name adlc -o -name c1 -o -name agent
+else
+# compiler1 and core use the same exclude list
+TOPLEVEL_EXCLUDE_DIRS	= $(ALWAYS_EXCLUDE_DIRS) -o -name adlc -o -name opto -o -name libadt -o -name agent
+endif
+endif
+
+# Get things from the platform file.
+COMPILER	= $(shell sed -n 's/^compiler[ 	]*=[ 	]*//p' $(PLATFORM_FILE))
+
+# dtracefiles is used on BSD versions that implement Dtrace (like MacOS X)
+SIMPLE_DIRS	= \
+	$(PLATFORM_DIR)/generated/dependencies \
+	$(PLATFORM_DIR)/generated/adfiles \
+	$(PLATFORM_DIR)/generated/jvmtifiles \
+	$(PLATFORM_DIR)/generated/dtracefiles
+
+TARGETS      = debug fastdebug jvmg optimized product profiled
+SUBMAKE_DIRS = $(addprefix $(PLATFORM_DIR)/,$(TARGETS))
+
+# For dependencies and recursive makes.
+BUILDTREE_MAKE	= $(GAMMADIR)/make/$(OS_FAMILY)/makefiles/buildtree.make
+
+# dtrace.make is used on BSD versions that implement Dtrace (like MacOS X)
+BUILDTREE_TARGETS = Makefile flags.make flags_vm.make vm.make adlc.make \
+	jvmti.make sa.make dtrace.make \
+        env.sh env.csh jdkpath.sh .dbxrc test_gamma
+
+BUILDTREE_VARS	= GAMMADIR=$(GAMMADIR) OS_FAMILY=$(OS_FAMILY) \
+	SRCARCH=$(SRCARCH) BUILDARCH=$(BUILDARCH) LIBARCH=$(LIBARCH) VARIANT=$(VARIANT)
+
+# Define variables to be set in flags.make.
+# Default values are set in make/defs.make.
+ifeq ($(HOTSPOT_BUILD_VERSION),)
+  HS_BUILD_VER=$(HOTSPOT_RELEASE_VERSION)
+else
+  HS_BUILD_VER=$(HOTSPOT_RELEASE_VERSION)-$(HOTSPOT_BUILD_VERSION)
+endif
+# Set BUILD_USER from system-dependent hints:  $LOGNAME, $(whoami)
+ifndef HOTSPOT_BUILD_USER
+  HOTSPOT_BUILD_USER := $(shell echo $$LOGNAME)
+endif
+ifndef HOTSPOT_BUILD_USER
+  HOTSPOT_BUILD_USER := $(shell whoami)
+endif
+# Define HOTSPOT_VM_DISTRO based on settings in make/openjdk_distro
+# or make/hotspot_distro.
+ifndef HOTSPOT_VM_DISTRO
+  ifeq ($(call if-has-altsrc,$(HS_COMMON_SRC)/,true,false),true)
+    include $(GAMMADIR)/make/hotspot_distro
+  else
+    include $(GAMMADIR)/make/openjdk_distro
+  endif
+endif
+
+# MACOSX FIXME: we should be able to run test_gamma (see MACOSX_PORT-214)
+ifdef ALWAYS_PASS_TEST_GAMMA
+  TEST_GAMMA_STATUS= echo 'exit 0';
+else
+  TEST_GAMMA_STATUS=
+endif
+
+BUILDTREE_VARS += HOTSPOT_RELEASE_VERSION=$(HS_BUILD_VER) HOTSPOT_BUILD_VERSION=  JRE_RELEASE_VERSION=$(JRE_RELEASE_VERSION)
+
+BUILDTREE	= \
+	$(MAKE) -f $(BUILDTREE_MAKE) $(BUILDTREE_TARGETS) $(BUILDTREE_VARS)
+
+BUILDTREE_COMMENT	= echo "\# Generated by $(BUILDTREE_MAKE)"
+
+all:  $(SUBMAKE_DIRS)
+
+# Run make in each subdirectory recursively.
+$(SUBMAKE_DIRS): $(SIMPLE_DIRS) FORCE
+	$(QUIETLY) [ -d $@ ] || { mkdir -p $@; }
+	$(QUIETLY) cd $@ && $(BUILDTREE) TARGET=$(@F)
+	$(QUIETLY) touch $@
+
+$(SIMPLE_DIRS):
+	$(QUIETLY) mkdir -p $@
+
+# Convenience macro which takes a source relative path, applies $(1) to the
+# absolute path, and then replaces $(GAMMADIR) in the result with a 
+# literal "$(GAMMADIR)/" suitable for inclusion in a Makefile.  
+gamma-path=$(subst $(GAMMADIR),\$$(GAMMADIR),$(call $(1),$(HS_COMMON_SRC)/$(2)))
+
+flags.make: $(BUILDTREE_MAKE) ../shared_dirs.lst
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo "Platform_file = $(PLATFORM_FILE)" | sed 's|$(GAMMADIR)|$$(GAMMADIR)|'; \
+	sed -n '/=/s/^ */Platform_/p' < $(PLATFORM_FILE); \
+	echo; \
+	echo "GAMMADIR = $(GAMMADIR)"; \
+	echo "SYSDEFS = \$$(Platform_sysdefs)"; \
+	echo "SRCARCH = $(SRCARCH)"; \
+	echo "BUILDARCH = $(BUILDARCH)"; \
+	echo "LIBARCH = $(LIBARCH)"; \
+	echo "TARGET = $(TARGET)"; \
+	echo "HS_BUILD_VER = $(HS_BUILD_VER)"; \
+	echo "JRE_RELEASE_VER = $(JRE_RELEASE_VERSION)"; \
+	echo "SA_BUILD_VERSION = $(HS_BUILD_VER)"; \
+	echo "HOTSPOT_BUILD_USER = $(HOTSPOT_BUILD_USER)"; \
+	echo "HOTSPOT_VM_DISTRO = $(HOTSPOT_VM_DISTRO)"; \
+	echo; \
+	echo "# Used for platform dispatching"; \
+	echo "TARGET_DEFINES  = -DTARGET_OS_FAMILY_\$$(Platform_os_family)"; \
+	echo "TARGET_DEFINES += -DTARGET_ARCH_\$$(Platform_arch)"; \
+	echo "TARGET_DEFINES += -DTARGET_ARCH_MODEL_\$$(Platform_arch_model)"; \
+	echo "TARGET_DEFINES += -DTARGET_OS_ARCH_\$$(Platform_os_arch)"; \
+	echo "TARGET_DEFINES += -DTARGET_OS_ARCH_MODEL_\$$(Platform_os_arch_model)"; \
+	echo "TARGET_DEFINES += -DTARGET_COMPILER_\$$(Platform_compiler)"; \
+	echo "CFLAGS += \$$(TARGET_DEFINES)"; \
+	echo; \
+	echo "Src_Dirs_V = \\"; \
+	sed 's/$$/ \\/;s|$(GAMMADIR)|$$(GAMMADIR)|' ../shared_dirs.lst; \
+	echo "$(call gamma-path,altsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/posix/vm)"; \
+	echo; \
+	echo "Src_Dirs_I = \\"; \
+	echo "$(call gamma-path,altsrc,share/vm/prims) \\"; \
+	echo "$(call gamma-path,commonsrc,share/vm/prims) \\"; \
+	echo "$(call gamma-path,altsrc,share/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,share/vm) \\"; \
+	echo "$(call gamma-path,altsrc,share/vm/precompiled) \\"; \
+	echo "$(call gamma-path,commonsrc,share/vm/precompiled) \\"; \
+	echo "$(call gamma-path,altsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/posix/vm)"; \
+	[ -n "$(CFLAGS_BROWSE)" ] && \
+	    echo && echo "CFLAGS_BROWSE = $(CFLAGS_BROWSE)"; \
+	[ -n "$(HOTSPOT_EXTRA_SYSDEFS)" ] && \
+	    echo && \
+	    echo "HOTSPOT_EXTRA_SYSDEFS\$$(HOTSPOT_EXTRA_SYSDEFS) = $(HOTSPOT_EXTRA_SYSDEFS)" && \
+	    echo "SYSDEFS += \$$(HOTSPOT_EXTRA_SYSDEFS)"; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(VARIANT).make"; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(COMPILER).make"; \
+	) > $@
+
+flags_vm.make: $(BUILDTREE_MAKE) ../shared_dirs.lst
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	[ "$(TARGET)" = profiled ] && \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/optimized.make"; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(TARGET).make"; \
+	) > $@
+
+../shared_dirs.lst:  $(BUILDTREE_MAKE) $(GAMMADIR)/src/share/vm
+	@echo Creating directory list $@
+	$(QUIETLY) if [ -d $(HS_ALT_SRC)/share/vm ]; then \
+          find $(HS_ALT_SRC)/share/vm/* -prune \
+	  -type d \! \( $(TOPLEVEL_EXCLUDE_DIRS) \) -exec find {} \
+          \( $(ALWAYS_EXCLUDE_DIRS) \) -prune -o -type d -print \; > $@; \
+        fi;
+	$(QUIETLY) find $(HS_COMMON_SRC)/share/vm/* -prune \
+	-type d \! \( $(TOPLEVEL_EXCLUDE_DIRS) \) -exec find {} \
+        \( $(ALWAYS_EXCLUDE_DIRS) \) -prune -o -type d -print \; >> $@
+
+Makefile: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/top.make"; \
+	) > $@
+
+vm.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo include flags_vm.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+adlc.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+jvmti.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+sa.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+dtrace.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+env.sh: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	[ -n "$$JAVA_HOME" ] && { echo ": \$${JAVA_HOME:=$${JAVA_HOME}}"; }; \
+	{ \
+	echo "LD_LIBRARY_PATH=.:$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
+	echo "DYLD_LIBRARY_PATH=.:$${DYLD_LIBRARY_PATH:+$$DYLD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
+	echo "CLASSPATH=$${CLASSPATH:+$$CLASSPATH:}.:\$${JAVA_HOME}/jre/lib/rt.jar:\$${JAVA_HOME}/jre/lib/i18n.jar"; \
+	} | sed s:$${JAVA_HOME:--------}:\$${JAVA_HOME}:g; \
+	echo "HOTSPOT_BUILD_USER=\"$${LOGNAME:-$$USER} in `basename $(GAMMADIR)`\""; \
+	echo "export JAVA_HOME LD_LIBRARY_PATH DYLD_LIBRARY_PATH CLASSPATH HOTSPOT_BUILD_USER"; \
+	) > $@
+
+env.csh: env.sh
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	[ -n "$$JAVA_HOME" ] && \
+	{ echo "if (! \$$?JAVA_HOME) setenv JAVA_HOME \"$$JAVA_HOME\""; }; \
+	sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=/setenv \1 /p' $?; \
+	) > $@
+
+jdkpath.sh: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo "JDK=${JAVA_HOME}"; \
+	) > $@	   
+
+.dbxrc:  $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	echo "echo '# Loading $(PLATFORM_DIR)/$(TARGET)/.dbxrc'"; \
+	echo "if [ -f \"\$${HOTSPOT_DBXWARE}\" ]"; \
+	echo "then"; \
+	echo "	source \"\$${HOTSPOT_DBXWARE}\""; \
+	echo "elif [ -f \"\$$HOME/.dbxrc\" ]"; \
+	echo "then"; \
+	echo "	source \"\$$HOME/.dbxrc\""; \
+	echo "fi"; \
+	) > $@
+
+# Skip the test for product builds (which only work when installed in a JDK), to
+# avoid exiting with an error and causing make to halt.
+NO_TEST_MSG	= \
+	echo "$@:  skipping the test--this build must be tested in a JDK."
+
+NO_JAVA_HOME_MSG	= \
+	echo "JAVA_HOME must be set to run this test."
+
+DATA_MODE = $(DATA_MODE/$(BUILDARCH))
+JAVA_FLAG = $(JAVA_FLAG/$(DATA_MODE))
+
+DATA_MODE/i486    = 32
+DATA_MODE/sparc   = 32
+DATA_MODE/sparcv9 = 64
+DATA_MODE/amd64   = 64
+DATA_MODE/ia64    = 64
+DATA_MODE/zero    = $(ARCH_DATA_MODEL)
+
+JAVA_FLAG/32 = -d32
+JAVA_FLAG/64 = -d64
+
+WRONG_DATA_MODE_MSG = \
+	echo "JAVA_HOME must point to $(DATA_MODE)bit JDK."
+
+CROSS_COMPILING_MSG = \
+	echo "Cross compiling for ARCH $(CROSS_COMPILE_ARCH), skipping gamma run."
+
+test_gamma:  $(BUILDTREE_MAKE) $(GAMMADIR)/make/test/Queens.java
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	echo '#!/bin/sh'; \
+	$(BUILDTREE_COMMENT); \
+	echo '. ./env.sh'; \
+	echo "if [ \"$(CROSS_COMPILE_ARCH)\" != \"\" ]; then { $(CROSS_COMPILING_MSG); exit 0; }; fi"; \
+	echo "if [ -z \$$JAVA_HOME ]; then { $(NO_JAVA_HOME_MSG); exit 0; }; fi"; \
+	echo "if ! \$${JAVA_HOME}/bin/java $(JAVA_FLAG) -fullversion 2>&1 > /dev/null"; \
+	echo "then"; \
+	echo "  $(WRONG_DATA_MODE_MSG); exit 0;"; \
+	echo "fi"; \
+	echo "rm -f Queens.class"; \
+	echo "\$${JAVA_HOME}/bin/javac -d . $(GAMMADIR)/make/test/Queens.java"; \
+	echo '[ -f gamma_g ] && { gamma=gamma_g; }'; \
+	echo './$${gamma:-gamma} $(TESTFLAGS) Queens < /dev/null'; \
+	$(TEST_GAMMA_STATUS) \
+	) > $@
+	$(QUIETLY) chmod +x $@
+
+FORCE:
+
+.PHONY:  all FORCE
diff --git a/hotspot/make/bsd/makefiles/compiler1.make b/hotspot/make/bsd/makefiles/compiler1.make
new file mode 100644
index 0000000..0057814
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/compiler1.make
@@ -0,0 +1,31 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making client version of VM
+
+TYPE=COMPILER1
+
+VM_SUBDIR = client
+
+CFLAGS += -DCOMPILER1
diff --git a/hotspot/make/bsd/makefiles/compiler2.make b/hotspot/make/bsd/makefiles/compiler2.make
new file mode 100644
index 0000000..c881079
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/compiler2.make
@@ -0,0 +1,31 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making server version of VM
+
+TYPE=COMPILER2
+
+VM_SUBDIR = server
+
+CFLAGS += -DCOMPILER2
diff --git a/hotspot/make/bsd/makefiles/core.make b/hotspot/make/bsd/makefiles/core.make
new file mode 100644
index 0000000..e032d96
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/core.make
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making core version of VM
+
+# Select which files to use (in top.make)
+TYPE=CORE
+
+# There is no "core" directory in JDK. Install core build in server directory.
+VM_SUBDIR = server
+
+# Note:  macros.hpp defines CORE
diff --git a/hotspot/make/bsd/makefiles/cscope.make b/hotspot/make/bsd/makefiles/cscope.make
new file mode 100644
index 0000000..7a12b3b
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/cscope.make
@@ -0,0 +1,160 @@
+#
+# Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+#
+# The cscope.out file is made in the current directory and spans the entire
+# source tree.
+#
+# Things to note:
+#	1. We use relative names for cscope.
+#	2. We *don't* remove the old cscope.out file, because cscope is smart
+#	   enough to only build what has changed.  It can be confused, however,
+#	   if files are renamed or removed, so it may be necessary to manually
+#	   remove cscope.out if a lot of reorganization has occurred.
+#
+
+include $(GAMMADIR)/make/scm.make
+
+NAWK	= awk
+RM	= rm -f
+HG	= hg
+CS_TOP	= ../..
+
+CSDIRS	= $(CS_TOP)/src $(CS_TOP)/build
+CSINCS	= $(CSDIRS:%=-I%)
+
+CSCOPE		= cscope
+CSCOPE_FLAGS	= -b
+
+# Allow .java files to be added from the environment (CSCLASSES=yes).
+ifdef	CSCLASSES
+ADDCLASSES=	-o -name '*.java'
+endif
+
+# Adding CClassHeaders also pushes the file count of a full workspace up about
+# 200 files (these files also don't exist in a new workspace, and thus will
+# cause the recreation of the database as they get created, which might seem
+# a little confusing).  Thus allow these files to be added from the environment
+# (CSHEADERS=yes).
+ifndef	CSHEADERS
+RMCCHEADERS=	-o -name CClassHeaders
+endif
+
+# Use CS_GENERATED=x to include auto-generated files in the build directories.
+ifdef	CS_GENERATED
+CS_ADD_GENERATED	= -o -name '*.incl'
+else
+CS_PRUNE_GENERATED	= -o -name '${OS}_*_core' -o -name '${OS}_*_compiler?'
+endif
+
+# OS-specific files for other systems are excluded by default.  Use CS_OS=yes
+# to include platform-specific files for other platforms.
+ifndef	CS_OS
+CS_OS		= linux macos solaris win32 bsd
+CS_PRUNE_OS	= $(patsubst %,-o -name '*%*',$(filter-out ${OS},${CS_OS}))
+endif
+
+# Processor-specific files for other processors are excluded by default.  Use
+# CS_CPU=x to include platform-specific files for other platforms.
+ifndef	CS_CPU
+CS_CPU		= i486 sparc amd64 ia64
+CS_PRUNE_CPU	= $(patsubst %,-o -name '*%*',$(filter-out ${SRCARCH},${CS_CPU}))
+endif
+
+# What files should we include?  A simple rule might be just those files under
+# SCCS control, however this would miss files we create like the opcodes and
+# CClassHeaders.  The following attempts to find everything that is *useful*.
+# (.del files are created by sccsrm, demo directories contain many .java files
+# that probably aren't useful for development, and the pkgarchive may contain
+# duplicates of files within the source hierarchy).
+
+# Directories to exclude.
+CS_PRUNE_STD	= $(SCM_DIRS) \
+		  -o -name '.del-*' \
+		  -o -name '*demo' \
+		  -o -name pkgarchive
+
+CS_PRUNE	= $(CS_PRUNE_STD) \
+		  $(CS_PRUNE_OS) \
+		  $(CS_PRUNE_CPU) \
+		  $(CS_PRUNE_GENERATED) \
+		  $(RMCCHEADERS)
+
+# File names to include.
+CSFILENAMES	= -name '*.[ch]pp' \
+		  -o -name '*.[Ccshlxy]' \
+		  $(CS_ADD_GENERATED) \
+		  -o -name '*.il' \
+		  -o -name '*.cc' \
+		  -o -name '*[Mm]akefile*' \
+		  -o -name '*.gmk' \
+		  -o -name '*.make' \
+		  -o -name '*.ad' \
+		  $(ADDCLASSES)
+
+.PRECIOUS:	cscope.out
+
+cscope cscope.out: cscope.files FORCE
+	$(CSCOPE) $(CSCOPE_FLAGS)
+
+# The .raw file is reordered here in an attempt to make cscope display the most
+# relevant files first.
+cscope.files: .cscope.files.raw
+	echo "$(CSINCS)" > $@
+	-egrep -v "\.java|\/make\/"	$< >> $@
+	-fgrep ".java"			$< >> $@
+	-fgrep "/make/"		$< >> $@
+
+.cscope.files.raw:  .nametable.files
+	-find $(CSDIRS) -type d \( $(CS_PRUNE) \) -prune -o \
+	    -type f \( $(CSFILENAMES) \) -print > $@
+
+cscope.clean:  nametable.clean
+	-$(RM) cscope.out cscope.files .cscope.files.raw
+
+TAGS:  cscope.files FORCE
+	egrep -v '^-|^$$' $< | etags --members -
+
+TAGS.clean:  nametable.clean
+	-$(RM) TAGS
+
+# .nametable.files and .nametable.files.tmp are used to determine if any files
+# were added to/deleted from/renamed in the workspace.  If not, then there's
+# normally no need to rebuild the cscope database. To force a rebuild of
+# the cscope database: gmake nametable.clean.
+.nametable.files:  .nametable.files.tmp
+	( cmp -s $@ $< ) || ( cp $< $@ )
+	-$(RM) $<
+
+# `hg status' is slightly faster than `hg fstatus'. Both are
+# quite a bit slower on an NFS mounted file system, so this is
+# really geared towards repos on local file systems.
+.nametable.files.tmp:
+	-$(HG) fstatus -acmn > $@
+nametable.clean:
+	-$(RM) .nametable.files .nametable.files.tmp
+
+FORCE:
+
+.PHONY:		cscope cscope.clean TAGS.clean nametable.clean FORCE
diff --git a/hotspot/make/bsd/makefiles/debug.make b/hotspot/make/bsd/makefiles/debug.make
new file mode 100644
index 0000000..f0aec17
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/debug.make
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making debug version of VM
+
+# Compiler specific DEBUG_CFLAGS are passed in from gcc.make, sparcWorks.make
+DEBUG_CFLAGS/DEFAULT= $(DEBUG_CFLAGS)
+DEBUG_CFLAGS/BYFILE = $(DEBUG_CFLAGS/$@)$(DEBUG_CFLAGS/DEFAULT$(DEBUG_CFLAGS/$@))
+CFLAGS += $(DEBUG_CFLAGS/BYFILE)
+
+# Linker mapfile
+MAPFILE = $(GAMMADIR)/make/bsd/makefiles/mapfile-vers-debug
+
+_JUNK_ := $(shell echo -e >&2 ""\
+ "----------------------------------------------------------------------\n" \
+ "WARNING: 'make debug' is deprecated. It will be removed in the future.\n" \
+ "Please use 'make jvmg' to build debug JVM.                            \n" \
+ "----------------------------------------------------------------------\n")
+
+G_SUFFIX = _g
+VERSION = debug
+SYSDEFS += -DASSERT -DDEBUG
+PICFLAGS = DEFAULT
diff --git a/hotspot/make/bsd/makefiles/defs.make b/hotspot/make/bsd/makefiles/defs.make
new file mode 100644
index 0000000..040cd7b
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/defs.make
@@ -0,0 +1,180 @@
+#
+# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# The common definitions for hotspot bsd builds.
+# Include the top level defs.make under make directory instead of this one.
+# This file is included into make/defs.make.
+
+SLASH_JAVA ?= /java
+
+# Need PLATFORM (os-arch combo names) for jdk and hotspot, plus libarch name
+ARCH:=$(shell uname -m)
+PATH_SEP = :
+ifeq ($(LP64), 1)
+  ARCH_DATA_MODEL ?= 64
+else
+  ARCH_DATA_MODEL ?= 32
+endif
+
+# zero
+ifeq ($(ZERO_BUILD), true)
+  ifeq ($(ARCH_DATA_MODEL), 64)
+    MAKE_ARGS      += LP64=1
+  endif
+  PLATFORM         = bsd-zero
+  VM_PLATFORM      = bsd_$(subst i386,i486,$(ZERO_LIBARCH))
+  HS_ARCH          = zero
+  ARCH             = zero
+endif
+
+# ia64
+ifeq ($(ARCH), ia64)
+  ARCH_DATA_MODEL = 64
+  MAKE_ARGS      += LP64=1
+  PLATFORM        = bsd-ia64
+  VM_PLATFORM     = bsd_ia64
+  HS_ARCH         = ia64
+endif
+
+# sparc
+ifeq ($(ARCH), sparc64)
+  ifeq ($(ARCH_DATA_MODEL), 64)
+    ARCH_DATA_MODEL  = 64
+    MAKE_ARGS        += LP64=1
+    PLATFORM         = bsd-sparcv9
+    VM_PLATFORM      = bsd_sparcv9
+  else
+    ARCH_DATA_MODEL  = 32
+    PLATFORM         = bsd-sparc
+    VM_PLATFORM      = bsd_sparc
+  endif
+  HS_ARCH            = sparc
+endif
+
+# amd64
+ifneq (,$(findstring $(ARCH), amd64 x86_64))
+  ifeq ($(ARCH_DATA_MODEL), 64)
+    ARCH_DATA_MODEL = 64
+    MAKE_ARGS       += LP64=1
+    PLATFORM        = bsd-amd64
+    VM_PLATFORM     = bsd_amd64
+    HS_ARCH         = x86
+  else
+    ARCH_DATA_MODEL = 32
+    PLATFORM        = bsd-i586
+    VM_PLATFORM     = bsd_i486
+    HS_ARCH         = x86
+    # We have to reset ARCH to i386 since SRCARCH relies on it
+    ARCH            = i386   
+  endif
+endif
+
+# i386
+ifeq ($(ARCH), i386)
+  ifeq ($(ARCH_DATA_MODEL), 64)
+    ARCH_DATA_MODEL = 64
+    MAKE_ARGS       += LP64=1
+    PLATFORM        = bsd-amd64
+    VM_PLATFORM     = bsd_amd64
+    HS_ARCH         = x86
+    # We have to reset ARCH to amd64 since SRCARCH relies on it
+    ARCH            = amd64
+  else
+    ARCH_DATA_MODEL  = 32
+    PLATFORM         = bsd-i586
+    VM_PLATFORM      = bsd_i486
+    HS_ARCH          = x86
+  endif
+endif
+
+# ARM
+ifeq ($(ARCH), arm)
+  ARCH_DATA_MODEL  = 32
+  PLATFORM         = bsd-arm
+  VM_PLATFORM      = bsd_arm
+  HS_ARCH          = arm
+endif
+
+# PPC
+ifeq ($(ARCH), ppc)
+  ARCH_DATA_MODEL  = 32
+  PLATFORM         = bsd-ppc
+  VM_PLATFORM      = bsd_ppc
+  HS_ARCH          = ppc
+endif
+
+JDK_INCLUDE_SUBDIR=bsd
+
+# Library suffix
+OS_VENDOR:=$(shell uname -s)
+ifeq ($(OS_VENDOR),Darwin)
+  LIBRARY_SUFFIX=dylib
+else
+  LIBRARY_SUFFIX=so
+endif
+
+# FIXUP: The subdirectory for a debug build is NOT the same on all platforms
+VM_DEBUG=jvmg
+
+EXPORT_LIST += $(EXPORT_DOCS_DIR)/platform/jvmti/jvmti.html
+
+# client and server subdirectories have symbolic links to ../libjsig.so
+EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.$(LIBRARY_SUFFIX)
+EXPORT_SERVER_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/server
+
+ifndef BUILD_CLIENT_ONLY
+EXPORT_LIST += $(EXPORT_SERVER_DIR)/Xusage.txt
+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.$(LIBRARY_SUFFIX)
+endif
+
+ifneq ($(ZERO_BUILD), true)
+  ifeq ($(ARCH_DATA_MODEL), 32)
+    EXPORT_CLIENT_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/client
+    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/Xusage.txt
+    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.$(LIBRARY_SUFFIX)
+  endif
+endif
+
+# Serviceability Binaries
+# No SA Support for PPC, IA64, ARM or zero
+ADD_SA_BINARIES/x86   = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
+                        $(EXPORT_LIB_DIR)/sa-jdi.jar
+ADD_SA_BINARIES/sparc = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
+                        $(EXPORT_LIB_DIR)/sa-jdi.jar
+ADD_SA_BINARIES/universal = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
+                            $(EXPORT_LIB_DIR)/sa-jdi.jar
+ADD_SA_BINARIES/ppc   =
+ADD_SA_BINARIES/ia64  =
+ADD_SA_BINARIES/arm   =
+ADD_SA_BINARIES/zero  =
+
+EXPORT_LIST += $(ADD_SA_BINARIES/$(HS_ARCH))
+
+UNIVERSAL_LIPO_LIST += $(EXPORT_JRE_LIB_DIR)/libjsig.$(LIBRARY_SUFFIX)
+UNIVERSAL_LIPO_LIST += $(EXPORT_JRE_LIB_DIR)/libsaproc.$(LIBRARY_SUFFIX)
+UNIVERSAL_LIPO_LIST += $(EXPORT_JRE_LIB_DIR)/server/libjvm.$(LIBRARY_SUFFIX)
+
+UNIVERSAL_COPY_LIST += $(EXPORT_JRE_LIB_DIR)/server/Xusage.txt
+UNIVERSAL_COPY_LIST += $(EXPORT_JRE_LIB_DIR)/client/Xusage.txt
+UNIVERSAL_COPY_LIST += $(EXPORT_JRE_LIB_DIR)/client/libjvm.$(LIBRARY_SUFFIX)
diff --git a/hotspot/make/bsd/makefiles/dtrace.make b/hotspot/make/bsd/makefiles/dtrace.make
new file mode 100644
index 0000000..77e9c2f
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/dtrace.make
@@ -0,0 +1,303 @@
+#
+# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Rules to build jvm_db/dtrace, used by vm.make
+
+# We build libjvm_dtrace/libjvm_db/dtrace for COMPILER1 and COMPILER2
+# but not for CORE or KERNEL configurations.
+
+ifneq ("${TYPE}", "CORE")
+ifneq ("${TYPE}", "KERNEL")
+
+ifeq ($(OS_VENDOR), Darwin)
+# we build dtrace for macosx using USDT2 probes
+
+DtraceOutDir = $(GENERATED)/dtracefiles
+
+# Bsd does not build libjvm_db, does not compile on macosx
+# disabled in build: rule in vm.make
+JVM_DB = libjvm_db
+#LIBJVM_DB = libjvm_db.dylib
+LIBJVM_DB = libjvm$(G_SUFFIX)_db.dylib
+
+JVM_DTRACE = jvm_dtrace
+#LIBJVM_DTRACE = libjvm_dtrace.dylib
+LIBJVM_DTRACE = libjvm$(G_SUFFIX)_dtrace.dylib
+
+JVMOFFS = JvmOffsets
+JVMOFFS.o = $(JVMOFFS).o
+GENOFFS = generate$(JVMOFFS)
+
+DTRACE_SRCDIR = $(GAMMADIR)/src/os/$(Platform_os_family)/dtrace
+DTRACE = dtrace
+DTRACE.o = $(DTRACE).o
+
+# to remove '-g' option which causes link problems
+# also '-z nodefs' is used as workaround
+GENOFFS_CFLAGS = $(shell echo $(CFLAGS) | sed -e 's/ -g / /g' -e 's/ -g0 / /g';)
+
+ifdef LP64
+DTRACE_OPTS = -D_LP64
+endif
+
+# making libjvm_db
+
+# Use mapfile with libjvm_db.so
+LIBJVM_DB_MAPFILE = # no mapfile for usdt2 # $(MAKEFILES_DIR)/mapfile-vers-jvm_db
+#LFLAGS_JVM_DB += $(MAPFLAG:FILENAME=$(LIBJVM_DB_MAPFILE))
+
+# Use mapfile with libjvm_dtrace.so
+LIBJVM_DTRACE_MAPFILE = # no mapfile for usdt2 # $(MAKEFILES_DIR)/mapfile-vers-jvm_dtrace
+#LFLAGS_JVM_DTRACE += $(MAPFLAG:FILENAME=$(LIBJVM_DTRACE_MAPFILE))
+
+LFLAGS_JVM_DB += $(PICFLAG) # -D_REENTRANT
+LFLAGS_JVM_DTRACE += $(PICFLAG) # -D_REENTRANT
+
+ISA = $(subst i386,i486,$(BUILDARCH))
+
+# Making 64/libjvm_db.so: 64-bit version of libjvm_db.so which handles 32-bit libjvm.so
+ifneq ("${ISA}","${BUILDARCH}")
+
+XLIBJVM_DB = 64/$(LIBJVM_DB)
+XLIBJVM_DB_G = 64/$(LIBJVM_DB_G)
+XLIBJVM_DTRACE = 64/$(LIBJVM_DTRACE)
+XLIBJVM_DTRACE_G = 64/$(LIBJVM_DTRACE_G)
+XARCH = $(subst sparcv9,v9,$(shell echo $(ISA)))
+
+$(XLIBJVM_DB): $(DTRACE_SRCDIR)/$(JVM_DB).c $(JVMOFFS).h $(LIBJVM_DB_MAPFILE)
+	@echo Making $@
+	$(QUIETLY) mkdir -p 64/ ; \
+	$(CC) $(SYMFLAG) -xarch=$(XARCH) -D$(TYPE) -I. -I$(GENERATED) \
+		$(SHARED_FLAG) $(LFLAGS_JVM_DB) -o $@ $(DTRACE_SRCDIR)/$(JVM_DB).c #-lc
+#	[ -f $(XLIBJVM_DB_G) ] || { ln -s $(LIBJVM_DB) $(XLIBJVM_DB_G); }
+
+$(XLIBJVM_DTRACE): $(DTRACE_SRCDIR)/$(JVM_DTRACE).c $(DTRACE_SRCDIR)/$(JVM_DTRACE).h $(LIBJVM_DTRACE_MAPFILE)
+	@echo Making $@
+	$(QUIETLY) mkdir -p 64/ ; \
+	$(CC) $(SYMFLAG) -xarch=$(XARCH) -D$(TYPE) -I. \
+		$(SHARED_FLAG) $(LFLAGS_JVM_DTRACE) -o $@ $(DTRACE_SRCDIR)/$(JVM_DTRACE).c #-lc -lthread -ldoor
+#	[ -f $(XLIBJVM_DTRACE_G) ] || { ln -s $(LIBJVM_DTRACE) $(XLIBJVM_DTRACE_G); }
+
+endif # ifneq ("${ISA}","${BUILDARCH}")
+
+LFLAGS_GENOFFS += -L.
+
+lib$(GENOFFS).dylib: $(DTRACE_SRCDIR)/$(GENOFFS).cpp $(DTRACE_SRCDIR)/$(GENOFFS).h \
+                  $(LIBJVM.o)
+	$(QUIETLY) $(CCC) $(CPPFLAGS) $(GENOFFS_CFLAGS) $(SHARED_FLAG) $(PICFLAG) \
+		 $(LFLAGS_GENOFFS) -o $@ $(DTRACE_SRCDIR)/$(GENOFFS).cpp -ljvm
+
+$(GENOFFS): $(DTRACE_SRCDIR)/$(GENOFFS)Main.c lib$(GENOFFS).dylib
+	$(QUIETLY) $(LINK.CC) -o $@ $(DTRACE_SRCDIR)/$(GENOFFS)Main.c \
+		./lib$(GENOFFS).dylib
+
+# $@.tmp is created first to avoid an empty $(JVMOFFS).h if an error occurs.
+$(JVMOFFS).h: $(GENOFFS)
+	$(QUIETLY) DYLD_LIBRARY_PATH=. ./$(GENOFFS) -header > $@.tmp; touch $@; \
+	if [ `diff $@.tmp $@ > /dev/null 2>&1; echo $$?` -ne 0 ] ; \
+	then rm -f $@; mv $@.tmp $@; \
+	else rm -f $@.tmp; \
+	fi
+
+$(JVMOFFS)Index.h: $(GENOFFS)
+	$(QUIETLY) DYLD_LIBRARY_PATH=. ./$(GENOFFS) -index > $@.tmp; touch $@; \
+	if [ `diff $@.tmp $@ > /dev/null 2>&1; echo $$?` -ne 0 ] ; \
+	then rm -f $@; mv $@.tmp $@; \
+	else rm -f $@.tmp; \
+	fi
+
+$(JVMOFFS).cpp: $(GENOFFS) $(JVMOFFS).h $(JVMOFFS)Index.h
+	$(QUIETLY) DYLD_LIBRARY_PATH=. ./$(GENOFFS) -table > $@.tmp; touch $@; \
+	if [ `diff $@.tmp $@ > /dev/null 2>&1; echo $$?` -ne 0 ] ; \
+	then rm -f $@; mv $@.tmp $@; \
+	else rm -f $@.tmp; \
+	fi
+
+$(JVMOFFS.o): $(JVMOFFS).h $(JVMOFFS).cpp 
+	$(QUIETLY) $(CCC) -c -I. -o $@ $(ARCHFLAG) -D$(TYPE) $(JVMOFFS).cpp
+
+$(LIBJVM_DB): $(DTRACE_SRCDIR)/$(JVM_DB).c $(JVMOFFS.o) $(XLIBJVM_DB) $(LIBJVM_DB_MAPFILE)
+	@echo Making $@
+	$(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) -D$(TYPE) -I. -I$(GENERATED) \
+		$(SHARED_FLAG) $(LFLAGS_JVM_DB) -o $@ $(DTRACE_SRCDIR)/$(JVM_DB).c -Wall # -lc
+#	[ -f $(LIBJVM_DB_G) ] || { ln -s $@ $(LIBJVM_DB_G); }
+
+$(LIBJVM_DTRACE): $(DTRACE_SRCDIR)/$(JVM_DTRACE).c $(XLIBJVM_DTRACE) $(DTRACE_SRCDIR)/$(JVM_DTRACE).h $(LIBJVM_DTRACE_MAPFILE)
+	@echo Making $@
+	$(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) -D$(TYPE) -I.  \
+		$(SHARED_FLAG) $(LFLAGS_JVM_DTRACE) -o $@ $(DTRACE_SRCDIR)/$(JVM_DTRACE).c #-lc -lthread -ldoor
+#	[ -f $(LIBJVM_DTRACE_G) ] || { ln -s $@ $(LIBJVM_DTRACE_G); }
+
+#$(DTRACE).d: $(DTRACE_SRCDIR)/hotspot.d $(DTRACE_SRCDIR)/hotspot_jni.d \
+#             $(DTRACE_SRCDIR)/hs_private.d $(DTRACE_SRCDIR)/jhelper.d
+#	$(QUIETLY) cat $^ > $@
+
+$(DtraceOutDir):
+	mkdir $(DtraceOutDir)
+
+$(DtraceOutDir)/hotspot.h: $(DTRACE_SRCDIR)/hotspot.d | $(DtraceOutDir)
+	$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/hotspot.d
+
+$(DtraceOutDir)/hotspot_jni.h: $(DTRACE_SRCDIR)/hotspot_jni.d | $(DtraceOutDir)
+	$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/hotspot_jni.d
+
+$(DtraceOutDir)/hs_private.h: $(DTRACE_SRCDIR)/hs_private.d | $(DtraceOutDir)
+	$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/hs_private.d
+
+$(DtraceOutDir)/jhelper.h: $(DTRACE_SRCDIR)/jhelper.d $(JVMOFFS).o | $(DtraceOutDir)
+	$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/jhelper.d
+
+# jhelper currently disabled
+dtrace_gen_headers: $(DtraceOutDir)/hotspot.h $(DtraceOutDir)/hotspot_jni.h $(DtraceOutDir)/hs_private.h 
+
+DTraced_Files = ciEnv.o \
+                classLoadingService.o \
+                compileBroker.o \
+                hashtable.o \
+                instanceKlass.o \
+                java.o \
+                jni.o \
+                jvm.o \
+                memoryManager.o \
+                nmethod.o \
+                objectMonitor.o \
+                runtimeService.o \
+                sharedRuntime.o \
+                synchronizer.o \
+                thread.o \
+                unsafe.o \
+                vmThread.o \
+                vmCMSOperations.o \
+                vmPSOperations.o \
+                vmGCOperations.o \
+
+# Dtrace is available, so we build $(DTRACE.o)  
+#$(DTRACE.o): $(DTRACE).d $(JVMOFFS).h $(JVMOFFS)Index.h $(DTraced_Files)
+#	@echo Compiling $(DTRACE).d
+
+#	$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -G -xlazyload -o $@ -s $(DTRACE).d \
+#     $(DTraced_Files) ||\
+#  STATUS=$$?;\
+#	if [ x"$$STATUS" = x"1" -a \
+#       x`uname -r` = x"5.10" -a \
+#       x`uname -p` = x"sparc" ]; then\
+#    echo "*****************************************************************";\
+#    echo "* If you are building server compiler, and the error message is ";\
+#    echo "* \"incorrect ELF machine type...\", you have run into solaris bug ";\
+#    echo "* 6213962, \"dtrace -G doesn't work on sparcv8+ object files\".";\
+#    echo "* Either patch/upgrade your system (>= S10u1_15), or set the ";\
+#    echo "* environment variable HOTSPOT_DISABLE_DTRACE_PROBES to disable ";\
+#    echo "* dtrace probes for this build.";\
+#    echo "*****************************************************************";\
+#  fi;\
+#  exit $$STATUS
+  # Since some DTraced_Files are in LIBJVM.o and they are touched by this
+  # command, and libgenerateJvmOffsets.so depends on LIBJVM.o, 'make' will
+  # think it needs to rebuild libgenerateJvmOffsets.so and thus JvmOffsets*
+  # files, but it doesn't, so we touch the necessary files to prevent later
+  # recompilation. Note: we only touch the necessary files if they already
+  # exist in order to close a race where an empty file can be created
+  # before the real build rule is executed.
+  # But, we can't touch the *.h files:  This rule depends
+  # on them, and that would cause an infinite cycle of rebuilding.
+  # Neither the *.h or *.ccp files need to be touched, since they have
+  # rules which do not update them when the generator file has not
+  # changed their contents.
+#	$(QUIETLY) if [ -f lib$(GENOFFS).so ]; then touch lib$(GENOFFS).so; fi
+#	$(QUIETLY) if [ -f $(GENOFFS) ]; then touch $(GENOFFS); fi
+#	$(QUIETLY) if [ -f $(JVMOFFS.o) ]; then touch $(JVMOFFS.o); fi
+
+.PHONY: dtraceCheck
+
+#SYSTEM_DTRACE_H = /usr/include/dtrace.h
+SYSTEM_DTRACE_PROG = /usr/sbin/dtrace
+#PATCH_DTRACE_PROG = /opt/SUNWdtrd/sbin/dtrace
+systemDtraceFound := $(wildcard ${SYSTEM_DTRACE_PROG})
+#patchDtraceFound := $(wildcard ${PATCH_DTRACE_PROG})
+#systemDtraceHdrFound := $(wildcard $(SYSTEM_DTRACE_H))
+
+#ifneq ("$(systemDtraceHdrFound)", "") 
+#CFLAGS += -DHAVE_DTRACE_H
+#endif
+
+#ifneq ("$(patchDtraceFound)", "")
+#DTRACE_PROG=$(PATCH_DTRACE_PROG)
+#DTRACE_INCL=-I/opt/SUNWdtrd/include
+#else
+ifneq ("$(systemDtraceFound)", "")
+DTRACE_PROG=$(SYSTEM_DTRACE_PROG)
+else
+
+endif # ifneq ("$(systemDtraceFound)", "")
+#endif # ifneq ("$(patchDtraceFound)", "")
+
+ifneq ("${DTRACE_PROG}", "")
+ifeq ("${HOTSPOT_DISABLE_DTRACE_PROBES}", "")
+
+DTRACE_OBJS = $(DTRACE.o) #$(JVMOFFS.o)
+CFLAGS += -DDTRACE_ENABLED #$(DTRACE_INCL)
+#clangCFLAGS += -DDTRACE_ENABLED -fno-optimize-sibling-calls
+#MAPFILE_DTRACE_OPT = $(MAPFILE_DTRACE)
+
+
+dtraceCheck:
+
+dtrace_stuff: dtrace_gen_headers
+	$(QUIETLY) echo "dtrace headers generated"
+
+
+else # manually disabled
+
+dtraceCheck:
+	$(QUIETLY) echo "**NOTICE** Dtrace support disabled via environment variable"
+
+dtrace_stuff:
+
+endif # ifeq ("${HOTSPOT_DISABLE_DTRACE_PROBES}", "")
+
+else # No dtrace program found
+
+dtraceCheck:
+	$(QUIETLY) echo "**NOTICE** Dtrace support disabled: not supported by system"
+
+dtrace_stuff:
+
+endif # ifneq ("${dtraceFound}", "")
+
+endif # ifeq ($(OS_VENDOR), Darwin)
+
+
+else # KERNEL build
+
+dtraceCheck:
+	$(QUIETLY) echo "**NOTICE** Dtrace support disabled for KERNEL builds"
+
+endif # ifneq ("${TYPE}", "KERNEL")
+
+else # CORE build
+
+dtraceCheck:
+	$(QUIETLY) echo "**NOTICE** Dtrace support disabled for CORE builds"
+
+endif # ifneq ("${TYPE}", "CORE")
diff --git a/hotspot/make/bsd/makefiles/fastdebug.make b/hotspot/make/bsd/makefiles/fastdebug.make
new file mode 100644
index 0000000..c550d9b
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/fastdebug.make
@@ -0,0 +1,64 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making debug version of VM
+
+# Compiler specific OPT_CFLAGS are passed in from gcc.make, sparcWorks.make
+OPT_CFLAGS/DEFAULT= $(OPT_CFLAGS)
+OPT_CFLAGS/BYFILE = $(OPT_CFLAGS/$@)$(OPT_CFLAGS/DEFAULT$(OPT_CFLAGS/$@))
+
+# (OPT_CFLAGS/SLOWER is also available, to alter compilation of buggy files)
+
+ifeq ($(BUILDARCH), ia64)
+  # Bug in GCC, causes hang.  -O1 will override the -O3 specified earlier
+  OPT_CFLAGS/callGenerator.o += -O1
+  OPT_CFLAGS/ciTypeFlow.o += -O1
+  OPT_CFLAGS/compile.o += -O1
+  OPT_CFLAGS/concurrentMarkSweepGeneration.o += -O1
+  OPT_CFLAGS/doCall.o += -O1
+  OPT_CFLAGS/generateOopMap.o += -O1
+  OPT_CFLAGS/generateOptoStub.o += -O1
+  OPT_CFLAGS/graphKit.o += -O1
+  OPT_CFLAGS/instanceKlass.o += -O1
+  OPT_CFLAGS/interpreterRT_ia64.o += -O1
+  OPT_CFLAGS/output.o += -O1
+  OPT_CFLAGS/parse1.o += -O1
+  OPT_CFLAGS/runtime.o += -O1
+  OPT_CFLAGS/synchronizer.o += -O1
+endif
+
+
+# If you set HOTSPARC_GENERIC=yes, you disable all OPT_CFLAGS settings
+CFLAGS$(HOTSPARC_GENERIC) += $(OPT_CFLAGS/BYFILE)
+
+# Set the environment variable HOTSPARC_GENERIC to "true"
+# to inhibit the effect of the previous line on CFLAGS.
+
+# Linker mapfile
+MAPFILE = $(GAMMADIR)/make/bsd/makefiles/mapfile-vers-debug
+
+G_SUFFIX = _g
+VERSION = optimized
+SYSDEFS += -DASSERT -DFASTDEBUG
+PICFLAGS = DEFAULT
diff --git a/hotspot/make/bsd/makefiles/gcc.make b/hotspot/make/bsd/makefiles/gcc.make
new file mode 100644
index 0000000..6214845
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/gcc.make
@@ -0,0 +1,307 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+OS_VENDOR = $(shell uname -s)
+
+#------------------------------------------------------------------------
+# CC, CPP & AS
+
+# When cross-compiling the ALT_COMPILER_PATH points
+# to the cross-compilation toolset
+ifdef CROSS_COMPILE_ARCH
+ CPP = $(ALT_COMPILER_PATH)/g++
+ CC  = $(ALT_COMPILER_PATH)/gcc
+ HOSTCPP = g++
+ HOSTCC  = gcc
+else ifneq ($(OS_VENDOR), Darwin)
+ CXX = g++
+ CPP = $(CXX)
+ CC  = gcc
+ HOSTCPP = $(CPP)
+ HOSTCC  = $(CC)
+endif
+
+# i486 hotspot requires -mstackrealign on Darwin.
+# llvm-gcc supports this in Xcode 3.2.6 and 4.0.
+# gcc-4.0 supports this on earlier versions.
+# Prefer llvm-gcc where available.
+ifeq ($(OS_VENDOR), Darwin)
+  ifeq ($(origin CXX), default)
+   CXX = llvm-g++
+  endif
+  ifeq ($(origin CC), default)
+   CC  = llvm-gcc
+  endif
+  CPP  = $(CXX)
+
+  ifeq ($(ARCH), i486)
+  LLVM_SUPPORTS_STACKREALIGN := $(shell \
+   [ "0"`llvm-gcc -v 2>&1 | grep LLVM | sed -E "s/.*LLVM build ([0-9]+).*/\1/"` -gt "2333" ] \
+   && echo true || echo false)
+
+  ifeq ($(LLVM_SUPPORTS_STACKREALIGN), true)
+    CXX32 ?= llvm-g++
+    CC32  ?= llvm-gcc
+  else
+    CXX32 ?= g++-4.0
+    CC32  ?= gcc-4.0
+  endif
+  CPP = $(CXX32)
+  CC  = $(CC32)
+  endif
+
+  HOSTCPP = $(CPP)
+  HOSTCC  = $(CC)
+endif
+
+AS   = $(CC) -c -x assembler-with-cpp
+
+# -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only
+# prints the numbers (e.g. "2.95", "3.2.1")
+CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1)
+CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2)
+
+# check for precompiled headers support
+ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0"
+# Allow the user to turn off precompiled headers from the command line.
+ifneq ($(USE_PRECOMPILED_HEADER),0)
+USE_PRECOMPILED_HEADER=1
+PRECOMPILED_HEADER_DIR=.
+PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp
+PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch
+endif
+endif
+
+
+#------------------------------------------------------------------------
+# Compiler flags
+
+# position-independent code
+PICFLAG = -fPIC
+
+VM_PICFLAG/LIBJVM = $(PICFLAG)
+VM_PICFLAG/AOUT   =
+VM_PICFLAG        = $(VM_PICFLAG/$(LINK_INTO))
+
+ifeq ($(ZERO_BUILD), true)
+CFLAGS += $(LIBFFI_CFLAGS)
+endif
+ifeq ($(SHARK_BUILD), true)
+CFLAGS += $(LLVM_CFLAGS)
+endif
+CFLAGS += $(VM_PICFLAG)
+CFLAGS += -fno-rtti
+CFLAGS += -fno-exceptions
+CFLAGS += -pthread
+CFLAGS += -fcheck-new
+# version 4 and above support fvisibility=hidden (matches jni_x86.h file)
+# except 4.1.2 gives pointless warnings that can't be disabled (afaik)
+ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
+CFLAGS += -fvisibility=hidden
+endif
+
+ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
+ARCHFLAG/i486    = -m32 -march=i586
+ARCHFLAG/amd64   = -m64
+ARCHFLAG/ia64    =
+ARCHFLAG/sparc   = -m32 -mcpu=v9
+ARCHFLAG/sparcv9 = -m64 -mcpu=v9
+ARCHFLAG/zero    = $(ZERO_ARCHFLAG)
+
+# Darwin-specific build flags
+ifeq ($(OS_VENDOR), Darwin)
+  # Ineffecient 16-byte stack re-alignment on Darwin/IA32
+  ARCHFLAG/i486 += -mstackrealign
+endif
+
+CFLAGS     += $(ARCHFLAG)
+AOUT_FLAGS += $(ARCHFLAG)
+LFLAGS     += $(ARCHFLAG)
+ASFLAGS    += $(ARCHFLAG)
+
+ifdef E500V2
+CFLAGS += -DE500V2
+endif
+
+# Use C++ Interpreter
+ifdef CC_INTERP
+  CFLAGS += -DCC_INTERP
+endif
+
+# Build for embedded targets
+ifdef JAVASE_EMBEDDED
+  CFLAGS += -DJAVASE_EMBEDDED
+endif
+
+# Keep temporary files (.ii, .s)
+ifdef NEED_ASM
+  CFLAGS += -save-temps
+else
+  CFLAGS += -pipe
+endif
+
+# Compiler warnings are treated as errors
+ifneq ($(COMPILER_WARNINGS_FATAL),false)
+  WARNINGS_ARE_ERRORS = -Werror
+endif
+
+# Except for a few acceptable ones
+# Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
+# conversions which might affect the values. To avoid that, we need to turn
+# it off explicitly. 
+ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
+ACCEPTABLE_WARNINGS = -Wpointer-arith -Wsign-compare
+else
+ACCEPTABLE_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare
+endif
+
+CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS)
+# Special cases
+CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 
+# XXXDARWIN: for _dyld_bind_fully_image_containing_address
+ifeq ($(OS_VENDOR), Darwin)
+  CFLAGS_WARN/os_bsd.o = $(CFLAGS_WARN/DEFAULT) -Wno-deprecated-declarations
+endif
+
+
+# The flags to use for an Optimized g++ build
+ifeq ($(OS_VENDOR), Darwin)
+  # use -Os by default, unless -O3 can be proved to be worth the cost, as per policy
+  # <http://wikis.sun.com/display/OpenJDK/Mac+OS+X+Port+Compilers>
+  OPT_CFLAGS += -Os
+else
+  OPT_CFLAGS += -O3
+endif
+
+# Hotspot uses very unstrict aliasing turn this optimization off
+OPT_CFLAGS += -fno-strict-aliasing
+
+# The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 
+# if we use expensive-optimizations
+ifeq ($(BUILDARCH), ia64)
+OPT_CFLAGS += -fno-expensive-optimizations
+endif
+
+OPT_CFLAGS/NOOPT=-O0
+
+# 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 
+ifneq "$(shell expr \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) = 3 \) \))" "0"
+OPT_CFLAGS/mulnode.o += -O0
+endif
+
+# Flags for generating make dependency flags.
+ifneq ("${CC_VER_MAJOR}", "2")
+DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
+endif
+
+# -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp.
+ifneq ($(USE_PRECOMPILED_HEADER),1)
+CFLAGS += -DDONT_USE_PRECOMPILED_HEADER
+endif
+
+#------------------------------------------------------------------------
+# Linker flags
+
+# statically link libstdc++.so, work with gcc but ignored by g++
+STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
+
+# statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x.
+ifneq ("${CC_VER_MAJOR}", "2")
+STATIC_LIBGCC += -static-libgcc
+endif
+
+ifeq ($(BUILDARCH), ia64)
+LFLAGS += -Wl,-relax
+endif
+
+# Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
+MAPFLAG = -Xlinker --version-script=FILENAME
+
+#
+# Shared Library
+#
+ifeq ($(OS_VENDOR), Darwin)
+  # Standard linker flags
+  LFLAGS +=
+
+  # Darwin doesn't use ELF and doesn't support version scripts
+  LDNOMAP = true
+
+  # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
+  SONAMEFLAG =
+
+  # Build shared library
+  SHARED_FLAG = -Wl,-install_name,@rpath/$(@F) -dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $(VM_PICFLAG)
+
+  # Keep symbols even they are not used
+  #AOUT_FLAGS += -Xlinker -export-dynamic
+else
+  # Enable linker optimization
+  LFLAGS += -Xlinker -O1
+
+  # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
+  SONAMEFLAG = -Xlinker -soname=SONAME
+
+  # Build shared library
+  SHARED_FLAG = -shared $(VM_PICFLAG)
+
+  # Keep symbols even they are not used
+  AOUT_FLAGS += -Xlinker -export-dynamic
+endif
+
+#------------------------------------------------------------------------
+# Debug flags
+
+# Use the stabs format for debugging information (this is the default
+# on gcc-2.91). It's good enough, has all the information about line
+# numbers and local variables, and libjvm_g.so is only about 16M.
+# Change this back to "-g" if you want the most expressive format.
+# (warning: that could easily inflate libjvm_g.so to 150M!)
+# Note: The Itanium gcc compiler crashes when using -gstabs.
+DEBUG_CFLAGS/ia64  = -g
+DEBUG_CFLAGS/amd64 = -g
+DEBUG_CFLAGS/arm   = -g
+DEBUG_CFLAGS/ppc   = -g
+DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH))
+ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),)
+DEBUG_CFLAGS += -gstabs
+endif
+
+# DEBUG_BINARIES overrides everything, use full -g debug information
+ifeq ($(DEBUG_BINARIES), true)
+  DEBUG_CFLAGS = -g
+  CFLAGS += $(DEBUG_CFLAGS)
+endif
+
+# If we are building HEADLESS, pass on to VM
+# so it can set the java.awt.headless property
+ifdef HEADLESS
+CFLAGS += -DHEADLESS
+endif
+
+# We are building Embedded for a small device
+# favor code space over speed
+ifdef MINIMIZE_RAM_USAGE
+CFLAGS += -DMINIMIZE_RAM_USAGE
+endif
diff --git a/hotspot/make/bsd/makefiles/hp.make b/hotspot/make/bsd/makefiles/hp.make
new file mode 100644
index 0000000..e0b262a
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/hp.make
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making premium version of VM
+
+TYPE=HP
+
+CFLAGS += -DCOMPILER2
diff --git a/hotspot/make/bsd/makefiles/hp1.make b/hotspot/make/bsd/makefiles/hp1.make
new file mode 100644
index 0000000..2e37a6e
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/hp1.make
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making premium version of VM
+
+TYPE=HP1
+
+CFLAGS += -DCOMPILER1
diff --git a/hotspot/make/bsd/makefiles/i486.make b/hotspot/make/bsd/makefiles/i486.make
new file mode 100644
index 0000000..86e825d
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/i486.make
@@ -0,0 +1,34 @@
+#
+# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# TLS helper, assembled from .s file
+
+# The copied fdlibm routines in sharedRuntimeTrig.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrig.o = $(OPT_CFLAGS/NOOPT)
+# The copied fdlibm routines in sharedRuntimeTrans.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrans.o = $(OPT_CFLAGS/NOOPT)
+# Must also specify if CPU is little endian
+CFLAGS += -DVM_LITTLE_ENDIAN
+
+OPT_CFLAGS/compactingPermGenGen.o = -O1
diff --git a/hotspot/make/bsd/makefiles/ia64.make b/hotspot/make/bsd/makefiles/ia64.make
new file mode 100644
index 0000000..0fa65f2
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/ia64.make
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+#
+# IA64 only uses c++ based interpreter
+CFLAGS += -DCC_INTERP -D_LP64=1 -DVM_LITTLE_ENDIAN
+# Hotspot uses very unstrict aliasing turn this optimization off
+OPT_CFLAGS += -fno-strict-aliasing
+ifeq ($(VERSION),debug)
+ASM_FLAGS= -DDEBUG
+else
+ASM_FLAGS=
+endif
+# workaround gcc bug in compiling varargs
+OPT_CFLAGS/jni.o = -O0
+
+# gcc/ia64 has a bug that internal gcc functions linked with libjvm.so
+# are made public. Hiding those symbols will cause undefined symbol error
+# when VM is dropped into older JDK. We probably will need an IA64
+# mapfile to include those symbols as a workaround. Disable linker mapfile 
+# for now.
+LDNOMAP=true
diff --git a/hotspot/make/bsd/makefiles/jsig.make b/hotspot/make/bsd/makefiles/jsig.make
new file mode 100644
index 0000000..80be208
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/jsig.make
@@ -0,0 +1,67 @@
+#
+# Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Rules to build signal interposition library, used by vm.make
+
+# libjsig[_g].so: signal interposition library
+JSIG   = jsig
+JSIG_G = $(JSIG)$(G_SUFFIX)
+
+ifeq ($(OS_VENDOR), Darwin)
+  LIBJSIG   = lib$(JSIG).dylib
+  LIBJSIG_G = lib$(JSIG_G).dylib
+else
+  LIBJSIG   = lib$(JSIG).so
+  LIBJSIG_G = lib$(JSIG_G).so
+endif
+
+JSIGSRCDIR = $(GAMMADIR)/src/os/$(Platform_os_family)/vm
+
+DEST_JSIG  = $(JDK_LIBDIR)/$(LIBJSIG)
+
+LIBJSIG_MAPFILE = $(MAKEFILES_DIR)/mapfile-vers-jsig
+
+# On Bsd we really dont want a mapfile, as this library is small 
+# and preloaded using LD_PRELOAD, making functions private will 
+# cause problems with interposing. See CR: 6466665
+# LFLAGS_JSIG += $(MAPFLAG:FILENAME=$(LIBJSIG_MAPFILE))
+
+LFLAGS_JSIG += -D_GNU_SOURCE -pthread $(LDFLAGS_HASH_STYLE)
+
+# DEBUG_BINARIES overrides everything, use full -g debug information
+ifeq ($(DEBUG_BINARIES), true)
+  JSIG_DEBUG_CFLAGS = -g
+endif
+
+$(LIBJSIG): $(JSIGSRCDIR)/jsig.c $(LIBJSIG_MAPFILE)
+	@echo Making signal interposition lib...
+	$(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) $(SHARED_FLAG) $(PICFLAG) \
+                         $(LFLAGS_JSIG) $(JSIG_DEBUG_CFLAGS) -o $@ $<
+	$(QUIETLY) [ -f $(LIBJSIG_G) ] || { ln -s $@ $(LIBJSIG_G); }
+
+install_jsig: $(LIBJSIG)
+	@echo "Copying $(LIBJSIG) to $(DEST_JSIG)"
+	$(QUIETLY) cp -f $(LIBJSIG) $(DEST_JSIG) && echo "Done"
+
+.PHONY: install_jsig
diff --git a/hotspot/make/bsd/makefiles/jvmg.make b/hotspot/make/bsd/makefiles/jvmg.make
new file mode 100644
index 0000000..8c56368
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/jvmg.make
@@ -0,0 +1,41 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making debug version of VM
+
+# Compiler specific DEBUG_CFLAGS are passed in from gcc.make, sparcWorks.make
+DEBUG_CFLAGS/DEFAULT= $(DEBUG_CFLAGS)
+DEBUG_CFLAGS/BYFILE = $(DEBUG_CFLAGS/$@)$(DEBUG_CFLAGS/DEFAULT$(DEBUG_CFLAGS/$@))
+CFLAGS += $(DEBUG_CFLAGS/BYFILE)
+
+# Set the environment variable HOTSPARC_GENERIC to "true"
+# to inhibit the effect of the previous line on CFLAGS.
+
+# Linker mapfile
+MAPFILE = $(GAMMADIR)/make/bsd/makefiles/mapfile-vers-debug
+
+G_SUFFIX = _g
+VERSION = debug
+SYSDEFS += -DASSERT -DDEBUG
+PICFLAGS = DEFAULT
diff --git a/hotspot/make/bsd/makefiles/jvmti.make b/hotspot/make/bsd/makefiles/jvmti.make
new file mode 100644
index 0000000..ee3cc1e
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/jvmti.make
@@ -0,0 +1,117 @@
+#
+# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# This makefile (jvmti.make) is included from the jvmti.make in the
+# build directories.
+#
+# It knows how to build and run the tools to generate jvmti.
+
+include $(GAMMADIR)/make/bsd/makefiles/rules.make
+
+# #########################################################################
+
+TOPDIR      = $(shell echo `pwd`)
+GENERATED   = $(TOPDIR)/../generated
+JvmtiOutDir = $(GENERATED)/jvmtifiles
+
+JvmtiSrcDir = $(GAMMADIR)/src/share/vm/prims
+InterpreterSrcDir = $(GAMMADIR)/src/share/vm/interpreter
+
+# set VPATH so make knows where to look for source files
+Src_Dirs_V += $(JvmtiSrcDir)
+VPATH += $(Src_Dirs_V:%=%:)
+
+JvmtiGeneratedNames = \
+        jvmtiEnv.hpp \
+        jvmtiEnter.cpp \
+        jvmtiEnterTrace.cpp \
+        jvmtiEnvRecommended.cpp \
+        bytecodeInterpreterWithChecks.cpp \
+        jvmti.h \
+
+JvmtiEnvFillSource = $(JvmtiSrcDir)/jvmtiEnvFill.java
+JvmtiEnvFillClass = $(JvmtiOutDir)/jvmtiEnvFill.class
+
+JvmtiGenSource = $(JvmtiSrcDir)/jvmtiGen.java
+JvmtiGenClass = $(JvmtiOutDir)/jvmtiGen.class
+
+JvmtiGeneratedFiles = $(JvmtiGeneratedNames:%=$(JvmtiOutDir)/%)
+
+XSLT = $(QUIETLY) $(REMOTE) $(RUN.JAVA) -classpath $(JvmtiOutDir) jvmtiGen
+
+.PHONY: all jvmtidocs clean cleanall
+
+# #########################################################################
+
+all: $(JvmtiGeneratedFiles)
+
+both = $(JvmtiGenClass) $(JvmtiSrcDir)/jvmti.xml $(JvmtiSrcDir)/jvmtiLib.xsl
+
+$(JvmtiGenClass): $(JvmtiGenSource)
+	$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -d $(JvmtiOutDir) $(JvmtiGenSource)
+
+$(JvmtiEnvFillClass): $(JvmtiEnvFillSource)
+	$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -d $(JvmtiOutDir) $(JvmtiEnvFillSource)
+
+$(JvmtiOutDir)/jvmtiEnter.cpp: $(both) $(JvmtiSrcDir)/jvmtiEnter.xsl
+	@echo Generating $@
+	$(XSLT) -IN $(JvmtiSrcDir)/jvmti.xml -XSL $(JvmtiSrcDir)/jvmtiEnter.xsl -OUT $(JvmtiOutDir)/jvmtiEnter.cpp -PARAM interface jvmti
+
+$(JvmtiOutDir)/bytecodeInterpreterWithChecks.cpp: $(JvmtiGenClass) $(InterpreterSrcDir)/bytecodeInterpreter.cpp $(InterpreterSrcDir)/bytecodeInterpreterWithChecks.xml $(InterpreterSrcDir)/bytecodeInterpreterWithChecks.xsl
+	@echo Generating $@
+	$(XSLT) -IN $(InterpreterSrcDir)/bytecodeInterpreterWithChecks.xml -XSL $(InterpreterSrcDir)/bytecodeInterpreterWithChecks.xsl -OUT $(JvmtiOutDir)/bytecodeInterpreterWithChecks.cpp 
+
+$(JvmtiOutDir)/jvmtiEnterTrace.cpp: $(both) $(JvmtiSrcDir)/jvmtiEnter.xsl
+	@echo Generating $@
+	$(XSLT) -IN $(JvmtiSrcDir)/jvmti.xml -XSL $(JvmtiSrcDir)/jvmtiEnter.xsl -OUT $(JvmtiOutDir)/jvmtiEnterTrace.cpp -PARAM interface jvmti -PARAM trace Trace
+
+$(JvmtiOutDir)/jvmtiEnvRecommended.cpp: $(both) $(JvmtiSrcDir)/jvmtiEnv.xsl $(JvmtiSrcDir)/jvmtiEnv.cpp $(JvmtiEnvFillClass)
+	@echo Generating $@
+	$(XSLT) -IN $(JvmtiSrcDir)/jvmti.xml -XSL $(JvmtiSrcDir)/jvmtiEnv.xsl -OUT $(JvmtiOutDir)/jvmtiEnvStub.cpp
+	$(QUIETLY) $(REMOTE) $(RUN.JAVA) -classpath $(JvmtiOutDir) jvmtiEnvFill $(JvmtiSrcDir)/jvmtiEnv.cpp $(JvmtiOutDir)/jvmtiEnvStub.cpp $(JvmtiOutDir)/jvmtiEnvRecommended.cpp
+
+$(JvmtiOutDir)/jvmtiEnv.hpp: $(both) $(JvmtiSrcDir)/jvmtiHpp.xsl
+	@echo Generating $@
+	$(XSLT) -IN $(JvmtiSrcDir)/jvmti.xml -XSL $(JvmtiSrcDir)/jvmtiHpp.xsl -OUT $(JvmtiOutDir)/jvmtiEnv.hpp
+
+$(JvmtiOutDir)/jvmti.h: $(both) $(JvmtiSrcDir)/jvmtiH.xsl
+	@echo Generating $@
+	$(XSLT) -IN $(JvmtiSrcDir)/jvmti.xml -XSL $(JvmtiSrcDir)/jvmtiH.xsl -OUT $(JvmtiOutDir)/jvmti.h
+
+jvmtidocs:  $(JvmtiOutDir)/jvmti.html 
+
+$(JvmtiOutDir)/jvmti.html: $(both) $(JvmtiSrcDir)/jvmti.xsl
+	@echo Generating $@
+	$(XSLT) -IN $(JvmtiSrcDir)/jvmti.xml -XSL $(JvmtiSrcDir)/jvmti.xsl -OUT $(JvmtiOutDir)/jvmti.html
+
+# #########################################################################
+
+clean :
+	rm $(JvmtiGenClass) $(JvmtiEnvFillClass) $(JvmtiGeneratedFiles)
+
+cleanall :
+	rm $(JvmtiGenClass) $(JvmtiEnvFillClass) $(JvmtiGeneratedFiles)
+
+# #########################################################################
+
diff --git a/hotspot/make/bsd/makefiles/launcher.make b/hotspot/make/bsd/makefiles/launcher.make
new file mode 100644
index 0000000..b405fbc
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/launcher.make
@@ -0,0 +1,93 @@
+#
+# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Rules to build gamma launcher, used by vm.make
+
+
+LAUNCHER_SCRIPT = hotspot
+LAUNCHER   = gamma
+
+LAUNCHERDIR   := $(GAMMADIR)/src/os/posix/launcher
+LAUNCHERDIR_SHARE := $(GAMMADIR)/src/share/tools/launcher
+LAUNCHERFLAGS := $(ARCHFLAG) \
+                -I$(LAUNCHERDIR) -I$(GAMMADIR)/src/share/vm/prims \
+                -I$(LAUNCHERDIR_SHARE) \
+                -DFULL_VERSION=\"$(HOTSPOT_RELEASE_VERSION)\" \
+                -DJDK_MAJOR_VERSION=\"$(JDK_MAJOR_VERSION)\" \
+                -DJDK_MINOR_VERSION=\"$(JDK_MINOR_VERSION)\" \
+                -DARCH=\"$(LIBARCH)\" \
+                -DGAMMA \
+                -DLAUNCHER_TYPE=\"gamma\" \
+                -DLINK_INTO_$(LINK_INTO) \
+                $(TARGET_DEFINES)
+
+ifeq ($(LINK_INTO),AOUT)
+  LAUNCHER.o                 = launcher.o $(JVM_OBJ_FILES)
+  LAUNCHER_MAPFILE           = mapfile_reorder
+  LFLAGS_LAUNCHER$(LDNOMAP) += $(MAPFLAG:FILENAME=$(LAUNCHER_MAPFILE))
+  LFLAGS_LAUNCHER           += $(SONAMEFLAG:SONAME=$(LIBJVM)) $(STATIC_LIBGCC)
+  LIBS_LAUNCHER             += $(STATIC_STDCXX) $(LIBS)
+else
+  LAUNCHER.o                 = launcher.o
+  LFLAGS_LAUNCHER           += -L`pwd`
+  LIBS_LAUNCHER             += -l$(JVM) $(LIBS)
+endif
+
+LINK_LAUNCHER = $(LINK.c)
+
+LINK_LAUNCHER/PRE_HOOK  = $(LINK_LIB.CC/PRE_HOOK)
+LINK_LAUNCHER/POST_HOOK = $(LINK_LIB.CC/POST_HOOK)
+
+LAUNCHER_OUT = launcher
+
+SUFFIXES += .d
+
+SOURCES := $(shell find $(LAUNCHERDIR) -name "*.c")
+SOURCES_SHARE := $(shell find $(LAUNCHERDIR_SHARE) -name "*.c")
+
+OBJS := $(patsubst $(LAUNCHERDIR)/%.c,$(LAUNCHER_OUT)/%.o,$(SOURCES)) $(patsubst $(LAUNCHERDIR_SHARE)/%.c,$(LAUNCHER_OUT)/%.o,$(SOURCES_SHARE))
+
+DEPFILES := $(patsubst %.o,%.d,$(OBJS))
+-include $(DEPFILES)
+
+$(LAUNCHER_OUT)/%.o: $(LAUNCHERDIR_SHARE)/%.c
+	$(QUIETLY) [ -d $(LAUNCHER_OUT) ] || { mkdir -p $(LAUNCHER_OUT); }
+	$(QUIETLY) $(CC) -g -o $@ -c $< -MMD $(LAUNCHERFLAGS) $(CPPFLAGS)
+
+$(LAUNCHER_OUT)/%.o: $(LAUNCHERDIR)/%.c
+	$(QUIETLY) [ -d $(LAUNCHER_OUT) ] || { mkdir -p $(LAUNCHER_OUT); }
+	$(QUIETLY) $(CC) -g -o $@ -c $< -MMD $(LAUNCHERFLAGS) $(CPPFLAGS)
+
+$(LAUNCHER): $(OBJS) $(LIBJVM) $(LAUNCHER_MAPFILE)
+	$(QUIETLY) echo Linking launcher...
+	$(QUIETLY) $(LINK_LAUNCHER/PRE_HOOK)
+	$(QUIETLY) $(LINK_LAUNCHER) $(LFLAGS_LAUNCHER) -o $@ $(OBJS) $(LIBS_LAUNCHER)
+	$(QUIETLY) $(LINK_LAUNCHER/POST_HOOK)
+
+$(LAUNCHER): $(LAUNCHER_SCRIPT)
+
+$(LAUNCHER_SCRIPT): $(LAUNCHERDIR)/launcher.script
+	$(QUIETLY) sed -e 's/@@LIBARCH@@/$(LIBARCH)/g' $< > $@
+	$(QUIETLY) chmod +x $@
+
diff --git a/hotspot/make/bsd/makefiles/mapfile-vers-debug b/hotspot/make/bsd/makefiles/mapfile-vers-debug
new file mode 100644
index 0000000..9a2d42f
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/mapfile-vers-debug
@@ -0,0 +1,291 @@
+#
+# @(#)mapfile-vers-debug	1.18 07/10/25 16:47:35
+#
+
+#
+# Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Define public interface.
+
+SUNWprivate_1.1 {
+        global:
+                # JNI
+                JNI_CreateJavaVM;
+                JNI_GetCreatedJavaVMs;
+                JNI_GetDefaultJavaVMInitArgs;
+
+                # JVM
+                JVM_Accept;
+                JVM_ActiveProcessorCount;
+                JVM_AllocateNewArray;
+                JVM_AllocateNewObject;
+                JVM_ArrayCopy;
+                JVM_AssertionStatusDirectives;
+                JVM_Available;
+                JVM_Bind;
+                JVM_ClassDepth;
+                JVM_ClassLoaderDepth;
+                JVM_Clone;
+                JVM_Close;
+                JVM_CX8Field;
+                JVM_CompileClass;
+                JVM_CompileClasses;
+                JVM_CompilerCommand;
+                JVM_Connect;
+                JVM_ConstantPoolGetClassAt;
+                JVM_ConstantPoolGetClassAtIfLoaded;
+                JVM_ConstantPoolGetDoubleAt;
+                JVM_ConstantPoolGetFieldAt;
+                JVM_ConstantPoolGetFieldAtIfLoaded;
+                JVM_ConstantPoolGetFloatAt;
+                JVM_ConstantPoolGetIntAt;
+                JVM_ConstantPoolGetLongAt;
+                JVM_ConstantPoolGetMethodAt;
+                JVM_ConstantPoolGetMethodAtIfLoaded;
+                JVM_ConstantPoolGetMemberRefInfoAt;
+                JVM_ConstantPoolGetSize;
+                JVM_ConstantPoolGetStringAt;
+                JVM_ConstantPoolGetUTF8At;
+                JVM_CountStackFrames;
+                JVM_CurrentClassLoader;
+                JVM_CurrentLoadedClass;
+                JVM_CurrentThread;
+                JVM_CurrentTimeMillis;
+                JVM_DefineClass;
+                JVM_DefineClassWithSource;
+                JVM_DefineClassWithSourceCond;
+                JVM_DesiredAssertionStatus;
+                JVM_DisableCompiler;
+                JVM_DoPrivileged;
+                JVM_DTraceGetVersion;
+                JVM_DTraceActivate;
+                JVM_DTraceIsProbeEnabled;
+                JVM_DTraceIsSupported;
+                JVM_DTraceDispose;
+                JVM_DumpAllStacks;
+                JVM_DumpThreads;
+                JVM_EnableCompiler;
+                JVM_Exit;
+                JVM_FillInStackTrace;
+                JVM_FindClassFromClass;
+                JVM_FindClassFromClassLoader;
+                JVM_FindClassFromBootLoader;
+                JVM_FindLibraryEntry;
+                JVM_FindLoadedClass;
+                JVM_FindPrimitiveClass;
+                JVM_FindSignal;
+                JVM_FreeMemory;
+                JVM_GC;
+                JVM_GetAllThreads;
+                JVM_GetArrayElement;
+                JVM_GetArrayLength;
+                JVM_GetCPClassNameUTF;
+                JVM_GetCPFieldClassNameUTF;
+                JVM_GetCPFieldModifiers;
+                JVM_GetCPFieldNameUTF;
+                JVM_GetCPFieldSignatureUTF;
+                JVM_GetCPMethodClassNameUTF;
+                JVM_GetCPMethodModifiers;
+                JVM_GetCPMethodNameUTF;
+                JVM_GetCPMethodSignatureUTF;
+                JVM_GetCallerClass;
+                JVM_GetClassAccessFlags;
+                JVM_GetClassAnnotations;
+                JVM_GetClassCPEntriesCount;
+                JVM_GetClassCPTypes;
+                JVM_GetClassConstantPool;
+                JVM_GetClassContext;
+                JVM_GetClassDeclaredConstructors;
+                JVM_GetClassDeclaredFields;
+                JVM_GetClassDeclaredMethods;
+                JVM_GetClassFieldsCount;
+                JVM_GetClassInterfaces;
+                JVM_GetClassLoader;
+                JVM_GetClassMethodsCount;
+                JVM_GetClassModifiers;
+                JVM_GetClassName;
+                JVM_GetClassNameUTF;
+		JVM_GetClassSignature;
+                JVM_GetClassSigners;
+                JVM_GetComponentType;
+                JVM_GetDeclaredClasses;
+                JVM_GetDeclaringClass;
+                JVM_GetEnclosingMethodInfo;
+                JVM_GetFieldAnnotations;
+                JVM_GetFieldIxModifiers;
+                JVM_GetHostName;
+                JVM_GetInheritedAccessControlContext;
+                JVM_GetInterfaceVersion;
+                JVM_GetLastErrorString;
+                JVM_GetManagement;
+                JVM_GetMethodAnnotations;
+                JVM_GetMethodDefaultAnnotationValue;
+                JVM_GetMethodIxArgsSize;
+                JVM_GetMethodIxByteCode;
+                JVM_GetMethodIxByteCodeLength;
+                JVM_GetMethodIxExceptionIndexes;
+                JVM_GetMethodIxExceptionTableEntry;
+                JVM_GetMethodIxExceptionTableLength;
+                JVM_GetMethodIxExceptionsCount;
+                JVM_GetMethodIxLocalsCount;
+                JVM_GetMethodIxMaxStack;
+                JVM_GetMethodIxModifiers;
+                JVM_GetMethodIxNameUTF;
+                JVM_GetMethodIxSignatureUTF;
+                JVM_GetMethodParameterAnnotations;
+                JVM_GetPrimitiveArrayElement;
+                JVM_GetProtectionDomain;
+                JVM_GetSockName;
+                JVM_GetSockOpt;
+                JVM_GetStackAccessControlContext;
+                JVM_GetStackTraceDepth;
+                JVM_GetStackTraceElement;
+                JVM_GetSystemPackage;
+                JVM_GetSystemPackages;
+                JVM_GetThreadStateNames;
+                JVM_GetThreadStateValues;
+                JVM_GetVersionInfo;
+                JVM_Halt;
+                JVM_HoldsLock;
+                JVM_IHashCode;
+                JVM_InitAgentProperties;
+                JVM_InitProperties;
+                JVM_InitializeCompiler;
+                JVM_InitializeSocketLibrary;
+                JVM_InternString;
+                JVM_Interrupt;
+                JVM_InvokeMethod;
+                JVM_IsArrayClass;
+                JVM_IsConstructorIx;
+                JVM_IsInterface;
+                JVM_IsInterrupted;
+                JVM_IsNaN;
+                JVM_IsPrimitiveClass;
+                JVM_IsSameClassPackage;
+                JVM_IsSilentCompiler;
+                JVM_IsSupportedJNIVersion;
+                JVM_IsThreadAlive;
+                JVM_LatestUserDefinedLoader;
+                JVM_Listen;
+                JVM_LoadClass0;
+                JVM_LoadLibrary;
+                JVM_Lseek;
+                JVM_MaxObjectInspectionAge;
+                JVM_MaxMemory;
+                JVM_MonitorNotify;
+                JVM_MonitorNotifyAll;
+                JVM_MonitorWait;
+                JVM_NanoTime;
+                JVM_NativePath;
+                JVM_NewArray;
+                JVM_NewInstanceFromConstructor;
+                JVM_NewMultiArray;
+                JVM_OnExit;
+                JVM_Open;
+                JVM_PrintStackTrace;
+                JVM_RaiseSignal;
+                JVM_RawMonitorCreate;
+                JVM_RawMonitorDestroy;
+                JVM_RawMonitorEnter;
+                JVM_RawMonitorExit;
+                JVM_Read;
+                JVM_Recv;
+                JVM_RecvFrom;
+                JVM_RegisterSignal;
+                JVM_ReleaseUTF;
+                JVM_ResolveClass;
+                JVM_ResumeThread;
+                JVM_Send;
+                JVM_SendTo;
+                JVM_SetArrayElement;
+                JVM_SetClassSigners;
+                JVM_SetLength;
+                JVM_SetPrimitiveArrayElement;
+                JVM_SetProtectionDomain;
+                JVM_SetSockOpt;
+                JVM_SetThreadPriority;
+                JVM_Sleep;
+                JVM_Socket;
+                JVM_SocketAvailable;
+                JVM_SocketClose;
+                JVM_SocketShutdown;
+                JVM_StartThread;
+                JVM_StopThread;
+                JVM_SuspendThread;
+                JVM_SupportsCX8;
+                JVM_Sync;
+                JVM_Timeout;
+                JVM_TotalMemory;
+                JVM_TraceInstructions;
+                JVM_TraceMethodCalls;
+                JVM_UnloadLibrary;
+                JVM_Write;
+                JVM_Yield;
+                JVM_handle_bsd_signal;
+
+                # Old reflection routines
+                # These do not need to be present in the product build in JDK 1.4
+                # but their code has not been removed yet because there will not
+                # be a substantial code savings until JVM_InvokeMethod and
+                # JVM_NewInstanceFromConstructor can also be removed; see
+                # reflectionCompat.hpp.
+                JVM_GetClassConstructor;
+                JVM_GetClassConstructors;
+                JVM_GetClassField;
+                JVM_GetClassFields;
+                JVM_GetClassMethod;
+                JVM_GetClassMethods;
+                JVM_GetField;
+                JVM_GetPrimitiveField;
+                JVM_NewInstance;
+                JVM_SetField;
+                JVM_SetPrimitiveField;
+
+                # debug JVM
+                JVM_AccessVMBooleanFlag;
+                JVM_AccessVMIntFlag;
+                JVM_VMBreakPoint;
+
+                # miscellaneous functions
+                jio_fprintf;
+                jio_printf;
+                jio_snprintf;
+                jio_vfprintf;
+                jio_vsnprintf;
+                fork1;
+                numa_warn;
+                numa_error;
+
+                # Needed because there is no JVM interface for this.
+                sysThreadAvailableStackWithSlack;
+
+                # This is for Forte Analyzer profiling support.
+                AsyncGetCallTrace;
+
+		# INSERT VTABLE SYMBOLS HERE
+
+        local:
+                *;
+};
+
diff --git a/hotspot/make/bsd/makefiles/mapfile-vers-jsig b/hotspot/make/bsd/makefiles/mapfile-vers-jsig
new file mode 100644
index 0000000..8a67504
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/mapfile-vers-jsig
@@ -0,0 +1,40 @@
+#
+
+#
+# Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Define library interface.
+
+SUNWprivate_1.1 {
+        global:
+            JVM_begin_signal_setting;
+            JVM_end_signal_setting;
+            JVM_get_libjsig_version;
+            JVM_get_signal_action;
+            sigaction;
+            signal;
+            sigset;
+        local:
+                *;
+};
diff --git a/hotspot/make/bsd/makefiles/mapfile-vers-product b/hotspot/make/bsd/makefiles/mapfile-vers-product
new file mode 100644
index 0000000..7a5d7c7
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/mapfile-vers-product
@@ -0,0 +1,286 @@
+#
+# @(#)mapfile-vers-product	1.19 08/02/12 10:56:37
+#
+
+#
+# Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Define public interface.
+
+SUNWprivate_1.1 {
+        global:
+                # JNI
+                JNI_CreateJavaVM;
+                JNI_GetCreatedJavaVMs;
+                JNI_GetDefaultJavaVMInitArgs;
+
+                # JVM
+                JVM_Accept;
+                JVM_ActiveProcessorCount;
+                JVM_AllocateNewArray;
+                JVM_AllocateNewObject;
+                JVM_ArrayCopy;
+                JVM_AssertionStatusDirectives;
+                JVM_Available;
+                JVM_Bind;
+                JVM_ClassDepth;
+                JVM_ClassLoaderDepth;
+                JVM_Clone;
+                JVM_Close;
+                JVM_CX8Field;
+                JVM_CompileClass;
+                JVM_CompileClasses;
+                JVM_CompilerCommand;
+                JVM_Connect;
+                JVM_ConstantPoolGetClassAt;
+                JVM_ConstantPoolGetClassAtIfLoaded;
+                JVM_ConstantPoolGetDoubleAt;
+                JVM_ConstantPoolGetFieldAt;
+                JVM_ConstantPoolGetFieldAtIfLoaded;
+                JVM_ConstantPoolGetFloatAt;
+                JVM_ConstantPoolGetIntAt;
+                JVM_ConstantPoolGetLongAt;
+                JVM_ConstantPoolGetMethodAt;
+                JVM_ConstantPoolGetMethodAtIfLoaded;
+                JVM_ConstantPoolGetMemberRefInfoAt;
+                JVM_ConstantPoolGetSize;
+                JVM_ConstantPoolGetStringAt;
+                JVM_ConstantPoolGetUTF8At;
+                JVM_CountStackFrames;
+                JVM_CurrentClassLoader;
+                JVM_CurrentLoadedClass;
+                JVM_CurrentThread;
+                JVM_CurrentTimeMillis;
+                JVM_DefineClass;
+                JVM_DefineClassWithSource;
+                JVM_DefineClassWithSourceCond;
+                JVM_DesiredAssertionStatus;
+                JVM_DisableCompiler;
+                JVM_DoPrivileged;
+                JVM_DTraceGetVersion;
+                JVM_DTraceActivate;
+                JVM_DTraceIsProbeEnabled;
+                JVM_DTraceIsSupported;
+                JVM_DTraceDispose;
+                JVM_DumpAllStacks;
+                JVM_DumpThreads;
+                JVM_EnableCompiler;
+                JVM_Exit;
+                JVM_FillInStackTrace;
+                JVM_FindClassFromClass;
+                JVM_FindClassFromClassLoader;
+                JVM_FindClassFromBootLoader;
+                JVM_FindLibraryEntry;
+                JVM_FindLoadedClass;
+                JVM_FindPrimitiveClass;
+                JVM_FindSignal;
+                JVM_FreeMemory;
+                JVM_GC;
+                JVM_GetAllThreads;
+                JVM_GetArrayElement;
+                JVM_GetArrayLength;
+                JVM_GetCPClassNameUTF;
+                JVM_GetCPFieldClassNameUTF;
+                JVM_GetCPFieldModifiers;
+                JVM_GetCPFieldNameUTF;
+                JVM_GetCPFieldSignatureUTF;
+                JVM_GetCPMethodClassNameUTF;
+                JVM_GetCPMethodModifiers;
+                JVM_GetCPMethodNameUTF;
+                JVM_GetCPMethodSignatureUTF;
+                JVM_GetCallerClass;
+                JVM_GetClassAccessFlags;
+                JVM_GetClassAnnotations;
+                JVM_GetClassCPEntriesCount;
+                JVM_GetClassCPTypes;
+                JVM_GetClassConstantPool;
+                JVM_GetClassContext;
+                JVM_GetClassDeclaredConstructors;
+                JVM_GetClassDeclaredFields;
+                JVM_GetClassDeclaredMethods;
+                JVM_GetClassFieldsCount;
+                JVM_GetClassInterfaces;
+                JVM_GetClassLoader;
+                JVM_GetClassMethodsCount;
+                JVM_GetClassModifiers;
+                JVM_GetClassName;
+                JVM_GetClassNameUTF;
+                JVM_GetClassSignature;
+                JVM_GetClassSigners;
+                JVM_GetComponentType;
+                JVM_GetDeclaredClasses;
+                JVM_GetDeclaringClass;
+                JVM_GetEnclosingMethodInfo;
+                JVM_GetFieldAnnotations;
+                JVM_GetFieldIxModifiers;
+                JVM_GetHostName;
+                JVM_GetInheritedAccessControlContext;
+                JVM_GetInterfaceVersion;
+                JVM_GetLastErrorString;
+                JVM_GetManagement;
+                JVM_GetMethodAnnotations;
+                JVM_GetMethodDefaultAnnotationValue;
+                JVM_GetMethodIxArgsSize;
+                JVM_GetMethodIxByteCode;
+                JVM_GetMethodIxByteCodeLength;
+                JVM_GetMethodIxExceptionIndexes;
+                JVM_GetMethodIxExceptionTableEntry;
+                JVM_GetMethodIxExceptionTableLength;
+                JVM_GetMethodIxExceptionsCount;
+                JVM_GetMethodIxLocalsCount;
+                JVM_GetMethodIxMaxStack;
+                JVM_GetMethodIxModifiers;
+                JVM_GetMethodIxNameUTF;
+                JVM_GetMethodIxSignatureUTF;
+                JVM_GetMethodParameterAnnotations;
+                JVM_GetPrimitiveArrayElement;
+                JVM_GetProtectionDomain;
+                JVM_GetSockName;
+                JVM_GetSockOpt;
+                JVM_GetStackAccessControlContext;
+                JVM_GetStackTraceDepth;
+                JVM_GetStackTraceElement;
+                JVM_GetSystemPackage;
+                JVM_GetSystemPackages;
+                JVM_GetThreadStateNames;
+                JVM_GetThreadStateValues;
+                JVM_GetVersionInfo;
+                JVM_Halt;
+                JVM_HoldsLock;
+                JVM_IHashCode;
+                JVM_InitAgentProperties;
+                JVM_InitProperties;
+                JVM_InitializeCompiler;
+                JVM_InitializeSocketLibrary;
+                JVM_InternString;
+                JVM_Interrupt;
+                JVM_InvokeMethod;
+                JVM_IsArrayClass;
+                JVM_IsConstructorIx;
+                JVM_IsInterface;
+                JVM_IsInterrupted;
+                JVM_IsNaN;
+                JVM_IsPrimitiveClass;
+                JVM_IsSameClassPackage;
+                JVM_IsSilentCompiler;
+                JVM_IsSupportedJNIVersion;
+                JVM_IsThreadAlive;
+                JVM_LatestUserDefinedLoader;
+                JVM_Listen;
+                JVM_LoadClass0;
+                JVM_LoadLibrary;
+                JVM_Lseek;
+                JVM_MaxObjectInspectionAge;
+                JVM_MaxMemory;
+                JVM_MonitorNotify;
+                JVM_MonitorNotifyAll;
+                JVM_MonitorWait;
+                JVM_NanoTime;
+                JVM_NativePath;
+                JVM_NewArray;
+                JVM_NewInstanceFromConstructor;
+                JVM_NewMultiArray;
+                JVM_OnExit;
+                JVM_Open;
+                JVM_PrintStackTrace;
+                JVM_RaiseSignal;
+                JVM_RawMonitorCreate;
+                JVM_RawMonitorDestroy;
+                JVM_RawMonitorEnter;
+                JVM_RawMonitorExit;
+                JVM_Read;
+                JVM_Recv;
+                JVM_RecvFrom;
+                JVM_RegisterSignal;
+                JVM_ReleaseUTF;
+                JVM_ResolveClass;
+                JVM_ResumeThread;
+                JVM_Send;
+                JVM_SendTo;
+                JVM_SetArrayElement;
+                JVM_SetClassSigners;
+                JVM_SetLength;
+                JVM_SetPrimitiveArrayElement;
+                JVM_SetProtectionDomain;
+                JVM_SetSockOpt;
+                JVM_SetThreadPriority;
+                JVM_Sleep;
+                JVM_Socket;
+                JVM_SocketAvailable;
+                JVM_SocketClose;
+                JVM_SocketShutdown;
+                JVM_StartThread;
+                JVM_StopThread;
+                JVM_SuspendThread;
+                JVM_SupportsCX8;
+                JVM_Sync;
+                JVM_Timeout;
+                JVM_TotalMemory;
+                JVM_TraceInstructions;
+                JVM_TraceMethodCalls;
+                JVM_UnloadLibrary;
+                JVM_Write;
+                JVM_Yield;
+                JVM_handle_bsd_signal;
+
+                # Old reflection routines
+                # These do not need to be present in the product build in JDK 1.4
+                # but their code has not been removed yet because there will not
+                # be a substantial code savings until JVM_InvokeMethod and
+                # JVM_NewInstanceFromConstructor can also be removed; see
+                # reflectionCompat.hpp.
+                JVM_GetClassConstructor;
+                JVM_GetClassConstructors;
+                JVM_GetClassField;
+                JVM_GetClassFields;
+                JVM_GetClassMethod;
+                JVM_GetClassMethods;
+                JVM_GetField;
+                JVM_GetPrimitiveField;
+                JVM_NewInstance;
+                JVM_SetField;
+                JVM_SetPrimitiveField;
+
+                # miscellaneous functions
+                jio_fprintf;
+                jio_printf;
+                jio_snprintf;
+                jio_vfprintf;
+                jio_vsnprintf;
+                fork1;
+                numa_warn;
+                numa_error;
+
+                # Needed because there is no JVM interface for this.
+                sysThreadAvailableStackWithSlack;
+
+                # This is for Forte Analyzer profiling support.
+                AsyncGetCallTrace;
+
+		# INSERT VTABLE SYMBOLS HERE
+
+        local:
+                *;
+};
+
diff --git a/hotspot/make/bsd/makefiles/optimized.make b/hotspot/make/bsd/makefiles/optimized.make
new file mode 100644
index 0000000..6090c97
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/optimized.make
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making optimized version of Gamma VM
+# (This is the "product", not the "release" version.)
+
+# Compiler specific OPT_CFLAGS are passed in from gcc.make, sparcWorks.make
+OPT_CFLAGS/DEFAULT= $(OPT_CFLAGS)
+OPT_CFLAGS/BYFILE = $(OPT_CFLAGS/$@)$(OPT_CFLAGS/DEFAULT$(OPT_CFLAGS/$@))
+
+# (OPT_CFLAGS/SLOWER is also available, to alter compilation of buggy files)
+
+# If you set HOTSPARC_GENERIC=yes, you disable all OPT_CFLAGS settings
+CFLAGS$(HOTSPARC_GENERIC) += $(OPT_CFLAGS/BYFILE)
+
+# Set the environment variable HOTSPARC_GENERIC to "true"
+# to inhibit the effect of the previous line on CFLAGS.
+
+# Linker mapfile
+MAPFILE = $(GAMMADIR)/make/bsd/makefiles/mapfile-vers-debug
+
+G_SUFFIX =
+VERSION = optimized
diff --git a/hotspot/make/bsd/makefiles/ppc.make b/hotspot/make/bsd/makefiles/ppc.make
new file mode 100644
index 0000000..92957f9
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/ppc.make
@@ -0,0 +1,30 @@
+#
+# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# The copied fdlibm routines in sharedRuntimeTrig.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrig.o = $(OPT_CFLAGS/NOOPT)
+
+# Must also specify if CPU is big endian
+CFLAGS += -DVM_BIG_ENDIAN
+
diff --git a/hotspot/make/bsd/makefiles/product.make b/hotspot/make/bsd/makefiles/product.make
new file mode 100644
index 0000000..1b8acbb
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/product.make
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making optimized version of Gamma VM
+# (This is the "product", not the "release" version.)
+
+# Compiler specific OPT_CFLAGS are passed in from gcc.make, sparcWorks.make
+OPT_CFLAGS/DEFAULT= $(OPT_CFLAGS)
+OPT_CFLAGS/BYFILE = $(OPT_CFLAGS/$@)$(OPT_CFLAGS/DEFAULT$(OPT_CFLAGS/$@))
+
+# (OPT_CFLAGS/SLOWER is also available, to alter compilation of buggy files)
+
+# If you set HOTSPARC_GENERIC=yes, you disable all OPT_CFLAGS settings
+CFLAGS$(HOTSPARC_GENERIC) += $(OPT_CFLAGS/BYFILE)
+
+# Set the environment variable HOTSPARC_GENERIC to "true"
+# to inhibit the effect of the previous line on CFLAGS.
+
+# Linker mapfile
+MAPFILE = $(GAMMADIR)/make/bsd/makefiles/mapfile-vers-product
+
+G_SUFFIX =
+SYSDEFS += -DPRODUCT
+VERSION = optimized
+
+# use -g to strip library as -x will discard its symbol table; -x is fine for
+# executables.
+ifdef CROSS_COMPILE_ARCH
+  STRIP = $(ALT_COMPILER_PATH)/strip
+else
+  STRIP = strip
+endif
+STRIP_LIBJVM = $(STRIP) -g $@ || exit 1;
+STRIP_AOUT   = $(STRIP) -x $@ || exit 1;
+
+# Don't strip in VM build; JDK build will strip libraries later
+# LINK_LIB.CC/POST_HOOK += $(STRIP_$(LINK_INTO))
diff --git a/hotspot/make/bsd/makefiles/profiled.make b/hotspot/make/bsd/makefiles/profiled.make
new file mode 100644
index 0000000..fa5c915
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/profiled.make
@@ -0,0 +1,30 @@
+#
+# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making profiled version of Gamma VM
+# (It is also optimized.)
+
+CFLAGS += -pg
+AOUT_FLAGS += -pg
+LDNOMAP = true
diff --git a/hotspot/make/bsd/makefiles/rules.make b/hotspot/make/bsd/makefiles/rules.make
new file mode 100644
index 0000000..12eafe8
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/rules.make
@@ -0,0 +1,216 @@
+#
+# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Common rules/macros for the vm, adlc.
+
+# Tell make that .cpp is important
+.SUFFIXES: .cpp $(SUFFIXES)
+
+# For now.  Other makefiles use CPP as the c++ compiler, but that should really
+# name the preprocessor.
+ifeq    ($(CCC),)
+CCC             = $(CPP)
+endif
+
+DEMANGLER       = c++filt
+DEMANGLE        = $(DEMANGLER) < $@ > .$@ && mv -f .$@ $@
+
+# $(CC) is the c compiler (cc/gcc), $(CCC) is the c++ compiler (CC/g++).
+C_COMPILE       = $(CC) $(CPPFLAGS) $(CFLAGS)
+CC_COMPILE      = $(CCC) $(CPPFLAGS) $(CFLAGS)
+
+AS.S            = $(AS) $(ASFLAGS)
+
+COMPILE.c       = $(C_COMPILE) -c
+GENASM.c        = $(C_COMPILE) -S
+LINK.c          = $(CC) $(LFLAGS) $(AOUT_FLAGS) $(PROF_AOUT_FLAGS)
+LINK_LIB.c      = $(CC) $(LFLAGS) $(SHARED_FLAG)
+PREPROCESS.c    = $(C_COMPILE) -E
+
+COMPILE.CC      = $(CC_COMPILE) -c
+GENASM.CC       = $(CC_COMPILE) -S
+LINK.CC         = $(CCC) $(LFLAGS) $(AOUT_FLAGS) $(PROF_AOUT_FLAGS)
+LINK_NOPROF.CC  = $(CCC) $(LFLAGS) $(AOUT_FLAGS)
+LINK_LIB.CC     = $(CCC) $(LFLAGS) $(SHARED_FLAG)
+PREPROCESS.CC   = $(CC_COMPILE) -E
+
+# cross compiling the jvm with c2 requires host compilers to build
+# adlc tool
+
+HOST.CC_COMPILE      = $(HOSTCPP) $(CPPFLAGS) $(CFLAGS)
+HOST.COMPILE.CC      = $(HOST.CC_COMPILE) -c
+HOST.LINK_NOPROF.CC  = $(HOSTCPP) $(LFLAGS) $(AOUT_FLAGS)
+
+
+# Effect of REMOVE_TARGET is to delete out-of-date files during "gnumake -k".
+REMOVE_TARGET   = rm -f $@
+
+# Synonyms.
+COMPILE.cpp     = $(COMPILE.CC)
+GENASM.cpp      = $(GENASM.CC)
+LINK.cpp        = $(LINK.CC)
+LINK_LIB.cpp    = $(LINK_LIB.CC)
+PREPROCESS.cpp  = $(PREPROCESS.CC)
+
+# Note use of ALT_BOOTDIR to explicitly specify location of java and
+# javac; this is the same environment variable used in the J2SE build
+# process for overriding the default spec, which is BOOTDIR.
+# Note also that we fall back to using JAVA_HOME if neither of these is
+# specified.
+
+ifdef ALT_BOOTDIR
+
+RUN.JAVA  = $(ALT_BOOTDIR)/bin/java
+RUN.JAVAP = $(ALT_BOOTDIR)/bin/javap
+RUN.JAVAH = $(ALT_BOOTDIR)/bin/javah
+RUN.JAR   = $(ALT_BOOTDIR)/bin/jar
+COMPILE.JAVAC = $(ALT_BOOTDIR)/bin/javac
+COMPILE.RMIC = $(ALT_BOOTDIR)/bin/rmic
+BOOT_JAVA_HOME = $(ALT_BOOTDIR)
+
+else
+
+ifdef BOOTDIR
+
+RUN.JAVA  = $(BOOTDIR)/bin/java
+RUN.JAVAP = $(BOOTDIR)/bin/javap
+RUN.JAVAH = $(BOOTDIR)/bin/javah
+RUN.JAR   = $(BOOTDIR)/bin/jar
+COMPILE.JAVAC = $(BOOTDIR)/bin/javac
+COMPILE.RMIC  = $(BOOTDIR)/bin/rmic
+BOOT_JAVA_HOME = $(BOOTDIR)
+
+else
+
+ifdef JAVA_HOME
+
+RUN.JAVA  = $(JAVA_HOME)/bin/java
+RUN.JAVAP = $(JAVA_HOME)/bin/javap
+RUN.JAVAH = $(JAVA_HOME)/bin/javah
+RUN.JAR   = $(JAVA_HOME)/bin/jar
+COMPILE.JAVAC = $(JAVA_HOME)/bin/javac
+COMPILE.RMIC  = $(JAVA_HOME)/bin/rmic
+BOOT_JAVA_HOME = $(JAVA_HOME)
+
+else
+
+# take from the PATH, if ALT_BOOTDIR, BOOTDIR and JAVA_HOME are not defined
+# note that this is to support hotspot build without SA. To build
+# SA along with hotspot, you need to define ALT_BOOTDIR, BOOTDIR or JAVA_HOME
+
+RUN.JAVA  = java
+RUN.JAVAP = javap
+RUN.JAVAH = javah
+RUN.JAR   = jar
+COMPILE.JAVAC = javac
+COMPILE.RMIC  = rmic
+
+endif
+endif
+endif
+
+COMPILE.JAVAC += $(BOOTSTRAP_JAVAC_FLAGS)
+
+SUM = /usr/bin/sum
+
+# 'gmake MAKE_VERBOSE=y' gives all the gory details.
+QUIETLY$(MAKE_VERBOSE)  = @
+RUN.JAR$(MAKE_VERBOSE) += >/dev/null
+
+# Settings for javac
+BOOT_SOURCE_LANGUAGE_VERSION = 6
+BOOT_TARGET_CLASS_VERSION = 6
+JAVAC_FLAGS = -g -encoding ascii
+BOOTSTRAP_JAVAC_FLAGS = $(JAVAC_FLAGS) -source $(BOOT_SOURCE_LANGUAGE_VERSION) -target $(BOOT_TARGET_CLASS_VERSION)
+
+# With parallel makes, print a message at the end of compilation.
+ifeq    ($(findstring j,$(MFLAGS)),j)
+COMPILE_DONE    = && { echo Done with $<; }
+endif
+
+# Include $(NONPIC_OBJ_FILES) definition
+ifndef LP64
+include $(GAMMADIR)/make/pic.make
+endif
+
+include $(GAMMADIR)/make/altsrc.make
+
+# The non-PIC object files are only generated for 32 bit platforms.
+ifdef LP64
+%.o: %.cpp
+	@echo Compiling $<
+	$(QUIETLY) $(REMOVE_TARGET)
+	$(QUIETLY) $(COMPILE.CC) $(DEPFLAGS) -o $@ $< $(COMPILE_DONE)
+else
+%.o: %.cpp
+	@echo Compiling $<
+	$(QUIETLY) $(REMOVE_TARGET)
+	$(QUIETLY) $(if $(findstring $@, $(NONPIC_OBJ_FILES)), \
+	   $(subst $(VM_PICFLAG), ,$(COMPILE.CC)) $(DEPFLAGS) -o $@ $< $(COMPILE_DONE), \
+	   $(COMPILE.CC) $(DEPFLAGS) -o $@ $< $(COMPILE_DONE))
+endif
+
+%.o: %.s
+	@echo Assembling $<
+	$(QUIETLY) $(REMOVE_TARGET)
+	$(QUIETLY) $(AS.S) $(DEPFLAGS) -o $@ $< $(COMPILE_DONE)
+
+%.s: %.cpp
+	@echo Generating assembly for $<
+	$(QUIETLY) $(GENASM.CC) -o $@ $<
+	$(QUIETLY) $(DEMANGLE) $(COMPILE_DONE)
+
+# Intermediate files (for debugging macros)
+%.i: %.cpp
+	@echo Preprocessing $< to $@
+	$(QUIETLY) $(PREPROCESS.CC) $< > $@ $(COMPILE_DONE)
+
+#  Override gnumake built-in rules which do sccs get operations badly.
+#  (They put the checked out code in the current directory, not in the
+#  directory of the original file.)  Since this is a symptom of a teamware
+#  failure, and since not all problems can be detected by gnumake due
+#  to incomplete dependency checking... just complain and stop.
+%:: s.%
+	@echo "========================================================="
+	@echo File $@
+	@echo is out of date with respect to its SCCS file.
+	@echo This file may be from an unresolved Teamware conflict.
+	@echo This is also a symptom of a Teamware bringover/putback failure
+	@echo in which SCCS files are updated but not checked out.
+	@echo Check for other out of date files in your workspace.
+	@echo "========================================================="
+	@exit 666
+
+%:: SCCS/s.%
+	@echo "========================================================="
+	@echo File $@
+	@echo is out of date with respect to its SCCS file.
+	@echo This file may be from an unresolved Teamware conflict.
+	@echo This is also a symptom of a Teamware bringover/putback failure
+	@echo in which SCCS files are updated but not checked out.
+	@echo Check for other out of date files in your workspace.
+	@echo "========================================================="
+	@exit 666
+
+.PHONY: default
diff --git a/hotspot/make/bsd/makefiles/sa.make b/hotspot/make/bsd/makefiles/sa.make
new file mode 100644
index 0000000..d01d2bb
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/sa.make
@@ -0,0 +1,117 @@
+#
+# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# This makefile (sa.make) is included from the sa.make in the
+# build directories.
+
+# This makefile is used to build Serviceability Agent java code
+# and generate JNI header file for native methods.
+
+include $(GAMMADIR)/make/bsd/makefiles/rules.make
+
+AGENT_DIR = $(GAMMADIR)/agent
+
+include $(GAMMADIR)/make/sa.files
+
+TOPDIR    = $(shell echo `pwd`)
+GENERATED = $(TOPDIR)/../generated
+
+# tools.jar is needed by the JDI - SA binding
+ifeq ($(SA_APPLE_BOOT_JAVA),true)
+  SA_CLASSPATH = $(BOOT_JAVA_HOME)/bundle/Classes/classes.jar
+else
+  SA_CLASSPATH = $(BOOT_JAVA_HOME)/lib/tools.jar
+endif
+
+# TODO: if it's a modules image, check if SA module is installed.
+MODULELIB_PATH= $(BOOT_JAVA_HOME)/lib/modules
+
+AGENT_FILES_LIST := $(GENERATED)/agent.classes.list
+
+SA_CLASSDIR = $(GENERATED)/saclasses
+
+SA_BUILD_VERSION_PROP = "sun.jvm.hotspot.runtime.VM.saBuildVersion=$(SA_BUILD_VERSION)"
+
+SA_PROPERTIES = $(SA_CLASSDIR)/sa.properties
+
+# if $(AGENT_DIR) does not exist, we don't build SA
+# also, we don't build SA on Itanium, PowerPC, ARM or zero.
+
+all: 
+	if [ -d $(AGENT_DIR) -a "$(SRCARCH)" != "ia64" \
+             -a "$(SRCARCH)" != "arm" \
+             -a "$(SRCARCH)" != "ppc" \
+             -a "$(SRCARCH)" != "zero" ] ; then \
+	   $(MAKE) -f sa.make $(GENERATED)/sa-jdi.jar; \
+	fi
+
+$(GENERATED)/sa-jdi.jar: $(AGENT_FILES)
+	$(QUIETLY) echo "Making $@"
+	$(QUIETLY) if [ "$(BOOT_JAVA_HOME)" = "" ]; then \
+	  echo "ALT_BOOTDIR, BOOTDIR or JAVA_HOME needs to be defined to build SA"; \
+	  exit 1; \
+	fi
+	$(QUIETLY) if [ ! -f $(SA_CLASSPATH) -a ! -d $(MODULELIB_PATH) ] ; then \
+	  echo "Missing $(SA_CLASSPATH) file. Use 1.6.0 or later version of JDK";\
+	  echo ""; \
+	  exit 1; \
+	fi
+	$(QUIETLY) if [ ! -d $(SA_CLASSDIR) ] ; then \
+	  mkdir -p $(SA_CLASSDIR);        \
+	fi
+# Note: When indented, make tries to execute the '$(shell' comment.
+# In some environments, cmd processors have limited line length.
+# To prevent the javac invocation in the next block from using
+# a very long cmd line, we use javac's @file-list option. We
+# generate the file lists using make's built-in 'foreach' control
+# flow which also avoids cmd processor line length issues. Since
+# the 'foreach' is done as part of make's macro expansion phase,
+# the initialization of the lists is also done in the same phase
+# using '$(shell rm ...' instead of using the more traditional
+# 'rm ...' rule.
+	$(shell rm -rf $(AGENT_FILES_LIST))
+# gnumake 3.78.1 does not accept the *'s that
+# are in AGENT_FILES, so use the shell to expand them.
+# Be extra carefull to not produce too long command lines in the shell!
+	$(foreach file,$(AGENT_FILES),$(shell ls -1 $(file) >> $(AGENT_FILES_LIST)))
+	$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES_LIST)
+	$(QUIETLY) $(REMOTE) $(COMPILE.RMIC)  -classpath $(SA_CLASSDIR) -d $(SA_CLASSDIR) sun.jvm.hotspot.debugger.remote.RemoteDebuggerServer
+	$(QUIETLY) echo "$(SA_BUILD_VERSION_PROP)" > $(SA_PROPERTIES)
+	$(QUIETLY) rm -f $(SA_CLASSDIR)/sun/jvm/hotspot/utilities/soql/sa.js
+	$(QUIETLY) cp $(AGENT_SRC_DIR)/sun/jvm/hotspot/utilities/soql/sa.js $(SA_CLASSDIR)/sun/jvm/hotspot/utilities/soql
+	$(QUIETLY) mkdir -p $(SA_CLASSDIR)/sun/jvm/hotspot/ui/resources
+	$(QUIETLY) rm -f $(SA_CLASSDIR)/sun/jvm/hotspot/ui/resources/*
+	$(QUIETLY) cp $(AGENT_SRC_DIR)/sun/jvm/hotspot/ui/resources/*.png $(SA_CLASSDIR)/sun/jvm/hotspot/ui/resources/
+	$(QUIETLY) cp -r $(AGENT_SRC_DIR)/images/* $(SA_CLASSDIR)/
+	$(QUIETLY) $(REMOTE) $(RUN.JAR) cf $@ -C $(SA_CLASSDIR)/ .
+	$(QUIETLY) $(REMOTE) $(RUN.JAR) uf $@ -C $(AGENT_SRC_DIR) META-INF/services/com.sun.jdi.connect.Connector
+	$(QUIETLY) $(REMOTE) $(RUN.JAVAH) -classpath $(SA_CLASSDIR) -d $(GENERATED) -jni sun.jvm.hotspot.debugger.x86.X86ThreadContext
+	$(QUIETLY) $(REMOTE) $(RUN.JAVAH) -classpath $(SA_CLASSDIR) -d $(GENERATED) -jni sun.jvm.hotspot.debugger.ia64.IA64ThreadContext
+	$(QUIETLY) $(REMOTE) $(RUN.JAVAH) -classpath $(SA_CLASSDIR) -d $(GENERATED) -jni sun.jvm.hotspot.debugger.amd64.AMD64ThreadContext
+	$(QUIETLY) $(REMOTE) $(RUN.JAVAH) -classpath $(SA_CLASSDIR) -d $(GENERATED) -jni sun.jvm.hotspot.debugger.sparc.SPARCThreadContext
+
+clean:
+	rm -rf $(SA_CLASSDIR)
+	rm -rf $(GENERATED)/sa-jdi.jar
+	rm -rf $(AGENT_FILES_LIST)
diff --git a/hotspot/make/bsd/makefiles/saproc.make b/hotspot/make/bsd/makefiles/saproc.make
new file mode 100644
index 0000000..458cd3a
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/saproc.make
@@ -0,0 +1,124 @@
+#
+# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Rules to build serviceability agent library, used by vm.make
+
+# libsaproc[_g].so: serviceability agent
+SAPROC   = saproc
+SAPROC_G = $(SAPROC)$(G_SUFFIX)
+
+ifeq ($(OS_VENDOR), Darwin)
+  LIBSAPROC   = lib$(SAPROC).dylib
+  LIBSAPROC_G = lib$(SAPROC_G).dylib
+else
+  LIBSAPROC   = lib$(SAPROC).so
+  LIBSAPROC_G = lib$(SAPROC_G).so
+endif
+
+AGENT_DIR = $(GAMMADIR)/agent
+
+SASRCDIR = $(AGENT_DIR)/src/os/$(Platform_os_family)
+
+NON_STUB_SASRCFILES = $(SASRCDIR)/salibelf.c          \
+                      $(SASRCDIR)/symtab.c            \
+                      $(SASRCDIR)/libproc_impl.c      \
+                      $(SASRCDIR)/ps_proc.c           \
+                      $(SASRCDIR)/ps_core.c           \
+                      $(SASRCDIR)/BsdDebuggerLocal.c
+
+ifeq ($(OS_VENDOR), FreeBSD)
+  SASRCFILES = $(NON_STUB_SASRCFILES)
+  SALIBS = -lutil -lthread_db
+  SAARCH = $(ARCHFLAG)
+else
+  ifeq ($(OS_VENDOR), Darwin)
+    SASRCFILES = $(SASRCDIR)/MacosxDebuggerLocal.m
+    SALIBS = -g -framework Foundation -F/System/Library/Frameworks/JavaVM.framework/Frameworks -framework JavaNativeFoundation -framework Security -framework CoreFoundation
+    #objc compiler blows up on -march=i586, perhaps it should not be included in the macosx intel 32-bit C++ compiles?
+    SAARCH = $(subst -march=i586,,$(ARCHFLAG))
+  else
+    SASRCFILES = $(SASRCDIR)/StubDebuggerLocal.c
+    SALIBS = 
+    SAARCH = $(ARCHFLAG)
+  endif
+endif
+
+SAMAPFILE = $(SASRCDIR)/mapfile
+
+DEST_SAPROC = $(JDK_LIBDIR)/$(LIBSAPROC)
+
+# DEBUG_BINARIES overrides everything, use full -g debug information
+ifeq ($(DEBUG_BINARIES), true)
+  SA_DEBUG_CFLAGS = -g
+endif
+
+# if $(AGENT_DIR) does not exist, we don't build SA
+# also, we don't build SA on Itanium, PPC, ARM or zero.
+
+ifneq ($(wildcard $(AGENT_DIR)),)
+ifneq ($(filter-out ia64 arm ppc zero,$(SRCARCH)),)
+  BUILDLIBSAPROC = $(LIBSAPROC)
+endif
+endif
+
+
+ifneq ($(OS_VENDOR), Darwin)
+SA_LFLAGS = $(MAPFLAG:FILENAME=$(SAMAPFILE))
+endif
+SA_LFLAGS += $(LDFLAGS_HASH_STYLE)
+
+ifeq ($(OS_VENDOR), Darwin)
+  BOOT_JAVA_INCLUDES = -I$(BOOT_JAVA_HOME)/include \
+    -I$(BOOT_JAVA_HOME)/include/$(shell uname -s | tr "[:upper:]" "[:lower:]") \
+    -I/System/Library/Frameworks/JavaVM.framework/Headers
+else
+  BOOT_JAVA_INCLUDES = -I$(BOOT_JAVA_HOME)/include \
+    -I$(BOOT_JAVA_HOME)/include/$(shell uname -s | tr "[:upper:]" "[:lower:]")
+endif
+
+$(LIBSAPROC): $(SASRCFILES) $(SAMAPFILE)
+	$(QUIETLY) if [ "$(BOOT_JAVA_HOME)" = "" ]; then \
+	  echo "ALT_BOOTDIR, BOOTDIR or JAVA_HOME needs to be defined to build SA"; \
+	  exit 1; \
+	fi
+	@echo Making SA debugger back-end...
+	$(QUIETLY) $(CC) -D$(BUILDARCH) -D_GNU_SOURCE                   \
+                   $(SYMFLAG) $(SAARCH) $(SHARED_FLAG) $(PICFLAG)     \
+	           -I$(SASRCDIR)                                        \
+	           -I$(GENERATED)                                       \
+	           $(BOOT_JAVA_INCLUDES)                                \
+	           $(SASRCFILES)                                        \
+	           $(SA_LFLAGS)                                         \
+	           $(SA_DEBUG_CFLAGS)                                   \
+	           -o $@                                                \
+	           $(SALIBS)
+	$(QUIETLY) [ -f $(LIBSAPROC_G) ] || { ln -s $@ $(LIBSAPROC_G); }
+
+install_saproc: $(BUILDLIBSAPROC)
+	$(QUIETLY) if [ -e $(LIBSAPROC) ] ; then             \
+	  echo "Copying $(LIBSAPROC) to $(DEST_SAPROC)";     \
+	  cp -f $(LIBSAPROC) $(DEST_SAPROC) && echo "Done";  \
+	fi
+
+.PHONY: install_saproc
diff --git a/hotspot/make/bsd/makefiles/shark.make b/hotspot/make/bsd/makefiles/shark.make
new file mode 100644
index 0000000..ca702ee
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/shark.make
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2008, 2010 Red Hat, Inc.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making Shark version of VM
+
+TYPE = SHARK
+
+VM_SUBDIR = server
+
+CFLAGS += -DSHARK
diff --git a/hotspot/make/bsd/makefiles/sparc.make b/hotspot/make/bsd/makefiles/sparc.make
new file mode 100644
index 0000000..ddb0513
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/sparc.make
@@ -0,0 +1,24 @@
+#
+# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
diff --git a/hotspot/make/bsd/makefiles/sparcWorks.make b/hotspot/make/bsd/makefiles/sparcWorks.make
new file mode 100644
index 0000000..6e6c841
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/sparcWorks.make
@@ -0,0 +1,104 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+#------------------------------------------------------------------------
+# CC, CPP & AS
+
+CPP = CC
+CC  = cc
+AS  = $(CC) -c
+
+HOSTCPP = $(CPP)
+HOSTCC  = $(CC)
+
+ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
+ARCHFLAG/i486    = -m32
+ARCHFLAG/amd64   = -m64
+
+CFLAGS     += $(ARCHFLAG)
+AOUT_FLAGS += $(ARCHFLAG)
+LFLAGS     += $(ARCHFLAG)
+ASFLAGS    += $(ARCHFLAG)
+
+#------------------------------------------------------------------------
+# Compiler flags
+
+# position-independent code
+PICFLAG = -KPIC
+
+CFLAGS += $(PICFLAG)
+# no more exceptions
+CFLAGS += -features=no%except
+# Reduce code bloat by reverting back to 5.0 behavior for static initializers
+CFLAGS += -features=no%split_init
+# allow zero sized arrays
+CFLAGS += -features=zla
+
+# Use C++ Interpreter
+ifdef CC_INTERP
+  CFLAGS += -DCC_INTERP
+endif
+
+# We don't need libCstd.so and librwtools7.so, only libCrun.so
+CFLAGS += -library=Crun
+LIBS += -lCrun
+
+CFLAGS += -mt
+LFLAGS += -mt
+
+# Compiler warnings are treated as errors
+#WARNINGS_ARE_ERRORS = -errwarn=%all
+CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) 
+# Special cases
+CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 
+
+# The flags to use for an Optimized build
+OPT_CFLAGS+=-xO4
+OPT_CFLAGS/NOOPT=-xO0
+
+# Flags for creating the dependency files.
+ifeq ($(shell expr $(COMPILER_REV_NUMERIC) \>= 509), 1)
+DEPFLAGS = -xMMD -xMF $(DEP_DIR)/$(@:%=%.d)
+endif
+
+# -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp.
+CFLAGS += -DDONT_USE_PRECOMPILED_HEADER
+
+#------------------------------------------------------------------------
+# Linker flags
+
+# Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
+MAPFLAG = -Wl,--version-script=FILENAME
+
+# Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
+SONAMEFLAG = -h SONAME
+
+# Build shared library
+SHARED_FLAG = -G
+
+#------------------------------------------------------------------------
+# Debug flags
+DEBUG_CFLAGS += -g
+FASTDEBUG_CFLAGS = -g0
+
diff --git a/hotspot/make/bsd/makefiles/sparcv9.make b/hotspot/make/bsd/makefiles/sparcv9.make
new file mode 100644
index 0000000..b9e4e52
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/sparcv9.make
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+
+# gcc 4.0 miscompiles this code in -m64
+OPT_CFLAGS/macro.o = -O0
+
+CFLAGS += -D_LP64=1
diff --git a/hotspot/make/bsd/makefiles/tiered.make b/hotspot/make/bsd/makefiles/tiered.make
new file mode 100644
index 0000000..da79ade
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/tiered.make
@@ -0,0 +1,31 @@
+#
+# Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Sets make macros for making tiered version of VM
+
+TYPE=TIERED
+
+VM_SUBDIR = server
+
+CFLAGS += -DCOMPILER2 -DCOMPILER1
diff --git a/hotspot/make/bsd/makefiles/top.make b/hotspot/make/bsd/makefiles/top.make
new file mode 100644
index 0000000..f85d196
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/top.make
@@ -0,0 +1,151 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# top.make is included in the Makefile in the build directories.
+# It DOES NOT include the vm dependency info in order to be faster.
+# Its main job is to implement the incremental form of make lists.
+# It also:
+#   -builds and runs adlc via adlc.make
+#   -generates JVMTI source and docs via jvmti.make (JSR-163)
+#   -generate sa-jdi.jar (JDI binding to core files)
+
+# It assumes the following flags are set:
+# CFLAGS Platform_file, Src_Dirs_I, Src_Dirs_V, SYSDEFS, AOUT, Obj_Files
+
+# -- D. Ungar (5/97) from a file by Bill Bush
+
+# Don't override the built-in $(MAKE).
+# Instead, use "gmake" (or "gnumake") from the command line.  --Rose
+#MAKE = gmake
+
+include $(GAMMADIR)/make/altsrc.make
+
+TOPDIR      = $(shell echo `pwd`)
+GENERATED   = $(TOPDIR)/../generated
+VM          = $(GAMMADIR)/src/share/vm
+Plat_File   = $(Platform_file)
+CDG         = cd $(GENERATED); 
+
+ifdef USE_PRECOMPILED_HEADER
+PrecompiledOption = -DUSE_PRECOMPILED_HEADER
+UpdatePCH         = $(MAKE) -f vm.make $(PRECOMPILED_HEADER) $(MFLAGS) 
+else
+UpdatePCH         = \# precompiled header is not used
+PrecompiledOption = 
+endif
+
+Cached_plat = $(GENERATED)/platform.current
+
+AD_Dir   = $(GENERATED)/adfiles
+ADLC     = $(AD_Dir)/adlc
+AD_Spec  = $(call altsrc-replace,$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm/$(Platform_arch_model).ad)
+AD_Src   = $(call altsrc-replace,$(HS_COMMON_SRC)/share/vm/adlc)
+AD_Names = ad_$(Platform_arch_model).hpp ad_$(Platform_arch_model).cpp
+AD_Files = $(AD_Names:%=$(AD_Dir)/%)
+
+# AD_Files_If_Required/COMPILER1 = ad_stuff
+AD_Files_If_Required/COMPILER2 = ad_stuff
+AD_Files_If_Required/TIERED = ad_stuff
+AD_Files_If_Required = $(AD_Files_If_Required/$(TYPE))
+
+# Wierd argument adjustment for "gnumake -j..."
+adjust-mflags   = $(GENERATED)/adjust-mflags
+MFLAGS-adjusted = -r `$(adjust-mflags) "$(MFLAGS)" "$(HOTSPOT_BUILD_JOBS)"`
+
+
+# default target: update lists, make vm
+# done in stages to force sequential order with parallel make
+#
+
+default: vm_build_preliminaries the_vm
+	@echo All done.
+
+# This is an explicit dependency for the sake of parallel makes.
+vm_build_preliminaries:  checks $(Cached_plat) $(AD_Files_If_Required) jvmti_stuff sa_stuff dtrace_stuff
+	@# We need a null action here, so implicit rules don't get consulted.
+
+$(Cached_plat): $(Plat_File)
+	$(CDG) cp $(Plat_File) $(Cached_plat)
+
+# make AD files as necessary
+ad_stuff: $(Cached_plat) $(adjust-mflags)
+	@$(MAKE) -f adlc.make $(MFLAGS-adjusted)
+
+# generate JVMTI files from the spec
+jvmti_stuff: $(Cached_plat) $(adjust-mflags)
+	@$(MAKE) -f jvmti.make $(MFLAGS-adjusted)
+
+ifeq ($(OS_VENDOR), Darwin)
+# generate dtrace header files
+dtrace_stuff: $(Cached_plat) $(adjust-mflags)
+	@$(MAKE) -f dtrace.make dtrace_stuff $(MFLAGS-adjusted) GENERATED=$(GENERATED)
+else
+dtrace_stuff:
+	@# We need a null action here, so implicit rules don't get consulted.
+endif
+
+# generate SA jar files and native header
+sa_stuff:
+	@$(MAKE) -f sa.make $(MFLAGS-adjusted)
+
+# and the VM: must use other makefile with dependencies included
+
+# We have to go to great lengths to get control over the -jN argument
+# to the recursive invocation of vm.make.  The problem is that gnumake
+# resets -jN to -j1 for recursive runs.  (How helpful.)
+# Note that the user must specify the desired parallelism level via a
+# command-line or environment variable name HOTSPOT_BUILD_JOBS.
+$(adjust-mflags): $(GAMMADIR)/make/$(Platform_os_family)/makefiles/adjust-mflags.sh
+	@+rm -f $@ $@+
+	@+cat $< > $@+
+	@+chmod +x $@+
+	@+mv $@+ $@
+
+the_vm: vm_build_preliminaries $(adjust-mflags)
+	@$(UpdatePCH)
+	@$(MAKE) -f vm.make $(MFLAGS-adjusted)
+
+install: the_vm
+	@$(MAKE) -f vm.make install
+
+# next rules support "make foo.[ois]"
+
+%.o %.i %.s:
+	$(UpdatePCH) 
+	$(MAKE) -f vm.make $(MFLAGS) $@
+	#$(MAKE) -f vm.make $@
+
+# this should force everything to be rebuilt
+clean: 
+	rm -f $(GENERATED)/*.class
+	$(MAKE) -f vm.make $(MFLAGS) clean
+
+# just in case it doesn't, this should do it
+realclean:
+	$(MAKE) -f vm.make $(MFLAGS) clean
+	rm -fr $(GENERATED)
+
+.PHONY: default vm_build_preliminaries
+.PHONY: lists ad_stuff jvmti_stuff sa_stuff the_vm clean realclean
+.PHONY: checks check_os_version install
diff --git a/hotspot/make/bsd/makefiles/vm.make b/hotspot/make/bsd/makefiles/vm.make
new file mode 100644
index 0000000..35eca5d
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/vm.make
@@ -0,0 +1,339 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Rules to build JVM and related libraries, included from vm.make in the build
+# directory.
+
+# Common build rules.
+MAKEFILES_DIR=$(GAMMADIR)/make/$(Platform_os_family)/makefiles
+include $(MAKEFILES_DIR)/rules.make
+include $(GAMMADIR)/make/altsrc.make
+
+default: build
+
+#----------------------------------------------------------------------
+# Defs
+
+GENERATED     = ../generated
+DEP_DIR       = $(GENERATED)/dependencies
+
+# reads the generated files defining the set of .o's and the .o .h dependencies
+-include $(DEP_DIR)/*.d
+
+# read machine-specific adjustments (%%% should do this via buildtree.make?)
+ifeq ($(ZERO_BUILD), true)
+  include $(MAKEFILES_DIR)/zeroshark.make
+else
+  include $(MAKEFILES_DIR)/$(BUILDARCH).make
+endif
+
+# set VPATH so make knows where to look for source files
+# Src_Dirs_V is everything in src/share/vm/*, plus the right os/*/vm and cpu/*/vm
+# The adfiles directory contains ad_<arch>.[ch]pp.
+# The jvmtifiles directory contains jvmti*.[ch]pp
+Src_Dirs_V += $(GENERATED)/adfiles $(GENERATED)/jvmtifiles
+VPATH += $(Src_Dirs_V:%=%:)
+
+# set INCLUDES for C preprocessor.
+Src_Dirs_I += $(GENERATED)
+# The order is important for the precompiled headers to work.
+INCLUDES += $(PRECOMPILED_HEADER_DIR:%=-I%) $(Src_Dirs_I:%=-I%)
+
+ifeq (${VERSION}, debug)
+  SYMFLAG = -g
+else
+  SYMFLAG =
+endif
+
+# HOTSPOT_RELEASE_VERSION and HOTSPOT_BUILD_VERSION are defined 
+# in $(GAMMADIR)/make/defs.make
+ifeq ($(HOTSPOT_BUILD_VERSION),)
+  BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)\""
+else
+  BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)-$(HOTSPOT_BUILD_VERSION)\""
+endif
+
+# The following variables are defined in the generated flags.make file.
+BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HS_BUILD_VER)\""
+JRE_VERSION   = -DJRE_RELEASE_VERSION="\"$(JRE_RELEASE_VER)\""
+HS_LIB_ARCH   = -DHOTSPOT_LIB_ARCH=\"$(LIBARCH)\"
+BUILD_TARGET  = -DHOTSPOT_BUILD_TARGET="\"$(TARGET)\""
+BUILD_USER    = -DHOTSPOT_BUILD_USER="\"$(HOTSPOT_BUILD_USER)\""
+VM_DISTRO     = -DHOTSPOT_VM_DISTRO="\"$(HOTSPOT_VM_DISTRO)\""
+
+CPPFLAGS =           \
+  ${SYSDEFS}         \
+  ${INCLUDES}        \
+  ${BUILD_VERSION}   \
+  ${BUILD_TARGET}    \
+  ${BUILD_USER}      \
+  ${HS_LIB_ARCH}     \
+  ${JRE_VERSION}     \
+  ${VM_DISTRO}
+
+ifdef DEFAULT_LIBPATH
+CPPFLAGS += -DDEFAULT_LIBPATH="\"$(DEFAULT_LIBPATH)\""
+endif
+
+# CFLAGS_WARN holds compiler options to suppress/enable warnings.
+CFLAGS += $(CFLAGS_WARN/BYFILE)
+
+# Do not use C++ exception handling
+CFLAGS += $(CFLAGS/NOEX)
+
+# Extra flags from gnumake's invocation or environment
+CFLAGS += $(EXTRA_CFLAGS)
+LFLAGS += $(EXTRA_CFLAGS)
+
+# Don't set excutable bit on stack segment
+# the same could be done by separate execstack command
+# Darwin is non-executable-stack by default
+ifneq ($(OS_VENDOR), Darwin)
+LFLAGS += -Xlinker -z -Xlinker noexecstack
+endif
+
+LIBS += -lm -pthread
+
+# By default, link the *.o into the library, not the executable.
+LINK_INTO$(LINK_INTO) = LIBJVM
+
+JDK_LIBDIR = $(JAVA_HOME)/jre/lib/$(LIBARCH)
+
+#----------------------------------------------------------------------
+# jvm_db & dtrace
+include $(MAKEFILES_DIR)/dtrace.make
+
+#----------------------------------------------------------------------
+# JVM
+
+JVM    = jvm
+ifeq ($(OS_VENDOR), Darwin)
+  LIBJVM   = lib$(JVM).dylib
+  LIBJVM_G = lib$(JVM)$(G_SUFFIX).dylib
+  CFLAGS  += -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
+else
+  LIBJVM   = lib$(JVM).so
+  LIBJVM_G = lib$(JVM)$(G_SUFFIX).so
+endif
+
+SPECIAL_PATHS:=adlc c1 gc_implementation opto shark libadt
+
+SOURCE_PATHS=\
+  $(shell find $(HS_COMMON_SRC)/share/vm/* -type d \! \
+      \( -name DUMMY $(foreach dir,$(SPECIAL_PATHS),-o -name $(dir)) \))
+SOURCE_PATHS+=$(HS_COMMON_SRC)/os/$(Platform_os_family)/vm
+SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm
+SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm
+SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm
+
+CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path))
+CORE_PATHS+=$(GENERATED)/jvmtifiles
+
+COMPILER1_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/c1)
+COMPILER1_PATHS += $(HS_COMMON_SRC)/share/vm/c1
+
+COMPILER2_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/opto)
+COMPILER2_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/libadt)
+COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/opto
+COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/libadt
+COMPILER2_PATHS += $(GENERATED)/adfiles
+
+SHARK_PATHS := $(GAMMADIR)/src/share/vm/shark
+
+# Include dirs per type.
+Src_Dirs/CORE      := $(CORE_PATHS)
+Src_Dirs/COMPILER1 := $(CORE_PATHS) $(COMPILER1_PATHS)
+Src_Dirs/COMPILER2 := $(CORE_PATHS) $(COMPILER2_PATHS)
+Src_Dirs/TIERED    := $(CORE_PATHS) $(COMPILER1_PATHS) $(COMPILER2_PATHS)
+Src_Dirs/ZERO      := $(CORE_PATHS)
+Src_Dirs/SHARK     := $(CORE_PATHS) $(SHARK_PATHS)
+Src_Dirs := $(Src_Dirs/$(TYPE))
+
+COMPILER2_SPECIFIC_FILES := opto libadt bcEscapeAnalyzer.cpp chaitin\* c2_\* runtime_\*
+COMPILER1_SPECIFIC_FILES := c1_\*
+SHARK_SPECIFIC_FILES     := shark
+ZERO_SPECIFIC_FILES      := zero
+
+# Always exclude these.
+Src_Files_EXCLUDE := jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp
+
+# Exclude per type.
+Src_Files_EXCLUDE/CORE      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
+Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
+Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
+Src_Files_EXCLUDE/TIERED    := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
+Src_Files_EXCLUDE/ZERO      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
+Src_Files_EXCLUDE/SHARK     := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES)
+
+Src_Files_EXCLUDE +=  $(Src_Files_EXCLUDE/$(TYPE))
+
+# Special handling of arch model.
+ifeq ($(Platform_arch_model), x86_32)
+Src_Files_EXCLUDE += \*x86_64\*
+endif
+ifeq ($(Platform_arch_model), x86_64)
+Src_Files_EXCLUDE += \*x86_32\*
+endif
+
+# Locate all source files in the given directory, excluding files in Src_Files_EXCLUDE.
+define findsrc
+	$(notdir $(shell find $(1)/. ! -name . -prune \
+		-a \( -name \*.c -o -name \*.cpp -o -name \*.s \) \
+		-a ! \( -name DUMMY $(addprefix -o -name ,$(Src_Files_EXCLUDE)) \)))
+endef
+
+Src_Files := $(foreach e,$(Src_Dirs),$(call findsrc,$(e)))
+
+Obj_Files = $(sort $(addsuffix .o,$(basename $(Src_Files))))
+
+JVM_OBJ_FILES = $(Obj_Files)
+
+vm_version.o: $(filter-out vm_version.o,$(JVM_OBJ_FILES))
+
+mapfile : $(MAPFILE) vm.def
+	rm -f $@
+	awk '{ if ($$0 ~ "INSERT VTABLE SYMBOLS HERE")	\
+                 { system ("cat vm.def"); }		\
+               else					\
+                 { print $$0 }				\
+             }' > $@ < $(MAPFILE)
+
+mapfile_reorder : mapfile $(REORDERFILE)
+	rm -f $@
+	cat $^ > $@
+
+vm.def: $(Res_Files) $(Obj_Files)
+	sh $(GAMMADIR)/make/bsd/makefiles/build_vm_def.sh *.o > $@
+
+STATIC_CXX = false
+
+ifeq ($(LINK_INTO),AOUT)
+  LIBJVM.o                 =
+  LIBJVM_MAPFILE           =
+  LIBS_VM                  = $(LIBS)
+else
+  LIBJVM.o                 = $(JVM_OBJ_FILES)
+  LIBJVM_MAPFILE$(LDNOMAP) = mapfile_reorder
+  LFLAGS_VM$(LDNOMAP)      += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
+  LFLAGS_VM                += $(SONAMEFLAG:SONAME=$(LIBJVM))
+
+  ifeq ($(OS_VENDOR), Darwin)
+    LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/.
+    LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/..
+    LFLAGS_VM += -Xlinker -install_name -Xlinker @rpath/$(@F)
+  endif
+
+  # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
+  # get around library dependency and compatibility issues. Must use gcc not
+  # g++ to link.
+  ifeq ($(STATIC_CXX), true)
+    LFLAGS_VM              += $(STATIC_LIBGCC)
+    LIBS_VM                += $(STATIC_STDCXX)
+    LINK_VM                = $(LINK_LIB.c)
+  else
+    LINK_VM                = $(LINK_LIB.CC)
+  endif
+
+  LIBS_VM                  += $(LIBS)
+endif
+ifeq ($(ZERO_BUILD), true)
+  LIBS_VM += $(LIBFFI_LIBS)
+endif
+ifeq ($(SHARK_BUILD), true)
+  LFLAGS_VM += $(LLVM_LDFLAGS)
+  LIBS_VM   += $(LLVM_LIBS)
+endif
+
+
+# rule for building precompiled header
+$(PRECOMPILED_HEADER):
+	$(QUIETLY) echo Generating precompiled header $@
+	$(QUIETLY) mkdir -p $(PRECOMPILED_HEADER_DIR)
+	$(QUIETLY) $(COMPILE.CC) $(DEPFLAGS) -x c++-header $(PRECOMPILED_HEADER_SRC) -o $@ $(COMPILE_DONE)
+
+# making the library:
+
+ifneq ($(JVM_BASE_ADDR),)
+# By default shared library is linked at base address == 0. Modify the
+# linker script if JVM prefers a different base location. It can also be
+# implemented with 'prelink -r'. But 'prelink' is not (yet) available on
+# our build platform (AS-2.1).
+LD_SCRIPT = libjvm.so.lds
+$(LD_SCRIPT): $(LIBJVM_MAPFILE)
+	$(QUIETLY) {                                                \
+	  rm -rf $@;                                                \
+	  $(LINK_VM) -Wl,--verbose $(LFLAGS_VM) 2>&1             |  \
+	    sed -e '/^======/,/^======/!d'                          \
+		-e '/^======/d'                                     \
+		-e 's/0\( + SIZEOF_HEADERS\)/$(JVM_BASE_ADDR)\1/'   \
+		> $@;                                               \
+	}
+LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
+endif
+
+$(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
+	$(QUIETLY) {                                                    \
+	    echo Linking vm...;                                         \
+	    $(LINK_LIB.CC/PRE_HOOK)                                     \
+	    $(LINK_VM) $(LD_SCRIPT_FLAG)                                \
+		       $(LFLAGS_VM) -o $@ $(LIBJVM.o) $(LIBS_VM);       \
+	    $(LINK_LIB.CC/POST_HOOK)                                    \
+	    rm -f $@.1; ln -s $@ $@.1;                                  \
+	    [ -f $(LIBJVM_G) ] || { ln -s $@ $(LIBJVM_G); ln -s $@.1 $(LIBJVM_G).1; }; \
+	}
+
+DEST_JVM = $(JDK_LIBDIR)/$(VM_SUBDIR)/$(LIBJVM)
+
+install_jvm: $(LIBJVM)
+	@echo "Copying $(LIBJVM) to $(DEST_JVM)"
+	$(QUIETLY) cp -f $(LIBJVM) $(DEST_JVM) && echo "Done"
+
+#----------------------------------------------------------------------
+# Other files
+
+# Gamma launcher
+include $(MAKEFILES_DIR)/launcher.make
+
+# Signal interposition library
+include $(MAKEFILES_DIR)/jsig.make
+
+# Serviceability agent
+include $(MAKEFILES_DIR)/saproc.make
+
+#----------------------------------------------------------------------
+
+ifeq ($(OS_VENDOR), Darwin)
+$(LIBJVM).dSYM: $(LIBJVM)
+	dsymutil $(LIBJVM)
+
+# no launcher or libjvm_db for macosx
+build: $(LIBJVM) $(LIBJSIG) $(BUILDLIBSAPROC) dtraceCheck $(LIBJVM).dSYM
+	echo "Doing vm.make build:"
+else
+build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) $(BUILDLIBSAPROC)
+endif
+
+install: install_jvm install_jsig install_saproc
+
+.PHONY: default build install install_jvm
diff --git a/hotspot/make/bsd/makefiles/zero.make b/hotspot/make/bsd/makefiles/zero.make
new file mode 100644
index 0000000..0270711
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/zero.make
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2009 Red Hat, Inc.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
+#
+
+# Setup for Zero (non-Shark) version of VM
+
+# Select which files to use (in top.make)
+TYPE = ZERO
+
+# Install libjvm.so, etc in in server directory.
+VM_SUBDIR = server
diff --git a/hotspot/make/bsd/makefiles/zeroshark.make b/hotspot/make/bsd/makefiles/zeroshark.make
new file mode 100644
index 0000000..12c4198
--- /dev/null
+++ b/hotspot/make/bsd/makefiles/zeroshark.make
@@ -0,0 +1,62 @@
+#
+# Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2007, 2008 Red Hat, Inc.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+#
+
+# Setup common to Zero (non-Shark) and Shark versions of VM
+
+# The copied fdlibm routines in sharedRuntimeTrig.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrig.o = $(OPT_CFLAGS/NOOPT)
+# The copied fdlibm routines in sharedRuntimeTrans.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrans.o = $(OPT_CFLAGS/NOOPT)
+
+# Specify that the CPU is little endian, if necessary
+ifeq ($(ZERO_ENDIANNESS), little)
+  CFLAGS += -DVM_LITTLE_ENDIAN
+endif
+
+# Specify that the CPU is 64 bit, if necessary
+ifeq ($(ARCH_DATA_MODEL), 64)
+  CFLAGS += -D_LP64=1
+endif
+
+# Specify the path to the FFI headers
+ifdef ALT_PACKAGE_PATH
+  PACKAGE_PATH = $(ALT_PACKAGE_PATH)
+else
+  ifeq ($(OS_VENDOR),Apple)
+    PACKAGE_PATH = /opt/local
+  else
+    ifeq ($(OS_VENDOR),NetBSD)
+      PACKAGE_PATH = /usr/pkg
+      LIBS += -Wl,-R${PACKAGE_PATH}/lib
+    else
+      PACKAGE_PATH = /usr/local
+    endif
+  endif
+endif
+
+CFLAGS += -I$(PACKAGE_PATH)/include
+LIBS += -L$(PACKAGE_PATH)/lib -lffi
+
+OPT_CFLAGS/compactingPermGenGen.o = -O1
diff --git a/hotspot/make/bsd/platform_amd64 b/hotspot/make/bsd/platform_amd64
new file mode 100644
index 0000000..51b2b1c
--- /dev/null
+++ b/hotspot/make/bsd/platform_amd64
@@ -0,0 +1,15 @@
+os_family = bsd
+
+arch = x86
+
+arch_model = x86_64
+
+os_arch = bsd_x86
+
+os_arch_model = bsd_x86_64
+
+lib_arch = amd64
+
+compiler = gcc
+
+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DAMD64
diff --git a/hotspot/make/bsd/platform_amd64.suncc b/hotspot/make/bsd/platform_amd64.suncc
new file mode 100644
index 0000000..68e0cc3
--- /dev/null
+++ b/hotspot/make/bsd/platform_amd64.suncc
@@ -0,0 +1,17 @@
+os_family = bsd
+
+arch = x86
+
+arch_model = x86_64
+
+os_arch = bsd_x86
+
+os_arch_model = bsd_x86_64
+
+lib_arch = amd64
+
+compiler = sparcWorks
+
+gnu_dis_arch = amd64
+
+sysdefs = -D_ALLBSD_SOURCE -DSPARC_WORKS -D_GNU_SOURCE -DAMD64
diff --git a/hotspot/make/bsd/platform_i486 b/hotspot/make/bsd/platform_i486
new file mode 100644
index 0000000..2f77e79
--- /dev/null
+++ b/hotspot/make/bsd/platform_i486
@@ -0,0 +1,15 @@
+os_family = bsd
+
+arch = x86
+
+arch_model = x86_32
+
+os_arch = bsd_x86
+
+os_arch_model = bsd_x86_32
+
+lib_arch = i386
+
+compiler = gcc
+
+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DIA32
diff --git a/hotspot/make/bsd/platform_i486.suncc b/hotspot/make/bsd/platform_i486.suncc
new file mode 100644
index 0000000..5b203cd
--- /dev/null
+++ b/hotspot/make/bsd/platform_i486.suncc
@@ -0,0 +1,17 @@
+os_family = bsd
+
+arch = x86
+
+arch_model = x86_32
+
+os_arch = bsd_x86
+
+os_arch_model = bsd_x86_32
+
+lib_arch = i386
+
+compiler = sparcWorks
+
+gnu_dis_arch = i386
+
+sysdefs = -D_ALLBSD_SOURCE -DSPARC_WORKS -D_GNU_SOURCE -DIA32
diff --git a/hotspot/make/bsd/platform_ia64 b/hotspot/make/bsd/platform_ia64
new file mode 100644
index 0000000..00b9f33
--- /dev/null
+++ b/hotspot/make/bsd/platform_ia64
@@ -0,0 +1,15 @@
+os_family = bsd
+
+arch = ia64
+
+os_arch = bsd_ia64
+
+lib_arch = ia64
+
+compiler = gcc
+
+gnu_dis_arch = ia64
+
+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DIA64 -DCC_INTERP
+
+mark_style = alignment
diff --git a/hotspot/make/bsd/platform_sparc b/hotspot/make/bsd/platform_sparc
new file mode 100644
index 0000000..04772ad
--- /dev/null
+++ b/hotspot/make/bsd/platform_sparc
@@ -0,0 +1,15 @@
+os_family = bsd
+
+arch = sparc
+
+arch_model = sparc
+
+os_arch = bsd_sparc
+
+os_arch_model = bsd_sparc
+
+lib_arch = sparc
+
+compiler = gcc
+
+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DSPARC
diff --git a/hotspot/make/bsd/platform_sparcv9 b/hotspot/make/bsd/platform_sparcv9
new file mode 100644
index 0000000..89e51c5
--- /dev/null
+++ b/hotspot/make/bsd/platform_sparcv9
@@ -0,0 +1,15 @@
+os_family = bsd
+
+arch = sparc
+
+arch_model = sparc
+
+os_arch = bsd_sparc
+
+os_arch_model = bsd_sparc
+
+lib_arch = sparcv9
+
+compiler = gcc
+
+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DSPARC
diff --git a/hotspot/make/bsd/platform_zero.in b/hotspot/make/bsd/platform_zero.in
new file mode 100644
index 0000000..f6729c2
--- /dev/null
+++ b/hotspot/make/bsd/platform_zero.in
@@ -0,0 +1,17 @@
+os_family = bsd
+
+arch = zero
+
+arch_model = zero
+
+os_arch = bsd_zero
+
+os_arch_model = bsd_zero
+
+lib_arch = zero
+
+compiler = gcc
+
+gnu_dis_arch = zero
+
+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DCC_INTERP -DZERO -D@ZERO_ARCHDEF@ -DZERO_LIBARCH=\"@ZERO_LIBARCH@\"
diff --git a/hotspot/make/cscope.make b/hotspot/make/cscope.make
index 17c3aa3..c38b7a5 100644
--- a/hotspot/make/cscope.make
+++ b/hotspot/make/cscope.make
@@ -63,7 +63,7 @@
 # space-separated list of identifiers to include only those systems.
 ifdef	CS_OS
 CS_PRUNE_OS	= $(patsubst %,-o -name '*%*',\
-		    $(filter-out ${CS_OS},linux macos solaris windows))
+		    $(filter-out ${CS_OS},bsd linux macos solaris windows))
 endif
 
 # CPU-specific files for all processors are included by default.  Set CS_CPU 
diff --git a/hotspot/make/defs.make b/hotspot/make/defs.make
index fe6c4a2..7434dae 100644
--- a/hotspot/make/defs.make
+++ b/hotspot/make/defs.make
@@ -118,13 +118,23 @@
 # Windows should have OS predefined
 ifeq ($(OS),)
   OS   := $(shell uname -s)
+  ifneq ($(findstring BSD,$(OS)),)
+    OS=bsd
+  endif
+  ifeq ($(OS), Darwin)
+    OS=bsd
+  endif
   HOST := $(shell uname -n)
 endif
 
-# If not SunOS and not Linux, assume Windows
+# If not SunOS, not Linux and not BSD, assume Windows
 ifneq ($(OS), Linux)
   ifneq ($(OS), SunOS)
-    OSNAME=windows
+    ifneq ($(OS), bsd)
+      OSNAME=windows
+    else
+      OSNAME=bsd
+    endif
   else
     OSNAME=solaris
   endif
@@ -271,6 +281,13 @@
 EXPORT_JRE_LIB_DIR = $(EXPORT_JRE_DIR)/lib
 EXPORT_JRE_LIB_ARCH_DIR = $(EXPORT_JRE_LIB_DIR)/$(LIBARCH)
 
+# non-universal macosx builds need to appear universal
+ifeq ($(OS_VENDOR), Darwin)
+  ifneq ($(MACOSX_UNIVERSAL), true)
+    EXPORT_JRE_LIB_ARCH_DIR = $(EXPORT_JRE_LIB_DIR)
+  endif
+endif
+
 # Common export list of files
 EXPORT_LIST += $(EXPORT_INCLUDE_DIR)/jvmti.h
 EXPORT_LIST += $(EXPORT_INCLUDE_DIR)/jvmticmlr.h
diff --git a/hotspot/make/hotspot_version b/hotspot/make/hotspot_version
index 27ad10e..9a906cc 100644
--- a/hotspot/make/hotspot_version
+++ b/hotspot/make/hotspot_version
@@ -33,9 +33,9 @@
 # Don't put quotes (fail windows build).
 HOTSPOT_VM_COPYRIGHT=Copyright 2011
 
-HS_MAJOR_VER=22
+HS_MAJOR_VER=23
 HS_MINOR_VER=0
-HS_BUILD_NUMBER=10
+HS_BUILD_NUMBER=06
 
 JDK_MAJOR_VER=1
 JDK_MINOR_VER=8
diff --git a/hotspot/make/jprt.properties b/hotspot/make/jprt.properties
index 4c88ed0..76944a0 100644
--- a/hotspot/make/jprt.properties
+++ b/hotspot/make/jprt.properties
@@ -541,9 +541,20 @@
   ${jprt.my.windows.i586}-*-c2-servertest, \
   ${jprt.my.windows.x64}-*-c2-servertest
 
+jprt.make.rule.test.targets.standard.internalvmtests = \
+  ${jprt.my.solaris.sparc}-fastdebug-c2-internalvmtests, \
+  ${jprt.my.solaris.sparcv9}-fastdebug-c2-internalvmtests, \
+  ${jprt.my.solaris.i586}-fastdebug-c2-internalvmtests, \
+  ${jprt.my.solaris.x64}-fastdebug-c2-internalvmtests, \
+  ${jprt.my.linux.i586}-fastdebug-c2-internalvmtests, \
+  ${jprt.my.linux.x64}-fastdebug-c2-internalvmtests, \
+  ${jprt.my.windows.i586}-fastdebug-c2-internalvmtests, \
+  ${jprt.my.windows.x64}-fastdebug-c2-internalvmtests
+  
 jprt.make.rule.test.targets.standard = \
   ${jprt.make.rule.test.targets.standard.client}, \
-  ${jprt.make.rule.test.targets.standard.server}
+  ${jprt.make.rule.test.targets.standard.server}, \
+  ${jprt.make.rule.test.targets.standard.internalvmtests}
 
 jprt.make.rule.test.targets.embedded = \
   ${jprt.make.rule.test.targets.standard.client}
diff --git a/hotspot/make/linux/build.sh b/hotspot/make/linux/build.sh
index f46b8df..79844c5 100644
--- a/hotspot/make/linux/build.sh
+++ b/hotspot/make/linux/build.sh
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -45,6 +45,9 @@
   i386|i486|i586|i686)
     mach=i386
     ;;
+  x86_64)
+    mach=amd64
+    ;;
   *)
     echo "Unsupported machine: " `uname -m`
     exit 1
diff --git a/hotspot/make/linux/makefiles/arm.make b/hotspot/make/linux/makefiles/arm.make
index e210303..6d7079e 100644
--- a/hotspot/make/linux/makefiles/arm.make
+++ b/hotspot/make/linux/makefiles/arm.make
@@ -1,6 +1,25 @@
 #
 # Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
-# ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
 #
 
 Obj_Files += linux_arm.o
diff --git a/hotspot/make/linux/makefiles/buildtree.make b/hotspot/make/linux/makefiles/buildtree.make
index f8a1e88..b1eb00b 100644
--- a/hotspot/make/linux/makefiles/buildtree.make
+++ b/hotspot/make/linux/makefiles/buildtree.make
@@ -223,6 +223,8 @@
 	echo "$(call gamma-path,commonsrc,share/vm/prims) \\"; \
 	echo "$(call gamma-path,altsrc,share/vm) \\"; \
 	echo "$(call gamma-path,commonsrc,share/vm) \\"; \
+	echo "$(call gamma-path,altsrc,share/vm/precompiled) \\"; \
+	echo "$(call gamma-path,commonsrc,share/vm/precompiled) \\"; \
 	echo "$(call gamma-path,altsrc,cpu/$(SRCARCH)/vm) \\"; \
 	echo "$(call gamma-path,commonsrc,cpu/$(SRCARCH)/vm) \\"; \
 	echo "$(call gamma-path,altsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
diff --git a/hotspot/make/linux/makefiles/defs.make b/hotspot/make/linux/makefiles/defs.make
index c327974..df5b8e4 100644
--- a/hotspot/make/linux/makefiles/defs.make
+++ b/hotspot/make/linux/makefiles/defs.make
@@ -177,23 +177,25 @@
 
 JDK_INCLUDE_SUBDIR=linux
 
+# Library suffix
+LIBRARY_SUFFIX=so
+
 # FIXUP: The subdirectory for a debug build is NOT the same on all platforms
 VM_DEBUG=jvmg
 
 EXPORT_LIST += $(EXPORT_DOCS_DIR)/platform/jvmti/jvmti.html
 
 # client and server subdirectories have symbolic links to ../libjsig.so
-EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.so
+EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.$(LIBRARY_SUFFIX)
 ifneq ($(OBJCOPY),)
   EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.debuginfo
 endif
-
 EXPORT_SERVER_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/server
 EXPORT_CLIENT_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/client
 
 ifndef BUILD_CLIENT_ONLY
 EXPORT_LIST += $(EXPORT_SERVER_DIR)/Xusage.txt
-EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.so
+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.$(LIBRARY_SUFFIX)
   ifneq ($(OBJCOPY),)
     EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.debuginfo
   endif
@@ -202,7 +204,7 @@
 ifneq ($(ZERO_BUILD), true)
   ifeq ($(ARCH_DATA_MODEL), 32)
     EXPORT_LIST += $(EXPORT_CLIENT_DIR)/Xusage.txt
-    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.so 
+    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.$(LIBRARY_SUFFIX)
     ifneq ($(OBJCOPY),)
       EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.debuginfo
     endif
@@ -211,9 +213,9 @@
 
 # Serviceability Binaries
 # No SA Support for PPC, IA64, ARM or zero
-ADD_SA_BINARIES/x86   = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.so \
+ADD_SA_BINARIES/x86   = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
                         $(EXPORT_LIB_DIR)/sa-jdi.jar 
-ADD_SA_BINARIES/sparc = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.so \
+ADD_SA_BINARIES/sparc = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
                         $(EXPORT_LIB_DIR)/sa-jdi.jar 
 ifneq ($(OBJCOPY),)
   ADD_SA_BINARIES/x86   += $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.debuginfo
diff --git a/hotspot/make/linux/makefiles/gcc.make b/hotspot/make/linux/makefiles/gcc.make
index e36cec6..2da52739 100644
--- a/hotspot/make/linux/makefiles/gcc.make
+++ b/hotspot/make/linux/makefiles/gcc.make
@@ -52,7 +52,7 @@
 ifneq ($(USE_PRECOMPILED_HEADER),0)
 USE_PRECOMPILED_HEADER=1
 PRECOMPILED_HEADER_DIR=.
-PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled.hpp
+PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp
 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch
 endif
 endif
diff --git a/hotspot/make/linux/makefiles/ppc.make b/hotspot/make/linux/makefiles/ppc.make
index a3a19bc..92957f9 100644
--- a/hotspot/make/linux/makefiles/ppc.make
+++ b/hotspot/make/linux/makefiles/ppc.make
@@ -1,6 +1,25 @@
 #
 # Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
-# ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#  
 #
 
 # The copied fdlibm routines in sharedRuntimeTrig.o must not be optimized
diff --git a/hotspot/make/linux/makefiles/sa.make b/hotspot/make/linux/makefiles/sa.make
index 37a53b8..ede5761 100644
--- a/hotspot/make/linux/makefiles/sa.make
+++ b/hotspot/make/linux/makefiles/sa.make
@@ -43,13 +43,7 @@
 # TODO: if it's a modules image, check if SA module is installed.
 MODULELIB_PATH= $(BOOT_JAVA_HOME)/lib/modules
 
-# gnumake 3.78.1 does not accept the *s that
-# are in AGENT_FILES1 and AGENT_FILES2, so use the shell to expand them
-AGENT_FILES1 := $(shell /usr/bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES1))
-AGENT_FILES2 := $(shell /usr/bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES2))
-
-AGENT_FILES1_LIST := $(GENERATED)/agent1.classes.list
-AGENT_FILES2_LIST := $(GENERATED)/agent2.classes.list
+AGENT_FILES_LIST := $(GENERATED)/agent.classes.list
 
 SA_CLASSDIR = $(GENERATED)/saclasses
 
@@ -68,7 +62,7 @@
 	   $(MAKE) -f sa.make $(GENERATED)/sa-jdi.jar; \
 	fi
 
-$(GENERATED)/sa-jdi.jar: $(AGENT_FILES1) $(AGENT_FILES2)
+$(GENERATED)/sa-jdi.jar: $(AGENT_FILES)
 	$(QUIETLY) echo "Making $@"
 	$(QUIETLY) if [ "$(BOOT_JAVA_HOME)" = "" ]; then \
 	  echo "ALT_BOOTDIR, BOOTDIR or JAVA_HOME needs to be defined to build SA"; \
@@ -82,7 +76,6 @@
 	$(QUIETLY) if [ ! -d $(SA_CLASSDIR) ] ; then \
 	  mkdir -p $(SA_CLASSDIR);        \
 	fi
-	
 # Note: When indented, make tries to execute the '$(shell' comment.
 # In some environments, cmd processors have limited line length.
 # To prevent the javac invocation in the next block from using
@@ -93,13 +86,12 @@
 # the initialization of the lists is also done in the same phase
 # using '$(shell rm ...' instead of using the more traditional
 # 'rm ...' rule.
-	$(shell rm -rf $(AGENT_FILES1_LIST) $(AGENT_FILES2_LIST))
-	$(foreach file,$(AGENT_FILES1),$(shell echo $(file) >> $(AGENT_FILES1_LIST)))
-	$(foreach file,$(AGENT_FILES2),$(shell echo $(file) >> $(AGENT_FILES2_LIST)))
-	
-	$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES1_LIST)
-	$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES2_LIST)
-	
+	$(shell rm -rf $(AGENT_FILES_LIST))
+# gnumake 3.78.1 does not accept the *'s that
+# are in AGENT_FILES, so use the shell to expand them.
+# Be extra carefull to not produce too long command lines in the shell!
+	$(foreach file,$(AGENT_FILES),$(shell ls -1 $(file) >> $(AGENT_FILES_LIST)))
+	$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES_LIST)
 	$(QUIETLY) $(REMOTE) $(COMPILE.RMIC)  -classpath $(SA_CLASSDIR) -d $(SA_CLASSDIR) sun.jvm.hotspot.debugger.remote.RemoteDebuggerServer
 	$(QUIETLY) echo "$(SA_BUILD_VERSION_PROP)" > $(SA_PROPERTIES)
 	$(QUIETLY) rm -f $(SA_CLASSDIR)/sun/jvm/hotspot/utilities/soql/sa.js
@@ -118,4 +110,4 @@
 clean:
 	rm -rf $(SA_CLASSDIR)
 	rm -rf $(GENERATED)/sa-jdi.jar
-	rm -rf $(AGENT_FILES1_LIST) $(AGENT_FILES2_LIST)
+	rm -rf $(AGENT_FILES_LIST)
diff --git a/hotspot/make/sa.files b/hotspot/make/sa.files
index da4c669..c634590 100644
--- a/hotspot/make/sa.files
+++ b/hotspot/make/sa.files
@@ -36,7 +36,7 @@
 # Splitted the set of files into two sets because on linux plaform
 # listing or compiling all the files results in 'Argument list too long' error.
 
-AGENT_FILES1 = \
+AGENT_FILES = \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/asm/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/asm/amd64/*.java \
@@ -51,6 +51,9 @@
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/compiler/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/amd64/*.java \
+$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/*.java \
+$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/amd64/*.java \
+$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/x86/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/x86/*.java \
@@ -89,12 +92,12 @@
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/memory/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/oops/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/opto/*.java \
-$(AGENT_SRC_DIR)/sun/jvm/hotspot/prims/*.java 
-
-
-AGENT_FILES2 = \
+$(AGENT_SRC_DIR)/sun/jvm/hotspot/prims/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/amd64/*.java \
+$(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/bsd/*.java \
+$(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/bsd_amd64/*.java \
+$(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/bsd_x86/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/ia64/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/linux/*.java \
 $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/linux_amd64/*.java \
diff --git a/hotspot/make/solaris/makefiles/buildtree.make b/hotspot/make/solaris/makefiles/buildtree.make
index 30e03be..a46d6b3 100644
--- a/hotspot/make/solaris/makefiles/buildtree.make
+++ b/hotspot/make/solaris/makefiles/buildtree.make
@@ -216,6 +216,8 @@
 	echo "$(call gamma-path,commonsrc,share/vm/prims) \\"; \
 	echo "$(call gamma-path,altsrc,share/vm) \\"; \
 	echo "$(call gamma-path,commonsrc,share/vm) \\"; \
+	echo "$(call gamma-path,altsrc,share/vm/precompiled) \\"; \
+	echo "$(call gamma-path,commonsrc,share/vm/precompiled) \\"; \
 	echo "$(call gamma-path,altsrc,cpu/$(ARCH)/vm) \\"; \
 	echo "$(call gamma-path,commonsrc,cpu/$(ARCH)/vm) \\"; \
 	echo "$(call gamma-path,altsrc,os_cpu/$(OS_FAMILY)_$(ARCH)/vm) \\"; \
diff --git a/hotspot/make/solaris/makefiles/defs.make b/hotspot/make/solaris/makefiles/defs.make
index 64e96be..f4b6ea3 100644
--- a/hotspot/make/solaris/makefiles/defs.make
+++ b/hotspot/make/solaris/makefiles/defs.make
@@ -134,13 +134,16 @@
 
 JDK_INCLUDE_SUBDIR=solaris
 
+# Library suffix
+LIBRARY_SUFFIX=so
+
 # FIXUP: The subdirectory for a debug build is NOT the same on all platforms
 VM_DEBUG=jvmg
 
 EXPORT_LIST += $(EXPORT_DOCS_DIR)/platform/jvmti/jvmti.html
 
-# client and server subdirectories have symbolic links to ../libjsig.so
-EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.so
+# client and server subdirectories have symbolic links to ../libjsig.$(LIBRARY_SUFFIX)
+EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.$(LIBRARY_SUFFIX)
 ifneq ($(OBJCOPY),)
   EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.debuginfo
 endif
@@ -150,9 +153,9 @@
 
 ifneq ($(BUILD_CLIENT_ONLY),true)
 EXPORT_LIST += $(EXPORT_SERVER_DIR)/Xusage.txt
-EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.so
-EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm_db.so
-EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm_dtrace.so
+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.$(LIBRARY_SUFFIX)
+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm_db.$(LIBRARY_SUFFIX)
+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm_dtrace.$(LIBRARY_SUFFIX)
   ifneq ($(OBJCOPY),)
     EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.debuginfo
     EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm_db.debuginfo
@@ -161,21 +164,21 @@
 endif
 ifeq ($(ARCH_DATA_MODEL), 32)
   EXPORT_LIST += $(EXPORT_CLIENT_DIR)/Xusage.txt
-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.so 
-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm_db.so 
-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm_dtrace.so
-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/64/libjvm_db.so
-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/64/libjvm_dtrace.so
+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.$(LIBRARY_SUFFIX) 
+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm_db.$(LIBRARY_SUFFIX) 
+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm_dtrace.$(LIBRARY_SUFFIX)
+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/64/libjvm_db.$(LIBRARY_SUFFIX)
+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/64/libjvm_dtrace.$(LIBRARY_SUFFIX)
   ifneq ($(OBJCOPY),)
-    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.debuginfo 
-    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm_db.debuginfo 
+    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.debuginfo
+    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm_db.debuginfo
     EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm_dtrace.debuginfo
     EXPORT_LIST += $(EXPORT_CLIENT_DIR)/64/libjvm_db.debuginfo
     EXPORT_LIST += $(EXPORT_CLIENT_DIR)/64/libjvm_dtrace.debuginfo
   endif
   ifneq ($(BUILD_CLIENT_ONLY), true)
-    EXPORT_LIST += $(EXPORT_SERVER_DIR)/64/libjvm_db.so
-    EXPORT_LIST += $(EXPORT_SERVER_DIR)/64/libjvm_dtrace.so
+    EXPORT_LIST += $(EXPORT_SERVER_DIR)/64/libjvm_db.$(LIBRARY_SUFFIX)
+    EXPORT_LIST += $(EXPORT_SERVER_DIR)/64/libjvm_dtrace.$(LIBRARY_SUFFIX)
     ifneq ($(OBJCOPY),)
       EXPORT_LIST += $(EXPORT_SERVER_DIR)/64/libjvm_db.debuginfo
       EXPORT_LIST += $(EXPORT_SERVER_DIR)/64/libjvm_dtrace.debuginfo
@@ -183,7 +186,7 @@
   endif
 endif
 
-EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.so
+EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX)
 ifneq ($(OBJCOPY),)
   EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.debuginfo
 endif
diff --git a/hotspot/make/solaris/makefiles/gcc.make b/hotspot/make/solaris/makefiles/gcc.make
index b0cdfc9..15e43ea 100644
--- a/hotspot/make/solaris/makefiles/gcc.make
+++ b/hotspot/make/solaris/makefiles/gcc.make
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -51,7 +51,7 @@
 ifneq ($(USE_PRECOMPILED_HEADER),0)
 USE_PRECOMPILED_HEADER=1
 PRECOMPILED_HEADER_DIR=.
-PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled.hpp
+PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp
 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch
 endif
 endif
diff --git a/hotspot/make/solaris/makefiles/sa.make b/hotspot/make/solaris/makefiles/sa.make
index d510443..ec27f56 100644
--- a/hotspot/make/solaris/makefiles/sa.make
+++ b/hotspot/make/solaris/makefiles/sa.make
@@ -39,13 +39,7 @@
 # TODO: if it's a modules image, check if SA module is installed.
 MODULELIB_PATH= $(BOOT_JAVA_HOME)/lib/modules
 
-# gnumake 3.78.1 does not accept the *s that
-# are in AGENT_FILES1 and AGENT_FILES2, so use the shell to expand them
-AGENT_FILES1 := $(shell /usr/bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES1))
-AGENT_FILES2 := $(shell /usr/bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES2))
-
-AGENT_FILES1_LIST := $(GENERATED)/agent1.classes.list
-AGENT_FILES2_LIST := $(GENERATED)/agent2.classes.list
+AGENT_FILES_LIST := $(GENERATED)/agent.classes.list
 
 SA_CLASSDIR = $(GENERATED)/saclasses
 
@@ -59,7 +53,7 @@
 	   $(MAKE) -f sa.make $(GENERATED)/sa-jdi.jar; \
 	fi
 
-$(GENERATED)/sa-jdi.jar: $(AGENT_FILES1) $(AGENT_FILES2)
+$(GENERATED)/sa-jdi.jar: $(AGENT_FILES)
 	$(QUIETLY) echo "Making $@";
 	$(QUIETLY) if [ "$(BOOT_JAVA_HOME)" = "" ]; then \
 	   echo "ALT_BOOTDIR, BOOTDIR or JAVA_HOME needs to be defined to build SA"; \
@@ -73,7 +67,6 @@
 	$(QUIETLY) if [ ! -d $(SA_CLASSDIR) ] ; then \
 	  mkdir -p $(SA_CLASSDIR);        \
 	fi
-	
 # Note: When indented, make tries to execute the '$(shell' comment.
 # In some environments, cmd processors have limited line length.
 # To prevent the javac invocation in the next block from using
@@ -84,13 +77,12 @@
 # the initialization of the lists is also done in the same phase
 # using '$(shell rm ...' instead of using the more traditional
 # 'rm ...' rule.
-	$(shell rm -rf $(AGENT_FILES1_LIST) $(AGENT_FILES2_LIST))
-	$(foreach file,$(AGENT_FILES1),$(shell echo $(file) >> $(AGENT_FILES1_LIST)))
-	$(foreach file,$(AGENT_FILES2),$(shell echo $(file) >> $(AGENT_FILES2_LIST)))
-	
-	$(QUIETLY) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES1_LIST)
-	$(QUIETLY) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES2_LIST)
-	
+	$(shell rm -rf $(AGENT_FILES_LIST))
+# gnumake 3.78.1 does not accept the *'s that
+# are in AGENT_FILES, so use the shell to expand them.
+# Be extra carefull to not produce too long command lines in the shell!
+	$(foreach file,$(AGENT_FILES),$(shell ls -1 $(file) >> $(AGENT_FILES_LIST)))
+	$(QUIETLY) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES_LIST)
 	$(QUIETLY) $(COMPILE.RMIC)  -classpath $(SA_CLASSDIR) -d $(SA_CLASSDIR) sun.jvm.hotspot.debugger.remote.RemoteDebuggerServer
 	$(QUIETLY) echo "$(SA_BUILD_VERSION_PROP)" > $(SA_PROPERTIES)
 	$(QUIETLY) rm -f $(SA_CLASSDIR)/sun/jvm/hotspot/utilities/soql/sa.js
@@ -106,4 +98,4 @@
 clean:
 	rm -rf $(SA_CLASSDIR)
 	rm -rf $(GENERATED)/sa-jdi.jar
-	rm -rf $(AGENT_FILES1_LIST) $(AGENT_FILES2_LIST)
+	rm -rf $(AGENT_FILES_LIST)
diff --git a/hotspot/make/templates/bsd-header b/hotspot/make/templates/bsd-header
deleted file mode 100644
index 95ed87b..0000000
--- a/hotspot/make/templates/bsd-header
+++ /dev/null
@@ -1,28 +0,0 @@
-Copyright (c) %YEARS%, Oracle and/or its affiliates. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-  - Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
-
-  - Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution.
-
-  - Neither the name of Oracle nor the names of its
-    contributors may be used to endorse or promote products derived
-    from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/hotspot/make/windows/makefiles/defs.make b/hotspot/make/windows/makefiles/defs.make
index b4b3454..c1be7d2 100644
--- a/hotspot/make/windows/makefiles/defs.make
+++ b/hotspot/make/windows/makefiles/defs.make
@@ -109,6 +109,9 @@
 
 JDK_INCLUDE_SUBDIR=win32
 
+# Library suffix
+LIBRARY_SUFFIX=dll
+
 # HOTSPOT_RELEASE_VERSION and HOTSPOT_BUILD_VERSION are defined
 # and added to MAKE_ARGS list in $(GAMMADIR)/make/defs.make.
 
@@ -175,24 +178,24 @@
 EXPORT_KERNEL_DIR = $(EXPORT_JRE_BIN_DIR)/kernel
 
 EXPORT_LIST += $(EXPORT_SERVER_DIR)/Xusage.txt
-EXPORT_LIST += $(EXPORT_SERVER_DIR)/jvm.dll
+EXPORT_LIST += $(EXPORT_SERVER_DIR)/jvm.$(LIBRARY_SUFFIX)
 EXPORT_LIST += $(EXPORT_SERVER_DIR)/jvm.pdb
 EXPORT_LIST += $(EXPORT_SERVER_DIR)/jvm.map
 EXPORT_LIST += $(EXPORT_LIB_DIR)/jvm.lib
 ifeq ($(ARCH_DATA_MODEL), 32)
   EXPORT_LIST += $(EXPORT_CLIENT_DIR)/Xusage.txt
-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/jvm.dll
+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/jvm.$(LIBRARY_SUFFIX)
   EXPORT_LIST += $(EXPORT_CLIENT_DIR)/jvm.pdb
   EXPORT_LIST += $(EXPORT_CLIENT_DIR)/jvm.map
   # kernel vm
   EXPORT_LIST += $(EXPORT_KERNEL_DIR)/Xusage.txt
-  EXPORT_LIST += $(EXPORT_KERNEL_DIR)/jvm.dll
+  EXPORT_LIST += $(EXPORT_KERNEL_DIR)/jvm.$(LIBRARY_SUFFIX)
   EXPORT_LIST += $(EXPORT_KERNEL_DIR)/jvm.pdb
   EXPORT_LIST += $(EXPORT_KERNEL_DIR)/jvm.map
 endif
 
 ifeq ($(BUILD_WIN_SA), 1)
-  EXPORT_LIST += $(EXPORT_JRE_BIN_DIR)/sawindbg.dll
+  EXPORT_LIST += $(EXPORT_JRE_BIN_DIR)/sawindbg.$(LIBRARY_SUFFIX)
   EXPORT_LIST += $(EXPORT_JRE_BIN_DIR)/sawindbg.pdb
   EXPORT_LIST += $(EXPORT_JRE_BIN_DIR)/sawindbg.map
   EXPORT_LIST += $(EXPORT_LIB_DIR)/sa-jdi.jar
diff --git a/hotspot/make/windows/makefiles/sa.make b/hotspot/make/windows/makefiles/sa.make
index 00d2e9e..ac59711 100644
--- a/hotspot/make/windows/makefiles/sa.make
+++ b/hotspot/make/windows/makefiles/sa.make
@@ -52,12 +52,11 @@
 # Remove the space between $(SA_BUILD_VERSION_PROP) and > below as it adds a white space
 # at the end of SA version string and causes a version mismatch with the target VM version.
 
-$(GENERATED)\sa-jdi.jar: $(AGENT_FILES1:/=\) $(AGENT_FILES2:/=\)
+$(GENERATED)\sa-jdi.jar: $(AGENT_FILES:/=\)
 	@if not exist $(SA_CLASSDIR) mkdir $(SA_CLASSDIR)
 	@echo ...Building sa-jdi.jar
 	@echo ...$(COMPILE_JAVAC) -classpath $(SA_CLASSPATH) -d $(SA_CLASSDIR) ....
-	@$(COMPILE_JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) $(AGENT_FILES1:/=\)
-	@$(COMPILE_JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) $(AGENT_FILES2:/=\)
+	@$(COMPILE_JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) $(AGENT_FILES:/=\)
 	$(COMPILE_RMIC) -classpath $(SA_CLASSDIR) -d $(SA_CLASSDIR) sun.jvm.hotspot.debugger.remote.RemoteDebuggerServer
 	$(QUIETLY) echo $(SA_BUILD_VERSION_PROP)> $(SA_PROPERTIES)
 	$(QUIETLY) rm -f $(SA_CLASSDIR)/sun/jvm/hotspot/utilities/soql/sa.js
diff --git a/hotspot/make/windows/makefiles/vm.make b/hotspot/make/windows/makefiles/vm.make
index 1ee8664..f0b1b93 100644
--- a/hotspot/make/windows/makefiles/vm.make
+++ b/hotspot/make/windows/makefiles/vm.make
@@ -134,6 +134,7 @@
 
 CPP_INCLUDE_DIRS=$(CPP_INCLUDE_DIRS) \
   /I "$(COMMONSRC)\share\vm" \
+  /I "$(COMMONSRC)\share\vm\precompiled" \
   /I "$(COMMONSRC)\share\vm\prims" \
   /I "$(COMMONSRC)\os\windows\vm" \
   /I "$(COMMONSRC)\os_cpu\windows_$(Platform_arch)\vm" \
diff --git a/hotspot/src/cpu/sparc/vm/assembler_sparc.inline.hpp b/hotspot/src/cpu/sparc/vm/assembler_sparc.inline.hpp
index bbacbe9a..d9b1aa5 100644
--- a/hotspot/src/cpu/sparc/vm/assembler_sparc.inline.hpp
+++ b/hotspot/src/cpu/sparc/vm/assembler_sparc.inline.hpp
@@ -597,6 +597,10 @@
 inline void MacroAssembler::jmp( Register s1, int simm13a, RelocationHolder const& rspec ) { jmpl( s1, simm13a, G0, rspec); }
 
 inline bool MacroAssembler::is_far_target(address d) {
+  if (ForceUnreachable) {
+    // References outside the code cache should be treated as far
+    return d < CodeCache::low_bound() || d > CodeCache::high_bound();
+  }
   return !is_in_wdisp30_range(d, CodeCache::low_bound()) || !is_in_wdisp30_range(d, CodeCache::high_bound());
 }
 
@@ -679,28 +683,44 @@
 
 inline void MacroAssembler::load_contents(const AddressLiteral& addrlit, Register d, int offset) {
   assert_not_delayed();
-  sethi(addrlit, d);
+  if (ForceUnreachable) {
+    patchable_sethi(addrlit, d);
+  } else {
+    sethi(addrlit, d);
+  }
   ld(d, addrlit.low10() + offset, d);
 }
 
 
 inline void MacroAssembler::load_ptr_contents(const AddressLiteral& addrlit, Register d, int offset) {
   assert_not_delayed();
-  sethi(addrlit, d);
+  if (ForceUnreachable) {
+    patchable_sethi(addrlit, d);
+  } else {
+    sethi(addrlit, d);
+  }
   ld_ptr(d, addrlit.low10() + offset, d);
 }
 
 
 inline void MacroAssembler::store_contents(Register s, const AddressLiteral& addrlit, Register temp, int offset) {
   assert_not_delayed();
-  sethi(addrlit, temp);
+  if (ForceUnreachable) {
+    patchable_sethi(addrlit, temp);
+  } else {
+    sethi(addrlit, temp);
+  }
   st(s, temp, addrlit.low10() + offset);
 }
 
 
 inline void MacroAssembler::store_ptr_contents(Register s, const AddressLiteral& addrlit, Register temp, int offset) {
   assert_not_delayed();
-  sethi(addrlit, temp);
+  if (ForceUnreachable) {
+    patchable_sethi(addrlit, temp);
+  } else {
+    sethi(addrlit, temp);
+  }
   st_ptr(s, temp, addrlit.low10() + offset);
 }
 
diff --git a/hotspot/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp
index e155153..a54b68c 100644
--- a/hotspot/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp
@@ -367,10 +367,10 @@
 
 void DeoptimizeStub::emit_code(LIR_Assembler* ce) {
   __ bind(_entry);
-  __ call(SharedRuntime::deopt_blob()->unpack_with_reexecution());
+  __ call(Runtime1::entry_for(Runtime1::deoptimize_id), relocInfo::runtime_call_type);
   __ delayed()->nop();
   ce->add_call_info_here(_info);
-  debug_only(__ should_not_reach_here());
+  DEBUG_ONLY(__ should_not_reach_here());
 }
 
 
diff --git a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp
index 7a8b555..15be6d3 100644
--- a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp
@@ -1116,7 +1116,7 @@
       } else {
         __ set(value_hi, O7);
       }
-      offset = store(tmp, base, addr->disp() + hi_word_offset_in_bytes, T_INT, wide, false);
+      store(tmp, base, addr->disp() + hi_word_offset_in_bytes, T_INT, wide, false);
       break;
     }
     case T_OBJECT: {
diff --git a/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp
index 7b60789..abf3ab9 100644
--- a/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp
@@ -328,7 +328,8 @@
   bool use_length = x->length() != NULL;
   bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
   bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
-                                         !get_jobject_constant(x->value())->is_null_object());
+                                         !get_jobject_constant(x->value())->is_null_object() ||
+                                         x->should_profile());
 
   LIRItem array(x->array(), this);
   LIRItem index(x->index(), this);
@@ -382,7 +383,7 @@
     LIR_Opr tmp3 = FrameMap::G5_opr;
 
     CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
-    __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info);
+    __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());
   }
 
   if (obj_store) {
diff --git a/hotspot/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp
index 23bf235..64f15e0 100644
--- a/hotspot/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp
@@ -766,7 +766,22 @@
 
         __ ret();
         __ delayed()->restore();
+      }
+      break;
 
+    case deoptimize_id:
+      {
+        __ set_info("deoptimize", dont_gc_arguments);
+        OopMap* oop_map = save_live_registers(sasm);
+        int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize));
+        oop_maps = new OopMapSet();
+        oop_maps->add_gc_map(call_offset, oop_map);
+        restore_live_registers(sasm);
+        DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
+        assert(deopt_blob != NULL, "deoptimization blob must have been created");
+        AddressLiteral dest(deopt_blob->unpack_with_reexecution());
+        __ jump_to(dest, O0);
+        __ delayed()->restore();
       }
       break;
 
diff --git a/hotspot/src/cpu/sparc/vm/copy_sparc.hpp b/hotspot/src/cpu/sparc/vm/copy_sparc.hpp
index 176ed04..13829b1 100644
--- a/hotspot/src/cpu/sparc/vm/copy_sparc.hpp
+++ b/hotspot/src/cpu/sparc/vm/copy_sparc.hpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -82,13 +82,35 @@
 }
 
 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
-  // FIXME
-  (void)memmove(to, from, count << LogBytesPerShort);
+  if (from > to) {
+    while (count-- > 0) {
+      // Copy forwards
+      *to++ = *from++;
+    }
+  } else {
+    from += count - 1;
+    to   += count - 1;
+    while (count-- > 0) {
+      // Copy backwards
+      *to-- = *from--;
+    }
+  }
 }
 
 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
-  // FIXME
-  (void)memmove(to, from, count << LogBytesPerInt);
+  if (from > to) {
+    while (count-- > 0) {
+      // Copy forwards
+      *to++ = *from++;
+    }
+  } else {
+    from += count - 1;
+    to   += count - 1;
+    while (count-- > 0) {
+      // Copy backwards
+      *to-- = *from--;
+    }
+  }
 }
 
 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
diff --git a/hotspot/src/cpu/sparc/vm/methodHandles_sparc.cpp b/hotspot/src/cpu/sparc/vm/methodHandles_sparc.cpp
index 14030c0..3b2b5dd 100644
--- a/hotspot/src/cpu/sparc/vm/methodHandles_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/methodHandles_sparc.cpp
@@ -352,6 +352,7 @@
   BLOCK_COMMENT("load_stack_move {");
   __ ldsw(G3_amh_conversion, stack_move_reg);
   __ sra(stack_move_reg, CONV_STACK_MOVE_SHIFT, stack_move_reg);
+#ifdef ASSERT
   if (VerifyMethodHandles) {
     Label L_ok, L_bad;
     int32_t stack_move_limit = 0x0800;  // extra-large
@@ -363,6 +364,7 @@
     __ stop("load_stack_move of garbage value");
     __ BIND(L_ok);
   }
+#endif
   BLOCK_COMMENT("} load_stack_move");
 }
 
diff --git a/hotspot/src/cpu/sparc/vm/methodHandles_sparc.hpp b/hotspot/src/cpu/sparc/vm/methodHandles_sparc.hpp
index 4a0bca8..0c28510 100644
--- a/hotspot/src/cpu/sparc/vm/methodHandles_sparc.hpp
+++ b/hotspot/src/cpu/sparc/vm/methodHandles_sparc.hpp
@@ -27,7 +27,7 @@
 
 // Adapters
 enum /* platform_dependent_constants */ {
-  adapter_code_size = NOT_LP64(22000 DEBUG_ONLY(+ 40000)) LP64_ONLY(32000 DEBUG_ONLY(+ 80000))
+  adapter_code_size = NOT_LP64(23000 DEBUG_ONLY(+ 40000)) LP64_ONLY(35000 DEBUG_ONLY(+ 50000))
 };
 
 public:
diff --git a/hotspot/src/cpu/sparc/vm/sparc.ad b/hotspot/src/cpu/sparc/vm/sparc.ad
index 1484f6b..92f3c86 100644
--- a/hotspot/src/cpu/sparc/vm/sparc.ad
+++ b/hotspot/src/cpu/sparc/vm/sparc.ad
@@ -1860,6 +1860,14 @@
 // Threshold size for cleararray.
 const int Matcher::init_array_short_size = 8 * BytesPerLong;
 
+// No additional cost for CMOVL.
+const int Matcher::long_cmove_cost() { return 0; }
+
+// CMOVF/CMOVD are expensive on T4 and on SPARC64.
+const int Matcher::float_cmove_cost() {
+  return (VM_Version::is_T4() || VM_Version::is_sparc64()) ? ConditionalMoveLimit : 0;
+}
+
 // Should the Matcher clone shifts on addressing modes, expecting them to
 // be subsumed into complex addressing expressions or compute them into
 // registers?  True for Intel but false for most RISCs
diff --git a/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp b/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp
index cf40304..9415c7b 100644
--- a/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp
@@ -2359,10 +2359,10 @@
     for (int off = 0; off < 64; off += 16) {
       if (use_prefetch && (off & 31) == 0) {
         if (ArraycopySrcPrefetchDistance > 0) {
-          __ prefetch(from, ArraycopySrcPrefetchDistance, Assembler::severalReads);
+          __ prefetch(from, ArraycopySrcPrefetchDistance+off, Assembler::severalReads);
         }
         if (ArraycopyDstPrefetchDistance > 0) {
-          __ prefetch(to, ArraycopyDstPrefetchDistance, Assembler::severalWritesAndPossiblyReads);
+          __ prefetch(to, ArraycopyDstPrefetchDistance+off, Assembler::severalWritesAndPossiblyReads);
         }
       }
       __ ldx(from,  off+0, O4);
diff --git a/hotspot/src/cpu/sparc/vm/vm_version_sparc.cpp b/hotspot/src/cpu/sparc/vm/vm_version_sparc.cpp
index e1429c6..1d49662 100644
--- a/hotspot/src/cpu/sparc/vm/vm_version_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/vm_version_sparc.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -211,7 +211,7 @@
 #ifdef COMPILER2
   // T4 and newer Sparc cpus have fast RDPC.
   if (has_fast_rdpc() && FLAG_IS_DEFAULT(UseRDPCForConstantTableBase)) {
-//    FLAG_SET_DEFAULT(UseRDPCForConstantTableBase, true);
+    FLAG_SET_DEFAULT(UseRDPCForConstantTableBase, true);
   }
 
   // Currently not supported anywhere.
diff --git a/hotspot/src/cpu/x86/vm/bytes_x86.hpp b/hotspot/src/cpu/x86/vm/bytes_x86.hpp
index ac096dc..9f939a3 100644
--- a/hotspot/src/cpu/x86/vm/bytes_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/bytes_x86.hpp
@@ -81,6 +81,9 @@
 #ifdef TARGET_OS_ARCH_windows_x86
 # include "bytes_windows_x86.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "bytes_bsd_x86.inline.hpp"
+#endif
 
 
 #endif // CPU_X86_VM_BYTES_X86_HPP
diff --git a/hotspot/src/cpu/x86/vm/c1_CodeStubs_x86.cpp b/hotspot/src/cpu/x86/vm/c1_CodeStubs_x86.cpp
index 5e2d7fe..f276df9 100644
--- a/hotspot/src/cpu/x86/vm/c1_CodeStubs_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/c1_CodeStubs_x86.cpp
@@ -387,9 +387,9 @@
 
 void DeoptimizeStub::emit_code(LIR_Assembler* ce) {
   __ bind(_entry);
-  __ call(RuntimeAddress(SharedRuntime::deopt_blob()->unpack_with_reexecution()));
+  __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::deoptimize_id)));
   ce->add_call_info_here(_info);
-  debug_only(__ should_not_reach_here());
+  DEBUG_ONLY(__ should_not_reach_here());
 }
 
 
diff --git a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
index 407f0fc..dbdd708 100644
--- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
@@ -427,8 +427,8 @@
   // Fetch the exception from TLS and clear out exception related thread state
   __ get_thread(rsi);
   __ movptr(rax, Address(rsi, JavaThread::exception_oop_offset()));
-  __ movptr(Address(rsi, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);
-  __ movptr(Address(rsi, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
+  __ movptr(Address(rsi, JavaThread::exception_oop_offset()), (intptr_t)NULL_WORD);
+  __ movptr(Address(rsi, JavaThread::exception_pc_offset()), (intptr_t)NULL_WORD);
 
   __ bind(_unwind_handler_entry);
   __ verify_not_null_oop(rax);
diff --git a/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
index c71590a..1ff91ca 100644
--- a/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
@@ -267,7 +267,8 @@
   bool use_length = x->length() != NULL;
   bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
   bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
-                                         !get_jobject_constant(x->value())->is_null_object());
+                                         !get_jobject_constant(x->value())->is_null_object() ||
+                                         x->should_profile());
 
   LIRItem array(x->array(), this);
   LIRItem index(x->index(), this);
@@ -321,7 +322,7 @@
     LIR_Opr tmp3 = new_register(objectType);
 
     CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
-    __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info);
+    __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());
   }
 
   if (obj_store) {
diff --git a/hotspot/src/cpu/x86/vm/c1_Runtime1_x86.cpp b/hotspot/src/cpu/x86/vm/c1_Runtime1_x86.cpp
index 9ad2e58..9d13221 100644
--- a/hotspot/src/cpu/x86/vm/c1_Runtime1_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/c1_Runtime1_x86.cpp
@@ -1447,7 +1447,22 @@
         oop_maps = new OopMapSet();
         oop_maps->add_gc_map(call_offset, map);
         restore_live_registers(sasm, save_fpu_registers);
+      }
+      break;
 
+    case deoptimize_id:
+      {
+        StubFrame f(sasm, "deoptimize", dont_gc_arguments);
+        const int num_rt_args = 1;  // thread
+        OopMap* oop_map = save_live_registers(sasm, num_rt_args);
+        int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize));
+        oop_maps = new OopMapSet();
+        oop_maps->add_gc_map(call_offset, oop_map);
+        restore_live_registers(sasm);
+        DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
+        assert(deopt_blob != NULL, "deoptimization blob must have been created");
+        __ leave();
+        __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
       }
       break;
 
diff --git a/hotspot/src/cpu/x86/vm/copy_x86.hpp b/hotspot/src/cpu/x86/vm/copy_x86.hpp
index dbadb0e..d5c6d5e 100644
--- a/hotspot/src/cpu/x86/vm/copy_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/copy_x86.hpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_ARCH_windows_x86
 # include "copy_windows_x86.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "copy_bsd_x86.inline.hpp"
+#endif
 
 
 static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
diff --git a/hotspot/src/cpu/x86/vm/frame_x86.cpp b/hotspot/src/cpu/x86/vm/frame_x86.cpp
index 3d82d06..5d4da62 100644
--- a/hotspot/src/cpu/x86/vm/frame_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/frame_x86.cpp
@@ -232,11 +232,15 @@
 
 
 void frame::patch_pc(Thread* thread, address pc) {
+  address* pc_addr = &(((address*) sp())[-1]);
   if (TracePcPatching) {
-    tty->print_cr("patch_pc at address" INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "] ",
-                  &((address *)sp())[-1], ((address *)sp())[-1], pc);
+    tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
+                  pc_addr, *pc_addr, pc);
   }
-  ((address *)sp())[-1] = pc;
+  // Either the return address is the original one or we are going to
+  // patch in the same address that's already there.
+  assert(_pc == *pc_addr || pc == *pc_addr, "must be");
+  *pc_addr = pc;
   _cb = CodeCache::find_blob(pc);
   address original_pc = nmethod::get_deopt_original_pc(this);
   if (original_pc != NULL) {
@@ -671,4 +675,3 @@
   // used to reset the saved FP
   return fp();
 }
-
diff --git a/hotspot/src/cpu/x86/vm/globals_x86.hpp b/hotspot/src/cpu/x86/vm/globals_x86.hpp
index 8b79f8e..d40f559 100644
--- a/hotspot/src/cpu/x86/vm/globals_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/globals_x86.hpp
@@ -70,7 +70,11 @@
 define_pd_global(bool, RewriteBytecodes,     true);
 define_pd_global(bool, RewriteFrequentPairs, true);
 
+#ifdef _ALLBSD_SOURCE
+define_pd_global(bool, UseMembar,            true);
+#else
 define_pd_global(bool, UseMembar,            false);
+#endif
 
 // GC Ergo Flags
 define_pd_global(intx, CMSYoungGenPerWorker, 64*M);  // default max size of CMS young gen, per GC worker thread
diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp b/hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp
index 9651470..f06d54e 100644
--- a/hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp
+++ b/hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp
@@ -45,6 +45,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 // Implementation of InterpreterMacroAssembler
@@ -1158,7 +1161,7 @@
   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
   set_mdp_data_at(mdp, recvr_offset, receiver);
   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
-  movptr(reg2, (int32_t)DataLayout::counter_increment);
+  movptr(reg2, (intptr_t)DataLayout::counter_increment);
   set_mdp_data_at(mdp, count_offset, reg2);
   if (start_row > 0) {
     jmp(done);
@@ -1301,7 +1304,7 @@
     test_method_data_pointer(mdp, profile_continue);
 
     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
-    movptr(reg2, (int32_t)in_bytes(MultiBranchData::per_case_size()));
+    movptr(reg2, (intptr_t)in_bytes(MultiBranchData::per_case_size()));
     // index is positive and so should have correct value if this code were
     // used on 64bits
     imulptr(index, reg2);
diff --git a/hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp b/hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp
index 3cd4355..e418436 100644
--- a/hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp
@@ -45,6 +45,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 // Implementation of InterpreterMacroAssembler
diff --git a/hotspot/src/cpu/x86/vm/jni_x86.h b/hotspot/src/cpu/x86/vm/jni_x86.h
index d06bb5c..d724c86 100644
--- a/hotspot/src/cpu/x86/vm/jni_x86.h
+++ b/hotspot/src/cpu/x86/vm/jni_x86.h
@@ -26,7 +26,7 @@
 #ifndef _JAVASOFT_JNI_MD_H_
 #define _JAVASOFT_JNI_MD_H_
 
-#if defined(SOLARIS) || defined(LINUX)
+#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
 
 #if defined(__GNUC__) && (__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2)
   #define JNIEXPORT     __attribute__((visibility("default")))
@@ -38,10 +38,14 @@
 
   #define JNICALL
   typedef int jint;
-
-#ifdef _LP64
+#if defined(_LP64) && !defined(__APPLE__)
   typedef long jlong;
 #else
+  /*
+   * On _LP64 __APPLE__ "long" and "long long" are both 64 bits,
+   * but we use the "long long" typedef to avoid complaints from
+   * the __APPLE__ compiler about fprintf formats.
+   */
   typedef long long jlong;
 #endif
 
diff --git a/hotspot/src/cpu/x86/vm/methodHandles_x86.cpp b/hotspot/src/cpu/x86/vm/methodHandles_x86.cpp
index dd741fd..254d087 100644
--- a/hotspot/src/cpu/x86/vm/methodHandles_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/methodHandles_x86.cpp
@@ -382,6 +382,7 @@
     __ movslq(rdi_stack_move, rdi_stack_move);
   }
 #endif //_LP64
+#ifdef ASSERT
   if (VerifyMethodHandles) {
     Label L_ok, L_bad;
     int32_t stack_move_limit = 0x4000;  // extra-large
@@ -393,6 +394,7 @@
     __ stop("load_stack_move of garbage value");
     __ BIND(L_ok);
   }
+#endif
   BLOCK_COMMENT("} load_stack_move");
 }
 
@@ -410,8 +412,8 @@
 
 void MethodHandles::RicochetFrame::verify() const {
   verify_offsets();
-  assert(magic_number_1() == MAGIC_NUMBER_1, "");
-  assert(magic_number_2() == MAGIC_NUMBER_2, "");
+  assert(magic_number_1() == MAGIC_NUMBER_1, err_msg(PTR_FORMAT " == " PTR_FORMAT, magic_number_1(), MAGIC_NUMBER_1));
+  assert(magic_number_2() == MAGIC_NUMBER_2, err_msg(PTR_FORMAT " == " PTR_FORMAT, magic_number_2(), MAGIC_NUMBER_2));
   if (!Universe::heap()->is_gc_active()) {
     if (saved_args_layout() != NULL) {
       assert(saved_args_layout()->is_method(), "must be valid oop");
diff --git a/hotspot/src/cpu/x86/vm/methodHandles_x86.hpp b/hotspot/src/cpu/x86/vm/methodHandles_x86.hpp
index bf85c33..9d7168a 100644
--- a/hotspot/src/cpu/x86/vm/methodHandles_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/methodHandles_x86.hpp
@@ -27,7 +27,7 @@
 
 // Adapters
 enum /* platform_dependent_constants */ {
-  adapter_code_size = NOT_LP64(30000 DEBUG_ONLY(+ 10000)) LP64_ONLY(80000 DEBUG_ONLY(+ 120000))
+  adapter_code_size = NOT_LP64(16000 DEBUG_ONLY(+ 15000)) LP64_ONLY(32000 DEBUG_ONLY(+ 80000))
 };
 
 public:
@@ -132,7 +132,10 @@
   intptr_t* sender_link() const         { return _sender_link; }
   address   sender_pc() const           { return _sender_pc; }
 
-  intptr_t* extended_sender_sp() const  { return saved_args_base(); }
+  intptr_t* extended_sender_sp() const {
+    // The extended sender SP is above the current RicochetFrame.
+    return (intptr_t*) (((address) this) + sizeof(RicochetFrame));
+  }
 
   intptr_t  return_value_slot_number() const {
     return adapter_conversion_vminfo(conversion());
diff --git a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
index effb3ce..b03eb92 100644
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
@@ -2797,17 +2797,25 @@
   // void Deoptimization::unpack_frames(JavaThread* thread, int exec_mode)
 
   // Use rbp because the frames look interpreted now
-  __ set_last_Java_frame(noreg, rbp, NULL);
+  // Save "the_pc" since it cannot easily be retrieved using the last_java_SP after we aligned SP.
+  // Don't need the precise return PC here, just precise enough to point into this code blob.
+  address the_pc = __ pc();
+  __ set_last_Java_frame(noreg, rbp, the_pc);
 
+  __ andptr(rsp, -(StackAlignmentInBytes));  // Fix stack alignment as required by ABI
   __ mov(c_rarg0, r15_thread);
   __ movl(c_rarg1, r14); // second arg: exec_mode
   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
+  // Revert SP alignment after call since we're going to do some SP relative addressing below
+  __ movptr(rsp, Address(r15_thread, JavaThread::last_Java_sp_offset()));
 
   // Set an oopmap for the call site
-  oop_maps->add_gc_map(__ pc() - start,
+  // Use the same PC we used for the last java frame
+  oop_maps->add_gc_map(the_pc - start,
                        new OopMap( frame_size_in_words, 0 ));
 
-  __ reset_last_Java_frame(true, false);
+  // Clear fp AND pc
+  __ reset_last_Java_frame(true, true);
 
   // Collect return values
   __ movdbl(xmm0, Address(rsp, RegisterSaver::xmm0_offset_in_bytes()));
@@ -2968,7 +2976,10 @@
                               // Prolog
 
   // Use rbp because the frames look interpreted now
-  __ set_last_Java_frame(noreg, rbp, NULL);
+  // Save "the_pc" since it cannot easily be retrieved using the last_java_SP after we aligned SP.
+  // Don't need the precise return PC here, just precise enough to point into this code blob.
+  address the_pc = __ pc();
+  __ set_last_Java_frame(noreg, rbp, the_pc);
 
   // Call C code.  Need thread but NOT official VM entry
   // crud.  We cannot block on this call, no GC can happen.  Call should
@@ -2977,14 +2988,17 @@
   //
   // BasicType unpack_frames(JavaThread* thread, int exec_mode);
 
+  __ andptr(rsp, -(StackAlignmentInBytes)); // Align SP as required by ABI
   __ mov(c_rarg0, r15_thread);
   __ movl(c_rarg1, Deoptimization::Unpack_uncommon_trap);
   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
 
   // Set an oopmap for the call site
-  oop_maps->add_gc_map(__ pc() - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
+  // Use the same PC we used for the last java frame
+  oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
 
-  __ reset_last_Java_frame(true, false);
+  // Clear fp AND pc
+  __ reset_last_Java_frame(true, true);
 
   // Pop self-frame.
   __ leave();                 // Epilog
diff --git a/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp b/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
index e8a8533..fb85fff 100644
--- a/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
+++ b/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
@@ -47,6 +47,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifdef COMPILER2
 #include "opto/runtime.hpp"
 #endif
diff --git a/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp b/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
index a58b8d9..53d9431 100644
--- a/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
@@ -47,6 +47,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifdef COMPILER2
 #include "opto/runtime.hpp"
 #endif
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
index dfdab6f..6ec4121 100644
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // Implementation of the platform-specific part of StubRoutines - for
 // a description of how to extend it, see the stubRoutines.hpp file.
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
index caab63b..182872b 100644
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // Implementation of the platform-specific part of StubRoutines - for
 // a description of how to extend it, see the stubRoutines.hpp file.
diff --git a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp
index 3f3370e..6f8e35a 100644
--- a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp
+++ b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp
@@ -1609,6 +1609,12 @@
     // and sender_sp is fp+8
     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
 
+#ifdef ASSERT
+    if (caller->is_interpreted_frame()) {
+      assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
+    }
+#endif
+
     interpreter_frame->interpreter_frame_set_locals(locals);
     BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
     BasicObjectLock* monbot = montop - moncount;
diff --git a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp
index 9aa8c34..40c7d63 100644
--- a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp
@@ -1622,6 +1622,12 @@
     // sender_sp is fp+16 XXX
     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
 
+#ifdef ASSERT
+    if (caller->is_interpreted_frame()) {
+      assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
+    }
+#endif
+
     interpreter_frame->interpreter_frame_set_locals(locals);
     BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
     BasicObjectLock* monbot = montop - moncount;
diff --git a/hotspot/src/cpu/x86/vm/vm_version_x86.cpp b/hotspot/src/cpu/x86/vm/vm_version_x86.cpp
index 42a4c3c..7a8ee72 100644
--- a/hotspot/src/cpu/x86/vm/vm_version_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/vm_version_x86.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 
 int VM_Version::_cpu;
diff --git a/hotspot/src/cpu/x86/vm/x86_32.ad b/hotspot/src/cpu/x86/vm/x86_32.ad
index b403752..e00df3a 100644
--- a/hotspot/src/cpu/x86/vm/x86_32.ad
+++ b/hotspot/src/cpu/x86/vm/x86_32.ad
@@ -1393,6 +1393,12 @@
 // Threshold size for cleararray.
 const int Matcher::init_array_short_size = 8 * BytesPerLong;
 
+// Needs 2 CMOV's for longs.
+const int Matcher::long_cmove_cost() { return 1; }
+
+// No CMOVF/CMOVD with SSE/SSE2
+const int Matcher::float_cmove_cost() { return (UseSSE>=1) ? ConditionalMoveLimit : 0; }
+
 // Should the Matcher clone shifts on addressing modes, expecting them to
 // be subsumed into complex addressing expressions or compute them into
 // registers?  True for Intel but false for most RISCs
@@ -7905,6 +7911,40 @@
 
 //----------Conditional Move---------------------------------------------------
 // Conditional move
+instruct jmovI_reg(cmpOp cop, eFlagsReg cr, eRegI dst, eRegI src) %{
+  predicate(!VM_Version::supports_cmov() );
+  match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
+  ins_cost(200);
+  format %{ "J$cop,us skip\t# signed cmove\n\t"
+            "MOV    $dst,$src\n"
+      "skip:" %}
+  ins_encode %{
+    Label Lskip;
+    // Invert sense of branch from sense of CMOV
+    __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
+    __ movl($dst$$Register, $src$$Register);
+    __ bind(Lskip);
+  %}
+  ins_pipe( pipe_cmov_reg );
+%}
+
+instruct jmovI_regU(cmpOpU cop, eFlagsRegU cr, eRegI dst, eRegI src) %{
+  predicate(!VM_Version::supports_cmov() );
+  match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
+  ins_cost(200);
+  format %{ "J$cop,us skip\t# unsigned cmove\n\t"
+            "MOV    $dst,$src\n"
+      "skip:" %}
+  ins_encode %{
+    Label Lskip;
+    // Invert sense of branch from sense of CMOV
+    __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
+    __ movl($dst$$Register, $src$$Register);
+    __ bind(Lskip);
+  %}
+  ins_pipe( pipe_cmov_reg );
+%}
+
 instruct cmovI_reg(eRegI dst, eRegI src, eFlagsReg cr, cmpOp cop ) %{
   predicate(VM_Version::supports_cmov() );
   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
diff --git a/hotspot/src/cpu/x86/vm/x86_64.ad b/hotspot/src/cpu/x86/vm/x86_64.ad
index 4f6fa3c..3e76c40 100644
--- a/hotspot/src/cpu/x86/vm/x86_64.ad
+++ b/hotspot/src/cpu/x86/vm/x86_64.ad
@@ -1993,6 +1993,12 @@
 // Threshold size for cleararray.
 const int Matcher::init_array_short_size = 8 * BytesPerLong;
 
+// No additional cost for CMOVL.
+const int Matcher::long_cmove_cost() { return 0; }
+
+// No CMOVF/CMOVD with SSE2
+const int Matcher::float_cmove_cost() { return ConditionalMoveLimit; }
+
 // Should the Matcher clone shifts on addressing modes, expecting them
 // to be subsumed into complex addressing expressions or compute them
 // into registers?  True for Intel but false for most RISCs
diff --git a/hotspot/src/cpu/zero/vm/bytes_zero.hpp b/hotspot/src/cpu/zero/vm/bytes_zero.hpp
index 39caaea..be2e09a 100644
--- a/hotspot/src/cpu/zero/vm/bytes_zero.hpp
+++ b/hotspot/src/cpu/zero/vm/bytes_zero.hpp
@@ -168,6 +168,9 @@
 #ifdef TARGET_OS_ARCH_linux_zero
 # include "bytes_linux_zero.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "bytes_bsd_zero.inline.hpp"
+#endif
 
 #endif // VM_LITTLE_ENDIAN
 
diff --git a/hotspot/src/cpu/zero/vm/globals_zero.hpp b/hotspot/src/cpu/zero/vm/globals_zero.hpp
index c45f1f5..6754e69 100644
--- a/hotspot/src/cpu/zero/vm/globals_zero.hpp
+++ b/hotspot/src/cpu/zero/vm/globals_zero.hpp
@@ -52,7 +52,11 @@
 define_pd_global(bool,  RewriteBytecodes,     true);
 define_pd_global(bool,  RewriteFrequentPairs, true);
 
+#ifdef _ALLBSD_SOURCE
+define_pd_global(bool,  UseMembar,            true);
+#else
 define_pd_global(bool,  UseMembar,            false);
+#endif
 
 // GC Ergo Flags
 define_pd_global(intx, CMSYoungGenPerWorker, 16*M);  // default max size of CMS young gen, per GC worker thread
diff --git a/hotspot/src/cpu/zero/vm/interp_masm_zero.cpp b/hotspot/src/cpu/zero/vm/interp_masm_zero.cpp
index 8b470eb..a85431b 100644
--- a/hotspot/src/cpu/zero/vm/interp_masm_zero.cpp
+++ b/hotspot/src/cpu/zero/vm/interp_masm_zero.cpp
@@ -40,5 +40,8 @@
 #ifdef TARGET_OS_FAMILY_linux
 # include "thread_linux.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // This file is intentionally empty
diff --git a/hotspot/src/cpu/zero/vm/stubGenerator_zero.cpp b/hotspot/src/cpu/zero/vm/stubGenerator_zero.cpp
index b13c0f3..4142e02 100644
--- a/hotspot/src/cpu/zero/vm/stubGenerator_zero.cpp
+++ b/hotspot/src/cpu/zero/vm/stubGenerator_zero.cpp
@@ -43,6 +43,9 @@
 #ifdef TARGET_OS_FAMILY_linux
 # include "thread_linux.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifdef COMPILER2
 #include "opto/runtime.hpp"
 #endif
diff --git a/hotspot/src/cpu/zero/vm/stubRoutines_zero.cpp b/hotspot/src/cpu/zero/vm/stubRoutines_zero.cpp
index 96df53e..8b21dde 100644
--- a/hotspot/src/cpu/zero/vm/stubRoutines_zero.cpp
+++ b/hotspot/src/cpu/zero/vm/stubRoutines_zero.cpp
@@ -30,3 +30,6 @@
 #ifdef TARGET_OS_FAMILY_linux
 # include "thread_linux.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
diff --git a/hotspot/src/cpu/zero/vm/vm_version_zero.cpp b/hotspot/src/cpu/zero/vm/vm_version_zero.cpp
index 87ff88b..391e29d 100644
--- a/hotspot/src/cpu/zero/vm/vm_version_zero.cpp
+++ b/hotspot/src/cpu/zero/vm/vm_version_zero.cpp
@@ -32,5 +32,8 @@
 #ifdef TARGET_OS_FAMILY_linux
 # include "os_linux.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 // This file is intentionally empty
diff --git a/hotspot/src/os/bsd/dtrace/generateJvmOffsets.cpp b/hotspot/src/os/bsd/dtrace/generateJvmOffsets.cpp
new file mode 100644
index 0000000..8f47282
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/generateJvmOffsets.cpp
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * This is to provide sanity check in jhelper.d which compares SCCS
+ * versions of generateJvmOffsets.cpp used to create and extract
+ * contents of __JvmOffsets[] table.
+ * The __JvmOffsets[] table is located in generated JvmOffsets.cpp.
+ *
+ * GENOFFS_SCCS_VER 34
+ */
+
+#include "generateJvmOffsets.h"
+
+/* A workaround for private and protected fields */
+#define private   public
+#define protected public
+
+// not on macosx #include <proc_service.h>
+#include "code/codeBlob.hpp"
+#include "code/nmethod.hpp"
+#include "code/pcDesc.hpp"
+#include "gc_interface/collectedHeap.hpp"
+#include "memory/heap.hpp"
+#include "memory/memRegion.hpp"
+#include "memory/universe.hpp"
+#include "oops/constMethodOop.hpp"
+#include "oops/klass.hpp"
+#include "oops/methodOop.hpp"
+#include "oops/oop.hpp"
+#include "oops/symbol.hpp"
+#include "runtime/virtualspace.hpp"
+#include "runtime/vmStructs.hpp"
+#include "utilities/accessFlags.hpp"
+#include "utilities/globalDefinitions.hpp"
+
+// These are defined somewhere for Solaris
+#define PR_MODEL_ILP32 1
+#define PR_MODEL_LP64  2
+
+#ifdef COMPILER1
+#if defined(DEBUG) || defined(FASTDEBUG)
+
+/*
+ * To avoid the most part of potential link errors
+ * we link this program with -z nodefs .
+ *
+ * But for 'debug1' and 'fastdebug1' we still have to provide
+ * a particular workaround for the following symbols bellow.
+ * It will be good to find out a generic way in the future.
+ */
+
+#pragma weak tty
+#pragma weak CMSExpAvgFactor
+
+#if defined(i386) || defined(__i386) || defined(__amd64)
+#pragma weak noreg
+#endif /* i386 */
+
+LIR_Opr LIR_OprFact::illegalOpr = (LIR_Opr) 0;
+
+address StubRoutines::_call_stub_return_address = NULL;
+
+StubQueue* AbstractInterpreter::_code = NULL;
+
+#endif /* defined(DEBUG) || defined(FASTDEBUG) */
+#endif /* COMPILER1 */
+
+#define GEN_OFFS(Type,Name)                             \
+  switch(gen_variant) {                                 \
+  case GEN_OFFSET:                                      \
+    printf("#define OFFSET_%-33s %ld\n",                 \
+           #Type #Name, offset_of(Type, Name)); \
+    break;                                              \
+  case GEN_INDEX:                                       \
+    printf("#define IDX_OFFSET_%-33s %d\n",             \
+            #Type #Name, index++);                      \
+    break;                                              \
+  case GEN_TABLE:                                       \
+    printf("\tOFFSET_%s,\n", #Type #Name);              \
+    break;                                              \
+  }
+
+#define GEN_SIZE(Type)                                  \
+  switch(gen_variant) {                                 \
+  case GEN_OFFSET:                                      \
+    printf("#define SIZE_%-35s %ld\n",                   \
+            #Type, sizeof(Type));                       \
+    break;                                              \
+  case GEN_INDEX:                                       \
+    printf("#define IDX_SIZE_%-35s %d\n",               \
+            #Type, index++);                            \
+    break;                                              \
+  case GEN_TABLE:                                       \
+    printf("\tSIZE_%s,\n", #Type);                      \
+    break;                                              \
+  }
+
+#define GEN_VALUE(String,Value)                         \
+  switch(gen_variant) {                                 \
+  case GEN_OFFSET:                                      \
+    printf("#define %-40s %d\n", #String, Value);       \
+    break;                                              \
+  case GEN_INDEX:                                       \
+    printf("#define IDX_%-40s %d\n", #String, index++); \
+    break;                                              \
+  case GEN_TABLE:                                       \
+    printf("\t" #String ",\n");                         \
+    break;                                              \
+  }
+
+void gen_prologue(GEN_variant gen_variant) {
+    const char *suffix;
+
+    switch(gen_variant) {
+      case GEN_OFFSET: suffix = ".h";        break;
+      case GEN_INDEX:  suffix = "Index.h";   break;
+      case GEN_TABLE:  suffix = ".cpp";      break;
+    }
+
+    printf("/*\n");
+    printf(" * JvmOffsets%s !!!DO NOT EDIT!!! \n", suffix);
+    printf(" * The generateJvmOffsets program generates this file!\n");
+    printf(" */\n\n");
+    switch(gen_variant) {
+
+      case GEN_OFFSET:
+      case GEN_INDEX:
+        break;
+
+      case GEN_TABLE:
+        printf("#include \"JvmOffsets.h\"\n");
+        printf("\n");
+        printf("int __JvmOffsets[] = {\n");
+        break;
+    }
+}
+
+void gen_epilogue(GEN_variant gen_variant) {
+    if (gen_variant != GEN_TABLE) {
+        return;
+    }
+    printf("};\n\n");
+    return;
+}
+
+int generateJvmOffsets(GEN_variant gen_variant) {
+  int index = 0;        /* It is used to generate JvmOffsetsIndex.h */
+  int pointer_size = sizeof(void *);
+  int data_model = (pointer_size == 4) ? PR_MODEL_ILP32 : PR_MODEL_LP64;
+
+  gen_prologue(gen_variant);
+
+  GEN_VALUE(DATA_MODEL, data_model);
+  GEN_VALUE(POINTER_SIZE, pointer_size);
+#if defined(TIERED)
+  GEN_VALUE(COMPILER, 3);
+#elif COMPILER1
+  GEN_VALUE(COMPILER, 1);
+#elif COMPILER2
+  GEN_VALUE(COMPILER, 2);
+#else
+  GEN_VALUE(COMPILER, 0);
+#endif // COMPILER1 && COMPILER2
+  printf("\n");
+
+  GEN_OFFS(CollectedHeap, _reserved);
+  GEN_OFFS(MemRegion, _start);
+  GEN_OFFS(MemRegion, _word_size);
+  GEN_SIZE(HeapWord);
+  printf("\n");
+
+  GEN_OFFS(VMStructEntry, typeName);
+  GEN_OFFS(VMStructEntry, fieldName);
+  GEN_OFFS(VMStructEntry, address);
+  GEN_SIZE(VMStructEntry);
+  printf("\n");
+
+  GEN_VALUE(MAX_METHOD_CODE_SIZE, max_method_code_size);
+#if defined(sparc) || defined(__sparc)
+  GEN_VALUE(OFFSET_interpreter_frame_method, 2 * pointer_size);     /* L2 in saved window */
+  GEN_VALUE(OFFSET_interpreter_frame_sender_sp, 13 * pointer_size); /* I5 in saved window */
+  // Fake value for consistency. It is not going to be used.
+  GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, 0xFFFF);
+#elif defined(i386) || defined(__i386) || defined(__amd64)
+  GEN_VALUE(OFFSET_interpreter_frame_sender_sp, -1 * pointer_size);
+  GEN_VALUE(OFFSET_interpreter_frame_method, -3 * pointer_size);
+  GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, -7 * pointer_size);
+#endif
+
+  GEN_OFFS(Klass, _name);
+  GEN_OFFS(constantPoolOopDesc, _pool_holder);
+  printf("\n");
+
+  GEN_VALUE(OFFSET_HeapBlockHeader_used, (int) offset_of(HeapBlock::Header, _used));
+  GEN_OFFS(oopDesc, _metadata);
+  printf("\n");
+
+  GEN_VALUE(AccessFlags_NATIVE, JVM_ACC_NATIVE);
+  GEN_VALUE(constMethodOopDesc_has_linenumber_table, constMethodOopDesc::_has_linenumber_table);
+  GEN_OFFS(AccessFlags, _flags);
+  GEN_OFFS(Symbol, _length);
+  GEN_OFFS(Symbol, _body);
+  printf("\n");
+
+  GEN_OFFS(methodOopDesc, _constMethod);
+  GEN_OFFS(methodOopDesc, _constants);
+  GEN_OFFS(methodOopDesc, _access_flags);
+  printf("\n");
+
+  GEN_OFFS(constMethodOopDesc, _flags);
+  GEN_OFFS(constMethodOopDesc, _code_size);
+  GEN_OFFS(constMethodOopDesc, _name_index);
+  GEN_OFFS(constMethodOopDesc, _signature_index);
+  printf("\n");
+
+  GEN_OFFS(CodeHeap, _memory);
+  GEN_OFFS(CodeHeap, _segmap);
+  GEN_OFFS(CodeHeap, _log2_segment_size);
+  printf("\n");
+
+  GEN_OFFS(VirtualSpace, _low_boundary);
+  GEN_OFFS(VirtualSpace, _high_boundary);
+  GEN_OFFS(VirtualSpace, _low);
+  GEN_OFFS(VirtualSpace, _high);
+  printf("\n");
+
+  GEN_OFFS(CodeBlob, _name);
+  GEN_OFFS(CodeBlob, _header_size);
+  GEN_OFFS(CodeBlob, _content_offset);
+  GEN_OFFS(CodeBlob, _code_offset);
+  GEN_OFFS(CodeBlob, _data_offset);
+  GEN_OFFS(CodeBlob, _frame_size);
+  printf("\n");
+
+  GEN_OFFS(nmethod, _method);
+  GEN_OFFS(nmethod, _oops_offset);
+  GEN_OFFS(nmethod, _scopes_data_offset);
+  GEN_OFFS(nmethod, _scopes_pcs_offset);
+  GEN_OFFS(nmethod, _handler_table_offset);
+  GEN_OFFS(nmethod, _deoptimize_offset);
+  GEN_OFFS(nmethod, _orig_pc_offset);
+
+  GEN_OFFS(PcDesc, _pc_offset);
+  GEN_OFFS(PcDesc, _scope_decode_offset);
+
+  printf("\n");
+
+  GEN_OFFS(NarrowOopStruct, _base);
+  GEN_OFFS(NarrowOopStruct, _shift);
+  printf("\n");
+
+  GEN_VALUE(SIZE_HeapBlockHeader, (int) sizeof(HeapBlock::Header));
+  GEN_SIZE(oopDesc);
+  GEN_SIZE(constantPoolOopDesc);
+  printf("\n");
+
+  GEN_SIZE(PcDesc);
+  GEN_SIZE(methodOopDesc);
+  GEN_SIZE(constMethodOopDesc);
+  GEN_SIZE(nmethod);
+  GEN_SIZE(CodeBlob);
+  GEN_SIZE(BufferBlob);
+  GEN_SIZE(SingletonBlob);
+  GEN_SIZE(RuntimeStub);
+  GEN_SIZE(SafepointBlob);
+
+  gen_epilogue(gen_variant);
+  printf("\n");
+
+  fflush(stdout);
+  return 0;
+}
diff --git a/hotspot/src/os/bsd/dtrace/generateJvmOffsets.h b/hotspot/src/os/bsd/dtrace/generateJvmOffsets.h
new file mode 100644
index 0000000..99146f1
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/generateJvmOffsets.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_SOLARIS_DTRACE_GENERATEJVMOFFSETS_H
+#define OS_SOLARIS_DTRACE_GENERATEJVMOFFSETS_H
+
+#include <stdio.h>
+#include <strings.h>
+
+typedef enum GEN_variant {
+        GEN_OFFSET = 0,
+        GEN_INDEX  = 1,
+        GEN_TABLE  = 2
+} GEN_variant;
+
+extern "C" {
+        int generateJvmOffsets(GEN_variant gen_var);
+        void gen_prologue(GEN_variant gen_var);
+        void gen_epilogue(GEN_variant gen_var);
+}
+
+#endif // OS_SOLARIS_DTRACE_GENERATEJVMOFFSETS_H
diff --git a/hotspot/src/os/bsd/dtrace/generateJvmOffsetsMain.c b/hotspot/src/os/bsd/dtrace/generateJvmOffsetsMain.c
new file mode 100644
index 0000000..4cd8ebf
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/generateJvmOffsetsMain.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+
+#include "generateJvmOffsets.h"
+
+const char *HELP =
+    "HELP: generateJvmOffsets {-header | -index | -table} \n";
+
+int main(int argc, const char *argv[]) {
+    GEN_variant gen_var;
+
+    if (argc != 2) {
+        printf("%s", HELP);
+        return 1;
+    }
+
+    if (0 == strcmp(argv[1], "-header")) {
+        gen_var = GEN_OFFSET;
+    }
+    else if (0 == strcmp(argv[1], "-index")) {
+        gen_var = GEN_INDEX;
+    }
+    else if (0 == strcmp(argv[1], "-table")) {
+        gen_var = GEN_TABLE;
+    }
+    else {
+        printf("%s", HELP);
+        return 1;
+    }
+    return generateJvmOffsets(gen_var);
+}
diff --git a/hotspot/src/os/bsd/dtrace/hotspot.d b/hotspot/src/os/bsd/dtrace/hotspot.d
new file mode 100644
index 0000000..0e4802b
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/hotspot.d
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *  
+ */
+
+provider hotspot {
+  probe class__loaded(char*, uintptr_t, void*, uintptr_t);
+  probe class__unloaded(char*, uintptr_t, void*, uintptr_t);
+  probe class__initialization__required(char*, uintptr_t, void*, intptr_t);
+  probe class__initialization__recursive(char*, uintptr_t, void*, intptr_t,int);
+  probe class__initialization__concurrent(char*, uintptr_t, void*, intptr_t,int);
+  probe class__initialization__erroneous(char*, uintptr_t, void*, intptr_t, int);
+  probe class__initialization__super__failed(char*, uintptr_t, void*, intptr_t,int);
+  probe class__initialization__clinit(char*, uintptr_t, void*, intptr_t,int);
+  probe class__initialization__error(char*, uintptr_t, void*, intptr_t,int);
+  probe class__initialization__end(char*, uintptr_t, void*, intptr_t,int);
+  probe vm__init__begin();
+  probe vm__init__end();
+  probe vm__shutdown();
+  probe vmops__request(char*, uintptr_t, int);
+  probe vmops__begin(char*, uintptr_t, int);
+  probe vmops__end(char*, uintptr_t, int);
+  probe gc__begin(uintptr_t);
+  probe gc__end();
+  probe mem__pool__gc__begin(
+    char*, uintptr_t, char*, uintptr_t, 
+    uintptr_t, uintptr_t, uintptr_t, uintptr_t);
+  probe mem__pool__gc__end(
+    char*, uintptr_t, char*, uintptr_t, 
+    uintptr_t, uintptr_t, uintptr_t, uintptr_t);
+  probe thread__probe__start(char*, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
+  probe thread__probe__stop(char*, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
+  probe thread__sleep__begin(long long);
+  probe thread__sleep__end(int);
+  probe thread__yield();
+  probe thread__park__begin(uintptr_t, int, long long);
+  probe thread__park__end(uintptr_t);
+  probe thread__unpark(uintptr_t);
+  probe method__compile__begin(
+    const char*, uintptr_t, const char*, uintptr_t, const char*, uintptr_t, const char*, uintptr_t); 
+  probe method__compile__end(
+    char*, uintptr_t, char*, uintptr_t, char*, uintptr_t, 
+    char*, uintptr_t, uintptr_t); 
+  probe compiled__method__load(
+    char*, uintptr_t, char*, uintptr_t, char*, uintptr_t, void*, uintptr_t);
+  probe compiled__method__unload(
+    char*, uintptr_t, char*, uintptr_t, char*, uintptr_t); 
+  probe monitor__contended__enter(uintptr_t, uintptr_t, char*, uintptr_t);
+  probe monitor__contended__entered(uintptr_t, uintptr_t, char*, uintptr_t);
+  probe monitor__contended__exit(uintptr_t, uintptr_t, char*, uintptr_t);
+  probe monitor__wait(uintptr_t, uintptr_t, char*, uintptr_t, uintptr_t);
+  probe monitor__probe__waited(uintptr_t, uintptr_t, char*, uintptr_t);
+  probe monitor__notify(uintptr_t, uintptr_t, char*, uintptr_t);
+  probe monitor__notifyAll(uintptr_t, uintptr_t, char*, uintptr_t);
+
+  probe object__alloc(int, char*, uintptr_t, uintptr_t);
+  probe method__entry(
+    int, char*, int, char*, int, char*, int);
+  probe method__return(
+    int, char*, int, char*, int, char*, int);
+};
+
+#pragma D attributes Evolving/Evolving/Common provider hotspot provider
+#pragma D attributes Private/Private/Unknown provider hotspot module
+#pragma D attributes Private/Private/Unknown provider hotspot function
+#pragma D attributes Evolving/Evolving/Common provider hotspot name
+#pragma D attributes Evolving/Evolving/Common provider hotspot args
diff --git a/hotspot/src/os/bsd/dtrace/hotspot_jni.d b/hotspot/src/os/bsd/dtrace/hotspot_jni.d
new file mode 100644
index 0000000..cca1c51
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/hotspot_jni.d
@@ -0,0 +1,506 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *  
+ */
+
+provider hotspot_jni {
+  probe AllocObject__entry(void*, void*);
+  probe AllocObject__return(void*);
+  probe AttachCurrentThreadAsDaemon__entry(void*, void**, void*);
+  probe AttachCurrentThreadAsDaemon__return(uint32_t);
+  probe AttachCurrentThread__entry(void*, void**, void*);
+  probe AttachCurrentThread__return(uint32_t);
+  probe CallBooleanMethodA__entry(void*, void*, uintptr_t);
+  probe CallBooleanMethodA__return(uintptr_t);
+  probe CallBooleanMethod__entry(void*, void*, uintptr_t);
+  probe CallBooleanMethod__return(uintptr_t);
+  probe CallBooleanMethodV__entry(void*, void*, uintptr_t);
+  probe CallBooleanMethodV__return(uintptr_t);
+  probe CallByteMethodA__entry(void*, void*, uintptr_t);
+  probe CallByteMethodA__return(char);
+  probe CallByteMethod__entry(void*, void*, uintptr_t);
+  probe CallByteMethod__return(char);
+  probe CallByteMethodV__entry(void*, void*, uintptr_t);
+  probe CallByteMethodV__return(char);
+  probe CallCharMethodA__entry(void*, void*, uintptr_t);
+  probe CallCharMethodA__return(uint16_t);
+  probe CallCharMethod__entry(void*, void*, uintptr_t);
+  probe CallCharMethod__return(uint16_t);
+  probe CallCharMethodV__entry(void*, void*, uintptr_t);
+  probe CallCharMethodV__return(uint16_t);
+  probe CallDoubleMethodA__entry(void*, void*, uintptr_t);
+  probe CallDoubleMethodA__return();
+  probe CallDoubleMethod__entry(void*, void*, uintptr_t);
+  probe CallDoubleMethod__return();
+  probe CallDoubleMethodV__entry(void*, void*, uintptr_t);
+  probe CallDoubleMethodV__return();
+  probe CallFloatMethodA__entry(void*, void*, uintptr_t);
+  probe CallFloatMethodA__return();
+  probe CallFloatMethod__entry(void*, void*, uintptr_t);
+  probe CallFloatMethod__return();
+  probe CallFloatMethodV__entry(void*, void*, uintptr_t);
+  probe CallFloatMethodV__return();
+  probe CallIntMethodA__entry(void*, void*, uintptr_t);
+  probe CallIntMethodA__return(uint32_t);
+  probe CallIntMethod__entry(void*, void*, uintptr_t);
+  probe CallIntMethod__return(uint32_t);
+  probe CallIntMethodV__entry(void*, void*, uintptr_t);
+  probe CallIntMethodV__return(uint32_t);
+  probe CallLongMethodA__entry(void*, void*, uintptr_t);
+  probe CallLongMethodA__return(uintptr_t);
+  probe CallLongMethod__entry(void*, void*, uintptr_t);
+  probe CallLongMethod__return(uintptr_t);
+  probe CallLongMethodV__entry(void*, void*, uintptr_t);
+  probe CallLongMethodV__return(uintptr_t);
+  probe CallNonvirtualBooleanMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualBooleanMethodA__return(uintptr_t);
+  probe CallNonvirtualBooleanMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualBooleanMethod__return(uintptr_t);
+  probe CallNonvirtualBooleanMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualBooleanMethodV__return(uintptr_t);
+  probe CallNonvirtualByteMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualByteMethodA__return(char);
+  probe CallNonvirtualByteMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualByteMethod__return(char);
+  probe CallNonvirtualByteMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualByteMethodV__return(char);
+  probe CallNonvirtualCharMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualCharMethodA__return(uint16_t);
+  probe CallNonvirtualCharMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualCharMethod__return(uint16_t);
+  probe CallNonvirtualCharMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualCharMethodV__return(uint16_t);
+  probe CallNonvirtualDoubleMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualDoubleMethodA__return();
+  probe CallNonvirtualDoubleMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualDoubleMethod__return();
+  probe CallNonvirtualDoubleMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualDoubleMethodV__return();
+  probe CallNonvirtualFloatMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualFloatMethodA__return();
+  probe CallNonvirtualFloatMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualFloatMethod__return();
+  probe CallNonvirtualFloatMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualFloatMethodV__return();
+  probe CallNonvirtualIntMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualIntMethodA__return(uint32_t);
+  probe CallNonvirtualIntMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualIntMethod__return(uint32_t);
+  probe CallNonvirtualIntMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualIntMethodV__return(uint32_t);
+  probe CallNonvirtualLongMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualLongMethodA__return(uintptr_t);
+  probe CallNonvirtualLongMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualLongMethod__return(uintptr_t);
+  probe CallNonvirtualLongMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualLongMethodV__return(uintptr_t);
+  probe CallNonvirtualObjectMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualObjectMethodA__return(void*);
+  probe CallNonvirtualObjectMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualObjectMethod__return(void*);
+  probe CallNonvirtualObjectMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualObjectMethodV__return(void*);
+  probe CallNonvirtualShortMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualShortMethodA__return(uint16_t);
+  probe CallNonvirtualShortMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualShortMethod__return(uint16_t);
+  probe CallNonvirtualShortMethodV__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualShortMethodV__return(uint16_t);
+  probe CallNonvirtualVoidMethodA__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualVoidMethodA__return();
+  probe CallNonvirtualVoidMethod__entry(void*, void*, void*, uintptr_t);
+  probe CallNonvirtualVoidMethod__return();
+  probe CallNonvirtualVoidMethodV__entry(void*, void*, void*, uintptr_t);  
+  probe CallNonvirtualVoidMethodV__return();
+  probe CallObjectMethodA__entry(void*, void*, uintptr_t);
+  probe CallObjectMethodA__return(void*);
+  probe CallObjectMethod__entry(void*, void*, uintptr_t);
+  probe CallObjectMethod__return(void*);
+  probe CallObjectMethodV__entry(void*, void*, uintptr_t);
+  probe CallObjectMethodV__return(void*);
+  probe CallShortMethodA__entry(void*, void*, uintptr_t);
+  probe CallShortMethodA__return(uint16_t);
+  probe CallShortMethod__entry(void*, void*, uintptr_t);
+  probe CallShortMethod__return(uint16_t);
+  probe CallShortMethodV__entry(void*, void*, uintptr_t);
+  probe CallShortMethodV__return(uint16_t);
+  probe CallStaticBooleanMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticBooleanMethodA__return(uintptr_t);
+  probe CallStaticBooleanMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticBooleanMethod__return(uintptr_t);
+  probe CallStaticBooleanMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticBooleanMethodV__return(uintptr_t);
+  probe CallStaticByteMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticByteMethodA__return(char);
+  probe CallStaticByteMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticByteMethod__return(char);
+  probe CallStaticByteMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticByteMethodV__return(char);
+  probe CallStaticCharMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticCharMethodA__return(uint16_t);
+  probe CallStaticCharMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticCharMethod__return(uint16_t);
+  probe CallStaticCharMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticCharMethodV__return(uint16_t);
+  probe CallStaticDoubleMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticDoubleMethodA__return();
+  probe CallStaticDoubleMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticDoubleMethod__return();
+  probe CallStaticDoubleMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticDoubleMethodV__return();
+  probe CallStaticFloatMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticFloatMethodA__return();
+  probe CallStaticFloatMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticFloatMethod__return();
+  probe CallStaticFloatMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticFloatMethodV__return();
+  probe CallStaticIntMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticIntMethodA__return(uint32_t);
+  probe CallStaticIntMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticIntMethod__return(uint32_t);
+  probe CallStaticIntMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticIntMethodV__return(uint32_t);
+  probe CallStaticLongMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticLongMethodA__return(uintptr_t);
+  probe CallStaticLongMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticLongMethod__return(uintptr_t);
+  probe CallStaticLongMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticLongMethodV__return(uintptr_t);
+  probe CallStaticObjectMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticObjectMethodA__return(void*);
+  probe CallStaticObjectMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticObjectMethod__return(void*);
+  probe CallStaticObjectMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticObjectMethodV__return(void*);
+  probe CallStaticShortMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticShortMethodA__return(uint16_t);
+  probe CallStaticShortMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticShortMethod__return(uint16_t);
+  probe CallStaticShortMethodV__entry(void*, void*, uintptr_t);
+  probe CallStaticShortMethodV__return(uint16_t);
+  probe CallStaticVoidMethodA__entry(void*, void*, uintptr_t);
+  probe CallStaticVoidMethodA__return();
+  probe CallStaticVoidMethod__entry(void*, void*, uintptr_t);
+  probe CallStaticVoidMethod__return(); 
+  probe CallStaticVoidMethodV__entry(void*, void*, uintptr_t);  
+  probe CallStaticVoidMethodV__return();
+  probe CallVoidMethodA__entry(void*, void*, uintptr_t);  
+  probe CallVoidMethodA__return();
+  probe CallVoidMethod__entry(void*, void*, uintptr_t);  
+  probe CallVoidMethod__return(); 
+  probe CallVoidMethodV__entry(void*, void*, uintptr_t);  
+  probe CallVoidMethodV__return();
+  probe CreateJavaVM__entry(void**, void**, void*);
+  probe CreateJavaVM__return(uint32_t);
+  probe DefineClass__entry(void*, const char*, void*, char*, uintptr_t);
+  probe DefineClass__return(void*);
+  probe DeleteGlobalRef__entry(void*, void*);
+  probe DeleteGlobalRef__return();
+  probe DeleteLocalRef__entry(void*, void*);
+  probe DeleteLocalRef__return();
+  probe DeleteWeakGlobalRef__entry(void*, void*);
+  probe DeleteWeakGlobalRef__return();
+  probe DestroyJavaVM__entry(void*);
+  probe DestroyJavaVM__return(uint32_t);
+  probe DetachCurrentThread__entry(void*);
+  probe DetachCurrentThread__return(uint32_t);
+  probe EnsureLocalCapacity__entry(void*, uint32_t);
+  probe EnsureLocalCapacity__return(uint32_t);
+  probe ExceptionCheck__entry(void*);
+  probe ExceptionCheck__return(uintptr_t);
+  probe ExceptionClear__entry(void*);
+  probe ExceptionClear__return();
+  probe ExceptionDescribe__entry(void*);  
+  probe ExceptionDescribe__return();
+  probe ExceptionOccurred__entry(void*);
+  probe ExceptionOccurred__return(void*);
+  probe FatalError__entry(void* env, const char*);
+  probe FindClass__entry(void*, const char*);
+  probe FindClass__return(void*);
+  probe FromReflectedField__entry(void*, void*);
+  probe FromReflectedField__return(uintptr_t);
+  probe FromReflectedMethod__entry(void*, void*);
+  probe FromReflectedMethod__return(uintptr_t);
+  probe GetArrayLength__entry(void*, void*);
+  probe GetArrayLength__return(uintptr_t);
+  probe GetBooleanArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetBooleanArrayElements__return(uintptr_t*);
+  probe GetBooleanArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, uintptr_t*);
+  probe GetBooleanArrayRegion__return();
+  probe GetBooleanField__entry(void*, void*, uintptr_t);
+  probe GetBooleanField__return(uintptr_t);
+  probe GetByteArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetByteArrayElements__return(char*);
+  probe GetByteArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, char*);
+  probe GetByteArrayRegion__return();
+  probe GetByteField__entry(void*, void*, uintptr_t);
+  probe GetByteField__return(char);
+  probe GetCharArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetCharArrayElements__return(uint16_t*);
+  probe GetCharArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, uint16_t*);
+  probe GetCharArrayRegion__return();
+  probe GetCharField__entry(void*, void*, uintptr_t);
+  probe GetCharField__return(uint16_t);
+  probe GetCreatedJavaVMs__entry(void**, uintptr_t, uintptr_t*);
+  probe GetCreatedJavaVMs__return(uintptr_t);
+  probe GetDefaultJavaVMInitArgs__entry(void*);
+  probe GetDefaultJavaVMInitArgs__return(uint32_t);
+  probe GetDirectBufferAddress__entry(void*, void*);
+  probe GetDirectBufferAddress__return(void*);
+  probe GetDirectBufferCapacity__entry(void*, void*);
+  probe GetDirectBufferCapacity__return(uintptr_t);
+  probe GetDoubleArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetDoubleArrayElements__return(double*);
+  probe GetDoubleArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, double*);
+  probe GetDoubleArrayRegion__return();
+  probe GetDoubleField__entry(void*, void*, uintptr_t);
+  probe GetDoubleField__return();
+  probe GetEnv__entry(void*, void*, uint32_t);
+  probe GetEnv__return(uint32_t);
+  probe GetFieldID__entry(void*, void*, const char*, const char*);
+  probe GetFieldID__return(uintptr_t);
+  probe GetFloatArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetFloatArrayElements__return(float*);
+  probe GetFloatArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, float*);
+  probe GetFloatArrayRegion__return();
+  probe GetFloatField__entry(void*, void*, uintptr_t);
+  probe GetFloatField__return();
+  probe GetIntArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetIntArrayElements__return(uint32_t*);
+  probe GetIntArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, uint32_t*);
+  probe GetIntArrayRegion__return();
+  probe GetIntField__entry(void*, void*, uintptr_t);
+  probe GetIntField__return(uint32_t);
+  probe GetJavaVM__entry(void*, void**);
+  probe GetJavaVM__return(uint32_t);
+  probe GetLongArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetLongArrayElements__return(uintptr_t*);
+  probe GetLongArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, uintptr_t*);
+  probe GetLongArrayRegion__return();
+  probe GetLongField__entry(void*, void*, uintptr_t);
+  probe GetLongField__return(uintptr_t);
+  probe GetMethodID__entry(void*, void*, const char*, const char*);
+  probe GetMethodID__return(uintptr_t);
+  probe GetObjectArrayElement__entry(void*, void*, uintptr_t);
+  probe GetObjectArrayElement__return(void*);
+  probe GetObjectClass__entry(void*, void*);
+  probe GetObjectClass__return(void*);
+  probe GetObjectField__entry(void*, void*, uintptr_t);
+  probe GetObjectField__return(void*);
+  probe GetObjectRefType__entry(void*, void*);
+  probe GetObjectRefType__return(void*);
+  probe GetPrimitiveArrayCritical__entry(void*, void*, uintptr_t*);
+  probe GetPrimitiveArrayCritical__return(void*);
+  probe GetShortArrayElements__entry(void*, void*, uintptr_t*);
+  probe GetShortArrayElements__return(uint16_t*);
+  probe GetShortArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, uint16_t*);
+  probe GetShortArrayRegion__return();
+  probe GetShortField__entry(void*, void*, uintptr_t);
+  probe GetShortField__return(uint16_t);
+  probe GetStaticBooleanField__entry(void*, void*, uintptr_t);
+  probe GetStaticBooleanField__return(uintptr_t);
+  probe GetStaticByteField__entry(void*, void*, uintptr_t);
+  probe GetStaticByteField__return(char);
+  probe GetStaticCharField__entry(void*, void*, uintptr_t);
+  probe GetStaticCharField__return(uint16_t);
+  probe GetStaticDoubleField__entry(void*, void*, uintptr_t);
+  probe GetStaticDoubleField__return();
+  probe GetStaticFieldID__entry(void*, void*, const char*, const char*);
+  probe GetStaticFieldID__return(uintptr_t);
+  probe GetStaticFloatField__entry(void*, void*, uintptr_t);
+  probe GetStaticFloatField__return();
+  probe GetStaticIntField__entry(void*, void*, uintptr_t);
+  probe GetStaticIntField__return(uint32_t);
+  probe GetStaticLongField__entry(void*, void*, uintptr_t);
+  probe GetStaticLongField__return(uintptr_t);
+  probe GetStaticMethodID__entry(void*, void*, const char*, const char*);
+  probe GetStaticMethodID__return(uintptr_t);
+  probe GetStaticObjectField__entry(void*, void*, uintptr_t);
+  probe GetStaticObjectField__return(void*);
+  probe GetStaticShortField__entry(void*, void*, uintptr_t);
+  probe GetStaticShortField__return(uint16_t);
+  probe GetStringChars__entry(void*, void*, uintptr_t*);
+  probe GetStringChars__return(const uint16_t*);
+  probe GetStringCritical__entry(void*, void*, uintptr_t*);
+  probe GetStringCritical__return(const uint16_t*);
+  probe GetStringLength__entry(void*, void*);
+  probe GetStringLength__return(uintptr_t);
+  probe GetStringRegion__entry(void*, void*, uintptr_t, uintptr_t, uint16_t*);
+  probe GetStringRegion__return();
+  probe GetStringUTFChars__entry(void*, void*, uintptr_t*);
+  probe GetStringUTFChars__return(const char*);
+  probe GetStringUTFLength__entry(void*, void*);
+  probe GetStringUTFLength__return(uintptr_t);
+  probe GetStringUTFRegion__entry(void*, void*, uintptr_t, uintptr_t, char*);
+  probe GetStringUTFRegion__return();
+  probe GetSuperclass__entry(void*, void*);
+  probe GetSuperclass__return(void*);
+  probe GetVersion__entry(void*);
+  probe GetVersion__return(uint32_t);
+  probe IsAssignableFrom__entry(void*, void*, void*);
+  probe IsAssignableFrom__return(uintptr_t);
+  probe IsInstanceOf__entry(void*, void*, void*);
+  probe IsInstanceOf__return(uintptr_t);
+  probe IsSameObject__entry(void*, void*, void*);
+  probe IsSameObject__return(uintptr_t);
+  probe MonitorEnter__entry(void*, void*);
+  probe MonitorEnter__return(uint32_t);
+  probe MonitorExit__entry(void*, void*);
+  probe MonitorExit__return(uint32_t);
+  probe NewBooleanArray__entry(void*, uintptr_t);
+  probe NewBooleanArray__return(void*);
+  probe NewByteArray__entry(void*, uintptr_t);
+  probe NewByteArray__return(void*);
+  probe NewCharArray__entry(void*, uintptr_t);
+  probe NewCharArray__return(void*);
+  probe NewDirectByteBuffer__entry(void*, void*, uintptr_t);
+  probe NewDirectByteBuffer__return(void*);
+  probe NewDoubleArray__entry(void*, uintptr_t);
+  probe NewDoubleArray__return(void*);
+  probe NewFloatArray__entry(void*, uintptr_t);
+  probe NewFloatArray__return(void*);
+  probe NewGlobalRef__entry(void*, void*);
+  probe NewGlobalRef__return(void*);
+  probe NewIntArray__entry(void*, uintptr_t);
+  probe NewIntArray__return(void*);
+  probe NewLocalRef__entry(void*, void*);
+  probe NewLocalRef__return(void*);
+  probe NewLongArray__entry(void*, uintptr_t);
+  probe NewLongArray__return(void*);
+  probe NewObjectA__entry(void*, void*, uintptr_t);  
+  probe NewObjectA__return(void*);
+  probe NewObjectArray__entry(void*, uintptr_t, void*, void*);
+  probe NewObjectArray__return(void*);
+  probe NewObject__entry(void*, void*, uintptr_t); 
+  probe NewObject__return(void*);
+  probe NewObjectV__entry(void*, void*, uintptr_t);  
+  probe NewObjectV__return(void*);
+  probe NewShortArray__entry(void*, uintptr_t);
+  probe NewShortArray__return(void*);
+  probe NewString__entry(void*, const uint16_t*, uintptr_t);
+  probe NewString__return(void*);
+  probe NewStringUTF__entry(void*, const char*);
+  probe NewStringUTF__return(void*);
+  probe NewWeakGlobalRef__entry(void*, void*);
+  probe NewWeakGlobalRef__return(void*);
+  probe PopLocalFrame__entry(void*, void*);
+  probe PopLocalFrame__return(void*);
+  probe PushLocalFrame__entry(void*, uint32_t);
+  probe PushLocalFrame__return(uint32_t);
+  probe RegisterNatives__entry(void*, void*, const void*, uint32_t);  
+  probe RegisterNatives__return(uint32_t);
+  probe ReleaseBooleanArrayElements__entry(void*, void*, uintptr_t*, uint32_t);
+  probe ReleaseBooleanArrayElements__return();
+  probe ReleaseByteArrayElements__entry(void*, void*, char*, uint32_t);
+  probe ReleaseByteArrayElements__return();
+  probe ReleaseCharArrayElements__entry(void*, void*, uint16_t*, uint32_t);
+  probe ReleaseCharArrayElements__return();
+  probe ReleaseDoubleArrayElements__entry(void*, void*, double*, uint32_t);
+  probe ReleaseDoubleArrayElements__return();
+  probe ReleaseFloatArrayElements__entry(void*, void*, float*, uint32_t);
+  probe ReleaseFloatArrayElements__return();
+  probe ReleaseIntArrayElements__entry(void*, void*, uint32_t*, uint32_t);
+  probe ReleaseIntArrayElements__return();
+  probe ReleaseLongArrayElements__entry(void*, void*, uintptr_t*, uint32_t);
+  probe ReleaseLongArrayElements__return();
+  probe ReleasePrimitiveArrayCritical__entry(void*, void*, void*, uint32_t);
+  probe ReleasePrimitiveArrayCritical__return();
+  probe ReleaseShortArrayElements__entry(void*, void*, uint16_t*, uint32_t);
+  probe ReleaseShortArrayElements__return();
+  probe ReleaseStringChars__entry(void*, void*, const uint16_t*);
+  probe ReleaseStringChars__return();
+  probe ReleaseStringCritical__entry(void*, void*, const uint16_t*);
+  probe ReleaseStringCritical__return();
+  probe ReleaseStringUTFChars__entry(void*, void*, const char*);
+  probe ReleaseStringUTFChars__return();
+  probe SetBooleanArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const uintptr_t*);
+  probe SetBooleanArrayRegion__return();
+  probe SetBooleanField__entry(void*, void*, uintptr_t, uintptr_t);
+  probe SetBooleanField__return();
+  probe SetByteArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const char*);
+  probe SetByteArrayRegion__return();
+  probe SetByteField__entry(void*, void*, uintptr_t, char);
+  probe SetByteField__return();
+  probe SetCharArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const uint16_t*);
+  probe SetCharArrayRegion__return();
+  probe SetCharField__entry(void*, void*, uintptr_t, uint16_t);
+  probe SetCharField__return();
+  probe SetDoubleArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const double*);
+  probe SetDoubleArrayRegion__return();
+  probe SetDoubleField__entry(void*, void*, uintptr_t);
+  probe SetDoubleField__return();
+  probe SetFloatArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const float*);
+  probe SetFloatArrayRegion__return();
+  probe SetFloatField__entry(void*, void*, uintptr_t);
+  probe SetFloatField__return();
+  probe SetIntArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const uint32_t*);
+  probe SetIntArrayRegion__return();
+  probe SetIntField__entry(void*, void*, uintptr_t, uint32_t);
+  probe SetIntField__return();
+  probe SetLongArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const uintptr_t*);
+  probe SetLongArrayRegion__return();
+  probe SetLongField__entry(void*, void*, uintptr_t, uintptr_t);
+  probe SetLongField__return();
+  probe SetObjectArrayElement__entry(void*, void*, uintptr_t, void*);
+  probe SetObjectArrayElement__return();
+  probe SetObjectField__entry(void*, void*, uintptr_t, void*);
+  probe SetObjectField__return();
+  probe SetShortArrayRegion__entry(void*, void*, uintptr_t, uintptr_t, const uint16_t*);
+  probe SetShortArrayRegion__return();
+  probe SetShortField__entry(void*, void*, uintptr_t, uint16_t);
+  probe SetShortField__return();
+  probe SetStaticBooleanField__entry(void*, void*, uintptr_t, uintptr_t);
+  probe SetStaticBooleanField__return();
+  probe SetStaticByteField__entry(void*, void*, uintptr_t, char);
+  probe SetStaticByteField__return();
+  probe SetStaticCharField__entry(void*, void*, uintptr_t, uint16_t);
+  probe SetStaticCharField__return();
+  probe SetStaticDoubleField__entry(void*, void*, uintptr_t);
+  probe SetStaticDoubleField__return();
+  probe SetStaticFloatField__entry(void*, void*, uintptr_t);
+  probe SetStaticFloatField__return();
+  probe SetStaticIntField__entry(void*, void*, uintptr_t, uint32_t);
+  probe SetStaticIntField__return();
+  probe SetStaticLongField__entry(void*, void*, uintptr_t, uintptr_t);
+  probe SetStaticLongField__return();
+  probe SetStaticObjectField__entry(void*, void*, uintptr_t, void*);
+  probe SetStaticObjectField__return();
+  probe SetStaticShortField__entry(void*, void*, uintptr_t, uint16_t);
+  probe SetStaticShortField__return();
+  probe Throw__entry(void*, void*);
+  probe Throw__return(intptr_t);
+  probe ThrowNew__entry(void*, void*, const char*);  
+  probe ThrowNew__return(intptr_t);  
+  probe ToReflectedField__entry(void*, void*, uintptr_t, uintptr_t);
+  probe ToReflectedField__return(void*);
+  probe ToReflectedMethod__entry(void*, void*, uintptr_t, uintptr_t);
+  probe ToReflectedMethod__return(void*);
+  probe UnregisterNatives__entry(void*, void*);  
+  probe UnregisterNatives__return(uint32_t);
+};
+
+#pragma D attributes Standard/Standard/Common provider hotspot_jni provider
+#pragma D attributes Private/Private/Unknown provider hotspot_jni module
+#pragma D attributes Private/Private/Unknown provider hotspot_jni function
+#pragma D attributes Standard/Standard/Common provider hotspot_jni name
+#pragma D attributes Evolving/Evolving/Common provider hotspot_jni args
+
diff --git a/hotspot/src/os/bsd/dtrace/hs_private.d b/hotspot/src/os/bsd/dtrace/hs_private.d
new file mode 100644
index 0000000..50f4264
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/hs_private.d
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *  
+ */
+
+provider hs_private {
+  probe hashtable__new_entry(void*, uint32_t, uintptr_t, void*); 
+  probe safepoint__begin();
+  probe safepoint__end();
+  probe cms__initmark__begin();
+  probe cms__initmark__end();
+  probe cms__remark__begin();
+  probe cms__remark__end();
+};
+
+#pragma D attributes Private/Private/Common provider hs_private provider
+#pragma D attributes Private/Private/Unknown provider hs_private module
+#pragma D attributes Private/Private/Unknown provider hs_private function
+#pragma D attributes Private/Private/Common provider hs_private name
+#pragma D attributes Private/Private/Common provider hs_private args
+
diff --git a/hotspot/src/os/bsd/dtrace/jhelper.d b/hotspot/src/os/bsd/dtrace/jhelper.d
new file mode 100644
index 0000000..75e7426
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/jhelper.d
@@ -0,0 +1,447 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *  
+ */
+
+/* This file is auto-generated */
+#include "JvmOffsetsIndex.h"
+
+#define DEBUG
+
+#ifdef DEBUG
+#define MARK_LINE this->line = __LINE__
+#else
+#define MARK_LINE 
+#endif
+
+#ifdef _LP64
+#define STACK_BIAS 0x7ff
+#define pointer uint64_t
+#else
+#define STACK_BIAS 0
+#define pointer uint32_t
+#endif
+
+extern pointer __JvmOffsets;
+
+extern pointer __1cJCodeCacheF_heap_;
+extern pointer __1cIUniverseP_methodKlassObj_;
+extern pointer __1cIUniverseO_collectedHeap_;
+extern pointer __1cIUniverseL_narrow_oop_;
+#ifdef _LP64
+extern pointer UseCompressedOops;
+#endif
+
+extern pointer __1cHnmethodG__vtbl_;
+extern pointer __1cKBufferBlobG__vtbl_;
+
+#define copyin_ptr(ADDR)    *(pointer*)  copyin((pointer) (ADDR), sizeof(pointer))
+#define copyin_uchar(ADDR)  *(uchar_t*)  copyin((pointer) (ADDR), sizeof(uchar_t))
+#define copyin_uint16(ADDR) *(uint16_t*) copyin((pointer) (ADDR), sizeof(uint16_t))
+#define copyin_uint32(ADDR) *(uint32_t*) copyin((pointer) (ADDR), sizeof(uint32_t))
+#define copyin_int32(ADDR)  *(int32_t*)  copyin((pointer) (ADDR), sizeof(int32_t))
+#define copyin_uint8(ADDR)  *(uint8_t*)  copyin((pointer) (ADDR), sizeof(uint8_t))
+
+#define SAME(x) x
+#define copyin_offset(JVM_CONST)  JVM_CONST = \
+	copyin_int32(JvmOffsetsPtr + SAME(IDX_)JVM_CONST * sizeof(int32_t))
+
+int init_done;
+
+dtrace:helper:ustack:
+{
+  MARK_LINE;
+  this->done = 0;
+  /*
+   * TBD:
+   * Here we initialize init_done, otherwise jhelper does not work.
+   * Therefore, copyin_offset() statements work multiple times now.
+   * There is a hope we could avoid it in the future, and so,
+   * this initialization can be removed.
+   */
+  init_done  = 0;
+  this->error = (char *) NULL;
+  this->result = (char *) NULL;
+  this->methodOop = 0;
+  this->codecache = 0;
+  this->klass = (pointer) NULL;
+  this->vtbl  = (pointer) NULL;
+  this->suffix = '\0';
+}
+
+dtrace:helper:ustack:
+{
+  MARK_LINE;
+  /* Initialization of JvmOffsets constants */
+  JvmOffsetsPtr = (pointer) &``__JvmOffsets;
+}
+
+dtrace:helper:ustack:
+/!init_done && !this->done/
+{
+  MARK_LINE;
+  init_done = 1;
+
+  copyin_offset(COMPILER);
+  copyin_offset(OFFSET_CollectedHeap_reserved);
+  copyin_offset(OFFSET_MemRegion_start);
+  copyin_offset(OFFSET_MemRegion_word_size);
+  copyin_offset(SIZE_HeapWord);
+
+  copyin_offset(OFFSET_interpreter_frame_method);
+  copyin_offset(OFFSET_Klass_name);
+  copyin_offset(OFFSET_constantPoolOopDesc_pool_holder);
+
+  copyin_offset(OFFSET_HeapBlockHeader_used);
+  copyin_offset(OFFSET_oopDesc_metadata);
+
+  copyin_offset(OFFSET_Symbol_length);
+  copyin_offset(OFFSET_Symbol_body);
+
+  copyin_offset(OFFSET_methodOopDesc_constMethod);
+  copyin_offset(OFFSET_methodOopDesc_constants);
+  copyin_offset(OFFSET_constMethodOopDesc_name_index);
+  copyin_offset(OFFSET_constMethodOopDesc_signature_index);
+
+  copyin_offset(OFFSET_CodeHeap_memory);
+  copyin_offset(OFFSET_CodeHeap_segmap);
+  copyin_offset(OFFSET_CodeHeap_log2_segment_size);
+
+  copyin_offset(OFFSET_VirtualSpace_low);
+  copyin_offset(OFFSET_VirtualSpace_high);
+
+  copyin_offset(OFFSET_CodeBlob_name);
+
+  copyin_offset(OFFSET_nmethod_method);
+  copyin_offset(SIZE_HeapBlockHeader);
+  copyin_offset(SIZE_oopDesc);
+  copyin_offset(SIZE_constantPoolOopDesc);
+
+  copyin_offset(OFFSET_NarrowOopStruct_base);
+  copyin_offset(OFFSET_NarrowOopStruct_shift);
+
+  /*
+   * The PC to translate is in arg0.
+   */
+  this->pc = arg0;
+
+  /*
+   * The methodOopPtr is in %l2 on SPARC.  This can be found at
+   * offset 8 from the frame pointer on 32-bit processes.
+   */
+#if   defined(__sparc)
+  this->methodOopPtr = copyin_ptr(arg1 + 2 * sizeof(pointer) + STACK_BIAS);
+#elif defined(__i386) || defined(__amd64)
+  this->methodOopPtr = copyin_ptr(arg1 + OFFSET_interpreter_frame_method);
+#else
+#error "Don't know architecture"
+#endif
+
+  this->Universe_methodKlassOop = copyin_ptr(&``__1cIUniverseP_methodKlassObj_);
+  this->CodeCache_heap_address = copyin_ptr(&``__1cJCodeCacheF_heap_);
+
+  /* Reading volatile values */
+#ifdef _LP64
+  this->Use_Compressed_Oops  = copyin_uint8(&``UseCompressedOops);
+#else
+  this->Use_Compressed_Oops  = 0;
+#endif
+
+  this->Universe_narrow_oop_base  = copyin_ptr(&``__1cIUniverseL_narrow_oop_ +
+                                               OFFSET_NarrowOopStruct_base);
+  this->Universe_narrow_oop_shift = copyin_int32(&``__1cIUniverseL_narrow_oop_ +
+                                                 OFFSET_NarrowOopStruct_shift);
+
+  this->CodeCache_low = copyin_ptr(this->CodeCache_heap_address + 
+      OFFSET_CodeHeap_memory + OFFSET_VirtualSpace_low);
+
+  this->CodeCache_high = copyin_ptr(this->CodeCache_heap_address +
+      OFFSET_CodeHeap_memory + OFFSET_VirtualSpace_high);
+
+  this->CodeCache_segmap_low = copyin_ptr(this->CodeCache_heap_address +
+      OFFSET_CodeHeap_segmap + OFFSET_VirtualSpace_low);
+
+  this->CodeCache_segmap_high = copyin_ptr(this->CodeCache_heap_address +
+      OFFSET_CodeHeap_segmap + OFFSET_VirtualSpace_high);
+
+  this->CodeHeap_log2_segment_size = copyin_uint32(
+      this->CodeCache_heap_address + OFFSET_CodeHeap_log2_segment_size);
+
+  /*
+   * Get Java heap bounds
+   */
+  this->Universe_collectedHeap = copyin_ptr(&``__1cIUniverseO_collectedHeap_);
+  this->heap_start = copyin_ptr(this->Universe_collectedHeap +
+      OFFSET_CollectedHeap_reserved +
+      OFFSET_MemRegion_start);
+  this->heap_size = SIZE_HeapWord *
+    copyin_ptr(this->Universe_collectedHeap +
+        OFFSET_CollectedHeap_reserved +
+        OFFSET_MemRegion_word_size
+        );
+  this->heap_end = this->heap_start + this->heap_size;
+}
+
+dtrace:helper:ustack:
+/!this->done &&
+this->CodeCache_low <= this->pc && this->pc < this->CodeCache_high/
+{
+  MARK_LINE;
+  this->codecache = 1;
+
+  /*
+   * Find start.
+   */
+  this->segment = (this->pc - this->CodeCache_low) >>
+    this->CodeHeap_log2_segment_size;
+  this->block = this->CodeCache_segmap_low;
+  this->tag = copyin_uchar(this->block + this->segment);
+  "second";
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache && this->tag > 0/
+{
+  MARK_LINE;
+  this->tag = copyin_uchar(this->block + this->segment);
+  this->segment = this->segment - this->tag;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache && this->tag > 0/
+{
+  MARK_LINE;
+  this->tag = copyin_uchar(this->block + this->segment);
+  this->segment = this->segment - this->tag;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache && this->tag > 0/
+{
+  MARK_LINE;
+  this->tag = copyin_uchar(this->block + this->segment);
+  this->segment = this->segment - this->tag;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache && this->tag > 0/
+{
+  MARK_LINE;
+  this->tag = copyin_uchar(this->block + this->segment);
+  this->segment = this->segment - this->tag;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache && this->tag > 0/
+{
+  MARK_LINE;
+  this->tag = copyin_uchar(this->block + this->segment);
+  this->segment = this->segment - this->tag;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache && this->tag > 0/
+{
+  MARK_LINE;
+  this->error = "<couldn't find start>";
+  this->done = 1;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache/
+{
+  MARK_LINE;
+  this->block = this->CodeCache_low +
+    (this->segment << this->CodeHeap_log2_segment_size);
+  this->used = copyin_uint32(this->block + OFFSET_HeapBlockHeader_used);
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache && !this->used/
+{
+  MARK_LINE;
+  this->error = "<block not in use>";
+  this->done = 1;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache/
+{
+  MARK_LINE;
+  this->start = this->block + SIZE_HeapBlockHeader;
+  this->vtbl = copyin_ptr(this->start);
+
+  this->nmethod_vtbl            = (pointer) &``__1cHnmethodG__vtbl_;
+  this->BufferBlob_vtbl         = (pointer) &``__1cKBufferBlobG__vtbl_;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->vtbl == this->nmethod_vtbl/
+{
+  MARK_LINE;
+  this->methodOopPtr = copyin_ptr(this->start + OFFSET_nmethod_method);
+  this->suffix = '*';
+  this->methodOop = 1;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->vtbl == this->BufferBlob_vtbl/
+{
+  MARK_LINE;
+  this->name = copyin_ptr(this->start + OFFSET_CodeBlob_name);
+}
+
+dtrace:helper:ustack:
+/!this->done && this->vtbl == this->BufferBlob_vtbl &&
+this->Use_Compressed_Oops == 0 &&
+this->methodOopPtr > this->heap_start && this->methodOopPtr < this->heap_end/
+{
+  MARK_LINE;
+  this->klass = copyin_ptr(this->methodOopPtr + OFFSET_oopDesc_metadata);
+  this->methodOop = this->klass == this->Universe_methodKlassOop;
+  this->done = !this->methodOop;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->vtbl == this->BufferBlob_vtbl &&
+this->Use_Compressed_Oops != 0 &&
+this->methodOopPtr > this->heap_start && this->methodOopPtr < this->heap_end/
+{
+  MARK_LINE;
+  /*
+   * Read compressed pointer and  decode heap oop, same as oop.inline.hpp
+   */
+  this->cklass = copyin_uint32(this->methodOopPtr + OFFSET_oopDesc_metadata);
+  this->klass = (uint64_t)((uintptr_t)this->Universe_narrow_oop_base +
+                ((uintptr_t)this->cklass << this->Universe_narrow_oop_shift));
+  this->methodOop = this->klass == this->Universe_methodKlassOop;
+  this->done = !this->methodOop;
+}
+
+dtrace:helper:ustack:
+/!this->done && !this->methodOop/
+{
+  MARK_LINE;
+  this->name = copyin_ptr(this->start + OFFSET_CodeBlob_name);
+  this->result = this->name != 0 ? copyinstr(this->name) : "<CodeBlob>";
+  this->done = 1;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->methodOop/
+{
+  MARK_LINE;
+  this->constMethod = copyin_ptr(this->methodOopPtr +
+      OFFSET_methodOopDesc_constMethod);
+
+  this->nameIndex = copyin_uint16(this->constMethod +
+      OFFSET_constMethodOopDesc_name_index);
+
+  this->signatureIndex = copyin_uint16(this->constMethod +
+      OFFSET_constMethodOopDesc_signature_index);
+
+  this->constantPool = copyin_ptr(this->methodOopPtr +
+      OFFSET_methodOopDesc_constants);
+
+  this->nameSymbol = copyin_ptr(this->constantPool +
+      this->nameIndex * sizeof (pointer) + SIZE_constantPoolOopDesc);
+
+  this->nameSymbolLength = copyin_uint16(this->nameSymbol +
+      OFFSET_Symbol_length);
+
+  this->signatureSymbol = copyin_ptr(this->constantPool +
+      this->signatureIndex * sizeof (pointer) + SIZE_constantPoolOopDesc);
+
+  this->signatureSymbolLength = copyin_uint16(this->signatureSymbol +
+      OFFSET_Symbol_length);
+
+  this->klassPtr = copyin_ptr(this->constantPool +
+      OFFSET_constantPoolOopDesc_pool_holder);
+
+  this->klassSymbol = copyin_ptr(this->klassPtr +
+      OFFSET_Klass_name + SIZE_oopDesc);
+
+  this->klassSymbolLength = copyin_uint16(this->klassSymbol +
+      OFFSET_Symbol_length);
+
+  /*
+   * Enough for three strings, plus the '.', plus the trailing '\0'.
+   */
+  this->result = (char *) alloca(this->klassSymbolLength +
+      this->nameSymbolLength +
+      this->signatureSymbolLength + 2 + 1);
+
+  copyinto(this->klassSymbol + OFFSET_Symbol_body,
+      this->klassSymbolLength, this->result);
+
+  /*
+   * Add the '.' between the class and the name.
+   */
+  this->result[this->klassSymbolLength] = '.';
+
+  copyinto(this->nameSymbol + OFFSET_Symbol_body,
+      this->nameSymbolLength,
+      this->result + this->klassSymbolLength + 1);
+
+  copyinto(this->signatureSymbol + OFFSET_Symbol_body,
+      this->signatureSymbolLength,
+      this->result + this->klassSymbolLength +
+      this->nameSymbolLength + 1);
+
+  /*
+   * Now we need to add a trailing '\0' and possibly a tag character.
+   */
+  this->result[this->klassSymbolLength + 1 + 
+      this->nameSymbolLength +
+      this->signatureSymbolLength] = this->suffix;
+  this->result[this->klassSymbolLength + 2 + 
+      this->nameSymbolLength +
+      this->signatureSymbolLength] = '\0';
+
+  this->done = 1;
+}
+
+dtrace:helper:ustack:
+/this->done && this->error == (char *) NULL/
+{
+  this->result;   
+}
+
+dtrace:helper:ustack:
+/this->done && this->error != (char *) NULL/
+{
+  this->error;
+}
+
+dtrace:helper:ustack:
+/!this->done && this->codecache/
+{
+  this->done = 1;
+  "error";
+}
+
+
+dtrace:helper:ustack:
+/!this->done/
+{
+  NULL;
+}
diff --git a/hotspot/src/os/bsd/dtrace/jvm_dtrace.c b/hotspot/src/os/bsd/dtrace/jvm_dtrace.c
new file mode 100644
index 0000000..fd0c433
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/jvm_dtrace.c
@@ -0,0 +1,565 @@
+/*
+ * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <door.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <poll.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <thread.h>
+#include <unistd.h>
+#include "jvm_dtrace.h"
+
+// NOTE: These constants are used in JVM code as well.
+// KEEP JVM CODE IN SYNC if you are going to change these...
+
+#define DTRACE_ALLOC_PROBES   0x1
+#define DTRACE_METHOD_PROBES  0x2
+#define DTRACE_MONITOR_PROBES 0x4
+#define DTRACE_ALL_PROBES     -1
+
+// generic error messages
+#define JVM_ERR_OUT_OF_MEMORY            "out of memory (native heap)"
+#define JVM_ERR_INVALID_PARAM            "invalid input parameter(s)"
+#define JVM_ERR_NULL_PARAM               "input paramater is NULL"
+
+// error messages for attach
+#define JVM_ERR_CANT_OPEN_DOOR           "cannot open door file"
+#define JVM_ERR_CANT_CREATE_ATTACH_FILE  "cannot create attach file"
+#define JVM_ERR_DOOR_FILE_PERMISSION     "door file is not secure"
+#define JVM_ERR_CANT_SIGNAL              "cannot send SIGQUIT to target"
+
+// error messages for enable probe
+#define JVM_ERR_DOOR_CMD_SEND            "door command send failed"
+#define JVM_ERR_DOOR_CANT_READ_STATUS    "cannot read door command status"
+#define JVM_ERR_DOOR_CMD_STATUS          "door command error status"
+
+// error message for detach
+#define JVM_ERR_CANT_CLOSE_DOOR          "cannot close door file"
+
+#define RESTARTABLE(_cmd, _result) do { \
+    do { \
+        _result = _cmd; \
+    } while((_result == -1) && (errno == EINTR)); \
+} while(0)
+
+struct _jvm_t {
+    pid_t pid;
+    int door_fd;
+};
+
+static int libjvm_dtrace_debug;
+static void print_debug(const char* fmt,...) {
+    if (libjvm_dtrace_debug) {
+        va_list alist;
+        va_start(alist, fmt);
+        fputs("libjvm_dtrace DEBUG: ", stderr);
+        vfprintf(stderr, fmt, alist);
+        va_end(alist);
+    }
+}
+
+/* Key for thread local error message */
+static thread_key_t jvm_error_key;
+
+/* init function for this library */
+static void init_jvm_dtrace() {
+    /* check for env. var for debug mode */
+    libjvm_dtrace_debug = getenv("LIBJVM_DTRACE_DEBUG") != NULL;
+    /* create key for thread local error message */
+    if (thr_keycreate(&jvm_error_key, NULL) != 0) {
+        print_debug("can't create thread_key_t for jvm error key\n");
+        // exit(1); ?
+    }
+}
+
+#pragma init(init_jvm_dtrace)
+
+/* set thread local error message */
+static void set_jvm_error(const char* msg) {
+    thr_setspecific(jvm_error_key, (void*)msg);
+}
+
+/* clear thread local error message */
+static void clear_jvm_error() {
+    thr_setspecific(jvm_error_key, NULL);
+}
+
+/* file handling functions that can handle interrupt */
+
+static int file_open(const char* path, int flag) {
+    int ret;
+    RESTARTABLE(open(path, flag), ret);
+    return ret;
+}
+
+static int file_close(int fd) {
+    int ret;
+    RESTARTABLE(close(fd), ret);
+    return ret;
+}
+
+static int file_read(int fd, char* buf, int len) {
+    int ret;
+    RESTARTABLE(read(fd, buf, len), ret);
+    return ret;
+}
+
+/* send SIGQUIT signal to given process */
+static int send_sigquit(pid_t pid) {
+    int ret;
+    RESTARTABLE(kill(pid, SIGQUIT), ret);
+    return ret;
+}
+
+/* called to check permissions on attach file */
+static int check_permission(const char* path) {
+    struct stat64 sb;
+    uid_t uid, gid;
+    int res;
+
+    /*
+     * Check that the path is owned by the effective uid/gid of this
+     * process. Also check that group/other access is not allowed.
+     */
+    uid = geteuid();
+    gid = getegid();
+
+    res = stat64(path, &sb);
+    if (res != 0) {
+        print_debug("stat failed for %s\n", path);
+        return -1;
+    }
+
+    if ((sb.st_uid != uid) || (sb.st_gid != gid) ||
+        ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0)) {
+        print_debug("well-known file %s is not secure\n", path);
+        return -1;
+    }
+    return 0;
+}
+
+#define ATTACH_FILE_PATTERN "/tmp/.attach_pid%d"
+
+/* fill-in the name of attach file name in given buffer */
+static void fill_attach_file_name(char* path, int len, pid_t pid) {
+    memset(path, 0, len);
+    sprintf(path, ATTACH_FILE_PATTERN, pid);
+}
+
+#define DOOR_FILE_PATTERN "/tmp/.java_pid%d"
+
+/* open door file for the given JVM */
+static int open_door(pid_t pid) {
+    char path[PATH_MAX + 1];
+    int fd;
+
+    sprintf(path, DOOR_FILE_PATTERN, pid);
+    fd = file_open(path, O_RDONLY);
+    if (fd < 0) {
+        set_jvm_error(JVM_ERR_CANT_OPEN_DOOR);
+        print_debug("cannot open door file %s\n", path);
+        return -1;
+    }
+    print_debug("opened door file %s\n", path);
+    if (check_permission(path) != 0) {
+        set_jvm_error(JVM_ERR_DOOR_FILE_PERMISSION);
+        print_debug("check permission failed for %s\n", path);
+        file_close(fd);
+        fd = -1;
+    }
+    return fd;
+}
+
+/* create attach file for given process */
+static int create_attach_file(pid_t pid) {
+    char path[PATH_MAX + 1];
+    int fd;
+    fill_attach_file_name(path, sizeof(path), pid);
+    fd = file_open(path, O_CREAT | O_RDWR);
+    if (fd < 0) {
+        set_jvm_error(JVM_ERR_CANT_CREATE_ATTACH_FILE);
+        print_debug("cannot create file %s\n", path);
+    } else {
+        print_debug("created attach file %s\n", path);
+    }
+    return fd;
+}
+
+/* delete attach file for given process */
+static void delete_attach_file(pid_t pid) {
+    char path[PATH_MAX + 1];
+    fill_attach_file_name(path, sizeof(path), pid);
+    int res = unlink(path);
+    if (res) {
+        print_debug("cannot delete attach file %s\n", path);
+    } else {
+        print_debug("deleted attach file %s\n", path);
+    }
+}
+
+/* attach to given JVM */
+jvm_t* jvm_attach(pid_t pid) {
+    jvm_t* jvm;
+    int door_fd, attach_fd, i;
+
+    jvm = (jvm_t*) calloc(1, sizeof(jvm_t));
+    if (jvm == NULL) {
+        set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
+        print_debug("calloc failed in %s at %d\n", __FILE__, __LINE__);
+        return NULL;
+    }
+    jvm->pid = pid;
+    attach_fd = -1;
+
+    door_fd = open_door(pid);
+    if (door_fd < 0) {
+        print_debug("trying to create attach file\n");
+        if ((attach_fd = create_attach_file(pid)) < 0) {
+            goto quit;
+        }
+
+        /* send QUIT signal to the target so that it will
+         * check for the attach file.
+         */
+        if (send_sigquit(pid) != 0) {
+            set_jvm_error(JVM_ERR_CANT_SIGNAL);
+            print_debug("sending SIGQUIT failed\n");
+            goto quit;
+        }
+
+        /* give the target VM time to start the attach mechanism */
+        do {
+            int res;
+            RESTARTABLE(poll(0, 0, 200), res);
+            door_fd = open_door(pid);
+            i++;
+        } while (i <= 50 && door_fd == -1);
+        if (door_fd < 0) {
+            print_debug("Unable to open door to process %d\n", pid);
+            goto quit;
+        }
+    }
+
+quit:
+    if (attach_fd >= 0) {
+        file_close(attach_fd);
+        delete_attach_file(jvm->pid);
+    }
+    if (door_fd >= 0) {
+        jvm->door_fd = door_fd;
+        clear_jvm_error();
+    } else {
+        free(jvm);
+        jvm = NULL;
+    }
+    return jvm;
+}
+
+/* return the last thread local error message */
+const char* jvm_get_last_error() {
+    const char* res = NULL;
+    thr_getspecific(jvm_error_key, (void**)&res);
+    return res;
+}
+
+/* detach the givenb JVM */
+int jvm_detach(jvm_t* jvm) {
+    if (jvm) {
+        int res;
+        if (jvm->door_fd != -1) {
+            if (file_close(jvm->door_fd) != 0) {
+                set_jvm_error(JVM_ERR_CANT_CLOSE_DOOR);
+                res = -1;
+            } else {
+                clear_jvm_error();
+                res = 0;
+            }
+        }
+        free(jvm);
+        return res;
+    } else {
+        set_jvm_error(JVM_ERR_NULL_PARAM);
+        print_debug("jvm_t* is NULL\n");
+        return -1;
+    }
+}
+
+/*
+ * A simple table to translate some known errors into reasonable
+ * error messages
+ */
+static struct {
+    int err;
+    const char* msg;
+} const error_messages[] = {
+    { 100,      "Bad request" },
+    { 101,      "Protocol mismatch" },
+    { 102,      "Resource failure" },
+    { 103,      "Internal error" },
+    { 104,      "Permission denied" },
+};
+
+/*
+ * Lookup the given error code and return the appropriate
+ * message. If not found return NULL.
+ */
+static const char* translate_error(int err) {
+    int table_size = sizeof(error_messages) / sizeof(error_messages[0]);
+    int i;
+
+    for (i=0; i<table_size; i++) {
+        if (err == error_messages[i].err) {
+            return error_messages[i].msg;
+        }
+    }
+    return NULL;
+}
+
+/*
+ * Current protocol version
+ */
+static const char* PROTOCOL_VERSION = "1";
+
+#define RES_BUF_SIZE 128
+
+/*
+ * Enqueue attach-on-demand command to the given JVM
+ */
+static
+int enqueue_command(jvm_t* jvm, const char* cstr, int arg_count, const char** args) {
+    size_t size;
+    door_arg_t door_args;
+    char res_buffer[RES_BUF_SIZE];
+    int rc, i;
+    char* buf = NULL;
+    int result = -1;
+
+    /*
+     * First we get the command string and create the start of the
+     * argument string to send to the target VM:
+     * <ver>\0<cmd>\0
+     */
+    if (cstr == NULL) {
+        print_debug("command name is NULL\n");
+        goto quit;
+    }
+    size = strlen(PROTOCOL_VERSION) + strlen(cstr) + 2;
+    buf = (char*)malloc(size);
+    if (buf != NULL) {
+        char* pos = buf;
+        strcpy(buf, PROTOCOL_VERSION);
+        pos += strlen(PROTOCOL_VERSION)+1;
+        strcpy(pos, cstr);
+    } else {
+        set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
+        print_debug("malloc failed at %d in %s\n", __LINE__, __FILE__);
+        goto quit;
+    }
+
+    /*
+     * Next we iterate over the arguments and extend the buffer
+     * to include them.
+     */
+    for (i=0; i<arg_count; i++) {
+        cstr = args[i];
+        if (cstr != NULL) {
+            size_t len = strlen(cstr);
+            char* newbuf = (char*)realloc(buf, size+len+1);
+            if (newbuf == NULL) {
+                set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
+                print_debug("realloc failed in %s at %d\n", __FILE__, __LINE__);
+                goto quit;
+            }
+            buf = newbuf;
+            strcpy(buf+size, cstr);
+            size += len+1;
+        }
+    }
+
+    /*
+     * The arguments to the door function are in 'buf' so we now
+     * do the door call
+     */
+    door_args.data_ptr = buf;
+    door_args.data_size = size;
+    door_args.desc_ptr = NULL;
+    door_args.desc_num = 0;
+    door_args.rbuf = (char*)&res_buffer;
+    door_args.rsize = sizeof(res_buffer);
+
+    RESTARTABLE(door_call(jvm->door_fd, &door_args), rc);
+
+    /*
+     * door_call failed
+     */
+    if (rc == -1) {
+        print_debug("door_call failed\n");
+    } else {
+        /*
+         * door_call succeeded but the call didn't return the the expected jint.
+         */
+        if (door_args.data_size < sizeof(int)) {
+            print_debug("Enqueue error - reason unknown as result is truncated!");
+        } else {
+            int* res = (int*)(door_args.data_ptr);
+            if (*res != 0) {
+                const char* msg = translate_error(*res);
+                if (msg == NULL) {
+                    print_debug("Unable to enqueue command to target VM: %d\n", *res);
+                } else {
+                    print_debug("Unable to enqueue command to target VM: %s\n", msg);
+                }
+            } else {
+                /*
+                 * The door call should return a file descriptor to one end of
+                 * a socket pair
+                 */
+                if ((door_args.desc_ptr != NULL) &&
+                    (door_args.desc_num == 1) &&
+                    (door_args.desc_ptr->d_attributes & DOOR_DESCRIPTOR)) {
+                    result = door_args.desc_ptr->d_data.d_desc.d_descriptor;
+                } else {
+                    print_debug("Reply from enqueue missing descriptor!\n");
+                }
+            }
+        }
+    }
+
+quit:
+    if (buf) free(buf);
+    return result;
+}
+
+/* read status code for a door command */
+static int read_status(int fd) {
+    char ch, buf[16];
+    int index = 0;
+
+    while (1) {
+        if (file_read(fd, &ch, sizeof(ch)) != sizeof(ch)) {
+            set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
+            print_debug("door cmd status: read status failed\n");
+            return -1;
+        }
+        buf[index++] = ch;
+        if (ch == '\n') {
+            buf[index - 1] = '\0';
+            return atoi(buf);
+        }
+        if (index == sizeof(buf)) {
+            set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
+            print_debug("door cmd status: read status overflow\n");
+            return -1;
+        }
+    }
+}
+
+static const char* ENABLE_DPROBES_CMD = "enabledprobes";
+
+/* enable one or more DTrace probes for a given JVM */
+int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types) {
+    int fd, status = 0;
+    char ch;
+    const char* args[1];
+    char buf[16];
+    int probe_type = 0, index;
+    int count = 0;
+
+    if (jvm == NULL) {
+        set_jvm_error(JVM_ERR_NULL_PARAM);
+        print_debug("jvm_t* is NULL\n");
+        return -1;
+    }
+
+    if (num_probe_types == 0 || probe_types == NULL ||
+        probe_types[0] == NULL) {
+        set_jvm_error(JVM_ERR_INVALID_PARAM);
+        print_debug("invalid probe type argument(s)\n");
+        return -1;
+    }
+
+    for (index = 0; index < num_probe_types; index++) {
+        const char* p = probe_types[index];
+        if (strcmp(p, JVM_DTPROBE_OBJECT_ALLOC) == 0) {
+            probe_type |= DTRACE_ALLOC_PROBES;
+            count++;
+        } else if (strcmp(p, JVM_DTPROBE_METHOD_ENTRY) == 0 ||
+                   strcmp(p, JVM_DTPROBE_METHOD_RETURN) == 0) {
+            probe_type |= DTRACE_METHOD_PROBES;
+            count++;
+        } else if (strcmp(p, JVM_DTPROBE_MONITOR_ENTER) == 0   ||
+                   strcmp(p, JVM_DTPROBE_MONITOR_ENTERED) == 0 ||
+                   strcmp(p, JVM_DTPROBE_MONITOR_EXIT) == 0    ||
+                   strcmp(p, JVM_DTPROBE_MONITOR_WAIT) == 0    ||
+                   strcmp(p, JVM_DTPROBE_MONITOR_WAITED) == 0  ||
+                   strcmp(p, JVM_DTPROBE_MONITOR_NOTIFY) == 0  ||
+                   strcmp(p, JVM_DTPROBE_MONITOR_NOTIFYALL) == 0) {
+            probe_type |= DTRACE_MONITOR_PROBES;
+            count++;
+        } else if (strcmp(p, JVM_DTPROBE_ALL) == 0) {
+            probe_type |= DTRACE_ALL_PROBES;
+            count++;
+        }
+    }
+
+    if (count == 0) {
+        return count;
+    }
+    sprintf(buf, "%d", probe_type);
+    args[0] = buf;
+
+    fd = enqueue_command(jvm, ENABLE_DPROBES_CMD, 1, args);
+    if (fd < 0) {
+        set_jvm_error(JVM_ERR_DOOR_CMD_SEND);
+        return -1;
+    }
+
+    status = read_status(fd);
+    // non-zero status is error
+    if (status) {
+        set_jvm_error(JVM_ERR_DOOR_CMD_STATUS);
+        print_debug("%s command failed (status: %d) in target JVM\n",
+                    ENABLE_DPROBES_CMD, status);
+        file_close(fd);
+        return -1;
+    }
+    // read from stream until EOF
+    while (file_read(fd, &ch, sizeof(ch)) == sizeof(ch)) {
+        if (libjvm_dtrace_debug) {
+            printf("%c", ch);
+        }
+    }
+
+    file_close(fd);
+    clear_jvm_error();
+    return count;
+}
diff --git a/hotspot/src/os/bsd/dtrace/jvm_dtrace.h b/hotspot/src/os/bsd/dtrace/jvm_dtrace.h
new file mode 100644
index 0000000..edc6dbd
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/jvm_dtrace.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef _JVM_DTRACE_H_
+#define _JVM_DTRACE_H_
+
+/*
+ * Interface to dynamically turn on probes in Hotspot JVM. Currently,
+ * this interface can be used to dynamically enable certain DTrace
+ * probe points that are costly to have "always on".
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+
+
+struct _jvm_t;
+typedef struct _jvm_t jvm_t;
+
+
+/* Attach to the given JVM process. Returns NULL on failure.
+   jvm_get_last_error() returns last error message. */
+jvm_t* jvm_attach(pid_t pid);
+
+/* Returns the last error message from this library or NULL if none. */
+const char* jvm_get_last_error();
+
+/* few well-known probe type constants for 'probe_types' param below */
+
+#define JVM_DTPROBE_METHOD_ENTRY         "method-entry"
+#define JVM_DTPROBE_METHOD_RETURN        "method-return"
+#define JVM_DTPROBE_MONITOR_ENTER        "monitor-contended-enter"
+#define JVM_DTPROBE_MONITOR_ENTERED      "monitor-contended-entered"
+#define JVM_DTPROBE_MONITOR_EXIT         "monitor-contended-exit"
+#define JVM_DTPROBE_MONITOR_WAIT         "monitor-wait"
+#define JVM_DTPROBE_MONITOR_WAITED       "monitor-waited"
+#define JVM_DTPROBE_MONITOR_NOTIFY       "monitor-notify"
+#define JVM_DTPROBE_MONITOR_NOTIFYALL    "monitor-notifyall"
+#define JVM_DTPROBE_OBJECT_ALLOC         "object-alloc"
+#define JVM_DTPROBE_ALL                  "*"
+
+/* Enable the specified DTrace probes of given probe types on
+ * the specified JVM. Returns >= 0 on success, -1 on failure.
+ * On success, this returns number of probe_types enabled.
+ * On failure, jvm_get_last_error() returns the last error message.
+ */
+int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types);
+
+/* Note: There is no jvm_disable_dtprobes function. Probes are automatically
+ * disabled when there are no more clients requiring those probes.
+ */
+
+/* Detach the given JVM. Returns 0 on success, -1 on failure.
+ * jvm_get_last_error() returns the last error message.
+ */
+int jvm_detach(jvm_t* jvm);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _JVM_DTRACE_H_ */
diff --git a/hotspot/src/os/bsd/dtrace/libjvm_db.c b/hotspot/src/os/bsd/dtrace/libjvm_db.c
new file mode 100644
index 0000000..bffa08a
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/libjvm_db.c
@@ -0,0 +1,1548 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+// not available on macosx #include <gelf.h>
+
+#include "libjvm_db.h"
+#include "JvmOffsets.h"
+
+#define LIBJVM_SO "libjvm.so"
+
+#if defined(i386) || defined(__i386) || defined(__amd64)
+#ifdef COMPILER2
+#define X86_COMPILER2
+#endif /* COMPILER2 */
+#endif /* i386 */
+
+typedef struct {
+    short     vf_cnt; /* number of recognized java vframes */
+    short     bci;    /* current frame method byte code index */
+    int       line;   /* current frame method source line */
+    uint64_t new_fp; /* fp for the next frame */
+    uint64_t new_pc; /* pc for the next frame */
+    uint64_t new_sp; /* "raw" sp for the next frame (includes extension by interpreter/adapter */
+    char      locinf; /* indicates there is valid location info */
+} Jframe_t;
+
+int Jlookup_by_regs(jvm_agent_t* J, const prgregset_t regs, char *name,
+                    size_t size, Jframe_t *jframe);
+
+int main(int arg) { return arg; }
+
+static int debug = 0;
+
+static void failed(int err, const char * file, int line) {
+  if (debug) {
+    fprintf(stderr, "failed %d at %s:%d\n", err, file, line);
+  }
+}
+
+static void warn(const char * file, int line, const char * msg) {
+  if (debug) {
+    fprintf(stderr, "warning: %s at %s:%d\n", msg, file, line);
+  }
+}
+
+static void warn1(const char * file, int line, const char * msg, intptr_t arg1) {
+  if (debug) {
+    fprintf(stderr, "warning: ");
+    fprintf(stderr, msg, arg1);
+    fprintf(stderr, " at %s:%d\n", file, line);
+  }
+}
+
+#define CHECK_FAIL(err) \
+        if (err != PS_OK) { failed(err, __FILE__, __LINE__); goto fail; }
+#define WARN(msg)  warn(__FILE__, __LINE__, msg)
+#define WARN1(msg, arg1)  warn1(__FILE__, __LINE__, msg, arg1)
+
+typedef struct VMStructEntry {
+  const char * typeName;           /* The type name containing the given field (example: "Klass") */
+  const char * fieldName;          /* The field name within the type           (example: "_name") */
+  uint64_t address;                /* Address of field; only used for static fields */
+                                   /* ("offset" can not be reused because of apparent SparcWorks compiler bug */
+                                   /* in generation of initializer data) */
+} VMStructEntry;
+
+/* Prototyping inlined methods */
+
+int sprintf(char *s, const char *format, ...);
+
+#define SZ16  sizeof(int16_t)
+#define SZ32  sizeof(int32_t)
+
+#define COMP_METHOD_SIGN '*'
+
+#define MAX_VFRAMES_CNT 256
+
+typedef struct vframe {
+  uint64_t methodOop;
+  int32_t  sender_decode_offset;
+  int32_t  methodIdx;
+  int32_t  bci;
+  int32_t  line;
+} Vframe_t;
+
+typedef struct frame {
+  uintptr_t fp;
+  uintptr_t pc;
+  uintptr_t sp;
+  uintptr_t sender_sp; // The unextended sp of the caller
+} Frame_t;
+
+typedef struct Nmethod_t {
+  struct jvm_agent* J;
+  Jframe_t *jframe;
+
+  uint64_t nm;                  /* _nmethod */
+  uint64_t pc;
+  uint64_t pc_desc;
+
+  int32_t  orig_pc_offset;      /* _orig_pc_offset */
+  int32_t  instrs_beg;          /* _code_offset */
+  int32_t  instrs_end;
+  int32_t  deopt_beg;           /* _deoptimize_offset */
+  int32_t  scopes_data_beg;     /* _scopes_data_offset */
+  int32_t  scopes_data_end;
+  int32_t  oops_beg;            /* _oops_offset */
+  int32_t  oops_end;
+  int32_t  scopes_pcs_beg;      /* _scopes_pcs_offset */
+  int32_t  scopes_pcs_end;
+
+  int      vf_cnt;
+  Vframe_t vframes[MAX_VFRAMES_CNT];
+} Nmethod_t;
+
+struct jvm_agent {
+  struct ps_prochandle* P;
+
+  uint64_t nmethod_vtbl;
+  uint64_t CodeBlob_vtbl;
+  uint64_t BufferBlob_vtbl;
+  uint64_t RuntimeStub_vtbl;
+
+  uint64_t Use_Compressed_Oops_address;
+  uint64_t Universe_methodKlassObj_address;
+  uint64_t Universe_narrow_oop_base_address;
+  uint64_t Universe_narrow_oop_shift_address;
+  uint64_t CodeCache_heap_address;
+
+  /* Volatiles */
+  uint8_t  Use_Compressed_Oops;
+  uint64_t Universe_methodKlassObj;
+  uint64_t Universe_narrow_oop_base;
+  uint32_t Universe_narrow_oop_shift;
+  uint64_t CodeCache_low;
+  uint64_t CodeCache_high;
+  uint64_t CodeCache_segmap_low;
+  uint64_t CodeCache_segmap_high;
+
+  int32_t  SIZE_CodeCache_log2_segment;
+
+  uint64_t methodOopPtr;
+  uint64_t bcx;
+
+  Nmethod_t *N;                 /*Inlined methods support */
+  Frame_t   prev_fr;
+  Frame_t   curr_fr;
+};
+
+static int
+read_string(struct ps_prochandle *P,
+        char *buf,              /* caller's buffer */
+        size_t size,            /* upper limit on bytes to read */
+        uintptr_t addr)         /* address in process */
+{
+  int err = PS_OK;
+  while (size-- > 1 && err == PS_OK) {
+    err = ps_pread(P, addr, buf, 1);
+    if (*buf == '\0') {
+      return PS_OK;
+    }
+    addr += 1;
+    buf += 1;
+  }
+  return -1;
+}
+
+static int read_compressed_pointer(jvm_agent_t* J, uint64_t base, uint32_t *ptr) {
+  int err = -1;
+  uint32_t ptr32;
+  err = ps_pread(J->P, base, &ptr32, sizeof(uint32_t));
+  *ptr = ptr32;
+  return err;
+}
+
+static int read_pointer(jvm_agent_t* J, uint64_t base, uint64_t* ptr) {
+  int err = -1;
+  uint32_t ptr32;
+
+  switch (DATA_MODEL) {
+  case PR_MODEL_LP64:
+    err = ps_pread(J->P, base, ptr, sizeof(uint64_t));
+    break;
+  case PR_MODEL_ILP32:
+    err = ps_pread(J->P, base, &ptr32, sizeof(uint32_t));
+    *ptr = ptr32;
+    break;
+  }
+
+  return err;
+}
+
+static int read_string_pointer(jvm_agent_t* J, uint64_t base, const char ** stringp) {
+  uint64_t ptr;
+  int err;
+  char buffer[1024];
+
+  *stringp = NULL;
+  err = read_pointer(J, base, &ptr);
+  CHECK_FAIL(err);
+  if (ptr != 0) {
+    err = read_string(J->P, buffer, sizeof(buffer), ptr);
+    CHECK_FAIL(err);
+    *stringp = strdup(buffer);
+  }
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+static int parse_vmstruct_entry(jvm_agent_t* J, uint64_t base, VMStructEntry* vmp) {
+  uint64_t ptr;
+  int err;
+
+  err = read_string_pointer(J, base + OFFSET_VMStructEntrytypeName, &vmp->typeName);
+  CHECK_FAIL(err);
+  err = read_string_pointer(J, base + OFFSET_VMStructEntryfieldName, &vmp->fieldName);
+  CHECK_FAIL(err);
+  err = read_pointer(J, base + OFFSET_VMStructEntryaddress, &vmp->address);
+  CHECK_FAIL(err);
+
+  return PS_OK;
+
+ fail:
+  if (vmp->typeName != NULL) free((void*)vmp->typeName);
+  if (vmp->fieldName != NULL) free((void*)vmp->fieldName);
+  return err;
+}
+
+static int parse_vmstructs(jvm_agent_t* J) {
+  VMStructEntry  vmVar;
+  VMStructEntry* vmp = &vmVar;
+  uint64_t gHotSpotVMStructs;
+  psaddr_t sym_addr;
+  uint64_t base;
+  int err;
+
+  err = ps_pglobal_lookup(J->P, LIBJVM_SO, "gHotSpotVMStructs", &sym_addr);
+  CHECK_FAIL(err);
+  err = read_pointer(J, sym_addr, &gHotSpotVMStructs);
+  CHECK_FAIL(err);
+  base = gHotSpotVMStructs;
+
+  err = PS_OK;
+  while (err == PS_OK) {
+    memset(vmp, 0, sizeof(VMStructEntry));
+    err = parse_vmstruct_entry(J, base, vmp);
+    if (err != PS_OK || vmp->typeName == NULL) {
+      break;
+    }
+
+    if (vmp->typeName[0] == 'C' && strcmp("CodeCache", vmp->typeName) == 0) {
+      if (strcmp("_heap", vmp->fieldName) == 0) {
+        err = read_pointer(J, vmp->address, &J->CodeCache_heap_address);
+      }
+    } else if (vmp->typeName[0] == 'U' && strcmp("Universe", vmp->typeName) == 0) {
+      if (strcmp("_methodKlassObj", vmp->fieldName) == 0) {
+        J->Universe_methodKlassObj_address = vmp->address;
+      }
+      if (strcmp("_narrow_oop._base", vmp->fieldName) == 0) {
+        J->Universe_narrow_oop_base_address = vmp->address;
+      }
+      if (strcmp("_narrow_oop._shift", vmp->fieldName) == 0) {
+        J->Universe_narrow_oop_shift_address = vmp->address;
+      }
+    }
+    CHECK_FAIL(err);
+
+    base += SIZE_VMStructEntry;
+    if (vmp->typeName != NULL) free((void*)vmp->typeName);
+    if (vmp->fieldName != NULL) free((void*)vmp->fieldName);
+  }
+
+  return PS_OK;
+
+ fail:
+  if (vmp->typeName != NULL) free((void*)vmp->typeName);
+  if (vmp->fieldName != NULL) free((void*)vmp->fieldName);
+  return -1;
+}
+
+static int find_symbol(jvm_agent_t* J, const char *name, uint64_t* valuep) {
+  psaddr_t sym_addr;
+  int err;
+
+  err = ps_pglobal_lookup(J->P, LIBJVM_SO, name, &sym_addr);
+  if (err != PS_OK) goto fail;
+  *valuep = sym_addr;
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+static int read_volatiles(jvm_agent_t* J) {
+  uint64_t ptr;
+  int err;
+
+  err = find_symbol(J, "UseCompressedOops", &J->Use_Compressed_Oops_address);
+  if (err == PS_OK) {
+    err = ps_pread(J->P,  J->Use_Compressed_Oops_address, &J->Use_Compressed_Oops, sizeof(uint8_t));
+    CHECK_FAIL(err);
+  } else {
+    J->Use_Compressed_Oops = 0;
+  }
+
+  err = read_pointer(J, J->Universe_methodKlassObj_address, &J->Universe_methodKlassObj);
+  CHECK_FAIL(err);
+
+  err = read_pointer(J, J->Universe_narrow_oop_base_address, &J->Universe_narrow_oop_base);
+  CHECK_FAIL(err);
+  err = ps_pread(J->P,  J->Universe_narrow_oop_shift_address, &J->Universe_narrow_oop_shift, sizeof(uint32_t));
+  CHECK_FAIL(err);
+
+  err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_memory +
+                     OFFSET_VirtualSpace_low, &J->CodeCache_low);
+  CHECK_FAIL(err);
+  err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_memory +
+                     OFFSET_VirtualSpace_high, &J->CodeCache_high);
+  CHECK_FAIL(err);
+  err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_segmap +
+                     OFFSET_VirtualSpace_low, &J->CodeCache_segmap_low);
+  CHECK_FAIL(err);
+  err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_segmap +
+                     OFFSET_VirtualSpace_high, &J->CodeCache_segmap_high);
+  CHECK_FAIL(err);
+
+  err = ps_pread(J->P, J->CodeCache_heap_address + OFFSET_CodeHeap_log2_segment_size,
+                 &J->SIZE_CodeCache_log2_segment, sizeof(J->SIZE_CodeCache_log2_segment));
+  CHECK_FAIL(err);
+
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+
+static int codecache_contains(jvm_agent_t* J, uint64_t ptr) {
+  /* make sure the code cache is up to date */
+  return (J->CodeCache_low <= ptr && ptr < J->CodeCache_high);
+}
+
+static uint64_t segment_for(jvm_agent_t* J, uint64_t p) {
+  return (p - J->CodeCache_low) >> J->SIZE_CodeCache_log2_segment;
+}
+
+static uint64_t block_at(jvm_agent_t* J, int i) {
+  return J->CodeCache_low + (i << J->SIZE_CodeCache_log2_segment);
+}
+
+static int find_start(jvm_agent_t* J, uint64_t ptr, uint64_t *startp) {
+  int err;
+
+  *startp = 0;
+  if (J->CodeCache_low <= ptr && ptr < J->CodeCache_high) {
+    int32_t used;
+    uint64_t segment = segment_for(J, ptr);
+    uint64_t block = J->CodeCache_segmap_low;
+    uint8_t tag;
+    err = ps_pread(J->P, block + segment, &tag, sizeof(tag));
+    CHECK_FAIL(err);
+    if (tag == 0xff)
+      return PS_OK;
+    while (tag > 0) {
+      err = ps_pread(J->P, block + segment, &tag, sizeof(tag));
+      CHECK_FAIL(err);
+      segment -= tag;
+    }
+    block = block_at(J, segment);
+    err = ps_pread(J->P, block + OFFSET_HeapBlockHeader_used, &used, sizeof(used));
+    CHECK_FAIL(err);
+    if (used) {
+      *startp = block + SIZE_HeapBlockHeader;
+    }
+  }
+  return PS_OK;
+
+ fail:
+  return -1;
+}
+
+static int find_jlong_constant(jvm_agent_t* J, const char *name, uint64_t* valuep) {
+  psaddr_t sym_addr;
+  int err = ps_pglobal_lookup(J->P, LIBJVM_SO, name, &sym_addr);
+  if (err == PS_OK) {
+    err = ps_pread(J->P, sym_addr, valuep, sizeof(uint64_t));
+    return err;
+  }
+  *valuep = -1;
+  return -1;
+}
+
+jvm_agent_t *Jagent_create(struct ps_prochandle *P, int vers) {
+  jvm_agent_t* J;
+  int err;
+
+  if (vers != JVM_DB_VERSION) {
+    errno = ENOTSUP;
+    return NULL;
+  }
+
+  J = (jvm_agent_t*)calloc(sizeof(struct jvm_agent), 1);
+
+  debug = getenv("LIBJVMDB_DEBUG") != NULL;
+  if (debug) debug = 3;
+
+  if (debug) {
+      fprintf(stderr, "Jagent_create: debug=%d\n", debug);
+#ifdef X86_COMPILER2
+      fprintf(stderr, "Jagent_create: R_SP=%d, R_FP=%d, POINTER_SIZE=%d\n", R_SP, R_FP, POINTER_SIZE);
+#endif  /* X86_COMPILER2 */
+  }
+
+  J->P = P;
+
+  // Initialize the initial previous frame
+
+  J->prev_fr.fp = 0;
+  J->prev_fr.pc = 0;
+  J->prev_fr.sp = 0;
+  J->prev_fr.sender_sp = 0;
+
+  err = find_symbol(J, "__1cHnmethodG__vtbl_", &J->nmethod_vtbl);
+  CHECK_FAIL(err);
+  err = find_symbol(J, "__1cKBufferBlobG__vtbl_", &J->BufferBlob_vtbl);
+  if (err != PS_OK) J->BufferBlob_vtbl = 0;
+  err = find_symbol(J, "__1cICodeBlobG__vtbl_", &J->CodeBlob_vtbl);
+  CHECK_FAIL(err);
+  err = find_symbol(J, "__1cLRuntimeStubG__vtbl_", &J->RuntimeStub_vtbl);
+  CHECK_FAIL(err);
+
+  err = parse_vmstructs(J);
+  CHECK_FAIL(err);
+  err = read_volatiles(J);
+  CHECK_FAIL(err);
+
+  return J;
+
+ fail:
+  Jagent_destroy(J);
+  return NULL;
+}
+
+void Jagent_destroy(jvm_agent_t *J) {
+  if (J != NULL) {
+    free(J);
+  }
+}
+
+static int is_methodOop(jvm_agent_t* J, uint64_t methodOopPtr) {
+  uint64_t klass;
+  int err;
+  // If UseCompressedOops, this was a compressed oop.
+  if (J->Use_Compressed_Oops != 0) {
+    uint32_t cklass;
+    err = read_compressed_pointer(J, methodOopPtr + OFFSET_oopDesc_metadata,
+          &cklass);
+    // decode heap oop, same as oop.inline.hpp
+    klass = (uint64_t)((uintptr_t)J->Universe_narrow_oop_base +
+            ((uintptr_t)cklass << J->Universe_narrow_oop_shift));
+  } else {
+    err = read_pointer(J, methodOopPtr + OFFSET_oopDesc_metadata, &klass);
+  }
+  if (err != PS_OK) goto fail;
+  return klass == J->Universe_methodKlassObj;
+
+ fail:
+  return 0;
+}
+
+static int
+name_for_methodOop(jvm_agent_t* J, uint64_t methodOopPtr, char * result, size_t size)
+{
+  short nameIndex;
+  short signatureIndex;
+  uint64_t constantPool;
+  uint64_t constMethod;
+  uint64_t nameSymbol;
+  uint64_t signatureSymbol;
+  uint64_t klassPtr;
+  uint64_t klassSymbol;
+  short klassSymbolLength;
+  short nameSymbolLength;
+  short signatureSymbolLength;
+  char * nameString = NULL;
+  char * klassString = NULL;
+  char * signatureString = NULL;
+  int err;
+
+  err = read_pointer(J, methodOopPtr + OFFSET_methodOopDesc_constants, &constantPool);
+  CHECK_FAIL(err);
+  err = read_pointer(J, methodOopPtr + OFFSET_methodOopDesc_constMethod, &constMethod);
+  CHECK_FAIL(err);
+
+  /* To get name string */
+  err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_name_index, &nameIndex, 2);
+  CHECK_FAIL(err);
+  err = read_pointer(J, constantPool + nameIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &nameSymbol);
+  CHECK_FAIL(err);
+  // The symbol is a CPSlot and has lower bit set to indicate metadata
+  nameSymbol &= (~1); // remove metadata lsb
+  err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_length, &nameSymbolLength, 2);
+  CHECK_FAIL(err);
+  nameString = (char*)calloc(nameSymbolLength + 1, 1);
+  err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_body, nameString, nameSymbolLength);
+  CHECK_FAIL(err);
+
+  /* To get signature string */
+  err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_signature_index, &signatureIndex, 2);
+  CHECK_FAIL(err);
+  err = read_pointer(J, constantPool + signatureIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &signatureSymbol);
+  CHECK_FAIL(err);
+  signatureSymbol &= (~1);  // remove metadata lsb
+  err = ps_pread(J->P, signatureSymbol + OFFSET_Symbol_length, &signatureSymbolLength, 2);
+  CHECK_FAIL(err);
+  signatureString = (char*)calloc(signatureSymbolLength + 1, 1);
+  err = ps_pread(J->P, signatureSymbol + OFFSET_Symbol_body, signatureString, signatureSymbolLength);
+  CHECK_FAIL(err);
+
+  /* To get klass string */
+  err = read_pointer(J, constantPool + OFFSET_constantPoolOopDesc_pool_holder, &klassPtr);
+  CHECK_FAIL(err);
+  err = read_pointer(J, klassPtr + OFFSET_Klass_name + SIZE_oopDesc, &klassSymbol);
+  CHECK_FAIL(err);
+  err = ps_pread(J->P, klassSymbol + OFFSET_Symbol_length, &klassSymbolLength, 2);
+  CHECK_FAIL(err);
+  klassString = (char*)calloc(klassSymbolLength + 1, 1);
+  err = ps_pread(J->P, klassSymbol + OFFSET_Symbol_body, klassString, klassSymbolLength);
+  CHECK_FAIL(err);
+
+  result[0] = '\0';
+  strncat(result, klassString, size);
+  size -= strlen(klassString);
+  strncat(result, ".", size);
+  size -= 1;
+  strncat(result, nameString, size);
+  size -= strlen(nameString);
+  strncat(result, signatureString, size);
+
+  if (nameString != NULL) free(nameString);
+  if (klassString != NULL) free(klassString);
+  if (signatureString != NULL) free(signatureString);
+
+  return PS_OK;
+
+ fail:
+  if (debug) {
+      fprintf(stderr, "name_for_methodOop: FAIL \n\n");
+  }
+  if (nameString != NULL) free(nameString);
+  if (klassString != NULL) free(klassString);
+  if (signatureString != NULL) free(signatureString);
+  return -1;
+}
+
+static int nmethod_info(Nmethod_t *N)
+{
+  jvm_agent_t *J = N->J;
+  uint64_t    nm = N->nm;
+  int32_t err;
+
+  if (debug > 2 )
+      fprintf(stderr, "\t nmethod_info: BEGIN \n");
+
+  /* Instructions */
+  err = ps_pread(J->P, nm + OFFSET_CodeBlob_code_offset, &N->instrs_beg, SZ32);
+  CHECK_FAIL(err);
+  err = ps_pread(J->P, nm + OFFSET_CodeBlob_data_offset, &N->instrs_end, SZ32);
+  CHECK_FAIL(err);
+  err = ps_pread(J->P, nm + OFFSET_nmethod_deoptimize_offset, &N->deopt_beg, SZ32);
+  CHECK_FAIL(err);
+  err = ps_pread(J->P, nm + OFFSET_nmethod_orig_pc_offset, &N->orig_pc_offset, SZ32);
+  CHECK_FAIL(err);
+
+  /* Oops */
+  err = ps_pread(J->P, nm + OFFSET_nmethod_oops_offset, &N->oops_beg, SZ32);
+  CHECK_FAIL(err);
+  err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_data_offset, &N->oops_end, SZ32);
+  CHECK_FAIL(err);
+
+  /* scopes_pcs */
+  err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_pcs_offset, &N->scopes_pcs_beg, SZ32);
+  CHECK_FAIL(err);
+  err = ps_pread(J->P, nm + OFFSET_nmethod_handler_table_offset, &N->scopes_pcs_end, SZ32);
+  CHECK_FAIL(err);
+
+  /* scopes_data */
+  err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_data_offset, &N->scopes_data_beg, SZ32);
+  CHECK_FAIL(err);
+
+  if (debug > 2 ) {
+      N->scopes_data_end = N->scopes_pcs_beg;
+
+      fprintf(stderr, "\t nmethod_info: instrs_beg: %#x, instrs_end: %#x\n",
+                       N->instrs_beg, N->instrs_end);
+
+      fprintf(stderr, "\t nmethod_info: deopt_beg: %#x \n",
+                       N->deopt_beg);
+
+      fprintf(stderr, "\t nmethod_info: orig_pc_offset: %#x \n",
+                       N->orig_pc_offset);
+
+      fprintf(stderr, "\t nmethod_info: oops_beg: %#x, oops_end: %#x\n",
+                       N->oops_beg, N->oops_end);
+
+      fprintf(stderr, "\t nmethod_info: scopes_data_beg: %#x, scopes_data_end: %#x\n",
+                       N->scopes_data_beg, N->scopes_data_end);
+
+      fprintf(stderr, "\t nmethod_info: scopes_pcs_beg: %#x, scopes_pcs_end: %#x\n",
+                       N->scopes_pcs_beg, N->scopes_pcs_end);
+
+      fprintf(stderr, "\t nmethod_info: END \n\n");
+  }
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+static int
+raw_read_int(jvm_agent_t* J, uint64_t *buffer, int32_t *val)
+{
+  int shift = 0;
+  int value = 0;
+  uint8_t ch = 0;
+  int32_t  err;
+  int32_t sum;
+  // Constants for UNSIGNED5 coding of Pack200
+  // see compressedStream.hpp
+  enum {
+    lg_H = 6,
+    H = 1<<lg_H,
+    BitsPerByte = 8,
+    L = (1<<BitsPerByte)-H,
+  };
+  int i;
+
+  err = ps_pread(J->P, (*buffer)++, &ch, sizeof(uint8_t));
+  CHECK_FAIL(err);
+  if (debug > 2)
+      fprintf(stderr, "\t\t\t raw_read_int: *buffer: %#llx, ch: %#x\n", *buffer, ch);
+
+  sum = ch;
+  if ( sum >= L ) {
+    int32_t lg_H_i = lg_H;
+    // Read maximum of 5 total bytes (we've already read 1).
+    // See CompressedReadStream::read_int_mb
+    for ( i = 0;  i < 4; i++) {
+      err = ps_pread(J->P, (*buffer)++, &ch, sizeof(uint8_t));
+      CHECK_FAIL(err);
+      sum += ch << lg_H_i;
+      if (ch < L ) {
+        *val = sum;
+        return PS_OK;
+      }
+      lg_H_i += lg_H;
+    }
+  }
+  *val = sum;
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+static int
+read_pair(jvm_agent_t* J, uint64_t *buffer, int32_t *bci, int32_t *line)
+{
+  uint8_t next = 0;
+  int32_t bci_delta;
+  int32_t line_delta;
+  int32_t err;
+
+  if (debug > 2)
+      fprintf(stderr, "\t\t read_pair: BEGIN\n");
+
+  err = ps_pread(J->P, (*buffer)++, &next, sizeof(uint8_t));
+  CHECK_FAIL(err);
+
+  if (next == 0) {
+      if (debug > 2)
+          fprintf(stderr, "\t\t read_pair: END: next == 0\n");
+      return 1; /* stream terminated */
+  }
+  if (next == 0xFF) {
+      if (debug > 2)
+          fprintf(stderr, "\t\t read_pair: END: next == 0xFF\n");
+
+      /* Escape character, regular compression used */
+
+      err = raw_read_int(J, buffer, &bci_delta);
+      CHECK_FAIL(err);
+
+      err = raw_read_int(J, buffer, &line_delta);
+      CHECK_FAIL(err);
+
+      *bci  += bci_delta;
+      *line += line_delta;
+
+      if (debug > 2) {
+          fprintf(stderr, "\t\t read_pair: delta = (line %d: %d)\n",
+                          line_delta, bci_delta);
+          fprintf(stderr, "\t\t read_pair: unpack= (line %d: %d)\n",
+                          *line, *bci);
+      }
+  } else {
+      /* Single byte compression used */
+      *bci  += next >> 3;
+      *line += next & 0x7;
+      if (debug > 2) {
+          fprintf(stderr, "\t\t read_pair: delta = (line %d: %d)\n",
+                          next & 0x7, next >> 3);
+          fprintf(stderr, "\t\t read_pair: unpack= (line %d: %d)\n",
+                          *line, *bci);
+      }
+  }
+  if (debug > 2)
+      fprintf(stderr, "\t\t read_pair: END\n");
+  return PS_OK;
+
+ fail:
+  if (debug)
+      fprintf(stderr, "\t\t read_pair: FAIL\n");
+  return err;
+}
+
+static int
+line_number_from_bci(jvm_agent_t* J, Vframe_t *vf)
+{
+  uint64_t buffer;
+  uint16_t code_size;
+  uint64_t code_end_delta;
+  uint64_t constMethod;
+  int8_t   access_flags;
+  int32_t  best_bci    = 0;
+  int32_t  stream_bci  = 0;
+  int32_t  stream_line = 0;
+  int32_t  err;
+
+  if (debug > 2) {
+      char name[256];
+      err = name_for_methodOop(J, vf->methodOop, name, 256);
+      CHECK_FAIL(err);
+      fprintf(stderr, "\t line_number_from_bci: BEGIN, method name: %s, targ bci: %d\n",
+                       name, vf->bci);
+  }
+
+  err = read_pointer(J, vf->methodOop + OFFSET_methodOopDesc_constMethod, &constMethod);
+  CHECK_FAIL(err);
+
+  vf->line = 0;
+  err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_flags, &access_flags, sizeof(int8_t));
+  CHECK_FAIL(err);
+
+  if (!(access_flags & constMethodOopDesc_has_linenumber_table)) {
+      if (debug > 2)
+          fprintf(stderr, "\t line_number_from_bci: END: !HAS_LINE_NUMBER_TABLE \n\n");
+      return PS_OK;
+  }
+
+  /*  The line numbers are a short array of 2-tuples [start_pc, line_number].
+   *  Not necessarily sorted and not necessarily one-to-one.
+   */
+
+  err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_code_size, &code_size, SZ16);
+  CHECK_FAIL(err);
+
+  /* inlined_table_start() */
+  code_end_delta = (uint64_t) (access_flags & AccessFlags_NATIVE) ? 2*POINTER_SIZE : 0;
+  buffer = constMethod + (uint64_t) SIZE_constMethodOopDesc + (uint64_t) code_size + code_end_delta;
+
+  if (debug > 2) {
+      fprintf(stderr, "\t\t line_number_from_bci: methodOop: %#llx, native: %d\n",
+                      vf->methodOop, (access_flags & AccessFlags_NATIVE));
+      fprintf(stderr, "\t\t line_number_from_bci: buffer: %#llx, code_size: %d\n",
+                      buffer, (int) code_size);
+  }
+
+  while (read_pair(J, &buffer, &stream_bci, &stream_line) == 0) {
+      if (stream_bci == vf->bci) {
+          /* perfect match */
+          if (debug > 2)
+              fprintf(stderr, "\t line_number_from_bci: END: exact line: %ld \n\n", vf->line);
+          vf->line = stream_line;
+          return PS_OK;
+      } else {
+          /* update best_bci/line */
+          if (stream_bci < vf->bci && stream_bci >= best_bci) {
+              best_bci = stream_bci;
+              vf->line = stream_line;
+              if (debug > 2) {
+                  fprintf(stderr, "\t line_number_from_bci: best_bci: %ld, best_line: %ld\n",
+                                   best_bci, vf->line);
+              }
+          }
+      }
+  }
+  if (debug > 2)
+      fprintf(stderr, "\t line_number_from_bci: END: line: %ld \n\n", vf->line);
+  return PS_OK;
+
+ fail:
+  if (debug)
+      fprintf(stderr, "\t line_number_from_bci: FAIL\n");
+  return err;
+}
+
+static int
+get_real_pc(Nmethod_t *N, uint64_t pc_desc, uint64_t *real_pc)
+{
+  int32_t pc_offset;
+  int32_t err;
+
+  err = ps_pread(N->J->P, pc_desc + OFFSET_PcDesc_pc_offset, &pc_offset, SZ32);
+  CHECK_FAIL(err);
+
+  *real_pc = N->nm + N->instrs_beg + pc_offset;
+  if (debug > 2) {
+      fprintf(stderr, "\t\t get_real_pc: pc_offset: %lx, real_pc: %llx\n",
+                       pc_offset, *real_pc);
+  }
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+/* Finds a PcDesc with real-pc equal to N->pc */
+static int pc_desc_at(Nmethod_t *N)
+{
+  uint64_t pc_diff;
+  int32_t offs;
+  int32_t err;
+
+  if (debug > 2)
+      fprintf(stderr, "\t pc_desc_at: BEGIN\n");
+
+  N->vf_cnt  = 0;
+  N->pc_desc = 0;
+
+  for (offs = N->scopes_pcs_beg; offs < N->scopes_pcs_end; offs += SIZE_PcDesc) {
+      uint64_t pd;
+      uint64_t best_pc_diff = 16;       /* some approximation */
+      uint64_t real_pc = 0;
+
+      pd = N->nm + offs;
+      err = get_real_pc(N, pd, &real_pc);
+      CHECK_FAIL(err);
+
+      pc_diff = real_pc - N->pc;
+
+      /* In general, this fragment should work */
+      if (pc_diff == 0) {
+          N->pc_desc = pd;
+          if (debug) {
+            fprintf(stderr, "\t pc_desc_at: END: pc_desc: FOUND: %#lx \n\n", pd);
+          }
+          return PS_OK;
+      }
+      /* This fragment is to be able to find out an appropriate
+       * pc_desc entry even if pc_desc info is inaccurate.
+       */
+      if (best_pc_diff > pc_diff && pc_diff > 0) {
+          best_pc_diff = pc_diff;
+          N->pc_desc = pd;
+      }
+  }
+  if (debug) {
+      fprintf(stderr, "\t pc_desc_at: END: pc_desc NOT FOUND");
+      if (pc_diff < 20)
+          fprintf(stderr, ", best pc_diff: %d\n\n", pc_diff);
+      else
+          fprintf(stderr, "\n\n");
+  }
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+static int
+scope_desc_at(Nmethod_t *N, int32_t decode_offset, Vframe_t *vf)
+{
+  uint64_t buffer;
+  int32_t  err;
+
+  if (debug > 2) {
+      fprintf(stderr, "\t\t scope_desc_at: BEGIN \n");
+  }
+
+  buffer = N->nm + N->scopes_data_beg + decode_offset;
+
+  err = raw_read_int(N->J, &buffer, &vf->sender_decode_offset);
+  CHECK_FAIL(err);
+
+  err = raw_read_int(N->J, &buffer, &vf->methodIdx);
+  CHECK_FAIL(err);
+
+  err = raw_read_int(N->J, &buffer, &vf->bci);
+  CHECK_FAIL(err);
+
+  if (debug > 2) {
+      fprintf(stderr, "\t\t scope_desc_at: sender_decode_offset: %#x\n",
+                      vf->sender_decode_offset);
+      fprintf(stderr, "\t\t scope_desc_at: methodIdx: %d\n", vf->methodIdx);
+      fprintf(stderr, "\t\t scope_desc_at: bci: %d\n", vf->bci);
+
+      fprintf(stderr, "\t\t scope_desc_at: END \n\n");
+  }
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+static int scopeDesc_chain(Nmethod_t *N) {
+  int32_t decode_offset = 0;
+  int32_t err;
+
+  if (debug > 2) {
+    fprintf(stderr, "\t scopeDesc_chain: BEGIN\n");
+  }
+
+  err = ps_pread(N->J->P, N->pc_desc + OFFSET_PcDesc_scope_decode_offset,
+                 &decode_offset, SZ32);
+  CHECK_FAIL(err);
+
+  while (decode_offset > 0) {
+    Vframe_t *vf = &N->vframes[N->vf_cnt];
+
+    if (debug > 2) {
+      fprintf(stderr, "\t scopeDesc_chain: decode_offset: %#x\n", decode_offset);
+    }
+
+    err = scope_desc_at(N, decode_offset, vf);
+    CHECK_FAIL(err);
+
+    if (vf->methodIdx > ((N->oops_end - N->oops_beg) / POINTER_SIZE)) {
+      fprintf(stderr, "\t scopeDesc_chain: (methodIdx > oops length) !\n");
+      return -1;
+    }
+    err = read_pointer(N->J, N->nm + N->oops_beg + (vf->methodIdx-1)*POINTER_SIZE,
+                       &vf->methodOop);
+    CHECK_FAIL(err);
+
+    if (vf->methodOop) {
+      N->vf_cnt++;
+      err = line_number_from_bci(N->J, vf);
+      CHECK_FAIL(err);
+      if (debug > 2) {
+        fprintf(stderr, "\t scopeDesc_chain: methodOop: %#8llx, line: %ld\n",
+                vf->methodOop, vf->line);
+      }
+    }
+    decode_offset = vf->sender_decode_offset;
+  }
+  if (debug > 2) {
+    fprintf(stderr, "\t scopeDesc_chain: END \n\n");
+  }
+  return PS_OK;
+
+ fail:
+  if (debug) {
+    fprintf(stderr, "\t scopeDesc_chain: FAIL \n\n");
+  }
+  return err;
+}
+
+
+static int
+name_for_nmethod(jvm_agent_t* J,
+                 uint64_t nm,
+                 uint64_t pc,
+                 uint64_t methodOop,
+                 char *result,
+                 size_t size,
+                 Jframe_t *jframe
+) {
+  Nmethod_t *N;
+  Vframe_t *vf;
+  int32_t err;
+  int deoptimized = 0;
+
+  if (debug) {
+      fprintf(stderr, "name_for_nmethod: BEGIN: nmethod: %#llx, pc: %#llx\n", nm, pc);
+  }
+  if (J->N == NULL) {
+    J->N = (Nmethod_t *) malloc(sizeof(Nmethod_t));
+  }
+  memset(J->N, 0, sizeof(Nmethod_t));   /* Initial stat: all values are zeros */
+  N     = J->N;
+  N->J  = J;
+  N->nm = nm;
+  N->pc = pc;
+  N->jframe = jframe;
+
+  err = nmethod_info(N);
+  CHECK_FAIL(err);
+  if (debug) {
+      fprintf(stderr, "name_for_nmethod: pc: %#llx, deopt_pc:  %#llx\n",
+              pc, N->nm + N->deopt_beg);
+  }
+
+  /* check for a deoptimized frame */
+  if ( pc == N->nm + N->deopt_beg) {
+    uint64_t base;
+    if (debug) {
+        fprintf(stderr, "name_for_nmethod: found deoptimized frame\n");
+    }
+    if (J->prev_fr.sender_sp != 0) {
+      base = J->prev_fr.sender_sp + N->orig_pc_offset;
+    } else {
+      base = J->curr_fr.sp + N->orig_pc_offset;
+    }
+    err = read_pointer(J, base, &N->pc);
+    CHECK_FAIL(err);
+    if (debug) {
+        fprintf(stderr, "name_for_nmethod: found deoptimized frame converting pc from %#8llx to %#8llx\n",
+        pc,  N->pc);
+    }
+    deoptimized = 1;
+  }
+
+  err = pc_desc_at(N);
+  CHECK_FAIL(err);
+
+  if (N->pc_desc > 0) {
+      jframe->locinf = 1;
+      err = scopeDesc_chain(N);
+      CHECK_FAIL(err);
+  }
+  result[0] = COMP_METHOD_SIGN;
+  vf = &N->vframes[0];
+  if (N->vf_cnt > 0) {
+      jframe->vf_cnt = N->vf_cnt;
+      jframe->bci  = vf->bci;
+      jframe->line = vf->line;
+      err = name_for_methodOop(J, N->vframes[0].methodOop, result+1, size-1);
+      CHECK_FAIL(err);
+  } else {
+      err = name_for_methodOop(J, methodOop, result+1, size-1);
+      CHECK_FAIL(err);
+  }
+  if (deoptimized) {
+    strncat(result + 1, " [deoptimized frame]; ", size-1);
+  } else {
+    strncat(result + 1, " [compiled] ", size-1);
+  }
+  if (debug)
+      fprintf(stderr, "name_for_nmethod: END: method name: %s, vf_cnt: %d\n\n",
+                      result, N->vf_cnt);
+  return PS_OK;
+
+ fail:
+  if (debug)
+      fprintf(stderr, "name_for_nmethod: FAIL \n\n");
+  return err;
+}
+
+int is_bci(intptr_t bcx) {
+  switch (DATA_MODEL) {
+  case PR_MODEL_LP64:
+    return ((uintptr_t) bcx) <= ((uintptr_t) MAX_METHOD_CODE_SIZE) ;
+  case PR_MODEL_ILP32:
+  default:
+    return 0 <= bcx && bcx <= MAX_METHOD_CODE_SIZE;
+  }
+}
+
+static int
+name_for_imethod(jvm_agent_t* J,
+                 uint64_t bcx,
+                 uint64_t methodOop,
+                 char *result,
+                 size_t size,
+                 Jframe_t *jframe
+) {
+  uint64_t bci;
+  uint64_t constMethod;
+  Vframe_t vframe = {0};
+  Vframe_t *vf = &vframe;
+  int32_t   err;
+
+  err = read_pointer(J, methodOop + OFFSET_methodOopDesc_constMethod, &constMethod);
+  CHECK_FAIL(err);
+
+  bci = is_bci(bcx) ? bcx : bcx - (constMethod + (uint64_t) SIZE_constMethodOopDesc);
+
+  if (debug)
+      fprintf(stderr, "\t name_for_imethod: BEGIN: methodOop: %#llx\n", methodOop);
+
+  err = name_for_methodOop(J, methodOop, result, size);
+  CHECK_FAIL(err);
+  if (debug)
+      fprintf(stderr, "\t name_for_imethod: method name: %s\n", result);
+
+  if (bci > 0) {
+      vf->methodOop = methodOop;
+      vf->bci       = bci;
+      err = line_number_from_bci(J, vf);
+      CHECK_FAIL(err);
+  }
+  jframe->bci  = vf->bci;
+  jframe->line = vf->line;
+  jframe->locinf = 1;
+
+  if (debug) {
+      fprintf(stderr, "\t name_for_imethod: END: bci: %d, line: %d\n\n",
+                      vf->bci, vf->line);
+  }
+  return PS_OK;
+
+ fail:
+  if (debug)
+      fprintf(stderr, "\t name_for_imethod: FAIL\n");
+  return err;
+}
+
+static int
+name_for_codecache(jvm_agent_t* J, uint64_t fp, uint64_t pc, char * result,
+                   size_t size, Jframe_t *jframe, int* is_interpreted)
+{
+  uint64_t start;
+  uint64_t vtbl;
+  int32_t err;
+  *is_interpreted = 0;
+
+  result[0] = '\0';
+
+  err = find_start(J, pc, &start);
+  CHECK_FAIL(err);
+
+  err = read_pointer(J, start, &vtbl);
+  CHECK_FAIL(err);
+
+  if (vtbl == J->nmethod_vtbl) {
+    uint64_t methodOop;
+
+    err = read_pointer(J, start + OFFSET_nmethod_method, &methodOop);
+    CHECK_FAIL(err);
+
+    if (debug) {
+        fprintf(stderr, "name_for_codecache: start: %#8llx, pc: %#8llx, methodOop: %#8llx \n",
+                        start, pc, methodOop);
+    }
+    err = name_for_nmethod(J, start, pc, methodOop, result, size, jframe);
+    CHECK_FAIL(err);
+  } else if (vtbl == J->BufferBlob_vtbl) {
+    const char * name;
+
+    err = read_string_pointer(J, start + OFFSET_CodeBlob_name, &name);
+
+    /*
+     * Temporary usage of string "Interpreter".
+     * We need some other way to distinguish "StubRoutines"
+     * and regular interpreted frames.
+     */
+    if (err == PS_OK && strncmp(name, "Interpreter", 11) == 0) {
+      *is_interpreted = 1;
+      if (is_methodOop(J, J->methodOopPtr)) {
+        return name_for_imethod(J, J->bcx, J->methodOopPtr, result, size, jframe);
+      }
+    }
+
+    if (err == PS_OK) {
+      strncpy(result, name, size);
+      free((void*)name);
+    } else {
+      strncpy(result, "<unknown BufferBlob>", size);
+    }
+    /* return PS_OK; */
+  } else {
+    const char * name;
+
+    err = read_string_pointer(J, start + OFFSET_CodeBlob_name, &name);
+    if (err == PS_OK) {
+      strncpy(result, name, size);
+      free((void*)name);
+    } else {
+      strncpy(result, "<unknown CodeBlob>", size);
+      WARN1("unknown CodeBlob: vtbl = 0x%x", vtbl);
+    }
+  }
+  result[size-1] = '\0';
+
+#ifdef X86_COMPILER2
+  if (vtbl != J->RuntimeStub_vtbl) {
+    uint64_t trial_pc;
+    int frame_size;
+    err = ps_pread(J->P, start + OFFSET_CodeBlob_frame_size,
+                         &frame_size, SZ32);
+    CHECK_FAIL(err);
+
+    // frame_size is in words, we want bytes.
+    frame_size *= POINTER_SIZE; /* word => byte conversion */
+
+    /*
+      Because c2 doesn't use FP as a framepointer the value of sp/fp we receive
+      in the initial entry to a set of stack frames containing server frames
+      will pretty much be nonsense. We can detect that nonsense by looking to
+      see if the PC we received is correct if we look at the expected storage
+      location in relation to the FP (ie. POINTER_SIZE(FP) )
+    */
+
+    err = read_pointer(J, fp + POINTER_SIZE , &trial_pc);
+    if ( (err != PS_OK || trial_pc != pc) && frame_size > 0 ) {
+      // Either we couldn't even read at the "fp" or the pc didn't match
+      // both are sure clues that the fp is bogus. We no search the stack
+      // for a reasonable number of words trying to find the bogus fp
+      // and the current pc in adjacent words. The we will be able to
+      // deduce an approximation of the frame pointer and actually get
+      // the correct stack pointer. Which we can then unwind for the
+      // next frame.
+      int i;
+      uint64_t check;
+      uint64_t base = J->curr_fr.sp;
+      uint64_t prev_fp = 0;
+      for ( i = 0; i < frame_size * 5 ; i++, base += POINTER_SIZE ) {
+        err = read_pointer(J, base , &check);
+        CHECK_FAIL(err);
+        if (check == fp) {
+          base += POINTER_SIZE;
+          err = read_pointer(J, base , &check);
+          CHECK_FAIL(err);
+          if (check == pc) {
+            if (debug) {
+              fprintf(stderr, "name_for_codecache: found matching fp/pc combo at 0x%llx\n", base - POINTER_SIZE);
+            }
+            prev_fp = base - 2 * POINTER_SIZE;
+            break;
+          }
+        }
+      }
+      if ( prev_fp != 0 ) {
+        // real_sp is the sp we should have received for this frame
+        uint64_t real_sp = prev_fp + 2 * POINTER_SIZE;
+        // +POINTER_SIZE because callee owns the return address so caller's sp is +1 word
+        jframe->new_sp = real_sp + frame_size + POINTER_SIZE;
+        err = read_pointer(J, jframe->new_sp - POINTER_SIZE , &jframe->new_pc);
+        CHECK_FAIL(err);
+        err = read_pointer(J, jframe->new_sp - 2*POINTER_SIZE, &jframe->new_fp);
+        CHECK_FAIL(err);
+        return PS_OK;
+      }
+    }
+
+    /* A prototype to workaround FP absence */
+    /*
+     * frame_size can be 0 for StubRoutines (1) frame.
+     * In this case it should work with fp as usual.
+     */
+    if (frame_size > 0) {
+      jframe->new_fp = J->prev_fr.fp + frame_size;
+      jframe->new_sp = jframe->new_fp + 2 * POINTER_SIZE;
+    } else {
+      memset(&J->curr_fr, 0, sizeof(Frame_t));
+      err = read_pointer(J,  fp, &jframe->new_fp);
+      CHECK_FAIL(err);
+
+      err = read_pointer(J,  jframe->new_fp + POINTER_SIZE,  &jframe->new_pc);
+      CHECK_FAIL(err);
+    }
+    if (debug) {
+      fprintf(stderr, "name_for_codecache: %s, frame_size=%#lx\n",
+                       result, frame_size);
+      fprintf(stderr, "name_for_codecache: prev_fr.fp=%#lx, fp=%#lx\n",
+                       J->prev_fr.fp, jframe->new_fp);
+    }
+  }
+#endif /* X86_COMPILER2 */
+
+  return PS_OK;
+
+ fail:
+  return err;
+}
+
+int Jget_vframe(jvm_agent_t* J, int vframe_no,
+                char *name, size_t size, Jframe_t *jframe)
+{
+  Nmethod_t *N = J->N;
+  Vframe_t  *vf;
+  int32_t   err;
+
+  if (vframe_no >= N->vf_cnt) {
+     (void) sprintf(name, "Wrong inlinedMethod%1d()", vframe_no);
+     return -1;
+  }
+  vf = N->vframes + vframe_no;
+  name[0] = COMP_METHOD_SIGN;
+  err = name_for_methodOop(J, vf->methodOop, name + 1, size);
+  CHECK_FAIL(err);
+
+  jframe->bci = vf->bci;
+  jframe->line = vf->line;
+  if (debug) {
+      fprintf(stderr, "\t Jget_vframe: method name: %s, line: %ld\n",
+                       name, vf->line);
+  }
+  return PS_OK;
+
+ fail:
+  if (debug) {
+      fprintf(stderr, "\t Jget_vframe: FAIL\n");
+  }
+  return err;
+}
+
+#define MAX_SYM_SIZE 256
+
+int Jlookup_by_regs(jvm_agent_t* J, const prgregset_t regs, char *name,
+                    size_t size, Jframe_t *jframe) {
+  uintptr_t fp;
+  uintptr_t pc;
+  /* arguments given to read_pointer need to be worst case sized */
+  uint64_t methodOopPtr = 0;
+  uint64_t sender_sp;
+  uint64_t bcx = 0;
+  int is_interpreted = 0;
+  int result = PS_OK;
+  int err = PS_OK;
+
+  if (J == NULL) {
+    return -1;
+  }
+
+  jframe->vf_cnt = 1;
+  jframe->new_fp = 0;
+  jframe->new_pc = 0;
+  jframe->line   = 0;
+  jframe->bci    = 0;
+  jframe->locinf = 0;
+
+  read_volatiles(J);
+  pc = (uintptr_t) regs[R_PC];
+  J->curr_fr.pc = pc;
+  J->curr_fr.fp = regs[R_FP];
+  J->curr_fr.sp = regs[R_SP];
+
+  if (debug)
+      fprintf(stderr, "Jlookup_by_regs: BEGINs: fp=%#lx, pc=%#lx\n", regs[R_FP], pc);
+
+#if defined(sparc) || defined(__sparc)
+    /* The following workaround is for SPARC. CALL instruction occupates 8 bytes.
+     * In the pcDesc structure return pc offset is recorded for CALL instructions.
+     * regs[R_PC] contains a CALL instruction pc offset.
+     */
+    pc += 8;
+    bcx          = (uintptr_t) regs[R_L1];
+    methodOopPtr = (uintptr_t) regs[R_L2];
+    sender_sp = regs[R_I5];
+    if (debug > 2) {
+        fprintf(stderr, "\nregs[R_I1]=%lx, regs[R_I2]=%lx, regs[R_I5]=%lx, regs[R_L1]=%lx, regs[R_L2]=%lx\n",
+                         regs[R_I1], regs[R_I2], regs[R_I5], regs[R_L1], regs[R_L2]);
+    }
+#elif defined(i386) || defined(__i386) || defined(__amd64)
+
+    fp = (uintptr_t) regs[R_FP];
+    if (J->prev_fr.fp == 0) {
+#ifdef X86_COMPILER2
+        /* A workaround for top java frames */
+        J->prev_fr.fp = (uintptr_t)(regs[R_SP] - 2 * POINTER_SIZE);
+#else
+        J->prev_fr.fp = (uintptr_t)(regs[R_SP] - POINTER_SIZE);
+#endif /* COMPILER2 */
+    }
+    if (debug > 2) {
+        printf("Jlookup_by_regs: J->prev_fr.fp = %#lx\n", J->prev_fr.fp);
+    }
+
+    if (read_pointer(J,  fp + OFFSET_interpreter_frame_method, &methodOopPtr) != PS_OK) {
+      methodOopPtr = 0;
+    }
+    if (read_pointer(J,  fp + OFFSET_interpreter_frame_sender_sp, &sender_sp) != PS_OK) {
+      sender_sp = 0;
+    }
+    if (read_pointer(J,  fp + OFFSET_interpreter_frame_bcx_offset, &bcx) != PS_OK) {
+      bcx = 0;
+    }
+#endif /* i386 */
+
+  J->methodOopPtr = methodOopPtr;
+  J->bcx = bcx;
+
+  /* On x86 with C2 JVM: native frame may have wrong regs[R_FP]
+   * For example: JVM_SuspendThread frame poins to the top interpreted frame.
+   * If we call is_methodOop(J, methodOopPtr) before codecache_contains(J, pc)
+   * then we go over and omit both: nmethod and I2CAdapter frames.
+   * Note, that regs[R_PC] is always correct if frame defined correctly.
+   * So it is better to call codecache_contains(J, pc) from the beginning.
+   */
+#ifndef X86_COMPILER2
+  if (is_methodOop(J, J->methodOopPtr)) {
+    result = name_for_imethod(J, bcx, J->methodOopPtr, name, size, jframe);
+    /* If the methodOopPtr is a method then this is highly likely to be
+       an interpreter frame */
+    if (result >= 0) {
+      is_interpreted = 1;
+    }
+  } else
+#endif /* ! X86_COMPILER2 */
+
+  if (codecache_contains(J, pc)) {
+    result = name_for_codecache(J, fp, pc, name, size, jframe, &is_interpreted);
+  }
+#ifdef X86_COMPILER2
+  else if (is_methodOop(J, J->methodOopPtr)) {
+    result = name_for_imethod(J, bcx, J->methodOopPtr, name, size, jframe);
+    /* If the methodOopPtr is a method then this is highly likely to be
+       an interpreter frame */
+    if (result >= 0) {
+      is_interpreted = 1;
+    }
+  }
+#endif /* X86_COMPILER2 */
+  else {
+    if (debug) {
+        fprintf(stderr, "Jlookup_by_regs: END with -1\n\n");
+    }
+    result = -1;
+  }
+  if (!is_interpreted) {
+    sender_sp = 0;
+  }
+  J->curr_fr.sender_sp = sender_sp;
+
+#ifdef X86_COMPILER2
+  if (!J->curr_fr.fp) {
+    J->curr_fr.fp = (jframe->new_fp) ? jframe->new_fp : (uintptr_t)regs[R_FP];
+  }
+  if (!jframe->new_pc && jframe->new_fp) {
+    // This seems dubious
+    read_pointer(J,  jframe->new_fp + POINTER_SIZE,  &jframe->new_pc);
+    CHECK_FAIL(err);
+    if (debug > 2) {
+        printf("Jlookup_by_regs: (update pc) jframe->new_fp: %#llx, jframe->new_pc: %#llx\n",
+               jframe->new_fp, jframe->new_pc);
+    }
+  }
+
+#endif /* X86_COMPILER2 */
+  J->prev_fr = J->curr_fr;
+
+  if (debug)
+      fprintf(stderr, "Jlookup_by_regs: END\n\n");
+
+  return result;
+
+ fail:
+  return err;
+}
+
+void update_gregs(prgregset_t gregs, Jframe_t jframe) {
+#ifdef X86_COMPILER2
+    if (debug > 0) {
+      fprintf(stderr, "update_gregs: before update sp = 0x%llx, fp = 0x%llx, pc = 0x%llx\n", gregs[R_SP], gregs[R_FP], gregs[R_PC]);
+    }
+    /*
+     * A workaround for java C2 frames with unconventional FP.
+     * may have to modify regset with new values for FP/PC/SP when needed.
+     */
+     if (jframe.new_sp) {
+         *((uintptr_t *) &gregs[R_SP]) = (uintptr_t) jframe.new_sp;
+     } else {
+         // *((uintptr_t *) &gregs[R_SP]) = (uintptr_t) gregs[R_FP] + 2 * POINTER_SIZE;
+     }
+
+     if (jframe.new_fp) {
+         *((uintptr_t *) &gregs[R_FP]) = (uintptr_t) jframe.new_fp;
+     }
+     if (jframe.new_pc) {
+         *((uintptr_t *) &gregs[R_PC]) = (uintptr_t) jframe.new_pc;
+     }
+    if (debug > 0) {
+      fprintf(stderr, "update_gregs: after update sp = 0x%llx, fp = 0x%llx, pc = 0x%llx\n", gregs[R_SP], gregs[R_FP], gregs[R_PC]);
+    }
+#endif  /* X86_COMPILER2 */
+}
+
+/*
+ * Iterates over java frames at current location given by 'gregs'.
+ *
+ *  Returns -1 if no java frames are present or if an error is encountered.
+ *  Returns the result of calling 'func' if the return value is non-zero.
+ *  Returns 0 otherwise.
+ */
+int Jframe_iter(jvm_agent_t *J, prgregset_t gregs, java_stack_f *func, void* cld) {
+    char buf[MAX_SYM_SIZE + 1];
+    Jframe_t jframe;
+    int i = 0, res;
+#ifdef X86_COMPILER2
+    if (debug > 0) {
+      fprintf(stderr, "Jframe_iter: Entry sp = 0x%llx, fp = 0x%llx, pc = 0x%llx\n", gregs[R_SP], gregs[R_FP], gregs[R_PC]);
+    }
+#endif  /* X86_COMPILER2 */
+
+    memset(&jframe, 0, sizeof(Jframe_t));
+    memset(buf, 0, sizeof(buf));
+    res =  Jlookup_by_regs(J, gregs, buf, sizeof(buf), &jframe);
+    if (res != PS_OK)
+        return (-1);
+
+
+    res = func(cld, gregs, buf, (jframe.locinf)? jframe.bci : -1,
+               jframe.line, NULL);
+    if (res != 0) {
+        update_gregs(gregs, jframe);
+        return (res);
+    }
+    for (i = 1; i < jframe.vf_cnt; i++) {
+        Jget_vframe(J, i, buf, sizeof(buf), &jframe);
+        res = func(cld, gregs, buf, (jframe.locinf)? jframe.bci : -1,
+                   jframe.line, NULL);
+        if (res != 0) {
+            update_gregs(gregs, jframe);
+            return (res);
+        }
+    }
+    update_gregs(gregs, jframe);
+    return (0);
+}
diff --git a/hotspot/src/os/bsd/dtrace/libjvm_db.h b/hotspot/src/os/bsd/dtrace/libjvm_db.h
new file mode 100644
index 0000000..f56b9d8
--- /dev/null
+++ b/hotspot/src/os/bsd/dtrace/libjvm_db.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_SOLARIS_DTRACE_LIBJVM_DB_H
+#define OS_SOLARIS_DTRACE_LIBJVM_DB_H
+
+// not available on macosx #include <proc_service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct jvm_agent jvm_agent_t;
+
+#define JVM_DB_VERSION  1
+
+jvm_agent_t *Jagent_create(struct ps_prochandle *P, int vers);
+
+/*
+ * Called from Jframe_iter() for each java frame.  If it returns 0, then
+ * Jframe_iter() proceeds to the next frame.  Otherwise, the return value is
+ * immediately returned to the caller of Jframe_iter().
+ *
+ * Parameters:
+ *    'cld' is client supplied data (to maintain iterator state, if any).
+ *    'name' is java method name.
+ *    'bci' is byte code index. it will be -1 if not available.
+ *    'line' is java source line number. it will be 0 if not available.
+ *    'handle' is an abstract client handle, reserved for future expansions
+ */
+
+typedef int java_stack_f(void *cld, const prgregset_t regs, const char* name, int bci, int line, void *handle);
+
+/*
+ * Iterates over the java frames at the current location.  Returns -1 if no java
+ * frames were found, or if there was some unrecoverable error.  Otherwise,
+ * returns the last value returned from 'func'.
+ */
+int Jframe_iter(jvm_agent_t *agent, prgregset_t gregs, java_stack_f *func, void* cld);
+
+void Jagent_destroy(jvm_agent_t *J);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* __cplusplus */
+
+#endif // OS_SOLARIS_DTRACE_LIBJVM_DB_H
diff --git a/hotspot/src/os/bsd/vm/attachListener_bsd.cpp b/hotspot/src/os/bsd/vm/attachListener_bsd.cpp
new file mode 100644
index 0000000..f742470
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/attachListener_bsd.cpp
@@ -0,0 +1,520 @@
+/*
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/interfaceSupport.hpp"
+#include "runtime/os.hpp"
+#include "services/attachListener.hpp"
+#include "services/dtraceAttacher.hpp"
+
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+
+#ifndef UNIX_PATH_MAX
+#define UNIX_PATH_MAX   sizeof(((struct sockaddr_un *)0)->sun_path)
+#endif
+
+// The attach mechanism on Bsd uses a UNIX domain socket. An attach listener
+// thread is created at startup or is created on-demand via a signal from
+// the client tool. The attach listener creates a socket and binds it to a file
+// in the filesystem. The attach listener then acts as a simple (single-
+// threaded) server - it waits for a client to connect, reads the request,
+// executes it, and returns the response to the client via the socket
+// connection.
+//
+// As the socket is a UNIX domain socket it means that only clients on the
+// local machine can connect. In addition there are two other aspects to
+// the security:
+// 1. The well known file that the socket is bound to has permission 400
+// 2. When a client connect, the SO_PEERCRED socket option is used to
+//    obtain the credentials of client. We check that the effective uid
+//    of the client matches this process.
+
+// forward reference
+class BsdAttachOperation;
+
+class BsdAttachListener: AllStatic {
+ private:
+  // the path to which we bind the UNIX domain socket
+  static char _path[UNIX_PATH_MAX];
+  static bool _has_path;
+
+  // the file descriptor for the listening socket
+  static int _listener;
+
+  static void set_path(char* path) {
+    if (path == NULL) {
+      _has_path = false;
+    } else {
+      strncpy(_path, path, UNIX_PATH_MAX);
+      _path[UNIX_PATH_MAX-1] = '\0';
+      _has_path = true;
+    }
+  }
+
+  static void set_listener(int s)               { _listener = s; }
+
+  // reads a request from the given connected socket
+  static BsdAttachOperation* read_request(int s);
+
+ public:
+  enum {
+    ATTACH_PROTOCOL_VER = 1                     // protocol version
+  };
+  enum {
+    ATTACH_ERROR_BADVERSION     = 101           // error codes
+  };
+
+  // initialize the listener, returns 0 if okay
+  static int init();
+
+  static char* path()                   { return _path; }
+  static bool has_path()                { return _has_path; }
+  static int listener()                 { return _listener; }
+
+  // write the given buffer to a socket
+  static int write_fully(int s, char* buf, int len);
+
+  static BsdAttachOperation* dequeue();
+};
+
+class BsdAttachOperation: public AttachOperation {
+ private:
+  // the connection to the client
+  int _socket;
+
+ public:
+  void complete(jint res, bufferedStream* st);
+
+  void set_socket(int s)                                { _socket = s; }
+  int socket() const                                    { return _socket; }
+
+  BsdAttachOperation(char* name) : AttachOperation(name) {
+    set_socket(-1);
+  }
+};
+
+// statics
+char BsdAttachListener::_path[UNIX_PATH_MAX];
+bool BsdAttachListener::_has_path;
+int BsdAttachListener::_listener = -1;
+
+// Supporting class to help split a buffer into individual components
+class ArgumentIterator : public StackObj {
+ private:
+  char* _pos;
+  char* _end;
+ public:
+  ArgumentIterator(char* arg_buffer, size_t arg_size) {
+    _pos = arg_buffer;
+    _end = _pos + arg_size - 1;
+  }
+  char* next() {
+    if (*_pos == '\0') {
+      return NULL;
+    }
+    char* res = _pos;
+    char* next_pos = strchr(_pos, '\0');
+    if (next_pos < _end)  {
+      next_pos++;
+    }
+    _pos = next_pos;
+    return res;
+  }
+};
+
+
+// atexit hook to stop listener and unlink the file that it is
+// bound too.
+extern "C" {
+  static void listener_cleanup() {
+    static int cleanup_done;
+    if (!cleanup_done) {
+      cleanup_done = 1;
+      int s = BsdAttachListener::listener();
+      if (s != -1) {
+        ::close(s);
+      }
+      if (BsdAttachListener::has_path()) {
+        ::unlink(BsdAttachListener::path());
+      }
+    }
+  }
+}
+
+// Initialization - create a listener socket and bind it to a file
+
+int BsdAttachListener::init() {
+  char path[UNIX_PATH_MAX];          // socket file
+  char initial_path[UNIX_PATH_MAX];  // socket file during setup
+  int listener;                      // listener socket (file descriptor)
+
+  // register function to cleanup
+  ::atexit(listener_cleanup);
+
+  int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
+                   os::get_temp_directory(), os::current_process_id());
+  if (n < (int)UNIX_PATH_MAX) {
+    n = snprintf(initial_path, UNIX_PATH_MAX, "%s.tmp", path);
+  }
+  if (n >= (int)UNIX_PATH_MAX) {
+    return -1;
+  }
+
+  // create the listener socket
+  listener = ::socket(PF_UNIX, SOCK_STREAM, 0);
+  if (listener == -1) {
+    return -1;
+  }
+
+  // bind socket
+  struct sockaddr_un addr;
+  addr.sun_family = AF_UNIX;
+  strcpy(addr.sun_path, initial_path);
+  ::unlink(initial_path);
+  int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
+  if (res == -1) {
+    RESTARTABLE(::close(listener), res);
+    return -1;
+  }
+
+  // put in listen mode, set permissions, and rename into place
+  res = ::listen(listener, 5);
+  if (res == 0) {
+      RESTARTABLE(::chmod(initial_path, S_IREAD|S_IWRITE), res);
+      if (res == 0) {
+          res = ::rename(initial_path, path);
+      }
+  }
+  if (res == -1) {
+    RESTARTABLE(::close(listener), res);
+    ::unlink(initial_path);
+    return -1;
+  }
+  set_path(path);
+  set_listener(listener);
+
+  return 0;
+}
+
+// Given a socket that is connected to a peer we read the request and
+// create an AttachOperation. As the socket is blocking there is potential
+// for a denial-of-service if the peer does not response. However this happens
+// after the peer credentials have been checked and in the worst case it just
+// means that the attach listener thread is blocked.
+//
+BsdAttachOperation* BsdAttachListener::read_request(int s) {
+  char ver_str[8];
+  sprintf(ver_str, "%d", ATTACH_PROTOCOL_VER);
+
+  // The request is a sequence of strings so we first figure out the
+  // expected count and the maximum possible length of the request.
+  // The request is:
+  //   <ver>0<cmd>0<arg>0<arg>0<arg>0
+  // where <ver> is the protocol version (1), <cmd> is the command
+  // name ("load", "datadump", ...), and <arg> is an argument
+  int expected_str_count = 2 + AttachOperation::arg_count_max;
+  const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
+    AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);
+
+  char buf[max_len];
+  int str_count = 0;
+
+  // Read until all (expected) strings have been read, the buffer is
+  // full, or EOF.
+
+  int off = 0;
+  int left = max_len;
+
+  do {
+    int n;
+    RESTARTABLE(read(s, buf+off, left), n);
+    if (n == -1) {
+      return NULL;      // reset by peer or other error
+    }
+    if (n == 0) {
+      break;
+    }
+    for (int i=0; i<n; i++) {
+      if (buf[off+i] == 0) {
+        // EOS found
+        str_count++;
+
+        // The first string is <ver> so check it now to
+        // check for protocol mis-match
+        if (str_count == 1) {
+          if ((strlen(buf) != strlen(ver_str)) ||
+              (atoi(buf) != ATTACH_PROTOCOL_VER)) {
+            char msg[32];
+            sprintf(msg, "%d\n", ATTACH_ERROR_BADVERSION);
+            write_fully(s, msg, strlen(msg));
+            return NULL;
+          }
+        }
+      }
+    }
+    off += n;
+    left -= n;
+  } while (left > 0 && str_count < expected_str_count);
+
+  if (str_count != expected_str_count) {
+    return NULL;        // incomplete request
+  }
+
+  // parse request
+
+  ArgumentIterator args(buf, (max_len)-left);
+
+  // version already checked
+  char* v = args.next();
+
+  char* name = args.next();
+  if (name == NULL || strlen(name) > AttachOperation::name_length_max) {
+    return NULL;
+  }
+
+  BsdAttachOperation* op = new BsdAttachOperation(name);
+
+  for (int i=0; i<AttachOperation::arg_count_max; i++) {
+    char* arg = args.next();
+    if (arg == NULL) {
+      op->set_arg(i, NULL);
+    } else {
+      if (strlen(arg) > AttachOperation::arg_length_max) {
+        delete op;
+        return NULL;
+      }
+      op->set_arg(i, arg);
+    }
+  }
+
+  op->set_socket(s);
+  return op;
+}
+
+
+// Dequeue an operation
+//
+// In the Bsd implementation there is only a single operation and clients
+// cannot queue commands (except at the socket level).
+//
+BsdAttachOperation* BsdAttachListener::dequeue() {
+  for (;;) {
+    int s;
+
+    // wait for client to connect
+    struct sockaddr addr;
+    socklen_t len = sizeof(addr);
+    RESTARTABLE(::accept(listener(), &addr, &len), s);
+    if (s == -1) {
+      return NULL;      // log a warning?
+    }
+
+    // get the credentials of the peer and check the effective uid/guid
+    // - check with jeff on this.
+#ifdef _ALLBSD_SOURCE
+    uid_t puid;
+    gid_t pgid;
+    if (::getpeereid(s, &puid, &pgid) != 0) {
+      int res;
+      RESTARTABLE(::close(s), res);
+      continue;
+    }
+#else
+    struct ucred cred_info;
+    socklen_t optlen = sizeof(cred_info);
+    if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) {
+      int res;
+      RESTARTABLE(::close(s), res);
+      continue;
+    }
+    uid_t puid = cred_info.uid;
+    gid_t pgid = cred_info.gid;
+#endif
+    uid_t euid = geteuid();
+    gid_t egid = getegid();
+
+    if (puid != euid || pgid != egid) {
+      int res;
+      RESTARTABLE(::close(s), res);
+      continue;
+    }
+
+    // peer credential look okay so we read the request
+    BsdAttachOperation* op = read_request(s);
+    if (op == NULL) {
+      int res;
+      RESTARTABLE(::close(s), res);
+      continue;
+    } else {
+      return op;
+    }
+  }
+}
+
+// write the given buffer to the socket
+int BsdAttachListener::write_fully(int s, char* buf, int len) {
+  do {
+    int n = ::write(s, buf, len);
+    if (n == -1) {
+      if (errno != EINTR) return -1;
+    } else {
+      buf += n;
+      len -= n;
+    }
+  }
+  while (len > 0);
+  return 0;
+}
+
+// Complete an operation by sending the operation result and any result
+// output to the client. At this time the socket is in blocking mode so
+// potentially we can block if there is a lot of data and the client is
+// non-responsive. For most operations this is a non-issue because the
+// default send buffer is sufficient to buffer everything. In the future
+// if there are operations that involves a very big reply then it the
+// socket could be made non-blocking and a timeout could be used.
+
+void BsdAttachOperation::complete(jint result, bufferedStream* st) {
+  JavaThread* thread = JavaThread::current();
+  ThreadBlockInVM tbivm(thread);
+
+  thread->set_suspend_equivalent();
+  // cleared by handle_special_suspend_equivalent_condition() or
+  // java_suspend_self() via check_and_wait_while_suspended()
+
+  // write operation result
+  char msg[32];
+  sprintf(msg, "%d\n", result);
+  int rc = BsdAttachListener::write_fully(this->socket(), msg, strlen(msg));
+
+  // write any result data
+  if (rc == 0) {
+    BsdAttachListener::write_fully(this->socket(), (char*) st->base(), st->size());
+    ::shutdown(this->socket(), 2);
+  }
+
+  // done
+  RESTARTABLE(::close(this->socket()), rc);
+
+  // were we externally suspended while we were waiting?
+  thread->check_and_wait_while_suspended();
+
+  delete this;
+}
+
+
+// AttachListener functions
+
+AttachOperation* AttachListener::dequeue() {
+  JavaThread* thread = JavaThread::current();
+  ThreadBlockInVM tbivm(thread);
+
+  thread->set_suspend_equivalent();
+  // cleared by handle_special_suspend_equivalent_condition() or
+  // java_suspend_self() via check_and_wait_while_suspended()
+
+  AttachOperation* op = BsdAttachListener::dequeue();
+
+  // were we externally suspended while we were waiting?
+  thread->check_and_wait_while_suspended();
+
+  return op;
+}
+
+int AttachListener::pd_init() {
+  JavaThread* thread = JavaThread::current();
+  ThreadBlockInVM tbivm(thread);
+
+  thread->set_suspend_equivalent();
+  // cleared by handle_special_suspend_equivalent_condition() or
+  // java_suspend_self() via check_and_wait_while_suspended()
+
+  int ret_code = BsdAttachListener::init();
+
+  // were we externally suspended while we were waiting?
+  thread->check_and_wait_while_suspended();
+
+  return ret_code;
+}
+
+// Attach Listener is started lazily except in the case when
+// +ReduseSignalUsage is used
+bool AttachListener::init_at_startup() {
+  if (ReduceSignalUsage) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
+// If the file .attach_pid<pid> exists in the working directory
+// or /tmp then this is the trigger to start the attach mechanism
+bool AttachListener::is_init_trigger() {
+  if (init_at_startup() || is_initialized()) {
+    return false;               // initialized at startup or already initialized
+  }
+  char path[PATH_MAX + 1];
+  int ret;
+  struct stat st;
+
+  snprintf(path, PATH_MAX + 1, "%s/.attach_pid%d",
+           os::get_temp_directory(), os::current_process_id());
+  RESTARTABLE(::stat(path, &st), ret);
+  if (ret == 0) {
+    // simple check to avoid starting the attach mechanism when
+    // a bogus user creates the file
+    if (st.st_uid == geteuid()) {
+      init();
+      return true;
+    }
+  }
+  return false;
+}
+
+// if VM aborts then remove listener
+void AttachListener::abort() {
+  listener_cleanup();
+}
+
+void AttachListener::pd_data_dump() {
+  os::signal_notify(SIGQUIT);
+}
+
+AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
+  return NULL;
+}
+
+jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
+  out->print_cr("flag '%s' cannot be changed", op->arg(0));
+  return JNI_ERR;
+}
+
+void AttachListener::pd_detachall() {
+  // do nothing for now
+}
diff --git a/hotspot/src/os/bsd/vm/c1_globals_bsd.hpp b/hotspot/src/os/bsd/vm/c1_globals_bsd.hpp
new file mode 100644
index 0000000..27e26af
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/c1_globals_bsd.hpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_C1_GLOBALS_BSD_HPP
+#define OS_BSD_VM_C1_GLOBALS_BSD_HPP
+
+#include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
+
+//
+// Sets the default values for operating system dependent flags used by the
+// client compiler. (see c1_globals.hpp)
+//
+
+#endif // OS_BSD_VM_C1_GLOBALS_BSD_HPP
diff --git a/hotspot/src/os/bsd/vm/c2_globals_bsd.hpp b/hotspot/src/os/bsd/vm/c2_globals_bsd.hpp
new file mode 100644
index 0000000..21737f1
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/c2_globals_bsd.hpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_C2_GLOBALS_BSD_HPP
+#define OS_BSD_VM_C2_GLOBALS_BSD_HPP
+
+#include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
+
+//
+// Sets the default values for operating system dependent flags used by the
+// server compiler. (see c2_globals.hpp)
+//
+
+#endif // OS_BSD_VM_C2_GLOBALS_BSD_HPP
diff --git a/hotspot/src/os/bsd/vm/chaitin_bsd.cpp b/hotspot/src/os/bsd/vm/chaitin_bsd.cpp
new file mode 100644
index 0000000..e492564
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/chaitin_bsd.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "opto/chaitin.hpp"
+#include "opto/machnode.hpp"
+
+void PhaseRegAlloc::pd_preallocate_hook() {
+  // no action
+}
+
+#ifdef ASSERT
+void PhaseRegAlloc::pd_postallocate_verify_hook() {
+  // no action
+}
+#endif
+
+
+// Reconciliation History
+// chaitin_solaris.cpp  1.7 99/07/12 23:54:22
+// End
diff --git a/hotspot/src/os/bsd/vm/decoder_bsd.cpp b/hotspot/src/os/bsd/vm/decoder_bsd.cpp
new file mode 100644
index 0000000..dd95929
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/decoder_bsd.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "prims/jvm.h"
+#include "utilities/decoder.hpp"
+
+#include <cxxabi.h>
+
+#ifdef __APPLE__
+
+void Decoder::initialize() {
+  _initialized = true;
+}
+
+void Decoder::uninitialize() {
+  _initialized = false;
+}
+
+bool Decoder::can_decode_C_frame_in_vm() {
+  return false;
+}
+
+Decoder::decoder_status Decoder::decode(address addr, const char* filepath, char *buf, int buflen, int *offset) {
+  return symbol_not_found;
+}
+
+
+#endif
+
+bool Decoder::demangle(const char* symbol, char *buf, int buflen) {
+  int   status;
+  char* result;
+  size_t size = (size_t)buflen;
+
+  // Don't pass buf to __cxa_demangle. In case of the 'buf' is too small,
+  // __cxa_demangle will call system "realloc" for additional memory, which
+  // may use different malloc/realloc mechanism that allocates 'buf'.
+  if ((result = abi::__cxa_demangle(symbol, NULL, NULL, &status)) != NULL) {
+    jio_snprintf(buf, buflen, "%s", result);
+      // call c library's free
+      ::free(result);
+      return true;
+  }
+  return false;
+}
diff --git a/hotspot/src/os/bsd/vm/dtraceJSDT_bsd.cpp b/hotspot/src/os/bsd/vm/dtraceJSDT_bsd.cpp
new file mode 100644
index 0000000..d6c091b1
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/dtraceJSDT_bsd.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "classfile/javaClasses.hpp"
+#include "code/codeBlob.hpp"
+#include "memory/allocation.hpp"
+#include "prims/jvm.h"
+#include "runtime/dtraceJSDT.hpp"
+#include "runtime/jniHandles.hpp"
+#include "runtime/os.hpp"
+#include "runtime/signature.hpp"
+#include "utilities/globalDefinitions.hpp"
+
+/*
+ * JSDT java dtrace probes have never been implemented in macosx.  It is unknown if the solaris implementation
+ * is close or if significant implementation work is necessary.  The future of the solaris implementation also
+ * appears to be unclear since compiling code with JSDT probes produces the following warning:
+ * "warning: ProviderFactory is internal proprietary API and may be removed in a future release"
+ */
+
+int DTraceJSDT::pd_activate(
+    void* baseAddress, jstring module,
+    jint providers_count, JVM_DTraceProvider* providers) {
+  return -1;
+}
+
+void DTraceJSDT::pd_dispose(int handle) {
+}
+
+jboolean DTraceJSDT::pd_is_supported() {
+  return false;
+}
diff --git a/hotspot/src/os/bsd/vm/globals_bsd.hpp b/hotspot/src/os/bsd/vm/globals_bsd.hpp
new file mode 100644
index 0000000..213f470
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/globals_bsd.hpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_GLOBALS_BSD_HPP
+#define OS_BSD_VM_GLOBALS_BSD_HPP
+
+//
+// Defines Bsd specific flags. They are not available on other platforms.
+//
+#define RUNTIME_OS_FLAGS(develop, develop_pd, product, product_pd, diagnostic, notproduct) \
+  product(bool, UseOprofile, false,                                     \
+        "enable support for Oprofile profiler")                         \
+                                                                        \
+  product(bool, UseBsdPosixThreadCPUClocks, true,                     \
+          "enable fast Bsd Posix clocks where available")             \
+/*  NB: The default value of UseBsdPosixThreadCPUClocks may be        \
+    overridden in Arguments::parse_each_vm_init_arg.  */                \
+                                                                        \
+  product(bool, UseHugeTLBFS, false,                                    \
+          "Use MAP_HUGETLB for large pages")                            \
+                                                                        \
+  product(bool, UseSHM, false,                                          \
+          "Use SYSV shared memory for large pages")
+
+//
+// Defines Bsd-specific default values. The flags are available on all
+// platforms, but they may have different default values on other platforms.
+//
+define_pd_global(bool, UseLargePages, false);
+define_pd_global(bool, UseLargePagesIndividualAllocation, false);
+define_pd_global(bool, UseOSErrorReporting, false);
+define_pd_global(bool, UseThreadPriorities, true) ;
+
+#endif // OS_BSD_VM_GLOBALS_BSD_HPP
diff --git a/hotspot/src/os/bsd/vm/interfaceSupport_bsd.hpp b/hotspot/src/os/bsd/vm/interfaceSupport_bsd.hpp
new file mode 100644
index 0000000..795bf4d
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/interfaceSupport_bsd.hpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_INTERFACESUPPORT_BSD_HPP
+#define OS_BSD_VM_INTERFACESUPPORT_BSD_HPP
+
+// Contains inlined functions for class InterfaceSupport
+
+static inline void serialize_memory(JavaThread *thread) {
+  os::write_memory_serialize_page(thread);
+}
+
+#endif // OS_BSD_VM_INTERFACESUPPORT_BSD_HPP
diff --git a/hotspot/src/os/bsd/vm/jsig.c b/hotspot/src/os/bsd/vm/jsig.c
new file mode 100644
index 0000000..a8d98a0
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/jsig.c
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/* CopyrightVersion 1.2 */
+
+/* This is a special library that should be loaded before libc &
+ * libthread to interpose the signal handler installation functions:
+ * sigaction(), signal(), sigset().
+ * Used for signal-chaining. See RFE 4381843.
+ */
+
+#include <signal.h>
+#include <dlfcn.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#define MAXSIGNUM 32
+#define MASK(sig) ((unsigned int)1 << sig)
+
+static struct sigaction sact[MAXSIGNUM]; /* saved signal handlers */
+static unsigned int jvmsigs = 0; /* signals used by jvm */
+
+/* used to synchronize the installation of signal handlers */
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_t tid = 0;
+
+typedef void (*sa_handler_t)(int);
+typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
+typedef sa_handler_t (*signal_t)(int, sa_handler_t);
+typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
+
+static signal_t os_signal = 0; /* os's version of signal()/sigset() */
+static sigaction_t os_sigaction = 0; /* os's version of sigaction() */
+
+static bool jvm_signal_installing = false;
+static bool jvm_signal_installed = false;
+
+static void signal_lock() {
+  pthread_mutex_lock(&mutex);
+  /* When the jvm is installing its set of signal handlers, threads
+   * other than the jvm thread should wait */
+  if (jvm_signal_installing) {
+    if (tid != pthread_self()) {
+      pthread_cond_wait(&cond, &mutex);
+    }
+  }
+}
+
+static void signal_unlock() {
+  pthread_mutex_unlock(&mutex);
+}
+
+static sa_handler_t call_os_signal(int sig, sa_handler_t disp,
+                                   bool is_sigset) {
+  if (os_signal == NULL) {
+    if (!is_sigset) {
+      os_signal = (signal_t)dlsym(RTLD_NEXT, "signal");
+    } else {
+      os_signal = (signal_t)dlsym(RTLD_NEXT, "sigset");
+    }
+    if (os_signal == NULL) {
+      printf("%s\n", dlerror());
+      exit(0);
+    }
+  }
+  return (*os_signal)(sig, disp);
+}
+
+static void save_signal_handler(int sig, sa_handler_t disp) {
+  sigset_t set;
+  sact[sig].sa_handler = disp;
+  sigemptyset(&set);
+  sact[sig].sa_mask = set;
+  sact[sig].sa_flags = 0;
+}
+
+static sa_handler_t set_signal(int sig, sa_handler_t disp, bool is_sigset) {
+  sa_handler_t oldhandler;
+  bool sigused;
+
+  signal_lock();
+
+  sigused = (MASK(sig) & jvmsigs) != 0;
+  if (jvm_signal_installed && sigused) {
+    /* jvm has installed its signal handler for this signal. */
+    /* Save the handler. Don't really install it. */
+    oldhandler = sact[sig].sa_handler;
+    save_signal_handler(sig, disp);
+
+    signal_unlock();
+    return oldhandler;
+  } else if (jvm_signal_installing) {
+    /* jvm is installing its signal handlers. Install the new
+     * handlers and save the old ones. jvm uses sigaction().
+     * Leave the piece here just in case. */
+    oldhandler = call_os_signal(sig, disp, is_sigset);
+    save_signal_handler(sig, oldhandler);
+
+    /* Record the signals used by jvm */
+    jvmsigs |= MASK(sig);
+
+    signal_unlock();
+    return oldhandler;
+  } else {
+    /* jvm has no relation with this signal (yet). Install the
+     * the handler. */
+    oldhandler = call_os_signal(sig, disp, is_sigset);
+
+    signal_unlock();
+    return oldhandler;
+  }
+}
+
+sa_handler_t signal(int sig, sa_handler_t disp) {
+  return set_signal(sig, disp, false);
+}
+
+sa_handler_t sigset(int sig, sa_handler_t disp) {
+  printf("sigset() is not supported by BSD");
+  exit(0);
+ }
+
+static int call_os_sigaction(int sig, const struct sigaction  *act,
+                             struct sigaction *oact) {
+  if (os_sigaction == NULL) {
+    os_sigaction = (sigaction_t)dlsym(RTLD_NEXT, "sigaction");
+    if (os_sigaction == NULL) {
+      printf("%s\n", dlerror());
+      exit(0);
+    }
+  }
+  return (*os_sigaction)(sig, act, oact);
+}
+
+int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
+  int res;
+  bool sigused;
+  struct sigaction oldAct;
+
+  signal_lock();
+
+  sigused = (MASK(sig) & jvmsigs) != 0;
+  if (jvm_signal_installed && sigused) {
+    /* jvm has installed its signal handler for this signal. */
+    /* Save the handler. Don't really install it. */
+    if (oact != NULL) {
+      *oact = sact[sig];
+    }
+    if (act != NULL) {
+      sact[sig] = *act;
+    }
+
+    signal_unlock();
+    return 0;
+  } else if (jvm_signal_installing) {
+    /* jvm is installing its signal handlers. Install the new
+     * handlers and save the old ones. */
+    res = call_os_sigaction(sig, act, &oldAct);
+    sact[sig] = oldAct;
+    if (oact != NULL) {
+      *oact = oldAct;
+    }
+
+    /* Record the signals used by jvm */
+    jvmsigs |= MASK(sig);
+
+    signal_unlock();
+    return res;
+  } else {
+    /* jvm has no relation with this signal (yet). Install the
+     * the handler. */
+    res = call_os_sigaction(sig, act, oact);
+
+    signal_unlock();
+    return res;
+  }
+}
+
+/* The three functions for the jvm to call into */
+void JVM_begin_signal_setting() {
+  signal_lock();
+  jvm_signal_installing = true;
+  tid = pthread_self();
+  signal_unlock();
+}
+
+void JVM_end_signal_setting() {
+  signal_lock();
+  jvm_signal_installed = true;
+  jvm_signal_installing = false;
+  pthread_cond_broadcast(&cond);
+  signal_unlock();
+}
+
+struct sigaction *JVM_get_signal_action(int sig) {
+  /* Does race condition make sense here? */
+  if ((MASK(sig) & jvmsigs) != 0) {
+    return &sact[sig];
+  }
+  return NULL;
+}
diff --git a/hotspot/src/os/bsd/vm/jvm_bsd.cpp b/hotspot/src/os/bsd/vm/jvm_bsd.cpp
new file mode 100644
index 0000000..a828631
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/jvm_bsd.cpp
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "prims/jvm.h"
+#include "runtime/interfaceSupport.hpp"
+#include "runtime/osThread.hpp"
+
+#include <signal.h>
+
+
+// sun.misc.Signal ///////////////////////////////////////////////////////////
+// Signal code is mostly copied from classic vm, signals_md.c   1.4 98/08/23
+/*
+ * This function is included primarily as a debugging aid. If Java is
+ * running in a console window, then pressing <CTRL-\\> will cause
+ * the current state of all active threads and monitors to be written
+ * to the console window.
+ */
+
+JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
+  // Copied from classic vm
+  // signals_md.c       1.4 98/08/23
+  void* newHandler = handler == (void *)2
+                   ? os::user_handler()
+                   : handler;
+  switch (sig) {
+    /* The following are already used by the VM. */
+    case INTERRUPT_SIGNAL:
+    case SIGFPE:
+    case SIGILL:
+    case SIGSEGV:
+
+    /* The following signal is used by the VM to dump thread stacks unless
+       ReduceSignalUsage is set, in which case the user is allowed to set
+       his own _native_ handler for this signal; thus, in either case,
+       we do not allow JVM_RegisterSignal to change the handler. */
+    case BREAK_SIGNAL:
+      return (void *)-1;
+
+    /* The following signals are used for Shutdown Hooks support. However, if
+       ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
+       System.exit(), Java is not allowed to use these signals, and the the
+       user is allowed to set his own _native_ handler for these signals and
+       invoke System.exit() as needed. Terminator.setup() is avoiding
+       registration of these signals when -Xrs is present.
+       - If the HUP signal is ignored (from the nohup) command, then Java
+         is not allowed to use this signal.
+     */
+
+    case SHUTDOWN1_SIGNAL:
+    case SHUTDOWN2_SIGNAL:
+    case SHUTDOWN3_SIGNAL:
+      if (ReduceSignalUsage) return (void*)-1;
+      if (os::Bsd::is_sig_ignored(sig)) return (void*)1;
+  }
+
+  void* oldHandler = os::signal(sig, newHandler);
+  if (oldHandler == os::user_handler()) {
+      return (void *)2;
+  } else {
+      return oldHandler;
+  }
+JVM_END
+
+
+JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
+  if (ReduceSignalUsage) {
+    // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,
+    // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since
+    // no handler for them is actually registered in JVM or via
+    // JVM_RegisterSignal.
+    if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
+        sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {
+      return JNI_FALSE;
+    }
+  }
+  else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
+            sig == SHUTDOWN3_SIGNAL) && os::Bsd::is_sig_ignored(sig)) {
+    // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL
+    // is ignored, since no handler for them is actually registered in JVM
+    // or via JVM_RegisterSignal.
+    // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL
+    return JNI_FALSE;
+  }
+
+  os::signal_raise(sig);
+  return JNI_TRUE;
+JVM_END
+
+/*
+  All the defined signal names for Bsd.
+
+  NOTE that not all of these names are accepted by our Java implementation
+
+  Via an existing claim by the VM, sigaction restrictions, or
+  the "rules of Unix" some of these names will be rejected at runtime.
+  For example the VM sets up to handle USR1, sigaction returns EINVAL for
+  STOP, and Bsd simply doesn't allow catching of KILL.
+
+  Here are the names currently accepted by a user of sun.misc.Signal with
+  1.4.1 (ignoring potential interaction with use of chaining, etc):
+
+    HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT,
+    CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF,
+    WINCH, POLL, IO, PWR, SYS
+
+*/
+
+struct siglabel {
+  const char *name;
+  int   number;
+};
+
+struct siglabel siglabels[] = {
+  /* derived from /usr/include/bits/signum.h on RH7.2 */
+   "HUP",       SIGHUP,         /* Hangup (POSIX).  */
+  "INT",        SIGINT,         /* Interrupt (ANSI).  */
+  "QUIT",       SIGQUIT,        /* Quit (POSIX).  */
+  "ILL",        SIGILL,         /* Illegal instruction (ANSI).  */
+  "TRAP",       SIGTRAP,        /* Trace trap (POSIX).  */
+  "ABRT",       SIGABRT,        /* Abort (ANSI).  */
+  "EMT",        SIGEMT,         /* EMT trap  */
+  "FPE",        SIGFPE,         /* Floating-point exception (ANSI).  */
+  "KILL",       SIGKILL,        /* Kill, unblockable (POSIX).  */
+  "BUS",        SIGBUS,         /* BUS error (4.2 BSD).  */
+  "SEGV",       SIGSEGV,        /* Segmentation violation (ANSI).  */
+  "SYS",        SIGSYS,         /* Bad system call. Only on some Bsden! */
+  "PIPE",       SIGPIPE,        /* Broken pipe (POSIX).  */
+  "ALRM",       SIGALRM,        /* Alarm clock (POSIX).  */
+  "TERM",       SIGTERM,        /* Termination (ANSI).  */
+  "URG",        SIGURG,         /* Urgent condition on socket (4.2 BSD).  */
+  "STOP",       SIGSTOP,        /* Stop, unblockable (POSIX).  */
+  "TSTP",       SIGTSTP,        /* Keyboard stop (POSIX).  */
+  "CONT",       SIGCONT,        /* Continue (POSIX).  */
+  "CHLD",       SIGCHLD,        /* Child status has changed (POSIX).  */
+  "TTIN",       SIGTTIN,        /* Background read from tty (POSIX).  */
+  "TTOU",       SIGTTOU,        /* Background write to tty (POSIX).  */
+  "IO",         SIGIO,          /* I/O now possible (4.2 BSD).  */
+  "XCPU",       SIGXCPU,        /* CPU limit exceeded (4.2 BSD).  */
+  "XFSZ",       SIGXFSZ,        /* File size limit exceeded (4.2 BSD).  */
+  "VTALRM",     SIGVTALRM,      /* Virtual alarm clock (4.2 BSD).  */
+  "PROF",       SIGPROF,        /* Profiling alarm clock (4.2 BSD).  */
+  "WINCH",      SIGWINCH,       /* Window size change (4.3 BSD, Sun).  */
+  "INFO",       SIGINFO,        /* Information request.  */
+  "USR1",       SIGUSR1,        /* User-defined signal 1 (POSIX).  */
+  "USR2",       SIGUSR2         /* User-defined signal 2 (POSIX).  */
+  };
+
+JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
+
+  /* find and return the named signal's number */
+
+  for(uint i=0; i<ARRAY_SIZE(siglabels); i++)
+    if(!strcmp(name, siglabels[i].name))
+      return siglabels[i].number;
+
+  return -1;
+
+JVM_END
+
+// used by os::exception_name()
+extern bool signal_name(int signo, char* buf, size_t len) {
+  for(uint i = 0; i < ARRAY_SIZE(siglabels); i++) {
+    if (signo == siglabels[i].number) {
+      jio_snprintf(buf, len, "SIG%s", siglabels[i].name);
+      return true;
+    }
+  }
+  return false;
+}
diff --git a/hotspot/src/os/bsd/vm/jvm_bsd.h b/hotspot/src/os/bsd/vm/jvm_bsd.h
new file mode 100644
index 0000000..5f96410
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/jvm_bsd.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_JVM_BSD_H
+#define OS_BSD_VM_JVM_BSD_H
+
+/*
+// HotSpot integration note:
+//
+// This is derived from the JDK classic file:
+// "$JDK/src/solaris/javavm/export/jvm_md.h":15 (ver. 1.10 98/04/22)
+// All local includes have been commented out.
+*/
+
+
+#ifndef JVM_MD_H
+#define JVM_MD_H
+
+/*
+ * This file is currently collecting system-specific dregs for the
+ * JNI conversion, which should be sorted out later.
+ */
+#ifdef __NetBSD__
+/*
+ * Since we are compiling with c++, we need the following to make c macros
+ * visible.
+ */
+# if !defined(__STDC_LIMIT_MACROS)
+#  define __STDC_LIMIT_MACROS           1
+# endif
+# if !defined(__STDC_CONSTANT_MACROS)
+#  define __STDC_CONSTANT_MACROS        1
+# endif
+# if !defined(__STDC_FORMAT_MACROS)
+#  define __STDC_FORMAT_MACROS          1
+# endif
+#endif
+
+#include <dirent.h>             /* For DIR */
+#include <sys/param.h>          /* For MAXPATHLEN */
+#include <unistd.h>             /* For F_OK, R_OK, W_OK */
+
+#define JNI_ONLOAD_SYMBOLS      {"JNI_OnLoad"}
+#define JNI_ONUNLOAD_SYMBOLS    {"JNI_OnUnload"}
+#define JVM_ONLOAD_SYMBOLS      {"JVM_OnLoad"}
+#define AGENT_ONLOAD_SYMBOLS    {"Agent_OnLoad"}
+#define AGENT_ONUNLOAD_SYMBOLS  {"Agent_OnUnload"}
+#define AGENT_ONATTACH_SYMBOLS  {"Agent_OnAttach"}
+
+#define JNI_LIB_PREFIX "lib"
+#ifdef __APPLE__
+#define JNI_LIB_SUFFIX ".dylib"
+#else
+#define JNI_LIB_SUFFIX ".so"
+#endif
+
+// Hack: MAXPATHLEN is 4095 on some Bsd and 4096 on others. This may
+//       cause problems if JVM and the rest of JDK are built on different
+//       Bsd releases. Here we define JVM_MAXPATHLEN to be MAXPATHLEN + 1,
+//       so buffers declared in VM are always >= 4096.
+#define JVM_MAXPATHLEN MAXPATHLEN + 1
+
+#define JVM_R_OK    R_OK
+#define JVM_W_OK    W_OK
+#define JVM_X_OK    X_OK
+#define JVM_F_OK    F_OK
+
+/*
+ * File I/O
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+/* O Flags */
+
+#define JVM_O_RDONLY     O_RDONLY
+#define JVM_O_WRONLY     O_WRONLY
+#define JVM_O_RDWR       O_RDWR
+#define JVM_O_O_APPEND   O_APPEND
+#define JVM_O_EXCL       O_EXCL
+#define JVM_O_CREAT      O_CREAT
+
+/* Signal definitions */
+
+#define BREAK_SIGNAL     SIGQUIT           /* Thread dumping support.    */
+#define INTERRUPT_SIGNAL SIGUSR1           /* Interruptible I/O support. */
+#define SHUTDOWN1_SIGNAL SIGHUP            /* Shutdown Hooks support.    */
+#define SHUTDOWN2_SIGNAL SIGINT
+#define SHUTDOWN3_SIGNAL SIGTERM
+
+#ifndef SIGRTMIN
+#ifdef __OpenBSD__
+#define SIGRTMIN        1
+#else
+#define SIGRTMIN        33
+#endif
+#endif
+#ifndef SIGRTMAX
+#ifdef __OpenBSD__
+#define SIGRTMAX        31
+#else
+#define SIGRTMAX        63
+#endif
+#endif
+#endif /* JVM_MD_H */
+
+// Reconciliation History
+// jvm_solaris.h        1.6 99/06/22 16:38:47
+// End
+
+#endif // OS_BSD_VM_JVM_BSD_H
diff --git a/hotspot/src/os/bsd/vm/mutex_bsd.cpp b/hotspot/src/os/bsd/vm/mutex_bsd.cpp
new file mode 100644
index 0000000..f39482e
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/mutex_bsd.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "mutex_bsd.inline.hpp"
+#include "runtime/interfaceSupport.hpp"
+#include "runtime/mutex.hpp"
+#include "thread_bsd.inline.hpp"
+#include "utilities/events.hpp"
+
+// put OS-includes here
+# include <signal.h>
diff --git a/hotspot/src/os/bsd/vm/mutex_bsd.inline.hpp b/hotspot/src/os/bsd/vm/mutex_bsd.inline.hpp
new file mode 100644
index 0000000..f75267f
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/mutex_bsd.inline.hpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_MUTEX_BSD_INLINE_HPP
+#define OS_BSD_VM_MUTEX_BSD_INLINE_HPP
+
+#include "os_bsd.inline.hpp"
+#include "runtime/interfaceSupport.hpp"
+#include "thread_bsd.inline.hpp"
+
+
+// Reconciliation History
+// mutex_solaris.inline.hpp     1.5 99/06/22 16:38:49
+// End
+
+#endif // OS_BSD_VM_MUTEX_BSD_INLINE_HPP
diff --git a/hotspot/src/os/bsd/vm/osThread_bsd.cpp b/hotspot/src/os/bsd/vm/osThread_bsd.cpp
new file mode 100644
index 0000000..efac803
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/osThread_bsd.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+// no precompiled headers
+#include "runtime/atomic.hpp"
+#include "runtime/handles.inline.hpp"
+#include "runtime/mutexLocker.hpp"
+#include "runtime/os.hpp"
+#include "runtime/osThread.hpp"
+#include "runtime/safepoint.hpp"
+#include "runtime/vmThread.hpp"
+#ifdef TARGET_ARCH_x86
+# include "assembler_x86.inline.hpp"
+#endif
+#ifdef TARGET_ARCH_sparc
+# include "assembler_sparc.inline.hpp"
+#endif
+#ifdef TARGET_ARCH_zero
+# include "assembler_zero.inline.hpp"
+#endif
+#ifdef TARGET_ARCH_arm
+# include "assembler_arm.inline.hpp"
+#endif
+#ifdef TARGET_ARCH_ppc
+# include "assembler_ppc.inline.hpp"
+#endif
+
+
+void OSThread::pd_initialize() {
+  assert(this != NULL, "check");
+  _thread_id        = NULL;
+  _pthread_id       = NULL;
+  _siginfo = NULL;
+  _ucontext = NULL;
+  _expanding_stack = 0;
+  _alt_sig_stack = NULL;
+
+  sigemptyset(&_caller_sigmask);
+
+  _startThread_lock = new Monitor(Mutex::event, "startThread_lock", true);
+  assert(_startThread_lock !=NULL, "check");
+}
+
+void OSThread::pd_destroy() {
+  delete _startThread_lock;
+}
diff --git a/hotspot/src/os/bsd/vm/osThread_bsd.hpp b/hotspot/src/os/bsd/vm/osThread_bsd.hpp
new file mode 100644
index 0000000..82dd34f
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/osThread_bsd.hpp
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_OSTHREAD_BSD_HPP
+#define OS_BSD_VM_OSTHREAD_BSD_HPP
+
+ private:
+  int _thread_type;
+
+ public:
+
+  int thread_type() const {
+    return _thread_type;
+  }
+  void set_thread_type(int type) {
+    _thread_type = type;
+  }
+
+ private:
+
+#ifdef _ALLBSD_SOURCE
+  // _thread_id and _pthread_id are the same on BSD
+  // keep both to minimize code divergence in os_bsd.cpp
+  pthread_t _thread_id;
+  pthread_t _pthread_id;
+#else
+  // _thread_id is kernel thread id (similar to LWP id on Solaris). Each
+  // thread has a unique thread_id (BsdThreads or NPTL). It can be used
+  // to access /proc.
+  pid_t     _thread_id;
+
+  // _pthread_id is the pthread id, which is used by library calls
+  // (e.g. pthread_kill).
+  pthread_t _pthread_id;
+#endif
+
+  sigset_t _caller_sigmask; // Caller's signal mask
+
+ public:
+
+  // Methods to save/restore caller's signal mask
+  sigset_t  caller_sigmask() const       { return _caller_sigmask; }
+  void    set_caller_sigmask(sigset_t sigmask)  { _caller_sigmask = sigmask; }
+
+#ifdef _ALLBSD_SOURCE
+  pthread_t thread_id() const {
+    return _thread_id;
+  }
+#else
+  pid_t thread_id() const {
+    return _thread_id;
+  }
+#endif
+#ifndef PRODUCT
+  // Used for debugging, return a unique integer for each thread.
+  intptr_t thread_identifier() const   { return (intptr_t)_pthread_id; }
+#endif
+#ifdef ASSERT
+  // We expect no reposition failures so kill vm if we get one.
+  //
+  bool valid_reposition_failure() {
+    return false;
+  }
+#endif // ASSERT
+#ifdef _ALLBSD_SOURCE
+  void set_thread_id(pthread_t id) {
+    _thread_id = id;
+  }
+#else
+  void set_thread_id(pid_t id) {
+    _thread_id = id;
+  }
+#endif
+  pthread_t pthread_id() const {
+    return _pthread_id;
+  }
+  void set_pthread_id(pthread_t tid) {
+    _pthread_id = tid;
+  }
+
+  // ***************************************************************
+  // suspension support.
+  // ***************************************************************
+
+public:
+  // flags that support signal based suspend/resume on Bsd are in a
+  // separate class to avoid confusion with many flags in OSThread that
+  // are used by VM level suspend/resume.
+  os::Bsd::SuspendResume sr;
+
+  // _ucontext and _siginfo are used by SR_handler() to save thread context,
+  // and they will later be used to walk the stack or reposition thread PC.
+  // If the thread is not suspended in SR_handler() (e.g. self suspend),
+  // the value in _ucontext is meaningless, so we must use the last Java
+  // frame information as the frame. This will mean that for threads
+  // that are parked on a mutex the profiler (and safepoint mechanism)
+  // will see the thread as if it were still in the Java frame. This
+  // not a problem for the profiler since the Java frame is a close
+  // enough result. For the safepoint mechanism when the give it the
+  // Java frame we are not at a point where the safepoint needs the
+  // frame to that accurate (like for a compiled safepoint) since we
+  // should be in a place where we are native and will block ourselves
+  // if we transition.
+private:
+  void* _siginfo;
+  ucontext_t* _ucontext;
+  int _expanding_stack;                 /* non zero if manually expanding stack */
+  address _alt_sig_stack;               /* address of base of alternate signal stack */
+
+public:
+  void* siginfo() const                   { return _siginfo;  }
+  void set_siginfo(void* ptr)             { _siginfo = ptr;   }
+  ucontext_t* ucontext() const            { return _ucontext; }
+  void set_ucontext(ucontext_t* ptr)      { _ucontext = ptr;  }
+  void set_expanding_stack(void)          { _expanding_stack = 1;  }
+  void clear_expanding_stack(void)        { _expanding_stack = 0;  }
+  int  expanding_stack(void)              { return _expanding_stack;  }
+
+  void set_alt_sig_stack(address val)     { _alt_sig_stack = val; }
+  address alt_sig_stack(void)             { return _alt_sig_stack; }
+
+private:
+  Monitor* _startThread_lock;     // sync parent and child in thread creation
+
+public:
+
+  Monitor* startThread_lock() const {
+    return _startThread_lock;
+  }
+
+  // ***************************************************************
+  // Platform dependent initialization and cleanup
+  // ***************************************************************
+
+private:
+
+  void pd_initialize();
+  void pd_destroy();
+
+// Reconciliation History
+// osThread_solaris.hpp 1.24 99/08/27 13:11:54
+// End
+
+#endif // OS_BSD_VM_OSTHREAD_BSD_HPP
diff --git a/hotspot/src/os/bsd/vm/os_bsd.cpp b/hotspot/src/os/bsd/vm/os_bsd.cpp
new file mode 100644
index 0000000..2a3faa0
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp
@@ -0,0 +1,5816 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+// no precompiled headers
+#include "classfile/classLoader.hpp"
+#include "classfile/systemDictionary.hpp"
+#include "classfile/vmSymbols.hpp"
+#include "code/icBuffer.hpp"
+#include "code/vtableStubs.hpp"
+#include "compiler/compileBroker.hpp"
+#include "interpreter/interpreter.hpp"
+#include "jvm_bsd.h"
+#include "memory/allocation.inline.hpp"
+#include "memory/filemap.hpp"
+#include "mutex_bsd.inline.hpp"
+#include "oops/oop.inline.hpp"
+#include "os_share_bsd.hpp"
+#include "prims/jniFastGetField.hpp"
+#include "prims/jvm.h"
+#include "prims/jvm_misc.hpp"
+#include "runtime/arguments.hpp"
+#include "runtime/extendedPC.hpp"
+#include "runtime/globals.hpp"
+#include "runtime/interfaceSupport.hpp"
+#include "runtime/java.hpp"
+#include "runtime/javaCalls.hpp"
+#include "runtime/mutexLocker.hpp"
+#include "runtime/objectMonitor.hpp"
+#include "runtime/osThread.hpp"
+#include "runtime/perfMemory.hpp"
+#include "runtime/sharedRuntime.hpp"
+#include "runtime/statSampler.hpp"
+#include "runtime/stubRoutines.hpp"
+#include "runtime/threadCritical.hpp"
+#include "runtime/timer.hpp"
+#include "services/attachListener.hpp"
+#include "services/runtimeService.hpp"
+#include "thread_bsd.inline.hpp"
+#include "utilities/decoder.hpp"
+#include "utilities/defaultStream.hpp"
+#include "utilities/events.hpp"
+#include "utilities/growableArray.hpp"
+#include "utilities/vmError.hpp"
+#ifdef TARGET_ARCH_x86
+# include "assembler_x86.inline.hpp"
+# include "nativeInst_x86.hpp"
+#endif
+#ifdef TARGET_ARCH_sparc
+# include "assembler_sparc.inline.hpp"
+# include "nativeInst_sparc.hpp"
+#endif
+#ifdef TARGET_ARCH_zero
+# include "assembler_zero.inline.hpp"
+# include "nativeInst_zero.hpp"
+#endif
+#ifdef TARGET_ARCH_arm
+# include "assembler_arm.inline.hpp"
+# include "nativeInst_arm.hpp"
+#endif
+#ifdef TARGET_ARCH_ppc
+# include "assembler_ppc.inline.hpp"
+# include "nativeInst_ppc.hpp"
+#endif
+#ifdef COMPILER1
+#include "c1/c1_Runtime1.hpp"
+#endif
+#ifdef COMPILER2
+#include "opto/runtime.hpp"
+#endif
+
+// put OS-includes here
+# include <sys/types.h>
+# include <sys/mman.h>
+# include <sys/stat.h>
+# include <sys/select.h>
+# include <pthread.h>
+# include <signal.h>
+# include <errno.h>
+# include <dlfcn.h>
+# include <stdio.h>
+# include <unistd.h>
+# include <sys/resource.h>
+# include <pthread.h>
+# include <sys/stat.h>
+# include <sys/time.h>
+# include <sys/times.h>
+# include <sys/utsname.h>
+# include <sys/socket.h>
+# include <sys/wait.h>
+# include <time.h>
+# include <pwd.h>
+# include <poll.h>
+# include <semaphore.h>
+# include <fcntl.h>
+# include <string.h>
+#ifdef _ALLBSD_SOURCE
+# include <sys/param.h>
+# include <sys/sysctl.h>
+#else
+# include <syscall.h>
+# include <sys/sysinfo.h>
+# include <gnu/libc-version.h>
+#endif
+# include <sys/ipc.h>
+# include <sys/shm.h>
+#ifndef __APPLE__
+# include <link.h>
+#endif
+# include <stdint.h>
+# include <inttypes.h>
+# include <sys/ioctl.h>
+
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+# include <elf.h>
+#endif
+
+#ifdef __APPLE__
+# include <mach/mach.h> // semaphore_* API
+# include <mach-o/dyld.h>
+# include <sys/proc_info.h>
+# include <objc/objc-auto.h>
+#endif
+
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+#define MAX_PATH    (2 * K)
+
+// for timer info max values which include all bits
+#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
+#define SEC_IN_NANOSECS  1000000000LL
+
+#define LARGEPAGES_BIT (1 << 6)
+////////////////////////////////////////////////////////////////////////////////
+// global variables
+julong os::Bsd::_physical_memory = 0;
+
+#ifndef _ALLBSD_SOURCE
+address   os::Bsd::_initial_thread_stack_bottom = NULL;
+uintptr_t os::Bsd::_initial_thread_stack_size   = 0;
+#endif
+
+int (*os::Bsd::_clock_gettime)(clockid_t, struct timespec *) = NULL;
+#ifndef _ALLBSD_SOURCE
+int (*os::Bsd::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
+Mutex* os::Bsd::_createThread_lock = NULL;
+#endif
+pthread_t os::Bsd::_main_thread;
+int os::Bsd::_page_size = -1;
+#ifndef _ALLBSD_SOURCE
+bool os::Bsd::_is_floating_stack = false;
+bool os::Bsd::_is_NPTL = false;
+bool os::Bsd::_supports_fast_thread_cpu_time = false;
+const char * os::Bsd::_glibc_version = NULL;
+const char * os::Bsd::_libpthread_version = NULL;
+#endif
+
+static jlong initial_time_count=0;
+
+static int clock_tics_per_sec = 100;
+
+// For diagnostics to print a message once. see run_periodic_checks
+static sigset_t check_signal_done;
+static bool check_signals = true;;
+
+static pid_t _initial_pid = 0;
+
+/* Signal number used to suspend/resume a thread */
+
+/* do not use any signal number less than SIGSEGV, see 4355769 */
+static int SR_signum = SIGUSR2;
+sigset_t SR_sigset;
+
+
+////////////////////////////////////////////////////////////////////////////////
+// utility functions
+
+static int SR_initialize();
+static int SR_finalize();
+
+julong os::available_memory() {
+  return Bsd::available_memory();
+}
+
+julong os::Bsd::available_memory() {
+#ifdef _ALLBSD_SOURCE
+  // XXXBSD: this is just a stopgap implementation
+  return physical_memory() >> 2;
+#else
+  // values in struct sysinfo are "unsigned long"
+  struct sysinfo si;
+  sysinfo(&si);
+
+  return (julong)si.freeram * si.mem_unit;
+#endif
+}
+
+julong os::physical_memory() {
+  return Bsd::physical_memory();
+}
+
+julong os::allocatable_physical_memory(julong size) {
+#ifdef _LP64
+  return size;
+#else
+  julong result = MIN2(size, (julong)3800*M);
+   if (!is_allocatable(result)) {
+     // See comments under solaris for alignment considerations
+     julong reasonable_size = (julong)2*G - 2 * os::vm_page_size();
+     result =  MIN2(size, reasonable_size);
+   }
+   return result;
+#endif // _LP64
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// environment support
+
+bool os::getenv(const char* name, char* buf, int len) {
+  const char* val = ::getenv(name);
+  if (val != NULL && strlen(val) < (size_t)len) {
+    strcpy(buf, val);
+    return true;
+  }
+  if (len > 0) buf[0] = 0;  // return a null string
+  return false;
+}
+
+
+// Return true if user is running as root.
+
+bool os::have_special_privileges() {
+  static bool init = false;
+  static bool privileges = false;
+  if (!init) {
+    privileges = (getuid() != geteuid()) || (getgid() != getegid());
+    init = true;
+  }
+  return privileges;
+}
+
+
+#ifndef _ALLBSD_SOURCE
+#ifndef SYS_gettid
+// i386: 224, ia64: 1105, amd64: 186, sparc 143
+#ifdef __ia64__
+#define SYS_gettid 1105
+#elif __i386__
+#define SYS_gettid 224
+#elif __amd64__
+#define SYS_gettid 186
+#elif __sparc__
+#define SYS_gettid 143
+#else
+#error define gettid for the arch
+#endif
+#endif
+#endif
+
+// Cpu architecture string
+#if   defined(ZERO)
+static char cpu_arch[] = ZERO_LIBARCH;
+#elif defined(IA64)
+static char cpu_arch[] = "ia64";
+#elif defined(IA32)
+static char cpu_arch[] = "i386";
+#elif defined(AMD64)
+static char cpu_arch[] = "amd64";
+#elif defined(ARM)
+static char cpu_arch[] = "arm";
+#elif defined(PPC)
+static char cpu_arch[] = "ppc";
+#elif defined(SPARC)
+#  ifdef _LP64
+static char cpu_arch[] = "sparcv9";
+#  else
+static char cpu_arch[] = "sparc";
+#  endif
+#else
+#error Add appropriate cpu_arch setting
+#endif
+
+
+#ifndef _ALLBSD_SOURCE
+// pid_t gettid()
+//
+// Returns the kernel thread id of the currently running thread. Kernel
+// thread id is used to access /proc.
+//
+// (Note that getpid() on BsdThreads returns kernel thread id too; but
+// on NPTL, it returns the same pid for all threads, as required by POSIX.)
+//
+pid_t os::Bsd::gettid() {
+  int rslt = syscall(SYS_gettid);
+  if (rslt == -1) {
+     // old kernel, no NPTL support
+     return getpid();
+  } else {
+     return (pid_t)rslt;
+  }
+}
+
+// Most versions of bsd have a bug where the number of processors are
+// determined by looking at the /proc file system.  In a chroot environment,
+// the system call returns 1.  This causes the VM to act as if it is
+// a single processor and elide locking (see is_MP() call).
+static bool unsafe_chroot_detected = false;
+static const char *unstable_chroot_error = "/proc file system not found.\n"
+                     "Java may be unstable running multithreaded in a chroot "
+                     "environment on Bsd when /proc filesystem is not mounted.";
+#endif
+
+#ifdef _ALLBSD_SOURCE
+void os::Bsd::initialize_system_info() {
+  int mib[2];
+  size_t len;
+  int cpu_val;
+  u_long mem_val;
+
+  /* get processors count via hw.ncpus sysctl */
+  mib[0] = CTL_HW;
+  mib[1] = HW_NCPU;
+  len = sizeof(cpu_val);
+  if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1 && cpu_val >= 1) {
+       set_processor_count(cpu_val);
+  }
+  else {
+       set_processor_count(1);   // fallback
+  }
+
+  /* get physical memory via hw.usermem sysctl (hw.usermem is used
+   * instead of hw.physmem because we need size of allocatable memory
+   */
+  mib[0] = CTL_HW;
+  mib[1] = HW_USERMEM;
+  len = sizeof(mem_val);
+  if (sysctl(mib, 2, &mem_val, &len, NULL, 0) != -1)
+       _physical_memory = mem_val;
+  else
+       _physical_memory = 256*1024*1024;       // fallback (XXXBSD?)
+
+#ifdef __OpenBSD__
+  {
+       // limit _physical_memory memory view on OpenBSD since
+       // datasize rlimit restricts us anyway.
+       struct rlimit limits;
+       getrlimit(RLIMIT_DATA, &limits);
+       _physical_memory = MIN2(_physical_memory, (julong)limits.rlim_cur);
+  }
+#endif
+}
+#else
+void os::Bsd::initialize_system_info() {
+  set_processor_count(sysconf(_SC_NPROCESSORS_CONF));
+  if (processor_count() == 1) {
+    pid_t pid = os::Bsd::gettid();
+    char fname[32];
+    jio_snprintf(fname, sizeof(fname), "/proc/%d", pid);
+    FILE *fp = fopen(fname, "r");
+    if (fp == NULL) {
+      unsafe_chroot_detected = true;
+    } else {
+      fclose(fp);
+    }
+  }
+  _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE);
+  assert(processor_count() > 0, "bsd error");
+}
+#endif
+
+#ifdef __APPLE__
+static const char *get_home() {
+  const char *home_dir = ::getenv("HOME");
+  if ((home_dir == NULL) || (*home_dir == '\0')) {
+    struct passwd *passwd_info = getpwuid(geteuid());
+    if (passwd_info != NULL) {
+      home_dir = passwd_info->pw_dir;
+    }
+  }
+
+  return home_dir;
+}
+#endif
+
+void os::init_system_properties_values() {
+//  char arch[12];
+//  sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
+
+  // The next steps are taken in the product version:
+  //
+  // Obtain the JAVA_HOME value from the location of libjvm[_g].so.
+  // This library should be located at:
+  // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm[_g].so.
+  //
+  // If "/jre/lib/" appears at the right place in the path, then we
+  // assume libjvm[_g].so is installed in a JDK and we use this path.
+  //
+  // Otherwise exit with message: "Could not create the Java virtual machine."
+  //
+  // The following extra steps are taken in the debugging version:
+  //
+  // If "/jre/lib/" does NOT appear at the right place in the path
+  // instead of exit check for $JAVA_HOME environment variable.
+  //
+  // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
+  // then we append a fake suffix "hotspot/libjvm[_g].so" to this path so
+  // it looks like libjvm[_g].so is installed there
+  // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm[_g].so.
+  //
+  // Otherwise exit.
+  //
+  // Important note: if the location of libjvm.so changes this
+  // code needs to be changed accordingly.
+
+  // The next few definitions allow the code to be verbatim:
+#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n))
+#define getenv(n) ::getenv(n)
+
+/*
+ * See ld(1):
+ *      The linker uses the following search paths to locate required
+ *      shared libraries:
+ *        1: ...
+ *        ...
+ *        7: The default directories, normally /lib and /usr/lib.
+ */
+#ifndef DEFAULT_LIBPATH
+#define DEFAULT_LIBPATH "/lib:/usr/lib"
+#endif
+
+#define EXTENSIONS_DIR  "/lib/ext"
+#define ENDORSED_DIR    "/lib/endorsed"
+#define REG_DIR         "/usr/java/packages"
+
+#ifdef __APPLE__
+#define SYS_EXTENSIONS_DIR   "/Library/Java/Extensions"
+#define SYS_EXTENSIONS_DIRS  SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java"
+        const char *user_home_dir = get_home();
+        // the null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir
+        int system_ext_size = strlen(user_home_dir) + sizeof(SYS_EXTENSIONS_DIR) +
+            sizeof(SYS_EXTENSIONS_DIRS);
+#endif
+
+  {
+    /* sysclasspath, java_home, dll_dir */
+    {
+        char *home_path;
+        char *dll_path;
+        char *pslash;
+        char buf[MAXPATHLEN];
+        os::jvm_path(buf, sizeof(buf));
+
+        // Found the full path to libjvm.so.
+        // Now cut the path to <java_home>/jre if we can.
+        *(strrchr(buf, '/')) = '\0';  /* get rid of /libjvm.so */
+        pslash = strrchr(buf, '/');
+        if (pslash != NULL)
+            *pslash = '\0';           /* get rid of /{client|server|hotspot} */
+        dll_path = malloc(strlen(buf) + 1);
+        if (dll_path == NULL)
+            return;
+        strcpy(dll_path, buf);
+        Arguments::set_dll_dir(dll_path);
+
+        if (pslash != NULL) {
+            pslash = strrchr(buf, '/');
+            if (pslash != NULL) {
+                *pslash = '\0';       /* get rid of /<arch> (/lib on macosx) */
+#ifndef __APPLE__
+                pslash = strrchr(buf, '/');
+                if (pslash != NULL)
+                    *pslash = '\0';   /* get rid of /lib */
+#endif
+            }
+        }
+
+        home_path = malloc(strlen(buf) + 1);
+        if (home_path == NULL)
+            return;
+        strcpy(home_path, buf);
+        Arguments::set_java_home(home_path);
+
+        if (!set_boot_path('/', ':'))
+            return;
+    }
+
+    /*
+     * Where to look for native libraries
+     *
+     * Note: Due to a legacy implementation, most of the library path
+     * is set in the launcher.  This was to accomodate linking restrictions
+     * on legacy Bsd implementations (which are no longer supported).
+     * Eventually, all the library path setting will be done here.
+     *
+     * However, to prevent the proliferation of improperly built native
+     * libraries, the new path component /usr/java/packages is added here.
+     * Eventually, all the library path setting will be done here.
+     */
+    {
+        char *ld_library_path;
+
+        /*
+         * Construct the invariant part of ld_library_path. Note that the
+         * space for the colon and the trailing null are provided by the
+         * nulls included by the sizeof operator (so actually we allocate
+         * a byte more than necessary).
+         */
+#ifdef __APPLE__
+        ld_library_path = (char *) malloc(system_ext_size);
+        sprintf(ld_library_path, "%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS, user_home_dir);
+#else
+        ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") +
+            strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH));
+        sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch);
+#endif
+
+        /*
+         * Get the user setting of LD_LIBRARY_PATH, and prepended it.  It
+         * should always exist (until the legacy problem cited above is
+         * addressed).
+         */
+#ifdef __APPLE__
+        // Prepend the default path with the JAVA_LIBRARY_PATH so that the app launcher code can specify a directory inside an app wrapper
+        char *l = getenv("JAVA_LIBRARY_PATH");
+        if (l != NULL) {
+            char *t = ld_library_path;
+            /* That's +1 for the colon and +1 for the trailing '\0' */
+            ld_library_path = (char *) malloc(strlen(l) + 1 + strlen(t) + 1);
+            sprintf(ld_library_path, "%s:%s", l, t);
+            free(t);
+        }
+
+        char *v = getenv("DYLD_LIBRARY_PATH");
+#else
+        char *v = getenv("LD_LIBRARY_PATH");
+#endif
+        if (v != NULL) {
+            char *t = ld_library_path;
+            /* That's +1 for the colon and +1 for the trailing '\0' */
+            ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
+            sprintf(ld_library_path, "%s:%s", v, t);
+            free(t);
+        }
+        Arguments::set_library_path(ld_library_path);
+    }
+
+    /*
+     * Extensions directories.
+     *
+     * Note that the space for the colon and the trailing null are provided
+     * by the nulls included by the sizeof operator (so actually one byte more
+     * than necessary is allocated).
+     */
+    {
+#ifdef __APPLE__
+        char *buf = malloc(strlen(Arguments::get_java_home()) +
+            sizeof(EXTENSIONS_DIR) + system_ext_size);
+        sprintf(buf, "%s" SYS_EXTENSIONS_DIR ":%s" EXTENSIONS_DIR ":"
+            SYS_EXTENSIONS_DIRS, user_home_dir, Arguments::get_java_home());
+#else
+        char *buf = malloc(strlen(Arguments::get_java_home()) +
+            sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR));
+        sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR,
+            Arguments::get_java_home());
+#endif
+
+        Arguments::set_ext_dirs(buf);
+    }
+
+    /* Endorsed standards default directory. */
+    {
+        char * buf;
+        buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
+        sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
+        Arguments::set_endorsed_dirs(buf);
+    }
+  }
+
+#ifdef __APPLE__
+#undef SYS_EXTENSIONS_DIR
+#endif
+#undef malloc
+#undef getenv
+#undef EXTENSIONS_DIR
+#undef ENDORSED_DIR
+
+  // Done
+  return;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// breakpoint support
+
+void os::breakpoint() {
+  BREAKPOINT;
+}
+
+extern "C" void breakpoint() {
+  // use debugger to set breakpoint here
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// signal support
+
+debug_only(static bool signal_sets_initialized = false);
+static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
+
+bool os::Bsd::is_sig_ignored(int sig) {
+      struct sigaction oact;
+      sigaction(sig, (struct sigaction*)NULL, &oact);
+      void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oact.sa_sigaction)
+                                     : CAST_FROM_FN_PTR(void*,  oact.sa_handler);
+      if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN))
+           return true;
+      else
+           return false;
+}
+
+void os::Bsd::signal_sets_init() {
+  // Should also have an assertion stating we are still single-threaded.
+  assert(!signal_sets_initialized, "Already initialized");
+  // Fill in signals that are necessarily unblocked for all threads in
+  // the VM. Currently, we unblock the following signals:
+  // SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden
+  //                         by -Xrs (=ReduceSignalUsage));
+  // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all
+  // other threads. The "ReduceSignalUsage" boolean tells us not to alter
+  // the dispositions or masks wrt these signals.
+  // Programs embedding the VM that want to use the above signals for their
+  // own purposes must, at this time, use the "-Xrs" option to prevent
+  // interference with shutdown hooks and BREAK_SIGNAL thread dumping.
+  // (See bug 4345157, and other related bugs).
+  // In reality, though, unblocking these signals is really a nop, since
+  // these signals are not blocked by default.
+  sigemptyset(&unblocked_sigs);
+  sigemptyset(&allowdebug_blocked_sigs);
+  sigaddset(&unblocked_sigs, SIGILL);
+  sigaddset(&unblocked_sigs, SIGSEGV);
+  sigaddset(&unblocked_sigs, SIGBUS);
+  sigaddset(&unblocked_sigs, SIGFPE);
+  sigaddset(&unblocked_sigs, SR_signum);
+
+  if (!ReduceSignalUsage) {
+   if (!os::Bsd::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
+      sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
+      sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL);
+   }
+   if (!os::Bsd::is_sig_ignored(SHUTDOWN2_SIGNAL)) {
+      sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL);
+      sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL);
+   }
+   if (!os::Bsd::is_sig_ignored(SHUTDOWN3_SIGNAL)) {
+      sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL);
+      sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
+   }
+  }
+  // Fill in signals that are blocked by all but the VM thread.
+  sigemptyset(&vm_sigs);
+  if (!ReduceSignalUsage)
+    sigaddset(&vm_sigs, BREAK_SIGNAL);
+  debug_only(signal_sets_initialized = true);
+
+}
+
+// These are signals that are unblocked while a thread is running Java.
+// (For some reason, they get blocked by default.)
+sigset_t* os::Bsd::unblocked_signals() {
+  assert(signal_sets_initialized, "Not initialized");
+  return &unblocked_sigs;
+}
+
+// These are the signals that are blocked while a (non-VM) thread is
+// running Java. Only the VM thread handles these signals.
+sigset_t* os::Bsd::vm_signals() {
+  assert(signal_sets_initialized, "Not initialized");
+  return &vm_sigs;
+}
+
+// These are signals that are blocked during cond_wait to allow debugger in
+sigset_t* os::Bsd::allowdebug_blocked_signals() {
+  assert(signal_sets_initialized, "Not initialized");
+  return &allowdebug_blocked_sigs;
+}
+
+void os::Bsd::hotspot_sigmask(Thread* thread) {
+
+  //Save caller's signal mask before setting VM signal mask
+  sigset_t caller_sigmask;
+  pthread_sigmask(SIG_BLOCK, NULL, &caller_sigmask);
+
+  OSThread* osthread = thread->osthread();
+  osthread->set_caller_sigmask(caller_sigmask);
+
+  pthread_sigmask(SIG_UNBLOCK, os::Bsd::unblocked_signals(), NULL);
+
+  if (!ReduceSignalUsage) {
+    if (thread->is_VM_thread()) {
+      // Only the VM thread handles BREAK_SIGNAL ...
+      pthread_sigmask(SIG_UNBLOCK, vm_signals(), NULL);
+    } else {
+      // ... all other threads block BREAK_SIGNAL
+      pthread_sigmask(SIG_BLOCK, vm_signals(), NULL);
+    }
+  }
+}
+
+#ifndef _ALLBSD_SOURCE
+//////////////////////////////////////////////////////////////////////////////
+// detecting pthread library
+
+void os::Bsd::libpthread_init() {
+  // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION
+  // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a
+  // generic name for earlier versions.
+  // Define macros here so we can build HotSpot on old systems.
+# ifndef _CS_GNU_LIBC_VERSION
+# define _CS_GNU_LIBC_VERSION 2
+# endif
+# ifndef _CS_GNU_LIBPTHREAD_VERSION
+# define _CS_GNU_LIBPTHREAD_VERSION 3
+# endif
+
+  size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
+  if (n > 0) {
+     char *str = (char *)malloc(n);
+     confstr(_CS_GNU_LIBC_VERSION, str, n);
+     os::Bsd::set_glibc_version(str);
+  } else {
+     // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version()
+     static char _gnu_libc_version[32];
+     jio_snprintf(_gnu_libc_version, sizeof(_gnu_libc_version),
+              "glibc %s %s", gnu_get_libc_version(), gnu_get_libc_release());
+     os::Bsd::set_glibc_version(_gnu_libc_version);
+  }
+
+  n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
+  if (n > 0) {
+     char *str = (char *)malloc(n);
+     confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n);
+     // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells
+     // us "NPTL-0.29" even we are running with BsdThreads. Check if this
+     // is the case. BsdThreads has a hard limit on max number of threads.
+     // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value.
+     // On the other hand, NPTL does not have such a limit, sysconf()
+     // will return -1 and errno is not changed. Check if it is really NPTL.
+     if (strcmp(os::Bsd::glibc_version(), "glibc 2.3.2") == 0 &&
+         strstr(str, "NPTL") &&
+         sysconf(_SC_THREAD_THREADS_MAX) > 0) {
+       free(str);
+       os::Bsd::set_libpthread_version("bsdthreads");
+     } else {
+       os::Bsd::set_libpthread_version(str);
+     }
+  } else {
+    // glibc before 2.3.2 only has BsdThreads.
+    os::Bsd::set_libpthread_version("bsdthreads");
+  }
+
+  if (strstr(libpthread_version(), "NPTL")) {
+     os::Bsd::set_is_NPTL();
+  } else {
+     os::Bsd::set_is_BsdThreads();
+  }
+
+  // BsdThreads have two flavors: floating-stack mode, which allows variable
+  // stack size; and fixed-stack mode. NPTL is always floating-stack.
+  if (os::Bsd::is_NPTL() || os::Bsd::supports_variable_stack_size()) {
+     os::Bsd::set_is_floating_stack();
+  }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// thread stack
+
+// Force Bsd kernel to expand current thread stack. If "bottom" is close
+// to the stack guard, caller should block all signals.
+//
+// MAP_GROWSDOWN:
+//   A special mmap() flag that is used to implement thread stacks. It tells
+//   kernel that the memory region should extend downwards when needed. This
+//   allows early versions of BsdThreads to only mmap the first few pages
+//   when creating a new thread. Bsd kernel will automatically expand thread
+//   stack as needed (on page faults).
+//
+//   However, because the memory region of a MAP_GROWSDOWN stack can grow on
+//   demand, if a page fault happens outside an already mapped MAP_GROWSDOWN
+//   region, it's hard to tell if the fault is due to a legitimate stack
+//   access or because of reading/writing non-exist memory (e.g. buffer
+//   overrun). As a rule, if the fault happens below current stack pointer,
+//   Bsd kernel does not expand stack, instead a SIGSEGV is sent to the
+//   application (see Bsd kernel fault.c).
+//
+//   This Bsd feature can cause SIGSEGV when VM bangs thread stack for
+//   stack overflow detection.
+//
+//   Newer version of BsdThreads (since glibc-2.2, or, RH-7.x) and NPTL do
+//   not use this flag. However, the stack of initial thread is not created
+//   by pthread, it is still MAP_GROWSDOWN. Also it's possible (though
+//   unlikely) that user code can create a thread with MAP_GROWSDOWN stack
+//   and then attach the thread to JVM.
+//
+// To get around the problem and allow stack banging on Bsd, we need to
+// manually expand thread stack after receiving the SIGSEGV.
+//
+// There are two ways to expand thread stack to address "bottom", we used
+// both of them in JVM before 1.5:
+//   1. adjust stack pointer first so that it is below "bottom", and then
+//      touch "bottom"
+//   2. mmap() the page in question
+//
+// Now alternate signal stack is gone, it's harder to use 2. For instance,
+// if current sp is already near the lower end of page 101, and we need to
+// call mmap() to map page 100, it is possible that part of the mmap() frame
+// will be placed in page 100. When page 100 is mapped, it is zero-filled.
+// That will destroy the mmap() frame and cause VM to crash.
+//
+// The following code works by adjusting sp first, then accessing the "bottom"
+// page to force a page fault. Bsd kernel will then automatically expand the
+// stack mapping.
+//
+// _expand_stack_to() assumes its frame size is less than page size, which
+// should always be true if the function is not inlined.
+
+#if __GNUC__ < 3    // gcc 2.x does not support noinline attribute
+#define NOINLINE
+#else
+#define NOINLINE __attribute__ ((noinline))
+#endif
+
+static void _expand_stack_to(address bottom) NOINLINE;
+
+static void _expand_stack_to(address bottom) {
+  address sp;
+  size_t size;
+  volatile char *p;
+
+  // Adjust bottom to point to the largest address within the same page, it
+  // gives us a one-page buffer if alloca() allocates slightly more memory.
+  bottom = (address)align_size_down((uintptr_t)bottom, os::Bsd::page_size());
+  bottom += os::Bsd::page_size() - 1;
+
+  // sp might be slightly above current stack pointer; if that's the case, we
+  // will alloca() a little more space than necessary, which is OK. Don't use
+  // os::current_stack_pointer(), as its result can be slightly below current
+  // stack pointer, causing us to not alloca enough to reach "bottom".
+  sp = (address)&sp;
+
+  if (sp > bottom) {
+    size = sp - bottom;
+    p = (volatile char *)alloca(size);
+    assert(p != NULL && p <= (volatile char *)bottom, "alloca problem?");
+    p[0] = '\0';
+  }
+}
+
+bool os::Bsd::manually_expand_stack(JavaThread * t, address addr) {
+  assert(t!=NULL, "just checking");
+  assert(t->osthread()->expanding_stack(), "expand should be set");
+  assert(t->stack_base() != NULL, "stack_base was not initialized");
+
+  if (addr <  t->stack_base() && addr >= t->stack_yellow_zone_base()) {
+    sigset_t mask_all, old_sigset;
+    sigfillset(&mask_all);
+    pthread_sigmask(SIG_SETMASK, &mask_all, &old_sigset);
+    _expand_stack_to(addr);
+    pthread_sigmask(SIG_SETMASK, &old_sigset, NULL);
+    return true;
+  }
+  return false;
+}
+#endif
+
+//////////////////////////////////////////////////////////////////////////////
+// create new thread
+
+static address highest_vm_reserved_address();
+
+// check if it's safe to start a new thread
+static bool _thread_safety_check(Thread* thread) {
+#ifdef _ALLBSD_SOURCE
+    return true;
+#else
+  if (os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack()) {
+    // Fixed stack BsdThreads (SuSE Bsd/x86, and some versions of Redhat)
+    //   Heap is mmap'ed at lower end of memory space. Thread stacks are
+    //   allocated (MAP_FIXED) from high address space. Every thread stack
+    //   occupies a fixed size slot (usually 2Mbytes, but user can change
+    //   it to other values if they rebuild BsdThreads).
+    //
+    // Problem with MAP_FIXED is that mmap() can still succeed even part of
+    // the memory region has already been mmap'ed. That means if we have too
+    // many threads and/or very large heap, eventually thread stack will
+    // collide with heap.
+    //
+    // Here we try to prevent heap/stack collision by comparing current
+    // stack bottom with the highest address that has been mmap'ed by JVM
+    // plus a safety margin for memory maps created by native code.
+    //
+    // This feature can be disabled by setting ThreadSafetyMargin to 0
+    //
+    if (ThreadSafetyMargin > 0) {
+      address stack_bottom = os::current_stack_base() - os::current_stack_size();
+
+      // not safe if our stack extends below the safety margin
+      return stack_bottom - ThreadSafetyMargin >= highest_vm_reserved_address();
+    } else {
+      return true;
+    }
+  } else {
+    // Floating stack BsdThreads or NPTL:
+    //   Unlike fixed stack BsdThreads, thread stacks are not MAP_FIXED. When
+    //   there's not enough space left, pthread_create() will fail. If we come
+    //   here, that means enough space has been reserved for stack.
+    return true;
+  }
+#endif
+}
+
+#ifdef __APPLE__
+// library handle for calling objc_registerThreadWithCollector()
+// without static linking to the libobjc library
+#define OBJC_LIB "/usr/lib/libobjc.dylib"
+#define OBJC_GCREGISTER "objc_registerThreadWithCollector"
+typedef void (*objc_registerThreadWithCollector_t)();
+extern "C" objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction;
+objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = NULL;
+#endif
+
+// Thread start routine for all newly created threads
+static void *java_start(Thread *thread) {
+  // Try to randomize the cache line index of hot stack frames.
+  // This helps when threads of the same stack traces evict each other's
+  // cache lines. The threads can be either from the same JVM instance, or
+  // from different JVM instances. The benefit is especially true for
+  // processors with hyperthreading technology.
+  static int counter = 0;
+  int pid = os::current_process_id();
+  alloca(((pid ^ counter++) & 7) * 128);
+
+  ThreadLocalStorage::set_thread(thread);
+
+  OSThread* osthread = thread->osthread();
+  Monitor* sync = osthread->startThread_lock();
+
+  // non floating stack BsdThreads needs extra check, see above
+  if (!_thread_safety_check(thread)) {
+    // notify parent thread
+    MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
+    osthread->set_state(ZOMBIE);
+    sync->notify_all();
+    return NULL;
+  }
+
+#ifdef _ALLBSD_SOURCE
+  // thread_id is pthread_id on BSD
+  osthread->set_thread_id(::pthread_self());
+#else
+  // thread_id is kernel thread id (similar to Solaris LWP id)
+  osthread->set_thread_id(os::Bsd::gettid());
+
+  if (UseNUMA) {
+    int lgrp_id = os::numa_get_group_id();
+    if (lgrp_id != -1) {
+      thread->set_lgrp_id(lgrp_id);
+    }
+  }
+#endif
+  // initialize signal mask for this thread
+  os::Bsd::hotspot_sigmask(thread);
+
+  // initialize floating point control register
+  os::Bsd::init_thread_fpu_state();
+
+#ifdef __APPLE__
+  // register thread with objc gc
+  if (objc_registerThreadWithCollectorFunction != NULL) {
+    objc_registerThreadWithCollectorFunction();
+  }
+#endif
+
+  // handshaking with parent thread
+  {
+    MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
+
+    // notify parent thread
+    osthread->set_state(INITIALIZED);
+    sync->notify_all();
+
+    // wait until os::start_thread()
+    while (osthread->get_state() == INITIALIZED) {
+      sync->wait(Mutex::_no_safepoint_check_flag);
+    }
+  }
+
+  // call one more level start routine
+  thread->run();
+
+  return 0;
+}
+
+bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
+  assert(thread->osthread() == NULL, "caller responsible");
+
+  // Allocate the OSThread object
+  OSThread* osthread = new OSThread(NULL, NULL);
+  if (osthread == NULL) {
+    return false;
+  }
+
+  // set the correct thread state
+  osthread->set_thread_type(thr_type);
+
+  // Initial state is ALLOCATED but not INITIALIZED
+  osthread->set_state(ALLOCATED);
+
+  thread->set_osthread(osthread);
+
+  // init thread attributes
+  pthread_attr_t attr;
+  pthread_attr_init(&attr);
+  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+  // stack size
+  if (os::Bsd::supports_variable_stack_size()) {
+    // calculate stack size if it's not specified by caller
+    if (stack_size == 0) {
+      stack_size = os::Bsd::default_stack_size(thr_type);
+
+      switch (thr_type) {
+      case os::java_thread:
+        // Java threads use ThreadStackSize which default value can be
+        // changed with the flag -Xss
+        assert (JavaThread::stack_size_at_create() > 0, "this should be set");
+        stack_size = JavaThread::stack_size_at_create();
+        break;
+      case os::compiler_thread:
+        if (CompilerThreadStackSize > 0) {
+          stack_size = (size_t)(CompilerThreadStackSize * K);
+          break;
+        } // else fall through:
+          // use VMThreadStackSize if CompilerThreadStackSize is not defined
+      case os::vm_thread:
+      case os::pgc_thread:
+      case os::cgc_thread:
+      case os::watcher_thread:
+        if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
+        break;
+      }
+    }
+
+    stack_size = MAX2(stack_size, os::Bsd::min_stack_allowed);
+    pthread_attr_setstacksize(&attr, stack_size);
+  } else {
+    // let pthread_create() pick the default value.
+  }
+
+#ifndef _ALLBSD_SOURCE
+  // glibc guard page
+  pthread_attr_setguardsize(&attr, os::Bsd::default_guard_size(thr_type));
+#endif
+
+  ThreadState state;
+
+  {
+
+#ifndef _ALLBSD_SOURCE
+    // Serialize thread creation if we are running with fixed stack BsdThreads
+    bool lock = os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack();
+    if (lock) {
+      os::Bsd::createThread_lock()->lock_without_safepoint_check();
+    }
+#endif
+
+    pthread_t tid;
+    int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
+
+    pthread_attr_destroy(&attr);
+
+    if (ret != 0) {
+      if (PrintMiscellaneous && (Verbose || WizardMode)) {
+        perror("pthread_create()");
+      }
+      // Need to clean up stuff we've allocated so far
+      thread->set_osthread(NULL);
+      delete osthread;
+#ifndef _ALLBSD_SOURCE
+      if (lock) os::Bsd::createThread_lock()->unlock();
+#endif
+      return false;
+    }
+
+    // Store pthread info into the OSThread
+    osthread->set_pthread_id(tid);
+
+    // Wait until child thread is either initialized or aborted
+    {
+      Monitor* sync_with_child = osthread->startThread_lock();
+      MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
+      while ((state = osthread->get_state()) == ALLOCATED) {
+        sync_with_child->wait(Mutex::_no_safepoint_check_flag);
+      }
+    }
+
+#ifndef _ALLBSD_SOURCE
+    if (lock) {
+      os::Bsd::createThread_lock()->unlock();
+    }
+#endif
+  }
+
+  // Aborted due to thread limit being reached
+  if (state == ZOMBIE) {
+      thread->set_osthread(NULL);
+      delete osthread;
+      return false;
+  }
+
+  // The thread is returned suspended (in state INITIALIZED),
+  // and is started higher up in the call chain
+  assert(state == INITIALIZED, "race condition");
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// attach existing thread
+
+// bootstrap the main thread
+bool os::create_main_thread(JavaThread* thread) {
+  assert(os::Bsd::_main_thread == pthread_self(), "should be called inside main thread");
+  return create_attached_thread(thread);
+}
+
+bool os::create_attached_thread(JavaThread* thread) {
+#ifdef ASSERT
+    thread->verify_not_published();
+#endif
+
+  // Allocate the OSThread object
+  OSThread* osthread = new OSThread(NULL, NULL);
+
+  if (osthread == NULL) {
+    return false;
+  }
+
+  // Store pthread info into the OSThread
+#ifdef _ALLBSD_SOURCE
+  osthread->set_thread_id(::pthread_self());
+#else
+  osthread->set_thread_id(os::Bsd::gettid());
+#endif
+  osthread->set_pthread_id(::pthread_self());
+
+  // initialize floating point control register
+  os::Bsd::init_thread_fpu_state();
+
+  // Initial thread state is RUNNABLE
+  osthread->set_state(RUNNABLE);
+
+  thread->set_osthread(osthread);
+
+#ifndef _ALLBSD_SOURCE
+  if (UseNUMA) {
+    int lgrp_id = os::numa_get_group_id();
+    if (lgrp_id != -1) {
+      thread->set_lgrp_id(lgrp_id);
+    }
+  }
+
+  if (os::Bsd::is_initial_thread()) {
+    // If current thread is initial thread, its stack is mapped on demand,
+    // see notes about MAP_GROWSDOWN. Here we try to force kernel to map
+    // the entire stack region to avoid SEGV in stack banging.
+    // It is also useful to get around the heap-stack-gap problem on SuSE
+    // kernel (see 4821821 for details). We first expand stack to the top
+    // of yellow zone, then enable stack yellow zone (order is significant,
+    // enabling yellow zone first will crash JVM on SuSE Bsd), so there
+    // is no gap between the last two virtual memory regions.
+
+    JavaThread *jt = (JavaThread *)thread;
+    address addr = jt->stack_yellow_zone_base();
+    assert(addr != NULL, "initialization problem?");
+    assert(jt->stack_available(addr) > 0, "stack guard should not be enabled");
+
+    osthread->set_expanding_stack();
+    os::Bsd::manually_expand_stack(jt, addr);
+    osthread->clear_expanding_stack();
+  }
+#endif
+
+  // initialize signal mask for this thread
+  // and save the caller's signal mask
+  os::Bsd::hotspot_sigmask(thread);
+
+  return true;
+}
+
+void os::pd_start_thread(Thread* thread) {
+  OSThread * osthread = thread->osthread();
+  assert(osthread->get_state() != INITIALIZED, "just checking");
+  Monitor* sync_with_child = osthread->startThread_lock();
+  MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
+  sync_with_child->notify();
+}
+
+// Free Bsd resources related to the OSThread
+void os::free_thread(OSThread* osthread) {
+  assert(osthread != NULL, "osthread not set");
+
+  if (Thread::current()->osthread() == osthread) {
+    // Restore caller's signal mask
+    sigset_t sigmask = osthread->caller_sigmask();
+    pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
+   }
+
+  delete osthread;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// thread local storage
+
+int os::allocate_thread_local_storage() {
+  pthread_key_t key;
+  int rslt = pthread_key_create(&key, NULL);
+  assert(rslt == 0, "cannot allocate thread local storage");
+  return (int)key;
+}
+
+// Note: This is currently not used by VM, as we don't destroy TLS key
+// on VM exit.
+void os::free_thread_local_storage(int index) {
+  int rslt = pthread_key_delete((pthread_key_t)index);
+  assert(rslt == 0, "invalid index");
+}
+
+void os::thread_local_storage_at_put(int index, void* value) {
+  int rslt = pthread_setspecific((pthread_key_t)index, value);
+  assert(rslt == 0, "pthread_setspecific failed");
+}
+
+extern "C" Thread* get_thread() {
+  return ThreadLocalStorage::thread();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// initial thread
+
+#ifndef _ALLBSD_SOURCE
+// Check if current thread is the initial thread, similar to Solaris thr_main.
+bool os::Bsd::is_initial_thread(void) {
+  char dummy;
+  // If called before init complete, thread stack bottom will be null.
+  // Can be called if fatal error occurs before initialization.
+  if (initial_thread_stack_bottom() == NULL) return false;
+  assert(initial_thread_stack_bottom() != NULL &&
+         initial_thread_stack_size()   != 0,
+         "os::init did not locate initial thread's stack region");
+  if ((address)&dummy >= initial_thread_stack_bottom() &&
+      (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size())
+       return true;
+  else return false;
+}
+
+// Find the virtual memory area that contains addr
+static bool find_vma(address addr, address* vma_low, address* vma_high) {
+  FILE *fp = fopen("/proc/self/maps", "r");
+  if (fp) {
+    address low, high;
+    while (!feof(fp)) {
+      if (fscanf(fp, "%p-%p", &low, &high) == 2) {
+        if (low <= addr && addr < high) {
+           if (vma_low)  *vma_low  = low;
+           if (vma_high) *vma_high = high;
+           fclose (fp);
+           return true;
+        }
+      }
+      for (;;) {
+        int ch = fgetc(fp);
+        if (ch == EOF || ch == (int)'\n') break;
+      }
+    }
+    fclose(fp);
+  }
+  return false;
+}
+
+// Locate initial thread stack. This special handling of initial thread stack
+// is needed because pthread_getattr_np() on most (all?) Bsd distros returns
+// bogus value for initial thread.
+void os::Bsd::capture_initial_stack(size_t max_size) {
+  // stack size is the easy part, get it from RLIMIT_STACK
+  size_t stack_size;
+  struct rlimit rlim;
+  getrlimit(RLIMIT_STACK, &rlim);
+  stack_size = rlim.rlim_cur;
+
+  // 6308388: a bug in ld.so will relocate its own .data section to the
+  //   lower end of primordial stack; reduce ulimit -s value a little bit
+  //   so we won't install guard page on ld.so's data section.
+  stack_size -= 2 * page_size();
+
+  // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat
+  //   7.1, in both cases we will get 2G in return value.
+  // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0,
+  //   SuSE 7.2, Debian) can not handle alternate signal stack correctly
+  //   for initial thread if its stack size exceeds 6M. Cap it at 2M,
+  //   in case other parts in glibc still assumes 2M max stack size.
+  // FIXME: alt signal stack is gone, maybe we can relax this constraint?
+#ifndef IA64
+  if (stack_size > 2 * K * K) stack_size = 2 * K * K;
+#else
+  // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
+  if (stack_size > 4 * K * K) stack_size = 4 * K * K;
+#endif
+
+  // Try to figure out where the stack base (top) is. This is harder.
+  //
+  // When an application is started, glibc saves the initial stack pointer in
+  // a global variable "__libc_stack_end", which is then used by system
+  // libraries. __libc_stack_end should be pretty close to stack top. The
+  // variable is available since the very early days. However, because it is
+  // a private interface, it could disappear in the future.
+  //
+  // Bsd kernel saves start_stack information in /proc/<pid>/stat. Similar
+  // to __libc_stack_end, it is very close to stack top, but isn't the real
+  // stack top. Note that /proc may not exist if VM is running as a chroot
+  // program, so reading /proc/<pid>/stat could fail. Also the contents of
+  // /proc/<pid>/stat could change in the future (though unlikely).
+  //
+  // We try __libc_stack_end first. If that doesn't work, look for
+  // /proc/<pid>/stat. If neither of them works, we use current stack pointer
+  // as a hint, which should work well in most cases.
+
+  uintptr_t stack_start;
+
+  // try __libc_stack_end first
+  uintptr_t *p = (uintptr_t *)dlsym(RTLD_DEFAULT, "__libc_stack_end");
+  if (p && *p) {
+    stack_start = *p;
+  } else {
+    // see if we can get the start_stack field from /proc/self/stat
+    FILE *fp;
+    int pid;
+    char state;
+    int ppid;
+    int pgrp;
+    int session;
+    int nr;
+    int tpgrp;
+    unsigned long flags;
+    unsigned long minflt;
+    unsigned long cminflt;
+    unsigned long majflt;
+    unsigned long cmajflt;
+    unsigned long utime;
+    unsigned long stime;
+    long cutime;
+    long cstime;
+    long prio;
+    long nice;
+    long junk;
+    long it_real;
+    uintptr_t start;
+    uintptr_t vsize;
+    intptr_t rss;
+    uintptr_t rsslim;
+    uintptr_t scodes;
+    uintptr_t ecode;
+    int i;
+
+    // Figure what the primordial thread stack base is. Code is inspired
+    // by email from Hans Boehm. /proc/self/stat begins with current pid,
+    // followed by command name surrounded by parentheses, state, etc.
+    char stat[2048];
+    int statlen;
+
+    fp = fopen("/proc/self/stat", "r");
+    if (fp) {
+      statlen = fread(stat, 1, 2047, fp);
+      stat[statlen] = '\0';
+      fclose(fp);
+
+      // Skip pid and the command string. Note that we could be dealing with
+      // weird command names, e.g. user could decide to rename java launcher
+      // to "java 1.4.2 :)", then the stat file would look like
+      //                1234 (java 1.4.2 :)) R ... ...
+      // We don't really need to know the command string, just find the last
+      // occurrence of ")" and then start parsing from there. See bug 4726580.
+      char * s = strrchr(stat, ')');
+
+      i = 0;
+      if (s) {
+        // Skip blank chars
+        do s++; while (isspace(*s));
+
+#define _UFM UINTX_FORMAT
+#define _DFM INTX_FORMAT
+
+        /*                                     1   1   1   1   1   1   1   1   1   1   2   2    2    2    2    2    2    2    2 */
+        /*              3  4  5  6  7  8   9   0   1   2   3   4   5   6   7   8   9   0   1    2    3    4    5    6    7    8 */
+        i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " _UFM _UFM _DFM _UFM _UFM _UFM _UFM,
+             &state,          /* 3  %c  */
+             &ppid,           /* 4  %d  */
+             &pgrp,           /* 5  %d  */
+             &session,        /* 6  %d  */
+             &nr,             /* 7  %d  */
+             &tpgrp,          /* 8  %d  */
+             &flags,          /* 9  %lu  */
+             &minflt,         /* 10 %lu  */
+             &cminflt,        /* 11 %lu  */
+             &majflt,         /* 12 %lu  */
+             &cmajflt,        /* 13 %lu  */
+             &utime,          /* 14 %lu  */
+             &stime,          /* 15 %lu  */
+             &cutime,         /* 16 %ld  */
+             &cstime,         /* 17 %ld  */
+             &prio,           /* 18 %ld  */
+             &nice,           /* 19 %ld  */
+             &junk,           /* 20 %ld  */
+             &it_real,        /* 21 %ld  */
+             &start,          /* 22 UINTX_FORMAT */
+             &vsize,          /* 23 UINTX_FORMAT */
+             &rss,            /* 24 INTX_FORMAT  */
+             &rsslim,         /* 25 UINTX_FORMAT */
+             &scodes,         /* 26 UINTX_FORMAT */
+             &ecode,          /* 27 UINTX_FORMAT */
+             &stack_start);   /* 28 UINTX_FORMAT */
+      }
+
+#undef _UFM
+#undef _DFM
+
+      if (i != 28 - 2) {
+         assert(false, "Bad conversion from /proc/self/stat");
+         // product mode - assume we are the initial thread, good luck in the
+         // embedded case.
+         warning("Can't detect initial thread stack location - bad conversion");
+         stack_start = (uintptr_t) &rlim;
+      }
+    } else {
+      // For some reason we can't open /proc/self/stat (for example, running on
+      // FreeBSD with a Bsd emulator, or inside chroot), this should work for
+      // most cases, so don't abort:
+      warning("Can't detect initial thread stack location - no /proc/self/stat");
+      stack_start = (uintptr_t) &rlim;
+    }
+  }
+
+  // Now we have a pointer (stack_start) very close to the stack top, the
+  // next thing to do is to figure out the exact location of stack top. We
+  // can find out the virtual memory area that contains stack_start by
+  // reading /proc/self/maps, it should be the last vma in /proc/self/maps,
+  // and its upper limit is the real stack top. (again, this would fail if
+  // running inside chroot, because /proc may not exist.)
+
+  uintptr_t stack_top;
+  address low, high;
+  if (find_vma((address)stack_start, &low, &high)) {
+    // success, "high" is the true stack top. (ignore "low", because initial
+    // thread stack grows on demand, its real bottom is high - RLIMIT_STACK.)
+    stack_top = (uintptr_t)high;
+  } else {
+    // failed, likely because /proc/self/maps does not exist
+    warning("Can't detect initial thread stack location - find_vma failed");
+    // best effort: stack_start is normally within a few pages below the real
+    // stack top, use it as stack top, and reduce stack size so we won't put
+    // guard page outside stack.
+    stack_top = stack_start;
+    stack_size -= 16 * page_size();
+  }
+
+  // stack_top could be partially down the page so align it
+  stack_top = align_size_up(stack_top, page_size());
+
+  if (max_size && stack_size > max_size) {
+     _initial_thread_stack_size = max_size;
+  } else {
+     _initial_thread_stack_size = stack_size;
+  }
+
+  _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
+  _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// time support
+
+// Time since start-up in seconds to a fine granularity.
+// Used by VMSelfDestructTimer and the MemProfiler.
+double os::elapsedTime() {
+
+  return (double)(os::elapsed_counter()) * 0.000001;
+}
+
+jlong os::elapsed_counter() {
+  timeval time;
+  int status = gettimeofday(&time, NULL);
+  return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
+}
+
+jlong os::elapsed_frequency() {
+  return (1000 * 1000);
+}
+
+// XXX: For now, code this as if BSD does not support vtime.
+bool os::supports_vtime() { return false; }
+bool os::enable_vtime()   { return false; }
+bool os::vtime_enabled()  { return false; }
+double os::elapsedVTime() {
+  // better than nothing, but not much
+  return elapsedTime();
+}
+
+jlong os::javaTimeMillis() {
+  timeval time;
+  int status = gettimeofday(&time, NULL);
+  assert(status != -1, "bsd error");
+  return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
+}
+
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC (1)
+#endif
+
+#ifdef __APPLE__
+void os::Bsd::clock_init() {
+        // XXXDARWIN: Investigate replacement monotonic clock
+}
+#elif defined(_ALLBSD_SOURCE)
+void os::Bsd::clock_init() {
+  struct timespec res;
+  struct timespec tp;
+  if (::clock_getres(CLOCK_MONOTONIC, &res) == 0 &&
+      ::clock_gettime(CLOCK_MONOTONIC, &tp)  == 0) {
+    // yes, monotonic clock is supported
+    _clock_gettime = ::clock_gettime;
+  }
+}
+#else
+void os::Bsd::clock_init() {
+  // we do dlopen's in this particular order due to bug in bsd
+  // dynamical loader (see 6348968) leading to crash on exit
+  void* handle = dlopen("librt.so.1", RTLD_LAZY);
+  if (handle == NULL) {
+    handle = dlopen("librt.so", RTLD_LAZY);
+  }
+
+  if (handle) {
+    int (*clock_getres_func)(clockid_t, struct timespec*) =
+           (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres");
+    int (*clock_gettime_func)(clockid_t, struct timespec*) =
+           (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime");
+    if (clock_getres_func && clock_gettime_func) {
+      // See if monotonic clock is supported by the kernel. Note that some
+      // early implementations simply return kernel jiffies (updated every
+      // 1/100 or 1/1000 second). It would be bad to use such a low res clock
+      // for nano time (though the monotonic property is still nice to have).
+      // It's fixed in newer kernels, however clock_getres() still returns
+      // 1/HZ. We check if clock_getres() works, but will ignore its reported
+      // resolution for now. Hopefully as people move to new kernels, this
+      // won't be a problem.
+      struct timespec res;
+      struct timespec tp;
+      if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 &&
+          clock_gettime_func(CLOCK_MONOTONIC, &tp)  == 0) {
+        // yes, monotonic clock is supported
+        _clock_gettime = clock_gettime_func;
+      } else {
+        // close librt if there is no monotonic clock
+        dlclose(handle);
+      }
+    }
+  }
+}
+#endif
+
+#ifndef _ALLBSD_SOURCE
+#ifndef SYS_clock_getres
+
+#if defined(IA32) || defined(AMD64)
+#define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229)
+#define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
+#else
+#warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
+#define sys_clock_getres(x,y)  -1
+#endif
+
+#else
+#define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
+#endif
+
+void os::Bsd::fast_thread_clock_init() {
+  if (!UseBsdPosixThreadCPUClocks) {
+    return;
+  }
+  clockid_t clockid;
+  struct timespec tp;
+  int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) =
+      (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid");
+
+  // Switch to using fast clocks for thread cpu time if
+  // the sys_clock_getres() returns 0 error code.
+  // Note, that some kernels may support the current thread
+  // clock (CLOCK_THREAD_CPUTIME_ID) but not the clocks
+  // returned by the pthread_getcpuclockid().
+  // If the fast Posix clocks are supported then the sys_clock_getres()
+  // must return at least tp.tv_sec == 0 which means a resolution
+  // better than 1 sec. This is extra check for reliability.
+
+  if(pthread_getcpuclockid_func &&
+     pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
+     sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
+
+    _supports_fast_thread_cpu_time = true;
+    _pthread_getcpuclockid = pthread_getcpuclockid_func;
+  }
+}
+#endif
+
+jlong os::javaTimeNanos() {
+  if (Bsd::supports_monotonic_clock()) {
+    struct timespec tp;
+    int status = Bsd::clock_gettime(CLOCK_MONOTONIC, &tp);
+    assert(status == 0, "gettime error");
+    jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec);
+    return result;
+  } else {
+    timeval time;
+    int status = gettimeofday(&time, NULL);
+    assert(status != -1, "bsd error");
+    jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec);
+    return 1000 * usecs;
+  }
+}
+
+void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
+  if (Bsd::supports_monotonic_clock()) {
+    info_ptr->max_value = ALL_64_BITS;
+
+    // CLOCK_MONOTONIC - amount of time since some arbitrary point in the past
+    info_ptr->may_skip_backward = false;      // not subject to resetting or drifting
+    info_ptr->may_skip_forward = false;       // not subject to resetting or drifting
+  } else {
+    // gettimeofday - based on time in seconds since the Epoch thus does not wrap
+    info_ptr->max_value = ALL_64_BITS;
+
+    // gettimeofday is a real time clock so it skips
+    info_ptr->may_skip_backward = true;
+    info_ptr->may_skip_forward = true;
+  }
+
+  info_ptr->kind = JVMTI_TIMER_ELAPSED;                // elapsed not CPU time
+}
+
+// Return the real, user, and system times in seconds from an
+// arbitrary fixed point in the past.
+bool os::getTimesSecs(double* process_real_time,
+                      double* process_user_time,
+                      double* process_system_time) {
+  struct tms ticks;
+  clock_t real_ticks = times(&ticks);
+
+  if (real_ticks == (clock_t) (-1)) {
+    return false;
+  } else {
+    double ticks_per_second = (double) clock_tics_per_sec;
+    *process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
+    *process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
+    *process_real_time = ((double) real_ticks) / ticks_per_second;
+
+    return true;
+  }
+}
+
+
+char * os::local_time_string(char *buf, size_t buflen) {
+  struct tm t;
+  time_t long_time;
+  time(&long_time);
+  localtime_r(&long_time, &t);
+  jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
+               t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
+               t.tm_hour, t.tm_min, t.tm_sec);
+  return buf;
+}
+
+struct tm* os::localtime_pd(const time_t* clock, struct tm*  res) {
+  return localtime_r(clock, res);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// runtime exit support
+
+// Note: os::shutdown() might be called very early during initialization, or
+// called from signal handler. Before adding something to os::shutdown(), make
+// sure it is async-safe and can handle partially initialized VM.
+void os::shutdown() {
+
+  // allow PerfMemory to attempt cleanup of any persistent resources
+  perfMemory_exit();
+
+  // needs to remove object in file system
+  AttachListener::abort();
+
+  // flush buffered output, finish log files
+  ostream_abort();
+
+  // Check for abort hook
+  abort_hook_t abort_hook = Arguments::abort_hook();
+  if (abort_hook != NULL) {
+    abort_hook();
+  }
+
+}
+
+// Note: os::abort() might be called very early during initialization, or
+// called from signal handler. Before adding something to os::abort(), make
+// sure it is async-safe and can handle partially initialized VM.
+void os::abort(bool dump_core) {
+  os::shutdown();
+  if (dump_core) {
+#ifndef PRODUCT
+    fdStream out(defaultStream::output_fd());
+    out.print_raw("Current thread is ");
+    char buf[16];
+    jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id());
+    out.print_raw_cr(buf);
+    out.print_raw_cr("Dumping core ...");
+#endif
+    ::abort(); // dump core
+  }
+
+  ::exit(1);
+}
+
+// Die immediately, no exit hook, no abort hook, no cleanup.
+void os::die() {
+  // _exit() on BsdThreads only kills current thread
+  ::abort();
+}
+
+// unused on bsd for now.
+void os::set_error_file(const char *logfile) {}
+
+
+// This method is a copy of JDK's sysGetLastErrorString
+// from src/solaris/hpi/src/system_md.c
+
+size_t os::lasterror(char *buf, size_t len) {
+
+  if (errno == 0)  return 0;
+
+  const char *s = ::strerror(errno);
+  size_t n = ::strlen(s);
+  if (n >= len) {
+    n = len - 1;
+  }
+  ::strncpy(buf, s, n);
+  buf[n] = '\0';
+  return n;
+}
+
+intx os::current_thread_id() { return (intx)pthread_self(); }
+int os::current_process_id() {
+
+  // Under the old bsd thread library, bsd gives each thread
+  // its own process id. Because of this each thread will return
+  // a different pid if this method were to return the result
+  // of getpid(2). Bsd provides no api that returns the pid
+  // of the launcher thread for the vm. This implementation
+  // returns a unique pid, the pid of the launcher thread
+  // that starts the vm 'process'.
+
+  // Under the NPTL, getpid() returns the same pid as the
+  // launcher thread rather than a unique pid per thread.
+  // Use gettid() if you want the old pre NPTL behaviour.
+
+  // if you are looking for the result of a call to getpid() that
+  // returns a unique pid for the calling thread, then look at the
+  // OSThread::thread_id() method in osThread_bsd.hpp file
+
+  return (int)(_initial_pid ? _initial_pid : getpid());
+}
+
+// DLL functions
+
+#define JNI_LIB_PREFIX "lib"
+#ifdef __APPLE__
+#define JNI_LIB_SUFFIX ".dylib"
+#else
+#define JNI_LIB_SUFFIX ".so"
+#endif
+
+const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; }
+
+// This must be hard coded because it's the system's temporary
+// directory not the java application's temp directory, ala java.io.tmpdir.
+#ifdef __APPLE__
+// macosx has a secure per-user temporary directory
+char temp_path_storage[PATH_MAX];
+const char* os::get_temp_directory() {
+  static char *temp_path = NULL;
+  if (temp_path == NULL) {
+    int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, temp_path_storage, PATH_MAX);
+    if (pathSize == 0 || pathSize > PATH_MAX) {
+      strlcpy(temp_path_storage, "/tmp/", sizeof(temp_path_storage));
+    }
+    temp_path = temp_path_storage;
+  }
+  return temp_path;
+}
+#else /* __APPLE__ */
+const char* os::get_temp_directory() { return "/tmp"; }
+#endif /* __APPLE__ */
+
+static bool file_exists(const char* filename) {
+  struct stat statbuf;
+  if (filename == NULL || strlen(filename) == 0) {
+    return false;
+  }
+  return os::stat(filename, &statbuf) == 0;
+}
+
+void os::dll_build_name(char* buffer, size_t buflen,
+                        const char* pname, const char* fname) {
+  // Copied from libhpi
+  const size_t pnamelen = pname ? strlen(pname) : 0;
+
+  // Quietly truncate on buffer overflow.  Should be an error.
+  if (pnamelen + strlen(fname) + strlen(JNI_LIB_PREFIX) + strlen(JNI_LIB_SUFFIX) + 2 > buflen) {
+      *buffer = '\0';
+      return;
+  }
+
+  if (pnamelen == 0) {
+    snprintf(buffer, buflen, JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX, fname);
+  } else if (strchr(pname, *os::path_separator()) != NULL) {
+    int n;
+    char** pelements = split_path(pname, &n);
+    for (int i = 0 ; i < n ; i++) {
+      // Really shouldn't be NULL, but check can't hurt
+      if (pelements[i] == NULL || strlen(pelements[i]) == 0) {
+        continue; // skip the empty path values
+      }
+      snprintf(buffer, buflen, "%s/" JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX,
+          pelements[i], fname);
+      if (file_exists(buffer)) {
+        break;
+      }
+    }
+    // release the storage
+    for (int i = 0 ; i < n ; i++) {
+      if (pelements[i] != NULL) {
+        FREE_C_HEAP_ARRAY(char, pelements[i]);
+      }
+    }
+    if (pelements != NULL) {
+      FREE_C_HEAP_ARRAY(char*, pelements);
+    }
+  } else {
+    snprintf(buffer, buflen, "%s/" JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX, pname, fname);
+  }
+}
+
+const char* os::get_current_directory(char *buf, int buflen) {
+  return getcwd(buf, buflen);
+}
+
+// check if addr is inside libjvm[_g].so
+bool os::address_is_in_vm(address addr) {
+  static address libjvm_base_addr;
+  Dl_info dlinfo;
+
+  if (libjvm_base_addr == NULL) {
+    dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo);
+    libjvm_base_addr = (address)dlinfo.dli_fbase;
+    assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm");
+  }
+
+  if (dladdr((void *)addr, &dlinfo)) {
+    if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true;
+  }
+
+  return false;
+}
+
+bool os::dll_address_to_function_name(address addr, char *buf,
+                                      int buflen, int *offset) {
+  Dl_info dlinfo;
+
+  if (dladdr((void*)addr, &dlinfo) && dlinfo.dli_sname != NULL) {
+    if (buf != NULL) {
+      if(!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
+        jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
+      }
+    }
+    if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
+    return true;
+  } else if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) {
+    if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
+       dlinfo.dli_fname, buf, buflen, offset) == Decoder::no_error) {
+       return true;
+    }
+  }
+
+  if (buf != NULL) buf[0] = '\0';
+  if (offset != NULL) *offset = -1;
+  return false;
+}
+
+#ifdef _ALLBSD_SOURCE
+// ported from solaris version
+bool os::dll_address_to_library_name(address addr, char* buf,
+                                     int buflen, int* offset) {
+  Dl_info dlinfo;
+
+  if (dladdr((void*)addr, &dlinfo)){
+     if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
+     if (offset) *offset = addr - (address)dlinfo.dli_fbase;
+     return true;
+  } else {
+     if (buf) buf[0] = '\0';
+     if (offset) *offset = -1;
+     return false;
+  }
+}
+#else
+struct _address_to_library_name {
+  address addr;          // input : memory address
+  size_t  buflen;        //         size of fname
+  char*   fname;         // output: library name
+  address base;          //         library base addr
+};
+
+static int address_to_library_name_callback(struct dl_phdr_info *info,
+                                            size_t size, void *data) {
+  int i;
+  bool found = false;
+  address libbase = NULL;
+  struct _address_to_library_name * d = (struct _address_to_library_name *)data;
+
+  // iterate through all loadable segments
+  for (i = 0; i < info->dlpi_phnum; i++) {
+    address segbase = (address)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
+    if (info->dlpi_phdr[i].p_type == PT_LOAD) {
+      // base address of a library is the lowest address of its loaded
+      // segments.
+      if (libbase == NULL || libbase > segbase) {
+        libbase = segbase;
+      }
+      // see if 'addr' is within current segment
+      if (segbase <= d->addr &&
+          d->addr < segbase + info->dlpi_phdr[i].p_memsz) {
+        found = true;
+      }
+    }
+  }
+
+  // dlpi_name is NULL or empty if the ELF file is executable, return 0
+  // so dll_address_to_library_name() can fall through to use dladdr() which
+  // can figure out executable name from argv[0].
+  if (found && info->dlpi_name && info->dlpi_name[0]) {
+    d->base = libbase;
+    if (d->fname) {
+      jio_snprintf(d->fname, d->buflen, "%s", info->dlpi_name);
+    }
+    return 1;
+  }
+  return 0;
+}
+
+bool os::dll_address_to_library_name(address addr, char* buf,
+                                     int buflen, int* offset) {
+  Dl_info dlinfo;
+  struct _address_to_library_name data;
+
+  // There is a bug in old glibc dladdr() implementation that it could resolve
+  // to wrong library name if the .so file has a base address != NULL. Here
+  // we iterate through the program headers of all loaded libraries to find
+  // out which library 'addr' really belongs to. This workaround can be
+  // removed once the minimum requirement for glibc is moved to 2.3.x.
+  data.addr = addr;
+  data.fname = buf;
+  data.buflen = buflen;
+  data.base = NULL;
+  int rslt = dl_iterate_phdr(address_to_library_name_callback, (void *)&data);
+
+  if (rslt) {
+     // buf already contains library name
+     if (offset) *offset = addr - data.base;
+     return true;
+  } else if (dladdr((void*)addr, &dlinfo)){
+     if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
+     if (offset) *offset = addr - (address)dlinfo.dli_fbase;
+     return true;
+  } else {
+     if (buf) buf[0] = '\0';
+     if (offset) *offset = -1;
+     return false;
+  }
+}
+#endif
+
+  // Loads .dll/.so and
+  // in case of error it checks if .dll/.so was built for the
+  // same architecture as Hotspot is running on
+
+#ifdef __APPLE__
+void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
+  void * result= ::dlopen(filename, RTLD_LAZY);
+  if (result != NULL) {
+    // Successful loading
+    return result;
+  }
+
+  // Read system error message into ebuf
+  ::strncpy(ebuf, ::dlerror(), ebuflen-1);
+  ebuf[ebuflen-1]='\0';
+
+  return NULL;
+}
+#else
+void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
+{
+  void * result= ::dlopen(filename, RTLD_LAZY);
+  if (result != NULL) {
+    // Successful loading
+    return result;
+  }
+
+  Elf32_Ehdr elf_head;
+
+  // Read system error message into ebuf
+  // It may or may not be overwritten below
+  ::strncpy(ebuf, ::dlerror(), ebuflen-1);
+  ebuf[ebuflen-1]='\0';
+  int diag_msg_max_length=ebuflen-strlen(ebuf);
+  char* diag_msg_buf=ebuf+strlen(ebuf);
+
+  if (diag_msg_max_length==0) {
+    // No more space in ebuf for additional diagnostics message
+    return NULL;
+  }
+
+
+  int file_descriptor= ::open(filename, O_RDONLY | O_NONBLOCK);
+
+  if (file_descriptor < 0) {
+    // Can't open library, report dlerror() message
+    return NULL;
+  }
+
+  bool failed_to_read_elf_head=
+    (sizeof(elf_head)!=
+        (::read(file_descriptor, &elf_head,sizeof(elf_head)))) ;
+
+  ::close(file_descriptor);
+  if (failed_to_read_elf_head) {
+    // file i/o error - report dlerror() msg
+    return NULL;
+  }
+
+  typedef struct {
+    Elf32_Half  code;         // Actual value as defined in elf.h
+    Elf32_Half  compat_class; // Compatibility of archs at VM's sense
+    char        elf_class;    // 32 or 64 bit
+    char        endianess;    // MSB or LSB
+    char*       name;         // String representation
+  } arch_t;
+
+  #ifndef EM_486
+  #define EM_486          6               /* Intel 80486 */
+  #endif
+
+  #ifndef EM_MIPS_RS3_LE
+  #define EM_MIPS_RS3_LE  10              /* MIPS */
+  #endif
+
+  #ifndef EM_PPC64
+  #define EM_PPC64        21              /* PowerPC64 */
+  #endif
+
+  #ifndef EM_S390
+  #define EM_S390         22              /* IBM System/390 */
+  #endif
+
+  #ifndef EM_IA_64
+  #define EM_IA_64        50              /* HP/Intel IA-64 */
+  #endif
+
+  #ifndef EM_X86_64
+  #define EM_X86_64       62              /* AMD x86-64 */
+  #endif
+
+  static const arch_t arch_array[]={
+    {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
+    {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
+    {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
+    {EM_X86_64,      EM_X86_64,  ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},
+    {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
+    {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
+    {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
+    {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
+    {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
+    {EM_ARM,         EM_ARM,     ELFCLASS32,   ELFDATA2LSB, (char*)"ARM"},
+    {EM_S390,        EM_S390,    ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"},
+    {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
+    {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
+    {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
+    {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
+    {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"}
+  };
+
+  #if  (defined IA32)
+    static  Elf32_Half running_arch_code=EM_386;
+  #elif   (defined AMD64)
+    static  Elf32_Half running_arch_code=EM_X86_64;
+  #elif  (defined IA64)
+    static  Elf32_Half running_arch_code=EM_IA_64;
+  #elif  (defined __sparc) && (defined _LP64)
+    static  Elf32_Half running_arch_code=EM_SPARCV9;
+  #elif  (defined __sparc) && (!defined _LP64)
+    static  Elf32_Half running_arch_code=EM_SPARC;
+  #elif  (defined __powerpc64__)
+    static  Elf32_Half running_arch_code=EM_PPC64;
+  #elif  (defined __powerpc__)
+    static  Elf32_Half running_arch_code=EM_PPC;
+  #elif  (defined ARM)
+    static  Elf32_Half running_arch_code=EM_ARM;
+  #elif  (defined S390)
+    static  Elf32_Half running_arch_code=EM_S390;
+  #elif  (defined ALPHA)
+    static  Elf32_Half running_arch_code=EM_ALPHA;
+  #elif  (defined MIPSEL)
+    static  Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
+  #elif  (defined PARISC)
+    static  Elf32_Half running_arch_code=EM_PARISC;
+  #elif  (defined MIPS)
+    static  Elf32_Half running_arch_code=EM_MIPS;
+  #elif  (defined M68K)
+    static  Elf32_Half running_arch_code=EM_68K;
+  #else
+    #error Method os::dll_load requires that one of following is defined:\
+         IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K
+  #endif
+
+  // Identify compatability class for VM's architecture and library's architecture
+  // Obtain string descriptions for architectures
+
+  arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
+  int running_arch_index=-1;
+
+  for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) {
+    if (running_arch_code == arch_array[i].code) {
+      running_arch_index    = i;
+    }
+    if (lib_arch.code == arch_array[i].code) {
+      lib_arch.compat_class = arch_array[i].compat_class;
+      lib_arch.name         = arch_array[i].name;
+    }
+  }
+
+  assert(running_arch_index != -1,
+    "Didn't find running architecture code (running_arch_code) in arch_array");
+  if (running_arch_index == -1) {
+    // Even though running architecture detection failed
+    // we may still continue with reporting dlerror() message
+    return NULL;
+  }
+
+  if (lib_arch.endianess != arch_array[running_arch_index].endianess) {
+    ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)");
+    return NULL;
+  }
+
+#ifndef S390
+  if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
+    ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)");
+    return NULL;
+  }
+#endif // !S390
+
+  if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
+    if ( lib_arch.name!=NULL ) {
+      ::snprintf(diag_msg_buf, diag_msg_max_length-1,
+        " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
+        lib_arch.name, arch_array[running_arch_index].name);
+    } else {
+      ::snprintf(diag_msg_buf, diag_msg_max_length-1,
+      " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
+        lib_arch.code,
+        arch_array[running_arch_index].name);
+    }
+  }
+
+  return NULL;
+}
+#endif /* !__APPLE__ */
+
+// XXX: Do we need a lock around this as per Linux?
+void* os::dll_lookup(void* handle, const char* name) {
+  return dlsym(handle, name);
+}
+
+
+static bool _print_ascii_file(const char* filename, outputStream* st) {
+  int fd = ::open(filename, O_RDONLY);
+  if (fd == -1) {
+     return false;
+  }
+
+  char buf[32];
+  int bytes;
+  while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) {
+    st->print_raw(buf, bytes);
+  }
+
+  ::close(fd);
+
+  return true;
+}
+
+void os::print_dll_info(outputStream *st) {
+   st->print_cr("Dynamic libraries:");
+#ifdef _ALLBSD_SOURCE
+#ifdef RTLD_DI_LINKMAP
+    Dl_info dli;
+    void *handle;
+    Link_map *map;
+    Link_map *p;
+
+    if (!dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli)) {
+        st->print_cr("Error: Cannot print dynamic libraries.");
+        return;
+    }
+    handle = dlopen(dli.dli_fname, RTLD_LAZY);
+    if (handle == NULL) {
+        st->print_cr("Error: Cannot print dynamic libraries.");
+        return;
+    }
+    dlinfo(handle, RTLD_DI_LINKMAP, &map);
+    if (map == NULL) {
+        st->print_cr("Error: Cannot print dynamic libraries.");
+        return;
+    }
+
+    while (map->l_prev != NULL)
+        map = map->l_prev;
+
+    while (map != NULL) {
+        st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
+        map = map->l_next;
+    }
+
+    dlclose(handle);
+#elif defined(__APPLE__)
+    uint32_t count;
+    uint32_t i;
+
+    count = _dyld_image_count();
+    for (i = 1; i < count; i++) {
+        const char *name = _dyld_get_image_name(i);
+        intptr_t slide = _dyld_get_image_vmaddr_slide(i);
+        st->print_cr(PTR_FORMAT " \t%s", slide, name);
+    }
+#else
+   st->print_cr("Error: Cannot print dynamic libraries.");
+#endif
+#else
+   char fname[32];
+   pid_t pid = os::Bsd::gettid();
+
+   jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
+
+   if (!_print_ascii_file(fname, st)) {
+     st->print("Can not get library information for pid = %d\n", pid);
+   }
+#endif
+}
+
+
+void os::print_os_info(outputStream* st) {
+  st->print("OS:");
+
+  // Try to identify popular distros.
+  // Most Bsd distributions have /etc/XXX-release file, which contains
+  // the OS version string. Some have more than one /etc/XXX-release file
+  // (e.g. Mandrake has both /etc/mandrake-release and /etc/redhat-release.),
+  // so the order is important.
+  if (!_print_ascii_file("/etc/mandrake-release", st) &&
+      !_print_ascii_file("/etc/sun-release", st) &&
+      !_print_ascii_file("/etc/redhat-release", st) &&
+      !_print_ascii_file("/etc/SuSE-release", st) &&
+      !_print_ascii_file("/etc/turbobsd-release", st) &&
+      !_print_ascii_file("/etc/gentoo-release", st) &&
+      !_print_ascii_file("/etc/debian_version", st) &&
+      !_print_ascii_file("/etc/ltib-release", st) &&
+      !_print_ascii_file("/etc/angstrom-version", st)) {
+      st->print("Bsd");
+  }
+  st->cr();
+
+  // kernel
+  st->print("uname:");
+  struct utsname name;
+  uname(&name);
+  st->print(name.sysname); st->print(" ");
+  st->print(name.release); st->print(" ");
+  st->print(name.version); st->print(" ");
+  st->print(name.machine);
+  st->cr();
+
+#ifndef _ALLBSD_SOURCE
+  // Print warning if unsafe chroot environment detected
+  if (unsafe_chroot_detected) {
+    st->print("WARNING!! ");
+    st->print_cr(unstable_chroot_error);
+  }
+
+  // libc, pthread
+  st->print("libc:");
+  st->print(os::Bsd::glibc_version()); st->print(" ");
+  st->print(os::Bsd::libpthread_version()); st->print(" ");
+  if (os::Bsd::is_BsdThreads()) {
+     st->print("(%s stack)", os::Bsd::is_floating_stack() ? "floating" : "fixed");
+  }
+  st->cr();
+#endif
+
+  // rlimit
+  st->print("rlimit:");
+  struct rlimit rlim;
+
+  st->print(" STACK ");
+  getrlimit(RLIMIT_STACK, &rlim);
+  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
+  else st->print("%uk", rlim.rlim_cur >> 10);
+
+  st->print(", CORE ");
+  getrlimit(RLIMIT_CORE, &rlim);
+  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
+  else st->print("%uk", rlim.rlim_cur >> 10);
+
+  st->print(", NPROC ");
+  getrlimit(RLIMIT_NPROC, &rlim);
+  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
+  else st->print("%d", rlim.rlim_cur);
+
+  st->print(", NOFILE ");
+  getrlimit(RLIMIT_NOFILE, &rlim);
+  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
+  else st->print("%d", rlim.rlim_cur);
+
+#ifndef _ALLBSD_SOURCE
+  st->print(", AS ");
+  getrlimit(RLIMIT_AS, &rlim);
+  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
+  else st->print("%uk", rlim.rlim_cur >> 10);
+  st->cr();
+
+  // load average
+  st->print("load average:");
+  double loadavg[3];
+  os::loadavg(loadavg, 3);
+  st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
+  st->cr();
+#endif
+}
+
+void os::pd_print_cpu_info(outputStream* st) {
+  // Nothing to do for now.
+}
+
+void os::print_memory_info(outputStream* st) {
+
+  st->print("Memory:");
+  st->print(" %dk page", os::vm_page_size()>>10);
+
+#ifndef _ALLBSD_SOURCE
+  // values in struct sysinfo are "unsigned long"
+  struct sysinfo si;
+  sysinfo(&si);
+#endif
+
+  st->print(", physical " UINT64_FORMAT "k",
+            os::physical_memory() >> 10);
+  st->print("(" UINT64_FORMAT "k free)",
+            os::available_memory() >> 10);
+#ifndef _ALLBSD_SOURCE
+  st->print(", swap " UINT64_FORMAT "k",
+            ((jlong)si.totalswap * si.mem_unit) >> 10);
+  st->print("(" UINT64_FORMAT "k free)",
+            ((jlong)si.freeswap * si.mem_unit) >> 10);
+#endif
+  st->cr();
+
+  // meminfo
+  st->print("\n/proc/meminfo:\n");
+  _print_ascii_file("/proc/meminfo", st);
+  st->cr();
+}
+
+// Taken from /usr/include/bits/siginfo.h  Supposed to be architecture specific
+// but they're the same for all the bsd arch that we support
+// and they're the same for solaris but there's no common place to put this.
+const char *ill_names[] = { "ILL0", "ILL_ILLOPC", "ILL_ILLOPN", "ILL_ILLADR",
+                          "ILL_ILLTRP", "ILL_PRVOPC", "ILL_PRVREG",
+                          "ILL_COPROC", "ILL_BADSTK" };
+
+const char *fpe_names[] = { "FPE0", "FPE_INTDIV", "FPE_INTOVF", "FPE_FLTDIV",
+                          "FPE_FLTOVF", "FPE_FLTUND", "FPE_FLTRES",
+                          "FPE_FLTINV", "FPE_FLTSUB", "FPE_FLTDEN" };
+
+const char *segv_names[] = { "SEGV0", "SEGV_MAPERR", "SEGV_ACCERR" };
+
+const char *bus_names[] = { "BUS0", "BUS_ADRALN", "BUS_ADRERR", "BUS_OBJERR" };
+
+void os::print_siginfo(outputStream* st, void* siginfo) {
+  st->print("siginfo:");
+
+  const int buflen = 100;
+  char buf[buflen];
+  siginfo_t *si = (siginfo_t*)siginfo;
+  st->print("si_signo=%s: ", os::exception_name(si->si_signo, buf, buflen));
+  if (si->si_errno != 0 && strerror_r(si->si_errno, buf, buflen) == 0) {
+    st->print("si_errno=%s", buf);
+  } else {
+    st->print("si_errno=%d", si->si_errno);
+  }
+  const int c = si->si_code;
+  assert(c > 0, "unexpected si_code");
+  switch (si->si_signo) {
+  case SIGILL:
+    st->print(", si_code=%d (%s)", c, c > 8 ? "" : ill_names[c]);
+    st->print(", si_addr=" PTR_FORMAT, si->si_addr);
+    break;
+  case SIGFPE:
+    st->print(", si_code=%d (%s)", c, c > 9 ? "" : fpe_names[c]);
+    st->print(", si_addr=" PTR_FORMAT, si->si_addr);
+    break;
+  case SIGSEGV:
+    st->print(", si_code=%d (%s)", c, c > 2 ? "" : segv_names[c]);
+    st->print(", si_addr=" PTR_FORMAT, si->si_addr);
+    break;
+  case SIGBUS:
+    st->print(", si_code=%d (%s)", c, c > 3 ? "" : bus_names[c]);
+    st->print(", si_addr=" PTR_FORMAT, si->si_addr);
+    break;
+  default:
+    st->print(", si_code=%d", si->si_code);
+    // no si_addr
+  }
+
+  if ((si->si_signo == SIGBUS || si->si_signo == SIGSEGV) &&
+      UseSharedSpaces) {
+    FileMapInfo* mapinfo = FileMapInfo::current_info();
+    if (mapinfo->is_in_shared_space(si->si_addr)) {
+      st->print("\n\nError accessing class data sharing archive."   \
+                " Mapped file inaccessible during execution, "      \
+                " possible disk/network problem.");
+    }
+  }
+  st->cr();
+}
+
+
+static void print_signal_handler(outputStream* st, int sig,
+                                 char* buf, size_t buflen);
+
+void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
+  st->print_cr("Signal Handlers:");
+  print_signal_handler(st, SIGSEGV, buf, buflen);
+  print_signal_handler(st, SIGBUS , buf, buflen);
+  print_signal_handler(st, SIGFPE , buf, buflen);
+  print_signal_handler(st, SIGPIPE, buf, buflen);
+  print_signal_handler(st, SIGXFSZ, buf, buflen);
+  print_signal_handler(st, SIGILL , buf, buflen);
+  print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen);
+  print_signal_handler(st, SR_signum, buf, buflen);
+  print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
+  print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
+  print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
+  print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
+}
+
+static char saved_jvm_path[MAXPATHLEN] = {0};
+
+// Find the full path to the current module, libjvm.so or libjvm_g.so
+void os::jvm_path(char *buf, jint buflen) {
+  // Error checking.
+  if (buflen < MAXPATHLEN) {
+    assert(false, "must use a large-enough buffer");
+    buf[0] = '\0';
+    return;
+  }
+  // Lazy resolve the path to current module.
+  if (saved_jvm_path[0] != 0) {
+    strcpy(buf, saved_jvm_path);
+    return;
+  }
+
+  char dli_fname[MAXPATHLEN];
+  bool ret = dll_address_to_library_name(
+                CAST_FROM_FN_PTR(address, os::jvm_path),
+                dli_fname, sizeof(dli_fname), NULL);
+  assert(ret != 0, "cannot locate libjvm");
+  char *rp = realpath(dli_fname, buf);
+  if (rp == NULL)
+    return;
+
+  if (Arguments::created_by_gamma_launcher()) {
+    // Support for the gamma launcher.  Typical value for buf is
+    // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so".  If "/jre/lib/" appears at
+    // the right place in the string, then assume we are installed in a JDK and
+    // we're done.  Otherwise, check for a JAVA_HOME environment variable and fix
+    // up the path so it looks like libjvm.so is installed there (append a
+    // fake suffix hotspot/libjvm.so).
+    const char *p = buf + strlen(buf) - 1;
+    for (int count = 0; p > buf && count < 5; ++count) {
+      for (--p; p > buf && *p != '/'; --p)
+        /* empty */ ;
+    }
+
+    if (strncmp(p, "/jre/lib/", 9) != 0) {
+      // Look for JAVA_HOME in the environment.
+      char* java_home_var = ::getenv("JAVA_HOME");
+      if (java_home_var != NULL && java_home_var[0] != 0) {
+        char* jrelib_p;
+        int len;
+
+        // Check the current module name "libjvm.so" or "libjvm_g.so".
+        p = strrchr(buf, '/');
+        assert(strstr(p, "/libjvm") == p, "invalid library name");
+        p = strstr(p, "_g") ? "_g" : "";
+
+        rp = realpath(java_home_var, buf);
+        if (rp == NULL)
+          return;
+
+        // determine if this is a legacy image or modules image
+        // modules image doesn't have "jre" subdirectory
+        len = strlen(buf);
+        jrelib_p = buf + len;
+        snprintf(jrelib_p, buflen-len, "/jre/lib/%s", cpu_arch);
+        if (0 != access(buf, F_OK)) {
+          snprintf(jrelib_p, buflen-len, "/lib/%s", cpu_arch);
+        }
+
+        if (0 == access(buf, F_OK)) {
+          // Use current module name "libjvm[_g].so" instead of
+          // "libjvm"debug_only("_g")".so" since for fastdebug version
+          // we should have "libjvm.so" but debug_only("_g") adds "_g"!
+          len = strlen(buf);
+          snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p);
+        } else {
+          // Go back to path of .so
+          rp = realpath(dli_fname, buf);
+          if (rp == NULL)
+            return;
+        }
+      }
+    }
+  }
+
+  strcpy(saved_jvm_path, buf);
+}
+
+void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
+  // no prefix required, not even "_"
+}
+
+void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
+  // no suffix required
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// sun.misc.Signal support
+
+static volatile jint sigint_count = 0;
+
+static void
+UserHandler(int sig, void *siginfo, void *context) {
+  // 4511530 - sem_post is serialized and handled by the manager thread. When
+  // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
+  // don't want to flood the manager thread with sem_post requests.
+  if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1)
+      return;
+
+  // Ctrl-C is pressed during error reporting, likely because the error
+  // handler fails to abort. Let VM die immediately.
+  if (sig == SIGINT && is_error_reported()) {
+     os::die();
+  }
+
+  os::signal_notify(sig);
+}
+
+void* os::user_handler() {
+  return CAST_FROM_FN_PTR(void*, UserHandler);
+}
+
+extern "C" {
+  typedef void (*sa_handler_t)(int);
+  typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
+}
+
+void* os::signal(int signal_number, void* handler) {
+  struct sigaction sigAct, oldSigAct;
+
+  sigfillset(&(sigAct.sa_mask));
+  sigAct.sa_flags   = SA_RESTART|SA_SIGINFO;
+  sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler);
+
+  if (sigaction(signal_number, &sigAct, &oldSigAct)) {
+    // -1 means registration failed
+    return (void *)-1;
+  }
+
+  return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
+}
+
+void os::signal_raise(int signal_number) {
+  ::raise(signal_number);
+}
+
+/*
+ * The following code is moved from os.cpp for making this
+ * code platform specific, which it is by its very nature.
+ */
+
+// Will be modified when max signal is changed to be dynamic
+int os::sigexitnum_pd() {
+  return NSIG;
+}
+
+// a counter for each possible signal value
+static volatile jint pending_signals[NSIG+1] = { 0 };
+
+// Bsd(POSIX) specific hand shaking semaphore.
+#ifdef __APPLE__
+static semaphore_t sig_sem;
+#define SEM_INIT(sem, value)    semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, value)
+#define SEM_WAIT(sem)           semaphore_wait(sem);
+#define SEM_POST(sem)           semaphore_signal(sem);
+#else
+static sem_t sig_sem;
+#define SEM_INIT(sem, value)    sem_init(&sem, 0, value)
+#define SEM_WAIT(sem)           sem_wait(&sem);
+#define SEM_POST(sem)           sem_post(&sem);
+#endif
+
+void os::signal_init_pd() {
+  // Initialize signal structures
+  ::memset((void*)pending_signals, 0, sizeof(pending_signals));
+
+  // Initialize signal semaphore
+  ::SEM_INIT(sig_sem, 0);
+}
+
+void os::signal_notify(int sig) {
+  Atomic::inc(&pending_signals[sig]);
+  ::SEM_POST(sig_sem);
+}
+
+static int check_pending_signals(bool wait) {
+  Atomic::store(0, &sigint_count);
+  for (;;) {
+    for (int i = 0; i < NSIG + 1; i++) {
+      jint n = pending_signals[i];
+      if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
+        return i;
+      }
+    }
+    if (!wait) {
+      return -1;
+    }
+    JavaThread *thread = JavaThread::current();
+    ThreadBlockInVM tbivm(thread);
+
+    bool threadIsSuspended;
+    do {
+      thread->set_suspend_equivalent();
+      // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
+      ::SEM_WAIT(sig_sem);
+
+      // were we externally suspended while we were waiting?
+      threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
+      if (threadIsSuspended) {
+        //
+        // The semaphore has been incremented, but while we were waiting
+        // another thread suspended us. We don't want to continue running
+        // while suspended because that would surprise the thread that
+        // suspended us.
+        //
+        ::SEM_POST(sig_sem);
+
+        thread->java_suspend_self();
+      }
+    } while (threadIsSuspended);
+  }
+}
+
+int os::signal_lookup() {
+  return check_pending_signals(false);
+}
+
+int os::signal_wait() {
+  return check_pending_signals(true);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Virtual Memory
+
+int os::vm_page_size() {
+  // Seems redundant as all get out
+  assert(os::Bsd::page_size() != -1, "must call os::init");
+  return os::Bsd::page_size();
+}
+
+// Solaris allocates memory by pages.
+int os::vm_allocation_granularity() {
+  assert(os::Bsd::page_size() != -1, "must call os::init");
+  return os::Bsd::page_size();
+}
+
+// Rationale behind this function:
+//  current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable
+//  mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get
+//  samples for JITted code. Here we create private executable mapping over the code cache
+//  and then we can use standard (well, almost, as mapping can change) way to provide
+//  info for the reporting script by storing timestamp and location of symbol
+void bsd_wrap_code(char* base, size_t size) {
+  static volatile jint cnt = 0;
+
+  if (!UseOprofile) {
+    return;
+  }
+
+  char buf[PATH_MAX + 1];
+  int num = Atomic::add(1, &cnt);
+
+  snprintf(buf, PATH_MAX + 1, "%s/hs-vm-%d-%d",
+           os::get_temp_directory(), os::current_process_id(), num);
+  unlink(buf);
+
+  int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
+
+  if (fd != -1) {
+    off_t rv = ::lseek(fd, size-2, SEEK_SET);
+    if (rv != (off_t)-1) {
+      if (::write(fd, "", 1) == 1) {
+        mmap(base, size,
+             PROT_READ|PROT_WRITE|PROT_EXEC,
+             MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
+      }
+    }
+    ::close(fd);
+    unlink(buf);
+  }
+}
+
+// NOTE: Bsd kernel does not really reserve the pages for us.
+//       All it does is to check if there are enough free pages
+//       left at the time of mmap(). This could be a potential
+//       problem.
+bool os::commit_memory(char* addr, size_t size, bool exec) {
+  int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
+#ifdef __OpenBSD__
+  // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
+  return ::mprotect(addr, size, prot) == 0;
+#else
+  uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
+                                   MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
+  return res != (uintptr_t) MAP_FAILED;
+#endif
+}
+
+#ifndef _ALLBSD_SOURCE
+// Define MAP_HUGETLB here so we can build HotSpot on old systems.
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB 0x40000
+#endif
+
+// Define MADV_HUGEPAGE here so we can build HotSpot on old systems.
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE 14
+#endif
+#endif
+
+bool os::commit_memory(char* addr, size_t size, size_t alignment_hint,
+                       bool exec) {
+#ifndef _ALLBSD_SOURCE
+  if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
+    int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
+    uintptr_t res =
+      (uintptr_t) ::mmap(addr, size, prot,
+                         MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_HUGETLB,
+                         -1, 0);
+    return res != (uintptr_t) MAP_FAILED;
+  }
+#endif
+
+  return commit_memory(addr, size, exec);
+}
+
+void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
+#ifndef _ALLBSD_SOURCE
+  if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
+    // We don't check the return value: madvise(MADV_HUGEPAGE) may not
+    // be supported or the memory may already be backed by huge pages.
+    ::madvise(addr, bytes, MADV_HUGEPAGE);
+  }
+#endif
+}
+
+void os::free_memory(char *addr, size_t bytes) {
+  ::madvise(addr, bytes, MADV_DONTNEED);
+}
+
+void os::numa_make_global(char *addr, size_t bytes) {
+}
+
+void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
+}
+
+bool os::numa_topology_changed()   { return false; }
+
+size_t os::numa_get_groups_num() {
+  return 1;
+}
+
+int os::numa_get_group_id() {
+  return 0;
+}
+
+size_t os::numa_get_leaf_groups(int *ids, size_t size) {
+  if (size > 0) {
+    ids[0] = 0;
+    return 1;
+  }
+  return 0;
+}
+
+bool os::get_page_info(char *start, page_info* info) {
+  return false;
+}
+
+char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
+  return end;
+}
+
+#ifndef _ALLBSD_SOURCE
+// Something to do with the numa-aware allocator needs these symbols
+extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
+extern "C" JNIEXPORT void numa_error(char *where) { }
+extern "C" JNIEXPORT int fork1() { return fork(); }
+
+
+// If we are running with libnuma version > 2, then we should
+// be trying to use symbols with versions 1.1
+// If we are running with earlier version, which did not have symbol versions,
+// we should use the base version.
+void* os::Bsd::libnuma_dlsym(void* handle, const char *name) {
+  void *f = dlvsym(handle, name, "libnuma_1.1");
+  if (f == NULL) {
+    f = dlsym(handle, name);
+  }
+  return f;
+}
+
+bool os::Bsd::libnuma_init() {
+  // sched_getcpu() should be in libc.
+  set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
+                                  dlsym(RTLD_DEFAULT, "sched_getcpu")));
+
+  if (sched_getcpu() != -1) { // Does it work?
+    void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
+    if (handle != NULL) {
+      set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
+                                           libnuma_dlsym(handle, "numa_node_to_cpus")));
+      set_numa_max_node(CAST_TO_FN_PTR(numa_max_node_func_t,
+                                       libnuma_dlsym(handle, "numa_max_node")));
+      set_numa_available(CAST_TO_FN_PTR(numa_available_func_t,
+                                        libnuma_dlsym(handle, "numa_available")));
+      set_numa_tonode_memory(CAST_TO_FN_PTR(numa_tonode_memory_func_t,
+                                            libnuma_dlsym(handle, "numa_tonode_memory")));
+      set_numa_interleave_memory(CAST_TO_FN_PTR(numa_interleave_memory_func_t,
+                                            libnuma_dlsym(handle, "numa_interleave_memory")));
+
+
+      if (numa_available() != -1) {
+        set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes"));
+        // Create a cpu -> node mapping
+        _cpu_to_node = new (ResourceObj::C_HEAP) GrowableArray<int>(0, true);
+        rebuild_cpu_to_node_map();
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+// rebuild_cpu_to_node_map() constructs a table mapping cpud id to node id.
+// The table is later used in get_node_by_cpu().
+void os::Bsd::rebuild_cpu_to_node_map() {
+  const size_t NCPUS = 32768; // Since the buffer size computation is very obscure
+                              // in libnuma (possible values are starting from 16,
+                              // and continuing up with every other power of 2, but less
+                              // than the maximum number of CPUs supported by kernel), and
+                              // is a subject to change (in libnuma version 2 the requirements
+                              // are more reasonable) we'll just hardcode the number they use
+                              // in the library.
+  const size_t BitsPerCLong = sizeof(long) * CHAR_BIT;
+
+  size_t cpu_num = os::active_processor_count();
+  size_t cpu_map_size = NCPUS / BitsPerCLong;
+  size_t cpu_map_valid_size =
+    MIN2((cpu_num + BitsPerCLong - 1) / BitsPerCLong, cpu_map_size);
+
+  cpu_to_node()->clear();
+  cpu_to_node()->at_grow(cpu_num - 1);
+  size_t node_num = numa_get_groups_num();
+
+  unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size);
+  for (size_t i = 0; i < node_num; i++) {
+    if (numa_node_to_cpus(i, cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) {
+      for (size_t j = 0; j < cpu_map_valid_size; j++) {
+        if (cpu_map[j] != 0) {
+          for (size_t k = 0; k < BitsPerCLong; k++) {
+            if (cpu_map[j] & (1UL << k)) {
+              cpu_to_node()->at_put(j * BitsPerCLong + k, i);
+            }
+          }
+        }
+      }
+    }
+  }
+  FREE_C_HEAP_ARRAY(unsigned long, cpu_map);
+}
+
+int os::Bsd::get_node_by_cpu(int cpu_id) {
+  if (cpu_to_node() != NULL && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) {
+    return cpu_to_node()->at(cpu_id);
+  }
+  return -1;
+}
+
+GrowableArray<int>* os::Bsd::_cpu_to_node;
+os::Bsd::sched_getcpu_func_t os::Bsd::_sched_getcpu;
+os::Bsd::numa_node_to_cpus_func_t os::Bsd::_numa_node_to_cpus;
+os::Bsd::numa_max_node_func_t os::Bsd::_numa_max_node;
+os::Bsd::numa_available_func_t os::Bsd::_numa_available;
+os::Bsd::numa_tonode_memory_func_t os::Bsd::_numa_tonode_memory;
+os::Bsd::numa_interleave_memory_func_t os::Bsd::_numa_interleave_memory;
+unsigned long* os::Bsd::_numa_all_nodes;
+#endif
+
+bool os::uncommit_memory(char* addr, size_t size) {
+#ifdef __OpenBSD__
+  // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
+  return ::mprotect(addr, size, PROT_NONE) == 0;
+#else
+  uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
+                MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
+  return res  != (uintptr_t) MAP_FAILED;
+#endif
+}
+
+bool os::create_stack_guard_pages(char* addr, size_t size) {
+  return os::commit_memory(addr, size);
+}
+
+// If this is a growable mapping, remove the guard pages entirely by
+// munmap()ping them.  If not, just call uncommit_memory().
+bool os::remove_stack_guard_pages(char* addr, size_t size) {
+  return os::uncommit_memory(addr, size);
+}
+
+static address _highest_vm_reserved_address = NULL;
+
+// If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory
+// at 'requested_addr'. If there are existing memory mappings at the same
+// location, however, they will be overwritten. If 'fixed' is false,
+// 'requested_addr' is only treated as a hint, the return value may or
+// may not start from the requested address. Unlike Bsd mmap(), this
+// function returns NULL to indicate failure.
+static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) {
+  char * addr;
+  int flags;
+
+  flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS;
+  if (fixed) {
+    assert((uintptr_t)requested_addr % os::Bsd::page_size() == 0, "unaligned address");
+    flags |= MAP_FIXED;
+  }
+
+  // Map uncommitted pages PROT_READ and PROT_WRITE, change access
+  // to PROT_EXEC if executable when we commit the page.
+  addr = (char*)::mmap(requested_addr, bytes, PROT_READ|PROT_WRITE,
+                       flags, -1, 0);
+
+  if (addr != MAP_FAILED) {
+    // anon_mmap() should only get called during VM initialization,
+    // don't need lock (actually we can skip locking even it can be called
+    // from multiple threads, because _highest_vm_reserved_address is just a
+    // hint about the upper limit of non-stack memory regions.)
+    if ((address)addr + bytes > _highest_vm_reserved_address) {
+      _highest_vm_reserved_address = (address)addr + bytes;
+    }
+  }
+
+  return addr == MAP_FAILED ? NULL : addr;
+}
+
+// Don't update _highest_vm_reserved_address, because there might be memory
+// regions above addr + size. If so, releasing a memory region only creates
+// a hole in the address space, it doesn't help prevent heap-stack collision.
+//
+static int anon_munmap(char * addr, size_t size) {
+  return ::munmap(addr, size) == 0;
+}
+
+char* os::reserve_memory(size_t bytes, char* requested_addr,
+                         size_t alignment_hint) {
+  return anon_mmap(requested_addr, bytes, (requested_addr != NULL));
+}
+
+bool os::release_memory(char* addr, size_t size) {
+  return anon_munmap(addr, size);
+}
+
+static address highest_vm_reserved_address() {
+  return _highest_vm_reserved_address;
+}
+
+static bool bsd_mprotect(char* addr, size_t size, int prot) {
+  // Bsd wants the mprotect address argument to be page aligned.
+  char* bottom = (char*)align_size_down((intptr_t)addr, os::Bsd::page_size());
+
+  // According to SUSv3, mprotect() should only be used with mappings
+  // established by mmap(), and mmap() always maps whole pages. Unaligned
+  // 'addr' likely indicates problem in the VM (e.g. trying to change
+  // protection of malloc'ed or statically allocated memory). Check the
+  // caller if you hit this assert.
+  assert(addr == bottom, "sanity check");
+
+  size = align_size_up(pointer_delta(addr, bottom, 1) + size, os::Bsd::page_size());
+  return ::mprotect(bottom, size, prot) == 0;
+}
+
+// Set protections specified
+bool os::protect_memory(char* addr, size_t bytes, ProtType prot,
+                        bool is_committed) {
+  unsigned int p = 0;
+  switch (prot) {
+  case MEM_PROT_NONE: p = PROT_NONE; break;
+  case MEM_PROT_READ: p = PROT_READ; break;
+  case MEM_PROT_RW:   p = PROT_READ|PROT_WRITE; break;
+  case MEM_PROT_RWX:  p = PROT_READ|PROT_WRITE|PROT_EXEC; break;
+  default:
+    ShouldNotReachHere();
+  }
+  // is_committed is unused.
+  return bsd_mprotect(addr, bytes, p);
+}
+
+bool os::guard_memory(char* addr, size_t size) {
+  return bsd_mprotect(addr, size, PROT_NONE);
+}
+
+bool os::unguard_memory(char* addr, size_t size) {
+  return bsd_mprotect(addr, size, PROT_READ|PROT_WRITE);
+}
+
+bool os::Bsd::hugetlbfs_sanity_check(bool warn, size_t page_size) {
+  bool result = false;
+#ifndef _ALLBSD_SOURCE
+  void *p = mmap (NULL, page_size, PROT_READ|PROT_WRITE,
+                  MAP_ANONYMOUS|MAP_PRIVATE|MAP_HUGETLB,
+                  -1, 0);
+
+  if (p != (void *) -1) {
+    // We don't know if this really is a huge page or not.
+    FILE *fp = fopen("/proc/self/maps", "r");
+    if (fp) {
+      while (!feof(fp)) {
+        char chars[257];
+        long x = 0;
+        if (fgets(chars, sizeof(chars), fp)) {
+          if (sscanf(chars, "%lx-%*x", &x) == 1
+              && x == (long)p) {
+            if (strstr (chars, "hugepage")) {
+              result = true;
+              break;
+            }
+          }
+        }
+      }
+      fclose(fp);
+    }
+    munmap (p, page_size);
+    if (result)
+      return true;
+  }
+
+  if (warn) {
+    warning("HugeTLBFS is not supported by the operating system.");
+  }
+#endif
+
+  return result;
+}
+
+/*
+* Set the coredump_filter bits to include largepages in core dump (bit 6)
+*
+* From the coredump_filter documentation:
+*
+* - (bit 0) anonymous private memory
+* - (bit 1) anonymous shared memory
+* - (bit 2) file-backed private memory
+* - (bit 3) file-backed shared memory
+* - (bit 4) ELF header pages in file-backed private memory areas (it is
+*           effective only if the bit 2 is cleared)
+* - (bit 5) hugetlb private memory
+* - (bit 6) hugetlb shared memory
+*/
+static void set_coredump_filter(void) {
+  FILE *f;
+  long cdm;
+
+  if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
+    return;
+  }
+
+  if (fscanf(f, "%lx", &cdm) != 1) {
+    fclose(f);
+    return;
+  }
+
+  rewind(f);
+
+  if ((cdm & LARGEPAGES_BIT) == 0) {
+    cdm |= LARGEPAGES_BIT;
+    fprintf(f, "%#lx", cdm);
+  }
+
+  fclose(f);
+}
+
+// Large page support
+
+static size_t _large_page_size = 0;
+
+void os::large_page_init() {
+#ifndef _ALLBSD_SOURCE
+  if (!UseLargePages) {
+    UseHugeTLBFS = false;
+    UseSHM = false;
+    return;
+  }
+
+  if (FLAG_IS_DEFAULT(UseHugeTLBFS) && FLAG_IS_DEFAULT(UseSHM)) {
+    // If UseLargePages is specified on the command line try both methods,
+    // if it's default, then try only HugeTLBFS.
+    if (FLAG_IS_DEFAULT(UseLargePages)) {
+      UseHugeTLBFS = true;
+    } else {
+      UseHugeTLBFS = UseSHM = true;
+    }
+  }
+
+  if (LargePageSizeInBytes) {
+    _large_page_size = LargePageSizeInBytes;
+  } else {
+    // large_page_size on Bsd is used to round up heap size. x86 uses either
+    // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
+    // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
+    // page as large as 256M.
+    //
+    // Here we try to figure out page size by parsing /proc/meminfo and looking
+    // for a line with the following format:
+    //    Hugepagesize:     2048 kB
+    //
+    // If we can't determine the value (e.g. /proc is not mounted, or the text
+    // format has been changed), we'll use the largest page size supported by
+    // the processor.
+
+#ifndef ZERO
+    _large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
+                       ARM_ONLY(2 * M) PPC_ONLY(4 * M);
+#endif // ZERO
+
+    FILE *fp = fopen("/proc/meminfo", "r");
+    if (fp) {
+      while (!feof(fp)) {
+        int x = 0;
+        char buf[16];
+        if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
+          if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
+            _large_page_size = x * K;
+            break;
+          }
+        } else {
+          // skip to next line
+          for (;;) {
+            int ch = fgetc(fp);
+            if (ch == EOF || ch == (int)'\n') break;
+          }
+        }
+      }
+      fclose(fp);
+    }
+  }
+
+  // print a warning if any large page related flag is specified on command line
+  bool warn_on_failure = !FLAG_IS_DEFAULT(UseHugeTLBFS);
+
+  const size_t default_page_size = (size_t)Bsd::page_size();
+  if (_large_page_size > default_page_size) {
+    _page_sizes[0] = _large_page_size;
+    _page_sizes[1] = default_page_size;
+    _page_sizes[2] = 0;
+  }
+  UseHugeTLBFS = UseHugeTLBFS &&
+                 Bsd::hugetlbfs_sanity_check(warn_on_failure, _large_page_size);
+
+  if (UseHugeTLBFS)
+    UseSHM = false;
+
+  UseLargePages = UseHugeTLBFS || UseSHM;
+
+  set_coredump_filter();
+#endif
+}
+
+#ifndef _ALLBSD_SOURCE
+#ifndef SHM_HUGETLB
+#define SHM_HUGETLB 04000
+#endif
+#endif
+
+char* os::reserve_memory_special(size_t bytes, char* req_addr, bool exec) {
+  // "exec" is passed in but not used.  Creating the shared image for
+  // the code cache doesn't have an SHM_X executable permission to check.
+  assert(UseLargePages && UseSHM, "only for SHM large pages");
+
+  key_t key = IPC_PRIVATE;
+  char *addr;
+
+  bool warn_on_failure = UseLargePages &&
+                        (!FLAG_IS_DEFAULT(UseLargePages) ||
+                         !FLAG_IS_DEFAULT(LargePageSizeInBytes)
+                        );
+  char msg[128];
+
+  // Create a large shared memory region to attach to based on size.
+  // Currently, size is the total size of the heap
+#ifndef _ALLBSD_SOURCE
+  int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
+#else
+  int shmid = shmget(key, bytes, IPC_CREAT|SHM_R|SHM_W);
+#endif
+  if (shmid == -1) {
+     // Possible reasons for shmget failure:
+     // 1. shmmax is too small for Java heap.
+     //    > check shmmax value: cat /proc/sys/kernel/shmmax
+     //    > increase shmmax value: echo "0xffffffff" > /proc/sys/kernel/shmmax
+     // 2. not enough large page memory.
+     //    > check available large pages: cat /proc/meminfo
+     //    > increase amount of large pages:
+     //          echo new_value > /proc/sys/vm/nr_hugepages
+     //      Note 1: different Bsd may use different name for this property,
+     //            e.g. on Redhat AS-3 it is "hugetlb_pool".
+     //      Note 2: it's possible there's enough physical memory available but
+     //            they are so fragmented after a long run that they can't
+     //            coalesce into large pages. Try to reserve large pages when
+     //            the system is still "fresh".
+     if (warn_on_failure) {
+       jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno);
+       warning(msg);
+     }
+     return NULL;
+  }
+
+  // attach to the region
+  addr = (char*)shmat(shmid, req_addr, 0);
+  int err = errno;
+
+  // Remove shmid. If shmat() is successful, the actual shared memory segment
+  // will be deleted when it's detached by shmdt() or when the process
+  // terminates. If shmat() is not successful this will remove the shared
+  // segment immediately.
+  shmctl(shmid, IPC_RMID, NULL);
+
+  if ((intptr_t)addr == -1) {
+     if (warn_on_failure) {
+       jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err);
+       warning(msg);
+     }
+     return NULL;
+  }
+
+  return addr;
+}
+
+bool os::release_memory_special(char* base, size_t bytes) {
+  // detaching the SHM segment will also delete it, see reserve_memory_special()
+  int rslt = shmdt(base);
+  return rslt == 0;
+}
+
+size_t os::large_page_size() {
+  return _large_page_size;
+}
+
+// HugeTLBFS allows application to commit large page memory on demand;
+// with SysV SHM the entire memory region must be allocated as shared
+// memory.
+bool os::can_commit_large_page_memory() {
+  return UseHugeTLBFS;
+}
+
+bool os::can_execute_large_page_memory() {
+  return UseHugeTLBFS;
+}
+
+// Reserve memory at an arbitrary address, only if that area is
+// available (and not reserved for something else).
+
+char* os::attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
+  const int max_tries = 10;
+  char* base[max_tries];
+  size_t size[max_tries];
+  const size_t gap = 0x000000;
+
+  // Assert only that the size is a multiple of the page size, since
+  // that's all that mmap requires, and since that's all we really know
+  // about at this low abstraction level.  If we need higher alignment,
+  // we can either pass an alignment to this method or verify alignment
+  // in one of the methods further up the call chain.  See bug 5044738.
+  assert(bytes % os::vm_page_size() == 0, "reserving unexpected size block");
+
+  // Repeatedly allocate blocks until the block is allocated at the
+  // right spot. Give up after max_tries. Note that reserve_memory() will
+  // automatically update _highest_vm_reserved_address if the call is
+  // successful. The variable tracks the highest memory address every reserved
+  // by JVM. It is used to detect heap-stack collision if running with
+  // fixed-stack BsdThreads. Because here we may attempt to reserve more
+  // space than needed, it could confuse the collision detecting code. To
+  // solve the problem, save current _highest_vm_reserved_address and
+  // calculate the correct value before return.
+  address old_highest = _highest_vm_reserved_address;
+
+  // Bsd mmap allows caller to pass an address as hint; give it a try first,
+  // if kernel honors the hint then we can return immediately.
+  char * addr = anon_mmap(requested_addr, bytes, false);
+  if (addr == requested_addr) {
+     return requested_addr;
+  }
+
+  if (addr != NULL) {
+     // mmap() is successful but it fails to reserve at the requested address
+     anon_munmap(addr, bytes);
+  }
+
+  int i;
+  for (i = 0; i < max_tries; ++i) {
+    base[i] = reserve_memory(bytes);
+
+    if (base[i] != NULL) {
+      // Is this the block we wanted?
+      if (base[i] == requested_addr) {
+        size[i] = bytes;
+        break;
+      }
+
+      // Does this overlap the block we wanted? Give back the overlapped
+      // parts and try again.
+
+      size_t top_overlap = requested_addr + (bytes + gap) - base[i];
+      if (top_overlap >= 0 && top_overlap < bytes) {
+        unmap_memory(base[i], top_overlap);
+        base[i] += top_overlap;
+        size[i] = bytes - top_overlap;
+      } else {
+        size_t bottom_overlap = base[i] + bytes - requested_addr;
+        if (bottom_overlap >= 0 && bottom_overlap < bytes) {
+          unmap_memory(requested_addr, bottom_overlap);
+          size[i] = bytes - bottom_overlap;
+        } else {
+          size[i] = bytes;
+        }
+      }
+    }
+  }
+
+  // Give back the unused reserved pieces.
+
+  for (int j = 0; j < i; ++j) {
+    if (base[j] != NULL) {
+      unmap_memory(base[j], size[j]);
+    }
+  }
+
+  if (i < max_tries) {
+    _highest_vm_reserved_address = MAX2(old_highest, (address)requested_addr + bytes);
+    return requested_addr;
+  } else {
+    _highest_vm_reserved_address = old_highest;
+    return NULL;
+  }
+}
+
+size_t os::read(int fd, void *buf, unsigned int nBytes) {
+  RESTARTABLE_RETURN_INT(::read(fd, buf, nBytes));
+}
+
+// TODO-FIXME: reconcile Solaris' os::sleep with the bsd variation.
+// Solaris uses poll(), bsd uses park().
+// Poll() is likely a better choice, assuming that Thread.interrupt()
+// generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
+// SIGSEGV, see 4355769.
+
+const int NANOSECS_PER_MILLISECS = 1000000;
+
+int os::sleep(Thread* thread, jlong millis, bool interruptible) {
+  assert(thread == Thread::current(),  "thread consistency check");
+
+  ParkEvent * const slp = thread->_SleepEvent ;
+  slp->reset() ;
+  OrderAccess::fence() ;
+
+  if (interruptible) {
+    jlong prevtime = javaTimeNanos();
+
+    for (;;) {
+      if (os::is_interrupted(thread, true)) {
+        return OS_INTRPT;
+      }
+
+      jlong newtime = javaTimeNanos();
+
+      if (newtime - prevtime < 0) {
+        // time moving backwards, should only happen if no monotonic clock
+        // not a guarantee() because JVM should not abort on kernel/glibc bugs
+        assert(!Bsd::supports_monotonic_clock(), "time moving backwards");
+      } else {
+        millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS;
+      }
+
+      if(millis <= 0) {
+        return OS_OK;
+      }
+
+      prevtime = newtime;
+
+      {
+        assert(thread->is_Java_thread(), "sanity check");
+        JavaThread *jt = (JavaThread *) thread;
+        ThreadBlockInVM tbivm(jt);
+        OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
+
+        jt->set_suspend_equivalent();
+        // cleared by handle_special_suspend_equivalent_condition() or
+        // java_suspend_self() via check_and_wait_while_suspended()
+
+        slp->park(millis);
+
+        // were we externally suspended while we were waiting?
+        jt->check_and_wait_while_suspended();
+      }
+    }
+  } else {
+    OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
+    jlong prevtime = javaTimeNanos();
+
+    for (;;) {
+      // It'd be nice to avoid the back-to-back javaTimeNanos() calls on
+      // the 1st iteration ...
+      jlong newtime = javaTimeNanos();
+
+      if (newtime - prevtime < 0) {
+        // time moving backwards, should only happen if no monotonic clock
+        // not a guarantee() because JVM should not abort on kernel/glibc bugs
+        assert(!Bsd::supports_monotonic_clock(), "time moving backwards");
+      } else {
+        millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS;
+      }
+
+      if(millis <= 0) break ;
+
+      prevtime = newtime;
+      slp->park(millis);
+    }
+    return OS_OK ;
+  }
+}
+
+int os::naked_sleep() {
+  // %% make the sleep time an integer flag. for now use 1 millisec.
+  return os::sleep(Thread::current(), 1, false);
+}
+
+// Sleep forever; naked call to OS-specific sleep; use with CAUTION
+void os::infinite_sleep() {
+  while (true) {    // sleep forever ...
+    ::sleep(100);   // ... 100 seconds at a time
+  }
+}
+
+// Used to convert frequent JVM_Yield() to nops
+bool os::dont_yield() {
+  return DontYieldALot;
+}
+
+void os::yield() {
+  sched_yield();
+}
+
+os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN ;}
+
+void os::yield_all(int attempts) {
+  // Yields to all threads, including threads with lower priorities
+  // Threads on Bsd are all with same priority. The Solaris style
+  // os::yield_all() with nanosleep(1ms) is not necessary.
+  sched_yield();
+}
+
+// Called from the tight loops to possibly influence time-sharing heuristics
+void os::loop_breaker(int attempts) {
+  os::yield_all(attempts);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// thread priority support
+
+// Note: Normal Bsd applications are run with SCHED_OTHER policy. SCHED_OTHER
+// only supports dynamic priority, static priority must be zero. For real-time
+// applications, Bsd supports SCHED_RR which allows static priority (1-99).
+// However, for large multi-threaded applications, SCHED_RR is not only slower
+// than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out
+// of 5 runs - Sep 2005).
+//
+// The following code actually changes the niceness of kernel-thread/LWP. It
+// has an assumption that setpriority() only modifies one kernel-thread/LWP,
+// not the entire user process, and user level threads are 1:1 mapped to kernel
+// threads. It has always been the case, but could change in the future. For
+// this reason, the code should not be used as default (ThreadPriorityPolicy=0).
+// It is only used when ThreadPriorityPolicy=1 and requires root privilege.
+
+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
+int os::java_to_os_priority[MaxPriority + 1] = {
+  19,              // 0 Entry should never be used
+
+   0,              // 1 MinPriority
+   3,              // 2
+   6,              // 3
+
+   10,              // 4
+   15,              // 5 NormPriority
+   18,              // 6
+
+   21,              // 7
+   25,              // 8
+   28,              // 9 NearMaxPriority
+
+   31              // 10 MaxPriority
+};
+#elif defined(__APPLE__)
+/* Using Mach high-level priority assignments */
+int os::java_to_os_priority[MaxPriority + 1] = {
+   0,              // 0 Entry should never be used (MINPRI_USER)
+
+  27,              // 1 MinPriority
+  28,              // 2
+  29,              // 3
+
+  30,              // 4
+  31,              // 5 NormPriority (BASEPRI_DEFAULT)
+  32,              // 6
+
+  33,              // 7
+  34,              // 8
+  35,              // 9 NearMaxPriority
+
+  36               // 10 MaxPriority
+};
+#else
+int os::java_to_os_priority[MaxPriority + 1] = {
+  19,              // 0 Entry should never be used
+
+   4,              // 1 MinPriority
+   3,              // 2
+   2,              // 3
+
+   1,              // 4
+   0,              // 5 NormPriority
+  -1,              // 6
+
+  -2,              // 7
+  -3,              // 8
+  -4,              // 9 NearMaxPriority
+
+  -5               // 10 MaxPriority
+};
+#endif
+
+static int prio_init() {
+  if (ThreadPriorityPolicy == 1) {
+    // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1
+    // if effective uid is not root. Perhaps, a more elegant way of doing
+    // this is to test CAP_SYS_NICE capability, but that will require libcap.so
+    if (geteuid() != 0) {
+      if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) {
+        warning("-XX:ThreadPriorityPolicy requires root privilege on Bsd");
+      }
+      ThreadPriorityPolicy = 0;
+    }
+  }
+  return 0;
+}
+
+OSReturn os::set_native_priority(Thread* thread, int newpri) {
+  if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK;
+
+#ifdef __OpenBSD__
+  // OpenBSD pthread_setprio starves low priority threads
+  return OS_OK;
+#elif defined(__FreeBSD__)
+  int ret = pthread_setprio(thread->osthread()->pthread_id(), newpri);
+#elif defined(__APPLE__) || defined(__NetBSD__)
+  struct sched_param sp;
+  int policy;
+  pthread_t self = pthread_self();
+
+  if (pthread_getschedparam(self, &policy, &sp) != 0)
+    return OS_ERR;
+
+  sp.sched_priority = newpri;
+  if (pthread_setschedparam(self, policy, &sp) != 0)
+    return OS_ERR;
+
+  return OS_OK;
+#else
+  int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);
+  return (ret == 0) ? OS_OK : OS_ERR;
+#endif
+}
+
+OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
+  if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) {
+    *priority_ptr = java_to_os_priority[NormPriority];
+    return OS_OK;
+  }
+
+  errno = 0;
+#if defined(__OpenBSD__) || defined(__FreeBSD__)
+  *priority_ptr = pthread_getprio(thread->osthread()->pthread_id());
+#elif defined(__APPLE__) || defined(__NetBSD__)
+  int policy;
+  struct sched_param sp;
+
+  pthread_getschedparam(pthread_self(), &policy, &sp);
+  *priority_ptr = sp.sched_priority;
+#else
+  *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id());
+#endif
+  return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR);
+}
+
+// Hint to the underlying OS that a task switch would not be good.
+// Void return because it's a hint and can fail.
+void os::hint_no_preempt() {}
+
+////////////////////////////////////////////////////////////////////////////////
+// suspend/resume support
+
+//  the low-level signal-based suspend/resume support is a remnant from the
+//  old VM-suspension that used to be for java-suspension, safepoints etc,
+//  within hotspot. Now there is a single use-case for this:
+//    - calling get_thread_pc() on the VMThread by the flat-profiler task
+//      that runs in the watcher thread.
+//  The remaining code is greatly simplified from the more general suspension
+//  code that used to be used.
+//
+//  The protocol is quite simple:
+//  - suspend:
+//      - sends a signal to the target thread
+//      - polls the suspend state of the osthread using a yield loop
+//      - target thread signal handler (SR_handler) sets suspend state
+//        and blocks in sigsuspend until continued
+//  - resume:
+//      - sets target osthread state to continue
+//      - sends signal to end the sigsuspend loop in the SR_handler
+//
+//  Note that the SR_lock plays no role in this suspend/resume protocol.
+//
+
+static void resume_clear_context(OSThread *osthread) {
+  osthread->set_ucontext(NULL);
+  osthread->set_siginfo(NULL);
+
+  // notify the suspend action is completed, we have now resumed
+  osthread->sr.clear_suspended();
+}
+
+static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) {
+  osthread->set_ucontext(context);
+  osthread->set_siginfo(siginfo);
+}
+
+//
+// Handler function invoked when a thread's execution is suspended or
+// resumed. We have to be careful that only async-safe functions are
+// called here (Note: most pthread functions are not async safe and
+// should be avoided.)
+//
+// Note: sigwait() is a more natural fit than sigsuspend() from an
+// interface point of view, but sigwait() prevents the signal hander
+// from being run. libpthread would get very confused by not having
+// its signal handlers run and prevents sigwait()'s use with the
+// mutex granting granting signal.
+//
+// Currently only ever called on the VMThread
+//
+static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) {
+  // Save and restore errno to avoid confusing native code with EINTR
+  // after sigsuspend.
+  int old_errno = errno;
+
+  Thread* thread = Thread::current();
+  OSThread* osthread = thread->osthread();
+  assert(thread->is_VM_thread(), "Must be VMThread");
+  // read current suspend action
+  int action = osthread->sr.suspend_action();
+  if (action == SR_SUSPEND) {
+    suspend_save_context(osthread, siginfo, context);
+
+    // Notify the suspend action is about to be completed. do_suspend()
+    // waits until SR_SUSPENDED is set and then returns. We will wait
+    // here for a resume signal and that completes the suspend-other
+    // action. do_suspend/do_resume is always called as a pair from
+    // the same thread - so there are no races
+
+    // notify the caller
+    osthread->sr.set_suspended();
+
+    sigset_t suspend_set;  // signals for sigsuspend()
+
+    // get current set of blocked signals and unblock resume signal
+    pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
+    sigdelset(&suspend_set, SR_signum);
+
+    // wait here until we are resumed
+    do {
+      sigsuspend(&suspend_set);
+      // ignore all returns until we get a resume signal
+    } while (osthread->sr.suspend_action() != SR_CONTINUE);
+
+    resume_clear_context(osthread);
+
+  } else {
+    assert(action == SR_CONTINUE, "unexpected sr action");
+    // nothing special to do - just leave the handler
+  }
+
+  errno = old_errno;
+}
+
+
+static int SR_initialize() {
+  struct sigaction act;
+  char *s;
+  /* Get signal number to use for suspend/resume */
+  if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
+    int sig = ::strtol(s, 0, 10);
+    if (sig > 0 || sig < NSIG) {
+        SR_signum = sig;
+    }
+  }
+
+  assert(SR_signum > SIGSEGV && SR_signum > SIGBUS,
+        "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
+
+  sigemptyset(&SR_sigset);
+  sigaddset(&SR_sigset, SR_signum);
+
+  /* Set up signal handler for suspend/resume */
+  act.sa_flags = SA_RESTART|SA_SIGINFO;
+  act.sa_handler = (void (*)(int)) SR_handler;
+
+  // SR_signum is blocked by default.
+  // 4528190 - We also need to block pthread restart signal (32 on all
+  // supported Bsd platforms). Note that BsdThreads need to block
+  // this signal for all threads to work properly. So we don't have
+  // to use hard-coded signal number when setting up the mask.
+  pthread_sigmask(SIG_BLOCK, NULL, &act.sa_mask);
+
+  if (sigaction(SR_signum, &act, 0) == -1) {
+    return -1;
+  }
+
+  // Save signal flag
+  os::Bsd::set_our_sigflags(SR_signum, act.sa_flags);
+  return 0;
+}
+
+static int SR_finalize() {
+  return 0;
+}
+
+
+// returns true on success and false on error - really an error is fatal
+// but this seems the normal response to library errors
+static bool do_suspend(OSThread* osthread) {
+  // mark as suspended and send signal
+  osthread->sr.set_suspend_action(SR_SUSPEND);
+  int status = pthread_kill(osthread->pthread_id(), SR_signum);
+  assert_status(status == 0, status, "pthread_kill");
+
+  // check status and wait until notified of suspension
+  if (status == 0) {
+    for (int i = 0; !osthread->sr.is_suspended(); i++) {
+      os::yield_all(i);
+    }
+    osthread->sr.set_suspend_action(SR_NONE);
+    return true;
+  }
+  else {
+    osthread->sr.set_suspend_action(SR_NONE);
+    return false;
+  }
+}
+
+static void do_resume(OSThread* osthread) {
+  assert(osthread->sr.is_suspended(), "thread should be suspended");
+  osthread->sr.set_suspend_action(SR_CONTINUE);
+
+  int status = pthread_kill(osthread->pthread_id(), SR_signum);
+  assert_status(status == 0, status, "pthread_kill");
+  // check status and wait unit notified of resumption
+  if (status == 0) {
+    for (int i = 0; osthread->sr.is_suspended(); i++) {
+      os::yield_all(i);
+    }
+  }
+  osthread->sr.set_suspend_action(SR_NONE);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// interrupt support
+
+void os::interrupt(Thread* thread) {
+  assert(Thread::current() == thread || Threads_lock->owned_by_self(),
+    "possibility of dangling Thread pointer");
+
+  OSThread* osthread = thread->osthread();
+
+  if (!osthread->interrupted()) {
+    osthread->set_interrupted(true);
+    // More than one thread can get here with the same value of osthread,
+    // resulting in multiple notifications.  We do, however, want the store
+    // to interrupted() to be visible to other threads before we execute unpark().
+    OrderAccess::fence();
+    ParkEvent * const slp = thread->_SleepEvent ;
+    if (slp != NULL) slp->unpark() ;
+  }
+
+  // For JSR166. Unpark even if interrupt status already was set
+  if (thread->is_Java_thread())
+    ((JavaThread*)thread)->parker()->unpark();
+
+  ParkEvent * ev = thread->_ParkEvent ;
+  if (ev != NULL) ev->unpark() ;
+
+}
+
+bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
+  assert(Thread::current() == thread || Threads_lock->owned_by_self(),
+    "possibility of dangling Thread pointer");
+
+  OSThread* osthread = thread->osthread();
+
+  bool interrupted = osthread->interrupted();
+
+  if (interrupted && clear_interrupted) {
+    osthread->set_interrupted(false);
+    // consider thread->_SleepEvent->reset() ... optional optimization
+  }
+
+  return interrupted;
+}
+
+///////////////////////////////////////////////////////////////////////////////////
+// signal handling (except suspend/resume)
+
+// This routine may be used by user applications as a "hook" to catch signals.
+// The user-defined signal handler must pass unrecognized signals to this
+// routine, and if it returns true (non-zero), then the signal handler must
+// return immediately.  If the flag "abort_if_unrecognized" is true, then this
+// routine will never retun false (zero), but instead will execute a VM panic
+// routine kill the process.
+//
+// If this routine returns false, it is OK to call it again.  This allows
+// the user-defined signal handler to perform checks either before or after
+// the VM performs its own checks.  Naturally, the user code would be making
+// a serious error if it tried to handle an exception (such as a null check
+// or breakpoint) that the VM was generating for its own correct operation.
+//
+// This routine may recognize any of the following kinds of signals:
+//    SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
+// It should be consulted by handlers for any of those signals.
+//
+// The caller of this routine must pass in the three arguments supplied
+// to the function referred to in the "sa_sigaction" (not the "sa_handler")
+// field of the structure passed to sigaction().  This routine assumes that
+// the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
+//
+// Note that the VM will print warnings if it detects conflicting signal
+// handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
+//
+extern "C" JNIEXPORT int
+JVM_handle_bsd_signal(int signo, siginfo_t* siginfo,
+                        void* ucontext, int abort_if_unrecognized);
+
+void signalHandler(int sig, siginfo_t* info, void* uc) {
+  assert(info != NULL && uc != NULL, "it must be old kernel");
+  JVM_handle_bsd_signal(sig, info, uc, true);
+}
+
+
+// This boolean allows users to forward their own non-matching signals
+// to JVM_handle_bsd_signal, harmlessly.
+bool os::Bsd::signal_handlers_are_installed = false;
+
+// For signal-chaining
+struct sigaction os::Bsd::sigact[MAXSIGNUM];
+unsigned int os::Bsd::sigs = 0;
+bool os::Bsd::libjsig_is_loaded = false;
+typedef struct sigaction *(*get_signal_t)(int);
+get_signal_t os::Bsd::get_signal_action = NULL;
+
+struct sigaction* os::Bsd::get_chained_signal_action(int sig) {
+  struct sigaction *actp = NULL;
+
+  if (libjsig_is_loaded) {
+    // Retrieve the old signal handler from libjsig
+    actp = (*get_signal_action)(sig);
+  }
+  if (actp == NULL) {
+    // Retrieve the preinstalled signal handler from jvm
+    actp = get_preinstalled_handler(sig);
+  }
+
+  return actp;
+}
+
+static bool call_chained_handler(struct sigaction *actp, int sig,
+                                 siginfo_t *siginfo, void *context) {
+  // Call the old signal handler
+  if (actp->sa_handler == SIG_DFL) {
+    // It's more reasonable to let jvm treat it as an unexpected exception
+    // instead of taking the default action.
+    return false;
+  } else if (actp->sa_handler != SIG_IGN) {
+    if ((actp->sa_flags & SA_NODEFER) == 0) {
+      // automaticlly block the signal
+      sigaddset(&(actp->sa_mask), sig);
+    }
+
+    sa_handler_t hand;
+    sa_sigaction_t sa;
+    bool siginfo_flag_set = (actp->sa_flags & SA_SIGINFO) != 0;
+    // retrieve the chained handler
+    if (siginfo_flag_set) {
+      sa = actp->sa_sigaction;
+    } else {
+      hand = actp->sa_handler;
+    }
+
+    if ((actp->sa_flags & SA_RESETHAND) != 0) {
+      actp->sa_handler = SIG_DFL;
+    }
+
+    // try to honor the signal mask
+    sigset_t oset;
+    pthread_sigmask(SIG_SETMASK, &(actp->sa_mask), &oset);
+
+    // call into the chained handler
+    if (siginfo_flag_set) {
+      (*sa)(sig, siginfo, context);
+    } else {
+      (*hand)(sig);
+    }
+
+    // restore the signal mask
+    pthread_sigmask(SIG_SETMASK, &oset, 0);
+  }
+  // Tell jvm's signal handler the signal is taken care of.
+  return true;
+}
+
+bool os::Bsd::chained_handler(int sig, siginfo_t* siginfo, void* context) {
+  bool chained = false;
+  // signal-chaining
+  if (UseSignalChaining) {
+    struct sigaction *actp = get_chained_signal_action(sig);
+    if (actp != NULL) {
+      chained = call_chained_handler(actp, sig, siginfo, context);
+    }
+  }
+  return chained;
+}
+
+struct sigaction* os::Bsd::get_preinstalled_handler(int sig) {
+  if ((( (unsigned int)1 << sig ) & sigs) != 0) {
+    return &sigact[sig];
+  }
+  return NULL;
+}
+
+void os::Bsd::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
+  assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
+  sigact[sig] = oldAct;
+  sigs |= (unsigned int)1 << sig;
+}
+
+// for diagnostic
+int os::Bsd::sigflags[MAXSIGNUM];
+
+int os::Bsd::get_our_sigflags(int sig) {
+  assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
+  return sigflags[sig];
+}
+
+void os::Bsd::set_our_sigflags(int sig, int flags) {
+  assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
+  sigflags[sig] = flags;
+}
+
+void os::Bsd::set_signal_handler(int sig, bool set_installed) {
+  // Check for overwrite.
+  struct sigaction oldAct;
+  sigaction(sig, (struct sigaction*)NULL, &oldAct);
+
+  void* oldhand = oldAct.sa_sigaction
+                ? CAST_FROM_FN_PTR(void*,  oldAct.sa_sigaction)
+                : CAST_FROM_FN_PTR(void*,  oldAct.sa_handler);
+  if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) &&
+      oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) &&
+      oldhand != CAST_FROM_FN_PTR(void*, (sa_sigaction_t)signalHandler)) {
+    if (AllowUserSignalHandlers || !set_installed) {
+      // Do not overwrite; user takes responsibility to forward to us.
+      return;
+    } else if (UseSignalChaining) {
+      // save the old handler in jvm
+      save_preinstalled_handler(sig, oldAct);
+      // libjsig also interposes the sigaction() call below and saves the
+      // old sigaction on it own.
+    } else {
+      fatal(err_msg("Encountered unexpected pre-existing sigaction handler "
+                    "%#lx for signal %d.", (long)oldhand, sig));
+    }
+  }
+
+  struct sigaction sigAct;
+  sigfillset(&(sigAct.sa_mask));
+  sigAct.sa_handler = SIG_DFL;
+  if (!set_installed) {
+    sigAct.sa_flags = SA_SIGINFO|SA_RESTART;
+  } else {
+    sigAct.sa_sigaction = signalHandler;
+    sigAct.sa_flags = SA_SIGINFO|SA_RESTART;
+  }
+  // Save flags, which are set by ours
+  assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
+  sigflags[sig] = sigAct.sa_flags;
+
+  int ret = sigaction(sig, &sigAct, &oldAct);
+  assert(ret == 0, "check");
+
+  void* oldhand2  = oldAct.sa_sigaction
+                  ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
+                  : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
+  assert(oldhand2 == oldhand, "no concurrent signal handler installation");
+}
+
+// install signal handlers for signals that HotSpot needs to
+// handle in order to support Java-level exception handling.
+
+void os::Bsd::install_signal_handlers() {
+  if (!signal_handlers_are_installed) {
+    signal_handlers_are_installed = true;
+
+    // signal-chaining
+    typedef void (*signal_setting_t)();
+    signal_setting_t begin_signal_setting = NULL;
+    signal_setting_t end_signal_setting = NULL;
+    begin_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
+                             dlsym(RTLD_DEFAULT, "JVM_begin_signal_setting"));
+    if (begin_signal_setting != NULL) {
+      end_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
+                             dlsym(RTLD_DEFAULT, "JVM_end_signal_setting"));
+      get_signal_action = CAST_TO_FN_PTR(get_signal_t,
+                            dlsym(RTLD_DEFAULT, "JVM_get_signal_action"));
+      libjsig_is_loaded = true;
+      assert(UseSignalChaining, "should enable signal-chaining");
+    }
+    if (libjsig_is_loaded) {
+      // Tell libjsig jvm is setting signal handlers
+      (*begin_signal_setting)();
+    }
+
+    set_signal_handler(SIGSEGV, true);
+    set_signal_handler(SIGPIPE, true);
+    set_signal_handler(SIGBUS, true);
+    set_signal_handler(SIGILL, true);
+    set_signal_handler(SIGFPE, true);
+    set_signal_handler(SIGXFSZ, true);
+
+#if defined(__APPLE__)
+    // In Mac OS X 10.4, CrashReporter will write a crash log for all 'fatal' signals, including
+    // signals caught and handled by the JVM. To work around this, we reset the mach task
+    // signal handler that's placed on our process by CrashReporter. This disables
+    // CrashReporter-based reporting.
+    //
+    // This work-around is not necessary for 10.5+, as CrashReporter no longer intercedes
+    // on caught fatal signals.
+    //
+    // Additionally, gdb installs both standard BSD signal handlers, and mach exception
+    // handlers. By replacing the existing task exception handler, we disable gdb's mach
+    // exception handling, while leaving the standard BSD signal handlers functional.
+    kern_return_t kr;
+    kr = task_set_exception_ports(mach_task_self(),
+        EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC,
+        MACH_PORT_NULL,
+        EXCEPTION_STATE_IDENTITY,
+        MACHINE_THREAD_STATE);
+
+    assert(kr == KERN_SUCCESS, "could not set mach task signal handler");
+#endif
+
+    if (libjsig_is_loaded) {
+      // Tell libjsig jvm finishes setting signal handlers
+      (*end_signal_setting)();
+    }
+
+    // We don't activate signal checker if libjsig is in place, we trust ourselves
+    // and if UserSignalHandler is installed all bets are off
+    if (CheckJNICalls) {
+      if (libjsig_is_loaded) {
+        tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
+        check_signals = false;
+      }
+      if (AllowUserSignalHandlers) {
+        tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
+        check_signals = false;
+      }
+    }
+  }
+}
+
+#ifndef _ALLBSD_SOURCE
+// This is the fastest way to get thread cpu time on Bsd.
+// Returns cpu time (user+sys) for any thread, not only for current.
+// POSIX compliant clocks are implemented in the kernels 2.6.16+.
+// It might work on 2.6.10+ with a special kernel/glibc patch.
+// For reference, please, see IEEE Std 1003.1-2004:
+//   http://www.unix.org/single_unix_specification
+
+jlong os::Bsd::fast_thread_cpu_time(clockid_t clockid) {
+  struct timespec tp;
+  int rc = os::Bsd::clock_gettime(clockid, &tp);
+  assert(rc == 0, "clock_gettime is expected to return 0 code");
+
+  return (tp.tv_sec * SEC_IN_NANOSECS) + tp.tv_nsec;
+}
+#endif
+
+/////
+// glibc on Bsd platform uses non-documented flag
+// to indicate, that some special sort of signal
+// trampoline is used.
+// We will never set this flag, and we should
+// ignore this flag in our diagnostic
+#ifdef SIGNIFICANT_SIGNAL_MASK
+#undef SIGNIFICANT_SIGNAL_MASK
+#endif
+#define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
+
+static const char* get_signal_handler_name(address handler,
+                                           char* buf, int buflen) {
+  int offset;
+  bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
+  if (found) {
+    // skip directory names
+    const char *p1, *p2;
+    p1 = buf;
+    size_t len = strlen(os::file_separator());
+    while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
+    jio_snprintf(buf, buflen, "%s+0x%x", p1, offset);
+  } else {
+    jio_snprintf(buf, buflen, PTR_FORMAT, handler);
+  }
+  return buf;
+}
+
+static void print_signal_handler(outputStream* st, int sig,
+                                 char* buf, size_t buflen) {
+  struct sigaction sa;
+
+  sigaction(sig, NULL, &sa);
+
+  // See comment for SIGNIFICANT_SIGNAL_MASK define
+  sa.sa_flags &= SIGNIFICANT_SIGNAL_MASK;
+
+  st->print("%s: ", os::exception_name(sig, buf, buflen));
+
+  address handler = (sa.sa_flags & SA_SIGINFO)
+    ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
+    : CAST_FROM_FN_PTR(address, sa.sa_handler);
+
+  if (handler == CAST_FROM_FN_PTR(address, SIG_DFL)) {
+    st->print("SIG_DFL");
+  } else if (handler == CAST_FROM_FN_PTR(address, SIG_IGN)) {
+    st->print("SIG_IGN");
+  } else {
+    st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
+  }
+
+  st->print(", sa_mask[0]=" PTR32_FORMAT, *(uint32_t*)&sa.sa_mask);
+
+  address rh = VMError::get_resetted_sighandler(sig);
+  // May be, handler was resetted by VMError?
+  if(rh != NULL) {
+    handler = rh;
+    sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK;
+  }
+
+  st->print(", sa_flags="   PTR32_FORMAT, sa.sa_flags);
+
+  // Check: is it our handler?
+  if(handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) ||
+     handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
+    // It is our signal handler
+    // check for flags, reset system-used one!
+    if((int)sa.sa_flags != os::Bsd::get_our_sigflags(sig)) {
+      st->print(
+                ", flags was changed from " PTR32_FORMAT ", consider using jsig library",
+                os::Bsd::get_our_sigflags(sig));
+    }
+  }
+  st->cr();
+}
+
+
+#define DO_SIGNAL_CHECK(sig) \
+  if (!sigismember(&check_signal_done, sig)) \
+    os::Bsd::check_signal_handler(sig)
+
+// This method is a periodic task to check for misbehaving JNI applications
+// under CheckJNI, we can add any periodic checks here
+
+void os::run_periodic_checks() {
+
+  if (check_signals == false) return;
+
+  // SEGV and BUS if overridden could potentially prevent
+  // generation of hs*.log in the event of a crash, debugging
+  // such a case can be very challenging, so we absolutely
+  // check the following for a good measure:
+  DO_SIGNAL_CHECK(SIGSEGV);
+  DO_SIGNAL_CHECK(SIGILL);
+  DO_SIGNAL_CHECK(SIGFPE);
+  DO_SIGNAL_CHECK(SIGBUS);
+  DO_SIGNAL_CHECK(SIGPIPE);
+  DO_SIGNAL_CHECK(SIGXFSZ);
+
+
+  // ReduceSignalUsage allows the user to override these handlers
+  // see comments at the very top and jvm_solaris.h
+  if (!ReduceSignalUsage) {
+    DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
+    DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL);
+    DO_SIGNAL_CHECK(SHUTDOWN3_SIGNAL);
+    DO_SIGNAL_CHECK(BREAK_SIGNAL);
+  }
+
+  DO_SIGNAL_CHECK(SR_signum);
+  DO_SIGNAL_CHECK(INTERRUPT_SIGNAL);
+}
+
+typedef int (*os_sigaction_t)(int, const struct sigaction *, struct sigaction *);
+
+static os_sigaction_t os_sigaction = NULL;
+
+void os::Bsd::check_signal_handler(int sig) {
+  char buf[O_BUFLEN];
+  address jvmHandler = NULL;
+
+
+  struct sigaction act;
+  if (os_sigaction == NULL) {
+    // only trust the default sigaction, in case it has been interposed
+    os_sigaction = (os_sigaction_t)dlsym(RTLD_DEFAULT, "sigaction");
+    if (os_sigaction == NULL) return;
+  }
+
+  os_sigaction(sig, (struct sigaction*)NULL, &act);
+
+
+  act.sa_flags &= SIGNIFICANT_SIGNAL_MASK;
+
+  address thisHandler = (act.sa_flags & SA_SIGINFO)
+    ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
+    : CAST_FROM_FN_PTR(address, act.sa_handler) ;
+
+
+  switch(sig) {
+  case SIGSEGV:
+  case SIGBUS:
+  case SIGFPE:
+  case SIGPIPE:
+  case SIGILL:
+  case SIGXFSZ:
+    jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler);
+    break;
+
+  case SHUTDOWN1_SIGNAL:
+  case SHUTDOWN2_SIGNAL:
+  case SHUTDOWN3_SIGNAL:
+  case BREAK_SIGNAL:
+    jvmHandler = (address)user_handler();
+    break;
+
+  case INTERRUPT_SIGNAL:
+    jvmHandler = CAST_FROM_FN_PTR(address, SIG_DFL);
+    break;
+
+  default:
+    if (sig == SR_signum) {
+      jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler);
+    } else {
+      return;
+    }
+    break;
+  }
+
+  if (thisHandler != jvmHandler) {
+    tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN));
+    tty->print("expected:%s", get_signal_handler_name(jvmHandler, buf, O_BUFLEN));
+    tty->print_cr("  found:%s", get_signal_handler_name(thisHandler, buf, O_BUFLEN));
+    // No need to check this sig any longer
+    sigaddset(&check_signal_done, sig);
+  } else if(os::Bsd::get_our_sigflags(sig) != 0 && (int)act.sa_flags != os::Bsd::get_our_sigflags(sig)) {
+    tty->print("Warning: %s handler flags ", exception_name(sig, buf, O_BUFLEN));
+    tty->print("expected:" PTR32_FORMAT, os::Bsd::get_our_sigflags(sig));
+    tty->print_cr("  found:" PTR32_FORMAT, act.sa_flags);
+    // No need to check this sig any longer
+    sigaddset(&check_signal_done, sig);
+  }
+
+  // Dump all the signal
+  if (sigismember(&check_signal_done, sig)) {
+    print_signal_handlers(tty, buf, O_BUFLEN);
+  }
+}
+
+extern void report_error(char* file_name, int line_no, char* title, char* format, ...);
+
+extern bool signal_name(int signo, char* buf, size_t len);
+
+const char* os::exception_name(int exception_code, char* buf, size_t size) {
+  if (0 < exception_code && exception_code <= SIGRTMAX) {
+    // signal
+    if (!signal_name(exception_code, buf, size)) {
+      jio_snprintf(buf, size, "SIG%d", exception_code);
+    }
+    return buf;
+  } else {
+    return NULL;
+  }
+}
+
+// this is called _before_ the most of global arguments have been parsed
+void os::init(void) {
+  char dummy;   /* used to get a guess on initial stack address */
+//  first_hrtime = gethrtime();
+
+  // With BsdThreads the JavaMain thread pid (primordial thread)
+  // is different than the pid of the java launcher thread.
+  // So, on Bsd, the launcher thread pid is passed to the VM
+  // via the sun.java.launcher.pid property.
+  // Use this property instead of getpid() if it was correctly passed.
+  // See bug 6351349.
+  pid_t java_launcher_pid = (pid_t) Arguments::sun_java_launcher_pid();
+
+  _initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid();
+
+  clock_tics_per_sec = CLK_TCK;
+
+  init_random(1234567);
+
+  ThreadCritical::initialize();
+
+  Bsd::set_page_size(getpagesize());
+  if (Bsd::page_size() == -1) {
+    fatal(err_msg("os_bsd.cpp: os::init: sysconf failed (%s)",
+                  strerror(errno)));
+  }
+  init_page_sizes((size_t) Bsd::page_size());
+
+  Bsd::initialize_system_info();
+
+  // main_thread points to the aboriginal thread
+  Bsd::_main_thread = pthread_self();
+
+  Bsd::clock_init();
+  initial_time_count = os::elapsed_counter();
+
+#ifdef __APPLE__
+  // XXXDARWIN
+  // Work around the unaligned VM callbacks in hotspot's
+  // sharedRuntime. The callbacks don't use SSE2 instructions, and work on
+  // Linux, Solaris, and FreeBSD. On Mac OS X, dyld (rightly so) enforces
+  // alignment when doing symbol lookup. To work around this, we force early
+  // binding of all symbols now, thus binding when alignment is known-good.
+  _dyld_bind_fully_image_containing_address((const void *) &os::init);
+#endif
+}
+
+// To install functions for atexit system call
+extern "C" {
+  static void perfMemory_exit_helper() {
+    perfMemory_exit();
+  }
+}
+
+// this is called _after_ the global arguments have been parsed
+jint os::init_2(void)
+{
+#ifndef _ALLBSD_SOURCE
+  Bsd::fast_thread_clock_init();
+#endif
+
+  // Allocate a single page and mark it as readable for safepoint polling
+  address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
+
+  os::set_polling_page( polling_page );
+
+#ifndef PRODUCT
+  if(Verbose && PrintMiscellaneous)
+    tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
+#endif
+
+  if (!UseMembar) {
+    address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+    guarantee( mem_serialize_page != NULL, "mmap Failed for memory serialize page");
+    os::set_memory_serialize_page( mem_serialize_page );
+
+#ifndef PRODUCT
+    if(Verbose && PrintMiscellaneous)
+      tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
+#endif
+  }
+
+  os::large_page_init();
+
+  // initialize suspend/resume support - must do this before signal_sets_init()
+  if (SR_initialize() != 0) {
+    perror("SR_initialize failed");
+    return JNI_ERR;
+  }
+
+  Bsd::signal_sets_init();
+  Bsd::install_signal_handlers();
+
+  // Check minimum allowable stack size for thread creation and to initialize
+  // the java system classes, including StackOverflowError - depends on page
+  // size.  Add a page for compiler2 recursion in main thread.
+  // Add in 2*BytesPerWord times page size to account for VM stack during
+  // class initialization depending on 32 or 64 bit VM.
+  os::Bsd::min_stack_allowed = MAX2(os::Bsd::min_stack_allowed,
+            (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
+                    2*BytesPerWord COMPILER2_PRESENT(+1)) * Bsd::page_size());
+
+  size_t threadStackSizeInBytes = ThreadStackSize * K;
+  if (threadStackSizeInBytes != 0 &&
+      threadStackSizeInBytes < os::Bsd::min_stack_allowed) {
+        tty->print_cr("\nThe stack size specified is too small, "
+                      "Specify at least %dk",
+                      os::Bsd::min_stack_allowed/ K);
+        return JNI_ERR;
+  }
+
+  // Make the stack size a multiple of the page size so that
+  // the yellow/red zones can be guarded.
+  JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
+        vm_page_size()));
+
+#ifndef _ALLBSD_SOURCE
+  Bsd::capture_initial_stack(JavaThread::stack_size_at_create());
+
+  Bsd::libpthread_init();
+  if (PrintMiscellaneous && (Verbose || WizardMode)) {
+     tty->print_cr("[HotSpot is running with %s, %s(%s)]\n",
+          Bsd::glibc_version(), Bsd::libpthread_version(),
+          Bsd::is_floating_stack() ? "floating stack" : "fixed stack");
+  }
+
+  if (UseNUMA) {
+    if (!Bsd::libnuma_init()) {
+      UseNUMA = false;
+    } else {
+      if ((Bsd::numa_max_node() < 1)) {
+        // There's only one node(they start from 0), disable NUMA.
+        UseNUMA = false;
+      }
+    }
+    // With SHM large pages we cannot uncommit a page, so there's not way
+    // we can make the adaptive lgrp chunk resizing work. If the user specified
+    // both UseNUMA and UseLargePages (or UseSHM) on the command line - warn and
+    // disable adaptive resizing.
+    if (UseNUMA && UseLargePages && UseSHM) {
+      if (!FLAG_IS_DEFAULT(UseNUMA)) {
+        if (FLAG_IS_DEFAULT(UseLargePages) && FLAG_IS_DEFAULT(UseSHM)) {
+          UseLargePages = false;
+        } else {
+          warning("UseNUMA is not fully compatible with SHM large pages, disabling adaptive resizing");
+          UseAdaptiveSizePolicy = false;
+          UseAdaptiveNUMAChunkSizing = false;
+        }
+      } else {
+        UseNUMA = false;
+      }
+    }
+    if (!UseNUMA && ForceNUMA) {
+      UseNUMA = true;
+    }
+  }
+#endif
+
+  if (MaxFDLimit) {
+    // set the number of file descriptors to max. print out error
+    // if getrlimit/setrlimit fails but continue regardless.
+    struct rlimit nbr_files;
+    int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
+    if (status != 0) {
+      if (PrintMiscellaneous && (Verbose || WizardMode))
+        perror("os::init_2 getrlimit failed");
+    } else {
+      nbr_files.rlim_cur = nbr_files.rlim_max;
+
+#ifdef __APPLE__
+      // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
+      // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
+      // be used instead
+      nbr_files.rlim_cur = MIN(OPEN_MAX, nbr_files.rlim_cur);
+#endif
+
+      status = setrlimit(RLIMIT_NOFILE, &nbr_files);
+      if (status != 0) {
+        if (PrintMiscellaneous && (Verbose || WizardMode))
+          perror("os::init_2 setrlimit failed");
+      }
+    }
+  }
+
+#ifndef _ALLBSD_SOURCE
+  // Initialize lock used to serialize thread creation (see os::create_thread)
+  Bsd::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false));
+#endif
+
+  // at-exit methods are called in the reverse order of their registration.
+  // atexit functions are called on return from main or as a result of a
+  // call to exit(3C). There can be only 32 of these functions registered
+  // and atexit() does not set errno.
+
+  if (PerfAllowAtExitRegistration) {
+    // only register atexit functions if PerfAllowAtExitRegistration is set.
+    // atexit functions can be delayed until process exit time, which
+    // can be problematic for embedded VM situations. Embedded VMs should
+    // call DestroyJavaVM() to assure that VM resources are released.
+
+    // note: perfMemory_exit_helper atexit function may be removed in
+    // the future if the appropriate cleanup code can be added to the
+    // VM_Exit VMOperation's doit method.
+    if (atexit(perfMemory_exit_helper) != 0) {
+      warning("os::init2 atexit(perfMemory_exit_helper) failed");
+    }
+  }
+
+  // initialize thread priority policy
+  prio_init();
+
+#ifdef __APPLE__
+  // dynamically link to objective c gc registration
+  void *handleLibObjc = dlopen(OBJC_LIB, RTLD_LAZY);
+  if (handleLibObjc != NULL) {
+    objc_registerThreadWithCollectorFunction = (objc_registerThreadWithCollector_t) dlsym(handleLibObjc, OBJC_GCREGISTER);
+  }
+#endif
+
+  return JNI_OK;
+}
+
+// this is called at the end of vm_initialization
+void os::init_3(void) { }
+
+// Mark the polling page as unreadable
+void os::make_polling_page_unreadable(void) {
+  if( !guard_memory((char*)_polling_page, Bsd::page_size()) )
+    fatal("Could not disable polling page");
+};
+
+// Mark the polling page as readable
+void os::make_polling_page_readable(void) {
+  if( !bsd_mprotect((char *)_polling_page, Bsd::page_size(), PROT_READ)) {
+    fatal("Could not enable polling page");
+  }
+};
+
+int os::active_processor_count() {
+#ifdef _ALLBSD_SOURCE
+  return _processor_count;
+#else
+  // Bsd doesn't yet have a (official) notion of processor sets,
+  // so just return the number of online processors.
+  int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
+  assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
+  return online_cpus;
+#endif
+}
+
+void os::set_native_thread_name(const char *name) {
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
+  // This is only supported in Snow Leopard and beyond
+  if (name != NULL) {
+    // Add a "Java: " prefix to the name
+    char buf[MAXTHREADNAMESIZE];
+    snprintf(buf, sizeof(buf), "Java: %s", name);
+    pthread_setname_np(buf);
+  }
+#endif
+}
+
+bool os::distribute_processes(uint length, uint* distribution) {
+  // Not yet implemented.
+  return false;
+}
+
+bool os::bind_to_processor(uint processor_id) {
+  // Not yet implemented.
+  return false;
+}
+
+///
+
+// Suspends the target using the signal mechanism and then grabs the PC before
+// resuming the target. Used by the flat-profiler only
+ExtendedPC os::get_thread_pc(Thread* thread) {
+  // Make sure that it is called by the watcher for the VMThread
+  assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
+  assert(thread->is_VM_thread(), "Can only be called for VMThread");
+
+  ExtendedPC epc;
+
+  OSThread* osthread = thread->osthread();
+  if (do_suspend(osthread)) {
+    if (osthread->ucontext() != NULL) {
+      epc = os::Bsd::ucontext_get_pc(osthread->ucontext());
+    } else {
+      // NULL context is unexpected, double-check this is the VMThread
+      guarantee(thread->is_VM_thread(), "can only be called for VMThread");
+    }
+    do_resume(osthread);
+  }
+  // failure means pthread_kill failed for some reason - arguably this is
+  // a fatal problem, but such problems are ignored elsewhere
+
+  return epc;
+}
+
+int os::Bsd::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
+{
+#ifdef _ALLBSD_SOURCE
+  return pthread_cond_timedwait(_cond, _mutex, _abstime);
+#else
+   if (is_NPTL()) {
+      return pthread_cond_timedwait(_cond, _mutex, _abstime);
+   } else {
+#ifndef IA64
+      // 6292965: BsdThreads pthread_cond_timedwait() resets FPU control
+      // word back to default 64bit precision if condvar is signaled. Java
+      // wants 53bit precision.  Save and restore current value.
+      int fpu = get_fpu_control_word();
+#endif // IA64
+      int status = pthread_cond_timedwait(_cond, _mutex, _abstime);
+#ifndef IA64
+      set_fpu_control_word(fpu);
+#endif // IA64
+      return status;
+   }
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// debug support
+
+static address same_page(address x, address y) {
+  int page_bits = -os::vm_page_size();
+  if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits))
+    return x;
+  else if (x > y)
+    return (address)(intptr_t(y) | ~page_bits) + 1;
+  else
+    return (address)(intptr_t(y) & page_bits);
+}
+
+bool os::find(address addr, outputStream* st) {
+  Dl_info dlinfo;
+  memset(&dlinfo, 0, sizeof(dlinfo));
+  if (dladdr(addr, &dlinfo)) {
+    st->print(PTR_FORMAT ": ", addr);
+    if (dlinfo.dli_sname != NULL) {
+      st->print("%s+%#x", dlinfo.dli_sname,
+                 addr - (intptr_t)dlinfo.dli_saddr);
+    } else if (dlinfo.dli_fname) {
+      st->print("<offset %#x>", addr - (intptr_t)dlinfo.dli_fbase);
+    } else {
+      st->print("<absolute address>");
+    }
+    if (dlinfo.dli_fname) {
+      st->print(" in %s", dlinfo.dli_fname);
+    }
+    if (dlinfo.dli_fbase) {
+      st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
+    }
+    st->cr();
+
+    if (Verbose) {
+      // decode some bytes around the PC
+      address begin = same_page(addr-40, addr);
+      address end   = same_page(addr+40, addr);
+      address       lowest = (address) dlinfo.dli_sname;
+      if (!lowest)  lowest = (address) dlinfo.dli_fbase;
+      if (begin < lowest)  begin = lowest;
+      Dl_info dlinfo2;
+      if (dladdr(end, &dlinfo2) && dlinfo2.dli_saddr != dlinfo.dli_saddr
+          && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin)
+        end = (address) dlinfo2.dli_saddr;
+      Disassembler::decode(begin, end, st);
+    }
+    return true;
+  }
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// misc
+
+// This does not do anything on Bsd. This is basically a hook for being
+// able to use structured exception handling (thread-local exception filters)
+// on, e.g., Win32.
+void
+os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method,
+                         JavaCallArguments* args, Thread* thread) {
+  f(value, method, args, thread);
+}
+
+void os::print_statistics() {
+}
+
+int os::message_box(const char* title, const char* message) {
+  int i;
+  fdStream err(defaultStream::error_fd());
+  for (i = 0; i < 78; i++) err.print_raw("=");
+  err.cr();
+  err.print_raw_cr(title);
+  for (i = 0; i < 78; i++) err.print_raw("-");
+  err.cr();
+  err.print_raw_cr(message);
+  for (i = 0; i < 78; i++) err.print_raw("=");
+  err.cr();
+
+  char buf[16];
+  // Prevent process from exiting upon "read error" without consuming all CPU
+  while (::read(0, buf, sizeof(buf)) <= 0) { ::sleep(100); }
+
+  return buf[0] == 'y' || buf[0] == 'Y';
+}
+
+int os::stat(const char *path, struct stat *sbuf) {
+  char pathbuf[MAX_PATH];
+  if (strlen(path) > MAX_PATH - 1) {
+    errno = ENAMETOOLONG;
+    return -1;
+  }
+  os::native_path(strcpy(pathbuf, path));
+  return ::stat(pathbuf, sbuf);
+}
+
+bool os::check_heap(bool force) {
+  return true;
+}
+
+int local_vsnprintf(char* buf, size_t count, const char* format, va_list args) {
+  return ::vsnprintf(buf, count, format, args);
+}
+
+// Is a (classpath) directory empty?
+bool os::dir_is_empty(const char* path) {
+  DIR *dir = NULL;
+  struct dirent *ptr;
+
+  dir = opendir(path);
+  if (dir == NULL) return true;
+
+  /* Scan the directory */
+  bool result = true;
+  char buf[sizeof(struct dirent) + MAX_PATH];
+  while (result && (ptr = ::readdir(dir)) != NULL) {
+    if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
+      result = false;
+    }
+  }
+  closedir(dir);
+  return result;
+}
+
+// This code originates from JDK's sysOpen and open64_w
+// from src/solaris/hpi/src/system_md.c
+
+#ifndef O_DELETE
+#define O_DELETE 0x10000
+#endif
+
+// Open a file. Unlink the file immediately after open returns
+// if the specified oflag has the O_DELETE flag set.
+// O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
+
+int os::open(const char *path, int oflag, int mode) {
+
+  if (strlen(path) > MAX_PATH - 1) {
+    errno = ENAMETOOLONG;
+    return -1;
+  }
+  int fd;
+  int o_delete = (oflag & O_DELETE);
+  oflag = oflag & ~O_DELETE;
+
+  fd = ::open(path, oflag, mode);
+  if (fd == -1) return -1;
+
+  //If the open succeeded, the file might still be a directory
+  {
+    struct stat buf;
+    int ret = ::fstat(fd, &buf);
+    int st_mode = buf.st_mode;
+
+    if (ret != -1) {
+      if ((st_mode & S_IFMT) == S_IFDIR) {
+        errno = EISDIR;
+        ::close(fd);
+        return -1;
+      }
+    } else {
+      ::close(fd);
+      return -1;
+    }
+  }
+
+    /*
+     * All file descriptors that are opened in the JVM and not
+     * specifically destined for a subprocess should have the
+     * close-on-exec flag set.  If we don't set it, then careless 3rd
+     * party native code might fork and exec without closing all
+     * appropriate file descriptors (e.g. as we do in closeDescriptors in
+     * UNIXProcess.c), and this in turn might:
+     *
+     * - cause end-of-file to fail to be detected on some file
+     *   descriptors, resulting in mysterious hangs, or
+     *
+     * - might cause an fopen in the subprocess to fail on a system
+     *   suffering from bug 1085341.
+     *
+     * (Yes, the default setting of the close-on-exec flag is a Unix
+     * design flaw)
+     *
+     * See:
+     * 1085341: 32-bit stdio routines should support file descriptors >255
+     * 4843136: (process) pipe file descriptor from Runtime.exec not being closed
+     * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
+     */
+#ifdef FD_CLOEXEC
+    {
+        int flags = ::fcntl(fd, F_GETFD);
+        if (flags != -1)
+            ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+    }
+#endif
+
+  if (o_delete != 0) {
+    ::unlink(path);
+  }
+  return fd;
+}
+
+
+// create binary file, rewriting existing file if required
+int os::create_binary_file(const char* path, bool rewrite_existing) {
+  int oflags = O_WRONLY | O_CREAT;
+  if (!rewrite_existing) {
+    oflags |= O_EXCL;
+  }
+  return ::open(path, oflags, S_IREAD | S_IWRITE);
+}
+
+// return current position of file pointer
+jlong os::current_file_offset(int fd) {
+  return (jlong)::lseek(fd, (off_t)0, SEEK_CUR);
+}
+
+// move file pointer to the specified offset
+jlong os::seek_to_file_offset(int fd, jlong offset) {
+  return (jlong)::lseek(fd, (off_t)offset, SEEK_SET);
+}
+
+// This code originates from JDK's sysAvailable
+// from src/solaris/hpi/src/native_threads/src/sys_api_td.c
+
+int os::available(int fd, jlong *bytes) {
+  jlong cur, end;
+  int mode;
+  struct stat buf;
+
+  if (::fstat(fd, &buf) >= 0) {
+    mode = buf.st_mode;
+    if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
+      /*
+      * XXX: is the following call interruptible? If so, this might
+      * need to go through the INTERRUPT_IO() wrapper as for other
+      * blocking, interruptible calls in this file.
+      */
+      int n;
+      if (::ioctl(fd, FIONREAD, &n) >= 0) {
+        *bytes = n;
+        return 1;
+      }
+    }
+  }
+  if ((cur = ::lseek(fd, 0L, SEEK_CUR)) == -1) {
+    return 0;
+  } else if ((end = ::lseek(fd, 0L, SEEK_END)) == -1) {
+    return 0;
+  } else if (::lseek(fd, cur, SEEK_SET) == -1) {
+    return 0;
+  }
+  *bytes = end - cur;
+  return 1;
+}
+
+int os::socket_available(int fd, jint *pbytes) {
+   if (fd < 0)
+     return OS_OK;
+
+   int ret;
+
+   RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret);
+
+   //%% note ioctl can return 0 when successful, JVM_SocketAvailable
+   // is expected to return 0 on failure and 1 on success to the jdk.
+
+   return (ret == OS_ERR) ? 0 : 1;
+}
+
+// Map a block of memory.
+char* os::map_memory(int fd, const char* file_name, size_t file_offset,
+                     char *addr, size_t bytes, bool read_only,
+                     bool allow_exec) {
+  int prot;
+  int flags;
+
+  if (read_only) {
+    prot = PROT_READ;
+    flags = MAP_SHARED;
+  } else {
+    prot = PROT_READ | PROT_WRITE;
+    flags = MAP_PRIVATE;
+  }
+
+  if (allow_exec) {
+    prot |= PROT_EXEC;
+  }
+
+  if (addr != NULL) {
+    flags |= MAP_FIXED;
+  }
+
+  char* mapped_address = (char*)mmap(addr, (size_t)bytes, prot, flags,
+                                     fd, file_offset);
+  if (mapped_address == MAP_FAILED) {
+    return NULL;
+  }
+  return mapped_address;
+}
+
+
+// Remap a block of memory.
+char* os::remap_memory(int fd, const char* file_name, size_t file_offset,
+                       char *addr, size_t bytes, bool read_only,
+                       bool allow_exec) {
+  // same as map_memory() on this OS
+  return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
+                        allow_exec);
+}
+
+
+// Unmap a block of memory.
+bool os::unmap_memory(char* addr, size_t bytes) {
+  return munmap(addr, bytes) == 0;
+}
+
+#ifndef _ALLBSD_SOURCE
+static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
+
+static clockid_t thread_cpu_clockid(Thread* thread) {
+  pthread_t tid = thread->osthread()->pthread_id();
+  clockid_t clockid;
+
+  // Get thread clockid
+  int rc = os::Bsd::pthread_getcpuclockid(tid, &clockid);
+  assert(rc == 0, "pthread_getcpuclockid is expected to return 0 code");
+  return clockid;
+}
+#endif
+
+// current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
+// are used by JVM M&M and JVMTI to get user+sys or user CPU time
+// of a thread.
+//
+// current_thread_cpu_time() and thread_cpu_time(Thread*) returns
+// the fast estimate available on the platform.
+
+jlong os::current_thread_cpu_time() {
+#ifdef __APPLE__
+  return os::thread_cpu_time(Thread::current(), true /* user + sys */);
+#elif !defined(_ALLBSD_SOURCE)
+  if (os::Bsd::supports_fast_thread_cpu_time()) {
+    return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
+  } else {
+    // return user + sys since the cost is the same
+    return slow_thread_cpu_time(Thread::current(), true /* user + sys */);
+  }
+#endif
+}
+
+jlong os::thread_cpu_time(Thread* thread) {
+#ifndef _ALLBSD_SOURCE
+  // consistent with what current_thread_cpu_time() returns
+  if (os::Bsd::supports_fast_thread_cpu_time()) {
+    return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
+  } else {
+    return slow_thread_cpu_time(thread, true /* user + sys */);
+  }
+#endif
+}
+
+jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
+#ifdef __APPLE__
+  return os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
+#elif !defined(_ALLBSD_SOURCE)
+  if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
+    return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
+  } else {
+    return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time);
+  }
+#endif
+}
+
+jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
+#ifdef __APPLE__
+  struct thread_basic_info tinfo;
+  mach_msg_type_number_t tcount = THREAD_INFO_MAX;
+  kern_return_t kr;
+  mach_port_t mach_thread;
+
+  mach_thread = pthread_mach_thread_np(thread->osthread()->thread_id());
+  kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount);
+  if (kr != KERN_SUCCESS)
+    return -1;
+
+  if (user_sys_cpu_time) {
+    jlong nanos;
+    nanos = ((jlong) tinfo.system_time.seconds + tinfo.user_time.seconds) * (jlong)1000000000;
+    nanos += ((jlong) tinfo.system_time.microseconds + (jlong) tinfo.user_time.microseconds) * (jlong)1000;
+    return nanos;
+  } else {
+    return ((jlong)tinfo.user_time.seconds * 1000000000) + ((jlong)tinfo.user_time.microseconds * (jlong)1000);
+  }
+#elif !defined(_ALLBSD_SOURCE)
+  if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
+    return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
+  } else {
+    return slow_thread_cpu_time(thread, user_sys_cpu_time);
+  }
+#endif
+}
+
+#ifndef _ALLBSD_SOURCE
+//
+//  -1 on error.
+//
+
+static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
+  static bool proc_pid_cpu_avail = true;
+  static bool proc_task_unchecked = true;
+  static const char *proc_stat_path = "/proc/%d/stat";
+  pid_t  tid = thread->osthread()->thread_id();
+  int i;
+  char *s;
+  char stat[2048];
+  int statlen;
+  char proc_name[64];
+  int count;
+  long sys_time, user_time;
+  char string[64];
+  char cdummy;
+  int idummy;
+  long ldummy;
+  FILE *fp;
+
+  // We first try accessing /proc/<pid>/cpu since this is faster to
+  // process.  If this file is not present (bsd kernels 2.5 and above)
+  // then we open /proc/<pid>/stat.
+  if ( proc_pid_cpu_avail ) {
+    sprintf(proc_name, "/proc/%d/cpu", tid);
+    fp =  fopen(proc_name, "r");
+    if ( fp != NULL ) {
+      count = fscanf( fp, "%s %lu %lu\n", string, &user_time, &sys_time);
+      fclose(fp);
+      if ( count != 3 ) return -1;
+
+      if (user_sys_cpu_time) {
+        return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
+      } else {
+        return (jlong)user_time * (1000000000 / clock_tics_per_sec);
+      }
+    }
+    else proc_pid_cpu_avail = false;
+  }
+
+  // The /proc/<tid>/stat aggregates per-process usage on
+  // new Bsd kernels 2.6+ where NPTL is supported.
+  // The /proc/self/task/<tid>/stat still has the per-thread usage.
+  // See bug 6328462.
+  // There can be no directory /proc/self/task on kernels 2.4 with NPTL
+  // and possibly in some other cases, so we check its availability.
+  if (proc_task_unchecked && os::Bsd::is_NPTL()) {
+    // This is executed only once
+    proc_task_unchecked = false;
+    fp = fopen("/proc/self/task", "r");
+    if (fp != NULL) {
+      proc_stat_path = "/proc/self/task/%d/stat";
+      fclose(fp);
+    }
+  }
+
+  sprintf(proc_name, proc_stat_path, tid);
+  fp = fopen(proc_name, "r");
+  if ( fp == NULL ) return -1;
+  statlen = fread(stat, 1, 2047, fp);
+  stat[statlen] = '\0';
+  fclose(fp);
+
+  // Skip pid and the command string. Note that we could be dealing with
+  // weird command names, e.g. user could decide to rename java launcher
+  // to "java 1.4.2 :)", then the stat file would look like
+  //                1234 (java 1.4.2 :)) R ... ...
+  // We don't really need to know the command string, just find the last
+  // occurrence of ")" and then start parsing from there. See bug 4726580.
+  s = strrchr(stat, ')');
+  i = 0;
+  if (s == NULL ) return -1;
+
+  // Skip blank chars
+  do s++; while (isspace(*s));
+
+  count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu",
+                 &cdummy, &idummy, &idummy, &idummy, &idummy, &idummy,
+                 &ldummy, &ldummy, &ldummy, &ldummy, &ldummy,
+                 &user_time, &sys_time);
+  if ( count != 13 ) return -1;
+  if (user_sys_cpu_time) {
+    return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
+  } else {
+    return (jlong)user_time * (1000000000 / clock_tics_per_sec);
+  }
+}
+#endif
+
+void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
+  info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
+  info_ptr->may_skip_backward = false;     // elapsed time not wall time
+  info_ptr->may_skip_forward = false;      // elapsed time not wall time
+  info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
+}
+
+void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
+  info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
+  info_ptr->may_skip_backward = false;     // elapsed time not wall time
+  info_ptr->may_skip_forward = false;      // elapsed time not wall time
+  info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
+}
+
+bool os::is_thread_cpu_time_supported() {
+#ifdef __APPLE__
+  return true;
+#elif defined(_ALLBSD_SOURCE)
+  return false;
+#else
+  return true;
+#endif
+}
+
+// System loadavg support.  Returns -1 if load average cannot be obtained.
+// Bsd doesn't yet have a (official) notion of processor sets,
+// so just return the system wide load average.
+int os::loadavg(double loadavg[], int nelem) {
+  return ::getloadavg(loadavg, nelem);
+}
+
+void os::pause() {
+  char filename[MAX_PATH];
+  if (PauseAtStartupFile && PauseAtStartupFile[0]) {
+    jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
+  } else {
+    jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
+  }
+
+  int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+  if (fd != -1) {
+    struct stat buf;
+    ::close(fd);
+    while (::stat(filename, &buf) == 0) {
+      (void)::poll(NULL, 0, 100);
+    }
+  } else {
+    jio_fprintf(stderr,
+      "Could not open pause file '%s', continuing immediately.\n", filename);
+  }
+}
+
+
+// Refer to the comments in os_solaris.cpp park-unpark.
+//
+// Beware -- Some versions of NPTL embody a flaw where pthread_cond_timedwait() can
+// hang indefinitely.  For instance NPTL 0.60 on 2.4.21-4ELsmp is vulnerable.
+// For specifics regarding the bug see GLIBC BUGID 261237 :
+//    http://www.mail-archive.com/debian-glibc@lists.debian.org/msg10837.html.
+// Briefly, pthread_cond_timedwait() calls with an expiry time that's not in the future
+// will either hang or corrupt the condvar, resulting in subsequent hangs if the condvar
+// is used.  (The simple C test-case provided in the GLIBC bug report manifests the
+// hang).  The JVM is vulernable via sleep(), Object.wait(timo), LockSupport.parkNanos()
+// and monitorenter when we're using 1-0 locking.  All those operations may result in
+// calls to pthread_cond_timedwait().  Using LD_ASSUME_KERNEL to use an older version
+// of libpthread avoids the problem, but isn't practical.
+//
+// Possible remedies:
+//
+// 1.   Establish a minimum relative wait time.  50 to 100 msecs seems to work.
+//      This is palliative and probabilistic, however.  If the thread is preempted
+//      between the call to compute_abstime() and pthread_cond_timedwait(), more
+//      than the minimum period may have passed, and the abstime may be stale (in the
+//      past) resultin in a hang.   Using this technique reduces the odds of a hang
+//      but the JVM is still vulnerable, particularly on heavily loaded systems.
+//
+// 2.   Modify park-unpark to use per-thread (per ParkEvent) pipe-pairs instead
+//      of the usual flag-condvar-mutex idiom.  The write side of the pipe is set
+//      NDELAY. unpark() reduces to write(), park() reduces to read() and park(timo)
+//      reduces to poll()+read().  This works well, but consumes 2 FDs per extant
+//      thread.
+//
+// 3.   Embargo pthread_cond_timedwait() and implement a native "chron" thread
+//      that manages timeouts.  We'd emulate pthread_cond_timedwait() by enqueuing
+//      a timeout request to the chron thread and then blocking via pthread_cond_wait().
+//      This also works well.  In fact it avoids kernel-level scalability impediments
+//      on certain platforms that don't handle lots of active pthread_cond_timedwait()
+//      timers in a graceful fashion.
+//
+// 4.   When the abstime value is in the past it appears that control returns
+//      correctly from pthread_cond_timedwait(), but the condvar is left corrupt.
+//      Subsequent timedwait/wait calls may hang indefinitely.  Given that, we
+//      can avoid the problem by reinitializing the condvar -- by cond_destroy()
+//      followed by cond_init() -- after all calls to pthread_cond_timedwait().
+//      It may be possible to avoid reinitialization by checking the return
+//      value from pthread_cond_timedwait().  In addition to reinitializing the
+//      condvar we must establish the invariant that cond_signal() is only called
+//      within critical sections protected by the adjunct mutex.  This prevents
+//      cond_signal() from "seeing" a condvar that's in the midst of being
+//      reinitialized or that is corrupt.  Sadly, this invariant obviates the
+//      desirable signal-after-unlock optimization that avoids futile context switching.
+//
+//      I'm also concerned that some versions of NTPL might allocate an auxilliary
+//      structure when a condvar is used or initialized.  cond_destroy()  would
+//      release the helper structure.  Our reinitialize-after-timedwait fix
+//      put excessive stress on malloc/free and locks protecting the c-heap.
+//
+// We currently use (4).  See the WorkAroundNTPLTimedWaitHang flag.
+// It may be possible to refine (4) by checking the kernel and NTPL verisons
+// and only enabling the work-around for vulnerable environments.
+
+// utility to compute the abstime argument to timedwait:
+// millis is the relative timeout time
+// abstime will be the absolute timeout time
+// TODO: replace compute_abstime() with unpackTime()
+
+static struct timespec* compute_abstime(struct timespec* abstime, jlong millis) {
+  if (millis < 0)  millis = 0;
+  struct timeval now;
+  int status = gettimeofday(&now, NULL);
+  assert(status == 0, "gettimeofday");
+  jlong seconds = millis / 1000;
+  millis %= 1000;
+  if (seconds > 50000000) { // see man cond_timedwait(3T)
+    seconds = 50000000;
+  }
+  abstime->tv_sec = now.tv_sec  + seconds;
+  long       usec = now.tv_usec + millis * 1000;
+  if (usec >= 1000000) {
+    abstime->tv_sec += 1;
+    usec -= 1000000;
+  }
+  abstime->tv_nsec = usec * 1000;
+  return abstime;
+}
+
+
+// Test-and-clear _Event, always leaves _Event set to 0, returns immediately.
+// Conceptually TryPark() should be equivalent to park(0).
+
+int os::PlatformEvent::TryPark() {
+  for (;;) {
+    const int v = _Event ;
+    guarantee ((v == 0) || (v == 1), "invariant") ;
+    if (Atomic::cmpxchg (0, &_Event, v) == v) return v  ;
+  }
+}
+
+void os::PlatformEvent::park() {       // AKA "down()"
+  // Invariant: Only the thread associated with the Event/PlatformEvent
+  // may call park().
+  // TODO: assert that _Assoc != NULL or _Assoc == Self
+  int v ;
+  for (;;) {
+      v = _Event ;
+      if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ;
+  }
+  guarantee (v >= 0, "invariant") ;
+  if (v == 0) {
+     // Do this the hard way by blocking ...
+     int status = pthread_mutex_lock(_mutex);
+     assert_status(status == 0, status, "mutex_lock");
+     guarantee (_nParked == 0, "invariant") ;
+     ++ _nParked ;
+     while (_Event < 0) {
+        status = pthread_cond_wait(_cond, _mutex);
+        // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
+        // Treat this the same as if the wait was interrupted
+        if (status == ETIMEDOUT) { status = EINTR; }
+        assert_status(status == 0 || status == EINTR, status, "cond_wait");
+     }
+     -- _nParked ;
+
+    // In theory we could move the ST of 0 into _Event past the unlock(),
+    // but then we'd need a MEMBAR after the ST.
+    _Event = 0 ;
+     status = pthread_mutex_unlock(_mutex);
+     assert_status(status == 0, status, "mutex_unlock");
+  }
+  guarantee (_Event >= 0, "invariant") ;
+}
+
+int os::PlatformEvent::park(jlong millis) {
+  guarantee (_nParked == 0, "invariant") ;
+
+  int v ;
+  for (;;) {
+      v = _Event ;
+      if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ;
+  }
+  guarantee (v >= 0, "invariant") ;
+  if (v != 0) return OS_OK ;
+
+  // We do this the hard way, by blocking the thread.
+  // Consider enforcing a minimum timeout value.
+  struct timespec abst;
+  compute_abstime(&abst, millis);
+
+  int ret = OS_TIMEOUT;
+  int status = pthread_mutex_lock(_mutex);
+  assert_status(status == 0, status, "mutex_lock");
+  guarantee (_nParked == 0, "invariant") ;
+  ++_nParked ;
+
+  // Object.wait(timo) will return because of
+  // (a) notification
+  // (b) timeout
+  // (c) thread.interrupt
+  //
+  // Thread.interrupt and object.notify{All} both call Event::set.
+  // That is, we treat thread.interrupt as a special case of notification.
+  // The underlying Solaris implementation, cond_timedwait, admits
+  // spurious/premature wakeups, but the JLS/JVM spec prevents the
+  // JVM from making those visible to Java code.  As such, we must
+  // filter out spurious wakeups.  We assume all ETIME returns are valid.
+  //
+  // TODO: properly differentiate simultaneous notify+interrupt.
+  // In that case, we should propagate the notify to another waiter.
+
+  while (_Event < 0) {
+    status = os::Bsd::safe_cond_timedwait(_cond, _mutex, &abst);
+    if (status != 0 && WorkAroundNPTLTimedWaitHang) {
+      pthread_cond_destroy (_cond);
+      pthread_cond_init (_cond, NULL) ;
+    }
+    assert_status(status == 0 || status == EINTR ||
+                  status == ETIMEDOUT,
+                  status, "cond_timedwait");
+    if (!FilterSpuriousWakeups) break ;                 // previous semantics
+    if (status == ETIMEDOUT) break ;
+    // We consume and ignore EINTR and spurious wakeups.
+  }
+  --_nParked ;
+  if (_Event >= 0) {
+     ret = OS_OK;
+  }
+  _Event = 0 ;
+  status = pthread_mutex_unlock(_mutex);
+  assert_status(status == 0, status, "mutex_unlock");
+  assert (_nParked == 0, "invariant") ;
+  return ret;
+}
+
+void os::PlatformEvent::unpark() {
+  int v, AnyWaiters ;
+  for (;;) {
+      v = _Event ;
+      if (v > 0) {
+         // The LD of _Event could have reordered or be satisfied
+         // by a read-aside from this processor's write buffer.
+         // To avoid problems execute a barrier and then
+         // ratify the value.
+         OrderAccess::fence() ;
+         if (_Event == v) return ;
+         continue ;
+      }
+      if (Atomic::cmpxchg (v+1, &_Event, v) == v) break ;
+  }
+  if (v < 0) {
+     // Wait for the thread associated with the event to vacate
+     int status = pthread_mutex_lock(_mutex);
+     assert_status(status == 0, status, "mutex_lock");
+     AnyWaiters = _nParked ;
+     assert (AnyWaiters == 0 || AnyWaiters == 1, "invariant") ;
+     if (AnyWaiters != 0 && WorkAroundNPTLTimedWaitHang) {
+        AnyWaiters = 0 ;
+        pthread_cond_signal (_cond);
+     }
+     status = pthread_mutex_unlock(_mutex);
+     assert_status(status == 0, status, "mutex_unlock");
+     if (AnyWaiters != 0) {
+        status = pthread_cond_signal(_cond);
+        assert_status(status == 0, status, "cond_signal");
+     }
+  }
+
+  // Note that we signal() _after dropping the lock for "immortal" Events.
+  // This is safe and avoids a common class of  futile wakeups.  In rare
+  // circumstances this can cause a thread to return prematurely from
+  // cond_{timed}wait() but the spurious wakeup is benign and the victim will
+  // simply re-test the condition and re-park itself.
+}
+
+
+// JSR166
+// -------------------------------------------------------
+
+/*
+ * The solaris and bsd implementations of park/unpark are fairly
+ * conservative for now, but can be improved. They currently use a
+ * mutex/condvar pair, plus a a count.
+ * Park decrements count if > 0, else does a condvar wait.  Unpark
+ * sets count to 1 and signals condvar.  Only one thread ever waits
+ * on the condvar. Contention seen when trying to park implies that someone
+ * is unparking you, so don't wait. And spurious returns are fine, so there
+ * is no need to track notifications.
+ */
+
+
+#define NANOSECS_PER_SEC 1000000000
+#define NANOSECS_PER_MILLISEC 1000000
+#define MAX_SECS 100000000
+/*
+ * This code is common to bsd and solaris and will be moved to a
+ * common place in dolphin.
+ *
+ * The passed in time value is either a relative time in nanoseconds
+ * or an absolute time in milliseconds. Either way it has to be unpacked
+ * into suitable seconds and nanoseconds components and stored in the
+ * given timespec structure.
+ * Given time is a 64-bit value and the time_t used in the timespec is only
+ * a signed-32-bit value (except on 64-bit Bsd) we have to watch for
+ * overflow if times way in the future are given. Further on Solaris versions
+ * prior to 10 there is a restriction (see cond_timedwait) that the specified
+ * number of seconds, in abstime, is less than current_time  + 100,000,000.
+ * As it will be 28 years before "now + 100000000" will overflow we can
+ * ignore overflow and just impose a hard-limit on seconds using the value
+ * of "now + 100,000,000". This places a limit on the timeout of about 3.17
+ * years from "now".
+ */
+
+static void unpackTime(struct timespec* absTime, bool isAbsolute, jlong time) {
+  assert (time > 0, "convertTime");
+
+  struct timeval now;
+  int status = gettimeofday(&now, NULL);
+  assert(status == 0, "gettimeofday");
+
+  time_t max_secs = now.tv_sec + MAX_SECS;
+
+  if (isAbsolute) {
+    jlong secs = time / 1000;
+    if (secs > max_secs) {
+      absTime->tv_sec = max_secs;
+    }
+    else {
+      absTime->tv_sec = secs;
+    }
+    absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
+  }
+  else {
+    jlong secs = time / NANOSECS_PER_SEC;
+    if (secs >= MAX_SECS) {
+      absTime->tv_sec = max_secs;
+      absTime->tv_nsec = 0;
+    }
+    else {
+      absTime->tv_sec = now.tv_sec + secs;
+      absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
+      if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
+        absTime->tv_nsec -= NANOSECS_PER_SEC;
+        ++absTime->tv_sec; // note: this must be <= max_secs
+      }
+    }
+  }
+  assert(absTime->tv_sec >= 0, "tv_sec < 0");
+  assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs");
+  assert(absTime->tv_nsec >= 0, "tv_nsec < 0");
+  assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec");
+}
+
+void Parker::park(bool isAbsolute, jlong time) {
+  // Optional fast-path check:
+  // Return immediately if a permit is available.
+  if (_counter > 0) {
+      _counter = 0 ;
+      OrderAccess::fence();
+      return ;
+  }
+
+  Thread* thread = Thread::current();
+  assert(thread->is_Java_thread(), "Must be JavaThread");
+  JavaThread *jt = (JavaThread *)thread;
+
+  // Optional optimization -- avoid state transitions if there's an interrupt pending.
+  // Check interrupt before trying to wait
+  if (Thread::is_interrupted(thread, false)) {
+    return;
+  }
+
+  // Next, demultiplex/decode time arguments
+  struct timespec absTime;
+  if (time < 0 || (isAbsolute && time == 0) ) { // don't wait at all
+    return;
+  }
+  if (time > 0) {
+    unpackTime(&absTime, isAbsolute, time);
+  }
+
+
+  // Enter safepoint region
+  // Beware of deadlocks such as 6317397.
+  // The per-thread Parker:: mutex is a classic leaf-lock.
+  // In particular a thread must never block on the Threads_lock while
+  // holding the Parker:: mutex.  If safepoints are pending both the
+  // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
+  ThreadBlockInVM tbivm(jt);
+
+  // Don't wait if cannot get lock since interference arises from
+  // unblocking.  Also. check interrupt before trying wait
+  if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) {
+    return;
+  }
+
+  int status ;
+  if (_counter > 0)  { // no wait needed
+    _counter = 0;
+    status = pthread_mutex_unlock(_mutex);
+    assert (status == 0, "invariant") ;
+    OrderAccess::fence();
+    return;
+  }
+
+#ifdef ASSERT
+  // Don't catch signals while blocked; let the running threads have the signals.
+  // (This allows a debugger to break into the running thread.)
+  sigset_t oldsigs;
+  sigset_t* allowdebug_blocked = os::Bsd::allowdebug_blocked_signals();
+  pthread_sigmask(SIG_BLOCK, allowdebug_blocked, &oldsigs);
+#endif
+
+  OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
+  jt->set_suspend_equivalent();
+  // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
+
+  if (time == 0) {
+    status = pthread_cond_wait (_cond, _mutex) ;
+  } else {
+    status = os::Bsd::safe_cond_timedwait (_cond, _mutex, &absTime) ;
+    if (status != 0 && WorkAroundNPTLTimedWaitHang) {
+      pthread_cond_destroy (_cond) ;
+      pthread_cond_init    (_cond, NULL);
+    }
+  }
+  assert_status(status == 0 || status == EINTR ||
+                status == ETIMEDOUT,
+                status, "cond_timedwait");
+
+#ifdef ASSERT
+  pthread_sigmask(SIG_SETMASK, &oldsigs, NULL);
+#endif
+
+  _counter = 0 ;
+  status = pthread_mutex_unlock(_mutex) ;
+  assert_status(status == 0, status, "invariant") ;
+  // If externally suspended while waiting, re-suspend
+  if (jt->handle_special_suspend_equivalent_condition()) {
+    jt->java_suspend_self();
+  }
+
+  OrderAccess::fence();
+}
+
+void Parker::unpark() {
+  int s, status ;
+  status = pthread_mutex_lock(_mutex);
+  assert (status == 0, "invariant") ;
+  s = _counter;
+  _counter = 1;
+  if (s < 1) {
+     if (WorkAroundNPTLTimedWaitHang) {
+        status = pthread_cond_signal (_cond) ;
+        assert (status == 0, "invariant") ;
+        status = pthread_mutex_unlock(_mutex);
+        assert (status == 0, "invariant") ;
+     } else {
+        status = pthread_mutex_unlock(_mutex);
+        assert (status == 0, "invariant") ;
+        status = pthread_cond_signal (_cond) ;
+        assert (status == 0, "invariant") ;
+     }
+  } else {
+    pthread_mutex_unlock(_mutex);
+    assert (status == 0, "invariant") ;
+  }
+}
+
+
+/* Darwin has no "environ" in a dynamic library. */
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#else
+extern char** environ;
+#endif
+
+// Run the specified command in a separate process. Return its exit value,
+// or -1 on failure (e.g. can't fork a new process).
+// Unlike system(), this function can be called from signal handler. It
+// doesn't block SIGINT et al.
+int os::fork_and_exec(char* cmd) {
+  const char * argv[4] = {"sh", "-c", cmd, NULL};
+
+  // fork() in BsdThreads/NPTL is not async-safe. It needs to run
+  // pthread_atfork handlers and reset pthread library. All we need is a
+  // separate process to execve. Make a direct syscall to fork process.
+  // On IA64 there's no fork syscall, we have to use fork() and hope for
+  // the best...
+  pid_t pid = fork();
+
+  if (pid < 0) {
+    // fork failed
+    return -1;
+
+  } else if (pid == 0) {
+    // child process
+
+    // execve() in BsdThreads will call pthread_kill_other_threads_np()
+    // first to kill every thread on the thread list. Because this list is
+    // not reset by fork() (see notes above), execve() will instead kill
+    // every thread in the parent process. We know this is the only thread
+    // in the new process, so make a system call directly.
+    // IA64 should use normal execve() from glibc to match the glibc fork()
+    // above.
+    execve("/bin/sh", (char* const*)argv, environ);
+
+    // execve failed
+    _exit(-1);
+
+  } else  {
+    // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
+    // care about the actual exit code, for now.
+
+    int status;
+
+    // Wait for the child process to exit.  This returns immediately if
+    // the child has already exited. */
+    while (waitpid(pid, &status, 0) < 0) {
+        switch (errno) {
+        case ECHILD: return 0;
+        case EINTR: break;
+        default: return -1;
+        }
+    }
+
+    if (WIFEXITED(status)) {
+       // The child exited normally; get its exit code.
+       return WEXITSTATUS(status);
+    } else if (WIFSIGNALED(status)) {
+       // The child exited because of a signal
+       // The best value to return is 0x80 + signal number,
+       // because that is what all Unix shells do, and because
+       // it allows callers to distinguish between process exit and
+       // process death by signal.
+       return 0x80 + WTERMSIG(status);
+    } else {
+       // Unknown exit code; pass it through
+       return status;
+    }
+  }
+}
+
+// is_headless_jre()
+//
+// Test for the existence of libmawt in motif21 or xawt directories
+// in order to report if we are running in a headless jre
+//
+bool os::is_headless_jre() {
+    struct stat statbuf;
+    char buf[MAXPATHLEN];
+    char libmawtpath[MAXPATHLEN];
+    const char *xawtstr  = "/xawt/libmawt" JNI_LIB_SUFFIX;
+    const char *motifstr = "/motif21/libmawt" JNI_LIB_SUFFIX;
+    char *p;
+
+    // Get path to libjvm.so
+    os::jvm_path(buf, sizeof(buf));
+
+    // Get rid of libjvm.so
+    p = strrchr(buf, '/');
+    if (p == NULL) return false;
+    else *p = '\0';
+
+    // Get rid of client or server
+    p = strrchr(buf, '/');
+    if (p == NULL) return false;
+    else *p = '\0';
+
+    // check xawt/libmawt.so
+    strcpy(libmawtpath, buf);
+    strcat(libmawtpath, xawtstr);
+    if (::stat(libmawtpath, &statbuf) == 0) return false;
+
+    // check motif21/libmawt.so
+    strcpy(libmawtpath, buf);
+    strcat(libmawtpath, motifstr);
+    if (::stat(libmawtpath, &statbuf) == 0) return false;
+
+    return true;
+}
diff --git a/hotspot/src/os/bsd/vm/os_bsd.hpp b/hotspot/src/os/bsd/vm/os_bsd.hpp
new file mode 100644
index 0000000..271d1e2
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/os_bsd.hpp
@@ -0,0 +1,368 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_OS_BSD_HPP
+#define OS_BSD_VM_OS_BSD_HPP
+
+// Bsd_OS defines the interface to Bsd operating systems
+
+/* pthread_getattr_np comes with BsdThreads-0.9-7 on RedHat 7.1 */
+typedef int (*pthread_getattr_func_type) (pthread_t, pthread_attr_t *);
+
+#ifdef __APPLE__
+// Mac OS X doesn't support clock_gettime. Stub out the type, it is
+// unused
+typedef int clockid_t;
+#endif
+
+class Bsd {
+  friend class os;
+
+  // For signal-chaining
+#define MAXSIGNUM 32
+  static struct sigaction sigact[MAXSIGNUM]; // saved preinstalled sigactions
+  static unsigned int sigs;             // mask of signals that have
+                                        // preinstalled signal handlers
+  static bool libjsig_is_loaded;        // libjsig that interposes sigaction(),
+                                        // __sigaction(), signal() is loaded
+  static struct sigaction *(*get_signal_action)(int);
+  static struct sigaction *get_preinstalled_handler(int);
+  static void save_preinstalled_handler(int, struct sigaction&);
+
+  static void check_signal_handler(int sig);
+
+  // For signal flags diagnostics
+  static int sigflags[MAXSIGNUM];
+
+  static int (*_clock_gettime)(clockid_t, struct timespec *);
+#ifndef _ALLBSD_SOURCE
+  static int (*_pthread_getcpuclockid)(pthread_t, clockid_t *);
+
+  static address   _initial_thread_stack_bottom;
+  static uintptr_t _initial_thread_stack_size;
+
+  static const char *_glibc_version;
+  static const char *_libpthread_version;
+
+  static bool _is_floating_stack;
+  static bool _is_NPTL;
+  static bool _supports_fast_thread_cpu_time;
+#endif
+
+  static GrowableArray<int>* _cpu_to_node;
+
+ protected:
+
+  static julong _physical_memory;
+  static pthread_t _main_thread;
+#ifndef _ALLBSD_SOURCE
+  static Mutex* _createThread_lock;
+#endif
+  static int _page_size;
+
+  static julong available_memory();
+  static julong physical_memory() { return _physical_memory; }
+  static void initialize_system_info();
+
+#ifndef _ALLBSD_SOURCE
+  static void set_glibc_version(const char *s)      { _glibc_version = s; }
+  static void set_libpthread_version(const char *s) { _libpthread_version = s; }
+#endif
+
+  static bool supports_variable_stack_size();
+
+#ifndef _ALLBSD_SOURCE
+  static void set_is_NPTL()                   { _is_NPTL = true;  }
+  static void set_is_BsdThreads()           { _is_NPTL = false; }
+  static void set_is_floating_stack()         { _is_floating_stack = true; }
+#endif
+
+  static void rebuild_cpu_to_node_map();
+  static GrowableArray<int>* cpu_to_node()    { return _cpu_to_node; }
+
+  static bool hugetlbfs_sanity_check(bool warn, size_t page_size);
+
+ public:
+
+  static void init_thread_fpu_state();
+#ifndef _ALLBSD_SOURCE
+  static int  get_fpu_control_word();
+  static void set_fpu_control_word(int fpu_control);
+#endif
+  static pthread_t main_thread(void)                                { return _main_thread; }
+
+#ifndef _ALLBSD_SOURCE
+  // returns kernel thread id (similar to LWP id on Solaris), which can be
+  // used to access /proc
+  static pid_t gettid();
+  static void set_createThread_lock(Mutex* lk)                      { _createThread_lock = lk; }
+  static Mutex* createThread_lock(void)                             { return _createThread_lock; }
+#endif
+  static void hotspot_sigmask(Thread* thread);
+
+#ifndef _ALLBSD_SOURCE
+  static address   initial_thread_stack_bottom(void)                { return _initial_thread_stack_bottom; }
+  static uintptr_t initial_thread_stack_size(void)                  { return _initial_thread_stack_size; }
+#endif
+  static bool is_initial_thread(void);
+
+  static int page_size(void)                                        { return _page_size; }
+  static void set_page_size(int val)                                { _page_size = val; }
+
+  static address   ucontext_get_pc(ucontext_t* uc);
+  static intptr_t* ucontext_get_sp(ucontext_t* uc);
+  static intptr_t* ucontext_get_fp(ucontext_t* uc);
+
+  // For Analyzer Forte AsyncGetCallTrace profiling support:
+  //
+  // This interface should be declared in os_bsd_i486.hpp, but
+  // that file provides extensions to the os class and not the
+  // Bsd class.
+  static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc,
+    intptr_t** ret_sp, intptr_t** ret_fp);
+
+  // This boolean allows users to forward their own non-matching signals
+  // to JVM_handle_bsd_signal, harmlessly.
+  static bool signal_handlers_are_installed;
+
+  static int get_our_sigflags(int);
+  static void set_our_sigflags(int, int);
+  static void signal_sets_init();
+  static void install_signal_handlers();
+  static void set_signal_handler(int, bool);
+  static bool is_sig_ignored(int sig);
+
+  static sigset_t* unblocked_signals();
+  static sigset_t* vm_signals();
+  static sigset_t* allowdebug_blocked_signals();
+
+  // For signal-chaining
+  static struct sigaction *get_chained_signal_action(int sig);
+  static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
+
+#ifndef _ALLBSD_SOURCE
+  // GNU libc and libpthread version strings
+  static const char *glibc_version()          { return _glibc_version; }
+  static const char *libpthread_version()     { return _libpthread_version; }
+
+  // NPTL or BsdThreads?
+  static bool is_BsdThreads()               { return !_is_NPTL; }
+  static bool is_NPTL()                       { return _is_NPTL;  }
+
+  // NPTL is always floating stack. BsdThreads could be using floating
+  // stack or fixed stack.
+  static bool is_floating_stack()             { return _is_floating_stack; }
+
+  static void libpthread_init();
+  static bool libnuma_init();
+  static void* libnuma_dlsym(void* handle, const char* name);
+#endif
+  // Minimum stack size a thread can be created with (allowing
+  // the VM to completely create the thread and enter user code)
+  static size_t min_stack_allowed;
+
+  // Return default stack size or guard size for the specified thread type
+  static size_t default_stack_size(os::ThreadType thr_type);
+  static size_t default_guard_size(os::ThreadType thr_type);
+
+#ifndef _ALLBSD_SOURCE
+  static void capture_initial_stack(size_t max_size);
+
+  // Stack overflow handling
+  static bool manually_expand_stack(JavaThread * t, address addr);
+  static int max_register_window_saves_before_flushing();
+#endif
+
+  // Real-time clock functions
+  static void clock_init(void);
+
+#ifndef _ALLBSD_SOURCE
+  // fast POSIX clocks support
+  static void fast_thread_clock_init(void);
+#endif
+
+  static bool supports_monotonic_clock() {
+    return _clock_gettime != NULL;
+  }
+
+  static int clock_gettime(clockid_t clock_id, struct timespec *tp) {
+    return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
+  }
+
+#ifndef _ALLBSD_SOURCE
+  static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
+    return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
+  }
+
+  static bool supports_fast_thread_cpu_time() {
+    return _supports_fast_thread_cpu_time;
+  }
+
+  static jlong fast_thread_cpu_time(clockid_t clockid);
+#endif
+
+  // Stack repair handling
+
+  // none present
+
+  // BsdThreads work-around for 6292965
+  static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);
+
+
+  // Bsd suspend/resume support - this helper is a shadow of its former
+  // self now that low-level suspension is barely used, and old workarounds
+  // for BsdThreads are no longer needed.
+  class SuspendResume {
+  private:
+    volatile int _suspend_action;
+    // values for suspend_action:
+    #define SR_NONE               (0x00)
+    #define SR_SUSPEND            (0x01)  // suspend request
+    #define SR_CONTINUE           (0x02)  // resume request
+
+    volatile jint _state;
+    // values for _state: + SR_NONE
+    #define SR_SUSPENDED          (0x20)
+  public:
+    SuspendResume() { _suspend_action = SR_NONE; _state = SR_NONE; }
+
+    int suspend_action() const     { return _suspend_action; }
+    void set_suspend_action(int x) { _suspend_action = x;    }
+
+    // atomic updates for _state
+    void set_suspended()           {
+      jint temp, temp2;
+      do {
+        temp = _state;
+        temp2 = Atomic::cmpxchg(temp | SR_SUSPENDED, &_state, temp);
+      } while (temp2 != temp);
+    }
+    void clear_suspended()        {
+      jint temp, temp2;
+      do {
+        temp = _state;
+        temp2 = Atomic::cmpxchg(temp & ~SR_SUSPENDED, &_state, temp);
+      } while (temp2 != temp);
+    }
+    bool is_suspended()            { return _state & SR_SUSPENDED;       }
+
+    #undef SR_SUSPENDED
+  };
+
+private:
+  typedef int (*sched_getcpu_func_t)(void);
+  typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
+  typedef int (*numa_max_node_func_t)(void);
+  typedef int (*numa_available_func_t)(void);
+  typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
+  typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
+
+  static sched_getcpu_func_t _sched_getcpu;
+  static numa_node_to_cpus_func_t _numa_node_to_cpus;
+  static numa_max_node_func_t _numa_max_node;
+  static numa_available_func_t _numa_available;
+  static numa_tonode_memory_func_t _numa_tonode_memory;
+  static numa_interleave_memory_func_t _numa_interleave_memory;
+  static unsigned long* _numa_all_nodes;
+
+  static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
+  static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
+  static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
+  static void set_numa_available(numa_available_func_t func) { _numa_available = func; }
+  static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; }
+  static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; }
+  static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; }
+public:
+  static int sched_getcpu()  { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }
+  static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {
+    return _numa_node_to_cpus != NULL ? _numa_node_to_cpus(node, buffer, bufferlen) : -1;
+  }
+  static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; }
+  static int numa_available() { return _numa_available != NULL ? _numa_available() : -1; }
+  static int numa_tonode_memory(void *start, size_t size, int node) {
+    return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1;
+  }
+  static void numa_interleave_memory(void *start, size_t size) {
+    if (_numa_interleave_memory != NULL && _numa_all_nodes != NULL) {
+      _numa_interleave_memory(start, size, _numa_all_nodes);
+    }
+  }
+  static int get_node_by_cpu(int cpu_id);
+};
+
+
+class PlatformEvent : public CHeapObj {
+  private:
+    double CachePad [4] ;   // increase odds that _mutex is sole occupant of cache line
+    volatile int _Event ;
+    volatile int _nParked ;
+    pthread_mutex_t _mutex  [1] ;
+    pthread_cond_t  _cond   [1] ;
+    double PostPad  [2] ;
+    Thread * _Assoc ;
+
+  public:       // TODO-FIXME: make dtor private
+    ~PlatformEvent() { guarantee (0, "invariant") ; }
+
+  public:
+    PlatformEvent() {
+      int status;
+      status = pthread_cond_init (_cond, NULL);
+      assert_status(status == 0, status, "cond_init");
+      status = pthread_mutex_init (_mutex, NULL);
+      assert_status(status == 0, status, "mutex_init");
+      _Event   = 0 ;
+      _nParked = 0 ;
+      _Assoc   = NULL ;
+    }
+
+    // Use caution with reset() and fired() -- they may require MEMBARs
+    void reset() { _Event = 0 ; }
+    int  fired() { return _Event; }
+    void park () ;
+    void unpark () ;
+    int  TryPark () ;
+    int  park (jlong millis) ;
+    void SetAssociation (Thread * a) { _Assoc = a ; }
+} ;
+
+class PlatformParker : public CHeapObj {
+  protected:
+    pthread_mutex_t _mutex [1] ;
+    pthread_cond_t  _cond  [1] ;
+
+  public:       // TODO-FIXME: make dtor private
+    ~PlatformParker() { guarantee (0, "invariant") ; }
+
+  public:
+    PlatformParker() {
+      int status;
+      status = pthread_cond_init (_cond, NULL);
+      assert_status(status == 0, status, "cond_init");
+      status = pthread_mutex_init (_mutex, NULL);
+      assert_status(status == 0, status, "mutex_init");
+    }
+} ;
+
+#endif // OS_BSD_VM_OS_BSD_HPP
diff --git a/hotspot/src/os/bsd/vm/os_bsd.inline.hpp b/hotspot/src/os/bsd/vm/os_bsd.inline.hpp
new file mode 100644
index 0000000..731a7e6
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/os_bsd.inline.hpp
@@ -0,0 +1,302 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_OS_BSD_INLINE_HPP
+#define OS_BSD_VM_OS_BSD_INLINE_HPP
+
+#include "runtime/atomic.hpp"
+#include "runtime/os.hpp"
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "atomic_bsd_x86.inline.hpp"
+# include "orderAccess_bsd_x86.inline.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "atomic_bsd_zero.inline.hpp"
+# include "orderAccess_bsd_zero.inline.hpp"
+#endif
+
+// System includes
+
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netdb.h>
+
+inline void* os::thread_local_storage_at(int index) {
+  return pthread_getspecific((pthread_key_t)index);
+}
+
+inline const char* os::file_separator() {
+  return "/";
+}
+
+inline const char* os::line_separator() {
+  return "\n";
+}
+
+inline const char* os::path_separator() {
+  return ":";
+}
+
+inline const char* os::jlong_format_specifier() {
+  return "%lld";
+}
+
+inline const char* os::julong_format_specifier() {
+  return "%llu";
+}
+
+// File names are case-sensitive on windows only
+inline int os::file_name_strcmp(const char* s1, const char* s2) {
+  return strcmp(s1, s2);
+}
+
+inline bool os::obsolete_option(const JavaVMOption *option) {
+  return false;
+}
+
+inline bool os::uses_stack_guard_pages() {
+  return true;
+}
+
+inline bool os::allocate_stack_guard_pages() {
+  assert(uses_stack_guard_pages(), "sanity check");
+#if !defined(__FreeBSD__) || __FreeBSD__ < 5
+  // Since FreeBSD 4 uses malloc() for allocating the thread stack
+  // there is no need to do anything extra to allocate the guard pages
+  return false;
+#else
+  // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.
+  // Must 'allocate' them or guard pages are ignored.
+  return true;
+#endif
+}
+
+
+// On Bsd, reservations are made on a page by page basis, nothing to do.
+inline void os::split_reserved_memory(char *base, size_t size,
+                                      size_t split, bool realloc) {
+}
+
+
+// Bang the shadow pages if they need to be touched to be mapped.
+inline void os::bang_stack_shadow_pages() {
+}
+
+inline void os::dll_unload(void *lib) {
+  ::dlclose(lib);
+}
+
+inline const int os::default_file_open_flags() { return 0;}
+
+inline DIR* os::opendir(const char* dirname)
+{
+  assert(dirname != NULL, "just checking");
+  return ::opendir(dirname);
+}
+
+inline int os::readdir_buf_size(const char *path)
+{
+  return NAME_MAX + sizeof(dirent) + 1;
+}
+
+inline jlong os::lseek(int fd, jlong offset, int whence) {
+  return (jlong) ::lseek(fd, offset, whence);
+}
+
+inline int os::fsync(int fd) {
+  return ::fsync(fd);
+}
+
+inline char* os::native_path(char *path) {
+  return path;
+}
+
+inline int os::ftruncate(int fd, jlong length) {
+  return ::ftruncate(fd, length);
+}
+
+inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
+{
+  dirent* p;
+  int status;
+  assert(dirp != NULL, "just checking");
+
+  // NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
+  // version. Here is the doc for this function:
+  // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
+
+  if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
+    errno = status;
+    return NULL;
+  } else
+    return p;
+}
+
+inline int os::closedir(DIR *dirp) {
+  assert(dirp != NULL, "argument is NULL");
+  return ::closedir(dirp);
+}
+
+// macros for restartable system calls
+
+#define RESTARTABLE(_cmd, _result) do { \
+    _result = _cmd; \
+  } while(((int)_result == OS_ERR) && (errno == EINTR))
+
+#define RESTARTABLE_RETURN_INT(_cmd) do { \
+  int _result; \
+  RESTARTABLE(_cmd, _result); \
+  return _result; \
+} while(false)
+
+inline bool os::numa_has_static_binding()   { return true; }
+inline bool os::numa_has_group_homing()     { return false;  }
+
+inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
+  size_t res;
+  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
+  return res;
+}
+
+inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
+  size_t res;
+  RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
+  return res;
+}
+
+inline int os::close(int fd) {
+  RESTARTABLE_RETURN_INT(::close(fd));
+}
+
+inline int os::socket_close(int fd) {
+  RESTARTABLE_RETURN_INT(::close(fd));
+}
+
+inline int os::socket(int domain, int type, int protocol) {
+  return ::socket(domain, type, protocol);
+}
+
+inline int os::recv(int fd, char *buf, int nBytes, int flags) {
+  RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags));
+}
+
+inline int os::send(int fd, char *buf, int nBytes, int flags) {
+  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags));
+}
+
+inline int os::raw_send(int fd, char *buf, int nBytes, int flags) {
+  return os::send(fd, buf, nBytes, flags);
+}
+
+inline int os::timeout(int fd, long timeout) {
+  julong prevtime,newtime;
+  struct timeval t;
+
+  gettimeofday(&t, NULL);
+  prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
+
+  for(;;) {
+    struct pollfd pfd;
+
+    pfd.fd = fd;
+    pfd.events = POLLIN | POLLERR;
+
+    int res = ::poll(&pfd, 1, timeout);
+
+    if (res == OS_ERR && errno == EINTR) {
+
+      // On Bsd any value < 0 means "forever"
+
+      if(timeout >= 0) {
+        gettimeofday(&t, NULL);
+        newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
+        timeout -= newtime - prevtime;
+        if(timeout <= 0)
+          return OS_OK;
+        prevtime = newtime;
+      }
+    } else
+      return res;
+  }
+}
+
+inline int os::listen(int fd, int count) {
+  return ::listen(fd, count);
+}
+
+inline int os::connect(int fd, struct sockaddr *him, int len) {
+  RESTARTABLE_RETURN_INT(::connect(fd, him, len));
+}
+
+inline int os::accept(int fd, struct sockaddr *him, int *len) {
+  // This cast is from int to unsigned int on bsd.  Since we
+  // only pass the parameter "len" around the vm and don't try to
+  // fetch it's value, this cast is safe for now. The java.net group
+  // may need and want to change this interface someday if socklen_t goes
+  // to 64 bits on some platform that we support.
+
+  // At least OpenBSD and FreeBSD can return EINTR from accept.
+  RESTARTABLE_RETURN_INT(::accept(fd, him, (socklen_t *)len));
+}
+
+inline int os::recvfrom(int fd, char *buf, int nBytes, int flags,
+                         sockaddr *from, int *fromlen) {
+  RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen));
+}
+
+inline int os::sendto(int fd, char *buf, int len, int flags,
+                        struct sockaddr *to, int tolen) {
+  RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen));
+}
+
+inline int os::socket_shutdown(int fd, int howto){
+  return ::shutdown(fd, howto);
+}
+
+inline int os::bind(int fd, struct sockaddr *him, int len){
+  return ::bind(fd, him, len);
+}
+
+inline int os::get_sock_name(int fd, struct sockaddr *him, int *len){
+  return ::getsockname(fd, him, (socklen_t *)len);
+}
+
+inline int os::get_host_name(char* name, int namelen){
+  return ::gethostname(name, namelen);
+}
+
+inline struct hostent*  os::get_host_by_name(char* name) {
+  return ::gethostbyname(name);
+}
+inline int os::get_sock_opt(int fd, int level, int optname,
+                             char *optval, int* optlen){
+  return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen);
+}
+
+inline int os::set_sock_opt(int fd, int level, int optname,
+                             const char *optval, int optlen){
+  return ::setsockopt(fd, level, optname, optval, optlen);
+}
+#endif // OS_BSD_VM_OS_BSD_INLINE_HPP
diff --git a/hotspot/src/os/bsd/vm/os_share_bsd.hpp b/hotspot/src/os/bsd/vm/os_share_bsd.hpp
new file mode 100644
index 0000000..5caa782
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/os_share_bsd.hpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_OS_SHARE_BSD_HPP
+#define OS_BSD_VM_OS_SHARE_BSD_HPP
+
+// misc
+void signalHandler(int, siginfo_t*, ucontext_t*);
+void handle_unexpected_exception(Thread* thread, int sig, siginfo_t* info, address pc, address adjusted_pc);
+#ifndef PRODUCT
+void continue_with_dump(void);
+#endif
+
+#define PROCFILE_LENGTH 128
+
+#endif // OS_BSD_VM_OS_SHARE_BSD_HPP
diff --git a/hotspot/src/os/bsd/vm/perfMemory_bsd.cpp b/hotspot/src/os/bsd/vm/perfMemory_bsd.cpp
new file mode 100644
index 0000000..c93289e
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/perfMemory_bsd.cpp
@@ -0,0 +1,1041 @@
+/*
+ * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "classfile/vmSymbols.hpp"
+#include "memory/allocation.inline.hpp"
+#include "memory/resourceArea.hpp"
+#include "oops/oop.inline.hpp"
+#include "os_bsd.inline.hpp"
+#include "runtime/handles.inline.hpp"
+#include "runtime/perfMemory.hpp"
+#include "utilities/exceptions.hpp"
+
+// put OS-includes here
+# include <sys/types.h>
+# include <sys/mman.h>
+# include <errno.h>
+# include <stdio.h>
+# include <unistd.h>
+# include <sys/stat.h>
+# include <signal.h>
+# include <pwd.h>
+
+static char* backing_store_file_name = NULL;  // name of the backing store
+                                              // file, if successfully created.
+
+// Standard Memory Implementation Details
+
+// create the PerfData memory region in standard memory.
+//
+static char* create_standard_memory(size_t size) {
+
+  // allocate an aligned chuck of memory
+  char* mapAddress = os::reserve_memory(size);
+
+  if (mapAddress == NULL) {
+    return NULL;
+  }
+
+  // commit memory
+  if (!os::commit_memory(mapAddress, size)) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("Could not commit PerfData memory\n");
+    }
+    os::release_memory(mapAddress, size);
+    return NULL;
+  }
+
+  return mapAddress;
+}
+
+// delete the PerfData memory region
+//
+static void delete_standard_memory(char* addr, size_t size) {
+
+  // there are no persistent external resources to cleanup for standard
+  // memory. since DestroyJavaVM does not support unloading of the JVM,
+  // cleanup of the memory resource is not performed. The memory will be
+  // reclaimed by the OS upon termination of the process.
+  //
+  return;
+}
+
+// save the specified memory region to the given file
+//
+// Note: this function might be called from signal handler (by os::abort()),
+// don't allocate heap memory.
+//
+static void save_memory_to_file(char* addr, size_t size) {
+
+ const char* destfile = PerfMemory::get_perfdata_file_path();
+ assert(destfile[0] != '\0', "invalid PerfData file path");
+
+  int result;
+
+  RESTARTABLE(::open(destfile, O_CREAT|O_WRONLY|O_TRUNC, S_IREAD|S_IWRITE),
+              result);;
+  if (result == OS_ERR) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("Could not create Perfdata save file: %s: %s\n",
+              destfile, strerror(errno));
+    }
+  } else {
+    int fd = result;
+
+    for (size_t remaining = size; remaining > 0;) {
+
+      RESTARTABLE(::write(fd, addr, remaining), result);
+      if (result == OS_ERR) {
+        if (PrintMiscellaneous && Verbose) {
+          warning("Could not write Perfdata save file: %s: %s\n",
+                  destfile, strerror(errno));
+        }
+        break;
+      }
+
+      remaining -= (size_t)result;
+      addr += result;
+    }
+
+    RESTARTABLE(::close(fd), result);
+    if (PrintMiscellaneous && Verbose) {
+      if (result == OS_ERR) {
+        warning("Could not close %s: %s\n", destfile, strerror(errno));
+      }
+    }
+  }
+  FREE_C_HEAP_ARRAY(char, destfile);
+}
+
+
+// Shared Memory Implementation Details
+
+// Note: the solaris and bsd shared memory implementation uses the mmap
+// interface with a backing store file to implement named shared memory.
+// Using the file system as the name space for shared memory allows a
+// common name space to be supported across a variety of platforms. It
+// also provides a name space that Java applications can deal with through
+// simple file apis.
+//
+// The solaris and bsd implementations store the backing store file in
+// a user specific temporary directory located in the /tmp file system,
+// which is always a local file system and is sometimes a RAM based file
+// system.
+
+// return the user specific temporary directory name.
+//
+// the caller is expected to free the allocated memory.
+//
+static char* get_user_tmp_dir(const char* user) {
+
+  const char* tmpdir = os::get_temp_directory();
+  const char* perfdir = PERFDATA_NAME;
+  size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 3;
+  char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
+
+  // construct the path name to user specific tmp directory
+  snprintf(dirname, nbytes, "%s/%s_%s", tmpdir, perfdir, user);
+
+  return dirname;
+}
+
+// convert the given file name into a process id. if the file
+// does not meet the file naming constraints, return 0.
+//
+static pid_t filename_to_pid(const char* filename) {
+
+  // a filename that doesn't begin with a digit is not a
+  // candidate for conversion.
+  //
+  if (!isdigit(*filename)) {
+    return 0;
+  }
+
+  // check if file name can be converted to an integer without
+  // any leftover characters.
+  //
+  char* remainder = NULL;
+  errno = 0;
+  pid_t pid = (pid_t)strtol(filename, &remainder, 10);
+
+  if (errno != 0) {
+    return 0;
+  }
+
+  // check for left over characters. If any, then the filename is
+  // not a candidate for conversion.
+  //
+  if (remainder != NULL && *remainder != '\0') {
+    return 0;
+  }
+
+  // successful conversion, return the pid
+  return pid;
+}
+
+
+// check if the given path is considered a secure directory for
+// the backing store files. Returns true if the directory exists
+// and is considered a secure location. Returns false if the path
+// is a symbolic link or if an error occurred.
+//
+static bool is_directory_secure(const char* path) {
+  struct stat statbuf;
+  int result = 0;
+
+  RESTARTABLE(::lstat(path, &statbuf), result);
+  if (result == OS_ERR) {
+    return false;
+  }
+
+  // the path exists, now check it's mode
+  if (S_ISLNK(statbuf.st_mode) || !S_ISDIR(statbuf.st_mode)) {
+    // the path represents a link or some non-directory file type,
+    // which is not what we expected. declare it insecure.
+    //
+    return false;
+  }
+  else {
+    // we have an existing directory, check if the permissions are safe.
+    //
+    if ((statbuf.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
+      // the directory is open for writing and could be subjected
+      // to a symlnk attack. declare it insecure.
+      //
+      return false;
+    }
+  }
+  return true;
+}
+
+
+// return the user name for the given user id
+//
+// the caller is expected to free the allocated memory.
+//
+static char* get_user_name(uid_t uid) {
+
+  struct passwd pwent;
+
+  // determine the max pwbuf size from sysconf, and hardcode
+  // a default if this not available through sysconf.
+  //
+  long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+  if (bufsize == -1)
+    bufsize = 1024;
+
+  char* pwbuf = NEW_C_HEAP_ARRAY(char, bufsize);
+
+  // POSIX interface to getpwuid_r is used on LINUX
+  struct passwd* p;
+  int result = getpwuid_r(uid, &pwent, pwbuf, (size_t)bufsize, &p);
+
+  if (result != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
+    if (PrintMiscellaneous && Verbose) {
+      if (result != 0) {
+        warning("Could not retrieve passwd entry: %s\n",
+                strerror(result));
+      }
+      else if (p == NULL) {
+        // this check is added to protect against an observed problem
+        // with getpwuid_r() on RedHat 9 where getpwuid_r returns 0,
+        // indicating success, but has p == NULL. This was observed when
+        // inserting a file descriptor exhaustion fault prior to the call
+        // getpwuid_r() call. In this case, error is set to the appropriate
+        // error condition, but this is undocumented behavior. This check
+        // is safe under any condition, but the use of errno in the output
+        // message may result in an erroneous message.
+        // Bug Id 89052 was opened with RedHat.
+        //
+        warning("Could not retrieve passwd entry: %s\n",
+                strerror(errno));
+      }
+      else {
+        warning("Could not determine user name: %s\n",
+                p->pw_name == NULL ? "pw_name = NULL" :
+                                     "pw_name zero length");
+      }
+    }
+    FREE_C_HEAP_ARRAY(char, pwbuf);
+    return NULL;
+  }
+
+  char* user_name = NEW_C_HEAP_ARRAY(char, strlen(p->pw_name) + 1);
+  strcpy(user_name, p->pw_name);
+
+  FREE_C_HEAP_ARRAY(char, pwbuf);
+  return user_name;
+}
+
+// return the name of the user that owns the process identified by vmid.
+//
+// This method uses a slow directory search algorithm to find the backing
+// store file for the specified vmid and returns the user name, as determined
+// by the user name suffix of the hsperfdata_<username> directory name.
+//
+// the caller is expected to free the allocated memory.
+//
+static char* get_user_name_slow(int vmid, TRAPS) {
+
+  // short circuit the directory search if the process doesn't even exist.
+  if (kill(vmid, 0) == OS_ERR) {
+    if (errno == ESRCH) {
+      THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
+                  "Process not found");
+    }
+    else /* EPERM */ {
+      THROW_MSG_0(vmSymbols::java_io_IOException(), strerror(errno));
+    }
+  }
+
+  // directory search
+  char* oldest_user = NULL;
+  time_t oldest_ctime = 0;
+
+  const char* tmpdirname = os::get_temp_directory();
+
+  DIR* tmpdirp = os::opendir(tmpdirname);
+
+  if (tmpdirp == NULL) {
+    return NULL;
+  }
+
+  // for each entry in the directory that matches the pattern hsperfdata_*,
+  // open the directory and check if the file for the given vmid exists.
+  // The file with the expected name and the latest creation date is used
+  // to determine the user name for the process id.
+  //
+  struct dirent* dentry;
+  char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname));
+  errno = 0;
+  while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) {
+
+    // check if the directory entry is a hsperfdata file
+    if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
+      continue;
+    }
+
+    char* usrdir_name = NEW_C_HEAP_ARRAY(char,
+                              strlen(tmpdirname) + strlen(dentry->d_name) + 2);
+    strcpy(usrdir_name, tmpdirname);
+    strcat(usrdir_name, "/");
+    strcat(usrdir_name, dentry->d_name);
+
+    DIR* subdirp = os::opendir(usrdir_name);
+
+    if (subdirp == NULL) {
+      FREE_C_HEAP_ARRAY(char, usrdir_name);
+      continue;
+    }
+
+    // Since we don't create the backing store files in directories
+    // pointed to by symbolic links, we also don't follow them when
+    // looking for the files. We check for a symbolic link after the
+    // call to opendir in order to eliminate a small window where the
+    // symlink can be exploited.
+    //
+    if (!is_directory_secure(usrdir_name)) {
+      FREE_C_HEAP_ARRAY(char, usrdir_name);
+      os::closedir(subdirp);
+      continue;
+    }
+
+    struct dirent* udentry;
+    char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name));
+    errno = 0;
+    while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) {
+
+      if (filename_to_pid(udentry->d_name) == vmid) {
+        struct stat statbuf;
+        int result;
+
+        char* filename = NEW_C_HEAP_ARRAY(char,
+                            strlen(usrdir_name) + strlen(udentry->d_name) + 2);
+
+        strcpy(filename, usrdir_name);
+        strcat(filename, "/");
+        strcat(filename, udentry->d_name);
+
+        // don't follow symbolic links for the file
+        RESTARTABLE(::lstat(filename, &statbuf), result);
+        if (result == OS_ERR) {
+           FREE_C_HEAP_ARRAY(char, filename);
+           continue;
+        }
+
+        // skip over files that are not regular files.
+        if (!S_ISREG(statbuf.st_mode)) {
+          FREE_C_HEAP_ARRAY(char, filename);
+          continue;
+        }
+
+        // compare and save filename with latest creation time
+        if (statbuf.st_size > 0 && statbuf.st_ctime > oldest_ctime) {
+
+          if (statbuf.st_ctime > oldest_ctime) {
+            char* user = strchr(dentry->d_name, '_') + 1;
+
+            if (oldest_user != NULL) FREE_C_HEAP_ARRAY(char, oldest_user);
+            oldest_user = NEW_C_HEAP_ARRAY(char, strlen(user)+1);
+
+            strcpy(oldest_user, user);
+            oldest_ctime = statbuf.st_ctime;
+          }
+        }
+
+        FREE_C_HEAP_ARRAY(char, filename);
+      }
+    }
+    os::closedir(subdirp);
+    FREE_C_HEAP_ARRAY(char, udbuf);
+    FREE_C_HEAP_ARRAY(char, usrdir_name);
+  }
+  os::closedir(tmpdirp);
+  FREE_C_HEAP_ARRAY(char, tdbuf);
+
+  return(oldest_user);
+}
+
+// return the name of the user that owns the JVM indicated by the given vmid.
+//
+static char* get_user_name(int vmid, TRAPS) {
+  return get_user_name_slow(vmid, CHECK_NULL);
+}
+
+// return the file name of the backing store file for the named
+// shared memory region for the given user name and vmid.
+//
+// the caller is expected to free the allocated memory.
+//
+static char* get_sharedmem_filename(const char* dirname, int vmid) {
+
+  // add 2 for the file separator and a null terminator.
+  size_t nbytes = strlen(dirname) + UINT_CHARS + 2;
+
+  char* name = NEW_C_HEAP_ARRAY(char, nbytes);
+  snprintf(name, nbytes, "%s/%d", dirname, vmid);
+
+  return name;
+}
+
+
+// remove file
+//
+// this method removes the file specified by the given path
+//
+static void remove_file(const char* path) {
+
+  int result;
+
+  // if the file is a directory, the following unlink will fail. since
+  // we don't expect to find directories in the user temp directory, we
+  // won't try to handle this situation. even if accidentially or
+  // maliciously planted, the directory's presence won't hurt anything.
+  //
+  RESTARTABLE(::unlink(path), result);
+  if (PrintMiscellaneous && Verbose && result == OS_ERR) {
+    if (errno != ENOENT) {
+      warning("Could not unlink shared memory backing"
+              " store file %s : %s\n", path, strerror(errno));
+    }
+  }
+}
+
+
+// remove file
+//
+// this method removes the file with the given file name in the
+// named directory.
+//
+static void remove_file(const char* dirname, const char* filename) {
+
+  size_t nbytes = strlen(dirname) + strlen(filename) + 2;
+  char* path = NEW_C_HEAP_ARRAY(char, nbytes);
+
+  strcpy(path, dirname);
+  strcat(path, "/");
+  strcat(path, filename);
+
+  remove_file(path);
+
+  FREE_C_HEAP_ARRAY(char, path);
+}
+
+
+// cleanup stale shared memory resources
+//
+// This method attempts to remove all stale shared memory files in
+// the named user temporary directory. It scans the named directory
+// for files matching the pattern ^$[0-9]*$. For each file found, the
+// process id is extracted from the file name and a test is run to
+// determine if the process is alive. If the process is not alive,
+// any stale file resources are removed.
+//
+static void cleanup_sharedmem_resources(const char* dirname) {
+
+  // open the user temp directory
+  DIR* dirp = os::opendir(dirname);
+
+  if (dirp == NULL) {
+    // directory doesn't exist, so there is nothing to cleanup
+    return;
+  }
+
+  if (!is_directory_secure(dirname)) {
+    // the directory is not a secure directory
+    return;
+  }
+
+  // for each entry in the directory that matches the expected file
+  // name pattern, determine if the file resources are stale and if
+  // so, remove the file resources. Note, instrumented HotSpot processes
+  // for this user may start and/or terminate during this search and
+  // remove or create new files in this directory. The behavior of this
+  // loop under these conditions is dependent upon the implementation of
+  // opendir/readdir.
+  //
+  struct dirent* entry;
+  char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname));
+  errno = 0;
+  while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
+
+    pid_t pid = filename_to_pid(entry->d_name);
+
+    if (pid == 0) {
+
+      if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
+
+        // attempt to remove all unexpected files, except "." and ".."
+        remove_file(dirname, entry->d_name);
+      }
+
+      errno = 0;
+      continue;
+    }
+
+    // we now have a file name that converts to a valid integer
+    // that could represent a process id . if this process id
+    // matches the current process id or the process is not running,
+    // then remove the stale file resources.
+    //
+    // process liveness is detected by sending signal number 0 to
+    // the process id (see kill(2)). if kill determines that the
+    // process does not exist, then the file resources are removed.
+    // if kill determines that that we don't have permission to
+    // signal the process, then the file resources are assumed to
+    // be stale and are removed because the resources for such a
+    // process should be in a different user specific directory.
+    //
+    if ((pid == os::current_process_id()) ||
+        (kill(pid, 0) == OS_ERR && (errno == ESRCH || errno == EPERM))) {
+
+        remove_file(dirname, entry->d_name);
+    }
+    errno = 0;
+  }
+  os::closedir(dirp);
+  FREE_C_HEAP_ARRAY(char, dbuf);
+}
+
+// make the user specific temporary directory. Returns true if
+// the directory exists and is secure upon return. Returns false
+// if the directory exists but is either a symlink, is otherwise
+// insecure, or if an error occurred.
+//
+static bool make_user_tmp_dir(const char* dirname) {
+
+  // create the directory with 0755 permissions. note that the directory
+  // will be owned by euid::egid, which may not be the same as uid::gid.
+  //
+  if (mkdir(dirname, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) == OS_ERR) {
+    if (errno == EEXIST) {
+      // The directory already exists and was probably created by another
+      // JVM instance. However, this could also be the result of a
+      // deliberate symlink. Verify that the existing directory is safe.
+      //
+      if (!is_directory_secure(dirname)) {
+        // directory is not secure
+        if (PrintMiscellaneous && Verbose) {
+          warning("%s directory is insecure\n", dirname);
+        }
+        return false;
+      }
+    }
+    else {
+      // we encountered some other failure while attempting
+      // to create the directory
+      //
+      if (PrintMiscellaneous && Verbose) {
+        warning("could not create directory %s: %s\n",
+                dirname, strerror(errno));
+      }
+      return false;
+    }
+  }
+  return true;
+}
+
+// create the shared memory file resources
+//
+// This method creates the shared memory file with the given size
+// This method also creates the user specific temporary directory, if
+// it does not yet exist.
+//
+static int create_sharedmem_resources(const char* dirname, const char* filename, size_t size) {
+
+  // make the user temporary directory
+  if (!make_user_tmp_dir(dirname)) {
+    // could not make/find the directory or the found directory
+    // was not secure
+    return -1;
+  }
+
+  int result;
+
+  RESTARTABLE(::open(filename, O_RDWR|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE), result);
+  if (result == OS_ERR) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("could not create file %s: %s\n", filename, strerror(errno));
+    }
+    return -1;
+  }
+
+  // save the file descriptor
+  int fd = result;
+
+  // set the file size
+  RESTARTABLE(::ftruncate(fd, (off_t)size), result);
+  if (result == OS_ERR) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("could not set shared memory file size: %s\n", strerror(errno));
+    }
+    RESTARTABLE(::close(fd), result);
+    return -1;
+  }
+
+  // Verify that we have enough disk space for this file.
+  // We'll get random SIGBUS crashes on memory accesses if
+  // we don't.
+
+  for (size_t seekpos = 0; seekpos < size; seekpos += os::vm_page_size()) {
+    int zero_int = 0;
+    result = (int)os::seek_to_file_offset(fd, (jlong)(seekpos));
+    if (result == -1 ) break;
+    RESTARTABLE(::write(fd, &zero_int, 1), result);
+    if (result != 1) {
+      if (errno == ENOSPC) {
+        warning("Insufficient space for shared memory file:\n   %s\nTry using the -Djava.io.tmpdir= option to select an alternate temp location.\n", filename);
+      }
+      break;
+    }
+  }
+
+  if (result != -1) {
+    return fd;
+  } else {
+    RESTARTABLE(::close(fd), result);
+    return -1;
+  }
+}
+
+// open the shared memory file for the given user and vmid. returns
+// the file descriptor for the open file or -1 if the file could not
+// be opened.
+//
+static int open_sharedmem_file(const char* filename, int oflags, TRAPS) {
+
+  // open the file
+  int result;
+  RESTARTABLE(::open(filename, oflags), result);
+  if (result == OS_ERR) {
+    if (errno == ENOENT) {
+      THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
+                  "Process not found");
+    }
+    else if (errno == EACCES) {
+      THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
+                  "Permission denied");
+    }
+    else {
+      THROW_MSG_0(vmSymbols::java_io_IOException(), strerror(errno));
+    }
+  }
+
+  return result;
+}
+
+// create a named shared memory region. returns the address of the
+// memory region on success or NULL on failure. A return value of
+// NULL will ultimately disable the shared memory feature.
+//
+// On Solaris and Bsd, the name space for shared memory objects
+// is the file system name space.
+//
+// A monitoring application attaching to a JVM does not need to know
+// the file system name of the shared memory object. However, it may
+// be convenient for applications to discover the existence of newly
+// created and terminating JVMs by watching the file system name space
+// for files being created or removed.
+//
+static char* mmap_create_shared(size_t size) {
+
+  int result;
+  int fd;
+  char* mapAddress;
+
+  int vmid = os::current_process_id();
+
+  char* user_name = get_user_name(geteuid());
+
+  if (user_name == NULL)
+    return NULL;
+
+  char* dirname = get_user_tmp_dir(user_name);
+  char* filename = get_sharedmem_filename(dirname, vmid);
+
+  // cleanup any stale shared memory files
+  cleanup_sharedmem_resources(dirname);
+
+  assert(((size > 0) && (size % os::vm_page_size() == 0)),
+         "unexpected PerfMemory region size");
+
+  fd = create_sharedmem_resources(dirname, filename, size);
+
+  FREE_C_HEAP_ARRAY(char, user_name);
+  FREE_C_HEAP_ARRAY(char, dirname);
+
+  if (fd == -1) {
+    FREE_C_HEAP_ARRAY(char, filename);
+    return NULL;
+  }
+
+  mapAddress = (char*)::mmap((char*)0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+
+  // attempt to close the file - restart it if it was interrupted,
+  // but ignore other failures
+  RESTARTABLE(::close(fd), result);
+  assert(result != OS_ERR, "could not close file");
+
+  if (mapAddress == MAP_FAILED) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("mmap failed -  %s\n", strerror(errno));
+    }
+    remove_file(filename);
+    FREE_C_HEAP_ARRAY(char, filename);
+    return NULL;
+  }
+
+  // save the file name for use in delete_shared_memory()
+  backing_store_file_name = filename;
+
+  // clear the shared memory region
+  (void)::memset((void*) mapAddress, 0, size);
+
+  return mapAddress;
+}
+
+// release a named shared memory region
+//
+static void unmap_shared(char* addr, size_t bytes) {
+  os::release_memory(addr, bytes);
+}
+
+// create the PerfData memory region in shared memory.
+//
+static char* create_shared_memory(size_t size) {
+
+  // create the shared memory region.
+  return mmap_create_shared(size);
+}
+
+// delete the shared PerfData memory region
+//
+static void delete_shared_memory(char* addr, size_t size) {
+
+  // cleanup the persistent shared memory resources. since DestroyJavaVM does
+  // not support unloading of the JVM, unmapping of the memory resource is
+  // not performed. The memory will be reclaimed by the OS upon termination of
+  // the process. The backing store file is deleted from the file system.
+
+  assert(!PerfDisableSharedMem, "shouldn't be here");
+
+  if (backing_store_file_name != NULL) {
+    remove_file(backing_store_file_name);
+    // Don't.. Free heap memory could deadlock os::abort() if it is called
+    // from signal handler. OS will reclaim the heap memory.
+    // FREE_C_HEAP_ARRAY(char, backing_store_file_name);
+    backing_store_file_name = NULL;
+  }
+}
+
+// return the size of the file for the given file descriptor
+// or 0 if it is not a valid size for a shared memory file
+//
+static size_t sharedmem_filesize(int fd, TRAPS) {
+
+  struct stat statbuf;
+  int result;
+
+  RESTARTABLE(::fstat(fd, &statbuf), result);
+  if (result == OS_ERR) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("fstat failed: %s\n", strerror(errno));
+    }
+    THROW_MSG_0(vmSymbols::java_io_IOException(),
+                "Could not determine PerfMemory size");
+  }
+
+  if ((statbuf.st_size == 0) ||
+     ((size_t)statbuf.st_size % os::vm_page_size() != 0)) {
+    THROW_MSG_0(vmSymbols::java_lang_Exception(),
+                "Invalid PerfMemory size");
+  }
+
+  return (size_t)statbuf.st_size;
+}
+
+// attach to a named shared memory region.
+//
+static void mmap_attach_shared(const char* user, int vmid, PerfMemory::PerfMemoryMode mode, char** addr, size_t* sizep, TRAPS) {
+
+  char* mapAddress;
+  int result;
+  int fd;
+  size_t size;
+  const char* luser = NULL;
+
+  int mmap_prot;
+  int file_flags;
+
+  ResourceMark rm;
+
+  // map the high level access mode to the appropriate permission
+  // constructs for the file and the shared memory mapping.
+  if (mode == PerfMemory::PERF_MODE_RO) {
+    mmap_prot = PROT_READ;
+    file_flags = O_RDONLY;
+  }
+  else if (mode == PerfMemory::PERF_MODE_RW) {
+#ifdef LATER
+    mmap_prot = PROT_READ | PROT_WRITE;
+    file_flags = O_RDWR;
+#else
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Unsupported access mode");
+#endif
+  }
+  else {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Illegal access mode");
+  }
+
+  if (user == NULL || strlen(user) == 0) {
+    luser = get_user_name(vmid, CHECK);
+  }
+  else {
+    luser = user;
+  }
+
+  if (luser == NULL) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Could not map vmid to user Name");
+  }
+
+  char* dirname = get_user_tmp_dir(luser);
+
+  // since we don't follow symbolic links when creating the backing
+  // store file, we don't follow them when attaching either.
+  //
+  if (!is_directory_secure(dirname)) {
+    FREE_C_HEAP_ARRAY(char, dirname);
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Process not found");
+  }
+
+  char* filename = get_sharedmem_filename(dirname, vmid);
+
+  // copy heap memory to resource memory. the open_sharedmem_file
+  // method below need to use the filename, but could throw an
+  // exception. using a resource array prevents the leak that
+  // would otherwise occur.
+  char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
+  strcpy(rfilename, filename);
+
+  // free the c heap resources that are no longer needed
+  if (luser != user) FREE_C_HEAP_ARRAY(char, luser);
+  FREE_C_HEAP_ARRAY(char, dirname);
+  FREE_C_HEAP_ARRAY(char, filename);
+
+  // open the shared memory file for the give vmid
+  fd = open_sharedmem_file(rfilename, file_flags, CHECK);
+  assert(fd != OS_ERR, "unexpected value");
+
+  if (*sizep == 0) {
+    size = sharedmem_filesize(fd, CHECK);
+    assert(size != 0, "unexpected size");
+  }
+
+  mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
+
+  // attempt to close the file - restart if it gets interrupted,
+  // but ignore other failures
+  RESTARTABLE(::close(fd), result);
+  assert(result != OS_ERR, "could not close file");
+
+  if (mapAddress == MAP_FAILED) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("mmap failed: %s\n", strerror(errno));
+    }
+    THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
+              "Could not map PerfMemory");
+  }
+
+  *addr = mapAddress;
+  *sizep = size;
+
+  if (PerfTraceMemOps) {
+    tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
+               INTPTR_FORMAT "\n", size, vmid, (void*)mapAddress);
+  }
+}
+
+
+
+
+// create the PerfData memory region
+//
+// This method creates the memory region used to store performance
+// data for the JVM. The memory may be created in standard or
+// shared memory.
+//
+void PerfMemory::create_memory_region(size_t size) {
+
+  if (PerfDisableSharedMem) {
+    // do not share the memory for the performance data.
+    _start = create_standard_memory(size);
+  }
+  else {
+    _start = create_shared_memory(size);
+    if (_start == NULL) {
+
+      // creation of the shared memory region failed, attempt
+      // to create a contiguous, non-shared memory region instead.
+      //
+      if (PrintMiscellaneous && Verbose) {
+        warning("Reverting to non-shared PerfMemory region.\n");
+      }
+      PerfDisableSharedMem = true;
+      _start = create_standard_memory(size);
+    }
+  }
+
+  if (_start != NULL) _capacity = size;
+
+}
+
+// delete the PerfData memory region
+//
+// This method deletes the memory region used to store performance
+// data for the JVM. The memory region indicated by the <address, size>
+// tuple will be inaccessible after a call to this method.
+//
+void PerfMemory::delete_memory_region() {
+
+  assert((start() != NULL && capacity() > 0), "verify proper state");
+
+  // If user specifies PerfDataSaveFile, it will save the performance data
+  // to the specified file name no matter whether PerfDataSaveToFile is specified
+  // or not. In other word, -XX:PerfDataSaveFile=.. overrides flag
+  // -XX:+PerfDataSaveToFile.
+  if (PerfDataSaveToFile || PerfDataSaveFile != NULL) {
+    save_memory_to_file(start(), capacity());
+  }
+
+  if (PerfDisableSharedMem) {
+    delete_standard_memory(start(), capacity());
+  }
+  else {
+    delete_shared_memory(start(), capacity());
+  }
+}
+
+// attach to the PerfData memory region for another JVM
+//
+// This method returns an <address, size> tuple that points to
+// a memory buffer that is kept reasonably synchronized with
+// the PerfData memory region for the indicated JVM. This
+// buffer may be kept in synchronization via shared memory
+// or some other mechanism that keeps the buffer updated.
+//
+// If the JVM chooses not to support the attachability feature,
+// this method should throw an UnsupportedOperation exception.
+//
+// This implementation utilizes named shared memory to map
+// the indicated process's PerfData memory region into this JVMs
+// address space.
+//
+void PerfMemory::attach(const char* user, int vmid, PerfMemoryMode mode, char** addrp, size_t* sizep, TRAPS) {
+
+  if (vmid == 0 || vmid == os::current_process_id()) {
+     *addrp = start();
+     *sizep = capacity();
+     return;
+  }
+
+  mmap_attach_shared(user, vmid, mode, addrp, sizep, CHECK);
+}
+
+// detach from the PerfData memory region of another JVM
+//
+// This method detaches the PerfData memory region of another
+// JVM, specified as an <address, size> tuple of a buffer
+// in this process's address space. This method may perform
+// arbitrary actions to accomplish the detachment. The memory
+// region specified by <address, size> will be inaccessible after
+// a call to this method.
+//
+// If the JVM chooses not to support the attachability feature,
+// this method should throw an UnsupportedOperation exception.
+//
+// This implementation utilizes named shared memory to detach
+// the indicated process's PerfData memory region from this
+// process's address space.
+//
+void PerfMemory::detach(char* addr, size_t bytes, TRAPS) {
+
+  assert(addr != 0, "address sanity check");
+  assert(bytes > 0, "capacity sanity check");
+
+  if (PerfMemory::contains(addr) || PerfMemory::contains(addr + bytes - 1)) {
+    // prevent accidental detachment of this process's PerfMemory region
+    return;
+  }
+
+  unmap_shared(addr, bytes);
+}
+
+char* PerfMemory::backing_store_filename() {
+  return backing_store_file_name;
+}
diff --git a/hotspot/src/os/bsd/vm/stubRoutines_bsd.cpp b/hotspot/src/os/bsd/vm/stubRoutines_bsd.cpp
new file mode 100644
index 0000000..1fa7d3a
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/stubRoutines_bsd.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/os.hpp"
+#include "runtime/stubRoutines.hpp"
diff --git a/hotspot/src/os/bsd/vm/threadCritical_bsd.cpp b/hotspot/src/os/bsd/vm/threadCritical_bsd.cpp
new file mode 100644
index 0000000..e337a5b
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/threadCritical_bsd.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/threadCritical.hpp"
+#include "thread_bsd.inline.hpp"
+
+// put OS-includes here
+# include <pthread.h>
+
+//
+// See threadCritical.hpp for details of this class.
+//
+
+static pthread_t             tc_owner = 0;
+static pthread_mutex_t       tc_mutex = PTHREAD_MUTEX_INITIALIZER;
+static int                   tc_count = 0;
+
+void ThreadCritical::initialize() {
+}
+
+void ThreadCritical::release() {
+}
+
+ThreadCritical::ThreadCritical() {
+  pthread_t self = pthread_self();
+  if (self != tc_owner) {
+    int ret = pthread_mutex_lock(&tc_mutex);
+    guarantee(ret == 0, "fatal error with pthread_mutex_lock()");
+    assert(tc_count == 0, "Lock acquired with illegal reentry count.");
+    tc_owner = self;
+  }
+  tc_count++;
+}
+
+ThreadCritical::~ThreadCritical() {
+  assert(tc_owner == pthread_self(), "must have correct owner");
+  assert(tc_count > 0, "must have correct count");
+
+  tc_count--;
+  if (tc_count == 0) {
+    tc_owner = 0;
+    int ret = pthread_mutex_unlock(&tc_mutex);
+    guarantee(ret == 0, "fatal error with pthread_mutex_unlock()");
+  }
+}
diff --git a/hotspot/src/os/bsd/vm/thread_bsd.inline.hpp b/hotspot/src/os/bsd/vm/thread_bsd.inline.hpp
new file mode 100644
index 0000000..290f477
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/thread_bsd.inline.hpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_BSD_VM_THREAD_BSD_INLINE_HPP
+#define OS_BSD_VM_THREAD_BSD_INLINE_HPP
+
+#include "runtime/atomic.hpp"
+#include "runtime/prefetch.hpp"
+#include "runtime/thread.hpp"
+#include "runtime/threadLocalStorage.hpp"
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "atomic_bsd_x86.inline.hpp"
+# include "orderAccess_bsd_x86.inline.hpp"
+# include "prefetch_bsd_x86.inline.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "atomic_bsd_zero.inline.hpp"
+# include "orderAccess_bsd_zero.inline.hpp"
+# include "prefetch_bsd_zero.inline.hpp"
+#endif
+
+// Contains inlined functions for class Thread and ThreadLocalStorage
+
+inline void ThreadLocalStorage::pd_invalidate_all() {} // nothing to do
+
+#endif // OS_BSD_VM_THREAD_BSD_INLINE_HPP
diff --git a/hotspot/src/os/bsd/vm/vmError_bsd.cpp b/hotspot/src/os/bsd/vm/vmError_bsd.cpp
new file mode 100644
index 0000000..8ec6ca0
--- /dev/null
+++ b/hotspot/src/os/bsd/vm/vmError_bsd.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/arguments.hpp"
+#include "runtime/os.hpp"
+#include "runtime/thread.hpp"
+#include "utilities/vmError.hpp"
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <signal.h>
+
+void VMError::show_message_box(char *buf, int buflen) {
+  bool yes;
+  do {
+    error_string(buf, buflen);
+    int len = (int)strlen(buf);
+    char *p = &buf[len];
+
+    jio_snprintf(p, buflen - len,
+               "\n\n"
+               "Do you want to debug the problem?\n\n"
+               "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"
+               "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
+               "Otherwise, press RETURN to abort...",
+               os::current_process_id(), os::current_process_id(),
+               os::current_thread_id(), os::current_thread_id());
+
+    yes = os::message_box("Unexpected Error", buf);
+
+    if (yes) {
+      // yes, user asked VM to launch debugger
+      jio_snprintf(buf, buflen, "gdb /proc/%d/exe %d",
+                   os::current_process_id(), os::current_process_id());
+
+      os::fork_and_exec(buf);
+      yes = false;
+    }
+  } while (yes);
+}
+
+// Space for our "saved" signal flags and handlers
+static int resettedSigflags[2];
+static address resettedSighandler[2];
+
+static void save_signal(int idx, int sig)
+{
+  struct sigaction sa;
+  sigaction(sig, NULL, &sa);
+  resettedSigflags[idx]   = sa.sa_flags;
+  resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
+                              ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
+                              : CAST_FROM_FN_PTR(address, sa.sa_handler);
+}
+
+int VMError::get_resetted_sigflags(int sig) {
+  if(SIGSEGV == sig) {
+    return resettedSigflags[0];
+  } else if(SIGBUS == sig) {
+    return resettedSigflags[1];
+  }
+  return -1;
+}
+
+address VMError::get_resetted_sighandler(int sig) {
+  if(SIGSEGV == sig) {
+    return resettedSighandler[0];
+  } else if(SIGBUS == sig) {
+    return resettedSighandler[1];
+  }
+  return NULL;
+}
+
+static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
+  // unmask current signal
+  sigset_t newset;
+  sigemptyset(&newset);
+  sigaddset(&newset, sig);
+  sigprocmask(SIG_UNBLOCK, &newset, NULL);
+
+  VMError err(NULL, sig, NULL, info, ucVoid);
+  err.report_and_die();
+}
+
+void VMError::reset_signal_handlers() {
+  // Save sigflags for resetted signals
+  save_signal(0, SIGSEGV);
+  save_signal(1, SIGBUS);
+  os::signal(SIGSEGV, CAST_FROM_FN_PTR(void *, crash_handler));
+  os::signal(SIGBUS, CAST_FROM_FN_PTR(void *, crash_handler));
+}
diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp
index f1e6f15..3bf1039 100644
--- a/hotspot/src/os/linux/vm/os_linux.cpp
+++ b/hotspot/src/os/linux/vm/os_linux.cpp
@@ -22,8 +22,6 @@
  *
  */
 
-# define __STDC_FORMAT_MACROS
-
 // no precompiled headers
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -3895,14 +3893,19 @@
     }
 
     // We don't activate signal checker if libjsig is in place, we trust ourselves
-    // and if UserSignalHandler is installed all bets are off
+    // and if UserSignalHandler is installed all bets are off.
+    // Log that signal checking is off only if -verbose:jni is specified.
     if (CheckJNICalls) {
       if (libjsig_is_loaded) {
-        tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
+        if (PrintJNIResolving) {
+          tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
+        }
         check_signals = false;
       }
       if (AllowUserSignalHandlers) {
-        tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
+        if (PrintJNIResolving) {
+          tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
+        }
         check_signals = false;
       }
     }
@@ -4354,6 +4357,11 @@
   return online_cpus;
 }
 
+void os::set_native_thread_name(const char *name) {
+  // Not yet implemented.
+  return;
+}
+
 bool os::distribute_processes(uint length, uint* distribution) {
   // Not yet implemented.
   return false;
diff --git a/hotspot/src/os/posix/launcher/java_md.c b/hotspot/src/os/posix/launcher/java_md.c
index 3ee0f20..63cee98 100644
--- a/hotspot/src/os/posix/launcher/java_md.c
+++ b/hotspot/src/os/posix/launcher/java_md.c
@@ -41,14 +41,21 @@
 #include "version_comp.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <pthread.h>
 #else
 #include <thread.h>
 #endif
 
+#ifdef __APPLE__
+#define JVM_DLL "libjvm.dylib"
+#define JAVA_DLL "libjava.dylib"
+#define LD_LIBRARY_PATH "DYLD_LIBRARY_PATH"
+#else
 #define JVM_DLL "libjvm.so"
 #define JAVA_DLL "libjava.so"
+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
+#endif
 
 #ifndef GAMMA   /* launcher.make defines ARCH */
 /*
@@ -423,10 +430,10 @@
        * If not on Solaris, assume only a single LD_LIBRARY_PATH
        * variable.
        */
-      runpath = getenv("LD_LIBRARY_PATH");
+      runpath = getenv(LD_LIBRARY_PATH);
 #endif /* __sun */
 
-#ifdef __linux
+#if defined(__linux__)
       /*
        * On linux, if a binary is running as sgid or suid, glibc sets
        * LD_LIBRARY_PATH to the empty string for security purposes.  (In
@@ -442,6 +449,22 @@
       if((getgid() != getegid()) || (getuid() != geteuid()) ) {
         return;
       }
+#elif defined(_ALLBSD_SOURCE)
+      /*
+       * On BSD, if a binary is running as sgid or suid, libc sets
+       * LD_LIBRARY_PATH to the empty string for security purposes.  (In
+       * contrast, on Solaris the LD_LIBRARY_PATH variable for a
+       * privileged binary does not lose its settings; but the dynamic
+       * linker does apply more scrutiny to the path.) The launcher uses
+       * the value of LD_LIBRARY_PATH to prevent an exec loop.
+       * Therefore, if we are running sgid or suid, this function's
+       * setting of LD_LIBRARY_PATH will be ineffective and we should
+       * return from the function now.  Getting the right libraries to
+       * be found must be handled through other mechanisms.
+       */
+      if(issetugid()) {
+        return;
+      }
 #endif
 
       /* runpath contains current effective LD_LIBRARY_PATH setting */
@@ -450,7 +473,7 @@
       new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) +
                               2*strlen(jrepath) + 2*strlen(arch) +
                               strlen(jvmpath) + 52);
-      newpath = new_runpath + strlen("LD_LIBRARY_PATH=");
+      newpath = new_runpath + strlen(LD_LIBRARY_PATH "=");
 
 
       /*
@@ -465,7 +488,7 @@
 
         /* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */
 
-        sprintf(new_runpath, "LD_LIBRARY_PATH="
+        sprintf(new_runpath, LD_LIBRARY_PATH "="
                 "%s:"
                 "%s/lib/%s:"
                 "%s/../lib/%s",
@@ -792,7 +815,7 @@
 jboolean
 GetApplicationHome(char *buf, jint bufsize)
 {
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     char *execname = GetExecname();
     if (execname) {
         strncpy(buf, execname, bufsize-1);
@@ -1175,7 +1198,7 @@
 
 #endif /* __sun && i586 */
 
-#if defined(__linux__) && defined(i586)
+#if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(i586)
 
 /*
  * A utility method for asking the CPU about itself.
@@ -1452,6 +1475,39 @@
 
 #endif /* __linux__ && i586 */
 
+#if defined(_ALLBSD_SOURCE) && defined(i586)
+
+/* The definition of a server-class machine for bsd-i586 */
+jboolean
+bsd_i586_ServerClassMachine(void) {
+  jboolean            result            = JNI_FALSE;
+  /* How big is a server class machine? */
+  const unsigned long server_processors = 2UL;
+  const uint64_t      server_memory     = 2UL * GB;
+  /*
+   * We seem not to get our full complement of memory.
+   *     We allow some part (1/8?) of the memory to be "missing",
+   *     based on the sizes of DIMMs, and maybe graphics cards.
+   */
+  const uint64_t      missing_memory    = 256UL * MB;
+  const uint64_t      actual_memory     = physical_memory();
+
+  /* Is this a server class machine? */
+  if (actual_memory >= (server_memory - missing_memory)) {
+    const unsigned long actual_processors = physical_processors();
+    if (actual_processors >= server_processors) {
+      result = JNI_TRUE;
+    }
+  }
+  if (_launcher_debug) {
+    printf("linux_" LIBARCHNAME "_ServerClassMachine: %s\n",
+           (result == JNI_TRUE ? "true" : "false"));
+  }
+  return result;
+}
+
+#endif /* _ALLBSD_SOURCE && i586 */
+
 /* Dispatch to the platform-specific definition of "server-class" */
 jboolean
 ServerClassMachine(void) {
@@ -1466,6 +1522,8 @@
   result = solaris_i586_ServerClassMachine();
 #elif defined(__linux__) && defined(i586)
   result = linux_i586_ServerClassMachine();
+#elif defined(_ALLBSD_SOURCE) && defined(i586)
+  result = bsd_i586_ServerClassMachine();
 #else
   if (_launcher_debug) {
     printf("ServerClassMachine: returns default value of %s\n",
@@ -1821,7 +1879,7 @@
 int
 ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
     int rslt;
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     pthread_t tid;
     pthread_attr_t attr;
     pthread_attr_init(&attr);
diff --git a/hotspot/src/os/posix/launcher/launcher.script b/hotspot/src/os/posix/launcher/launcher.script
index 22ed66b..c4db5a4 100644
--- a/hotspot/src/os/posix/launcher/launcher.script
+++ b/hotspot/src/os/posix/launcher/launcher.script
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/bin/sh
 
-# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -69,8 +69,8 @@
 #
 
 # Make sure the paths are fully specified, i.e. they must begin with /.
-SCRIPT=$(cd $(dirname $0) && pwd)/$(basename $0)
-RUNDIR=$(pwd)
+REL_MYDIR=`dirname $0`
+MYDIR=`cd $REL_MYDIR && pwd`
 
 # Look whether the user wants to run inside gdb
 case "$1" in
@@ -95,12 +95,9 @@
         ;;
 esac
 
-# Find out the absolute path to this script
-MYDIR=$(cd $(dirname $SCRIPT) && pwd)
-
 JDK=
 if [ "${ALT_JAVA_HOME}" = "" ]; then
-    source ${MYDIR}/jdkpath.sh
+    . ${MYDIR}/jdkpath.sh
 else 
     JDK=${ALT_JAVA_HOME%%/jre};
 fi
@@ -119,9 +116,6 @@
 JAVA_HOME=$JDK
 ARCH=@@LIBARCH@@
 
-# Find out the absolute path to this script
-MYDIR=$(cd $(dirname $SCRIPT) && pwd)
-
 SBP=${MYDIR}:${JRE}/lib/${ARCH}
 
 # Set up a suitable LD_LIBRARY_PATH
@@ -146,7 +140,7 @@
 fi
 
 GDBSRCDIR=$MYDIR
-BASEDIR=$(cd $MYDIR/../../.. && pwd)
+BASEDIR=`cd $MYDIR/../../.. && pwd`
 
 init_gdb() {
 # Create a gdb script in case we should run inside gdb
@@ -179,7 +173,7 @@
 	init_gdb
 # First find out what emacs version we're using, so that we can
 # use the new pretty GDB mode if emacs -version >= 22.1
-	case $($EMACS -version 2> /dev/null) in
+	case `$EMACS -version 2> /dev/null` in
 	    *GNU\ Emacs\ 2[23]*)
 	    emacs_gud_cmd="gdba"
 	    emacs_gud_args="--annotate=3"
diff --git a/hotspot/src/os/solaris/vm/os_solaris.cpp b/hotspot/src/os/solaris/vm/os_solaris.cpp
index ad02278..92664d6 100644
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp
@@ -669,6 +669,11 @@
   return true;
 }
 
+void os::set_native_thread_name(const char *name) {
+  // Not yet implemented.
+  return;
+}
+
 bool os::distribute_processes(uint length, uint* distribution) {
   bool result = false;
   // Find the processor id's of all the available CPUs.
@@ -4592,14 +4597,19 @@
   }
 
   // We don't activate signal checker if libjsig is in place, we trust ourselves
-  // and if UserSignalHandler is installed all bets are off
+  // and if UserSignalHandler is installed all bets are off.
+  // Log that signal checking is off only if -verbose:jni is specified.
   if (CheckJNICalls) {
     if (libjsig_is_loaded) {
-      tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
+      if (PrintJNIResolving) {
+        tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
+      }
       check_signals = false;
     }
     if (AllowUserSignalHandlers) {
-      tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
+      if (PrintJNIResolving) {
+        tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
+      }
       check_signals = false;
     }
   }
diff --git a/hotspot/src/os/windows/vm/os_windows.cpp b/hotspot/src/os/windows/vm/os_windows.cpp
index 9de05fa..e80ffb5 100644
--- a/hotspot/src/os/windows/vm/os_windows.cpp
+++ b/hotspot/src/os/windows/vm/os_windows.cpp
@@ -710,6 +710,11 @@
   }
 }
 
+void os::set_native_thread_name(const char *name) {
+  // Not yet implemented.
+  return;
+}
+
 bool os::distribute_processes(uint length, uint* distribution) {
   // Not yet implemented.
   return false;
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/assembler_bsd_x86.cpp b/hotspot/src/os_cpu/bsd_x86/vm/assembler_bsd_x86.cpp
new file mode 100644
index 0000000..5cd9410
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/assembler_bsd_x86.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "asm/assembler.hpp"
+#include "assembler_x86.inline.hpp"
+#include "runtime/os.hpp"
+#include "runtime/threadLocalStorage.hpp"
+
+#ifndef _LP64
+void MacroAssembler::int3() {
+  call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
+}
+
+void MacroAssembler::get_thread(Register thread) {
+  movl(thread, rsp);
+  shrl(thread, PAGE_SHIFT);
+
+  ExternalAddress tls_base((address)ThreadLocalStorage::sp_map_addr());
+  Address index(noreg, thread, Address::times_4);
+  ArrayAddress tls(tls_base, index);
+
+  movptr(thread, tls);
+}
+#else
+void MacroAssembler::int3() {
+  call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
+}
+
+void MacroAssembler::get_thread(Register thread) {
+  // call pthread_getspecific
+  // void * pthread_getspecific(pthread_key_t key);
+   if (thread != rax) {
+     push(rax);
+   }
+   push(rdi);
+   push(rsi);
+   push(rdx);
+   push(rcx);
+   push(r8);
+   push(r9);
+   push(r10);
+   // XXX
+   mov(r10, rsp);
+   andq(rsp, -16);
+   push(r10);
+   push(r11);
+
+   movl(rdi, ThreadLocalStorage::thread_index());
+   call(RuntimeAddress(CAST_FROM_FN_PTR(address, pthread_getspecific)));
+
+   pop(r11);
+   pop(rsp);
+   pop(r10);
+   pop(r9);
+   pop(r8);
+   pop(rcx);
+   pop(rdx);
+   pop(rsi);
+   pop(rdi);
+   if (thread != rax) {
+       mov(thread, rax);
+       pop(rax);
+   }
+}
+#endif
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.inline.hpp b/hotspot/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.inline.hpp
new file mode 100644
index 0000000..aa47196
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.inline.hpp
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_INLINE_HPP
+#define OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_INLINE_HPP
+
+#include "orderAccess_bsd_x86.inline.hpp"
+#include "runtime/atomic.hpp"
+#include "runtime/os.hpp"
+#include "vm_version_x86.hpp"
+
+// Implementation of class atomic
+
+inline void Atomic::store    (jbyte    store_value, jbyte*    dest) { *dest = store_value; }
+inline void Atomic::store    (jshort   store_value, jshort*   dest) { *dest = store_value; }
+inline void Atomic::store    (jint     store_value, jint*     dest) { *dest = store_value; }
+inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
+inline void Atomic::store_ptr(void*    store_value, void*     dest) { *(void**)dest = store_value; }
+
+inline void Atomic::store    (jbyte    store_value, volatile jbyte*    dest) { *dest = store_value; }
+inline void Atomic::store    (jshort   store_value, volatile jshort*   dest) { *dest = store_value; }
+inline void Atomic::store    (jint     store_value, volatile jint*     dest) { *dest = store_value; }
+inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
+inline void Atomic::store_ptr(void*    store_value, volatile void*     dest) { *(void* volatile *)dest = store_value; }
+
+
+// Adding a lock prefix to an instruction on MP machine
+#define LOCK_IF_MP(mp) "cmp $0, " #mp "; je 1f; lock; 1: "
+
+inline jint     Atomic::add    (jint     add_value, volatile jint*     dest) {
+  jint addend = add_value;
+  int mp = os::is_MP();
+  __asm__ volatile (  LOCK_IF_MP(%3) "xaddl %0,(%2)"
+                    : "=r" (addend)
+                    : "0" (addend), "r" (dest), "r" (mp)
+                    : "cc", "memory");
+  return addend + add_value;
+}
+
+inline void Atomic::inc    (volatile jint*     dest) {
+  int mp = os::is_MP();
+  __asm__ volatile (LOCK_IF_MP(%1) "addl $1,(%0)" :
+                    : "r" (dest), "r" (mp) : "cc", "memory");
+}
+
+inline void Atomic::inc_ptr(volatile void*     dest) {
+  inc_ptr((volatile intptr_t*)dest);
+}
+
+inline void Atomic::dec    (volatile jint*     dest) {
+  int mp = os::is_MP();
+  __asm__ volatile (LOCK_IF_MP(%1) "subl $1,(%0)" :
+                    : "r" (dest), "r" (mp) : "cc", "memory");
+}
+
+inline void Atomic::dec_ptr(volatile void*     dest) {
+  dec_ptr((volatile intptr_t*)dest);
+}
+
+inline jint     Atomic::xchg    (jint     exchange_value, volatile jint*     dest) {
+  __asm__ volatile (  "xchgl (%2),%0"
+                    : "=r" (exchange_value)
+                    : "0" (exchange_value), "r" (dest)
+                    : "memory");
+  return exchange_value;
+}
+
+inline void*    Atomic::xchg_ptr(void*    exchange_value, volatile void*     dest) {
+  return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
+}
+
+
+inline jint     Atomic::cmpxchg    (jint     exchange_value, volatile jint*     dest, jint     compare_value) {
+  int mp = os::is_MP();
+  __asm__ volatile (LOCK_IF_MP(%4) "cmpxchgl %1,(%3)"
+                    : "=a" (exchange_value)
+                    : "r" (exchange_value), "a" (compare_value), "r" (dest), "r" (mp)
+                    : "cc", "memory");
+  return exchange_value;
+}
+
+#ifdef AMD64
+inline void Atomic::store    (jlong    store_value, jlong*    dest) { *dest = store_value; }
+inline void Atomic::store    (jlong    store_value, volatile jlong*    dest) { *dest = store_value; }
+
+inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
+  intptr_t addend = add_value;
+  bool mp = os::is_MP();
+  __asm__ __volatile__ (LOCK_IF_MP(%3) "xaddq %0,(%2)"
+                        : "=r" (addend)
+                        : "0" (addend), "r" (dest), "r" (mp)
+                        : "cc", "memory");
+  return addend + add_value;
+}
+
+inline void*    Atomic::add_ptr(intptr_t add_value, volatile void*     dest) {
+  return (void*)add_ptr(add_value, (volatile intptr_t*)dest);
+}
+
+inline void Atomic::inc_ptr(volatile intptr_t* dest) {
+  bool mp = os::is_MP();
+  __asm__ __volatile__ (LOCK_IF_MP(%1) "addq $1,(%0)"
+                        :
+                        : "r" (dest), "r" (mp)
+                        : "cc", "memory");
+}
+
+inline void Atomic::dec_ptr(volatile intptr_t* dest) {
+  bool mp = os::is_MP();
+  __asm__ __volatile__ (LOCK_IF_MP(%1) "subq $1,(%0)"
+                        :
+                        : "r" (dest), "r" (mp)
+                        : "cc", "memory");
+}
+
+inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
+  __asm__ __volatile__ ("xchgq (%2),%0"
+                        : "=r" (exchange_value)
+                        : "0" (exchange_value), "r" (dest)
+                        : "memory");
+  return exchange_value;
+}
+
+inline jlong    Atomic::cmpxchg    (jlong    exchange_value, volatile jlong*    dest, jlong    compare_value) {
+  bool mp = os::is_MP();
+  __asm__ __volatile__ (LOCK_IF_MP(%4) "cmpxchgq %1,(%3)"
+                        : "=a" (exchange_value)
+                        : "r" (exchange_value), "a" (compare_value), "r" (dest), "r" (mp)
+                        : "cc", "memory");
+  return exchange_value;
+}
+
+inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
+  return (intptr_t)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
+}
+
+inline void*    Atomic::cmpxchg_ptr(void*    exchange_value, volatile void*     dest, void*    compare_value) {
+  return (void*)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
+}
+
+inline jlong Atomic::load(volatile jlong* src) { return *src; }
+
+#else // !AMD64
+
+inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
+  return (intptr_t)Atomic::add((jint)add_value, (volatile jint*)dest);
+}
+
+inline void*    Atomic::add_ptr(intptr_t add_value, volatile void*     dest) {
+  return (void*)Atomic::add((jint)add_value, (volatile jint*)dest);
+}
+
+
+inline void Atomic::inc_ptr(volatile intptr_t* dest) {
+  inc((volatile jint*)dest);
+}
+
+inline void Atomic::dec_ptr(volatile intptr_t* dest) {
+  dec((volatile jint*)dest);
+}
+
+inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
+  return (intptr_t)xchg((jint)exchange_value, (volatile jint*)dest);
+}
+
+extern "C" {
+  // defined in bsd_x86.s
+  jlong _Atomic_cmpxchg_long(jlong, volatile jlong*, jlong, bool);
+  void _Atomic_move_long(volatile jlong* src, volatile jlong* dst);
+}
+
+inline jlong    Atomic::cmpxchg    (jlong    exchange_value, volatile jlong*    dest, jlong    compare_value) {
+  return _Atomic_cmpxchg_long(exchange_value, dest, compare_value, os::is_MP());
+}
+
+inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
+  return (intptr_t)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
+}
+
+inline void*    Atomic::cmpxchg_ptr(void*    exchange_value, volatile void*     dest, void*    compare_value) {
+  return (void*)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
+}
+
+inline jlong Atomic::load(volatile jlong* src) {
+  volatile jlong dest;
+  _Atomic_move_long(src, &dest);
+  return dest;
+}
+
+inline void Atomic::store(jlong store_value, jlong* dest) {
+  _Atomic_move_long((volatile jlong*)&store_value, (volatile jlong*)dest);
+}
+
+inline void Atomic::store(jlong store_value, volatile jlong* dest) {
+  _Atomic_move_long((volatile jlong*)&store_value, dest);
+}
+
+#endif // AMD64
+
+#endif // OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.ad b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.ad
new file mode 100644
index 0000000..192a78f
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.ad
@@ -0,0 +1,160 @@
+//
+// Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+//
+// This code is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License version 2 only, as
+// published by the Free Software Foundation.
+//
+// This code is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// version 2 for more details (a copy is included in the LICENSE file that
+// accompanied this code).
+//
+// You should have received a copy of the GNU General Public License version
+// 2 along with this work; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+// or visit www.oracle.com if you need additional information or have any
+// questions.
+//
+//
+
+// X86 Bsd Architecture Description File
+
+//----------OS-DEPENDENT ENCODING BLOCK-----------------------------------------------------
+// This block specifies the encoding classes used by the compiler to output
+// byte streams.  Encoding classes generate functions which are called by
+// Machine Instruction Nodes in order to generate the bit encoding of the
+// instruction.  Operands specify their base encoding interface with the
+// interface keyword.  There are currently supported four interfaces,
+// REG_INTER, CONST_INTER, MEMORY_INTER, & COND_INTER.  REG_INTER causes an
+// operand to generate a function which returns its register number when
+// queried.   CONST_INTER causes an operand to generate a function which
+// returns the value of the constant when queried.  MEMORY_INTER causes an
+// operand to generate four functions which return the Base Register, the
+// Index Register, the Scale Value, and the Offset Value of the operand when
+// queried.  COND_INTER causes an operand to generate six functions which
+// return the encoding code (ie - encoding bits for the instruction)
+// associated with each basic boolean condition for a conditional instruction.
+// Instructions specify two basic values for encoding.  They use the
+// ins_encode keyword to specify their encoding class (which must be one of
+// the class names specified in the encoding block), and they use the
+// opcode keyword to specify, in order, their primary, secondary, and
+// tertiary opcode.  Only the opcode sections which a particular instruction
+// needs for encoding need to be specified.
+encode %{
+  // Build emit functions for each basic byte or larger field in the intel
+  // encoding scheme (opcode, rm, sib, immediate), and call them from C++
+  // code in the enc_class source block.  Emit functions will live in the
+  // main source block for now.  In future, we can generalize this by
+  // adding a syntax that specifies the sizes of fields in an order,
+  // so that the adlc can build the emit functions automagically
+
+  enc_class bsd_tlsencode (eRegP dst) %{
+    Register dstReg = as_Register($dst$$reg);
+    MacroAssembler* masm = new MacroAssembler(&cbuf);
+      masm->get_thread(dstReg);
+  %}
+
+  enc_class bsd_breakpoint  %{
+    MacroAssembler* masm = new MacroAssembler(&cbuf);
+    masm->call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
+  %}
+
+  enc_class call_epilog %{
+    if( VerifyStackAtCalls ) {
+      // Check that stack depth is unchanged: find majik cookie on stack
+      int framesize = ra_->reg2offset_unchecked(OptoReg::add(ra_->_matcher._old_SP,-3*VMRegImpl::slots_per_word));
+      if(framesize >= 128) {
+        emit_opcode(cbuf, 0x81); // cmp [esp+0],0xbadb1ood
+        emit_d8(cbuf,0xBC);
+        emit_d8(cbuf,0x24);
+        emit_d32(cbuf,framesize); // Find majik cookie from ESP
+        emit_d32(cbuf, 0xbadb100d);
+      }
+      else {
+        emit_opcode(cbuf, 0x81); // cmp [esp+0],0xbadb1ood
+        emit_d8(cbuf,0x7C);
+        emit_d8(cbuf,0x24);
+        emit_d8(cbuf,framesize); // Find majik cookie from ESP
+        emit_d32(cbuf, 0xbadb100d);
+      }
+      // jmp EQ around INT3
+      // QQQ TODO
+      const int jump_around = 5; // size of call to breakpoint, 1 for CC
+      emit_opcode(cbuf,0x74);
+      emit_d8(cbuf, jump_around);
+      // QQQ temporary
+      emit_break(cbuf);
+      // Die if stack mismatch
+      // emit_opcode(cbuf,0xCC);
+    }
+  %}
+
+%}
+
+// INSTRUCTIONS -- Platform dependent
+
+//----------OS and Locking Instructions----------------------------------------
+
+// This name is KNOWN by the ADLC and cannot be changed.
+// The ADLC forces a 'TypeRawPtr::BOTTOM' output type
+// for this guy.
+instruct tlsLoadP(eRegP dst, eFlagsReg cr) %{
+  match(Set dst (ThreadLocal));
+  effect(DEF dst, KILL cr);
+
+  format %{ "MOV    $dst, Thread::current()" %}
+  ins_encode( bsd_tlsencode(dst) );
+  ins_pipe( ialu_reg_fat );
+%}
+
+instruct TLS(eRegP dst) %{
+  match(Set dst (ThreadLocal));
+
+  expand %{
+    tlsLoadP(dst);
+  %}
+%}
+
+// Die now
+instruct ShouldNotReachHere( )
+%{
+  match(Halt);
+
+  // Use the following format syntax
+  format %{ "INT3   ; ShouldNotReachHere" %}
+  // QQQ TODO for now call breakpoint
+  // opcode(0xCC);
+  // ins_encode(Opc);
+  ins_encode(bsd_breakpoint);
+  ins_pipe( pipe_slow );
+%}
+
+
+
+// Platform dependent source
+
+source %{
+
+// emit an interrupt that is caught by the debugger
+void emit_break(CodeBuffer &cbuf) {
+
+  // Debugger doesn't really catch this but best we can do so far QQQ
+  MacroAssembler* masm = new MacroAssembler(&cbuf);
+  masm->call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
+}
+
+void MachBreakpointNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
+  emit_break(cbuf);
+}
+
+
+uint MachBreakpointNode::size(PhaseRegAlloc *ra_) const {
+  return 5;
+}
+
+%}
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s
new file mode 100644
index 0000000..402c8da
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s
@@ -0,0 +1,689 @@
+#
+# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+
+#ifdef __APPLE__
+# Darwin uses _ prefixed global symbols
+#define SYMBOL(s) _ ## s
+#define ELF_TYPE(name, description)
+#else
+#define SYMBOL(s) s
+#define ELF_TYPE(name, description) .type name,description
+#endif
+
+        .globl SYMBOL(fixcw)
+
+        # NOTE WELL!  The _Copy functions are called directly
+        # from server-compiler-generated code via CallLeafNoFP,
+        # which means that they *must* either not use floating
+        # point or use it in the same manner as does the server
+        # compiler.
+
+        .globl SYMBOL(_Copy_conjoint_bytes)
+        .globl SYMBOL(_Copy_arrayof_conjoint_bytes)
+        .globl SYMBOL(_Copy_conjoint_jshorts_atomic)
+        .globl SYMBOL(_Copy_arrayof_conjoint_jshorts)
+        .globl SYMBOL(_Copy_conjoint_jints_atomic)
+        .globl SYMBOL(_Copy_arrayof_conjoint_jints)
+        .globl SYMBOL(_Copy_conjoint_jlongs_atomic)
+        .globl SYMBOL(_mmx_Copy_arrayof_conjoint_jshorts)
+
+        .globl SYMBOL(_Atomic_cmpxchg_long)
+        .globl SYMBOL(_Atomic_move_long)
+
+        .text
+
+# Support for void os::Solaris::init_thread_fpu_state() in os_solaris_i486.cpp
+# Set fpu to 53 bit precision.  This happens too early to use a stub.
+# ported from solaris_x86_32.s
+        .p2align 4,,15
+SYMBOL(fixcw):
+        pushl    $0x27f
+        fldcw    0(%esp)
+        popl     %eax
+        ret
+
+        .globl  SYMBOL(SafeFetch32), SYMBOL(Fetch32PFI), SYMBOL(Fetch32Resume)
+        .globl  SYMBOL(SafeFetchN)
+        ## TODO: avoid exposing Fetch32PFI and Fetch32Resume.
+        ## Instead, the signal handler would call a new SafeFetchTriage(FaultingEIP)
+        ## routine to vet the address.  If the address is the faulting LD then
+        ## SafeFetchTriage() would return the resume-at EIP, otherwise null.
+        ELF_TYPE(SafeFetch32,@function)
+        .p2align 4,,15
+SYMBOL(SafeFetch32):
+SYMBOL(SafeFetchN):
+         movl    0x8(%esp), %eax
+         movl    0x4(%esp), %ecx
+SYMBOL(Fetch32PFI):
+         movl    (%ecx), %eax
+SYMBOL(Fetch32Resume):
+         ret
+
+
+        .globl  SYMBOL(SpinPause)
+        ELF_TYPE(SpinPause,@function)
+        .p2align 4,,15
+SYMBOL(SpinPause):
+        rep
+        nop
+        movl    $1, %eax
+        ret
+
+        # Support for void Copy::conjoint_bytes(void* from,
+        #                                       void* to,
+        #                                       size_t count)
+        .p2align 4,,15
+        ELF_TYPE(_Copy_conjoint_bytes,@function)
+SYMBOL(_Copy_conjoint_bytes):
+        pushl    %esi
+        movl     4+12(%esp),%ecx      # count
+        pushl    %edi
+        movl     8+ 4(%esp),%esi      # from
+        movl     8+ 8(%esp),%edi      # to
+        cmpl     %esi,%edi
+        leal     -1(%esi,%ecx),%eax   # from + count - 1
+        jbe      cb_CopyRight
+        cmpl     %eax,%edi
+        jbe      cb_CopyLeft
+        # copy from low to high
+cb_CopyRight:
+        cmpl     $3,%ecx
+        jbe      5f                   # <= 3 bytes
+        # align source address at dword address boundary
+        movl     %ecx,%eax            # original count
+        movl     $4,%ecx
+        subl     %esi,%ecx
+        andl     $3,%ecx              # prefix byte count
+        jz       1f                   # no prefix
+        subl     %ecx,%eax            # byte count less prefix
+        # copy prefix
+        subl     %esi,%edi
+0:      movb     (%esi),%dl
+        movb     %dl,(%edi,%esi,1)
+        addl     $1,%esi
+        subl     $1,%ecx
+        jnz      0b
+        addl     %esi,%edi
+1:      movl     %eax,%ecx            # byte count less prefix
+        shrl     $2,%ecx              # dword count
+        jz       4f                   # no dwords to move
+        cmpl     $32,%ecx
+        jbe      2f                   # <= 32 dwords
+        # copy aligned dwords
+        rep;     smovl
+        jmp      4f
+        # copy aligned dwords
+2:      subl     %esi,%edi
+        .p2align 4,,15
+3:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        addl     $4,%esi
+        subl     $1,%ecx
+        jnz      3b
+        addl     %esi,%edi
+4:      movl     %eax,%ecx            # byte count less prefix
+5:      andl     $3,%ecx              # suffix byte count
+        jz       7f                   # no suffix
+        # copy suffix
+        xorl     %eax,%eax
+6:      movb     (%esi,%eax,1),%dl
+        movb     %dl,(%edi,%eax,1)
+        addl     $1,%eax
+        subl     $1,%ecx
+        jnz      6b
+7:      popl     %edi
+        popl     %esi
+        ret
+        # copy from high to low
+cb_CopyLeft:
+        std
+        leal     -4(%edi,%ecx),%edi   # to + count - 4
+        movl     %eax,%esi            # from + count - 1
+        movl     %ecx,%eax
+        subl     $3,%esi              # from + count - 4
+        cmpl     $3,%ecx
+        jbe      5f                   # <= 3 bytes
+1:      shrl     $2,%ecx              # dword count
+        jz       4f                   # no dwords to move
+        cmpl     $32,%ecx
+        ja       3f                   # > 32 dwords
+        # copy dwords, aligned or not
+        subl     %esi,%edi
+        .p2align 4,,15
+2:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        subl     $4,%esi
+        subl     $1,%ecx
+        jnz      2b
+        addl     %esi,%edi
+        jmp      4f
+        # copy dwords, aligned or not
+3:      rep;     smovl
+4:      movl     %eax,%ecx            # byte count
+5:      andl     $3,%ecx              # suffix byte count
+        jz       7f                   # no suffix
+        # copy suffix
+        subl     %esi,%edi
+        addl     $3,%esi
+6:      movb     (%esi),%dl
+        movb     %dl,(%edi,%esi,1)
+        subl     $1,%esi
+        subl     $1,%ecx
+        jnz      6b
+7:      cld
+        popl     %edi
+        popl     %esi
+        ret
+
+        # Support for void Copy::arrayof_conjoint_bytes(void* from,
+        #                                               void* to,
+        #                                               size_t count)
+        #
+        # Same as _Copy_conjoint_bytes, except no source alignment check.
+        .p2align 4,,15
+        ELF_TYPE(_Copy_arrayof_conjoint_bytes,@function)
+SYMBOL(_Copy_arrayof_conjoint_bytes):
+        pushl    %esi
+        movl     4+12(%esp),%ecx      # count
+        pushl    %edi
+        movl     8+ 4(%esp),%esi      # from
+        movl     8+ 8(%esp),%edi      # to
+        cmpl     %esi,%edi
+        leal     -1(%esi,%ecx),%eax   # from + count - 1
+        jbe      acb_CopyRight
+        cmpl     %eax,%edi
+        jbe      acb_CopyLeft
+        # copy from low to high
+acb_CopyRight:
+        cmpl     $3,%ecx
+        jbe      5f
+1:      movl     %ecx,%eax
+        shrl     $2,%ecx
+        jz       4f
+        cmpl     $32,%ecx
+        ja       3f
+        # copy aligned dwords
+        subl     %esi,%edi
+        .p2align 4,,15
+2:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        addl     $4,%esi
+        subl     $1,%ecx
+        jnz      2b
+        addl     %esi,%edi
+        jmp      4f
+        # copy aligned dwords
+3:      rep;     smovl
+4:      movl     %eax,%ecx
+5:      andl     $3,%ecx
+        jz       7f
+        # copy suffix
+        xorl     %eax,%eax
+6:      movb     (%esi,%eax,1),%dl
+        movb     %dl,(%edi,%eax,1)
+        addl     $1,%eax
+        subl     $1,%ecx
+        jnz      6b
+7:      popl     %edi
+        popl     %esi
+        ret
+acb_CopyLeft:
+        std
+        leal     -4(%edi,%ecx),%edi   # to + count - 4
+        movl     %eax,%esi            # from + count - 1
+        movl     %ecx,%eax
+        subl     $3,%esi              # from + count - 4
+        cmpl     $3,%ecx
+        jbe      5f
+1:      shrl     $2,%ecx
+        jz       4f
+        cmpl     $32,%ecx
+        jbe      2f                   # <= 32 dwords
+        rep;     smovl
+        jmp      4f
+        .space 8
+2:      subl     %esi,%edi
+        .p2align 4,,15
+3:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        subl     $4,%esi
+        subl     $1,%ecx
+        jnz      3b
+        addl     %esi,%edi
+4:      movl     %eax,%ecx
+5:      andl     $3,%ecx
+        jz       7f
+        subl     %esi,%edi
+        addl     $3,%esi
+6:      movb     (%esi),%dl
+        movb     %dl,(%edi,%esi,1)
+        subl     $1,%esi
+        subl     $1,%ecx
+        jnz      6b
+7:      cld
+        popl     %edi
+        popl     %esi
+        ret
+
+        # Support for void Copy::conjoint_jshorts_atomic(void* from,
+        #                                                void* to,
+        #                                                size_t count)
+        .p2align 4,,15
+        ELF_TYPE(_Copy_conjoint_jshorts_atomic,@function)
+SYMBOL(_Copy_conjoint_jshorts_atomic):
+        pushl    %esi
+        movl     4+12(%esp),%ecx      # count
+        pushl    %edi
+        movl     8+ 4(%esp),%esi      # from
+        movl     8+ 8(%esp),%edi      # to
+        cmpl     %esi,%edi
+        leal     -2(%esi,%ecx,2),%eax # from + count*2 - 2
+        jbe      cs_CopyRight
+        cmpl     %eax,%edi
+        jbe      cs_CopyLeft
+        # copy from low to high
+cs_CopyRight:
+        # align source address at dword address boundary
+        movl     %esi,%eax            # original from
+        andl     $3,%eax              # either 0 or 2
+        jz       1f                   # no prefix
+        # copy prefix
+        subl     $1,%ecx
+        jl       5f                   # zero count
+        movw     (%esi),%dx
+        movw     %dx,(%edi)
+        addl     %eax,%esi            # %eax == 2
+        addl     %eax,%edi
+1:      movl     %ecx,%eax            # word count less prefix
+        sarl     %ecx                 # dword count
+        jz       4f                   # no dwords to move
+        cmpl     $32,%ecx
+        jbe      2f                   # <= 32 dwords
+        # copy aligned dwords
+        rep;     smovl
+        jmp      4f
+        # copy aligned dwords
+2:      subl     %esi,%edi
+        .p2align 4,,15
+3:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        addl     $4,%esi
+        subl     $1,%ecx
+        jnz      3b
+        addl     %esi,%edi
+4:      andl     $1,%eax              # suffix count
+        jz       5f                   # no suffix
+        # copy suffix
+        movw     (%esi),%dx
+        movw     %dx,(%edi)
+5:      popl     %edi
+        popl     %esi
+        ret
+        # copy from high to low
+cs_CopyLeft:
+        std
+        leal     -4(%edi,%ecx,2),%edi # to + count*2 - 4
+        movl     %eax,%esi            # from + count*2 - 2
+        movl     %ecx,%eax
+        subl     $2,%esi              # from + count*2 - 4
+1:      sarl     %ecx                 # dword count
+        jz       4f                   # no dwords to move
+        cmpl     $32,%ecx
+        ja       3f                   # > 32 dwords
+        subl     %esi,%edi
+        .p2align 4,,15
+2:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        subl     $4,%esi
+        subl     $1,%ecx
+        jnz      2b
+        addl     %esi,%edi
+        jmp      4f
+3:      rep;     smovl
+4:      andl     $1,%eax              # suffix count
+        jz       5f                   # no suffix
+        # copy suffix
+        addl     $2,%esi
+        addl     $2,%edi
+        movw     (%esi),%dx
+        movw     %dx,(%edi)
+5:      cld
+        popl     %edi
+        popl     %esi
+        ret
+
+        # Support for void Copy::arrayof_conjoint_jshorts(void* from,
+        #                                                 void* to,
+        #                                                 size_t count)
+        .p2align 4,,15
+        ELF_TYPE(_Copy_arrayof_conjoint_jshorts,@function)
+SYMBOL(_Copy_arrayof_conjoint_jshorts):
+        pushl    %esi
+        movl     4+12(%esp),%ecx      # count
+        pushl    %edi
+        movl     8+ 4(%esp),%esi      # from
+        movl     8+ 8(%esp),%edi      # to
+        cmpl     %esi,%edi
+        leal     -2(%esi,%ecx,2),%eax # from + count*2 - 2
+        jbe      acs_CopyRight
+        cmpl     %eax,%edi
+        jbe      acs_CopyLeft
+acs_CopyRight:
+        movl     %ecx,%eax            # word count
+        sarl     %ecx                 # dword count
+        jz       4f                   # no dwords to move
+        cmpl     $32,%ecx
+        jbe      2f                   # <= 32 dwords
+        # copy aligned dwords
+        rep;     smovl
+        jmp      4f
+        # copy aligned dwords
+        .space 5
+2:      subl     %esi,%edi
+        .p2align 4,,15
+3:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        addl     $4,%esi
+        subl     $1,%ecx
+        jnz      3b
+        addl     %esi,%edi
+4:      andl     $1,%eax              # suffix count
+        jz       5f                   # no suffix
+        # copy suffix
+        movw     (%esi),%dx
+        movw     %dx,(%edi)
+5:      popl     %edi
+        popl     %esi
+        ret
+acs_CopyLeft:
+        std
+        leal     -4(%edi,%ecx,2),%edi # to + count*2 - 4
+        movl     %eax,%esi            # from + count*2 - 2
+        movl     %ecx,%eax
+        subl     $2,%esi              # from + count*2 - 4
+        sarl     %ecx                 # dword count
+        jz       4f                   # no dwords to move
+        cmpl     $32,%ecx
+        ja       3f                   # > 32 dwords
+        subl     %esi,%edi
+        .p2align 4,,15
+2:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        subl     $4,%esi
+        subl     $1,%ecx
+        jnz      2b
+        addl     %esi,%edi
+        jmp      4f
+3:      rep;     smovl
+4:      andl     $1,%eax              # suffix count
+        jz       5f                   # no suffix
+        # copy suffix
+        addl     $2,%esi
+        addl     $2,%edi
+        movw     (%esi),%dx
+        movw     %dx,(%edi)
+5:      cld
+        popl     %edi
+        popl     %esi
+        ret
+
+        # Support for void Copy::conjoint_jints_atomic(void* from,
+        #                                              void* to,
+        #                                              size_t count)
+        # Equivalent to
+        #   arrayof_conjoint_jints
+        .p2align 4,,15
+        ELF_TYPE(_Copy_conjoint_jints_atomic,@function)
+        ELF_TYPE(_Copy_arrayof_conjoint_jints,@function)
+SYMBOL(_Copy_conjoint_jints_atomic):
+SYMBOL(_Copy_arrayof_conjoint_jints):
+        pushl    %esi
+        movl     4+12(%esp),%ecx      # count
+        pushl    %edi
+        movl     8+ 4(%esp),%esi      # from
+        movl     8+ 8(%esp),%edi      # to
+        cmpl     %esi,%edi
+        leal     -4(%esi,%ecx,4),%eax # from + count*4 - 4
+        jbe      ci_CopyRight
+        cmpl     %eax,%edi
+        jbe      ci_CopyLeft
+ci_CopyRight:
+        cmpl     $32,%ecx
+        jbe      2f                   # <= 32 dwords
+        rep;     smovl
+        popl     %edi
+        popl     %esi
+        ret
+        .space 10
+2:      subl     %esi,%edi
+        jmp      4f
+        .p2align 4,,15
+3:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        addl     $4,%esi
+4:      subl     $1,%ecx
+        jge      3b
+        popl     %edi
+        popl     %esi
+        ret
+ci_CopyLeft:
+        std
+        leal     -4(%edi,%ecx,4),%edi # to + count*4 - 4
+        cmpl     $32,%ecx
+        ja       4f                   # > 32 dwords
+        subl     %eax,%edi            # eax == from + count*4 - 4
+        jmp      3f
+        .p2align 4,,15
+2:      movl     (%eax),%edx
+        movl     %edx,(%edi,%eax,1)
+        subl     $4,%eax
+3:      subl     $1,%ecx
+        jge      2b
+        cld
+        popl     %edi
+        popl     %esi
+        ret
+4:      movl     %eax,%esi            # from + count*4 - 4
+        rep;     smovl
+        cld
+        popl     %edi
+        popl     %esi
+        ret
+
+        # Support for void Copy::conjoint_jlongs_atomic(jlong* from,
+        #                                               jlong* to,
+        #                                               size_t count)
+        #
+        # 32-bit
+        #
+        # count treated as signed
+        #
+        # // if (from > to) {
+        #   while (--count >= 0) {
+        #     *to++ = *from++;
+        #   }
+        # } else {
+        #   while (--count >= 0) {
+        #     to[count] = from[count];
+        #   }
+        # }
+        .p2align 4,,15
+        ELF_TYPE(_Copy_conjoint_jlongs_atomic,@function)
+SYMBOL(_Copy_conjoint_jlongs_atomic):
+        movl     4+8(%esp),%ecx       # count
+        movl     4+0(%esp),%eax       # from
+        movl     4+4(%esp),%edx       # to
+        cmpl     %eax,%edx
+        jae      cla_CopyLeft
+cla_CopyRight:
+        subl     %eax,%edx
+        jmp      2f
+        .p2align 4,,15
+1:      fildll   (%eax)
+        fistpll  (%edx,%eax,1)
+        addl     $8,%eax
+2:      subl     $1,%ecx
+        jge      1b
+        ret
+        .p2align 4,,15
+3:      fildll   (%eax,%ecx,8)
+        fistpll  (%edx,%ecx,8)
+cla_CopyLeft:
+        subl     $1,%ecx
+        jge      3b
+        ret
+
+        # Support for void Copy::arrayof_conjoint_jshorts(void* from,
+        #                                                 void* to,
+        #                                                 size_t count)
+        .p2align 4,,15
+        ELF_TYPE(_mmx_Copy_arrayof_conjoint_jshorts,@function)
+SYMBOL(_mmx_Copy_arrayof_conjoint_jshorts):
+        pushl    %esi
+        movl     4+12(%esp),%ecx
+        pushl    %edi
+        movl     8+ 4(%esp),%esi
+        movl     8+ 8(%esp),%edi
+        cmpl     %esi,%edi
+        leal     -2(%esi,%ecx,2),%eax
+        jbe      mmx_acs_CopyRight
+        cmpl     %eax,%edi
+        jbe      mmx_acs_CopyLeft
+mmx_acs_CopyRight:
+        movl     %ecx,%eax
+        sarl     %ecx
+        je       5f
+        cmpl     $33,%ecx
+        jae      3f
+1:      subl     %esi,%edi
+        .p2align 4,,15
+2:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        addl     $4,%esi
+        subl     $1,%ecx
+        jnz      2b
+        addl     %esi,%edi
+        jmp      5f
+3:      smovl # align to 8 bytes, we know we are 4 byte aligned to start
+        subl     $1,%ecx
+4:      .p2align 4,,15
+        movq     0(%esi),%mm0
+        addl     $64,%edi
+        movq     8(%esi),%mm1
+        subl     $16,%ecx
+        movq     16(%esi),%mm2
+        movq     %mm0,-64(%edi)
+        movq     24(%esi),%mm0
+        movq     %mm1,-56(%edi)
+        movq     32(%esi),%mm1
+        movq     %mm2,-48(%edi)
+        movq     40(%esi),%mm2
+        movq     %mm0,-40(%edi)
+        movq     48(%esi),%mm0
+        movq     %mm1,-32(%edi)
+        movq     56(%esi),%mm1
+        movq     %mm2,-24(%edi)
+        movq     %mm0,-16(%edi)
+        addl     $64,%esi
+        movq     %mm1,-8(%edi)
+        cmpl     $16,%ecx
+        jge      4b
+        emms
+        testl    %ecx,%ecx
+        ja       1b
+5:      andl     $1,%eax
+        je       7f
+6:      movw     (%esi),%dx
+        movw     %dx,(%edi)
+7:      popl     %edi
+        popl     %esi
+        ret
+mmx_acs_CopyLeft:
+        std
+        leal     -4(%edi,%ecx,2),%edi
+        movl     %eax,%esi
+        movl     %ecx,%eax
+        subl     $2,%esi
+        sarl     %ecx
+        je       4f
+        cmpl     $32,%ecx
+        ja       3f
+        subl     %esi,%edi
+        .p2align 4,,15
+2:      movl     (%esi),%edx
+        movl     %edx,(%edi,%esi,1)
+        subl     $4,%esi
+        subl     $1,%ecx
+        jnz      2b
+        addl     %esi,%edi
+        jmp      4f
+3:      rep;     smovl
+4:      andl     $1,%eax
+        je       6f
+        addl     $2,%esi
+        addl     $2,%edi
+5:      movw     (%esi),%dx
+        movw     %dx,(%edi)
+6:      cld
+        popl     %edi
+        popl     %esi
+        ret
+
+
+        # Support for jlong Atomic::cmpxchg(jlong exchange_value,
+        #                                   volatile jlong* dest,
+        #                                   jlong compare_value,
+        #                                   bool is_MP)
+        #
+        .p2align 4,,15
+        ELF_TYPE(_Atomic_cmpxchg_long,@function)
+SYMBOL(_Atomic_cmpxchg_long):
+                                   #  8(%esp) : return PC
+        pushl    %ebx              #  4(%esp) : old %ebx
+        pushl    %edi              #  0(%esp) : old %edi
+        movl     12(%esp), %ebx    # 12(%esp) : exchange_value (low)
+        movl     16(%esp), %ecx    # 16(%esp) : exchange_value (high)
+        movl     24(%esp), %eax    # 24(%esp) : compare_value (low)
+        movl     28(%esp), %edx    # 28(%esp) : compare_value (high)
+        movl     20(%esp), %edi    # 20(%esp) : dest
+        cmpl     $0, 32(%esp)      # 32(%esp) : is_MP
+        je       1f
+        lock
+1:      cmpxchg8b (%edi)
+        popl     %edi
+        popl     %ebx
+        ret
+
+
+        # Support for jlong Atomic::load and Atomic::store.
+        # void _Atomic_move_long(volatile jlong* src, volatile jlong* dst)
+        .p2align 4,,15
+        ELF_TYPE(_Atomic_move_long,@function)
+SYMBOL(_Atomic_move_long):
+        movl     4(%esp), %eax   # src
+        fildll    (%eax)
+        movl     8(%esp), %eax   # dest
+        fistpll   (%eax)
+        ret
+
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.ad b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.ad
new file mode 100644
index 0000000..233a1fe
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.ad
@@ -0,0 +1,173 @@
+//
+// Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+//
+// This code is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License version 2 only, as
+// published by the Free Software Foundation.
+//
+// This code is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// version 2 for more details (a copy is included in the LICENSE file that
+// accompanied this code).
+//
+// You should have received a copy of the GNU General Public License version
+// 2 along with this work; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+// or visit www.oracle.com if you need additional information or have any
+// questions.
+//
+//
+
+// AMD64 Bsd Architecture Description File
+
+//----------OS-DEPENDENT ENCODING BLOCK----------------------------------------
+// This block specifies the encoding classes used by the compiler to
+// output byte streams.  Encoding classes generate functions which are
+// called by Machine Instruction Nodes in order to generate the bit
+// encoding of the instruction.  Operands specify their base encoding
+// interface with the interface keyword.  There are currently
+// supported four interfaces, REG_INTER, CONST_INTER, MEMORY_INTER, &
+// COND_INTER.  REG_INTER causes an operand to generate a function
+// which returns its register number when queried.  CONST_INTER causes
+// an operand to generate a function which returns the value of the
+// constant when queried.  MEMORY_INTER causes an operand to generate
+// four functions which return the Base Register, the Index Register,
+// the Scale Value, and the Offset Value of the operand when queried.
+// COND_INTER causes an operand to generate six functions which return
+// the encoding code (ie - encoding bits for the instruction)
+// associated with each basic boolean condition for a conditional
+// instruction.  Instructions specify two basic values for encoding.
+// They use the ins_encode keyword to specify their encoding class
+// (which must be one of the class names specified in the encoding
+// block), and they use the opcode keyword to specify, in order, their
+// primary, secondary, and tertiary opcode.  Only the opcode sections
+// which a particular instruction needs for encoding need to be
+// specified.
+encode %{
+  // Build emit functions for each basic byte or larger field in the intel
+  // encoding scheme (opcode, rm, sib, immediate), and call them from C++
+  // code in the enc_class source block.  Emit functions will live in the
+  // main source block for now.  In future, we can generalize this by
+  // adding a syntax that specifies the sizes of fields in an order,
+  // so that the adlc can build the emit functions automagically
+
+  enc_class Java_To_Runtime(method meth)
+  %{
+    // No relocation needed
+
+    // movq r10, <meth>
+    emit_opcode(cbuf, Assembler::REX_WB);
+    emit_opcode(cbuf, 0xB8 | (R10_enc - 8));
+    emit_d64(cbuf, (int64_t) $meth$$method);
+
+    // call (r10)
+    emit_opcode(cbuf, Assembler::REX_B);
+    emit_opcode(cbuf, 0xFF);
+    emit_opcode(cbuf, 0xD0 | (R10_enc - 8));
+  %}
+
+  enc_class bsd_breakpoint
+  %{
+    MacroAssembler* masm = new MacroAssembler(&cbuf);
+    masm->call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
+  %}
+
+  enc_class call_epilog
+  %{
+    if (VerifyStackAtCalls) {
+      // Check that stack depth is unchanged: find majik cookie on stack
+      int framesize =
+        ra_->reg2offset_unchecked(OptoReg::add(ra_->_matcher._old_SP, -3*VMRegImpl::slots_per_word));
+      if (framesize) {
+        if (framesize < 0x80) {
+          emit_opcode(cbuf, Assembler::REX_W);
+          emit_opcode(cbuf, 0x81); // cmpq [rsp+0],0xbadb1ood
+          emit_d8(cbuf, 0x7C);
+          emit_d8(cbuf, 0x24);
+          emit_d8(cbuf, framesize); // Find majik cookie from ESP
+          emit_d32(cbuf, 0xbadb100d);
+        } else {
+          emit_opcode(cbuf, Assembler::REX_W);
+          emit_opcode(cbuf, 0x81); // cmpq [rsp+0],0xbadb1ood
+          emit_d8(cbuf, 0xBC);
+          emit_d8(cbuf, 0x24);
+          emit_d32(cbuf, framesize); // Find majik cookie from ESP
+          emit_d32(cbuf, 0xbadb100d);
+        }
+      }
+      // jmp EQ around INT3
+      // QQQ TODO
+      const int jump_around = 5; // size of call to breakpoint, 1 for CC
+      emit_opcode(cbuf, 0x74);
+      emit_d8(cbuf, jump_around);
+      // QQQ temporary
+      emit_break(cbuf);
+      // Die if stack mismatch
+      // emit_opcode(cbuf,0xCC);
+    }
+  %}
+
+%}
+
+// INSTRUCTIONS -- Platform dependent
+
+//----------OS and Locking Instructions----------------------------------------
+
+// This name is KNOWN by the ADLC and cannot be changed.
+// The ADLC forces a 'TypeRawPtr::BOTTOM' output type
+// for this guy.
+instruct tlsLoadP(r15_RegP dst)
+%{
+  match(Set dst (ThreadLocal));
+  effect(DEF dst);
+
+  size(0);
+  format %{ "# TLS is in R15" %}
+  ins_encode( /*empty encoding*/ );
+  ins_pipe(ialu_reg_reg);
+%}
+
+// Die now
+instruct ShouldNotReachHere()
+%{
+  match(Halt);
+
+  // Use the following format syntax
+  format %{ "int3\t# ShouldNotReachHere" %}
+  // QQQ TODO for now call breakpoint
+  // opcode(0xCC);
+  // ins_encode(Opc);
+  ins_encode(bsd_breakpoint);
+  ins_pipe(pipe_slow);
+%}
+
+
+// Platform dependent source
+
+source
+%{
+
+int MachCallRuntimeNode::ret_addr_offset() {
+  return 13; // movq r10,#addr; callq (r10)
+}
+
+// emit an interrupt that is caught by the debugger
+void emit_break(CodeBuffer& cbuf) {
+  // Debugger doesn't really catch this but best we can do so far QQQ
+  MacroAssembler* masm = new MacroAssembler(&cbuf);
+  masm->call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
+}
+
+void MachBreakpointNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
+  emit_break(cbuf);
+}
+
+uint MachBreakpointNode::size(PhaseRegAlloc* ra_) const {
+  return 5;
+}
+
+%}
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s
new file mode 100644
index 0000000..65d2db4
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s
@@ -0,0 +1,410 @@
+# 
+# Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#ifdef __APPLE__
+# Darwin uses _ prefixed global symbols
+#define SYMBOL(s) _ ## s
+#define ELF_TYPE(name, description)
+#else
+#define SYMBOL(s) s
+#define ELF_TYPE(name, description) .type name,description
+#endif
+
+        # NOTE WELL!  The _Copy functions are called directly
+	# from server-compiler-generated code via CallLeafNoFP,
+	# which means that they *must* either not use floating
+	# point or use it in the same manner as does the server
+	# compiler.
+	
+        .globl SYMBOL(_Copy_arrayof_conjoint_bytes)
+	.globl SYMBOL(_Copy_arrayof_conjoint_jshorts)
+        .globl SYMBOL(_Copy_conjoint_jshorts_atomic)
+        .globl SYMBOL(_Copy_arrayof_conjoint_jints)
+        .globl SYMBOL(_Copy_conjoint_jints_atomic)
+        .globl SYMBOL(_Copy_arrayof_conjoint_jlongs)
+        .globl SYMBOL(_Copy_conjoint_jlongs_atomic)
+
+	.text
+
+        .globl SYMBOL(SafeFetch32), SYMBOL(Fetch32PFI), SYMBOL(Fetch32Resume)
+        .p2align 4,,15
+        ELF_TYPE(SafeFetch32,@function)
+        // Prototype: int SafeFetch32 (int * Adr, int ErrValue) 
+SYMBOL(SafeFetch32):
+        movl    %esi, %eax
+SYMBOL(Fetch32PFI):
+        movl    (%rdi), %eax
+SYMBOL(Fetch32Resume):
+        ret
+
+        .globl SYMBOL(SafeFetchN), SYMBOL(FetchNPFI), SYMBOL(FetchNResume)
+        .p2align 4,,15
+        ELF_TYPE(SafeFetchN,@function)
+        // Prototype: intptr_t SafeFetchN (intptr_t * Adr, intptr_t ErrValue) 
+SYMBOL(SafeFetchN):
+        movq    %rsi, %rax
+SYMBOL(FetchNPFI):
+        movq    (%rdi), %rax
+SYMBOL(FetchNResume):
+        ret
+
+        .globl SYMBOL(SpinPause)
+        .p2align 4,,15
+        ELF_TYPE(SpinPause,@function)
+SYMBOL(SpinPause):
+        rep
+        nop
+        movq   $1, %rax
+        ret
+
+        # Support for void Copy::arrayof_conjoint_bytes(void* from,
+        #                                               void* to,
+        #                                               size_t count)
+        # rdi - from
+        # rsi - to
+        # rdx - count, treated as ssize_t
+        #
+        .p2align 4,,15
+	ELF_TYPE(_Copy_arrayof_conjoint_bytes,@function)
+SYMBOL(_Copy_arrayof_conjoint_bytes):
+        movq     %rdx,%r8             # byte count
+        shrq     $3,%rdx              # qword count
+        cmpq     %rdi,%rsi
+        leaq     -1(%rdi,%r8,1),%rax  # from + bcount*1 - 1
+        jbe      acb_CopyRight
+        cmpq     %rax,%rsi
+        jbe      acb_CopyLeft 
+acb_CopyRight:
+        leaq     -8(%rdi,%rdx,8),%rax # from + qcount*8 - 8
+        leaq     -8(%rsi,%rdx,8),%rcx # to + qcount*8 - 8
+        negq     %rdx
+        jmp      7f
+        .p2align 4,,15
+1:      movq     8(%rax,%rdx,8),%rsi
+        movq     %rsi,8(%rcx,%rdx,8)
+        addq     $1,%rdx
+        jnz      1b
+2:      testq    $4,%r8               # check for trailing dword
+        jz       3f
+        movl     8(%rax),%esi         # copy trailing dword
+        movl     %esi,8(%rcx)
+        addq     $4,%rax
+        addq     $4,%rcx              # original %rsi is trashed, so we
+                                      #  can't use it as a base register
+3:      testq    $2,%r8               # check for trailing word
+        jz       4f
+        movw     8(%rax),%si          # copy trailing word
+        movw     %si,8(%rcx)
+        addq     $2,%rcx
+4:      testq    $1,%r8               # check for trailing byte
+        jz       5f
+        movb     -1(%rdi,%r8,1),%al   # copy trailing byte
+        movb     %al,8(%rcx)
+5:      ret
+        .p2align 4,,15
+6:      movq     -24(%rax,%rdx,8),%rsi
+        movq     %rsi,-24(%rcx,%rdx,8)
+        movq     -16(%rax,%rdx,8),%rsi
+        movq     %rsi,-16(%rcx,%rdx,8)
+        movq     -8(%rax,%rdx,8),%rsi
+        movq     %rsi,-8(%rcx,%rdx,8)
+        movq     (%rax,%rdx,8),%rsi
+        movq     %rsi,(%rcx,%rdx,8)
+7:      addq     $4,%rdx
+        jle      6b
+        subq     $4,%rdx
+        jl       1b
+        jmp      2b
+acb_CopyLeft:
+        testq    $1,%r8               # check for trailing byte
+        jz       1f
+        movb     -1(%rdi,%r8,1),%cl   # copy trailing byte
+        movb     %cl,-1(%rsi,%r8,1)
+        subq     $1,%r8               # adjust for possible trailing word
+1:      testq    $2,%r8               # check for trailing word
+        jz       2f
+        movw     -2(%rdi,%r8,1),%cx   # copy trailing word
+        movw     %cx,-2(%rsi,%r8,1)
+2:      testq    $4,%r8               # check for trailing dword
+        jz       5f
+        movl     (%rdi,%rdx,8),%ecx   # copy trailing dword
+        movl     %ecx,(%rsi,%rdx,8)
+        jmp      5f
+        .p2align 4,,15
+3:      movq     -8(%rdi,%rdx,8),%rcx
+        movq     %rcx,-8(%rsi,%rdx,8)
+        subq     $1,%rdx
+        jnz      3b
+        ret
+        .p2align 4,,15
+4:      movq     24(%rdi,%rdx,8),%rcx
+        movq     %rcx,24(%rsi,%rdx,8)
+        movq     16(%rdi,%rdx,8),%rcx
+        movq     %rcx,16(%rsi,%rdx,8)
+        movq     8(%rdi,%rdx,8),%rcx
+        movq     %rcx,8(%rsi,%rdx,8)
+        movq     (%rdi,%rdx,8),%rcx
+        movq     %rcx,(%rsi,%rdx,8)
+5:      subq     $4,%rdx
+        jge      4b
+        addq     $4,%rdx
+        jg       3b
+        ret
+
+        # Support for void Copy::arrayof_conjoint_jshorts(void* from,
+        #                                                 void* to,
+        #                                                 size_t count)
+        # Equivalent to
+        #   conjoint_jshorts_atomic
+        #
+        # If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we
+        # let the hardware handle it.  The tow or four words within dwords
+        # or qwords that span cache line boundaries will still be loaded
+        # and stored atomically.
+        #
+        # rdi - from
+        # rsi - to
+        # rdx - count, treated as ssize_t
+        #
+        .p2align 4,,15
+	ELF_TYPE(_Copy_arrayof_conjoint_jshorts,@function)
+	ELF_TYPE(_Copy_conjoint_jshorts_atomic,@function)
+SYMBOL(_Copy_arrayof_conjoint_jshorts):
+SYMBOL(_Copy_conjoint_jshorts_atomic):
+        movq     %rdx,%r8             # word count
+        shrq     $2,%rdx              # qword count
+        cmpq     %rdi,%rsi
+        leaq     -2(%rdi,%r8,2),%rax  # from + wcount*2 - 2
+        jbe      acs_CopyRight
+        cmpq     %rax,%rsi
+        jbe      acs_CopyLeft 
+acs_CopyRight:
+        leaq     -8(%rdi,%rdx,8),%rax # from + qcount*8 - 8
+        leaq     -8(%rsi,%rdx,8),%rcx # to + qcount*8 - 8
+        negq     %rdx
+        jmp      6f
+1:      movq     8(%rax,%rdx,8),%rsi
+        movq     %rsi,8(%rcx,%rdx,8)
+        addq     $1,%rdx
+        jnz      1b
+2:      testq    $2,%r8               # check for trailing dword
+        jz       3f
+        movl     8(%rax),%esi         # copy trailing dword
+        movl     %esi,8(%rcx)
+        addq     $4,%rcx              # original %rsi is trashed, so we
+                                      #  can't use it as a base register
+3:      testq    $1,%r8               # check for trailing word
+        jz       4f
+        movw     -2(%rdi,%r8,2),%si   # copy trailing word
+        movw     %si,8(%rcx)
+4:      ret
+        .p2align 4,,15
+5:      movq     -24(%rax,%rdx,8),%rsi
+        movq     %rsi,-24(%rcx,%rdx,8)
+        movq     -16(%rax,%rdx,8),%rsi
+        movq     %rsi,-16(%rcx,%rdx,8)
+        movq     -8(%rax,%rdx,8),%rsi
+        movq     %rsi,-8(%rcx,%rdx,8)
+        movq     (%rax,%rdx,8),%rsi
+        movq     %rsi,(%rcx,%rdx,8)
+6:      addq     $4,%rdx
+        jle      5b
+        subq     $4,%rdx
+        jl       1b
+        jmp      2b
+acs_CopyLeft:
+        testq    $1,%r8               # check for trailing word
+        jz       1f
+        movw     -2(%rdi,%r8,2),%cx   # copy trailing word
+        movw     %cx,-2(%rsi,%r8,2)
+1:      testq    $2,%r8               # check for trailing dword
+        jz       4f
+        movl     (%rdi,%rdx,8),%ecx   # copy trailing dword
+        movl     %ecx,(%rsi,%rdx,8)
+        jmp      4f
+2:      movq     -8(%rdi,%rdx,8),%rcx
+        movq     %rcx,-8(%rsi,%rdx,8)
+        subq     $1,%rdx
+        jnz      2b
+        ret
+        .p2align 4,,15
+3:      movq     24(%rdi,%rdx,8),%rcx
+        movq     %rcx,24(%rsi,%rdx,8)
+        movq     16(%rdi,%rdx,8),%rcx
+        movq     %rcx,16(%rsi,%rdx,8)
+        movq     8(%rdi,%rdx,8),%rcx
+        movq     %rcx,8(%rsi,%rdx,8)
+        movq     (%rdi,%rdx,8),%rcx
+        movq     %rcx,(%rsi,%rdx,8)
+4:      subq     $4,%rdx
+        jge      3b
+        addq     $4,%rdx
+        jg       2b
+        ret
+
+        # Support for void Copy::arrayof_conjoint_jints(jint* from,
+        #                                               jint* to,
+        #                                               size_t count)
+        # Equivalent to
+        #   conjoint_jints_atomic
+        #
+        # If 'from' and/or 'to' are aligned on 4-byte boundaries, we let
+        # the hardware handle it.  The two dwords within qwords that span
+        # cache line boundaries will still be loaded and stored atomically.
+        #
+        # rdi - from
+        # rsi - to
+        # rdx - count, treated as ssize_t
+        #
+        .p2align 4,,15
+	ELF_TYPE(_Copy_arrayof_conjoint_jints,@function)
+	ELF_TYPE(_Copy_conjoint_jints_atomic,@function)
+SYMBOL(_Copy_arrayof_conjoint_jints):
+SYMBOL(_Copy_conjoint_jints_atomic):
+        movq     %rdx,%r8             # dword count
+        shrq     %rdx                 # qword count
+        cmpq     %rdi,%rsi
+        leaq     -4(%rdi,%r8,4),%rax  # from + dcount*4 - 4
+        jbe      aci_CopyRight
+        cmpq     %rax,%rsi
+        jbe      aci_CopyLeft 
+aci_CopyRight:
+        leaq     -8(%rdi,%rdx,8),%rax # from + qcount*8 - 8
+        leaq     -8(%rsi,%rdx,8),%rcx # to + qcount*8 - 8
+        negq     %rdx
+        jmp      5f
+        .p2align 4,,15
+1:      movq     8(%rax,%rdx,8),%rsi
+        movq     %rsi,8(%rcx,%rdx,8)
+        addq     $1,%rdx
+        jnz       1b
+2:      testq    $1,%r8               # check for trailing dword
+        jz       3f
+        movl     8(%rax),%esi         # copy trailing dword
+        movl     %esi,8(%rcx)
+3:      ret
+        .p2align 4,,15
+4:      movq     -24(%rax,%rdx,8),%rsi
+        movq     %rsi,-24(%rcx,%rdx,8)
+        movq     -16(%rax,%rdx,8),%rsi
+        movq     %rsi,-16(%rcx,%rdx,8)
+        movq     -8(%rax,%rdx,8),%rsi
+        movq     %rsi,-8(%rcx,%rdx,8)
+        movq     (%rax,%rdx,8),%rsi
+        movq     %rsi,(%rcx,%rdx,8)
+5:      addq     $4,%rdx
+        jle      4b
+        subq     $4,%rdx
+        jl       1b
+        jmp      2b
+aci_CopyLeft:
+        testq    $1,%r8               # check for trailing dword
+        jz       3f
+        movl     -4(%rdi,%r8,4),%ecx  # copy trailing dword
+        movl     %ecx,-4(%rsi,%r8,4)
+        jmp      3f
+1:      movq     -8(%rdi,%rdx,8),%rcx
+        movq     %rcx,-8(%rsi,%rdx,8)
+        subq     $1,%rdx
+        jnz      1b
+        ret
+        .p2align 4,,15
+2:      movq     24(%rdi,%rdx,8),%rcx
+        movq     %rcx,24(%rsi,%rdx,8)
+        movq     16(%rdi,%rdx,8),%rcx
+        movq     %rcx,16(%rsi,%rdx,8)
+        movq     8(%rdi,%rdx,8),%rcx
+        movq     %rcx,8(%rsi,%rdx,8)
+        movq     (%rdi,%rdx,8),%rcx
+        movq     %rcx,(%rsi,%rdx,8)
+3:      subq     $4,%rdx
+        jge      2b
+        addq     $4,%rdx
+        jg       1b
+        ret
+
+        # Support for void Copy::arrayof_conjoint_jlongs(jlong* from,
+        #                                                jlong* to,
+        #                                                size_t count)
+        # Equivalent to
+        #   conjoint_jlongs_atomic
+        #   arrayof_conjoint_oops
+        #   conjoint_oops_atomic
+        #
+        # rdi - from
+        # rsi - to
+        # rdx - count, treated as ssize_t
+        #
+        .p2align 4,,15
+	ELF_TYPE(_Copy_arrayof_conjoint_jlongs,@function)
+	ELF_TYPE(_Copy_conjoint_jlongs_atomic,@function)
+SYMBOL(_Copy_arrayof_conjoint_jlongs):
+SYMBOL(_Copy_conjoint_jlongs_atomic):
+        cmpq     %rdi,%rsi
+        leaq     -8(%rdi,%rdx,8),%rax # from + count*8 - 8
+        jbe      acl_CopyRight
+        cmpq     %rax,%rsi
+        jbe      acl_CopyLeft 
+acl_CopyRight:
+        leaq     -8(%rsi,%rdx,8),%rcx # to + count*8 - 8
+        negq     %rdx
+        jmp      3f
+1:      movq     8(%rax,%rdx,8),%rsi
+        movq     %rsi,8(%rcx,%rdx,8)
+        addq     $1,%rdx
+        jnz      1b
+        ret
+        .p2align 4,,15
+2:      movq     -24(%rax,%rdx,8),%rsi
+        movq     %rsi,-24(%rcx,%rdx,8)
+        movq     -16(%rax,%rdx,8),%rsi
+        movq     %rsi,-16(%rcx,%rdx,8)
+        movq     -8(%rax,%rdx,8),%rsi
+        movq     %rsi,-8(%rcx,%rdx,8)
+        movq     (%rax,%rdx,8),%rsi
+        movq     %rsi,(%rcx,%rdx,8)
+3:      addq     $4,%rdx
+        jle      2b
+        subq     $4,%rdx
+        jl       1b
+        ret
+4:      movq     -8(%rdi,%rdx,8),%rcx
+        movq     %rcx,-8(%rsi,%rdx,8)
+        subq     $1,%rdx
+        jnz      4b
+        ret
+        .p2align 4,,15
+5:      movq     24(%rdi,%rdx,8),%rcx
+        movq     %rcx,24(%rsi,%rdx,8)
+        movq     16(%rdi,%rdx,8),%rcx
+        movq     %rcx,16(%rsi,%rdx,8)
+        movq     8(%rdi,%rdx,8),%rcx
+        movq     %rcx,8(%rsi,%rdx,8)
+        movq     (%rdi,%rdx,8),%rcx
+        movq     %rcx,(%rsi,%rdx,8)
+acl_CopyLeft:
+        subq     $4,%rdx
+        jge      5b
+        addq     $4,%rdx
+        jg       4b
+        ret
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp b/hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp
new file mode 100644
index 0000000..4fe770a
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_BYTES_BSD_X86_INLINE_HPP
+#define OS_CPU_BSD_X86_VM_BYTES_BSD_X86_INLINE_HPP
+
+#ifndef _ALLBSD_SOURCE
+#include <byteswap.h>
+#endif
+
+#ifdef __APPLE__
+#include <libkern/OSByteOrder.h>
+#endif
+
+#if defined(AMD64)
+#  if defined(__APPLE__)
+#    define bswap_16(x) OSSwapInt16(x)
+#    define bswap_32(x) OSSwapInt32(x)
+#    define bswap_64(x) OSSwapInt64(x)
+#  elif defined(__OpenBSD__)
+#    define bswap_16(x) swap16(x)
+#    define bswap_32(x) swap32(x)
+#    define bswap_64(x) swap64(x)
+#  elif defined(__NetBSD__)
+#    define bswap_16(x) bswap16(x)
+#    define bswap_32(x) bswap32(x)
+#    define bswap_64(x) bswap64(x)
+#  else
+#    define bswap_16(x) __bswap16(x)
+#    define bswap_32(x) __bswap32(x)
+#    define bswap_64(x) __bswap64(x)
+#  endif
+#endif
+
+// Efficient swapping of data bytes from Java byte
+// ordering to native byte ordering and vice versa.
+inline u2   Bytes::swap_u2(u2 x) {
+#ifdef AMD64
+  return bswap_16(x);
+#else
+  u2 ret;
+  __asm__ __volatile__ (
+    "movw %0, %%ax;"
+    "xchg %%al, %%ah;"
+    "movw %%ax, %0"
+    :"=r" (ret)      // output : register 0 => ret
+    :"0"  (x)        // input  : x => register 0
+    :"ax", "0"       // clobbered registers
+  );
+  return ret;
+#endif // AMD64
+}
+
+inline u4   Bytes::swap_u4(u4 x) {
+#ifdef AMD64
+  return bswap_32(x);
+#else
+  u4 ret;
+  __asm__ __volatile__ (
+    "bswap %0"
+    :"=r" (ret)      // output : register 0 => ret
+    :"0"  (x)        // input  : x => register 0
+    :"0"             // clobbered register
+  );
+  return ret;
+#endif // AMD64
+}
+
+#ifdef AMD64
+inline u8 Bytes::swap_u8(u8 x) {
+#ifdef SPARC_WORKS
+  // workaround for SunStudio12 CR6615391
+  __asm__ __volatile__ (
+    "bswapq %0"
+    :"=r" (x)        // output : register 0 => x
+    :"0"  (x)        // input  : x => register 0
+    :"0"             // clobbered register
+  );
+  return x;
+#else
+  return bswap_64(x);
+#endif
+}
+#else
+// Helper function for swap_u8
+inline u8   Bytes::swap_u8_base(u4 x, u4 y) {
+  return (((u8)swap_u4(x))<<32) | swap_u4(y);
+}
+
+inline u8 Bytes::swap_u8(u8 x) {
+  return swap_u8_base(*(u4*)&x, *(((u4*)&x)+1));
+}
+#endif // !AMD64
+
+#endif // OS_CPU_BSD_X86_VM_BYTES_BSD_X86_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/copy_bsd_x86.inline.hpp b/hotspot/src/os_cpu/bsd_x86/vm/copy_bsd_x86.inline.hpp
new file mode 100644
index 0000000..760c61a
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/copy_bsd_x86.inline.hpp
@@ -0,0 +1,309 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_COPY_BSD_X86_INLINE_HPP
+#define OS_CPU_BSD_X86_VM_COPY_BSD_X86_INLINE_HPP
+
+static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
+#ifdef AMD64
+  (void)memmove(to, from, count * HeapWordSize);
+#else
+  // Includes a zero-count check.
+  intx temp;
+  __asm__ volatile("        testl   %6,%6         ;"
+                   "        jz      7f            ;"
+                   "        cmpl    %4,%5         ;"
+                   "        leal    -4(%4,%6,4),%3;"
+                   "        jbe     1f            ;"
+                   "        cmpl    %7,%5         ;"
+                   "        jbe     4f            ;"
+                   "1:      cmpl    $32,%6        ;"
+                   "        ja      3f            ;"
+                   "        subl    %4,%1         ;"
+                   "2:      movl    (%4),%3       ;"
+                   "        movl    %7,(%5,%4,1)  ;"
+                   "        addl    $4,%0         ;"
+                   "        subl    $1,%2          ;"
+                   "        jnz     2b            ;"
+                   "        jmp     7f            ;"
+                   "3:      rep;    smovl         ;"
+                   "        jmp     7f            ;"
+                   "4:      cmpl    $32,%2        ;"
+                   "        movl    %7,%0         ;"
+                   "        leal    -4(%5,%6,4),%1;"
+                   "        ja      6f            ;"
+                   "        subl    %4,%1         ;"
+                   "5:      movl    (%4),%3       ;"
+                   "        movl    %7,(%5,%4,1)  ;"
+                   "        subl    $4,%0         ;"
+                   "        subl    $1,%2          ;"
+                   "        jnz     5b            ;"
+                   "        jmp     7f            ;"
+                   "6:      std                   ;"
+                   "        rep;    smovl         ;"
+                   "        cld                   ;"
+                   "7:      nop                    "
+                   : "=S" (from), "=D" (to), "=c" (count), "=r" (temp)
+                   : "0"  (from), "1"  (to), "2"  (count), "3"  (temp)
+                   : "memory", "flags");
+#endif // AMD64
+}
+
+static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
+#ifdef AMD64
+  switch (count) {
+  case 8:  to[7] = from[7];
+  case 7:  to[6] = from[6];
+  case 6:  to[5] = from[5];
+  case 5:  to[4] = from[4];
+  case 4:  to[3] = from[3];
+  case 3:  to[2] = from[2];
+  case 2:  to[1] = from[1];
+  case 1:  to[0] = from[0];
+  case 0:  break;
+  default:
+    (void)memcpy(to, from, count * HeapWordSize);
+    break;
+  }
+#else
+  // Includes a zero-count check.
+  intx temp;
+  __asm__ volatile("        testl   %6,%6       ;"
+                   "        jz      3f          ;"
+                   "        cmpl    $32,%6      ;"
+                   "        ja      2f          ;"
+                   "        subl    %4,%1       ;"
+                   "1:      movl    (%4),%3     ;"
+                   "        movl    %7,(%5,%4,1);"
+                   "        addl    $4,%0       ;"
+                   "        subl    $1,%2        ;"
+                   "        jnz     1b          ;"
+                   "        jmp     3f          ;"
+                   "2:      rep;    smovl       ;"
+                   "3:      nop                  "
+                   : "=S" (from), "=D" (to), "=c" (count), "=r" (temp)
+                   : "0"  (from), "1"  (to), "2"  (count), "3"  (temp)
+                   : "memory", "cc");
+#endif // AMD64
+}
+
+static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
+#ifdef AMD64
+  switch (count) {
+  case 8:  to[7] = from[7];
+  case 7:  to[6] = from[6];
+  case 6:  to[5] = from[5];
+  case 5:  to[4] = from[4];
+  case 4:  to[3] = from[3];
+  case 3:  to[2] = from[2];
+  case 2:  to[1] = from[1];
+  case 1:  to[0] = from[0];
+  case 0:  break;
+  default:
+    while (count-- > 0) {
+      *to++ = *from++;
+    }
+    break;
+  }
+#else
+  // pd_disjoint_words is word-atomic in this implementation.
+  pd_disjoint_words(from, to, count);
+#endif // AMD64
+}
+
+static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
+  pd_conjoint_words(from, to, count);
+}
+
+static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
+  pd_disjoint_words(from, to, count);
+}
+
+static void pd_conjoint_bytes(void* from, void* to, size_t count) {
+#ifdef AMD64
+  (void)memmove(to, from, count);
+#else
+  // Includes a zero-count check.
+  intx temp;
+  __asm__ volatile("        testl   %6,%6          ;"
+                   "        jz      13f            ;"
+                   "        cmpl    %4,%5          ;"
+                   "        leal    -1(%4,%6),%3   ;"
+                   "        jbe     1f             ;"
+                   "        cmpl    %7,%5          ;"
+                   "        jbe     8f             ;"
+                   "1:      cmpl    $3,%6          ;"
+                   "        jbe     6f             ;"
+                   "        movl    %6,%3          ;"
+                   "        movl    $4,%2          ;"
+                   "        subl    %4,%2          ;"
+                   "        andl    $3,%2          ;"
+                   "        jz      2f             ;"
+                   "        subl    %6,%3          ;"
+                   "        rep;    smovb          ;"
+                   "2:      movl    %7,%2          ;"
+                   "        shrl    $2,%2          ;"
+                   "        jz      5f             ;"
+                   "        cmpl    $32,%2         ;"
+                   "        ja      4f             ;"
+                   "        subl    %4,%1          ;"
+                   "3:      movl    (%4),%%edx     ;"
+                   "        movl    %%edx,(%5,%4,1);"
+                   "        addl    $4,%0          ;"
+                   "        subl    $1,%2           ;"
+                   "        jnz     3b             ;"
+                   "        addl    %4,%1          ;"
+                   "        jmp     5f             ;"
+                   "4:      rep;    smovl          ;"
+                   "5:      movl    %7,%2          ;"
+                   "        andl    $3,%2          ;"
+                   "        jz      13f            ;"
+                   "6:      xorl    %7,%3          ;"
+                   "7:      movb    (%4,%7,1),%%dl ;"
+                   "        movb    %%dl,(%5,%7,1) ;"
+                   "        addl    $1,%3          ;"
+                   "        subl    $1,%2           ;"
+                   "        jnz     7b             ;"
+                   "        jmp     13f            ;"
+                   "8:      std                    ;"
+                   "        cmpl    $12,%2         ;"
+                   "        ja      9f             ;"
+                   "        movl    %7,%0          ;"
+                   "        leal    -1(%6,%5),%1   ;"
+                   "        jmp     11f            ;"
+                   "9:      xchgl   %3,%2          ;"
+                   "        movl    %6,%0          ;"
+                   "        addl    $1,%2          ;"
+                   "        leal    -1(%7,%5),%1   ;"
+                   "        andl    $3,%2          ;"
+                   "        jz      10f            ;"
+                   "        subl    %6,%3          ;"
+                   "        rep;    smovb          ;"
+                   "10:     movl    %7,%2          ;"
+                   "        subl    $3,%0          ;"
+                   "        shrl    $2,%2          ;"
+                   "        subl    $3,%1          ;"
+                   "        rep;    smovl          ;"
+                   "        andl    $3,%3          ;"
+                   "        jz      12f            ;"
+                   "        movl    %7,%2          ;"
+                   "        addl    $3,%0          ;"
+                   "        addl    $3,%1          ;"
+                   "11:     rep;    smovb          ;"
+                   "12:     cld                    ;"
+                   "13:     nop                    ;"
+                   : "=S" (from), "=D" (to), "=c" (count), "=r" (temp)
+                   : "0"  (from), "1"  (to), "2"  (count), "3"  (temp)
+                   : "memory", "flags", "%edx");
+#endif // AMD64
+}
+
+static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
+  pd_conjoint_bytes(from, to, count);
+}
+
+static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
+  _Copy_conjoint_jshorts_atomic(from, to, count);
+}
+
+static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
+#ifdef AMD64
+  _Copy_conjoint_jints_atomic(from, to, count);
+#else
+  assert(HeapWordSize == BytesPerInt, "heapwords and jints must be the same size");
+  // pd_conjoint_words is word-atomic in this implementation.
+  pd_conjoint_words((HeapWord*)from, (HeapWord*)to, count);
+#endif // AMD64
+}
+
+static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
+#ifdef AMD64
+  _Copy_conjoint_jlongs_atomic(from, to, count);
+#else
+  // Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't.
+  if (from > to) {
+    while (count-- > 0) {
+      __asm__ volatile("fildll (%0); fistpll (%1)"
+                       :
+                       : "r" (from), "r" (to)
+                       : "memory" );
+      ++from;
+      ++to;
+    }
+  } else {
+    while (count-- > 0) {
+      __asm__ volatile("fildll (%0,%2,8); fistpll (%1,%2,8)"
+                       :
+                       : "r" (from), "r" (to), "r" (count)
+                       : "memory" );
+    }
+  }
+#endif // AMD64
+}
+
+static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
+#ifdef AMD64
+  assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
+  _Copy_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
+#else
+  assert(HeapWordSize == BytesPerOop, "heapwords and oops must be the same size");
+  // pd_conjoint_words is word-atomic in this implementation.
+  pd_conjoint_words((HeapWord*)from, (HeapWord*)to, count);
+#endif // AMD64
+}
+
+static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
+  _Copy_arrayof_conjoint_bytes(from, to, count);
+}
+
+static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
+  _Copy_arrayof_conjoint_jshorts(from, to, count);
+}
+
+static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
+#ifdef AMD64
+   _Copy_arrayof_conjoint_jints(from, to, count);
+#else
+  pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
+#endif // AMD64
+}
+
+static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
+#ifdef AMD64
+  _Copy_arrayof_conjoint_jlongs(from, to, count);
+#else
+  pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
+#endif // AMD64
+}
+
+static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
+#ifdef AMD64
+  assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
+  _Copy_arrayof_conjoint_jlongs(from, to, count);
+#else
+  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
+#endif // AMD64
+}
+
+#endif // OS_CPU_BSD_X86_VM_COPY_BSD_X86_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp b/hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp
new file mode 100644
index 0000000..9601188
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_GLOBALS_BSD_X86_HPP
+#define OS_CPU_BSD_X86_VM_GLOBALS_BSD_X86_HPP
+
+//
+// Sets the default values for platform dependent flags used by the runtime system.
+// (see globals.hpp)
+//
+define_pd_global(bool, DontYieldALot,            false);
+#ifdef AMD64
+define_pd_global(intx, ThreadStackSize,          1024); // 0 => use system default
+define_pd_global(intx, VMThreadStackSize,        1024);
+#else
+// ThreadStackSize 320 allows a couple of test cases to run while
+// keeping the number of threads that can be created high.  System
+// default ThreadStackSize appears to be 512 which is too big.
+define_pd_global(intx, ThreadStackSize,          320);
+define_pd_global(intx, VMThreadStackSize,        512);
+#endif // AMD64
+
+define_pd_global(intx, CompilerThreadStackSize,  0);
+define_pd_global(intx, SurvivorRatio,            8);
+
+define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
+
+// Only used on 64 bit platforms
+define_pd_global(uintx, HeapBaseMinAddress,      2*G);
+// Only used on 64 bit Windows platforms
+define_pd_global(bool, UseVectoredExceptions,    false);
+
+#endif // OS_CPU_BSD_X86_VM_GLOBALS_BSD_X86_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/orderAccess_bsd_x86.inline.hpp b/hotspot/src/os_cpu/bsd_x86/vm/orderAccess_bsd_x86.inline.hpp
new file mode 100644
index 0000000..eaecd9c
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/orderAccess_bsd_x86.inline.hpp
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_ORDERACCESS_BSD_X86_INLINE_HPP
+#define OS_CPU_BSD_X86_VM_ORDERACCESS_BSD_X86_INLINE_HPP
+
+#include "runtime/atomic.hpp"
+#include "runtime/orderAccess.hpp"
+#include "vm_version_x86.hpp"
+
+// Implementation of class OrderAccess.
+
+inline void OrderAccess::loadload()   { acquire(); }
+inline void OrderAccess::storestore() { release(); }
+inline void OrderAccess::loadstore()  { acquire(); }
+inline void OrderAccess::storeload()  { fence(); }
+
+inline void OrderAccess::acquire() {
+  volatile intptr_t local_dummy;
+#ifdef AMD64
+  __asm__ volatile ("movq 0(%%rsp), %0" : "=r" (local_dummy) : : "memory");
+#else
+  __asm__ volatile ("movl 0(%%esp),%0" : "=r" (local_dummy) : : "memory");
+#endif // AMD64
+}
+
+inline void OrderAccess::release() {
+  // Avoid hitting the same cache-line from
+  // different threads.
+  volatile jint local_dummy = 0;
+}
+
+inline void OrderAccess::fence() {
+  if (os::is_MP()) {
+    // always use locked addl since mfence is sometimes expensive
+#ifdef AMD64
+    __asm__ volatile ("lock; addl $0,0(%%rsp)" : : : "cc", "memory");
+#else
+    __asm__ volatile ("lock; addl $0,0(%%esp)" : : : "cc", "memory");
+#endif
+  }
+}
+
+inline jbyte    OrderAccess::load_acquire(volatile jbyte*   p) { return *p; }
+inline jshort   OrderAccess::load_acquire(volatile jshort*  p) { return *p; }
+inline jint     OrderAccess::load_acquire(volatile jint*    p) { return *p; }
+inline jlong    OrderAccess::load_acquire(volatile jlong*   p) { return Atomic::load(p); }
+inline jubyte   OrderAccess::load_acquire(volatile jubyte*  p) { return *p; }
+inline jushort  OrderAccess::load_acquire(volatile jushort* p) { return *p; }
+inline juint    OrderAccess::load_acquire(volatile juint*   p) { return *p; }
+inline julong   OrderAccess::load_acquire(volatile julong*  p) { return Atomic::load((volatile jlong*)p); }
+inline jfloat   OrderAccess::load_acquire(volatile jfloat*  p) { return *p; }
+inline jdouble  OrderAccess::load_acquire(volatile jdouble* p) { return *p; }
+
+inline intptr_t OrderAccess::load_ptr_acquire(volatile intptr_t*   p) { return *p; }
+inline void*    OrderAccess::load_ptr_acquire(volatile void*       p) { return *(void* volatile *)p; }
+inline void*    OrderAccess::load_ptr_acquire(const volatile void* p) { return *(void* const volatile *)p; }
+
+inline void     OrderAccess::release_store(volatile jbyte*   p, jbyte   v) { *p = v; }
+inline void     OrderAccess::release_store(volatile jshort*  p, jshort  v) { *p = v; }
+inline void     OrderAccess::release_store(volatile jint*    p, jint    v) { *p = v; }
+inline void     OrderAccess::release_store(volatile jlong*   p, jlong   v) { Atomic::store(v, p); }
+inline void     OrderAccess::release_store(volatile jubyte*  p, jubyte  v) { *p = v; }
+inline void     OrderAccess::release_store(volatile jushort* p, jushort v) { *p = v; }
+inline void     OrderAccess::release_store(volatile juint*   p, juint   v) { *p = v; }
+inline void     OrderAccess::release_store(volatile julong*  p, julong  v) { Atomic::store((jlong)v, (volatile jlong*)p); }
+inline void     OrderAccess::release_store(volatile jfloat*  p, jfloat  v) { *p = v; }
+inline void     OrderAccess::release_store(volatile jdouble* p, jdouble v) { *p = v; }
+
+inline void     OrderAccess::release_store_ptr(volatile intptr_t* p, intptr_t v) { *p = v; }
+inline void     OrderAccess::release_store_ptr(volatile void*     p, void*    v) { *(void* volatile *)p = v; }
+
+inline void     OrderAccess::store_fence(jbyte*  p, jbyte  v) {
+  __asm__ volatile (  "xchgb (%2),%0"
+                    : "=q" (v)
+                    : "0" (v), "r" (p)
+                    : "memory");
+}
+inline void     OrderAccess::store_fence(jshort* p, jshort v) {
+  __asm__ volatile (  "xchgw (%2),%0"
+                    : "=r" (v)
+                    : "0" (v), "r" (p)
+                    : "memory");
+}
+inline void     OrderAccess::store_fence(jint*   p, jint   v) {
+  __asm__ volatile (  "xchgl (%2),%0"
+                    : "=r" (v)
+                    : "0" (v), "r" (p)
+                    : "memory");
+}
+
+inline void     OrderAccess::store_fence(jlong*   p, jlong   v) {
+#ifdef AMD64
+  __asm__ __volatile__ ("xchgq (%2), %0"
+                        : "=r" (v)
+                        : "0" (v), "r" (p)
+                        : "memory");
+#else
+  *p = v; fence();
+#endif // AMD64
+}
+
+// AMD64 copied the bodies for the the signed version. 32bit did this. As long as the
+// compiler does the inlining this is simpler.
+inline void     OrderAccess::store_fence(jubyte*  p, jubyte  v) { store_fence((jbyte*)p,  (jbyte)v);  }
+inline void     OrderAccess::store_fence(jushort* p, jushort v) { store_fence((jshort*)p, (jshort)v); }
+inline void     OrderAccess::store_fence(juint*   p, juint   v) { store_fence((jint*)p,   (jint)v);   }
+inline void     OrderAccess::store_fence(julong*  p, julong  v) { store_fence((jlong*)p,  (jlong)v);  }
+inline void     OrderAccess::store_fence(jfloat*  p, jfloat  v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(jdouble* p, jdouble v) { *p = v; fence(); }
+
+inline void     OrderAccess::store_ptr_fence(intptr_t* p, intptr_t v) {
+#ifdef AMD64
+  __asm__ __volatile__ ("xchgq (%2), %0"
+                        : "=r" (v)
+                        : "0" (v), "r" (p)
+                        : "memory");
+#else
+  store_fence((jint*)p, (jint)v);
+#endif // AMD64
+}
+
+inline void     OrderAccess::store_ptr_fence(void**    p, void*    v) {
+#ifdef AMD64
+  __asm__ __volatile__ ("xchgq (%2), %0"
+                        : "=r" (v)
+                        : "0" (v), "r" (p)
+                        : "memory");
+#else
+  store_fence((jint*)p, (jint)v);
+#endif // AMD64
+}
+
+// Must duplicate definitions instead of calling store_fence because we don't want to cast away volatile.
+inline void     OrderAccess::release_store_fence(volatile jbyte*  p, jbyte  v) {
+  __asm__ volatile (  "xchgb (%2),%0"
+                    : "=q" (v)
+                    : "0" (v), "r" (p)
+                    : "memory");
+}
+inline void     OrderAccess::release_store_fence(volatile jshort* p, jshort v) {
+  __asm__ volatile (  "xchgw (%2),%0"
+                    : "=r" (v)
+                    : "0" (v), "r" (p)
+                    : "memory");
+}
+inline void     OrderAccess::release_store_fence(volatile jint*   p, jint   v) {
+  __asm__ volatile (  "xchgl (%2),%0"
+                    : "=r" (v)
+                    : "0" (v), "r" (p)
+                    : "memory");
+}
+
+inline void     OrderAccess::release_store_fence(volatile jlong*   p, jlong   v) {
+#ifdef AMD64
+  __asm__ __volatile__ (  "xchgq (%2), %0"
+                          : "=r" (v)
+                          : "0" (v), "r" (p)
+                          : "memory");
+#else
+  release_store(p, v); fence();
+#endif // AMD64
+}
+
+inline void     OrderAccess::release_store_fence(volatile jubyte*  p, jubyte  v) { release_store_fence((volatile jbyte*)p,  (jbyte)v);  }
+inline void     OrderAccess::release_store_fence(volatile jushort* p, jushort v) { release_store_fence((volatile jshort*)p, (jshort)v); }
+inline void     OrderAccess::release_store_fence(volatile juint*   p, juint   v) { release_store_fence((volatile jint*)p,   (jint)v);   }
+inline void     OrderAccess::release_store_fence(volatile julong*  p, julong  v) { release_store_fence((volatile jlong*)p,  (jlong)v);  }
+
+inline void     OrderAccess::release_store_fence(volatile jfloat*  p, jfloat  v) { *p = v; fence(); }
+inline void     OrderAccess::release_store_fence(volatile jdouble* p, jdouble v) { *p = v; fence(); }
+
+inline void     OrderAccess::release_store_ptr_fence(volatile intptr_t* p, intptr_t v) {
+#ifdef AMD64
+  __asm__ __volatile__ (  "xchgq (%2), %0"
+                          : "=r" (v)
+                          : "0" (v), "r" (p)
+                          : "memory");
+#else
+  release_store_fence((volatile jint*)p, (jint)v);
+#endif // AMD64
+}
+inline void     OrderAccess::release_store_ptr_fence(volatile void*     p, void*    v) {
+#ifdef AMD64
+  __asm__ __volatile__ (  "xchgq (%2), %0"
+                          : "=r" (v)
+                          : "0" (v), "r" (p)
+                          : "memory");
+#else
+  release_store_fence((volatile jint*)p, (jint)v);
+#endif // AMD64
+}
+
+#endif // OS_CPU_BSD_X86_VM_ORDERACCESS_BSD_X86_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
new file mode 100644
index 0000000..df67421
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
@@ -0,0 +1,1128 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+// no precompiled headers
+#include "assembler_x86.inline.hpp"
+#include "classfile/classLoader.hpp"
+#include "classfile/systemDictionary.hpp"
+#include "classfile/vmSymbols.hpp"
+#include "code/icBuffer.hpp"
+#include "code/vtableStubs.hpp"
+#include "interpreter/interpreter.hpp"
+#include "jvm_bsd.h"
+#include "memory/allocation.inline.hpp"
+#include "mutex_bsd.inline.hpp"
+#include "nativeInst_x86.hpp"
+#include "os_share_bsd.hpp"
+#include "prims/jniFastGetField.hpp"
+#include "prims/jvm.h"
+#include "prims/jvm_misc.hpp"
+#include "runtime/arguments.hpp"
+#include "runtime/extendedPC.hpp"
+#include "runtime/frame.inline.hpp"
+#include "runtime/interfaceSupport.hpp"
+#include "runtime/java.hpp"
+#include "runtime/javaCalls.hpp"
+#include "runtime/mutexLocker.hpp"
+#include "runtime/osThread.hpp"
+#include "runtime/sharedRuntime.hpp"
+#include "runtime/stubRoutines.hpp"
+#include "runtime/timer.hpp"
+#include "thread_bsd.inline.hpp"
+#include "utilities/events.hpp"
+#include "utilities/vmError.hpp"
+#ifdef COMPILER1
+#include "c1/c1_Runtime1.hpp"
+#endif
+#ifdef COMPILER2
+#include "opto/runtime.hpp"
+#endif
+
+// put OS-includes here
+# include <sys/types.h>
+# include <sys/mman.h>
+# include <pthread.h>
+# include <signal.h>
+# include <errno.h>
+# include <dlfcn.h>
+# include <stdlib.h>
+# include <stdio.h>
+# include <unistd.h>
+# include <sys/resource.h>
+# include <pthread.h>
+# include <sys/stat.h>
+# include <sys/time.h>
+# include <sys/utsname.h>
+# include <sys/socket.h>
+# include <sys/wait.h>
+# include <pwd.h>
+# include <poll.h>
+#ifndef __OpenBSD__
+# include <ucontext.h>
+#endif
+
+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__)
+# include <pthread_np.h>
+#endif
+
+#ifdef AMD64
+#define SPELL_REG_SP "rsp"
+#define SPELL_REG_FP "rbp"
+#else
+#define SPELL_REG_SP "esp"
+#define SPELL_REG_FP "ebp"
+#endif // AMD64
+
+#ifdef __FreeBSD__
+# define context_trapno uc_mcontext.mc_trapno
+# ifdef AMD64
+#  define context_pc uc_mcontext.mc_rip
+#  define context_sp uc_mcontext.mc_rsp
+#  define context_fp uc_mcontext.mc_rbp
+#  define context_rip uc_mcontext.mc_rip
+#  define context_rsp uc_mcontext.mc_rsp
+#  define context_rbp uc_mcontext.mc_rbp
+#  define context_rax uc_mcontext.mc_rax
+#  define context_rbx uc_mcontext.mc_rbx
+#  define context_rcx uc_mcontext.mc_rcx
+#  define context_rdx uc_mcontext.mc_rdx
+#  define context_rsi uc_mcontext.mc_rsi
+#  define context_rdi uc_mcontext.mc_rdi
+#  define context_r8  uc_mcontext.mc_r8
+#  define context_r9  uc_mcontext.mc_r9
+#  define context_r10 uc_mcontext.mc_r10
+#  define context_r11 uc_mcontext.mc_r11
+#  define context_r12 uc_mcontext.mc_r12
+#  define context_r13 uc_mcontext.mc_r13
+#  define context_r14 uc_mcontext.mc_r14
+#  define context_r15 uc_mcontext.mc_r15
+#  define context_flags uc_mcontext.mc_flags
+#  define context_err uc_mcontext.mc_err
+# else
+#  define context_pc uc_mcontext.mc_eip
+#  define context_sp uc_mcontext.mc_esp
+#  define context_fp uc_mcontext.mc_ebp
+#  define context_eip uc_mcontext.mc_eip
+#  define context_esp uc_mcontext.mc_esp
+#  define context_eax uc_mcontext.mc_eax
+#  define context_ebx uc_mcontext.mc_ebx
+#  define context_ecx uc_mcontext.mc_ecx
+#  define context_edx uc_mcontext.mc_edx
+#  define context_ebp uc_mcontext.mc_ebp
+#  define context_esi uc_mcontext.mc_esi
+#  define context_edi uc_mcontext.mc_edi
+#  define context_eflags uc_mcontext.mc_eflags
+#  define context_trapno uc_mcontext.mc_trapno
+# endif
+#endif
+
+#ifdef __APPLE__
+# if __DARWIN_UNIX03 && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
+  // 10.5 UNIX03 member name prefixes
+  #define DU3_PREFIX(s, m) __ ## s.__ ## m
+# else
+  #define DU3_PREFIX(s, m) s ## . ## m
+# endif
+
+# ifdef AMD64
+#  define context_pc context_rip
+#  define context_sp context_rsp
+#  define context_fp context_rbp
+#  define context_rip uc_mcontext->DU3_PREFIX(ss,rip)
+#  define context_rsp uc_mcontext->DU3_PREFIX(ss,rsp)
+#  define context_rax uc_mcontext->DU3_PREFIX(ss,rax)
+#  define context_rbx uc_mcontext->DU3_PREFIX(ss,rbx)
+#  define context_rcx uc_mcontext->DU3_PREFIX(ss,rcx)
+#  define context_rdx uc_mcontext->DU3_PREFIX(ss,rdx)
+#  define context_rbp uc_mcontext->DU3_PREFIX(ss,rbp)
+#  define context_rsi uc_mcontext->DU3_PREFIX(ss,rsi)
+#  define context_rdi uc_mcontext->DU3_PREFIX(ss,rdi)
+#  define context_r8  uc_mcontext->DU3_PREFIX(ss,r8)
+#  define context_r9  uc_mcontext->DU3_PREFIX(ss,r9)
+#  define context_r10 uc_mcontext->DU3_PREFIX(ss,r10)
+#  define context_r11 uc_mcontext->DU3_PREFIX(ss,r11)
+#  define context_r12 uc_mcontext->DU3_PREFIX(ss,r12)
+#  define context_r13 uc_mcontext->DU3_PREFIX(ss,r13)
+#  define context_r14 uc_mcontext->DU3_PREFIX(ss,r14)
+#  define context_r15 uc_mcontext->DU3_PREFIX(ss,r15)
+#  define context_flags uc_mcontext->DU3_PREFIX(ss,rflags)
+#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
+#  define context_err uc_mcontext->DU3_PREFIX(es,err)
+# else
+#  define context_pc context_eip
+#  define context_sp context_esp
+#  define context_fp context_ebp
+#  define context_eip uc_mcontext->DU3_PREFIX(ss,eip)
+#  define context_esp uc_mcontext->DU3_PREFIX(ss,esp)
+#  define context_eax uc_mcontext->DU3_PREFIX(ss,eax)
+#  define context_ebx uc_mcontext->DU3_PREFIX(ss,ebx)
+#  define context_ecx uc_mcontext->DU3_PREFIX(ss,ecx)
+#  define context_edx uc_mcontext->DU3_PREFIX(ss,edx)
+#  define context_ebp uc_mcontext->DU3_PREFIX(ss,ebp)
+#  define context_esi uc_mcontext->DU3_PREFIX(ss,esi)
+#  define context_edi uc_mcontext->DU3_PREFIX(ss,edi)
+#  define context_eflags uc_mcontext->DU3_PREFIX(ss,eflags)
+#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
+# endif
+#endif
+
+#ifdef __OpenBSD__
+# define context_trapno sc_trapno
+# ifdef AMD64
+#  define context_pc sc_rip
+#  define context_sp sc_rsp
+#  define context_fp sc_rbp
+#  define context_rip sc_rip
+#  define context_rsp sc_rsp
+#  define context_rbp sc_rbp
+#  define context_rax sc_rax
+#  define context_rbx sc_rbx
+#  define context_rcx sc_rcx
+#  define context_rdx sc_rdx
+#  define context_rsi sc_rsi
+#  define context_rdi sc_rdi
+#  define context_r8  sc_r8
+#  define context_r9  sc_r9
+#  define context_r10 sc_r10
+#  define context_r11 sc_r11
+#  define context_r12 sc_r12
+#  define context_r13 sc_r13
+#  define context_r14 sc_r14
+#  define context_r15 sc_r15
+#  define context_flags sc_rflags
+#  define context_err sc_err
+# else
+#  define context_pc sc_eip
+#  define context_sp sc_esp
+#  define context_fp sc_ebp
+#  define context_eip sc_eip
+#  define context_esp sc_esp
+#  define context_eax sc_eax
+#  define context_ebx sc_ebx
+#  define context_ecx sc_ecx
+#  define context_edx sc_edx
+#  define context_ebp sc_ebp
+#  define context_esi sc_esi
+#  define context_edi sc_edi
+#  define context_eflags sc_eflags
+#  define context_trapno sc_trapno
+# endif
+#endif
+
+#ifdef __NetBSD__
+# define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
+# ifdef AMD64
+#  define __register_t __greg_t
+#  define context_pc uc_mcontext.__gregs[_REG_RIP]
+#  define context_sp uc_mcontext.__gregs[_REG_URSP]
+#  define context_fp uc_mcontext.__gregs[_REG_RBP]
+#  define context_rip uc_mcontext.__gregs[_REG_RIP]
+#  define context_rsp uc_mcontext.__gregs[_REG_URSP]
+#  define context_rax uc_mcontext.__gregs[_REG_RAX]
+#  define context_rbx uc_mcontext.__gregs[_REG_RBX]
+#  define context_rcx uc_mcontext.__gregs[_REG_RCX]
+#  define context_rdx uc_mcontext.__gregs[_REG_RDX]
+#  define context_rbp uc_mcontext.__gregs[_REG_RBP]
+#  define context_rsi uc_mcontext.__gregs[_REG_RSI]
+#  define context_rdi uc_mcontext.__gregs[_REG_RDI]
+#  define context_r8  uc_mcontext.__gregs[_REG_R8]
+#  define context_r9  uc_mcontext.__gregs[_REG_R9]
+#  define context_r10 uc_mcontext.__gregs[_REG_R10]
+#  define context_r11 uc_mcontext.__gregs[_REG_R11]
+#  define context_r12 uc_mcontext.__gregs[_REG_R12]
+#  define context_r13 uc_mcontext.__gregs[_REG_R13]
+#  define context_r14 uc_mcontext.__gregs[_REG_R14]
+#  define context_r15 uc_mcontext.__gregs[_REG_R15]
+#  define context_flags uc_mcontext.__gregs[_REG_RFL]
+#  define context_err uc_mcontext.__gregs[_REG_ERR]
+# else
+#  define context_pc uc_mcontext.__gregs[_REG_EIP]
+#  define context_sp uc_mcontext.__gregs[_REG_UESP]
+#  define context_fp uc_mcontext.__gregs[_REG_EBP]
+#  define context_eip uc_mcontext.__gregs[_REG_EIP]
+#  define context_esp uc_mcontext.__gregs[_REG_UESP]
+#  define context_eax uc_mcontext.__gregs[_REG_EAX]
+#  define context_ebx uc_mcontext.__gregs[_REG_EBX]
+#  define context_ecx uc_mcontext.__gregs[_REG_ECX]
+#  define context_edx uc_mcontext.__gregs[_REG_EDX]
+#  define context_ebp uc_mcontext.__gregs[_REG_EBP]
+#  define context_esi uc_mcontext.__gregs[_REG_ESI]
+#  define context_edi uc_mcontext.__gregs[_REG_EDI]
+#  define context_eflags uc_mcontext.__gregs[_REG_EFL]
+#  define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
+# endif
+#endif
+
+address os::current_stack_pointer() {
+#if defined(__clang__) || defined(__llvm__)
+  register void *esp;
+  __asm__("mov %%"SPELL_REG_SP", %0":"=r"(esp));
+  return (address) esp;
+#elif defined(SPARC_WORKS)
+  register void *esp;
+  __asm__("mov %%"SPELL_REG_SP", %0":"=r"(esp));
+  return (address) ((char*)esp + sizeof(long)*2);
+#else
+  register void *esp __asm__ (SPELL_REG_SP);
+  return (address) esp;
+#endif
+}
+
+char* os::non_memory_address_word() {
+  // Must never look like an address returned by reserve_memory,
+  // even in its subfields (as defined by the CPU immediate fields,
+  // if the CPU splits constants across multiple instructions).
+
+  return (char*) -1;
+}
+
+void os::initialize_thread() {
+// Nothing to do.
+}
+
+address os::Bsd::ucontext_get_pc(ucontext_t * uc) {
+  return (address)uc->context_pc;
+}
+
+intptr_t* os::Bsd::ucontext_get_sp(ucontext_t * uc) {
+  return (intptr_t*)uc->context_sp;
+}
+
+intptr_t* os::Bsd::ucontext_get_fp(ucontext_t * uc) {
+  return (intptr_t*)uc->context_fp;
+}
+
+// For Forte Analyzer AsyncGetCallTrace profiling support - thread
+// is currently interrupted by SIGPROF.
+// os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
+// frames. Currently we don't do that on Bsd, so it's the same as
+// os::fetch_frame_from_context().
+ExtendedPC os::Bsd::fetch_frame_from_ucontext(Thread* thread,
+  ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
+
+  assert(thread != NULL, "just checking");
+  assert(ret_sp != NULL, "just checking");
+  assert(ret_fp != NULL, "just checking");
+
+  return os::fetch_frame_from_context(uc, ret_sp, ret_fp);
+}
+
+ExtendedPC os::fetch_frame_from_context(void* ucVoid,
+                    intptr_t** ret_sp, intptr_t** ret_fp) {
+
+  ExtendedPC  epc;
+  ucontext_t* uc = (ucontext_t*)ucVoid;
+
+  if (uc != NULL) {
+    epc = ExtendedPC(os::Bsd::ucontext_get_pc(uc));
+    if (ret_sp) *ret_sp = os::Bsd::ucontext_get_sp(uc);
+    if (ret_fp) *ret_fp = os::Bsd::ucontext_get_fp(uc);
+  } else {
+    // construct empty ExtendedPC for return value checking
+    epc = ExtendedPC(NULL);
+    if (ret_sp) *ret_sp = (intptr_t *)NULL;
+    if (ret_fp) *ret_fp = (intptr_t *)NULL;
+  }
+
+  return epc;
+}
+
+frame os::fetch_frame_from_context(void* ucVoid) {
+  intptr_t* sp;
+  intptr_t* fp;
+  ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
+  return frame(sp, fp, epc.pc());
+}
+
+// By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get
+// turned off by -fomit-frame-pointer,
+frame os::get_sender_for_C_frame(frame* fr) {
+  return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
+}
+
+intptr_t* _get_previous_fp() {
+#if defined(SPARC_WORKS) || defined(__clang__)
+  register intptr_t **ebp;
+  __asm__("mov %%"SPELL_REG_FP", %0":"=r"(ebp));
+#else
+  register intptr_t **ebp __asm__ (SPELL_REG_FP);
+#endif
+  return (intptr_t*) *ebp;   // we want what it points to.
+}
+
+
+frame os::current_frame() {
+  intptr_t* fp = _get_previous_fp();
+  frame myframe((intptr_t*)os::current_stack_pointer(),
+                (intptr_t*)fp,
+                CAST_FROM_FN_PTR(address, os::current_frame));
+  if (os::is_first_C_frame(&myframe)) {
+    // stack is not walkable
+    return frame(NULL, NULL, NULL);
+  } else {
+    return os::get_sender_for_C_frame(&myframe);
+  }
+}
+
+// Utility functions
+
+// From IA32 System Programming Guide
+enum {
+  trap_page_fault = 0xE
+};
+
+extern "C" void Fetch32PFI () ;
+extern "C" void Fetch32Resume () ;
+#ifdef AMD64
+extern "C" void FetchNPFI () ;
+extern "C" void FetchNResume () ;
+#endif // AMD64
+
+extern "C" JNIEXPORT int
+JVM_handle_bsd_signal(int sig,
+                        siginfo_t* info,
+                        void* ucVoid,
+                        int abort_if_unrecognized) {
+  ucontext_t* uc = (ucontext_t*) ucVoid;
+
+  Thread* t = ThreadLocalStorage::get_thread_slow();
+
+  SignalHandlerMark shm(t);
+
+  // Note: it's not uncommon that JNI code uses signal/sigset to install
+  // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
+  // or have a SIGILL handler when detecting CPU type). When that happens,
+  // JVM_handle_bsd_signal() might be invoked with junk info/ucVoid. To
+  // avoid unnecessary crash when libjsig is not preloaded, try handle signals
+  // that do not require siginfo/ucontext first.
+
+  if (sig == SIGPIPE || sig == SIGXFSZ) {
+    // allow chained handler to go first
+    if (os::Bsd::chained_handler(sig, info, ucVoid)) {
+      return true;
+    } else {
+      if (PrintMiscellaneous && (WizardMode || Verbose)) {
+        char buf[64];
+        warning("Ignoring %s - see bugs 4229104 or 646499219",
+                os::exception_name(sig, buf, sizeof(buf)));
+      }
+      return true;
+    }
+  }
+
+  JavaThread* thread = NULL;
+  VMThread* vmthread = NULL;
+  if (os::Bsd::signal_handlers_are_installed) {
+    if (t != NULL ){
+      if(t->is_Java_thread()) {
+        thread = (JavaThread*)t;
+      }
+      else if(t->is_VM_thread()){
+        vmthread = (VMThread *)t;
+      }
+    }
+  }
+/*
+  NOTE: does not seem to work on bsd.
+  if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
+    // can't decode this kind of signal
+    info = NULL;
+  } else {
+    assert(sig == info->si_signo, "bad siginfo");
+  }
+*/
+  // decide if this trap can be handled by a stub
+  address stub = NULL;
+
+  address pc          = NULL;
+
+  //%note os_trap_1
+  if (info != NULL && uc != NULL && thread != NULL) {
+    pc = (address) os::Bsd::ucontext_get_pc(uc);
+
+    if (pc == (address) Fetch32PFI) {
+       uc->context_pc = intptr_t(Fetch32Resume) ;
+       return 1 ;
+    }
+#ifdef AMD64
+    if (pc == (address) FetchNPFI) {
+       uc->context_pc = intptr_t (FetchNResume) ;
+       return 1 ;
+    }
+#endif // AMD64
+
+    // Handle ALL stack overflow variations here
+    if (sig == SIGSEGV || sig == SIGBUS) {
+      address addr = (address) info->si_addr;
+
+      // check if fault address is within thread stack
+      if (addr < thread->stack_base() &&
+          addr >= thread->stack_base() - thread->stack_size()) {
+        // stack overflow
+        if (thread->in_stack_yellow_zone(addr)) {
+          thread->disable_stack_yellow_zone();
+          if (thread->thread_state() == _thread_in_Java) {
+            // Throw a stack overflow exception.  Guard pages will be reenabled
+            // while unwinding the stack.
+            stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
+          } else {
+            // Thread was in the vm or native code.  Return and try to finish.
+            return 1;
+          }
+        } else if (thread->in_stack_red_zone(addr)) {
+          // Fatal red zone violation.  Disable the guard pages and fall through
+          // to handle_unexpected_exception way down below.
+          thread->disable_stack_red_zone();
+          tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
+#ifndef _ALLBSD_SOURCE
+        } else {
+          // Accessing stack address below sp may cause SEGV if current
+          // thread has MAP_GROWSDOWN stack. This should only happen when
+          // current thread was created by user code with MAP_GROWSDOWN flag
+          // and then attached to VM. See notes in os_bsd.cpp.
+          if (thread->osthread()->expanding_stack() == 0) {
+             thread->osthread()->set_expanding_stack();
+             if (os::Bsd::manually_expand_stack(thread, addr)) {
+               thread->osthread()->clear_expanding_stack();
+               return 1;
+             }
+             thread->osthread()->clear_expanding_stack();
+          } else {
+             fatal("recursive segv. expanding stack.");
+          }
+#endif
+        }
+      }
+    }
+
+    if (thread->thread_state() == _thread_in_Java) {
+      // Java thread running in Java code => find exception handler if any
+      // a fault inside compiled code, the interpreter, or a stub
+
+      if ((sig == SIGSEGV || sig == SIGBUS) && os::is_poll_address((address)info->si_addr)) {
+        stub = SharedRuntime::get_poll_stub(pc);
+#if defined(__APPLE__) && !defined(AMD64)
+      // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
+      // Catching SIGBUS here prevents the implicit SIGBUS NULL check below from
+      // being called, so only do so if the implicit NULL check is not necessary.
+      } else if (sig == SIGBUS && MacroAssembler::needs_explicit_null_check((int)info->si_addr)) {
+#else
+      } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
+#endif
+        // BugId 4454115: A read from a MappedByteBuffer can fault
+        // here if the underlying file has been truncated.
+        // Do not crash the VM in such a case.
+        CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
+        nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
+        if (nm != NULL && nm->has_unsafe_access()) {
+          stub = StubRoutines::handler_for_unsafe_access();
+        }
+      }
+      else
+
+#ifdef AMD64
+      if (sig == SIGFPE  &&
+          (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
+        stub =
+          SharedRuntime::
+          continuation_for_implicit_exception(thread,
+                                              pc,
+                                              SharedRuntime::
+                                              IMPLICIT_DIVIDE_BY_ZERO);
+#ifdef __APPLE__
+      } else if (sig == SIGFPE && info->si_code == FPE_NOOP) {
+        int op = pc[0];
+
+        // Skip REX
+        if ((pc[0] & 0xf0) == 0x40) {
+          op = pc[1];
+        } else {
+          op = pc[0];
+        }
+
+        // Check for IDIV
+        if (op == 0xF7) {
+          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime:: IMPLICIT_DIVIDE_BY_ZERO);
+        } else {
+          // TODO: handle more cases if we are using other x86 instructions
+          //   that can generate SIGFPE signal.
+          tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
+          fatal("please update this code.");
+        }
+#endif /* __APPLE__ */
+
+#else
+      if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
+        // HACK: si_code does not work on bsd 2.2.12-20!!!
+        int op = pc[0];
+        if (op == 0xDB) {
+          // FIST
+          // TODO: The encoding of D2I in i486.ad can cause an exception
+          // prior to the fist instruction if there was an invalid operation
+          // pending. We want to dismiss that exception. From the win_32
+          // side it also seems that if it really was the fist causing
+          // the exception that we do the d2i by hand with different
+          // rounding. Seems kind of weird.
+          // NOTE: that we take the exception at the NEXT floating point instruction.
+          assert(pc[0] == 0xDB, "not a FIST opcode");
+          assert(pc[1] == 0x14, "not a FIST opcode");
+          assert(pc[2] == 0x24, "not a FIST opcode");
+          return true;
+        } else if (op == 0xF7) {
+          // IDIV
+          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
+        } else {
+          // TODO: handle more cases if we are using other x86 instructions
+          //   that can generate SIGFPE signal on bsd.
+          tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
+          fatal("please update this code.");
+        }
+#endif // AMD64
+      } else if ((sig == SIGSEGV || sig == SIGBUS) &&
+               !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
+          // Determination of interpreter/vtable stub/compiled code null exception
+          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
+      }
+    } else if (thread->thread_state() == _thread_in_vm &&
+               sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
+               thread->doing_unsafe_access()) {
+        stub = StubRoutines::handler_for_unsafe_access();
+    }
+
+    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
+    // and the heap gets shrunk before the field access.
+    if ((sig == SIGSEGV) || (sig == SIGBUS)) {
+      address addr = JNI_FastGetField::find_slowcase_pc(pc);
+      if (addr != (address)-1) {
+        stub = addr;
+      }
+    }
+
+    // Check to see if we caught the safepoint code in the
+    // process of write protecting the memory serialization page.
+    // It write enables the page immediately after protecting it
+    // so we can just return to retry the write.
+    if ((sig == SIGSEGV || sig == SIGBUS) &&
+        os::is_memory_serialize_page(thread, (address) info->si_addr)) {
+      // Block current thread until the memory serialize page permission restored.
+      os::block_on_serialize_page_trap();
+      return true;
+    }
+  }
+
+#ifndef AMD64
+  // Execution protection violation
+  //
+  // This should be kept as the last step in the triage.  We don't
+  // have a dedicated trap number for a no-execute fault, so be
+  // conservative and allow other handlers the first shot.
+  //
+  // Note: We don't test that info->si_code == SEGV_ACCERR here.
+  // this si_code is so generic that it is almost meaningless; and
+  // the si_code for this condition may change in the future.
+  // Furthermore, a false-positive should be harmless.
+  if (UnguardOnExecutionViolation > 0 &&
+      (sig == SIGSEGV || sig == SIGBUS) &&
+      uc->context_trapno == trap_page_fault) {
+    int page_size = os::vm_page_size();
+    address addr = (address) info->si_addr;
+    address pc = os::Bsd::ucontext_get_pc(uc);
+    // Make sure the pc and the faulting address are sane.
+    //
+    // If an instruction spans a page boundary, and the page containing
+    // the beginning of the instruction is executable but the following
+    // page is not, the pc and the faulting address might be slightly
+    // different - we still want to unguard the 2nd page in this case.
+    //
+    // 15 bytes seems to be a (very) safe value for max instruction size.
+    bool pc_is_near_addr =
+      (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
+    bool instr_spans_page_boundary =
+      (align_size_down((intptr_t) pc ^ (intptr_t) addr,
+                       (intptr_t) page_size) > 0);
+
+    if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
+      static volatile address last_addr =
+        (address) os::non_memory_address_word();
+
+      // In conservative mode, don't unguard unless the address is in the VM
+      if (addr != last_addr &&
+          (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
+
+        // Set memory to RWX and retry
+        address page_start =
+          (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
+        bool res = os::protect_memory((char*) page_start, page_size,
+                                      os::MEM_PROT_RWX);
+
+        if (PrintMiscellaneous && Verbose) {
+          char buf[256];
+          jio_snprintf(buf, sizeof(buf), "Execution protection violation "
+                       "at " INTPTR_FORMAT
+                       ", unguarding " INTPTR_FORMAT ": %s, errno=%d", addr,
+                       page_start, (res ? "success" : "failed"), errno);
+          tty->print_raw_cr(buf);
+        }
+        stub = pc;
+
+        // Set last_addr so if we fault again at the same address, we don't end
+        // up in an endless loop.
+        //
+        // There are two potential complications here.  Two threads trapping at
+        // the same address at the same time could cause one of the threads to
+        // think it already unguarded, and abort the VM.  Likely very rare.
+        //
+        // The other race involves two threads alternately trapping at
+        // different addresses and failing to unguard the page, resulting in
+        // an endless loop.  This condition is probably even more unlikely than
+        // the first.
+        //
+        // Although both cases could be avoided by using locks or thread local
+        // last_addr, these solutions are unnecessary complication: this
+        // handler is a best-effort safety net, not a complete solution.  It is
+        // disabled by default and should only be used as a workaround in case
+        // we missed any no-execute-unsafe VM code.
+
+        last_addr = addr;
+      }
+    }
+  }
+#endif // !AMD64
+
+  if (stub != NULL) {
+    // save all thread context in case we need to restore it
+    if (thread != NULL) thread->set_saved_exception_pc(pc);
+
+    uc->context_pc = (intptr_t)stub;
+    return true;
+  }
+
+  // signal-chaining
+  if (os::Bsd::chained_handler(sig, info, ucVoid)) {
+     return true;
+  }
+
+  if (!abort_if_unrecognized) {
+    // caller wants another chance, so give it to him
+    return false;
+  }
+
+  if (pc == NULL && uc != NULL) {
+    pc = os::Bsd::ucontext_get_pc(uc);
+  }
+
+  // unmask current signal
+  sigset_t newset;
+  sigemptyset(&newset);
+  sigaddset(&newset, sig);
+  sigprocmask(SIG_UNBLOCK, &newset, NULL);
+
+  VMError err(t, sig, pc, info, ucVoid);
+  err.report_and_die();
+
+  ShouldNotReachHere();
+}
+
+#ifdef _ALLBSD_SOURCE
+// From solaris_i486.s ported to bsd_i486.s
+extern "C" void fixcw();
+#endif
+
+void os::Bsd::init_thread_fpu_state(void) {
+#ifndef AMD64
+# ifdef _ALLBSD_SOURCE
+  // Set fpu to 53 bit precision. This happens too early to use a stub.
+  fixcw();
+# else
+  // set fpu to 53 bit precision
+  set_fpu_control_word(0x27f);
+# endif
+#endif // !AMD64
+}
+
+#ifndef _ALLBSD_SOURCE
+int os::Bsd::get_fpu_control_word(void) {
+#ifdef AMD64
+  return 0;
+#else
+  int fpu_control;
+  _FPU_GETCW(fpu_control);
+  return fpu_control & 0xffff;
+#endif // AMD64
+}
+
+void os::Bsd::set_fpu_control_word(int fpu_control) {
+#ifndef AMD64
+  _FPU_SETCW(fpu_control);
+#endif // !AMD64
+}
+#endif
+
+// Check that the bsd kernel version is 2.4 or higher since earlier
+// versions do not support SSE without patches.
+bool os::supports_sse() {
+#if defined(AMD64) || defined(_ALLBSD_SOURCE)
+  return true;
+#else
+  struct utsname uts;
+  if( uname(&uts) != 0 ) return false; // uname fails?
+  char *minor_string;
+  int major = strtol(uts.release,&minor_string,10);
+  int minor = strtol(minor_string+1,NULL,10);
+  bool result = (major > 2 || (major==2 && minor >= 4));
+#ifndef PRODUCT
+  if (PrintMiscellaneous && Verbose) {
+    tty->print("OS version is %d.%d, which %s support SSE/SSE2\n",
+               major,minor, result ? "DOES" : "does NOT");
+  }
+#endif
+  return result;
+#endif // AMD64
+}
+
+bool os::is_allocatable(size_t bytes) {
+#ifdef AMD64
+  // unused on amd64?
+  return true;
+#else
+
+  if (bytes < 2 * G) {
+    return true;
+  }
+
+  char* addr = reserve_memory(bytes, NULL);
+
+  if (addr != NULL) {
+    release_memory(addr, bytes);
+  }
+
+  return addr != NULL;
+#endif // AMD64
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// thread stack
+
+#ifdef AMD64
+size_t os::Bsd::min_stack_allowed  = 64 * K;
+
+// amd64: pthread on amd64 is always in floating stack mode
+bool os::Bsd::supports_variable_stack_size() {  return true; }
+#else
+size_t os::Bsd::min_stack_allowed  =  (48 DEBUG_ONLY(+4))*K;
+
+#ifdef __GNUC__
+#define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
+#endif
+
+#ifdef _ALLBSD_SOURCE
+bool os::Bsd::supports_variable_stack_size() { return true; }
+#else
+// Test if pthread library can support variable thread stack size. BsdThreads
+// in fixed stack mode allocates 2M fixed slot for each thread. BsdThreads
+// in floating stack mode and NPTL support variable stack size.
+bool os::Bsd::supports_variable_stack_size() {
+  if (os::Bsd::is_NPTL()) {
+     // NPTL, yes
+     return true;
+
+  } else {
+    // Note: We can't control default stack size when creating a thread.
+    // If we use non-default stack size (pthread_attr_setstacksize), both
+    // floating stack and non-floating stack BsdThreads will return the
+    // same value. This makes it impossible to implement this function by
+    // detecting thread stack size directly.
+    //
+    // An alternative approach is to check %gs. Fixed-stack BsdThreads
+    // do not use %gs, so its value is 0. Floating-stack BsdThreads use
+    // %gs (either as LDT selector or GDT selector, depending on kernel)
+    // to access thread specific data.
+    //
+    // Note that %gs is a reserved glibc register since early 2001, so
+    // applications are not allowed to change its value (Ulrich Drepper from
+    // Redhat confirmed that all known offenders have been modified to use
+    // either %fs or TSD). In the worst case scenario, when VM is embedded in
+    // a native application that plays with %gs, we might see non-zero %gs
+    // even BsdThreads is running in fixed stack mode. As the result, we'll
+    // return true and skip _thread_safety_check(), so we may not be able to
+    // detect stack-heap collisions. But otherwise it's harmless.
+    //
+#ifdef __GNUC__
+    return (GET_GS() != 0);
+#else
+    return false;
+#endif
+  }
+}
+#endif
+#endif // AMD64
+
+// return default stack size for thr_type
+size_t os::Bsd::default_stack_size(os::ThreadType thr_type) {
+  // default stack size (compiler thread needs larger stack)
+#ifdef AMD64
+  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
+#else
+  size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
+#endif // AMD64
+  return s;
+}
+
+size_t os::Bsd::default_guard_size(os::ThreadType thr_type) {
+  // Creating guard page is very expensive. Java thread has HotSpot
+  // guard page, only enable glibc guard page for non-Java threads.
+  return (thr_type == java_thread ? 0 : page_size());
+}
+
+// Java thread:
+//
+//   Low memory addresses
+//    +------------------------+
+//    |                        |\  JavaThread created by VM does not have glibc
+//    |    glibc guard page    | - guard, attached Java thread usually has
+//    |                        |/  1 page glibc guard.
+// P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
+//    |                        |\
+//    |  HotSpot Guard Pages   | - red and yellow pages
+//    |                        |/
+//    +------------------------+ JavaThread::stack_yellow_zone_base()
+//    |                        |\
+//    |      Normal Stack      | -
+//    |                        |/
+// P2 +------------------------+ Thread::stack_base()
+//
+// Non-Java thread:
+//
+//   Low memory addresses
+//    +------------------------+
+//    |                        |\
+//    |  glibc guard page      | - usually 1 page
+//    |                        |/
+// P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
+//    |                        |\
+//    |      Normal Stack      | -
+//    |                        |/
+// P2 +------------------------+ Thread::stack_base()
+//
+// ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
+//    pthread_attr_getstack()
+
+static void current_stack_region(address * bottom, size_t * size) {
+#ifdef __APPLE__
+  pthread_t self = pthread_self();
+  void *stacktop = pthread_get_stackaddr_np(self);
+  *size = pthread_get_stacksize_np(self);
+  *bottom = (address) stacktop - *size;
+#elif defined(__OpenBSD__)
+  stack_t ss;
+  int rslt = pthread_stackseg_np(pthread_self(), &ss);
+
+  if (rslt != 0)
+    fatal(err_msg("pthread_stackseg_np failed with err = %d", rslt));
+
+  *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
+  *size   = ss.ss_size;
+#elif defined(_ALLBSD_SOURCE)
+  pthread_attr_t attr;
+
+  int rslt = pthread_attr_init(&attr);
+
+  // JVM needs to know exact stack location, abort if it fails
+  if (rslt != 0)
+    fatal(err_msg("pthread_attr_init failed with err = %d", rslt));
+
+  rslt = pthread_attr_get_np(pthread_self(), &attr);
+
+  if (rslt != 0)
+    fatal(err_msg("pthread_attr_get_np failed with err = %d", rslt));
+
+  if (pthread_attr_getstackaddr(&attr, (void **)bottom) != 0 ||
+    pthread_attr_getstacksize(&attr, size) != 0) {
+    fatal("Can not locate current stack attributes!");
+  }
+
+  pthread_attr_destroy(&attr);
+#else
+  if (os::Bsd::is_initial_thread()) {
+     // initial thread needs special handling because pthread_getattr_np()
+     // may return bogus value.
+     *bottom = os::Bsd::initial_thread_stack_bottom();
+     *size   = os::Bsd::initial_thread_stack_size();
+  } else {
+     pthread_attr_t attr;
+
+     int rslt = pthread_getattr_np(pthread_self(), &attr);
+
+     // JVM needs to know exact stack location, abort if it fails
+     if (rslt != 0) {
+       if (rslt == ENOMEM) {
+         vm_exit_out_of_memory(0, "pthread_getattr_np");
+       } else {
+         fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
+       }
+     }
+
+     if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
+         fatal("Can not locate current stack attributes!");
+     }
+
+     pthread_attr_destroy(&attr);
+
+  }
+#endif
+  assert(os::current_stack_pointer() >= *bottom &&
+         os::current_stack_pointer() < *bottom + *size, "just checking");
+}
+
+address os::current_stack_base() {
+  address bottom;
+  size_t size;
+  current_stack_region(&bottom, &size);
+  return (bottom + size);
+}
+
+size_t os::current_stack_size() {
+  // stack size includes normal stack and HotSpot guard pages
+  address bottom;
+  size_t size;
+  current_stack_region(&bottom, &size);
+  return size;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// helper functions for fatal error handler
+
+void os::print_context(outputStream *st, void *context) {
+  if (context == NULL) return;
+
+  ucontext_t *uc = (ucontext_t*)context;
+  st->print_cr("Registers:");
+#ifdef AMD64
+  st->print(  "RAX=" INTPTR_FORMAT, uc->context_rax);
+  st->print(", RBX=" INTPTR_FORMAT, uc->context_rbx);
+  st->print(", RCX=" INTPTR_FORMAT, uc->context_rcx);
+  st->print(", RDX=" INTPTR_FORMAT, uc->context_rdx);
+  st->cr();
+  st->print(  "RSP=" INTPTR_FORMAT, uc->context_rsp);
+  st->print(", RBP=" INTPTR_FORMAT, uc->context_rbp);
+  st->print(", RSI=" INTPTR_FORMAT, uc->context_rsi);
+  st->print(", RDI=" INTPTR_FORMAT, uc->context_rdi);
+  st->cr();
+  st->print(  "R8 =" INTPTR_FORMAT, uc->context_r8);
+  st->print(", R9 =" INTPTR_FORMAT, uc->context_r9);
+  st->print(", R10=" INTPTR_FORMAT, uc->context_r10);
+  st->print(", R11=" INTPTR_FORMAT, uc->context_r11);
+  st->cr();
+  st->print(  "R12=" INTPTR_FORMAT, uc->context_r12);
+  st->print(", R13=" INTPTR_FORMAT, uc->context_r13);
+  st->print(", R14=" INTPTR_FORMAT, uc->context_r14);
+  st->print(", R15=" INTPTR_FORMAT, uc->context_r15);
+  st->cr();
+  st->print(  "RIP=" INTPTR_FORMAT, uc->context_rip);
+  st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_flags);
+  st->print(", ERR=" INTPTR_FORMAT, uc->context_err);
+  st->cr();
+  st->print("  TRAPNO=" INTPTR_FORMAT, uc->context_trapno);
+#else
+  st->print(  "EAX=" INTPTR_FORMAT, uc->context_eax);
+  st->print(", EBX=" INTPTR_FORMAT, uc->context_ebx);
+  st->print(", ECX=" INTPTR_FORMAT, uc->context_ecx);
+  st->print(", EDX=" INTPTR_FORMAT, uc->context_edx);
+  st->cr();
+  st->print(  "ESP=" INTPTR_FORMAT, uc->context_esp);
+  st->print(", EBP=" INTPTR_FORMAT, uc->context_ebp);
+  st->print(", ESI=" INTPTR_FORMAT, uc->context_esi);
+  st->print(", EDI=" INTPTR_FORMAT, uc->context_edi);
+  st->cr();
+  st->print(  "EIP=" INTPTR_FORMAT, uc->context_eip);
+  st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_eflags);
+#endif // AMD64
+  st->cr();
+  st->cr();
+
+  intptr_t *sp = (intptr_t *)os::Bsd::ucontext_get_sp(uc);
+  st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
+  print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
+  st->cr();
+
+  // Note: it may be unsafe to inspect memory near pc. For example, pc may
+  // point to garbage if entry point in an nmethod is corrupted. Leave
+  // this at the end, and hope for the best.
+  address pc = os::Bsd::ucontext_get_pc(uc);
+  st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
+  print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
+}
+
+void os::print_register_info(outputStream *st, void *context) {
+  if (context == NULL) return;
+
+  ucontext_t *uc = (ucontext_t*)context;
+
+  st->print_cr("Register to memory mapping:");
+  st->cr();
+
+  // this is horrendously verbose but the layout of the registers in the
+  // context does not match how we defined our abstract Register set, so
+  // we can't just iterate through the gregs area
+
+  // this is only for the "general purpose" registers
+
+#ifdef AMD64
+  st->print("RAX="); print_location(st, uc->context_rax);
+  st->print("RBX="); print_location(st, uc->context_rbx);
+  st->print("RCX="); print_location(st, uc->context_rcx);
+  st->print("RDX="); print_location(st, uc->context_rdx);
+  st->print("RSP="); print_location(st, uc->context_rsp);
+  st->print("RBP="); print_location(st, uc->context_rbp);
+  st->print("RSI="); print_location(st, uc->context_rsi);
+  st->print("RDI="); print_location(st, uc->context_rdi);
+  st->print("R8 ="); print_location(st, uc->context_r8);
+  st->print("R9 ="); print_location(st, uc->context_r9);
+  st->print("R10="); print_location(st, uc->context_r10);
+  st->print("R11="); print_location(st, uc->context_r11);
+  st->print("R12="); print_location(st, uc->context_r12);
+  st->print("R13="); print_location(st, uc->context_r13);
+  st->print("R14="); print_location(st, uc->context_r14);
+  st->print("R15="); print_location(st, uc->context_r15);
+#else
+  st->print("EAX="); print_location(st, uc->context_eax);
+  st->print("EBX="); print_location(st, uc->context_ebx);
+  st->print("ECX="); print_location(st, uc->context_ecx);
+  st->print("EDX="); print_location(st, uc->context_edx);
+  st->print("ESP="); print_location(st, uc->context_esp);
+  st->print("EBP="); print_location(st, uc->context_ebp);
+  st->print("ESI="); print_location(st, uc->context_esi);
+  st->print("EDI="); print_location(st, uc->context_edi);
+#endif // AMD64
+
+  st->cr();
+}
+
+void os::setup_fpu() {
+#ifndef AMD64
+  address fpu_cntrl = StubRoutines::addr_fpu_cntrl_wrd_std();
+  __asm__ volatile (  "fldcw (%0)" :
+                      : "r" (fpu_cntrl) : "memory");
+#endif // !AMD64
+}
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.hpp b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.hpp
new file mode 100644
index 0000000..7a4e710
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.hpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_OS_BSD_X86_HPP
+#define OS_CPU_BSD_X86_VM_OS_BSD_X86_HPP
+
+  static void setup_fpu();
+  static bool supports_sse();
+
+  static bool is_allocatable(size_t bytes);
+
+  // Used to register dynamic code cache area with the OS
+  // Note: Currently only used in 64 bit Windows implementations
+  static bool register_code_area(char *low, char *high) { return true; }
+
+#endif // OS_CPU_BSD_X86_VM_OS_BSD_X86_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/prefetch_bsd_x86.inline.hpp b/hotspot/src/os_cpu/bsd_x86/vm/prefetch_bsd_x86.inline.hpp
new file mode 100644
index 0000000..6da429b
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/prefetch_bsd_x86.inline.hpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_PREFETCH_BSD_X86_INLINE_HPP
+#define OS_CPU_BSD_X86_VM_PREFETCH_BSD_X86_INLINE_HPP
+
+#include "runtime/prefetch.hpp"
+
+
+inline void Prefetch::read (void *loc, intx interval) {
+#ifdef AMD64
+  __asm__ ("prefetcht0 (%0,%1,1)" : : "r" (loc), "r" (interval));
+#endif // AMD64
+}
+
+inline void Prefetch::write(void *loc, intx interval) {
+#ifdef AMD64
+
+  // Do not use the 3dnow prefetchw instruction.  It isn't supported on em64t.
+  //  __asm__ ("prefetchw (%0,%1,1)" : : "r" (loc), "r" (interval));
+  __asm__ ("prefetcht0 (%0,%1,1)" : : "r" (loc), "r" (interval));
+
+#endif // AMD64
+}
+
+#endif // OS_CPU_BSD_X86_VM_PREFETCH_BSD_X86_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.cpp b/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.cpp
new file mode 100644
index 0000000..3c76437
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/threadLocalStorage.hpp"
+#include "thread_bsd.inline.hpp"
+
+// Map stack pointer (%esp) to thread pointer for faster TLS access
+//
+// Here we use a flat table for better performance. Getting current thread
+// is down to one memory access (read _sp_map[%esp>>12]) in generated code
+// and two in runtime code (-fPIC code needs an extra load for _sp_map).
+//
+// This code assumes stack page is not shared by different threads. It works
+// in 32-bit VM when page size is 4K (or a multiple of 4K, if that matters).
+//
+// Notice that _sp_map is allocated in the bss segment, which is ZFOD
+// (zero-fill-on-demand). While it reserves 4M address space upfront,
+// actual memory pages are committed on demand.
+//
+// If an application creates and destroys a lot of threads, usually the
+// stack space freed by a thread will soon get reused by new thread
+// (this is especially true in NPTL or BsdThreads in fixed-stack mode).
+// No memory page in _sp_map is wasted.
+//
+// However, it's still possible that we might end up populating &
+// committing a large fraction of the 4M table over time, but the actual
+// amount of live data in the table could be quite small. The max wastage
+// is less than 4M bytes. If it becomes an issue, we could use madvise()
+// with MADV_DONTNEED to reclaim unused (i.e. all-zero) pages in _sp_map.
+// MADV_DONTNEED on Bsd keeps the virtual memory mapping, but zaps the
+// physical memory page (i.e. similar to MADV_FREE on Solaris).
+
+#ifndef AMD64
+Thread* ThreadLocalStorage::_sp_map[1UL << (SP_BITLENGTH - PAGE_SHIFT)];
+#endif // !AMD64
+
+void ThreadLocalStorage::generate_code_for_get_thread() {
+    // nothing we can do here for user-level thread
+}
+
+void ThreadLocalStorage::pd_init() {
+#ifndef AMD64
+  assert(align_size_down(os::vm_page_size(), PAGE_SIZE) == os::vm_page_size(),
+         "page size must be multiple of PAGE_SIZE");
+#endif // !AMD64
+}
+
+void ThreadLocalStorage::pd_set_thread(Thread* thread) {
+  os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
+
+#ifndef AMD64
+  address stack_top = os::current_stack_base();
+  size_t stack_size = os::current_stack_size();
+
+  for (address p = stack_top - stack_size; p < stack_top; p += PAGE_SIZE) {
+    // pd_set_thread() is called with non-NULL value when a new thread is
+    // created/attached, or with NULL value when a thread is about to exit.
+    // If both "thread" and the corresponding _sp_map[] entry are non-NULL,
+    // they should have the same value. Otherwise it might indicate that the
+    // stack page is shared by multiple threads. However, a more likely cause
+    // for this assertion to fail is that an attached thread exited without
+    // detaching itself from VM, which is a program error and could cause VM
+    // to crash.
+    assert(thread == NULL || _sp_map[(uintptr_t)p >> PAGE_SHIFT] == NULL ||
+           thread == _sp_map[(uintptr_t)p >> PAGE_SHIFT],
+           "thread exited without detaching from VM??");
+    _sp_map[(uintptr_t)p >> PAGE_SHIFT] = thread;
+  }
+#endif // !AMD64
+}
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp b/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp
new file mode 100644
index 0000000..7fedb95
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_THREADLS_BSD_X86_HPP
+#define OS_CPU_BSD_X86_VM_THREADLS_BSD_X86_HPP
+
+  // Processor dependent parts of ThreadLocalStorage
+
+#ifndef AMD64
+  // map stack pointer to thread pointer - see notes in threadLS_bsd_x86.cpp
+  #define SP_BITLENGTH  32
+#ifndef PAGE_SHIFT
+  #define PAGE_SHIFT    12
+  #define PAGE_SIZE     (1UL << PAGE_SHIFT)
+#endif
+  static Thread* _sp_map[1UL << (SP_BITLENGTH - PAGE_SHIFT)];
+#endif // !AMD64
+
+public:
+
+#ifndef AMD64
+  static Thread** sp_map_addr() { return _sp_map; }
+#endif // !AMD64
+
+  static Thread* thread() {
+#ifdef AMD64
+    return (Thread*) os::thread_local_storage_at(thread_index());
+#else
+    uintptr_t sp;
+    __asm__ volatile ("movl %%esp, %0" : "=r" (sp));
+    return _sp_map[sp >> PAGE_SHIFT];
+#endif // AMD64
+  }
+
+#endif // OS_CPU_BSD_X86_VM_THREADLS_BSD_X86_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/thread_bsd_x86.cpp b/hotspot/src/os_cpu/bsd_x86/vm/thread_bsd_x86.cpp
new file mode 100644
index 0000000..e63c46e
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/thread_bsd_x86.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/frame.inline.hpp"
+#include "thread_bsd.inline.hpp"
+
+// For Forte Analyzer AsyncGetCallTrace profiling support - thread is
+// currently interrupted by SIGPROF
+bool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr,
+  void* ucontext, bool isInJava) {
+
+  assert(Thread::current() == this, "caller must be current thread");
+  assert(this->is_Java_thread(), "must be JavaThread");
+
+  JavaThread* jt = (JavaThread *)this;
+
+  // If we have a last_Java_frame, then we should use it even if
+  // isInJava == true.  It should be more reliable than ucontext info.
+  if (jt->has_last_Java_frame()) {
+    *fr_addr = jt->pd_last_frame();
+    return true;
+  }
+
+  // At this point, we don't have a last_Java_frame, so
+  // we try to glean some information out of the ucontext
+  // if we were running Java code when SIGPROF came in.
+  if (isInJava) {
+    ucontext_t* uc = (ucontext_t*) ucontext;
+
+    intptr_t* ret_fp;
+    intptr_t* ret_sp;
+    ExtendedPC addr = os::Bsd::fetch_frame_from_ucontext(this, uc,
+      &ret_sp, &ret_fp);
+    if (addr.pc() == NULL || ret_sp == NULL ) {
+      // ucontext wasn't useful
+      return false;
+    }
+
+    frame ret_frame(ret_sp, ret_fp, addr.pc());
+    if (!ret_frame.safe_for_sender(jt)) {
+#ifdef COMPILER2
+      // C2 uses ebp as a general register see if NULL fp helps
+      frame ret_frame2(ret_sp, NULL, addr.pc());
+      if (!ret_frame2.safe_for_sender(jt)) {
+        // nothing else to try if the frame isn't good
+        return false;
+      }
+      ret_frame = ret_frame2;
+#else
+      // nothing else to try if the frame isn't good
+      return false;
+#endif /* COMPILER2 */
+    }
+    *fr_addr = ret_frame;
+    return true;
+  }
+
+  // nothing else to try
+  return false;
+}
+
+void JavaThread::cache_global_variables() { }
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/thread_bsd_x86.hpp b/hotspot/src/os_cpu/bsd_x86/vm/thread_bsd_x86.hpp
new file mode 100644
index 0000000..69dba9b
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/thread_bsd_x86.hpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_THREAD_BSD_X86_HPP
+#define OS_CPU_BSD_X86_VM_THREAD_BSD_X86_HPP
+
+ private:
+  void pd_initialize() {
+    _anchor.clear();
+  }
+
+  frame pd_last_frame() {
+    assert(has_last_Java_frame(), "must have last_Java_sp() when suspended");
+    if (_anchor.last_Java_pc() != NULL) {
+      return frame(_anchor.last_Java_sp(), _anchor.last_Java_fp(), _anchor.last_Java_pc());
+    } else {
+      // This will pick up pc from sp
+      return frame(_anchor.last_Java_sp(), _anchor.last_Java_fp());
+    }
+  }
+
+ public:
+  // Mutators are highly dangerous....
+  intptr_t* last_Java_fp()                       { return _anchor.last_Java_fp(); }
+  void  set_last_Java_fp(intptr_t* fp)           { _anchor.set_last_Java_fp(fp);   }
+
+  void set_base_of_stack_pointer(intptr_t* base_sp) {
+  }
+
+  static ByteSize last_Java_fp_offset()          {
+    return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_fp_offset();
+  }
+
+  intptr_t* base_of_stack_pointer() {
+    return NULL;
+  }
+  void record_base_of_stack_pointer() {
+  }
+
+  bool pd_get_top_frame_for_signal_handler(frame* fr_addr, void* ucontext,
+    bool isInJava);
+
+  // These routines are only used on cpu architectures that
+  // have separate register stacks (Itanium).
+  static bool register_stack_overflow() { return false; }
+  static void enable_register_stack_guard() {}
+  static void disable_register_stack_guard() {}
+
+#endif // OS_CPU_BSD_X86_VM_THREAD_BSD_X86_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp b/hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp
new file mode 100644
index 0000000..210d5d9
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_X86_VM_VMSTRUCTS_BSD_X86_HPP
+#define OS_CPU_BSD_X86_VM_VMSTRUCTS_BSD_X86_HPP
+
+// These are the OS and CPU-specific fields, types and integer
+// constants required by the Serviceability Agent. This file is
+// referenced by vmStructs.cpp.
+
+#define VM_STRUCTS_OS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field, last_entry) \
+                                                                                                                                     \
+  /******************************/                                                                                                   \
+  /* Threads (NOTE: incomplete) */                                                                                                   \
+  /******************************/                                                                                                   \
+  nonstatic_field(OSThread,                      _thread_id,                                      pthread_t)                             \
+  nonstatic_field(OSThread,                      _pthread_id,                                     pthread_t)                         \
+  /* This must be the last entry, and must be present */                                                                             \
+  last_entry()
+
+
+#define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type, last_entry) \
+                                                                          \
+  /**********************/                                                \
+  /* Posix Thread IDs   */                                                \
+  /**********************/                                                \
+                                                                          \
+  declare_integer_type(pid_t)                                             \
+  declare_unsigned_integer_type(pthread_t)                                \
+                                                                          \
+  /* This must be the last entry, and must be present */                  \
+  last_entry()
+
+#define VM_INT_CONSTANTS_OS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant, last_entry) \
+                                                                        \
+  /* This must be the last entry, and must be present */                \
+  last_entry()
+
+#define VM_LONG_CONSTANTS_OS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant, last_entry) \
+                                                                        \
+  /* This must be the last entry, and must be present */                \
+  last_entry()
+
+#endif // OS_CPU_BSD_X86_VM_VMSTRUCTS_BSD_X86_HPP
diff --git a/hotspot/src/os_cpu/bsd_x86/vm/vm_version_bsd_x86.cpp b/hotspot/src/os_cpu/bsd_x86/vm/vm_version_bsd_x86.cpp
new file mode 100644
index 0000000..d1c8c6b
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_x86/vm/vm_version_bsd_x86.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/os.hpp"
+#include "vm_version_x86.hpp"
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/assembler_bsd_zero.cpp b/hotspot/src/os_cpu/bsd_zero/vm/assembler_bsd_zero.cpp
new file mode 100644
index 0000000..ec56a35
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/assembler_bsd_zero.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2009 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "asm/assembler.hpp"
+#include "assembler_zero.inline.hpp"
+#include "runtime/os.hpp"
+#include "runtime/threadLocalStorage.hpp"
+
+// This file is intentionally empty
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp b/hotspot/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp
new file mode 100644
index 0000000..19027bd
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp
@@ -0,0 +1,323 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007, 2008, 2011 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_ATOMIC_BSD_ZERO_INLINE_HPP
+#define OS_CPU_BSD_ZERO_VM_ATOMIC_BSD_ZERO_INLINE_HPP
+
+#include "orderAccess_bsd_zero.inline.hpp"
+#include "runtime/atomic.hpp"
+#include "runtime/os.hpp"
+#include "vm_version_zero.hpp"
+
+// Implementation of class atomic
+
+#ifdef M68K
+
+/*
+ * __m68k_cmpxchg
+ *
+ * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
+ * Returns newval on success and oldval if no exchange happened.
+ * This implementation is processor specific and works on
+ * 68020 68030 68040 and 68060.
+ *
+ * It will not work on ColdFire, 68000 and 68010 since they lack the CAS
+ * instruction.
+ * Using a kernelhelper would be better for arch complete implementation.
+ *
+ */
+
+static inline int __m68k_cmpxchg(int oldval, int newval, volatile int *ptr) {
+  int ret;
+  __asm __volatile ("cas%.l %0,%2,%1"
+                   : "=d" (ret), "+m" (*(ptr))
+                   : "d" (newval), "0" (oldval));
+  return ret;
+}
+
+/* Perform an atomic compare and swap: if the current value of `*PTR'
+   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
+   `*PTR' before the operation.*/
+static inline int m68k_compare_and_swap(volatile int *ptr,
+                                        int oldval,
+                                        int newval) {
+  for (;;) {
+      int prev = *ptr;
+      if (prev != oldval)
+        return prev;
+
+      if (__m68k_cmpxchg (prev, newval, ptr) == newval)
+        // Success.
+        return prev;
+
+      // We failed even though prev == oldval.  Try again.
+    }
+}
+
+/* Atomically add an int to memory.  */
+static inline int m68k_add_and_fetch(volatile int *ptr, int add_value) {
+  for (;;) {
+      // Loop until success.
+
+      int prev = *ptr;
+
+      if (__m68k_cmpxchg (prev, prev + add_value, ptr) == prev + add_value)
+        return prev + add_value;
+    }
+}
+
+/* Atomically write VALUE into `*PTR' and returns the previous
+   contents of `*PTR'.  */
+static inline int m68k_lock_test_and_set(volatile int *ptr, int newval) {
+  for (;;) {
+      // Loop until success.
+      int prev = *ptr;
+
+      if (__m68k_cmpxchg (prev, newval, ptr) == prev)
+        return prev;
+    }
+}
+#endif // M68K
+
+#ifdef ARM
+
+/*
+ * __kernel_cmpxchg
+ *
+ * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
+ * Return zero if *ptr was changed or non-zero if no exchange happened.
+ * The C flag is also set if *ptr was changed to allow for assembly
+ * optimization in the calling code.
+ *
+ */
+
+typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
+#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *) 0xffff0fc0)
+
+
+
+/* Perform an atomic compare and swap: if the current value of `*PTR'
+   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
+   `*PTR' before the operation.*/
+static inline int arm_compare_and_swap(volatile int *ptr,
+                                       int oldval,
+                                       int newval) {
+  for (;;) {
+      int prev = *ptr;
+      if (prev != oldval)
+        return prev;
+
+      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
+        // Success.
+        return prev;
+
+      // We failed even though prev == oldval.  Try again.
+    }
+}
+
+/* Atomically add an int to memory.  */
+static inline int arm_add_and_fetch(volatile int *ptr, int add_value) {
+  for (;;) {
+      // Loop until a __kernel_cmpxchg succeeds.
+
+      int prev = *ptr;
+
+      if (__kernel_cmpxchg (prev, prev + add_value, ptr) == 0)
+        return prev + add_value;
+    }
+}
+
+/* Atomically write VALUE into `*PTR' and returns the previous
+   contents of `*PTR'.  */
+static inline int arm_lock_test_and_set(volatile int *ptr, int newval) {
+  for (;;) {
+      // Loop until a __kernel_cmpxchg succeeds.
+      int prev = *ptr;
+
+      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
+        return prev;
+    }
+}
+#endif // ARM
+
+inline void Atomic::store(jint store_value, volatile jint* dest) {
+#if !defined(ARM) && !defined(M68K)
+  __sync_synchronize();
+#endif
+  *dest = store_value;
+}
+
+inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) {
+#if !defined(ARM) && !defined(M68K)
+  __sync_synchronize();
+#endif
+  *dest = store_value;
+}
+
+inline jint Atomic::add(jint add_value, volatile jint* dest) {
+#ifdef ARM
+  return arm_add_and_fetch(dest, add_value);
+#else
+#ifdef M68K
+  return m68k_add_and_fetch(dest, add_value);
+#else
+  return __sync_add_and_fetch(dest, add_value);
+#endif // M68K
+#endif // ARM
+}
+
+inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
+#ifdef ARM
+  return arm_add_and_fetch(dest, add_value);
+#else
+#ifdef M68K
+  return m68k_add_and_fetch(dest, add_value);
+#else
+  return __sync_add_and_fetch(dest, add_value);
+#endif // M68K
+#endif // ARM
+}
+
+inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
+  return (void *) add_ptr(add_value, (volatile intptr_t *) dest);
+}
+
+inline void Atomic::inc(volatile jint* dest) {
+  add(1, dest);
+}
+
+inline void Atomic::inc_ptr(volatile intptr_t* dest) {
+  add_ptr(1, dest);
+}
+
+inline void Atomic::inc_ptr(volatile void* dest) {
+  add_ptr(1, dest);
+}
+
+inline void Atomic::dec(volatile jint* dest) {
+  add(-1, dest);
+}
+
+inline void Atomic::dec_ptr(volatile intptr_t* dest) {
+  add_ptr(-1, dest);
+}
+
+inline void Atomic::dec_ptr(volatile void* dest) {
+  add_ptr(-1, dest);
+}
+
+inline jint Atomic::xchg(jint exchange_value, volatile jint* dest) {
+#ifdef ARM
+  return arm_lock_test_and_set(dest, exchange_value);
+#else
+#ifdef M68K
+  return m68k_lock_test_and_set(dest, exchange_value);
+#else
+  // __sync_lock_test_and_set is a bizarrely named atomic exchange
+  // operation.  Note that some platforms only support this with the
+  // limitation that the only valid value to store is the immediate
+  // constant 1.  There is a test for this in JNI_CreateJavaVM().
+  return __sync_lock_test_and_set (dest, exchange_value);
+#endif // M68K
+#endif // ARM
+}
+
+inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value,
+                                 volatile intptr_t* dest) {
+#ifdef ARM
+  return arm_lock_test_and_set(dest, exchange_value);
+#else
+#ifdef M68K
+  return m68k_lock_test_and_set(dest, exchange_value);
+#else
+  return __sync_lock_test_and_set (dest, exchange_value);
+#endif // M68K
+#endif // ARM
+}
+
+inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
+  return (void *) xchg_ptr((intptr_t) exchange_value,
+                           (volatile intptr_t*) dest);
+}
+
+inline jint Atomic::cmpxchg(jint exchange_value,
+                            volatile jint* dest,
+                            jint compare_value) {
+#ifdef ARM
+  return arm_compare_and_swap(dest, compare_value, exchange_value);
+#else
+#ifdef M68K
+  return m68k_compare_and_swap(dest, compare_value, exchange_value);
+#else
+  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
+#endif // M68K
+#endif // ARM
+}
+
+inline jlong Atomic::cmpxchg(jlong exchange_value,
+                             volatile jlong* dest,
+                             jlong compare_value) {
+
+  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
+}
+
+inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value,
+                                    volatile intptr_t* dest,
+                                    intptr_t compare_value) {
+#ifdef ARM
+  return arm_compare_and_swap(dest, compare_value, exchange_value);
+#else
+#ifdef M68K
+  return m68k_compare_and_swap(dest, compare_value, exchange_value);
+#else
+  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
+#endif // M68K
+#endif // ARM
+}
+
+inline void* Atomic::cmpxchg_ptr(void* exchange_value,
+                                 volatile void* dest,
+                                 void* compare_value) {
+
+  return (void *) cmpxchg_ptr((intptr_t) exchange_value,
+                              (volatile intptr_t*) dest,
+                              (intptr_t) compare_value);
+}
+
+inline jlong Atomic::load(volatile jlong* src) {
+  volatile jlong dest;
+  os::atomic_copy64(src, &dest);
+  return dest;
+}
+
+inline void Atomic::store(jlong store_value, jlong* dest) {
+  os::atomic_copy64((volatile jlong*)&store_value, (volatile jlong*)dest);
+}
+
+inline void Atomic::store(jlong store_value, volatile jlong* dest) {
+  os::atomic_copy64((volatile jlong*)&store_value, dest);
+}
+
+#endif // OS_CPU_BSD_ZERO_VM_ATOMIC_BSD_ZERO_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/bytes_bsd_zero.inline.hpp b/hotspot/src/os_cpu/bsd_zero/vm/bytes_bsd_zero.inline.hpp
new file mode 100644
index 0000000..368e90c
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/bytes_bsd_zero.inline.hpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_BYTES_BSD_ZERO_INLINE_HPP
+#define OS_CPU_BSD_ZERO_VM_BYTES_BSD_ZERO_INLINE_HPP
+
+// Efficient swapping of data bytes from Java byte
+// ordering to native byte ordering and vice versa.
+
+#ifdef __APPLE__
+#  include <libkern/OSByteOrder.h>
+#else
+#  include <sys/endian.h>
+#endif
+
+#if defined(__APPLE__)
+#  define bswap_16(x)   OSSwapInt16(x)
+#  define bswap_32(x)   OSSwapInt32(x)
+#  define bswap_64(x)   OSSwapInt64(x)
+#elif defined(__OpenBSD__)
+#  define bswap_16(x)   swap16(x)
+#  define bswap_32(x)   swap32(x)
+#  define bswap_64(x)   swap64(x)
+#elif defined(__NetBSD__)
+#  define bswap_16(x)   bswap16(x)
+#  define bswap_32(x)   bswap32(x)
+#  define bswap_64(x)   bswap64(x)
+#else
+#  define bswap_16(x) __bswap16(x)
+#  define bswap_32(x) __bswap32(x)
+#  define bswap_64(x) __bswap64(x)
+#endif
+
+inline u2 Bytes::swap_u2(u2 x) {
+  return bswap_16(x);
+}
+
+inline u4 Bytes::swap_u4(u4 x) {
+  return bswap_32(x);
+}
+
+inline u8 Bytes::swap_u8(u8 x) {
+  return bswap_64(x);
+}
+
+#endif // OS_CPU_BSD_ZERO_VM_BYTES_BSD_ZERO_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/globals_bsd_zero.hpp b/hotspot/src/os_cpu/bsd_zero/vm/globals_bsd_zero.hpp
new file mode 100644
index 0000000..57e2759
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/globals_bsd_zero.hpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007, 2008, 2010 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_GLOBALS_BSD_ZERO_HPP
+#define OS_CPU_BSD_ZERO_VM_GLOBALS_BSD_ZERO_HPP
+
+//
+// Set the default values for platform dependent flags used by the
+// runtime system.  See globals.hpp for details of what they do.
+//
+
+define_pd_global(bool,  DontYieldALot,           false);
+define_pd_global(intx,  ThreadStackSize,         1536);
+#ifdef _LP64
+define_pd_global(intx,  VMThreadStackSize,       1024);
+#else
+define_pd_global(intx,  VMThreadStackSize,       512);
+#endif // _LP64
+define_pd_global(intx,  CompilerThreadStackSize, 0);
+define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
+
+define_pd_global(bool,  UseVectoredExceptions,   false);
+// Only used on 64 bit platforms
+define_pd_global(uintx, HeapBaseMinAddress,      2*G);
+
+#endif // OS_CPU_BSD_ZERO_VM_GLOBALS_BSD_ZERO_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/orderAccess_bsd_zero.inline.hpp b/hotspot/src/os_cpu/bsd_zero/vm/orderAccess_bsd_zero.inline.hpp
new file mode 100644
index 0000000..7f8e78b
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/orderAccess_bsd_zero.inline.hpp
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007, 2008, 2009 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_ORDERACCESS_BSD_ZERO_INLINE_HPP
+#define OS_CPU_BSD_ZERO_VM_ORDERACCESS_BSD_ZERO_INLINE_HPP
+
+#include "runtime/orderAccess.hpp"
+#include "vm_version_zero.hpp"
+
+#ifdef ARM
+
+/*
+ * ARM Kernel helper for memory barrier.
+ * Using __asm __volatile ("":::"memory") does not work reliable on ARM
+ * and gcc __sync_synchronize(); implementation does not use the kernel
+ * helper for all gcc versions so it is unreliable to use as well.
+ */
+typedef void (__kernel_dmb_t) (void);
+#define __kernel_dmb (*(__kernel_dmb_t *) 0xffff0fa0)
+
+#define FULL_MEM_BARRIER __kernel_dmb()
+#define READ_MEM_BARRIER __kernel_dmb()
+#define WRITE_MEM_BARRIER __kernel_dmb()
+
+#else // ARM
+
+#define FULL_MEM_BARRIER __sync_synchronize()
+
+#ifdef PPC
+
+#ifdef __NO_LWSYNC__
+#define READ_MEM_BARRIER __asm __volatile ("sync":::"memory")
+#define WRITE_MEM_BARRIER __asm __volatile ("sync":::"memory")
+#else
+#define READ_MEM_BARRIER __asm __volatile ("lwsync":::"memory")
+#define WRITE_MEM_BARRIER __asm __volatile ("lwsync":::"memory")
+#endif
+
+#else // PPC
+
+#define READ_MEM_BARRIER __asm __volatile ("":::"memory")
+#define WRITE_MEM_BARRIER __asm __volatile ("":::"memory")
+
+#endif // PPC
+
+#endif // ARM
+
+
+inline void OrderAccess::loadload()   { acquire(); }
+inline void OrderAccess::storestore() { release(); }
+inline void OrderAccess::loadstore()  { acquire(); }
+inline void OrderAccess::storeload()  { fence(); }
+
+inline void OrderAccess::acquire() {
+  READ_MEM_BARRIER;
+}
+
+inline void OrderAccess::release() {
+  WRITE_MEM_BARRIER;
+}
+
+inline void OrderAccess::fence() {
+  FULL_MEM_BARRIER;
+}
+
+inline jbyte    OrderAccess::load_acquire(volatile jbyte*   p) { jbyte data = *p; acquire(); return data; }
+inline jshort   OrderAccess::load_acquire(volatile jshort*  p) { jshort data = *p; acquire(); return data; }
+inline jint     OrderAccess::load_acquire(volatile jint*    p) { jint data = *p; acquire(); return data; }
+inline jlong    OrderAccess::load_acquire(volatile jlong*   p) {
+  jlong tmp;
+  os::atomic_copy64(p, &tmp);
+  acquire();
+  return tmp;
+}
+inline jubyte    OrderAccess::load_acquire(volatile jubyte*   p) { jubyte data = *p; acquire(); return data; }
+inline jushort   OrderAccess::load_acquire(volatile jushort*  p) { jushort data = *p; acquire(); return data; }
+inline juint     OrderAccess::load_acquire(volatile juint*    p) { juint data = *p; acquire(); return data; }
+inline julong   OrderAccess::load_acquire(volatile julong*  p) {
+  julong tmp;
+  os::atomic_copy64(p, &tmp);
+  acquire();
+  return tmp;
+}
+inline jfloat   OrderAccess::load_acquire(volatile jfloat*  p) { jfloat data = *p; acquire(); return data; }
+inline jdouble  OrderAccess::load_acquire(volatile jdouble* p) {
+  jdouble tmp;
+  os::atomic_copy64(p, &tmp);
+  acquire();
+  return tmp;
+}
+
+inline intptr_t OrderAccess::load_ptr_acquire(volatile intptr_t*   p) {
+  intptr_t data = *p;
+  acquire();
+  return data;
+}
+inline void*    OrderAccess::load_ptr_acquire(volatile void*       p) {
+  void *data = *(void* volatile *)p;
+  acquire();
+  return data;
+}
+inline void*    OrderAccess::load_ptr_acquire(const volatile void* p) {
+  void *data = *(void* const volatile *)p;
+  acquire();
+  return data;
+}
+
+inline void     OrderAccess::release_store(volatile jbyte*   p, jbyte   v) { release(); *p = v; }
+inline void     OrderAccess::release_store(volatile jshort*  p, jshort  v) { release(); *p = v; }
+inline void     OrderAccess::release_store(volatile jint*    p, jint    v) { release(); *p = v; }
+inline void     OrderAccess::release_store(volatile jlong*   p, jlong   v)
+{ release(); os::atomic_copy64(&v, p); }
+inline void     OrderAccess::release_store(volatile jubyte*  p, jubyte  v) { release(); *p = v; }
+inline void     OrderAccess::release_store(volatile jushort* p, jushort v) { release(); *p = v; }
+inline void     OrderAccess::release_store(volatile juint*   p, juint   v) { release(); *p = v; }
+inline void     OrderAccess::release_store(volatile julong*  p, julong  v)
+{ release(); os::atomic_copy64(&v, p); }
+inline void     OrderAccess::release_store(volatile jfloat*  p, jfloat  v) { release(); *p = v; }
+inline void     OrderAccess::release_store(volatile jdouble* p, jdouble v)
+{ release(); os::atomic_copy64(&v, p); }
+
+inline void     OrderAccess::release_store_ptr(volatile intptr_t* p, intptr_t v) { release(); *p = v; }
+inline void     OrderAccess::release_store_ptr(volatile void*     p, void*    v)
+{ release(); *(void* volatile *)p = v; }
+
+inline void     OrderAccess::store_fence(jbyte*   p, jbyte   v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(jshort*  p, jshort  v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(jint*    p, jint    v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(jlong*   p, jlong   v) { os::atomic_copy64(&v, p); fence(); }
+inline void     OrderAccess::store_fence(jubyte*  p, jubyte  v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(jushort* p, jushort v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(juint*   p, juint   v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(julong*  p, julong  v) { os::atomic_copy64(&v, p); fence(); }
+inline void     OrderAccess::store_fence(jfloat*  p, jfloat  v) { *p = v; fence(); }
+inline void     OrderAccess::store_fence(jdouble* p, jdouble v) { os::atomic_copy64(&v, p); fence(); }
+
+inline void     OrderAccess::store_ptr_fence(intptr_t* p, intptr_t v) { *p = v; fence(); }
+inline void     OrderAccess::store_ptr_fence(void**    p, void*    v) { *p = v; fence(); }
+
+inline void     OrderAccess::release_store_fence(volatile jbyte*   p, jbyte   v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile jshort*  p, jshort  v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile jint*    p, jint    v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile jlong*   p, jlong   v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile jubyte*  p, jubyte  v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile jushort* p, jushort v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile juint*   p, juint   v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile julong*  p, julong  v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile jfloat*  p, jfloat  v) { release_store(p, v); fence(); }
+inline void     OrderAccess::release_store_fence(volatile jdouble* p, jdouble v) { release_store(p, v); fence(); }
+
+inline void     OrderAccess::release_store_ptr_fence(volatile intptr_t* p, intptr_t v) { release_store_ptr(p, v); fence(); }
+inline void     OrderAccess::release_store_ptr_fence(volatile void*     p, void*    v) { release_store_ptr(p, v); fence(); }
+
+#endif // OS_CPU_BSD_ZERO_VM_ORDERACCESS_BSD_ZERO_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp b/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp
new file mode 100644
index 0000000..ff5b32d
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp
@@ -0,0 +1,564 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__)
+#include <pthread.h>
+# include <pthread_np.h> /* For pthread_attr_get_np */
+#endif
+
+// no precompiled headers
+#include "assembler_zero.inline.hpp"
+#include "classfile/classLoader.hpp"
+#include "classfile/systemDictionary.hpp"
+#include "classfile/vmSymbols.hpp"
+#include "code/icBuffer.hpp"
+#include "code/vtableStubs.hpp"
+#include "interpreter/interpreter.hpp"
+#include "jvm_bsd.h"
+#include "memory/allocation.inline.hpp"
+#include "mutex_bsd.inline.hpp"
+#include "nativeInst_zero.hpp"
+#include "os_share_bsd.hpp"
+#include "prims/jniFastGetField.hpp"
+#include "prims/jvm.h"
+#include "prims/jvm_misc.hpp"
+#include "runtime/arguments.hpp"
+#include "runtime/extendedPC.hpp"
+#include "runtime/frame.inline.hpp"
+#include "runtime/interfaceSupport.hpp"
+#include "runtime/java.hpp"
+#include "runtime/javaCalls.hpp"
+#include "runtime/mutexLocker.hpp"
+#include "runtime/osThread.hpp"
+#include "runtime/sharedRuntime.hpp"
+#include "runtime/stubRoutines.hpp"
+#include "runtime/timer.hpp"
+#include "thread_bsd.inline.hpp"
+#include "utilities/events.hpp"
+#include "utilities/vmError.hpp"
+#ifdef COMPILER1
+#include "c1/c1_Runtime1.hpp"
+#endif
+#ifdef COMPILER2
+#include "opto/runtime.hpp"
+#endif
+
+address os::current_stack_pointer() {
+  address dummy = (address) &dummy;
+  return dummy;
+}
+
+frame os::get_sender_for_C_frame(frame* fr) {
+  ShouldNotCallThis();
+}
+
+frame os::current_frame() {
+  // The only thing that calls this is the stack printing code in
+  // VMError::report:
+  //   - Step 110 (printing stack bounds) uses the sp in the frame
+  //     to determine the amount of free space on the stack.  We
+  //     set the sp to a close approximation of the real value in
+  //     order to allow this step to complete.
+  //   - Step 120 (printing native stack) tries to walk the stack.
+  //     The frame we create has a NULL pc, which is ignored as an
+  //     invalid frame.
+  frame dummy = frame();
+  dummy.set_sp((intptr_t *) current_stack_pointer());
+  return dummy;
+}
+
+char* os::non_memory_address_word() {
+  // Must never look like an address returned by reserve_memory,
+  // even in its subfields (as defined by the CPU immediate fields,
+  // if the CPU splits constants across multiple instructions).
+#ifdef SPARC
+  // On SPARC, 0 != %hi(any real address), because there is no
+  // allocation in the first 1Kb of the virtual address space.
+  return (char *) 0;
+#else
+  // This is the value for x86; works pretty well for PPC too.
+  return (char *) -1;
+#endif // SPARC
+}
+
+void os::initialize_thread() {
+  // Nothing to do.
+}
+
+address os::Bsd::ucontext_get_pc(ucontext_t* uc) {
+  ShouldNotCallThis();
+}
+
+ExtendedPC os::fetch_frame_from_context(void* ucVoid,
+                                        intptr_t** ret_sp,
+                                        intptr_t** ret_fp) {
+  ShouldNotCallThis();
+}
+
+frame os::fetch_frame_from_context(void* ucVoid) {
+  ShouldNotCallThis();
+}
+
+extern "C" JNIEXPORT int
+JVM_handle_bsd_signal(int sig,
+                        siginfo_t* info,
+                        void* ucVoid,
+                        int abort_if_unrecognized) {
+  ucontext_t* uc = (ucontext_t*) ucVoid;
+
+  Thread* t = ThreadLocalStorage::get_thread_slow();
+
+  SignalHandlerMark shm(t);
+
+  // Note: it's not uncommon that JNI code uses signal/sigset to
+  // install then restore certain signal handler (e.g. to temporarily
+  // block SIGPIPE, or have a SIGILL handler when detecting CPU
+  // type). When that happens, JVM_handle_bsd_signal() might be
+  // invoked with junk info/ucVoid. To avoid unnecessary crash when
+  // libjsig is not preloaded, try handle signals that do not require
+  // siginfo/ucontext first.
+
+  if (sig == SIGPIPE || sig == SIGXFSZ) {
+    // allow chained handler to go first
+    if (os::Bsd::chained_handler(sig, info, ucVoid)) {
+      return true;
+    } else {
+      if (PrintMiscellaneous && (WizardMode || Verbose)) {
+        char buf[64];
+        warning("Ignoring %s - see bugs 4229104 or 646499219",
+                os::exception_name(sig, buf, sizeof(buf)));
+      }
+      return true;
+    }
+  }
+
+  JavaThread* thread = NULL;
+  VMThread* vmthread = NULL;
+  if (os::Bsd::signal_handlers_are_installed) {
+    if (t != NULL ){
+      if(t->is_Java_thread()) {
+        thread = (JavaThread*)t;
+      }
+      else if(t->is_VM_thread()){
+        vmthread = (VMThread *)t;
+      }
+    }
+  }
+
+  if (info != NULL && thread != NULL) {
+    // Handle ALL stack overflow variations here
+    if (sig == SIGSEGV || sig == SIGBUS) {
+      address addr = (address) info->si_addr;
+
+      // check if fault address is within thread stack
+      if (addr < thread->stack_base() &&
+          addr >= thread->stack_base() - thread->stack_size()) {
+        // stack overflow
+        if (thread->in_stack_yellow_zone(addr)) {
+          thread->disable_stack_yellow_zone();
+          ShouldNotCallThis();
+        }
+        else if (thread->in_stack_red_zone(addr)) {
+          thread->disable_stack_red_zone();
+          ShouldNotCallThis();
+        }
+#ifndef _ALLBSD_SOURCE
+        else {
+          // Accessing stack address below sp may cause SEGV if
+          // current thread has MAP_GROWSDOWN stack. This should
+          // only happen when current thread was created by user
+          // code with MAP_GROWSDOWN flag and then attached to VM.
+          // See notes in os_bsd.cpp.
+          if (thread->osthread()->expanding_stack() == 0) {
+            thread->osthread()->set_expanding_stack();
+            if (os::Bsd::manually_expand_stack(thread, addr)) {
+              thread->osthread()->clear_expanding_stack();
+              return true;
+            }
+            thread->osthread()->clear_expanding_stack();
+          }
+          else {
+            fatal("recursive segv. expanding stack.");
+          }
+        }
+#endif
+      }
+    }
+
+    /*if (thread->thread_state() == _thread_in_Java) {
+      ShouldNotCallThis();
+    }
+    else*/ if (thread->thread_state() == _thread_in_vm &&
+               sig == SIGBUS && thread->doing_unsafe_access()) {
+      ShouldNotCallThis();
+    }
+
+    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC
+    // kicks in and the heap gets shrunk before the field access.
+    /*if (sig == SIGSEGV || sig == SIGBUS) {
+      address addr = JNI_FastGetField::find_slowcase_pc(pc);
+      if (addr != (address)-1) {
+        stub = addr;
+      }
+    }*/
+
+    // Check to see if we caught the safepoint code in the process
+    // of write protecting the memory serialization page.  It write
+    // enables the page immediately after protecting it so we can
+    // just return to retry the write.
+    if ((sig == SIGSEGV || sig == SIGBUS) &&
+        os::is_memory_serialize_page(thread, (address) info->si_addr)) {
+      // Block current thread until permission is restored.
+      os::block_on_serialize_page_trap();
+      return true;
+    }
+  }
+
+  // signal-chaining
+  if (os::Bsd::chained_handler(sig, info, ucVoid)) {
+     return true;
+  }
+
+  if (!abort_if_unrecognized) {
+    // caller wants another chance, so give it to him
+    return false;
+  }
+
+#ifndef PRODUCT
+  if (sig == SIGSEGV) {
+    fatal("\n#"
+          "\n#    /--------------------\\"
+          "\n#    | segmentation fault |"
+          "\n#    \\---\\ /--------------/"
+          "\n#        /"
+          "\n#    [-]        |\\_/|    "
+          "\n#    (+)=C      |o o|__  "
+          "\n#    | |        =-*-=__\\ "
+          "\n#    OOO        c_c_(___)");
+  }
+#endif // !PRODUCT
+
+  const char *fmt =
+      "caught unhandled signal " INT32_FORMAT " at address " PTR_FORMAT;
+  char buf[128];
+
+  sprintf(buf, fmt, sig, info->si_addr);
+  fatal(buf);
+}
+
+void os::Bsd::init_thread_fpu_state(void) {
+  // Nothing to do
+}
+
+#ifndef _ALLBSD_SOURCE
+int os::Bsd::get_fpu_control_word() {
+  ShouldNotCallThis();
+}
+
+void os::Bsd::set_fpu_control_word(int fpu) {
+  ShouldNotCallThis();
+}
+#endif
+
+bool os::is_allocatable(size_t bytes) {
+#ifdef _LP64
+  return true;
+#else
+  if (bytes < 2 * G) {
+    return true;
+  }
+
+  char* addr = reserve_memory(bytes, NULL);
+
+  if (addr != NULL) {
+    release_memory(addr, bytes);
+  }
+
+  return addr != NULL;
+#endif // _LP64
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// thread stack
+
+size_t os::Bsd::min_stack_allowed = 64 * K;
+
+bool os::Bsd::supports_variable_stack_size() {
+  return true;
+}
+
+size_t os::Bsd::default_stack_size(os::ThreadType thr_type) {
+#ifdef _LP64
+  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
+#else
+  size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
+#endif // _LP64
+  return s;
+}
+
+size_t os::Bsd::default_guard_size(os::ThreadType thr_type) {
+  // Only enable glibc guard pages for non-Java threads
+  // (Java threads have HotSpot guard pages)
+  return (thr_type == java_thread ? 0 : page_size());
+}
+
+static void current_stack_region(address *bottom, size_t *size) {
+  address stack_bottom;
+  address stack_top;
+  size_t stack_bytes;
+
+#ifdef __APPLE__
+  pthread_t self = pthread_self();
+  stack_top = (address) pthread_get_stackaddr_np(self);
+  stack_bytes = pthread_get_stacksize_np(self);
+  stack_bottom = stack_top - stack_bytes;
+#elif defined(__OpenBSD__)
+  stack_t ss;
+  int rslt = pthread_stackseg_np(pthread_self(), &ss);
+
+  if (rslt != 0)
+    fatal(err_msg("pthread_stackseg_np failed with err = " INT32_FORMAT,
+          rslt));
+
+  stack_top = (address) ss.ss_sp;
+  stack_bytes  = ss.ss_size;
+  stack_bottom = stack_top - stack_bytes;
+#elif defined(_ALLBSD_SOURCE)
+  pthread_attr_t attr;
+
+  int rslt = pthread_attr_init(&attr);
+
+  // JVM needs to know exact stack location, abort if it fails
+  if (rslt != 0)
+    fatal(err_msg("pthread_attr_init failed with err = " INT32_FORMAT, rslt));
+
+  rslt = pthread_attr_get_np(pthread_self(), &attr);
+
+  if (rslt != 0)
+    fatal(err_msg("pthread_attr_get_np failed with err = " INT32_FORMAT,
+          rslt));
+
+  if (pthread_attr_getstackaddr(&attr, (void **) &stack_bottom) != 0 ||
+      pthread_attr_getstacksize(&attr, &stack_bytes) != 0) {
+    fatal("Can not locate current stack attributes!");
+  }
+
+  pthread_attr_destroy(&attr);
+
+  stack_top = stack_bottom + stack_bytes;
+#else /* Linux */
+  pthread_attr_t attr;
+  int res = pthread_getattr_np(pthread_self(), &attr);
+  if (res != 0) {
+    if (res == ENOMEM) {
+      vm_exit_out_of_memory(0, "pthread_getattr_np");
+    }
+    else {
+      fatal(err_msg("pthread_getattr_np failed with errno = " INT32_FORMAT,
+            res));
+    }
+  }
+
+  res = pthread_attr_getstack(&attr, (void **) &stack_bottom, &stack_bytes);
+  if (res != 0) {
+    fatal(err_msg("pthread_attr_getstack failed with errno = " INT32_FORMAT,
+          res));
+  }
+  stack_top = stack_bottom + stack_bytes;
+
+  // The block of memory returned by pthread_attr_getstack() includes
+  // guard pages where present.  We need to trim these off.
+  size_t page_bytes = os::Bsd::page_size();
+  assert(((intptr_t) stack_bottom & (page_bytes - 1)) == 0, "unaligned stack");
+
+  size_t guard_bytes;
+  res = pthread_attr_getguardsize(&attr, &guard_bytes);
+  if (res != 0) {
+    fatal(err_msg(
+        "pthread_attr_getguardsize failed with errno = " INT32_FORMAT, res));
+  }
+  int guard_pages = align_size_up(guard_bytes, page_bytes) / page_bytes;
+  assert(guard_bytes == guard_pages * page_bytes, "unaligned guard");
+
+#ifdef IA64
+  // IA64 has two stacks sharing the same area of memory, a normal
+  // stack growing downwards and a register stack growing upwards.
+  // Guard pages, if present, are in the centre.  This code splits
+  // the stack in two even without guard pages, though in theory
+  // there's nothing to stop us allocating more to the normal stack
+  // or more to the register stack if one or the other were found
+  // to grow faster.
+  int total_pages = align_size_down(stack_bytes, page_bytes) / page_bytes;
+  stack_bottom += (total_pages - guard_pages) / 2 * page_bytes;
+#endif // IA64
+
+  stack_bottom += guard_bytes;
+
+  pthread_attr_destroy(&attr);
+
+  // The initial thread has a growable stack, and the size reported
+  // by pthread_attr_getstack is the maximum size it could possibly
+  // be given what currently mapped.  This can be huge, so we cap it.
+  if (os::Bsd::is_initial_thread()) {
+    stack_bytes = stack_top - stack_bottom;
+
+    if (stack_bytes > JavaThread::stack_size_at_create())
+      stack_bytes = JavaThread::stack_size_at_create();
+
+    stack_bottom = stack_top - stack_bytes;
+  }
+#endif
+
+  assert(os::current_stack_pointer() >= stack_bottom, "should do");
+  assert(os::current_stack_pointer() < stack_top, "should do");
+
+  *bottom = stack_bottom;
+  *size = stack_top - stack_bottom;
+}
+
+address os::current_stack_base() {
+  address bottom;
+  size_t size;
+  current_stack_region(&bottom, &size);
+  return bottom + size;
+}
+
+size_t os::current_stack_size() {
+  // stack size includes normal stack and HotSpot guard pages
+  address bottom;
+  size_t size;
+  current_stack_region(&bottom, &size);
+  return size;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// helper functions for fatal error handler
+
+void os::print_context(outputStream* st, void* context) {
+  ShouldNotCallThis();
+}
+
+void os::print_register_info(outputStream *st, void *context) {
+  ShouldNotCallThis();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// Stubs for things that would be in bsd_zero.s if it existed.
+// You probably want to disassemble these monkeys to check they're ok.
+
+extern "C" {
+  int SpinPause() {
+  }
+
+  int SafeFetch32(int *adr, int errValue) {
+    int value = errValue;
+    value = *adr;
+    return value;
+  }
+  intptr_t SafeFetchN(intptr_t *adr, intptr_t errValue) {
+    intptr_t value = errValue;
+    value = *adr;
+    return value;
+  }
+
+  void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
+    if (from > to) {
+      jshort *end = from + count;
+      while (from < end)
+        *(to++) = *(from++);
+    }
+    else if (from < to) {
+      jshort *end = from;
+      from += count - 1;
+      to   += count - 1;
+      while (from >= end)
+        *(to--) = *(from--);
+    }
+  }
+  void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
+    if (from > to) {
+      jint *end = from + count;
+      while (from < end)
+        *(to++) = *(from++);
+    }
+    else if (from < to) {
+      jint *end = from;
+      from += count - 1;
+      to   += count - 1;
+      while (from >= end)
+        *(to--) = *(from--);
+    }
+  }
+  void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
+    if (from > to) {
+      jlong *end = from + count;
+      while (from < end)
+        os::atomic_copy64(from++, to++);
+    }
+    else if (from < to) {
+      jlong *end = from;
+      from += count - 1;
+      to   += count - 1;
+      while (from >= end)
+        os::atomic_copy64(from--, to--);
+    }
+  }
+
+  void _Copy_arrayof_conjoint_bytes(HeapWord* from,
+                                    HeapWord* to,
+                                    size_t    count) {
+    memmove(to, from, count);
+  }
+  void _Copy_arrayof_conjoint_jshorts(HeapWord* from,
+                                      HeapWord* to,
+                                      size_t    count) {
+    memmove(to, from, count * 2);
+  }
+  void _Copy_arrayof_conjoint_jints(HeapWord* from,
+                                    HeapWord* to,
+                                    size_t    count) {
+    memmove(to, from, count * 4);
+  }
+  void _Copy_arrayof_conjoint_jlongs(HeapWord* from,
+                                     HeapWord* to,
+                                     size_t    count) {
+    memmove(to, from, count * 8);
+  }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+// Implementations of atomic operations not supported by processors.
+//  -- http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Atomic-Builtins.html
+
+#ifndef _LP64
+extern "C" {
+  long long unsigned int __sync_val_compare_and_swap_8(
+    volatile void *ptr,
+    long long unsigned int oldval,
+    long long unsigned int newval) {
+    ShouldNotCallThis();
+  }
+};
+#endif // !_LP64
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.hpp b/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.hpp
new file mode 100644
index 0000000..873e598
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.hpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007, 2008, 2010 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_OS_BSD_ZERO_HPP
+#define OS_CPU_BSD_ZERO_VM_OS_BSD_ZERO_HPP
+
+  static void setup_fpu() {}
+
+  static bool is_allocatable(size_t bytes);
+
+  // Used to register dynamic code cache area with the OS
+  // Note: Currently only used in 64 bit Windows implementations
+  static bool register_code_area(char *low, char *high) { return true; }
+
+  // Atomically copy 64 bits of data
+  static void atomic_copy64(volatile void *src, volatile void *dst) {
+#if defined(PPC) && !defined(_LP64)
+    double tmp;
+    asm volatile ("lfd  %0, 0(%1)\n"
+                  "stfd %0, 0(%2)\n"
+                  : "=f"(tmp)
+                  : "b"(src), "b"(dst));
+#elif defined(S390) && !defined(_LP64)
+    double tmp;
+    asm volatile ("ld  %0, 0(%1)\n"
+                  "std %0, 0(%2)\n"
+                  : "=r"(tmp)
+                  : "a"(src), "a"(dst));
+#else
+    *(jlong *) dst = *(jlong *) src;
+#endif
+  }
+
+#endif // OS_CPU_BSD_ZERO_VM_OS_BSD_ZERO_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/prefetch_bsd_zero.inline.hpp b/hotspot/src/os_cpu/bsd_zero/vm/prefetch_bsd_zero.inline.hpp
new file mode 100644
index 0000000..7c4f786
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/prefetch_bsd_zero.inline.hpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007, 2008 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_PREFETCH_BSD_ZERO_INLINE_HPP
+#define OS_CPU_BSD_ZERO_VM_PREFETCH_BSD_ZERO_INLINE_HPP
+
+#include "runtime/prefetch.hpp"
+
+inline void Prefetch::read(void* loc, intx interval) {
+}
+
+inline void Prefetch::write(void* loc, intx interval) {
+}
+
+#endif // OS_CPU_BSD_ZERO_VM_PREFETCH_BSD_ZERO_INLINE_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/threadLS_bsd_zero.cpp b/hotspot/src/os_cpu/bsd_zero/vm/threadLS_bsd_zero.cpp
new file mode 100644
index 0000000..cd6e0f7
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/threadLS_bsd_zero.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/threadLocalStorage.hpp"
+#include "thread_bsd.inline.hpp"
+
+void ThreadLocalStorage::generate_code_for_get_thread() {
+  // nothing to do
+}
+
+void ThreadLocalStorage::pd_init() {
+  // nothing to do
+}
+
+void ThreadLocalStorage::pd_set_thread(Thread* thread) {
+  os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
+}
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/threadLS_bsd_zero.hpp b/hotspot/src/os_cpu/bsd_zero/vm/threadLS_bsd_zero.hpp
new file mode 100644
index 0000000..0360b58
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/threadLS_bsd_zero.hpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_THREADLS_BSD_ZERO_HPP
+#define OS_CPU_BSD_ZERO_VM_THREADLS_BSD_ZERO_HPP
+
+// Processor dependent parts of ThreadLocalStorage
+
+ public:
+  static Thread* thread() {
+    return (Thread*) os::thread_local_storage_at(thread_index());
+  }
+
+#endif // OS_CPU_BSD_ZERO_VM_THREADLS_BSD_ZERO_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/thread_bsd_zero.cpp b/hotspot/src/os_cpu/bsd_zero/vm/thread_bsd_zero.cpp
new file mode 100644
index 0000000..eb0abaa
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/thread_bsd_zero.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2009, 2010 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/frame.inline.hpp"
+#include "thread_bsd.inline.hpp"
+
+void JavaThread::cache_global_variables() {
+  // nothing to do
+}
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/thread_bsd_zero.hpp b/hotspot/src/os_cpu/bsd_zero/vm/thread_bsd_zero.hpp
new file mode 100644
index 0000000..12971a6
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/thread_bsd_zero.hpp
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_THREAD_BSD_ZERO_HPP
+#define OS_CPU_BSD_ZERO_VM_THREAD_BSD_ZERO_HPP
+
+ private:
+  ZeroStack  _zero_stack;
+  ZeroFrame* _top_zero_frame;
+
+  void pd_initialize() {
+    _top_zero_frame = NULL;
+  }
+
+ public:
+  ZeroStack *zero_stack() {
+    return &_zero_stack;
+  }
+
+ public:
+  ZeroFrame *top_zero_frame() {
+    return _top_zero_frame;
+  }
+  void push_zero_frame(ZeroFrame *frame) {
+    *(ZeroFrame **) frame = _top_zero_frame;
+    _top_zero_frame = frame;
+  }
+  void pop_zero_frame() {
+    zero_stack()->set_sp((intptr_t *) _top_zero_frame + 1);
+    _top_zero_frame = *(ZeroFrame **) _top_zero_frame;
+  }
+
+ public:
+  static ByteSize zero_stack_offset() {
+    return byte_offset_of(JavaThread, _zero_stack);
+  }
+  static ByteSize top_zero_frame_offset() {
+    return byte_offset_of(JavaThread, _top_zero_frame);
+  }
+
+ public:
+  void record_base_of_stack_pointer() {
+    assert(top_zero_frame() == NULL, "junk on stack prior to Java call");
+  }
+  void set_base_of_stack_pointer(intptr_t* base_sp) {
+    assert(base_sp == NULL, "should be");
+    assert(top_zero_frame() == NULL, "junk on stack after Java call");
+  }
+
+ public:
+  void set_last_Java_frame() {
+    set_last_Java_frame(top_zero_frame(), zero_stack()->sp());
+  }
+  void reset_last_Java_frame() {
+    frame_anchor()->zap();
+  }
+  void set_last_Java_frame(ZeroFrame* fp, intptr_t* sp) {
+    frame_anchor()->set(sp, NULL, fp);
+  }
+
+ public:
+  ZeroFrame* last_Java_fp() {
+    return frame_anchor()->last_Java_fp();
+  }
+
+ private:
+  frame pd_last_frame() {
+    assert(has_last_Java_frame(), "must have last_Java_sp() when suspended");
+    return frame(last_Java_fp(), last_Java_sp());
+  }
+
+ public:
+  static ByteSize last_Java_fp_offset() {
+    return byte_offset_of(JavaThread, _anchor) +
+      JavaFrameAnchor::last_Java_fp_offset();
+  }
+
+ public:
+  // Check for pending suspend requests and pending asynchronous
+  // exceptions.  There are separate accessors for these, but
+  // _suspend_flags is volatile so using them would be unsafe.
+  bool has_special_condition_for_native_trans() {
+    return _suspend_flags != 0;
+  }
+
+ public:
+  bool pd_get_top_frame_for_signal_handler(frame* fr_addr,
+                                           void* ucontext,
+                                           bool isInJava) {
+    ShouldNotCallThis();
+  }
+
+  // These routines are only used on cpu architectures that
+  // have separate register stacks (Itanium).
+  static bool register_stack_overflow() { return false; }
+  static void enable_register_stack_guard() {}
+  static void disable_register_stack_guard() {}
+
+#endif // OS_CPU_BSD_ZERO_VM_THREAD_BSD_ZERO_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/vmStructs_bsd_zero.hpp b/hotspot/src/os_cpu/bsd_zero/vm/vmStructs_bsd_zero.hpp
new file mode 100644
index 0000000..17165cc
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/vmStructs_bsd_zero.hpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2007 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_BSD_ZERO_VM_VMSTRUCTS_BSD_ZERO_HPP
+#define OS_CPU_BSD_ZERO_VM_VMSTRUCTS_BSD_ZERO_HPP
+
+// These are the OS and CPU-specific fields, types and integer
+// constants required by the Serviceability Agent. This file is
+// referenced by vmStructs.cpp.
+
+#define VM_STRUCTS_OS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field, last_entry) \
+  /* This must be the last entry, and must be present */                \
+  last_entry()
+
+
+#define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type, last_entry) \
+  /* This must be the last entry, and must be present */                \
+  last_entry()
+
+#define VM_INT_CONSTANTS_OS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant, last_entry) \
+  /* This must be the last entry, and must be present */                \
+  last_entry()
+
+#define VM_LONG_CONSTANTS_OS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant, last_entry) \
+  /* This must be the last entry, and must be present */                \
+  last_entry()
+
+#endif // OS_CPU_BSD_ZERO_VM_VMSTRUCTS_BSD_ZERO_HPP
diff --git a/hotspot/src/os_cpu/bsd_zero/vm/vm_version_bsd_zero.cpp b/hotspot/src/os_cpu/bsd_zero/vm/vm_version_bsd_zero.cpp
new file mode 100644
index 0000000..f2ca79f
--- /dev/null
+++ b/hotspot/src/os_cpu/bsd_zero/vm/vm_version_bsd_zero.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2009 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/os.hpp"
+#include "vm_version_zero.hpp"
+
+// This file is intentionally empty
diff --git a/hotspot/src/os_cpu/linux_zero/vm/globals_linux_zero.hpp b/hotspot/src/os_cpu/linux_zero/vm/globals_linux_zero.hpp
index f12bec9..d952cb7 100644
--- a/hotspot/src/os_cpu/linux_zero/vm/globals_linux_zero.hpp
+++ b/hotspot/src/os_cpu/linux_zero/vm/globals_linux_zero.hpp
@@ -38,7 +38,6 @@
 #else
 define_pd_global(intx,  VMThreadStackSize,       512);
 #endif // _LP64
-define_pd_global(intx,  SurvivorRatio,           8);
 define_pd_global(intx,  CompilerThreadStackSize, 0);
 define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
 
diff --git a/hotspot/src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp b/hotspot/src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp
index f39b7a0..c064210 100644
--- a/hotspot/src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp
+++ b/hotspot/src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -85,13 +85,35 @@
 }
 
 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
-  // FIXME
-  (void)memmove(to, from, count << LogBytesPerShort);
+  if (from > to) {
+    while (count-- > 0) {
+      // Copy forwards
+      *to++ = *from++;
+    }
+  } else {
+    from += count - 1;
+    to   += count - 1;
+    while (count-- > 0) {
+      // Copy backwards
+      *to-- = *from--;
+    }
+  }
 }
 
 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
-  // FIXME
-  (void)memmove(to, from, count << LogBytesPerInt);
+  if (from > to) {
+    while (count-- > 0) {
+      // Copy forwards
+      *to++ = *from++;
+    }
+  } else {
+    from += count - 1;
+    to   += count - 1;
+    while (count-- > 0) {
+      // Copy backwards
+      *to-- = *from--;
+    }
+  }
 }
 
 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
diff --git a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/CallSite.java b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/CallSite.java
index c72d777..354b32a 100644
--- a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/CallSite.java
+++ b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/CallSite.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,6 +37,8 @@
     private int receiver_count;
     private String reason;
     private List<CallSite> calls;
+    private int endNodes;
+    private double timeStamp;
 
     CallSite() {
     }
@@ -93,18 +95,22 @@
         emit(stream, indent);
         String m = getMethod().getHolder().replace('/', '.') + "::" + getMethod().getName();
         if (getReason() == null) {
-            stream.println("  @ " + getBci() + " " + m + " (" + getMethod().getBytes() + " bytes)");
+            stream.print("  @ " + getBci() + " " + m + " (" + getMethod().getBytes() + " bytes)");
 
         } else {
             if (isCompat()) {
-                stream.println("  @ " + getBci() + " " + m + " " + getReason());
+                stream.print("  @ " + getBci() + " " + m + " " + getReason());
             } else {
-                stream.println("- @ " + getBci() + " " + m +
+                stream.print("- @ " + getBci() + " " + m +
                         " (" + getMethod().getBytes() + " bytes) " + getReason());
             }
         }
+        if (getEndNodes() > 0) {
+          stream.printf(" (end time: %6.4f nodes: %d)", getTimeStamp(), getEndNodes());
+        }
+        stream.println("");
         if (getReceiver() != null) {
-            emit(stream, indent + 3);
+            emit(stream, indent + 4);
             //                 stream.println("type profile " + method.holder + " -> " + receiver + " (" +
             //                                receiver_count + "/" + count + "," + (receiver_count * 100 / count) + "%)");
             stream.println("type profile " + getMethod().getHolder() + " -> " + getReceiver() + " (" +
@@ -180,4 +186,21 @@
     public static void setCompat(boolean aCompat) {
         compat = aCompat;
     }
+
+    void setEndNodes(int n) {
+        endNodes = n;
+    }
+
+    public int getEndNodes() {
+        return endNodes;
+    }
+
+    void setTimeStamp(double time) {
+        timeStamp = time;
+    }
+
+    public double getTimeStamp() {
+        return timeStamp;
+    }
+
 }
diff --git a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java
index 5705888..12689b0 100644
--- a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java
+++ b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -126,7 +126,6 @@
                 maxattempts = Math.max(maxattempts,c.getAttempts());
                 elapsed += c.getElapsedTime();
                 for (Phase phase : c.getPhases()) {
-                    out.printf("\t%s %6.4f\n", phase.getName(), phase.getElapsedTime());
                     Double v = phaseTime.get(phase.getName());
                     if (v == null) {
                         v = Double.valueOf(0.0);
@@ -138,6 +137,7 @@
                         v2 = Integer.valueOf(0);
                     }
                     phaseNodes.put(phase.getName(), Integer.valueOf(v2.intValue() + phase.getNodes()));
+                    out.printf("\t%s %6.4f %d %d\n", phase.getName(), phase.getElapsedTime(), phase.getStartNodes(), phase.getNodes());
                 }
             } else if (e instanceof MakeNotEntrantEvent) {
                 MakeNotEntrantEvent mne = (MakeNotEntrantEvent) e;
diff --git a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java
index 265e92e..d864db0 100644
--- a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java
+++ b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -365,7 +365,7 @@
             if (currentTrap != null) {
                 currentTrap.addJVMS(atts.getValue("method"), Integer.parseInt(atts.getValue("bci")));
             } else {
-                System.err.println("Missing uncommon_trap for jvms");
+                // Ignore <eliminate_allocation type='667'> and <eliminate_lock lock='1'>
             }
         } else if (qname.equals("nmethod")) {
             String id = makeId(atts);
@@ -391,6 +391,11 @@
                     throw new InternalError("call site and parse don't match");
                 }
             }
+        } else if (qname.equals("parse_done")) {
+            CallSite call = scopes.pop();
+            call.setEndNodes(Integer.parseInt(search(atts, "nodes")));
+            call.setTimeStamp(Double.parseDouble(search(atts, "stamp")));
+            scopes.push(call);
         }
     }
 
diff --git a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Phase.java b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Phase.java
index 4dc50ca..b448f45 100644
--- a/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Phase.java
+++ b/hotspot/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Phase.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
     }
 
     int getNodes() {
-        return getStartNodes();
+        return getEndNodes() - getStartNodes();
     }
 
     void setEndNodes(int n) {
diff --git a/hotspot/src/share/vm/adlc/adlc.hpp b/hotspot/src/share/vm/adlc/adlc.hpp
index 0ed4b77..8d48ed6 100644
--- a/hotspot/src/share/vm/adlc/adlc.hpp
+++ b/hotspot/src/share/vm/adlc/adlc.hpp
@@ -67,9 +67,9 @@
 #endif
 #endif // _WIN32
 
-#ifdef LINUX
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
   #include <inttypes.h>
-#endif // LINUX
+#endif // LINUX || _ALLBSD_SOURCE
 
 // Macros
 #define uint32 unsigned int
diff --git a/hotspot/src/share/vm/adlc/formssel.cpp b/hotspot/src/share/vm/adlc/formssel.cpp
index 85118e8..d3817ed 100644
--- a/hotspot/src/share/vm/adlc/formssel.cpp
+++ b/hotspot/src/share/vm/adlc/formssel.cpp
@@ -1225,7 +1225,7 @@
   // Handle special constant table variables.
   if (strcmp(rep_var, "constanttablebase") == 0) {
     fprintf(fp, "char reg[128];  ra->dump_register(in(mach_constant_base_node_input()), reg);\n");
-    fprintf(fp, "st->print(\"%%s\");\n");
+    fprintf(fp, "    st->print(\"%%s\", reg);\n");
     return;
   }
   if (strcmp(rep_var, "constantoffset") == 0) {
diff --git a/hotspot/src/share/vm/asm/codeBuffer.cpp b/hotspot/src/share/vm/asm/codeBuffer.cpp
index f2d9bbc..f52b942 100644
--- a/hotspot/src/share/vm/asm/codeBuffer.cpp
+++ b/hotspot/src/share/vm/asm/codeBuffer.cpp
@@ -26,6 +26,7 @@
 #include "asm/codeBuffer.hpp"
 #include "compiler/disassembler.hpp"
 #include "utilities/copy.hpp"
+#include "utilities/xmlstream.hpp"
 
 // The structure of a CodeSection:
 //
@@ -81,7 +82,7 @@
 CodeBuffer::CodeBuffer(CodeBlob* blob) {
   initialize_misc("static buffer");
   initialize(blob->content_begin(), blob->content_size());
-  assert(verify_section_allocation(), "initial use of buffer OK");
+  verify_section_allocation();
 }
 
 void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) {
@@ -108,17 +109,18 @@
     _insts.initialize_locs(locs_size / sizeof(relocInfo));
   }
 
-  assert(verify_section_allocation(), "initial use of blob is OK");
+  verify_section_allocation();
 }
 
 
 CodeBuffer::~CodeBuffer() {
+  verify_section_allocation();
+
   // If we allocate our code buffer from the CodeCache
   // via a BufferBlob, and it's not permanent, then
   // free the BufferBlob.
   // The rest of the memory will be freed when the ResourceObj
   // is released.
-  assert(verify_section_allocation(), "final storage configuration still OK");
   for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) {
     // Previous incarnations of this buffer are held live, so that internal
     // addresses constructed before expansions will not be confused.
@@ -484,7 +486,7 @@
 
   // Done calculating sections; did it come out to the right end?
   assert(buf_offset == total_content_size(), "sanity");
-  assert(dest->verify_section_allocation(), "final configuration works");
+  dest->verify_section_allocation();
 }
 
 csize_t CodeBuffer::total_offset_of(CodeSection* cs) const {
@@ -632,7 +634,8 @@
 // CodeBuffer gets the final layout (consts, insts, stubs in order of
 // ascending address).
 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const {
-  DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size);
+  address dest_end = dest->_total_start + dest->_total_size;
+  address dest_filled = NULL;
   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
     // pull code out of each section
     const CodeSection* cs = code_section(n);
@@ -654,6 +657,8 @@
       Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(),
                           Assembler::code_fill_byte());
     }
+    // Keep track of the highest filled address
+    dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining());
 
     assert(cs->locs_start() != (relocInfo*)badAddress,
            "this section carries no reloc storage, but reloc was attempted");
@@ -668,6 +673,14 @@
       }
     }
   }
+
+  if (dest->blob() == NULL) {
+    // Destination is a final resting place, not just another buffer.
+    // Normalize uninitialized bytes in the final padding.
+    Copy::fill_to_bytes(dest_filled, dest_end - dest_filled,
+                        Assembler::code_fill_byte());
+
+  }
 }
 
 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs,
@@ -799,7 +812,7 @@
   _decode_begin = NULL;  // sanity
 
   // Make certain that the new sections are all snugly inside the new blob.
-  assert(verify_section_allocation(), "expanded allocation is ship-shape");
+  verify_section_allocation();
 
 #ifndef PRODUCT
   if (PrintNMethods && (WizardMode || Verbose)) {
@@ -828,35 +841,48 @@
   DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress);
 }
 
-#ifdef ASSERT
-bool CodeBuffer::verify_section_allocation() {
+void CodeBuffer::verify_section_allocation() {
   address tstart = _total_start;
-  if (tstart == badAddress)  return true;  // smashed by set_blob(NULL)
+  if (tstart == badAddress)  return;  // smashed by set_blob(NULL)
   address tend   = tstart + _total_size;
   if (_blob != NULL) {
-    assert(tstart >= _blob->content_begin(), "sanity");
-    assert(tend   <= _blob->content_end(),   "sanity");
+
+    guarantee(tstart >= _blob->content_begin(), "sanity");
+    guarantee(tend   <= _blob->content_end(),   "sanity");
   }
   // Verify disjointness.
   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
     CodeSection* sect = code_section(n);
     if (!sect->is_allocated() || sect->is_empty())  continue;
-    assert((intptr_t)sect->start() % sect->alignment() == 0
+    guarantee((intptr_t)sect->start() % sect->alignment() == 0
            || sect->is_empty() || _blob == NULL,
            "start is aligned");
     for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) {
       CodeSection* other = code_section(m);
       if (!other->is_allocated() || other == sect)  continue;
-      assert(!other->contains(sect->start()    ), "sanity");
+      guarantee(!other->contains(sect->start()    ), "sanity");
       // limit is an exclusive address and can be the start of another
       // section.
-      assert(!other->contains(sect->limit() - 1), "sanity");
+      guarantee(!other->contains(sect->limit() - 1), "sanity");
     }
-    assert(sect->end() <= tend, "sanity");
+    guarantee(sect->end() <= tend, "sanity");
+    guarantee(sect->end() <= sect->limit(), "sanity");
   }
-  return true;
 }
-#endif //ASSERT
+
+void CodeBuffer::log_section_sizes(const char* name) {
+  if (xtty != NULL) {
+    // log info about buffer usage
+    xtty->print_cr("<blob name='%s' size='%d'>", name, _total_size);
+    for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
+      CodeSection* sect = code_section(n);
+      if (!sect->is_allocated() || sect->is_empty())  continue;
+      xtty->print_cr("<sect index='%d' size='" SIZE_FORMAT "' free='" SIZE_FORMAT "'/>",
+                     n, sect->limit() - sect->start(), sect->limit() - sect->end());
+    }
+    xtty->print_cr("</blob>");
+  }
+}
 
 #ifndef PRODUCT
 
@@ -884,7 +910,6 @@
   _comments.add_comment(offset, comment);
 }
 
-
 class CodeComment: public CHeapObj {
  private:
   friend class CodeComments;
diff --git a/hotspot/src/share/vm/asm/codeBuffer.hpp b/hotspot/src/share/vm/asm/codeBuffer.hpp
index e9b2950..53c90c2 100644
--- a/hotspot/src/share/vm/asm/codeBuffer.hpp
+++ b/hotspot/src/share/vm/asm/codeBuffer.hpp
@@ -362,10 +362,8 @@
   // helper for CodeBuffer::expand()
   void take_over_code_from(CodeBuffer* cs);
 
-#ifdef ASSERT
   // ensure sections are disjoint, ordered, and contained in the blob
-  bool verify_section_allocation();
-#endif
+  void verify_section_allocation();
 
   // copies combined relocations to the blob, returns bytes copied
   // (if target is null, it is a dry run only, just for sizing)
@@ -393,7 +391,7 @@
     assert(code_start != NULL, "sanity");
     initialize_misc("static buffer");
     initialize(code_start, code_size);
-    assert(verify_section_allocation(), "initial use of buffer OK");
+    verify_section_allocation();
   }
 
   // (2) CodeBuffer referring to pre-allocated CodeBlob.
@@ -545,6 +543,9 @@
 
   void block_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
 
+  // Log a little info about section usage in the CodeBuffer
+  void log_section_sizes(const char* name);
+
 #ifndef PRODUCT
  public:
   // Printing / Decoding
diff --git a/hotspot/src/share/vm/c1/c1_Canonicalizer.hpp b/hotspot/src/share/vm/c1/c1_Canonicalizer.hpp
index c5048c7..571e707 100644
--- a/hotspot/src/share/vm/c1/c1_Canonicalizer.hpp
+++ b/hotspot/src/share/vm/c1/c1_Canonicalizer.hpp
@@ -51,6 +51,7 @@
 
  public:
   Canonicalizer(Compilation* c, Value x, int bci) : _compilation(c), _canonical(x), _bci(bci) {
+    NOT_PRODUCT(x->set_printable_bci(bci));
     if (CanonicalizeNodes) x->visit(this);
   }
   Value canonical() const                        { return _canonical; }
diff --git a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
index e103fbf..0c3f32b 100644
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
@@ -1165,11 +1165,11 @@
   Goto *x = new Goto(block_at(to_bci), to_bci <= from_bci);
   if (is_profiling()) {
     compilation()->set_would_profile(true);
-  }
-  if (profile_branches()) {
-    x->set_profiled_method(method());
     x->set_profiled_bci(bci());
-    x->set_should_profile(true);
+    if (profile_branches()) {
+      x->set_profiled_method(method());
+      x->set_should_profile(true);
+    }
   }
   append(x);
 }
@@ -1203,9 +1203,9 @@
     Goto *goto_node = i->as_Goto();
     if (goto_node != NULL) {
       compilation()->set_would_profile(true);
+      goto_node->set_profiled_bci(bci());
       if (profile_branches()) {
         goto_node->set_profiled_method(method());
-        goto_node->set_profiled_bci(bci());
         goto_node->set_should_profile(true);
         // Find out which successor is used.
         if (goto_node->default_sux() == tsux) {
diff --git a/hotspot/src/share/vm/c1/c1_LIR.cpp b/hotspot/src/share/vm/c1/c1_LIR.cpp
index 44f2b62..267b966 100644
--- a/hotspot/src/share/vm/c1/c1_LIR.cpp
+++ b/hotspot/src/share/vm/c1/c1_LIR.cpp
@@ -1394,8 +1394,15 @@
 }
 
 
-void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception) {
-  append(new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception));
+void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
+                           CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {
+  LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);
+  if (profiled_method != NULL) {
+    c->set_profiled_method(profiled_method);
+    c->set_profiled_bci(profiled_bci);
+    c->set_should_profile(true);
+  }
+  append(c);
 }
 
 
diff --git a/hotspot/src/share/vm/c1/c1_LIR.hpp b/hotspot/src/share/vm/c1/c1_LIR.hpp
index a2770e4..c440b71 100644
--- a/hotspot/src/share/vm/c1/c1_LIR.hpp
+++ b/hotspot/src/share/vm/c1/c1_LIR.hpp
@@ -2100,7 +2100,7 @@
   void fpop_raw()                                { append(new LIR_Op0(lir_fpop_raw)); }
 
   void instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci);
-  void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
+  void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci);
 
   void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
diff --git a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
index 676efe3..f9099e9 100644
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
@@ -2493,7 +2493,7 @@
 
     // increment backedge counter if needed
     CodeEmitInfo* info = state_for(x, state);
-    increment_backedge_counter(info, info->stack()->bci());
+    increment_backedge_counter(info, x->profiled_bci());
     CodeEmitInfo* safepoint_info = state_for(x, state);
     __ safepoint(safepoint_poll_register(), safepoint_info);
   }
@@ -2970,8 +2970,8 @@
   // accessors are also always mature.
   if (!x->inlinee()->is_accessor()) {
     CodeEmitInfo* info = state_for(x, x->state(), true);
-    // Increment invocation counter, don't notify the runtime, because we don't inline loops,
-    increment_event_counter_impl(info, x->inlinee(), 0, InvocationEntryBci, false, false);
+    // Notify the runtime very infrequently only to take care of counter overflows
+    increment_event_counter_impl(info, x->inlinee(), (1 << Tier23InlineeNotifyFreqLog) - 1, InvocationEntryBci, false, true);
   }
 }
 
diff --git a/hotspot/src/share/vm/c1/c1_Runtime1.cpp b/hotspot/src/share/vm/c1/c1_Runtime1.cpp
index 675d389..183be88 100644
--- a/hotspot/src/share/vm/c1/c1_Runtime1.cpp
+++ b/hotspot/src/share/vm/c1/c1_Runtime1.cpp
@@ -681,6 +681,23 @@
   }
 JRT_END
 
+// Cf. OptoRuntime::deoptimize_caller_frame
+JRT_ENTRY(void, Runtime1::deoptimize(JavaThread* thread))
+  // Called from within the owner thread, so no need for safepoint
+  RegisterMap reg_map(thread, false);
+  frame stub_frame = thread->last_frame();
+  assert(stub_frame.is_runtime_frame(), "sanity check");
+  frame caller_frame = stub_frame.sender(&reg_map);
+
+  // We are coming from a compiled method; check this is true.
+  assert(CodeCache::find_nmethod(caller_frame.pc()) != NULL, "sanity");
+
+  // Deoptimize the caller frame.
+  Deoptimization::deoptimize_frame(thread, caller_frame.id());
+
+  // Return to the now deoptimized frame.
+JRT_END
+
 
 static klassOop resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
   Bytecode_field field_access(caller, bci);
diff --git a/hotspot/src/share/vm/c1/c1_Runtime1.hpp b/hotspot/src/share/vm/c1/c1_Runtime1.hpp
index 5499740..2032564 100644
--- a/hotspot/src/share/vm/c1/c1_Runtime1.hpp
+++ b/hotspot/src/share/vm/c1/c1_Runtime1.hpp
@@ -63,6 +63,7 @@
   stub(monitorenter_nofpu)             /* optimized version that does not preserve fpu registers */ \
   stub(monitorexit)                  \
   stub(monitorexit_nofpu)              /* optimized version that does not preserve fpu registers */ \
+  stub(deoptimize)                   \
   stub(access_field_patching)        \
   stub(load_klass_patching)          \
   stub(g1_pre_barrier_slow)          \
@@ -152,6 +153,8 @@
   static void monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock);
   static void monitorexit (JavaThread* thread, BasicObjectLock* lock);
 
+  static void deoptimize(JavaThread* thread);
+
   static int access_field_patching(JavaThread* thread);
   static int move_klass_patching(JavaThread* thread);
 
diff --git a/hotspot/src/share/vm/c1/c1_globals.hpp b/hotspot/src/share/vm/c1/c1_globals.hpp
index 60fe6d0..15f3cc1 100644
--- a/hotspot/src/share/vm/c1/c1_globals.hpp
+++ b/hotspot/src/share/vm/c1/c1_globals.hpp
@@ -47,6 +47,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "c1_globals_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "c1_globals_bsd.hpp"
+#endif
 
 //
 // Defines all global flags used by the client compiler.
diff --git a/hotspot/src/share/vm/ci/ciEnv.cpp b/hotspot/src/share/vm/ci/ciEnv.cpp
index 82492a0..1366177 100644
--- a/hotspot/src/share/vm/ci/ciEnv.cpp
+++ b/hotspot/src/share/vm/ci/ciEnv.cpp
@@ -473,6 +473,7 @@
   }
 
   if (require_local)  return NULL;
+
   // Not yet loaded into the VM, or not governed by loader constraints.
   // Make a CI representative for it.
   return get_unloaded_klass(accessing_klass, name);
@@ -498,7 +499,7 @@
                                         bool& is_accessible,
                                         ciInstanceKlass* accessor) {
   EXCEPTION_CONTEXT;
-  KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
+  KlassHandle klass(THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
   Symbol* klass_name = NULL;
   if (klass.is_null()) {
     // The klass has not been inserted into the constant pool.
@@ -785,17 +786,17 @@
   // Either the declared holder was not loaded, or the method could
   // not be found.  Create a dummy ciMethod to represent the failed
   // lookup.
-
-  return get_unloaded_method(declared_holder,
-                             get_symbol(name_sym),
-                             get_symbol(sig_sym));
+  ciSymbol* name      = get_symbol(name_sym);
+  ciSymbol* signature = get_symbol(sig_sym);
+  return get_unloaded_method(declared_holder, name, signature, accessor);
 }
 
 
 // ------------------------------------------------------------------
 // ciEnv::get_fake_invokedynamic_method_impl
 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(constantPoolHandle cpool,
-                                                    int index, Bytecodes::Code bc) {
+                                                    int index, Bytecodes::Code bc,
+                                                    ciInstanceKlass* accessor) {
   // Compare the following logic with InterpreterRuntime::resolve_invokedynamic.
   assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic");
 
@@ -807,9 +808,10 @@
   // Call site might not be resolved yet.  We could create a real invoker method from the
   // compiler, but it is simpler to stop the code path here with an unlinked method.
   if (!is_resolved) {
-    ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
-    ciSymbol*        sig_sym  = get_symbol(cpool->signature_ref_at(index));
-    return get_unloaded_method(mh_klass, ciSymbol::invokeExact_name(), sig_sym);
+    ciInstanceKlass* holder    = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
+    ciSymbol*        name      = ciSymbol::invokeExact_name();
+    ciSymbol*        signature = get_symbol(cpool->signature_ref_at(index));
+    return get_unloaded_method(holder, name, signature, accessor);
   }
 
   // Get the invoker methodOop from the constant pool.
@@ -850,9 +852,9 @@
                                      int index, Bytecodes::Code bc,
                                      ciInstanceKlass* accessor) {
   if (bc == Bytecodes::_invokedynamic) {
-    GUARDED_VM_ENTRY(return get_fake_invokedynamic_method_impl(cpool, index, bc);)
+    GUARDED_VM_ENTRY(return get_fake_invokedynamic_method_impl(cpool, index, bc, accessor);)
   } else {
-    GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);)
+    GUARDED_VM_ENTRY(return get_method_by_index_impl(          cpool, index, bc, accessor);)
   }
 }
 
diff --git a/hotspot/src/share/vm/ci/ciEnv.hpp b/hotspot/src/share/vm/ci/ciEnv.hpp
index f5242ca..12f4bb2 100644
--- a/hotspot/src/share/vm/ci/ciEnv.hpp
+++ b/hotspot/src/share/vm/ci/ciEnv.hpp
@@ -153,7 +153,8 @@
                                       int method_index, Bytecodes::Code bc,
                                       ciInstanceKlass* loading_klass);
   ciMethod*  get_fake_invokedynamic_method_impl(constantPoolHandle cpool,
-                                                int index, Bytecodes::Code bc);
+                                                int index, Bytecodes::Code bc,
+                                                ciInstanceKlass* accessor);
 
   // Helper methods
   bool       check_klass_accessibility(ciKlass* accessing_klass,
@@ -192,13 +193,14 @@
   // the result.
   ciMethod* get_unloaded_method(ciInstanceKlass* holder,
                                 ciSymbol*        name,
-                                ciSymbol*        signature) {
-    return _factory->get_unloaded_method(holder, name, signature);
+                                ciSymbol*        signature,
+                                ciInstanceKlass* accessor) {
+    return _factory->get_unloaded_method(holder, name, signature, accessor);
   }
 
   // Get a ciKlass representing an unloaded klass.
   // Ensures uniqueness of the result.
-  ciKlass* get_unloaded_klass(ciKlass* accessing_klass,
+  ciKlass* get_unloaded_klass(ciKlass*  accessing_klass,
                               ciSymbol* name) {
     return _factory->get_unloaded_klass(accessing_klass, name, true);
   }
@@ -224,7 +226,7 @@
 
   // See if we already have an unloaded klass for the given name
   // or return NULL if not.
-  ciKlass *check_get_unloaded_klass(ciKlass* accessing_klass, ciSymbol* name) {
+  ciKlass *check_get_unloaded_klass(ciKlass*  accessing_klass, ciSymbol* name) {
     return _factory->get_unloaded_klass(accessing_klass, name, false);
   }
 
diff --git a/hotspot/src/share/vm/ci/ciMethod.cpp b/hotspot/src/share/vm/ci/ciMethod.cpp
index a985d5e..6049d7b 100644
--- a/hotspot/src/share/vm/ci/ciMethod.cpp
+++ b/hotspot/src/share/vm/ci/ciMethod.cpp
@@ -148,21 +148,27 @@
 //
 // Unloaded method.
 ciMethod::ciMethod(ciInstanceKlass* holder,
-                   ciSymbol* name,
-                   ciSymbol* signature) : ciObject(ciMethodKlass::make()) {
-  // These fields are always filled in.
-  _name = name;
-  _holder = holder;
-  _signature = new (CURRENT_ENV->arena()) ciSignature(_holder, constantPoolHandle(), signature);
-  _intrinsic_id = vmIntrinsics::_none;
-  _liveness = NULL;
-  _can_be_statically_bound = false;
-  _method_blocks = NULL;
-  _method_data = NULL;
+                   ciSymbol*        name,
+                   ciSymbol*        signature,
+                   ciInstanceKlass* accessor) :
+  ciObject(ciMethodKlass::make()),
+  _name(                   name),
+  _holder(                 holder),
+  _intrinsic_id(           vmIntrinsics::_none),
+  _liveness(               NULL),
+  _can_be_statically_bound(false),
+  _method_blocks(          NULL),
+  _method_data(            NULL)
 #if defined(COMPILER2) || defined(SHARK)
-  _flow = NULL;
-  _bcea = NULL;
+  ,
+  _flow(                   NULL),
+  _bcea(                   NULL)
 #endif // COMPILER2 || SHARK
+{
+  // Usually holder and accessor are the same type but in some cases
+  // the holder has the wrong class loader (e.g. invokedynamic call
+  // sites) so we pass the accessor.
+  _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);
 }
 
 
diff --git a/hotspot/src/share/vm/ci/ciMethod.hpp b/hotspot/src/share/vm/ci/ciMethod.hpp
index db71752..45a491f 100644
--- a/hotspot/src/share/vm/ci/ciMethod.hpp
+++ b/hotspot/src/share/vm/ci/ciMethod.hpp
@@ -88,7 +88,7 @@
 #endif
 
   ciMethod(methodHandle h_m);
-  ciMethod(ciInstanceKlass* holder, ciSymbol* name, ciSymbol* signature);
+  ciMethod(ciInstanceKlass* holder, ciSymbol* name, ciSymbol* signature, ciInstanceKlass* accessor);
 
   methodOop get_methodOop() const {
     methodOop m = (methodOop)get_oop();
diff --git a/hotspot/src/share/vm/ci/ciMethodHandle.cpp b/hotspot/src/share/vm/ci/ciMethodHandle.cpp
index b4c9161..831c6a5 100644
--- a/hotspot/src/share/vm/ci/ciMethodHandle.cpp
+++ b/hotspot/src/share/vm/ci/ciMethodHandle.cpp
@@ -86,12 +86,12 @@
 }
 
 
-#ifndef PRODUCT
+#ifdef ASSERT
 // ------------------------------------------------------------------
 // ciMethodHandle::print_chain_impl
 //
 // Implementation of the print method.
-void ciMethodHandle::print_chain_impl(outputStream* st) {
+void ciMethodHandle::print_chain_impl() {
   ASSERT_IN_VM;
   MethodHandleChain::print(get_oop());
 }
@@ -101,7 +101,7 @@
 // ciMethodHandle::print_chain
 //
 // Implementation of the print_chain method.
-void ciMethodHandle::print_chain(outputStream* st) {
-  GUARDED_VM_ENTRY(print_chain_impl(st););
+void ciMethodHandle::print_chain() {
+  GUARDED_VM_ENTRY(print_chain_impl(););
 }
 #endif
diff --git a/hotspot/src/share/vm/ci/ciMethodHandle.hpp b/hotspot/src/share/vm/ci/ciMethodHandle.hpp
index e19d053..536ebef 100644
--- a/hotspot/src/share/vm/ci/ciMethodHandle.hpp
+++ b/hotspot/src/share/vm/ci/ciMethodHandle.hpp
@@ -45,7 +45,7 @@
   ciMethod* get_adapter(     bool is_invokedynamic);
 
 protected:
-  void print_chain_impl(outputStream* st) PRODUCT_RETURN;
+  void print_chain_impl() NOT_DEBUG_RETURN;
 
 public:
   ciMethodHandle(instanceHandle h_i) :
@@ -79,7 +79,7 @@
     return _invokedynamic_adapter;
   }
 
-  void print_chain(outputStream* st = tty) PRODUCT_RETURN;
+  void print_chain() NOT_DEBUG_RETURN;
 };
 
 #endif // SHARE_VM_CI_CIMETHODHANDLE_HPP
diff --git a/hotspot/src/share/vm/ci/ciObjectFactory.cpp b/hotspot/src/share/vm/ci/ciObjectFactory.cpp
index b0e9064..9aa6b26 100644
--- a/hotspot/src/share/vm/ci/ciObjectFactory.cpp
+++ b/hotspot/src/share/vm/ci/ciObjectFactory.cpp
@@ -374,20 +374,32 @@
 // unloaded method.  This may need to change.
 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
                                                ciSymbol*        name,
-                                               ciSymbol*        signature) {
-  for (int i=0; i<_unloaded_methods->length(); i++) {
+                                               ciSymbol*        signature,
+                                               ciInstanceKlass* accessor) {
+  ciSignature* that = NULL;
+  for (int i = 0; i < _unloaded_methods->length(); i++) {
     ciMethod* entry = _unloaded_methods->at(i);
     if (entry->holder()->equals(holder) &&
         entry->name()->equals(name) &&
         entry->signature()->as_symbol()->equals(signature)) {
-      // We've found a match.
-      return entry;
+      // Short-circuit slow resolve.
+      if (entry->signature()->accessing_klass() == accessor) {
+        // We've found a match.
+        return entry;
+      } else {
+        // Lazily create ciSignature
+        if (that == NULL)  that = new (arena()) ciSignature(accessor, constantPoolHandle(), signature);
+        if (entry->signature()->equals(that)) {
+          // We've found a match.
+          return entry;
+        }
+      }
     }
   }
 
   // This is a new unloaded method.  Create it and stick it in
   // the cache.
-  ciMethod* new_method = new (arena()) ciMethod(holder, name, signature);
+  ciMethod* new_method = new (arena()) ciMethod(holder, name, signature, accessor);
 
   init_ident_of(new_method);
   _unloaded_methods->append(new_method);
diff --git a/hotspot/src/share/vm/ci/ciObjectFactory.hpp b/hotspot/src/share/vm/ci/ciObjectFactory.hpp
index 6222b9f..26cc2c3 100644
--- a/hotspot/src/share/vm/ci/ciObjectFactory.hpp
+++ b/hotspot/src/share/vm/ci/ciObjectFactory.hpp
@@ -108,7 +108,8 @@
   // Get the ciMethod representing an unloaded/unfound method.
   ciMethod* get_unloaded_method(ciInstanceKlass* holder,
                                 ciSymbol*        name,
-                                ciSymbol*        signature);
+                                ciSymbol*        signature,
+                                ciInstanceKlass* accessor);
 
   // Get a ciKlass representing an unloaded klass.
   ciKlass* get_unloaded_klass(ciKlass* accessing_klass,
diff --git a/hotspot/src/share/vm/ci/ciSignature.cpp b/hotspot/src/share/vm/ci/ciSignature.cpp
index 8754fb4..229a904 100644
--- a/hotspot/src/share/vm/ci/ciSignature.cpp
+++ b/hotspot/src/share/vm/ci/ciSignature.cpp
@@ -80,7 +80,7 @@
 }
 
 // ------------------------------------------------------------------
-// ciSignature::return_ciType
+// ciSignature::return_type
 //
 // What is the return type of this signature?
 ciType* ciSignature::return_type() const {
@@ -88,7 +88,7 @@
 }
 
 // ------------------------------------------------------------------
-// ciSignature::ciType_at
+// ciSignature::type_at
 //
 // What is the type of the index'th element of this
 // signature?
@@ -99,6 +99,24 @@
 }
 
 // ------------------------------------------------------------------
+// ciSignature::equals
+//
+// Compare this signature to another one.  Signatures with different
+// accessing classes but with signature-types resolved to the same
+// types are defined to be equal.
+bool ciSignature::equals(ciSignature* that) {
+  // Compare signature
+  if (!this->as_symbol()->equals(that->as_symbol()))  return false;
+  // Compare all types of the arguments
+  for (int i = 0; i < _count; i++) {
+    if (this->type_at(i) != that->type_at(i))         return false;
+  }
+  // Compare the return type
+  if (this->return_type() != that->return_type())     return false;
+  return true;
+}
+
+// ------------------------------------------------------------------
 // ciSignature::print_signature
 void ciSignature::print_signature() {
   _symbol->print_symbol();
diff --git a/hotspot/src/share/vm/ci/ciSignature.hpp b/hotspot/src/share/vm/ci/ciSignature.hpp
index aaeac41..25ba097 100644
--- a/hotspot/src/share/vm/ci/ciSignature.hpp
+++ b/hotspot/src/share/vm/ci/ciSignature.hpp
@@ -43,6 +43,7 @@
   int _count;
 
   friend class ciMethod;
+  friend class ciObjectFactory;
 
   ciSignature(ciKlass* accessing_klass, constantPoolHandle cpool, ciSymbol* signature);
 
@@ -52,6 +53,7 @@
 
 public:
   ciSymbol* as_symbol() const                    { return _symbol; }
+  ciKlass*  accessing_klass() const              { return _accessing_klass; }
 
   ciType* return_type() const;
   ciType* type_at(int index) const;
@@ -59,6 +61,8 @@
   int       size() const                         { return _size; }
   int       count() const                        { return _count; }
 
+  bool equals(ciSignature* that);
+
   void print_signature();
   void print();
 };
diff --git a/hotspot/src/share/vm/classfile/classLoader.cpp b/hotspot/src/share/vm/classfile/classLoader.cpp
index 0a3b5ca..df42dc7 100644
--- a/hotspot/src/share/vm/classfile/classLoader.cpp
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp
@@ -68,6 +68,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 
 // Entry points in zip.dll for loading zip/jar file entries
diff --git a/hotspot/src/share/vm/classfile/javaClasses.cpp b/hotspot/src/share/vm/classfile/javaClasses.cpp
index 542ed3f..59db6c3 100644
--- a/hotspot/src/share/vm/classfile/javaClasses.cpp
+++ b/hotspot/src/share/vm/classfile/javaClasses.cpp
@@ -58,6 +58,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 #define INJECTED_FIELD_COMPUTE_OFFSET(klass, name, signature, may_be_java)    \
   klass::_##name##_offset = JavaClasses::compute_injected_offset(JavaClasses::klass##_##name##_enum);
@@ -500,12 +503,8 @@
   if (SystemDictionary::Class_klass_loaded() && (k->oop_is_instance() || k->oop_is_javaArray())) {
     // Allocate mirror (java.lang.Class instance)
     Handle mirror = instanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK_0);
-    // Setup indirections
-    mirror->obj_field_put(_klass_offset,  k());
-    k->set_java_mirror(mirror());
 
     instanceMirrorKlass* mk = instanceMirrorKlass::cast(mirror->klass());
-    java_lang_Class::set_oop_size(mirror(), mk->instance_size(k));
     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 
     // It might also have a component mirror.  This mirror must already exist.
@@ -568,9 +567,10 @@
     assert(aklass != NULL, "correct bootstrap");
     set_array_klass(java_class, aklass);
   }
+#ifdef ASSERT
   instanceMirrorKlass* mk = instanceMirrorKlass::cast(SystemDictionary::Class_klass());
-  java_lang_Class::set_oop_size(java_class, mk->instance_size(oop(NULL)));
-  java_lang_Class::set_static_oop_field_count(java_class, 0);
+  assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
+#endif
   return java_class;
 }
 
@@ -584,6 +584,12 @@
 }
 
 
+void java_lang_Class::set_klass(oop java_class, klassOop klass) {
+  assert(java_lang_Class::is_instance(java_class), "must be a Class object");
+  java_class->obj_field_put(_klass_offset, klass);
+}
+
+
 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
   Symbol* name = NULL;
@@ -1145,7 +1151,7 @@
     }
     nmethod* nm = method->code();
     if (WizardMode && nm != NULL) {
-      sprintf(buf + (int)strlen(buf), "(nmethod " PTR_FORMAT ")", (intptr_t)nm);
+      sprintf(buf + (int)strlen(buf), "(nmethod " INTPTR_FORMAT ")", (intptr_t)nm);
     }
   }
 
diff --git a/hotspot/src/share/vm/classfile/javaClasses.hpp b/hotspot/src/share/vm/classfile/javaClasses.hpp
index fca9897..2a32801 100644
--- a/hotspot/src/share/vm/classfile/javaClasses.hpp
+++ b/hotspot/src/share/vm/classfile/javaClasses.hpp
@@ -188,6 +188,7 @@
   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
   // Conversion
   static klassOop as_klassOop(oop java_class);
+  static void set_klass(oop java_class, klassOop klass);
   static BasicType as_BasicType(oop java_class, klassOop* reference_klass = NULL);
   static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
     klassOop refk_oop = NULL;
diff --git a/hotspot/src/share/vm/code/dependencies.cpp b/hotspot/src/share/vm/code/dependencies.cpp
index 0a19acf..a3fd99e 100644
--- a/hotspot/src/share/vm/code/dependencies.cpp
+++ b/hotspot/src/share/vm/code/dependencies.cpp
@@ -763,9 +763,14 @@
       // Method m is inherited into ctxk.
       return true;
     if (lm != NULL) {
-      if (!(lm->is_public() || lm->is_protected()))
+      if (!(lm->is_public() || lm->is_protected())) {
         // Method is [package-]private, so the override story is complex.
         return true;  // Must punt the assertion to true.
+      }
+      if (lm->is_static()) {
+        // Static methods don't override non-static so punt
+        return true;
+      }
       if (   !Dependencies::is_concrete_method(lm)
           && !Dependencies::is_concrete_method(m)
           && Klass::cast(lm->method_holder())->is_subtype_of(m->method_holder()))
@@ -1091,9 +1096,11 @@
 }
 
 bool Dependencies::is_concrete_method(methodOop m) {
-  if (m->is_abstract())  return false;
-  // %%% We could treat unexecuted methods as virtually abstract also.
-  // This would require a deoptimization barrier on first execution.
+  // Statics are irrelevant to virtual call sites.
+  if (m->is_static())  return false;
+
+  // We could also return false if m does not yet appear to be
+  // executed, if the VM version supports this distinction also.
   return !m->is_abstract();
 }
 
@@ -1113,7 +1120,7 @@
 
 bool Dependencies::is_concrete_klass(ciInstanceKlass* k) {
   if (k->is_abstract())  return false;
-  // We could return also false if k does not yet appear to be
+  // We could also return false if k does not yet appear to be
   // instantiated, if the VM version supports this distinction also.
   //if (k->is_not_instantiated())  return false;
   return true;
@@ -1123,7 +1130,7 @@
   // Statics are irrelevant to virtual call sites.
   if (m->is_static())  return false;
 
-  // We could return also false if m does not yet appear to be
+  // We could also return false if m does not yet appear to be
   // executed, if the VM version supports this distinction also.
   return !m->is_abstract();
 }
diff --git a/hotspot/src/share/vm/code/nmethod.cpp b/hotspot/src/share/vm/code/nmethod.cpp
index f375bdc..31424e1 100644
--- a/hotspot/src/share/vm/code/nmethod.cpp
+++ b/hotspot/src/share/vm/code/nmethod.cpp
@@ -50,6 +50,7 @@
 
 // Only bother with this argument setup if dtrace is available
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL8(hotspot, compiled__method__load,
   const char*, int, const char*, int, const char*, int, void*, size_t);
 
@@ -69,6 +70,21 @@
         signature->bytes(), signature->utf8_length());                    \
     }                                                                     \
   }
+#else /* USDT2 */
+#define DTRACE_METHOD_UNLOAD_PROBE(method)                                \
+  {                                                                       \
+    methodOop m = (method);                                               \
+    if (m != NULL) {                                                      \
+      Symbol* klass_name = m->klass_name();                               \
+      Symbol* name = m->name();                                           \
+      Symbol* signature = m->signature();                                 \
+      HOTSPOT_COMPILED_METHOD_UNLOAD(                                     \
+        (char *) klass_name->bytes(), klass_name->utf8_length(),                   \
+        (char *) name->bytes(), name->utf8_length(),                               \
+        (char *) signature->bytes(), signature->utf8_length());                    \
+    }                                                                     \
+  }
+#endif /* USDT2 */
 
 #else //  ndef DTRACE_ENABLED
 
@@ -1473,6 +1489,7 @@
 void nmethod::post_compiled_method_load_event() {
 
   methodOop moop = method();
+#ifndef USDT2
   HS_DTRACE_PROBE8(hotspot, compiled__method__load,
       moop->klass_name()->bytes(),
       moop->klass_name()->utf8_length(),
@@ -1481,6 +1498,16 @@
       moop->signature()->bytes(),
       moop->signature()->utf8_length(),
       insts_begin(), insts_size());
+#else /* USDT2 */
+  HOTSPOT_COMPILED_METHOD_LOAD(
+      (char *) moop->klass_name()->bytes(),
+      moop->klass_name()->utf8_length(),
+      (char *) moop->name()->bytes(),
+      moop->name()->utf8_length(),
+      (char *) moop->signature()->bytes(),
+      moop->signature()->utf8_length(),
+      insts_begin(), insts_size());
+#endif /* USDT2 */
 
   if (JvmtiExport::should_post_compiled_method_load() ||
       JvmtiExport::should_post_compiled_method_unload()) {
diff --git a/hotspot/src/share/vm/code/stubs.hpp b/hotspot/src/share/vm/code/stubs.hpp
index ed5380f..328ad8b 100644
--- a/hotspot/src/share/vm/code/stubs.hpp
+++ b/hotspot/src/share/vm/code/stubs.hpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 // The classes in this file provide a simple framework for the
 // management of little pieces of machine code - or stubs -
diff --git a/hotspot/src/share/vm/compiler/compileBroker.cpp b/hotspot/src/share/vm/compiler/compileBroker.cpp
index 504d1a0..55ef1e4 100644
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp
@@ -58,6 +58,7 @@
 
 // Only bother with this argument setup if dtrace is available
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin,
   char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t);
 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end,
@@ -89,6 +90,35 @@
       signature->bytes(), signature->utf8_length(), (success));          \
   }
 
+#else /* USDT2 */
+
+#define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method)              \
+  {                                                                      \
+    char* comp_name = (char*)(compiler)->name();                         \
+    Symbol* klass_name = (method)->klass_name();                         \
+    Symbol* name = (method)->name();                                     \
+    Symbol* signature = (method)->signature();                           \
+    HOTSPOT_METHOD_COMPILE_BEGIN(                                       \
+      comp_name, strlen(comp_name),                                      \
+      (char *) klass_name->bytes(), klass_name->utf8_length(),          \
+      (char *) name->bytes(), name->utf8_length(),                       \
+      (char *) signature->bytes(), signature->utf8_length());            \
+  }
+
+#define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success)       \
+  {                                                                      \
+    char* comp_name = (char*)(compiler)->name();                         \
+    Symbol* klass_name = (method)->klass_name();                         \
+    Symbol* name = (method)->name();                                     \
+    Symbol* signature = (method)->signature();                           \
+    HOTSPOT_METHOD_COMPILE_END(                                          \
+      comp_name, strlen(comp_name),                                      \
+      (char *) klass_name->bytes(), klass_name->utf8_length(),           \
+      (char *) name->bytes(), name->utf8_length(),                       \
+      (char *) signature->bytes(), signature->utf8_length(), (success)); \
+  }
+#endif /* USDT2 */
+
 #else //  ndef DTRACE_ENABLED
 
 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method)
@@ -1692,11 +1722,11 @@
       if (PrintCompilation) {
         const char* reason = ci_env.failure_reason();
         if (compilable == ciEnv::MethodCompilable_not_at_tier) {
-            tty->print_cr("%3d   COMPILE SKIPPED: %s (retry at different tier)", compile_id, reason);
+          tty->print_cr("%4d   COMPILE SKIPPED: %s (retry at different tier)", compile_id, reason);
         } else if (compilable == ciEnv::MethodCompilable_never) {
-          tty->print_cr("%3d   COMPILE SKIPPED: %s (not retryable)", compile_id, reason);
+          tty->print_cr("%4d   COMPILE SKIPPED: %s (not retryable)", compile_id, reason);
         } else if (compilable == ciEnv::MethodCompilable) {
-          tty->print_cr("%3d   COMPILE SKIPPED: %s", compile_id, reason);
+          tty->print_cr("%4d   COMPILE SKIPPED: %s", compile_id, reason);
         }
       }
     } else {
@@ -1713,6 +1743,14 @@
 
   collect_statistics(thread, time, task);
 
+  if (PrintCompilation && PrintCompilation2) {
+    tty->print("%7d ", (int) tty->time_stamp().milliseconds());  // print timestamp
+    tty->print("%4d ", compile_id);    // print compilation number
+    tty->print("%s ", (is_osr ? "%" : " "));
+    int code_size = (task->code() == NULL) ? 0 : task->code()->total_size();
+    tty->print_cr("size: %d time: %d inlined: %d bytes", code_size, time.milliseconds(), task->num_inlined_bytecodes());
+  }
+
   if (compilable == ciEnv::MethodCompilable_never) {
     if (is_osr) {
       method->set_not_osr_compilable();
diff --git a/hotspot/src/share/vm/compiler/disassembler.hpp b/hotspot/src/share/vm/compiler/disassembler.hpp
index 3761540..a70b8cc 100644
--- a/hotspot/src/share/vm/compiler/disassembler.hpp
+++ b/hotspot/src/share/vm/compiler/disassembler.hpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 class decode_env;
 
diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.cpp
index 5bee77e..5edd8cc 100644
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.cpp
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 elapsedTimer CMSAdaptiveSizePolicy::_concurrent_timer;
 elapsedTimer CMSAdaptiveSizePolicy::_STW_timer;
 
diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
index cbe5953..0566f38 100644
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
@@ -50,6 +50,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 //
 // ConcurrentMarkSweepPolicy methods
diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
index c989486..eeabe97 100644
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
@@ -50,8 +50,8 @@
 int CompactibleFreeListSpace::_lockRank = Mutex::leaf + 3;
 
 // Defaults are 0 so things will break badly if incorrectly initialized.
-int CompactibleFreeListSpace::IndexSetStart  = 0;
-int CompactibleFreeListSpace::IndexSetStride = 0;
+size_t CompactibleFreeListSpace::IndexSetStart  = 0;
+size_t CompactibleFreeListSpace::IndexSetStride = 0;
 
 size_t MinChunkSize = 0;
 
@@ -62,7 +62,7 @@
   MinChunkSize = numQuanta(sizeof(FreeChunk), MinObjAlignmentInBytes) * MinObjAlignment;
 
   assert(IndexSetStart == 0 && IndexSetStride == 0, "already set");
-  IndexSetStart  = MinObjAlignment;
+  IndexSetStart  = MinChunkSize;
   IndexSetStride = MinObjAlignment;
 }
 
@@ -138,7 +138,7 @@
   } else {
     _fitStrategy = FreeBlockStrategyNone;
   }
-  checkFreeListConsistency();
+  check_free_list_consistency();
 
   // Initialize locks for parallel case.
 
@@ -250,7 +250,7 @@
 }
 
 void CompactibleFreeListSpace::resetIndexedFreeListArray() {
-  for (int i = 1; i < IndexSetSize; i++) {
+  for (size_t i = 1; i < IndexSetSize; i++) {
     assert(_indexedFreeList[i].size() == (size_t) i,
       "Indexed free list sizes are incorrect");
     _indexedFreeList[i].reset(IndexSetSize);
@@ -337,7 +337,7 @@
 
 size_t CompactibleFreeListSpace::totalCountInIndexedFreeLists() const {
   size_t count = 0;
-  for (int i = (int)MinChunkSize; i < IndexSetSize; i++) {
+  for (size_t i = IndexSetStart; i < IndexSetSize; i++) {
     debug_only(
       ssize_t total_list_count = 0;
       for (FreeChunk* fc = _indexedFreeList[i].head(); fc != NULL;
@@ -1358,17 +1358,29 @@
   ShouldNotReachHere();
 }
 
-bool CompactibleFreeListSpace::verifyChunkInIndexedFreeLists(FreeChunk* fc)
-  const {
+bool CompactibleFreeListSpace::verifyChunkInIndexedFreeLists(FreeChunk* fc) const {
   assert(fc->size() < IndexSetSize, "Size of chunk is too large");
   return _indexedFreeList[fc->size()].verifyChunkInFreeLists(fc);
 }
 
+bool CompactibleFreeListSpace::verify_chunk_is_linear_alloc_block(FreeChunk* fc) const {
+  assert((_smallLinearAllocBlock._ptr != (HeapWord*)fc) ||
+         (_smallLinearAllocBlock._word_size == fc->size()),
+         "Linear allocation block shows incorrect size");
+  return ((_smallLinearAllocBlock._ptr == (HeapWord*)fc) &&
+          (_smallLinearAllocBlock._word_size == fc->size()));
+}
+
+// Check if the purported free chunk is present either as a linear
+// allocation block, the size-indexed table of (smaller) free blocks,
+// or the larger free blocks kept in the binary tree dictionary.
 bool CompactibleFreeListSpace::verifyChunkInFreeLists(FreeChunk* fc) const {
-  if (fc->size() >= IndexSetSize) {
-    return dictionary()->verifyChunkInFreeLists(fc);
-  } else {
+  if (verify_chunk_is_linear_alloc_block(fc)) {
+    return true;
+  } else if (fc->size() < IndexSetSize) {
     return verifyChunkInIndexedFreeLists(fc);
+  } else {
+    return dictionary()->verifyChunkInFreeLists(fc);
   }
 }
 
@@ -2188,7 +2200,7 @@
 
 void CompactibleFreeListSpace::clearFLCensus() {
   assert_locked();
-  int i;
+  size_t i;
   for (i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) {
     FreeList *fl = &_indexedFreeList[i];
     fl->set_prevSweep(fl->count());
@@ -2482,7 +2494,7 @@
 
 void CompactibleFreeListSpace::verifyIndexedFreeLists() const {
   size_t i = 0;
-  for (; i < MinChunkSize; i++) {
+  for (; i < IndexSetStart; i++) {
     guarantee(_indexedFreeList[i].head() == NULL, "should be NULL");
   }
   for (; i < IndexSetSize; i++) {
@@ -2495,7 +2507,8 @@
   FreeChunk* tail =  _indexedFreeList[size].tail();
   size_t    num = _indexedFreeList[size].count();
   size_t      n = 0;
-  guarantee((size % 2 == 0) || fc == NULL, "Odd slots should be empty");
+  guarantee(((size >= IndexSetStart) && (size % IndexSetStride == 0)) || fc == NULL,
+            "Slot should have been empty");
   for (; fc != NULL; fc = fc->next(), n++) {
     guarantee(fc->size() == size, "Size inconsistency");
     guarantee(fc->isFree(), "!free?");
@@ -2506,15 +2519,15 @@
 }
 
 #ifndef PRODUCT
-void CompactibleFreeListSpace::checkFreeListConsistency() const {
+void CompactibleFreeListSpace::check_free_list_consistency() const {
   assert(_dictionary->minSize() <= IndexSetSize,
     "Some sizes can't be allocated without recourse to"
     " linear allocation buffers");
   assert(MIN_TREE_CHUNK_SIZE*HeapWordSize == sizeof(TreeChunk),
     "else MIN_TREE_CHUNK_SIZE is wrong");
-  assert((IndexSetStride == 2 && IndexSetStart == 2) ||
-         (IndexSetStride == 1 && IndexSetStart == 1), "just checking");
-  assert((IndexSetStride != 2) || (MinChunkSize % 2 == 0),
+  assert((IndexSetStride == 2 && IndexSetStart == 4) ||                   // 32-bit
+         (IndexSetStride == 1 && IndexSetStart == 3), "just checking");   // 64-bit
+  assert((IndexSetStride != 2) || (IndexSetStart % 2 == 0),
       "Some for-loops may be incorrectly initialized");
   assert((IndexSetStride != 2) || (IndexSetSize % 2 == 1),
       "For-loops that iterate over IndexSet with stride 2 may be wrong");
@@ -2688,33 +2701,27 @@
   }
 }
 
+// If this is changed in the future to allow parallel
+// access, one would need to take the FL locks and,
+// depending on how it is used, stagger access from
+// parallel threads to reduce contention.
 void CFLS_LAB::retire(int tid) {
   // We run this single threaded with the world stopped;
   // so no need for locks and such.
-#define CFLS_LAB_PARALLEL_ACCESS 0
   NOT_PRODUCT(Thread* t = Thread::current();)
   assert(Thread::current()->is_VM_thread(), "Error");
-  assert(CompactibleFreeListSpace::IndexSetStart == CompactibleFreeListSpace::IndexSetStride,
-         "Will access to uninitialized slot below");
-#if CFLS_LAB_PARALLEL_ACCESS
-  for (size_t i = CompactibleFreeListSpace::IndexSetSize - 1;
-       i > 0;
-       i -= CompactibleFreeListSpace::IndexSetStride) {
-#else // CFLS_LAB_PARALLEL_ACCESS
   for (size_t i =  CompactibleFreeListSpace::IndexSetStart;
        i < CompactibleFreeListSpace::IndexSetSize;
        i += CompactibleFreeListSpace::IndexSetStride) {
-#endif // !CFLS_LAB_PARALLEL_ACCESS
     assert(_num_blocks[i] >= (size_t)_indexedFreeList[i].count(),
            "Can't retire more than what we obtained");
     if (_num_blocks[i] > 0) {
       size_t num_retire =  _indexedFreeList[i].count();
       assert(_num_blocks[i] > num_retire, "Should have used at least one");
       {
-#if CFLS_LAB_PARALLEL_ACCESS
-        MutexLockerEx x(_cfls->_indexedFreeListParLocks[i],
-                        Mutex::_no_safepoint_check_flag);
-#endif // CFLS_LAB_PARALLEL_ACCESS
+        // MutexLockerEx x(_cfls->_indexedFreeListParLocks[i],
+        //                Mutex::_no_safepoint_check_flag);
+
         // Update globals stats for num_blocks used
         _global_num_blocks[i] += (_num_blocks[i] - num_retire);
         _global_num_workers[i]++;
diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
index 3f36432..81e220b 100644
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
@@ -104,8 +104,8 @@
     SmallForDictionary  = 257,       // size < this then use _indexedFreeList
     IndexSetSize        = SmallForDictionary  // keep this odd-sized
   };
-  static int IndexSetStart;
-  static int IndexSetStride;
+  static size_t IndexSetStart;
+  static size_t IndexSetStride;
 
  private:
   enum FitStrategyOptions {
@@ -502,10 +502,14 @@
   void verifyFreeLists()                  const PRODUCT_RETURN;
   void verifyIndexedFreeLists()           const;
   void verifyIndexedFreeList(size_t size) const;
-  // verify that the given chunk is in the free lists.
+  // Verify that the given chunk is in the free lists:
+  // i.e. either the binary tree dictionary, the indexed free lists
+  // or the linear allocation block.
   bool verifyChunkInFreeLists(FreeChunk* fc) const;
+  // Verify that the given chunk is the linear allocation block
+  bool verify_chunk_is_linear_alloc_block(FreeChunk* fc) const;
   // Do some basic checks on the the free lists.
-  void checkFreeListConsistency()         const PRODUCT_RETURN;
+  void check_free_list_consistency()      const PRODUCT_RETURN;
 
   // Printing support
   void dump_at_safepoint_with_locks(CMSCollector* c, outputStream* st);
diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp
index a299c32..63e5cb4 100644
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp
@@ -36,6 +36,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 class ConcurrentMarkSweepGeneration;
 class CMSCollector;
diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.cpp
index 1c1b3ff..1870c1f 100644
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.cpp
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.cpp
@@ -33,6 +33,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 #ifndef PRODUCT
 Mutex* FreeBlockDictionary::par_lock() const {
diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp
index 0ceec0b..c3b9d54 100644
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp
@@ -30,11 +30,15 @@
 #include "memory/gcLocker.inline.hpp"
 #include "runtime/interfaceSupport.hpp"
 #include "utilities/dtrace.hpp"
+
+
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL(hs_private, cms__initmark__begin);
 HS_DTRACE_PROBE_DECL(hs_private, cms__initmark__end);
 
 HS_DTRACE_PROBE_DECL(hs_private, cms__remark__begin);
 HS_DTRACE_PROBE_DECL(hs_private, cms__remark__end);
+#endif /* !USDT2 */
 
 //////////////////////////////////////////////////////////
 // Methods in abstract class VM_CMS_Operation
@@ -129,7 +133,12 @@
     // Nothing to do.
     return;
   }
+#ifndef USDT2
   HS_DTRACE_PROBE(hs_private, cms__initmark__begin);
+#else /* USDT2 */
+  HS_PRIVATE_CMS_INITMARK_BEGIN(
+                                );
+#endif /* USDT2 */
 
   GenCollectedHeap* gch = GenCollectedHeap::heap();
   GCCauseSetter gccs(gch, GCCause::_cms_initial_mark);
@@ -140,7 +149,12 @@
   _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsInitial);
 
   VM_CMS_Operation::verify_after_gc();
+#ifndef USDT2
   HS_DTRACE_PROBE(hs_private, cms__initmark__end);
+#else /* USDT2 */
+  HS_PRIVATE_CMS_INITMARK_END(
+                                );
+#endif /* USDT2 */
 }
 
 //////////////////////////////////////////////////////////
@@ -151,7 +165,12 @@
     // Nothing to do.
     return;
   }
+#ifndef USDT2
   HS_DTRACE_PROBE(hs_private, cms__remark__begin);
+#else /* USDT2 */
+  HS_PRIVATE_CMS_REMARK_BEGIN(
+                                );
+#endif /* USDT2 */
 
   GenCollectedHeap* gch = GenCollectedHeap::heap();
   GCCauseSetter gccs(gch, GCCause::_cms_final_remark);
@@ -162,7 +181,12 @@
   _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsFinal);
 
   VM_CMS_Operation::verify_after_gc();
+#ifndef USDT2
   HS_DTRACE_PROBE(hs_private, cms__remark__end);
+#else /* USDT2 */
+  HS_PRIVATE_CMS_REMARK_END(
+                                );
+#endif /* USDT2 */
 }
 
 // VM operation to invoke a concurrent collection of a
diff --git a/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.cpp b/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.cpp
index 73d578d..0b78565 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.cpp
@@ -118,30 +118,6 @@
   }
 }
 
-// this is a bit expensive... but we expect that it should not be called
-// to often.
-void CSetChooserCache::remove(HeapRegion *hr) {
-  assert(_occupancy > 0, "cache should not be empty");
-  assert(hr->sort_index() < -1, "should already be in the cache");
-  int index = get_index(hr->sort_index());
-  assert(_cache[index] == hr, "index should be correct");
-  int next_index = trim_index(index + 1);
-  int last_index = trim_index(_first + _occupancy - 1);
-  while (index != last_index) {
-    assert(_cache[next_index] != NULL, "should not be null");
-    _cache[index] = _cache[next_index];
-    _cache[index]->set_sort_index(get_sort_index(index));
-
-    index = next_index;
-    next_index = trim_index(next_index+1);
-  }
-  assert(index == last_index, "should have reached the last one");
-  _cache[index] = NULL;
-  hr->set_sort_index(-1);
-  --_occupancy;
-  assert(verify(), "cache should be consistent");
-}
-
 static inline int orderRegions(HeapRegion* hr1, HeapRegion* hr2) {
   if (hr1 == NULL) {
     if (hr2 == NULL) return 0;
@@ -197,43 +173,34 @@
   HeapRegion *prev = NULL;
   while (index < _numMarkedRegions) {
     HeapRegion *curr = _markedRegions.at(index++);
-    if (curr != NULL) {
-      int si = curr->sort_index();
-      guarantee(!curr->is_young(), "should not be young!");
-      guarantee(si > -1 && si == (index-1), "sort index invariant");
-      if (prev != NULL) {
-        guarantee(orderRegions(prev, curr) != 1, "regions should be sorted");
-      }
-      prev = curr;
+    guarantee(curr != NULL, "Regions in _markedRegions array cannot be NULL");
+    int si = curr->sort_index();
+    guarantee(!curr->is_young(), "should not be young!");
+    guarantee(si > -1 && si == (index-1), "sort index invariant");
+    if (prev != NULL) {
+      guarantee(orderRegions(prev, curr) != 1, "regions should be sorted");
     }
+    prev = curr;
   }
   return _cache.verify();
 }
 #endif
 
-bool
-CollectionSetChooser::addRegionToCache() {
-  assert(!_cache.is_full(), "cache should not be full");
-
-  HeapRegion *hr = NULL;
-  while (hr == NULL && _curMarkedIndex < _numMarkedRegions) {
-    hr = _markedRegions.at(_curMarkedIndex++);
-  }
-  if (hr == NULL)
-    return false;
-  assert(!hr->is_young(), "should not be young!");
-  assert(hr->sort_index() == _curMarkedIndex-1, "sort_index invariant");
-  _markedRegions.at_put(hr->sort_index(), NULL);
-  _cache.insert(hr);
-  assert(!_cache.is_empty(), "cache should not be empty");
-  assert(verify(), "cache should be consistent");
-  return false;
-}
-
 void
 CollectionSetChooser::fillCache() {
-  while (!_cache.is_full() && addRegionToCache()) {
+  while (!_cache.is_full() && (_curMarkedIndex < _numMarkedRegions)) {
+    HeapRegion* hr = _markedRegions.at(_curMarkedIndex);
+    assert(hr != NULL,
+           err_msg("Unexpected NULL hr in _markedRegions at index %d",
+                   _curMarkedIndex));
+    _curMarkedIndex += 1;
+    assert(!hr->is_young(), "should not be young!");
+    assert(hr->sort_index() == _curMarkedIndex-1, "sort_index invariant");
+    _markedRegions.at_put(hr->sort_index(), NULL);
+    _cache.insert(hr);
+    assert(!_cache.is_empty(), "cache should not be empty");
   }
+  assert(verify(), "cache should be consistent");
 }
 
 void
@@ -334,20 +301,6 @@
   clearMarkedHeapRegions();
 }
 
-void CollectionSetChooser::removeRegion(HeapRegion *hr) {
-  int si = hr->sort_index();
-  assert(si == -1 || hr->is_marked(), "Sort index not valid.");
-  if (si > -1) {
-    assert(_markedRegions.at(si) == hr, "Sort index not valid." );
-    _markedRegions.at_put(si, NULL);
-  } else if (si < -1) {
-    assert(_cache.region_in_cache(hr), "should be in the cache");
-    _cache.remove(hr);
-    assert(hr->sort_index() == -1, "sort index invariant");
-  }
-  hr->set_sort_index(-1);
-}
-
 // if time_remaining < 0.0, then this method should try to return
 // a region, whether it fits within the remaining time or not
 HeapRegion*
diff --git a/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp b/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
index c8e2233..ff4bca9 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,26 @@
 #include "utilities/growableArray.hpp"
 
 // We need to sort heap regions by collection desirability.
+// This sorting is currently done in two "stages". An initial sort is
+// done following a cleanup pause as soon as all of the marked but
+// non-empty regions have been identified and the completely empty
+// ones reclaimed.
+// This gives us a global sort on a GC efficiency metric
+// based on predictive data available at that time. However,
+// any of these regions that are collected will only be collected
+// during a future GC pause, by which time it is possible that newer
+// data might allow us to revise and/or refine the earlier
+// pause predictions, leading to changes in expected gc efficiency
+// order. To somewhat mitigate this obsolescence, more so in the
+// case of regions towards the end of the list, which will be
+// picked later, these pre-sorted regions from the _markedRegions
+// array are not used as is, but a small prefix thereof is
+// insertion-sorted again into a small cache, based on more
+// recent remembered set information. Regions are then drawn
+// from this cache to construct the collection set at each
+// incremental GC.
+// This scheme and/or its implementation may be subject to
+// revision in the future.
 
 class CSetChooserCache VALUE_OBJ_CLASS_SPEC {
 private:
@@ -37,8 +57,8 @@
   } PrivateConstants;
 
   HeapRegion*  _cache[CacheLength];
-  int          _occupancy; // number of region in cache
-  int          _first; // "first" region in the cache
+  int          _occupancy; // number of regions in cache
+  int          _first;     // (index of) "first" region in the cache
 
   // adding CacheLength to deal with negative values
   inline int trim_index(int index) {
@@ -62,7 +82,6 @@
   void clear(void);
   void insert(HeapRegion *hr);
   HeapRegion *remove_first(void);
-  void remove (HeapRegion *hr);
   inline HeapRegion *get_first(void) {
     return _cache[_first];
   }
@@ -102,7 +121,6 @@
 
   void sortMarkedHeapRegions();
   void fillCache();
-  bool addRegionToCache(void);
   void addMarkedHeapRegion(HeapRegion *hr);
 
   // Must be called before calls to getParMarkedHeapRegionChunk.
@@ -122,9 +140,6 @@
 
   void updateAfterFullCollection();
 
-  // Ensure that "hr" is not a member of the marked region array or the cache
-  void removeRegion(HeapRegion* hr);
-
   bool unmarked_age_1_returned_as_new() { return _unmarked_age_1_returned_as_new; }
 
   // Returns true if the used portion of "_markedRegions" is properly
diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp
index d78db6e..f414613 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp
@@ -1518,6 +1518,7 @@
   size_t _regions_claimed;
   size_t _freed_bytes;
   FreeRegionList* _local_cleanup_list;
+  OldRegionSet* _old_proxy_set;
   HumongousRegionSet* _humongous_proxy_set;
   HRRSCleanupTask* _hrrs_cleanup_task;
   double _claimed_region_time;
@@ -1527,6 +1528,7 @@
   G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1,
                              int worker_num,
                              FreeRegionList* local_cleanup_list,
+                             OldRegionSet* old_proxy_set,
                              HumongousRegionSet* humongous_proxy_set,
                              HRRSCleanupTask* hrrs_cleanup_task);
   size_t freed_bytes() { return _freed_bytes; }
@@ -1557,9 +1559,11 @@
   void work(int i) {
     double start = os::elapsedTime();
     FreeRegionList local_cleanup_list("Local Cleanup List");
+    OldRegionSet old_proxy_set("Local Cleanup Old Proxy Set");
     HumongousRegionSet humongous_proxy_set("Local Cleanup Humongous Proxy Set");
     HRRSCleanupTask hrrs_cleanup_task;
     G1NoteEndOfConcMarkClosure g1_note_end(_g1h, i, &local_cleanup_list,
+                                           &old_proxy_set,
                                            &humongous_proxy_set,
                                            &hrrs_cleanup_task);
     if (G1CollectedHeap::use_parallel_gc_threads()) {
@@ -1573,6 +1577,7 @@
     // Now update the lists
     _g1h->update_sets_after_freeing_regions(g1_note_end.freed_bytes(),
                                             NULL /* free_list */,
+                                            &old_proxy_set,
                                             &humongous_proxy_set,
                                             true /* par */);
     {
@@ -1643,6 +1648,7 @@
 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1,
                            int worker_num,
                            FreeRegionList* local_cleanup_list,
+                           OldRegionSet* old_proxy_set,
                            HumongousRegionSet* humongous_proxy_set,
                            HRRSCleanupTask* hrrs_cleanup_task)
   : _g1(g1), _worker_num(worker_num),
@@ -1650,6 +1656,7 @@
     _freed_bytes(0),
     _claimed_region_time(0.0), _max_region_time(0.0),
     _local_cleanup_list(local_cleanup_list),
+    _old_proxy_set(old_proxy_set),
     _humongous_proxy_set(humongous_proxy_set),
     _hrrs_cleanup_task(hrrs_cleanup_task) { }
 
@@ -1665,6 +1672,7 @@
     _g1->free_region_if_empty(hr,
                               &_freed_bytes,
                               _local_cleanup_list,
+                              _old_proxy_set,
                               _humongous_proxy_set,
                               _hrrs_cleanup_task,
                               true /* par */);
@@ -1689,6 +1697,7 @@
     return;
   }
 
+  HRSPhaseSetter x(HRSPhaseCleanup);
   g1h->verify_region_sets_optional();
 
   if (VerifyDuringGC) {
@@ -1816,9 +1825,7 @@
 
   // this will also free any regions totally full of garbage objects,
   // and sort the regions.
-  g1h->g1_policy()->record_concurrent_mark_cleanup_end(
-                        g1_par_note_end_task.freed_bytes(),
-                        g1_par_note_end_task.max_live_bytes());
+  g1h->g1_policy()->record_concurrent_mark_cleanup_end();
 
   // Statistics.
   double end = os::elapsedTime();
@@ -4573,7 +4580,7 @@
                  G1PPRL_SUM_BYTE_FORMAT("region-size"),
                  g1_committed.start(), g1_committed.end(),
                  g1_reserved.start(), g1_reserved.end(),
-                 (size_t)HeapRegion::GrainBytes);
+                 HeapRegion::GrainBytes);
   _out->print_cr(G1PPRL_LINE_PREFIX);
   _out->print_cr(G1PPRL_LINE_PREFIX
                  G1PPRL_TYPE_H_FORMAT
@@ -4604,7 +4611,7 @@
   // The > 0 check is to deal with the prev and next live bytes which
   // could be 0.
   if (*hum_bytes > 0) {
-    bytes = MIN2((size_t) HeapRegion::GrainBytes, *hum_bytes);
+    bytes = MIN2(HeapRegion::GrainBytes, *hum_bytes);
     *hum_bytes -= bytes;
   }
   return bytes;
diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMarkThread.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMarkThread.cpp
index 85fb9a4..0a4c81a 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMarkThread.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMarkThread.cpp
@@ -147,12 +147,8 @@
           }
         }
       } while (cm()->restart_for_overflow());
+
       double counting_start_time = os::elapsedVTime();
-
-      // YSR: These look dubious (i.e. redundant) !!! FIX ME
-      slt()->manipulatePLL(SurrogateLockerThread::acquirePLL);
-      slt()->manipulatePLL(SurrogateLockerThread::releaseAndNotifyPLL);
-
       if (!cm()->has_aborted()) {
         double count_start_sec = os::elapsedTime();
         if (PrintGC) {
@@ -175,6 +171,7 @@
           }
         }
       }
+
       double end_time = os::elapsedVTime();
       _vtime_count_accum += (end_time - counting_start_time);
       // Update the total virtual time before doing this, since it will try
@@ -215,19 +212,19 @@
           gclog_or_tty->print_cr("[GC concurrent-cleanup-start]");
         }
 
-        // Now do the remainder of the cleanup operation.
+        // Now do the concurrent cleanup operation.
         _cm->completeCleanup();
-        // Notify anyone who's waiting that there are no more free
-        // regions coming. We have to do this before we join the STS,
-        // otherwise we might deadlock: a GC worker could be blocked
-        // waiting for the notification whereas this thread will be
-        // blocked for the pause to finish while it's trying to join
-        // the STS, which is conditional on the GC workers finishing.
-        g1h->reset_free_regions_coming();
 
-        _sts.join();
-        g1_policy->record_concurrent_mark_cleanup_completed();
-        _sts.leave();
+        // Notify anyone who's waiting that there are no more free
+        // regions coming. We have to do this before we join the STS
+        // (in fact, we should not attempt to join the STS in the
+        // interval between finishing the cleanup pause and clearing
+        // the free_regions_coming flag) otherwise we might deadlock:
+        // a GC worker could be blocked waiting for the notification
+        // whereas this thread will be blocked for the pause to finish
+        // while it's trying to join the STS, which is conditional on
+        // the GC workers finishing.
+        g1h->reset_free_regions_coming();
 
         double cleanup_end_sec = os::elapsedTime();
         if (PrintGC) {
@@ -240,6 +237,36 @@
       guarantee(cm()->cleanup_list_is_empty(),
                 "at this point there should be no regions on the cleanup list");
 
+      // There is a tricky race before recording that the concurrent
+      // cleanup has completed and a potential Full GC starting around
+      // the same time. We want to make sure that the Full GC calls
+      // abort() on concurrent mark after
+      // record_concurrent_mark_cleanup_completed(), since abort() is
+      // the method that will reset the concurrent mark state. If we
+      // end up calling record_concurrent_mark_cleanup_completed()
+      // after abort() then we might incorrectly undo some of the work
+      // abort() did. Checking the has_aborted() flag after joining
+      // the STS allows the correct ordering of the two methods. There
+      // are two scenarios:
+      //
+      // a) If we reach here before the Full GC, the fact that we have
+      // joined the STS means that the Full GC cannot start until we
+      // leave the STS, so record_concurrent_mark_cleanup_completed()
+      // will complete before abort() is called.
+      //
+      // b) If we reach here during the Full GC, we'll be held up from
+      // joining the STS until the Full GC is done, which means that
+      // abort() will have completed and has_aborted() will return
+      // true to prevent us from calling
+      // record_concurrent_mark_cleanup_completed() (and, in fact, it's
+      // not needed any more as the concurrent mark state has been
+      // already reset).
+      _sts.join();
+      if (!cm()->has_aborted()) {
+        g1_policy->record_concurrent_mark_cleanup_completed();
+      }
+      _sts.leave();
+
       if (cm()->has_aborted()) {
         if (PrintGC) {
           gclog_or_tty->date_stamp(PrintGCDateStamps);
@@ -248,7 +275,7 @@
         }
       }
 
-      // we now want to allow clearing of the marking bitmap to be
+      // We now want to allow clearing of the marking bitmap to be
       // suspended by a collection pause.
       _sts.join();
       _cm->clearNextBitmap();
@@ -305,13 +332,15 @@
   clear_started();
 }
 
-// Note: this method, although exported by the ConcurrentMarkSweepThread,
-// which is a non-JavaThread, can only be called by a JavaThread.
-// Currently this is done at vm creation time (post-vm-init) by the
-// main/Primordial (Java)Thread.
-// XXX Consider changing this in the future to allow the CMS thread
+// Note: As is the case with CMS - this method, although exported
+// by the ConcurrentMarkThread, which is a non-JavaThread, can only
+// be called by a JavaThread. Currently this is done at vm creation
+// time (post-vm-init) by the main/Primordial (Java)Thread.
+// XXX Consider changing this in the future to allow the CM thread
 // itself to create this thread?
 void ConcurrentMarkThread::makeSurrogateLockerThread(TRAPS) {
+  assert(UseG1GC, "SLT thread needed only for concurrent GC");
+  assert(THREAD->is_Java_thread(), "must be a Java thread");
   assert(_slt == NULL, "SLT already created");
   _slt = SurrogateLockerThread::make(THREAD);
 }
diff --git a/hotspot/src/share/vm/gc_implementation/g1/dirtyCardQueue.cpp b/hotspot/src/share/vm/gc_implementation/g1/dirtyCardQueue.cpp
index 2a7f513..915ee25 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/dirtyCardQueue.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/dirtyCardQueue.cpp
@@ -39,6 +39,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 bool DirtyCardQueue::apply_closure(CardTableEntryClosure* cl,
                                    bool consume,
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
index 1550dbc..50eb833 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
@@ -552,8 +552,7 @@
 }
 
 HeapRegion* G1CollectedHeap::new_region(size_t word_size, bool do_expand) {
-  assert(!isHumongous(word_size) ||
-                                  word_size <= (size_t) HeapRegion::GrainWords,
+  assert(!isHumongous(word_size) || word_size <= HeapRegion::GrainWords,
          "the only time we use this to allocate a humongous region is "
          "when we are allocating a single humongous region");
 
@@ -1170,7 +1169,7 @@
       if (!hr->isHumongous()) {
         _hr_printer->post_compaction(hr, G1HRPrinter::Old);
       } else if (hr->startsHumongous()) {
-        if (hr->capacity() == (size_t) HeapRegion::GrainBytes) {
+        if (hr->capacity() == HeapRegion::GrainBytes) {
           // single humongous region
           _hr_printer->post_compaction(hr, G1HRPrinter::SingleHumongous);
         } else {
@@ -1204,6 +1203,7 @@
     Universe::print_heap_before_gc();
   }
 
+  HRSPhaseSetter x(HRSPhaseFullGC);
   verify_region_sets_optional();
 
   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
@@ -1264,7 +1264,6 @@
     release_mutator_alloc_region();
     abandon_gc_alloc_regions();
     g1_rem_set()->cleanupHRRS();
-    tear_down_region_lists();
 
     // We should call this after we retire any currently active alloc
     // regions so that all the ALLOC / RETIRE events are generated
@@ -1279,7 +1278,7 @@
     g1_policy()->clear_incremental_cset();
     g1_policy()->stop_incremental_cset_building();
 
-    empty_young_list();
+    tear_down_region_sets(false /* free_list_only */);
     g1_policy()->set_full_young_gcs(true);
 
     // See the comments in g1CollectedHeap.hpp and
@@ -1302,9 +1301,7 @@
     }
 
     assert(free_regions() == 0, "we should not have added any free regions");
-    rebuild_region_lists();
-
-    _summary_bytes_used = recalculate_used();
+    rebuild_region_sets(false /* free_list_only */);
 
     // Enqueue any discovered reference objects that have
     // not been removed from the discovered lists.
@@ -1765,9 +1762,9 @@
   // Instead of tearing down / rebuilding the free lists here, we
   // could instead use the remove_all_pending() method on free_list to
   // remove only the ones that we need to remove.
-  tear_down_region_lists();  // We will rebuild them in a moment.
+  tear_down_region_sets(true /* free_list_only */);
   shrink_helper(shrink_bytes);
-  rebuild_region_lists();
+  rebuild_region_sets(true /* free_list_only */);
 
   _hrs.verify_optional();
   verify_region_sets_optional();
@@ -1800,6 +1797,7 @@
   _full_collection(false),
   _free_list("Master Free List"),
   _secondary_free_list("Secondary Free List"),
+  _old_set("Old Set"),
   _humongous_set("Master Humongous Set"),
   _free_regions_coming(false),
   _young_list(new YoungList(this)),
@@ -1971,7 +1969,7 @@
 
   size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
   guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
-  guarantee((size_t) HeapRegion::CardsPerRegion < max_cards_per_region,
+  guarantee(HeapRegion::CardsPerRegion < max_cards_per_region,
             "too many cards per region");
 
   HeapRegionSet::set_unrealistically_long_length(max_regions() + 1);
@@ -2012,8 +2010,6 @@
   // Perform any initialization actions delegated to the policy.
   g1_policy()->init();
 
-  g1_policy()->note_start_of_mark_thread();
-
   _refine_cte_cl =
     new RefineCardTableEntryClosure(ConcurrentG1RefineThread::sts(),
                                     g1_rem_set(),
@@ -3010,7 +3006,10 @@
 
     if (failures) {
       gclog_or_tty->print_cr("Heap:");
-      print_on(gclog_or_tty, true /* extended */);
+      // It helps to have the per-region information in the output to
+      // help us track down what went wrong. This is why we call
+      // print_extended_on() instead of print_on().
+      print_extended_on(gclog_or_tty);
       gclog_or_tty->print_cr("");
 #ifndef PRODUCT
       if (VerifyDuringGC && G1VerifyDuringGCPrintReachable) {
@@ -3036,13 +3035,7 @@
   }
 };
 
-void G1CollectedHeap::print() const { print_on(tty); }
-
 void G1CollectedHeap::print_on(outputStream* st) const {
-  print_on(st, PrintHeapAtGCExtended);
-}
-
-void G1CollectedHeap::print_on(outputStream* st, bool extended) const {
   st->print(" %-20s", "garbage-first heap");
   st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
             capacity()/K, used_unlocked()/K);
@@ -3051,8 +3044,7 @@
             _g1_storage.high(),
             _g1_storage.high_boundary());
   st->cr();
-  st->print("  region size " SIZE_FORMAT "K, ",
-            HeapRegion::GrainBytes/K);
+  st->print("  region size " SIZE_FORMAT "K, ", HeapRegion::GrainBytes / K);
   size_t young_regions = _young_list->length();
   st->print(SIZE_FORMAT " young (" SIZE_FORMAT "K), ",
             young_regions, young_regions * HeapRegion::GrainBytes / K);
@@ -3061,13 +3053,14 @@
             survivor_regions, survivor_regions * HeapRegion::GrainBytes / K);
   st->cr();
   perm()->as_gen()->print_on(st);
-  if (extended) {
-    st->cr();
-    print_on_extended(st);
-  }
 }
 
-void G1CollectedHeap::print_on_extended(outputStream* st) const {
+void G1CollectedHeap::print_extended_on(outputStream* st) const {
+  print_on(st);
+
+  // Print the per-region information.
+  st->cr();
+  st->print_cr("Heap Regions: (Y=young(eden), SU=young(survivor), HS=humongous(starts), HC=humongous(continues), CS=collection set, F=free, TS=gc time stamp, PTAMS=previous top-at-mark-start, NTAMS=next top-at-mark-start)");
   PrintRegionClosure blk(st);
   heap_region_iterate(&blk);
 }
@@ -3356,6 +3349,7 @@
     Universe::print_heap_before_gc();
   }
 
+  HRSPhaseSetter x(HRSPhaseEvacuation);
   verify_region_sets_optional();
   verify_dirty_young_regions();
 
@@ -3778,6 +3772,11 @@
       !retained_region->is_empty() &&
       !retained_region->isHumongous()) {
     retained_region->set_saved_mark();
+    // The retained region was added to the old region set when it was
+    // retired. We have to remove it now, since we don't allow regions
+    // we allocate to in the region sets. We'll re-add it later, when
+    // it's retired again.
+    _old_set.remove(retained_region);
     _old_gc_alloc_region.set(retained_region);
     _hr_printer.reuse(retained_region);
   }
@@ -3962,9 +3961,6 @@
         // _next_top_at_mark_start == top, _next_marked_bytes == 0
         // _next_marked_bytes == next_marked_bytes.
       }
-
-      // Now make sure the region has the right index in the sorted array.
-      g1_policy()->note_change_in_marked_bytes(cur);
     }
     cur = cur->next_in_collection_set();
   }
@@ -5075,7 +5071,7 @@
 
     // Select discovered lists [i, i+stride, i+2*stride,...,limit)
     for (int idx = i; idx < limit; idx += stride) {
-      DiscoveredList& ref_list = rp->discovered_soft_refs()[idx];
+      DiscoveredList& ref_list = rp->discovered_refs()[idx];
 
       DiscoveredListIterator iter(ref_list, &keep_alive, &always_alive);
       while (iter.has_next()) {
@@ -5345,6 +5341,7 @@
 void G1CollectedHeap::free_region_if_empty(HeapRegion* hr,
                                      size_t* pre_used,
                                      FreeRegionList* free_list,
+                                     OldRegionSet* old_proxy_set,
                                      HumongousRegionSet* humongous_proxy_set,
                                      HRRSCleanupTask* hrrs_cleanup_task,
                                      bool par) {
@@ -5353,6 +5350,7 @@
       assert(hr->startsHumongous(), "we should only see starts humongous");
       free_humongous_region(hr, pre_used, free_list, humongous_proxy_set, par);
     } else {
+      _old_set.remove_with_proxy(hr, old_proxy_set);
       free_region(hr, pre_used, free_list, par);
     }
   } else {
@@ -5409,6 +5407,7 @@
 
 void G1CollectedHeap::update_sets_after_freeing_regions(size_t pre_used,
                                        FreeRegionList* free_list,
+                                       OldRegionSet* old_proxy_set,
                                        HumongousRegionSet* humongous_proxy_set,
                                        bool par) {
   if (pre_used > 0) {
@@ -5424,6 +5423,10 @@
     MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
     _free_list.add_as_head(free_list);
   }
+  if (old_proxy_set != NULL && !old_proxy_set->is_empty()) {
+    MutexLockerEx x(OldSets_lock, Mutex::_no_safepoint_check_flag);
+    _old_set.update_from_proxy(old_proxy_set);
+  }
   if (humongous_proxy_set != NULL && !humongous_proxy_set->is_empty()) {
     MutexLockerEx x(OldSets_lock, Mutex::_no_safepoint_check_flag);
     _humongous_set.update_from_proxy(humongous_proxy_set);
@@ -5509,34 +5512,36 @@
   CardTableModRefBS* ct_bs = (CardTableModRefBS*) (barrier_set());
   double start = os::elapsedTime();
 
-  // Iterate over the dirty cards region list.
-  G1ParCleanupCTTask cleanup_task(ct_bs, this);
+  {
+    // Iterate over the dirty cards region list.
+    G1ParCleanupCTTask cleanup_task(ct_bs, this);
 
-  if (ParallelGCThreads > 0) {
-    set_par_threads(workers()->total_workers());
-    workers()->run_task(&cleanup_task);
-    set_par_threads(0);
-  } else {
-    while (_dirty_cards_region_list) {
-      HeapRegion* r = _dirty_cards_region_list;
-      cleanup_task.clear_cards(r);
-      _dirty_cards_region_list = r->get_next_dirty_cards_region();
-      if (_dirty_cards_region_list == r) {
-        // The last region.
-        _dirty_cards_region_list = NULL;
+    if (ParallelGCThreads > 0) {
+      set_par_threads(workers()->total_workers());
+      workers()->run_task(&cleanup_task);
+      set_par_threads(0);
+    } else {
+      while (_dirty_cards_region_list) {
+        HeapRegion* r = _dirty_cards_region_list;
+        cleanup_task.clear_cards(r);
+        _dirty_cards_region_list = r->get_next_dirty_cards_region();
+        if (_dirty_cards_region_list == r) {
+          // The last region.
+          _dirty_cards_region_list = NULL;
+        }
+        r->set_next_dirty_cards_region(NULL);
       }
-      r->set_next_dirty_cards_region(NULL);
     }
+#ifndef PRODUCT
+    if (G1VerifyCTCleanup || VerifyAfterGC) {
+      G1VerifyCardTableCleanup cleanup_verifier(this, ct_bs);
+      heap_region_iterate(&cleanup_verifier);
+    }
+#endif
   }
 
   double elapsed = os::elapsedTime() - start;
   g1_policy()->record_clear_ct_time(elapsed * 1000.0);
-#ifndef PRODUCT
-  if (G1VerifyCTCleanup || VerifyAfterGC) {
-    G1VerifyCardTableCleanup cleanup_verifier(this, ct_bs);
-    heap_region_iterate(&cleanup_verifier);
-  }
-#endif
 }
 
 void G1CollectedHeap::free_collection_set(HeapRegion* cs_head) {
@@ -5619,6 +5624,8 @@
         cur->set_young_index_in_cset(-1);
       cur->set_not_young();
       cur->set_evacuation_failed(false);
+      // The region is now considered to be old.
+      _old_set.add(cur);
     }
     cur = next;
   }
@@ -5634,6 +5641,7 @@
     young_time_ms += elapsed_ms;
 
   update_sets_after_freeing_regions(pre_used, &local_free_list,
+                                    NULL /* old_proxy_set */,
                                     NULL /* humongous_proxy_set */,
                                     false /* par */);
   policy->record_young_free_cset_time_ms(young_time_ms);
@@ -5745,52 +5753,106 @@
   return ret;
 }
 
-void G1CollectedHeap::empty_young_list() {
-  assert(heap_lock_held_for_gc(),
-              "the heap lock should already be held by or for this thread");
-
-  _young_list->empty_list();
-}
-
-// Done at the start of full GC.
-void G1CollectedHeap::tear_down_region_lists() {
-  _free_list.remove_all();
-}
-
-class RegionResetter: public HeapRegionClosure {
-  G1CollectedHeap* _g1h;
-  FreeRegionList _local_free_list;
+class TearDownRegionSetsClosure : public HeapRegionClosure {
+private:
+  OldRegionSet *_old_set;
 
 public:
-  RegionResetter() : _g1h(G1CollectedHeap::heap()),
-                     _local_free_list("Local Free List for RegionResetter") { }
+  TearDownRegionSetsClosure(OldRegionSet* old_set) : _old_set(old_set) { }
 
   bool doHeapRegion(HeapRegion* r) {
-    if (r->continuesHumongous()) return false;
-    if (r->top() > r->bottom()) {
-      if (r->top() < r->end()) {
-        Copy::fill_to_words(r->top(),
-                          pointer_delta(r->end(), r->top()));
-      }
+    if (r->is_empty()) {
+      // We ignore empty regions, we'll empty the free list afterwards
+    } else if (r->is_young()) {
+      // We ignore young regions, we'll empty the young list afterwards
+    } else if (r->isHumongous()) {
+      // We ignore humongous regions, we're not tearing down the
+      // humongous region set
     } else {
-      assert(r->is_empty(), "tautology");
-      _local_free_list.add_as_tail(r);
+      // The rest should be old
+      _old_set->remove(r);
     }
     return false;
   }
 
-  void update_free_lists() {
-    _g1h->update_sets_after_freeing_regions(0, &_local_free_list, NULL,
-                                            false /* par */);
+  ~TearDownRegionSetsClosure() {
+    assert(_old_set->is_empty(), "post-condition");
   }
 };
 
-// Done at the end of full GC.
-void G1CollectedHeap::rebuild_region_lists() {
-  // This needs to go at the end of the full GC.
-  RegionResetter rs;
-  heap_region_iterate(&rs);
-  rs.update_free_lists();
+void G1CollectedHeap::tear_down_region_sets(bool free_list_only) {
+  assert_at_safepoint(true /* should_be_vm_thread */);
+
+  if (!free_list_only) {
+    TearDownRegionSetsClosure cl(&_old_set);
+    heap_region_iterate(&cl);
+
+    // Need to do this after the heap iteration to be able to
+    // recognize the young regions and ignore them during the iteration.
+    _young_list->empty_list();
+  }
+  _free_list.remove_all();
+}
+
+class RebuildRegionSetsClosure : public HeapRegionClosure {
+private:
+  bool            _free_list_only;
+  OldRegionSet*   _old_set;
+  FreeRegionList* _free_list;
+  size_t          _total_used;
+
+public:
+  RebuildRegionSetsClosure(bool free_list_only,
+                           OldRegionSet* old_set, FreeRegionList* free_list) :
+    _free_list_only(free_list_only),
+    _old_set(old_set), _free_list(free_list), _total_used(0) {
+    assert(_free_list->is_empty(), "pre-condition");
+    if (!free_list_only) {
+      assert(_old_set->is_empty(), "pre-condition");
+    }
+  }
+
+  bool doHeapRegion(HeapRegion* r) {
+    if (r->continuesHumongous()) {
+      return false;
+    }
+
+    if (r->is_empty()) {
+      // Add free regions to the free list
+      _free_list->add_as_tail(r);
+    } else if (!_free_list_only) {
+      assert(!r->is_young(), "we should not come across young regions");
+
+      if (r->isHumongous()) {
+        // We ignore humongous regions, we left the humongous set unchanged
+      } else {
+        // The rest should be old, add them to the old set
+        _old_set->add(r);
+      }
+      _total_used += r->used();
+    }
+
+    return false;
+  }
+
+  size_t total_used() {
+    return _total_used;
+  }
+};
+
+void G1CollectedHeap::rebuild_region_sets(bool free_list_only) {
+  assert_at_safepoint(true /* should_be_vm_thread */);
+
+  RebuildRegionSetsClosure cl(free_list_only, &_old_set, &_free_list);
+  heap_region_iterate(&cl);
+
+  if (!free_list_only) {
+    _summary_bytes_used = cl.total_used();
+  }
+  assert(_summary_bytes_used == recalculate_used(),
+         err_msg("inconsistent _summary_bytes_used, "
+                 "value: "SIZE_FORMAT" recalculated: "SIZE_FORMAT,
+                 _summary_bytes_used, recalculate_used()));
 }
 
 void G1CollectedHeap::set_refine_cte_cl_concurrency(bool concurrent) {
@@ -5887,6 +5949,8 @@
   g1_policy()->record_bytes_copied_during_gc(allocated_bytes);
   if (ap == GCAllocForSurvived) {
     young_list()->add_survivor_region(alloc_region);
+  } else {
+    _old_set.add(alloc_region);
   }
   _hr_printer.retire(alloc_region);
 }
@@ -5918,15 +5982,17 @@
 
 class VerifyRegionListsClosure : public HeapRegionClosure {
 private:
-  HumongousRegionSet* _humongous_set;
   FreeRegionList*     _free_list;
+  OldRegionSet*       _old_set;
+  HumongousRegionSet* _humongous_set;
   size_t              _region_count;
 
 public:
-  VerifyRegionListsClosure(HumongousRegionSet* humongous_set,
+  VerifyRegionListsClosure(OldRegionSet* old_set,
+                           HumongousRegionSet* humongous_set,
                            FreeRegionList* free_list) :
-    _humongous_set(humongous_set), _free_list(free_list),
-    _region_count(0) { }
+    _old_set(old_set), _humongous_set(humongous_set),
+    _free_list(free_list), _region_count(0) { }
 
   size_t region_count()      { return _region_count;      }
 
@@ -5943,6 +6009,8 @@
       _humongous_set->verify_next_region(hr);
     } else if (hr->is_empty()) {
       _free_list->verify_next_region(hr);
+    } else {
+      _old_set->verify_next_region(hr);
     }
     return false;
   }
@@ -5969,6 +6037,7 @@
     MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);
     _secondary_free_list.verify();
   }
+  _old_set.verify();
   _humongous_set.verify();
 
   // If a concurrent region freeing operation is in progress it will
@@ -5992,12 +6061,14 @@
 
   // Finally, make sure that the region accounting in the lists is
   // consistent with what we see in the heap.
+  _old_set.verify_start();
   _humongous_set.verify_start();
   _free_list.verify_start();
 
-  VerifyRegionListsClosure cl(&_humongous_set, &_free_list);
+  VerifyRegionListsClosure cl(&_old_set, &_humongous_set, &_free_list);
   heap_region_iterate(&cl);
 
+  _old_set.verify_end();
   _humongous_set.verify_end();
   _free_list.verify_end();
 }
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp
index 76bf194..d0e0941 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp
@@ -239,6 +239,9 @@
   // master free list when appropriate.
   SecondaryFreeRegionList   _secondary_free_list;
 
+  // It keeps track of the old regions.
+  MasterOldRegionSet        _old_set;
+
   // It keeps track of the humongous regions.
   MasterHumongousRegionSet  _humongous_set;
 
@@ -248,10 +251,21 @@
   // The block offset table for the G1 heap.
   G1BlockOffsetSharedArray* _bot_shared;
 
-  // Move all of the regions off the free lists, then rebuild those free
-  // lists, before and after full GC.
-  void tear_down_region_lists();
-  void rebuild_region_lists();
+  // Tears down the region sets / lists so that they are empty and the
+  // regions on the heap do not belong to a region set / list. The
+  // only exception is the humongous set which we leave unaltered. If
+  // free_list_only is true, it will only tear down the master free
+  // list. It is called before a Full GC (free_list_only == false) or
+  // before heap shrinking (free_list_only == true).
+  void tear_down_region_sets(bool free_list_only);
+
+  // Rebuilds the region sets / lists so that they are repopulated to
+  // reflect the contents of the heap. The only exception is the
+  // humongous set which was not torn down in the first place. If
+  // free_list_only is true, it will only rebuild the master free
+  // list. It is called after a Full GC (free_list_only == false) or
+  // after heap shrinking (free_list_only == true).
+  void rebuild_region_sets(bool free_list_only);
 
   // The sequence of all heap regions in the heap.
   HeapRegionSeq _hrs;
@@ -1124,6 +1138,10 @@
     }
   }
 
+  void old_set_remove(HeapRegion* hr) {
+    _old_set.remove(hr);
+  }
+
   void set_free_regions_coming();
   void reset_free_regions_coming();
   bool free_regions_coming() { return _free_regions_coming; }
@@ -1153,6 +1171,7 @@
   void free_region_if_empty(HeapRegion* hr,
                             size_t* pre_used,
                             FreeRegionList* free_list,
+                            OldRegionSet* old_proxy_set,
                             HumongousRegionSet* humongous_proxy_set,
                             HRRSCleanupTask* hrrs_cleanup_task,
                             bool par);
@@ -1163,6 +1182,7 @@
   // (if par is true, it will do so by taking the ParGCRareEvent_lock).
   void update_sets_after_freeing_regions(size_t pre_used,
                                        FreeRegionList* free_list,
+                                       OldRegionSet* old_proxy_set,
                                        HumongousRegionSet* humongous_proxy_set,
                                        bool par);
 
@@ -1337,12 +1357,7 @@
   // storage in the heap comes from a young region or not.
   // See ReduceInitialCardMarks.
   virtual bool can_elide_tlab_store_barriers() const {
-    // 6920090: Temporarily disabled, because of lingering
-    // instabilities related to RICM with G1. In the
-    // interim, the option ReduceInitialCardMarksForG1
-    // below is left solely as a debugging device at least
-    // until 6920109 fixes the instabilities.
-    return ReduceInitialCardMarksForG1;
+    return true;
   }
 
   virtual bool card_mark_must_follow_store() const {
@@ -1366,8 +1381,6 @@
   // update logging post-barrier, we don't maintain remembered set
   // information for young gen objects.
   virtual bool can_elide_initializing_store_barrier(oop new_obj) {
-    // Re 6920090, 6920109 above.
-    assert(ReduceInitialCardMarksForG1, "Else cannot be here");
     return is_in_young(new_obj);
   }
 
@@ -1436,14 +1449,8 @@
 
   // Override; it uses the "prev" marking information
   virtual void verify(bool allow_dirty, bool silent);
-  // Default behavior by calling print(tty);
-  virtual void print() const;
-  // This calls print_on(st, PrintHeapAtGCExtended).
   virtual void print_on(outputStream* st) const;
-  // If extended is true, it will print out information for all
-  // regions in the heap by calling print_on_extended(st).
-  virtual void print_on(outputStream* st, bool extended) const;
-  virtual void print_on_extended(outputStream* st) const;
+  virtual void print_extended_on(outputStream* st) const;
 
   virtual void print_gc_threads_on(outputStream* st) const;
   virtual void gc_threads_do(ThreadClosure* tc) const;
@@ -1459,8 +1466,6 @@
   // asserted to be this type.
   static G1CollectedHeap* heap();
 
-  void empty_young_list();
-
   void set_region_short_lived_locked(HeapRegion* hr);
   // add appropriate methods for any other surv rate groups
 
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
index ee3fc6e..019f087 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
@@ -225,16 +225,12 @@
   _recent_CS_bytes_surviving(new TruncatedSeq(NumPrevPausesForHeuristics)),
 
   _recent_avg_pause_time_ratio(0.0),
-  _num_markings(0),
-  _n_marks(0),
-  _n_pauses_at_mark_end(0),
 
   _all_full_gc_times_ms(new NumberSeq()),
 
   // G1PausesBtwnConcMark defaults to -1
   // so the hack is to do the cast  QQQ FIXME
   _pauses_btwn_concurrent_mark((size_t)G1PausesBtwnConcMark),
-  _n_marks_since_last_pause(0),
   _initiate_conc_mark_if_possible(false),
   _during_initial_mark_pause(false),
   _should_revert_to_full_young_gcs(false),
@@ -298,10 +294,10 @@
   }
 
   // Verify PLAB sizes
-  const uint region_size = HeapRegion::GrainWords;
+  const size_t region_size = HeapRegion::GrainWords;
   if (YoungPLABSize > region_size || OldPLABSize > region_size) {
     char buffer[128];
-    jio_snprintf(buffer, sizeof(buffer), "%sPLABSize should be at most %u",
+    jio_snprintf(buffer, sizeof(buffer), "%sPLABSize should be at most "SIZE_FORMAT,
                  OldPLABSize > region_size ? "Old" : "Young", region_size);
     vm_exit_during_initialization(buffer);
   }
@@ -324,6 +320,7 @@
   _par_last_termination_attempts = new double[_parallel_gc_threads];
   _par_last_gc_worker_end_times_ms = new double[_parallel_gc_threads];
   _par_last_gc_worker_times_ms = new double[_parallel_gc_threads];
+  _par_last_gc_worker_other_times_ms = new double[_parallel_gc_threads];
 
   // start conservatively
   _expensive_region_limit_ms = 0.5 * (double) MaxGCPauseMillis;
@@ -440,6 +437,7 @@
   _reserve_regions = 0;
 
   initialize_all();
+  _collectionSetChooser = new CollectionSetChooser();
 }
 
 // Increment "i", mod "len"
@@ -500,7 +498,6 @@
   initialize_gc_policy_counters();
 
   G1YoungGenSizer sizer;
-  size_t initial_region_num = sizer.initial_young_region_num();
   _min_desired_young_length = sizer.min_young_region_num();
   _max_desired_young_length = sizer.max_young_region_num();
 
@@ -514,17 +511,14 @@
     }
   }
 
-  // GenCollectorPolicy guarantees that min <= initial <= max.
-  // Asserting here just to state that we rely on this property.
   assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
-  assert(initial_region_num <= _max_desired_young_length, "Initial young gen size too large");
-  assert(_min_desired_young_length <= initial_region_num, "Initial young gen size too small");
 
   set_adaptive_young_list_length(_min_desired_young_length < _max_desired_young_length);
   if (adaptive_young_list_length()) {
     _young_list_fixed_length = 0;
   } else {
-    _young_list_fixed_length = initial_region_num;
+    assert(_min_desired_young_length == _max_desired_young_length, "Min and max young size differ");
+    _young_list_fixed_length = _min_desired_young_length;
   }
   _free_regions_at_end_of_collection = _g1->free_regions();
   update_young_list_target_length();
@@ -921,6 +915,7 @@
   // Reset survivors SurvRateGroup.
   _survivor_surv_rate_group->reset();
   update_young_list_target_length();
+  _collectionSetChooser->updateAfterFullCollection();
 }
 
 void G1CollectorPolicy::record_stop_world_start() {
@@ -978,6 +973,7 @@
     _par_last_termination_attempts[i] = -1234.0;
     _par_last_gc_worker_end_times_ms[i] = -1234.0;
     _par_last_gc_worker_times_ms[i] = -1234.0;
+    _par_last_gc_worker_other_times_ms[i] = -1234.0;
   }
 #endif
 
@@ -986,8 +982,10 @@
     _cur_aux_times_set[i] = false;
   }
 
-  _satb_drain_time_set = false;
-  _last_satb_drain_processed_buffers = -1;
+  // These are initialized to zero here and they are set during
+  // the evacuation pause if marking is in progress.
+  _cur_satb_drain_time_ms = 0.0;
+  _last_satb_drain_processed_buffers = 0;
 
   _last_young_gc_full = false;
 
@@ -1029,39 +1027,7 @@
   _mark_cleanup_start_sec = os::elapsedTime();
 }
 
-void
-G1CollectorPolicy::record_concurrent_mark_cleanup_end(size_t freed_bytes,
-                                                      size_t max_live_bytes) {
-  record_concurrent_mark_cleanup_end_work1(freed_bytes, max_live_bytes);
-  record_concurrent_mark_cleanup_end_work2();
-}
-
-void
-G1CollectorPolicy::
-record_concurrent_mark_cleanup_end_work1(size_t freed_bytes,
-                                         size_t max_live_bytes) {
-  if (_n_marks < 2) {
-    _n_marks++;
-  }
-}
-
-// The important thing about this is that it includes "os::elapsedTime".
-void G1CollectorPolicy::record_concurrent_mark_cleanup_end_work2() {
-  double end_time_sec = os::elapsedTime();
-  double elapsed_time_ms = (end_time_sec - _mark_cleanup_start_sec)*1000.0;
-  _concurrent_mark_cleanup_times_ms->add(elapsed_time_ms);
-  _cur_mark_stop_world_time_ms += elapsed_time_ms;
-  _prev_collection_pause_end_ms += elapsed_time_ms;
-
-  _mmu_tracker->add_pause(_mark_cleanup_start_sec, end_time_sec, true);
-
-  _num_markings++;
-  _n_pauses_at_mark_end = _n_pauses;
-  _n_marks_since_last_pause++;
-}
-
-void
-G1CollectorPolicy::record_concurrent_mark_cleanup_completed() {
+void G1CollectorPolicy::record_concurrent_mark_cleanup_completed() {
   _should_revert_to_full_young_gcs = false;
   _last_full_young_gc = true;
   _in_marking_window = false;
@@ -1131,61 +1097,65 @@
     (int)total, (int)avg, (int)min, (int)max, (int)max - (int)min);
 }
 
-void G1CollectorPolicy::print_stats (int level,
-                                     const char* str,
-                                     double value) {
+void G1CollectorPolicy::print_stats(int level,
+                                    const char* str,
+                                    double value) {
   LineBuffer(level).append_and_print_cr("[%s: %5.1lf ms]", str, value);
 }
 
-void G1CollectorPolicy::print_stats (int level,
-                                     const char* str,
-                                     int value) {
+void G1CollectorPolicy::print_stats(int level,
+                                    const char* str,
+                                    int value) {
   LineBuffer(level).append_and_print_cr("[%s: %d]", str, value);
 }
 
-double G1CollectorPolicy::avg_value (double* data) {
+double G1CollectorPolicy::avg_value(double* data) {
   if (G1CollectedHeap::use_parallel_gc_threads()) {
     double ret = 0.0;
-    for (uint i = 0; i < ParallelGCThreads; ++i)
+    for (uint i = 0; i < ParallelGCThreads; ++i) {
       ret += data[i];
+    }
     return ret / (double) ParallelGCThreads;
   } else {
     return data[0];
   }
 }
 
-double G1CollectorPolicy::max_value (double* data) {
+double G1CollectorPolicy::max_value(double* data) {
   if (G1CollectedHeap::use_parallel_gc_threads()) {
     double ret = data[0];
-    for (uint i = 1; i < ParallelGCThreads; ++i)
-      if (data[i] > ret)
+    for (uint i = 1; i < ParallelGCThreads; ++i) {
+      if (data[i] > ret) {
         ret = data[i];
+      }
+    }
     return ret;
   } else {
     return data[0];
   }
 }
 
-double G1CollectorPolicy::sum_of_values (double* data) {
+double G1CollectorPolicy::sum_of_values(double* data) {
   if (G1CollectedHeap::use_parallel_gc_threads()) {
     double sum = 0.0;
-    for (uint i = 0; i < ParallelGCThreads; i++)
+    for (uint i = 0; i < ParallelGCThreads; i++) {
       sum += data[i];
+    }
     return sum;
   } else {
     return data[0];
   }
 }
 
-double G1CollectorPolicy::max_sum (double* data1,
-                                   double* data2) {
+double G1CollectorPolicy::max_sum(double* data1, double* data2) {
   double ret = data1[0] + data2[0];
 
   if (G1CollectedHeap::use_parallel_gc_threads()) {
     for (uint i = 1; i < ParallelGCThreads; ++i) {
       double data = data1[i] + data2[i];
-      if (data > ret)
+      if (data > ret) {
         ret = data;
+      }
     }
   }
   return ret;
@@ -1285,6 +1255,10 @@
 
   _n_pauses++;
 
+  // These values are used to update the summary information that is
+  // displayed when TraceGen0Time is enabled, and are output as part
+  // of the PrintGCDetails output, in the non-parallel case.
+
   double ext_root_scan_time = avg_value(_par_last_ext_root_scan_times_ms);
   double mark_stack_scan_time = avg_value(_par_last_mark_stack_scan_times_ms);
   double update_rs_time = avg_value(_par_last_update_rs_times_ms);
@@ -1294,42 +1268,68 @@
   double obj_copy_time = avg_value(_par_last_obj_copy_times_ms);
   double termination_time = avg_value(_par_last_termination_times_ms);
 
-  double parallel_known_time = update_rs_time +
-                               ext_root_scan_time +
-                               mark_stack_scan_time +
-                               scan_rs_time +
-                               obj_copy_time +
-                               termination_time;
+  double known_time = ext_root_scan_time +
+                      mark_stack_scan_time +
+                      update_rs_time +
+                      scan_rs_time +
+                      obj_copy_time;
 
-  double parallel_other_time = _cur_collection_par_time_ms - parallel_known_time;
+  double other_time_ms = elapsed_ms;
 
-  PauseSummary* summary = _summary;
+  // Subtract the SATB drain time. It's initialized to zero at the
+  // start of the pause and is updated during the pause if marking
+  // is in progress.
+  other_time_ms -= _cur_satb_drain_time_ms;
+
+  if (parallel) {
+    other_time_ms -= _cur_collection_par_time_ms;
+  } else {
+    other_time_ms -= known_time;
+  }
+
+  // Subtract the time taken to clean the card table from the
+  // current value of "other time"
+  other_time_ms -= _cur_clear_ct_time_ms;
+
+  // TraceGen0Time and TraceGen1Time summary info updating.
+  _all_pause_times_ms->add(elapsed_ms);
 
   if (update_stats) {
     _recent_rs_scan_times_ms->add(scan_rs_time);
     _recent_pause_times_ms->add(elapsed_ms);
     _recent_rs_sizes->add(rs_size);
 
-    MainBodySummary* body_summary = summary->main_body_summary();
-    guarantee(body_summary != NULL, "should not be null!");
+    _summary->record_total_time_ms(elapsed_ms);
+    _summary->record_other_time_ms(other_time_ms);
 
-    if (_satb_drain_time_set)
-      body_summary->record_satb_drain_time_ms(_cur_satb_drain_time_ms);
-    else
-      body_summary->record_satb_drain_time_ms(0.0);
+    MainBodySummary* body_summary = _summary->main_body_summary();
+    assert(body_summary != NULL, "should not be null!");
+
+    // This will be non-zero iff marking is currently in progress (i.e.
+    // _g1->mark_in_progress() == true) and the currrent pause was not
+    // an initial mark pause. Since the body_summary items are NumberSeqs,
+    // however, they have to be consistent and updated in lock-step with
+    // each other. Therefore we unconditionally record the SATB drain
+    // time - even if it's zero.
+    body_summary->record_satb_drain_time_ms(_cur_satb_drain_time_ms);
 
     body_summary->record_ext_root_scan_time_ms(ext_root_scan_time);
     body_summary->record_mark_stack_scan_time_ms(mark_stack_scan_time);
     body_summary->record_update_rs_time_ms(update_rs_time);
     body_summary->record_scan_rs_time_ms(scan_rs_time);
     body_summary->record_obj_copy_time_ms(obj_copy_time);
+
     if (parallel) {
       body_summary->record_parallel_time_ms(_cur_collection_par_time_ms);
-      body_summary->record_clear_ct_time_ms(_cur_clear_ct_time_ms);
       body_summary->record_termination_time_ms(termination_time);
+
+      double parallel_known_time = known_time + termination_time;
+      double parallel_other_time = _cur_collection_par_time_ms - parallel_known_time;
       body_summary->record_parallel_other_time_ms(parallel_other_time);
     }
+
     body_summary->record_mark_closure_time_ms(_mark_closure_time_ms);
+    body_summary->record_clear_ct_time_ms(_cur_clear_ct_time_ms);
 
     // We exempt parallel collection from this check because Alloc Buffer
     // fragmentation can produce negative collections.  Same with evac
@@ -1341,6 +1341,7 @@
            || _g1->evacuation_failed()
            || surviving_bytes <= _collection_set_bytes_used_before,
            "Or else negative collection!");
+
     _recent_CS_bytes_used_before->add(_collection_set_bytes_used_before);
     _recent_CS_bytes_surviving->add(surviving_bytes);
 
@@ -1391,6 +1392,13 @@
     }
   }
 
+  for (int i = 0; i < _aux_num; ++i) {
+    if (_cur_aux_times_set[i]) {
+      _all_aux_times_ms[i].add(_cur_aux_times_ms[i]);
+    }
+  }
+
+
   if (G1PolicyVerbose > 1) {
     gclog_or_tty->print_cr("   Recording collection pause(%d)", _n_pauses);
   }
@@ -1417,61 +1425,60 @@
                            recent_avg_pause_time_ratio() * 100.0);
   }
 
-  double other_time_ms = elapsed_ms;
-
-  if (_satb_drain_time_set) {
-    other_time_ms -= _cur_satb_drain_time_ms;
-  }
-
-  if (parallel) {
-    other_time_ms -= _cur_collection_par_time_ms + _cur_clear_ct_time_ms;
-  } else {
-    other_time_ms -=
-      update_rs_time +
-      ext_root_scan_time + mark_stack_scan_time +
-      scan_rs_time + obj_copy_time;
-  }
-
+  // PrintGCDetails output
   if (PrintGCDetails) {
+    bool print_marking_info =
+      _g1->mark_in_progress() && !last_pause_included_initial_mark;
+
     gclog_or_tty->print_cr("%s, %1.8lf secs]",
                            (last_pause_included_initial_mark) ? " (initial-mark)" : "",
                            elapsed_ms / 1000.0);
 
-    if (_satb_drain_time_set) {
+    if (print_marking_info) {
       print_stats(1, "SATB Drain Time", _cur_satb_drain_time_ms);
-    }
-    if (_last_satb_drain_processed_buffers >= 0) {
       print_stats(2, "Processed Buffers", _last_satb_drain_processed_buffers);
     }
+
     if (parallel) {
       print_stats(1, "Parallel Time", _cur_collection_par_time_ms);
-      print_par_stats(2, "GC Worker Start Time", _par_last_gc_worker_start_times_ms);
+      print_par_stats(2, "GC Worker Start", _par_last_gc_worker_start_times_ms);
+      print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms);
+      if (print_marking_info) {
+        print_par_stats(2, "Mark Stack Scanning", _par_last_mark_stack_scan_times_ms);
+      }
       print_par_stats(2, "Update RS", _par_last_update_rs_times_ms);
       print_par_sizes(3, "Processed Buffers", _par_last_update_rs_processed_buffers);
-      print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms);
-      print_par_stats(2, "Mark Stack Scanning", _par_last_mark_stack_scan_times_ms);
       print_par_stats(2, "Scan RS", _par_last_scan_rs_times_ms);
       print_par_stats(2, "Object Copy", _par_last_obj_copy_times_ms);
       print_par_stats(2, "Termination", _par_last_termination_times_ms);
       print_par_sizes(3, "Termination Attempts", _par_last_termination_attempts);
-      print_par_stats(2, "GC Worker End Time", _par_last_gc_worker_end_times_ms);
+      print_par_stats(2, "GC Worker End", _par_last_gc_worker_end_times_ms);
 
       for (int i = 0; i < _parallel_gc_threads; i++) {
         _par_last_gc_worker_times_ms[i] = _par_last_gc_worker_end_times_ms[i] - _par_last_gc_worker_start_times_ms[i];
-      }
-      print_par_stats(2, "GC Worker Times", _par_last_gc_worker_times_ms);
 
-      print_stats(2, "Parallel Other", parallel_other_time);
-      print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
+        double worker_known_time = _par_last_ext_root_scan_times_ms[i] +
+                                   _par_last_mark_stack_scan_times_ms[i] +
+                                   _par_last_update_rs_times_ms[i] +
+                                   _par_last_scan_rs_times_ms[i] +
+                                   _par_last_obj_copy_times_ms[i] +
+                                   _par_last_termination_times_ms[i];
+
+        _par_last_gc_worker_other_times_ms[i] = _cur_collection_par_time_ms - worker_known_time;
+      }
+      print_par_stats(2, "GC Worker", _par_last_gc_worker_times_ms);
+      print_par_stats(2, "GC Worker Other", _par_last_gc_worker_other_times_ms);
     } else {
-      print_stats(1, "Update RS", update_rs_time);
-      print_stats(2, "Processed Buffers",
-                  (int)update_rs_processed_buffers);
       print_stats(1, "Ext Root Scanning", ext_root_scan_time);
-      print_stats(1, "Mark Stack Scanning", mark_stack_scan_time);
+      if (print_marking_info) {
+        print_stats(1, "Mark Stack Scanning", mark_stack_scan_time);
+      }
+      print_stats(1, "Update RS", update_rs_time);
+      print_stats(2, "Processed Buffers", (int)update_rs_processed_buffers);
       print_stats(1, "Scan RS", scan_rs_time);
       print_stats(1, "Object Copying", obj_copy_time);
     }
+    print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
 #ifndef PRODUCT
     print_stats(1, "Cur Clear CC", _cur_clear_cc_time_ms);
     print_stats(1, "Cum Clear CC", _cum_clear_cc_time_ms);
@@ -1495,18 +1502,6 @@
     }
   }
 
-  _all_pause_times_ms->add(elapsed_ms);
-  if (update_stats) {
-    summary->record_total_time_ms(elapsed_ms);
-    summary->record_other_time_ms(other_time_ms);
-  }
-  for (int i = 0; i < _aux_num; ++i)
-    if (_cur_aux_times_set[i])
-      _all_aux_times_ms[i].add(_cur_aux_times_ms[i]);
-
-  // Reset marks-between-pauses counter.
-  _n_marks_since_last_pause = 0;
-
   // Update the efficiency-since-mark vars.
   double proc_ms = elapsed_ms * (double) _parallel_gc_threads;
   if (elapsed_ms < MIN_TIMER_GRANULARITY) {
@@ -1729,6 +1724,8 @@
   double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
   adjust_concurrent_refinement(update_rs_time, update_rs_processed_buffers, update_rs_time_goal_ms);
   // </NEW PREDICTION>
+
+  assert(assertMarkedBytesDataOK(), "Marked regions not OK at pause end.");
 }
 
 #define EXT_SIZE_FORMAT "%d%s"
@@ -2156,10 +2153,6 @@
   }
 }
 
-void G1CollectorPolicy::note_start_of_mark_thread() {
-  _mark_thread_startup_sec = os::elapsedTime();
-}
-
 class CountCSClosure: public HeapRegionClosure {
   G1CollectorPolicy* _g1_policy;
 public:
@@ -2176,17 +2169,17 @@
   _g1->collection_set_iterate(&cs_closure);
 }
 
-void G1CollectorPolicy::print_summary (int level,
-                                       const char* str,
-                                       NumberSeq* seq) const {
+void G1CollectorPolicy::print_summary(int level,
+                                      const char* str,
+                                      NumberSeq* seq) const {
   double sum = seq->sum();
   LineBuffer(level + 1).append_and_print_cr("%-24s = %8.2lf s (avg = %8.2lf ms)",
                 str, sum / 1000.0, seq->avg());
 }
 
-void G1CollectorPolicy::print_summary_sd (int level,
-                                          const char* str,
-                                          NumberSeq* seq) const {
+void G1CollectorPolicy::print_summary_sd(int level,
+                                         const char* str,
+                                         NumberSeq* seq) const {
   print_summary(level, str, seq);
   LineBuffer(level + 6).append_and_print_cr("(num = %5d, std dev = %8.2lf ms, max = %8.2lf ms)",
                 seq->num(), seq->sd(), seq->maximum());
@@ -2249,20 +2242,18 @@
       print_summary(1, "SATB Drain", body_summary->get_satb_drain_seq());
       if (parallel) {
         print_summary(1, "Parallel Time", body_summary->get_parallel_seq());
+        print_summary(2, "Ext Root Scanning", body_summary->get_ext_root_scan_seq());
+        print_summary(2, "Mark Stack Scanning", body_summary->get_mark_stack_scan_seq());
         print_summary(2, "Update RS", body_summary->get_update_rs_seq());
-        print_summary(2, "Ext Root Scanning",
-                      body_summary->get_ext_root_scan_seq());
-        print_summary(2, "Mark Stack Scanning",
-                      body_summary->get_mark_stack_scan_seq());
         print_summary(2, "Scan RS", body_summary->get_scan_rs_seq());
         print_summary(2, "Object Copy", body_summary->get_obj_copy_seq());
         print_summary(2, "Termination", body_summary->get_termination_seq());
-        print_summary(2, "Other", body_summary->get_parallel_other_seq());
+        print_summary(2, "Parallel Other", body_summary->get_parallel_other_seq());
         {
           NumberSeq* other_parts[] = {
-            body_summary->get_update_rs_seq(),
             body_summary->get_ext_root_scan_seq(),
             body_summary->get_mark_stack_scan_seq(),
+            body_summary->get_update_rs_seq(),
             body_summary->get_scan_rs_seq(),
             body_summary->get_obj_copy_seq(),
             body_summary->get_termination_seq()
@@ -2272,18 +2263,16 @@
           check_other_times(2, body_summary->get_parallel_other_seq(),
                             &calc_other_times_ms);
         }
-        print_summary(1, "Mark Closure", body_summary->get_mark_closure_seq());
-        print_summary(1, "Clear CT", body_summary->get_clear_ct_seq());
       } else {
+        print_summary(1, "Ext Root Scanning", body_summary->get_ext_root_scan_seq());
+        print_summary(1, "Mark Stack Scanning", body_summary->get_mark_stack_scan_seq());
         print_summary(1, "Update RS", body_summary->get_update_rs_seq());
-        print_summary(1, "Ext Root Scanning",
-                      body_summary->get_ext_root_scan_seq());
-        print_summary(1, "Mark Stack Scanning",
-                      body_summary->get_mark_stack_scan_seq());
         print_summary(1, "Scan RS", body_summary->get_scan_rs_seq());
         print_summary(1, "Object Copy", body_summary->get_obj_copy_seq());
       }
     }
+    print_summary(1, "Mark Closure", body_summary->get_mark_closure_seq());
+    print_summary(1, "Clear CT", body_summary->get_clear_ct_seq());
     print_summary(1, "Other", summary->get_other_seq());
     {
       if (body_summary != NULL) {
@@ -2446,7 +2435,7 @@
   }
 };
 
-bool G1CollectorPolicy_BestRegionsFirst::assertMarkedBytesDataOK() {
+bool G1CollectorPolicy::assertMarkedBytesDataOK() {
   HRSortIndexIsOKClosure cl(_collectionSetChooser);
   _g1->heap_region_iterate(&cl);
   return true;
@@ -2532,12 +2521,6 @@
   }
 }
 
-void
-G1CollectorPolicy_BestRegionsFirst::
-record_collection_pause_start(double start_time_sec, size_t start_used) {
-  G1CollectorPolicy::record_collection_pause_start(start_time_sec, start_used);
-}
-
 class KnownGarbageClosure: public HeapRegionClosure {
   CollectionSetChooser* _hrSorted;
 
@@ -2645,20 +2628,20 @@
 };
 
 void
-G1CollectorPolicy_BestRegionsFirst::
-record_concurrent_mark_cleanup_end(size_t freed_bytes,
-                                   size_t max_live_bytes) {
-  double start;
-  if (G1PrintParCleanupStats) start = os::elapsedTime();
-  record_concurrent_mark_cleanup_end_work1(freed_bytes, max_live_bytes);
+G1CollectorPolicy::record_concurrent_mark_cleanup_end() {
+  double start_sec;
+  if (G1PrintParCleanupStats) {
+    start_sec = os::elapsedTime();
+  }
 
   _collectionSetChooser->clearMarkedHeapRegions();
-  double clear_marked_end;
+  double clear_marked_end_sec;
   if (G1PrintParCleanupStats) {
-    clear_marked_end = os::elapsedTime();
-    gclog_or_tty->print_cr("  clear marked regions + work1: %8.3f ms.",
-                  (clear_marked_end - start)*1000.0);
+    clear_marked_end_sec = os::elapsedTime();
+    gclog_or_tty->print_cr("  clear marked regions: %8.3f ms.",
+                           (clear_marked_end_sec - start_sec) * 1000.0);
   }
+
   if (G1CollectedHeap::use_parallel_gc_threads()) {
     const size_t OverpartitionFactor = 4;
     const size_t MinWorkUnit = 8;
@@ -2677,27 +2660,25 @@
     KnownGarbageClosure knownGarbagecl(_collectionSetChooser);
     _g1->heap_region_iterate(&knownGarbagecl);
   }
-  double known_garbage_end;
+  double known_garbage_end_sec;
   if (G1PrintParCleanupStats) {
-    known_garbage_end = os::elapsedTime();
+    known_garbage_end_sec = os::elapsedTime();
     gclog_or_tty->print_cr("  compute known garbage: %8.3f ms.",
-                  (known_garbage_end - clear_marked_end)*1000.0);
-  }
-  _collectionSetChooser->sortMarkedHeapRegions();
-  double sort_end;
-  if (G1PrintParCleanupStats) {
-    sort_end = os::elapsedTime();
-    gclog_or_tty->print_cr("  sorting: %8.3f ms.",
-                  (sort_end - known_garbage_end)*1000.0);
+                      (known_garbage_end_sec - clear_marked_end_sec) * 1000.0);
   }
 
-  record_concurrent_mark_cleanup_end_work2();
-  double work2_end;
+  _collectionSetChooser->sortMarkedHeapRegions();
+  double end_sec = os::elapsedTime();
   if (G1PrintParCleanupStats) {
-    work2_end = os::elapsedTime();
-    gclog_or_tty->print_cr("  work2: %8.3f ms.",
-                  (work2_end - sort_end)*1000.0);
+    gclog_or_tty->print_cr("  sorting: %8.3f ms.",
+                           (end_sec - known_garbage_end_sec) * 1000.0);
   }
+
+  double elapsed_time_ms = (end_sec - _mark_cleanup_start_sec) * 1000.0;
+  _concurrent_mark_cleanup_times_ms->add(elapsed_time_ms);
+  _cur_mark_stop_world_time_ms += elapsed_time_ms;
+  _prev_collection_pause_end_ms += elapsed_time_ms;
+  _mmu_tracker->add_pause(_mark_cleanup_start_sec, end_sec, true);
 }
 
 // Add the heap region at the head of the non-incremental collection set
@@ -2912,9 +2893,7 @@
 }
 #endif // !PRODUCT
 
-void
-G1CollectorPolicy_BestRegionsFirst::choose_collection_set(
-                                                  double target_pause_time_ms) {
+void G1CollectorPolicy::choose_collection_set(double target_pause_time_ms) {
   // Set this here - in case we're not doing young collections.
   double non_young_start_time_sec = os::elapsedTime();
 
@@ -3036,6 +3015,7 @@
       hr = _collectionSetChooser->getNextMarkedRegion(time_remaining_ms,
                                                       avg_prediction);
       if (hr != NULL) {
+        _g1->old_set_remove(hr);
         double predicted_time_ms = predict_region_elapsed_time_ms(hr, false);
         time_remaining_ms -= predicted_time_ms;
         predicted_pause_time_ms += predicted_time_ms;
@@ -3115,14 +3095,3 @@
   _recorded_non_young_cset_choice_time_ms =
     (non_young_end_time_sec - non_young_start_time_sec) * 1000.0;
 }
-
-void G1CollectorPolicy_BestRegionsFirst::record_full_collection_end() {
-  G1CollectorPolicy::record_full_collection_end();
-  _collectionSetChooser->updateAfterFullCollection();
-}
-
-void G1CollectorPolicy_BestRegionsFirst::
-record_collection_pause_end() {
-  G1CollectorPolicy::record_collection_pause_end();
-  assert(assertMarkedBytesDataOK(), "Marked regions not OK at pause end.");
-}
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp
index 4e61395..cff4870 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp
@@ -74,7 +74,7 @@
     define_num_seq(termination) // parallel only
     define_num_seq(parallel_other) // parallel only
   define_num_seq(mark_closure)
-  define_num_seq(clear_ct)  // parallel only
+  define_num_seq(clear_ct)
 };
 
 class Summary: public PauseSummary,
@@ -84,7 +84,7 @@
 };
 
 class G1CollectorPolicy: public CollectorPolicy {
-protected:
+private:
   // The number of pauses during the execution.
   long _n_pauses;
 
@@ -106,10 +106,7 @@
     initialize_perm_generation(PermGen::MarkSweepCompact);
   }
 
-  virtual size_t default_init_heap_size() {
-    // Pick some reasonable default.
-    return 8*M;
-  }
+  CollectionSetChooser* _collectionSetChooser;
 
   double _cur_collection_start_sec;
   size_t _cur_collection_pause_used_at_start_bytes;
@@ -118,7 +115,6 @@
   double _cur_collection_par_time_ms;
   double _cur_satb_drain_time_ms;
   double _cur_clear_ct_time_ms;
-  bool   _satb_drain_time_set;
   double _cur_ref_proc_time_ms;
   double _cur_ref_enq_time_ms;
 
@@ -179,6 +175,11 @@
   double* _par_last_gc_worker_end_times_ms;
   double* _par_last_gc_worker_times_ms;
 
+  // Each workers 'other' time i.e. the elapsed time of the parallel
+  // phase of the pause minus the sum of the individual sub-phase
+  // times for a given worker thread.
+  double* _par_last_gc_worker_other_times_ms;
+
   // indicates whether we are in full young or partially young GC mode
   bool _full_young_gcs;
 
@@ -316,7 +317,6 @@
                                     double update_rs_processed_buffers,
                                     double goal_ms);
 
-protected:
   double _pause_time_target_ms;
   double _recorded_young_cset_choice_time_ms;
   double _recorded_non_young_cset_choice_time_ms;
@@ -554,7 +554,7 @@
     return _short_lived_surv_rate_group->accum_surv_rate_pred(age);
   }
 
-protected:
+private:
   void print_stats(int level, const char* str, double value);
   void print_stats(int level, const char* str, int value);
 
@@ -588,10 +588,6 @@
   // Statistics kept per GC stoppage, pause or full.
   TruncatedSeq* _recent_prev_end_times_for_all_gcs_sec;
 
-  // We track markings.
-  int _num_markings;
-  double _mark_thread_startup_sec;       // Time at startup of marking thread
-
   // Add a new GC of the given duration and end time to the record.
   void update_recent_gc_times(double end_time_sec, double elapsed_ms);
 
@@ -664,12 +660,6 @@
   // young list/collection set).
   size_t _inc_cset_predicted_bytes_to_copy;
 
-  // Info about marking.
-  int _n_marks; // Sticky at 2, so we know when we've done at least 2.
-
-  // The number of collection pauses at the end of the last mark.
-  size_t _n_pauses_at_mark_end;
-
   // Stash a pointer to the g1 heap.
   G1CollectedHeap* _g1;
 
@@ -737,8 +727,6 @@
   // Number of pauses between concurrent marking.
   size_t _pauses_btwn_concurrent_mark;
 
-  size_t _n_marks_since_last_pause;
-
   // At the end of a pause we check the heap occupancy and we decide
   // whether we will start a marking cycle during the next pause. If
   // we decide that we want to do that, we will set this parameter to
@@ -810,6 +798,11 @@
   bool predict_will_fit(size_t young_length, double base_time_ms,
                         size_t base_free_regions, double target_pause_time_ms);
 
+  // Count the number of bytes used in the CS.
+  void count_CS_bytes_used();
+
+  void update_young_list_size_using_newratio(size_t number_of_heap_regions);
+
 public:
 
   G1CollectorPolicy();
@@ -836,22 +829,9 @@
   // This should be called after the heap is resized.
   void record_new_heap_size(size_t new_number_of_regions);
 
-protected:
-
-  // Count the number of bytes used in the CS.
-  void count_CS_bytes_used();
-
-  // Together these do the base cleanup-recording work.  Subclasses might
-  // want to put something between them.
-  void record_concurrent_mark_cleanup_end_work1(size_t freed_bytes,
-                                                size_t max_live_bytes);
-  void record_concurrent_mark_cleanup_end_work2();
-
-  void update_young_list_size_using_newratio(size_t number_of_heap_regions);
-
 public:
 
-  virtual void init();
+  void init();
 
   // Create jstat counters for the policy.
   virtual void initialize_gc_policy_counters();
@@ -876,10 +856,9 @@
   // start time, where the given number of bytes were used at the start.
   // This may involve changing the desired size of a collection set.
 
-  virtual void record_stop_world_start();
+  void record_stop_world_start();
 
-  virtual void record_collection_pause_start(double start_time_sec,
-                                             size_t start_used);
+  void record_collection_pause_start(double start_time_sec, size_t start_used);
 
   // Must currently be called while the world is stopped.
   void record_concurrent_mark_init_end(double
@@ -887,23 +866,22 @@
 
   void record_mark_closure_time(double mark_closure_time_ms);
 
-  virtual void record_concurrent_mark_remark_start();
-  virtual void record_concurrent_mark_remark_end();
+  void record_concurrent_mark_remark_start();
+  void record_concurrent_mark_remark_end();
 
-  virtual void record_concurrent_mark_cleanup_start();
-  virtual void record_concurrent_mark_cleanup_end(size_t freed_bytes,
-                                                  size_t max_live_bytes);
-  virtual void record_concurrent_mark_cleanup_completed();
+  void record_concurrent_mark_cleanup_start();
+  void record_concurrent_mark_cleanup_end();
+  void record_concurrent_mark_cleanup_completed();
 
-  virtual void record_concurrent_pause();
-  virtual void record_concurrent_pause_end();
+  void record_concurrent_pause();
+  void record_concurrent_pause_end();
 
-  virtual void record_collection_pause_end();
+  void record_collection_pause_end();
   void print_heap_transition();
 
   // Record the fact that a full collection occurred.
-  virtual void record_full_collection_start();
-  virtual void record_full_collection_end();
+  void record_full_collection_start();
+  void record_full_collection_end();
 
   void record_gc_worker_start_time(int worker_i, double ms) {
     _par_last_gc_worker_start_times_ms[worker_i] = ms;
@@ -918,11 +896,12 @@
   }
 
   void record_satb_drain_time(double ms) {
+    assert(_g1->mark_in_progress(), "shouldn't be here otherwise");
     _cur_satb_drain_time_ms = ms;
-    _satb_drain_time_set    = true;
   }
 
-  void record_satb_drain_processed_buffers (int processed_buffers) {
+  void record_satb_drain_processed_buffers(int processed_buffers) {
+    assert(_g1->mark_in_progress(), "shouldn't be here otherwise");
     _last_satb_drain_processed_buffers = processed_buffers;
   }
 
@@ -1022,7 +1001,7 @@
   // Choose a new collection set.  Marks the chosen regions as being
   // "in_collection_set", and links them together.  The head and number of
   // the collection set are available via access methods.
-  virtual void choose_collection_set(double target_pause_time_ms) = 0;
+  void choose_collection_set(double target_pause_time_ms);
 
   // The head of the list (via "next_in_collection_set()") representing the
   // current collection set.
@@ -1107,19 +1086,12 @@
 
   // If an expansion would be appropriate, because recent GC overhead had
   // exceeded the desired limit, return an amount to expand by.
-  virtual size_t expansion_amount();
-
-  // note start of mark thread
-  void note_start_of_mark_thread();
-
-  // The marked bytes of the "r" has changed; reclassify it's desirability
-  // for marking.  Also asserts that "r" is eligible for a CS.
-  virtual void note_change_in_marked_bytes(HeapRegion* r) = 0;
+  size_t expansion_amount();
 
 #ifndef PRODUCT
   // Check any appropriate marked bytes info, asserting false if
   // something's wrong, else returning "true".
-  virtual bool assertMarkedBytesDataOK() = 0;
+  bool assertMarkedBytesDataOK();
 #endif
 
   // Print tracing information.
@@ -1182,10 +1154,10 @@
     return ret;
   }
 
+private:
   //
   // Survivor regions policy.
   //
-protected:
 
   // Current tenuring threshold, set to 0 if the collector reaches the
   // maximum amount of suvivors regions.
@@ -1265,51 +1237,6 @@
 
 };
 
-// This encapsulates a particular strategy for a g1 Collector.
-//
-//      Start a concurrent mark when our heap size is n bytes
-//            greater then our heap size was at the last concurrent
-//            mark.  Where n is a function of the CMSTriggerRatio
-//            and the MinHeapFreeRatio.
-//
-//      Start a g1 collection pause when we have allocated the
-//            average number of bytes currently being freed in
-//            a collection, but only if it is at least one region
-//            full
-//
-//      Resize Heap based on desired
-//      allocation space, where desired allocation space is
-//      a function of survival rate and desired future to size.
-//
-//      Choose collection set by first picking all older regions
-//      which have a survival rate which beats our projected young
-//      survival rate.  Then fill out the number of needed regions
-//      with young regions.
-
-class G1CollectorPolicy_BestRegionsFirst: public G1CollectorPolicy {
-  CollectionSetChooser* _collectionSetChooser;
-
-  virtual void choose_collection_set(double target_pause_time_ms);
-  virtual void record_collection_pause_start(double start_time_sec,
-                                             size_t start_used);
-  virtual void record_concurrent_mark_cleanup_end(size_t freed_bytes,
-                                                  size_t max_live_bytes);
-  virtual void record_full_collection_end();
-
-public:
-  G1CollectorPolicy_BestRegionsFirst() {
-    _collectionSetChooser = new CollectionSetChooser();
-  }
-  void record_collection_pause_end();
-  // This is not needed any more, after the CSet choosing code was
-  // changed to use the pause prediction work. But let's leave the
-  // hook in just in case.
-  void note_change_in_marked_bytes(HeapRegion* r) { }
-#ifndef PRODUCT
-  bool assertMarkedBytesDataOK();
-#endif
-};
-
 // This should move to some place more general...
 
 // If we have "n" measurements, and we've kept track of their "sum" and the
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp
index 84bbadb..c12bb56 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp
@@ -236,6 +236,7 @@
     // at the end of the GC, so no point in updating those values here.
     _g1h->update_sets_after_freeing_regions(0, /* pre_used */
                                             NULL, /* free_list */
+                                            NULL, /* old_proxy_set */
                                             &_humongous_proxy_set,
                                             false /* par */);
   }
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp
index 1e6373c..9f10ac2 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1RemSet.cpp
@@ -122,10 +122,10 @@
   void set_try_claimed() { _try_claimed = true; }
 
   void scanCard(size_t index, HeapRegion *r) {
-    DirtyCardToOopClosure* cl =
-      r->new_dcto_closure(_oc,
-                         CardTableModRefBS::Precise,
-                         HeapRegionDCTOC::IntoCSFilterKind);
+    // Stack allocate the DirtyCardToOopClosure instance
+    HeapRegionDCTOC cl(_g1h, r, _oc,
+                       CardTableModRefBS::Precise,
+                       HeapRegionDCTOC::IntoCSFilterKind);
 
     // Set the "from" region in the closure.
     _oc->set_region(r);
@@ -140,7 +140,7 @@
       // scans (the rsets of the regions in the cset can intersect).
       _ct_bs->set_card_claimed(index);
       _cards_done++;
-      cl->do_MemRegion(mr);
+      cl.do_MemRegion(mr);
     }
   }
 
@@ -635,10 +635,18 @@
   ct_freq_note_card(_ct_bs->index_for(start));
 #endif
 
-  assert(!check_for_refs_into_cset || _cset_rs_update_cl[worker_i] != NULL, "sanity");
+  OopsInHeapRegionClosure* oops_in_heap_closure = NULL;
+  if (check_for_refs_into_cset) {
+    // ConcurrentG1RefineThreads have worker numbers larger than what
+    // _cset_rs_update_cl[] is set up to handle. But those threads should
+    // only be active outside of a collection which means that when they
+    // reach here they should have check_for_refs_into_cset == false.
+    assert((size_t)worker_i < n_workers(), "index of worker larger than _cset_rs_update_cl[].length");
+    oops_in_heap_closure = _cset_rs_update_cl[worker_i];
+  }
   UpdateRSOrPushRefOopClosure update_rs_oop_cl(_g1,
                                                _g1->g1_rem_set(),
-                                               _cset_rs_update_cl[worker_i],
+                                               oops_in_heap_closure,
                                                check_for_refs_into_cset,
                                                worker_i);
   update_rs_oop_cl.set_from(r);
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
index 59d2590..e54956c 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
                                                  int max_covered_regions) :
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1_globals.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1_globals.hpp
index 1e2ab28..861c947 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1_globals.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1_globals.hpp
@@ -290,10 +290,6 @@
           "each evacuation pause in order to artificially fill up the "     \
           "heap and stress the marking implementation.")                    \
                                                                             \
-  develop(bool, ReduceInitialCardMarksForG1, false,                         \
-          "When ReduceInitialCardMarks is true, this flag setting "         \
-          " controls whether G1 allows the RICM optimization")              \
-                                                                            \
   develop(bool, G1ExitOnExpansionFailure, false,                            \
           "Raise a fatal VM exit out of memory failure in the event "       \
           " that heap expansion fails due to running out of swap.")         \
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp
index 069ce3c..98b7ebf 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp
@@ -33,11 +33,11 @@
 #include "memory/iterator.hpp"
 #include "oops/oop.inline.hpp"
 
-int HeapRegion::LogOfHRGrainBytes = 0;
-int HeapRegion::LogOfHRGrainWords = 0;
-int HeapRegion::GrainBytes        = 0;
-int HeapRegion::GrainWords        = 0;
-int HeapRegion::CardsPerRegion    = 0;
+int    HeapRegion::LogOfHRGrainBytes = 0;
+int    HeapRegion::LogOfHRGrainWords = 0;
+size_t HeapRegion::GrainBytes        = 0;
+size_t HeapRegion::GrainWords        = 0;
+size_t HeapRegion::CardsPerRegion    = 0;
 
 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
                                  HeapRegion* hr, OopClosure* cl,
@@ -322,11 +322,11 @@
   guarantee(GrainBytes == 0, "we should only set it once");
   // The cast to int is safe, given that we've bounded region_size by
   // MIN_REGION_SIZE and MAX_REGION_SIZE.
-  GrainBytes = (int) region_size;
+  GrainBytes = (size_t)region_size;
 
   guarantee(GrainWords == 0, "we should only set it once");
   GrainWords = GrainBytes >> LogHeapWordSize;
-  guarantee(1 << LogOfHRGrainWords == GrainWords, "sanity");
+  guarantee((size_t)(1 << LogOfHRGrainWords) == GrainWords, "sanity");
 
   guarantee(CardsPerRegion == 0, "we should only set it once");
   CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift;
@@ -340,14 +340,6 @@
   init_top_at_mark_start();
 }
 
-DirtyCardToOopClosure*
-HeapRegion::new_dcto_closure(OopClosure* cl,
-                             CardTableModRefBS::PrecisionStyle precision,
-                             HeapRegionDCTOC::FilterKind fk) {
-  return new HeapRegionDCTOC(G1CollectedHeap::heap(),
-                             this, cl, precision, fk);
-}
-
 void HeapRegion::hr_clear(bool par, bool clear_space) {
   assert(_humongous_type == NotHumongous,
          "we should have already filtered out humongous regions");
@@ -379,8 +371,7 @@
 
 void HeapRegion::par_clear() {
   assert(used() == 0, "the region should have been already cleared");
-  assert(capacity() == (size_t) HeapRegion::GrainBytes,
-         "should be back to normal");
+  assert(capacity() == HeapRegion::GrainBytes, "should be back to normal");
   HeapRegionRemSet* hrrs = rem_set();
   hrrs->clear();
   CardTableModRefBS* ct_bs =
@@ -436,7 +427,7 @@
     assert(end() == _orig_end, "sanity");
   }
 
-  assert(capacity() == (size_t) HeapRegion::GrainBytes, "pre-condition");
+  assert(capacity() == HeapRegion::GrainBytes, "pre-condition");
   _humongous_type = NotHumongous;
   _humongous_start_region = NULL;
 }
@@ -731,7 +722,7 @@
     st->print(" F");
   else
     st->print("  ");
-  st->print(" %5d", _gc_time_stamp);
+  st->print(" TS %5d", _gc_time_stamp);
   st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT,
             prev_top_at_mark_start(), next_top_at_mark_start());
   G1OffsetTableContigSpace::print_on(st);
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp
index 2a30331..7071ad4 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp
@@ -346,16 +346,12 @@
              G1BlockOffsetSharedArray* sharedOffsetArray,
              MemRegion mr, bool is_zeroed);
 
-  static int LogOfHRGrainBytes;
-  static int LogOfHRGrainWords;
-  // The normal type of these should be size_t. However, they used to
-  // be members of an enum before and they are assumed by the
-  // compilers to be ints. To avoid going and fixing all their uses,
-  // I'm declaring them as ints. I'm not anticipating heap region
-  // sizes to reach anywhere near 2g, so using an int here is safe.
-  static int GrainBytes;
-  static int GrainWords;
-  static int CardsPerRegion;
+  static int    LogOfHRGrainBytes;
+  static int    LogOfHRGrainWords;
+
+  static size_t GrainBytes;
+  static size_t GrainWords;
+  static size_t CardsPerRegion;
 
   static size_t align_up_to_region_byte_size(size_t sz) {
     return (sz + (size_t) GrainBytes - 1) &
@@ -435,6 +431,14 @@
     return _humongous_start_region;
   }
 
+  // Same as Space::is_in_reserved, but will use the original size of the region.
+  // The original size is different only for start humongous regions. They get
+  // their _end set up to be the end of the last continues region of the
+  // corresponding humongous object.
+  bool is_in_reserved_raw(const void* p) const {
+    return _bottom <= p && p < _orig_end;
+  }
+
   // Makes the current region be a "starts humongous" region, i.e.,
   // the first region in a series of one or more contiguous regions
   // that will contain a single "humongous" object. The two parameters
@@ -573,11 +577,6 @@
   // allocated in the current region before the last call to "save_mark".
   void oop_before_save_marks_iterate(OopClosure* cl);
 
-  DirtyCardToOopClosure*
-  new_dcto_closure(OopClosure* cl,
-                   CardTableModRefBS::PrecisionStyle precision,
-                   HeapRegionDCTOC::FilterKind fk);
-
   // Note the start or end of marking. This tells the heap region
   // that the collector is about to start or has finished (concurrently)
   // marking the heap.
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
index 8c5f15e..47c4155 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
@@ -143,12 +143,16 @@
     // If the test below fails, then this table was reused concurrently
     // with this operation.  This is OK, since the old table was coarsened,
     // and adding a bit to the new table is never incorrect.
-    if (loc_hr->is_in_reserved(from)) {
+    // If the table used to belong to a continues humongous region and is
+    // now reused for the corresponding start humongous region, we need to
+    // make sure that we detect this. Thus, we call is_in_reserved_raw()
+    // instead of just is_in_reserved() here.
+    if (loc_hr->is_in_reserved_raw(from)) {
       size_t hw_offset = pointer_delta((HeapWord*)from, loc_hr->bottom());
       CardIdx_t from_card = (CardIdx_t)
           hw_offset >> (CardTableModRefBS::card_shift - LogHeapWordSize);
 
-      assert(0 <= from_card && from_card < HeapRegion::CardsPerRegion,
+      assert(0 <= from_card && (size_t)from_card < HeapRegion::CardsPerRegion,
              "Must be in range.");
       add_card_work(from_card, par);
     }
@@ -639,7 +643,7 @@
         uintptr_t(from_hr->bottom())
           >> CardTableModRefBS::card_shift;
       CardIdx_t card_index = from_card - from_hr_bot_card_index;
-      assert(0 <= card_index && card_index < HeapRegion::CardsPerRegion,
+      assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion,
              "Must be in range.");
       if (G1HRRSUseSparseTable &&
           _sparse_table.add_card(from_hrs_ind, card_index)) {
@@ -1066,7 +1070,7 @@
       uintptr_t(hr->bottom()) >> CardTableModRefBS::card_shift;
     assert(from_card >= hr_bot_card_index, "Inv");
     CardIdx_t card_index = from_card - hr_bot_card_index;
-    assert(0 <= card_index && card_index < HeapRegion::CardsPerRegion,
+    assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion,
            "Must be in range.");
     return _sparse_table.contains_card(hr_ind, card_index);
   }
@@ -1191,7 +1195,7 @@
   _is = Sparse;
   // Set these values so that we increment to the first region.
   _coarse_cur_region_index = -1;
-  _coarse_cur_region_cur_card = (HeapRegion::CardsPerRegion-1);;
+  _coarse_cur_region_cur_card = (HeapRegion::CardsPerRegion-1);
 
   _cur_region_cur_card = 0;
 
@@ -1270,7 +1274,7 @@
 bool HeapRegionRemSetIterator::fine_has_next() {
   return
     _fine_cur_prt != NULL &&
-    _cur_region_cur_card < (size_t) HeapRegion::CardsPerRegion;
+    _cur_region_cur_card < HeapRegion::CardsPerRegion;
 }
 
 bool HeapRegionRemSetIterator::has_next(size_t& card_index) {
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp
index 09adcfa..4534350 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp
@@ -395,8 +395,8 @@
   // Coarse table iteration fields:
 
   // Current region index;
-  int _coarse_cur_region_index;
-  int _coarse_cur_region_cur_card;
+  int    _coarse_cur_region_index;
+  size_t _coarse_cur_region_cur_card;
 
   bool coarse_has_next(size_t& card_index);
 
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp
index 5f35e2f..e21cdd74 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp
@@ -26,6 +26,7 @@
 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
 
 size_t HeapRegionSetBase::_unrealistically_long_length = 0;
+HRSPhase HeapRegionSetBase::_phase = HRSPhaseNone;
 
 //////////////////// HeapRegionSetBase ////////////////////
 
@@ -192,6 +193,17 @@
   _verify_in_progress = false;
 }
 
+void HeapRegionSetBase::clear_phase() {
+  assert(_phase != HRSPhaseNone, "pre-condition");
+  _phase = HRSPhaseNone;
+}
+
+void HeapRegionSetBase::set_phase(HRSPhase phase) {
+  assert(_phase == HRSPhaseNone, "pre-condition");
+  assert(phase != HRSPhaseNone, "pre-condition");
+  _phase = phase;
+}
+
 void HeapRegionSetBase::print_on(outputStream* out, bool print_contents) {
   out->cr();
   out->print_cr("Set: %s ("PTR_FORMAT")", name(), this);
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.hpp
index 03fb764..9e862b4 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.hpp
@@ -47,8 +47,18 @@
 
 class hrs_ext_msg;
 
+typedef enum {
+  HRSPhaseNone,
+  HRSPhaseEvacuation,
+  HRSPhaseCleanup,
+  HRSPhaseFullGC
+} HRSPhase;
+
+class HRSPhaseSetter;
+
 class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC {
   friend class hrs_ext_msg;
+  friend class HRSPhaseSetter;
 
 protected:
   static size_t calculate_region_num(HeapRegion* hr);
@@ -80,6 +90,15 @@
   size_t      _calc_total_capacity_bytes;
   size_t      _calc_total_used_bytes;
 
+  // This is here so that it can be used in the subclasses to assert
+  // something different depending on which phase the GC is in. This
+  // can be particularly helpful in the check_mt_safety() methods.
+  static HRSPhase _phase;
+
+  // Only used by HRSPhaseSetter.
+  static void clear_phase();
+  static void set_phase(HRSPhase phase);
+
   // verify_region() is used to ensure that the contents of a region
   // added to / removed from a set are consistent. Different sets
   // make different assumptions about the regions added to them. So
@@ -177,6 +196,16 @@
   }
 };
 
+class HRSPhaseSetter {
+public:
+  HRSPhaseSetter(HRSPhase phase) {
+    HeapRegionSetBase::set_phase(phase);
+  }
+  ~HRSPhaseSetter() {
+    HeapRegionSetBase::clear_phase();
+  }
+};
+
 // These two macros are provided for convenience, to keep the uses of
 // these two asserts a bit more concise.
 
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.cpp
index 19b213a..d2a9665 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.cpp
@@ -26,6 +26,17 @@
 #include "gc_implementation/g1/heapRegionRemSet.hpp"
 #include "gc_implementation/g1/heapRegionSets.hpp"
 
+// Note on the check_mt_safety() methods below:
+//
+// Verification of the "master" heap region sets / lists that are
+// maintained by G1CollectedHeap is always done during a STW pause and
+// by the VM thread at the start / end of the pause. The standard
+// verification methods all assert check_mt_safety(). This is
+// important as it ensures that verification is done without
+// concurrent updates taking place at the same time. It follows, that,
+// for the "master" heap region sets / lists, the check_mt_safety()
+// method should include the VM thread / STW case.
+
 //////////////////// FreeRegionList ////////////////////
 
 const char* FreeRegionList::verify_region_extra(HeapRegion* hr) {
@@ -33,7 +44,7 @@
     return "the region should not be young";
   }
   // The superclass will check that the region is empty and
-  // not-humongous.
+  // not humongous.
   return HeapRegionLinkedList::verify_region_extra(hr);
 }
 
@@ -58,12 +69,16 @@
   // (b) If we're not at a safepoint, operations on the master free
   // list should be invoked while holding the Heap_lock.
 
-  guarantee((SafepointSynchronize::is_at_safepoint() &&
-               (Thread::current()->is_VM_thread() ||
-                                            FreeList_lock->owned_by_self())) ||
-            (!SafepointSynchronize::is_at_safepoint() &&
-                                                Heap_lock->owned_by_self()),
-            hrs_ext_msg(this, "master free list MT safety protocol"));
+  if (SafepointSynchronize::is_at_safepoint()) {
+    guarantee(Thread::current()->is_VM_thread() ||
+              FreeList_lock->owned_by_self(),
+              hrs_ext_msg(this, "master free list MT safety protocol "
+                                "at a safepoint"));
+  } else {
+    guarantee(Heap_lock->owned_by_self(),
+              hrs_ext_msg(this, "master free list MT safety protocol "
+                                "outside a safepoint"));
+  }
 
   return FreeRegionList::check_mt_safety();
 }
@@ -81,6 +96,48 @@
   return FreeRegionList::check_mt_safety();
 }
 
+//////////////////// OldRegionSet ////////////////////
+
+const char* OldRegionSet::verify_region_extra(HeapRegion* hr) {
+  if (hr->is_young()) {
+    return "the region should not be young";
+  }
+  // The superclass will check that the region is not empty and not
+  // humongous.
+  return HeapRegionSet::verify_region_extra(hr);
+}
+
+//////////////////// MasterOldRegionSet ////////////////////
+
+bool MasterOldRegionSet::check_mt_safety() {
+  // Master Old Set MT safety protocol:
+  // (a) If we're at a safepoint, operations on the master old set
+  // should be invoked:
+  // - by the VM thread (which will serialize them), or
+  // - by the GC workers while holding the FreeList_lock, if we're
+  //   at a safepoint for an evacuation pause (this lock is taken
+  //   anyway when an GC alloc region is retired so that a new one
+  //   is allocated from the free list), or
+  // - by the GC workers while holding the OldSets_lock, if we're at a
+  //   safepoint for a cleanup pause.
+  // (b) If we're not at a safepoint, operations on the master old set
+  // should be invoked while holding the Heap_lock.
+
+  if (SafepointSynchronize::is_at_safepoint()) {
+    guarantee(Thread::current()->is_VM_thread() ||
+              _phase == HRSPhaseEvacuation && FreeList_lock->owned_by_self() ||
+              _phase == HRSPhaseCleanup && OldSets_lock->owned_by_self(),
+              hrs_ext_msg(this, "master old set MT safety protocol "
+                                "at a safepoint"));
+  } else {
+    guarantee(Heap_lock->owned_by_self(),
+              hrs_ext_msg(this, "master old set MT safety protocol "
+                                "outside a safepoint"));
+  }
+
+  return OldRegionSet::check_mt_safety();
+}
+
 //////////////////// HumongousRegionSet ////////////////////
 
 const char* HumongousRegionSet::verify_region_extra(HeapRegion* hr) {
@@ -103,11 +160,16 @@
   // (b) If we're not at a safepoint, operations on the master
   // humongous set should be invoked while holding the Heap_lock.
 
-  guarantee((SafepointSynchronize::is_at_safepoint() &&
-               (Thread::current()->is_VM_thread() ||
-                                             OldSets_lock->owned_by_self())) ||
-            (!SafepointSynchronize::is_at_safepoint() &&
-                                                 Heap_lock->owned_by_self()),
-            hrs_ext_msg(this, "master humongous set MT safety protocol"));
+  if (SafepointSynchronize::is_at_safepoint()) {
+    guarantee(Thread::current()->is_VM_thread() ||
+              OldSets_lock->owned_by_self(),
+              hrs_ext_msg(this, "master humongous set MT safety protocol "
+                                "at a safepoint"));
+  } else {
+    guarantee(Heap_lock->owned_by_self(),
+              hrs_ext_msg(this, "master humongous set MT safety protocol "
+                                "outside a safepoint"));
+  }
+
   return HumongousRegionSet::check_mt_safety();
 }
diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.hpp
index 82636a5..6642326 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.hpp
@@ -61,6 +61,30 @@
   SecondaryFreeRegionList(const char* name) : FreeRegionList(name) { }
 };
 
+//////////////////// OldRegionSet ////////////////////
+
+class OldRegionSet : public HeapRegionSet {
+protected:
+  virtual const char* verify_region_extra(HeapRegion* hr);
+
+  virtual bool regions_humongous() { return false; }
+  virtual bool regions_empty()     { return false; }
+
+public:
+  OldRegionSet(const char* name) : HeapRegionSet(name) { }
+};
+
+//////////////////// MasterOldRegionSet ////////////////////
+
+class MasterOldRegionSet : public OldRegionSet {
+private:
+protected:
+  virtual bool check_mt_safety();
+
+public:
+  MasterOldRegionSet(const char* name) : OldRegionSet(name) { }
+};
+
 //////////////////// HumongousRegionSet ////////////////////
 
 class HumongousRegionSet : public HeapRegionSet {
diff --git a/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp b/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp
index 4186b42..7bf8fec 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 PtrQueue::PtrQueue(PtrQueueSet* qset, bool perm, bool active) :
   _qset(qset), _buf(NULL), _index(0), _active(active),
diff --git a/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp b/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp
index 1243a58..63c0e94 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp
@@ -31,7 +31,7 @@
 
 #define VM_STRUCTS_G1(nonstatic_field, static_field)                          \
                                                                               \
-  static_field(HeapRegion, GrainBytes, int)                                   \
+  static_field(HeapRegion, GrainBytes, size_t)                                \
                                                                               \
   nonstatic_field(HeapRegionSeq,   _regions, HeapRegion**)                    \
   nonstatic_field(HeapRegionSeq,   _length,  size_t)                          \
diff --git a/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp b/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp
index 04d051b..befacd6 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
 #include "gc_implementation/g1/vm_operations_g1.hpp"
@@ -165,6 +166,20 @@
   }
 }
 
+void VM_CGC_Operation::acquire_pending_list_lock() {
+  // The caller may block while communicating
+  // with the SLT thread in order to acquire/release the PLL.
+  ConcurrentMarkThread::slt()->
+    manipulatePLL(SurrogateLockerThread::acquirePLL);
+}
+
+void VM_CGC_Operation::release_and_notify_pending_list_lock() {
+  // The caller may block while communicating
+  // with the SLT thread in order to acquire/release the PLL.
+  ConcurrentMarkThread::slt()->
+    manipulatePLL(SurrogateLockerThread::releaseAndNotifyPLL);
+}
+
 void VM_CGC_Operation::doit() {
   gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
   TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
@@ -180,12 +195,19 @@
 }
 
 bool VM_CGC_Operation::doit_prologue() {
+  // Note the relative order of the locks must match that in
+  // VM_GC_Operation::doit_prologue() or deadlocks can occur
+  acquire_pending_list_lock();
+
   Heap_lock->lock();
   SharedHeap::heap()->_thread_holds_heap_lock_for_gc = true;
   return true;
 }
 
 void VM_CGC_Operation::doit_epilogue() {
+  // Note the relative order of the unlocks must match that in
+  // VM_GC_Operation::doit_epilogue()
   SharedHeap::heap()->_thread_holds_heap_lock_for_gc = false;
   Heap_lock->unlock();
+  release_and_notify_pending_list_lock();
 }
diff --git a/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp b/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp
index 825818d..c8bbe06 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp
@@ -93,11 +93,17 @@
   }
 };
 
-// Concurrent GC stop-the-world operations such as initial and final mark;
+// Concurrent GC stop-the-world operations such as remark and cleanup;
 // consider sharing these with CMS's counterparts.
 class VM_CGC_Operation: public VM_Operation {
   VoidClosure* _cl;
   const char* _printGCMessage;
+
+protected:
+  // java.lang.ref.Reference support
+  void acquire_pending_list_lock();
+  void release_and_notify_pending_list_lock();
+
 public:
   VM_CGC_Operation(VoidClosure* cl, const char *printGCMsg)
     : _cl(cl), _printGCMessage(printGCMsg) { }
diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp
index f43fffc..4496a69 100644
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp
@@ -38,6 +38,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 bool
 ParMarkBitMap::initialize(MemRegion covered_region)
diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp
index 42e65f1..04d2c72 100644
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp
@@ -863,8 +863,6 @@
   ensure_parsability(false);  // no need to retire TLABs for verification
 }
 
-void ParallelScavengeHeap::print() const { print_on(tty); }
-
 void ParallelScavengeHeap::print_on(outputStream* st) const {
   young_gen()->print_on(st);
   old_gen()->print_on(st);
diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp
index 3d1065f..f9ff996 100644
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp
@@ -246,8 +246,7 @@
   jlong millis_since_last_gc();
 
   void prepare_for_verify();
-  void print() const;
-  void print_on(outputStream* st) const;
+  virtual void print_on(outputStream* st) const;
   virtual void print_gc_threads_on(outputStream* st) const;
   virtual void gc_threads_do(ThreadClosure* tc) const;
   virtual void print_tracing_info() const;
diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp
index 3569ed7..fc05b2e 100644
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp
@@ -102,17 +102,15 @@
   _state = flushed;
 }
 
-bool PSPromotionLAB::unallocate_object(oop obj) {
+bool PSPromotionLAB::unallocate_object(HeapWord* obj, size_t obj_size) {
   assert(Universe::heap()->is_in(obj), "Object outside heap");
 
   if (contains(obj)) {
-    HeapWord* object_end = (HeapWord*)obj + obj->size();
-    assert(object_end <= top(), "Object crosses promotion LAB boundary");
+    HeapWord* object_end = obj + obj_size;
+    assert(object_end == top(), "Not matching last allocation");
 
-    if (object_end == top()) {
-      set_top((HeapWord*)obj);
-      return true;
-    }
+    set_top(obj);
+    return true;
   }
 
   return false;
diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.hpp
index bed0c0c..fd6a7bf 100644
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.hpp
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.hpp
@@ -73,7 +73,7 @@
 
   bool is_flushed()                  { return _state == flushed; }
 
-  bool unallocate_object(oop obj);
+  bool unallocate_object(HeapWord* obj, size_t obj_size);
 
   // Returns a subregion containing all objects in this space.
   MemRegion used_region()            { return MemRegion(bottom(), top()); }
diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp
index ad58a90..255bb8e 100644
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp
@@ -380,10 +380,10 @@
       // deallocate it, so we have to test.  If the deallocation fails,
       // overwrite with a filler object.
       if (new_obj_is_tenured) {
-        if (!_old_lab.unallocate_object(new_obj)) {
+        if (!_old_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
           CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
         }
-      } else if (!_young_lab.unallocate_object(new_obj)) {
+      } else if (!_young_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
         CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
       }
 
diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
index 8eba893..e194767 100644
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 // PSVirtualSpace
 
diff --git a/hotspot/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp b/hotspot/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp
index a231e5d..0dea420 100644
--- a/hotspot/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp
+++ b/hotspot/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp
@@ -224,6 +224,8 @@
   MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag);
   assert(_buffer == empty, "Should be empty");
   assert(msg != empty, "empty message");
+  assert(!Heap_lock->owned_by_self(), "Heap_lock owned by requesting thread");
+
   _buffer = msg;
   while (_buffer != empty) {
     _monitor.notify();
diff --git a/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp b/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp
index aacaf35..e38556d 100644
--- a/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp
+++ b/hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment) {
diff --git a/hotspot/src/share/vm/gc_implementation/shared/vmGCOperations.cpp b/hotspot/src/share/vm/gc_implementation/shared/vmGCOperations.cpp
index 0828c9c..19ea6cd 100644
--- a/hotspot/src/share/vm/gc_implementation/shared/vmGCOperations.cpp
+++ b/hotspot/src/share/vm/gc_implementation/shared/vmGCOperations.cpp
@@ -40,20 +40,32 @@
 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
 #endif
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL1(hotspot, gc__begin, bool);
 HS_DTRACE_PROBE_DECL(hotspot, gc__end);
+#endif /* !USDT2 */
 
 // The same dtrace probe can't be inserted in two different files, so we
 // have to call it here, so it's only in one file.  Can't create new probes
 // for the other file anymore.   The dtrace probes have to remain stable.
 void VM_GC_Operation::notify_gc_begin(bool full) {
+#ifndef USDT2
   HS_DTRACE_PROBE1(hotspot, gc__begin, full);
   HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();
+#else /* USDT2 */
+  HOTSPOT_GC_BEGIN(
+                   full);
+#endif /* USDT2 */
 }
 
 void VM_GC_Operation::notify_gc_end() {
+#ifndef USDT2
   HS_DTRACE_PROBE(hotspot, gc__end);
   HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();
+#else /* USDT2 */
+  HOTSPOT_GC_END(
+);
+#endif /* USDT2 */
 }
 
 void VM_GC_Operation::acquire_pending_list_lock() {
diff --git a/hotspot/src/share/vm/gc_interface/collectedHeap.cpp b/hotspot/src/share/vm/gc_interface/collectedHeap.cpp
index d5b0454..3623e9b 100644
--- a/hotspot/src/share/vm/gc_interface/collectedHeap.cpp
+++ b/hotspot/src/share/vm/gc_interface/collectedHeap.cpp
@@ -28,6 +28,7 @@
 #include "gc_interface/collectedHeap.hpp"
 #include "gc_interface/collectedHeap.inline.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/instanceMirrorKlass.hpp"
 #include "runtime/init.hpp"
 #include "services/heapDumper.hpp"
 #ifdef TARGET_OS_FAMILY_linux
@@ -39,6 +40,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 #ifdef ASSERT
@@ -433,3 +437,37 @@
     inspector.doit();
   }
 }
+
+oop CollectedHeap::Class_obj_allocate(KlassHandle klass, int size, KlassHandle real_klass, TRAPS) {
+  debug_only(check_for_valid_allocation_state());
+  assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
+  assert(size >= 0, "int won't convert to size_t");
+  HeapWord* obj;
+  if (JavaObjectsInPerm) {
+    obj = common_permanent_mem_allocate_init(size, CHECK_NULL);
+  } else {
+    assert(ScavengeRootsInCode > 0, "must be");
+    obj = common_mem_allocate_init(size, CHECK_NULL);
+  }
+  post_allocation_setup_common(klass, obj, size);
+  assert(Universe::is_bootstrapping() ||
+         !((oop)obj)->blueprint()->oop_is_array(), "must not be an array");
+  NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
+  oop mirror = (oop)obj;
+
+  java_lang_Class::set_oop_size(mirror, size);
+
+  // Setup indirections
+  if (!real_klass.is_null()) {
+    java_lang_Class::set_klass(mirror, real_klass());
+    real_klass->set_java_mirror(mirror);
+  }
+
+  instanceMirrorKlass* mk = instanceMirrorKlass::cast(mirror->klass());
+  assert(size == mk->instance_size(real_klass), "should have been set");
+
+  // notify jvmti and dtrace
+  post_allocation_notify(klass, (oop)obj);
+
+  return mirror;
+}
diff --git a/hotspot/src/share/vm/gc_interface/collectedHeap.hpp b/hotspot/src/share/vm/gc_interface/collectedHeap.hpp
index 36fcb40..726a30e 100644
--- a/hotspot/src/share/vm/gc_interface/collectedHeap.hpp
+++ b/hotspot/src/share/vm/gc_interface/collectedHeap.hpp
@@ -319,9 +319,13 @@
   // VM (then terminate).
   virtual void preload_and_dump(TRAPS) { ShouldNotReachHere(); }
 
+  // Allocate and initialize instances of Class
+  static oop Class_obj_allocate(KlassHandle klass, int size, KlassHandle real_klass, TRAPS);
+
   // General obj/array allocation facilities.
   inline static oop obj_allocate(KlassHandle klass, int size, TRAPS);
   inline static oop array_allocate(KlassHandle klass, int size, int length, TRAPS);
+  inline static oop array_allocate_nozero(KlassHandle klass, int size, int length, TRAPS);
 
   // Special obj/array allocation facilities.
   // Some heaps may want to manage "permanent" data uniquely. These default
@@ -586,13 +590,27 @@
   void pre_full_gc_dump();
   void post_full_gc_dump();
 
-  virtual void print() const = 0;
+  // Print heap information on the given outputStream.
   virtual void print_on(outputStream* st) const = 0;
+  // The default behavior is to call print_on() on tty.
+  virtual void print() const {
+    print_on(tty);
+  }
+  // Print more detailed heap information on the given
+  // outputStream. The default behaviour is to call print_on(). It is
+  // up to each subclass to override it and add any additional output
+  // it needs.
+  virtual void print_extended_on(outputStream* st) const {
+    print_on(st);
+  }
 
   // Print all GC threads (other than the VM thread)
   // used by this heap.
   virtual void print_gc_threads_on(outputStream* st) const = 0;
-  void print_gc_threads() { print_gc_threads_on(tty); }
+  // The default behavior is to call print_gc_threads_on() on tty.
+  void print_gc_threads() {
+    print_gc_threads_on(tty);
+  }
   // Iterator for all GC threads (other than VM thread)
   virtual void gc_threads_do(ThreadClosure* tc) const = 0;
 
diff --git a/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp b/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
index cf9946d..adced06 100644
--- a/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
+++ b/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
@@ -43,6 +43,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // Inline allocation implementations.
 
@@ -271,6 +274,23 @@
   return (oop)obj;
 }
 
+oop CollectedHeap::array_allocate_nozero(KlassHandle klass,
+                                         int size,
+                                         int length,
+                                         TRAPS) {
+  debug_only(check_for_valid_allocation_state());
+  assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
+  assert(size >= 0, "int won't convert to size_t");
+  HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL);
+  ((oop)obj)->set_klass_gap(0);
+  post_allocation_setup_array(klass, obj, size, length);
+#ifndef PRODUCT
+  const size_t hs = oopDesc::header_size()+1;
+  Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs);
+#endif
+  return (oop)obj;
+}
+
 oop CollectedHeap::permanent_obj_allocate(KlassHandle klass, int size, TRAPS) {
   oop obj = permanent_obj_allocate_no_klass_install(klass, size, CHECK_NULL);
   post_allocation_install_obj_klass(klass, obj, size);
diff --git a/hotspot/src/share/vm/gc_interface/gcCause.cpp b/hotspot/src/share/vm/gc_interface/gcCause.cpp
index 358b6b1..c4abd12 100644
--- a/hotspot/src/share/vm/gc_interface/gcCause.cpp
+++ b/hotspot/src/share/vm/gc_interface/gcCause.cpp
@@ -42,12 +42,6 @@
     case _jvmti_force_gc:
       return "JvmtiEnv ForceGarbageCollection";
 
-    case _no_gc:
-      return "No GC";
-
-    case _allocation_failure:
-      return "Allocation Failure";
-
     case _gc_locker:
       return "GCLocker Initiated GC";
 
@@ -57,6 +51,12 @@
     case _heap_dump:
       return "Heap Dump Initiated GC";
 
+    case _no_gc:
+      return "No GC";
+
+    case _allocation_failure:
+      return "Allocation Failure";
+
     case _tenured_generation_full:
       return "Tenured Generation Full";
 
@@ -78,6 +78,9 @@
     case _old_generation_too_full_to_scavenge:
       return "Old Generation Too Full To Scavenge";
 
+    case _adaptive_size_policy:
+      return "Ergonomics";
+
     case _g1_inc_collection_pause:
       return "G1 Evacuation Pause";
 
diff --git a/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp b/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
index a792812..a68fac1 100644
--- a/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
+++ b/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
@@ -56,6 +56,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // This file contains the platform-independent parts
 // of the abstract interpreter and the abstract interpreter generator.
diff --git a/hotspot/src/share/vm/interpreter/bytecode.hpp b/hotspot/src/share/vm/interpreter/bytecode.hpp
index 7fb50df..107161a 100644
--- a/hotspot/src/share/vm/interpreter/bytecode.hpp
+++ b/hotspot/src/share/vm/interpreter/bytecode.hpp
@@ -234,6 +234,13 @@
                                                           is_invokespecial()   ||
                                                           is_invokedynamic(); }
 
+  bool is_method_handle_invoke() const {
+    return (is_invokedynamic() ||
+            (is_invokevirtual() &&
+             method()->constants()->klass_ref_at_noresolve(index()) == vmSymbols::java_lang_invoke_MethodHandle() &&
+             methodOopDesc::is_method_handle_invoke_name(name())));
+  }
+
   // Helper to skip verification.   Used is_valid() to check if the result is really an invoke
   inline friend Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci);
 };
diff --git a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
index 7da054d..68bd1c7 100644
--- a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
+++ b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
@@ -65,6 +65,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "orderAccess_linux_ppc.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "orderAccess_bsd_x86.inline.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "orderAccess_bsd_zero.inline.hpp"
+#endif
 
 
 // no precompiled headers
diff --git a/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp b/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp
index 292e19c..e510358 100644
--- a/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp
+++ b/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp
@@ -92,7 +92,7 @@
       // the incoming method.  We could lose a line of trace output.
       // This is acceptable in a debug-only feature.
       st->cr();
-      st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
+      st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
       method->print_name(st);
       st->cr();
       _current_method = method();
@@ -106,7 +106,7 @@
     }
     _code = code;
      int bci = bcp - method->code_base();
-    st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
+    st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
     if (Verbose) {
       st->print("%8d  %4d  " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
            BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
@@ -241,7 +241,7 @@
         st->print_cr(" not secondary entry?", i);
         return false;
       }
-      i = cache->entry_at(i)->main_entry_index();
+      i = cache->entry_at(i)->main_entry_index() + constantPoolOopDesc::CPCACHE_INDEX_TAG;
       goto check_cache_index;
     } else {
       st->print_cr(" not in cache[*]?", i);
diff --git a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp
index 7b7b49d..c3eb879 100644
--- a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp
+++ b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp
@@ -549,8 +549,8 @@
 
   if (is_put && !is_static && klass->is_subclass_of(SystemDictionary::CallSite_klass()) && (info.name() == vmSymbols::target_name())) {
     const jint direction = frame::interpreter_frame_expression_stack_direction();
-    oop call_site     = *((oop*) thread->last_frame().interpreter_frame_tos_at(-1 * direction));
-    oop method_handle = *((oop*) thread->last_frame().interpreter_frame_tos_at( 0 * direction));
+    Handle call_site    (THREAD, *((oop*) thread->last_frame().interpreter_frame_tos_at(-1 * direction)));
+    Handle method_handle(THREAD, *((oop*) thread->last_frame().interpreter_frame_tos_at( 0 * direction)));
     assert(call_site    ->is_a(SystemDictionary::CallSite_klass()),     "must be");
     assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "must be");
 
diff --git a/hotspot/src/share/vm/interpreter/interpreterRuntime.hpp b/hotspot/src/share/vm/interpreter/interpreterRuntime.hpp
index d1d14b4..93c1a9e 100644
--- a/hotspot/src/share/vm/interpreter/interpreterRuntime.hpp
+++ b/hotspot/src/share/vm/interpreter/interpreterRuntime.hpp
@@ -41,6 +41,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // The InterpreterRuntime is called by the interpreter for everything
 // that cannot/should not be dealt with in assembly and needs C support.
diff --git a/hotspot/src/share/vm/interpreter/linkResolver.cpp b/hotspot/src/share/vm/interpreter/linkResolver.cpp
index 3d655af..b7defd7 100644
--- a/hotspot/src/share/vm/interpreter/linkResolver.cpp
+++ b/hotspot/src/share/vm/interpreter/linkResolver.cpp
@@ -52,6 +52,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 //------------------------------------------------------------------------------------------------------------------------
 // Implementation of FieldAccessInfo
diff --git a/hotspot/src/share/vm/libadt/vectset.cpp b/hotspot/src/share/vm/libadt/vectset.cpp
index 93cb48d..0042ca7 100644
--- a/hotspot/src/share/vm/libadt/vectset.cpp
+++ b/hotspot/src/share/vm/libadt/vectset.cpp
@@ -350,6 +350,21 @@
   return (int)_xor;
 }
 
+//------------------------------iterate----------------------------------------
+// Used by Set::print().
+class VSetI_ : public SetI_ {
+  VectorSetI vsi;
+public:
+  VSetI_( const VectorSet *vset, uint &elem ) : vsi(vset) { elem = vsi.elem; }
+
+  uint next(void) { ++vsi; return vsi.elem; }
+  int  test(void) { return vsi.test(); }
+};
+
+SetI_ *VectorSet::iterate(uint &elem) const {
+  return new(ResourceObj::C_HEAP) VSetI_(this, elem);
+}
+
 //=============================================================================
 //------------------------------next-------------------------------------------
 // Find and return the next element of a vector set, or return garbage and
diff --git a/hotspot/src/share/vm/libadt/vectset.hpp b/hotspot/src/share/vm/libadt/vectset.hpp
index c184773..552fdd1 100644
--- a/hotspot/src/share/vm/libadt/vectset.hpp
+++ b/hotspot/src/share/vm/libadt/vectset.hpp
@@ -151,7 +151,7 @@
 
 
 private:
-  SetI_ *iterate(uint&) const { ShouldNotCallThis(); return NULL; } // Removed
+  SetI_ *iterate(uint&) const;
 };
 
 //------------------------------Iteration--------------------------------------
diff --git a/hotspot/src/share/vm/memory/allocation.cpp b/hotspot/src/share/vm/memory/allocation.cpp
index 356e825..0479e73 100644
--- a/hotspot/src/share/vm/memory/allocation.cpp
+++ b/hotspot/src/share/vm/memory/allocation.cpp
@@ -39,6 +39,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 void* CHeapObj::operator new(size_t size){
   return (void *) AllocateHeap(size, "CHeapObj-new");
diff --git a/hotspot/src/share/vm/memory/collectorPolicy.cpp b/hotspot/src/share/vm/memory/collectorPolicy.cpp
index 7a1a294..8412682 100644
--- a/hotspot/src/share/vm/memory/collectorPolicy.cpp
+++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp
@@ -47,6 +47,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
 #include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp"
diff --git a/hotspot/src/share/vm/memory/defNewGeneration.cpp b/hotspot/src/share/vm/memory/defNewGeneration.cpp
index c1a7051..5913b2c 100644
--- a/hotspot/src/share/vm/memory/defNewGeneration.cpp
+++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp
@@ -48,6 +48,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 //
 // DefNewGeneration functions.
diff --git a/hotspot/src/share/vm/memory/gcLocker.hpp b/hotspot/src/share/vm/memory/gcLocker.hpp
index 09135cb..c9d913a 100644
--- a/hotspot/src/share/vm/memory/gcLocker.hpp
+++ b/hotspot/src/share/vm/memory/gcLocker.hpp
@@ -41,6 +41,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 // The direct lock/unlock calls do not force a collection if an unlock
 // decrements the count to zero. Avoid calling these if at all possible.
diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp
index d6a54e1..babb006 100644
--- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp
+++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp
@@ -1270,7 +1270,6 @@
   rem_set()->verify();
 }
 
-void GenCollectedHeap::print() const { print_on(tty); }
 void GenCollectedHeap::print_on(outputStream* st) const {
   for (int i = 0; i < _n_gens; i++) {
     _gens[i]->print_on(st);
diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.hpp b/hotspot/src/share/vm/memory/genCollectedHeap.hpp
index 9c15377..e7bea64 100644
--- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp
+++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp
@@ -360,8 +360,7 @@
   void verify(bool allow_dirty, bool silent, VerifyOption option);
 
   // Override.
-  void print() const;
-  void print_on(outputStream* st) const;
+  virtual void print_on(outputStream* st) const;
   virtual void print_gc_threads_on(outputStream* st) const;
   virtual void gc_threads_do(ThreadClosure* tc) const;
   virtual void print_tracing_info() const;
diff --git a/hotspot/src/share/vm/memory/genMarkSweep.cpp b/hotspot/src/share/vm/memory/genMarkSweep.cpp
index 802c646..94a73dd 100644
--- a/hotspot/src/share/vm/memory/genMarkSweep.cpp
+++ b/hotspot/src/share/vm/memory/genMarkSweep.cpp
@@ -55,6 +55,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp,
   bool clear_all_softrefs) {
diff --git a/hotspot/src/share/vm/memory/oopFactory.cpp b/hotspot/src/share/vm/memory/oopFactory.cpp
index 08f9825..c6e644c 100644
--- a/hotspot/src/share/vm/memory/oopFactory.cpp
+++ b/hotspot/src/share/vm/memory/oopFactory.cpp
@@ -77,7 +77,14 @@
 typeArrayOop oopFactory::new_typeArray(BasicType type, int length, TRAPS) {
   klassOop type_asKlassOop = Universe::typeArrayKlassObj(type);
   typeArrayKlass* type_asArrayKlass = typeArrayKlass::cast(type_asKlassOop);
-  typeArrayOop result = type_asArrayKlass->allocate(length, THREAD);
+  typeArrayOop result = type_asArrayKlass->allocate_common(length, true, THREAD);
+  return result;
+}
+
+typeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS) {
+  klassOop type_asKlassOop = Universe::typeArrayKlassObj(type);
+  typeArrayKlass* type_asArrayKlass = typeArrayKlass::cast(type_asKlassOop);
+  typeArrayOop result = type_asArrayKlass->allocate_common(length, false, THREAD);
   return result;
 }
 
diff --git a/hotspot/src/share/vm/memory/oopFactory.hpp b/hotspot/src/share/vm/memory/oopFactory.hpp
index 32e50fb..dbb42f0 100644
--- a/hotspot/src/share/vm/memory/oopFactory.hpp
+++ b/hotspot/src/share/vm/memory/oopFactory.hpp
@@ -63,6 +63,7 @@
   static typeArrayOop    new_permanent_intArray  (int length, TRAPS);  // used for class file structures
 
   static typeArrayOop    new_typeArray(BasicType type, int length, TRAPS);
+  static typeArrayOop    new_typeArray_nozero(BasicType type, int length, TRAPS);
 
   // Constant pools
   static constantPoolOop      new_constantPool     (int length,
diff --git a/hotspot/src/share/vm/memory/referencePolicy.cpp b/hotspot/src/share/vm/memory/referencePolicy.cpp
index 2af4368..a667332 100644
--- a/hotspot/src/share/vm/memory/referencePolicy.cpp
+++ b/hotspot/src/share/vm/memory/referencePolicy.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,8 +41,9 @@
 
 // The oop passed in is the SoftReference object, and not
 // the object the SoftReference points to.
-bool LRUCurrentHeapPolicy::should_clear_reference(oop p) {
-  jlong interval = java_lang_ref_SoftReference::clock() - java_lang_ref_SoftReference::timestamp(p);
+bool LRUCurrentHeapPolicy::should_clear_reference(oop p,
+                                                  jlong timestamp_clock) {
+  jlong interval = timestamp_clock - java_lang_ref_SoftReference::timestamp(p);
   assert(interval >= 0, "Sanity check");
 
   // The interval will be zero if the ref was accessed since the last scavenge/gc.
@@ -71,8 +72,9 @@
 
 // The oop passed in is the SoftReference object, and not
 // the object the SoftReference points to.
-bool LRUMaxHeapPolicy::should_clear_reference(oop p) {
-  jlong interval = java_lang_ref_SoftReference::clock() - java_lang_ref_SoftReference::timestamp(p);
+bool LRUMaxHeapPolicy::should_clear_reference(oop p,
+                                             jlong timestamp_clock) {
+  jlong interval = timestamp_clock - java_lang_ref_SoftReference::timestamp(p);
   assert(interval >= 0, "Sanity check");
 
   // The interval will be zero if the ref was accessed since the last scavenge/gc.
diff --git a/hotspot/src/share/vm/memory/referencePolicy.hpp b/hotspot/src/share/vm/memory/referencePolicy.hpp
index 9672ed9..6616f25 100644
--- a/hotspot/src/share/vm/memory/referencePolicy.hpp
+++ b/hotspot/src/share/vm/memory/referencePolicy.hpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,19 +31,27 @@
 
 class ReferencePolicy : public CHeapObj {
  public:
-  virtual bool should_clear_reference(oop p)       { ShouldNotReachHere(); return true; }
+  virtual bool should_clear_reference(oop p, jlong timestamp_clock) {
+    ShouldNotReachHere();
+    return true;
+  }
+
   // Capture state (of-the-VM) information needed to evaluate the policy
   virtual void setup() { /* do nothing */ }
 };
 
 class NeverClearPolicy : public ReferencePolicy {
  public:
-  bool should_clear_reference(oop p) { return false; }
+  virtual bool should_clear_reference(oop p, jlong timestamp_clock) {
+    return false;
+  }
 };
 
 class AlwaysClearPolicy : public ReferencePolicy {
  public:
-  bool should_clear_reference(oop p) { return true; }
+  virtual bool should_clear_reference(oop p, jlong timestamp_clock) {
+    return true;
+  }
 };
 
 class LRUCurrentHeapPolicy : public ReferencePolicy {
@@ -55,7 +63,7 @@
 
   // Capture state (of-the-VM) information needed to evaluate the policy
   void setup();
-  bool should_clear_reference(oop p);
+  virtual bool should_clear_reference(oop p, jlong timestamp_clock);
 };
 
 class LRUMaxHeapPolicy : public ReferencePolicy {
@@ -67,7 +75,7 @@
 
   // Capture state (of-the-VM) information needed to evaluate the policy
   void setup();
-  bool should_clear_reference(oop p);
+  virtual bool should_clear_reference(oop p, jlong timestamp_clock);
 };
 
 #endif // SHARE_VM_MEMORY_REFERENCEPOLICY_HPP
diff --git a/hotspot/src/share/vm/memory/referenceProcessor.cpp b/hotspot/src/share/vm/memory/referenceProcessor.cpp
index 27a1ff4..e0dabaf 100644
--- a/hotspot/src/share/vm/memory/referenceProcessor.cpp
+++ b/hotspot/src/share/vm/memory/referenceProcessor.cpp
@@ -36,14 +36,19 @@
 ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
 ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy      = NULL;
 bool             ReferenceProcessor::_pending_list_uses_discovered_field = false;
+jlong            ReferenceProcessor::_soft_ref_timestamp_clock = 0;
 
 void referenceProcessor_init() {
   ReferenceProcessor::init_statics();
 }
 
 void ReferenceProcessor::init_statics() {
-  // Initialize the master soft ref clock.
-  java_lang_ref_SoftReference::set_clock(os::javaTimeMillis());
+  jlong now = os::javaTimeMillis();
+
+  // Initialize the soft ref timestamp clock.
+  _soft_ref_timestamp_clock = now;
+  // Also update the soft ref clock in j.l.r.SoftReference
+  java_lang_ref_SoftReference::set_clock(_soft_ref_timestamp_clock);
 
   _always_clear_soft_ref_policy = new AlwaysClearPolicy();
   _default_soft_ref_policy      = new COMPILER2_PRESENT(LRUMaxHeapPolicy())
@@ -57,6 +62,28 @@
   _pending_list_uses_discovered_field = JDK_Version::current().pending_list_uses_discovered_field();
 }
 
+void ReferenceProcessor::enable_discovery(bool verify_disabled, bool check_no_refs) {
+#ifdef ASSERT
+  // Verify that we're not currently discovering refs
+  assert(!verify_disabled || !_discovering_refs, "nested call?");
+
+  if (check_no_refs) {
+    // Verify that the discovered lists are empty
+    verify_no_references_recorded();
+  }
+#endif // ASSERT
+
+  // Someone could have modified the value of the static
+  // field in the j.l.r.SoftReference class that holds the
+  // soft reference timestamp clock using reflection or
+  // Unsafe between GCs. Unconditionally update the static
+  // field in ReferenceProcessor here so that we use the new
+  // value during reference discovery.
+
+  _soft_ref_timestamp_clock = java_lang_ref_SoftReference::clock();
+  _discovering_refs = true;
+}
+
 ReferenceProcessor::ReferenceProcessor(MemRegion span,
                                        bool      mt_processing,
                                        int       mt_processing_degree,
@@ -78,19 +105,22 @@
   _discovery_is_mt     = mt_discovery;
   _num_q               = MAX2(1, mt_processing_degree);
   _max_num_q           = MAX2(_num_q, mt_discovery_degree);
-  _discoveredSoftRefs  = NEW_C_HEAP_ARRAY(DiscoveredList,
+  _discovered_refs     = NEW_C_HEAP_ARRAY(DiscoveredList,
                                           _max_num_q * number_of_subclasses_of_ref());
-  if (_discoveredSoftRefs == NULL) {
+  if (_discovered_refs == NULL) {
     vm_exit_during_initialization("Could not allocated RefProc Array");
   }
+  _discoveredSoftRefs    = &_discovered_refs[0];
   _discoveredWeakRefs    = &_discoveredSoftRefs[_max_num_q];
   _discoveredFinalRefs   = &_discoveredWeakRefs[_max_num_q];
   _discoveredPhantomRefs = &_discoveredFinalRefs[_max_num_q];
-  // Initialized all entries to NULL
+
+  // Initialize all entries to NULL
   for (int i = 0; i < _max_num_q * number_of_subclasses_of_ref(); i++) {
-    _discoveredSoftRefs[i].set_head(NULL);
-    _discoveredSoftRefs[i].set_length(0);
+    _discovered_refs[i].set_head(NULL);
+    _discovered_refs[i].set_length(0);
   }
+
   // If we do barriers, cache a copy of the barrier set.
   if (discovered_list_needs_barrier) {
     _bs = Universe::heap()->barrier_set();
@@ -102,7 +132,7 @@
 void ReferenceProcessor::verify_no_references_recorded() {
   guarantee(!_discovering_refs, "Discovering refs?");
   for (int i = 0; i < _max_num_q * number_of_subclasses_of_ref(); i++) {
-    guarantee(_discoveredSoftRefs[i].is_empty(),
+    guarantee(_discovered_refs[i].is_empty(),
               "Found non-empty discovered list");
   }
 }
@@ -111,9 +141,9 @@
 void ReferenceProcessor::weak_oops_do(OopClosure* f) {
   for (int i = 0; i < _max_num_q * number_of_subclasses_of_ref(); i++) {
     if (UseCompressedOops) {
-      f->do_oop((narrowOop*)_discoveredSoftRefs[i].adr_head());
+      f->do_oop((narrowOop*)_discovered_refs[i].adr_head());
     } else {
-      f->do_oop((oop*)_discoveredSoftRefs[i].adr_head());
+      f->do_oop((oop*)_discovered_refs[i].adr_head());
     }
   }
 }
@@ -122,17 +152,21 @@
   // Update (advance) the soft ref master clock field. This must be done
   // after processing the soft ref list.
   jlong now = os::javaTimeMillis();
-  jlong clock = java_lang_ref_SoftReference::clock();
+  jlong soft_ref_clock = java_lang_ref_SoftReference::clock();
+  assert(soft_ref_clock == _soft_ref_timestamp_clock, "soft ref clocks out of sync");
+
   NOT_PRODUCT(
-  if (now < clock) {
-    warning("time warp: %d to %d", clock, now);
+  if (now < _soft_ref_timestamp_clock) {
+    warning("time warp: "INT64_FORMAT" to "INT64_FORMAT,
+            _soft_ref_timestamp_clock, now);
   }
   )
   // In product mode, protect ourselves from system time being adjusted
   // externally and going backward; see note in the implementation of
   // GenCollectedHeap::time_since_last_gc() for the right way to fix
   // this uniformly throughout the VM; see bug-id 4741166. XXX
-  if (now > clock) {
+  if (now > _soft_ref_timestamp_clock) {
+    _soft_ref_timestamp_clock = now;
     java_lang_ref_SoftReference::set_clock(now);
   }
   // Else leave clock stalled at its old value until time progresses
@@ -150,6 +184,16 @@
   // Stop treating discovered references specially.
   disable_discovery();
 
+  // If discovery was concurrent, someone could have modified
+  // the value of the static field in the j.l.r.SoftReference
+  // class that holds the soft reference timestamp clock using
+  // reflection or Unsafe between when discovery was enabled and
+  // now. Unconditionally update the static field in ReferenceProcessor
+  // here so that we use the new value during processing of the
+  // discovered soft refs.
+
+  _soft_ref_timestamp_clock = java_lang_ref_SoftReference::clock();
+
   bool trace_time = PrintGCDetails && PrintReferenceGC;
   // Soft references
   {
@@ -382,15 +426,15 @@
   AbstractRefProcTaskExecutor* task_executor) {
   if (_processing_is_mt && task_executor != NULL) {
     // Parallel code
-    RefProcEnqueueTask tsk(*this, _discoveredSoftRefs,
+    RefProcEnqueueTask tsk(*this, _discovered_refs,
                            pending_list_addr, _max_num_q);
     task_executor->execute(tsk);
   } else {
     // Serial code: call the parent class's implementation
     for (int i = 0; i < _max_num_q * number_of_subclasses_of_ref(); i++) {
-      enqueue_discovered_reflist(_discoveredSoftRefs[i], pending_list_addr);
-      _discoveredSoftRefs[i].set_head(NULL);
-      _discoveredSoftRefs[i].set_length(0);
+      enqueue_discovered_reflist(_discovered_refs[i], pending_list_addr);
+      _discovered_refs[i].set_head(NULL);
+      _discovered_refs[i].set_length(0);
     }
   }
 }
@@ -486,7 +530,8 @@
   while (iter.has_next()) {
     iter.load_ptrs(DEBUG_ONLY(!discovery_is_atomic() /* allow_null_referent */));
     bool referent_is_dead = (iter.referent() != NULL) && !iter.is_referent_alive();
-    if (referent_is_dead && !policy->should_clear_reference(iter.obj())) {
+    if (referent_is_dead &&
+        !policy->should_clear_reference(iter.obj(), _soft_ref_timestamp_clock)) {
       if (TraceReferenceGC) {
         gclog_or_tty->print_cr("Dropping reference (" INTPTR_FORMAT ": %s"  ") by policy",
                                iter.obj(), iter.obj()->blueprint()->internal_name());
@@ -649,7 +694,7 @@
     if (TraceReferenceGC && PrintGCDetails && ((i % _max_num_q) == 0)) {
       gclog_or_tty->print_cr("\nAbandoning %s discovered list", list_name(i));
     }
-    abandon_partial_discovered_list(_discoveredSoftRefs[i]);
+    abandon_partial_discovered_list(_discovered_refs[i]);
   }
 }
 
@@ -910,7 +955,7 @@
         "\nScrubbing %s discovered list of Null referents",
         list_name(i));
     }
-    clean_up_discovered_reflist(_discoveredSoftRefs[i]);
+    clean_up_discovered_reflist(_discovered_refs[i]);
   }
 }
 
@@ -1117,7 +1162,7 @@
     // time-stamp policies advance the soft-ref clock only
     // at a major collection cycle, this is always currently
     // accurate.
-    if (!_current_soft_ref_policy->should_clear_reference(obj)) {
+    if (!_current_soft_ref_policy->should_clear_reference(obj, _soft_ref_timestamp_clock)) {
       return false;
     }
   }
@@ -1360,7 +1405,7 @@
 void ReferenceProcessor::clear_discovered_references() {
   guarantee(!_discovering_refs, "Discovering refs?");
   for (int i = 0; i < _max_num_q * number_of_subclasses_of_ref(); i++) {
-    clear_discovered_references(_discoveredSoftRefs[i]);
+    clear_discovered_references(_discovered_refs[i]);
   }
 }
 
diff --git a/hotspot/src/share/vm/memory/referenceProcessor.hpp b/hotspot/src/share/vm/memory/referenceProcessor.hpp
index 63ed31d..cbd8bfc 100644
--- a/hotspot/src/share/vm/memory/referenceProcessor.hpp
+++ b/hotspot/src/share/vm/memory/referenceProcessor.hpp
@@ -201,7 +201,6 @@
     assert(_ref != _first_seen, "cyclic ref_list found");
     NOT_PRODUCT(_processed++);
   }
-
 };
 
 class ReferenceProcessor : public CHeapObj {
@@ -209,6 +208,9 @@
   // Compatibility with pre-4965777 JDK's
   static bool _pending_list_uses_discovered_field;
 
+  // The SoftReference master timestamp clock
+  static jlong _soft_ref_timestamp_clock;
+
   MemRegion   _span;                    // (right-open) interval of heap
                                         // subject to wkref discovery
 
@@ -253,7 +255,11 @@
   int             _num_q;
   // The maximum MT'ness degree of the queues below
   int             _max_num_q;
-  // Arrays of lists of oops, one per thread
+
+  // Master array of discovered oops
+  DiscoveredList* _discovered_refs;
+
+  // Arrays of lists of oops, one per thread (pointers into master array above)
   DiscoveredList* _discoveredSoftRefs;
   DiscoveredList* _discoveredWeakRefs;
   DiscoveredList* _discoveredFinalRefs;
@@ -265,7 +271,8 @@
   int num_q()                              { return _num_q; }
   int max_num_q()                          { return _max_num_q; }
   void set_active_mt_degree(int v)         { _num_q = v; }
-  DiscoveredList* discovered_soft_refs()   { return _discoveredSoftRefs; }
+
+  DiscoveredList* discovered_refs()        { return _discovered_refs; }
 
   ReferencePolicy* setup_policy(bool always_clear) {
     _current_soft_ref_policy = always_clear ?
@@ -409,6 +416,7 @@
   // constructor
   ReferenceProcessor():
     _span((HeapWord*)NULL, (HeapWord*)NULL),
+    _discovered_refs(NULL),
     _discoveredSoftRefs(NULL),  _discoveredWeakRefs(NULL),
     _discoveredFinalRefs(NULL), _discoveredPhantomRefs(NULL),
     _discovering_refs(false),
@@ -456,19 +464,7 @@
   void      set_span(MemRegion span) { _span = span; }
 
   // start and stop weak ref discovery
-  void enable_discovery(bool verify_disabled, bool check_no_refs) {
-#ifdef ASSERT
-    // Verify that we're not currently discovering refs
-    assert(!verify_disabled || !_discovering_refs, "nested call?");
-
-    if (check_no_refs) {
-      // Verify that the discovered lists are empty
-      verify_no_references_recorded();
-    }
-#endif // ASSERT
-    _discovering_refs = true;
-  }
-
+  void enable_discovery(bool verify_disabled, bool check_no_refs);
   void disable_discovery()  { _discovering_refs = false; }
   bool discovery_enabled()  { return _discovering_refs;  }
 
diff --git a/hotspot/src/share/vm/memory/resourceArea.cpp b/hotspot/src/share/vm/memory/resourceArea.cpp
index 90c1e6e..28d5943 100644
--- a/hotspot/src/share/vm/memory/resourceArea.cpp
+++ b/hotspot/src/share/vm/memory/resourceArea.cpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 //------------------------------ResourceMark-----------------------------------
 debug_only(int ResourceArea::_warned;)      // to suppress multiple warnings
diff --git a/hotspot/src/share/vm/memory/resourceArea.hpp b/hotspot/src/share/vm/memory/resourceArea.hpp
index 3bb84b5..3d31248 100644
--- a/hotspot/src/share/vm/memory/resourceArea.hpp
+++ b/hotspot/src/share/vm/memory/resourceArea.hpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // The resource area holds temporary data structures in the VM.
 // The actual allocation areas are thread local. Typical usage:
diff --git a/hotspot/src/share/vm/memory/space.hpp b/hotspot/src/share/vm/memory/space.hpp
index 3693b64..ef7e231 100644
--- a/hotspot/src/share/vm/memory/space.hpp
+++ b/hotspot/src/share/vm/memory/space.hpp
@@ -44,6 +44,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 // A space is an abstraction for the "storage units" backing
 // up the generation abstraction. It includes specific
diff --git a/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp b/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp
index 74f2c44..03d6e6b 100644
--- a/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp
+++ b/hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp
@@ -38,6 +38,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // Thread-Local Edens support
 
diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp
index 355341c..22f5bb9 100644
--- a/hotspot/src/share/vm/memory/universe.cpp
+++ b/hotspot/src/share/vm/memory/universe.cpp
@@ -89,6 +89,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
 #include "gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp"
@@ -890,7 +893,7 @@
 
   } else if (UseG1GC) {
 #ifndef SERIALGC
-    G1CollectorPolicy* g1p = new G1CollectorPolicy_BestRegionsFirst();
+    G1CollectorPolicy* g1p = new G1CollectorPolicy();
     G1CollectedHeap* g1h = new G1CollectedHeap(g1p);
     Universe::_collectedHeap = g1h;
 #else  // SERIALGC
@@ -1278,11 +1281,17 @@
   }
 }
 
-void Universe::print() { print_on(gclog_or_tty); }
+void Universe::print() {
+  print_on(gclog_or_tty);
+}
 
-void Universe::print_on(outputStream* st) {
+void Universe::print_on(outputStream* st, bool extended) {
   st->print_cr("Heap");
-  heap()->print_on(st);
+  if (!extended) {
+    heap()->print_on(st);
+  } else {
+    heap()->print_extended_on(st);
+  }
 }
 
 void Universe::print_heap_at_SIGBREAK() {
@@ -1298,14 +1307,22 @@
   st->print_cr("{Heap before GC invocations=%u (full %u):",
                heap()->total_collections(),
                heap()->total_full_collections());
-  heap()->print_on(st);
+  if (!PrintHeapAtGCExtended) {
+    heap()->print_on(st);
+  } else {
+    heap()->print_extended_on(st);
+  }
 }
 
 void Universe::print_heap_after_gc(outputStream* st) {
   st->print_cr("Heap after GC invocations=%u (full %u):",
                heap()->total_collections(),
                heap()->total_full_collections());
-  heap()->print_on(st);
+  if (!PrintHeapAtGCExtended) {
+    heap()->print_on(st);
+  } else {
+    heap()->print_extended_on(st);
+  }
   st->print_cr("}");
 }
 
diff --git a/hotspot/src/share/vm/memory/universe.hpp b/hotspot/src/share/vm/memory/universe.hpp
index 0f90ff5..24c793f 100644
--- a/hotspot/src/share/vm/memory/universe.hpp
+++ b/hotspot/src/share/vm/memory/universe.hpp
@@ -414,9 +414,13 @@
   static bool verify_in_progress() { return _verify_in_progress; }
   static void verify(bool allow_dirty = true, bool silent = false,
                      VerifyOption option = VerifyOption_Default );
-  static int  verify_count()                  { return _verify_count; }
+  static int  verify_count()       { return _verify_count; }
+  // The default behavior is to call print_on() on gclog_or_tty.
   static void print();
-  static void print_on(outputStream* st);
+  // The extended parameter determines which method on the heap will
+  // be called: print_on() (extended == false) or print_extended_on()
+  // (extended == true).
+  static void print_on(outputStream* st, bool extended = false);
   static void print_heap_at_SIGBREAK();
   static void print_heap_before_gc() { print_heap_before_gc(gclog_or_tty); }
   static void print_heap_after_gc()  { print_heap_after_gc(gclog_or_tty); }
diff --git a/hotspot/src/share/vm/oops/arrayOop.cpp b/hotspot/src/share/vm/oops/arrayOop.cpp
index 62a971a..c159438 100644
--- a/hotspot/src/share/vm/oops/arrayOop.cpp
+++ b/hotspot/src/share/vm/oops/arrayOop.cpp
@@ -23,9 +23,40 @@
  */
 
 #include "precompiled.hpp"
-#include "oops/arrayOop.hpp"
-#include "oops/objArrayOop.hpp"
-#include "oops/oop.inline.hpp"
-#include "oops/symbol.hpp"
 
-// <<this page is intentionally left blank>>
+/////////////// Unit tests ///////////////
+
+#ifndef PRODUCT
+
+#include "oops/arrayOop.hpp"
+#include "utilities/globalDefinitions.hpp"
+
+bool arrayOopDesc::check_max_length_overflow(BasicType type) {
+  julong length = max_array_length(type);
+  julong bytes_per_element = type2aelembytes(type);
+  julong bytes = length * bytes_per_element + header_size_in_bytes();
+  return (julong)(size_t)bytes == bytes;
+}
+
+bool arrayOopDesc::test_max_array_length() {
+  tty->print_cr("test_max_array_length");
+
+  assert(check_max_length_overflow(T_BOOLEAN), "size_t overflow for boolean array");
+  assert(check_max_length_overflow(T_CHAR), "size_t overflow for char array");
+  assert(check_max_length_overflow(T_FLOAT), "size_t overflow for float array");
+  assert(check_max_length_overflow(T_DOUBLE), "size_t overflow for double array");
+  assert(check_max_length_overflow(T_BYTE), "size_t overflow for byte array");
+  assert(check_max_length_overflow(T_SHORT), "size_t overflow for short array");
+  assert(check_max_length_overflow(T_INT), "size_t overflow for int array");
+  assert(check_max_length_overflow(T_LONG), "size_t overflow for long array");
+  assert(check_max_length_overflow(T_OBJECT), "size_t overflow for object array");
+  assert(check_max_length_overflow(T_ARRAY), "size_t overflow for array array");
+  assert(check_max_length_overflow(T_NARROWOOP), "size_t overflow for narrowOop array");
+
+  // T_VOID and T_ADDRESS are not supported by max_array_length()
+
+  return true;
+}
+
+
+#endif //PRODUCT
diff --git a/hotspot/src/share/vm/oops/arrayOop.hpp b/hotspot/src/share/vm/oops/arrayOop.hpp
index 0e76239..e169990 100644
--- a/hotspot/src/share/vm/oops/arrayOop.hpp
+++ b/hotspot/src/share/vm/oops/arrayOop.hpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -104,20 +104,32 @@
 
   // Return the maximum length of an array of BasicType.  The length can passed
   // to typeArrayOop::object_size(scale, length, header_size) without causing an
-  // overflow.
+  // overflow. We also need to make sure that this will not overflow a size_t on
+  // 32 bit platforms when we convert it to a byte size.
   static int32_t max_array_length(BasicType type) {
     assert(type >= 0 && type < T_CONFLICT, "wrong type");
     assert(type2aelembytes(type) != 0, "wrong type");
-    const int bytes_per_element = type2aelembytes(type);
-    if (bytes_per_element < HeapWordSize) {
-      return max_jint;
-    }
 
-    const int32_t max_words = align_size_down(max_jint, MinObjAlignment);
-    const int32_t max_element_words = max_words - header_size(type);
-    const int32_t words_per_element = bytes_per_element >> LogHeapWordSize;
-    return max_element_words / words_per_element;
+    const size_t max_element_words_per_size_t =
+      align_size_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment);
+    const size_t max_elements_per_size_t =
+      HeapWordSize * max_element_words_per_size_t / type2aelembytes(type);
+    if ((size_t)max_jint < max_elements_per_size_t) {
+      // It should be ok to return max_jint here, but parts of the code
+      // (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for
+      // passing around the size (in words) of an object. So, we need to avoid
+      // overflowing an int when we add the header. See CRs 4718400 and 7110613.
+      return align_size_down(max_jint - header_size(type), MinObjAlignment);
+    }
+    return (int32_t)max_elements_per_size_t;
   }
+
+// for unit testing
+#ifndef PRODUCT
+  static bool check_max_length_overflow(BasicType type);
+  static int32_t old_max_array_length(BasicType type);
+  static bool test_max_array_length();
+#endif
 };
 
 #endif // SHARE_VM_OOPS_ARRAYOOP_HPP
diff --git a/hotspot/src/share/vm/oops/constantPoolKlass.cpp b/hotspot/src/share/vm/oops/constantPoolKlass.cpp
index 362e275..6e26731 100644
--- a/hotspot/src/share/vm/oops/constantPoolKlass.cpp
+++ b/hotspot/src/share/vm/oops/constantPoolKlass.cpp
@@ -44,6 +44,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
@@ -529,7 +532,7 @@
     if (cp->tag_at(i).is_unresolved_klass()) {
       // This will force loading of the class
       klassOop klass = cp->klass_at(i, CHECK);
-      if (klass->is_instance()) {
+      if (klass->klass_part()->oop_is_instance()) {
         // Force initialization of class
         instanceKlass::cast(klass)->initialize(CHECK);
       }
diff --git a/hotspot/src/share/vm/oops/constantPoolOop.cpp b/hotspot/src/share/vm/oops/constantPoolOop.cpp
index a46f4eb..87280c6 100644
--- a/hotspot/src/share/vm/oops/constantPoolOop.cpp
+++ b/hotspot/src/share/vm/oops/constantPoolOop.cpp
@@ -1355,7 +1355,7 @@
       }
       case JVM_CONSTANT_Long: {
         u8 val = Bytes::get_Java_u8(bytes);
-        printf("long         "INT64_FORMAT, *(jlong *) &val);
+        printf("long         "INT64_FORMAT, (int64_t) *(jlong *) &val);
         ent_size = 8;
         idx++; // Long takes two cpool slots
         break;
diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp
index 692dbc7..04b3c2f 100644
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp
@@ -61,6 +61,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
@@ -77,6 +80,8 @@
 
 #ifdef DTRACE_ENABLED
 
+#ifndef USDT2
+
 HS_DTRACE_PROBE_DECL4(hotspot, class__initialization__required,
   char*, intptr_t, oop, intptr_t);
 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__recursive,
@@ -119,6 +124,42 @@
     HS_DTRACE_PROBE5(hotspot, class__initialization__##type,     \
       data, len, (clss)->class_loader(), thread_type, wait);     \
   }
+#else /* USDT2 */
+
+#define HOTSPOT_CLASS_INITIALIZATION_required HOTSPOT_CLASS_INITIALIZATION_REQUIRED
+#define HOTSPOT_CLASS_INITIALIZATION_recursive HOTSPOT_CLASS_INITIALIZATION_RECURSIVE
+#define HOTSPOT_CLASS_INITIALIZATION_concurrent HOTSPOT_CLASS_INITIALIZATION_CONCURRENT
+#define HOTSPOT_CLASS_INITIALIZATION_erroneous HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS
+#define HOTSPOT_CLASS_INITIALIZATION_super__failed HOTSPOT_CLASS_INITIALIZATION_SUPER_FAILED
+#define HOTSPOT_CLASS_INITIALIZATION_clinit HOTSPOT_CLASS_INITIALIZATION_CLINIT
+#define HOTSPOT_CLASS_INITIALIZATION_error HOTSPOT_CLASS_INITIALIZATION_ERROR
+#define HOTSPOT_CLASS_INITIALIZATION_end HOTSPOT_CLASS_INITIALIZATION_END
+#define DTRACE_CLASSINIT_PROBE(type, clss, thread_type)          \
+  {                                                              \
+    char* data = NULL;                                           \
+    int len = 0;                                                 \
+    Symbol* name = (clss)->name();                               \
+    if (name != NULL) {                                          \
+      data = (char*)name->bytes();                               \
+      len = name->utf8_length();                                 \
+    }                                                            \
+    HOTSPOT_CLASS_INITIALIZATION_##type(                         \
+      data, len, (clss)->class_loader(), thread_type);           \
+  }
+
+#define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) \
+  {                                                              \
+    char* data = NULL;                                           \
+    int len = 0;                                                 \
+    Symbol* name = (clss)->name();                               \
+    if (name != NULL) {                                          \
+      data = (char*)name->bytes();                               \
+      len = name->utf8_length();                                 \
+    }                                                            \
+    HOTSPOT_CLASS_INITIALIZATION_##type(                         \
+      data, len, (clss)->class_loader(), thread_type, wait);     \
+  }
+#endif /* USDT2 */
 
 #else //  ndef DTRACE_ENABLED
 
diff --git a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp
index 8f66441..e0dd7d7 100644
--- a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp
+++ b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp
@@ -288,15 +288,7 @@
   // Query before forming handle.
   int size = instance_size(k);
   KlassHandle h_k(THREAD, as_klassOop());
-  instanceOop i;
-
-  if (JavaObjectsInPerm) {
-    i = (instanceOop) CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
-  } else {
-    assert(ScavengeRootsInCode > 0, "must be");
-    i = (instanceOop) CollectedHeap::obj_allocate(h_k, size, CHECK_NULL);
-  }
-
+  instanceOop i = (instanceOop) CollectedHeap::Class_obj_allocate(h_k, size, k, CHECK_NULL);
   return i;
 }
 
diff --git a/hotspot/src/share/vm/oops/markOop.cpp b/hotspot/src/share/vm/oops/markOop.cpp
index 5be365e..5e85944 100644
--- a/hotspot/src/share/vm/oops/markOop.cpp
+++ b/hotspot/src/share/vm/oops/markOop.cpp
@@ -33,6 +33,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 void markOopDesc::print_on(outputStream* st) const {
diff --git a/hotspot/src/share/vm/oops/oop.cpp b/hotspot/src/share/vm/oops/oop.cpp
index d8fa9b0..f836fb7 100644
--- a/hotspot/src/share/vm/oops/oop.cpp
+++ b/hotspot/src/share/vm/oops/oop.cpp
@@ -36,6 +36,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 bool always_do_update_barrier = false;
 
diff --git a/hotspot/src/share/vm/oops/oopsHierarchy.cpp b/hotspot/src/share/vm/oops/oopsHierarchy.cpp
index 9509806..b7d2c35 100644
--- a/hotspot/src/share/vm/oops/oopsHierarchy.cpp
+++ b/hotspot/src/share/vm/oops/oopsHierarchy.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 #ifdef CHECK_UNHANDLED_OOPS
 
diff --git a/hotspot/src/share/vm/oops/typeArrayKlass.cpp b/hotspot/src/share/vm/oops/typeArrayKlass.cpp
index 63384171..a3c58cd 100644
--- a/hotspot/src/share/vm/oops/typeArrayKlass.cpp
+++ b/hotspot/src/share/vm/oops/typeArrayKlass.cpp
@@ -76,7 +76,7 @@
   return k();
 }
 
-typeArrayOop typeArrayKlass::allocate(int length, TRAPS) {
+typeArrayOop typeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
   assert(log2_element_size() >= 0, "bad scale");
   if (length >= 0) {
     if (length <= max_length()) {
@@ -84,7 +84,11 @@
       KlassHandle h_k(THREAD, as_klassOop());
       typeArrayOop t;
       CollectedHeap* ch = Universe::heap();
-      t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL);
+      if (do_zero) {
+        t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL);
+      } else {
+        t = (typeArrayOop)CollectedHeap::array_allocate_nozero(h_k, (int)size, length, CHECK_NULL);
+      }
       assert(t->is_parsable(), "Don't publish unless parsable");
       return t;
     } else {
diff --git a/hotspot/src/share/vm/oops/typeArrayKlass.hpp b/hotspot/src/share/vm/oops/typeArrayKlass.hpp
index 78a26be..0f53066 100644
--- a/hotspot/src/share/vm/oops/typeArrayKlass.hpp
+++ b/hotspot/src/share/vm/oops/typeArrayKlass.hpp
@@ -56,7 +56,8 @@
   bool compute_is_subtype_of(klassOop k);
 
   // Allocation
-  typeArrayOop allocate(int length, TRAPS);
+  typeArrayOop allocate_common(int length, bool do_zero, TRAPS);
+  typeArrayOop allocate(int length, TRAPS) { return allocate_common(length, true, THREAD); }
   typeArrayOop allocate_permanent(int length, TRAPS);  // used for class file structures
   oop multi_allocate(int rank, jint* sizes, TRAPS);
 
diff --git a/hotspot/src/share/vm/oops/typeArrayOop.hpp b/hotspot/src/share/vm/oops/typeArrayOop.hpp
index e0133fd..292609e 100644
--- a/hotspot/src/share/vm/oops/typeArrayOop.hpp
+++ b/hotspot/src/share/vm/oops/typeArrayOop.hpp
@@ -51,6 +51,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "orderAccess_linux_ppc.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "orderAccess_bsd_x86.inline.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "orderAccess_bsd_zero.inline.hpp"
+#endif
 
 // A typeArrayOop is an array containing basic types (non oop elements).
 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
diff --git a/hotspot/src/share/vm/opto/addnode.cpp b/hotspot/src/share/vm/opto/addnode.cpp
index 33ecf15..ee6f6bc 100644
--- a/hotspot/src/share/vm/opto/addnode.cpp
+++ b/hotspot/src/share/vm/opto/addnode.cpp
@@ -34,8 +34,6 @@
 
 // Portions of code courtesy of Clifford Click
 
-#define MAXFLOAT        ((float)3.40282346638528860e+38)
-
 // Classic Add functionality.  This covers all the usual 'add' behaviors for
 // an algebraic ring.  Add-integer, add-float, add-double, and binary-or are
 // all inherited from this class.  The various identity values are supplied
diff --git a/hotspot/src/share/vm/opto/c2_globals.hpp b/hotspot/src/share/vm/opto/c2_globals.hpp
index 84a7d02..5cb4100 100644
--- a/hotspot/src/share/vm/opto/c2_globals.hpp
+++ b/hotspot/src/share/vm/opto/c2_globals.hpp
@@ -44,6 +44,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "c2_globals_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "c2_globals_bsd.hpp"
+#endif
 
 //
 // Defines all globals flags used by the server compiler.
@@ -198,7 +201,7 @@
   diagnostic(bool, UnrollLimitCheck, true,                                  \
           "Additional overflow checks during loop unroll")                  \
                                                                             \
-  product(bool, OptimizeFill, false,                                        \
+  product(bool, OptimizeFill, true,                                         \
           "convert fill/copy loops into intrinsic")                         \
                                                                             \
   develop(bool, TraceOptimizeFill, false,                                   \
@@ -456,7 +459,7 @@
   product(bool, UseOptoBiasInlining, true,                                  \
           "Generate biased locking code in C2 ideal graph")                 \
                                                                             \
-  product(bool, OptimizeStringConcat, false,                                \
+  product(bool, OptimizeStringConcat, true,                                 \
           "Optimize the construction of Strings by StringBuilder")          \
                                                                             \
   notproduct(bool, PrintOptimizeStringConcat, false,                        \
diff --git a/hotspot/src/share/vm/opto/callGenerator.cpp b/hotspot/src/share/vm/opto/callGenerator.cpp
index 150aa92..5ac3383 100644
--- a/hotspot/src/share/vm/opto/callGenerator.cpp
+++ b/hotspot/src/share/vm/opto/callGenerator.cpp
@@ -775,15 +775,15 @@
 
   Node* bol = NULL;
   int bc = jvms->method()->java_code_at_bci(jvms->bci());
-  if (bc == Bytecodes::_invokespecial) {
-    // This is the selectAlternative idiom for guardWithTest
+  if (bc != Bytecodes::_invokedynamic) {
+    // This is the selectAlternative idiom for guardWithTest or
+    // similar idioms.
     Node* receiver = kit.argument(0);
 
     // Check if the MethodHandle is the expected one
     Node* cmp = gvn.transform(new(kit.C, 3) CmpPNode(receiver, predicted_mh));
     bol = gvn.transform(new(kit.C, 2) BoolNode(cmp, BoolTest::eq) );
   } else {
-    assert(bc == Bytecodes::_invokedynamic, "must be");
     // Get the constant pool cache from the caller class.
     ciMethod* caller_method = jvms->method();
     ciBytecodeStream str(caller_method);
diff --git a/hotspot/src/share/vm/opto/compile.cpp b/hotspot/src/share/vm/opto/compile.cpp
index 2f0f294..358be62 100644
--- a/hotspot/src/share/vm/opto/compile.cpp
+++ b/hotspot/src/share/vm/opto/compile.cpp
@@ -346,15 +346,15 @@
 // Disconnect all useless nodes by disconnecting those at the boundary.
 void Compile::remove_useless_nodes(Unique_Node_List &useful) {
   uint next = 0;
-  while( next < useful.size() ) {
+  while (next < useful.size()) {
     Node *n = useful.at(next++);
     // Use raw traversal of out edges since this code removes out edges
     int max = n->outcnt();
-    for (int j = 0; j < max; ++j ) {
+    for (int j = 0; j < max; ++j) {
       Node* child = n->raw_out(j);
-      if( ! useful.member(child) ) {
-        assert( !child->is_top() || child != top(),
-                "If top is cached in Compile object it is in useful list");
+      if (! useful.member(child)) {
+        assert(!child->is_top() || child != top(),
+               "If top is cached in Compile object it is in useful list");
         // Only need to remove this out-edge to the useless node
         n->raw_del_out(j);
         --j;
@@ -362,7 +362,14 @@
       }
     }
     if (n->outcnt() == 1 && n->has_special_unique_user()) {
-      record_for_igvn( n->unique_out() );
+      record_for_igvn(n->unique_out());
+    }
+  }
+  // Remove useless macro and predicate opaq nodes
+  for (int i = C->macro_count()-1; i >= 0; i--) {
+    Node* n = C->macro_node(i);
+    if (!useful.member(n)) {
+      remove_macro_node(n);
     }
   }
   debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
@@ -719,6 +726,7 @@
       while (_late_inlines.length() > 0) {
         CallGenerator* cg = _late_inlines.pop();
         cg->do_late_inline();
+        if (failing())  return;
       }
     }
     assert(_late_inlines.length() == 0, "should have been processed");
@@ -1691,13 +1699,20 @@
 
   // Perform escape analysis
   if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {
+    if (has_loops()) {
+      // Cleanup graph (remove dead nodes).
+      TracePhase t2("idealLoop", &_t_idealLoop, true);
+      PhaseIdealLoop ideal_loop( igvn, false, true );
+      if (major_progress()) print_method("PhaseIdealLoop before EA", 2);
+      if (failing())  return;
+    }
     TracePhase t2("escapeAnalysis", &_t_escapeAnalysis, true);
     ConnectionGraph::do_analysis(this, &igvn);
 
     if (failing())  return;
 
     igvn.optimize();
-    print_method("Iter GVN 3", 2);
+    print_method("Iter GVN after EA", 2);
 
     if (failing())  return;
 
diff --git a/hotspot/src/share/vm/opto/connode.cpp b/hotspot/src/share/vm/opto/connode.cpp
index db36c6d..9a3b650 100644
--- a/hotspot/src/share/vm/opto/connode.cpp
+++ b/hotspot/src/share/vm/opto/connode.cpp
@@ -721,12 +721,7 @@
   if( t == Type::TOP ) return Type::TOP;
   if( t == Type::FLOAT ) return Type::DOUBLE;
   const TypeF *tf = t->is_float_constant();
-#ifndef IA64
   return TypeD::make( (double)tf->getf() );
-#else
-  float x = tf->getf();
-  return TypeD::make( (x == 0.0f) ? (double)x : (double)x + ia64_double_zero );
-#endif
 }
 
 //=============================================================================
diff --git a/hotspot/src/share/vm/opto/escape.cpp b/hotspot/src/share/vm/opto/escape.cpp
index 84e37bd..8ce7f96 100644
--- a/hotspot/src/share/vm/opto/escape.cpp
+++ b/hotspot/src/share/vm/opto/escape.cpp
@@ -108,14 +108,16 @@
   // Add ConP(#NULL) and ConN(#NULL) nodes.
   Node* oop_null = igvn->zerocon(T_OBJECT);
   _oop_null = oop_null->_idx;
-  assert(_oop_null < C->unique(), "should be created already");
+  assert(_oop_null < nodes_size(), "should be created already");
   add_node(oop_null, PointsToNode::JavaObject, PointsToNode::NoEscape, true);
 
   if (UseCompressedOops) {
     Node* noop_null = igvn->zerocon(T_NARROWOOP);
     _noop_null = noop_null->_idx;
-    assert(_noop_null < C->unique(), "should be created already");
+    assert(_noop_null < nodes_size(), "should be created already");
     add_node(noop_null, PointsToNode::JavaObject, PointsToNode::NoEscape, true);
+  } else {
+    _noop_null = _oop_null; // Should be initialized
   }
 }
 
@@ -174,6 +176,9 @@
 }
 
 void ConnectionGraph::set_escape_state(uint ni, PointsToNode::EscapeState es) {
+  // Don't change non-escaping state of NULL pointer.
+  if (ni == _noop_null || ni == _oop_null)
+    return;
   PointsToNode *npt = ptnode_adr(ni);
   PointsToNode::EscapeState old_es = npt->escape_state();
   if (es > old_es)
@@ -231,8 +236,8 @@
   }
   if (orig_es != es) {
     // cache the computed escape state
-    assert(es != PointsToNode::UnknownEscape, "should have computed an escape state");
-    ptnode_adr(idx)->set_escape_state(es);
+    assert(es > orig_es, "should have computed an escape state");
+    set_escape_state(idx, es);
   } // orig_es could be PointsToNode::UnknownEscape
   return es;
 }
@@ -334,7 +339,7 @@
         add_pointsto_edge(ni, etgt);
         if(etgt == _phantom_object) {
           // Special case - field set outside (globally escaping).
-          ptn->set_escape_state(PointsToNode::GlobalEscape);
+          set_escape_state(ni, PointsToNode::GlobalEscape);
         }
       } else if (et == PointsToNode::DeferredEdge) {
         deferred_edges->append(etgt);
@@ -373,16 +378,17 @@
 // whose offset matches "offset".
 void ConnectionGraph::add_deferred_edge_to_fields(uint from_i, uint adr_i, int offs) {
   PointsToNode* an = ptnode_adr(adr_i);
+  bool is_alloc = an->_node->is_Allocate();
   for (uint fe = 0; fe < an->edge_count(); fe++) {
     assert(an->edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge");
     int fi = an->edge_target(fe);
     PointsToNode* pf = ptnode_adr(fi);
-    int po = pf->offset();
-    if (pf->edge_count() == 0) {
-      // we have not seen any stores to this field, assume it was set outside this method
+    int offset = pf->offset();
+    if (!is_alloc) {
+      // Assume the field was set outside this method if it is not Allocation
       add_pointsto_edge(fi, _phantom_object);
     }
-    if (po == offs || po == Type::OffsetBot || offs == Type::OffsetBot) {
+    if (offset == offs || offset == Type::OffsetBot || offs == Type::OffsetBot) {
       add_deferred_edge(from_i, fi);
     }
   }
@@ -1036,7 +1042,7 @@
       PointsToNode::EscapeState es = escape_state(alloc);
       // We have an allocation or call which returns a Java object,
       // see if it is unescaped.
-      if (es != PointsToNode::NoEscape || !ptn->_scalar_replaceable)
+      if (es != PointsToNode::NoEscape || !ptn->scalar_replaceable())
         continue;
 
       // Find CheckCastPP for the allocate or for the return value of a call
@@ -1085,7 +1091,7 @@
         // so it could be eliminated.
         alloc->as_Allocate()->_is_scalar_replaceable = true;
       }
-      set_escape_state(n->_idx, es);
+      set_escape_state(n->_idx, es); // CheckCastPP escape state
       // in order for an object to be scalar-replaceable, it must be:
       //   - a direct allocation (not a call returning an object)
       //   - non-escaping
@@ -1097,15 +1103,14 @@
       set_map(n->_idx, alloc);
       const TypeOopPtr *t = igvn->type(n)->isa_oopptr();
       if (t == NULL)
-        continue;  // not a TypeInstPtr
+        continue;  // not a TypeOopPtr
       tinst = t->cast_to_exactness(true)->is_oopptr()->cast_to_instance_id(ni);
       igvn->hash_delete(n);
       igvn->set_type(n,  tinst);
       n->raise_bottom_type(tinst);
       igvn->hash_insert(n);
       record_for_optimizer(n);
-      if (alloc->is_Allocate() && ptn->_scalar_replaceable &&
-          (t->isa_instptr() || t->isa_aryptr())) {
+      if (alloc->is_Allocate() && (t->isa_instptr() || t->isa_aryptr())) {
 
         // First, put on the worklist all Field edges from Connection Graph
         // which is more accurate then putting immediate users from Ideal Graph.
@@ -1533,7 +1538,8 @@
     worklist_init.push(C->root());
   }
 
-  GrowableArray<int> cg_worklist;
+  GrowableArray<Node*> alloc_worklist;
+  GrowableArray<Node*> addp_worklist;
   PhaseGVN* igvn = _igvn;
   bool has_allocations = false;
 
@@ -1546,11 +1552,13 @@
     if (n->is_Allocate() || n->is_CallStaticJava() &&
         ptnode_adr(n->_idx)->node_type() == PointsToNode::JavaObject) {
       has_allocations = true;
+      if (n->is_Allocate())
+        alloc_worklist.append(n);
     }
     if(n->is_AddP()) {
       // Collect address nodes. Use them during stage 3 below
       // to build initial connection graph field edges.
-      cg_worklist.append(n->_idx);
+      addp_worklist.append(n);
     } else if (n->is_MergeMem()) {
       // Collect all MergeMem nodes to add memory slices for
       // scalar replaceable objects in split_unique_types().
@@ -1576,10 +1584,9 @@
 
   // 3. Pass to create initial fields edges (JavaObject -F-> AddP)
   //    to reduce number of iterations during stage 4 below.
-  uint cg_length = cg_worklist.length();
-  for( uint next = 0; next < cg_length; ++next ) {
-    int ni = cg_worklist.at(next);
-    Node* n = ptnode_adr(ni)->_node;
+  uint addp_length = addp_worklist.length();
+  for( uint next = 0; next < addp_length; ++next ) {
+    Node* n = addp_worklist.at(next);
     Node* base = get_addp_base(n);
     if (base->is_Proj())
       base = base->in(0);
@@ -1589,7 +1596,7 @@
     }
   }
 
-  cg_worklist.clear();
+  GrowableArray<int> cg_worklist;
   cg_worklist.append(_phantom_object);
   GrowableArray<uint>  worklist;
 
@@ -1648,73 +1655,44 @@
 
   Arena* arena = Thread::current()->resource_area();
   VectorSet visited(arena);
+
+  // 5. Find fields initializing values for not escaped allocations
+  uint alloc_length = alloc_worklist.length();
+  for (uint next = 0; next < alloc_length; ++next) {
+    Node* n = alloc_worklist.at(next);
+    if (ptnode_adr(n->_idx)->escape_state() == PointsToNode::NoEscape) {
+      find_init_values(n, &visited, igvn);
+    }
+  }
+
   worklist.clear();
 
-  // 5. Remove deferred edges from the graph and adjust
-  //    escape state of nonescaping objects.
-  cg_length = cg_worklist.length();
-  for( uint next = 0; next < cg_length; ++next ) {
+  // 6. Remove deferred edges from the graph.
+  uint cg_length = cg_worklist.length();
+  for (uint next = 0; next < cg_length; ++next) {
     int ni = cg_worklist.at(next);
     PointsToNode* ptn = ptnode_adr(ni);
     PointsToNode::NodeType nt = ptn->node_type();
     if (nt == PointsToNode::LocalVar || nt == PointsToNode::Field) {
       remove_deferred(ni, &worklist, &visited);
       Node *n = ptn->_node;
-      if (n->is_AddP()) {
-        // Search for objects which are not scalar replaceable
-        // and adjust their escape state.
-        adjust_escape_state(ni, igvn);
-      }
     }
   }
 
-  // 6. Propagate escape states.
+  // 7. Adjust escape state of nonescaping objects.
+  for (uint next = 0; next < addp_length; ++next) {
+    Node* n = addp_worklist.at(next);
+    adjust_escape_state(n);
+  }
+
+  // 8. Propagate escape states.
   worklist.clear();
-  bool has_non_escaping_obj = false;
 
-  // push all GlobalEscape nodes on the worklist
-  for( uint next = 0; next < cg_length; ++next ) {
-    int nk = cg_worklist.at(next);
-    if (ptnode_adr(nk)->escape_state() == PointsToNode::GlobalEscape)
-      worklist.push(nk);
-  }
   // mark all nodes reachable from GlobalEscape nodes
-  while(worklist.length() > 0) {
-    PointsToNode* ptn = ptnode_adr(worklist.pop());
-    uint e_cnt = ptn->edge_count();
-    for (uint ei = 0; ei < e_cnt; ei++) {
-      uint npi = ptn->edge_target(ei);
-      PointsToNode *np = ptnode_adr(npi);
-      if (np->escape_state() < PointsToNode::GlobalEscape) {
-        np->set_escape_state(PointsToNode::GlobalEscape);
-        worklist.push(npi);
-      }
-    }
-  }
+  (void)propagate_escape_state(&cg_worklist, &worklist, PointsToNode::GlobalEscape);
 
-  // push all ArgEscape nodes on the worklist
-  for( uint next = 0; next < cg_length; ++next ) {
-    int nk = cg_worklist.at(next);
-    if (ptnode_adr(nk)->escape_state() == PointsToNode::ArgEscape)
-      worklist.push(nk);
-  }
   // mark all nodes reachable from ArgEscape nodes
-  while(worklist.length() > 0) {
-    PointsToNode* ptn = ptnode_adr(worklist.pop());
-    if (ptn->node_type() == PointsToNode::JavaObject)
-      has_non_escaping_obj = true; // Non GlobalEscape
-    uint e_cnt = ptn->edge_count();
-    for (uint ei = 0; ei < e_cnt; ei++) {
-      uint npi = ptn->edge_target(ei);
-      PointsToNode *np = ptnode_adr(npi);
-      if (np->escape_state() < PointsToNode::ArgEscape) {
-        np->set_escape_state(PointsToNode::ArgEscape);
-        worklist.push(npi);
-      }
-    }
-  }
-
-  GrowableArray<Node*> alloc_worklist;
+  bool has_non_escaping_obj = propagate_escape_state(&cg_worklist, &worklist, PointsToNode::ArgEscape);
 
   // push all NoEscape nodes on the worklist
   for( uint next = 0; next < cg_length; ++next ) {
@@ -1722,15 +1700,20 @@
     if (ptnode_adr(nk)->escape_state() == PointsToNode::NoEscape)
       worklist.push(nk);
   }
+  alloc_worklist.clear();
   // mark all nodes reachable from NoEscape nodes
   while(worklist.length() > 0) {
-    PointsToNode* ptn = ptnode_adr(worklist.pop());
-    if (ptn->node_type() == PointsToNode::JavaObject)
-      has_non_escaping_obj = true; // Non GlobalEscape
+    uint nk = worklist.pop();
+    PointsToNode* ptn = ptnode_adr(nk);
+    if (ptn->node_type() == PointsToNode::JavaObject &&
+        !(nk == _noop_null || nk == _oop_null))
+      has_non_escaping_obj = true; // Non Escape
     Node* n = ptn->_node;
-    if (n->is_Allocate() && ptn->_scalar_replaceable ) {
+    bool scalar_replaceable = ptn->scalar_replaceable();
+    if (n->is_Allocate() && scalar_replaceable) {
       // Push scalar replaceable allocations on alloc_worklist
-      // for processing in split_unique_types().
+      // for processing in split_unique_types(). Note,
+      // following code may change scalar_replaceable value.
       alloc_worklist.append(n);
     }
     uint e_cnt = ptn->edge_count();
@@ -1738,7 +1721,14 @@
       uint npi = ptn->edge_target(ei);
       PointsToNode *np = ptnode_adr(npi);
       if (np->escape_state() < PointsToNode::NoEscape) {
-        np->set_escape_state(PointsToNode::NoEscape);
+        set_escape_state(npi, PointsToNode::NoEscape);
+        if (!scalar_replaceable) {
+          np->set_scalar_replaceable(false);
+        }
+        worklist.push(npi);
+      } else if (np->scalar_replaceable() && !scalar_replaceable) {
+        // Propagate scalar_replaceable value.
+        np->set_scalar_replaceable(false);
         worklist.push(npi);
       }
     }
@@ -1747,7 +1737,12 @@
   _collecting = false;
   assert(C->unique() == nodes_size(), "there should be no new ideal nodes during ConnectionGraph build");
 
-  if (EliminateLocks) {
+  assert(ptnode_adr(_oop_null)->escape_state() == PointsToNode::NoEscape, "sanity");
+  if (UseCompressedOops) {
+    assert(ptnode_adr(_noop_null)->escape_state() == PointsToNode::NoEscape, "sanity");
+  }
+
+  if (EliminateLocks && has_non_escaping_obj) {
     // Mark locks before changing ideal graph.
     int cnt = C->macro_count();
     for( int i=0; i < cnt; i++ ) {
@@ -1772,7 +1767,18 @@
   }
 #endif
 
-  bool has_scalar_replaceable_candidates = alloc_worklist.length() > 0;
+  bool has_scalar_replaceable_candidates = false;
+  alloc_length = alloc_worklist.length();
+  for (uint next = 0; next < alloc_length; ++next) {
+    Node* n = alloc_worklist.at(next);
+    PointsToNode* ptn = ptnode_adr(n->_idx);
+    assert(ptn->escape_state() == PointsToNode::NoEscape, "sanity");
+    if (ptn->scalar_replaceable()) {
+      has_scalar_replaceable_candidates = true;
+      break;
+    }
+  }
+
   if ( has_scalar_replaceable_candidates &&
        C->AliasLevel() >= 3 && EliminateAllocations ) {
 
@@ -1801,53 +1807,32 @@
   return has_non_escaping_obj;
 }
 
-// Adjust escape state after Connection Graph is built.
-void ConnectionGraph::adjust_escape_state(int nidx, PhaseTransform* phase) {
-  PointsToNode* ptn = ptnode_adr(nidx);
-  Node* n = ptn->_node;
-  assert(n->is_AddP(), "Should be called for AddP nodes only");
-  // Search for objects which are not scalar replaceable.
-  // Mark their escape state as ArgEscape to propagate the state
-  // to referenced objects.
-  // Note: currently there are no difference in compiler optimizations
-  // for ArgEscape objects and NoEscape objects which are not
-  // scalar replaceable.
+// Find fields initializing values for allocations.
+void ConnectionGraph::find_init_values(Node* alloc, VectorSet* visited, PhaseTransform* phase) {
+  assert(alloc->is_Allocate(), "Should be called for Allocate nodes only");
+  PointsToNode* pta = ptnode_adr(alloc->_idx);
+  assert(pta->escape_state() == PointsToNode::NoEscape, "Not escaped Allocate nodes only");
+  InitializeNode* ini = alloc->as_Allocate()->initialization();
 
   Compile* C = _compile;
-
-  int offset = ptn->offset();
-  Node* base = get_addp_base(n);
-  VectorSet* ptset = PointsTo(base);
-  int ptset_size = ptset->Size();
-
+  visited->Reset();
   // Check if a oop field's initializing value is recorded and add
   // a corresponding NULL field's value if it is not recorded.
   // Connection Graph does not record a default initialization by NULL
   // captured by Initialize node.
   //
-  // Note: it will disable scalar replacement in some cases:
-  //
-  //    Point p[] = new Point[1];
-  //    p[0] = new Point(); // Will be not scalar replaced
-  //
-  // but it will save us from incorrect optimizations in next cases:
-  //
-  //    Point p[] = new Point[1];
-  //    if ( x ) p[0] = new Point(); // Will be not scalar replaced
-  //
-  // Do a simple control flow analysis to distinguish above cases.
-  //
-  if (offset != Type::OffsetBot && ptset_size == 1) {
-    uint elem = ptset->getelem(); // Allocation node's index
-    // It does not matter if it is not Allocation node since
-    // only non-escaping allocations are scalar replaced.
-    if (ptnode_adr(elem)->_node->is_Allocate() &&
-        ptnode_adr(elem)->escape_state() == PointsToNode::NoEscape) {
-      AllocateNode* alloc = ptnode_adr(elem)->_node->as_Allocate();
-      InitializeNode* ini = alloc->initialization();
+  uint ae_cnt = pta->edge_count();
+  for (uint ei = 0; ei < ae_cnt; ei++) {
+    uint nidx = pta->edge_target(ei); // Field (AddP)
+    PointsToNode* ptn = ptnode_adr(nidx);
+    assert(ptn->_node->is_AddP(), "Should be AddP nodes only");
+    int offset = ptn->offset();
+    if (offset != Type::OffsetBot &&
+        offset != oopDesc::klass_offset_in_bytes() &&
+        !visited->test_set(offset)) {
 
       // Check only oop fields.
-      const Type* adr_type = n->as_AddP()->bottom_type();
+      const Type* adr_type = ptn->_node->as_AddP()->bottom_type();
       BasicType basic_field_type = T_INT;
       if (adr_type->isa_instptr()) {
         ciField* field = C->alias_type(adr_type->isa_instptr())->field();
@@ -1857,12 +1842,20 @@
           // Ignore non field load (for example, klass load)
         }
       } else if (adr_type->isa_aryptr()) {
-        const Type* elemtype = adr_type->isa_aryptr()->elem();
-        basic_field_type = elemtype->array_element_basic_type();
+        if (offset != arrayOopDesc::length_offset_in_bytes()) {
+          const Type* elemtype = adr_type->isa_aryptr()->elem();
+          basic_field_type = elemtype->array_element_basic_type();
+        } else {
+          // Ignore array length load
+        }
+#ifdef ASSERT
       } else {
-        // Raw pointers are used for initializing stores so skip it.
+        // Raw pointers are used for initializing stores so skip it
+        // since it should be recorded already
+        Node* base = get_addp_base(ptn->_node);
         assert(adr_type->isa_rawptr() && base->is_Proj() &&
                (base->in(0) == alloc),"unexpected pointer type");
+#endif
       }
       if (basic_field_type == T_OBJECT ||
           basic_field_type == T_NARROWOOP ||
@@ -1877,18 +1870,33 @@
             // Check for a store which follows allocation without branches.
             // For example, a volatile field store is not collected
             // by Initialize node. TODO: it would be nice to use idom() here.
-            for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
-              store = n->fast_out(i);
-              if (store->is_Store() && store->in(0) != NULL) {
-                Node* ctrl = store->in(0);
-                while(!(ctrl == ini || ctrl == alloc || ctrl == NULL ||
-                        ctrl == C->root() || ctrl == C->top() || ctrl->is_Region() ||
-                        ctrl->is_IfTrue() || ctrl->is_IfFalse())) {
-                   ctrl = ctrl->in(0);
-                }
-                if (ctrl == ini || ctrl == alloc) {
-                  value = store->in(MemNode::ValueIn);
-                  break;
+            //
+            // Search all references to the same field which use different
+            // AddP nodes, for example, in the next case:
+            //
+            //    Point p[] = new Point[1];
+            //    if ( x ) { p[0] = new Point(); p[0].x = x; }
+            //    if ( p[0] != null ) { y = p[0].x; } // has CastPP
+            //
+            for (uint next = ei; (next < ae_cnt) && (value == NULL); next++) {
+              uint fpi = pta->edge_target(next); // Field (AddP)
+              PointsToNode *ptf = ptnode_adr(fpi);
+              if (ptf->offset() == offset) {
+                Node* nf = ptf->_node;
+                for (DUIterator_Fast imax, i = nf->fast_outs(imax); i < imax; i++) {
+                  store = nf->fast_out(i);
+                  if (store->is_Store() && store->in(0) != NULL) {
+                    Node* ctrl = store->in(0);
+                    while(!(ctrl == ini || ctrl == alloc || ctrl == NULL ||
+                            ctrl == C->root() || ctrl == C->top() || ctrl->is_Region() ||
+                            ctrl->is_IfTrue() || ctrl->is_IfFalse())) {
+                       ctrl = ctrl->in(0);
+                    }
+                    if (ctrl == ini || ctrl == alloc) {
+                      value = store->in(MemNode::ValueIn);
+                      break;
+                    }
+                  }
                 }
               }
             }
@@ -1897,21 +1905,35 @@
         if (value == NULL || value != ptnode_adr(value->_idx)->_node) {
           // A field's initializing value was not recorded. Add NULL.
           uint null_idx = UseCompressedOops ? _noop_null : _oop_null;
-          add_pointsto_edge(nidx, null_idx);
+          add_edge_from_fields(alloc->_idx, null_idx, offset);
         }
       }
     }
   }
+}
+
+// Adjust escape state after Connection Graph is built.
+void ConnectionGraph::adjust_escape_state(Node* n) {
+  PointsToNode* ptn = ptnode_adr(n->_idx);
+  assert(n->is_AddP(), "Should be called for AddP nodes only");
+  // Search for objects which are not scalar replaceable
+  // and mark them to propagate the state to referenced objects.
+  //
+
+  int offset = ptn->offset();
+  Node* base = get_addp_base(n);
+  VectorSet* ptset = PointsTo(base);
+  int ptset_size = ptset->Size();
 
   // An object is not scalar replaceable if the field which may point
   // to it has unknown offset (unknown element of an array of objects).
   //
+
   if (offset == Type::OffsetBot) {
     uint e_cnt = ptn->edge_count();
     for (uint ei = 0; ei < e_cnt; ei++) {
       uint npi = ptn->edge_target(ei);
-      set_escape_state(npi, PointsToNode::ArgEscape);
-      ptnode_adr(npi)->_scalar_replaceable = false;
+      ptnode_adr(npi)->set_scalar_replaceable(false);
     }
   }
 
@@ -1930,20 +1952,62 @@
   // to unknown field (unknown element for arrays, offset is OffsetBot).
   //
   // Or the address may point to more then one object. This may produce
-  // the false positive result (set scalar_replaceable to false)
+  // the false positive result (set not scalar replaceable)
   // since the flow-insensitive escape analysis can't separate
   // the case when stores overwrite the field's value from the case
   // when stores happened on different control branches.
   //
+  // Note: it will disable scalar replacement in some cases:
+  //
+  //    Point p[] = new Point[1];
+  //    p[0] = new Point(); // Will be not scalar replaced
+  //
+  // but it will save us from incorrect optimizations in next cases:
+  //
+  //    Point p[] = new Point[1];
+  //    if ( x ) p[0] = new Point(); // Will be not scalar replaced
+  //
   if (ptset_size > 1 || ptset_size != 0 &&
       (has_LoadStore || offset == Type::OffsetBot)) {
     for( VectorSetI j(ptset); j.test(); ++j ) {
-      set_escape_state(j.elem, PointsToNode::ArgEscape);
-      ptnode_adr(j.elem)->_scalar_replaceable = false;
+      ptnode_adr(j.elem)->set_scalar_replaceable(false);
     }
   }
 }
 
+// Propagate escape states to referenced nodes.
+bool ConnectionGraph::propagate_escape_state(GrowableArray<int>* cg_worklist,
+                                             GrowableArray<uint>* worklist,
+                                             PointsToNode::EscapeState esc_state) {
+  bool has_java_obj = false;
+
+  // push all nodes with the same escape state on the worklist
+  uint cg_length = cg_worklist->length();
+  for (uint next = 0; next < cg_length; ++next) {
+    int nk = cg_worklist->at(next);
+    if (ptnode_adr(nk)->escape_state() == esc_state)
+      worklist->push(nk);
+  }
+  // mark all reachable nodes
+  while (worklist->length() > 0) {
+    PointsToNode* ptn = ptnode_adr(worklist->pop());
+    if (ptn->node_type() == PointsToNode::JavaObject) {
+      has_java_obj = true;
+    }
+    uint e_cnt = ptn->edge_count();
+    for (uint ei = 0; ei < e_cnt; ei++) {
+      uint npi = ptn->edge_target(ei);
+      PointsToNode *np = ptnode_adr(npi);
+      if (np->escape_state() < esc_state) {
+        set_escape_state(npi, esc_state);
+        worklist->push(npi);
+      }
+    }
+  }
+  // Has not escaping java objects
+  return has_java_obj && (esc_state < PointsToNode::GlobalEscape);
+}
+
 void ConnectionGraph::process_call_arguments(CallNode *call, PhaseTransform *phase) {
 
     switch (call->Opcode()) {
@@ -2100,6 +2164,7 @@
       } else {
         es = PointsToNode::NoEscape;
         edge_to = call_idx;
+        assert(ptnode_adr(call_idx)->scalar_replaceable(), "sanity");
       }
       set_escape_state(call_idx, es);
       add_pointsto_edge(resproj_idx, edge_to);
@@ -2123,10 +2188,11 @@
       } else {
         es = PointsToNode::NoEscape;
         edge_to = call_idx;
+        assert(ptnode_adr(call_idx)->scalar_replaceable(), "sanity");
         int length = call->in(AllocateNode::ALength)->find_int_con(-1);
         if (length < 0 || length > EliminateAllocationArraySizeLimit) {
           // Not scalar replaceable if the length is not constant or too big.
-          ptnode_adr(call_idx)->_scalar_replaceable = false;
+          ptnode_adr(call_idx)->set_scalar_replaceable(false);
         }
       }
       set_escape_state(call_idx, es);
@@ -2168,11 +2234,12 @@
           // Mark it as NoEscape so that objects referenced by
           // it's fields will be marked as NoEscape at least.
           set_escape_state(call_idx, PointsToNode::NoEscape);
+          ptnode_adr(call_idx)->set_scalar_replaceable(false);
           add_pointsto_edge(resproj_idx, call_idx);
           copy_dependencies = true;
         } else if (call_analyzer->is_return_local()) {
           // determine whether any arguments are returned
-          set_escape_state(call_idx, PointsToNode::NoEscape);
+          set_escape_state(call_idx, PointsToNode::ArgEscape);
           bool ret_arg = false;
           for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
             const Type* at = d->field_at(i);
@@ -2189,7 +2256,6 @@
                   add_pointsto_edge(resproj_idx, arg->_idx);
                 else
                   add_deferred_edge(resproj_idx, arg->_idx);
-                arg_esp->_hidden_alias = true;
               }
             }
           }
@@ -2198,18 +2264,12 @@
             set_escape_state(call_idx, PointsToNode::GlobalEscape);
             add_pointsto_edge(resproj_idx, _phantom_object);
           }
-          copy_dependencies = true;
+          if (done) {
+            copy_dependencies = true;
+          }
         } else {
           set_escape_state(call_idx, PointsToNode::GlobalEscape);
           add_pointsto_edge(resproj_idx, _phantom_object);
-          for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
-            const Type* at = d->field_at(i);
-            if (at->isa_oopptr() != NULL) {
-              Node *arg = call->in(i)->uncast();
-              PointsToNode *arg_esp = ptnode_adr(arg->_idx);
-              arg_esp->_hidden_alias = true;
-            }
-          }
         }
         if (copy_dependencies)
           call_analyzer->copy_dependencies(_compile->dependencies());
diff --git a/hotspot/src/share/vm/opto/escape.hpp b/hotspot/src/share/vm/opto/escape.hpp
index 0cd00f4..9ac2ca1 100644
--- a/hotspot/src/share/vm/opto/escape.hpp
+++ b/hotspot/src/share/vm/opto/escape.hpp
@@ -74,7 +74,7 @@
 // C2 does not have local variables.  However for the purposes of constructing
 // the connection graph, the following IR nodes are treated as local variables:
 //     Phi    (pointer values)
-//     LoadP
+//     LoadP, LoadN
 //     Proj#5 (value returned from callnodes including allocations)
 //     CheckCastPP, CastPP
 //
@@ -84,7 +84,7 @@
 //
 // The following node types are JavaObject:
 //
-//     top()
+//     phantom_object (general globally escaped object)
 //     Allocate
 //     AllocateArray
 //     Parm  (for incoming arguments)
@@ -93,6 +93,7 @@
 //     ConP
 //     LoadKlass
 //     ThreadLocal
+//     CallStaticJava (which returns Object)
 //
 // AddP nodes are fields.
 //
@@ -130,10 +131,12 @@
 
   typedef enum {
     UnknownEscape = 0,
-    NoEscape      = 1, // A scalar replaceable object with unique type.
-    ArgEscape     = 2, // An object passed as argument or referenced by
-                       // argument (and not globally escape during call).
-    GlobalEscape  = 3  // An object escapes the method and thread.
+    NoEscape      = 1, // An object does not escape method or thread and it is
+                       // not passed to call. It could be replaced with scalar.
+    ArgEscape     = 2, // An object does not escape method or thread but it is
+                       // passed as argument to call or referenced by argument
+                       // and it does not escape during call.
+    GlobalEscape  = 3  // An object escapes the method or thread.
   } EscapeState;
 
   typedef enum {
@@ -153,28 +156,25 @@
 
   NodeType             _type;
   EscapeState          _escape;
-  GrowableArray<uint>* _edges;   // outgoing edges
+  GrowableArray<uint>* _edges; // outgoing edges
+  Node* _node;                 // Ideal node corresponding to this PointsTo node.
+  int   _offset;               // Object fields offsets.
+  bool  _scalar_replaceable;   // Not escaped object could be replaced with scalar
 
 public:
-  Node* _node;              // Ideal node corresponding to this PointsTo node.
-  int   _offset;            // Object fields offsets.
-  bool  _scalar_replaceable;// Not escaped object could be replaced with scalar
-  bool  _hidden_alias;      // This node is an argument to a function.
-                            // which may return it creating a hidden alias.
-
   PointsToNode():
     _type(UnknownType),
     _escape(UnknownEscape),
     _edges(NULL),
     _node(NULL),
     _offset(-1),
-    _scalar_replaceable(true),
-    _hidden_alias(false) {}
+    _scalar_replaceable(true) {}
 
 
   EscapeState escape_state() const { return _escape; }
   NodeType node_type() const { return _type;}
   int offset() { return _offset;}
+  bool scalar_replaceable() { return _scalar_replaceable;}
 
   void set_offset(int offs) { _offset = offs;}
   void set_escape_state(EscapeState state) { _escape = state; }
@@ -182,6 +182,7 @@
     assert(_type == UnknownType || _type == ntype, "Can't change node type");
     _type = ntype;
   }
+  void set_scalar_replaceable(bool v) { _scalar_replaceable = v; }
 
   // count of outgoing edges
   uint edge_count() const { return (_edges == NULL) ? 0 : _edges->length(); }
@@ -233,8 +234,8 @@
                                        // that pointer values loaded from
                                        // a field which has not been set
                                        // are assumed to point to.
-  uint                      _oop_null; // ConP(#NULL)
-  uint                     _noop_null; // ConN(#NULL)
+  uint                      _oop_null; // ConP(#NULL)->_idx
+  uint                     _noop_null; // ConN(#NULL)->_idx
 
   Compile *                  _compile; // Compile object for current compilation
   PhaseIterGVN *                _igvn; // Value numbering
@@ -339,8 +340,16 @@
   // Set the escape state of a node
   void set_escape_state(uint ni, PointsToNode::EscapeState es);
 
+  // Find fields initializing values for allocations.
+  void find_init_values(Node* n, VectorSet* visited, PhaseTransform* phase);
+
   // Adjust escape state after Connection Graph is built.
-  void adjust_escape_state(int nidx, PhaseTransform* phase);
+  void adjust_escape_state(Node* n);
+
+  // Propagate escape states to referenced nodes.
+  bool propagate_escape_state(GrowableArray<int>* cg_worklist,
+                              GrowableArray<uint>* worklist,
+                              PointsToNode::EscapeState esc_state);
 
   // Compute the escape information
   bool compute_escape();
@@ -357,21 +366,6 @@
   // escape state of a node
   PointsToNode::EscapeState escape_state(Node *n);
 
-  // other information we have collected
-  bool is_scalar_replaceable(Node *n) {
-    if (_collecting || (n->_idx >= nodes_size()))
-      return false;
-    PointsToNode* ptn = ptnode_adr(n->_idx);
-    return ptn->escape_state() == PointsToNode::NoEscape && ptn->_scalar_replaceable;
-  }
-
-  bool hidden_alias(Node *n) {
-    if (_collecting || (n->_idx >= nodes_size()))
-      return true;
-    PointsToNode* ptn = ptnode_adr(n->_idx);
-    return (ptn->escape_state() != PointsToNode::NoEscape) || ptn->_hidden_alias;
-  }
-
 #ifndef PRODUCT
   void dump();
 #endif
diff --git a/hotspot/src/share/vm/opto/library_call.cpp b/hotspot/src/share/vm/opto/library_call.cpp
index 8179f37..d5ad00e 100644
--- a/hotspot/src/share/vm/opto/library_call.cpp
+++ b/hotspot/src/share/vm/opto/library_call.cpp
@@ -4658,6 +4658,7 @@
     // "You break it, you buy it."
     InitializeNode* init = alloc->initialization();
     assert(init->is_complete(), "we just did this");
+    init->set_complete_with_arraycopy();
     assert(dest->is_CheckCastPP(), "sanity");
     assert(dest->in(0)->in(0) == init, "dest pinned");
     adr_type = TypeRawPtr::BOTTOM;  // all initializations are into raw memory
diff --git a/hotspot/src/share/vm/opto/loopnode.cpp b/hotspot/src/share/vm/opto/loopnode.cpp
index 85a58f6..3bd04ad 100644
--- a/hotspot/src/share/vm/opto/loopnode.cpp
+++ b/hotspot/src/share/vm/opto/loopnode.cpp
@@ -715,6 +715,7 @@
     long limit_con = cl->limit()->get_int();
     julong trip_cnt = cl->trip_count();
     long final_con = init_con + trip_cnt*stride_con;
+    final_con -= stride_con;
     int final_int = (int)final_con;
     // The final value should be in integer range since the loop
     // is counted and the limit was checked for overflow.
@@ -1882,7 +1883,7 @@
 //----------------------------build_and_optimize-------------------------------
 // Create a PhaseLoop.  Build the ideal Loop tree.  Map each Ideal Node to
 // its corresponding LoopNode.  If 'optimize' is true, do some loop cleanups.
-void PhaseIdealLoop::build_and_optimize(bool do_split_ifs) {
+void PhaseIdealLoop::build_and_optimize(bool do_split_ifs, bool skip_loop_opts) {
   ResourceMark rm;
 
   int old_progress = C->major_progress();
@@ -2071,6 +2072,16 @@
   }
 #endif
 
+  if (skip_loop_opts) {
+    // Cleanup any modified bits
+    _igvn.optimize();
+
+    if (C->log() != NULL) {
+      log_loop_tree(_ltree_root, _ltree_root, C->log());
+    }
+    return;
+  }
+
   if (ReassociateInvariants) {
     // Reassociate invariants and prep for split_thru_phi
     for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) {
diff --git a/hotspot/src/share/vm/opto/loopnode.hpp b/hotspot/src/share/vm/opto/loopnode.hpp
index 817124b..9b4c38a 100644
--- a/hotspot/src/share/vm/opto/loopnode.hpp
+++ b/hotspot/src/share/vm/opto/loopnode.hpp
@@ -747,11 +747,11 @@
     _dom_lca_tags(arena()), // Thread::resource_area
     _verify_me(NULL),
     _verify_only(true) {
-    build_and_optimize(false);
+    build_and_optimize(false, false);
   }
 
   // build the loop tree and perform any requested optimizations
-  void build_and_optimize(bool do_split_if);
+  void build_and_optimize(bool do_split_if, bool skip_loop_opts);
 
 public:
   // Dominators for the sea of nodes
@@ -762,13 +762,13 @@
   Node *dom_lca_internal( Node *n1, Node *n2 ) const;
 
   // Compute the Ideal Node to Loop mapping
-  PhaseIdealLoop( PhaseIterGVN &igvn, bool do_split_ifs) :
+  PhaseIdealLoop( PhaseIterGVN &igvn, bool do_split_ifs, bool skip_loop_opts = false) :
     PhaseTransform(Ideal_Loop),
     _igvn(igvn),
     _dom_lca_tags(arena()), // Thread::resource_area
     _verify_me(NULL),
     _verify_only(false) {
-    build_and_optimize(do_split_ifs);
+    build_and_optimize(do_split_ifs, skip_loop_opts);
   }
 
   // Verify that verify_me made the same decisions as a fresh run.
@@ -778,7 +778,7 @@
     _dom_lca_tags(arena()), // Thread::resource_area
     _verify_me(verify_me),
     _verify_only(false) {
-    build_and_optimize(false);
+    build_and_optimize(false, false);
   }
 
   // Build and verify the loop tree without modifying the graph.  This
diff --git a/hotspot/src/share/vm/opto/loopopts.cpp b/hotspot/src/share/vm/opto/loopopts.cpp
index c693deb..93c1819 100644
--- a/hotspot/src/share/vm/opto/loopopts.cpp
+++ b/hotspot/src/share/vm/opto/loopopts.cpp
@@ -28,6 +28,7 @@
 #include "opto/connode.hpp"
 #include "opto/divnode.hpp"
 #include "opto/loopnode.hpp"
+#include "opto/matcher.hpp"
 #include "opto/mulnode.hpp"
 #include "opto/rootnode.hpp"
 #include "opto/subnode.hpp"
@@ -472,46 +473,50 @@
 // 1 or 2 items with a total of 1 or 2 ops executed speculatively.
 Node *PhaseIdealLoop::conditional_move( Node *region ) {
 
-  assert( region->is_Region(), "sanity check" );
-  if( region->req() != 3 ) return NULL;
+  assert(region->is_Region(), "sanity check");
+  if (region->req() != 3) return NULL;
 
   // Check for CFG diamond
   Node *lp = region->in(1);
   Node *rp = region->in(2);
-  if( !lp || !rp ) return NULL;
+  if (!lp || !rp) return NULL;
   Node *lp_c = lp->in(0);
-  if( lp_c == NULL || lp_c != rp->in(0) || !lp_c->is_If() ) return NULL;
+  if (lp_c == NULL || lp_c != rp->in(0) || !lp_c->is_If()) return NULL;
   IfNode *iff = lp_c->as_If();
 
-  // Check for highly predictable branch.  No point in CMOV'ing if
-  // we are going to predict accurately all the time.
-  // %%% This hides patterns produced by utility methods like Math.min.
-  if( iff->_prob < PROB_UNLIKELY_MAG(3) ||
-      iff->_prob > PROB_LIKELY_MAG(3) )
-    return NULL;
-
   // Check for ops pinned in an arm of the diamond.
   // Can't remove the control flow in this case
-  if( lp->outcnt() > 1 ) return NULL;
-  if( rp->outcnt() > 1 ) return NULL;
+  if (lp->outcnt() > 1) return NULL;
+  if (rp->outcnt() > 1) return NULL;
+
+  IdealLoopTree* r_loop = get_loop(region);
+  assert(r_loop == get_loop(iff), "sanity");
+  // Always convert to CMOVE if all results are used only outside this loop.
+  bool used_inside_loop = (r_loop == _ltree_root);
 
   // Check profitability
   int cost = 0;
   int phis = 0;
   for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
     Node *out = region->fast_out(i);
-    if( !out->is_Phi() ) continue; // Ignore other control edges, etc
+    if (!out->is_Phi()) continue; // Ignore other control edges, etc
     phis++;
     PhiNode* phi = out->as_Phi();
-    switch (phi->type()->basic_type()) {
-    case T_LONG:
-      cost++;                   // Probably encodes as 2 CMOV's
-    case T_INT:                 // These all CMOV fine
+    BasicType bt = phi->type()->basic_type();
+    switch (bt) {
     case T_FLOAT:
-    case T_DOUBLE:
-    case T_ADDRESS:             // (RawPtr)
+    case T_DOUBLE: {
+      cost += Matcher::float_cmove_cost(); // Could be very expensive
+      break;
+    }
+    case T_LONG: {
+      cost += Matcher::long_cmove_cost(); // May encodes as 2 CMOV's
+    }
+    case T_INT:                 // These all CMOV fine
+    case T_ADDRESS: {           // (RawPtr)
       cost++;
       break;
+    }
     case T_NARROWOOP: // Fall through
     case T_OBJECT: {            // Base oops are OK, but not derived oops
       const TypeOopPtr *tp = phi->type()->make_ptr()->isa_oopptr();
@@ -524,7 +529,7 @@
       // relevant bases.  This puts the allocator in the business of
       // manufacturing expensive instructions, generally a bad plan.
       // Just Say No to Conditionally-Moved Derived Pointers.
-      if( tp && tp->offset() != 0 )
+      if (tp && tp->offset() != 0)
         return NULL;
       cost++;
       break;
@@ -533,39 +538,64 @@
       return NULL;              // In particular, can't do memory or I/O
     }
     // Add in cost any speculative ops
-    for( uint j = 1; j < region->req(); j++ ) {
+    for (uint j = 1; j < region->req(); j++) {
       Node *proj = region->in(j);
       Node *inp = phi->in(j);
       if (get_ctrl(inp) == proj) { // Found local op
         cost++;
         // Check for a chain of dependent ops; these will all become
         // speculative in a CMOV.
-        for( uint k = 1; k < inp->req(); k++ )
+        for (uint k = 1; k < inp->req(); k++)
           if (get_ctrl(inp->in(k)) == proj)
-            return NULL;        // Too much speculative goo
+            cost += ConditionalMoveLimit; // Too much speculative goo
       }
     }
     // See if the Phi is used by a Cmp or Narrow oop Decode/Encode.
     // This will likely Split-If, a higher-payoff operation.
     for (DUIterator_Fast kmax, k = phi->fast_outs(kmax); k < kmax; k++) {
       Node* use = phi->fast_out(k);
-      if( use->is_Cmp() || use->is_DecodeN() || use->is_EncodeP() )
-        return NULL;
+      if (use->is_Cmp() || use->is_DecodeN() || use->is_EncodeP())
+        cost += ConditionalMoveLimit;
+      // Is there a use inside the loop?
+      // Note: check only basic types since CMoveP is pinned.
+      if (!used_inside_loop && is_java_primitive(bt)) {
+        IdealLoopTree* u_loop = get_loop(has_ctrl(use) ? get_ctrl(use) : use);
+        if (r_loop == u_loop || r_loop->is_member(u_loop)) {
+          used_inside_loop = true;
+        }
+      }
     }
   }
-  if( cost >= ConditionalMoveLimit ) return NULL; // Too much goo
   Node* bol = iff->in(1);
-  assert( bol->Opcode() == Op_Bool, "" );
+  assert(bol->Opcode() == Op_Bool, "");
   int cmp_op = bol->in(1)->Opcode();
   // It is expensive to generate flags from a float compare.
   // Avoid duplicated float compare.
-  if( phis > 1 && (cmp_op == Op_CmpF || cmp_op == Op_CmpD)) return NULL;
+  if (phis > 1 && (cmp_op == Op_CmpF || cmp_op == Op_CmpD)) return NULL;
+
+  float infrequent_prob = PROB_UNLIKELY_MAG(3);
+  // Ignore cost and blocks frequency if CMOVE can be moved outside the loop.
+  if (used_inside_loop) {
+    if (cost >= ConditionalMoveLimit) return NULL; // Too much goo
+
+    // BlockLayoutByFrequency optimization moves infrequent branch
+    // from hot path. No point in CMOV'ing in such case (110 is used
+    // instead of 100 to take into account not exactness of float value).
+    if (BlockLayoutByFrequency) {
+      infrequent_prob = MAX2(infrequent_prob, (float)BlockLayoutMinDiamondPercentage/110.0f);
+    }
+  }
+  // Check for highly predictable branch.  No point in CMOV'ing if
+  // we are going to predict accurately all the time.
+  if (iff->_prob < infrequent_prob ||
+      iff->_prob > (1.0f - infrequent_prob))
+    return NULL;
 
   // --------------
   // Now replace all Phis with CMOV's
   Node *cmov_ctrl = iff->in(0);
   uint flip = (lp->Opcode() == Op_IfTrue);
-  while( 1 ) {
+  while (1) {
     PhiNode* phi = NULL;
     for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
       Node *out = region->fast_out(i);
@@ -576,15 +606,15 @@
     }
     if (phi == NULL)  break;
 #ifndef PRODUCT
-    if( PrintOpto && VerifyLoopOptimizations ) tty->print_cr("CMOV");
+    if (PrintOpto && VerifyLoopOptimizations) tty->print_cr("CMOV");
 #endif
     // Move speculative ops
-    for( uint j = 1; j < region->req(); j++ ) {
+    for (uint j = 1; j < region->req(); j++) {
       Node *proj = region->in(j);
       Node *inp = phi->in(j);
       if (get_ctrl(inp) == proj) { // Found local op
 #ifndef PRODUCT
-        if( PrintOpto && VerifyLoopOptimizations ) {
+        if (PrintOpto && VerifyLoopOptimizations) {
           tty->print("  speculate: ");
           inp->dump();
         }
@@ -596,7 +626,15 @@
     register_new_node( cmov, cmov_ctrl );
     _igvn.replace_node( phi, cmov );
 #ifndef PRODUCT
-    if( VerifyLoopOptimizations ) verify();
+    if (TraceLoopOpts) {
+      tty->print("CMOV  ");
+      r_loop->dump_head();
+      if (Verbose) {
+        bol->in(1)->dump(1);
+        cmov->dump(1);
+      }
+    }
+    if (VerifyLoopOptimizations) verify();
 #endif
   }
 
@@ -676,14 +714,14 @@
 
   // Split 'n' through the merge point if it is profitable
   Node *phi = split_thru_phi( n, n_blk, policy );
-  if( !phi ) return n;
+  if (!phi) return n;
 
   // Found a Phi to split thru!
   // Replace 'n' with the new phi
   _igvn.replace_node( n, phi );
   // Moved a load around the loop, 'en-registering' something.
-  if( n_blk->Opcode() == Op_Loop && n->is_Load() &&
-      !phi->in(LoopNode::LoopBackControl)->is_Load() )
+  if (n_blk->is_Loop() && n->is_Load() &&
+      !phi->in(LoopNode::LoopBackControl)->is_Load())
     C->set_major_progress();
 
   return phi;
diff --git a/hotspot/src/share/vm/opto/machnode.cpp b/hotspot/src/share/vm/opto/machnode.cpp
index dd6c3c0..95ee4bf 100644
--- a/hotspot/src/share/vm/opto/machnode.cpp
+++ b/hotspot/src/share/vm/opto/machnode.cpp
@@ -484,6 +484,13 @@
   // Bind the offset lazily.
   if (offset == -1) {
     Compile::ConstantTable& constant_table = Compile::current()->constant_table();
+    // If called from Compile::scratch_emit_size assume the worst-case
+    // for load offsets: half the constant table size.
+    // NOTE: Don't return or calculate the actual offset (which might
+    // be zero) because that leads to problems with e.g. jumpXtnd on
+    // some architectures (cf. add-optimization in SPARC jumpXtnd).
+    if (Compile::current()->in_scratch_emit_size())
+      return constant_table.size() / 2;
     offset = constant_table.table_base_offset() + constant_table.find_offset(_constant);
     _constant.set_offset(offset);
   }
diff --git a/hotspot/src/share/vm/opto/macro.cpp b/hotspot/src/share/vm/opto/macro.cpp
index 1e12e36..b5f6453 100644
--- a/hotspot/src/share/vm/opto/macro.cpp
+++ b/hotspot/src/share/vm/opto/macro.cpp
@@ -1685,9 +1685,21 @@
 
 void PhaseMacroExpand::expand_allocate_array(AllocateArrayNode *alloc) {
   Node* length = alloc->in(AllocateNode::ALength);
+  InitializeNode* init = alloc->initialization();
+  Node* klass_node = alloc->in(AllocateNode::KlassNode);
+  ciKlass* k = _igvn.type(klass_node)->is_klassptr()->klass();
+  address slow_call_address;  // Address of slow call
+  if (init != NULL && init->is_complete_with_arraycopy() &&
+      k->is_type_array_klass()) {
+    // Don't zero type array during slow allocation in VM since
+    // it will be initialized later by arraycopy in compiled code.
+    slow_call_address = OptoRuntime::new_array_nozero_Java();
+  } else {
+    slow_call_address = OptoRuntime::new_array_Java();
+  }
   expand_allocate_common(alloc, length,
                          OptoRuntime::new_array_Type(),
-                         OptoRuntime::new_array_Java());
+                         slow_call_address);
 }
 
 //-----------------------mark_eliminated_locking_nodes-----------------------
diff --git a/hotspot/src/share/vm/opto/matcher.cpp b/hotspot/src/share/vm/opto/matcher.cpp
index 3244a94..1200d25 100644
--- a/hotspot/src/share/vm/opto/matcher.cpp
+++ b/hotspot/src/share/vm/opto/matcher.cpp
@@ -1915,7 +1915,7 @@
         set_dontcare(n);
         break;
       case Op_Jump:
-        mstack.push(n->in(1), Visit);         // Switch Value
+        mstack.push(n->in(1), Pre_Visit);     // Switch Value (could be shared)
         mstack.push(n->in(0), Pre_Visit);     // Visit Control input
         continue;                             // while (mstack.is_nonempty())
       case Op_StrComp:
diff --git a/hotspot/src/share/vm/opto/matcher.hpp b/hotspot/src/share/vm/opto/matcher.hpp
index 39b00b03..3d1a2dc 100644
--- a/hotspot/src/share/vm/opto/matcher.hpp
+++ b/hotspot/src/share/vm/opto/matcher.hpp
@@ -360,6 +360,12 @@
   // Anything this size or smaller may get converted to discrete scalar stores.
   static const int init_array_short_size;
 
+  // Some hardware needs 2 CMOV's for longs.
+  static const int long_cmove_cost();
+
+  // Some hardware have expensive CMOV for float and double.
+  static const int float_cmove_cost();
+
   // Should the Matcher clone shifts on addressing modes, expecting them to
   // be subsumed into complex addressing expressions or compute them into
   // registers?  True for Intel but false for most RISCs
diff --git a/hotspot/src/share/vm/opto/memnode.cpp b/hotspot/src/share/vm/opto/memnode.cpp
index ba09601..5d4afb0 100644
--- a/hotspot/src/share/vm/opto/memnode.cpp
+++ b/hotspot/src/share/vm/opto/memnode.cpp
@@ -1421,6 +1421,12 @@
     const TypeOopPtr *t_oop = addr_t->isa_oopptr();
     if (can_reshape && opt_mem->is_Phi() &&
         (t_oop != NULL) && t_oop->is_known_instance_field()) {
+      PhaseIterGVN *igvn = phase->is_IterGVN();
+      if (igvn != NULL && igvn->_worklist.member(opt_mem)) {
+        // Delay this transformation until memory Phi is processed.
+        phase->is_IterGVN()->_worklist.push(this);
+        return NULL;
+      }
       // Split instance field load through Phi.
       Node* result = split_through_phi(phase);
       if (result != NULL) return result;
@@ -2847,7 +2853,7 @@
 
 //---------------------------InitializeNode------------------------------------
 InitializeNode::InitializeNode(Compile* C, int adr_type, Node* rawoop)
-  : _is_complete(false),
+  : _is_complete(Incomplete),
     MemBarNode(C, adr_type, rawoop)
 {
   init_class_id(Class_Initialize);
@@ -2885,7 +2891,7 @@
 
 void InitializeNode::set_complete(PhaseGVN* phase) {
   assert(!is_complete(), "caller responsibility");
-  _is_complete = true;
+  _is_complete = Complete;
 
   // After this node is complete, it contains a bunch of
   // raw-memory initializations.  There is no need for
diff --git a/hotspot/src/share/vm/opto/memnode.hpp b/hotspot/src/share/vm/opto/memnode.hpp
index a9eacdd..d757b13 100644
--- a/hotspot/src/share/vm/opto/memnode.hpp
+++ b/hotspot/src/share/vm/opto/memnode.hpp
@@ -942,7 +942,12 @@
 class InitializeNode: public MemBarNode {
   friend class AllocateNode;
 
-  bool _is_complete;
+  enum {
+    Incomplete    = 0,
+    Complete      = 1,
+    WithArraycopy = 2
+  };
+  int _is_complete;
 
 public:
   enum {
@@ -976,10 +981,12 @@
   // An InitializeNode must completed before macro expansion is done.
   // Completion requires that the AllocateNode must be followed by
   // initialization of the new memory to zero, then to any initializers.
-  bool is_complete() { return _is_complete; }
+  bool is_complete() { return _is_complete != Incomplete; }
+  bool is_complete_with_arraycopy() { return (_is_complete & WithArraycopy) != 0; }
 
   // Mark complete.  (Must not yet be complete.)
   void set_complete(PhaseGVN* phase);
+  void set_complete_with_arraycopy() { _is_complete = Complete | WithArraycopy; }
 
 #ifdef ASSERT
   // ensure all non-degenerate stores are ordered and non-overlapping
diff --git a/hotspot/src/share/vm/opto/phaseX.cpp b/hotspot/src/share/vm/opto/phaseX.cpp
index 7b5d6cd..99b7393 100644
--- a/hotspot/src/share/vm/opto/phaseX.cpp
+++ b/hotspot/src/share/vm/opto/phaseX.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -322,11 +322,12 @@
 void NodeHash::dump() {
   _total_inserts       += _inserts;
   _total_insert_probes += _insert_probes;
-  if( PrintCompilation && PrintOptoStatistics && Verbose && (_inserts > 0) ) { // PrintOptoGVN
-    if( PrintCompilation2 ) {
-      for( uint i=0; i<_max; i++ )
-      if( _table[i] )
-        tty->print("%d/%d/%d ",i,_table[i]->hash()&(_max-1),_table[i]->_idx);
+  if (PrintCompilation && PrintOptoStatistics && Verbose && (_inserts > 0)) {
+    if (WizardMode) {
+      for (uint i=0; i<_max; i++) {
+        if (_table[i])
+          tty->print("%d/%d/%d ",i,_table[i]->hash()&(_max-1),_table[i]->_idx);
+      }
     }
     tty->print("\nGVN Hash stats:  %d grows to %d max_size\n", _grows, _max);
     tty->print("  %d/%d (%8.1f%% full)\n", _inserts, _max, (double)_inserts/_max*100.0);
@@ -864,6 +865,10 @@
   // Pull from worklist; transform node;
   // If node has changed: update edge info and put uses on worklist.
   while( _worklist.size() ) {
+    if (C->check_node_count(NodeLimitFudgeFactor * 2,
+                            "out of nodes optimizing method")) {
+      return;
+    }
     Node *n  = _worklist.pop();
     if (++loop_count >= K * C->unique()) {
       debug_only(n->dump(4);)
diff --git a/hotspot/src/share/vm/opto/runtime.cpp b/hotspot/src/share/vm/opto/runtime.cpp
index 49c5521..b97f06a 100644
--- a/hotspot/src/share/vm/opto/runtime.cpp
+++ b/hotspot/src/share/vm/opto/runtime.cpp
@@ -102,6 +102,7 @@
 // Compiled code entry points
 address OptoRuntime::_new_instance_Java                           = NULL;
 address OptoRuntime::_new_array_Java                              = NULL;
+address OptoRuntime::_new_array_nozero_Java                       = NULL;
 address OptoRuntime::_multianewarray2_Java                        = NULL;
 address OptoRuntime::_multianewarray3_Java                        = NULL;
 address OptoRuntime::_multianewarray4_Java                        = NULL;
@@ -151,6 +152,7 @@
   // -------------------------------------------------------------------------------------------------------------------------------
   gen(env, _new_instance_Java              , new_instance_Type            , new_instance_C                  ,    0 , true , false, false);
   gen(env, _new_array_Java                 , new_array_Type               , new_array_C                     ,    0 , true , false, false);
+  gen(env, _new_array_nozero_Java          , new_array_Type               , new_array_nozero_C              ,    0 , true , false, false);
   gen(env, _multianewarray2_Java           , multianewarray2_Type         , multianewarray2_C               ,    0 , true , false, false);
   gen(env, _multianewarray3_Java           , multianewarray3_Type         , multianewarray3_C               ,    0 , true , false, false);
   gen(env, _multianewarray4_Java           , multianewarray4_Type         , multianewarray4_C               ,    0 , true , false, false);
@@ -308,6 +310,54 @@
   }
 JRT_END
 
+// array allocation without zeroing
+JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(klassOopDesc* array_type, int len, JavaThread *thread))
+  JRT_BLOCK;
+#ifndef PRODUCT
+  SharedRuntime::_new_array_ctr++;            // new array requires GC
+#endif
+  assert(check_compiled_frame(thread), "incorrect caller");
+
+  // Scavenge and allocate an instance.
+  oop result;
+
+  assert(Klass::cast(array_type)->oop_is_typeArray(), "should be called only for type array");
+  // The oopFactory likes to work with the element type.
+  BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
+  result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
+
+  // Pass oops back through thread local storage.  Our apparent type to Java
+  // is that we return an oop, but we can block on exit from this routine and
+  // a GC can trash the oop in C's return register.  The generated stub will
+  // fetch the oop from TLS after any possible GC.
+  deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
+  thread->set_vm_result(result);
+  JRT_BLOCK_END;
+
+  if (GraphKit::use_ReduceInitialCardMarks()) {
+    // inform GC that we won't do card marks for initializing writes.
+    new_store_pre_barrier(thread);
+  }
+
+  oop result = thread->vm_result();
+  if ((len > 0) && (result != NULL) &&
+      is_deoptimized_caller_frame(thread)) {
+    // Zero array here if the caller is deoptimized.
+    int size = ((typeArrayOop)result)->object_size();
+    BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
+    const size_t hs = arrayOopDesc::header_size(elem_type);
+    // Align to next 8 bytes to avoid trashing arrays's length.
+    const size_t aligned_hs = align_object_offset(hs);
+    HeapWord* obj = (HeapWord*)result;
+    if (aligned_hs > hs) {
+      Copy::zero_to_words(obj+hs, aligned_hs-hs);
+    }
+    // Optimized zeroing.
+    Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
+  }
+
+JRT_END
+
 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
 
 // multianewarray for 2 dimensions
@@ -965,10 +1015,13 @@
         force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc);
 
       if (handler_address == NULL) {
+        Handle original_exception(thread, exception());
         handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
         assert (handler_address != NULL, "must have compiled handler");
-        // Update the exception cache only when the unwind was not forced.
-        if (!force_unwind) {
+        // Update the exception cache only when the unwind was not forced
+        // and there didn't happen another exception during the computation of the
+        // compiled exception handler.
+        if (!force_unwind && original_exception() == exception()) {
           nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
         }
       } else {
@@ -1095,12 +1148,22 @@
     assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
     frame caller_frame = stub_frame.sender(&reg_map);
 
-    // bypass VM_DeoptimizeFrame and deoptimize the frame directly
+    // Deoptimize the caller frame.
     Deoptimization::deoptimize_frame(thread, caller_frame.id());
   }
 }
 
 
+bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) {
+  // Called from within the owner thread, so no need for safepoint
+  RegisterMap reg_map(thread);
+  frame stub_frame = thread->last_frame();
+  assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
+  frame caller_frame = stub_frame.sender(&reg_map);
+  return caller_frame.is_deoptimized_frame();
+}
+
+
 const TypeFunc *OptoRuntime::register_finalizer_Type() {
   // create input type (domain)
   const Type **fields = TypeTuple::fields(1);
diff --git a/hotspot/src/share/vm/opto/runtime.hpp b/hotspot/src/share/vm/opto/runtime.hpp
index a691da3..3970298 100644
--- a/hotspot/src/share/vm/opto/runtime.hpp
+++ b/hotspot/src/share/vm/opto/runtime.hpp
@@ -114,6 +114,7 @@
   // References to generated stubs
   static address _new_instance_Java;
   static address _new_array_Java;
+  static address _new_array_nozero_Java;
   static address _multianewarray2_Java;
   static address _multianewarray3_Java;
   static address _multianewarray4_Java;
@@ -143,6 +144,7 @@
 
   // Allocate storage for a objArray or typeArray
   static void new_array_C(klassOopDesc* array_klass, int len, JavaThread *thread);
+  static void new_array_nozero_C(klassOopDesc* array_klass, int len, JavaThread *thread);
 
   // Post-slow-path-allocation, pre-initializing-stores step for
   // implementing ReduceInitialCardMarks
@@ -173,6 +175,7 @@
   static address handle_exception_C_helper(JavaThread* thread, nmethod*& nm);
   static address rethrow_C                (oopDesc* exception, JavaThread *thread, address return_pc );
   static void deoptimize_caller_frame     (JavaThread *thread, bool doit);
+  static bool is_deoptimized_caller_frame (JavaThread *thread);
 
   // CodeBlob support
   // ===================================================================
@@ -208,6 +211,7 @@
   // access to runtime stubs entry points for java code
   static address new_instance_Java()                     { return _new_instance_Java; }
   static address new_array_Java()                        { return _new_array_Java; }
+  static address new_array_nozero_Java()                 { return _new_array_nozero_Java; }
   static address multianewarray2_Java()                  { return _multianewarray2_Java; }
   static address multianewarray3_Java()                  { return _multianewarray3_Java; }
   static address multianewarray4_Java()                  { return _multianewarray4_Java; }
diff --git a/hotspot/src/share/vm/precompiled.hpp b/hotspot/src/share/vm/precompiled/precompiled.hpp
similarity index 100%
rename from hotspot/src/share/vm/precompiled.hpp
rename to hotspot/src/share/vm/precompiled/precompiled.hpp
diff --git a/hotspot/src/share/vm/prims/forte.cpp b/hotspot/src/share/vm/prims/forte.cpp
index f3a0878..d5eb0a6 100644
--- a/hotspot/src/share/vm/prims/forte.cpp
+++ b/hotspot/src/share/vm/prims/forte.cpp
@@ -621,6 +621,11 @@
 // Method to let libcollector know about a dynamically loaded function.
 // Because it is weakly bound, the calls become NOP's when the library
 // isn't present.
+#ifdef __APPLE__
+// XXXDARWIN: Link errors occur even when __attribute__((weak_import))
+// is added
+#define collector_func_load(x0,x1,x2,x3,x4,x5,x6) (0)
+#else
 void    collector_func_load(char* name,
                             void* null_argument_1,
                             void* null_argument_2,
@@ -631,6 +636,7 @@
 #pragma weak collector_func_load
 #define collector_func_load(x0,x1,x2,x3,x4,x5,x6) \
         ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),0 : 0 )
+#endif // __APPLE__
 #endif // !_WINDOWS
 
 } // end extern "C"
diff --git a/hotspot/src/share/vm/prims/jni.cpp b/hotspot/src/share/vm/prims/jni.cpp
index 2134b3e..aef42cb 100644
--- a/hotspot/src/share/vm/prims/jni.cpp
+++ b/hotspot/src/share/vm/prims/jni.cpp
@@ -82,6 +82,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 static jint CurrentVersion = JNI_VERSION_1_6;
 
@@ -106,6 +110,7 @@
 //   return_value = 5;
 //   return return_value;
 // JNI_END
+#ifndef USDT2
 #define DT_RETURN_MARK_DECL(name, type)                                    \
   HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type);                \
   DTRACE_ONLY(                                                             \
@@ -130,6 +135,30 @@
     }                                                                      \
   )
 
+#else /* USDT2 */
+
+#define DT_RETURN_MARK_DECL(name, type, probe)                             \
+  DTRACE_ONLY(                                                             \
+    class DTraceReturnProbeMark_##name {                                   \
+     public:                                                               \
+      const type& _ret_ref;                                                \
+      DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {}         \
+      ~DTraceReturnProbeMark_##name() {                                    \
+        probe;                                                             \
+      }                                                                    \
+    }                                                                      \
+  )
+// Void functions are simpler since there's no return value
+#define DT_VOID_RETURN_MARK_DECL(name, probe)                              \
+  DTRACE_ONLY(                                                             \
+    class DTraceReturnProbeMark_##name {                                   \
+     public:                                                               \
+      ~DTraceReturnProbeMark_##name() {                                    \
+        probe;                                                             \
+      }                                                                    \
+    }                                                                      \
+  )
+#endif /* USDT2 */
 
 // Place these macros in the function to mark the return.  Non-void
 // functions need the type and address of the return value.
@@ -158,9 +187,15 @@
 
 // Choose DT_RETURN_MARK macros  based on the type: float/double -> void
 // (dtrace doesn't do FP yet)
+#ifndef USDT2
 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \
   FP_SELECT(TypeName, \
     DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) )
+#else /* USDT2 */
+#define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe)    \
+  FP_SELECT(TypeName, \
+    DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) )
+#endif /* USDT2 */
 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \
   FP_SELECT(TypeName, \
     DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) )
@@ -319,14 +354,24 @@
 
 // Implementation of JNI entries
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(DefineClass, jclass);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(DefineClass, jclass
+                    , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef,
                                   const jbyte *buf, jsize bufLen))
   JNIWrapper("DefineClass");
 
+#ifndef USDT2
   DTRACE_PROBE5(hotspot_jni, DefineClass__entry,
     env, name, loaderRef, buf, bufLen);
+#else /* USDT2 */
+  HOTSPOT_JNI_DEFINECLASS_ENTRY(
+    env, (char*) name, loaderRef, (char*) buf, bufLen);
+#endif /* USDT2 */
   jclass cls = NULL;
   DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls);
 
@@ -372,11 +417,21 @@
 
 static bool first_time_FindClass = true;
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(FindClass, jclass);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(FindClass, jclass
+                    , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name))
   JNIWrapper("FindClass");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name);
+#else /* USDT2 */
+  HOTSPOT_JNI_FINDCLASS_ENTRY(
+                              env, (char *)name);
+#endif /* USDT2 */
 
   jclass result = NULL;
   DT_RETURN_MARK(FindClass, jclass, (const jclass&)result);
@@ -440,11 +495,21 @@
   return result;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
+                    , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
   JNIWrapper("FromReflectedMethod");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method);
+#else /* USDT2 */
+  HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(
+                                        env, method);
+#endif /* USDT2 */
   jmethodID ret = NULL;
   DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);
 
@@ -471,11 +536,21 @@
   return ret;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(FromReflectedField, jfieldID
+                    , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field))
   JNIWrapper("FromReflectedField");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field);
+#else /* USDT2 */
+  HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(
+                                       env, field);
+#endif /* USDT2 */
   jfieldID ret = NULL;
   DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret);
 
@@ -510,11 +585,21 @@
   return ret;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(ToReflectedMethod, jobject
+                    , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic))
   JNIWrapper("ToReflectedMethod");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic);
+#else /* USDT2 */
+  HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(
+                                      env, cls, (uintptr_t) method_id, isStatic);
+#endif /* USDT2 */
   jobject ret = NULL;
   DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret);
 
@@ -530,11 +615,21 @@
   return ret;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(GetSuperclass, jclass);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetSuperclass, jclass
+                    , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub))
   JNIWrapper("GetSuperclass");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSUPERCLASS_ENTRY(
+                                  env, sub);
+#endif /* USDT2 */
   jclass obj = NULL;
   DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj);
 
@@ -563,13 +658,23 @@
 
 JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super))
   JNIWrapper("IsSubclassOf");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super);
+#else /* USDT2 */
+  HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY(
+                                     env, sub, super);
+#endif /* USDT2 */
   oop sub_mirror   = JNIHandles::resolve_non_null(sub);
   oop super_mirror = JNIHandles::resolve_non_null(super);
   if (java_lang_Class::is_primitive(sub_mirror) ||
       java_lang_Class::is_primitive(super_mirror)) {
     jboolean ret = (sub_mirror == super_mirror);
+#ifndef USDT2
     DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret);
+#else /* USDT2 */
+    HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(
+                                        ret);
+#endif /* USDT2 */
     return ret;
   }
   klassOop sub_klass   = java_lang_Class::as_klassOop(sub_mirror);
@@ -577,15 +682,30 @@
   assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom");
   jboolean ret = Klass::cast(sub_klass)->is_subtype_of(super_klass) ?
                    JNI_TRUE : JNI_FALSE;
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(
+                                      ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(Throw, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(Throw, jint
+                    , HOTSPOT_JNI_THROW_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj))
   JNIWrapper("Throw");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj);
+#else /* USDT2 */
+  HOTSPOT_JNI_THROW_ENTRY(
+ env, obj);
+#endif /* USDT2 */
   jint ret = JNI_OK;
   DT_RETURN_MARK(Throw, jint, (const jint&)ret);
 
@@ -593,11 +713,21 @@
   ShouldNotReachHere();
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(ThrowNew, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(ThrowNew, jint
+                    , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message))
   JNIWrapper("ThrowNew");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message);
+#else /* USDT2 */
+  HOTSPOT_JNI_THROWNEW_ENTRY(
+                             env, clazz, (char *) message);
+#endif /* USDT2 */
   jint ret = JNI_OK;
   DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret);
 
@@ -626,18 +756,33 @@
 
 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env))
   JNIWrapper("ExceptionOccurred");
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env);
+#else /* USDT2 */
+  HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY(
+                                      env);
+#endif /* USDT2 */
   jni_check_async_exceptions(thread);
   oop exception = thread->pending_exception();
   jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN(
+                                       ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 
 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env))
   JNIWrapper("ExceptionDescribe");
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env);
+#else /* USDT2 */
+  HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY(
+                                      env);
+#endif /* USDT2 */
   if (thread->has_pending_exception()) {
     Handle ex(thread, thread->pending_exception());
     thread->clear_pending_exception();
@@ -673,13 +818,23 @@
       }
     }
   }
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN(
+                                       );
+#endif /* USDT2 */
 JNI_END
 
 
 JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env))
   JNIWrapper("ExceptionClear");
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env);
+#else /* USDT2 */
+  HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY(
+                                   env);
+#endif /* USDT2 */
 
   // The jni code might be using this API to clear java thrown exception.
   // So just mark jvmti thread exception state as exception caught.
@@ -688,13 +843,23 @@
     state->set_exception_caught();
   }
   thread->clear_pending_exception();
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, ExceptionClear__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN(
+                                    );
+#endif /* USDT2 */
 JNI_END
 
 
 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg))
   JNIWrapper("FatalError");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg);
+#else /* USDT2 */
+  HOTSPOT_JNI_FATALERROR_ENTRY(
+                               env, (char *) msg);
+#endif /* USDT2 */
   tty->print_cr("FATAL ERROR in native method: %s", msg);
   thread->print_stack();
   os::abort(); // Dump core and abort
@@ -703,10 +868,20 @@
 
 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity))
   JNIWrapper("PushLocalFrame");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity);
+#else /* USDT2 */
+  HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY(
+                                   env, capacity);
+#endif /* USDT2 */
   //%note jni_11
   if (capacity < 0 && capacity > MAX_REASONABLE_LOCAL_CAPACITY) {
+#ifndef USDT2
     DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR);
+#else /* USDT2 */
+    HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(
+                                      (uint32_t)JNI_ERR);
+#endif /* USDT2 */
     return JNI_ERR;
   }
   JNIHandleBlock* old_handles = thread->active_handles();
@@ -715,14 +890,24 @@
   new_handles->set_pop_frame_link(old_handles);
   thread->set_active_handles(new_handles);
   jint ret = JNI_OK;
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(
+                                    ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 
 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result))
   JNIWrapper("PopLocalFrame");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result);
+#else /* USDT2 */
+  HOTSPOT_JNI_POPLOCALFRAME_ENTRY(
+                                  env, result);
+#endif /* USDT2 */
   //%note jni_11
   Handle result_handle(thread, JNIHandles::resolve(result));
   JNIHandleBlock* old_handles = thread->active_handles();
@@ -737,71 +922,141 @@
     JNIHandleBlock::release_block(old_handles, thread); // may block
     result = JNIHandles::make_local(thread, result_handle());
   }
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result);
+#else /* USDT2 */
+  HOTSPOT_JNI_POPLOCALFRAME_RETURN(
+                                   result);
+#endif /* USDT2 */
   return result;
 JNI_END
 
 
 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref))
   JNIWrapper("NewGlobalRef");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWGLOBALREF_ENTRY(
+                                 env, ref);
+#endif /* USDT2 */
   Handle ref_handle(thread, JNIHandles::resolve(ref));
   jobject ret = JNIHandles::make_global(ref_handle);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWGLOBALREF_RETURN(
+                                  ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 // Must be JNI_ENTRY (with HandleMark)
 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref))
   JNIWrapper("DeleteGlobalRef");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref);
+#else /* USDT2 */
+  HOTSPOT_JNI_DELETEGLOBALREF_ENTRY(
+                                    env, ref);
+#endif /* USDT2 */
   JNIHandles::destroy_global(ref);
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_DELETEGLOBALREF_RETURN(
+                                     );
+#endif /* USDT2 */
 JNI_END
 
 JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj))
   JNIWrapper("DeleteLocalRef");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj);
+#else /* USDT2 */
+  HOTSPOT_JNI_DELETELOCALREF_ENTRY(
+                                   env, obj);
+#endif /* USDT2 */
   JNIHandles::destroy_local(obj);
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_DELETELOCALREF_RETURN(
+                                    );
+#endif /* USDT2 */
 JNI_END
 
 JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2))
   JNIWrapper("IsSameObject");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2);
+#else /* USDT2 */
+  HOTSPOT_JNI_ISSAMEOBJECT_ENTRY(
+                                 env, r1, r2);
+#endif /* USDT2 */
   oop a = JNIHandles::resolve(r1);
   oop b = JNIHandles::resolve(r2);
   jboolean ret = (a == b) ? JNI_TRUE : JNI_FALSE;
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, IsSameObject__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_ISSAMEOBJECT_RETURN(
+                                  ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 
 JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref))
   JNIWrapper("NewLocalRef");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, NewLocalRef__entry, env, ref);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWLOCALREF_ENTRY(
+                                env, ref);
+#endif /* USDT2 */
   jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref));
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, NewLocalRef__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWLOCALREF_RETURN(
+                                 ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity))
   JNIWrapper("EnsureLocalCapacity");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, EnsureLocalCapacity__entry, env, capacity);
+#else /* USDT2 */
+  HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY(
+                                        env, capacity);
+#endif /* USDT2 */
   jint ret;
   if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) {
     ret = JNI_OK;
   } else {
     ret = JNI_ERR;
   }
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, EnsureLocalCapacity__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN(
+                                         ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 // Return the Handle Type
 JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj))
   JNIWrapper("GetObjectRefType");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetObjectRefType__entry, env, obj);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY(
+                                     env, obj);
+#endif /* USDT2 */
   jobjectRefType ret;
   if (JNIHandles::is_local_handle(thread, obj) ||
       JNIHandles::is_frame_handle(thread, obj))
@@ -812,7 +1067,12 @@
     ret = JNIWeakGlobalRefType;
   else
     ret = JNIInvalidRefType;
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetObjectRefType__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN(
+                                      (void *) ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
@@ -1163,12 +1423,22 @@
   return ih;
 }
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(AllocObject, jobject);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(AllocObject, jobject
+                    , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
   JNIWrapper("AllocObject");
 
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, AllocObject__entry, env, clazz);
+#else /* USDT2 */
+  HOTSPOT_JNI_ALLOCOBJECT_ENTRY(
+                                env, clazz);
+#endif /* USDT2 */
   jobject ret = NULL;
   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
 
@@ -1177,11 +1447,21 @@
   return ret;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(NewObjectA, jobject);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(NewObjectA, jobject
+                    , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
   JNIWrapper("NewObjectA");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, NewObjectA__entry, env, clazz, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWOBJECTA_ENTRY(
+                               env, clazz, (uintptr_t) methodID);
+#endif /* USDT2 */
   jobject obj = NULL;
   DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj);
 
@@ -1193,11 +1473,21 @@
   return obj;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(NewObjectV, jobject);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(NewObjectV, jobject
+                    , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
   JNIWrapper("NewObjectV");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, NewObjectV__entry, env, clazz, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWOBJECTV_ENTRY(
+                               env, clazz, (uintptr_t) methodID);
+#endif /* USDT2 */
   jobject obj = NULL;
   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
 
@@ -1209,11 +1499,21 @@
   return obj;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(NewObject, jobject);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(NewObject, jobject
+                    , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
   JNIWrapper("NewObject");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, NewObject__entry, env, clazz, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWOBJECT_ENTRY(
+                              env, clazz, (uintptr_t) methodID);
+#endif /* USDT2 */
   jobject obj = NULL;
   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
 
@@ -1231,17 +1531,32 @@
 
 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
   JNIWrapper("GetObjectClass");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetObjectClass__entry, env, obj);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(
+                                   env, obj);
+#endif /* USDT2 */
   klassOop k = JNIHandles::resolve_non_null(obj)->klass();
   jclass ret =
     (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetObjectClass__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETOBJECTCLASS_RETURN(
+                                    ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz))
   JNIWrapper("IsInstanceOf");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, IsInstanceOf__entry, env, obj, clazz);
+#else /* USDT2 */
+  HOTSPOT_JNI_ISINSTANCEOF_ENTRY(
+                                 env, obj, clazz);
+#endif /* USDT2 */
   jboolean ret = JNI_TRUE;
   if (obj != NULL) {
     ret = JNI_FALSE;
@@ -1251,7 +1566,12 @@
       ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE;
     }
   }
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, IsInstanceOf__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_ISINSTANCEOF_RETURN(
+                                  ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
@@ -1313,9 +1633,19 @@
 JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz,
           const char *name, const char *sig))
   JNIWrapper("GetMethodID");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, GetMethodID__entry, env, clazz, name, sig);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETMETHODID_ENTRY(
+                                env, clazz, (char *) name, (char *) sig);
+#endif /* USDT2 */
   jmethodID ret = get_method_id(env, clazz, name, sig, false, thread);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetMethodID__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETMETHODID_RETURN(
+                                 (uintptr_t) ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
@@ -1323,9 +1653,19 @@
 JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz,
           const char *name, const char *sig))
   JNIWrapper("GetStaticMethodID");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, GetStaticMethodID__entry, env, clazz, name, sig);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTATICMETHODID_ENTRY(
+                                      env, (char *) clazz, (char *) name, (char *)sig);
+#endif /* USDT2 */
   jmethodID ret = get_method_id(env, clazz, name, sig, true, thread);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetStaticMethodID__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTATICMETHODID_RETURN(
+                                       (uintptr_t) ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
@@ -1335,7 +1675,7 @@
 // Calling Methods
 //
 
-
+#ifndef USDT2
 #define DEFINE_CALLMETHOD(ResultType, Result, Tag) \
 \
   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType);\
@@ -1346,7 +1686,7 @@
           jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \
   JNIWrapper("Call" XSTR(Result) "Method"); \
 \
-  DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID);\
+  DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID); \
   ResultType ret = 0;\
   DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \
                      (const ResultType&)ret);\
@@ -1366,7 +1706,7 @@
           jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \
   JNIWrapper("Call" XSTR(Result) "MethodV"); \
 \
-  DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID);\
+  DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID); \
   ResultType ret = 0;\
   DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \
                      (const ResultType&)ret);\
@@ -1382,7 +1722,7 @@
 JNI_ENTRY(ResultType, \
           jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \
   JNIWrapper("Call" XSTR(Result) "MethodA"); \
-  DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID);\
+  DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID); \
   ResultType ret = 0;\
   DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \
                      (const ResultType&)ret);\
@@ -1410,9 +1750,183 @@
 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV);
 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA);
 
+#else /* USDT2 */
+
+#define DEFINE_CALLMETHOD(ResultType, Result, Tag \
+                          , EntryProbe, ReturnProbe)    \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType \
+                          , ReturnProbe);                          \
+\
+JNI_ENTRY(ResultType, \
+          jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \
+  JNIWrapper("Call" XSTR(Result) "Method"); \
+\
+  EntryProbe; \
+  ResultType ret = 0;\
+  DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \
+                     (const ResultType&)ret);\
+\
+  va_list args; \
+  va_start(args, methodID); \
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherVaArg ap(methodID, args); \
+  jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
+  va_end(args); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN
+                  , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHOD(jbyte,    Byte,    T_BYTE
+                  , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHOD(jchar,    Char,    T_CHAR
+                  , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHOD(jshort,   Short,   T_SHORT
+                  , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref))
+
+DEFINE_CALLMETHOD(jobject,  Object,  T_OBJECT
+                  , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHOD(jint,     Int,     T_INT,
+                  HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHOD(jlong,    Long,    T_LONG
+                  , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref))
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_CALLMETHOD(jfloat,   Float,   T_FLOAT
+                  , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLFLOATMETHOD_RETURN())
+DEFINE_CALLMETHOD(jdouble,  Double,  T_DOUBLE
+                  , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN())
+
+#define DEFINE_CALLMETHODV(ResultType, Result, Tag \
+                          , EntryProbe, ReturnProbe)    \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType \
+                          , ReturnProbe);                          \
+\
+JNI_ENTRY(ResultType, \
+          jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \
+  JNIWrapper("Call" XSTR(Result) "MethodV"); \
+\
+  EntryProbe;\
+  ResultType ret = 0;\
+  DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \
+                     (const ResultType&)ret);\
+\
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherVaArg ap(methodID, args); \
+  jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLMETHODV(jboolean, Boolean, T_BOOLEAN
+                  , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODV(jbyte,    Byte,    T_BYTE
+                  , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODV(jchar,    Char,    T_CHAR
+                  , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODV(jshort,   Short,   T_SHORT
+                  , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref))
+
+DEFINE_CALLMETHODV(jobject,  Object,  T_OBJECT
+                  , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODV(jint,     Int,     T_INT,
+                  HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODV(jlong,    Long,    T_LONG
+                  , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref))
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_CALLMETHODV(jfloat,   Float,   T_FLOAT
+                  , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLFLOATMETHOD_RETURN())
+DEFINE_CALLMETHODV(jdouble,  Double,  T_DOUBLE
+                  , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN())
+
+#define DEFINE_CALLMETHODA(ResultType, Result, Tag \
+                          , EntryProbe, ReturnProbe)    \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType \
+                          , ReturnProbe);                          \
+\
+JNI_ENTRY(ResultType, \
+          jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \
+  JNIWrapper("Call" XSTR(Result) "MethodA"); \
+  EntryProbe; \
+  ResultType ret = 0;\
+  DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \
+                     (const ResultType&)ret);\
+\
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherArray ap(methodID, args); \
+  jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLMETHODA(jboolean, Boolean, T_BOOLEAN
+                  , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODA(jbyte,    Byte,    T_BYTE
+                  , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODA(jchar,    Char,    T_CHAR
+                  , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODA(jshort,   Short,   T_SHORT
+                  , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref))
+
+DEFINE_CALLMETHODA(jobject,  Object,  T_OBJECT
+                  , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODA(jint,     Int,     T_INT,
+                  HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLMETHODA(jlong,    Long,    T_LONG
+                  , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref))
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_CALLMETHODA(jfloat,   Float,   T_FLOAT
+                  , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLFLOATMETHOD_RETURN())
+DEFINE_CALLMETHODA(jdouble,  Double,  T_DOUBLE
+                  , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
+                  HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN())
+
+DT_VOID_RETURN_MARK_DECL(CallVoidMethod, HOTSPOT_JNI_CALLVOIDMETHOD_RETURN());
+DT_VOID_RETURN_MARK_DECL(CallVoidMethodV, HOTSPOT_JNI_CALLVOIDMETHODV_RETURN());
+DT_VOID_RETURN_MARK_DECL(CallVoidMethodA, HOTSPOT_JNI_CALLVOIDMETHODA_RETURN());
+
+#endif /* USDT2 */
+
 JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...))
   JNIWrapper("CallVoidMethod");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, CallVoidMethod__entry, env, obj, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY(
+                                   env, obj, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallVoidMethod);
 
   va_list args;
@@ -1426,7 +1940,12 @@
 
 JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args))
   JNIWrapper("CallVoidMethodV");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, CallVoidMethodV__entry, env, obj, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY(
+                                    env, obj, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallVoidMethodV);
 
   JavaValue jvalue(T_VOID);
@@ -1437,7 +1956,12 @@
 
 JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args))
   JNIWrapper("CallVoidMethodA");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, CallVoidMethodA__entry, env, obj, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY(
+                                    env, obj, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallVoidMethodA);
 
   JavaValue jvalue(T_VOID);
@@ -1446,6 +1970,7 @@
 JNI_END
 
 
+#ifndef USDT2
 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag) \
 \
   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType);\
@@ -1518,11 +2043,188 @@
 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV);
 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA);
 
+#else /* USDT2 */
+
+#define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag \
+                                    , EntryProbe, ReturnProbe)      \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType \
+                          , ReturnProbe);\
+\
+JNI_ENTRY(ResultType, \
+          jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \
+  JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \
+\
+  EntryProbe;\
+  ResultType ret;\
+  DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \
+                     (const ResultType&)ret);\
+\
+  va_list args; \
+  va_start(args, methodID); \
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherVaArg ap(methodID, args); \
+  jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
+  va_end(args); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN
+                            , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHOD(jbyte,    Byte,    T_BYTE
+                            , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHOD(jchar,    Char,    T_CHAR
+                            , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHOD(jshort,   Short,   T_SHORT
+                            , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(_ret_ref))
+
+DEFINE_CALLNONVIRTUALMETHOD(jobject,  Object,  T_OBJECT
+                            , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHOD(jint,     Int,     T_INT
+                            , HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHOD(jlong,    Long,    T_LONG
+                            , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+// Float and double probes don't return value because dtrace doesn't currently support it
+                            HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHOD(jfloat,   Float,   T_FLOAT
+                            , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN())
+DEFINE_CALLNONVIRTUALMETHOD(jdouble,  Double,  T_DOUBLE
+                            , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN())
+
+#define DEFINE_CALLNONVIRTUALMETHODV(ResultType, Result, Tag \
+                                    , EntryProbe, ReturnProbe)      \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType \
+                          , ReturnProbe);\
+\
+JNI_ENTRY(ResultType, \
+          jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \
+  JNIWrapper("CallNonvitual" XSTR(Result) "MethodV"); \
+\
+  EntryProbe;\
+  ResultType ret;\
+  DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \
+                     (const ResultType&)ret);\
+\
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherVaArg ap(methodID, args); \
+  jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLNONVIRTUALMETHODV(jboolean, Boolean, T_BOOLEAN
+                            , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODV(jbyte,    Byte,    T_BYTE
+                            , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODV(jchar,    Char,    T_CHAR
+                            , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODV(jshort,   Short,   T_SHORT
+                            , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(_ret_ref))
+
+DEFINE_CALLNONVIRTUALMETHODV(jobject,  Object,  T_OBJECT
+                            , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODV(jint,     Int,     T_INT
+                            , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODV(jlong,    Long,    T_LONG
+                            , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+// Float and double probes don't return value because dtrace doesn't currently support it
+                            HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODV(jfloat,   Float,   T_FLOAT
+                            , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN())
+DEFINE_CALLNONVIRTUALMETHODV(jdouble,  Double,  T_DOUBLE
+                            , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN())
+
+#define DEFINE_CALLNONVIRTUALMETHODA(ResultType, Result, Tag \
+                                    , EntryProbe, ReturnProbe)      \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType \
+                          , ReturnProbe);\
+\
+JNI_ENTRY(ResultType, \
+          jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \
+  JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \
+\
+  EntryProbe;\
+  ResultType ret;\
+  DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \
+                     (const ResultType&)ret);\
+\
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherArray ap(methodID, args); \
+  jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLNONVIRTUALMETHODA(jboolean, Boolean, T_BOOLEAN
+                            , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODA(jbyte,    Byte,    T_BYTE
+                            , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODA(jchar,    Char,    T_CHAR
+                            , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODA(jshort,   Short,   T_SHORT
+                            , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(_ret_ref))
+
+DEFINE_CALLNONVIRTUALMETHODA(jobject,  Object,  T_OBJECT
+                            , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODA(jint,     Int,     T_INT
+                            , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODA(jlong,    Long,    T_LONG
+                            , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+// Float and double probes don't return value because dtrace doesn't currently support it
+                            HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(_ret_ref))
+DEFINE_CALLNONVIRTUALMETHODA(jfloat,   Float,   T_FLOAT
+                            , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN())
+DEFINE_CALLNONVIRTUALMETHODA(jdouble,  Double,  T_DOUBLE
+                            , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
+                            HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN())
+
+DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod
+                         , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN());
+DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV
+                         , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN());
+DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA
+                         , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN());
+#endif /* USDT2 */
+
 JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...))
   JNIWrapper("CallNonvirtualVoidMethod");
 
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethod__entry,
                env, obj, cls, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY(
+               env, obj, cls, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod);
 
   va_list args;
@@ -1537,8 +2239,13 @@
 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args))
   JNIWrapper("CallNonvirtualVoidMethodV");
 
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodV__entry,
                env, obj, cls, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY(
+               env, obj, cls, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV);
 
   JavaValue jvalue(T_VOID);
@@ -1549,8 +2256,13 @@
 
 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args))
   JNIWrapper("CallNonvirtualVoidMethodA");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodA__entry,
                 env, obj, cls, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY(
+                env, obj, cls, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA);
   JavaValue jvalue(T_VOID);
   JNI_ArgumentPusherArray ap(methodID, args);
@@ -1558,6 +2270,7 @@
 JNI_END
 
 
+#ifndef USDT2
 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag) \
 \
   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType);\
@@ -1630,9 +2343,190 @@
 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV);
 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA);
 
+#else /* USDT2 */
+
+#define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag \
+                                , EntryProbe, ResultProbe) \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType \
+                          , ResultProbe);                               \
+\
+JNI_ENTRY(ResultType, \
+          jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \
+  JNIWrapper("CallStatic" XSTR(Result) "Method"); \
+\
+  EntryProbe; \
+  ResultType ret = 0;\
+  DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \
+                     (const ResultType&)ret);\
+\
+  va_list args; \
+  va_start(args, methodID); \
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherVaArg ap(methodID, args); \
+  jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
+  va_end(args); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN
+                        , HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHOD(jbyte,    Byte,    T_BYTE
+                        , HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHOD(jchar,    Char,    T_CHAR
+                        , HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHOD(jshort,   Short,   T_SHORT
+                        , HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(_ret_ref));
+
+DEFINE_CALLSTATICMETHOD(jobject,  Object,  T_OBJECT
+                        , HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHOD(jint,     Int,     T_INT
+                        , HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHOD(jlong,    Long,    T_LONG
+                        , HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(_ret_ref));
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_CALLSTATICMETHOD(jfloat,   Float,   T_FLOAT
+                        , HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN());
+DEFINE_CALLSTATICMETHOD(jdouble,  Double,  T_DOUBLE
+                        , HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN());
+
+#define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \
+                                , EntryProbe, ResultProbe) \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \
+                          , ResultProbe);                               \
+\
+JNI_ENTRY(ResultType, \
+          jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \
+  JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \
+\
+  EntryProbe; \
+  ResultType ret = 0;\
+  DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \
+                     (const ResultType&)ret);\
+\
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherVaArg ap(methodID, args); \
+  /* Make sure class is initialized before trying to invoke its method */ \
+  KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls))); \
+  Klass::cast(k())->initialize(CHECK_0); \
+  jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
+  va_end(args); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN
+                        , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODV(jbyte,    Byte,    T_BYTE
+                        , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODV(jchar,    Char,    T_CHAR
+                        , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODV(jshort,   Short,   T_SHORT
+                        , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref));
+
+DEFINE_CALLSTATICMETHODV(jobject,  Object,  T_OBJECT
+                        , HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODV(jint,     Int,     T_INT
+                        , HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODV(jlong,    Long,    T_LONG
+                        , HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(_ret_ref));
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_CALLSTATICMETHODV(jfloat,   Float,   T_FLOAT
+                        , HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN());
+DEFINE_CALLSTATICMETHODV(jdouble,  Double,  T_DOUBLE
+                        , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN());
+
+#define DEFINE_CALLSTATICMETHODA(ResultType, Result, Tag \
+                                , EntryProbe, ResultProbe) \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType \
+                          , ResultProbe);                               \
+\
+JNI_ENTRY(ResultType, \
+          jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \
+  JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \
+\
+  EntryProbe; \
+  ResultType ret = 0;\
+  DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \
+                     (const ResultType&)ret);\
+\
+  JavaValue jvalue(Tag); \
+  JNI_ArgumentPusherArray ap(methodID, args); \
+  jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
+  ret = jvalue.get_##ResultType(); \
+  return ret;\
+JNI_END
+
+// the runtime type of subword integral basic types is integer
+DEFINE_CALLSTATICMETHODA(jboolean, Boolean, T_BOOLEAN
+                        , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODA(jbyte,    Byte,    T_BYTE
+                        , HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODA(jchar,    Char,    T_CHAR
+                        , HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODA(jshort,   Short,   T_SHORT
+                        , HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(_ret_ref));
+
+DEFINE_CALLSTATICMETHODA(jobject,  Object,  T_OBJECT
+                        , HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODA(jint,     Int,     T_INT
+                        , HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(_ret_ref));
+DEFINE_CALLSTATICMETHODA(jlong,    Long,    T_LONG
+                        , HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(_ret_ref));
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_CALLSTATICMETHODA(jfloat,   Float,   T_FLOAT
+                        , HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN());
+DEFINE_CALLSTATICMETHODA(jdouble,  Double,  T_DOUBLE
+                        , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
+                        HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN());
+
+DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod
+                         , HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN());
+DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV
+                         , HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN());
+DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA
+                         , HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN());
+#endif /* USDT2 */
+
 JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...))
   JNIWrapper("CallStaticVoidMethod");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethod__entry, env, cls, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY(
+                                         env, cls, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallStaticVoidMethod);
 
   va_list args;
@@ -1646,7 +2540,12 @@
 
 JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args))
   JNIWrapper("CallStaticVoidMethodV");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodV__entry, env, cls, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY(
+                                          env, cls, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallStaticVoidMethodV);
 
   JavaValue jvalue(T_VOID);
@@ -1657,7 +2556,12 @@
 
 JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args))
   JNIWrapper("CallStaticVoidMethodA");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodA__entry, env, cls, methodID);
+#else /* USDT2 */
+  HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY(
+                                          env, cls, (uintptr_t) methodID);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(CallStaticVoidMethodA);
 
   JavaValue jvalue(T_VOID);
@@ -1671,12 +2575,22 @@
 //
 
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(GetFieldID, jfieldID);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetFieldID, jfieldID
+                    , HOTSPOT_JNI_GETFIELDID_RETURN((uintptr_t)_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz,
           const char *name, const char *sig))
   JNIWrapper("GetFieldID");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, GetFieldID__entry, env, clazz, name, sig);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETFIELDID_ENTRY(
+                               env, clazz, (char *) name, (char *) sig);
+#endif /* USDT2 */
   jfieldID ret = 0;
   DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret);
 
@@ -1708,7 +2622,12 @@
 
 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
   JNIWrapper("GetObjectField");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(
+                                   env, obj, (uintptr_t) fieldID);
+#endif /* USDT2 */
   oop o = JNIHandles::resolve_non_null(obj);
   klassOop k = o->klass();
   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
@@ -1738,11 +2657,17 @@
     }
   }
 #endif // SERIALGC
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret);
+#else /* USDT2 */
+HOTSPOT_JNI_GETOBJECTFIELD_RETURN(
+                                  ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 
+#ifndef USDT2
 #define DEFINE_GETFIELD(Return,Fieldname,Result) \
 \
   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return);\
@@ -1776,6 +2701,61 @@
 DEFINE_GETFIELD(jfloat,   float,  Float)
 DEFINE_GETFIELD(jdouble,  double, Double)
 
+#else /* USDT2 */
+
+#define DEFINE_GETFIELD(Return,Fieldname,Result \
+  , EntryProbe, ReturnProbe) \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
+  , ReturnProbe); \
+\
+JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
+  JNIWrapper("Get" XSTR(Result) "Field"); \
+\
+  EntryProbe; \
+  Return ret = 0;\
+  DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
+\
+  oop o = JNIHandles::resolve_non_null(obj); \
+  klassOop k = o->klass(); \
+  int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
+  /* Keep JVMTI addition small and only check enabled flag here.       */ \
+  /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \
+  /* and creates a ResetNoHandleMark.                                   */ \
+  if (JvmtiExport::should_post_field_access()) { \
+    o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \
+  } \
+  ret = o->Fieldname##_field(offset); \
+  return ret; \
+JNI_END
+
+DEFINE_GETFIELD(jboolean, bool,   Boolean
+                , HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(_ret_ref))
+DEFINE_GETFIELD(jbyte,    byte,   Byte
+                , HOTSPOT_JNI_GETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETBYTEFIELD_RETURN(_ret_ref))
+DEFINE_GETFIELD(jchar,    char,   Char
+                , HOTSPOT_JNI_GETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETCHARFIELD_RETURN(_ret_ref))
+DEFINE_GETFIELD(jshort,   short,  Short
+                , HOTSPOT_JNI_GETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETSHORTFIELD_RETURN(_ret_ref))
+DEFINE_GETFIELD(jint,     int,    Int
+                , HOTSPOT_JNI_GETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETINTFIELD_RETURN(_ret_ref))
+DEFINE_GETFIELD(jlong,    long,   Long
+                , HOTSPOT_JNI_GETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETLONGFIELD_RETURN(_ret_ref))
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_GETFIELD(jfloat,   float,  Float
+                , HOTSPOT_JNI_GETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETFLOATFIELD_RETURN())
+DEFINE_GETFIELD(jdouble,  double, Double
+                , HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_GETDOUBLEFIELD_RETURN())
+#endif /* USDT2 */
+
 address jni_GetBooleanField_addr() {
   return (address)jni_GetBooleanField;
 }
@@ -1803,7 +2783,12 @@
 
 JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value))
   JNIWrapper("SetObjectField");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, SetObjectField__entry, env, obj, fieldID, value);
+#else /* USDT2 */
+  HOTSPOT_JNI_SETOBJECTFIELD_ENTRY(
+                                   env, obj, (uintptr_t) fieldID, value);
+#endif /* USDT2 */
   oop o = JNIHandles::resolve_non_null(obj);
   klassOop k = o->klass();
   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
@@ -1816,9 +2801,15 @@
     o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value);
   }
   o->obj_field_put(offset, JNIHandles::resolve(value));
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, SetObjectField__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_SETOBJECTFIELD_RETURN(
+);
+#endif /* USDT2 */
 JNI_END
 
+#ifndef USDT2
 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType) \
 \
 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
@@ -1853,12 +2844,74 @@
 DEFINE_SETFIELD(jfloat,   float,  Float,   'F', f)
 DEFINE_SETFIELD(jdouble,  double, Double,  'D', d)
 
+#else /* USDT2 */
+
+#define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \
+                        , EntryProbe, ReturnProbe) \
+\
+JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
+  JNIWrapper("Set" XSTR(Result) "Field"); \
+\
+  EntryProbe; \
+\
+  oop o = JNIHandles::resolve_non_null(obj); \
+  klassOop k = o->klass(); \
+  int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
+  /* Keep JVMTI addition small and only check enabled flag here.       */ \
+  /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \
+  /* and creates a ResetNoHandleMark.                                   */ \
+  if (JvmtiExport::should_post_field_modification()) { \
+    jvalue field_value; \
+    field_value.unionType = value; \
+    o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \
+  } \
+  o->Fieldname##_field_put(offset, value); \
+  ReturnProbe; \
+JNI_END
+
+DEFINE_SETFIELD(jboolean, bool,   Boolean, 'Z', z
+                , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
+                HOTSPOT_JNI_SETBOOLEANFIELD_RETURN())
+DEFINE_SETFIELD(jbyte,    byte,   Byte,    'B', b
+                , HOTSPOT_JNI_SETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
+                HOTSPOT_JNI_SETBYTEFIELD_RETURN())
+DEFINE_SETFIELD(jchar,    char,   Char,    'C', c
+                , HOTSPOT_JNI_SETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
+                HOTSPOT_JNI_SETCHARFIELD_RETURN())
+DEFINE_SETFIELD(jshort,   short,  Short,   'S', s
+                , HOTSPOT_JNI_SETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
+                HOTSPOT_JNI_SETSHORTFIELD_RETURN())
+DEFINE_SETFIELD(jint,     int,    Int,     'I', i
+                , HOTSPOT_JNI_SETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
+                HOTSPOT_JNI_SETINTFIELD_RETURN())
+DEFINE_SETFIELD(jlong,    long,   Long,    'J', j
+                , HOTSPOT_JNI_SETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
+                HOTSPOT_JNI_SETLONGFIELD_RETURN())
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_SETFIELD(jfloat,   float,  Float,   'F', f
+                , HOTSPOT_JNI_SETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_SETFLOATFIELD_RETURN())
+DEFINE_SETFIELD(jdouble,  double, Double,  'D', d
+                , HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
+                HOTSPOT_JNI_SETDOUBLEFIELD_RETURN())
+#endif /* USDT2 */
+
+#ifndef USDT2
 DT_RETURN_MARK_DECL(ToReflectedField, jobject);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(ToReflectedField, jobject
+                    , HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic))
   JNIWrapper("ToReflectedField");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, ToReflectedField__entry,
                 env, cls, fieldID, isStatic);
+#else /* USDT2 */
+  HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY(
+                env, cls, (uintptr_t) fieldID, isStatic);
+#endif /* USDT2 */
   jobject ret = NULL;
   DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret);
 
@@ -1888,12 +2941,22 @@
 //
 // Accessing Static Fields
 //
+#ifndef USDT2
 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID
+                    , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz,
           const char *name, const char *sig))
   JNIWrapper("GetStaticFieldID");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, GetStaticFieldID__entry, env, clazz, name, sig);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTATICFIELDID_ENTRY(
+                                     env, clazz, (char *) name, (char *) sig);
+#endif /* USDT2 */
   jfieldID ret = NULL;
   DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret);
 
@@ -1929,7 +2992,12 @@
 
 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID))
   JNIWrapper("GetStaticObjectField");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetStaticObjectField__entry, env, clazz, fieldID);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY(
+                                         env, clazz, (uintptr_t) fieldID);
+#endif /* USDT2 */
 #ifndef JNICHECK_KERNEL
   DEBUG_ONLY(klassOop param_k = jniCheck::validate_class(thread, clazz);)
 #endif // JNICHECK_KERNEL
@@ -1941,10 +3009,16 @@
     JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true);
   }
   jobject ret = JNIHandles::make_local(id->holder()->java_mirror()->obj_field(id->offset()));
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN(
+                                          ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
+#ifndef USDT2
 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \
 \
   DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return);\
@@ -1975,10 +3049,58 @@
 DEFINE_GETSTATICFIELD(jfloat,   float,  Float)
 DEFINE_GETSTATICFIELD(jdouble,  double, Double)
 
+#else /* USDT2 */
+
+#define DEFINE_GETSTATICFIELD(Return,Fieldname,Result \
+                              , EntryProbe, ReturnProbe) \
+\
+  DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return \
+                          , ReturnProbe);                                          \
+\
+JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \
+  JNIWrapper("GetStatic" XSTR(Result) "Field"); \
+  EntryProbe; \
+  Return ret = 0;\
+  DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \
+                     (const Return&)ret);\
+  JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
+  assert(id->is_static_field_id(), "invalid static field id"); \
+  /* Keep JVMTI addition small and only check enabled flag here. */ \
+  /* jni_GetField_probe() assumes that is okay to create handles. */ \
+  if (JvmtiExport::should_post_field_access()) { \
+    JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \
+  } \
+  ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \
+  return ret;\
+JNI_END
+
+DEFINE_GETSTATICFIELD(jboolean, bool,   Boolean
+                      , HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(_ret_ref))
+DEFINE_GETSTATICFIELD(jbyte,    byte,   Byte
+                      , HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(_ret_ref)   )
+DEFINE_GETSTATICFIELD(jchar,    char,   Char
+                      , HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(_ret_ref)   )
+DEFINE_GETSTATICFIELD(jshort,   short,  Short
+                      , HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(_ret_ref)  )
+DEFINE_GETSTATICFIELD(jint,     int,    Int
+                      , HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),     HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(_ret_ref)    )
+DEFINE_GETSTATICFIELD(jlong,    long,   Long
+                      , HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(_ret_ref)   )
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_GETSTATICFIELD(jfloat,   float,  Float
+                      , HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN()          )
+DEFINE_GETSTATICFIELD(jdouble,  double, Double
+                      , HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),  HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN()         )
+#endif /* USDT2 */
 
 JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value))
   JNIWrapper("SetStaticObjectField");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, SetStaticObjectField__entry, env, clazz, fieldID, value);
+#else /* USDT2 */
+ HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY(
+                                        env, clazz, (uintptr_t) fieldID, value);
+#endif /* USDT2 */
   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
   assert(id->is_static_field_id(), "invalid static field id");
   // Keep JVMTI addition small and only check enabled flag here.
@@ -1989,10 +3111,16 @@
     JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value);
   }
   id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value));
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN(
+                                          );
+#endif /* USDT2 */
 JNI_END
 
 
+#ifndef USDT2
 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \
 \
 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \
@@ -2024,6 +3152,54 @@
 DEFINE_SETSTATICFIELD(jfloat,   float,  Float,   'F', f)
 DEFINE_SETSTATICFIELD(jdouble,  double, Double,  'D', d)
 
+#else /* USDT2 */
+
+#define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType \
+                              , EntryProbe, ReturnProbe) \
+\
+JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \
+  JNIWrapper("SetStatic" XSTR(Result) "Field"); \
+  EntryProbe; \
+\
+  JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
+  assert(id->is_static_field_id(), "invalid static field id"); \
+  /* Keep JVMTI addition small and only check enabled flag here. */ \
+  /* jni_SetField_probe() assumes that is okay to create handles. */ \
+  if (JvmtiExport::should_post_field_modification()) { \
+    jvalue field_value; \
+    field_value.unionType = value; \
+    JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \
+  } \
+  id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \
+  ReturnProbe;\
+JNI_END
+
+DEFINE_SETSTATICFIELD(jboolean, bool,   Boolean, 'Z', z
+                      , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t)fieldID, value),
+                      HOTSPOT_JNI_SETBOOLEANFIELD_RETURN())
+DEFINE_SETSTATICFIELD(jbyte,    byte,   Byte,    'B', b
+                      , HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
+                      HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN())
+DEFINE_SETSTATICFIELD(jchar,    char,   Char,    'C', c
+                      , HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
+                      HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN())
+DEFINE_SETSTATICFIELD(jshort,   short,  Short,   'S', s
+                      , HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
+                      HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN())
+DEFINE_SETSTATICFIELD(jint,     int,    Int,     'I', i
+                      , HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
+                      HOTSPOT_JNI_SETSTATICINTFIELD_RETURN())
+DEFINE_SETSTATICFIELD(jlong,    long,   Long,    'J', j
+                      , HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
+                      HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN())
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_SETSTATICFIELD(jfloat,   float,  Float,   'F', f
+                      , HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
+                      HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN())
+DEFINE_SETSTATICFIELD(jdouble,  double, Double,  'D', d
+                      , HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
+                      HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN())
+#endif /* USDT2 */
 
 //
 // String Operations
@@ -2031,11 +3207,21 @@
 
 // Unicode Interface
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(NewString, jstring);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(NewString, jstring
+                    , HOTSPOT_JNI_NEWSTRING_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len))
   JNIWrapper("NewString");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, NewString__entry, env, unicodeChars, len);
+#else /* USDT2 */
+ HOTSPOT_JNI_NEWSTRING_ENTRY(
+                             env, (uint16_t *) unicodeChars, len);
+#endif /* USDT2 */
   jstring ret = NULL;
   DT_RETURN_MARK(NewString, jstring, (const jstring&)ret);
   oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL);
@@ -2046,9 +3232,19 @@
 
 JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string))
   JNIWrapper("GetStringLength");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetStringLength__entry, env, string);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY(
+                                    env, string);
+#endif /* USDT2 */
   jsize ret = java_lang_String::length(JNIHandles::resolve_non_null(string));
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetStringLength__return, ret);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGLENGTH_RETURN(
+                                    ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
@@ -2056,7 +3252,12 @@
 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars(
   JNIEnv *env, jstring string, jboolean *isCopy))
   JNIWrapper("GetStringChars");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetStringChars__entry, env, string, isCopy);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGCHARS_ENTRY(
+                                  env, string, (uintptr_t *) isCopy);
+#endif /* USDT2 */
   //%note jni_5
   if (isCopy != NULL) {
     *isCopy = JNI_TRUE;
@@ -2070,31 +3271,56 @@
     memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len);
   }
   buf[s_len] = 0;
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetStringChars__return, buf);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTRINGCHARS_RETURN(
+                                    buf);
+#endif /* USDT2 */
   return buf;
 JNI_END
 
 
 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars))
   JNIWrapper("ReleaseStringChars");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, ReleaseStringChars__entry, env, str, chars);
+#else /* USDT2 */
+  HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY(
+                                       env, str, (uint16_t *) chars);
+#endif /* USDT2 */
   //%note jni_6
   if (chars != NULL) {
     // Since String objects are supposed to be immutable, don't copy any
     // new data back.  A bad user will have to go after the char array.
     FreeHeap((void*) chars);
   }
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, ReleaseStringChars__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN(
+);
+#endif /* USDT2 */
 JNI_END
 
 
 // UTF Interface
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(NewStringUTF, jstring);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(NewStringUTF, jstring
+                    , HOTSPOT_JNI_NEWSTRINGUTF_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes))
   JNIWrapper("NewStringUTF");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, NewStringUTF__entry, env, bytes);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWSTRINGUTF_ENTRY(
+                                 env, (char *) bytes);
+#endif /* USDT2 */
   jstring ret;
   DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret);
 
@@ -2106,43 +3332,83 @@
 
 JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string))
   JNIWrapper("GetStringUTFLength");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetStringUTFLength__entry, env, string);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY(
+                                      env, string);
+#endif /* USDT2 */
   jsize ret = java_lang_String::utf8_length(JNIHandles::resolve_non_null(string));
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetStringUTFLength__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN(
+                                        ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 
 JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy))
   JNIWrapper("GetStringUTFChars");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetStringUTFChars__entry, env, string, isCopy);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY(
+                                     env, string, (uintptr_t *) isCopy);
+#endif /* USDT2 */
   oop java_string = JNIHandles::resolve_non_null(string);
   size_t length = java_lang_String::utf8_length(java_string);
   char* result = AllocateHeap(length + 1, "GetStringUTFChars");
   java_lang_String::as_utf8_string(java_string, result, (int) length + 1);
   if (isCopy != NULL) *isCopy = JNI_TRUE;
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN(
+                                      result);
+#endif /* USDT2 */
   return result;
 JNI_END
 
 
 JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars))
   JNIWrapper("ReleaseStringUTFChars");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, ReleaseStringUTFChars__entry, env, str, chars);
+#else /* USDT2 */
+ HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY(
+                                         env, str, (char *) chars);
+#endif /* USDT2 */
   if (chars != NULL) {
     FreeHeap((char*) chars);
   }
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, ReleaseStringUTFChars__return);
+#else /* USDT2 */
+HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN(
+);
+#endif /* USDT2 */
 JNI_END
 
 
 JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array))
   JNIWrapper("GetArrayLength");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetArrayLength__entry, env, array);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETARRAYLENGTH_ENTRY(
+                                  env, array);
+#endif /* USDT2 */
   arrayOop a = arrayOop(JNIHandles::resolve_non_null(array));
   assert(a->is_array(), "must be array");
   jsize ret = a->length();
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetArrayLength__return, ret);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETARRAYLENGTH_RETURN(
+                                   ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
@@ -2151,11 +3417,21 @@
 // Object Array Operations
 //
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray
+                    , HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement))
   JNIWrapper("NewObjectArray");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, NewObjectArray__entry, env, length, elementClass, initialElement);
+#else /* USDT2 */
+ HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY(
+                                  env, length, elementClass, initialElement);
+#endif /* USDT2 */
   jobjectArray ret = NULL;
   DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret);
   KlassHandle ek(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(elementClass)));
@@ -2173,11 +3449,21 @@
   return ret;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject
+                    , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index))
   JNIWrapper("GetObjectArrayElement");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetObjectArrayElement__entry, env, array, index);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY(
+                                         env, array, index);
+#endif /* USDT2 */
   jobject ret = NULL;
   DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret);
   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
@@ -2191,11 +3477,21 @@
   }
 JNI_END
 
+#ifndef USDT2
 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement);
+#else /* USDT2 */
+DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement
+                         , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN());
+#endif /* USDT2 */
 
 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value))
   JNIWrapper("SetObjectArrayElement");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, SetObjectArrayElement__entry, env, array, index, value);
+#else /* USDT2 */
+ HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY(
+                                         env, array, index, value);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(SetObjectArrayElement);
 
   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
@@ -2214,9 +3510,10 @@
 JNI_END
 
 
+#ifndef USDT2
 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result) \
 \
-  DT_RETURN_MARK_DECL(New##Result##Array, Return);\
+  DT_RETURN_MARK_DECL(New##Result##Array, Return); \
 \
 JNI_ENTRY(Return, \
           jni_New##Result##Array(JNIEnv *env, jsize len)) \
@@ -2239,6 +3536,51 @@
 DEFINE_NEWSCALARARRAY(jfloatArray,   new_singleArray, Float)
 DEFINE_NEWSCALARARRAY(jdoubleArray,  new_doubleArray, Double)
 
+#else /* USDT2 */
+
+#define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \
+                              ,EntryProbe,ReturnProbe)  \
+\
+  DT_RETURN_MARK_DECL(New##Result##Array, Return \
+                      , ReturnProbe); \
+\
+JNI_ENTRY(Return, \
+          jni_New##Result##Array(JNIEnv *env, jsize len)) \
+  JNIWrapper("New" XSTR(Result) "Array"); \
+  EntryProbe; \
+  Return ret = NULL;\
+  DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\
+\
+  oop obj= oopFactory::Allocator(len, CHECK_0); \
+  ret = (Return) JNIHandles::make_local(env, obj); \
+  return ret;\
+JNI_END
+
+DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray,   Boolean,
+                      HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(_ret_ref))
+DEFINE_NEWSCALARARRAY(jbyteArray,    new_byteArray,   Byte,
+                      HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWBYTEARRAY_RETURN(_ret_ref))
+DEFINE_NEWSCALARARRAY(jshortArray,   new_shortArray,  Short,
+                      HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWSHORTARRAY_RETURN(_ret_ref))
+DEFINE_NEWSCALARARRAY(jcharArray,    new_charArray,   Char,
+                      HOTSPOT_JNI_NEWCHARARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWCHARARRAY_RETURN(_ret_ref))
+DEFINE_NEWSCALARARRAY(jintArray,     new_intArray,    Int,
+                      HOTSPOT_JNI_NEWINTARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWINTARRAY_RETURN(_ret_ref))
+DEFINE_NEWSCALARARRAY(jlongArray,    new_longArray,   Long,
+                      HOTSPOT_JNI_NEWLONGARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWLONGARRAY_RETURN(_ret_ref))
+DEFINE_NEWSCALARARRAY(jfloatArray,   new_singleArray, Float,
+                      HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWFLOATARRAY_RETURN(_ret_ref))
+DEFINE_NEWSCALARARRAY(jdoubleArray,  new_doubleArray, Double,
+                      HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(env, len),
+                      HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(_ret_ref))
+#endif /* USDT2 */
 
 // Return an address which will fault if the caller writes to it.
 
@@ -2256,6 +3598,7 @@
 }
 
 
+#ifndef USDT2
 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) \
 \
 JNI_QUICK_ENTRY(ElementType*, \
@@ -2290,7 +3633,62 @@
 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float)
 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double)
 
+#else /* USDT2 */
 
+#define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag \
+                                      , EntryProbe, ReturnProbe) \
+\
+JNI_QUICK_ENTRY(ElementType*, \
+          jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \
+  JNIWrapper("Get" XSTR(Result) "ArrayElements"); \
+  EntryProbe; \
+  /* allocate an chunk of memory in c land */ \
+  typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
+  ElementType* result; \
+  int len = a->length(); \
+  if (len == 0) { \
+    /* Empty array: legal but useless, can't return NULL. \
+     * Return a pointer to something useless. \
+     * Avoid asserts in typeArrayOop. */ \
+    result = (ElementType*)get_bad_address(); \
+  } else { \
+    result = NEW_C_HEAP_ARRAY(ElementType, len); \
+    /* copy the array to the c chunk */ \
+    memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \
+  } \
+  if (isCopy) *isCopy = JNI_TRUE; \
+  ReturnProbe; \
+  return result; \
+JNI_END
+
+DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
+                              , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result))
+DEFINE_GETSCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
+                              , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result))
+DEFINE_GETSCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
+                              , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result))
+DEFINE_GETSCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
+                              , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(result))
+DEFINE_GETSCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
+                              , HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN((uint32_t*)result))
+DEFINE_GETSCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
+                              , HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(((uintptr_t*)result)))
+// Float and double probes don't return value because dtrace doesn't currently support it
+DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
+                              , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result))
+DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
+                              , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
+                              HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result))
+#endif /* USDT2 */
+
+#ifndef USDT2
 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag) \
 \
 JNI_QUICK_ENTRY(void, \
@@ -2320,6 +3718,56 @@
 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float)
 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double)
 
+#else /* USDT2 */
+
+#define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \
+                                          , EntryProbe, ReturnProbe);\
+\
+JNI_QUICK_ENTRY(void, \
+          jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \
+                                             ElementType *buf, jint mode)) \
+  JNIWrapper("Release" XSTR(Result) "ArrayElements"); \
+  EntryProbe; \
+  typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
+  int len = a->length(); \
+  if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
+    if ((mode == 0) || (mode == JNI_COMMIT)) { \
+      memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \
+    } \
+    if ((mode == 0) || (mode == JNI_ABORT)) { \
+      FreeHeap(buf); \
+    } \
+  } \
+  ReturnProbe; \
+JNI_END
+
+DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
+                                  , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
+                                  HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN())
+DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
+                                  , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode),
+                                  HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN())
+DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
+                                  ,  HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
+                                  HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN())
+DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
+                                  ,  HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
+                                  HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN())
+DEFINE_RELEASESCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
+                                  , HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(env, array, (uint32_t *) buf, mode),
+                                  HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN())
+DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
+                                  , HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
+                                  HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN())
+DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
+                                  , HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(env, array, (float *) buf, mode),
+                                  HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN())
+DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
+                                  , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode),
+                                  HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN())
+#endif /* USDT2 */
+
+#ifndef USDT2
 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \
   DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion);\
 \
@@ -2351,6 +3799,59 @@
 DEFINE_GETSCALARARRAYREGION(T_FLOAT,   jfloat,  Float,   float)
 DEFINE_GETSCALARARRAYREGION(T_DOUBLE,  jdouble, Double,  double)
 
+#else /* USDT2 */
+
+#define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
+                                    , EntryProbe, ReturnProbe); \
+  DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \
+                           , ReturnProbe); \
+\
+JNI_ENTRY(void, \
+jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
+             jsize len, ElementType *buf)) \
+  JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \
+  EntryProbe; \
+  DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \
+  typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
+  if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \
+    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
+  } else { \
+    if (len > 0) { \
+      int sc = typeArrayKlass::cast(src->klass())->log2_element_size(); \
+      memcpy((u_char*) buf, \
+             (u_char*) src->Tag##_at_addr(start), \
+             len << sc);                          \
+    } \
+  } \
+JNI_END
+
+DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool
+                            , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
+                            HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN());
+DEFINE_GETSCALARARRAYREGION(T_BYTE,    jbyte,   Byte,    byte
+                            ,  HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
+                            HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN());
+DEFINE_GETSCALARARRAYREGION(T_SHORT,   jshort,  Short,   short
+                            , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
+                            HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN());
+DEFINE_GETSCALARARRAYREGION(T_CHAR,    jchar,   Char,    char
+                            ,  HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf),
+                            HOTSPOT_JNI_GETCHARARRAYREGION_RETURN());
+DEFINE_GETSCALARARRAYREGION(T_INT,     jint,    Int,     int
+                            , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf),
+                            HOTSPOT_JNI_GETINTARRAYREGION_RETURN());
+DEFINE_GETSCALARARRAYREGION(T_LONG,    jlong,   Long,    long
+                            ,  HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
+                            HOTSPOT_JNI_GETLONGARRAYREGION_RETURN());
+DEFINE_GETSCALARARRAYREGION(T_FLOAT,   jfloat,  Float,   float
+                            , HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
+                            HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN());
+DEFINE_GETSCALARARRAYREGION(T_DOUBLE,  jdouble, Double,  double
+                            , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
+                            HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN());
+#endif /* USDT2 */
+
+#ifndef USDT2
 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \
   DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion);\
 \
@@ -2382,6 +3883,58 @@
 DEFINE_SETSCALARARRAYREGION(T_FLOAT,   jfloat,   Float,   float)
 DEFINE_SETSCALARARRAYREGION(T_DOUBLE,  jdouble,  Double,  double)
 
+#else /* USDT2 */
+
+#define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
+                                    , EntryProbe, ReturnProbe); \
+  DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \
+                           ,ReturnProbe);           \
+\
+JNI_ENTRY(void, \
+jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
+             jsize len, const ElementType *buf)) \
+  JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \
+  EntryProbe; \
+  DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \
+  typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
+  if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \
+    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
+  } else { \
+    if (len > 0) { \
+      int sc = typeArrayKlass::cast(dst->klass())->log2_element_size(); \
+      memcpy((u_char*) dst->Tag##_at_addr(start), \
+             (u_char*) buf, \
+             len << sc);    \
+    } \
+  } \
+JNI_END
+
+DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool
+                            , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf),
+                            HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN())
+DEFINE_SETSCALARARRAYREGION(T_BYTE,    jbyte,    Byte,    byte
+                            , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
+                            HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN())
+DEFINE_SETSCALARARRAYREGION(T_SHORT,   jshort,   Short,   short
+                            , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
+                            HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
+DEFINE_SETSCALARARRAYREGION(T_CHAR,    jchar,    Char,    char
+                            , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
+                            HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
+DEFINE_SETSCALARARRAYREGION(T_INT,     jint,     Int,     int
+                            , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
+                            HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
+DEFINE_SETSCALARARRAYREGION(T_LONG,    jlong,    Long,    long
+                            , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
+                            HOTSPOT_JNI_SETLONGARRAYREGION_RETURN())
+DEFINE_SETSCALARARRAYREGION(T_FLOAT,   jfloat,   Float,   float
+                            , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
+                            HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN())
+DEFINE_SETSCALARARRAYREGION(T_DOUBLE,  jdouble,  Double,  double
+                            , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
+                            HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN())
+#endif /* USDT2 */
+
 
 //
 // Interception of natives
@@ -2463,13 +4016,23 @@
   return true;
 }
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(RegisterNatives, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(RegisterNatives, jint
+                    , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz,
                                     const JNINativeMethod *methods,
                                     jint nMethods))
   JNIWrapper("RegisterNatives");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, RegisterNatives__entry, env, clazz, methods, nMethods);
+#else /* USDT2 */
+  HOTSPOT_JNI_REGISTERNATIVES_ENTRY(
+                                    env, clazz, (void *) methods, nMethods);
+#endif /* USDT2 */
   jint ret = 0;
   DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret);
 
@@ -2507,7 +4070,12 @@
 
 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz))
   JNIWrapper("UnregisterNatives");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, UnregisterNatives__entry, env, clazz);
+#else /* USDT2 */
+ HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY(
+                                     env, clazz);
+#endif /* USDT2 */
   klassOop k   = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz));
   //%note jni_2
   if (Klass::cast(k)->oop_is_instance()) {
@@ -2519,7 +4087,12 @@
       }
     }
   }
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, UnregisterNatives__return, 0);
+#else /* USDT2 */
+ HOTSPOT_JNI_UNREGISTERNATIVES_RETURN(
+                                      0);
+#endif /* USDT2 */
   return 0;
 JNI_END
 
@@ -2527,10 +4100,20 @@
 // Monitor functions
 //
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(MonitorEnter, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(MonitorEnter, jint
+                    , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, MonitorEnter__entry, env, jobj);
+#else /* USDT2 */
+ HOTSPOT_JNI_MONITORENTER_ENTRY(
+                                env, jobj);
+#endif /* USDT2 */
   jint ret = JNI_ERR;
   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
 
@@ -2545,10 +4128,20 @@
   return ret;
 JNI_END
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(MonitorExit, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(MonitorExit, jint
+                    , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, MonitorExit__entry, env, jobj);
+#else /* USDT2 */
+ HOTSPOT_JNI_MONITOREXIT_ENTRY(
+                               env, jobj);
+#endif /* USDT2 */
   jint ret = JNI_ERR;
   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
 
@@ -2568,11 +4161,21 @@
 // Extensions
 //
 
+#ifndef USDT2
 DT_VOID_RETURN_MARK_DECL(GetStringRegion);
+#else /* USDT2 */
+DT_VOID_RETURN_MARK_DECL(GetStringRegion
+                         , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
+#endif /* USDT2 */
 
 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
   JNIWrapper("GetStringRegion");
+#ifndef USDT2
   DTRACE_PROBE5(hotspot_jni, GetStringRegion__entry, env, string, start, len, buf);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGREGION_ENTRY(
+                                   env, string, start, len, buf);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(GetStringRegion);
   oop s = JNIHandles::resolve_non_null(string);
   int s_len = java_lang_String::length(s);
@@ -2587,11 +4190,21 @@
   }
 JNI_END
 
+#ifndef USDT2
 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion);
+#else /* USDT2 */
+DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion
+                         , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN());
+#endif /* USDT2 */
 
 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf))
   JNIWrapper("GetStringUTFRegion");
+#ifndef USDT2
   DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string, start, len, buf);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY(
+                                      env, string, start, len, buf);
+#endif /* USDT2 */
   DT_VOID_RETURN_MARK(GetStringUTFRegion);
   oop s = JNIHandles::resolve_non_null(string);
   int s_len = java_lang_String::length(s);
@@ -2617,7 +4230,12 @@
 
 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy))
   JNIWrapper("GetPrimitiveArrayCritical");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY(
+                                             env, array, (uintptr_t *) isCopy);
+#endif /* USDT2 */
   GC_locker::lock_critical(thread);
   if (isCopy != NULL) {
     *isCopy = JNI_FALSE;
@@ -2631,23 +4249,43 @@
     type = typeArrayKlass::cast(a->klass())->element_type();
   }
   void* ret = arrayOop(a)->base(type);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN(
+                                              ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 
 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode))
   JNIWrapper("ReleasePrimitiveArrayCritical");
+#ifndef USDT2
   DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode);
+#else /* USDT2 */
+  HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(
+                                                  env, array, carray, mode);
+#endif /* USDT2 */
   // The array, carray and mode arguments are ignored
   GC_locker::unlock_critical(thread);
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return);
+#else /* USDT2 */
+HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN(
+);
+#endif /* USDT2 */
 JNI_END
 
 
 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy))
   JNIWrapper("GetStringCritical");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(
+                                      env, string, (uintptr_t *) isCopy);
+#endif /* USDT2 */
   GC_locker::lock_critical(thread);
   if (isCopy != NULL) {
     *isCopy = JNI_FALSE;
@@ -2662,44 +4300,89 @@
   } else {
     ret = (jchar*) s_value->base(T_CHAR);
   }
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret);
+#else /* USDT2 */
+ HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN(
+                                      (uint16_t *) ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 
 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars))
   JNIWrapper("ReleaseStringCritical");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars);
+#else /* USDT2 */
+  HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(
+                                          env, str, (uint16_t *) chars);
+#endif /* USDT2 */
   // The str and chars arguments are ignored
   GC_locker::unlock_critical(thread);
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return);
+#else /* USDT2 */
+HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN(
+);
+#endif /* USDT2 */
 JNI_END
 
 
 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
   JNIWrapper("jni_NewWeakGlobalRef");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref);
+#else /* USDT2 */
+ HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(
+                                    env, ref);
+#endif /* USDT2 */
   Handle ref_handle(thread, JNIHandles::resolve(ref));
   jweak ret = JNIHandles::make_weak_global(ref_handle);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret);
+#else /* USDT2 */
+ HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(
+                                     ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
 // Must be JNI_ENTRY (with HandleMark)
 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref))
   JNIWrapper("jni_DeleteWeakGlobalRef");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref);
+#else /* USDT2 */
+  HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY(
+                                        env, ref);
+#endif /* USDT2 */
   JNIHandles::destroy_weak_global(ref);
+#ifndef USDT2
   DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return);
+#else /* USDT2 */
+  HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN(
+                                         );
+#endif /* USDT2 */
 JNI_END
 
 
 JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env))
   JNIWrapper("jni_ExceptionCheck");
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env);
+#else /* USDT2 */
+ HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY(
+                                  env);
+#endif /* USDT2 */
   jni_check_async_exceptions(thread);
   jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE;
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret);
+#else /* USDT2 */
+ HOTSPOT_JNI_EXCEPTIONCHECK_RETURN(
+                                   ret);
+#endif /* USDT2 */
   return ret;
 JNI_END
 
@@ -2791,11 +4474,21 @@
   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
 
   JNIWrapper("jni_NewDirectByteBuffer");
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity);
+#else /* USDT2 */
+ HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(
+                                       env, address, capacity);
+#endif /* USDT2 */
 
   if (!directBufferSupportInitializeEnded) {
     if (!initializeDirectBufferSupport(env, thread)) {
+#ifndef USDT2
       DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL);
+#else /* USDT2 */
+      HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(
+                                             NULL);
+#endif /* USDT2 */
       return NULL;
     }
   }
@@ -2806,11 +4499,21 @@
   // takes int capacity
   jint  cap  = (jint)  capacity;
   jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(
+                                         ret);
+#endif /* USDT2 */
   return ret;
 }
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*
+                    , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref));
+#endif /* USDT2 */
 
 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf)
 {
@@ -2818,7 +4521,12 @@
   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
 
   JNIWrapper("jni_GetDirectBufferAddress");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY(
+                                           env, buf);
+#endif /* USDT2 */
   void* ret = NULL;
   DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret);
 
@@ -2836,7 +4544,12 @@
   return ret;
 }
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong
+                    , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf)
 {
@@ -2844,7 +4557,12 @@
   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
 
   JNIWrapper("jni_GetDirectBufferCapacity");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY(
+                                            env, buf);
+#endif /* USDT2 */
   jlong ret = -1;
   DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret);
 
@@ -2871,8 +4589,18 @@
 
 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env))
   JNIWrapper("GetVersion");
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETVERSION_ENTRY(
+                               env);
+#endif /* USDT2 */
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETVERSION_RETURN(
+                                CurrentVersion);
+#endif /* USDT2 */
   return CurrentVersion;
 JNI_END
 
@@ -2880,9 +4608,19 @@
 
 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm))
   JNIWrapper("jni_GetJavaVM");
+#ifndef USDT2
   DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETJAVAVM_ENTRY(
+                              env, (void **) vm);
+#endif /* USDT2 */
   *vm  = (JavaVM *)(&main_vm);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETJAVAVM_RETURN(
+                               JNI_OK);
+#endif /* USDT2 */
   return JNI_OK;
 JNI_END
 
@@ -3262,11 +5000,21 @@
 #define JAVASTACKSIZE (400 * 1024)    /* Default size of a thread java stack */
 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL };
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*);
 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint
+                    , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) {
+#ifndef USDT2
   HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY(
+                                             args_);
+#endif /* USDT2 */
   JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_;
   jint ret = JNI_ERR;
   DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret);
@@ -3294,17 +5042,28 @@
 void execute_internal_vm_tests() {
   if (ExecuteInternalVMTests) {
     assert(QuickSort::test_quick_sort(), "test_quick_sort failed");
-    tty->print_cr("All tests passed");
+    assert(arrayOopDesc::test_max_array_length(), "test_max_array_length failed");
+    tty->print_cr("All internal VM tests passed");
   }
 }
 
 #endif
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args);
 DT_RETURN_MARK_DECL(CreateJavaVM, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(CreateJavaVM, jint
+                    , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
+#ifndef USDT2
   HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args);
+#else /* USDT2 */
+  HOTSPOT_JNI_CREATEJAVAVM_ENTRY(
+                                 (void **) vm, penv, args);
+#endif /* USDT2 */
 
   jint result = JNI_ERR;
   DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result);
@@ -3394,31 +5153,53 @@
   return result;
 }
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \
   JavaVM**, jsize, jsize*);
 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint);
+#endif /* !USDT2 */
 
 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) {
   // See bug 4367188, the wrapper can sometimes cause VM crashes
   // JNIWrapper("GetCreatedJavaVMs");
+#ifndef USDT2
   HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \
     vm_buf, bufLen, numVMs);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY(
+                                      (void **) vm_buf, bufLen, (uintptr_t *) numVMs);
+#endif /* USDT2 */
   if (vm_created) {
     if (numVMs != NULL) *numVMs = 1;
     if (bufLen > 0)     *vm_buf = (JavaVM *)(&main_vm);
   } else {
     if (numVMs != NULL) *numVMs = 0;
   }
+#ifndef USDT2
   HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN(
+                                    JNI_OK);
+#endif /* USDT2 */
   return JNI_OK;
 }
 
 extern "C" {
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(DestroyJavaVM, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(DestroyJavaVM, jint
+                    , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) {
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm);
+#else /* USDT2 */
+  HOTSPOT_JNI_DESTROYJAVAVM_ENTRY(
+                                  vm);
+#endif /* USDT2 */
   jint res = JNI_ERR;
   DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res);
 
@@ -3536,7 +5317,7 @@
   // mark the thread as no longer attaching
   // this uses a fence to push the change through so we don't have
   // to regrab the threads_lock
-  thread->set_attached();
+  thread->set_done_attaching_via_jni();
 
   // Set java thread status.
   java_lang_Thread::set_thread_status(thread->threadObj(),
@@ -3564,34 +5345,64 @@
 
 
 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args);
+#else /* USDT2 */
+  HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(
+                                        vm, penv, _args);
+#endif /* USDT2 */
   if (!vm_created) {
+#ifndef USDT2
     DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR);
+#else /* USDT2 */
+  HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(
+                                         (uint32_t) JNI_ERR);
+#endif /* USDT2 */
     return JNI_ERR;
   }
 
   JNIWrapper("AttachCurrentThread");
   jint ret = attach_current_thread(vm, penv, _args, false);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(
+                                         ret);
+#endif /* USDT2 */
   return ret;
 }
 
 
 jint JNICALL jni_DetachCurrentThread(JavaVM *vm)  {
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm);
+#else /* USDT2 */
+  HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY(
+                                        vm);
+#endif /* USDT2 */
   VM_Exit::block_if_vm_exited();
 
   JNIWrapper("DetachCurrentThread");
 
   // If the thread has been deattacted the operations is a no-op
   if (ThreadLocalStorage::thread() == NULL) {
+#ifndef USDT2
     DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK);
+#else /* USDT2 */
+  HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
+                                         JNI_OK);
+#endif /* USDT2 */
     return JNI_OK;
   }
 
   JavaThread* thread = JavaThread::current();
   if (thread->has_last_Java_frame()) {
+#ifndef USDT2
     DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR);
+#else /* USDT2 */
+  HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
+                                         (uint32_t) JNI_ERR);
+#endif /* USDT2 */
     // Can't detach a thread that's running java, that can't work.
     return JNI_ERR;
   }
@@ -3612,14 +5423,29 @@
   thread->exit(false, JavaThread::jni_detach);
   delete thread;
 
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK);
+#else /* USDT2 */
+  HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
+                                         JNI_OK);
+#endif /* USDT2 */
   return JNI_OK;
 }
 
+#ifndef USDT2
 DT_RETURN_MARK_DECL(GetEnv, jint);
+#else /* USDT2 */
+DT_RETURN_MARK_DECL(GetEnv, jint
+                    , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
+#endif /* USDT2 */
 
 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version);
+#else /* USDT2 */
+  HOTSPOT_JNI_GETENV_ENTRY(
+                           vm, penv, version);
+#endif /* USDT2 */
   jint ret = JNI_ERR;
   DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
 
@@ -3674,15 +5500,30 @@
 
 
 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) {
+#ifndef USDT2
   DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args);
+#else /* USDT2 */
+  HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY(
+                                                vm, penv, _args);
+#endif /* USDT2 */
   if (!vm_created) {
+#ifndef USDT2
     DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR);
+#else /* USDT2 */
+  HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(
+                                                 (uint32_t) JNI_ERR);
+#endif /* USDT2 */
     return JNI_ERR;
   }
 
   JNIWrapper("AttachCurrentThreadAsDaemon");
   jint ret = attach_current_thread(vm, penv, _args, true);
+#ifndef USDT2
   DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret);
+#else /* USDT2 */
+  HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(
+                                                 ret);
+#endif /* USDT2 */
   return ret;
 }
 
diff --git a/hotspot/src/share/vm/prims/jniCheck.cpp b/hotspot/src/share/vm/prims/jniCheck.cpp
index 63281dc..3bf4ecd 100644
--- a/hotspot/src/share/vm/prims/jniCheck.cpp
+++ b/hotspot/src/share/vm/prims/jniCheck.cpp
@@ -107,7 +107,7 @@
     if (env != xenv) {                                                   \
       NativeReportJNIFatalError(thr, warn_wrong_jnienv);                 \
     }                                                                    \
-    __ENTRY(result_type, header, thr)
+    VM_ENTRY_BASE(result_type, header, thr)
 
 
 #define UNCHECKED() (unchecked_jni_NativeInterface)
diff --git a/hotspot/src/share/vm/prims/jvm.cpp b/hotspot/src/share/vm/prims/jvm.cpp
index 1e998e3..fedd18f 100644
--- a/hotspot/src/share/vm/prims/jvm.cpp
+++ b/hotspot/src/share/vm/prims/jvm.cpp
@@ -73,12 +73,17 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "jvm_windows.h"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "jvm_bsd.h"
+#endif
 
 #include <errno.h>
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
+#endif /* !USDT2 */
 
 /*
   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
@@ -2813,7 +2818,11 @@
 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
   JVMWrapper("JVM_Yield");
   if (os::dont_yield()) return;
+#ifndef USDT2
   HS_DTRACE_PROBE0(hotspot, thread__yield);
+#else /* USDT2 */
+  HOTSPOT_THREAD_YIELD();
+#endif /* USDT2 */
   // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
   // Critical for similar threading behaviour
   if (ConvertYieldToSleep) {
@@ -2839,7 +2848,12 @@
   // And set new thread state to SLEEPING.
   JavaThreadSleepState jtss(thread);
 
+#ifndef USDT2
   HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
+#else /* USDT2 */
+  HOTSPOT_THREAD_SLEEP_BEGIN(
+                             millis);
+#endif /* USDT2 */
 
   if (millis == 0) {
     // When ConvertSleepToYield is on, this matches the classic VM implementation of
@@ -2861,7 +2875,12 @@
       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
       // us while we were sleeping. We do not overwrite those.
       if (!HAS_PENDING_EXCEPTION) {
+#ifndef USDT2
         HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
+#else /* USDT2 */
+        HOTSPOT_THREAD_SLEEP_END(
+                                 1);
+#endif /* USDT2 */
         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
         // to properly restore the thread state.  That's likely wrong.
         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
@@ -2869,7 +2888,12 @@
     }
     thread->osthread()->set_state(old_state);
   }
+#ifndef USDT2
   HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
+#else /* USDT2 */
+  HOTSPOT_THREAD_SLEEP_END(
+                           0);
+#endif /* USDT2 */
 JVM_END
 
 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
@@ -2987,6 +3011,20 @@
   }
 JVM_END
 
+JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
+  JVMWrapper("JVM_SetNativeThreadName");
+  ResourceMark rm(THREAD);
+  oop java_thread = JNIHandles::resolve_non_null(jthread);
+  JavaThread* thr = java_lang_Thread::thread(java_thread);
+  // Thread naming only supported for the current thread, doesn't work for
+  // target threads.
+  if (Thread::current() == thr && !thr->has_attached_via_jni()) {
+    // we don't set the name of an attached thread to avoid stepping
+    // on other programs
+    const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
+    os::set_native_thread_name(thread_name);
+  }
+JVM_END
 
 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
 
diff --git a/hotspot/src/share/vm/prims/jvm.h b/hotspot/src/share/vm/prims/jvm.h
index dc4af47..a9b322c 100644
--- a/hotspot/src/share/vm/prims/jvm.h
+++ b/hotspot/src/share/vm/prims/jvm.h
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "jvm_windows.h"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "jvm_bsd.h"
+#endif
 
 #ifndef _JAVASOFT_JVM_H_
 #define _JAVASOFT_JVM_H_
@@ -288,6 +291,9 @@
 JNIEXPORT jobjectArray JNICALL
 JVM_GetAllThreads(JNIEnv *env, jclass dummy);
 
+JNIEXPORT void JNICALL
+JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name);
+
 /* getStackTrace() and getAllStackTraces() method */
 JNIEXPORT jobjectArray JNICALL
 JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads);
diff --git a/hotspot/src/share/vm/prims/jvmtiEnter.xsl b/hotspot/src/share/vm/prims/jvmtiEnter.xsl
index 1dc3de8..318d76b 100644
--- a/hotspot/src/share/vm/prims/jvmtiEnter.xsl
+++ b/hotspot/src/share/vm/prims/jvmtiEnter.xsl
@@ -426,7 +426,7 @@
     <xsl:value-of select="$space"/>
     <xsl:text>ThreadInVMfromNative __tiv(current_thread);</xsl:text>
     <xsl:value-of select="$space"/>
-    <xsl:text>__ENTRY(jvmtiError, </xsl:text>
+    <xsl:text>VM_ENTRY_BASE(jvmtiError, </xsl:text>
     <xsl:apply-templates select="." mode="functionid"/>
     <xsl:text> , current_thread)</xsl:text>
     <xsl:value-of select="$space"/>
diff --git a/hotspot/src/share/vm/prims/jvmtiEnv.cpp b/hotspot/src/share/vm/prims/jvmtiEnv.cpp
index f93fdf1..6084915 100644
--- a/hotspot/src/share/vm/prims/jvmtiEnv.cpp
+++ b/hotspot/src/share/vm/prims/jvmtiEnv.cpp
@@ -68,6 +68,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 
@@ -170,7 +173,7 @@
     // from native so as to resolve the jthread.
 
     ThreadInVMfromNative __tiv(current_thread);
-    __ENTRY(jvmtiError, JvmtiEnv::GetThreadLocalStorage , current_thread)
+    VM_ENTRY_BASE(jvmtiError, JvmtiEnv::GetThreadLocalStorage , current_thread)
     debug_only(VMNativeEntryWrapper __vew;)
 
     oop thread_oop = JNIHandles::resolve_external_guard(thread);
diff --git a/hotspot/src/share/vm/prims/jvmtiExport.cpp b/hotspot/src/share/vm/prims/jvmtiExport.cpp
index 48401ca..181716d 100644
--- a/hotspot/src/share/vm/prims/jvmtiExport.cpp
+++ b/hotspot/src/share/vm/prims/jvmtiExport.cpp
@@ -373,7 +373,7 @@
     JavaThread* current_thread = (JavaThread*) ThreadLocalStorage::thread();
     // transition code: native to VM
     ThreadInVMfromNative __tiv(current_thread);
-    __ENTRY(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
+    VM_ENTRY_BASE(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
     debug_only(VMNativeEntryWrapper __vew;)
 
     JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
diff --git a/hotspot/src/share/vm/prims/jvmtiImpl.cpp b/hotspot/src/share/vm/prims/jvmtiImpl.cpp
index f673e92..e0d809d 100644
--- a/hotspot/src/share/vm/prims/jvmtiImpl.cpp
+++ b/hotspot/src/share/vm/prims/jvmtiImpl.cpp
@@ -54,6 +54,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 //
 // class JvmtiAgentThread
diff --git a/hotspot/src/share/vm/prims/methodHandles.cpp b/hotspot/src/share/vm/prims/methodHandles.cpp
index c5d5c88..d43cb97 100644
--- a/hotspot/src/share/vm/prims/methodHandles.cpp
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp
@@ -206,9 +206,12 @@
   _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size);
   if (_adapter_code == NULL)
     vm_exit_out_of_memory(adapter_code_size, "CodeCache: no room for MethodHandles adapters");
-  CodeBuffer code(_adapter_code);
-  MethodHandlesAdapterGenerator g(&code);
-  g.generate();
+  {
+    CodeBuffer code(_adapter_code);
+    MethodHandlesAdapterGenerator g(&code);
+    g.generate();
+    code.log_section_sizes("MethodHandlesAdapterBlob");
+  }
 }
 
 //------------------------------------------------------------------------------
@@ -3079,26 +3082,26 @@
 JVM_END
 
 JVM_ENTRY(void, MHN_setCallSiteTargetNormal(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
-  oop call_site = JNIHandles::resolve_non_null(call_site_jh);
-  oop target    = JNIHandles::resolve(target_jh);
+  Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
+  Handle target   (THREAD, JNIHandles::resolve(target_jh));
   {
     // Walk all nmethods depending on this call site.
     MutexLocker mu(Compile_lock, thread);
     Universe::flush_dependents_on(call_site, target);
   }
-  java_lang_invoke_CallSite::set_target(call_site, target);
+  java_lang_invoke_CallSite::set_target(call_site(), target());
 }
 JVM_END
 
 JVM_ENTRY(void, MHN_setCallSiteTargetVolatile(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
-  oop call_site = JNIHandles::resolve_non_null(call_site_jh);
-  oop target    = JNIHandles::resolve(target_jh);
+  Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
+  Handle target   (THREAD, JNIHandles::resolve(target_jh));
   {
     // Walk all nmethods depending on this call site.
     MutexLocker mu(Compile_lock, thread);
     Universe::flush_dependents_on(call_site, target);
   }
-  java_lang_invoke_CallSite::set_target_volatile(call_site, target);
+  java_lang_invoke_CallSite::set_target_volatile(call_site(), target());
 }
 JVM_END
 
diff --git a/hotspot/src/share/vm/prims/nativeLookup.cpp b/hotspot/src/share/vm/prims/nativeLookup.cpp
index af62593..874c54d 100644
--- a/hotspot/src/share/vm/prims/nativeLookup.cpp
+++ b/hotspot/src/share/vm/prims/nativeLookup.cpp
@@ -49,6 +49,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 
 static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
diff --git a/hotspot/src/share/vm/prims/unsafe.cpp b/hotspot/src/share/vm/prims/unsafe.cpp
index 48d13db..19f77a5 100644
--- a/hotspot/src/share/vm/prims/unsafe.cpp
+++ b/hotspot/src/share/vm/prims/unsafe.cpp
@@ -42,9 +42,11 @@
  *      Implementation of class sun.misc.Unsafe
  */
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL3(hotspot, thread__park__begin, uintptr_t, int, long long);
 HS_DTRACE_PROBE_DECL1(hotspot, thread__park__end, uintptr_t);
 HS_DTRACE_PROBE_DECL1(hotspot, thread__unpark, uintptr_t);
+#endif /* !USDT2 */
 
 #define MAX_OBJECT_SIZE \
   ( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \
@@ -300,21 +302,24 @@
 
 UNSAFE_ENTRY(void, Unsafe_SetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h))
   UnsafeWrapper("Unsafe_SetObjectVolatile");
-  oop x = JNIHandles::resolve(x_h);
-  oop p = JNIHandles::resolve(obj);
-  // Catch VolatileCallSite.target stores (via
-  // CallSite.setTargetVolatile) and check call site dependencies.
-  if ((offset == java_lang_invoke_CallSite::target_offset_in_bytes()) && p->is_a(SystemDictionary::CallSite_klass())) {
-    oop call_site     = p;
-    oop method_handle = x;
-    assert(call_site    ->is_a(SystemDictionary::CallSite_klass()),     "must be");
-    assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "must be");
-    {
-      // Walk all nmethods depending on this call site.
-      MutexLocker mu(Compile_lock, thread);
-      Universe::flush_dependents_on(call_site, method_handle);
+  {
+    // Catch VolatileCallSite.target stores (via
+    // CallSite.setTargetVolatile) and check call site dependencies.
+    oop p = JNIHandles::resolve(obj);
+    if ((offset == java_lang_invoke_CallSite::target_offset_in_bytes()) && p->is_a(SystemDictionary::CallSite_klass())) {
+      Handle call_site    (THREAD, p);
+      Handle method_handle(THREAD, JNIHandles::resolve(x_h));
+      assert(call_site    ->is_a(SystemDictionary::CallSite_klass()),     "must be");
+      assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "must be");
+      {
+        // Walk all nmethods depending on this call site.
+        MutexLocker mu(Compile_lock, thread);
+        Universe::flush_dependents_on(call_site(), method_handle());
+      }
     }
   }
+  oop x = JNIHandles::resolve(x_h);
+  oop p = JNIHandles::resolve(obj);
   void* addr = index_oop_from_field_offset_long(p, offset);
   OrderAccess::release();
   if (UseCompressedOops) {
@@ -1187,10 +1192,20 @@
 
 UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time))
   UnsafeWrapper("Unsafe_Park");
+#ifndef USDT2
   HS_DTRACE_PROBE3(hotspot, thread__park__begin, thread->parker(), (int) isAbsolute, time);
+#else /* USDT2 */
+   HOTSPOT_THREAD_PARK_BEGIN(
+                             (uintptr_t) thread->parker(), (int) isAbsolute, time);
+#endif /* USDT2 */
   JavaThreadParkedState jtps(thread, time != 0);
   thread->parker()->park(isAbsolute != 0, time);
+#ifndef USDT2
   HS_DTRACE_PROBE1(hotspot, thread__park__end, thread->parker());
+#else /* USDT2 */
+  HOTSPOT_THREAD_PARK_END(
+                          (uintptr_t) thread->parker());
+#endif /* USDT2 */
 UNSAFE_END
 
 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread))
@@ -1222,7 +1237,12 @@
     }
   }
   if (p != NULL) {
+#ifndef USDT2
     HS_DTRACE_PROBE1(hotspot, thread__unpark, p);
+#else /* USDT2 */
+    HOTSPOT_THREAD_UNPARK(
+                          (uintptr_t) p);
+#endif /* USDT2 */
     p->unpark();
   }
 UNSAFE_END
diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp
index 07e31bf..b8e514d 100644
--- a/hotspot/src/share/vm/runtime/arguments.cpp
+++ b/hotspot/src/share/vm/runtime/arguments.cpp
@@ -46,6 +46,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
 #endif
@@ -1574,18 +1577,9 @@
     sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
     add_property(buffer);
   }
-  if (AggressiveOpts && FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
-    FLAG_SET_DEFAULT(DoEscapeAnalysis, true);
-  }
   if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
     FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
   }
-  if (AggressiveOpts && FLAG_IS_DEFAULT(OptimizeStringConcat)) {
-    FLAG_SET_DEFAULT(OptimizeStringConcat, true);
-  }
-  if (AggressiveOpts && FLAG_IS_DEFAULT(OptimizeFill)) {
-    FLAG_SET_DEFAULT(OptimizeFill, true);
-  }
 #endif
 
   if (AggressiveOpts) {
@@ -2599,16 +2593,16 @@
       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
     } else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) {
-#ifdef SOLARIS
+#if defined(DTRACE_ENABLED)
       FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
       FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
       FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true);
       FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true);
-#else // ndef SOLARIS
+#else // defined(DTRACE_ENABLED)
       jio_fprintf(defaultStream::error_stream(),
-                  "ExtendedDTraceProbes flag is only applicable on Solaris\n");
+                  "ExtendedDTraceProbes flag is not applicable for this configuration\n");
       return JNI_EINVAL;
-#endif // ndef SOLARIS
+#endif // defined(DTRACE_ENABLED)
 #ifdef ASSERT
     } else if (match_option(option, "-XX:+FullGCALot", &tail)) {
       FLAG_SET_CMDLINE(bool, FullGCALot, true);
diff --git a/hotspot/src/share/vm/runtime/atomic.cpp b/hotspot/src/share/vm/runtime/atomic.cpp
index 3b012e0..80780d7 100644
--- a/hotspot/src/share/vm/runtime/atomic.cpp
+++ b/hotspot/src/share/vm/runtime/atomic.cpp
@@ -33,6 +33,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 #ifdef TARGET_OS_ARCH_linux_x86
 # include "atomic_linux_x86.inline.hpp"
 #endif
@@ -57,6 +60,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "atomic_linux_ppc.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "atomic_bsd_x86.inline.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "atomic_bsd_zero.inline.hpp"
+#endif
 
 jbyte Atomic::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) {
   assert(sizeof(jbyte) == 1, "assumption.");
diff --git a/hotspot/src/share/vm/runtime/deoptimization.cpp b/hotspot/src/share/vm/runtime/deoptimization.cpp
index db95bad..05771c3 100644
--- a/hotspot/src/share/vm/runtime/deoptimization.cpp
+++ b/hotspot/src/share/vm/runtime/deoptimization.cpp
@@ -362,8 +362,6 @@
   intptr_t* frame_sizes = NEW_C_HEAP_ARRAY(intptr_t, number_of_frames);
   // +1 because we always have an interpreter return address for the final slot.
   address* frame_pcs = NEW_C_HEAP_ARRAY(address, number_of_frames + 1);
-  int callee_parameters = 0;
-  int callee_locals = 0;
   int popframe_extra_args = 0;
   // Create an interpreter return address for the stub to use as its return
   // address so the skeletal frames are perfectly walkable
@@ -387,14 +385,16 @@
   // handles are used.  If the caller is interpreted get the real
   // value so that the proper amount of space can be added to it's
   // frame.
-  int caller_actual_parameters = callee_parameters;
+  bool caller_was_method_handle = false;
   if (deopt_sender.is_interpreted_frame()) {
     methodHandle method = deopt_sender.interpreter_frame_method();
-    Bytecode_invoke cur = Bytecode_invoke_check(method,
-                                                deopt_sender.interpreter_frame_bci());
-    Symbol* signature = method->constants()->signature_ref_at(cur.index());
-    ArgumentSizeComputer asc(signature);
-    caller_actual_parameters = asc.size() + (cur.has_receiver() ? 1 : 0);
+    Bytecode_invoke cur = Bytecode_invoke_check(method, deopt_sender.interpreter_frame_bci());
+    if (cur.is_method_handle_invoke()) {
+      // Method handle invokes may involve fairly arbitrary chains of
+      // calls so it's impossible to know how much actual space the
+      // caller has for locals.
+      caller_was_method_handle = true;
+    }
   }
 
   //
@@ -411,14 +411,15 @@
   // in the frame_sizes/frame_pcs so the assembly code can do a trivial walk.
   // so things look a little strange in this loop.
   //
+  int callee_parameters = 0;
+  int callee_locals = 0;
   for (int index = 0; index < array->frames(); index++ ) {
     // frame[number_of_frames - 1 ] = on_stack_size(youngest)
     // frame[number_of_frames - 2 ] = on_stack_size(sender(youngest))
     // frame[number_of_frames - 3 ] = on_stack_size(sender(sender(youngest)))
     int caller_parms = callee_parameters;
-    if (index == array->frames() - 1) {
-      // Use the value from the interpreted caller
-      caller_parms = caller_actual_parameters;
+    if ((index == array->frames() - 1) && caller_was_method_handle) {
+      caller_parms = 0;
     }
     frame_sizes[number_of_frames - 1 - index] = BytesPerWord * array->element(index)->on_stack_size(caller_parms,
                                                                                                     callee_parameters,
@@ -460,13 +461,13 @@
   // QQQ I'd rather see this pushed down into last_frame_adjust
   // and have it take the sender (aka caller).
 
-  if (deopt_sender.is_compiled_frame()) {
+  if (deopt_sender.is_compiled_frame() || caller_was_method_handle) {
     caller_adjustment = last_frame_adjust(0, callee_locals);
-  } else if (callee_locals > caller_actual_parameters) {
+  } else if (callee_locals > callee_parameters) {
     // The caller frame may need extending to accommodate
     // non-parameter locals of the first unpacked interpreted frame.
     // Compute that adjustment.
-    caller_adjustment = last_frame_adjust(caller_actual_parameters, callee_locals);
+    caller_adjustment = last_frame_adjust(callee_parameters, callee_locals);
   }
 
   // If the sender is deoptimized the we must retrieve the address of the handler
@@ -481,7 +482,7 @@
 
   UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord,
                                       caller_adjustment * BytesPerWord,
-                                      caller_actual_parameters,
+                                      caller_was_method_handle ? 0 : callee_parameters,
                                       number_of_frames,
                                       frame_sizes,
                                       frame_pcs,
diff --git a/hotspot/src/share/vm/runtime/fprofiler.hpp b/hotspot/src/share/vm/runtime/fprofiler.hpp
index 60e51d2..2f8d615 100644
--- a/hotspot/src/share/vm/runtime/fprofiler.hpp
+++ b/hotspot/src/share/vm/runtime/fprofiler.hpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // a simple flat profiler for Java
 
diff --git a/hotspot/src/share/vm/runtime/frame.cpp b/hotspot/src/share/vm/runtime/frame.cpp
index e555433..c3a0852 100644
--- a/hotspot/src/share/vm/runtime/frame.cpp
+++ b/hotspot/src/share/vm/runtime/frame.cpp
@@ -1338,7 +1338,11 @@
     // Label values common to most frames
     values.describe(-1, unextended_sp(), err_msg("unextended_sp for #%d", frame_no));
     values.describe(-1, sp(), err_msg("sp for #%d", frame_no));
-    values.describe(-1, fp(), err_msg("fp for #%d", frame_no));
+    if (is_compiled_frame()) {
+      values.describe(-1, sp() + _cb->frame_size(), err_msg("computed fp for #%d", frame_no));
+    } else {
+      values.describe(-1, fp(), err_msg("fp for #%d", frame_no));
+    }
   }
   if (is_interpreted_frame()) {
     methodOop m = interpreter_frame_method();
@@ -1450,9 +1454,8 @@
 }
 
 
-void FrameValues::print() {
+void FrameValues::print(JavaThread* thread) {
   _values.sort(compare);
-  JavaThread* thread = JavaThread::current();
 
   // Sometimes values like the fp can be invalid values if the
   // register map wasn't updated during the walk.  Trim out values
@@ -1460,12 +1463,22 @@
   int min_index = 0;
   int max_index = _values.length() - 1;
   intptr_t* v0 = _values.at(min_index).location;
-  while (!thread->is_in_stack((address)v0)) {
-    v0 = _values.at(++min_index).location;
-  }
   intptr_t* v1 = _values.at(max_index).location;
-  while (!thread->is_in_stack((address)v1)) {
-    v1 = _values.at(--max_index).location;
+
+  if (thread == Thread::current()) {
+    while (!thread->is_in_stack((address)v0)) {
+      v0 = _values.at(++min_index).location;
+    }
+    while (!thread->is_in_stack((address)v1)) {
+      v1 = _values.at(--max_index).location;
+    }
+  } else {
+    while (!thread->on_local_stack((address)v0)) {
+      v0 = _values.at(++min_index).location;
+    }
+    while (!thread->on_local_stack((address)v1)) {
+      v1 = _values.at(--max_index).location;
+    }
   }
   intptr_t* min = MIN2(v0, v1);
   intptr_t* max = MAX2(v0, v1);
diff --git a/hotspot/src/share/vm/runtime/frame.hpp b/hotspot/src/share/vm/runtime/frame.hpp
index ec3e3e6..ec00e3a 100644
--- a/hotspot/src/share/vm/runtime/frame.hpp
+++ b/hotspot/src/share/vm/runtime/frame.hpp
@@ -516,7 +516,7 @@
   void describe(int owner, intptr_t* location, const char* description, int priority = 0);
 
   void validate();
-  void print();
+  void print(JavaThread* thread);
 };
 
 #endif
diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp
index 68d30cf..f330d44 100644
--- a/hotspot/src/share/vm/runtime/globals.hpp
+++ b/hotspot/src/share/vm/runtime/globals.hpp
@@ -50,6 +50,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "globals_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "globals_bsd.hpp"
+#endif
 #ifdef TARGET_OS_ARCH_linux_x86
 # include "globals_linux_x86.hpp"
 #endif
@@ -74,6 +77,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "globals_linux_ppc.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "globals_bsd_x86.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "globals_bsd_zero.hpp"
+#endif
 #ifdef COMPILER1
 #ifdef TARGET_ARCH_x86
 # include "c1_globals_x86.hpp"
@@ -96,6 +105,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "c1_globals_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "c1_globals_bsd.hpp"
+#endif
 #endif
 #ifdef COMPILER2
 #ifdef TARGET_ARCH_x86
@@ -116,6 +128,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "c2_globals_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "c2_globals_bsd.hpp"
+#endif
 #endif
 #ifdef SHARK
 #ifdef TARGET_ARCH_zero
@@ -562,8 +577,8 @@
   develop(bool, VerifyStack, false,                                         \
           "Verify stack of each thread when it is entering a runtime call") \
                                                                             \
-  develop(bool, ForceUnreachable, false,                                    \
-          "(amd64) Make all non code cache addresses to be unreachable with rip-rel forcing use of 64bit literal fixups") \
+  diagnostic(bool, ForceUnreachable, false,                                 \
+          "Make all non code cache addresses to be unreachable with forcing use of 64bit literal fixups") \
                                                                             \
   notproduct(bool, StressDerivedPointers, false,                            \
           "Force scavenge when a derived pointers is detected on stack "    \
@@ -662,7 +677,7 @@
   notproduct(bool, WalkStackALot, false,                                    \
           "trace stack (no print) at every exit from the runtime system")   \
                                                                             \
-  develop(bool, Debugging, false,                                           \
+  product(bool, Debugging, false,                                           \
           "set when executing debug methods in debug.ccp "                  \
           "(to prevent triggering assertions)")                             \
                                                                             \
@@ -889,7 +904,7 @@
   product(bool, AlwaysRestoreFPU, false,                                    \
           "Restore the FPU control word after every JNI call (expensive)")  \
                                                                             \
-  notproduct(bool, PrintCompilation2, false,                                \
+  diagnostic(bool, PrintCompilation2, false,                                \
           "Print additional statistics per compilation")                    \
                                                                             \
   diagnostic(bool, PrintAdapterHandlers, false,                             \
@@ -2565,7 +2580,7 @@
   diagnostic(bool, DebugInlinedCalls, true,                                 \
          "If false, restricts profiled locations to the root method only")  \
                                                                             \
-  product(bool, PrintVMOptions, trueInDebug,                                \
+  product(bool, PrintVMOptions, false,                                      \
          "Print flags that appeared on the command line")                   \
                                                                             \
   product(bool, IgnoreUnrecognizedVMOptions, false,                         \
@@ -3349,7 +3364,7 @@
   notproduct(bool, ExitOnFullCodeCache, false,                              \
           "Exit the VM if we fill the code cache.")                         \
                                                                             \
-  product(bool, UseCodeCacheFlushing, false,                                \
+  product(bool, UseCodeCacheFlushing, true,                                 \
           "Attempt to clean the code cache before shutting off compiler")   \
                                                                             \
   product(intx,  MinCodeCacheFlushingInterval, 30,                          \
@@ -3506,6 +3521,9 @@
           "C1 with MDO profiling (tier 3) invocation notification "         \
           "frequency.")                                                     \
                                                                             \
+  product(intx, Tier23InlineeNotifyFreqLog, 20,                             \
+          "Inlinee invocation (tiers 2 and 3) notification frequency")      \
+                                                                            \
   product(intx, Tier0BackedgeNotifyFreqLog, 10,                             \
           "Interpreter (tier 0) invocation notification frequency.")        \
                                                                             \
diff --git a/hotspot/src/share/vm/runtime/handles.cpp b/hotspot/src/share/vm/runtime/handles.cpp
index 4a57d26..3c24f81 100644
--- a/hotspot/src/share/vm/runtime/handles.cpp
+++ b/hotspot/src/share/vm/runtime/handles.cpp
@@ -38,6 +38,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 #ifdef ASSERT
 oop* HandleArea::allocate_handle(oop obj) {
diff --git a/hotspot/src/share/vm/runtime/handles.inline.hpp b/hotspot/src/share/vm/runtime/handles.inline.hpp
index 01060f5..3bd42fb 100644
--- a/hotspot/src/share/vm/runtime/handles.inline.hpp
+++ b/hotspot/src/share/vm/runtime/handles.inline.hpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // these inline functions are in a separate file to break an include cycle
 // between Thread and Handle
diff --git a/hotspot/src/share/vm/runtime/interfaceSupport.hpp b/hotspot/src/share/vm/runtime/interfaceSupport.hpp
index b119006..e1001ee 100644
--- a/hotspot/src/share/vm/runtime/interfaceSupport.hpp
+++ b/hotspot/src/share/vm/runtime/interfaceSupport.hpp
@@ -44,6 +44,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // Wrapper for all entry points to the virtual machine.
 // The HandleMarkCleaner is a faster version of HandleMark.
@@ -69,9 +72,9 @@
   }
 };
 
-// InterfaceSupport provides functionality used by the __LEAF and __ENTRY
-// macros. These macros are used to guard entry points into the VM and
-// perform checks upon leave of the VM.
+// InterfaceSupport provides functionality used by the VM_LEAF_BASE and
+// VM_ENTRY_BASE macros. These macros are used to guard entry points into
+// the VM and perform checks upon leave of the VM.
 
 
 class InterfaceSupport: AllStatic {
@@ -115,6 +118,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "interfaceSupport_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "interfaceSupport_bsd.hpp"
+#endif
 
 };
 
@@ -427,7 +433,7 @@
 
 // LEAF routines do not lock, GC or throw exceptions
 
-#define __LEAF(result_type, header)                                  \
+#define VM_LEAF_BASE(result_type, header)                            \
   TRACE_CALL(result_type, header)                                    \
   debug_only(NoHandleMark __hm;)                                     \
   /* begin of body */
@@ -435,7 +441,7 @@
 
 // ENTRY routines may lock, GC and throw exceptions
 
-#define __ENTRY(result_type, header, thread)                         \
+#define VM_ENTRY_BASE(result_type, header, thread)                   \
   TRACE_CALL(result_type, header)                                    \
   HandleMarkCleaner __hm(thread);                                    \
   Thread* THREAD = thread;                                           \
@@ -444,7 +450,7 @@
 
 // QUICK_ENTRY routines behave like ENTRY but without a handle mark
 
-#define __QUICK_ENTRY(result_type, header, thread)                   \
+#define VM_QUICK_ENTRY_BASE(result_type, header, thread)             \
   TRACE_CALL(result_type, header)                                    \
   debug_only(NoHandleMark __hm;)                                     \
   Thread* THREAD = thread;                                           \
@@ -457,20 +463,20 @@
 #define IRT_ENTRY(result_type, header)                               \
   result_type header {                                               \
     ThreadInVMfromJava __tiv(thread);                                \
-    __ENTRY(result_type, header, thread)                             \
+    VM_ENTRY_BASE(result_type, header, thread)                       \
     debug_only(VMEntryWrapper __vew;)
 
 
 #define IRT_LEAF(result_type, header)                                \
   result_type header {                                               \
-    __LEAF(result_type, header)                                      \
+    VM_LEAF_BASE(result_type, header)                                \
     debug_only(No_Safepoint_Verifier __nspv(true);)
 
 
 #define IRT_ENTRY_NO_ASYNC(result_type, header)                      \
   result_type header {                                               \
     ThreadInVMfromJavaNoAsyncException __tiv(thread);                \
-    __ENTRY(result_type, header, thread)                             \
+    VM_ENTRY_BASE(result_type, header, thread)                       \
     debug_only(VMEntryWrapper __vew;)
 
 // Another special case for nmethod_entry_point so the nmethod that the
@@ -481,7 +487,7 @@
   result_type header {                                               \
     nmethodLocker _nmlock(nm);                                       \
     ThreadInVMfromJavaNoAsyncException __tiv(thread);                                \
-    __ENTRY(result_type, header, thread)
+    VM_ENTRY_BASE(result_type, header, thread)
 
 #define IRT_END }
 
@@ -491,20 +497,20 @@
 #define JRT_ENTRY(result_type, header)                               \
   result_type header {                                               \
     ThreadInVMfromJava __tiv(thread);                                \
-    __ENTRY(result_type, header, thread)                             \
+    VM_ENTRY_BASE(result_type, header, thread)                       \
     debug_only(VMEntryWrapper __vew;)
 
 
 #define JRT_LEAF(result_type, header)                                \
   result_type header {                                               \
-  __LEAF(result_type, header)                                        \
+  VM_LEAF_BASE(result_type, header)                                  \
   debug_only(JRT_Leaf_Verifier __jlv;)
 
 
 #define JRT_ENTRY_NO_ASYNC(result_type, header)                      \
   result_type header {                                               \
     ThreadInVMfromJavaNoAsyncException __tiv(thread);                \
-    __ENTRY(result_type, header, thread)                             \
+    VM_ENTRY_BASE(result_type, header, thread)                       \
     debug_only(VMEntryWrapper __vew;)
 
 // Same as JRT Entry but allows for return value after the safepoint
@@ -537,11 +543,11 @@
     assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
     ThreadInVMfromNative __tiv(thread);                              \
     debug_only(VMNativeEntryWrapper __vew;)                          \
-    __ENTRY(result_type, header, thread)
+    VM_ENTRY_BASE(result_type, header, thread)
 
 
 // Ensure that the VMNativeEntryWrapper constructor, which can cause
-// a GC, is called outside the NoHandleMark (set via __QUICK_ENTRY).
+// a GC, is called outside the NoHandleMark (set via VM_QUICK_ENTRY_BASE).
 #define JNI_QUICK_ENTRY(result_type, header)                         \
 extern "C" {                                                         \
   result_type JNICALL header {                                \
@@ -549,7 +555,7 @@
     assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
     ThreadInVMfromNative __tiv(thread);                              \
     debug_only(VMNativeEntryWrapper __vew;)                          \
-    __QUICK_ENTRY(result_type, header, thread)
+    VM_QUICK_ENTRY_BASE(result_type, header, thread)
 
 
 #define JNI_LEAF(result_type, header)                                \
@@ -557,7 +563,7 @@
   result_type JNICALL header {                                \
     JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
     assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
-    __LEAF(result_type, header)
+    VM_LEAF_BASE(result_type, header)
 
 
 // Close the routine and the extern "C"
@@ -573,7 +579,7 @@
     JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
     ThreadInVMfromNative __tiv(thread);                              \
     debug_only(VMNativeEntryWrapper __vew;)                          \
-    __ENTRY(result_type, header, thread)
+    VM_ENTRY_BASE(result_type, header, thread)
 
 
 #define JVM_ENTRY_NO_ENV(result_type, header)                        \
@@ -582,7 +588,7 @@
     JavaThread* thread = (JavaThread*)ThreadLocalStorage::thread();  \
     ThreadInVMfromNative __tiv(thread);                              \
     debug_only(VMNativeEntryWrapper __vew;)                          \
-    __ENTRY(result_type, header, thread)
+    VM_ENTRY_BASE(result_type, header, thread)
 
 
 #define JVM_QUICK_ENTRY(result_type, header)                         \
@@ -591,14 +597,14 @@
     JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
     ThreadInVMfromNative __tiv(thread);                              \
     debug_only(VMNativeEntryWrapper __vew;)                          \
-    __QUICK_ENTRY(result_type, header, thread)
+    VM_QUICK_ENTRY_BASE(result_type, header, thread)
 
 
 #define JVM_LEAF(result_type, header)                                \
 extern "C" {                                                         \
   result_type JNICALL header {                                       \
     VM_Exit::block_if_vm_exited();                                   \
-    __LEAF(result_type, header)
+    VM_LEAF_BASE(result_type, header)
 
 
 #define JVM_END } }
diff --git a/hotspot/src/share/vm/runtime/java.cpp b/hotspot/src/share/vm/runtime/java.cpp
index 7f37e07..c04bd23 100644
--- a/hotspot/src/share/vm/runtime/java.cpp
+++ b/hotspot/src/share/vm/runtime/java.cpp
@@ -85,6 +85,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
@@ -102,7 +105,9 @@
 #include "opto/runtime.hpp"
 #endif
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown);
+#endif /* !USDT2 */
 
 #ifndef PRODUCT
 
@@ -544,8 +549,12 @@
 
 void notify_vm_shutdown() {
   // For now, just a dtrace probe.
+#ifndef USDT2
   HS_DTRACE_PROBE(hotspot, vm__shutdown);
   HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();
+#else /* USDT2 */
+  HOTSPOT_VM_SHUTDOWN();
+#endif /* USDT2 */
 }
 
 void vm_direct_exit(int code) {
diff --git a/hotspot/src/share/vm/runtime/javaCalls.cpp b/hotspot/src/share/vm/runtime/javaCalls.cpp
index d422c6c..edbba98 100644
--- a/hotspot/src/share/vm/runtime/javaCalls.cpp
+++ b/hotspot/src/share/vm/runtime/javaCalls.cpp
@@ -48,6 +48,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // -----------------------------------------------------
 // Implementation of JavaCallWrapper
@@ -557,4 +560,3 @@
   sc.check_doing_return(true);
   sc.iterate_returntype();
 }
-
diff --git a/hotspot/src/share/vm/runtime/javaCalls.hpp b/hotspot/src/share/vm/runtime/javaCalls.hpp
index af29462d..d4f8595 100644
--- a/hotspot/src/share/vm/runtime/javaCalls.hpp
+++ b/hotspot/src/share/vm/runtime/javaCalls.hpp
@@ -54,6 +54,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
 // Its purpose is to allocate/deallocate a new handle block and to save/restore the last
diff --git a/hotspot/src/share/vm/runtime/javaFrameAnchor.hpp b/hotspot/src/share/vm/runtime/javaFrameAnchor.hpp
index 501e59e1..8374aa2 100644
--- a/hotspot/src/share/vm/runtime/javaFrameAnchor.hpp
+++ b/hotspot/src/share/vm/runtime/javaFrameAnchor.hpp
@@ -50,6 +50,13 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "orderAccess_linux_ppc.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "orderAccess_bsd_x86.inline.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "orderAccess_bsd_zero.inline.hpp"
+#endif
+
 //
 // An object for encapsulating the machine/os dependent part of a JavaThread frame state
 //
diff --git a/hotspot/src/share/vm/runtime/jniHandles.cpp b/hotspot/src/share/vm/runtime/jniHandles.cpp
index e9c791d..3cbcaca 100644
--- a/hotspot/src/share/vm/runtime/jniHandles.cpp
+++ b/hotspot/src/share/vm/runtime/jniHandles.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 JNIHandleBlock* JNIHandles::_global_handles       = NULL;
diff --git a/hotspot/src/share/vm/runtime/memprofiler.cpp b/hotspot/src/share/vm/runtime/memprofiler.cpp
index cf49dd3..ab53d92 100644
--- a/hotspot/src/share/vm/runtime/memprofiler.cpp
+++ b/hotspot/src/share/vm/runtime/memprofiler.cpp
@@ -46,6 +46,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 #ifndef PRODUCT
 
diff --git a/hotspot/src/share/vm/runtime/mutex.cpp b/hotspot/src/share/vm/runtime/mutex.cpp
index 634ec43..80d3d87 100644
--- a/hotspot/src/share/vm/runtime/mutex.cpp
+++ b/hotspot/src/share/vm/runtime/mutex.cpp
@@ -39,6 +39,10 @@
 # include "mutex_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "mutex_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 // o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
 //
diff --git a/hotspot/src/share/vm/runtime/mutexLocker.cpp b/hotspot/src/share/vm/runtime/mutexLocker.cpp
index b3d082f..7653b5b 100644
--- a/hotspot/src/share/vm/runtime/mutexLocker.cpp
+++ b/hotspot/src/share/vm/runtime/mutexLocker.cpp
@@ -36,6 +36,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // Mutexes used in the VM (see comment in mutexLocker.hpp):
 //
diff --git a/hotspot/src/share/vm/runtime/mutexLocker.hpp b/hotspot/src/share/vm/runtime/mutexLocker.hpp
index 58060b8..37a3d31 100644
--- a/hotspot/src/share/vm/runtime/mutexLocker.hpp
+++ b/hotspot/src/share/vm/runtime/mutexLocker.hpp
@@ -36,6 +36,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 // Mutexes used in the VM.
 
diff --git a/hotspot/src/share/vm/runtime/objectMonitor.cpp b/hotspot/src/share/vm/runtime/objectMonitor.cpp
index e2b4bf2..cee8403 100644
--- a/hotspot/src/share/vm/runtime/objectMonitor.cpp
+++ b/hotspot/src/share/vm/runtime/objectMonitor.cpp
@@ -50,6 +50,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 #if defined(__GNUC__) && !defined(IA64)
   // Need to inhibit inlining for older versions of GCC to avoid build-time failures
@@ -64,16 +68,6 @@
 // Only bother with this argument setup if dtrace is available
 // TODO-FIXME: probes should not fire when caller is _blocked.  assert() accordingly.
 
-HS_DTRACE_PROBE_DECL4(hotspot, monitor__notify,
-  jlong, uintptr_t, char*, int);
-HS_DTRACE_PROBE_DECL4(hotspot, monitor__notifyAll,
-  jlong, uintptr_t, char*, int);
-HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__enter,
-  jlong, uintptr_t, char*, int);
-HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__entered,
-  jlong, uintptr_t, char*, int);
-HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__exit,
-  jlong, uintptr_t, char*, int);
 
 #define DTRACE_MONITOR_PROBE_COMMON(klassOop, thread)                      \
   char* bytes = NULL;                                                      \
@@ -85,6 +79,19 @@
     len = klassname->utf8_length();                                        \
   }
 
+#ifndef USDT2
+
+HS_DTRACE_PROBE_DECL4(hotspot, monitor__notify,
+  jlong, uintptr_t, char*, int);
+HS_DTRACE_PROBE_DECL4(hotspot, monitor__notifyAll,
+  jlong, uintptr_t, char*, int);
+HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__enter,
+  jlong, uintptr_t, char*, int);
+HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__entered,
+  jlong, uintptr_t, char*, int);
+HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__exit,
+  jlong, uintptr_t, char*, int);
+
 #define DTRACE_MONITOR_WAIT_PROBE(monitor, klassOop, thread, millis)       \
   {                                                                        \
     if (DTraceMonitorProbes) {                                            \
@@ -103,6 +110,33 @@
     }                                                                      \
   }
 
+#else /* USDT2 */
+
+#define DTRACE_MONITOR_WAIT_PROBE(monitor, klassOop, thread, millis)       \
+  {                                                                        \
+    if (DTraceMonitorProbes) {                                            \
+      DTRACE_MONITOR_PROBE_COMMON(klassOop, thread);                       \
+      HOTSPOT_MONITOR_WAIT(jtid,                                           \
+                       (monitor), bytes, len, (millis));                   \
+    }                                                                      \
+  }
+
+#define HOTSPOT_MONITOR_contended__enter HOTSPOT_MONITOR_CONTENDED_ENTER
+#define HOTSPOT_MONITOR_contended__entered HOTSPOT_MONITOR_CONTENDED_ENTERED
+#define HOTSPOT_MONITOR_contended__exit HOTSPOT_MONITOR_CONTENDED_EXIT
+#define HOTSPOT_MONITOR_notify HOTSPOT_MONITOR_NOTIFY
+#define HOTSPOT_MONITOR_notifyAll HOTSPOT_MONITOR_NOTIFYALL
+
+#define DTRACE_MONITOR_PROBE(probe, monitor, klassOop, thread)             \
+  {                                                                        \
+    if (DTraceMonitorProbes) {                                            \
+      DTRACE_MONITOR_PROBE_COMMON(klassOop, thread);                       \
+      HOTSPOT_MONITOR_##probe(jtid,                                               \
+                       (uintptr_t)(monitor), bytes, len);                  \
+    }                                                                      \
+  }
+
+#endif /* USDT2 */
 #else //  ndef DTRACE_ENABLED
 
 #define DTRACE_MONITOR_WAIT_PROBE(klassOop, thread, millis, mon)    {;}
diff --git a/hotspot/src/share/vm/runtime/os.cpp b/hotspot/src/share/vm/runtime/os.cpp
index 40ea175..583d32d 100644
--- a/hotspot/src/share/vm/runtime/os.cpp
+++ b/hotspot/src/share/vm/runtime/os.cpp
@@ -60,6 +60,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 # include <signal.h>
 
@@ -116,7 +120,11 @@
     assert(false, "Failed localtime_pd");
     return NULL;
   }
+#if defined(_ALLBSD_SOURCE)
+  const time_t zone = (time_t) time_struct.tm_gmtoff;
+#else
   const time_t zone = timezone;
+#endif
 
   // If daylight savings time is in effect,
   // we are 1 hour East of our time zone
@@ -384,6 +392,13 @@
     if (_native_java_library == NULL) {
       vm_exit_during_initialization("Unable to load native library", ebuf);
     }
+
+#if defined(__OpenBSD__)
+    // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so
+    // ignore errors
+    dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), "net");
+    dll_load(buffer, ebuf, sizeof(ebuf));
+#endif
   }
   static jboolean onLoaded = JNI_FALSE;
   if (onLoaded) {
@@ -1080,6 +1095,9 @@
         "%/lib/jsse.jar:"
         "%/lib/jce.jar:"
         "%/lib/charsets.jar:"
+#ifdef __APPLE__
+        "%/lib/JObjC.jar:"
+#endif
         "%/classes";
     char* sysclasspath = format_boot_path(classpath_format, home, home_len, fileSep, pathSep);
     if (sysclasspath == NULL) return false;
diff --git a/hotspot/src/share/vm/runtime/os.hpp b/hotspot/src/share/vm/runtime/os.hpp
index b43100d..80d29f7 100644
--- a/hotspot/src/share/vm/runtime/os.hpp
+++ b/hotspot/src/share/vm/runtime/os.hpp
@@ -39,6 +39,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "jvm_windows.h"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "jvm_bsd.h"
+#endif
 
 // os defines the interface to operating system; this includes traditional
 // OS services (time, I/O) as well as other functionality with system-
@@ -181,6 +184,9 @@
   //    Returns true if it worked, false if it didn't.
   static bool bind_to_processor(uint processor_id);
 
+  // Give a name to the current thread.
+  static void set_native_thread_name(const char *name);
+
   // Interface for stack banging (predetect possible stack overflow for
   // exception processing)  There are guard pages, and above that shadow
   // pages for stack overflow checking.
@@ -675,6 +681,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.hpp"
+#endif
 #ifdef TARGET_OS_ARCH_linux_x86
 # include "os_linux_x86.hpp"
 #endif
@@ -699,6 +708,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "os_linux_ppc.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "os_bsd_x86.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "os_bsd_zero.hpp"
+#endif
 
 
   // debugging support (mostly used by debug.cpp but also fatal error handler)
diff --git a/hotspot/src/share/vm/runtime/osThread.hpp b/hotspot/src/share/vm/runtime/osThread.hpp
index 5df645a..984bc9b 100644
--- a/hotspot/src/share/vm/runtime/osThread.hpp
+++ b/hotspot/src/share/vm/runtime/osThread.hpp
@@ -109,6 +109,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "osThread_windows.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "osThread_bsd.hpp"
+#endif
 
 };
 
diff --git a/hotspot/src/share/vm/runtime/safepoint.cpp b/hotspot/src/share/vm/runtime/safepoint.cpp
index bef8d6c..d338931 100644
--- a/hotspot/src/share/vm/runtime/safepoint.cpp
+++ b/hotspot/src/share/vm/runtime/safepoint.cpp
@@ -78,6 +78,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
 #include "gc_implementation/shared/concurrentGCThread.hpp"
diff --git a/hotspot/src/share/vm/runtime/sharedRuntime.cpp b/hotspot/src/share/vm/runtime/sharedRuntime.cpp
index 34369e8..486c21d 100644
--- a/hotspot/src/share/vm/runtime/sharedRuntime.cpp
+++ b/hotspot/src/share/vm/runtime/sharedRuntime.cpp
@@ -148,11 +148,13 @@
 
 #include <math.h>
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL4(hotspot, object__alloc, Thread*, char*, int, size_t);
 HS_DTRACE_PROBE_DECL7(hotspot, method__entry, int,
                       char*, int, char*, int, char*, int);
 HS_DTRACE_PROBE_DECL7(hotspot, method__return, int,
                       char*, int, char*, int, char*, int);
+#endif /* !USDT2 */
 
 // Implementation of SharedRuntime
 
@@ -659,12 +661,14 @@
   int scope_depth = 0;
   if (!force_unwind) {
     int bci = sd->bci();
+    bool recursive_exception = false;
     do {
       bool skip_scope_increment = false;
       // exception handler lookup
       KlassHandle ek (THREAD, exception->klass());
       handler_bci = sd->method()->fast_exception_handler_bci_for(ek, bci, THREAD);
       if (HAS_PENDING_EXCEPTION) {
+        recursive_exception = true;
         // We threw an exception while trying to find the exception handler.
         // Transfer the new exception to the exception handle which will
         // be set into thread local storage, and do another lookup for an
@@ -680,6 +684,9 @@
           skip_scope_increment = true;
         }
       }
+      else {
+        recursive_exception = false;
+      }
       if (!top_frame_only && handler_bci < 0 && !skip_scope_increment) {
         sd = sd->sender();
         if (sd != NULL) {
@@ -687,7 +694,7 @@
         }
         ++scope_depth;
       }
-    } while (!top_frame_only && handler_bci < 0 && sd != NULL);
+    } while (recursive_exception || (!top_frame_only && handler_bci < 0 && sd != NULL));
   }
 
   // found handling method => lookup exception handler
@@ -954,8 +961,14 @@
   Klass* klass = o->blueprint();
   int size = o->size();
   Symbol* name = klass->name();
+#ifndef USDT2
   HS_DTRACE_PROBE4(hotspot, object__alloc, get_java_tid(thread),
                    name->bytes(), name->utf8_length(), size * HeapWordSize);
+#else /* USDT2 */
+  HOTSPOT_OBJECT_ALLOC(
+                   get_java_tid(thread),
+                   (char *) name->bytes(), name->utf8_length(), size * HeapWordSize);
+#endif /* USDT2 */
   return 0;
 }
 
@@ -965,10 +978,18 @@
   Symbol* kname = method->klass_name();
   Symbol* name = method->name();
   Symbol* sig = method->signature();
+#ifndef USDT2
   HS_DTRACE_PROBE7(hotspot, method__entry, get_java_tid(thread),
       kname->bytes(), kname->utf8_length(),
       name->bytes(), name->utf8_length(),
       sig->bytes(), sig->utf8_length());
+#else /* USDT2 */
+  HOTSPOT_METHOD_ENTRY(
+      get_java_tid(thread),
+      (char *) kname->bytes(), kname->utf8_length(),
+      (char *) name->bytes(), name->utf8_length(),
+      (char *) sig->bytes(), sig->utf8_length());
+#endif /* USDT2 */
   return 0;
 JRT_END
 
@@ -978,10 +999,18 @@
   Symbol* kname = method->klass_name();
   Symbol* name = method->name();
   Symbol* sig = method->signature();
+#ifndef USDT2
   HS_DTRACE_PROBE7(hotspot, method__return, get_java_tid(thread),
       kname->bytes(), kname->utf8_length(),
       name->bytes(), name->utf8_length(),
       sig->bytes(), sig->utf8_length());
+#else /* USDT2 */
+  HOTSPOT_METHOD_RETURN(
+      get_java_tid(thread),
+      (char *) kname->bytes(), kname->utf8_length(),
+      (char *) name->bytes(), name->utf8_length(),
+      (char *) sig->bytes(), sig->utf8_length());
+#endif /* USDT2 */
   return 0;
 JRT_END
 
@@ -1643,9 +1672,12 @@
   nmethod* nm = cb->as_nmethod_or_null();
   assert(nm, "must be");
 
-  // Don't fixup MethodHandle call sites as c2i/i2c adapters are used
-  // to implement MethodHandle actions.
-  if (nm->is_method_handle_return(caller_pc)) {
+  // Get the return PC for the passed caller PC.
+  address return_pc = caller_pc + frame::pc_return_offset;
+
+  // Don't fixup method handle call sites as the executed method
+  // handle adapters are doing the required MethodHandle chain work.
+  if (nm->is_method_handle_return(return_pc)) {
     return;
   }
 
@@ -1664,8 +1696,8 @@
 
     // Expect to find a native call there (unless it was no-inline cache vtable dispatch)
     MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag);
-    if (NativeCall::is_call_before(caller_pc + frame::pc_return_offset)) {
-      NativeCall *call = nativeCall_before(caller_pc + frame::pc_return_offset);
+    if (NativeCall::is_call_before(return_pc)) {
+      NativeCall *call = nativeCall_before(return_pc);
       //
       // bug 6281185. We might get here after resolving a call site to a vanilla
       // virtual call. Because the resolvee uses the verified entry it may then
@@ -1715,7 +1747,6 @@
       }
     }
   }
-
 IRT_END
 
 
diff --git a/hotspot/src/share/vm/runtime/synchronizer.cpp b/hotspot/src/share/vm/runtime/synchronizer.cpp
index d51be5c..f2c3da0 100644
--- a/hotspot/src/share/vm/runtime/synchronizer.cpp
+++ b/hotspot/src/share/vm/runtime/synchronizer.cpp
@@ -51,6 +51,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 #if defined(__GNUC__) && !defined(IA64)
   // Need to inhibit inlining for older versions of GCC to avoid build-time failures
@@ -73,11 +77,6 @@
 // Only bother with this argument setup if dtrace is available
 // TODO-FIXME: probes should not fire when caller is _blocked.  assert() accordingly.
 
-HS_DTRACE_PROBE_DECL5(hotspot, monitor__wait,
-  jlong, uintptr_t, char*, int, long);
-HS_DTRACE_PROBE_DECL4(hotspot, monitor__waited,
-  jlong, uintptr_t, char*, int);
-
 #define DTRACE_MONITOR_PROBE_COMMON(klassOop, thread)                      \
   char* bytes = NULL;                                                      \
   int len = 0;                                                             \
@@ -88,6 +87,12 @@
     len = klassname->utf8_length();                                        \
   }
 
+#ifndef USDT2
+HS_DTRACE_PROBE_DECL5(hotspot, monitor__wait,
+  jlong, uintptr_t, char*, int, long);
+HS_DTRACE_PROBE_DECL4(hotspot, monitor__waited,
+  jlong, uintptr_t, char*, int);
+
 #define DTRACE_MONITOR_WAIT_PROBE(monitor, klassOop, thread, millis)       \
   {                                                                        \
     if (DTraceMonitorProbes) {                                            \
@@ -106,6 +111,29 @@
     }                                                                      \
   }
 
+#else /* USDT2 */
+
+#define DTRACE_MONITOR_WAIT_PROBE(monitor, klassOop, thread, millis)       \
+  {                                                                        \
+    if (DTraceMonitorProbes) {                                            \
+      DTRACE_MONITOR_PROBE_COMMON(klassOop, thread);                       \
+      HOTSPOT_MONITOR_WAIT(jtid,                                           \
+                           (uintptr_t)(monitor), bytes, len, (millis));  \
+    }                                                                      \
+  }
+
+#define HOTSPOT_MONITOR_PROBE_waited HOTSPOT_MONITOR_PROBE_WAITED
+
+#define DTRACE_MONITOR_PROBE(probe, monitor, klassOop, thread)             \
+  {                                                                        \
+    if (DTraceMonitorProbes) {                                            \
+      DTRACE_MONITOR_PROBE_COMMON(klassOop, thread);                       \
+      HOTSPOT_MONITOR_PROBE_##probe(jtid, /* probe = waited */             \
+                       (uintptr_t)(monitor), bytes, len);                  \
+    }                                                                      \
+  }
+
+#endif /* USDT2 */
 #else //  ndef DTRACE_ENABLED
 
 #define DTRACE_MONITOR_WAIT_PROBE(klassOop, thread, millis, mon)    {;}
diff --git a/hotspot/src/share/vm/runtime/task.cpp b/hotspot/src/share/vm/runtime/task.cpp
index 4c0cff7..bd45d65 100644
--- a/hotspot/src/share/vm/runtime/task.cpp
+++ b/hotspot/src/share/vm/runtime/task.cpp
@@ -39,6 +39,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 int PeriodicTask::_num_tasks = 0;
 PeriodicTask* PeriodicTask::_tasks[PeriodicTask::max_tasks];
diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp
index 8b7059c..a8cbf85 100644
--- a/hotspot/src/share/vm/runtime/thread.cpp
+++ b/hotspot/src/share/vm/runtime/thread.cpp
@@ -89,6 +89,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
@@ -106,6 +110,7 @@
 
 // Only bother with this argument setup if dtrace is available
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL(hotspot, vm__init__begin);
 HS_DTRACE_PROBE_DECL(hotspot, vm__init__end);
 HS_DTRACE_PROBE_DECL5(hotspot, thread__start, char*, intptr_t,
@@ -126,6 +131,26 @@
       java_lang_Thread::is_daemon((javathread)->threadObj()));             \
   }
 
+#else /* USDT2 */
+
+#define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_PROBE_START
+#define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_PROBE_STOP
+
+#define DTRACE_THREAD_PROBE(probe, javathread)                             \
+  {                                                                        \
+    ResourceMark rm(this);                                                 \
+    int len = 0;                                                           \
+    const char* name = (javathread)->get_thread_name();                    \
+    len = strlen(name);                                                    \
+    HOTSPOT_THREAD_PROBE_##probe(  /* probe = start, stop */               \
+      (char *) name, len,                                                           \
+      java_lang_Thread::thread_id((javathread)->threadObj()),              \
+      (uintptr_t) (javathread)->osthread()->thread_id(),                               \
+      java_lang_Thread::is_daemon((javathread)->threadObj()));             \
+  }
+
+#endif /* USDT2 */
+
 #else //  ndef DTRACE_ENABLED
 
 #define DTRACE_THREAD_PROBE(probe, javathread)
@@ -1324,7 +1349,7 @@
 DirtyCardQueueSet JavaThread::_dirty_card_queue_set;
 #endif // !SERIALGC
 
-JavaThread::JavaThread(bool is_attaching) :
+JavaThread::JavaThread(bool is_attaching_via_jni) :
   Thread()
 #ifndef SERIALGC
   , _satb_mark_queue(&_satb_mark_queue_set),
@@ -1332,7 +1357,11 @@
 #endif // !SERIALGC
 {
   initialize();
-  _is_attaching = is_attaching;
+  if (is_attaching_via_jni) {
+    _jni_attach_state = _attaching_via_jni;
+  } else {
+    _jni_attach_state = _not_attaching_via_jni;
+  }
   assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor");
 }
 
@@ -1388,7 +1417,7 @@
     tty->print_cr("creating thread %p", this);
   }
   initialize();
-  _is_attaching = false;
+  _jni_attach_state = _not_attaching_via_jni;
   set_entry_point(entry_point);
   // Create the native thread itself.
   // %note runtime_23
@@ -1500,6 +1529,10 @@
   // Note: Due to JVM_StopThread we can have pending exceptions already!
   if (!this->has_pending_exception() &&
       !java_lang_Thread::is_stillborn(this->threadObj())) {
+    {
+      ResourceMark rm(this);
+      this->set_native_thread_name(this->get_thread_name());
+    }
     HandleMark hm(this);
     this->entry_point()(this, this);
   }
@@ -2679,7 +2712,7 @@
         name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen);
       }
     }
-    else if (is_attaching()) { // workaround for 6412693 - see 6404306
+    else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306
       name_str = "<no-name - thread is attaching>";
     }
     else {
@@ -2914,7 +2947,7 @@
     values.validate();
   } else {
     tty->print_cr("[Describe stack layout]");
-    values.print();
+    values.print(this);
   }
 }
 #endif
@@ -3075,7 +3108,11 @@
     os::pause();
   }
 
+#ifndef USDT2
   HS_DTRACE_PROBE(hotspot, vm__init__begin);
+#else /* USDT2 */
+  HOTSPOT_VM_INIT_BEGIN();
+#endif /* USDT2 */
 
   // Record VM creation timing statistics
   TraceVmCreationTime create_vm_timer;
@@ -3330,7 +3367,11 @@
   // debug stuff, that does not work until all basic classes have been initialized.
   set_init_completed();
 
+#ifndef USDT2
   HS_DTRACE_PROBE(hotspot, vm__init__end);
+#else /* USDT2 */
+  HOTSPOT_VM_INIT_END();
+#endif /* USDT2 */
 
   // record VM initialization completion time
   Management::record_vm_init_completed();
diff --git a/hotspot/src/share/vm/runtime/thread.hpp b/hotspot/src/share/vm/runtime/thread.hpp
index 4d5478b..da13f12 100644
--- a/hotspot/src/share/vm/runtime/thread.hpp
+++ b/hotspot/src/share/vm/runtime/thread.hpp
@@ -309,6 +309,11 @@
   static void interrupt(Thread* thr);
   static bool is_interrupted(Thread* thr, bool clear_interrupted);
 
+  void set_native_thread_name(const char *name) {
+    assert(Thread::current() == this, "set_native_thread_name can only be called on the current thread");
+    os::set_native_thread_name(name);
+  }
+
   ObjectMonitor** omInUseList_addr()             { return (ObjectMonitor **)&omInUseList; }
   Monitor* SR_lock() const                       { return _SR_lock; }
 
@@ -818,10 +823,17 @@
   bool                  _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was
                                                  // never locked) when throwing an exception. Used by interpreter only.
 
-  //  Flag to mark a JNI thread in the process of attaching - See CR 6404306
-  //  This flag is never set true other than at construction, and in that case
-  //  is shortly thereafter set false
-  volatile bool _is_attaching;
+  // JNI attach states:
+  enum JNIAttachStates {
+    _not_attaching_via_jni = 1,  // thread is not attaching via JNI
+    _attaching_via_jni,          // thread is attaching via JNI
+    _attached_via_jni            // thread has attached via JNI
+  };
+
+  // A regular JavaThread's _jni_attach_state is _not_attaching_via_jni.
+  // A native thread that is attaching via JNI starts with a value
+  // of _attaching_via_jni and transitions to _attached_via_jni.
+  volatile JNIAttachStates _jni_attach_state;
 
  public:
   // State of the stack guard pages for this thread.
@@ -889,7 +901,7 @@
 
  public:
   // Constructor
-  JavaThread(bool is_attaching = false); // for main thread and JNI attached threads
+  JavaThread(bool is_attaching_via_jni = false); // for main thread and JNI attached threads
   JavaThread(ThreadFunction entry_point, size_t stack_size = 0);
   ~JavaThread();
 
@@ -1607,6 +1619,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "thread_linux_ppc.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "thread_bsd_x86.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "thread_bsd_zero.hpp"
+#endif
 
 
  public:
@@ -1635,8 +1653,9 @@
   void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; }
 
   // clearing/querying jni attach status
-  bool is_attaching() const { return _is_attaching; }
-  void set_attached() { _is_attaching = false; OrderAccess::fence(); }
+  bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; }
+  bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; }
+  void set_done_attaching_via_jni() { _jni_attach_state = _attached_via_jni; OrderAccess::fence(); }
 private:
   // This field is used to determine if a thread has claimed
   // a par_id: it is -1 if the thread has not claimed a par_id;
diff --git a/hotspot/src/share/vm/runtime/threadLocalStorage.cpp b/hotspot/src/share/vm/runtime/threadLocalStorage.cpp
index 0b35cda..0cdc48a 100644
--- a/hotspot/src/share/vm/runtime/threadLocalStorage.cpp
+++ b/hotspot/src/share/vm/runtime/threadLocalStorage.cpp
@@ -36,6 +36,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 // static member initialization
 int ThreadLocalStorage::_thread_index = -1;
diff --git a/hotspot/src/share/vm/runtime/threadLocalStorage.hpp b/hotspot/src/share/vm/runtime/threadLocalStorage.hpp
index c936216..c2f7a9e 100644
--- a/hotspot/src/share/vm/runtime/threadLocalStorage.hpp
+++ b/hotspot/src/share/vm/runtime/threadLocalStorage.hpp
@@ -68,6 +68,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "threadLS_linux_ppc.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "threadLS_bsd_x86.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "threadLS_bsd_zero.hpp"
+#endif
 
 
  public:
diff --git a/hotspot/src/share/vm/runtime/timer.cpp b/hotspot/src/share/vm/runtime/timer.cpp
index 8e6bbbe..ea05533 100644
--- a/hotspot/src/share/vm/runtime/timer.cpp
+++ b/hotspot/src/share/vm/runtime/timer.cpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 
 void elapsedTimer::add(elapsedTimer t) {
diff --git a/hotspot/src/share/vm/runtime/virtualspace.cpp b/hotspot/src/share/vm/runtime/virtualspace.cpp
index f290cf3..5eeb1ee 100644
--- a/hotspot/src/share/vm/runtime/virtualspace.cpp
+++ b/hotspot/src/share/vm/runtime/virtualspace.cpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 
 // ReservedSpace
diff --git a/hotspot/src/share/vm/runtime/vmStructs.cpp b/hotspot/src/share/vm/runtime/vmStructs.cpp
index 982b389..00fe358 100644
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp
@@ -133,6 +133,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifdef TARGET_OS_ARCH_linux_x86
 # include "vmStructs_linux_x86.hpp"
 #endif
@@ -157,6 +160,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "vmStructs_linux_ppc.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "vmStructs_bsd_x86.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "vmStructs_bsd_zero.hpp"
+#endif
 #ifndef SERIALGC
 #include "gc_implementation/concurrentMarkSweep/cmsPermGen.hpp"
 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
diff --git a/hotspot/src/share/vm/runtime/vmThread.cpp b/hotspot/src/share/vm/runtime/vmThread.cpp
index c50e0a1..d4fced2 100644
--- a/hotspot/src/share/vm/runtime/vmThread.cpp
+++ b/hotspot/src/share/vm/runtime/vmThread.cpp
@@ -46,10 +46,15 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL3(hotspot, vmops__request, char *, uintptr_t, int);
 HS_DTRACE_PROBE_DECL3(hotspot, vmops__begin, char *, uintptr_t, int);
 HS_DTRACE_PROBE_DECL3(hotspot, vmops__end, char *, uintptr_t, int);
+#endif /* !USDT2 */
 
 // Dummy VM operation to act as first element in our circular double-linked list
 class VM_Dummy: public VM_Operation {
@@ -159,8 +164,14 @@
 // High-level interface
 bool VMOperationQueue::add(VM_Operation *op) {
 
+#ifndef USDT2
   HS_DTRACE_PROBE3(hotspot, vmops__request, op->name(), strlen(op->name()),
                    op->evaluation_mode());
+#else /* USDT2 */
+  HOTSPOT_VMOPS_REQUEST(
+                   (char *) op->name(), strlen(op->name()),
+                   op->evaluation_mode());
+#endif /* USDT2 */
 
   // Encapsulates VM queue policy. Currently, that
   // only involves putting them on the right list
@@ -357,11 +368,23 @@
 
   {
     PerfTraceTime vm_op_timer(perf_accumulated_vm_operation_time());
+#ifndef USDT2
     HS_DTRACE_PROBE3(hotspot, vmops__begin, op->name(), strlen(op->name()),
                      op->evaluation_mode());
+#else /* USDT2 */
+    HOTSPOT_VMOPS_BEGIN(
+                     (char *) op->name(), strlen(op->name()),
+                     op->evaluation_mode());
+#endif /* USDT2 */
     op->evaluate();
+#ifndef USDT2
     HS_DTRACE_PROBE3(hotspot, vmops__end, op->name(), strlen(op->name()),
                      op->evaluation_mode());
+#else /* USDT2 */
+    HOTSPOT_VMOPS_END(
+                     (char *) op->name(), strlen(op->name()),
+                     op->evaluation_mode());
+#endif /* USDT2 */
   }
 
   // Last access of info in _cur_vm_operation!
diff --git a/hotspot/src/share/vm/runtime/vmThread.hpp b/hotspot/src/share/vm/runtime/vmThread.hpp
index 6698b12..f784496 100644
--- a/hotspot/src/share/vm/runtime/vmThread.hpp
+++ b/hotspot/src/share/vm/runtime/vmThread.hpp
@@ -36,6 +36,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 //
 // Prioritized queue of VM operations.
diff --git a/hotspot/src/share/vm/runtime/vm_operations.cpp b/hotspot/src/share/vm/runtime/vm_operations.cpp
index cb5d138..b010b9a 100644
--- a/hotspot/src/share/vm/runtime/vm_operations.cpp
+++ b/hotspot/src/share/vm/runtime/vm_operations.cpp
@@ -45,6 +45,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 #define VM_OP_NAME_INITIALIZE(name) #name,
 
diff --git a/hotspot/src/share/vm/runtime/vm_version.cpp b/hotspot/src/share/vm/runtime/vm_version.cpp
index 524ec49..eb55014 100644
--- a/hotspot/src/share/vm/runtime/vm_version.cpp
+++ b/hotspot/src/share/vm/runtime/vm_version.cpp
@@ -128,7 +128,7 @@
 #ifndef HOTSPOT_VM_DISTRO
   #error HOTSPOT_VM_DISTRO must be defined
 #endif
-#define VMNAME HOTSPOT_VM_DISTRO " " VMLP VMTYPE " VM"
+#define VMNAME HOTSPOT_VM_DISTRO " " VMLP EMBEDDED_ONLY("Embedded ") VMTYPE " VM"
 
 const char* Abstract_VM_Version::vm_name() {
   return VMNAME;
@@ -167,7 +167,8 @@
 
 #define OS       LINUX_ONLY("linux")             \
                  WINDOWS_ONLY("windows")         \
-                 SOLARIS_ONLY("solaris")
+                 SOLARIS_ONLY("solaris")         \
+                 BSD_ONLY("bsd")
 
 #ifdef ZERO
 #define CPU      ZERO_LIBARCH
diff --git a/hotspot/src/share/vm/services/classLoadingService.cpp b/hotspot/src/share/vm/services/classLoadingService.cpp
index 0f3ad68..b26258a 100644
--- a/hotspot/src/share/vm/services/classLoadingService.cpp
+++ b/hotspot/src/share/vm/services/classLoadingService.cpp
@@ -36,6 +36,8 @@
 
 // Only bother with this argument setup if dtrace is available
 
+#ifndef USDT2
+
 HS_DTRACE_PROBE_DECL4(hotspot, class__loaded, char*, int, oop, bool);
 HS_DTRACE_PROBE_DECL4(hotspot, class__unloaded, char*, int, oop, bool);
 
@@ -52,6 +54,24 @@
       data, len, (clss)->class_loader(), (shared)); \
   }
 
+#else /* USDT2 */
+
+#define HOTSPOT_CLASS_unloaded HOTSPOT_CLASS_UNLOADED
+#define HOTSPOT_CLASS_loaded HOTSPOT_CLASS_LOADED
+#define DTRACE_CLASSLOAD_PROBE(type, clss, shared)  \
+  {                                                 \
+    char* data = NULL;                              \
+    int len = 0;                                    \
+    Symbol* name = (clss)->name();                  \
+    if (name != NULL) {                             \
+      data = (char*)name->bytes();                  \
+      len = name->utf8_length();                    \
+    }                                               \
+    HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \
+      data, len, (clss)->class_loader(), (shared)); \
+  }
+
+#endif /* USDT2 */
 #else //  ndef DTRACE_ENABLED
 
 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared)
diff --git a/hotspot/src/share/vm/services/memoryManager.cpp b/hotspot/src/share/vm/services/memoryManager.cpp
index 3977a45..ceb6f4c 100644
--- a/hotspot/src/share/vm/services/memoryManager.cpp
+++ b/hotspot/src/share/vm/services/memoryManager.cpp
@@ -36,10 +36,12 @@
 #include "services/gcNotifier.hpp"
 #include "utilities/dtrace.hpp"
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL8(hotspot, mem__pool__gc__begin, char*, int, char*, int,
   size_t, size_t, size_t, size_t);
 HS_DTRACE_PROBE_DECL8(hotspot, mem__pool__gc__end, char*, int, char*, int,
   size_t, size_t, size_t, size_t);
+#endif /* !USDT2 */
 
 MemoryManager::MemoryManager() {
   _num_pools = 0;
@@ -238,11 +240,19 @@
       MemoryPool* pool = MemoryService::get_memory_pool(i);
       MemoryUsage usage = pool->get_memory_usage();
       _current_gc_stat->set_before_gc_usage(i, usage);
+#ifndef USDT2
       HS_DTRACE_PROBE8(hotspot, mem__pool__gc__begin,
         name(), strlen(name()),
         pool->name(), strlen(pool->name()),
         usage.init_size(), usage.used(),
         usage.committed(), usage.max_size());
+#else /* USDT2 */
+      HOTSPOT_MEM_POOL_GC_BEGIN(
+        (char *) name(), strlen(name()),
+        (char *) pool->name(), strlen(pool->name()),
+        usage.init_size(), usage.used(),
+        usage.committed(), usage.max_size());
+#endif /* USDT2 */
     }
   }
 }
@@ -268,11 +278,19 @@
       MemoryPool* pool = MemoryService::get_memory_pool(i);
       MemoryUsage usage = pool->get_memory_usage();
 
+#ifndef USDT2
       HS_DTRACE_PROBE8(hotspot, mem__pool__gc__end,
         name(), strlen(name()),
         pool->name(), strlen(pool->name()),
         usage.init_size(), usage.used(),
         usage.committed(), usage.max_size());
+#else /* USDT2 */
+      HOTSPOT_MEM_POOL_GC_END(
+        (char *) name(), strlen(name()),
+        (char *) pool->name(), strlen(pool->name()),
+        usage.init_size(), usage.used(),
+        usage.committed(), usage.max_size());
+#endif /* USDT2 */
 
       _current_gc_stat->set_after_gc_usage(i, usage);
     }
diff --git a/hotspot/src/share/vm/services/runtimeService.cpp b/hotspot/src/share/vm/services/runtimeService.cpp
index 7efac61..6ff1c68 100644
--- a/hotspot/src/share/vm/services/runtimeService.cpp
+++ b/hotspot/src/share/vm/services/runtimeService.cpp
@@ -30,8 +30,10 @@
 #include "utilities/dtrace.hpp"
 #include "utilities/exceptions.hpp"
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL(hs_private, safepoint__begin);
 HS_DTRACE_PROBE_DECL(hs_private, safepoint__end);
+#endif /* !USDT2 */
 
 TimeStamp RuntimeService::_app_timer;
 TimeStamp RuntimeService::_safepoint_timer;
@@ -108,7 +110,11 @@
 }
 
 void RuntimeService::record_safepoint_begin() {
+#ifndef USDT2
   HS_DTRACE_PROBE(hs_private, safepoint__begin);
+#else /* USDT2 */
+  HS_PRIVATE_SAFEPOINT_BEGIN();
+#endif /* USDT2 */
 
   // Print the time interval in which the app was executing
   if (PrintGCApplicationConcurrentTime) {
@@ -133,7 +139,11 @@
 }
 
 void RuntimeService::record_safepoint_end() {
+#ifndef USDT2
   HS_DTRACE_PROBE(hs_private, safepoint__end);
+#else /* USDT2 */
+  HS_PRIVATE_SAFEPOINT_END();
+#endif /* USDT2 */
 
   // Print the time interval for which the app was stopped
   // during the current safepoint operation.
diff --git a/hotspot/src/share/vm/services/threadService.cpp b/hotspot/src/share/vm/services/threadService.cpp
index d52b765..09f09f2 100644
--- a/hotspot/src/share/vm/services/threadService.cpp
+++ b/hotspot/src/share/vm/services/threadService.cpp
@@ -751,7 +751,7 @@
       _blocker_object = obj();
       JavaThread* owner = ObjectSynchronizer::get_lock_owner(obj, false);
       if ((owner == NULL && _thread_status == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER)
-          || (owner != NULL && owner->is_attaching())) {
+          || (owner != NULL && owner->is_attaching_via_jni())) {
         // ownership information of the monitor is not available
         // (may no longer be owned or releasing to some other thread)
         // make this thread in RUNNABLE state.
@@ -899,7 +899,7 @@
     }
 
     // skip jni threads in the process of attaching
-    if (!include_jni_attaching_threads && jt->is_attaching()) {
+    if (!include_jni_attaching_threads && jt->is_attaching_via_jni()) {
       continue;
     }
 
diff --git a/hotspot/src/share/vm/utilities/accessFlags.cpp b/hotspot/src/share/vm/utilities/accessFlags.cpp
index f244d0f..0c6ea1b 100644
--- a/hotspot/src/share/vm/utilities/accessFlags.cpp
+++ b/hotspot/src/share/vm/utilities/accessFlags.cpp
@@ -34,6 +34,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 
 void AccessFlags::atomic_set_bits(jint bits) {
diff --git a/hotspot/src/share/vm/utilities/array.cpp b/hotspot/src/share/vm/utilities/array.cpp
index ffea394..44782ea 100644
--- a/hotspot/src/share/vm/utilities/array.cpp
+++ b/hotspot/src/share/vm/utilities/array.cpp
@@ -34,6 +34,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 #ifdef ASSERT
diff --git a/hotspot/src/share/vm/utilities/bitMap.cpp b/hotspot/src/share/vm/utilities/bitMap.cpp
index b7c82ee..17231d3 100644
--- a/hotspot/src/share/vm/utilities/bitMap.cpp
+++ b/hotspot/src/share/vm/utilities/bitMap.cpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 
 BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
diff --git a/hotspot/src/share/vm/utilities/debug.cpp b/hotspot/src/share/vm/utilities/debug.cpp
index 27eaea8..b96e5bd 100644
--- a/hotspot/src/share/vm/utilities/debug.cpp
+++ b/hotspot/src/share/vm/utilities/debug.cpp
@@ -62,6 +62,10 @@
 # include "os_windows.inline.hpp"
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+# include "thread_bsd.inline.hpp"
+#endif
 
 #ifndef ASSERT
 #  ifdef _DEBUG
@@ -205,7 +209,7 @@
 // Place-holder for non-existent suppression check:
 #define error_is_suppressed(file_name, line_no) (false)
 
-#endif //PRODUCT
+#endif // !PRODUCT
 
 void report_vm_error(const char* file, int line, const char* error_msg,
                      const char* detail_msg)
@@ -260,7 +264,7 @@
 void report_untested(const char* file, int line, const char* message) {
 #ifndef PRODUCT
   warning("Untested: %s in %s: %d\n", message, file, line);
-#endif // PRODUCT
+#endif // !PRODUCT
 }
 
 void report_out_of_shared_space(SharedSpaceType shared_space) {
@@ -305,9 +309,6 @@
   }
 }
 
-
-extern "C" void ps();
-
 static bool error_reported = false;
 
 // call this when the VM is dying--it might loosen some asserts
@@ -362,11 +363,10 @@
     default: ShouldNotReachHere();
   }
 }
-#endif // #ifndef PRODUCT
+#endif // !PRODUCT
 
 // ------ helper functions for debugging go here ------------
 
-#ifndef PRODUCT
 // All debug entries should be wrapped with a stack allocated
 // Command object. It makes sure a resource mark is set and
 // flushes the logfile to prevent file sharing problems.
@@ -387,11 +387,17 @@
     tty->print_cr("\"Executing %s\"", str);
   }
 
-  ~Command() { tty->flush(); Debugging = debug_save; level--; }
+  ~Command() {
+        tty->flush();
+        Debugging = debug_save;
+        level--;
+  }
 };
 
 int Command::level = 0;
 
+#ifndef PRODUCT
+
 extern "C" void blob(CodeBlob* cb) {
   Command c("blob");
   cb->print();
@@ -474,7 +480,7 @@
     oop obj = oop(p);
     obj->print();
   } else {
-    tty->print("%#p", p);
+    tty->print(PTR_FORMAT, p);
   }
 }
 
@@ -483,7 +489,10 @@
 extern "C" void pa(intptr_t p)   { ((AllocatedObj*) p)->print(); }
 extern "C" void findpc(intptr_t x);
 
+#endif // !PRODUCT
+
 extern "C" void ps() { // print stack
+  if (Thread::current() == NULL) return;
   Command c("ps");
 
 
@@ -496,6 +505,11 @@
   if (p->has_last_Java_frame()) {
     // If the last_Java_fp is set we are in C land and
     // can call the standard stack_trace function.
+#ifdef PRODUCT
+    p->print_stack();
+  } else {
+    tty->print_cr("Cannot find the last Java frame, printing stack disabled.");
+#else // !PRODUCT
     p->trace_stack();
   } else {
     frame f = os::current_frame();
@@ -504,6 +518,7 @@
     tty->print("(guessing starting frame id=%#p based on current fp)\n", f.id());
     p->trace_stack_from(vframe::new_vframe(&f, &reg_map, p));
   pd_ps(f);
+#endif // PRODUCT
   }
 
 }
@@ -520,6 +535,8 @@
   }
 }
 
+#ifndef PRODUCT
+
 extern "C" void psf() { // print stack frames
   {
     Command c("psf");
@@ -551,12 +568,15 @@
   SafepointSynchronize::print_state();
 }
 
+#endif // !PRODUCT
 
 extern "C" void pss() { // print all stacks
+  if (Thread::current() == NULL) return;
   Command c("pss");
-  Threads::print(true, true);
+  Threads::print(true, PRODUCT_ONLY(false) NOT_PRODUCT(true));
 }
 
+#ifndef PRODUCT
 
 extern "C" void debug() {               // to set things up for compiler debugging
   Command c("debug");
@@ -907,4 +927,4 @@
 }
 #endif
 
-#endif // PRODUCT
+#endif // !PRODUCT
diff --git a/hotspot/src/share/vm/utilities/decoder.cpp b/hotspot/src/share/vm/utilities/decoder.cpp
index 032a8c2..ed156de 100644
--- a/hotspot/src/share/vm/utilities/decoder.cpp
+++ b/hotspot/src/share/vm/utilities/decoder.cpp
@@ -29,7 +29,7 @@
 Decoder::decoder_status  Decoder::_decoder_status = Decoder::no_error;
 bool                     Decoder::_initialized = false;
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
 
 // Implementation of common functionalities among Solaris and Linux
 #include "utilities/elfFile.hpp"
@@ -101,4 +101,3 @@
 }
 
 #endif
-
diff --git a/hotspot/src/share/vm/utilities/decoder.hpp b/hotspot/src/share/vm/utilities/decoder.hpp
index ade0fc2..70ffe21 100644
--- a/hotspot/src/share/vm/utilities/decoder.hpp
+++ b/hotspot/src/share/vm/utilities/decoder.hpp
@@ -38,6 +38,8 @@
 typedef BOOL  (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
 typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWORD);
 
+#elif defined(__APPLE__)
+
 #else
 
 class ElfFile;
@@ -79,7 +81,7 @@
 
   static decoder_status    get_status() { return _decoder_status; };
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
  private:
   static ElfFile*         get_elf_file(const char* filepath);
 #endif // _WINDOWS
@@ -94,6 +96,7 @@
   static bool                      _can_decode_in_vm;
   static pfn_SymGetSymFromAddr64   _pfnSymGetSymFromAddr64;
   static pfn_UndecorateSymbolName  _pfnUndecorateSymbolName;
+#elif __APPLE__
 #else
   static ElfFile*                  _opened_elf_files;
 #endif // _WINDOWS
diff --git a/hotspot/src/share/vm/utilities/dtrace.hpp b/hotspot/src/share/vm/utilities/dtrace.hpp
index 2f85694..799cd72 100644
--- a/hotspot/src/share/vm/utilities/dtrace.hpp
+++ b/hotspot/src/share/vm/utilities/dtrace.hpp
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_UTILITIES_DTRACE_HPP
 #define SHARE_VM_UTILITIES_DTRACE_HPP
 
-#if defined(SOLARIS) && defined(DTRACE_ENABLED)
+#if defined(DTRACE_ENABLED)
 
 #include <sys/sdt.h>
 
@@ -36,11 +36,27 @@
 #define HS_DTRACE_WORKAROUND_TAIL_CALL_BUG() \
   do { volatile size_t dtrace_workaround_tail_call_bug = 1; } while (0)
 
-#else // ndef SOLARIS || ndef DTRACE_ENABLED
+#if defined(SOLARIS)
+#define USDT1 1
+#elif defined(__APPLE__)
+#define USDT2 1
+#include <sys/types.h>
+#include "dtracefiles/hotspot.h"
+#include "dtracefiles/hotspot_jni.h"
+#include "dtracefiles/hs_private.h"
+#else
+#error "dtrace enabled for unknown os"
+#endif /* defined(SOLARIS) */
+
+#else /* defined(DTRACE_ENABLED) */
 
 #define DTRACE_ONLY(x)
 #define NOT_DTRACE(x) x
 
+#define HS_DTRACE_WORKAROUND_TAIL_CALL_BUG()
+
+#ifndef USDT2
+
 #define DTRACE_PROBE(a,b) {;}
 #define DTRACE_PROBE1(a,b,c) {;}
 #define DTRACE_PROBE2(a,b,c,d) {;}
@@ -48,9 +64,14 @@
 #define DTRACE_PROBE4(a,b,c,d,e,f) {;}
 #define DTRACE_PROBE5(a,b,c,d,e,f,g) {;}
 
-#define HS_DTRACE_WORKAROUND_TAIL_CALL_BUG()
+#else /* USDT2 */
 
-#endif
+#include "dtrace_usdt2_disabled.hpp"
+#endif /* USDT2 */
+
+#endif /* defined(DTRACE_ENABLED) */
+
+#ifndef USDT2
 
 #define HS_DTRACE_PROBE_FN(provider,name)\
   __dtrace_##provider##___##name
@@ -133,4 +154,6 @@
     (uintptr_t)a3,(uintptr_t)a4,(uintptr_t)a5,(uintptr_t)a6,(uintptr_t)a7,\
     (uintptr_t)a8,(uintptr_t)a9))
 
+#endif /* !USDT2 */
+
 #endif // SHARE_VM_UTILITIES_DTRACE_HPP
diff --git a/hotspot/src/share/vm/utilities/dtrace_usdt2_disabled.hpp b/hotspot/src/share/vm/utilities/dtrace_usdt2_disabled.hpp
new file mode 100644
index 0000000..5606bf6
--- /dev/null
+++ b/hotspot/src/share/vm/utilities/dtrace_usdt2_disabled.hpp
@@ -0,0 +1,1097 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_VM_UTILITIES_DTRACE_USDT2_DISABLED_HPP
+#define SHARE_VM_UTILITIES_DTRACE_USDT2_DISABLED_HPP
+
+/* This file contains dummy provider probes needed when compiling a hotspot
+ * that does not support dtrace probes. This could be because we're building
+ * on a system that doesn't suuport dtrace or because we're bulding a variant
+ * of hotspot (like core) where we do not support dtrace
+ */
+#if !defined(DTRACE_ENABLED)
+
+#ifdef USDT2
+
+/* hotspot provider probes */
+#define HOTSPOT_CLASS_LOADED(arg0, arg1, arg2, arg3)
+#define HOTSPOT_CLASS_LOADED_ENABLED()  0
+#define HOTSPOT_CLASS_UNLOADED(arg0, arg1, arg2, arg3)
+#define HOTSPOT_CLASS_UNLOADED_ENABLED()  0
+#define HOTSPOT_CLASS_INITIALIZATION_REQUIRED(arg0, arg1, arg2, arg3)
+#define HOTSPOT_CLASS_INITIALIZATION_REQUIRED_ENABLED() 0
+#define HOTSPOT_CLASS_INITIALIZATION_RECURSIVE(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_CLASS_INITIALIZATION_RECURSIVE_ENABLED() 0
+#define HOTSPOT_CLASS_INITIALIZATION_CONCURRENT(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_CLASS_INITIALIZATION_CONCURRENT_ENABLED() 0
+#define HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS_ENABLED() 0
+#define HOTSPOT_CLASS_INITIALIZATION_SUPER_FAILED(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_CLASS_INITIALIZATION_SUPER_FAILED_ENABLED() 0
+#define HOTSPOT_CLASS_INITIALIZATION_CLINIT(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_CLASS_INITIALIZATION_CLINIT_ENABLED() 0
+#define HOTSPOT_CLASS_INITIALIZATION_ERROR(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_CLASS_INITIALIZATION_ERROR_ENABLED() 0
+#define HOTSPOT_CLASS_INITIALIZATION_END(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_CLASS_INITIALIZATION_END_ENABLED() 0
+#define HOTSPOT_COMPILED_METHOD_LOAD(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
+#define HOTSPOT_COMPILED_METHOD_LOAD_ENABLED()  0
+#define HOTSPOT_COMPILED_METHOD_UNLOAD(arg0, arg1, arg2, arg3, arg4, arg5)
+#define HOTSPOT_COMPILED_METHOD_UNLOAD_ENABLED() 0
+#define HOTSPOT_GC_BEGIN(arg0)
+#define HOTSPOT_GC_BEGIN_ENABLED() 0
+#define HOTSPOT_GC_END()
+#define HOTSPOT_GC_END_ENABLED() 0
+#define HOTSPOT_MEM_POOL_GC_BEGIN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
+#define HOTSPOT_MEM_POOL_GC_BEGIN_ENABLED() 0
+#define HOTSPOT_MEM_POOL_GC_END(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
+#define HOTSPOT_MEM_POOL_GC_END_ENABLED() 0
+#define HOTSPOT_METHOD_COMPILE_BEGIN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
+#define HOTSPOT_METHOD_COMPILE_BEGIN_ENABLED() 0
+#define HOTSPOT_METHOD_COMPILE_END(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
+#define HOTSPOT_METHOD_COMPILE_END_ENABLED() 0
+#define HOTSPOT_METHOD_ENTRY(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
+#define HOTSPOT_METHOD_ENTRY_ENABLED() 0
+#define HOTSPOT_METHOD_RETURN(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
+#define HOTSPOT_METHOD_RETURN_ENABLED() 0
+#define HOTSPOT_MONITOR_CONTENDED_ENTER(arg0, arg1, arg2, arg3)
+#define HOTSPOT_MONITOR_CONTENDED_ENTER_ENABLED() 0
+#define HOTSPOT_MONITOR_CONTENDED_ENTERED(arg0, arg1, arg2, arg3)
+#define HOTSPOT_MONITOR_CONTENDED_ENTERED_ENABLED() 0
+#define HOTSPOT_MONITOR_CONTENDED_EXIT(arg0, arg1, arg2, arg3)
+#define HOTSPOT_MONITOR_CONTENDED_EXIT_ENABLED() 0
+#define HOTSPOT_MONITOR_NOTIFY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_MONITOR_NOTIFY_ENABLED() 0
+#define HOTSPOT_MONITOR_NOTIFYALL(arg0, arg1, arg2, arg3)
+#define HOTSPOT_MONITOR_NOTIFYALL_ENABLED() 0
+#define HOTSPOT_MONITOR_WAIT(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_MONITOR_WAIT_ENABLED() 0
+#define HOTSPOT_MONITOR_WAIT_PROBE(arg0, arg1, arg2, arg3)
+#define HOTSPOT_MONITOR_WAIT_PROBE_ENABLED() 0
+#define HOTSPOT_MONITOR_WAITED(arg0, arg1, arg2, arg3)
+#define HOTSPOT_MONITOR_WAITED_ENABLED() 0
+#define HOTSPOT_OBJECT_ALLOC(arg0, arg1, arg2, arg3)
+#define HOTSPOT_OBJECT_ALLOC_ENABLED() 0
+#define HOTSPOT_THREAD_START(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_THREAD_START_ENABLED() 0
+#define HOTSPOT_THREAD_STOP(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_THREAD_STOP_ENABLED() 0
+#define HOTSPOT_THREAD_SLEEP_BEGIN(arg0)
+#define HOTSPOT_THREAD_SLEEP_BEGIN_ENABLED() 0
+#define HOTSPOT_THREAD_SLEEP_END(arg0)
+#define HOTSPOT_THREAD_SLEEP_END_ENABLED() 0
+#define HOTSPOT_THREAD_YIELD()
+#define HOTSPOT_THREAD_YIELD_ENABLED() 0
+#define HOTSPOT_THREAD_PARK_BEGIN(arg0, arg1, arg2)
+#define HOTSPOT_THREAD_PARK_BEGIN_ENABLED() 0
+#define HOTSPOT_THREAD_PARK_END(arg0)
+#define HOTSPOT_THREAD_PARK_END_ENABLED() 0
+#define HOTSPOT_THREAD_UNPARK()
+#define HOTSPOT_THREAD_UNPARK_ENABLED() 0
+#define HOTSPOT_VM_INIT_BEGIN()
+#define HOTSPOT_VM_INIT_BEGIN_ENABLED() 0
+#define HOTSPOT_VM_INIT_END()
+#define HOTSPOT_VM_INIT_END_ENABLED() 0
+#define HOTSPOT_VM_SHUTDOWN()
+#define HOTSPOT_VM_SHUTDOWN_ENABLED() 0
+#define HOTSPOT_VMOPS_REQUEST(arg0, arg1, arg2)
+#define HOTSPOT_VMOPS_REQUEST_ENABLED() 0
+#define HOTSPOT_VMOPS_BEGIN(arg0, arg1, arg2)
+#define HOTSPOT_VMOPS_BEGIN_ENABLED() 0
+#define HOTSPOT_VMOPS_END(arg0, arg1, arg2)
+#define HOTSPOT_VMOPS_END_ENABLED() 0
+
+/* hs_private provider probes */
+#define HS_PRIVATE_CMS_INITMARK_BEGIN()
+#define HS_PRIVATE_CMS_INITMARK_BEGIN_ENABLED() 0
+#define HS_PRIVATE_CMS_INITMARK_END()
+#define HS_PRIVATE_CMS_INITMARK_END_ENABLED() 0
+#define HS_PRIVATE_CMS_REMARK_BEGIN()
+#define HS_PRIVATE_CMS_REMARK_BEGIN_ENABLED() 0
+#define HS_PRIVATE_CMS_REMARK_END()
+#define HS_PRIVATE_CMS_REMARK_END_ENABLED() 0
+#define HS_PRIVATE_HASHTABLE_NEW_ENTRY(arg0, arg1, arg2, arg3)
+#define HS_PRIVATE_HASHTABLE_NEW_ENTRY_ENABLED() 0
+#define HS_PRIVATE_SAFEPOINT_BEGIN()
+#define HS_PRIVATE_SAFEPOINT_BEGIN_ENABLED() 0
+#define HS_PRIVATE_SAFEPOINT_END()
+#define HS_PRIVATE_SAFEPOINT_END_ENABLED() 0
+
+/* hotspot_jni provider probes */
+#define HOTSPOT_JNI_ALLOCOBJECT_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_ALLOCOBJECT_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_ALLOCOBJECT_RETURN(arg0)
+#define HOTSPOT_JNI_ALLOCOBJECT_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(arg0)
+#define HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(arg0)
+#define HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLBOOLEANMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLBOOLEANMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLBOOLEANMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLBOOLEANMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLBOOLEANMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLBOOLEANMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLBOOLEANMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLBOOLEANMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLBYTEMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLBYTEMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLBYTEMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLBYTEMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLBYTEMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLBYTEMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLBYTEMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLBYTEMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLBYTEMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLCHARMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLCHARMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLCHARMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLCHARMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLCHARMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLCHARMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLCHARMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLCHARMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLCHARMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLCHARMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLCHARMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLDOUBLEMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLDOUBLEMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLDOUBLEMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLDOUBLEMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLDOUBLEMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLDOUBLEMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLDOUBLEMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLDOUBLEMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLFLOATMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLFLOATMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLFLOATMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLFLOATMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLFLOATMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLFLOATMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLFLOATMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLFLOATMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLFLOATMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLINTMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLINTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLINTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLINTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLINTMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLINTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLINTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLINTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLINTMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLINTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLINTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLINTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLLONGMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLLONGMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLLONGMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLLONGMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLLONGMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLLONGMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLLONGMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLLONGMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLLONGMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLLONGMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLLONGMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLOBJECTMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLOBJECTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLOBJECTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLOBJECTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLOBJECTMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLOBJECTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLOBJECTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLOBJECTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSHORTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSHORTMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSHORTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSHORTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSHORTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSHORTMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSHORTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSHORTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSHORTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(arg0)
+#define HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLVOIDMETHOD_RETURN()
+#define HOTSPOT_JNI_CALLVOIDMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLVOIDMETHODA_RETURN()
+#define HOTSPOT_JNI_CALLVOIDMETHODA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CALLVOIDMETHODV_RETURN()
+#define HOTSPOT_JNI_CALLVOIDMETHODV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_CREATEJAVAVM_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_CREATEJAVAVM_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_CREATEJAVAVM_RETURN(arg0)
+#define HOTSPOT_JNI_CREATEJAVAVM_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_DEFINECLASS_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_DEFINECLASS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_DEFINECLASS_RETURN(arg0)
+#define HOTSPOT_JNI_DEFINECLASS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_DELETEGLOBALREF_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_DELETEGLOBALREF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_DELETEGLOBALREF_RETURN()
+#define HOTSPOT_JNI_DELETEGLOBALREF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_DELETELOCALREF_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_DELETELOCALREF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_DELETELOCALREF_RETURN()
+#define HOTSPOT_JNI_DELETELOCALREF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN()
+#define HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_DESTROYJAVAVM_ENTRY(arg0)
+#define HOTSPOT_JNI_DESTROYJAVAVM_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_DESTROYJAVAVM_RETURN(arg0)
+#define HOTSPOT_JNI_DESTROYJAVAVM_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY(arg0)
+#define HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(arg0)
+#define HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN(arg0)
+#define HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY(arg0)
+#define HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONCHECK_RETURN(arg0)
+#define HOTSPOT_JNI_EXCEPTIONCHECK_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY(arg0)
+#define HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN()
+#define HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY(arg0)
+#define HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN()
+#define HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY(arg0)
+#define HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN(arg0)
+#define HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_FATALERROR_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_FATALERROR_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_FINDCLASS_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_FINDCLASS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_FINDCLASS_RETURN(arg0)
+#define HOTSPOT_JNI_FINDCLASS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETARRAYLENGTH_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETARRAYLENGTH_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETARRAYLENGTH_RETURN(arg0)
+#define HOTSPOT_JNI_GETARRAYLENGTH_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETBOOLEANFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETBYTEFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETBYTEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETBYTEFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETBYTEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETCHARARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETCHARARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETCHARFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETCHARFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETCHARFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETCHARFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN(arg0)
+#define HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY(arg0)
+#define HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(arg0)
+#define HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN(arg0)
+#define HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(arg0)
+#define HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETDOUBLEFIELD_RETURN()
+#define HOTSPOT_JNI_GETDOUBLEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETENV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETENV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETENV_RETURN(arg0)
+#define HOTSPOT_JNI_GETENV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETFIELDID_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_GETFIELDID_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETFIELDID_RETURN(arg0)
+#define HOTSPOT_JNI_GETFIELDID_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETFLOATFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETFLOATFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETFLOATFIELD_RETURN()
+#define HOTSPOT_JNI_GETFLOATFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETINTARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETINTARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETINTARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETINTFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETINTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETINTFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETINTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETJAVAVM_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETJAVAVM_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETJAVAVM_RETURN(arg0)
+#define HOTSPOT_JNI_GETJAVAVM_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETLONGARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETLONGARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETLONGFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETLONGFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETLONGFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETLONGFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETMETHODID_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_GETMETHODID_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETMETHODID_RETURN(arg0)
+#define HOTSPOT_JNI_GETMETHODID_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(arg0)
+#define HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETOBJECTCLASS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTCLASS_RETURN(arg0)
+#define HOTSPOT_JNI_GETOBJECTCLASS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETOBJECTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETOBJECTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN(arg0)
+#define HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN(arg0)
+#define HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN(arg0)
+#define HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN()
+#define HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSHORTFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSHORTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSHORTFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSHORTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN()
+#define HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICFIELDID_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_GETSTATICFIELDID_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICFIELDID_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICFIELDID_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN()
+#define HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICINTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICMETHODID_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_GETSTATICMETHODID_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICMETHODID_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICMETHODID_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGCHARS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTRINGCHARS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGCHARS_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTRINGCHARS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGLENGTH_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTRINGLENGTH_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETSTRINGREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGREGION_RETURN()
+#define HOTSPOT_JNI_GETSTRINGREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN(arg0)
+#define HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN()
+#define HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETSUPERCLASS_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETSUPERCLASS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETSUPERCLASS_RETURN(arg0)
+#define HOTSPOT_JNI_GETSUPERCLASS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_GETVERSION_ENTRY(arg0)
+#define HOTSPOT_JNI_GETVERSION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETVERSION_RETURN(arg0)
+#define HOTSPOT_JNI_GETVERSION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(arg0)
+#define HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_ISINSTANCEOF_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_ISINSTANCEOF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_ISINSTANCEOF_RETURN(arg0)
+#define HOTSPOT_JNI_ISINSTANCEOF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_ISSAMEOBJECT_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_ISSAMEOBJECT_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_ISSAMEOBJECT_RETURN(arg0)
+#define HOTSPOT_JNI_ISSAMEOBJECT_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_MONITORENTER_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_MONITORENTER_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_MONITORENTER_RETURN(arg0)
+#define HOTSPOT_JNI_MONITORENTER_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_MONITOREXIT_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_MONITOREXIT_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_MONITOREXIT_RETURN(arg0)
+#define HOTSPOT_JNI_MONITOREXIT_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWBYTEARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWBYTEARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWBYTEARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWCHARARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWCHARARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWCHARARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWCHARARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(arg0)
+#define HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWFLOATARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWFLOATARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWFLOATARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWGLOBALREF_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWGLOBALREF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWGLOBALREF_RETURN(arg0)
+#define HOTSPOT_JNI_NEWGLOBALREF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWINTARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWINTARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWINTARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWINTARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWLOCALREF_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWLOCALREF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWLOCALREF_RETURN(arg0)
+#define HOTSPOT_JNI_NEWLOCALREF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWLONGARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWLONGARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWLONGARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWLONGARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECT_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_NEWOBJECT_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECT_RETURN(arg0)
+#define HOTSPOT_JNI_NEWOBJECT_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECTA_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_NEWOBJECTA_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECTA_RETURN(arg0)
+#define HOTSPOT_JNI_NEWOBJECTA_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWOBJECTARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECTV_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_NEWOBJECTV_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWOBJECTV_RETURN(arg0)
+#define HOTSPOT_JNI_NEWOBJECTV_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWSHORTARRAY_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWSHORTARRAY_RETURN(arg0)
+#define HOTSPOT_JNI_NEWSHORTARRAY_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWSTRING_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_NEWSTRING_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWSTRING_RETURN(arg0)
+#define HOTSPOT_JNI_NEWSTRING_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWSTRINGUTF_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWSTRINGUTF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWSTRINGUTF_RETURN(arg0)
+#define HOTSPOT_JNI_NEWSTRINGUTF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(arg0)
+#define HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_POPLOCALFRAME_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_POPLOCALFRAME_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_POPLOCALFRAME_RETURN(arg0)
+#define HOTSPOT_JNI_POPLOCALFRAME_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(arg0)
+#define HOTSPOT_JNI_PUSHLOCALFRAME_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_REGISTERNATIVES_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_REGISTERNATIVES_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_REGISTERNATIVES_RETURN(arg0)
+#define HOTSPOT_JNI_REGISTERNATIVES_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN()
+#define HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN()
+#define HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN()
+#define HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN()
+#define HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN()
+#define HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETBOOLEANFIELD_RETURN()
+#define HOTSPOT_JNI_SETBOOLEANFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETBYTEFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETBYTEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETBYTEFIELD_RETURN()
+#define HOTSPOT_JNI_SETBYTEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETCHARARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETCHARARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETCHARFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETCHARFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETCHARFIELD_RETURN()
+#define HOTSPOT_JNI_SETCHARFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETDOUBLEFIELD_RETURN()
+#define HOTSPOT_JNI_SETDOUBLEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETFLOATFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_SETFLOATFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETFLOATFIELD_RETURN()
+#define HOTSPOT_JNI_SETFLOATFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETINTARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETINTARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETINTARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETINTFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETINTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETINTFIELD_RETURN()
+#define HOTSPOT_JNI_SETINTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETLONGARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETLONGARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETLONGFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETLONGFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETLONGFIELD_RETURN()
+#define HOTSPOT_JNI_SETLONGFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN()
+#define HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETOBJECTFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETOBJECTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETOBJECTFIELD_RETURN()
+#define HOTSPOT_JNI_SETOBJECTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(arg0, arg1, arg2, arg3, arg4)
+#define HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN()
+#define HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSHORTFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSHORTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSHORTFIELD_RETURN()
+#define HOTSPOT_JNI_SETSHORTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICBOOLEANFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSTATICBOOLEANFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICBOOLEANFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICBOOLEANFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICINTFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICINTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN()
+#define HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_THROW_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_THROW_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_THROW_RETURN(arg0)
+#define HOTSPOT_JNI_THROW_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_THROWNEW_ENTRY(arg0, arg1, arg2)
+#define HOTSPOT_JNI_THROWNEW_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_THROWNEW_RETURN(arg0)
+#define HOTSPOT_JNI_THROWNEW_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(arg0)
+#define HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(arg0, arg1, arg2, arg3)
+#define HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(arg0)
+#define HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN_ENABLED()  0
+#define HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_UNREGISTERNATIVES_RETURN(arg0)
+#define HOTSPOT_JNI_UNREGISTERNATIVES_RETURN_ENABLED()  0
+
+#else /* USDT2 */
+#error This file should only be included for USDT2
+#endif /* USDT2 */
+
+#else /* !defined(DTRACE_ENABLED) */
+#error This file should only be included when dtrace is not enabled
+#end /* !defined(DTRACE_ENABLED) */
+
+#endif // SHARE_VM_UTILITIES_DTRACE_USDT2_DISABLED_HPP
diff --git a/hotspot/src/share/vm/utilities/elfFile.cpp b/hotspot/src/share/vm/utilities/elfFile.cpp
index 4614b94..2db1f71 100644
--- a/hotspot/src/share/vm/utilities/elfFile.cpp
+++ b/hotspot/src/share/vm/utilities/elfFile.cpp
@@ -24,7 +24,7 @@
 
 #include "precompiled.hpp"
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
 
 #include <string.h>
 #include <stdio.h>
diff --git a/hotspot/src/share/vm/utilities/elfFile.hpp b/hotspot/src/share/vm/utilities/elfFile.hpp
index 0a1f965..b40b90a 100644
--- a/hotspot/src/share/vm/utilities/elfFile.hpp
+++ b/hotspot/src/share/vm/utilities/elfFile.hpp
@@ -25,9 +25,13 @@
 #ifndef __ELF_FILE_HPP
 #define __ELF_FILE_HPP
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
 
+#if defined(__OpenBSD__)
+#include <sys/exec_elf.h>
+#else
 #include <elf.h>
+#endif
 #include <stdio.h>
 
 #ifdef _LP64
@@ -41,7 +45,9 @@
 typedef Elf64_Shdr      Elf_Shdr;
 typedef Elf64_Sym       Elf_Sym;
 
+#if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
 #define ELF_ST_TYPE ELF64_ST_TYPE
+#endif
 
 #else
 
@@ -55,8 +61,10 @@
 typedef Elf32_Shdr      Elf_Shdr;
 typedef Elf32_Sym       Elf_Sym;
 
+#if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
 #define ELF_ST_TYPE ELF32_ST_TYPE
 #endif
+#endif
 
 #include "globalDefinitions.hpp"
 #include "memory/allocation.hpp"
@@ -137,4 +145,3 @@
 #endif // _WINDOWS
 
 #endif // __ELF_FILE_HPP
-
diff --git a/hotspot/src/share/vm/utilities/elfStringTable.cpp b/hotspot/src/share/vm/utilities/elfStringTable.cpp
index 994b80a..905f82b 100644
--- a/hotspot/src/share/vm/utilities/elfStringTable.cpp
+++ b/hotspot/src/share/vm/utilities/elfStringTable.cpp
@@ -24,7 +24,7 @@
 
 #include "precompiled.hpp"
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
 
 #include "memory/allocation.inline.hpp"
 #include "runtime/os.hpp"
@@ -87,4 +87,3 @@
 }
 
 #endif // _WINDOWS
-
diff --git a/hotspot/src/share/vm/utilities/elfStringTable.hpp b/hotspot/src/share/vm/utilities/elfStringTable.hpp
index bfafa1a..a984e3a 100644
--- a/hotspot/src/share/vm/utilities/elfStringTable.hpp
+++ b/hotspot/src/share/vm/utilities/elfStringTable.hpp
@@ -25,7 +25,7 @@
 #ifndef __ELF_STRING_TABLE_HPP
 #define __ELF_STRING_TABLE_HPP
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
 
 #include "memory/allocation.hpp"
 #include "utilities/decoder.hpp"
@@ -79,4 +79,3 @@
 #endif // _WINDOWS
 
 #endif // __ELF_STRING_TABLE_HPP
-
diff --git a/hotspot/src/share/vm/utilities/elfSymbolTable.cpp b/hotspot/src/share/vm/utilities/elfSymbolTable.cpp
index 0fa039c..d160601 100644
--- a/hotspot/src/share/vm/utilities/elfSymbolTable.cpp
+++ b/hotspot/src/share/vm/utilities/elfSymbolTable.cpp
@@ -24,7 +24,7 @@
 
 #include "precompiled.hpp"
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
 
 #include "memory/allocation.inline.hpp"
 #include "utilities/elfSymbolTable.hpp"
diff --git a/hotspot/src/share/vm/utilities/elfSymbolTable.hpp b/hotspot/src/share/vm/utilities/elfSymbolTable.hpp
index 5ac1c4a..c8a11fc 100644
--- a/hotspot/src/share/vm/utilities/elfSymbolTable.hpp
+++ b/hotspot/src/share/vm/utilities/elfSymbolTable.hpp
@@ -25,7 +25,7 @@
 #ifndef __ELF_SYMBOL_TABLE_HPP
 #define __ELF_SYMBOL_TABLE_HPP
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__APPLE__)
 
 
 #include "memory/allocation.hpp"
@@ -68,6 +68,3 @@
 #endif // _WINDOWS
 
 #endif // __ELF_SYMBOL_TABLE_HPP
-
-
-
diff --git a/hotspot/src/share/vm/utilities/events.cpp b/hotspot/src/share/vm/utilities/events.cpp
index 24e4eb4..6234119 100644
--- a/hotspot/src/share/vm/utilities/events.cpp
+++ b/hotspot/src/share/vm/utilities/events.cpp
@@ -38,6 +38,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 #ifndef PRODUCT
diff --git a/hotspot/src/share/vm/utilities/exceptions.cpp b/hotspot/src/share/vm/utilities/exceptions.cpp
index 3d2f3cf..9196027 100644
--- a/hotspot/src/share/vm/utilities/exceptions.cpp
+++ b/hotspot/src/share/vm/utilities/exceptions.cpp
@@ -42,6 +42,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 
 // Implementation of ThreadShadow
diff --git a/hotspot/src/share/vm/utilities/globalDefinitions.hpp b/hotspot/src/share/vm/utilities/globalDefinitions.hpp
index 8607a3e..dc7532b 100644
--- a/hotspot/src/share/vm/utilities/globalDefinitions.hpp
+++ b/hotspot/src/share/vm/utilities/globalDefinitions.hpp
@@ -25,6 +25,10 @@
 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #ifdef TARGET_COMPILER_gcc
 # include "utilities/globalDefinitions_gcc.hpp"
 #endif
@@ -1178,67 +1182,47 @@
 }
 
 // Printf-style formatters for fixed- and variable-width types as pointers and
-// integers.
-//
-// Each compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
-// must define the macro FORMAT64_MODIFIER, which is the modifier for '%x' or
-// '%d' formats to indicate a 64-bit quantity; commonly "l" (in LP64) or "ll"
-// (in ILP32).
+// integers.  These are derived from the definitions in inttypes.h.  If the platform
+// doesn't provide appropriate definitions, they should be provided in
+// the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
 
 #define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")
 
 // Format 32-bit quantities.
-#define INT32_FORMAT  "%d"
-#define UINT32_FORMAT "%u"
-#define INT32_FORMAT_W(width)   "%" #width "d"
-#define UINT32_FORMAT_W(width)  "%" #width "u"
+#define INT32_FORMAT           "%" PRId32
+#define UINT32_FORMAT          "%" PRIu32
+#define INT32_FORMAT_W(width)  "%" #width PRId32
+#define UINT32_FORMAT_W(width) "%" #width PRIu32
 
-#define PTR32_FORMAT  "0x%08x"
+#define PTR32_FORMAT           "0x%08" PRIx32
 
 // Format 64-bit quantities.
-#define INT64_FORMAT  "%" FORMAT64_MODIFIER "d"
-#define UINT64_FORMAT "%" FORMAT64_MODIFIER "u"
-#define PTR64_FORMAT  "0x%016" FORMAT64_MODIFIER "x"
+#define INT64_FORMAT           "%" PRId64
+#define UINT64_FORMAT          "%" PRIu64
+#define INT64_FORMAT_W(width)  "%" #width PRId64
+#define UINT64_FORMAT_W(width) "%" #width PRIu64
 
-#define INT64_FORMAT_W(width)  "%" #width FORMAT64_MODIFIER "d"
-#define UINT64_FORMAT_W(width) "%" #width FORMAT64_MODIFIER "u"
+#define PTR64_FORMAT           "0x%016" PRIx64
 
-// Format macros that allow the field width to be specified.  The width must be
-// a string literal (e.g., "8") or a macro that evaluates to one.
-#ifdef _LP64
-#define UINTX_FORMAT_W(width)   UINT64_FORMAT_W(width)
-#define SSIZE_FORMAT_W(width)   INT64_FORMAT_W(width)
-#define SIZE_FORMAT_W(width)    UINT64_FORMAT_W(width)
-#else
-#define UINTX_FORMAT_W(width)   UINT32_FORMAT_W(width)
-#define SSIZE_FORMAT_W(width)   INT32_FORMAT_W(width)
-#define SIZE_FORMAT_W(width)    UINT32_FORMAT_W(width)
-#endif // _LP64
-
-// Format pointers and size_t (or size_t-like integer types) which change size
-// between 32- and 64-bit. The pointer format theoretically should be "%p",
-// however, it has different output on different platforms. On Windows, the data
-// will be padded with zeros automatically. On Solaris, we can use "%016p" &
-// "%08p" on 64 bit & 32 bit platforms to make the data padded with extra zeros.
-// On Linux, "%016p" or "%08p" is not be allowed, at least on the latest GCC
-// 4.3.2. So we have to use "%016x" or "%08x" to simulate the printing format.
-// GCC 4.3.2, however requires the data to be converted to "intptr_t" when
-// using "%x".
+// Format pointers which change size between 32- and 64-bit.
 #ifdef  _LP64
-#define PTR_FORMAT    PTR64_FORMAT
-#define UINTX_FORMAT  UINT64_FORMAT
-#define INTX_FORMAT   INT64_FORMAT
-#define SIZE_FORMAT   UINT64_FORMAT
-#define SSIZE_FORMAT  INT64_FORMAT
+#define INTPTR_FORMAT "0x%016" PRIxPTR
+#define PTR_FORMAT    "0x%016" PRIxPTR
 #else   // !_LP64
-#define PTR_FORMAT    PTR32_FORMAT
-#define UINTX_FORMAT  UINT32_FORMAT
-#define INTX_FORMAT   INT32_FORMAT
-#define SIZE_FORMAT   UINT32_FORMAT
-#define SSIZE_FORMAT  INT32_FORMAT
+#define INTPTR_FORMAT "0x%08"  PRIxPTR
+#define PTR_FORMAT    "0x%08"  PRIxPTR
 #endif  // _LP64
 
-#define INTPTR_FORMAT PTR_FORMAT
+#define SSIZE_FORMAT          "%" PRIdPTR
+#define SIZE_FORMAT           "%" PRIuPTR
+#define SSIZE_FORMAT_W(width) "%" #width PRIdPTR
+#define SIZE_FORMAT_W(width)  "%" #width PRIuPTR
+
+#define INTX_FORMAT           "%" PRIdPTR
+#define UINTX_FORMAT          "%" PRIuPTR
+#define INTX_FORMAT_W(width)  "%" #width PRIdPTR
+#define UINTX_FORMAT_W(width) "%" #width PRIuPTR
+
 
 // Enable zap-a-lot if in debug version.
 
diff --git a/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp b/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
index ac7fdf8..45b5e8f 100644
--- a/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
+++ b/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
@@ -76,15 +76,28 @@
 # include <sys/procfs.h>
 # endif
 
-#ifdef LINUX
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
 #ifndef __STDC_LIMIT_MACROS
 #define __STDC_LIMIT_MACROS
 #endif // __STDC_LIMIT_MACROS
 #include <inttypes.h>
 #include <signal.h>
+#ifndef __OpenBSD__
 #include <ucontext.h>
+#endif
+#ifdef __APPLE__
+  #include <AvailabilityMacros.h>
+  #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4)
+    // Mac OS X 10.4 defines EFL_AC and EFL_ID,
+    // which conflict with hotspot variable names.
+    //
+    // This has been fixed in Mac OS X 10.5.
+    #undef EFL_AC
+    #undef EFL_ID
+  #endif
+#endif
 #include <sys/time.h>
-#endif // LINUX
+#endif // LINUX || _ALLBSD_SOURCE
 
 // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures
 // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in
@@ -120,7 +133,7 @@
 // pointer is stored as integer value.  On some platforms, sizeof(intptr_t) >
 // sizeof(void*), so here we want something which is integer type, but has the
 // same size as a pointer.
-#ifdef LINUX
+#ifdef __GNUC__
   #ifdef _LP64
     #define NULL_WORD  0L
   #else
@@ -132,7 +145,7 @@
   #define NULL_WORD  NULL
 #endif
 
-#ifndef LINUX
+#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
 // Compiler-specific primitive types
 typedef unsigned short     uint16_t;
 #ifndef _UINT32_T
@@ -152,7 +165,7 @@
 // prior definition of intptr_t, and add "&& !defined(XXX)" above.
 #endif // _SYS_INT_TYPES_H
 
-#endif // !LINUX
+#endif // !LINUX && !_ALLBSD_SOURCE
 
 // Additional Java basic types
 
@@ -244,7 +257,9 @@
 inline int g_isnan(float  f) { return isnand(f); }
 #endif
 inline int g_isnan(double f) { return isnand(f); }
-#elif LINUX
+#elif defined(__APPLE__)
+inline int g_isnan(double f) { return isnan(f); }
+#elif defined(LINUX) || defined(_ALLBSD_SOURCE)
 inline int g_isnan(float  f) { return isnanf(f); }
 inline int g_isnan(double f) { return isnan(f); }
 #else
diff --git a/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp b/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp
index fca43e0..e91e607 100644
--- a/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp
+++ b/hotspot/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp
@@ -74,8 +74,25 @@
 # ifdef SOLARIS_MUTATOR_LIBTHREAD
 # include <sys/procfs.h>
 # endif
+
+#include <inttypes.h>
+
+// Solaris 8 doesn't provide definitions of these
+#ifdef SOLARIS
+#ifndef PRIdPTR
+#if defined(_LP64)
+#define PRIdPTR                 "ld"
+#define PRIuPTR                 "lu"
+#define PRIxPTR                 "lx"
+#else
+#define PRIdPTR                 "d"
+#define PRIuPTR                 "u"
+#define PRIxPTR                 "x"
+#endif
+#endif
+#endif
+
 #ifdef LINUX
-# include <inttypes.h>
 # include <signal.h>
 # include <ucontext.h>
 # include <sys/time.h>
diff --git a/hotspot/src/share/vm/utilities/globalDefinitions_visCPP.hpp b/hotspot/src/share/vm/utilities/globalDefinitions_visCPP.hpp
index 3654999..ba54d22 100644
--- a/hotspot/src/share/vm/utilities/globalDefinitions_visCPP.hpp
+++ b/hotspot/src/share/vm/utilities/globalDefinitions_visCPP.hpp
@@ -207,6 +207,20 @@
 // Formatting.
 #define FORMAT64_MODIFIER "I64"
 
+// Visual Studio doesn't provide inttypes.h so provide appropriate definitions here.
+// The 32 bits ones might need I32 but seem to work ok without it.
+#define PRId32       "d"
+#define PRIu32       "u"
+#define PRIx32       "x"
+
+#define PRId64       "I64d"
+#define PRIu64       "I64u"
+#define PRIx64       "I64x"
+
+#define PRIdPTR       "d"
+#define PRIuPTR       "u"
+#define PRIxPTR       "x"
+
 #define offset_of(klass,field) offsetof(klass,field)
 
 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP
diff --git a/hotspot/src/share/vm/utilities/growableArray.cpp b/hotspot/src/share/vm/utilities/growableArray.cpp
index 00378af..a6ad8f3 100644
--- a/hotspot/src/share/vm/utilities/growableArray.cpp
+++ b/hotspot/src/share/vm/utilities/growableArray.cpp
@@ -34,6 +34,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 #ifdef ASSERT
 void GenericGrowableArray::set_nesting() {
   if (on_stack()) {
diff --git a/hotspot/src/share/vm/utilities/hashtable.cpp b/hotspot/src/share/vm/utilities/hashtable.cpp
index 7e93796..698e137 100644
--- a/hotspot/src/share/vm/utilities/hashtable.cpp
+++ b/hotspot/src/share/vm/utilities/hashtable.cpp
@@ -32,8 +32,10 @@
 #include "utilities/hashtable.inline.hpp"
 
 
+#ifndef USDT2
 HS_DTRACE_PROBE_DECL4(hs_private, hashtable__new_entry,
   void*, unsigned int, void*, void*);
+#endif /* !USDT2 */
 
 // This is a generic hashtable, designed to be used for the symbol
 // and string tables.
@@ -73,8 +75,13 @@
 
   entry = (HashtableEntry<T>*)BasicHashtable::new_entry(hashValue);
   entry->set_literal(obj);
+#ifndef USDT2
   HS_DTRACE_PROBE4(hs_private, hashtable__new_entry,
     this, hashValue, obj, entry);
+#else /* USDT2 */
+  HS_PRIVATE_HASHTABLE_NEW_ENTRY(
+    this, hashValue, (uintptr_t) obj, entry);
+#endif /* USDT2 */
   return entry;
 }
 
diff --git a/hotspot/src/share/vm/utilities/histogram.hpp b/hotspot/src/share/vm/utilities/histogram.hpp
index 9627a07..4eaa3d4 100644
--- a/hotspot/src/share/vm/utilities/histogram.hpp
+++ b/hotspot/src/share/vm/utilities/histogram.hpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 // This class provides a framework for collecting various statistics.
 // The current implementation is oriented towards counting invocations
diff --git a/hotspot/src/share/vm/utilities/macros.hpp b/hotspot/src/share/vm/utilities/macros.hpp
index 8c8b0f3..27e2a70 100644
--- a/hotspot/src/share/vm/utilities/macros.hpp
+++ b/hotspot/src/share/vm/utilities/macros.hpp
@@ -161,6 +161,14 @@
 #define NOT_WINDOWS(code) code
 #endif
 
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+#define BSD_ONLY(code) code
+#define NOT_BSD(code)
+#else
+#define BSD_ONLY(code)
+#define NOT_BSD(code) code
+#endif
+
 #ifdef _WIN64
 #define WIN64_ONLY(code) code
 #define NOT_WIN64(code)
diff --git a/hotspot/src/share/vm/utilities/ostream.cpp b/hotspot/src/share/vm/utilities/ostream.cpp
index 1e54ba2..6066000 100644
--- a/hotspot/src/share/vm/utilities/ostream.cpp
+++ b/hotspot/src/share/vm/utilities/ostream.cpp
@@ -39,6 +39,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "os_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 extern "C" void jio_print(const char* s); // Declarationtion of jvm method
 
@@ -992,7 +995,7 @@
 
 #ifndef PRODUCT
 
-#if defined(SOLARIS) || defined(LINUX)
+#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
diff --git a/hotspot/src/share/vm/utilities/preserveException.hpp b/hotspot/src/share/vm/utilities/preserveException.hpp
index d0e25ae..7737a37 100644
--- a/hotspot/src/share/vm/utilities/preserveException.hpp
+++ b/hotspot/src/share/vm/utilities/preserveException.hpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // This file provides more support for exception handling; see also exceptions.hpp
 class PreserveExceptionMark {
diff --git a/hotspot/src/share/vm/utilities/quickSort.cpp b/hotspot/src/share/vm/utilities/quickSort.cpp
index b377d9a..bf68af1 100644
--- a/hotspot/src/share/vm/utilities/quickSort.cpp
+++ b/hotspot/src/share/vm/utilities/quickSort.cpp
@@ -23,13 +23,13 @@
  */
 
 #include "precompiled.hpp"
-#include "utilities/quickSort.hpp"
+
+/////////////// Unit tests ///////////////
 
 #ifndef PRODUCT
 
-// Unit tests
-
 #include "runtime/os.hpp"
+#include "utilities/quickSort.hpp"
 #include <stdlib.h>
 
 static int test_comparator(int a, int b) {
@@ -54,16 +54,18 @@
   return 1;
 }
 
-static int test_stdlib_comparator(const void* a, const void* b) {
-  int ai = *(int*)a;
-  int bi = *(int*)b;
-  if (ai == bi) {
-    return 0;
+extern "C" {
+  static int test_stdlib_comparator(const void* a, const void* b) {
+    int ai = *(int*)a;
+    int bi = *(int*)b;
+    if (ai == bi) {
+      return 0;
+    }
+    if (ai < bi) {
+      return -1;
+    }
+    return 1;
   }
-  if (ai < bi) {
-    return -1;
-  }
-  return 1;
 }
 
 void QuickSort::print_array(const char* prefix, int* array, int length) {
@@ -92,8 +94,7 @@
 }
 
 bool QuickSort::test_quick_sort() {
-#if 0
-  tty->print_cr("test_quick_sort\n");
+  tty->print_cr("test_quick_sort");
   {
     int* test_array = NULL;
     int* expected_array = NULL;
@@ -213,7 +214,6 @@
     delete[] test_array;
     delete[] expected_array;
   }
-#endif
   return true;
 }
 
diff --git a/hotspot/src/share/vm/utilities/taskqueue.cpp b/hotspot/src/share/vm/utilities/taskqueue.cpp
index 5f93dc0..df61a55 100644
--- a/hotspot/src/share/vm/utilities/taskqueue.cpp
+++ b/hotspot/src/share/vm/utilities/taskqueue.cpp
@@ -37,6 +37,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 #ifdef TRACESPINNING
 uint ParallelTaskTerminator::_total_yields = 0;
@@ -274,4 +277,3 @@
   reset_for_reuse();
   _n_threads = n_threads;
 }
-
diff --git a/hotspot/src/share/vm/utilities/taskqueue.hpp b/hotspot/src/share/vm/utilities/taskqueue.hpp
index 5527e2f..545c6db 100644
--- a/hotspot/src/share/vm/utilities/taskqueue.hpp
+++ b/hotspot/src/share/vm/utilities/taskqueue.hpp
@@ -53,6 +53,12 @@
 #ifdef TARGET_OS_ARCH_linux_ppc
 # include "orderAccess_linux_ppc.inline.hpp"
 #endif
+#ifdef TARGET_OS_ARCH_bsd_x86
+# include "orderAccess_bsd_x86.inline.hpp"
+#endif
+#ifdef TARGET_OS_ARCH_bsd_zero
+# include "orderAccess_bsd_zero.inline.hpp"
+#endif
 
 // Simple TaskQueue stats that are collected by default in debug builds.
 
diff --git a/hotspot/src/share/vm/utilities/vmError.cpp b/hotspot/src/share/vm/utilities/vmError.cpp
index fa8b820..94ed68e 100644
--- a/hotspot/src/share/vm/utilities/vmError.cpp
+++ b/hotspot/src/share/vm/utilities/vmError.cpp
@@ -45,13 +45,18 @@
   "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
   "JAVA_COMPILER", "PATH", "USERNAME",
 
-  // Env variables that are defined on Solaris/Linux
+  // Env variables that are defined on Solaris/Linux/BSD
   "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
   "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
 
   // defined on Linux
   "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM",
 
+  // defined on Darwin
+  "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
+  "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
+  "DYLD_INSERT_LIBRARIES",
+
   // defined on Windows
   "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
 
@@ -675,8 +680,10 @@
   STEP(190, "(printing heap information)" )
 
      if (_verbose && Universe::is_fully_initialized()) {
-       // print heap information before vm abort
-       Universe::print_on(st);
+       // Print heap information before vm abort. As we'd like as much
+       // information as possible in the report we ask for the
+       // extended (i.e., more detailed) version.
+       Universe::print_on(st, true /* extended */);
        st->cr();
      }
 
@@ -958,7 +965,7 @@
     const char* ptr = OnError;
     while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
       out.print_raw   ("#   Executing ");
-#if defined(LINUX)
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
       out.print_raw   ("/bin/sh -c ");
 #elif defined(SOLARIS)
       out.print_raw   ("/usr/bin/sh -c ");
diff --git a/hotspot/src/share/vm/utilities/workgroup.hpp b/hotspot/src/share/vm/utilities/workgroup.hpp
index 2bd6e9c..8e9effe 100644
--- a/hotspot/src/share/vm/utilities/workgroup.hpp
+++ b/hotspot/src/share/vm/utilities/workgroup.hpp
@@ -35,6 +35,9 @@
 #ifdef TARGET_OS_FAMILY_windows
 # include "thread_windows.inline.hpp"
 #endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "thread_bsd.inline.hpp"
+#endif
 
 // Task class hierarchy:
 //   AbstractGangTask
diff --git a/hotspot/test/Makefile b/hotspot/test/Makefile
index 9c66ade..f536592 100644
--- a/hotspot/test/Makefile
+++ b/hotspot/test/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,22 @@
     ARCH = i586
   endif
 endif
+ifeq ($(OSNAME), Darwin)
+  PLATFORM = bsd
+  SLASH_JAVA = /java
+  ARCH = $(shell uname -m)
+  ifeq ($(ARCH), i386)
+    ARCH = i586
+  endif
+endif
+ifeq ($(findstring BSD,$(OSNAME)), BSD)
+  PLATFORM = bsd
+  SLASH_JAVA = /java
+  ARCH = $(shell uname -m)
+  ifeq ($(ARCH), i386)
+    ARCH = i586
+  endif
+endif
 ifeq ($(OSNAME), Windows_NT)
   PLATFORM = windows
   SLASH_JAVA = J:
@@ -203,6 +219,15 @@
 
 ################################################################
 
+# internalvmtests (run internal unit tests inside the VM)
+
+internalvmtests: prep $(PRODUCT_HOME)
+	$(PRODUCT_HOME)/bin/java $(JAVA_OPTIONS) -XX:+ExecuteInternalVMTests -version
+
+PHONY_LIST += internalvmtests
+
+################################################################
+
 # packtest
 
 # Expect JPRT to set JPRT_PACKTEST_HOME.
diff --git a/hotspot/test/compiler/6865265/StackOverflowBug.java b/hotspot/test/compiler/6865265/StackOverflowBug.java
new file mode 100644
index 0000000..d474814
--- /dev/null
+++ b/hotspot/test/compiler/6865265/StackOverflowBug.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/**
+ * @test
+ * @bug 6865265
+ * @summary JVM crashes with "missing exception handler" error
+ * @author volker.simonis@sap.com
+ *
+ * @run main/othervm -XX:CompileThreshold=100 -Xbatch -Xss224k StackOverflowBug
+ */
+
+
+public class StackOverflowBug {
+
+  public static int run() {
+    try {
+      try {
+        return run();
+      } catch (Throwable e) {
+        // Notice that the class 'Throwable' is NOT resolved by the verifier,
+        // because the verifier only checks if 'Throwable' is assignable to
+        // 'java.lang.Throwable' and this check succeeds immediately if the two
+        // types have equal names (see 'VerificationType::is_assignable_from' which
+        // is called from 'ClassVerifier::verify_exception_handler_table').
+        // This is strange, because if the two classes have different names,
+        // 'is_assignable_from()' calls 'is_reference_assignable_from()' which resolves
+        // both classes by calling 'SystemDictionary::resolve_or_fail()'. This call
+        // also takes into account the current class loader (i.e. the one which was used
+        // to load this class) and would place a corresponding
+        // "java.lang.Throwable / current-Classloader" entry into the system dictionary.
+        // This would in turn allow C2 to see 'java.lang.Throwable' as "loaded"
+        // (see 'Parse::catch_inline_exceptions()') when this method is compiled.
+        return 42;
+      }
+    }
+    finally {
+    }
+  }
+
+  public static void main(String argv[]) {
+    run();
+  }
+}
+
+/*
+  public static int run();
+    Code:
+       0: invokestatic  #2                  // Method run:()I
+       3: istore_0
+       4: iload_0
+       5: ireturn
+       6: astore_0
+       7: bipush        42
+       9: istore_1
+      10: iload_1
+      11: ireturn
+      12: astore_2
+      13: aload_2
+      14: athrow
+    Exception table:
+       from    to  target type
+           0     4     6   Class java/lang/Throwable
+           0     4    12   any
+           6    10    12   any
+          12    13    12   any
+
+ */
diff --git a/hotspot/test/compiler/7103261/Test7103261.java b/hotspot/test/compiler/7103261/Test7103261.java
new file mode 100644
index 0000000..3abdb87
--- /dev/null
+++ b/hotspot/test/compiler/7103261/Test7103261.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/**
+ * @test
+ * @bug 7103261
+ * @summary crash with jittester on sparc
+ *
+ * @run main Test7103261
+ */
+
+// exercise implicit null checking in the compiler for various field types
+public class Test7103261 {
+    static Test7103261 null_value;
+    static Test7103261 nonnull_value = new Test7103261();
+    static Test7103261 nonnull_value2 = new Test7103261();
+
+    long l;
+    int i;
+    float f;
+    double d;
+    byte b;
+    char c;
+    short s;
+    boolean z;
+
+    public static void main(String[] args) {
+        constantStore();
+        valueTest(false);
+        valueTest(true);
+    }
+    static void constantStore() {
+        for (int field = 0; field < 8; field++) {
+            try {
+                Test7103261 o = nonnull_value;
+                for (int i = 0; i < 100000; i++) {
+                    switch (field) {
+                    case 0: o.l = 0; break;
+                    case 1: o.i = 0; break;
+                    case 2: o.f = 0; break;
+                    case 3: o.d = 0; break;
+                    case 4: o.b = 0; break;
+                    case 5: o.c = 0; break;
+                    case 6: o.s = 0; break;
+                    case 7: o.z = false; break;
+                    default: throw new InternalError();
+                    }
+                    if (i == 90000) {
+                        // hide nullness from optimizer
+                        o = null_value;
+                    }
+                }
+            } catch (NullPointerException npe) {
+            }
+        }
+    }
+    static void valueTest(boolean store) {
+        for (int field = 0; field < 8; field++) {
+            try {
+                Test7103261 o  = nonnull_value;
+                Test7103261 o2 = nonnull_value2;
+                for (int i = 0; i < 100000; i++) {
+                    switch (field) {
+                    case 0: o.l = o2.l; break;
+                    case 1: o.i = o2.i; break;
+                    case 2: o.f = o2.f; break;
+                    case 3: o.d = o2.d; break;
+                    case 4: o.b = o2.b; break;
+                    case 5: o.c = o2.c; break;
+                    case 6: o.s = o2.s; break;
+                    case 7: o.z = o2.z; break;
+                    default: throw new InternalError();
+                    }
+                    if (i == 90000) {
+                        // hide nullness from optimizer
+                        if (store)
+                            o = null_value;
+                        else
+                            o2 = null_value;
+                    }
+                }
+            } catch (NullPointerException npe) {
+            }
+        }
+    }
+}
diff --git a/hotspot/test/compiler/7110586/Test7110586.java b/hotspot/test/compiler/7110586/Test7110586.java
deleted file mode 100644
index e40c903..0000000
--- a/hotspot/test/compiler/7110586/Test7110586.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-/**
- * @test
- * @bug 7110586
- * @summary C2 generates icorrect results
- *
- * @run main/othervm -Xbatch Test7110586
- */
-
-public class Test7110586 {
-  static int test1() {
-    int i = 0;
-    for ( ; i < 11; i+=1) {}
-    return i;
-  }
-  static int test2() {
-    int i = 0;
-    for ( ; i < 11; i+=2) {}
-    return i;
-  }
-  static int test3() {
-    int i = 0;
-    for ( ; i < 11; i+=3) {}
-    return i;
-  }
-  static int test11() {
-    int i = 0;
-    for ( ; i < 11; i+=11) {}
-    return i;
-  }
-
-  static int testm1() {
-    int i = 0;
-    for ( ; i > -11; i-=1) {}
-    return i;
-  }
-  static int testm2() {
-    int i = 0;
-    for ( ; i > -11; i-=2) {}
-    return i;
-  }
-  static int testm3() {
-    int i = 0;
-    for ( ; i > -11; i-=3) {}
-    return i;
-  }
-  static int testm11() {
-    int i = 0;
-    for ( ; i > -11; i-=11) {}
-    return i;
-  }
-
-  public static void main(String args[]) {
-    int x1  = 0;
-    int x2  = 0;
-    int x3  = 0;
-    int x11 = 0;
-    int m1  = 0;
-    int m2  = 0;
-    int m3  = 0;
-    int m11 = 0;
-    for (int i=0; i<10000; i++) {
-      x1  = test1();
-      x2  = test2();
-      x3  = test3();
-      x11 = test11();
-      m1  = testm1();
-      m2  = testm2();
-      m3  = testm3();
-      m11 = testm11();
-    }
-    boolean failed = false;
-    if (x1 != 11) {
-      System.out.println("ERROR (incr = +1): " + x1 + " != 11");
-      failed = true;
-    }
-    if (x2 != 12) {
-      System.out.println("ERROR (incr = +2): " + x2 + " != 12");
-      failed = true;
-    }
-    if (x3 != 12) {
-      System.out.println("ERROR (incr = +3): " + x3 + " != 12");
-      failed = true;
-    }
-    if (x11 != 11) {
-      System.out.println("ERROR (incr = +11): " + x11 + " != 11");
-      failed = true;
-    }
-    if (m1 != -11) {
-      System.out.println("ERROR (incr = -1): " + m1 + " != -11");
-      failed = true;
-    }
-    if (m2 != -12) {
-      System.out.println("ERROR (incr = -2): " + m2 + " != -12");
-      failed = true;
-    }
-    if (m3 != -12) {
-      System.out.println("ERROR (incr = -3): " + m3 + " != -12");
-      failed = true;
-    }
-    if (m11 != -11) {
-      System.out.println("ERROR (incr = -11): " + m11 + " != -11");
-      failed = true;
-    }
-    if (failed) {
-      System.exit(97);
-    }
-  }
-}
diff --git a/hotspot/test/jprt.config b/hotspot/test/jprt.config
index 53c33fd..53ffdae 100644
--- a/hotspot/test/jprt.config
+++ b/hotspot/test/jprt.config
@@ -75,8 +75,8 @@
 
 # Uses 'uname -s', but only expect SunOS or Linux, assume Windows otherwise.
 osname=`uname -s`
-if [ "${osname}" = SunOS ] ; then
-   
+case "${osname}" in
+  SunOS )
     # SOLARIS: Sparc or X86
     osarch=`uname -p`
     if [ "${osarch}" = sparc ] ; then
@@ -100,9 +100,9 @@
 
     # File creation mask
     umask 002
+    ;;
 
-elif [ "${osname}" = Linux ] ; then
-   
+  Linux | Darwin )
     # Add basic paths
     path4sdk=/usr/bin:/bin:/usr/sbin:/sbin
 
@@ -111,9 +111,31 @@
     fileMustExist "${make}" make
 
     umask 002
+    ;;
 
-else
+  FreeBSD | OpenBSD )
+    # Add basic paths
+    path4sdk=/usr/bin:/bin:/usr/sbin:/sbin
 
+    # Find GNU make
+    make=/usr/local/bin/gmake
+    fileMustExist "${make}" make
+
+    umask 002
+    ;;
+
+  NetBSD )
+    # Add basic paths
+    path4sdk=/usr/bin:/bin:/usr/sbin:/sbin
+
+    # Find GNU make
+    make=/usr/pkg/bin/gmake
+    fileMustExist "${make}" make
+
+    umask 002
+    ;;
+
+  * )
     # Windows: Differs on CYGWIN vs. MKS.
    
     # We need to determine if we are running a CYGWIN shell or an MKS shell
@@ -154,8 +176,8 @@
     if [ "${unix_toolset}" = CYGWIN ] ; then
 	path4sdk="`/usr/bin/cygpath -p ${path4sdk}`"
     fi
-
-fi
+    ;;
+esac
 
 # Export PATH setting
 PATH="${path4sdk}"
diff --git a/hotspot/test/runtime/6929067/Test6929067.sh b/hotspot/test/runtime/6929067/Test6929067.sh
index 51af191..8f9e13a 100644
--- a/hotspot/test/runtime/6929067/Test6929067.sh
+++ b/hotspot/test/runtime/6929067/Test6929067.sh
@@ -29,7 +29,7 @@
     PS=":"
     FS="/"
     ;;
-  SunOS | Windows_* )
+  SunOS | Windows_* | *BSD)
     NULL=NUL
     PS=";"
     FS="\\"
diff --git a/hotspot/test/runtime/7051189/Xchecksig.sh b/hotspot/test/runtime/7051189/Xchecksig.sh
new file mode 100644
index 0000000..410cdb9
--- /dev/null
+++ b/hotspot/test/runtime/7051189/Xchecksig.sh
@@ -0,0 +1,151 @@
+# 
+#  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+# 
+#  This code is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU General Public License version 2 only, as
+#  published by the Free Software Foundation.
+# 
+#  This code is distributed in the hope that it will be useful, but WITHOUT
+#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+#  version 2 for more details (a copy is included in the LICENSE file that
+#  accompanied this code).
+# 
+#  You should have received a copy of the GNU General Public License version
+#  2 along with this work; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+# 
+#  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+#  or visit www.oracle.com if you need additional information or have any
+#  questions.
+# 
+
+ 
+# @test Xchecksig.sh
+# @bug 7051189
+# @summary Need to suppress info message if -xcheck:jni used with libjsig.so
+# @run shell Xchecksig.sh
+#
+
+if [ "${TESTSRC}" = "" ]
+  then TESTSRC=.
+fi
+
+if [ "${TESTJAVA}" = "" ]
+then
+  PARENT=`dirname \`which java\``
+  TESTJAVA=`dirname ${PARENT}`
+  printf "TESTJAVA not set, selecting " ${TESTJAVA}
+  printf "  If this is incorrect, try setting the variable manually.\n"
+fi
+
+
+BIT_FLAG=""
+
+OS=`uname -s`
+case "$OS" in
+  SunOS | Linux )
+    FS="/"
+    ## for solaris, linux it's HOME
+    FILE_LOCATION=$HOME
+    if [ -f ${FILE_LOCATION}${FS}JDK64BIT -a ${OS} = "SunOS" ]
+    then
+        BIT_FLAG=`cat ${FILE_LOCATION}${FS}JDK64BIT`
+    fi
+    ;;
+  Windows_* )
+    printf "Not testing libjsig.so on Windows. PASSED.\n "
+    exit 0
+    ;;
+  * )
+    printf "Not testing libjsig.so on unrecognised system. PASSED.\n "
+    exit 0
+    ;;
+esac
+
+
+JAVA=${TESTJAVA}${FS}bin${FS}java
+
+# LD_PRELOAD arch needs to match the binary we run, so run the java
+# 64-bit binary directly if we are testing 64-bit (bin/ARCH/java).
+
+# However JPRT runs: .../solaris_x64_5.10-debug/bin/java
+# ..which is 32-bit, when it has built the 64-bit version to test.
+#
+# How does this script know we are meant to run the 64-bit version?
+# Can check for the path of the binary containing "x64" on Solaris.
+
+if [ ${OS} -eq "SunOS" ]
+then
+  printf  "SunOS test JAVA=${JAVA}"
+  printf ${JAVA} | grep x64 > /dev/null
+  if [ $? -eq 0 ]
+  then
+    printf "SunOS x64 test, forcing -d64\n"
+    BIT_FLAG=-d64
+  fi
+fi
+
+ARCH=`uname -p`
+case $ARCH in
+  i386)
+    if [ X${BIT_FLAG} != "X" ]
+    then
+      ARCH=amd64
+      JAVA=${TESTJAVA}${FS}bin${FS}${ARCH}${FS}java
+    fi
+    ;;
+  sparc)
+    if [ X${BIT_FLAG} != "X" ]
+    then
+      ARCH=sparcv9
+      JAVA=${TESTJAVA}${FS}bin${FS}${ARCH}${FS}java
+    fi
+    ;;
+  * )
+    printf "Not testing architecture $ARCH, skipping test.\n"
+    exit 0
+  ;; 
+esac
+
+LIBJSIG=${TESTJAVA}${FS}jre${FS}lib${FS}${ARCH}${FS}libjsig.so
+
+# If libjsig and binary do not match, skip test.
+
+A=`file ${LIBJSIG} | awk '{ print $3 }'`
+B=`file ${JAVA}    | awk '{ print $3 }'`
+
+if [ $A -ne $B ]
+then
+  printf "Mismatching binary and library to preload, skipping test.\n"
+  exit 0
+fi
+
+if [ ! -f ${LIBJSIG} ]
+then
+  printf "Skipping test: libjsig missing for given architecture: ${LIBJSIG}\n"
+  exit 0
+fi
+# Use java -version to test, java version info appeas on stderr,
+# the libjsig message we are removing appears on stdout.
+
+# grep returns zero meaning found, non-zero means not found:
+
+LD_PRELOAD=${LIBJSIG} ${JAVA} ${BIT_FLAG} -Xcheck:jni -version 2>&1  | grep "libjsig is activated"
+
+if [ $? -eq 0 ]; then
+  printf "Failed: -Xcheck:jni prints message when libjsig.so is loaded.\n"
+  exit 1
+fi
+
+
+LD_PRELOAD=${LIBJSIG} ${JAVA} ${BIT_FLAG} -Xcheck:jni -verbose:jni -version 2>&1 | grep "libjsig is activated"
+if [ $? != 0 ]; then
+  printf "Failed: -Xcheck:jni does not print message when libjsig.so is loaded and -verbose:jni is set.\n"
+  exit 1
+fi
+
+printf "PASSED\n"
+exit 0
+
diff --git a/hotspot/test/runtime/7100935/TestConjointAtomicArraycopy.java b/hotspot/test/runtime/7100935/TestConjointAtomicArraycopy.java
new file mode 100644
index 0000000..3e17118
--- /dev/null
+++ b/hotspot/test/runtime/7100935/TestConjointAtomicArraycopy.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2011 SAP AG.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test TestConjointAtomicArraycopy
+ * @bug 7100935
+ * @summary verify that oops are copied element-wise atomic
+ * @run main/othervm -Xint TestConjointAtomicArraycopy
+ * @run main/othervm -Xcomp -Xbatch TestConjointAtomicArraycopy
+ * @author axel.siebenborn@sap.com
+ */
+
+public class TestConjointAtomicArraycopy {
+
+  static volatile Object [] testArray = new Object [4];
+
+  static short[] a1 = new short[8];
+  static short[] a2 = new short[8];
+  static short[] a3 = new short[8];
+
+  static volatile boolean keepRunning = true;
+
+  static void testOopsCopy() throws InterruptedException{
+
+  }
+
+  public static void main(String[] args ) throws InterruptedException{
+    for (int i = 0; i < testArray.length; i++){
+      testArray[i] = new String("A");
+    }
+
+    Thread writer = new Thread (new Runnable(){
+      public void run(){
+        for (int i = 0 ; i < 1000000; i++) {
+          System.arraycopy(testArray, 1, testArray, 0, 3);
+          testArray[2] = new String("a");
+        }
+      }
+    });
+
+    Thread reader = new Thread( new Runnable(){
+      public void run(){
+        while (keepRunning){
+          String name = testArray[2].getClass().getName();
+          if(!(name.endsWith("String"))){
+            throw new RuntimeException("got wrong class name");
+          }
+        }
+      }
+    });
+    keepRunning = true;
+    reader.start();
+    writer.start();
+    writer.join();
+    keepRunning = false;
+    reader.join();
+  }
+}
diff --git a/hotspot/test/runtime/7100935/TestShortArraycopy.java b/hotspot/test/runtime/7100935/TestShortArraycopy.java
new file mode 100644
index 0000000..81b0489
--- /dev/null
+++ b/hotspot/test/runtime/7100935/TestShortArraycopy.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2011 SAP AG.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test TestShortArraycopy
+ * @bug 7100935
+ * @summary  verify that shorts are copied element-wise atomic.
+ * @run main/othervm -Xint TestShortArraycopy
+ * @run main/othervm -Xcomp -Xbatch TestShortArraycopy
+ * @author volker.simonis@gmail.com
+ */
+
+public class TestShortArraycopy {
+
+  static short[] a1 = new short[8];
+  static short[] a2 = new short[8];
+  static short[] a3 = new short[8];
+
+  static volatile boolean keepRunning = true;
+
+  public static void main(String[] args) throws InterruptedException {
+
+    for (int i = 0; i < a1.length ; i++) {
+      a1[i] = (short)0xffff;
+      a2[i] = (short)0xffff;
+      a3[i] = (short)0x0000;
+    }
+    Thread reader = new Thread() {
+      public void run() {
+        while (keepRunning) {
+          for (int j = 0; j < a1.length; j++) {
+            short s = a1[j];
+            if (s != (short)0xffff && s != (short)0x0000) {
+              System.out.println("Error: s = " + s);
+              throw new RuntimeException("wrong result");
+
+            }
+          }
+        }
+      }
+    };
+    Thread writer = new Thread() {
+      public void run() {
+        for (int i = 0; i < 1000000; i++) {
+          System.arraycopy(a2, 5, a1, 3, 3);
+          System.arraycopy(a3, 5, a1, 3, 3);
+        }
+      }
+    };
+    keepRunning = true;
+    reader.start();
+    writer.start();
+    writer.join();
+    keepRunning = false;
+    reader.join();
+  }
+}
diff --git a/jaxp/.hgtags b/jaxp/.hgtags
index 3c34ccf4..87aad3c 100644
--- a/jaxp/.hgtags
+++ b/jaxp/.hgtags
@@ -140,3 +140,4 @@
 0c5c2b2462f104970eefa4a47b3c4428efd81cf0 jdk7u2-b11
 0e61ef309edd2deb71f53f2bdaf6dcff1c80bfb8 jdk7u2-b12
 d9ac427e5149d1db12c6f3e4aa4280587c06aed5 jdk7u2-b13
+0efaf5c97fba2ee7864240efaa0df651a2635ae5 jdk7u2-b21
diff --git a/jaxp/build.xml b/jaxp/build.xml
index 3c4fda2..9a5897b 100644
--- a/jaxp/build.xml
+++ b/jaxp/build.xml
@@ -43,14 +43,6 @@
       Run 'make help' for help using the Makefile.
     </description>
 
-    <!-- Mac is special, need to downgrade these before build.properties. -->
-    <condition property="javac.source" value="1.5">
-        <os family="mac"/>
-    </condition>
-    <condition property="javac.target" value="1.5">
-        <os family="mac"/>
-    </condition>
-
     <!-- Project build properties. -->
     <property file="build.properties"/>
 
diff --git a/jaxp/make/jprt.properties b/jaxp/make/jprt.properties
index c95c9d0..537c099 100644
--- a/jaxp/make/jprt.properties
+++ b/jaxp/make/jprt.properties
@@ -25,12 +25,24 @@
 
 # Properties for jprt
 
-# Use whatever release that the submitted job requests
-jprt.tools.default.release=${jprt.submit.release}
+# Locked down to jdk7
+jprt.tools.default.release=jdk7
 
 # The different build flavors we want, we override here so we just get these 2
 jprt.build.flavors=product,fastdebug
 
+# Standard list of jprt build targets for this source tree
+jprt.build.targets=                                             \
+    solaris_sparc_5.10-{product|fastdebug},                     \
+    solaris_sparcv9_5.10-{product|fastdebug},                   \
+    solaris_i586_5.10-{product|fastdebug},                      \
+    solaris_x64_5.10-{product|fastdebug},                       \
+    linux_i586_2.6-{product|fastdebug},                         \
+    linux_x64_2.6-{product|fastdebug},                          \
+    macosx_x64_10.7-{product|fastdebug},                        \
+    windows_i586_5.1-{product|fastdebug},                       \
+    windows_x64_5.2-{product|fastdebug}
+
 # Directories to be excluded from the source bundles
 jprt.bundle.exclude.src.dirs=build dist webrev
 
diff --git a/jaxws/.hgtags b/jaxws/.hgtags
index 796641b..d6fb06c 100644
--- a/jaxws/.hgtags
+++ b/jaxws/.hgtags
@@ -140,3 +140,4 @@
 f3bb1066a71f2a64c7bcf45a7ba0a8de63657696 jdk7u2-b11
 21131044a61353ac20e360bce52d8f480e08d7a2 jdk7u2-b12
 9728fd833e01faa5e51484aeaf3c51d32d1175fb jdk7u2-b13
+d6db86a7ca32e6d97844f633badc0d516e55694f jdk7u2-b21
diff --git a/jaxws/build.xml b/jaxws/build.xml
index 9eddf09..818c939 100644
--- a/jaxws/build.xml
+++ b/jaxws/build.xml
@@ -43,14 +43,6 @@
       Run 'make help' for help using the Makefile.
     </description>
 
-    <!-- Mac is special, need to downgrade these before build.properties. -->
-    <condition property="javac.source" value="1.5">
-        <os family="mac"/>
-    </condition>
-    <condition property="javac.target" value="1.5">
-        <os family="mac"/>
-    </condition>
-
     <!-- Project build properties. -->
     <property file="build.properties"/>
 
diff --git a/jaxws/make/jprt.properties b/jaxws/make/jprt.properties
index c95c9d0..ccdd93a 100644
--- a/jaxws/make/jprt.properties
+++ b/jaxws/make/jprt.properties
@@ -25,12 +25,25 @@
 
 # Properties for jprt
 
-# Use whatever release that the submitted job requests
-jprt.tools.default.release=${jprt.submit.release}
+# Locked down to jdk7
+jprt.tools.default.release=jdk7
 
 # The different build flavors we want, we override here so we just get these 2
 jprt.build.flavors=product,fastdebug
 
+# Standard list of jprt build targets for this source tree
+jprt.build.targets=                                             \
+    solaris_sparc_5.10-{product|fastdebug},                     \
+    solaris_sparcv9_5.10-{product|fastdebug},                   \
+    solaris_i586_5.10-{product|fastdebug},                      \
+    solaris_x64_5.10-{product|fastdebug},                       \
+    linux_i586_2.6-{product|fastdebug},                         \
+    linux_x64_2.6-{product|fastdebug},                          \
+    macosx_x64_10.7-{product|fastdebug},                        \
+    windows_i586_5.1-{product|fastdebug},                       \
+    windows_x64_5.2-{product|fastdebug}
+
+
 # Directories to be excluded from the source bundles
 jprt.bundle.exclude.src.dirs=build dist webrev
 
diff --git a/jdk/.hgtags b/jdk/.hgtags
index df8c7d2..fdfcc97 100644
--- a/jdk/.hgtags
+++ b/jdk/.hgtags
@@ -140,3 +140,4 @@
 b5090771e19b2b20670bef60a84de95797cb01be jdk7u2-b11
 79c8c4608f60e1f981b17ba4077dfcaa2ed67be4 jdk7u2-b12
 fb2980d7c9439e3d62ab12f40506a2a2db2df0f4 jdk7u2-b13
+24e42f1f9029f9f5a9b1481d523facaf09452e5b jdk7u2-b21
diff --git a/jdk/make/Makefile b/jdk/make/Makefile
index d6a1d31..59b40ec 100644
--- a/jdk/make/Makefile
+++ b/jdk/make/Makefile
@@ -233,6 +233,9 @@
 all build:: sanity-all post-sanity-all
 
 SUBDIRS       = tools java javax sun com
+ifeq ($(PLATFORM), macosx)
+  SUBDIRS += apple
+endif
 SUBDIRS_tools = launchers
 SUBDIRS_misc  = org sunw jpda mkdemo mksample
 
diff --git a/jdk/make/apple/Makefile b/jdk/make/apple/Makefile
new file mode 100644
index 0000000..4dd03dd
--- /dev/null
+++ b/jdk/make/apple/Makefile
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# Makefile for building com/apple
+#
+
+BUILDDIR = ..
+PRODUCT = sun
+include $(BUILDDIR)/common/Defs.gmk
+
+SUBDIRS = applescript
+
+include $(BUILDDIR)/common/Subdirs.gmk
+
+all build clean clobber::
+	$(SUBDIRS-loop)
diff --git a/jdk/make/apple/applescript/Makefile b/jdk/make/apple/applescript/Makefile
new file mode 100644
index 0000000..6d0bc79
--- /dev/null
+++ b/jdk/make/apple/applescript/Makefile
@@ -0,0 +1,71 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../..
+PACKAGE = apple.applescript
+LIBRARY = AppleScriptEngine
+PRODUCT = sun
+include $(BUILDDIR)/common/Defs.gmk
+
+
+#
+# Files
+#
+AUTO_FILES_JAVA_DIRS = apple/applescript
+
+FILES_objc = \
+        $(TARGDIR)AppleScriptEngine.m \
+        $(TARGDIR)AppleScriptExecutionContext.m \
+        $(TARGDIR)AS_NS_ConversionUtils.m \
+        $(TARGDIR)NS_Java_ConversionUtils.m
+

+
+FILES_export = \
+	apple/applescript/AppleScriptEngine.java \
+	apple/applescript/AppleScriptEngineFactory.java
+
+#
+# Rules
+#
+include $(BUILDDIR)/common/Mapfile-vers.gmk
+include $(BUILDDIR)/common/Library.gmk
+
+
+#
+# Extra rules
+#
+
+#
+# Add to ambient vpath to get files in a subdirectory
+#
+vpath %.m   $(call NativeSrcDirList,,native/apple/applescript)
+
+CPPFLAGS += \
+	-I$(TEMPDIR)/../../sun.awt/awt/CClassHeaders
+
+OTHER_LDLIBS = \
+    -framework Cocoa \
+    -framework Carbon \
+    -framework JavaNativeFoundation
diff --git a/jdk/make/com/Makefile b/jdk/make/com/Makefile
index 16b908c..6f45213 100644
--- a/jdk/make/com/Makefile
+++ b/jdk/make/com/Makefile
@@ -32,6 +32,11 @@
 include $(BUILDDIR)/common/Defs.gmk
 
 SUBDIRS = sun oracle
+
+ifeq ($(PLATFORM), macosx)
+    SUBDIRS += apple
+endif
+
 include $(BUILDDIR)/common/Subdirs.gmk
 
 all build clean clobber::
diff --git a/jdk/make/com/apple/Makefile b/jdk/make/com/apple/Makefile
new file mode 100644
index 0000000..b616163
--- /dev/null
+++ b/jdk/make/com/apple/Makefile
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# Makefile for building com/apple
+#
+
+BUILDDIR = ../..
+PRODUCT = sun
+include $(BUILDDIR)/common/Defs.gmk
+
+# MMM: disable for now, depends on Max AWT (undisabled)
+SUBDIRS = osx osxui
+
+include $(BUILDDIR)/common/Subdirs.gmk
+
+all build clean clobber::
+	$(SUBDIRS-loop)
diff --git a/jdk/make/com/apple/osx/Makefile b/jdk/make/com/apple/osx/Makefile
new file mode 100644
index 0000000..bf0ef9c
--- /dev/null
+++ b/jdk/make/com/apple/osx/Makefile
@@ -0,0 +1,91 @@
+#
+# Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../../..
+PACKAGE = com.apple.osx
+LIBRARY = osx
+PRODUCT = sun
+include $(BUILDDIR)/common/Defs.gmk
+
+
+#
+# Files
+#
+AUTO_FILES_JAVA_DIRS = apple/launcher apple/security com/apple/concurrent com/apple/eio java/util/prefs
+
+FILES_objc += \
+    $(TARGDIR)Dispatch.m \
+    $(TARGDIR)CFileManager.m \
+    $(TARGDIR)KeystoreImpl.m \
+    $(TARGDIR)JavaAppLauncher.m \
+    $(TARGDIR)MacOSXPreferencesFile.m \
+    $(TARGDIR)SCDynamicStoreConfig.m
+
+FILES_export += \
+	com/apple/concurrent/LibDispatchNative.java \
+	com/apple/eio/FileManager.java \
+	apple/security/KeychainStore.java \
+	apple/launcher/JavaAppLauncher.java \
+	java/util/prefs/MacOSXPreferencesFile.java
+
+# TODO: couldn't figure out how to get resources working
+#LOCALE_SET_DEFINITION = jre
+#RESOURCE_BUNDLES_UNCOMPILED_PROPERTIES = apple/launcher/appLauncherErrors.properties
+
+
+#
+# Rules
+#
+include $(BUILDDIR)/common/Mapfile-vers.gmk
+include $(BUILDDIR)/common/Library.gmk
+
+
+#
+# Extra rules
+#
+
+#
+# Add to ambient vpath to get files in a subdirectory
+#
+vpath %.m   $(call NativeSrcDirList,,native/com/apple/concurrent)
+vpath %.m   $(call NativeSrcDirList,,native/com/apple/eio)
+vpath %.m   $(call NativeSrcDirList,,native/apple/launcher)
+vpath %.m   $(call NativeSrcDirList,,native/apple/security)
+vpath %.m   $(call NativeSrcDirList,,native/java/util)
+
+CPPFLAGS += \
+	$(call NativeSrcDirList,-I,native/com/apple/laf) \
+	$(call NativeSrcDirList,-I,native/apple/awt) \
+	$(call NativeSrcDirList,-I,native/sun/awt) \
+	$(call NativeSrcDirList,-I,native/sun/osxapp)
+
+OTHER_LDLIBS = \
+    -losxapp \
+    -framework Cocoa \
+    -framework ApplicationServices \
+    -framework JavaNativeFoundation \
+    -framework JavaRuntimeSupport \
+    -framework Security \
+    -framework SystemConfiguration
diff --git a/jdk/make/com/apple/osxui/Makefile b/jdk/make/com/apple/osxui/Makefile
new file mode 100644
index 0000000..ec3be99
--- /dev/null
+++ b/jdk/make/com/apple/osxui/Makefile
@@ -0,0 +1,106 @@
+#
+# Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../../..
+PACKAGE = com.apple.osxui
+LIBRARY = osxui
+PRODUCT = sun
+include $(BUILDDIR)/common/Defs.gmk
+
+
+#
+# Files
+#
+AUTO_FILES_JAVA_DIRS = apple/laf com/apple/laf com/apple/eawt
+
+FILES_objc = \
+        $(TARGDIR)AquaFileView.m \
+        $(TARGDIR)AquaLookAndFeel.m \
+        $(TARGDIR)AquaNativeResources.m \
+        $(TARGDIR)JRSUIConstantSync.m \
+        $(TARGDIR)JRSUIController.m \
+        $(TARGDIR)JRSUIFocus.m \
+        $(TARGDIR)ScreenPopupFactory.m \
+        $(TARGDIR)ScreenMenu.m
+
+FILES_export = \
+	apple/laf/AquaLookAndFeel.java \
+	apple/laf/JRSUIConstants.java \
+	apple/laf/JRSUIControl.java \
+	apple/laf/JRSUIFocus.java \
+	apple/laf/JRSUIState.java \
+	apple/laf/JRSUIStateFactory.java \
+	apple/laf/JRSUIUtils.java \
+	com/apple/laf/AquaFileView.java \
+	com/apple/laf/AquaNativeResources.java \
+	com/apple/laf/ScreenPopupFactory.java \
+	com/apple/laf/ScreenMenu.java \
+	com/apple/laf/ScreenMenuBar.java \
+	com/apple/laf/ScreenMenuBarProvider.java \
+	com/apple/laf/ScreenMenuItem.java \
+	com/apple/laf/ScreenMenuItemCheckbox.java \
+	com/apple/laf/ScreenMenuItemUI.java \
+	com/apple/laf/ScreenMenuPropertyHandler.java \
+	com/apple/laf/ScreenMenuPropertyListener.java
+
+#RESOURCE_BUNDLES_COMPILED_PROPERTIES += \
+#	com/apple/laf/resources/aqua.properties \
+#	com/apple/laf/resources/aqua_de.properties \
+#	com/apple/laf/resources/aqua_fr.properties \
+#	com/apple/laf/resources/aqua_ja.properties
+
+
+#
+# Rules
+#
+include $(BUILDDIR)/common/Mapfile-vers.gmk
+include $(BUILDDIR)/common/Library.gmk
+
+
+#
+# Extra rules
+#
+
+#
+# Add to ambient vpath to get files in a subdirectory
+#
+vpath %.m   $(call NativeSrcDirList,,native/com/apple/laf)
+vpath %.m $(call NativeSrcDirList,,native/com/apple/eawt)
+
+CPPFLAGS += \
+	$(call NativeSrcDirList,-I,native/com/apple/laf) \
+	$(call NativeSrcDirList,-I,native/apple/awt) \
+	$(call NativeSrcDirList,-I,native/sun/awt) \
+	$(call NativeSrcDirList,-I,native/sun/osxapp) \
+	-I$(TEMPDIR)/../../sun.awt/awt/CClassHeaders
+
+OTHER_LDLIBS = \
+    -lawt -losxapp \
+    -llwawt -L$(LIBDIR)/lwawt -Xlinker -rpath -Xlinker @loader_path/lwawt \
+    -framework Cocoa \
+    -framework Carbon \
+    -framework ApplicationServices \
+    -framework JavaNativeFoundation \
+    -framework JavaRuntimeSupport
diff --git a/jdk/make/com/oracle/net/Makefile b/jdk/make/com/oracle/net/Makefile
new file mode 100644
index 0000000..5fd3076
--- /dev/null
+++ b/jdk/make/com/oracle/net/Makefile
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../../..
+PRODUCT = oracle
+include $(BUILDDIR)/common/Defs.gmk
+
+#
+# Files to compile
+#
+AUTO_FILES_JAVA_DIRS = com/oracle/net
+
+#
+# Rules
+#
+include $(BUILDDIR)/common/Classes.gmk
+
diff --git a/jdk/make/com/sun/java/pack/Makefile b/jdk/make/com/sun/java/pack/Makefile
index f084152..c4973fc 100644
--- a/jdk/make/com/sun/java/pack/Makefile
+++ b/jdk/make/com/sun/java/pack/Makefile
@@ -57,6 +57,7 @@
 vpath %.cpp $(SHARE_SRC)/native/$(PKGDIR)
 
 ifeq ($(STANDALONE),true)
+ ifneq ($(SYSTEM_ZLIB),true)
   ZIPOBJDIR = $(OUTPUTDIR)/tmp/sun/java.util.zip/zip/$(OBJDIRNAME)
 
   ZIPOBJS =  $(ZIPOBJDIR)/zcrc32.$(OBJECT_SUFFIX) \
@@ -73,6 +74,10 @@
   ZINCLUDE=-I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
   OTHER_CXXFLAGS += $(ZINCLUDE)
   LDDFLAGS += $(ZIPOBJS)
+ else
+  LDDFLAGS += -lz
+  OTHER_CXXFLAGS += -DSYSTEM_ZLIB
+ endif
 else
   OTHER_CXXFLAGS += -DNO_ZLIB -DUNPACK_JNI
   OTHER_LDLIBS += $(JVMLIB)
diff --git a/jdk/make/com/sun/nio/Makefile b/jdk/make/com/sun/nio/Makefile
index bdff717..288b629 100644
--- a/jdk/make/com/sun/nio/Makefile
+++ b/jdk/make/com/sun/nio/Makefile
@@ -30,8 +30,12 @@
 BUILDDIR = ../../..
 include $(BUILDDIR)/common/Defs.gmk
 
-SUBDIRS = sctp
+# MMM: disable for now
+ifneq ($(PLATFORM), macosx)
 include $(BUILDDIR)/common/Subdirs.gmk
+SUBDIRS = sctp
+endif
+
 
 all build clean clobber::
 	$(SUBDIRS-loop)
diff --git a/jdk/make/com/sun/security/auth/module/Makefile b/jdk/make/com/sun/security/auth/module/Makefile
index c274fac..ea5b663 100644
--- a/jdk/make/com/sun/security/auth/module/Makefile
+++ b/jdk/make/com/sun/security/auth/module/Makefile
@@ -67,7 +67,7 @@
   include FILES_c_solaris.gmk
 endif # solaris
 
-ifeq ($(PLATFORM), linux)
+ifneq (,$(findstring $(PLATFORM), linux macosx))
   LIBRARY = jaas_unix
   include FILES_export_unix.gmk
   include FILES_c_unix.gmk
diff --git a/jdk/make/com/sun/tools/attach/Exportedfiles.gmk b/jdk/make/com/sun/tools/attach/Exportedfiles.gmk
index 7e07d31..8852c76 100644
--- a/jdk/make/com/sun/tools/attach/Exportedfiles.gmk
+++ b/jdk/make/com/sun/tools/attach/Exportedfiles.gmk
@@ -43,5 +43,7 @@
 	sun/tools/attach/LinuxVirtualMachine.java
 endif
 
-
-
+ifeq ($(PLATFORM), macosx)
+FILES_export = \
+	sun/tools/attach/BsdVirtualMachine.java
+endif
diff --git a/jdk/make/com/sun/tools/attach/FILES_c.gmk b/jdk/make/com/sun/tools/attach/FILES_c.gmk
index b495431..8a5baec 100644
--- a/jdk/make/com/sun/tools/attach/FILES_c.gmk
+++ b/jdk/make/com/sun/tools/attach/FILES_c.gmk
@@ -39,4 +39,7 @@
 	LinuxVirtualMachine.c
 endif
 
-
+ifeq ($(PLATFORM), macosx)
+FILES_c = \
+	BsdVirtualMachine.c
+endif
diff --git a/jdk/make/com/sun/tools/attach/FILES_java.gmk b/jdk/make/com/sun/tools/attach/FILES_java.gmk
index 2ac0b24..6e11f8c 100644
--- a/jdk/make/com/sun/tools/attach/FILES_java.gmk
+++ b/jdk/make/com/sun/tools/attach/FILES_java.gmk
@@ -43,6 +43,11 @@
 	sun/tools/attach/LinuxAttachProvider.java
 endif
 
+ifeq ($(PLATFORM), macosx)
+FILES_java += \
+	sun/tools/attach/BsdAttachProvider.java
+endif
+
 #
 # Files that need to be copied
 #
diff --git a/jdk/make/com/sun/tools/attach/Makefile b/jdk/make/com/sun/tools/attach/Makefile
index 1179f18..70bb242 100644
--- a/jdk/make/com/sun/tools/attach/Makefile
+++ b/jdk/make/com/sun/tools/attach/Makefile
@@ -36,6 +36,9 @@
 ifeq ($(PLATFORM), linux)
 FILES_m = mapfile-linux
 endif
+ifeq ($(PLATFORM), macosx)
+FILES_m = mapfile-bsd 
+endif
 include $(BUILDDIR)/common/Mapfile-vers.gmk
 
 #
@@ -52,7 +55,11 @@
 EXTRA_LIBS += psapi.lib
 endif
 
-vpath %.c $(PLATFORM_SRC)/native/sun/tools/attach
+ifeq ($PLATFORM), macosx)
+  vpath %.c $(call NativeSrcDirList,,native/sun/tools/attach)
+else
+  vpath %.c $(PLATFORM_SRC)/native/sun/tools/attach
+endif
 
 all: classes copy-files
 
diff --git a/jdk/make/com/sun/tools/attach/mapfile-bsd b/jdk/make/com/sun/tools/attach/mapfile-bsd
new file mode 100644
index 0000000..86515d5
--- /dev/null
+++ b/jdk/make/com/sun/tools/attach/mapfile-bsd
@@ -0,0 +1,41 @@
+#
+# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# Define public interface.
+
+SUNWprivate_1.1 {
+	global:
+	    Java_sun_tools_attach_BsdVirtualMachine_checkPermissions;
+	    Java_sun_tools_attach_BsdVirtualMachine_close;
+	    Java_sun_tools_attach_BsdVirtualMachine_connect;
+	    Java_sun_tools_attach_BsdVirtualMachine_open;
+	    Java_sun_tools_attach_BsdVirtualMachine_sendQuitTo;
+	    Java_sun_tools_attach_BsdVirtualMachine_socket;
+	    Java_sun_tools_attach_BsdVirtualMachine_read;
+	    Java_sun_tools_attach_BsdVirtualMachine_write;
+	    Java_sun_tools_attach_BsdVirtualMachine_createAttachFile;
+	local:
+		*;
+};
diff --git a/jdk/make/common/Defs-embedded.gmk b/jdk/make/common/Defs-embedded.gmk
index de449f8..320f76f 100644
--- a/jdk/make/common/Defs-embedded.gmk
+++ b/jdk/make/common/Defs-embedded.gmk
@@ -65,5 +65,12 @@
   NIO_PLATFORM_CLASSES_ROOT_DIR = $(CLOSED_PLATFORM_SRC)/classes/
 endif
 
+# For ARM sflt we need to link to a library with improved FP accuracy
+# and it must be linked after fdlibm - this places it at the end after libc
+# -z muldefs avoids linker errors for duplicate symbols.
+ifeq ($(CROSS_COMPILE_ARCH), arm)
+  EXTRA_LIBS += $(EXT_LIBS_PATH)/sflt_glibc_jdk.a -Xlinker -z -Xlinker muldefs
+endif 
+
 endif # JAVASE_EMBEDDED
 
diff --git a/jdk/make/common/Defs-linux.gmk b/jdk/make/common/Defs-linux.gmk
index d20efc9..995581d 100644
--- a/jdk/make/common/Defs-linux.gmk
+++ b/jdk/make/common/Defs-linux.gmk
@@ -375,6 +375,7 @@
 override LIBNSL                  =
 override LIBSCF                  =
 override LIBTHREAD               =
+override LIBDL                   = -ldl
 override MOOT_PRIORITIES         = true
 override NO_INTERRUPTIBLE_IO     = true
 ifeq ($(ARCH), amd64)
diff --git a/jdk/make/common/Defs-macosx.gmk b/jdk/make/common/Defs-macosx.gmk
new file mode 100644
index 0000000..518e458
--- /dev/null
+++ b/jdk/make/common/Defs-macosx.gmk
@@ -0,0 +1,400 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# Makefile to specify compiler flags for programs and libraries
+# targeted to MACOSX.  Should not contain any rules.
+#
+# WARNING: This file is shared with other workspaces. 
+#          So when it includes other files, it must use JDK_TOPDIR.
+#
+
+# Warning: the following variables are overriden by Defs.gmk. Set
+# values will be silently ignored:
+#   CFLAGS        (set $(OTHER_CFLAGS) instead)
+#   CPPFLAGS      (set $(OTHER_CPPFLAGS) instead)
+#   CXXFLAGS      (set $(OTHER_CXXFLAGS) instead)
+#   LDFLAGS       (set $(OTHER_LDFAGS) instead)
+#   LDLIBS        (set $(EXTRA_LIBS) instead)
+#   LDLIBS_COMMON (set $(EXTRA_LIBS) instead)
+
+# Get shared JDK settings
+include $(JDK_MAKE_SHARED_DIR)/Defs.gmk
+
+# Part of INCREMENTAL_BUILD mechanism.
+#   Compiler emits things like:  path/file.o: file.h
+#   We want something like: relative_path/file.o relative_path/file.d: file.h
+CC_DEPEND	 = -MM
+CC_DEPEND_FILTER = $(SED) -e 's!$*\.$(OBJECT_SUFFIX)!$(dir $@)& $(dir $@)$*.$(DEPEND_SUFFIX)!g'
+
+ifndef PLATFORM_SRC
+  PLATFORM_SRC = $(BUILDDIR)/../src/solaris
+endif # PLATFORM_SRC
+
+# BSD build pulls its platform sources from the solaris tree.
+JAVA_SRCDIR_LIST = src/$(PLATFORM) src/solaris src/share
+NATIVE_SRCDIR_LIST = src/$(PLATFORM) src/solaris src/share
+
+# Platform specific closed sources
+ifndef OPENJDK
+  ifndef CLOSED_PLATFORM_SRC
+    CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/solaris
+  endif
+endif
+
+# platform specific include files
+PLATFORM_INCLUDE_NAME = $(OS_NAME)
+PLATFORM_INCLUDE      = $(INCLUDEDIR)/$(PLATFORM_INCLUDE_NAME)
+
+# suffix used for make dependencies files.
+DEPEND_SUFFIX = d
+# The suffix applied to the library name for FDLIBM
+FDDLIBM_SUFFIX = a
+# The suffix applied to scripts (.bat for windows, nothing for unix)
+SCRIPT_SUFFIX =
+# CC compiler object code output directive flag value
+CC_OBJECT_OUTPUT_FLAG = -o #trailing blank required!
+CC_PROGRAM_OUTPUT_FLAG = -o #trailing blank required!
+
+#
+# Default optimization
+#
+
+ifndef OPTIMIZATION_LEVEL
+  ifeq ($(PRODUCT), java)
+    OPTIMIZATION_LEVEL = HIGHER
+  else
+    OPTIMIZATION_LEVEL = LOWER
+  endif
+endif
+ifndef FASTDEBUG_OPTIMIZATION_LEVEL
+  FASTDEBUG_OPTIMIZATION_LEVEL = LOWER
+endif
+
+# For macosx use -Os by default, unless -O3 can be proved to be worth the cost, as per policy
+# <http://wikis.sun.com/display/OpenJDK/Mac+OS+X+Port+Compilers>
+CC_OPT/NONE     = 
+CC_OPT/LOWER    = -Os
+CC_OPT/HIGHER   = -Os
+CC_OPT/HIGHEST  = -Os
+
+CC_OPT          = $(CC_OPT/$(OPTIMIZATION_LEVEL))
+
+# For all platforms, do not omit the frame pointer register usage. 
+#    We need this frame pointer to make it easy to walk the stacks.
+#    This should be the default on X86, but ia64 and amd64 may not have this
+#    as the default.
+CFLAGS_REQUIRED_amd64   += -m64 -fno-omit-frame-pointer -D_LITTLE_ENDIAN
+LDFLAGS_COMMON_amd64    += -m64
+CFLAGS_REQUIRED_i586    += -m32 -fno-omit-frame-pointer -D_LITTLE_ENDIAN
+LDFLAGS_COMMON_i586     += -m32
+CFLAGS_REQUIRED_ia64    += -m64 -fno-omit-frame-pointer -D_LITTLE_ENDIAN
+CFLAGS_REQUIRED_sparcv9 += -m64 -mcpu=v9
+LDFLAGS_COMMON_sparcv9  += -m64 -mcpu=v9
+CFLAGS_REQUIRED_sparc   += -m32 -mcpu=v9
+LDFLAGS_COMMON_sparc    += -m32 -mcpu=v9
+CFLAGS_REQUIRED_arm     += -fsigned-char -D_LITTLE_ENDIAN
+CFLAGS_REQUIRED_ppc     += -fsigned-char -D_BIG_ENDIAN
+ifeq ($(ZERO_BUILD), true)
+  CFLAGS_REQUIRED       =  $(ZERO_ARCHFLAG)
+  ifeq ($(ZERO_ENDIANNESS), little)
+    CFLAGS_REQUIRED     += -D_LITTLE_ENDIAN
+  endif
+  LDFLAGS_COMMON        += $(ZERO_ARCHFLAG)
+else ifeq ($(ARCH), universal)
+  CFLAGS_REQUIRED       += -arch i386 -arch x86_64 -D_LITTLE_ENDIAN
+  LDFLAGS_COMMON        += -arch i386 -arch x86_64
+else
+  CFLAGS_REQUIRED       =  $(CFLAGS_REQUIRED_$(ARCH))
+  LDFLAGS_COMMON        += $(LDFLAGS_COMMON_$(ARCH))
+endif
+# 16-byte stack re-alignment on 32-bit Darwin
+CFLAGS_REQUIRED_i586 += -mstackrealign
+
+OTHER_CFLAGS = \
+         -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
+	     -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks
+
+#
+# Selection of warning messages
+#
+GCC_INHIBIT	= -Wno-unused -Wno-parentheses
+GCC_STYLE	= 
+GCC_WARNINGS	= -W -Wall $(GCC_STYLE) $(GCC_INHIBIT)
+
+#
+# Treat compiler warnings as errors, if warnings not allowed
+#
+ifeq ($(COMPILER_WARNINGS_FATAL),true)
+  GCC_WARNINGS += -Werror
+endif
+
+#
+# Misc compiler options
+#
+ifneq ($(ARCH),ppc)
+  CFLAGS_COMMON   = -fno-strict-aliasing
+endif 
+PIC_CODE_LARGE = -fPIC
+PIC_CODE_SMALL = -fpic
+GLOBAL_KPIC = $(PIC_CODE_LARGE)
+CFLAGS_COMMON   += $(GLOBAL_KPIC) $(GCC_WARNINGS)
+ifeq ($(ARCH), amd64)
+ CFLAGS_COMMON += -pipe
+endif
+
+# BSD 64bit machines use Dwarf2, which can be HUGE, have fastdebug use -g1
+DEBUG_FLAG = -g
+ifeq ($(FASTDEBUG), true)
+  ifeq ($(ARCH_DATA_MODEL), 64)
+    DEBUG_FLAG = -g1
+  endif
+endif
+
+# DEBUG_BINARIES overrides everything, use full -g debug information
+ifeq ($(DEBUG_BINARIES), true)
+  DEBUG_FLAG = -g
+  CFLAGS_REQUIRED += $(DEBUG_FLAG)
+endif
+
+CFLAGS_OPT      = $(CC_OPT)
+CFLAGS_DBG      = $(DEBUG_FLAG)
+CFLAGS_COMMON += $(CFLAGS_REQUIRED)
+
+CXXFLAGS_COMMON = $(GLOBAL_KPIC) -DCC_NOEX $(GCC_WARNINGS)
+CXXFLAGS_OPT	= $(CC_OPT)
+CXXFLAGS_DBG	= $(DEBUG_FLAG)
+CXXFLAGS_COMMON += $(CFLAGS_REQUIRED)
+
+# FASTDEBUG: Optimize the code in the -g versions, gives us a faster debug java
+ifeq ($(FASTDEBUG), true)
+  CFLAGS_DBG    += $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL))
+  CXXFLAGS_DBG	+= $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL))
+endif
+
+CPP_ARCH_FLAGS = -DARCH='"$(ARCH)"'
+
+# Alpha arch does not like "alpha" defined (potential general arch cleanup issue here)
+ifneq ($(ARCH),alpha)
+  CPP_ARCH_FLAGS += -D$(ARCH)
+else
+  CPP_ARCH_FLAGS += -D_$(ARCH)_
+endif
+CPPFLAGS_COMMON = $(CPP_ARCH_FLAGS) -D_ALLBSD_SOURCE $(VERSION_DEFINES) \
+		  -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_REENTRANT
+
+CPPFLAGS_COMMON += -DMACOSX
+
+ifeq ($(ARCH_DATA_MODEL), 64)
+CPPFLAGS_COMMON += -D_LP64=1
+endif
+
+CPPFLAGS_OPT    = -DNDEBUG
+CPPFLAGS_DBG    = -DDEBUG
+ifneq ($(PRODUCT), java)
+  CPPFLAGS_DBG    += -DLOGGING 
+endif
+
+# Libraries need to locate other libraries at runtime, and you can tell
+#   a library where to look by way of the dynamic runpaths (RPATH or RUNPATH)
+#   buried inside the .{so,dylib}. The {$ORIGIN,@loader_path/} says to look
+#   relative to where the library itself is and it can be followed
+#   with relative paths from that. By default we always look in
+#   {$ORIGIN,@loader_path/}, optionally we add relative paths if the Makefile
+#   sets LD_RUNPATH_EXTRAS to those relative paths.
+#   Except on MacOS X we add a flag -z origin, not sure if this is necessary,
+#   but doesn't seem to hurt.
+#   The environment variable LD_LIBRARY_PATH will over-ride these runpaths.
+#   See 'man {dyld,rtld}' for more information.
+#   Try: 'readelf -d lib*.so' to see these settings in a library.
+#
+LDFLAGS_COMMON += -Xlinker -rpath -Xlinker @loader_path/.
+LDFLAGS_COMMON += $(LD_RUNPATH_EXTRAS:%=-Xlinker -rpath -Xlinker @loader_path/%)
+LDFLAGS_COMMON += -Xlinker -install_name -Xlinker @rpath/$(@F)
+
+#
+# -L paths for finding and -ljava
+#
+LDFLAGS_COMMON += -L$(LIBDIR)
+
+#
+# -static-libgcc is a gcc-3 flag to statically link libgcc, gcc-2.9x always
+# statically link libgcc but will print a warning with the flag. We don't 
+# want the warning, so check gcc version first.
+#
+ifeq ($(CC_MAJORVER),3)
+  OTHER_LDFLAGS  += -static-libgcc
+endif
+
+# Automatic precompiled header option to use (if COMPILE_APPROACH=batch)
+#   (See Rules.gmk) The gcc 5 compiler might have an option for this?
+AUTOMATIC_PCH_OPTION = 
+
+#
+# Post Processing of libraries/executables
+#
+ifeq ($(VARIANT), OPT)
+  ifneq ($(NO_STRIP), true)
+    ifneq ($(DEBUG_BINARIES), true)
+      # Debug 'strip -S' leaves local function Elf symbols (better stack
+      # traces)
+      POST_STRIP_PROCESS = $(STRIP) -S
+    endif
+  endif
+endif
+
+#
+# Use: ld $(LD_MAPFILE_FLAG) mapfile *.o
+#
+LD_MAPFILE_FLAG = -Xlinker --version-script -Xlinker
+
+#
+# Support for Quantify.
+#
+ifdef QUANTIFY
+QUANTIFY_CMD = quantify
+QUANTIFY_OPTIONS = -cache-dir=/tmp/quantify -always-use-cache-dir=yes
+LINK_PRE_CMD = $(QUANTIFY_CMD) $(QUANTIFY_OPTIONS)
+endif
+
+# Darwin does not support linker map files.
+LDNOMAP=true
+
+#
+# Path and option to link against the VM, if you have to.  Note that
+# there are libraries that link against only -ljava, but they do get
+# -L to the -ljvm, this is because -ljava depends on -ljvm, whereas
+# the library itself should not.
+#
+VM_NAME         = server
+JVMLIB          = -L$(LIBDIR)/$(VM_NAME) -ljvm
+JAVALIB         = -ljava $(JVMLIB)
+
+#
+# We want to privatize JVM symbols on Solaris. This is so the user can
+# write a function called FindClass and this should not override the 
+# FindClass that is inside the JVM. At this point in time we are not
+# concerned with other JNI libraries because we hope that there will
+# not be as many clashes there.
+#
+PRIVATIZE_JVM_SYMBOLS = false
+
+USE_PTHREADS = true
+override ALT_CODESET_KEY         = _NL_CTYPE_CODESET_NAME
+override AWT_RUNPATH             =
+override HAVE_ALTZONE            = false
+override HAVE_FILIOH             = false
+override HAVE_GETHRTIME          = false
+override HAVE_GETHRVTIME         = false
+override HAVE_SIGIGNORE          = true
+override LEX_LIBRARY             = -lfl
+ifeq ($(STATIC_CXX),true)
+override LIBCXX                  = -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic
+else
+override LIBCXX                  = -lstdc++
+endif
+override LIBPOSIX4               =
+override LIBSOCKET               =
+override LIBNSL                  =
+override LIBTHREAD               =
+override LIBDL                   =
+override MOOT_PRIORITIES         = true
+override NO_INTERRUPTIBLE_IO     = true
+override OPENWIN_HOME            = $(X11_PATH)
+override OPENWIN_LIB             = $(OPENWIN_HOME)/lib
+override OTHER_M4FLAGS           = -D__GLIBC__ -DGNU_ASSEMBLER
+override SUN_CMM_SUBDIR          =
+override THREADS_FLAG            = native
+override USE_GNU_M4              = true
+override USING_GNU_TAR           = true
+override WRITE_LIBVERSION        = false
+
+ifdef ALT_X11_PATH
+  X11_PATH = $(ALT_X11_PATH)
+else
+  X11_PATH = /usr/X11R6
+endif
+
+ifdef ALT_PACKAGE_PATH
+  PACKAGE_PATH = $(ALT_PACKAGE_PATH)
+else
+  PACKAGE_PATH = /opt/local
+endif
+
+# ALSA
+ifdef ALT_ALSA_LIB_PATH
+  ALSA_LIB_PATH = $(ALT_ALSA_LIB_PATH)
+else
+  ALSA_LIB_PATH = $(PACKAGE_PATH)/lib
+endif
+
+ifdef ALT_ALSA_HEADERS_PATH
+  ALSA_HEADERS_PATH = $(ALT_ALSA_HEADERS_PATH)
+else
+  ALSA_HEADERS_PATH = $(PACKAGE_PATH)/include
+endif
+
+# USE_EXECNAME forces the launcher to look up argv[0] on $PATH, and put the
+# resulting resolved absolute name of the executable in the environment
+# variable EXECNAME.  That executable name is then used that to locate the
+# installation area.
+override USE_EXECNAME            = true
+
+# If your platform has DPS, it will have Type1 fonts too, in which case
+# it is best to enable DPS support until such time as 2D's rasteriser
+# can fully handle Type1 fonts in all cases. Default is "yes".
+# HAVE_DPS should only be "no" if the platform has no DPS headers or libs
+# DPS (Displayable PostScript) is available on Solaris machines
+HAVE_DPS = no
+
+SYSTEM_ZLIB = true
+
+#
+# Japanese manpages
+#
+JA_SOURCE_ENCODING = eucJP
+JA_TARGET_ENCODINGS = UTF-8
+
+# Settings for the JDI - Serviceability Agent binding.
+
+HOTSPOT_SALIB_PATH = $(HOTSPOT_IMPORT_PATH)/jre/lib
+SALIB_NAME = $(LIB_PREFIX)saproc.$(LIBRARY_SUFFIX)
+
+# The JDI - Serviceability Agent binding is not currently supported
+# on ia64.
+ifeq ($(ARCH), ia64)
+  INCLUDE_SA = false
+else
+  INCLUDE_SA = true
+endif
+
+ifdef CROSS_COMPILE_ARCH
+  # X11 headers are not under /usr/include
+  OTHER_CFLAGS += -I$(OPENWIN_HOME)/include
+  OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include
+  OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include
+endif
+
+LIB_LOCATION ?= $(LIBDIR)
diff --git a/jdk/make/common/Defs-solaris.gmk b/jdk/make/common/Defs-solaris.gmk
index 666cdc1..02473d1 100644
--- a/jdk/make/common/Defs-solaris.gmk
+++ b/jdk/make/common/Defs-solaris.gmk
@@ -714,6 +714,9 @@
 # service configuration facility library
 LIBSCF = -lscf
 
+# Dynamic Loading library
+LIBDL = -ldl
+
 # GLOBAL_KPIC: If set means all libraries are PIC, position independent code
 #    EXCEPT for select compiles
 #    If a .o file is compiled non-PIC then it should be forced
diff --git a/jdk/make/common/Defs.gmk b/jdk/make/common/Defs.gmk
index e46aede..1b2b792 100644
--- a/jdk/make/common/Defs.gmk
+++ b/jdk/make/common/Defs.gmk
@@ -179,11 +179,18 @@
 
   ifdef ALT_FREETYPE_LIB_PATH
     FREETYPE_LIB_PATH = $(ALT_FREETYPE_LIB_PATH)
+    ifeq ($(PLATFORM), macosx)
+      USING_SYSTEM_FT_LIB=true
+    endif
   else
     ifeq ($(DEVTOOLS_FT_DIR_EXISTS), true)
       FREETYPE_LIB_PATH = $(DEVTOOLS_FT_DIR)/lib
     else
-      FREETYPE_LIB_PATH = /usr/lib
+      ifeq ($(PLATFORM), macosx)
+        FREETYPE_LIB_PATH = /usr/X11R6/lib
+      else
+        FREETYPE_LIB_PATH = /usr/lib
+      endif
       USING_SYSTEM_FT_LIB=true
     endif
   endif 
@@ -194,7 +201,11 @@
     ifeq ($(DEVTOOLS_FT_DIR_EXISTS), true)
       FREETYPE_HEADERS_PATH = $(DEVTOOLS_FT_DIR)/include
     else
-      FREETYPE_HEADERS_PATH = /usr/include
+      ifeq ($(PLATFORM), macosx)
+        FREETYPE_HEADERS_PATH = /usr/X11R6/include
+      else
+        FREETYPE_HEADERS_PATH = /usr/include
+      endif
     endif
   endif
 endif
@@ -243,6 +254,10 @@
     LDLIBS_COMMON = -ldl
   endif
 
+  ifeq ($(PLATFORM), macosx)
+    LDLIBS_COMMON = -pthread
+  endif
+
 endif # PROGRAM
 
 LDLIBS_COMMON += $(EXTRA_LIBS)
@@ -383,7 +398,12 @@
 # We define an intermediate variable for Java files because
 # we use its value later to help define $SOURCEPATH
 
-VPATH0.java = $(GENSRCDIR)$(CLASSPATH_SEPARATOR)$(PLATFORM_SRC)/classes$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/classes
+ifeq ($(PLATFORM), macosx)
+  VPATH0.java = $(subst $(ONESPACE),:,$(GENSRCDIR) $(call JavaSrcDirList,,classes))
+else
+  VPATH0.java = $(GENSRCDIR)$(CLASSPATH_SEPARATOR)$(PLATFORM_SRC)/classes$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/classes
+endif
+
 ifdef OPENJDK
   VPATH.java = $(VPATH0.java)
 else
diff --git a/jdk/make/common/Library.gmk b/jdk/make/common/Library.gmk
index 9999406..8cd1a82 100644
--- a/jdk/make/common/Library.gmk
+++ b/jdk/make/common/Library.gmk
@@ -58,6 +58,17 @@
 FILES_o  += $(patsubst %.s,   %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_s))))
 FILES_o  += $(patsubst %.cpp, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
 
+ifeq ($(PLATFORM), macosx)
+FILES_o  += $(patsubst %.m,   %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_objc))))
+FILES_o  += $(patsubst %.mm,  %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_objcpp))))
+
+# MMM: why?
+INCREMENTAL_BUILD=false
+
+endif # PLATFORM
+
+
+
 ifeq ($(INCREMENTAL_BUILD),true)
 FILES_d   = $(patsubst %.c,   %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
 FILES_d  += $(patsubst %.cpp, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
@@ -217,12 +228,17 @@
 # the shared library.  On other platforms set this to false at the
 # make command line.
 #
+
+ifneq ($(PLATFORM), macosx)
+  ARFLAGS = -r
+endif
+
 $(ACTUAL_LIBRARY):: $(COMPILE_FILES_o) $(FILES_m) $(FILES_reorder)
 	@$(prep-target)
 	@$(ECHO) "STATS: LIBRARY=$(LIBRARY), PRODUCT=$(PRODUCT), OPTIMIZATION_LEVEL=$(OPTIMIZATION_LEVEL)"
 	@$(ECHO) "Rebuilding $@ because of $?"
 ifeq ($(LIBRARY), fdlibm)
-	$(AR) -r $@ $(FILES_o)
+	$(AR) $(ARFLAGS) $@ $(FILES_o)
 else # LIBRARY
 	$(LINKER) $(SHARED_LIBRARY_FLAG) -o $@ $(FILES_o) $(LDLIBS)
 	@$(call binary_file_verification,$@)
diff --git a/jdk/make/common/Program.gmk b/jdk/make/common/Program.gmk
index 38adb13..d81d483 100644
--- a/jdk/make/common/Program.gmk
+++ b/jdk/make/common/Program.gmk
@@ -78,6 +78,17 @@
 # On Windows, this is done by using the same directory as the executable
 # itself, as with all the Windows libraries.
 #
+ifeq ($(PLATFORM), macosx)
+  ifneq ($(ARCH), universal)
+    LDFLAGS += -Wl,-all_load
+  endif
+  LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
+
+  ifeq ($(SYSTEM_ZLIB),true)
+    OTHER_LDLIBS += -lz
+  endif
+endif
+
 ifneq (,$(findstring $(PLATFORM), linux solaris))	# UNIX systems
     LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
     OTHER_LDLIBS += -ljli
@@ -183,6 +194,22 @@
   THREADLIBS = $(LIBTHREAD)
 endif # USE_PTHREADS
 
+ifeq ($(PLATFORM), macosx)
+THREADLIBS = -pthread
+# Needed for linking the various launchers
+LDFLAGS += -framework Cocoa -framework Security -framework ApplicationServices
+
+# Default Info.plist file for the command line tools. This gets overridden by
+# some of the jvmstat tools so that they have task_for_pid() privileges
+ifndef INFO_PLIST_FILE
+    INFO_PLIST_FILE=Info-cmdline.plist
+endif
+
+LDFLAGS += -sectcreate __TEXT __info_plist $(LAUNCHER_PLATFORM_SRC)/lib/$(INFO_PLIST_FILE)
+else # macosx
+INFO_PLIST_FILE=
+endif # macosx
+
 #
 # This rule only applies on unix.  It supports quantify and its ilk.
 #
@@ -193,6 +220,9 @@
 	@$(MKDIR) -p $(TEMPDIR)
 	$(LINK_PRE_CMD) $(CC) $(CC_OBJECT_OUTPUT_FLAG)$@ $(LDFLAGS) \
 	    $(FILES_o) $(THREADLIBS) $(LDLIBS)
+ifeq ($(findstring privileged, $(INFO_PLIST_FILE)), privileged)
+	-codesign -s openjdk_codesign $@
+endif
 	@$(call binary_file_verification,$@)
 
 endif # PLATFORM
@@ -247,7 +277,13 @@
 endif
 
 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
-OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
+ifeq ($(PLATFORM), macosx)
+  ifneq ($(SYSTEM_ZLIB), true)
+    OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
+  endif
+else 
+  OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
+endif
 
 OTHER_CPPFLAGS += -DPROGNAME='"$(PROGRAM)"'
 VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"'
diff --git a/jdk/make/common/Release-macosx.gmk b/jdk/make/common/Release-macosx.gmk
new file mode 100644
index 0000000..bda9907
--- /dev/null
+++ b/jdk/make/common/Release-macosx.gmk
@@ -0,0 +1,77 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+MANBASEDIRS=$(JDK_TOPDIR)/src/bsd/doc $(IMPORTDOCDIR)
+MAN1SUBDIR = man
+JA_DIRNAME=ja_JP.UTF-8
+
+# Defines the release targets for Mac OS X build products
+
+JDK_BUNDLE_DIR = $(ABS_OUTPUTDIR)/j2sdk-bundle/$(THIS_JDK_VERSION).jdk/Contents
+JRE_BUNDLE_DIR = $(ABS_OUTPUTDIR)/j2re-bundle/$(THIS_JDK_VERSION).jre/Contents
+
+MACOSX_SRC	 = $(JDK_TOPDIR)/src/macosx
+
+BUNDLE_ID ?= net.java.openjdk
+BUNLDE_ID_JRE ?= $(BUNDLE_ID).jre
+BUNLDE_ID_JDK ?= $(BUNDLE_ID).jdk
+
+BUNDLE_NAME ?= OpenJDK 7
+BUNDLE_NAME_JRE ?= $(BUNDLE_NAME)
+BUNDLE_NAME_JDK ?= $(BUNDLE_NAME)
+
+BUNDLE_INFO ?= OpenJDK (1.7.0)
+BUNDLE_INFO_JRE ?= $(BUNDLE_INFO)
+BUNDLE_INFO_JDK ?= $(BUNDLE_INFO)
+
+BUNDLE_PLATFORM_VERSION ?= 1.7
+BUNDLE_VERSION ?= 1.7.0
+BUNDLE_VENDOR ?= UNDEFINED
+
+jre-bundle-setup:
+	$(RM) -r $(JRE_BUNDLE_DIR)
+
+jdk-bundle-setup:
+	$(RM) -r $(JDK_BUNDLE_DIR)
+
+jre-bundle-files:
+	$(MKDIR) -p $(JRE_BUNDLE_DIR)/MacOS
+	ln -s ../Home/lib/jli/libjli.dylib $(JRE_BUNDLE_DIR)/MacOS/
+	$(MV) $(JRE_IMAGE_DIR) $(JRE_BUNDLE_DIR)/Home
+	$(SED) -e "s/@@ID@@/$(BUNDLE_ID_JRE)/g" -e "s/@@NAME@@/$(BUNDLE_NAME_JRE)/g" -e "s/@@INFO@@/$(BUNDLE_INFO_JRE)/g" -e "s/@@PLATFORM_VERSION@@/$(BUNDLE_PLATFORM_VERSION)/g" -e "s/@@VERSION@@/$(BUNDLE_VERSION)/g" -e "s/@@VENDOR@@/$(BUNDLE_VENDOR)/g" < $(MACOSX_SRC)/bundle/JRE-Info.plist > $(JRE_BUNDLE_DIR)/Info.plist
+	/usr/bin/SetFile -a B $(JRE_BUNDLE_DIR)/../
+	$(MV) $(ABS_OUTPUTDIR)/j2re-bundle $(JRE_IMAGE_DIR)
+
+jdk-bundle-files:
+	$(MKDIR) -p $(JDK_BUNDLE_DIR)/MacOS
+	ln -s ../Home/jre/lib/jli/libjli.dylib $(JDK_BUNDLE_DIR)/MacOS/
+	$(MV) $(JDK_IMAGE_DIR) $(JDK_BUNDLE_DIR)/Home
+	$(SED) -e "s/@@ID@@/$(BUNDLE_ID_JDK)/g" -e "s/@@NAME@@/$(BUNDLE_NAME_JDK)/g" -e "s/@@INFO@@/$(BUNDLE_INFO_JDK)/g" -e "s/@@PLATFORM_VERSION@@/$(BUNDLE_PLATFORM_VERSION)/g" -e "s/@@VERSION@@/$(BUNDLE_VERSION)/g" -e "s/@@VENDOR@@/$(BUNDLE_VENDOR)/g" < $(MACOSX_SRC)/bundle/JDK-Info.plist > $(JDK_BUNDLE_DIR)/Info.plist
+	/usr/bin/SetFile -a B $(JDK_BUNDLE_DIR)/../
+	$(MV) $(ABS_OUTPUTDIR)/j2sdk-bundle $(JDK_IMAGE_DIR)
+
+EXTRA_IMAGE_TARGETS += jre-bundle-setup jdk-bundle-setup jre-bundle-files jdk-bundle-files
+
+.PHONY: $(EXTRA_JRE_TARGETS) $(EXTRA_IMAGE_TARGETS)
diff --git a/jdk/make/common/Release.gmk b/jdk/make/common/Release.gmk
index c443115..d8e0ef0 100644
--- a/jdk/make/common/Release.gmk
+++ b/jdk/make/common/Release.gmk
@@ -74,6 +74,10 @@
 
 JTG_DOCS            = $(JDK_TOPDIR)/src/solaris/doc
 
+ifeq ($(PLATFORM), macosx)
+  include $(JDK_TOPDIR)/make/common/Release-$(PLATFORM).gmk
+endif
+
 # The base names of all the license and document files for the jdk and jre
 #   (These files get placed in the jdk and jre install images)
 ifdef OPENJDK
@@ -231,11 +235,22 @@
 	@$(ECHO) ">>>Making "$@" @ `$(DATE)` ..."
 
 # Order is important here, trim jre after jdk image is created
+ifeq ($(PLATFORM), macosx)
+
+images:: sanity-images post-sanity-images  \
+	 $(INITIAL_IMAGE_JRE) $(EXTRA_JRE_TARGETS) $(INITIAL_IMAGE_JDK) \
+	 trim-image-jre trim-image-jdk \
+     identify-image-jre identify-image-jdk \
+	 process-image-jre process-image-jdk sec-files sec-files-win jgss-files \
+	 $(EXTRA_IMAGE_TARGETS)
+else
+
 images:: sanity-images post-sanity-images  \
 	 $(INITIAL_IMAGE_JRE) $(INITIAL_IMAGE_JDK) \
 	 trim-image-jre trim-image-jdk \
          identify-image-jre identify-image-jdk \
 	 process-image-jre process-image-jdk sec-files sec-files-win jgss-files 
+endif
 
 # Don't use these
 image-jre:: initial-image-jre trim-image-jre identify-image-jre process-image-jre
@@ -775,6 +790,10 @@
 	    $(BOOT_JAVA_CMD) -jar $(BUILDMETAINDEX_JARFILE) \
 		-o meta-index *.jar
 	@$(CD) $(JRE_IMAGE_DIR)/lib/ext && $(java-vm-cleanup)
+ifeq ($(PLATFORM), macosx)
+	@#install jobjc, apple mac only
+	$(CP) $(OUTPUTDIR)/JObjC.build/JObjC.jar $(JRE_IMAGE_DIR)/lib/JObjC.jar
+endif # macosx
 ifeq ($(PLATFORM), windows)
 	@# Remove certain *.lib files
 	$(CD) $(JRE_IMAGE_DIR)/lib && \
@@ -1003,7 +1022,8 @@
 	@# generated by the more efficient solaris/windows method of copying files.
 	@# So for Linux, make use of the -T option (like Solaris' -I option) of
 	@# obtaining the list of files from a file. MKS tar has no such option.
-  ifeq ($(PLATFORM), linux)
+
+  ifneq (,$(findstring $(PLATFORM), linux macosx))
 	for d in $(SOURCE_DIRS); do \
 	  $(RM) $(ABS_TEMPDIR)/src-files.list; \
 	  ($(CD) $$d &&  \
diff --git a/jdk/make/common/Rules.gmk b/jdk/make/common/Rules.gmk
index 5072b33..77196f0 100644
--- a/jdk/make/common/Rules.gmk
+++ b/jdk/make/common/Rules.gmk
@@ -51,12 +51,23 @@
 #
 # All source tree areas for java/properties files (a few may be closed)
 #
-ifdef OPENJDK
-  ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
+ifeq ($(PLATFORM), macosx)
+  ifdef OPENJDK
+    ALL_CLASSES_SRC = $(call JavaSrcDirList,,classes)
+  else
+    # TODO(cpc): maybe we should modify JavaSrcDirList macro instead...
+    ALL_CLASSES_SRC = \
+	  $(CLOSED_SHARE_SRC)/classes $(CLOSED_PLATFORM_SRC)/classes \
+	  $(call JavaSrcDirList,,classes)
+  endif
 else
-  ALL_CLASSES_SRC = \
-	$(CLOSED_SHARE_SRC)/classes $(CLOSED_PLATFORM_SRC)/classes \
-	$(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
+  ifdef OPENJDK
+    ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
+  else
+    ALL_CLASSES_SRC = \
+	  $(CLOSED_SHARE_SRC)/classes $(CLOSED_PLATFORM_SRC)/classes \
+	  $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
+  endif
 endif
 
 #
@@ -200,8 +211,15 @@
 
 $(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
 	@$(add-java-file)
+
+ifeq ($(PLATFORM), macosx)
+# TODO(cpc): need to document why this is necessary...
+$(CLASSDESTDIR)/%.class: $(JDK_TOPDIR)/src/macosx/classes/%.java
+	@$(add-java-file)
+endif
 $(CLASSDESTDIR)/%.class: $(PLATFORM_SRC)/classes/%.java
 	@$(add-java-file)
+
 $(CLASSDESTDIR)/%.class: $(SHARE_SRC)/classes/%.java
 	@$(add-java-file)
 
diff --git a/jdk/make/common/internal/NativeCompileRules.gmk b/jdk/make/common/internal/NativeCompileRules.gmk
index 5d9cf72..5379ef3 100644
--- a/jdk/make/common/internal/NativeCompileRules.gmk
+++ b/jdk/make/common/internal/NativeCompileRules.gmk
@@ -176,6 +176,24 @@
     endif
 	@$(check-conventions)
 
+# Obj-C files (Mac OS X only).
+ifeq ($(PLATFORM), macosx)
+$(OBJDIR)/%.$(OBJECT_SUFFIX): %.m
+	@$(prep-target)
+	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
+	@$(check-conventions)
+
+$(OBJDIR)/%.$(OBJECT_SUFFIX): %.mm
+	@$(prep-target)
+	$(COMPILE.cc) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
+	@$(check-conventions)
+
+$(OBJDIR)/%.$(OBJECT_SUFFIX): %.c
+	@$(prep-target)
+	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
+	@$(check-conventions)
+endif # PLATFORM
+
 #
 # Quick hack for making the compiler generate just the assembly file.
 #	$ gnumake obj/sparc/myfile.s
diff --git a/jdk/make/common/shared/Compiler-llvm.gmk b/jdk/make/common/shared/Compiler-llvm.gmk
new file mode 100644
index 0000000..0b26a08
--- /dev/null
+++ b/jdk/make/common/shared/Compiler-llvm.gmk
@@ -0,0 +1,59 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# LLVM Compiler settings
+#
+
+ifeq ($(PLATFORM), macosx)
+
+  # Settings specific to Mac OS X
+  ifeq ($(origin CC), default)
+   CC             = $(COMPILER_PATH)llvm-gcc
+  endif
+  CPP             = $(COMPILER_PATH)llvm-gcc -E
+  ifeq ($(origin CXX), default)
+   CXX            = $(COMPILER_PATH)llvm-g++
+  endif
+
+  REQUIRED_CC_VER = 4.2.1
+
+  # Option used to create a shared library
+  SHARED_LIBRARY_FLAG = -Wl,-install_name,@rpath/$(@F) -dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0
+  SUN_COMP_VER := $(shell $(CC) --verbose 2>&1 )
+
+  AR = $(CC)
+  ARFLAGS = -nostdlib -r -arch i386 -arch x86_64 -o
+
+endif
+
+# Get llvm version
+_CC_VER :=$(shell $(CC) -dumpversion 2>&1 )
+CC_VER  :=$(call GetVersion,"$(_CC_VER)")
+
+# Name of compiler
+COMPILER_NAME = LLVM-GCC$(call MajorVersion,$(CC_VER))
+COMPILER_VERSION = $(COMPILER_NAME)
+
diff --git a/jdk/make/common/shared/Defs-java.gmk b/jdk/make/common/shared/Defs-java.gmk
index d4a27e3..17e8379 100644
--- a/jdk/make/common/shared/Defs-java.gmk
+++ b/jdk/make/common/shared/Defs-java.gmk
@@ -66,7 +66,12 @@
    -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput
 
 # JVM options
-JAVA_JVM_FLAGS = $(JAVA_HOTSPOT_DISABLE_PRINT_VMOPTIONS)
+# MMM: is headless option necessary?
+ifeq ($(PLATFORM), macosx)
+  JAVA_JVM_FLAGS = $(JAVA_HOTSPOT_DISABLE_PRINT_VMOPTIONS) -Djava.awt.headless=true
+else
+  JAVA_JVM_FLAGS = $(JAVA_HOTSPOT_DISABLE_PRINT_VMOPTIONS)
+endif
 
 ifeq ($(ADD_CLIENT_VM_OPTION), true)
   JAVA_JVM_FLAGS += -client
diff --git a/jdk/make/common/shared/Defs-macosx.gmk b/jdk/make/common/shared/Defs-macosx.gmk
new file mode 100644
index 0000000..b966296
--- /dev/null
+++ b/jdk/make/common/shared/Defs-macosx.gmk
@@ -0,0 +1,252 @@
+#
+# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# Definitions for Bsd.
+#
+
+# Default for COMPILER_WARNINGS_FATAL on Bsd (C & C++ compiler warnings)
+ifndef COMPILER_WARNINGS_FATAL
+  COMPILER_WARNINGS_FATAL=false
+endif
+
+# Bsd should use parallel compilation for best build times
+ifndef COMPILE_APPROACH
+  COMPILE_APPROACH = parallel
+endif
+
+# Indication that we are doing an incremental build.
+#    This may trigger the creation of make depend files.
+ifndef INCREMENTAL_BUILD
+  INCREMENTAL_BUILD = false
+endif
+
+# FullPath just makes sure it never ends with a / and no duplicates
+define FullPath
+$(shell cd $1 2> $(DEV_NULL) && pwd)
+endef
+
+# OptFullPath: Absolute path name of a dir that might not initially exist.
+define OptFullPath
+$(shell if [ "$1" != "" -a -d "$1" ]; then (cd $1 && pwd); else echo "$1"; fi)
+endef
+
+# Location on system where jdk installs might be
+USRJDKINSTANCES_PATH = $(PACKAGE_PATH)
+
+# UNIXCOMMAND_PATH: path to where the most common Unix commands are.
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_UNIXCOMMAND_PATH)" "undefined"
+  UNIXCOMMAND_PATH :=$(call PrefixPath,$(ALT_UNIXCOMMAND_PATH))
+else
+  UNIXCOMMAND_PATH  = /bin/
+endif
+
+# USRBIN_PATH: path to where the most common Unix commands are.
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_USRBIN_PATH)" "undefined"
+  USRBIN_PATH :=$(call PrefixPath,$(ALT_USRBIN_PATH))
+else
+  USRBIN_PATH  = /usr/bin/
+endif
+
+# UNIXCCS_PATH: path to where the Solaris ported UNIX commands can be found
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_UNIXCCS_PATH)" "undefined"
+  UNIXCCS_PATH :=$(call PrefixPath,$(ALT_UNIXCCS_PATH))
+else
+  UNIXCCS_PATH = /usr/ccs/bin/
+endif
+
+# SLASH_JAVA: location of all network accessable files
+ifdef ALT_SLASH_JAVA
+  SLASH_JAVA  :=$(ALT_SLASH_JAVA)
+else
+  SLASH_JAVA  := $(call DirExists,/java,/java,/NOT-SET)
+endif
+
+# JDK_DEVTOOLS_DIR: common path for all the java devtools
+ifdef ALT_JDK_DEVTOOLS_DIR
+  JDK_DEVTOOLS_DIR  =$(ALT_JDK_DEVTOOLS_DIR)
+else
+  JDK_DEVTOOLS_DIR =$(SLASH_JAVA)/devtools
+endif
+
+# COMPILER_PATH: path to where the compiler and tools are installed.
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_COMPILER_PATH)" "undefined"
+  COMPILER_PATH :=$(call PrefixPath,$(ALT_COMPILER_PATH))
+else
+ ifeq ($(OS_VENDOR), Apple)
+  ifndef DEVELOPER_DIR
+   DEVELOPER_DIR = $(shell /usr/bin/xcode-select -print-path)/usr/bin/
+  endif
+  
+  COMPILER_PATH  := $(call DirExists,$(DEVELOPER_DIR),/usr/bin/,/NOT-SET)
+ else
+  COMPILER_PATH  =/usr/bin/
+ endif
+endif
+
+# OPENWIN_HOME: path to where the X11 environment is installed.
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq ($(ALT_OPENWIN_HOME),)
+  OPENWIN_HOME :=$(call PrefixPath,$(ALT_OPENWIN_HOME))
+else
+  OPENWIN_HOME  =$(X11_PATH)
+endif
+
+# DEVTOOLS_PATH: for other tools required for building (such as zip, etc.)
+#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
+ifneq "$(origin ALT_DEVTOOLS_PATH)" "undefined"
+  DEVTOOLS_PATH :=$(call PrefixPath,$(ALT_DEVTOOLS_PATH))
+else
+  DEVTOOLS_PATH =$(PACKAGE_PATH)/bin/
+endif
+
+# _BOOTDIR1: First choice for a Bootstrap JDK, previous released JDK.
+# _BOOTDIR2: Second choice
+ifndef ALT_BOOTDIR
+  _BOOTDIR1  =$(SLASH_JAVA)/re/jdk/$(PREVIOUS_JDK_VERSION)/archive/fcs/binaries/$(PLATFORM)-$(ARCH)
+  _BOOTDIR2  =$(USRJDKINSTANCES_PATH)/jdk$(PREVIOUS_JDK_VERSION)
+endif
+
+# Always build headless on Bsd
+BUILD_HEADLESS = true
+LIBM=-lm
+
+ifeq ($(OS_VENDOR), Apple)
+  _CUPS_HEADERS_PATH=/usr/include
+else
+  _CUPS_HEADERS_PATH=$(PACKAGE_PATH)/include
+endif
+
+# Import JDK images allow for partial builds, components not built are
+#    imported (or copied from) these import areas when needed.
+
+# BUILD_JDK_IMPORT_PATH: location of JDK install trees to import for 
+#   multiple platforms, e.g. windows-i586, solaris-sparc, bsd-586, etc.
+ifdef ALT_BUILD_JDK_IMPORT_PATH
+  BUILD_JDK_IMPORT_PATH  :=$(call FullPath,$(ALT_BUILD_JDK_IMPORT_PATH))
+else
+  BUILD_JDK_IMPORT_PATH   = $(PROMOTED_BUILD_BINARIES)
+endif
+BUILD_JDK_IMPORT_PATH:=$(call AltCheckValue,BUILD_JDK_IMPORT_PATH)
+
+# JDK_IMPORT_PATH: location of JDK install tree (this version) to import
+ifdef ALT_JDK_IMPORT_PATH
+  JDK_IMPORT_PATH  :=$(call FullPath,$(ALT_JDK_IMPORT_PATH))
+else
+  JDK_IMPORT_PATH   = $(BUILD_JDK_IMPORT_PATH)/$(PLATFORM)-$(ARCH)$(_JDK_IMPORT_VARIANT)
+endif
+JDK_IMPORT_PATH:=$(call AltCheckValue,JDK_IMPORT_PATH)
+
+# HOTSPOT_IMPORT_PATH: location of hotspot pre-built files
+ifdef ALT_HOTSPOT_IMPORT_PATH
+  HOTSPOT_IMPORT_PATH :=$(call FullPath,$(ALT_HOTSPOT_IMPORT_PATH))
+else
+  HOTSPOT_IMPORT_PATH =$(JDK_IMPORT_PATH)
+endif
+HOTSPOT_IMPORT_PATH:=$(call AltCheckValue,HOTSPOT_IMPORT_PATH)
+
+# HOTSPOT_CLIENT_PATH: location of client jvm library file.
+ifeq ($(ARCH_DATA_MODEL), 32)
+  ifdef ALT_HOTSPOT_CLIENT_PATH
+    HOTSPOT_CLIENT_PATH :=$(call FullPath,$(ALT_HOTSPOT_CLIENT_PATH))
+  else
+    HOTSPOT_CLIENT_PATH   =$(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/client
+  endif
+  HOTSPOT_CLIENT_PATH:=$(call AltCheckValue,HOTSPOT_CLIENT_PATH)
+endif
+
+# HOTSPOT_SERVER_PATH: location of server jvm library file.
+ifdef ALT_HOTSPOT_SERVER_PATH
+  HOTSPOT_SERVER_PATH :=$(call FullPath,$(ALT_HOTSPOT_SERVER_PATH))
+else
+  HOTSPOT_SERVER_PATH   =$(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/server
+endif
+HOTSPOT_SERVER_PATH:=$(call AltCheckValue,HOTSPOT_SERVER_PATH)
+
+# Special define for checking the binaries
+
+# Debug builds should downgrade warnings to just info
+MAPFILE_WARNING-DBG=INFO
+MAPFILE_WARNING-OPT=WARNING
+MAPFILE_WARNING-=WARNING
+MAPFILE_WARNING=$(MAPFILE_WARNING-$(VARIANT))
+
+# Macro to check it's input file for banned dependencies and verify the
+#   binary built properly. Relies on process exit code.
+ifndef CROSS_COMPILE_ARCH
+ifeq ($(OS_VENDOR), Apple)
+define binary_file_verification # binary_file
+( \
+  $(ECHO) "Checking for mapfile use in: $1" && \
+  if [ "`$(NM) -g $1 | $(EGREP) 'SUNWprivate'`" = "" ] ; then \
+    $(ECHO) "WARNING: File was not built with a mapfile: $1"; \
+  fi && \
+  $(ECHO) "Library loads for: $1" && \
+  $(OTOOL) -L $1 && \
+  $(ECHO) "RUNPATH for: $1" && \
+  ( $(OTOOL) -l $1 | $(EGREP) 'path ' ) \
+) || true
+endef
+else
+ifeq ($(OS_VENDOR), OpenBSD)
+define binary_file_verification # binary_file
+( \
+  $(ECHO) "Checking for mapfile use in: $1" && \
+  if [ "`$(OBJDUMP) -T $1 | $(EGREP) '[0-9a-f]* g *DF \.text.*SUNWprivate'`" = "" ] ; then \
+    $(ECHO) "$(MAPFILE_WARNING): File was not built with a mapfile: $1"; \
+  fi && \
+  $(ECHO) "Library loads for: $1" && \
+  $(LDD) $1 && \
+  $(ECHO) "RUNPATH for: $1" && \
+  ( $(READELF) -d $1 | $(EGREP) 'NEEDED|RUNPATH|RPATH' ) \
+) || true
+endef
+else
+define binary_file_verification # binary_file
+( \
+  $(ECHO) "Checking for mapfile use in: $1" && \
+  if [ "`$(NM) -D -g --defined-only $1 | $(EGREP) 'SUNWprivate'`" = "" ] ; then \
+    $(ECHO) "$(MAPFILE_WARNING): File was not built with a mapfile: $1"; \
+  fi && \
+  $(ECHO) "Library loads for: $1" && \
+  $(LDD) $1 && \
+  $(ECHO) "RUNPATH for: $1" && \
+  ( $(READELF) -d $1 | $(EGREP) 'NEEDED|RUNPATH|RPATH' ) \
+)
+endef
+endif # OS_VENDOR == OpenBSD
+endif # OS_VENDOR == Apple
+else
+define binary_file_verification 
+( \
+  $(ECHO) "Skipping binary file verification for cross-compile build" \
+)
+endef
+endif
+
diff --git a/jdk/make/common/shared/Defs-utils.gmk b/jdk/make/common/shared/Defs-utils.gmk
index 1cebe93..9bc05d6 100644
--- a/jdk/make/common/shared/Defs-utils.gmk
+++ b/jdk/make/common/shared/Defs-utils.gmk
@@ -67,6 +67,13 @@
   UTILS_DEVTOOL_PATH=$(DEVTOOLS_PATH)
 endif
 
+ifeq ($(PLATFORM),macosx)
+  UTILS_COMMAND_PATH=$(UNIXCOMMAND_PATH)
+  UTILS_USR_BIN_PATH=$(USRBIN_PATH)
+  UTILS_CCS_BIN_PATH=$(USRBIN_PATH)
+  UTILS_DEVTOOL_PATH=$(DEVTOOLS_PATH)
+endif
+
 # Utilities
 ifdef CROSS_COMPILE_ARCH
   AR             = $(COMPILER_PATH)ar
@@ -126,6 +133,7 @@
 MSGFMT         = $(UTILS_USR_BIN_PATH)msgfmt
 MV             = $(UTILS_COMMAND_PATH)mv
 NAWK           = $(UTILS_USR_BIN_PATH)nawk
+OTOOL          = $(UTILS_USR_BIN_PATH)otool
 PKGMK          = $(UTILS_COMMAND_PATH)pkgmk
 PRINTF         = $(UTILS_USR_BIN_PATH)printf
 PWD            = $(UTILS_COMMAND_PATH)pwd
@@ -220,3 +228,26 @@
   ECHO           = /usr/bin/echo
 endif
 
+ifeq ($(PLATFORM), macosx) 
+  BASENAME     = $(UTILS_USR_BIN_PATH)basename
+  EGREP        = $(UTILS_USR_BIN_PATH)egrep
+  EXPR         = $(UTILS_COMMAND_PATH)expr
+  FMT          = $(UTILS_USR_BIN_PATH)fmt
+  GREP         = $(UTILS_USR_BIN_PATH)grep
+  GUNZIP       = $(UTILS_USR_BIN_PATH)gunzip
+  ID           = $(UTILS_USR_BIN_PATH)id
+  MSGFMT       = $(UTILS_DEVTOOL_PATH)msgfmt
+  SED          = $(UTILS_USR_BIN_PATH)sed
+  SORT         = $(UTILS_USR_BIN_PATH)sort
+  TEST         = $(UTILS_COMMAND_PATH)test
+  TOUCH        = $(UTILS_USR_BIN_PATH)touch
+  TRUE         = $(UTILS_USR_BIN_PATH)true
+  UNAME        = $(UTILS_USR_BIN_PATH)uname
+  NAWK         = $(UTILS_USR_BIN_PATH)awk
+  UNZIPSFX     = $(UTILS_USR_BIN_PATH)unzipsfx
+  ZIPEXE       = $(UTILS_USR_BIN_PATH)zip
+  CPIO         = $(UTILS_USR_BIN_PATH)cpio
+  TAR          = $(UTILS_USR_BIN_PATH)tar
+  # Builtin shell command, no -e option needed
+  ECHO         = echo
+endif
diff --git a/jdk/make/common/shared/Defs-versions.gmk b/jdk/make/common/shared/Defs-versions.gmk
index 6e00b22..1675e25 100644
--- a/jdk/make/common/shared/Defs-versions.gmk
+++ b/jdk/make/common/shared/Defs-versions.gmk
@@ -44,6 +44,11 @@
   override CC_VERSION = gcc
 endif
 
+# Mac OS X uses LLVM by default
+ifeq ($(PLATFORM), macosx)
+  override CC_VERSION = llvm
+endif
+
 ##########################################################################
 #
 # List of JDK official minimum, expected, or required versions:
@@ -164,6 +169,17 @@
   endif
 endif
 
+# Mac specific
+ifeq ($(PLATFORM), macosx)
+  REQUIRED_OS_NAME            = Darwin
+  REQUIRED_OS_VERSION         = 11.2
+  REQUIRED_OS_VARIANT_NAME    = MacOSX
+  REQUIRED_OS_VARIANT_VERSION = 10.7.2
+  REQUIRED_COMPILER_NAME      = GCC4
+  REQUIRED_COMPILER_VERSION   = GCC4
+  REQUIRED_CC_VER             = 4.2.1
+endif
+
 # Windows specific
 ifeq ($(PLATFORM), windows)
   REQUIRED_OS_NAME            = Windows
diff --git a/jdk/make/common/shared/Defs.gmk b/jdk/make/common/shared/Defs.gmk
index 87a3ec3..2e514d2 100644
--- a/jdk/make/common/shared/Defs.gmk
+++ b/jdk/make/common/shared/Defs.gmk
@@ -177,6 +177,19 @@
   fi)
 endef
 
+# Expand SRCDIR_LIST, which is used to automatically include various
+# platform and shared sources/headers.  This is mainly useful for the
+# Mac OS X build, which pulls its platform sources from the solaris and/or
+# macosx trees, depending on the component.
+ifeq ($(PLATFORM), macosx)
+  define JavaSrcDirList
+  $(JAVA_SRCDIR_LIST:%=$1$(JDK_TOPDIR)/%/$2)
+  endef
+  define NativeSrcDirList
+  $(NATIVE_SRCDIR_LIST:%=$1$(JDK_TOPDIR)/%/$2)
+  endef
+endif
+
 # Make sure certain variables are non-empty at this point
 _check_values:=\
 $(call CheckValue,ARCH,),\
diff --git a/jdk/make/common/shared/Platform.gmk b/jdk/make/common/shared/Platform.gmk
index 97cbc6e..3fa0622 100644
--- a/jdk/make/common/shared/Platform.gmk
+++ b/jdk/make/common/shared/Platform.gmk
@@ -224,6 +224,80 @@
   MB_OF_MEMORY := $(shell free -m | fgrep Mem: | awk '{print $$2;}' )
 endif
 
+ifeq ($(SYSTEM_UNAME), Darwin)
+  PLATFORM = macosx
+  OS_NAME = darwin
+  OS_VENDOR = Apple
+  GB_OF_MEMORY := $(shell system_profiler SPHardwareDataType | fgrep Memory: | awk '{print $$2}')
+  MB_OF_MEMORY := $(shell expr ${GB_OF_MEMORY} '*' 1024)
+endif
+
+# Platform settings specific to BSD/Mac OS X
+ifeq ($(PLATFORM), macosx)
+  OS_VERSION := $(shell uname -r)
+
+  # Arch and OS name/version
+  # Darwin x86 builds are i386/amd64 universal by default.
+  # Allow arch to be set from the environment to avoid this.
+  ifeq ($(origin ARCH), undefined)
+   ifeq ($(PLATFORM), macosx)
+# MMM: revisit when hotspot producinging universal libs
+#   mach := universal
+    mach := x86_64
+   else
+    mach := $(shell uname -m)
+   endif
+  else
+   mach := $(ARCH)
+  endif
+
+  archExpr = case "$(mach)" in \
+                i[3-9]86) \
+                    echo i586 \
+                    ;; \
+                sparc64) \
+                    echo sparcv9 \
+                    ;; \
+                sparc*) \
+                    echo sparc \
+                    ;; \
+                x86_64) \
+                    echo amd64 \
+                    ;; \
+                "Power Macintosh") \
+                    echo ppc \
+                    ;; \
+                *) \
+                    echo $(mach) \
+                    ;; \
+      esac
+  ARCH        := $(shell $(archExpr) )
+  ARCH_FAMILY := $(ARCH)
+
+  # i586, sparc, and ppc are 32 bit, amd64 and sparc64 are 64
+  # ARCH_DATA_MODEL does not exactly mean anything in universal
+  # but it has to be one or the other, so pick 32
+  ifneq (,$(findstring $(ARCH), i586 sparc ppc universal))
+    ARCH_DATA_MODEL=32
+  else
+    ARCH_DATA_MODEL=64
+  endif
+
+  # Need to maintain the jre/lib/i386 location for 32-bit Intel
+  ifeq ($(ARCH), i586)
+    LIBARCH = i386
+  else
+    LIBARCH = $(ARCH)
+  endif
+
+  # Value of Java os.arch property
+  ARCHPROP  = $(LIBARCH)
+
+  # Suffix for file bundles used in previous release
+  BUNDLE_FILE_SUFFIX=.tar.gz
+  # How much RAM does this machine have:
+endif
+
 # Windows with and without CYGWIN will be slightly different
 ifeq ($(SYSTEM_UNAME), Windows_NT)
   PLATFORM = windows
@@ -425,6 +499,22 @@
   ARCH_VM_SUBDIR=jre/lib/$(LIBARCH)
 endif
 
+# Darwin-specific Overrides
+ifeq ($(SYSTEM_UNAME),Darwin)
+  # The suffix applied to runtime libraries
+  LIBRARY_SUFFIX = dylib
+  # The suffix applied to link libraries
+  ifeq ($(ARCH), universal)
+    LIB_SUFFIX = o
+  else
+    LIB_SUFFIX = a
+  endif
+
+  ifeq ($(PLATFORM), macosx)
+  	ARCH_VM_SUBDIR=jre/lib
+  endif
+endif
+
 # Machines with 512Mb or less of real memory are considered low memory
 #    build machines and adjustments will be made to prevent excessing
 #    system swapping during the build.
diff --git a/jdk/make/common/shared/Sanity.gmk b/jdk/make/common/shared/Sanity.gmk
index 1dbedb1..be74ebf 100644
--- a/jdk/make/common/shared/Sanity.gmk
+++ b/jdk/make/common/shared/Sanity.gmk
@@ -113,6 +113,13 @@
   ALSA_VERSION := $(call GetVersion,$(_ALSA_VERSION))
 endif
 
+ifeq ($(PLATFORM), macosx)
+  # What kind of system we are using
+  OS_VERSION := $(shell uname -r)
+  OS_VARIANT_NAME := MacOSX
+  OS_VARIANT_VERSION := $(shell sw_vers -productVersion)
+endif
+
 ifeq ($(PLATFORM), windows)
   # Windows 2000 is 5.0, Windows XP is 5.1, Windows 2003 is 5.2
   #    Assume 5.0 (Windows 2000) if systeminfo does not help
@@ -839,8 +846,10 @@
 
 ######################################################
 # Check for existence of DEVTOOLS_PATH
+# All needed tools come with base system on Apple
 ######################################################
 sane-devtools_path:
+ifneq ($(OS_VENDOR), Apple)
 	@if [ "$(DEVTOOLS_PATH)" != "" -a ! -r "$(DEVTOOLS_PATH)" ]; then \
 	  $(ECHO) "ERROR: You do not have a valid DEVTOOLS_PATH setting. \n" \
 	    "      Please check your access to \n" \
@@ -848,6 +857,7 @@
 	    "      and/or check your value of ALT_DEVTOOLS_PATH. \n" \
 	    "" >> $(ERROR_FILE) ; \
 	fi
+endif
 
 ######################################################
 # Check for existence of MS_RUNTIME_LIBRARIES
diff --git a/jdk/make/docs/Makefile b/jdk/make/docs/Makefile
index 9a5a1aa..a9e55b7 100644
--- a/jdk/make/docs/Makefile
+++ b/jdk/make/docs/Makefile
@@ -70,6 +70,8 @@
 #    WARNING: This could cause thrashing on low memory machines.
 ifeq ($(ARCH_DATA_MODEL),64)
   MAX_VM_MEMORY = 1024
+else ifeq ($(ARCH),universal)
+  MAX_VM_MEMORY = 1024
 else
   MAX_VM_MEMORY = 512
 endif
diff --git a/jdk/make/docs/NON_CORE_PKGS.gmk b/jdk/make/docs/NON_CORE_PKGS.gmk
index e8eda9d..83a7ae4 100644
--- a/jdk/make/docs/NON_CORE_PKGS.gmk
+++ b/jdk/make/docs/NON_CORE_PKGS.gmk
@@ -88,6 +88,13 @@
 
 SCTPAPI_PKGS     = com.sun.nio.sctp
 
+ifeq ($(PLATFORM), macosx)
+APPLE_EXT_PKGS   = com.apple.concurrent   \
+                   com.apple.eawt         \
+                   com.apple.eawt.event   \
+                   com.apple.eio
+endif
+
 # non-core packages in rt.jar
 NON_CORE_PKGS    = $(DOMAPI_PKGS) \
                    $(MGMT_PKGS) \
@@ -97,5 +104,6 @@
                    $(OLD_JSSE_PKGS) \
                    $(HTTPSERVER_PKGS) \
                    $(SMARTCARDIO_PKGS) \
-                   $(SCTPAPI_PKGS)
+                   $(SCTPAPI_PKGS) \
+                   $(APPLE_EXT_PKGS)
 
diff --git a/jdk/make/java/Makefile b/jdk/make/java/Makefile
index 3956cad..664861a 100644
--- a/jdk/make/java/Makefile
+++ b/jdk/make/java/Makefile
@@ -57,6 +57,10 @@
   SUBDIRS += jexec
 endif # PLATFORM
 
+ifeq ($(PLATFORM), macosx)
+  SUBDIRS += jobjc
+endif # PLATFORM
+
 include $(BUILDDIR)/common/Subdirs.gmk
 
 all build clean clobber::
diff --git a/jdk/make/java/instrument/Makefile b/jdk/make/java/instrument/Makefile
index 7a2fbf1..eecfc2e 100644
--- a/jdk/make/java/instrument/Makefile
+++ b/jdk/make/java/instrument/Makefile
@@ -102,6 +102,16 @@
   # equivalent of strcasecmp is stricmp on Windows
   CPPFLAGS_COMMON += -Dstrcasecmp=stricmp
 else
+ifneq (,$(findstring $(PLATFORM), macosx))
+  ifneq ($(ARCH), universal)
+    LDFLAGS += -Wl,-all_load
+  endif
+  LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
+  OTHER_LDLIBS += -liconv
+  ifeq ($(SYSTEM_ZLIB), true)
+    OTHER_LDLIBS += -lz
+  endif
+else
   LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
   OTHER_LDLIBS += -ljli
   OTHER_LDLIBS += -ldl 
@@ -114,6 +124,11 @@
     LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/jli
   endif
 endif
+endif
+
+ifeq ($(PLATFORM), macosx)
+  LDFLAGS += -framework Cocoa -framework Security -framework ApplicationServices
+endif
 
 #
 # Library to compile.
diff --git a/jdk/make/java/java/Makefile b/jdk/make/java/java/Makefile
index 1c87b51..377d8b2 100644
--- a/jdk/make/java/java/Makefile
+++ b/jdk/make/java/java/Makefile
@@ -94,6 +94,15 @@
 
 endif # PLATFORM
 
+ifeq ($(PLATFORM), macosx)
+FILES_c    +=   java_props_macosx.c
+FILES_java += 	java/util/prefs/MacOSXPreferences.java \
+		java/util/prefs/MacOSXPreferencesFile.java \
+		java/util/prefs/MacOSXPreferencesFactory.java
+
+CFLAGS_$(VARIANT)/java_props_md.o = -Os -x objective-c
+endif
+
 #
 # Make sure first rule does 'all'
 #
@@ -165,8 +174,10 @@
 # Is the altzone extern documented in ctime(3C) available?
 #
 ifneq ($(PLATFORM), windows)
+ifneq ($(PLATFORM), macosx)
 HAVE_ALTZONE=true
 endif
+endif
 
 ifeq ($(HAVE_ALTZONE),true)
 OTHER_CPPFLAGS += -DHAVE_ALTZONE
@@ -205,8 +216,14 @@
 		       -libpath:$(OBJDIR)/../../../verify/$(OBJDIRNAME) verify.lib \
 		       shell32.lib delayimp.lib /DELAYLOAD:shell32.dll
 else
-OTHER_LDLIBS += $(JVMLIB) -lverify $(LIBSOCKET) $(LIBNSL) $(LIBSCF) -ldl \
+OTHER_LDLIBS += $(JVMLIB) -lverify $(LIBSOCKET) $(LIBNSL) $(LIBSCF) $(LIBDL) \
 		-L$(OBJDIR)/../../../fdlibm/$(OBJDIRNAME) -lfdlibm.$(ARCH)
+ifeq ($(PLATFORM), macosx)
+OTHER_LDLIBS += \
+        -framework CoreFoundation \
+        -framework Security \
+        -framework SystemConfiguration
+endif
 endif
 
 #
@@ -243,8 +260,15 @@
 # UNIXProcess.java is different for solaris and linux. We need to copy
 # the correct UNIXProcess.java over to $(GENSRCDIR)/java/lang/.
 
-$(GENSRCDIR)/java/lang/UNIXProcess.java: \
+ifeq ($(PLATFORM), macosx)
+PLATFORM_UNIX_PROCESS = \
+    $(PLATFORM_SRC)/classes/java/lang/UNIXProcess.java.bsd
+else
+PLATFORM_UNIX_PROCESS = \
     $(PLATFORM_SRC)/classes/java/lang/UNIXProcess.java.$(PLATFORM)
+endif
+
+$(GENSRCDIR)/java/lang/UNIXProcess.java: $(PLATFORM_UNIX_PROCESS)
 	$(install-file)
 
 clean:: 
diff --git a/jdk/make/java/java/genlocales.gmk b/jdk/make/java/java/genlocales.gmk
index b08239c..41cf00f 100644
--- a/jdk/make/java/java/genlocales.gmk
+++ b/jdk/make/java/java/genlocales.gmk
@@ -73,6 +73,26 @@
 LOCALEGEN_SH=localegen.sh
 RESOURCE_NAMES="FormatData CollationData TimeZoneNames LocaleNames CurrencyNames CalendarData"
 
+
+# On MacOSX sed does not enter a newline as it does on other platforms with the same pattern
+# Using awk instead
+
+ifeq ($(PLATFORM), macosx)
+
+$(LocaleDataMetaInfo_Dest):$(LocaleDataMetaInfo_Src) $(LOCALEGEN_SH)
+	@$(RM) $@.tmp.euro $@.tmp.noneuro;
+	@$(prep-target) 
+	@$(ECHO) $(Euro_Resources_properties) | $(NAWK) 'gsub(/.properties/,"\n") {print}'  > $@.tmp.euro;
+	@$(ECHO) $(Euro_Resources_java) | $(NAWK) 'gsub(/.java/,"\n") {print}' >> $@.tmp.euro;
+	@$(ECHO) $(NonEuro_Resources_properties) | $(NAWK) 'gsub(/.properties/,"\n") {print}' > $@.tmp.noneuro;
+	@$(ECHO) $(NonEuro_Resources_java) | $(NAWK) 'gsub(/.java/,"\n") {print}' >> $@.tmp.noneuro;
+	NAWK="$(NAWK)" SED="$(SED)" SORT="$(SORT)" \
+	     $(SH) $(LOCALEGEN_SH) $(RESOURCE_NAMES) $@.tmp.euro \
+		$@.tmp.noneuro $< $@
+	@$(RM) $@.tmp.euro $@.tmp.noneuro;
+
+else
+
 $(LocaleDataMetaInfo_Dest):$(LocaleDataMetaInfo_Src) $(LOCALEGEN_SH)
 	@$(RM) $@.tmp.euro $@.tmp.noneuro;
 	@$(prep-target) 
@@ -84,6 +104,7 @@
 	     $(SH) $(LOCALEGEN_SH) $(RESOURCE_NAMES) $@.tmp.euro \
 		$@.tmp.noneuro $< $@
 	@$(RM) $@.tmp.euro $@.tmp.noneuro;
+endif
 	
 genlocales : $(LocaleDataMetaInfo_Dest)  
 
diff --git a/jdk/make/java/java/localegen.sh b/jdk/make/java/java/localegen.sh
index 2ce98c9..c547145 100644
--- a/jdk/make/java/java/localegen.sh
+++ b/jdk/make/java/java/localegen.sh
@@ -52,12 +52,13 @@
 
 sed_script="$SED -e \"s@^#warn .*@// -- This file was mechanically generated: Do not edit! -- //@\" " 
 
+# MMM: check two sed script changes below work other platforms than mac
 for FILE in $RESOURCE_NAMES 
 do
     getlocalelist $FILE $EURO_FILES_LIST
-    sed_script=$sed_script"-e \"s/#"$FILE"_EuroLocales#/$localelist/g\" "
+    sed_script=$sed_script"-e \"s@#"$FILE"_EuroLocales#@$localelist@g\" "
     getlocalelist $FILE $NONEURO_FILES_LIST
-    sed_script=$sed_script"-e \"s/#"$FILE"_NonEuroLocales#/$localelist/g\" "
+    sed_script=$sed_script"-e \"s@#"$FILE"_NonEuroLocales#@$localelist@g\" "
 done
 
 sed_script=$sed_script"$INPUT_FILE > $OUTPUT_FILE"
diff --git a/jdk/make/java/java_hprof_demo/Makefile b/jdk/make/java/java_hprof_demo/Makefile
index 9449d2d..9880547 100644
--- a/jdk/make/java/java_hprof_demo/Makefile
+++ b/jdk/make/java/java_hprof_demo/Makefile
@@ -83,7 +83,7 @@
 ifeq ($(PLATFORM), windows)
   OTHER_LDLIBS += wsock32.lib winmm.lib
 else
-  OTHER_LDLIBS += $(LIBSOCKET) $(LIBNSL) -ldl
+  OTHER_LDLIBS += $(LIBSOCKET) $(LIBNSL) $(LIBDL)
 endif
 
 #
diff --git a/jdk/make/java/jli/Makefile b/jdk/make/java/jli/Makefile
index f342f62..0b48c3f 100644
--- a/jdk/make/java/jli/Makefile
+++ b/jdk/make/java/jli/Makefile
@@ -44,14 +44,16 @@
 
 include $(BUILDDIR)/common/Defs.gmk
 
+ifneq ($(SYSTEM_ZLIB),true)
 ZIP_SRC = $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+endif
 LAUNCHER_SHARE_SRC = $(SHARE_SRC)/bin
 LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)/bin
 
 ifeq ($(ZERO_BUILD), true)
 ERGO_FAMILY=zero
 else
-ifeq ($(ARCH_FAMILY), amd64)
+ifneq (,$(findstring $(ARCH_FAMILY), amd64 x86_64))
 ERGO_FAMILY=i586
 else
 ERGO_FAMILY=$(ARCH_FAMILY)
@@ -69,13 +71,17 @@
 	parse_manifest.c \
 	version_comp.c \
 	wildcard.c \
-	jli_util.c \
+	jli_util.c
+
+ifneq ($(SYSTEM_ZLIB),true)
+FILES_c += \
 	inflate.c \
 	inftrees.c \
 	inffast.c \
 	zadler32.c \
 	zcrc32.c \
 	zutil.c
+endif
 
 ifneq ($(PLATFORM), windows)
   FILES_c += ergo.c 
@@ -96,10 +102,15 @@
   LIBARCH_DEFINES += -DLIBARCH64NAME='"$(LIBARCH64)"'
 endif
 
-OTHER_CPPFLAGS += $(LIBARCH_DEFINES)
+ifeq ($(PLATFORM), macosx)
+  OTHER_CPPFLAGS += $(LIBARCH_DEFINES) -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
+else
+  OTHER_CPPFLAGS += $(LIBARCH_DEFINES)
+endif
 
 
 ifneq ($(PLATFORM), windows)	# UNIX systems
+ifneq ($(PLATFORM), macosx)
         LD_RUNPATH_EXTRAS += ..
 	LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/jli
 	# Note: its important to keep this order meaning -lc is the
@@ -110,6 +121,11 @@
 	LDLIBS += -lpthread
 endif # USE_PTHREADS 
 endif # PLATFORM
+endif # PLATFORM
+
+ifeq ($(PLATFORM), macosx)
+	LIB_LOCATION = $(LIBDIR)/jli
+endif
 
 ifeq ($(PLATFORM), windows)
 	EXTRA_LIBS = advapi32.lib \
@@ -129,7 +145,11 @@
 
 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)
 OTHER_INCLUDES += -I$(LAUNCHER_PLATFORM_SRC)
-OTHER_INCLUDES += -I$(ZIP_SRC)
+ifneq ($(SYSTEM_ZLIB),true)
+  OTHER_INCLUDES += -I$(ZIP_SRC)
+else
+  LDLIBS += -lz
+endif
 
 #
 # Library to compile.
@@ -161,7 +181,33 @@
 
 endif	# PLATFORM
 
+ifeq ($(PLATFORM), macosx)
+# Some Obj-C code is embedded in java_md.c, so need to inform compiler
+CFLAGS_$(VARIANT)/java_md.o = -Os -x objective-c
+# Needed for linking the various launchers
+LDFLAGS += -framework Cocoa -framework Security -framework ApplicationServices
+endif
+
+STATIC_LIBRARY_DIR = $(OBJDIR)/static
+STATIC_LIBRARY_NAME = lib$(LIBRARY).a
+STATIC_LIBRARY = $(STATIC_LIBRARY_DIR)/$(STATIC_LIBRARY_NAME)
+
+$(STATIC_LIBRARY_DIR): | $(OBJDIR)
+	@$(MKDIR) $(STATIC_LIBRARY_DIR)
+
+$(STATIC_LIBRARY): $(STATIC_LIBRARY_DIR)
+	@$(prep-target)
+	$(AR) $(ARFLAGS) $@ $(FILES_o)
+
+library:: $(STATIC_LIBRARY)
+
+vpath %.c $(LAUNCHER_SHARE_SRC) $(LAUNCHER_PLATFORM_SRC)
+ifneq ($(SYSTEM_ZLIB),true)
+  vpath %.c $(ZIP_SRC)
+
+else 
 #
 # Add to ambient vpath so we pick up the library files
 #
 vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC) $(LAUNCHER_PLATFORM_SRC)
+endif
diff --git a/jdk/make/java/jli/mapfile-vers b/jdk/make/java/jli/mapfile-vers
index 786e528..5ff5edb 100644
--- a/jdk/make/java/jli/mapfile-vers
+++ b/jdk/make/java/jli/mapfile-vers
@@ -25,6 +25,7 @@
 
 # Define public interface.
 
+# MMM: Three JNI funcs added for Mac. Check this out!
 SUNWprivate_1.1 {
 	global:
 		JLI_Launch;
@@ -34,6 +35,9 @@
 		JLI_ReportErrorMessageSys;
 		JLI_ReportMessage;
 		JLI_ReportExceptionDescription;
+#		JNI_CreateJavaVM;
+#		JNI_GetCreatedJavaVMs;
+#		JNI_GetDefaultJavaVMInitArgs;
 	local:
 		*;
 };
diff --git a/jdk/make/java/jobjc/Makefile b/jdk/make/java/jobjc/Makefile
new file mode 100644
index 0000000..5eb6d04
--- /dev/null
+++ b/jdk/make/java/jobjc/Makefile
@@ -0,0 +1,73 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# Makefile for building jobjc
+
+BUILDDIR = ../..
+include $(BUILDDIR)/common/Defs.gmk
+SRCDIR = $(JDK_TOPDIR)/src/macosx/native/jobjc
+
+ifeq ($(PLATFORM),macosx)
+
+# FRAMEWORKS for which we want to build bridge support
+FRAMEWORKS = Foundation CoreFoundation AppKit
+
+# metadata stuff
+GEN_DIR = $(OUTPUTDIR)/bridge_metadata
+STABLE_GEN_DIR = $(OUTPUTDIR)/stable_bridge_metadata
+STABLE_METADATA_FILES = $(addsuffix Full.bridgesupport,$(addprefix $(STABLE_GEN_DIR)/,$(FRAMEWORKS)))
+
+# source files
+CORE_SRC = $(shell $(FIND) $(SRCDIR) -type f -name "*.hs" -or -name "*.java" -or -name "*.m" -or -name "*.h" -print)
+GENERATOR_SRC = $(shell $(FIND) $(SRCDIR) -type f -name "*.java" -print)
+ADDITIONS_SRC = $(shell $(FIND) $(SRCDIR) -type f -name "*.java" -or -name "*.m" -or -name "*.h" -print)
+BUILD_SRC = $(SRCDIR)/JObjC.xcodeproj/project.pbxproj $(SRCDIR)/bridgesupport.gmk $(SRCDIR)/build.xml $(SRCDIR)/extract_classes.pl $(SRCDIR)/run-and-write-if-okay $(SRCDIR)/rungen $(SRCDIR)/runjava
+
+# jobjc products for jdk
+BUILT_DYLIB = $(OUTPUTDIR)/JObjC.dst/Debug/libJObjC.dylib
+BUILT_JAR = $(OUTPUTDIR)/JObjC.build/JObjC.jar
+
+$(GEN_DIR):
+	mkdir -p $(GEN_DIR)
+
+stabilize: $(GEN_DIR)
+	@echo Updating bridge support in $(GEN_DIR)
+	($(CD) $(GEN_DIR); $(MAKE) STABLE_GEN_DIR="$(STABLE_GEN_DIR)" FRAMEWORKS="$(FRAMEWORKS)" -f $(SRCDIR)/bridgesupport.gmk all)
+
+$(STABLE_METADATA_FILES): stabilize
+
+$(BUILT_DYLIB) $(BUILT_JAR): $(STABLE_METADATA_FILES) $(CORE_SRC) $(GENERATOR_SRC) $(ADDITIONS_SRC) $(BUILD_SRC)
+	@echo JObjC dylib or jar out of data wrt FRAMEWORKS '(' $(FRAMEWORKS) ')' or JObjC source '(' core, generator, additions, build ')'
+	@echo Running ant with java_home set to ${ALT_BOOTDIR}
+	(cd $(SRCDIR); OBJROOT="$(OUTPUTDIR)/JObjC.build" DSTROOT="$(OUTPUTDIR)/JObjC.dst" JAVA_HOME=${ALT_BOOTDIR} STABLE_GEN_DIR="$(STABLE_GEN_DIR)" /usr/bin/ant -verbose all)
+
+all: $(BUILD_DYLIB) $(BUILT_JAR)
+	$(CP) $(BUILT_DYLIB) $(LIB_LOCATION)/libJObjC.dylib
+
+clean clobber::
+	(cd $(SRCDIR); export OBJROOT=$(OUTPUTDIR)/JObjC.build; export DSTROOT=$(OUTPUTDIR)/JObjC.dst; /usr/bin/ant clean)
+
+endif
diff --git a/jdk/make/java/jvm/Makefile b/jdk/make/java/jvm/Makefile
index 9f847d3..bdde552 100644
--- a/jdk/make/java/jvm/Makefile
+++ b/jdk/make/java/jvm/Makefile
@@ -43,7 +43,12 @@
 $(PLATFORM_INCLUDE)/%.h: $(PLATFORM_SRC)/javavm/export/%.h
 	$(install-file)
 
-JVMCFG_DIR = $(LIBDIR)/$(LIBARCH)
+ifeq ($(PLATFORM),macosx)
+  JVMCFG_DIR = $(LIBDIR)
+else
+  JVMCFG_DIR = $(LIBDIR)/$(LIBARCH)
+endif
+
 JVMCFG = $(JVMCFG_DIR)/jvm.cfg
 
 #
diff --git a/jdk/make/java/management/Makefile b/jdk/make/java/management/Makefile
index 6f81ae7..bffb5ed 100644
--- a/jdk/make/java/management/Makefile
+++ b/jdk/make/java/management/Makefile
@@ -77,6 +77,12 @@
 
 endif # PLATFORM linux
 
+ifeq ($(PLATFORM),macosx)
+
+FILES_c     += MacosxOperatingSystem.c
+
+endif # PLATFORM macosx
+
 endif # PLATFORM
 
 #
diff --git a/jdk/make/java/net/FILES_c.gmk b/jdk/make/java/net/FILES_c.gmk
index 4b7d005..a4bbb40 100644
--- a/jdk/make/java/net/FILES_c.gmk
+++ b/jdk/make/java/net/FILES_c.gmk
@@ -43,6 +43,10 @@
     FILES_c += linux_close.c
 endif
 
+ifeq ($(PLATFORM), macosx)
+    FILES_c += bsd_close.c
+endif
+
 ifeq ($(PLATFORM), windows)
     FILES_c += TwoStacksPlainSocketImpl.c
     FILES_c += DualStackPlainSocketImpl.c
diff --git a/jdk/make/java/net/Makefile b/jdk/make/java/net/Makefile
index e6429c6..24e55c9 100644
--- a/jdk/make/java/net/Makefile
+++ b/jdk/make/java/net/Makefile
@@ -91,16 +91,23 @@
 
 include $(BUILDDIR)/common/Library.gmk
 
+ifeq ($(PLATFORM), macosx)
+ifdef DONT_ENABLE_IPV6
+  OTHER_CFLAGS += -DDONT_ENABLE_IPV6
+endif
+  OTHER_LDLIBS = $(JVMLIB) -pthread
+else
 ifeq ($(PLATFORM), windows)
   OTHER_LDLIBS = ws2_32.lib $(JVMLIB) \
                  secur32.lib iphlpapi.lib delayimp.lib \
                  /DELAYLOAD:secur32.dll /DELAYLOAD:iphlpapi.dll
 else
-  OTHER_LDLIBS = $(LIBSOCKET) $(LIBNSL) -ldl $(JVMLIB)
+  OTHER_LDLIBS = $(LIBSOCKET) $(LIBNSL) $(LIBDL) $(JVMLIB)
 endif
 ifeq ($(PLATFORM), linux)
   OTHER_LDLIBS += -lpthread
 endif
+endif # PLATFORM
 
 CLASSES.export += java.lang.Integer java.io.FileDescriptor java.net.InetAddressImplFactory java.net.Inet4AddressImpl java.net.Inet6AddressImpl
 
diff --git a/jdk/make/java/nio/Makefile b/jdk/make/java/nio/Makefile
index cedc64b..89f627e 100644
--- a/jdk/make/java/nio/Makefile
+++ b/jdk/make/java/nio/Makefile
@@ -260,6 +260,83 @@
 	sun/nio/fs/UnixConstants.java
 endif # PLATFORM = linux
 
+ifeq ($(PLATFORM), macosx)
+FILES_java += \
+        sun/nio/ch/AbstractPollSelectorImpl.java \
+	sun/nio/ch/InheritedChannel.java \
+        sun/nio/ch/PollSelectorProvider.java \
+        sun/nio/ch/PollSelectorImpl.java \
+	sun/nio/ch/Port.java \
+	sun/nio/ch/SimpleAsynchronousFileChannelImpl.java \
+	sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \
+	sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \
+	\
+	sun/nio/fs/GnomeFileTypeDetector.java \
+	sun/nio/fs/BsdFileStore.java \
+	sun/nio/fs/BsdFileSystem.java \
+	sun/nio/fs/BsdFileSystemProvider.java \
+	sun/nio/fs/BsdNativeDispatcher.java \
+	sun/nio/fs/PollingWatchService.java \
+	sun/nio/fs/UnixChannelFactory.java \
+	sun/nio/fs/UnixCopyFile.java \
+	sun/nio/fs/UnixDirectoryStream.java \
+	sun/nio/fs/UnixException.java \
+	sun/nio/fs/UnixFileAttributeViews.java \
+	sun/nio/fs/UnixFileAttributes.java \
+	sun/nio/fs/UnixFileKey.java \
+	sun/nio/fs/UnixFileModeAttribute.java \
+	sun/nio/fs/UnixFileStore.java \
+	sun/nio/fs/UnixFileStoreAttributes.java \
+	sun/nio/fs/UnixFileSystem.java \
+	sun/nio/fs/UnixFileSystemProvider.java \
+	sun/nio/fs/UnixMountEntry.java \
+	sun/nio/fs/UnixNativeDispatcher.java \
+	sun/nio/fs/UnixPath.java \
+	sun/nio/fs/UnixSecureDirectoryStream.java \
+	sun/nio/fs/UnixUriUtils.java \
+	sun/nio/fs/UnixUserPrincipals.java
+
+FILES_c += \
+	InheritedChannel.c \
+	NativeThread.c \
+        PollArrayWrapper.c \
+	UnixAsynchronousServerSocketChannelImpl.c \
+	UnixAsynchronousSocketChannelImpl.c \
+	\
+	GnomeFileTypeDetector.c \
+	BsdNativeDispatcher.c \
+	UnixCopyFile.c \
+	UnixNativeDispatcher.c
+
+FILES_export += \
+	sun/nio/ch/InheritedChannel.java \
+	sun/nio/ch/NativeThread.java \
+	sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \
+	sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \
+	\
+	sun/nio/fs/GnomeFileTypeDetector.java \
+	sun/nio/fs/BsdNativeDispatcher.java \
+	sun/nio/fs/UnixCopyFile.java \
+	sun/nio/fs/UnixNativeDispatcher.java
+	
+FILES_gen += \
+	sun/nio/fs/UnixConstants.java
+endif # PLATFORM = bsd, macosx
+
+ifeq ($(PLATFORM), macosx)
+FILES_java += \
+    sun/nio/ch/KQueueSelectorProvider.java \
+    sun/nio/ch/KQueueSelectorImpl.java \
+    sun/nio/ch/KQueueArrayWrapper.java
+
+FILES_c += \
+    KQueueArrayWrapper.c
+
+vpath %.c $(call NativeSrcDirList,,native/sun/nio/fs)
+vpath %.c $(call NativeSrcDirList,,native/sun/nio/ch)
+
+else
+
 #
 # Find platform-specific C source files
 #
@@ -267,6 +344,8 @@
 vpath %.c $(PLATFORM_SRC)/native/sun/nio/ch
 vpath %.c $(SHARE_SRC)/native/sun/nio/ch
 
+endif # PLATFORM = macosx
+
 #
 # Various variables
 #
@@ -292,10 +371,13 @@
      $(OBJDIR)/../../../java.lang/java/$(OBJDIRNAME)/FileDescriptor_md.obj
 endif
 ifeq ($(PLATFORM), linux)
-OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -lpthread -ldl
+OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -lpthread $(LIBDL)
+endif
+ifeq ($(PLATFORM), macosx)
+OTHER_LDLIBS += -L$(LIBDIR) -ljava -lnet -pthread
 endif
 ifeq ($(PLATFORM), solaris)
-OTHER_LDLIBS += $(JVMLIB) $(LIBSOCKET) -lposix4 -ldl -lsendfile \
+OTHER_LDLIBS += $(JVMLIB) $(LIBSOCKET) -lposix4 $(LIBDL) -lsendfile \
 		-L$(LIBDIR)/$(LIBARCH) -ljava -lnet
 endif # PLATFORM
 
@@ -316,6 +398,9 @@
 ifeq ($(PLATFORM), linux)
 FILES_m = mapfile-linux
 endif
+ifeq ($(PLATFORM), macosx)
+FILES_m = mapfile-bsd
+endif
 include $(BUILDDIR)/common/Mapfile-vers.gmk
 include $(BUILDDIR)/common/Library.gmk
 
@@ -818,9 +903,15 @@
 $(TEMPDIR)/$(GENSOR_SRC) : $(GENSOR_SRC)
 	$(install-file)
 
+ifeq ($(PLATFORM), macosx)
+  NIO_CC=$(HOST_CC)
+else
+  NIO_CC=$(CC)
+endif
+
 $(GENSOR_EXE) : $(TEMPDIR)/$(GENSOR_SRC)
 	$(prep-target)
-	($(CD) $(TEMPDIR); $(CC) $(CPPFLAGS) $(LDDFLAGS) \
+	($(CD) $(TEMPDIR); $(NIO_CC) $(CPPFLAGS) $(LDDFLAGS) \
 	   -o genSocketOptionRegistry$(EXE_SUFFIX) $(GENSOR_SRC))
 
 ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
@@ -856,7 +947,7 @@
 
 $(GENUC_EXE) : $(GENUC_SRC)
 	$(prep-target)
-	$(CC) $(CPPFLAGS) -o $@ $(GENUC_SRC)
+	$(NIO_CC) $(CPPFLAGS) -o $@ $(GENUC_SRC)
 
 ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
 $(SFS_GEN)/UnixConstants.java: $(NIO_PLATFORM_CLASSES_ROOT_DIR)/sun/nio/fs/UnixConstants-$(PLATFORM)-$(ARCH).java
@@ -878,7 +969,7 @@
 
 $(GENSC_EXE) : $(GENSC_SRC)
 	$(prep-target)
-	$(CC) $(CPPFLAGS) -o $@ $(GENSC_SRC)
+	$(NIO_CC) $(CPPFLAGS) -o $@ $(GENSC_SRC)
 
 ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
 $(SFS_GEN)/SolarisConstants.java: $(NIO_PLATFORM_CLASSES_ROOT_DIR)/sun/nio/fs/SolarisConstants-$(PLATFORM)-$(ARCH).java
diff --git a/jdk/make/java/nio/mapfile-bsd b/jdk/make/java/nio/mapfile-bsd
new file mode 100644
index 0000000..48bf3b9
--- /dev/null
+++ b/jdk/make/java/nio/mapfile-bsd
@@ -0,0 +1,168 @@
+#
+# Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+SUNWprivate_1.1 {
+	global:
+                Java_java_nio_MappedByteBuffer_force0;
+                Java_java_nio_MappedByteBuffer_isLoaded0;
+                Java_java_nio_MappedByteBuffer_load0;
+                Java_sun_nio_ch_DatagramChannelImpl_disconnect0;
+                Java_sun_nio_ch_DatagramChannelImpl_initIDs;
+                Java_sun_nio_ch_DatagramChannelImpl_receive0;
+                Java_sun_nio_ch_DatagramChannelImpl_send0;
+                Java_sun_nio_ch_DatagramDispatcher_read0;
+                Java_sun_nio_ch_DatagramDispatcher_readv0;
+                Java_sun_nio_ch_DatagramDispatcher_write0;
+                Java_sun_nio_ch_DatagramDispatcher_writev0;
+                Java_sun_nio_ch_FileChannelImpl_close0;
+                Java_sun_nio_ch_FileChannelImpl_initIDs;
+                Java_sun_nio_ch_FileChannelImpl_map0;
+                Java_sun_nio_ch_FileChannelImpl_position0;
+                Java_sun_nio_ch_FileChannelImpl_transferTo0;
+                Java_sun_nio_ch_FileChannelImpl_unmap0;
+                Java_sun_nio_ch_FileDispatcherImpl_close0;
+                Java_sun_nio_ch_FileDispatcherImpl_closeIntFD;
+		Java_sun_nio_ch_FileDispatcherImpl_force0;
+                Java_sun_nio_ch_FileDispatcherImpl_init;
+		Java_sun_nio_ch_FileDispatcherImpl_lock0;
+                Java_sun_nio_ch_FileDispatcherImpl_preClose0;
+                Java_sun_nio_ch_FileDispatcherImpl_pread0;
+                Java_sun_nio_ch_FileDispatcherImpl_pwrite0;
+                Java_sun_nio_ch_FileDispatcherImpl_read0;
+                Java_sun_nio_ch_FileDispatcherImpl_readv0;
+		Java_sun_nio_ch_FileDispatcherImpl_release0;
+		Java_sun_nio_ch_FileDispatcherImpl_size0;
+		Java_sun_nio_ch_FileDispatcherImpl_truncate0;
+                Java_sun_nio_ch_FileDispatcherImpl_write0;
+                Java_sun_nio_ch_FileDispatcherImpl_writev0;
+                Java_sun_nio_ch_FileKey_init;
+                Java_sun_nio_ch_FileKey_initIDs;
+		Java_sun_nio_ch_InheritedChannel_close0;
+		Java_sun_nio_ch_InheritedChannel_dup;
+		Java_sun_nio_ch_InheritedChannel_dup2;
+		Java_sun_nio_ch_InheritedChannel_open0;
+		Java_sun_nio_ch_InheritedChannel_peerAddress0;
+		Java_sun_nio_ch_InheritedChannel_peerPort0;
+		Java_sun_nio_ch_InheritedChannel_soType0;
+                Java_sun_nio_ch_IOUtil_configureBlocking;
+                Java_sun_nio_ch_IOUtil_drain;
+                Java_sun_nio_ch_IOUtil_fdVal;
+                Java_sun_nio_ch_IOUtil_initIDs;
+                Java_sun_nio_ch_IOUtil_makePipe;
+                Java_sun_nio_ch_IOUtil_randomBytes;
+                Java_sun_nio_ch_IOUtil_setfdVal;
+		Java_sun_nio_ch_NativeThread_current;
+		Java_sun_nio_ch_NativeThread_init;
+		Java_sun_nio_ch_NativeThread_signal;
+		Java_sun_nio_ch_Net_canIPv6SocketJoinIPv4Group0;
+		Java_sun_nio_ch_Net_canJoin6WithIPv4Group0;
+		Java_sun_nio_ch_Net_socket0;
+		Java_sun_nio_ch_Net_bind0;
+		Java_sun_nio_ch_Net_connect0;
+		Java_sun_nio_ch_Net_listen;
+		Java_sun_nio_ch_Net_localPort;
+		Java_sun_nio_ch_Net_localInetAddress;
+		Java_sun_nio_ch_Net_getIntOption0;
+		Java_sun_nio_ch_Net_setIntOption0;
+                Java_sun_nio_ch_Net_initIDs;
+		Java_sun_nio_ch_Net_isIPv6Available0;
+		Java_sun_nio_ch_Net_joinOrDrop4;
+		Java_sun_nio_ch_Net_blockOrUnblock4;
+		Java_sun_nio_ch_Net_joinOrDrop6;
+		Java_sun_nio_ch_Net_blockOrUnblock6;
+		Java_sun_nio_ch_Net_setInterface4;
+		Java_sun_nio_ch_Net_getInterface4;
+		Java_sun_nio_ch_Net_setInterface6;
+		Java_sun_nio_ch_Net_getInterface6;
+		Java_sun_nio_ch_Net_shutdown;
+                Java_sun_nio_ch_PollArrayWrapper_interrupt;
+                Java_sun_nio_ch_PollArrayWrapper_poll0;
+                Java_sun_nio_ch_ServerSocketChannelImpl_accept0;
+                Java_sun_nio_ch_ServerSocketChannelImpl_initIDs;
+                Java_sun_nio_ch_SocketChannelImpl_checkConnect;
+		Java_sun_nio_ch_SocketChannelImpl_sendOutOfBandData;
+		Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0;
+		Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs;
+		Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect;
+		Java_sun_nio_fs_BsdNativeDispatcher_initIDs;
+		Java_sun_nio_fs_BsdNativeDispatcher_getfsstat;
+		Java_sun_nio_fs_BsdNativeDispatcher_fsstatEntry;
+		Java_sun_nio_fs_BsdNativeDispatcher_endfsstat;
+		Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio;
+		Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio;
+		Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs;
+		Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs;
+		Java_sun_nio_fs_UnixNativeDispatcher_init;
+		Java_sun_nio_fs_UnixNativeDispatcher_getcwd;
+		Java_sun_nio_fs_UnixNativeDispatcher_strerror;
+		Java_sun_nio_fs_UnixNativeDispatcher_dup;
+		Java_sun_nio_fs_UnixNativeDispatcher_access0;
+		Java_sun_nio_fs_UnixNativeDispatcher_stat0;
+		Java_sun_nio_fs_UnixNativeDispatcher_lstat0;
+		Java_sun_nio_fs_UnixNativeDispatcher_fstat;
+		Java_sun_nio_fs_UnixNativeDispatcher_fstatat0;
+		Java_sun_nio_fs_UnixNativeDispatcher_chmod0;
+		Java_sun_nio_fs_UnixNativeDispatcher_fchmod;
+		Java_sun_nio_fs_UnixNativeDispatcher_chown0;
+		Java_sun_nio_fs_UnixNativeDispatcher_lchown0;
+		Java_sun_nio_fs_UnixNativeDispatcher_fchown;
+		Java_sun_nio_fs_UnixNativeDispatcher_utimes0;
+		Java_sun_nio_fs_UnixNativeDispatcher_futimes;
+		Java_sun_nio_fs_UnixNativeDispatcher_open0;
+		Java_sun_nio_fs_UnixNativeDispatcher_openat0;
+		Java_sun_nio_fs_UnixNativeDispatcher_close;
+		Java_sun_nio_fs_UnixNativeDispatcher_read;
+		Java_sun_nio_fs_UnixNativeDispatcher_write;
+		Java_sun_nio_fs_UnixNativeDispatcher_fopen0;
+		Java_sun_nio_fs_UnixNativeDispatcher_fclose;
+		Java_sun_nio_fs_UnixNativeDispatcher_opendir0;
+		Java_sun_nio_fs_UnixNativeDispatcher_fdopendir;
+		Java_sun_nio_fs_UnixNativeDispatcher_readdir;
+		Java_sun_nio_fs_UnixNativeDispatcher_closedir;
+		Java_sun_nio_fs_UnixNativeDispatcher_link0;
+		Java_sun_nio_fs_UnixNativeDispatcher_unlink0;
+		Java_sun_nio_fs_UnixNativeDispatcher_unlinkat0;
+		Java_sun_nio_fs_UnixNativeDispatcher_rename0;
+		Java_sun_nio_fs_UnixNativeDispatcher_renameat0;
+		Java_sun_nio_fs_UnixNativeDispatcher_mkdir0;
+		Java_sun_nio_fs_UnixNativeDispatcher_rmdir0;
+		Java_sun_nio_fs_UnixNativeDispatcher_symlink0;
+		Java_sun_nio_fs_UnixNativeDispatcher_readlink0;
+		Java_sun_nio_fs_UnixNativeDispatcher_realpath0;
+		Java_sun_nio_fs_UnixNativeDispatcher_statvfs0;
+		Java_sun_nio_fs_UnixNativeDispatcher_pathconf0;
+		Java_sun_nio_fs_UnixNativeDispatcher_fpathconf;
+		Java_sun_nio_fs_UnixNativeDispatcher_mknod0;
+		Java_sun_nio_fs_UnixNativeDispatcher_getpwuid;
+		Java_sun_nio_fs_UnixNativeDispatcher_getgrgid;
+		Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
+		Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
+		Java_sun_nio_fs_UnixNativeDispatcher_getextmntent;
+		Java_sun_nio_fs_UnixCopyFile_transfer;
+		handleSocketError;
+
+	local:
+		*;
+};
diff --git a/jdk/make/java/npt/Makefile b/jdk/make/java/npt/Makefile
index 587f299..b037972 100644
--- a/jdk/make/java/npt/Makefile
+++ b/jdk/make/java/npt/Makefile
@@ -67,6 +67,11 @@
   OTHER_LCF += -export:nptInitialize -export:nptTerminate
 endif
 
+# Add location of iconv header
+ifeq ($(PLATFORM), macosx))
+  OTHER_LDLIBS += -liconv
+endif
+
 #
 # Add to ambient vpath so we pick up the library files
 #
diff --git a/jdk/make/java/redist/Makefile b/jdk/make/java/redist/Makefile
index a0c4a67..d265ea3 100644
--- a/jdk/make/java/redist/Makefile
+++ b/jdk/make/java/redist/Makefile
@@ -46,6 +46,8 @@
 
 ifeq ($(PLATFORM), windows)
   LIB_LOCATION = $(BINDIR)
+else ifeq ($(PLATFORM), macosx)
+  LIB_LOCATION = $(LIBDIR)
 else
   LIB_LOCATION = $(LIBDIR)/$(LIBARCH)
 endif
diff --git a/jdk/make/java/redist/sajdi/Makefile b/jdk/make/java/redist/sajdi/Makefile
index 1eaa9a0..1e1e818 100644
--- a/jdk/make/java/redist/sajdi/Makefile
+++ b/jdk/make/java/redist/sajdi/Makefile
@@ -29,6 +29,8 @@
 
 ifeq ($(PLATFORM), windows)
   LIB_LOCATION = $(BINDIR)
+else ifeq ($(PLATFORM), macosx)
+  LIB_LOCATION = $(LIBDIR)
 else
   LIB_LOCATION = $(LIBDIR)/$(LIBARCH)
 endif
diff --git a/jdk/make/java/security/Makefile b/jdk/make/java/security/Makefile
index d06fc91..4cbc60f 100644
--- a/jdk/make/java/security/Makefile
+++ b/jdk/make/java/security/Makefile
@@ -42,13 +42,20 @@
 ifeq ($(PLATFORM), solaris)
 PROPS_SRC   = $(TOPDIR)/src/share/lib/security/java.security-solaris
 
-else # PLATFORM
+else # NOT_SOLARIS
 
 # Register Microsoft CryptoAPI provider only on Windows platform.
 ifeq ($(PLATFORM), windows)
   PROPS_SRC   = $(TOPDIR)/src/share/lib/security/java.security-windows
-endif
-endif # PLATFORM
+
+else # NOT_WINDOWS
+
+ifeq ($(PLATFORM), macosx)
+  PROPS_SRC   = $(TOPDIR)/src/share/lib/security/java.security-macosx
+endif # MACOSX
+
+endif # NOT_WINDOWS
+endif # NOT_SOLARIS
 
 
 PROPS_BUILD = $(LIBDIR)/security/java.security
diff --git a/jdk/make/java/zip/FILES_c.gmk b/jdk/make/java/zip/FILES_c.gmk
index 6664887..96f8cee 100644
--- a/jdk/make/java/zip/FILES_c.gmk
+++ b/jdk/make/java/zip/FILES_c.gmk
@@ -29,7 +29,10 @@
 	Deflater.c \
 	Inflater.c \
 	ZipFile.c \
-	zip_util.c \
+	zip_util.c
+
+ifneq ($(SYSTEM_ZLIB),true)
+FILES_c += \
 	compress.c \
 	deflate.c \
 	gzio.c \
@@ -41,4 +44,5 @@
 	uncompr.c \
 	zadler32.c \
 	zcrc32.c \
-	zutil.c 
+	zutil.c
+endif
diff --git a/jdk/make/java/zip/Makefile b/jdk/make/java/zip/Makefile
index 906e7e8..5955335 100644
--- a/jdk/make/java/zip/Makefile
+++ b/jdk/make/java/zip/Makefile
@@ -74,16 +74,24 @@
 CPPFLAGS += -UDEBUG 
 endif
 
-CPPFLAGS += -I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
 CPPFLAGS += -I$(SHARE_SRC)/native/java/io
 CPPFLAGS += -I$(PLATFORM_SRC)/native/java/io
 
+ifneq ($(SYSTEM_ZLIB),true)
+CPPFLAGS += -I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+
 #
 # Add to ambient vpath so we pick up the library files
 #
 vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/zlib-$(ZLIB_VERSION)
+endif
 
 #
 # Link to JVM library for JVM_Zip* functions
 #
+ifeq ($(SYSTEM_ZLIB),true)
+OTHER_LDLIBS = -lz
+else
 OTHER_LDLIBS = $(JVMLIB)
+endif
+
diff --git a/jdk/make/javax/sound/FILES_c.gmk b/jdk/make/javax/sound/FILES_c.gmk
index 9a5e5f2..3646393 100644
--- a/jdk/make/javax/sound/FILES_c.gmk
+++ b/jdk/make/javax/sound/FILES_c.gmk
@@ -34,6 +34,18 @@
 
 FILES_linux = 
 
+FILES_bsd =
+
+FILES_macosx = \
+    PLATFORM_API_MacOSX_MidiIn.c \
+    PLATFORM_API_MacOSX_MidiOut.c \
+    PLATFORM_API_MacOSX_MidiUtils.c
+
+FILES_cpp_macosx = \
+    PLATFORM_API_MacOSX_Utils.cpp \
+    PLATFORM_API_MacOSX_PCM.cpp \
+    PLATFORM_API_MacOSX_Ports.cpp
+
 FILES_windows = \
 	PLATFORM_API_WinOS_MidiIn.c \
 	PLATFORM_API_WinOS_MidiOut.c \
diff --git a/jdk/make/javax/sound/Makefile b/jdk/make/javax/sound/Makefile
index a048f23..e7664bc 100644
--- a/jdk/make/javax/sound/Makefile
+++ b/jdk/make/javax/sound/Makefile
@@ -27,6 +27,11 @@
 PACKAGE = javax.sound
 LIBRARY = jsound
 PRODUCT = sun
+
+ifeq ($(PLATFORM),macosx)
+CPLUSPLUSLIBRARY = true
+endif
+
 include $(BUILDDIR)/common/Defs.gmk
 
 # include defines for sound
@@ -77,6 +82,7 @@
 	$(FILES_mkdirs)
 
 FILES_c += $(FILES_$(PLATFORM))
+FILES_cpp += $(FILES_cpp_$(PLATFORM))
 
 
 #
@@ -105,6 +111,22 @@
   #MXSPP_ADD = $(PLATFORM)-$(ARCH)/
 endif # PLATFORM linux
 
+ifeq ($(PLATFORM), macosx)
+  CPPFLAGS += -DUSE_PORTS=TRUE \
+              -DUSE_DAUDIO=TRUE \
+              -DUSE_PLATFORM_MIDI_OUT=TRUE \
+              -DUSE_PLATFORM_MIDI_IN=TRUE
+
+  INCLUDE_PORTS = TRUE
+  INCLUDE_DAUDIO = TRUE
+  INCLUDE_MIDI = TRUE
+
+  LDFLAGS += -framework CoreAudio -framework CoreFoundation \
+             -framework CoreServices -framework AudioUnit -lstdc++ \
+             -framework CoreMIDI
+  CXXFLAGS += -I`xcode-select -print-path`/Extras/CoreAudio/PublicUtility
+endif
+
 ifeq ($(PLATFORM), solaris)
   # build with ports and direct audio
   CPPFLAGS += -DUSE_PORTS=TRUE 	\
@@ -144,6 +166,11 @@
 CPPFLAGS += \
 	-I$(SHARE_SRC)/native/com/sun/media/sound
 
+ifeq ($(PLATFORM), macosx)
+vpath %.c   $(call NativeSrcDirList,,native/com/sun/media/sound)
+vpath %.cpp $(call NativeSrcDirList,,native/com/sun/media/sound)
+
+else
 #
 # Add to the ambient VPATH.
 #
@@ -151,6 +178,7 @@
 vpath %.c $(PLATFORM_SRC)/native/com/sun/media/sound
 vpath %.cpp $(PLATFORM_SRC)/native/com/sun/media/sound
 
+endif
 
 #
 # Include rules
diff --git a/jdk/make/javax/sound/SoundDefs.gmk b/jdk/make/javax/sound/SoundDefs.gmk
index 557c773..06c0af8 100644
--- a/jdk/make/javax/sound/SoundDefs.gmk
+++ b/jdk/make/javax/sound/SoundDefs.gmk
@@ -40,6 +40,10 @@
   CPPFLAGS += -DX_PLATFORM=X_LINUX
 endif # PLATFORM linux
 
+ifeq ($(PLATFORM), macosx)
+  CPPFLAGS += -DX_PLATFORM=X_MACOSX
+endif # PLATFORM macosx
+
 ifeq ($(PLATFORM), solaris)
   CPPFLAGS += -DX_PLATFORM=X_SOLARIS
 
diff --git a/jdk/make/jpda/back/Makefile b/jdk/make/jpda/back/Makefile
index a0d9721..b2d7e22 100644
--- a/jdk/make/jpda/back/Makefile
+++ b/jdk/make/jpda/back/Makefile
@@ -49,7 +49,7 @@
                  -I$(GENNATIVESRCDIR)/jdwp
 
 ifneq ($(PLATFORM), windows)
-  OTHER_LDLIBS += -ldl
+  OTHER_LDLIBS += $(LIBDL)
 endif # PLATFORM
 
 #
diff --git a/jdk/make/jpda/transport/socket/Makefile b/jdk/make/jpda/transport/socket/Makefile
index ac1299d..efbc5a9 100644
--- a/jdk/make/jpda/transport/socket/Makefile
+++ b/jdk/make/jpda/transport/socket/Makefile
@@ -40,6 +40,11 @@
   OTHER_LDLIBS += $(LIBNSL) $(LIBSOCKET) -lpthread
 endif
 
+ifeq ($(PLATFORM), macosx))
+  LIBSOCKET =
+  OTHER_LDLIBS += -pthread
+endif
+
 ifeq ($(PLATFORM), solaris)
   OTHER_LDLIBS += $(LIBNSL) $(LIBSOCKET)
 endif
diff --git a/jdk/make/jprt.properties b/jdk/make/jprt.properties
index b479e22..7bf63e7 100644
--- a/jdk/make/jprt.properties
+++ b/jdk/make/jprt.properties
@@ -25,268 +25,80 @@
 
 # Properties for jprt
 
-# At submit time, the release supplied will be in jprt.submit.release
-#    and will be one of the official release names defined in jprt.
-#    jprt supports property value expansion using ${property.name} syntax.
-
-# This tells jprt what default release we want to build
-jprt.tools.default.release=${jprt.submit.release}
+# Locked down to jdk7
+jprt.tools.default.release=jdk7
 
 # The different build flavors we want, we override here so we just get these 2
 jprt.build.flavors=product,fastdebug
 
-# Define the Windows we want (temporary)
-jprt.my.windows.i586.jdk7b107=windows_i586_5.0
-jprt.my.windows.i586.jdk7temp=windows_i586_5.0
-jprt.my.windows.i586.jdk7=windows_i586_5.1
-jprt.my.windows.i586=${jprt.my.windows.i586.${jprt.tools.default.release}}
-
 # Standard list of jprt build targets for this source tree
-jprt.build.targets= 						\
-    solaris_sparc_5.10-{product|fastdebug}, 			\
+jprt.build.targets=                                         	\
+    solaris_sparc_5.10-{product|fastdebug},                 	\
     solaris_sparcv9_5.10-{product|fastdebug}, 			\
     solaris_i586_5.10-{product|fastdebug}, 			\
     solaris_x64_5.10-{product|fastdebug}, 			\
     linux_i586_2.6-{product|fastdebug}, 			\
     linux_x64_2.6-{product|fastdebug}, 				\
-    ${jprt.my.windows.i586}-{product|fastdebug}, 		\
+    macosx_x64_10.7-{product|fastdebug}, 			\
+    windows_i586_5.1-{product|fastdebug}, 			\
     windows_x64_5.2-{product|fastdebug}
 
 # User can select the test set with jprt submit "-testset name" option
 jprt.my.test.set=${jprt.test.set}
 
-# Standard vm test target
+# Test target list (no fastdebug & limited c2 testing)
+jprt.my.test.target.set= \
+    solaris_sparc_5.10-product-c1-TESTNAME,                     \
+    solaris_sparcv9_5.10-product-c2-TESTNAME,                   \
+    solaris_i586_5.10-product-c1-TESTNAME,                      \
+    solaris_x64_5.10-product-c2-TESTNAME,                       \
+    linux_i586_2.6-product-{c1|c2}-TESTNAME,                    \
+    linux_x64_2.6-product-c2-TESTNAME,                          \
+    macosx_x64_10.7-product-c2-TESTNAME,                        \
+    windows_i586_5.1-product-c1-TESTNAME,                       \
+    windows_x64_5.2-product-c2-TESTNAME
+
+# Default vm test targets (testset=default)
 jprt.vm.default.test.targets=					\
-    solaris_sparc_5.10-product-c1-jvm98, 			\
-    solaris_sparcv9_5.10-product-c2-jvm98, 			\
-    solaris_i586_5.10-product-c1-jvm98, 			\
-    solaris_x64_5.10-product-c2-jvm98, 				\
-    linux_i586_2.6-product-{c1|c2}-jvm98, 			\
-    linux_x64_2.6-product-c2-jvm98, 				\
-    ${jprt.my.windows.i586}-product-c1-jvm98, 			\
-    windows_x64_5.2-product-c2-jvm98
+    ${jprt.my.test.target.set:TESTNAME=jvm98}
 
-# Select vm testlist to use (allow for testset to be empty too)
-jprt.vm.all.test.targets=${jprt.vm.default.test.targets}
-jprt.vm..test.targets=${jprt.vm.default.test.targets} 
-jprt.test.targets=${jprt.vm.${jprt.my.test.set}.test.targets} 
-
-# Default jdk test targets in test/Makefile (no fastdebug & limited c2)
+# Default jdk test targets (testset=default)
 jprt.make.rule.default.test.targets=				\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_beans1, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_beans1, 		\
-    solaris_i586_5.10-product-c1-jdk_beans1, 			\
-    solaris_x64_5.10-product-c2-jdk_beans1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_beans1, 			\
-    linux_x64_2.6-product-c2-jdk_beans1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_beans1, 		\
-    windows_x64_5.2-product-c2-jdk_beans1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_io, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_io, 			\
-    solaris_i586_5.10-product-c1-jdk_io, 			\
-    solaris_x64_5.10-product-c2-jdk_io, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_io, 			\
-    linux_x64_2.6-product-c2-jdk_io, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_io, 			\
-    windows_x64_5.2-product-c2-jdk_io, 				\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_lang, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_lang, 			\
-    solaris_i586_5.10-product-c1-jdk_lang, 			\
-    solaris_x64_5.10-product-c2-jdk_lang, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_lang, 			\
-    linux_x64_2.6-product-c2-jdk_lang, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_lang, 		\
-    windows_x64_5.2-product-c2-jdk_lang, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_math, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_math, 			\
-    solaris_i586_5.10-product-c1-jdk_math, 			\
-    solaris_x64_5.10-product-c2-jdk_math, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_math, 			\
-    linux_x64_2.6-product-c2-jdk_math, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_math, 		\
-    windows_x64_5.2-product-c2-jdk_math, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_misc, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_misc, 			\
-    solaris_i586_5.10-product-c1-jdk_misc, 			\
-    solaris_x64_5.10-product-c2-jdk_misc, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_misc, 			\
-    linux_x64_2.6-product-c2-jdk_misc, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_misc, 		\
-    windows_x64_5.2-product-c2-jdk_misc, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_net, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_net, 			\
-    solaris_i586_5.10-product-c1-jdk_net, 			\
-    solaris_x64_5.10-product-c2-jdk_net, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_net, 			\
-    linux_x64_2.6-product-c2-jdk_net, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_net, 		\
-    windows_x64_5.2-product-c2-jdk_net, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_nio1, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_nio1, 			\
-    solaris_i586_5.10-product-c1-jdk_nio1, 			\
-    solaris_x64_5.10-product-c2-jdk_nio1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_nio1, 			\
-    linux_x64_2.6-product-c2-jdk_nio1, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_nio1, 		\
-    windows_x64_5.2-product-c2-jdk_nio1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_nio2, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_nio2, 			\
-    solaris_i586_5.10-product-c1-jdk_nio2, 			\
-    solaris_x64_5.10-product-c2-jdk_nio2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_nio2, 			\
-    linux_x64_2.6-product-c2-jdk_nio2, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_nio2, 		\
-    windows_x64_5.2-product-c2-jdk_nio2, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_nio3, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_nio3, 			\
-    solaris_i586_5.10-product-c1-jdk_nio3, 			\
-    solaris_x64_5.10-product-c2-jdk_nio3, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_nio3, 			\
-    linux_x64_2.6-product-c2-jdk_nio3, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_nio3, 		\
-    windows_x64_5.2-product-c2-jdk_nio3, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_security1, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_security1, 		\
-    solaris_i586_5.10-product-c1-jdk_security1, 		\
-    solaris_x64_5.10-product-c2-jdk_security1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_security1, 		\
-    linux_x64_2.6-product-c2-jdk_security1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_security1, 		\
-    windows_x64_5.2-product-c2-jdk_security1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_text, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_text, 			\
-    solaris_i586_5.10-product-c1-jdk_text, 			\
-    solaris_x64_5.10-product-c2-jdk_text, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_text, 			\
-    linux_x64_2.6-product-c2-jdk_text, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_text, 		\
-    windows_x64_5.2-product-c2-jdk_text, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_tools1, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_tools1, 		\
-    solaris_i586_5.10-product-c1-jdk_tools1, 			\
-    solaris_x64_5.10-product-c2-jdk_tools1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_tools1, 			\
-    linux_x64_2.6-product-c2-jdk_tools1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_tools1, 		\
-    windows_x64_5.2-product-c2-jdk_tools1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_util, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_util, 			\
-    solaris_i586_5.10-product-c1-jdk_util, 			\
-    solaris_x64_5.10-product-c2-jdk_util, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_util, 			\
-    linux_x64_2.6-product-c2-jdk_util, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_util, 		\
-    windows_x64_5.2-product-c2-jdk_util
+    ${jprt.my.test.target.set:TESTNAME=jdk_beans1},             \
+    ${jprt.my.test.target.set:TESTNAME=jdk_io},                 \
+    ${jprt.my.test.target.set:TESTNAME=jdk_lang},               \
+    ${jprt.my.test.target.set:TESTNAME=jdk_math},               \
+    ${jprt.my.test.target.set:TESTNAME=jdk_misc},               \
+    ${jprt.my.test.target.set:TESTNAME=jdk_net},                \
+    ${jprt.my.test.target.set:TESTNAME=jdk_nio1},               \
+    ${jprt.my.test.target.set:TESTNAME=jdk_nio2},               \
+    ${jprt.my.test.target.set:TESTNAME=jdk_nio3},               \
+    ${jprt.my.test.target.set:TESTNAME=jdk_security1},          \
+    ${jprt.my.test.target.set:TESTNAME=jdk_text},               \
+    ${jprt.my.test.target.set:TESTNAME=jdk_tools1},             \
+    ${jprt.my.test.target.set:TESTNAME=jdk_util}
 
-# All jdk test targets in test/Makefile (still no fastdebug & limited c2)
+# All vm test targets (testset=all)
+jprt.vm.all.test.targets=                                       \
+    ${jprt.vm.default.test.targets},                            \
+    ${jprt.my.test.target.set:TESTNAME=runThese},               \
+    ${jprt.my.test.target.set:TESTNAME=jbb_default}
+
+# All jdk test targets (testset=all)
 jprt.make.rule.all.test.targets=    				\
-    								\
-   ${jprt.make.rule.default.test.targets}, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_awt, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_awt, 			\
-    solaris_i586_5.10-product-c1-jdk_awt, 			\
-    solaris_x64_5.10-product-c2-jdk_awt, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_awt, 			\
-    linux_x64_2.6-product-c2-jdk_awt, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_awt, 		\
-    windows_x64_5.2-product-c2-jdk_awt, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_beans2, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_beans2, 		\
-    solaris_i586_5.10-product-c1-jdk_beans2, 			\
-    solaris_x64_5.10-product-c2-jdk_beans2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_beans2, 			\
-    linux_x64_2.6-product-c2-jdk_beans2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_beans2, 		\
-    windows_x64_5.2-product-c2-jdk_beans2, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_beans3, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_beans3, 		\
-    solaris_i586_5.10-product-c1-jdk_beans3, 			\
-    solaris_x64_5.10-product-c2-jdk_beans3, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_beans3, 			\
-    linux_x64_2.6-product-c2-jdk_beans3, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_beans3, 		\
-    windows_x64_5.2-product-c2-jdk_beans3, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_management1, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_management1, 		\
-    solaris_i586_5.10-product-c1-jdk_management1, 		\
-    solaris_x64_5.10-product-c2-jdk_management1, 		\
-    linux_i586_2.6-product-{c1|c2}-jdk_management1, 		\
-    linux_x64_2.6-product-c2-jdk_management1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_management1, 	\
-    windows_x64_5.2-product-c2-jdk_management1, 		\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_management2, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_management2, 		\
-    solaris_i586_5.10-product-c1-jdk_management2, 		\
-    solaris_x64_5.10-product-c2-jdk_management2, 		\
-    linux_i586_2.6-product-{c1|c2}-jdk_management2, 		\
-    linux_x64_2.6-product-c2-jdk_management2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_management2, 	\
-    windows_x64_5.2-product-c2-jdk_management2, 		\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_rmi, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_rmi, 			\
-    solaris_i586_5.10-product-c1-jdk_rmi, 			\
-    solaris_x64_5.10-product-c2-jdk_rmi, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_rmi, 			\
-    linux_x64_2.6-product-c2-jdk_rmi, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_rmi, 		\
-    windows_x64_5.2-product-c2-jdk_rmi, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_security2, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_security2, 		\
-    solaris_i586_5.10-product-c1-jdk_security2, 		\
-    solaris_x64_5.10-product-c2-jdk_security2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_security2, 		\
-    linux_x64_2.6-product-c2-jdk_security2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_security2, 		\
-    windows_x64_5.2-product-c2-jdk_security2, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_security3, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_security3, 		\
-    solaris_i586_5.10-product-c1-jdk_security3, 		\
-    solaris_x64_5.10-product-c2-jdk_security3, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_security3, 		\
-    linux_x64_2.6-product-c2-jdk_security3, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_security3, 		\
-    windows_x64_5.2-product-c2-jdk_security3, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_swing, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_swing, 			\
-    solaris_i586_5.10-product-c1-jdk_swing, 			\
-    solaris_x64_5.10-product-c2-jdk_swing, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_swing, 			\
-    linux_x64_2.6-product-c2-jdk_swing, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_swing, 		\
-    windows_x64_5.2-product-c2-jdk_swing, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_tools2, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_tools2, 		\
-    solaris_i586_5.10-product-c1-jdk_tools2, 			\
-    solaris_x64_5.10-product-c2-jdk_tools2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_tools2, 			\
-    linux_x64_2.6-product-c2-jdk_tools2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_tools2, 		\
-    windows_x64_5.2-product-c2-jdk_tools2
+    ${jprt.make.rule.default.test.targets}, 			\
+    ${jprt.my.test.target.set:TESTNAME=jdk_awt},                \
+    ${jprt.my.test.target.set:TESTNAME=jdk_beans2},             \
+    ${jprt.my.test.target.set:TESTNAME=jdk_beans3},             \
+    ${jprt.my.test.target.set:TESTNAME=jdk_management1},        \
+    ${jprt.my.test.target.set:TESTNAME=jdk_management2},        \
+    ${jprt.my.test.target.set:TESTNAME=jdk_rmi},                \
+    ${jprt.my.test.target.set:TESTNAME=jdk_security2},          \
+    ${jprt.my.test.target.set:TESTNAME=jdk_security3},          \
+    ${jprt.my.test.target.set:TESTNAME=jdk_swing},              \
+    ${jprt.my.test.target.set:TESTNAME=jdk_tools2}
 
-# JCK test targets in test/Makefile (no fastdebug & limited c2, windows broken)
+# JCK test targets in test/Makefile (no windows)
 jprt.my.jck.test.target.set=					\
     solaris_sparc_5.10-product-c1-JCK7TESTRULE, 		\
     solaris_sparcv9_5.10-product-c2-JCK7TESTRULE, 		\
@@ -302,8 +114,10 @@
     ${jprt.my.jck.test.target.set:JCK7TESTRULE=jck7compiler}
 
 # Select list to use (allow for testset to be empty too)
-jprt.make.rule..test.targets=${jprt.make.rule.default.test.targets} 
-jprt.make.rule.test.targets=${jprt.make.rule.${jprt.my.test.set}.test.targets} 
+jprt.make.rule..test.targets=${jprt.make.rule.default.test.targets}
+jprt.make.rule.test.targets=${jprt.make.rule.${jprt.my.test.set}.test.targets}
+jprt.vm..test.targets=${jprt.vm.default.test.targets}
+jprt.test.targets=${jprt.vm.${jprt.my.test.set}.test.targets}
 
 # Directories to be excluded from the source bundles
 jprt.bundle.exclude.src.dirs=build dist webrev
diff --git a/jdk/make/launchers/Makefile.launcher b/jdk/make/launchers/Makefile.launcher
index 0908d61..6069d98 100644
--- a/jdk/make/launchers/Makefile.launcher
+++ b/jdk/make/launchers/Makefile.launcher
@@ -86,12 +86,15 @@
 endif
 ifeq ($(PROGRAM),jsadebugd)
   SA_TOOL=true
+  INFO_PLIST_FILE=Info-privileged.plist
 endif
 ifeq ($(PROGRAM),jinfo)
   SA_TOOL=true
+  INFO_PLIST_FILE=Info-privileged.plist
 endif
 ifeq ($(PROGRAM),jmap)
   SA_TOOL=true
+  INFO_PLIST_FILE=Info-privileged.plist
 endif
 
 # special idlj launcher
diff --git a/jdk/make/mkdemo/jvmti/hprof/Makefile b/jdk/make/mkdemo/jvmti/hprof/Makefile
index e252919..fca8ec4 100644
--- a/jdk/make/mkdemo/jvmti/hprof/Makefile
+++ b/jdk/make/mkdemo/jvmti/hprof/Makefile
@@ -37,12 +37,11 @@
 
 ifeq ($(PLATFORM), windows)
   EXTRA_LIBS += wsock32.lib winmm.lib
-endif
-ifeq ($(PLATFORM), solaris)
-  OTHER_LDLIBS += $(LIBSOCKET) $(LIBNSL) -ldl
-endif
+else
+  OTHER_LDLIBS += $(LIBSOCKET) $(LIBNSL) $(LIBDL)
 ifeq ($(PLATFORM), linux)
-  OTHER_LDLIBS += $(LIBSOCKET) $(LIBNSL) -ldl -lpthread
+  OTHER_LDLIBS += -lpthread
+endif
 endif
 
 #
diff --git a/jdk/make/mksample/Makefile b/jdk/make/mksample/Makefile
index aa4e31d..aa0f748 100644
--- a/jdk/make/mksample/Makefile
+++ b/jdk/make/mksample/Makefile
@@ -47,6 +47,11 @@
 	SUBDIRS += dtrace
 endif
 
+# and Mac OS X too
+ifeq ($(PLATFORM), macosx) 
+	SUBDIRS += dtrace
+endif
+
 include $(BUILDDIR)/common/Subdirs.gmk
 
 TOPLEVEL_FILES =							\
diff --git a/jdk/make/netbeans/common/architectures/name-Bsd.properties b/jdk/make/netbeans/common/architectures/name-Bsd.properties
new file mode 100644
index 0000000..587e749
--- /dev/null
+++ b/jdk/make/netbeans/common/architectures/name-Bsd.properties
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   - Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#
+#   - Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+#   - Neither the name of Oracle nor the names of its
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+platform=bsd
diff --git a/jdk/make/sun/Makefile b/jdk/make/sun/Makefile
index 4c19f4e..03809f7 100644
--- a/jdk/make/sun/Makefile
+++ b/jdk/make/sun/Makefile
@@ -58,9 +58,17 @@
   XAWT_SUBDIR     = xawt
 endif
 
+ifeq ($(PLATFORM), macosx)
+  LWAWT_PRE_SUBDIR = osxapp
+  LWAWT_SUBDIR = lwawt
+endif
+
 ifndef OPENJDK
+ifneq ($(PLATFORM), macosx)
   JDBC_SUBDIR = jdbc
 endif
+endif
+
 ifdef OPENJDK
   RENDER_SUBDIR = pisces
 else
@@ -78,7 +86,7 @@
   DISPLAY_TOOLS = applet
 endif
 SUBDIRS_desktop    = audio $(RENDER_SUBDIR) image \
-                     $(DISPLAY_LIBS) $(DGA_SUBDIR) \
+                     $(LWAWT_PRE_SUBDIR) $(DISPLAY_LIBS) $(DGA_SUBDIR) $(LWAWT_SUBDIR) \
                      jawt font jpeg cmm $(DISPLAY_TOOLS) beans
 SUBDIRS_management = management
 SUBDIRS_misc       = $(ORG_SUBDIR) rmi $(JDBC_SUBDIR) tracing
diff --git a/jdk/make/sun/awt/FILES_c_macosx.gmk b/jdk/make/sun/awt/FILES_c_macosx.gmk
new file mode 100644
index 0000000..adf5a9a
--- /dev/null
+++ b/jdk/make/sun/awt/FILES_c_macosx.gmk
@@ -0,0 +1,28 @@
+#
+# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+FILES_AWT_objc = \
+        $(TARGDIR)MacOSXResourceBundle.m
+
diff --git a/jdk/make/sun/awt/FILES_export_macosx.gmk b/jdk/make/sun/awt/FILES_export_macosx.gmk
new file mode 100644
index 0000000..8975d6d
--- /dev/null
+++ b/jdk/make/sun/awt/FILES_export_macosx.gmk
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# FILES_export definitions for Mac OS X
+
+FILES_export += \
+	com/apple/resources/MacOSXResourceBundle.java
diff --git a/jdk/make/sun/awt/Makefile b/jdk/make/sun/awt/Makefile
index 071c362..d00f0c3 100644
--- a/jdk/make/sun/awt/Makefile
+++ b/jdk/make/sun/awt/Makefile
@@ -93,7 +93,7 @@
 ifeq  ($(PLATFORM), solaris)
 FILES_c = $(FILES_2D_c)
 FILES_c += awt_LoadLibrary.c
-OTHER_LDLIBS = $(JVMLIB) $(LIBM) -ldl
+OTHER_LDLIBS = $(JVMLIB) $(LIBM) $(LIBDL)
 ifeq ($(CC_VER), 5.8)
   ifndef REMOVE_ALL_WORKAROUNDS
     ifeq ($(ARCH_FAMILY), i586)
@@ -120,14 +120,42 @@
 FILES_c = $(FILES_2D_c)
 FILES_c += awt_LoadLibrary.c
 OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
-OTHER_LDLIBS = $(JVMLIB) $(LIBM) -ldl
+OTHER_LDLIBS = $(JVMLIB) $(LIBM) $(LIBDL)
 endif
 
 FILES_c += initIDs.c
 
+ifeq ($(PLATFORM), macosx)
+FILES_c = $(FILES_2D_c)
+FILES_c += awt_LoadLibrary.c
+OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
+OTHER_LDLIBS = $(JVMLIB) $(LIBM)
+endif
+
 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLARIS/LINUX
 endif # PLATFORM 
 
+ifeq ($(PLATFORM), macosx)
+# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv MAC OS X
+
+#
+# Files
+#
+include FILES_c_macosx.gmk
+include FILES_export_macosx.gmk
+
+FILES_objc = $(FILES_AWT_objc)
+OTHER_LDLIBS = -lmlib_image $(JVMLIB) $(LIBM) \
+    -framework Cocoa \
+    -framework OpenGL \
+    -framework JavaNativeFoundation \
+    -framework JavaRuntimeSupport \
+    -framework ApplicationServices \
+    -framework AudioToolbox
+
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ MAC OS X
+endif # PLATFORM 
+
 # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv SOLARIS-SPARC
 # solaris-sparc and solaris-sparcv9 both build 'vis'
 ifeq ("$(PLATFORM)-$(ARCH_FAMILY)", "solaris-sparc")
@@ -240,7 +268,7 @@
 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ WINDOWS
 endif # PLATFORM
 
-ifeq ($(PLATFORM), linux)
+ifneq (,$(findstring $(PLATFORM), linux bsd))
 # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv LINUX
 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/../java2d/opengl
 vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)/../java2d/opengl
@@ -249,6 +277,12 @@
 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LINUX
 endif # PLATFORM
 
+ifeq ($(PLATFORM), macosx)
+# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv MAC OS X
+vpath %.m   $(call NativeSrcDirList,,native/com/apple/resources)
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ MAC OS X
+endif # PLATFORM
+
 ifeq ($(PLATFORM), windows)
 # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv WINDOWS
 OTHER_LDLIBS = kernel32.lib user32.lib gdi32.lib winspool.lib \
@@ -390,6 +424,19 @@
 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLARIS
 endif # PLATFORM
 
+
+ifeq ($(PLATFORM), macosx)
+# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv MAC OS X
+
+FONTCONFIGS_SRC = $(JDK_TOPDIR)/src/macosx/classes/sun/awt/fontconfigs
+_FONTCONFIGS    = \
+        fontconfig.properties
+
+FONTCONFIGS_SRC_PREFIX = $(PLATFORM).
+
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ MAC OS X
+endif # PLATFORM
+
 FONTCONFIGS     = $(_FONTCONFIGS:%=$(LIBDIR)/%.src)
 BINARYFONTCONFIGS = $(_FONTCONFIGS:%.properties=$(LIBDIR)/%.bfc)
 
diff --git a/jdk/make/sun/awt/mapfile-vers-bsd b/jdk/make/sun/awt/mapfile-vers-bsd
new file mode 100644
index 0000000..5040b03
--- /dev/null
+++ b/jdk/make/sun/awt/mapfile-vers-bsd
@@ -0,0 +1,577 @@
+#
+# Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# Define public interface for libawt.so on Bsd.
+# Bsd port does not use mawt, all public symbols are in libawt.so
+
+SUNWprivate_1.1 {
+	global:
+		JNI_OnLoad;
+
+		Java_java_awt_CheckboxMenuItem_initIDs;
+		Java_java_awt_Color_initIDs;
+		Java_java_awt_FontMetrics_initIDs;
+		Java_java_awt_image_BufferedImage_initIDs;
+		Java_sun_awt_image_DataBufferNative_getElem;
+		Java_sun_awt_image_DataBufferNative_setElem;
+		Java_java_awt_image_ColorModel_initIDs;
+		Java_java_awt_image_ComponentSampleModel_initIDs;
+		Java_java_awt_image_IndexColorModel_initIDs;
+		Java_java_awt_image_Kernel_initIDs;
+		Java_java_awt_image_Raster_initIDs;
+		Java_java_awt_image_SampleModel_initIDs;
+		Java_java_awt_Label_initIDs;
+		Java_java_awt_MenuBar_initIDs;
+		Java_java_awt_ScrollPaneAdjustable_initIDs;
+		Java_java_awt_Toolkit_initIDs;
+		Java_java_awt_TrayIcon_initIDs;
+                Java_sun_awt_DebugSettings_setCTracingOn__Z; 
+                Java_sun_awt_DebugSettings_setCTracingOn__ZLjava_lang_String_2; 
+                Java_sun_awt_DebugSettings_setCTracingOn__ZLjava_lang_String_2I; 
+		Java_sun_awt_image_ByteComponentRaster_initIDs;
+		Java_sun_awt_image_GifImageDecoder_initIDs;
+		Java_sun_awt_image_GifImageDecoder_parseImage;
+		Java_sun_awt_image_Image_initIDs;
+		Java_sun_awt_image_ImageRepresentation_initIDs;
+		Java_sun_awt_image_ImageRepresentation_setDiffICM;
+		Java_sun_awt_image_ImageRepresentation_setICMpixels;
+		Java_sun_awt_image_ImagingLib_convolveBI;
+		Java_sun_awt_image_ImagingLib_convolveRaster;
+		Java_sun_awt_image_ImagingLib_init;
+		Java_sun_awt_image_ImagingLib_transformBI;
+		Java_sun_awt_image_ImagingLib_transformRaster;
+		Java_sun_awt_image_IntegerComponentRaster_initIDs;
+		Java_sun_awt_image_ShortComponentRaster_initIDs;
+		Java_sun_java2d_pipe_SpanClipRenderer_eraseTile;
+		Java_sun_java2d_pipe_SpanClipRenderer_fillTile;
+                Java_sun_java2d_pipe_ShapeSpanIterator_addSegment;
+                Java_sun_java2d_pipe_ShapeSpanIterator_moveTo;
+                Java_sun_java2d_pipe_ShapeSpanIterator_lineTo;
+                Java_sun_java2d_pipe_ShapeSpanIterator_quadTo;
+                Java_sun_java2d_pipe_ShapeSpanIterator_curveTo;
+                Java_sun_java2d_pipe_ShapeSpanIterator_closePath;
+                Java_sun_java2d_pipe_ShapeSpanIterator_pathDone;
+                Java_sun_java2d_pipe_ShapeSpanIterator_getNativeConsumer;
+                Java_sun_java2d_pipe_ShapeSpanIterator_appendPoly;
+                Java_sun_java2d_pipe_ShapeSpanIterator_dispose;
+                Java_sun_java2d_pipe_ShapeSpanIterator_getNativeIterator;
+                Java_sun_java2d_pipe_ShapeSpanIterator_getPathBox;
+                Java_sun_java2d_pipe_ShapeSpanIterator_initIDs;
+                Java_sun_java2d_pipe_ShapeSpanIterator_intersectClipBox;
+                Java_sun_java2d_pipe_ShapeSpanIterator_nextSpan;
+                Java_sun_java2d_pipe_ShapeSpanIterator_setNormalize;
+                Java_sun_java2d_pipe_ShapeSpanIterator_setOutputAreaXYXY;
+                Java_sun_java2d_pipe_ShapeSpanIterator_setRule;
+                Java_sun_java2d_pipe_ShapeSpanIterator_skipDownTo;
+
+		Java_java_awt_Dimension_initIDs;
+		Java_java_awt_event_MouseEvent_initIDs;
+		Java_java_awt_image_DataBufferInt_initIDs;
+		Java_java_awt_image_SinglePixelPackedSampleModel_initIDs;
+		Java_java_awt_Rectangle_initIDs;
+		Java_sun_awt_image_BufImgSurfaceData_getSurfaceData;
+		Java_sun_awt_image_BufImgSurfaceData_initIDs;
+		Java_sun_awt_image_BufImgSurfaceData_initRaster;
+		Java_sun_awt_image_BufImgSurfaceData_setSurfaceData;
+                Java_sun_awt_image_BufImgSurfaceData_freeNativeICMData;
+		Java_sun_awt_image_BytePackedRaster_initIDs;
+		Java_sun_awt_image_ImagingLib_lookupByteBI;
+		Java_sun_awt_image_ImagingLib_lookupByteRaster;
+		Java_sun_java2d_SurfaceData_initIDs;
+		Java_sun_java2d_SurfaceData_isOpaqueGray;
+		Java_sun_java2d_Disposer_initIDs;
+		Java_sun_java2d_DefaultDisposerRecord_invokeNativeDispose;
+		Java_sun_java2d_loops_BlitBg_BlitBg;
+		Java_sun_java2d_loops_Blit_Blit;
+		Java_sun_java2d_loops_ScaledBlit_Scale;
+		Java_sun_java2d_loops_DrawLine_DrawLine;
+		Java_sun_java2d_loops_DrawPolygons_DrawPolygons;
+		Java_sun_java2d_loops_DrawRect_DrawRect;
+		Java_sun_java2d_loops_FillRect_FillRect;
+		Java_sun_java2d_loops_FillSpans_FillSpans;
+		Java_sun_java2d_loops_GraphicsPrimitiveMgr_initIDs;
+		Java_sun_java2d_loops_GraphicsPrimitiveMgr_registerNativeLoops;
+		Java_sun_java2d_loops_MaskBlit_MaskBlit;
+		Java_sun_java2d_loops_MaskFill_MaskFill;
+		Java_sun_java2d_loops_MaskFill_FillAAPgram;
+		Java_sun_java2d_loops_MaskFill_DrawAAPgram;
+                Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans;
+		Java_sun_java2d_pipe_SpanClipRenderer_initIDs;
+		sun_awt_image_GifImageDecoder_initIDs;
+
+		# libmawt entry points
+		SurfaceData_InitOps;
+		SurfaceData_ThrowInvalidPipeException;
+                Region_GetBounds;
+                Region_GetInfo;
+                Region_StartIteration;
+                Region_CountIterationRects;
+                Region_NextIteration;
+                Region_EndIteration;
+                GrPrim_CompGetXorInfo;
+                GrPrim_CompGetAlphaInfo;
+		img_makePalette;
+		initInverseGrayLut;
+		make_dither_arrays;
+		make_uns_ordered_dither_array;
+
+		# variables exported to libmawt
+		std_img_oda_red;
+		std_img_oda_blue;
+		std_img_oda_green;
+		std_odas_computed;
+		g_CMpDataID;
+		colorValueID;
+                jvm;
+
+		# CDE private entry point
+                # This is in awt_LoadLibrary.c and falls through to libmawt.
+                # Evidently CDE needs this for backward compatability.
+		Java_sun_awt_motif_XsessionWMcommand;
+
+		# Java Plugin
+                # This is in awt_LoadLibrary.c and falls through to libmawt.
+                # Evidently plugin needs this for backward compatability.
+		getAwtLockFunctions;
+		getAwtData;
+		getAwtDisplay;
+
+		# libfontmanager entry points
+		AWTIsHeadless;
+		GrPrim_Sg2dGetCompInfo;
+		GrPrim_Sg2dGetClip;
+		GetNativePrim;
+		SurfaceData_IntersectBounds;
+		SurfaceData_GetOps;
+		Disposer_AddRecord;
+		GrPrim_Sg2dGetEaRGB;
+		GrPrim_Sg2dGetPixel;
+		GrPrim_Sg2dGetLCDTextContrast;
+
+		#Java_sun_awt_motif_MComponentPeer_restoreFocus;
+		Java_sun_awt_DefaultMouseInfoPeer_fillPointWithCoords;
+		Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse;
+		Java_java_awt_AWTEvent_nativeSetSource;
+		Java_java_awt_Checkbox_initIDs;
+		Java_java_awt_Component_initIDs;
+		Java_java_awt_Dialog_initIDs;
+		Java_java_awt_Font_initIDs;
+		Java_sun_awt_KeyboardFocusManagerPeerImpl_clearNativeGlobalFocusOwner;
+                Java_sun_awt_KeyboardFocusManagerPeerImpl_getNativeFocusOwner;
+                Java_sun_awt_KeyboardFocusManagerPeerImpl_getNativeFocusedWindow;
+                Java_java_awt_KeyboardFocusManager_initIDs;
+		Java_java_awt_Menu_initIDs;
+		Java_java_awt_MenuComponent_initIDs;
+		Java_java_awt_MenuItem_initIDs;
+		Java_java_awt_Scrollbar_initIDs;
+		Java_java_awt_ScrollPane_initIDs;
+		Java_java_awt_TextArea_initIDs;
+		Java_sun_awt_FontDescriptor_initIDs;
+		#Java_sun_awt_motif_MButtonPeer_create;
+		#Java_sun_awt_motif_MButtonPeer_setLabel;
+		#Java_sun_awt_motif_MCanvasPeer_create;
+		#Java_sun_awt_motif_MCanvasPeer_initIDs;
+		#Java_sun_awt_motif_MCanvasPeer_resetTargetGC;
+		#Java_sun_awt_motif_MCheckboxMenuItemPeer_pSetState;
+		#Java_sun_awt_motif_MCheckboxPeer_create;
+		#Java_sun_awt_motif_MCheckboxPeer_setCheckboxGroup;
+		#Java_sun_awt_motif_MCheckboxPeer_setLabel;
+		#Java_sun_awt_motif_MCheckboxPeer_pSetState;
+		#Java_sun_awt_motif_MCheckboxPeer_pGetState;
+		#Java_sun_awt_motif_MChoicePeer_addItem;
+		#Java_sun_awt_motif_MChoicePeer_appendItems;
+		#Java_sun_awt_motif_MChoicePeer_create;
+		#Java_sun_awt_motif_MChoicePeer_pReshape;
+		#Java_sun_awt_motif_MChoicePeer_remove;
+		#Java_sun_awt_motif_MChoicePeer_removeAll;
+		#Java_sun_awt_motif_MChoicePeer_setBackground;
+		#Java_sun_awt_motif_MChoicePeer_pSelect;
+		#Java_sun_awt_motif_MChoicePeer_setFont;
+		#Java_sun_awt_motif_MChoicePeer_setForeground;
+		#Java_sun_awt_motif_MComponentPeer_addNativeDropTarget;
+		#Java_sun_awt_motif_MComponentPeer_createBackBuffer;
+		#Java_sun_awt_motif_MComponentPeer_destroyBackBuffer;
+		#Java_sun_awt_motif_MComponentPeer_getNativeColor;
+		#Java_sun_awt_motif_MComponentPeer_getWindow;
+		#Java_sun_awt_motif_MComponentPeer_pDisable;
+		#Java_sun_awt_motif_MComponentPeer_pDispose;
+		#Java_sun_awt_motif_MComponentPeer_pEnable;
+		#Java_sun_awt_motif_MComponentPeer_pGetLocationOnScreen;
+		#Java_sun_awt_motif_MComponentPeer_pGetLocationOnScreen2;
+		#Java_sun_awt_motif_MComponentPeer_pHide;
+		#Java_sun_awt_motif_MComponentPeer_pInitialize;
+		#Java_sun_awt_motif_MComponentPeer_pMakeCursorVisible;
+		#Java_sun_awt_motif_MComponentPeer_pReshape;
+		#Java_sun_awt_motif_MComponentPeer_pShow;
+		#Java_sun_awt_motif_MComponentPeer_removeNativeDropTarget;
+		#Java_sun_awt_motif_MComponentPeer_swapBuffers;
+		#Java_sun_awt_motif_MComponentPeer_pSetBackground;
+		#Java_sun_awt_motif_MComponentPeer_pSetFont;
+                #Java_sun_awt_motif_MComponentPeer_processSynchronousLightweightTransfer;
+                #Java_sun_awt_motif_MComponentPeer__1requestFocus;
+		#Java_sun_awt_motif_MCheckboxMenuItemPeer_getState;
+		#Java_sun_awt_motif_MComponentPeer_pSetForeground;
+		#Java_sun_awt_motif_MDragSourceContextPeer_startDrag;
+		#Java_sun_awt_motif_MDragSourceContextPeer_setNativeCursor;
+		#Java_sun_awt_motif_MDropTargetContextPeer_addTransfer;
+		#Java_sun_awt_motif_MDropTargetContextPeer_dropDone;
+		#Java_sun_awt_motif_MDropTargetContextPeer_startTransfer;
+		#Java_sun_awt_motif_X11DragSourceContextPeer_startDrag;
+		#Java_sun_awt_motif_X11DragSourceContextPeer_setNativeCursor;
+		#Java_sun_awt_motif_X11DropTargetContextPeer_sendResponse;
+		#Java_sun_awt_motif_X11DropTargetContextPeer_dropDone;
+		#Java_sun_awt_motif_X11DropTargetContextPeer_getData;
+		#Java_sun_awt_motif_MEmbeddedFramePeer_NEFcreate;
+		#Java_sun_awt_motif_MEmbeddedFramePeer_pShowImpl;
+		#Java_sun_awt_motif_MEmbeddedFramePeer_pReshapePrivate;
+		#Java_sun_awt_motif_MEmbeddedFramePeer_getBoundsPrivate;
+		#Java_sun_awt_motif_MFramePeer_pSetIconImage___3B_3I_3SII;
+		#Java_sun_awt_motif_MEmbeddedFramePeer_requestXEmbedFocus;
+		#Java_sun_awt_motif_MEmbeddedFramePeer_isXEmbedApplicationActive;
+		#Java_sun_awt_motif_MEmbeddedFramePeer_isXEmbedActive;
+		#Java_sun_awt_motif_MEmbeddedFrame_getWidget;
+		#Java_sun_awt_motif_MEmbeddedFrame_mapWidget;
+		#Java_sun_awt_motif_MFileDialogPeer_create;
+		#Java_sun_awt_motif_MFileDialogPeer_pDispose;
+		#Java_sun_awt_motif_MFileDialogPeer_pHide;
+		#Java_sun_awt_motif_MFileDialogPeer_pReshape;
+		#Java_sun_awt_motif_MFileDialogPeer_pShow;
+		#Java_sun_awt_motif_MFileDialogPeer_setFileEntry;
+		#Java_sun_awt_motif_MFileDialogPeer_setFont;
+		#Java_sun_awt_motif_MFramePeer_pGetIconSize;
+		#Java_sun_awt_motif_MGlobalCursorManager_cacheInit;
+		#Java_sun_awt_motif_MGlobalCursorManager_findComponentAt;
+		#Java_sun_awt_motif_MGlobalCursorManager_findHeavyweightUnderCursor;
+		#Java_sun_awt_motif_MGlobalCursorManager_getCursorPos;
+		#Java_sun_awt_motif_MGlobalCursorManager_getLocationOnScreen;
+		#Java_sun_awt_motif_MLabelPeer_create;
+		#Java_sun_awt_motif_MLabelPeer_setAlignment;
+		#Java_sun_awt_motif_MLabelPeer_setText;
+		#Java_sun_awt_motif_MListPeer_addItem;
+		#Java_sun_awt_motif_MListPeer_create;
+		#Java_sun_awt_motif_MListPeer_delItems;
+		#Java_sun_awt_motif_MListPeer_deselect;
+		#Java_sun_awt_motif_MListPeer_isSelected;
+		#Java_sun_awt_motif_MListPeer_makeVisible;
+		#Java_sun_awt_motif_MListPeer_select;
+		#Java_sun_awt_motif_MListPeer_setMultipleSelections;
+		#Java_sun_awt_motif_MMenuBarPeer_create;
+		#Java_sun_awt_motif_MMenuItemPeer_createMenuItem;
+		#Java_sun_awt_motif_MMenuItemPeer_pDisable;
+		#Java_sun_awt_motif_MMenuItemPeer_pDispose;
+		#Java_sun_awt_motif_MMenuItemPeer_pEnable;
+		#Java_sun_awt_motif_MMenuItemPeer_pSetLabel;
+		#Java_sun_awt_motif_MMenuPeer_createMenu;
+		#Java_sun_awt_motif_MMenuPeer_createSubMenu;
+		#Java_sun_awt_motif_MMenuPeer_pDispose;
+		#Java_sun_awt_motif_MPopupMenuPeer_createMenu;
+		#Java_sun_awt_motif_MPopupMenuPeer_pDispose;
+		#Java_sun_awt_motif_MPopupMenuPeer_pShow;
+		#Java_sun_awt_motif_MRobotPeer_getRGBPixelsImpl;
+		#Java_sun_awt_motif_MRobotPeer_keyPressImpl;
+		#Java_sun_awt_motif_MRobotPeer_keyReleaseImpl;
+		#Java_sun_awt_motif_MRobotPeer_mouseMoveImpl;
+		#Java_sun_awt_motif_MRobotPeer_mousePressImpl;
+		#Java_sun_awt_motif_MRobotPeer_mouseReleaseImpl;
+		#Java_sun_awt_motif_MRobotPeer_mouseWheelImpl;
+		#Java_sun_awt_motif_MRobotPeer_setup;
+		#Java_sun_awt_motif_MScrollbarPeer_create;
+		#Java_sun_awt_motif_MScrollbarPeer_setLineIncrement;
+		#Java_sun_awt_motif_MScrollbarPeer_setPageIncrement;
+		#Java_sun_awt_motif_MScrollbarPeer_pSetValues;
+		#Java_sun_awt_motif_MScrollPanePeer_create;
+		#Java_sun_awt_motif_MScrollPanePeer_pGetBlockIncrement;
+		#Java_sun_awt_motif_MScrollPanePeer_pGetScrollbarSpace;
+		#Java_sun_awt_motif_MScrollPanePeer_pGetShadow;
+		#Java_sun_awt_motif_MScrollPanePeer_pInsets;
+		#Java_sun_awt_motif_MScrollPanePeer_pSetIncrement;
+		#Java_sun_awt_motif_MScrollPanePeer_pSetScrollChild;
+		#Java_sun_awt_motif_MScrollPanePeer_setScrollPosition;
+		#Java_sun_awt_motif_MTextAreaPeer_initIDs;
+		#Java_sun_awt_motif_MTextAreaPeer_pCreate;
+		#Java_sun_awt_motif_MTextAreaPeer_getCaretPosition;
+		#Java_sun_awt_motif_MTextAreaPeer_getExtraHeight;
+		#Java_sun_awt_motif_MTextAreaPeer_getExtraWidth;
+		#Java_sun_awt_motif_MTextAreaPeer_getSelectionEnd;
+		#Java_sun_awt_motif_MTextAreaPeer_getSelectionStart;
+		#Java_sun_awt_motif_MTextAreaPeer_getText;
+		#Java_sun_awt_motif_MTextAreaPeer_insert;
+		#Java_sun_awt_motif_MTextAreaPeer_pMakeCursorVisible;
+		#Java_sun_awt_motif_MTextAreaPeer_pSetEditable;
+		#Java_sun_awt_motif_MTextAreaPeer_pShow2;
+		#Java_sun_awt_motif_MTextAreaPeer_replaceRange;
+		#Java_sun_awt_motif_MTextAreaPeer_select;
+		#Java_sun_awt_motif_MTextAreaPeer_setCaretPosition;
+		#Java_sun_awt_motif_MTextAreaPeer_setFont;
+		#Java_sun_awt_motif_MTextAreaPeer_setText;
+		#Java_sun_awt_motif_MTextAreaPeer_setTextBackground;
+		#Java_sun_awt_motif_MTextFieldPeer_initIDs;
+		#Java_sun_awt_motif_MTextFieldPeer_pCreate;
+		#Java_sun_awt_motif_MTextFieldPeer_getCaretPosition;
+		#Java_sun_awt_motif_MTextFieldPeer_getSelectionEnd;
+		#Java_sun_awt_motif_MTextFieldPeer_getSelectionStart;
+		#Java_sun_awt_motif_MTextFieldPeer_getText;
+		#Java_sun_awt_motif_MTextFieldPeer_insertReplaceText;
+		#Java_sun_awt_motif_MTextFieldPeer_preDispose;
+		#Java_sun_awt_motif_MTextFieldPeer_pSetEditable;
+		#Java_sun_awt_motif_MTextFieldPeer_select;
+		#Java_sun_awt_motif_MTextFieldPeer_setCaretPosition;
+		#Java_sun_awt_motif_MTextFieldPeer_setEchoChar;
+		#Java_sun_awt_motif_MTextFieldPeer_setFont;
+		#Java_sun_awt_motif_MTextFieldPeer_setText;
+		Java_sun_awt_motif_MToolkit_beep;
+		Java_sun_awt_motif_MToolkit_getLockingKeyStateNative;
+		Java_sun_awt_motif_MToolkit_getMulticlickTime;
+                Java_sun_awt_motif_MToolkit_getNumMouseButtons;
+		Java_sun_awt_motif_MToolkit_getScreenHeight;
+		Java_sun_awt_motif_MToolkit_getScreenResolution;
+		Java_sun_awt_motif_MToolkit_getScreenWidth;
+		Java_sun_awt_motif_MToolkit_init;
+		Java_sun_awt_motif_MToolkit_isDynamicLayoutSupportedNative;
+		Java_sun_awt_motif_MToolkit_isFrameStateSupported;
+		Java_sun_awt_motif_MToolkit_loadSystemColors;
+		Java_sun_awt_motif_MToolkit_makeColorModel;
+		Java_sun_awt_motif_MToolkit_run;
+		Java_sun_awt_motif_MToolkit_sync;
+                Java_sun_awt_motif_MToolkit_isAlwaysOnTopSupported;
+		Java_sun_awt_motif_MWindowAttributes_initIDs;
+		#Java_sun_awt_motif_MWindowPeer_pDispose;
+		#Java_sun_awt_motif_MWindowPeer_pHide;
+		#Java_sun_awt_motif_MWindowPeer_pReshape;
+		#Java_sun_awt_motif_MWindowPeer_pSetTitle;
+		#Java_sun_awt_motif_MWindowPeer_pShow;
+		#Java_sun_awt_motif_MWindowPeer_setResizable;
+		#Java_sun_awt_motif_MWindowPeer_toBack;
+		#Java_sun_awt_motif_MWindowPeer_addTextComponentNative;
+		#Java_sun_awt_motif_MWindowPeer_getState;
+		#Java_sun_awt_motif_MWindowPeer_pSetIMMOption;
+		#Java_sun_awt_motif_MWindowPeer_pSetMenuBar;
+		#Java_sun_awt_motif_MWindowPeer_pShowModal;
+		#Java_sun_awt_motif_MWindowPeer_removeTextComponentNative;
+		#Java_sun_awt_motif_MWindowPeer_setSaveUnder;
+		#Java_sun_awt_motif_MWindowPeer_setState;
+		#Java_sun_awt_motif_MWindowPeer_resetTargetGC;
+		#Java_sun_awt_motif_MWindowPeer_registerX11DropTarget;
+		#Java_sun_awt_motif_MWindowPeer_unregisterX11DropTarget;
+                #Java_sun_awt_motif_MWindowPeer_updateAlwaysOnTop;
+		#Java_sun_awt_motif_X11CustomCursor_cacheInit;
+		#Java_sun_awt_motif_X11CustomCursor_createCursor;
+		#Java_sun_awt_motif_X11CustomCursor_queryBestCursor;
+		Java_sun_awt_motif_X11FontMetrics_bytesWidth;
+		Java_sun_awt_motif_X11FontMetrics_getMFCharsWidth;
+		Java_sun_awt_motif_X11FontMetrics_init;
+		Java_sun_awt_X11InputMethod_disposeXIC;
+		Java_sun_awt_X11InputMethod_isCompositionEnabledNative;
+		Java_sun_awt_X11InputMethod_resetXIC;
+		Java_sun_awt_X11InputMethod_setCompositionEnabledNative;
+		Java_sun_awt_X11InputMethod_turnoffStatusWindow;
+		#Java_sun_awt_motif_MInputMethod_openXIMNative;
+		#Java_sun_awt_motif_MInputMethod_configureStatusAreaNative;
+		#Java_sun_awt_motif_MInputMethod_createXICNative;
+		#Java_sun_awt_motif_MInputMethod_reconfigureXICNative;
+		#Java_sun_awt_motif_MInputMethod_setXICFocusNative;
+		#Java_sun_awt_motif_X11Clipboard_getClipboardData;
+		#Java_sun_awt_motif_X11Clipboard_getClipboardFormats;
+		#Java_sun_awt_motif_X11Clipboard_registerClipboardViewer;
+		#Java_sun_awt_motif_X11Clipboard_unregisterClipboardViewer;
+		#Java_sun_awt_motif_X11Selection_init;
+		#Java_sun_awt_motif_X11Selection_pGetSelectionOwnership;
+		#Java_sun_awt_motif_X11Selection_clearNativeContext;
+		Java_sun_awt_SunToolkit_closeSplashScreen;
+		Java_sun_awt_PlatformFont_initIDs;
+		Java_sun_awt_X11GraphicsConfig_init;
+		Java_sun_awt_X11GraphicsConfig_dispose;
+		Java_sun_awt_X11GraphicsConfig_pGetBounds;
+		Java_sun_awt_X11GraphicsConfig_getNumColors;
+		Java_sun_awt_X11GraphicsConfig_getXResolution;
+		Java_sun_awt_X11GraphicsConfig_getYResolution;
+                Java_sun_awt_X11GraphicsConfig_isTranslucencyCapable;
+		Java_sun_awt_X11GraphicsDevice_isDBESupported;
+		Java_sun_awt_X11GraphicsDevice_getDisplay;
+		Java_sun_awt_X11GraphicsDevice_getDoubleBufferVisuals;
+		Java_sun_awt_X11GraphicsDevice_getNumConfigs;
+		Java_sun_awt_X11GraphicsDevice_initIDs;
+                Java_sun_awt_X11GraphicsDevice_initXrandrExtension;
+                Java_sun_awt_X11GraphicsDevice_enterFullScreenExclusive;
+                Java_sun_awt_X11GraphicsDevice_exitFullScreenExclusive;
+                Java_sun_awt_X11GraphicsDevice_getCurrentDisplayMode;
+                Java_sun_awt_X11GraphicsDevice_enumDisplayModes;
+                Java_sun_awt_X11GraphicsDevice_configDisplayMode;
+                Java_sun_awt_X11GraphicsDevice_resetNativeData;
+		Java_sun_awt_X11GraphicsEnvironment_checkShmExt;
+		Java_sun_awt_X11GraphicsEnvironment_getDefaultScreenNum;
+		Java_sun_awt_X11GraphicsEnvironment_getDisplayString;
+		Java_sun_awt_X11GraphicsEnvironment_getNumScreens;
+		Java_sun_awt_X11GraphicsEnvironment_initDisplay;
+		Java_sun_awt_X11GraphicsEnvironment_pRunningXinerama;
+		Java_sun_awt_X11GraphicsEnvironment_getXineramaCenterPoint;
+		Java_sun_awt_X11GraphicsEnvironment_initXRender;
+        
+        
+
+		Java_java_awt_AWTEvent_initIDs;
+		Java_java_awt_Button_initIDs;
+		Java_java_awt_Container_initIDs;
+		Java_java_awt_Cursor_finalizeImpl;
+		Java_java_awt_Cursor_initIDs;
+		Java_java_awt_Event_initIDs;
+		Java_java_awt_event_InputEvent_initIDs;
+		Java_java_awt_event_KeyEvent_initIDs;
+		Java_java_awt_FileDialog_initIDs;
+		Java_java_awt_Frame_initIDs;
+		Java_java_awt_Insets_initIDs;
+		Java_java_awt_TextField_initIDs;
+		Java_java_awt_Window_initIDs;
+		#Java_sun_awt_motif_MCheckboxPeer_getIndicatorSize;
+		#Java_sun_awt_motif_MCheckboxPeer_getSpacing;
+		#Java_sun_awt_motif_MChoicePeer_freeNativeData;
+		#Java_sun_awt_motif_MComponentPeer_getComponents_1NoClientCode;
+		#Java_sun_awt_motif_MComponentPeer_getParent_1NoClientCode;
+		#Java_sun_awt_motif_MComponentPeer_initIDs;
+		#Java_sun_awt_motif_MComponentPeer_nativeHandleEvent;
+		#Java_sun_awt_motif_MComponentPeer_pSetCursor;
+		#Java_sun_awt_motif_MComponentPeer_pSetInnerForeground;
+		#Java_sun_awt_motif_MComponentPeer_pSetScrollbarBackground;
+		#Java_sun_awt_motif_MComponentPeer_setTargetBackground;
+		#Java_sun_awt_motif_MDataTransferer_dragQueryFile;
+		#Java_sun_awt_motif_MDataTransferer_getAtomForTarget;
+		#Java_sun_awt_motif_MDataTransferer_getTargetNameForAtom;
+		#Java_sun_awt_motif_MFileDialogPeer_insertReplaceFileDialogText;
+		Java_sun_awt_motif_MFontPeer_initIDs;
+		#Java_sun_awt_motif_MListPeer_setBackground;
+		#Java_sun_awt_motif_MMenuBarPeer_initIDs;
+		#Java_sun_awt_motif_MMenuBarPeer_pDispose;
+		#Java_sun_awt_motif_MMenuItemPeer_getParent_1NoClientCode;
+		#Java_sun_awt_motif_MMenuItemPeer_initIDs;
+		#Java_sun_awt_motif_MMenuItemPeer_pSetShortcut;
+		#Java_sun_awt_motif_MPopupMenuPeer_initIDs;
+		#Java_sun_awt_motif_MScrollbarPeer_initIDs;
+		#Java_sun_awt_motif_MScrollPanePeer_initIDs;
+		#Java_sun_awt_motif_MTextAreaPeer_pSetCursor;
+		Java_sun_awt_motif_MToolkit_shutdown;
+		#Java_sun_awt_motif_MWindowPeer_initIDs;
+		#Java_sun_awt_motif_MWindowPeer_pCreate;
+		#Java_sun_awt_motif_MWindowPeer_wrapInSequenced;
+		Java_sun_awt_motif_X11FontMetrics_initIDs;
+		#Java_sun_awt_X11InputMethod_initIDs;
+		Java_sun_awt_motif_X11OffScreenImage_updateBitmask;
+		#Java_sun_awt_motif_X11Selection_initIDs;
+		Java_sun_awt_motif_MToolkitThreadBlockedHandler_enter;
+		Java_sun_awt_motif_MToolkitThreadBlockedHandler_exit;
+		Java_sun_awt_X11GraphicsConfig_init;
+		Java_sun_awt_X11GraphicsConfig_initIDs;
+		Java_sun_awt_X11GraphicsConfig_makeColorModel;
+		Java_sun_awt_X11GraphicsDevice_getConfigVisualId;
+		Java_sun_awt_X11PMBlitLoops_Blit;
+		Java_sun_awt_X11PMBlitBgLoops_nativeBlitBg;
+		Java_sun_awt_X11Renderer_devFillSpans;
+		Java_sun_awt_X11Renderer_doDrawArc;
+		Java_sun_awt_X11Renderer_doDrawLine;
+		Java_sun_awt_X11Renderer_doDrawOval;
+		Java_sun_awt_X11Renderer_doDrawPoly;
+		Java_sun_awt_X11Renderer_doDrawRect;
+		Java_sun_awt_X11Renderer_doDrawRoundRect;
+		Java_sun_awt_X11Renderer_doFillArc;
+		Java_sun_awt_X11Renderer_doFillOval;
+		Java_sun_awt_X11Renderer_doFillPoly;
+		Java_sun_awt_X11Renderer_doFillRect;
+		Java_sun_awt_X11Renderer_doFillRoundRect;
+		Java_sun_awt_X11Renderer_devCopyArea;
+		Java_sun_awt_X11SurfaceData_initIDs;
+		Java_sun_awt_X11SurfaceData_initOps;
+		Java_sun_awt_X11SurfaceData_initSurface;
+		Java_sun_awt_X11SurfaceData_isDgaAvailable;
+		Java_sun_awt_X11SurfaceData_setInvalid;
+		Java_sun_awt_X11SurfaceData_flushNativeSurface;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_initXEmbedServer;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_destroyXEmbedServer;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_isXEmbedActive;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_initDispatching;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_endDispatching;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_embedChild;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_childDestroyed;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_getEmbedPreferredSize;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_getEmbedMinimumSize;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_getClientBounds;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_notifyChildEmbedded;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_detachChild;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_forwardKeyEvent;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_getAWTKeyCodeForKeySym;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_sendMessage__I;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_sendMessage__IJJJ;
+                #Java_sun_awt_motif_MEmbedCanvasPeer_getWindow;       
+                #Java_sun_awt_motif_MEmbedCanvasPeer_forwardEventToEmbedded;       
+                #Java_sun_awt_motif_GrabbedKey_initKeySymAndModifiers;
+                #Java_sun_awt_motif_MEmbeddedFramePeer_traverseOut;
+		awt_display;
+		awt_lock;
+		awt_Lock;
+		awt_Unlock;
+	        awt_GetDrawingSurface;
+	        awt_FreeDrawingSurface;
+	        awt_GetComponent;
+
+		X11SurfaceData_GetOps;
+		getDefaultConfig;
+                Java_sun_font_FontConfigManager_getFontConfig;
+                Java_sun_font_FontConfigManager_getFontConfigAASettings;
+		Java_sun_awt_X11FontManager_getFontPathNative;
+		Java_sun_font_SunFontManager_populateFontFileNameMap;
+
+		# CDE private entry point
+		Java_sun_awt_motif_XsessionWMcommand;
+
+		# Java Plugin
+		getAwtLockFunctions;
+		getAwtData;
+		getAwtDisplay;
+		
+		# libfontmanager entry points
+		AWTIsHeadless;
+		AWTCountFonts;
+                AWTLoadFont;
+                AWTFreeFont;
+                AWTFontMinByte1;
+                AWTFontMaxByte1;
+                AWTFontMinCharOrByte2;
+                AWTFontMaxCharOrByte2;
+                AWTFontDefaultChar;
+                AWTFontPerChar;
+                AWTFontMaxBounds;
+                AWTFontTextExtents16;
+                AWTFreeChar;
+                AWTFontGenerateImage;
+                AWTCharAdvance;
+                AWTCharLBearing;
+                AWTCharRBearing;
+                AWTCharAscent;
+                AWTCharDescent;
+                AWTDrawGlyphList;
+                AccelGlyphCache_RemoveAllCellInfos;
+
+	local:
+		*;
+};
+
diff --git a/jdk/make/sun/awt/mawt.gmk b/jdk/make/sun/awt/mawt.gmk
index f8160ee..4c9b08f 100644
--- a/jdk/make/sun/awt/mawt.gmk
+++ b/jdk/make/sun/awt/mawt.gmk
@@ -169,7 +169,7 @@
 OTHER_LDLIBS = -lXt -lXext $(LIBXTST) $(LIBXMU) -lX11 -lXi
 endif
 
-ifeq ($(PLATFORM), linux)
+ifneq (,$(findstring $(PLATFORM), linux macosx))
 OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
 # XXX what is this define below? Isn't it motif-related?
 OTHER_CFLAGS += -DXMSTRINGDEFINES=1
@@ -180,7 +180,7 @@
 # !HEADLESS
 
 OTHER_LDLIBS += $(JVMLIB) $(LIBCXX) \
-                -lawt $(LIBM) -ldl
+                -lawt $(LIBM) $(LIBDL)
 
 #
 # Sun CC with -Xa misdefines __STDC__ to 0 (zero).
@@ -223,16 +223,35 @@
         -I$(PLATFORM_SRC)/native/$(PKGDIR) \
         $(EVENT_MODEL)
 
+ifeq ($(PLATFORM), macosx)
+CPPFLAGS += -I$(CUPS_HEADERS_PATH)
+
+ifndef HEADLESS
+CPPFLAGS += -I$(MOTIF_DIR)/include \
+            -I$(OPENWIN_HOME)/include 
+LDFLAGS  += -L$(MOTIF_LIB) -L$(OPENWIN_LIB)
+
+endif # !HEADLESS
+endif # PLATFORM
+
 ifeq ($(PLATFORM), linux)
   # Checking for the X11/extensions headers at the additional location
   CPPFLAGS += -I$(firstword $(wildcard $(OPENWIN_HOME)/include/X11/extensions) \
                         $(wildcard /usr/include/X11/extensions))
 endif
 
+ifeq ($(PLATFORM), macosx))
+  CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions \
+              -I$(OPENWIN_HOME)/include 
+endif
+
 ifeq ($(PLATFORM), solaris)
   CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions
 endif
 
+ifeq ($(PLATFORM), macosx)
+  CPPFLAGS += -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
+endif
 
 LDFLAGS += -L$(LIBDIR)/$(LIBARCH)/$(TSOBJDIR) \
 	   $(AWT_RUNPATH)
diff --git a/jdk/make/sun/cmm/lcms/Makefile b/jdk/make/sun/cmm/lcms/Makefile
index bd01f5f..e068b0e 100644
--- a/jdk/make/sun/cmm/lcms/Makefile
+++ b/jdk/make/sun/cmm/lcms/Makefile
@@ -93,7 +93,11 @@
 	$(RM) $(OBJDIR)/cmm.h
 
 else
-OTHER_LDLIBS = $(LIBM) -lawt -L$(LIBDIR)/$(LIBARCH)/xawt 
+ifeq ($(PLATFORM), macosx)
+OTHER_LDLIBS = $(LIBM) -lawt -L$(LIBDIR)/xawt
+else
+OTHER_LDLIBS = $(LIBM) -lawt -L$(LIBDIR)/$(LIBARCH)/xawt
+endif
 CPPFLAGS += -I$(SHARE_SRC)/native/sun/java2d \
             -I$(SHARE_SRC)/native/sun/awt/debug
 endif
diff --git a/jdk/make/sun/font/Makefile b/jdk/make/sun/font/Makefile
index c9cf330..293bda5 100644
--- a/jdk/make/sun/font/Makefile
+++ b/jdk/make/sun/font/Makefile
@@ -172,6 +172,15 @@
 # Libraries to link, and other C flags.
 #
 
+ifeq ($(PLATFORM), macosx))
+OTHER_INCLUDES += -I$(X11_PATH)/include
+OTHER_LDLIBS  += -lawt $(LIBM) $(LIBCXX)
+ ifeq ($(OS_VENDOR),Apple)
+   # XXXDARWIN Match BSD/Linux behavior -- the mawt.dylib symbols will
+   # be available at runtime.
+   OTHER_LDLIBS += -undefined dynamic_lookup
+ endif
+else
 ifeq ($(PLATFORM), solaris)
   # Note that on Solaris, fontmanager is built against the headless library.
   LDFLAGS      += -L$(LIBDIR)/$(LIBARCH)/headless
@@ -182,11 +191,16 @@
     OTHER_LDLIBS  += -Wl,-Bstatic -lgcc_eh -Wl,-Bdynamic
   endif                           
 endif
+endif
 
 endif # PLATFORM
 
 # set up compile flags..
 
+ifeq ($(PLATFORM), macosx))
+CPPFLAGS += -I$(CLASSHDRDIR)
+endif
+
 CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR) \
             -I$(SHARE_SRC)/native/$(PKGDIR)/layout \
 	    -I$(SHARE_SRC)/native/sun/awt/image/cvutils \
diff --git a/jdk/make/sun/headless/Makefile b/jdk/make/sun/headless/Makefile
index 233d24f..2ec48f2 100644
--- a/jdk/make/sun/headless/Makefile
+++ b/jdk/make/sun/headless/Makefile
@@ -28,7 +28,12 @@
 NO_ROBOT = true
 MOTIF_VERSION = none
 MOTIF_VERSION_STRING=none
+
+ifeq ($(PLATFORM), macosx)
+LIB_LOCATION = $(LIBDIR)/headless
+else
 LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/headless
+endif
 
 PACKAGE = sun.awt
 LIBRARY = mawt
diff --git a/jdk/make/sun/image/generic/Makefile b/jdk/make/sun/image/generic/Makefile
index d55a697..d68eae0 100644
--- a/jdk/make/sun/image/generic/Makefile
+++ b/jdk/make/sun/image/generic/Makefile
@@ -70,6 +70,6 @@
 OTHER_CFLAGS += -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES
 
 ifneq ($(PLATFORM), windows)
-	OTHER_LDLIBS = $(LIBM) -ldl
+	OTHER_LDLIBS = $(LIBM) $(LIBDL)
 endif
 
diff --git a/jdk/make/sun/image/vis/Makefile b/jdk/make/sun/image/vis/Makefile
index 688d4ef..6281803 100644
--- a/jdk/make/sun/image/vis/Makefile
+++ b/jdk/make/sun/image/vis/Makefile
@@ -68,5 +68,5 @@
 CFLAGS += $(CFLAGS_$(ARCH)) $(INLINE) -I$(PLATFORM_SRC)/native/sun/awt/medialib -I$(SHARE_SRC)/native/sun/awt/medialib
 
 OTHER_CFLAGS += -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES
-OTHER_LDLIBS = $(LIBM) -ldl
+OTHER_LDLIBS = $(LIBM) $(LIBDL)
 
diff --git a/jdk/make/sun/jawt/Makefile b/jdk/make/sun/jawt/Makefile
index afbce78..3497200 100644
--- a/jdk/make/sun/jawt/Makefile
+++ b/jdk/make/sun/jawt/Makefile
@@ -35,6 +35,8 @@
 #
 ifeq ($(PLATFORM), windows)
 FILES_cpp = jawt.cpp
+else ifeq ($(PLATFORM), macosx) # PLATFORM
+FILES_objc = jawt.m
 else # PLATFORM
 FILES_c = jawt.c
 endif # PLATFORM
@@ -108,6 +110,7 @@
 	    -I$(SHARE_SRC)/native/$(PKGDIR)/../dc/path \
             -I$(PLATFORM_SRC)/native/$(PKGDIR)/../jdga \
 	    $(EVENT_MODEL)
+
 #
 # Libraries to link in.
 #
@@ -128,8 +131,13 @@
   endif
 endif # PLATFORM
 
+ifeq ($(PLATFORM), macosx)
+vpath %.m   $(call NativeSrcDirList,,native/sun/awt)
+OTHER_LDLIBS = -llwawt -L$(LIBDIR)/lwawt -Xlinker -rpath -Xlinker @loader_path/lwawt \
+               -framework Cocoa
 endif # PLATFORM
 
+endif # PLATFORM
 
 #
 # Lets not remove any class files.
diff --git a/jdk/make/sun/jdga/Makefile b/jdk/make/sun/jdga/Makefile
index 689e466..7c3c2b5 100644
--- a/jdk/make/sun/jdga/Makefile
+++ b/jdk/make/sun/jdga/Makefile
@@ -55,7 +55,7 @@
 vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)
 
 ifneq ($(PLATFORM), windows)
-  LDLIBS =  -ldga -lX11 -ldl -lc
+  LDLIBS =  -ldga -lX11 $(LIBDL) -lc
 
   CPPFLAGS += \
 	-I$(SHARE_SRC)/javavm/export \
diff --git a/jdk/make/sun/lwawt/FILES_c_macosx.gmk b/jdk/make/sun/lwawt/FILES_c_macosx.gmk
new file mode 100644
index 0000000..05b2d14
--- /dev/null
+++ b/jdk/make/sun/lwawt/FILES_c_macosx.gmk
@@ -0,0 +1,100 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+FILES_objc = \
+        awt.m \
+        ApplicationDelegate.m \
+        CFRetainedResource.m \
+        CGLGraphicsConfig.m \
+        CGLSurfaceData.m \
+        CGLLayer.m \
+        CGraphicsConfig.m \
+        CGraphicsDevice.m \
+        CGraphicsEnv.m \
+        CCharToGlyphMapper.m \
+        CSystemColors.m \
+        AWTFont.m \
+        CGGlyphOutlines.m \
+        CGGlyphImages.m \
+        CoreTextSupport.m \
+        AWTStrike.m \
+        InitIDs.m \
+        AWTEvent.m \
+        AWTView.m \
+        AWTWindow.m \
+	AWTSurfaceLayers.m \
+        CCursorManager.m \
+        CClipboard.m \
+        CDataTransferer.m \
+        CDragSource.m \
+        CDragSourceContextPeer.m \
+        CDropTarget.m \
+        CDropTargetContextPeer.m \
+        CInputMethod.m \
+				CDesktopPeer.m \
+        OSVersion.m \
+        DnDUtilities.m \
+        CFileDialog.m \
+        CImage.m \
+        CMenu.m \
+        CMenuBar.m \
+        CMenuComponent.m \
+        CMenuItem.m \
+        CPopupMenu.m \
+        CRobot.m \
+        CTrayIcon.m \
+        CWrapper.m \
+        JavaAccessibilityAction.m \
+        JavaAccessibilityUtilities.m \
+        JavaComponentAccessibility.m \
+        JavaTextAccessibility.m \
+        LWCToolkit.m \
+        GeomUtilities.m \
+        CPrinterJob.m \
+        PrintModel.m \
+        PrinterSurfaceData.m \
+        PrinterView.m \
+        QuartzSurfaceData.m \
+        QuartzRenderer.m \
+        CTextPipe.m \
+        ImageSurfaceData.m \
+        awt_DrawingSurface.m
+
+FILES_c = \
+        OGLBlitLoops.c \
+        OGLBufImgOps.c \
+        OGLContext.c \
+        OGLFuncs.c \
+        OGLMaskBlit.c \
+        OGLMaskFill.c \
+        OGLPaints.c \
+        OGLRenderQueue.c \
+        OGLRenderer.c \
+        OGLSurfaceData.c \
+        OGLTextRenderer.c \
+        OGLVertexCache.c \
+        AccelGlyphCache.c \
+        CUPSfuncs.c
+
diff --git a/jdk/make/sun/lwawt/FILES_export_macosx.gmk b/jdk/make/sun/lwawt/FILES_export_macosx.gmk
new file mode 100644
index 0000000..6ffbe12
--- /dev/null
+++ b/jdk/make/sun/lwawt/FILES_export_macosx.gmk
@@ -0,0 +1,276 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# FILES_export definitions for Mac OS X
+
+FILES_export = \
+        com/apple/eawt/Application.java \
+        com/apple/eawt/_AppDockIconHandler.java \
+        com/apple/eawt/_AppEventHandler.java \
+        com/apple/eawt/_AppEventLegacyHandler.java \
+        com/apple/eawt/_AppMenuBarHandler.java \
+        com/apple/eawt/_AppMiscHandlers.java \
+        com/apple/eawt/event/GestureHandler.java \
+        com/apple/eawt/FullScreenAdapter.java \
+        com/apple/eawt/FullScreenHandler.java \
+        com/apple/eawt/FullScreenListener.java \
+        com/apple/eawt/FullScreenUtilities.java \
+        sun/font/FontManager.java \
+        sun/awt/image/ImageRepresentation.java \
+        sun/awt/image/GifImageDecoder.java \
+        sun/awt/image/NativeLibLoader.java \
+        sun/java2d/CRenderer.java \
+        sun/java2d/CompositeCRenderer.java \
+        sun/java2d/DataBufferNIOInt.java \
+        sun/java2d/IntegerNIORaster.java \
+        sun/java2d/OSXSurfaceData.java \
+        sun/java2d/OSXOffScreenSurfaceData.java \
+        sun/java2d/loops/Blit.java \
+        sun/java2d/loops/BlitBg.java \
+        sun/java2d/loops/ScaledBlit.java \
+        sun/java2d/loops/TransformBlit.java \
+        sun/java2d/loops/FillRect.java \
+        sun/java2d/loops/FillSpans.java \
+        sun/java2d/loops/FillParallelogram.java \
+        sun/java2d/loops/DrawParallelogram.java \
+        sun/java2d/loops/DrawGlyphList.java \
+        sun/java2d/loops/DrawGlyphListAA.java \
+        sun/java2d/loops/DrawGlyphListLCD.java \
+        sun/java2d/loops/DrawLine.java \
+        sun/java2d/loops/DrawRect.java \
+        sun/java2d/loops/DrawPolygons.java \
+        sun/java2d/loops/DrawPath.java \
+        sun/java2d/loops/FillPath.java \
+        sun/java2d/loops/MaskBlit.java \
+        sun/java2d/loops/MaskFill.java \
+        sun/java2d/loops/TransformHelper.java \
+        sun/java2d/loops/GraphicsPrimitiveMgr.java \
+        sun/java2d/loops/GraphicsPrimitive.java \
+        sun/java2d/pipe/hw/AccelSurface.java \
+        sun/java2d/pipe/hw/AccelDeviceEventNotifier.java \
+        sun/java2d/pipe/hw/ContextCapabilities.java \
+        sun/awt/image/ImagingLib.java \
+        sun/java2d/SurfaceData.java \
+        sun/java2d/SunGraphics2D.java \
+        sun/awt/KeyboardFocusManagerPeerImpl.java \
+        sun/awt/image/BufImgSurfaceData.java \
+        sun/awt/image/DataBufferNative.java \
+        \
+        sun/awt/CGraphicsConfig.java \
+        sun/awt/CGraphicsDevice.java \
+        sun/awt/CGraphicsEnvironment.java \
+        sun/font/CCharToGlyphMapper.java \
+        sun/font/CFont.java \
+        sun/font/CFontConfiguration.java \
+        sun/font/CFontManager.java \
+        sun/font/CStrike.java \
+        sun/font/CStrikeDisposer.java \
+        sun/java2d/BackBufferCapsProvider.java \
+        sun/java2d/MacosxSurfaceManagerFactory.java \
+        sun/lwawt/LWButtonPeer.java \
+        sun/lwawt/LWCanvasPeer.java \
+        sun/lwawt/LWCheckboxPeer.java \
+        sun/lwawt/LWChoicePeer.java \
+        sun/lwawt/LWComponentPeer.java \
+        sun/lwawt/LWContainerPeer.java \
+        sun/lwawt/LWCursorManager.java \
+        sun/lwawt/LWKeyboardFocusManagerPeer.java \
+        sun/lwawt/LWLabelPeer.java \
+        sun/lwawt/LWListPeer.java \
+        sun/lwawt/LWMouseInfoPeer.java \
+        sun/lwawt/LWPanelPeer.java \
+        sun/lwawt/LWRepaintArea.java \
+        sun/lwawt/LWScrollBarPeer.java \
+        sun/lwawt/LWScrollPanePeer.java \
+        sun/lwawt/LWTextComponentPeer.java \
+        sun/lwawt/LWTextFieldPeer.java \
+        sun/lwawt/LWToolkit.java \
+        sun/lwawt/LWWindowPeer.java \
+        sun/lwawt/PlatformWindow.java \
+        sun/lwawt/SelectionClearListener.java \
+        sun/lwawt/macosx/CPrinterDevice.java \
+        sun/lwawt/macosx/CPrinterDialog.java \
+        sun/lwawt/macosx/CPrinterDialogPeer.java \
+        sun/lwawt/macosx/CPrinterGraphics.java \
+        sun/lwawt/macosx/CPrinterGraphicsConfig.java \
+        sun/lwawt/macosx/CPrinterJob.java \
+        sun/lwawt/macosx/CPrinterJobDialog.java \
+        sun/lwawt/macosx/CPrinterPageDialog.java \
+        sun/lwawt/macosx/CPrinterSurfaceData.java \
+        sun/lwawt/macosx/CTextPipe.java \
+        sun/lwawt/macosx/CDesktopPeer.java \
+        sun/java2d/CRenderer.java \
+        sun/lwawt/macosx/EventDispatchAccess.java \
+        sun/lwawt/macosx/NSPrintInfo.java \
+        sun/lwawt/macosx/CAccessibility.java \
+        sun/lwawt/macosx/CAccessible.java \
+        sun/lwawt/macosx/CFRetainedResource.java \
+        sun/lwawt/macosx/CCheckboxMenuItem.java \
+        sun/lwawt/macosx/CClipboard.java \
+        sun/lwawt/macosx/CDataTransferer.java \
+        sun/lwawt/macosx/CDragSourceContextPeer.java \
+        sun/lwawt/macosx/CMouseDragGestureRecognizer.java \
+        sun/lwawt/macosx/CDropTarget.java \
+        sun/lwawt/macosx/CDropTargetContextPeer.java \
+        sun/lwawt/macosx/CCursorManager.java \
+        sun/lwawt/macosx/CFileDialog.java \
+        sun/lwawt/macosx/CImage.java \
+        sun/lwawt/macosx/CMenu.java \
+        sun/lwawt/macosx/CMenuBar.java \
+        sun/lwawt/macosx/CMenuComponent.java \
+        sun/lwawt/macosx/CMenuItem.java \
+        sun/lwawt/macosx/CMouseInfoPeer.java \
+        sun/lwawt/macosx/CPlatformView.java \
+        sun/lwawt/macosx/CPlatformWindow.java \
+        sun/lwawt/macosx/CPlatformComponent.java \
+        sun/lwawt/macosx/CPopupMenu.java \
+        sun/lwawt/macosx/CRobot.java \
+        sun/lwawt/macosx/CSystemTray.java \
+        sun/lwawt/macosx/CTrayIcon.java \
+        sun/lwawt/macosx/CWrapper.java \
+        sun/lwawt/macosx/CocoaConstants.java \
+        sun/lwawt/macosx/LWCToolkit.java \
+        sun/lwawt/macosx/CInputMethod.java \
+        sun/lwawt/macosx/CInputMethodDescriptor.java \
+        sun/lwawt/macosx/event/NSEvent.java \
+        \
+        sun/awt/DebugSettings.java \
+        sun/awt/EmbeddedFrame.java \
+        sun/awt/PlatformFont.java \
+        sun/awt/FontDescriptor.java \
+        sun/awt/NativeLibLoader.java \
+        sun/awt/CharsetString.java \
+        sun/awt/SunHints.java \
+        sun/java2d/pipe/BufferedContext.java \
+        sun/java2d/pipe/BufferedMaskBlit.java \
+        sun/java2d/pipe/BufferedOpCodes.java \
+        sun/java2d/pipe/BufferedMaskBlit.java \
+        sun/java2d/pipe/BufferedPaints.java \
+        sun/java2d/pipe/BufferedRenderPipe.java \
+        sun/java2d/pipe/BufferedTextPipe.java \
+        sun/java2d/pipe/RenderBuffer.java \
+        sun/java2d/pipe/ShapeSpanIterator.java \
+        sun/java2d/pipe/SpanClipRenderer.java \
+        sun/java2d/pipe/RegionIterator.java \
+        sun/awt/image/IntegerComponentRaster.java \
+        sun/java2d/cmm/CMSManager.java \
+        sun/java2d/cmm/PCMM.java \
+        sun/java2d/cmm/ColorTransform.java \
+        sun/awt/datatransfer/DataTransferer.java \
+        sun/awt/dnd/SunDragSourceContextPeer.java \
+        sun/java2d/opengl/OGLBlitLoops.java \
+        sun/java2d/opengl/OGLContext.java \
+        sun/java2d/opengl/OGLMaskFill.java \
+        sun/java2d/opengl/OGLPaints.java \
+        sun/java2d/opengl/OGLRenderer.java \
+        sun/java2d/opengl/OGLRenderQueue.java \
+        sun/java2d/opengl/OGLSurfaceData.java \
+        sun/java2d/opengl/OGLTextRenderer.java \
+        sun/java2d/opengl/CGLGraphicsConfig.java \
+        sun/java2d/opengl/CGLSurfaceData.java \
+        sun/java2d/opengl/CGLLayer.java \
+        sun/awt/ExtendedKeyCodes.java 
+
+FILES_export2 = \
+        java/awt/AlphaComposite.java \
+        java/awt/MouseInfo.java \
+        java/awt/Cursor.java \
+        java/awt/Graphics.java \
+        java/awt/Color.java \
+        java/awt/Image.java \
+        java/awt/Rectangle.java \
+        java/awt/Event.java \
+        java/awt/Font.java \
+        java/awt/Insets.java \
+        java/awt/Point.java \
+        java/awt/FontMetrics.java \
+        java/awt/Toolkit.java \
+        java/awt/Component.java \
+        java/awt/Container.java \
+        java/awt/Canvas.java \
+        java/awt/Button.java \
+        java/awt/List.java \
+        java/awt/Adjustable.java \
+        java/awt/Scrollbar.java \
+        java/awt/ScrollPane.java \
+        java/awt/ScrollPaneAdjustable.java \
+        java/awt/Window.java \
+        java/awt/TextField.java \
+        java/awt/Label.java \
+        java/awt/Choice.java \
+        java/awt/TextArea.java \
+        java/awt/MenuBar.java \
+        java/awt/Menu.java \
+        java/awt/MenuComponent.java \
+        java/awt/PopupMenu.java \
+        java/awt/Dialog.java \
+        java/awt/FileDialog.java \
+        java/awt/MenuItem.java \
+        java/awt/Checkbox.java \
+        java/awt/CheckboxMenuItem.java \
+        java/awt/CheckboxGroup.java \
+        java/awt/Frame.java \
+        java/awt/Transparency.java \
+        java/awt/AWTException.java \
+        java/awt/AWTEvent.java \
+        java/awt/AWTKeyStroke.java \
+        java/awt/KeyboardFocusManager.java \
+        java/awt/Dimension.java \
+        java/awt/SystemColor.java \
+        java/awt/TrayIcon.java \
+        java/awt/DisplayMode.java \
+        java/awt/color/ColorSpace.java \
+        java/awt/color/ICC_Profile.java \
+        java/awt/geom/PathIterator.java \
+        java/awt/image/AffineTransformOp.java \
+        java/awt/image/ImageConsumer.java \
+        java/awt/image/ImageObserver.java \
+        java/awt/image/BufferedImage.java \
+        java/awt/image/ColorModel.java \
+        java/awt/image/ConvolveOp.java \
+        java/awt/image/DirectColorModel.java \
+        java/awt/image/IndexColorModel.java \
+        java/awt/image/DataBuffer.java \
+        java/awt/datatransfer/Transferable.java \
+        java/awt/datatransfer/DataFlavor.java \
+        java/awt/datatransfer/UnsupportedFlavorException.java \
+        java/awt/datatransfer/Clipboard.java \
+        java/awt/datatransfer/ClipboardOwner.java \
+        java/awt/datatransfer/StringSelection.java \
+        java/awt/event/AdjustmentEvent.java \
+        java/awt/event/KeyEvent.java \
+        java/awt/event/MouseEvent.java \
+        java/awt/event/MouseWheelEvent.java \
+        java/awt/event/FocusEvent.java \
+        java/awt/event/InputEvent.java \
+        java/awt/event/WindowEvent.java \
+        java/awt/event/NativeLibLoader.java \
+        java/awt/peer/ComponentPeer.java \
+        java/awt/dnd/DnDConstants.java \
+        sun/awt/CausedFocusEvent.java \
+        java/awt/print/PageFormat.java \
+        java/awt/print/Pageable.java \
+        java/awt/print/Printable.java \
+        java/awt/BasicStroke.java
diff --git a/jdk/make/sun/lwawt/Makefile b/jdk/make/sun/lwawt/Makefile
new file mode 100644
index 0000000..d02ae6f
--- /dev/null
+++ b/jdk/make/sun/lwawt/Makefile
@@ -0,0 +1,115 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../..
+MODULE  = awt
+PACKAGE = sun.lwawt
+LIBRARY = lwawt
+PRODUCT = sun
+
+LIB_LOCATION = $(LIBDIR)/lwawt
+
+include $(BUILDDIR)/common/Defs.gmk
+
+#
+# Files
+#
+include FILES_c_macosx.gmk
+include FILES_export_macosx.gmk
+AUTO_FILES_JAVA_DIRS = sun/awt sun/font sun/lwawt sun/lwawt/macosx sun/java2d sun/java2d/opengl com/apple/eawt
+
+#
+# Rules.
+#
+# include $(BUILDDIR)/common/Mapfile-vers.gmk
+include $(BUILDDIR)/common/Library.gmk
+
+#
+# Add to the ambient vpath to pick up files in subdirectories
+#
+vpath %.c   $(SHARE_SRC)/native/sun/awt/debug
+vpath %.c   $(SHARE_SRC)/native/sun/awt/image
+vpath %.c   $(SHARE_SRC)/native/sun/awt/image/gif
+vpath %.c   $(SHARE_SRC)/native/sun/awt/image/cvutils
+vpath %.c   $(SHARE_SRC)/native/sun/awt/shell
+vpath %.c   $(SHARE_SRC)/native/sun/java2d
+vpath %.c   $(SHARE_SRC)/native/sun/java2d/loops
+vpath %.c   $(SHARE_SRC)/native/sun/java2d/pipe
+vpath %.c   $(SHARE_SRC)/native/sun/java2d/opengl
+vpath %.c   $(SHARE_SRC)/native/sun/awt/medialib
+vpath %.c   $(SHARE_SRC)/native/sun/awt/utility
+vpath %.c   $(SHARE_SRC)/native/sun/font
+vpath %.c   $(call NativeSrcDirList,,native/sun/awt)
+
+vpath %.cpp $(SHARE_SRC)/native/sun/image
+
+vpath %.m   $(call NativeSrcDirList,,native/sun/awt)
+vpath %.m   $(call NativeSrcDirList,,native/sun/font)
+vpath %.m   $(call NativeSrcDirList,,native/sun/java2d)
+vpath %.m   $(call NativeSrcDirList,,native/sun/java2d/opengl)
+
+OTHER_LDLIBS += \
+	-lawt -lmlib_image -losxapp $(JVMLIB) $(LIBM) \
+	-framework Accelerate \
+	-framework ApplicationServices \
+	-framework AudioToolbox \
+	-framework Carbon \
+	-framework Cocoa \
+	-framework Security \
+	-framework ExceptionHandling \
+	-framework JavaNativeFoundation \
+	-framework JavaRuntimeSupport \
+	-framework OpenGL \
+	-framework IOSurface \
+        -framework QuartzCore
+CPPFLAGS += \
+        -I$(CLASSHDRDIR) \
+        -I$(SHARE_SRC)/native/sun/awt/debug \
+        -I$(SHARE_SRC)/native/sun/awt/image/cvutils \
+        -I$(SHARE_SRC)/native/sun/java2d \
+	-I$(SHARE_SRC)/native/sun/java2d/loops \
+	-I$(SHARE_SRC)/native/sun/awt/image/cvutils \
+	-I$(SHARE_SRC)/native/sun/awt/image \
+	-I$(SHARE_SRC)/native/sun/font \
+	-I$(SHARE_SRC)/native/sun/java2d/pipe \
+	-I$(SHARE_SRC)/native/sun/java2d/opengl \
+	-I$(SHARE_SRC)/native/sun/dc/path \
+	-I$(SHARE_SRC)/native/sun/dc/doe \
+	-I$(SHARE_SRC)/native/sun/awt/alphacomposite \
+        -I$(SHARE_SRC)/native/sun/awt/medialib \
+        -I$(SHARE_SRC)/native/sun/awt \
+        $(call NativeSrcDirList,-I,/native/sun/awt) \
+        $(call NativeSrcDirList,-I,/native/sun/osxapp) \
+        $(call NativeSrcDirList,-I,/native/sun/font) \
+	$(call NativeSrcDirList,-I,/native/sun/java2d) \
+	$(call NativeSrcDirList,-I,/native/sun/java2d/opengl)
+
+ifeq ($(MILESTONE), internal)
+  CPPFLAGS += -DINTERNAL_BUILD
+endif
+
+clean clobber::
+
+.PHONY:
diff --git a/jdk/make/sun/osxapp/Makefile b/jdk/make/sun/osxapp/Makefile
new file mode 100644
index 0000000..7c47edd
--- /dev/null
+++ b/jdk/make/sun/osxapp/Makefile
@@ -0,0 +1,75 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../..
+LIBRARY = osxapp
+PRODUCT = sun
+include $(BUILDDIR)/common/Defs.gmk
+
+#
+# Files
+#
+FILES_objc = \
+	NSApplicationAWT.m \
+	QueuingApplicationDelegate.m \
+	PropertiesUtilities.m \
+	ThreadUtilities.m
+
+#
+# Rules.
+#
+include $(BUILDDIR)/common/Library.gmk
+
+#
+# Add to the ambient vpath to pick up files in subdirectories
+#
+vpath %.m   $(call NativeSrcDirList,,native/sun/osxapp)
+
+# TODO: perhaps not all of the below frameworks are required
+OTHER_LDLIBS += \
+	-framework Accelerate \
+	-framework ApplicationServices \
+	-framework AudioToolbox \
+	-framework Carbon \
+	-framework Cocoa \
+	-framework Security \
+	-framework ExceptionHandling \
+	-framework JavaNativeFoundation \
+	-framework JavaRuntimeSupport \
+	-framework OpenGL \
+	-framework IOSurface \
+	-framework QuartzCore
+
+CPPFLAGS += \
+        $(call NativeSrcDirList,-I,/native/sun/osxapp)
+
+
+ifeq ($(MILESTONE), internal)
+  CPPFLAGS += -DINTERNAL_BUILD
+endif
+
+clean clobber::
+
+.PHONY:
diff --git a/jdk/make/sun/security/ec/Makefile b/jdk/make/sun/security/ec/Makefile
index b0d4090..da2119a 100644
--- a/jdk/make/sun/security/ec/Makefile
+++ b/jdk/make/sun/security/ec/Makefile
@@ -192,7 +192,7 @@
   ifeq ($(PLATFORM), windows)
     OTHER_LDLIBS += $(JVMLIB)
   else
-    OTHER_LDLIBS = -ldl $(JVMLIB) $(LIBCXX)
+    OTHER_LDLIBS = $(LIBDL) $(JVMLIB) $(LIBCXX)
   endif
 
   include $(BUILDDIR)/common/Mapfile-vers.gmk
diff --git a/jdk/make/sun/security/jgss/wrapper/Makefile b/jdk/make/sun/security/jgss/wrapper/Makefile
index c7c0a6a..b2dea89 100644
--- a/jdk/make/sun/security/jgss/wrapper/Makefile
+++ b/jdk/make/sun/security/jgss/wrapper/Makefile
@@ -72,5 +72,5 @@
 # Libraries to link
 #
 ifneq ($(PLATFORM), windows)
-  OTHER_LDLIBS = -ldl $(JVMLIB)
+  OTHER_LDLIBS = $(LIBDL) $(JVMLIB)
 endif
diff --git a/jdk/make/sun/security/krb5/Makefile b/jdk/make/sun/security/krb5/Makefile
index 3b6d4f6..b785dc8 100644
--- a/jdk/make/sun/security/krb5/Makefile
+++ b/jdk/make/sun/security/krb5/Makefile
@@ -75,7 +75,7 @@
 ifeq ($(PLATFORM), windows)
   OTHER_LDLIBS = $(JVMLIB)
 else
-  OTHER_LDLIBS = -ldl $(JVMLIB)
+  OTHER_LDLIBS = $(LIBDL) $(JVMLIB)
 endif
 
 build:
diff --git a/jdk/make/sun/security/pkcs11/Makefile b/jdk/make/sun/security/pkcs11/Makefile
index a63198f..2dcc8d7 100644
--- a/jdk/make/sun/security/pkcs11/Makefile
+++ b/jdk/make/sun/security/pkcs11/Makefile
@@ -159,7 +159,7 @@
 ifeq ($(PLATFORM), windows)
   OTHER_LDLIBS = $(JVMLIB)
 else
-  OTHER_LDLIBS = -ldl $(JVMLIB)
+  OTHER_LDLIBS = $(LIBDL) $(JVMLIB)
 endif
 
 # Other config files
diff --git a/jdk/make/sun/security/smartcardio/Makefile b/jdk/make/sun/security/smartcardio/Makefile
index 75b315d..95ecce5 100644
--- a/jdk/make/sun/security/smartcardio/Makefile
+++ b/jdk/make/sun/security/smartcardio/Makefile
@@ -75,6 +75,6 @@
 ifeq ($(PLATFORM), windows)
   OTHER_LDLIBS = $(JVMLIB) winscard.lib
 else
-  OTHER_LDLIBS = -ldl $(JVMLIB)
+  OTHER_LDLIBS = $(LIBDL) $(JVMLIB)
   OTHER_CFLAGS = -D__sun_jdk
 endif
diff --git a/jdk/make/sun/splashscreen/FILES_c.gmk b/jdk/make/sun/splashscreen/FILES_c.gmk
index a7684a2..02a904d 100644
--- a/jdk/make/sun/splashscreen/FILES_c.gmk
+++ b/jdk/make/sun/splashscreen/FILES_c.gmk
@@ -49,18 +49,6 @@
 	dgif_lib.c \
 	gif_err.c \
 	gifalloc.c \
-	compress.c \
-	deflate.c \
-	gzio.c \
-	infback.c \
-	inffast.c \
-	inflate.c \
-	inftrees.c \
-	trees.c \
-	uncompr.c \
-	zadler32.c \
-	zcrc32.c \
-	zutil.c \
 	jcomapi.c \
 	jdapimin.c \
 	jdapistd.c \
@@ -106,3 +94,18 @@
 	jfdctfst.c \
 	jfdctint.c
 
+ifneq ($(SYSTEM_ZLIB),true)
+  FILES_c += \
+	compress.c \
+	deflate.c \
+	gzio.c \
+	infback.c \
+	inffast.c \
+	inflate.c \
+	inftrees.c \
+	trees.c \
+	uncompr.c \
+	zadler32.c \
+	zcrc32.c \
+	zutil.c
+endif
diff --git a/jdk/make/sun/splashscreen/Makefile b/jdk/make/sun/splashscreen/Makefile
index 294fee4..5b0e18a 100644
--- a/jdk/make/sun/splashscreen/Makefile
+++ b/jdk/make/sun/splashscreen/Makefile
@@ -61,10 +61,37 @@
 
 CFLAGS += -DSPLASHSCREEN
 
-ifneq ($(PLATFORM), windows)
+ifeq ($(PLATFORM), macosx)
+  CFLAGS += -DWITH_MACOSX
+
+  # CFLAGS and CPPFLAGS are added when linking as well, so we use VARIANT
+  # instead to specify that we're actually compiling objective-c code here
+  CFLAGS_$(VARIANT)/java_awt_SplashScreen.o = -x objective-c
+  CFLAGS_$(VARIANT)/splashscreen_gfx_impl.o = -x objective-c
+  CFLAGS_$(VARIANT)/splashscreen_gif.o = -x objective-c
+  CFLAGS_$(VARIANT)/splashscreen_impl.o = -x objective-c
+  CFLAGS_$(VARIANT)/splashscreen_jpeg.o = -x objective-c
+  CFLAGS_$(VARIANT)/splashscreen_png.o = -x objective-c
+  CFLAGS_$(VARIANT)/splashscreen_sys.o = -x objective-c
+
+  OTHER_CFLAGS += -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks
+  CPPFLAGS += -I/System/Library/Frameworks/AppKit.framework/Versions/C/Headers
+  OTHER_LDLIBS += $(LIBM) -lpthread -liconv -losxapp \
+				  -framework ApplicationServices \
+				  -framework Foundation \
+				  -framework Cocoa \
+				  -framework JavaNativeFoundation
+else ifneq ($(PLATFORM), windows)
   CFLAGS += -DWITH_X11
-  CPPFLAGS += -I$(OPENWIN_HOME)/include -I$(OPENWIN_HOME)/include/X11/extensions
-  OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpthread
+  ifeq ($(PLATFORM), macosx))
+    OTHER_LDLIBS += -liconv
+    CPPFLAGS += -I$(OPENWIN_HOME)/include \
+                -I$(OPENWIN_HOME)/include/X11/extensions
+    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -pthread
+  else
+    CPPFLAGS += -I$(OPENWIN_HOME)/include -I$(OPENWIN_HOME)/include/X11/extensions
+    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpthread
+  endif
 else # PLATFORM
   CFLAGS += -DWITH_WIN32
   OTHER_LDLIBS += kernel32.lib user32.lib gdi32.lib delayimp.lib /DELAYLOAD:user32.dll
@@ -77,13 +104,30 @@
 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/splashscreen
 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)
 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/giflib
-vpath %.c   $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+ifneq ($(SYSTEM_ZLIB),true)
+  vpath %.c   $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+endif
 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/libpng
 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/image/jpeg
-vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen
+ifneq ($(PLATFORM), macosx)
+  vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen
+else
+  vpath %.m   $(call NativeSrcDirList,,native/$(PKGDIR)/splashscreen)
+endif
 
-CPPFLAGS += -I$(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen -I$(SHARE_SRC)/native/$(PKGDIR)/splashscreen
-CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/image/jpeg -I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+ifneq ($(PLATFORM), macosx)
+  CPPFLAGS += -I$(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen
+else
+  CPPFLAGS += $(call NativeSrcDirList,-I,native/$(PKGDIR)/splashscreen)
+  CPPFLAGS += $(call NativeSrcDirList,-I,/native/sun/osxapp)
+endif
+CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/splashscreen
+CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/image/jpeg
+ifneq ($(SYSTEM_ZLIB),true)
+  CPPFLAGS += -I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+else
+  OTHER_LDLIBS += -lz
+endif
 
 # Shun the less than portable MMX assembly code in pnggccrd.c,
 # and use alternative implementations in C.
diff --git a/jdk/make/sun/tracing/dtrace/Makefile b/jdk/make/sun/tracing/dtrace/Makefile
index 0729876..bf4d68b 100644
--- a/jdk/make/sun/tracing/dtrace/Makefile
+++ b/jdk/make/sun/tracing/dtrace/Makefile
@@ -55,7 +55,7 @@
 FILES_export = $(FILES_java)
 
 ifeq ($(PLATFORM), linux)
-OTHER_LDLIBS += -ldl
+OTHER_LDLIBS += $(LIBDL)
 endif
 
 #
diff --git a/jdk/make/sun/xawt/Makefile b/jdk/make/sun/xawt/Makefile
index cf322d9..b0ca149 100644
--- a/jdk/make/sun/xawt/Makefile
+++ b/jdk/make/sun/xawt/Makefile
@@ -27,9 +27,14 @@
 PACKAGE = sun.awt.X11
 LIBRARY = mawt
 LIBRARY_OUTPUT = xawt
-LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/xawt
 PRODUCT = sun
 
+ifeq ($(PLATFORM), macosx)
+LIB_LOCATION = $(LIBDIR)/xawt
+else
+LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/xawt
+endif
+
 include $(BUILDDIR)/common/Defs.gmk
 
 GEN_DIR=$(GENSRCDIR)/sun/awt/X11
@@ -58,6 +63,11 @@
 dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
 endif
 
+ifeq ($(PLATFORM), macosx))
+LDFLAGS += -pthread
+dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
+endif
+
 # Since this library will be living in a subdirectory below the other libraries
 #   we need to add an extra runpath so that libraries in the upper directory
 #   are found at runtime.
@@ -92,7 +102,7 @@
 vpath %.c   $(PLATFORM_SRC)/native/sun/java2d/opengl
 vpath %.c   $(PLATFORM_SRC)/native/sun/java2d/x11
 
-OTHER_LDLIBS = $(LIBM) -lawt -lXext -lX11 -lXrender -ldl \
+OTHER_LDLIBS = $(LIBM) -lawt -lXext -lX11 -lXrender $(LIBDL) \
                    $(LDFLAGS_COMMON) $(AWT_RUNPATH) $(OTHER_LDFLAGS) -lXtst -lXi
 
 ifeq  ($(PLATFORM), solaris)
@@ -163,6 +173,10 @@
  endif
 endif
 
+ifeq ($(PLATFORM), macosx)
+  CPPFLAGS += -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
+endif
+
 ifeq ($(MILESTONE), internal)
   CPPFLAGS += -DINTERNAL_BUILD
 endif
@@ -207,6 +221,13 @@
 
 else # !solaris
 
+ifeq ($(PLATFORM), macosx)
+CFLAGS_32=-arch i386
+SIZERS = $(SIZER).32 $(SIZER).64
+SIZERS_C = $(SIZER_32_C) $(SIZER_64_C)
+SIZES = $(WRAPPER_GENERATOR_DIR)/sizes.32 $(WRAPPER_GENERATOR_DIR)/sizes.64
+CFLAGS_64=-arch x86_64
+else # !macosx
 ifeq ($(ARCH_DATA_MODEL), 32)
 SIZERS = $(SIZER).32
 SIZERS_C = $(SIZER_32_C)
@@ -216,7 +237,7 @@
 SIZERS_C = $(SIZER_64_C)
 SIZES = $(WRAPPER_GENERATOR_DIR)/sizes.64
 endif # 32
-
+endif # !macosx
 endif # solaris
 
 # XXX Hack for 6185483 - use hard-coded sizes.
diff --git a/jdk/make/sun/xawt/mapfile-vers b/jdk/make/sun/xawt/mapfile-vers
index 8a12b69..abf2cc3 100644
--- a/jdk/make/sun/xawt/mapfile-vers
+++ b/jdk/make/sun/xawt/mapfile-vers
@@ -322,6 +322,8 @@
         Java_sun_awt_X11_XlibWrapper_XSynchronize;
         Java_java_awt_FileDialog_initIDs;
         Java_sun_awt_X11_XWindow_initIDs;
+        Java_sun_awt_X11_XWindowPeer_getLocalHostname;
+        Java_sun_awt_X11_XWindowPeer_getJvmPID;
 
         Java_sun_java2d_opengl_OGLContext_getOGLIdString;
         Java_sun_java2d_opengl_OGLMaskFill_maskFill;
diff --git a/jdk/make/tools/freetypecheck/Makefile b/jdk/make/tools/freetypecheck/Makefile
index dcacde5..a789fa1 100644
--- a/jdk/make/tools/freetypecheck/Makefile
+++ b/jdk/make/tools/freetypecheck/Makefile
@@ -49,8 +49,12 @@
   # Add runtime lib search path to ensure test will be runnable
   ifeq ($(PLATFORM), solaris)
     FT_LD_OPTIONS += -R $(FREETYPE_LIB_PATH) -lfreetype
-  else #linux
+  else 
+    ifeq ($(PLATFORM), macosx)
+      FT_LD_OPTIONS += -lfreetype -lz
+    else # linux
       FT_LD_OPTIONS += -Wl,-rpath -Wl,$(FREETYPE_LIB_PATH) -lfreetype
+    endif
   endif
 endif
 FT_OPTIONS += -I$(FREETYPE_HEADERS_PATH)
diff --git a/jdk/make/tools/reorder/Makefile b/jdk/make/tools/reorder/Makefile
index 4ffa9e5..3899bc7 100644
--- a/jdk/make/tools/reorder/Makefile
+++ b/jdk/make/tools/reorder/Makefile
@@ -185,11 +185,11 @@
 
 # This library 'libmcount.so' also used by hotspot reordering.
 $(OBJDIR)/libmcount.so : $(MCOUNT_OBJ)
-	$(CC) -G -mt -zdefs -o $@ $^ -ldl -lelf $(EXTRA_LIBS)
+	$(CC) -G -mt -zdefs -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
 
 # This library 'libmcount.so' also used by hotspot reordering.
 $(OBJDIR)/remove_mcount : remove_mcount.c
-	$(CC) -g -o $@ $^ -ldl -lelf $(EXTRA_LIBS)
+	$(CC) -g -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
 
 
 # Reorder libraries.
diff --git a/jdk/make/tools/sharing/classlist.macosx b/jdk/make/tools/sharing/classlist.macosx
new file mode 100644
index 0000000..d07236d
--- /dev/null
+++ b/jdk/make/tools/sharing/classlist.macosx
@@ -0,0 +1,2406 @@
+java/lang/Object
+java/lang/String
+java/io/Serializable
+java/lang/Comparable
+java/lang/CharSequence
+java/lang/Class
+java/lang/reflect/GenericDeclaration
+java/lang/reflect/Type
+java/lang/reflect/AnnotatedElement
+java/lang/Cloneable
+java/lang/ClassLoader
+java/lang/System
+java/lang/Throwable
+java/lang/Error
+java/lang/ThreadDeath
+java/lang/Exception
+java/lang/RuntimeException
+java/security/ProtectionDomain
+java/security/AccessControlContext
+java/lang/ClassNotFoundException
+java/lang/NoClassDefFoundError
+java/lang/LinkageError
+java/lang/ClassCastException
+java/lang/ArrayStoreException
+java/lang/VirtualMachineError
+java/lang/OutOfMemoryError
+java/lang/StackOverflowError
+java/lang/IllegalMonitorStateException
+java/lang/ref/Reference
+java/lang/ref/SoftReference
+java/lang/ref/WeakReference
+java/lang/ref/FinalReference
+java/lang/ref/PhantomReference
+java/lang/ref/Finalizer
+java/lang/Thread
+java/lang/Runnable
+java/lang/ThreadGroup
+java/lang/Thread$UncaughtExceptionHandler
+java/util/Properties
+java/util/Hashtable
+java/util/Map
+java/util/Dictionary
+java/lang/reflect/AccessibleObject
+java/lang/reflect/Field
+java/lang/reflect/Member
+java/lang/reflect/Method
+java/lang/reflect/Constructor
+sun/reflect/MagicAccessorImpl
+sun/reflect/MethodAccessorImpl
+sun/reflect/MethodAccessor
+sun/reflect/ConstructorAccessorImpl
+sun/reflect/ConstructorAccessor
+sun/reflect/DelegatingClassLoader
+sun/reflect/ConstantPool
+sun/reflect/UnsafeStaticFieldAccessorImpl
+sun/reflect/UnsafeFieldAccessorImpl
+sun/reflect/FieldAccessorImpl
+sun/reflect/FieldAccessor
+java/util/Vector
+java/util/List
+java/util/Collection
+java/lang/Iterable
+java/util/RandomAccess
+java/util/AbstractList
+java/util/AbstractCollection
+java/lang/StringBuffer
+java/lang/AbstractStringBuilder
+java/lang/Appendable
+java/lang/StackTraceElement
+java/nio/Buffer
+java/lang/Boolean
+java/lang/Character
+java/lang/Float
+java/lang/Number
+java/lang/Double
+java/lang/Byte
+java/lang/Short
+java/lang/Integer
+java/lang/Long
+java/lang/NullPointerException
+java/lang/ArithmeticException
+java/io/ObjectStreamField
+java/lang/String$CaseInsensitiveComparator
+java/util/Comparator
+java/lang/RuntimePermission
+java/security/BasicPermission
+java/security/Permission
+java/security/Guard
+sun/misc/SoftCache
+java/util/AbstractMap
+java/lang/ref/ReferenceQueue
+java/lang/ref/ReferenceQueue$Null
+java/lang/ref/ReferenceQueue$Lock
+java/util/HashMap
+java/lang/annotation/Annotation
+java/util/HashMap$Entry
+java/util/Map$Entry
+java/security/AccessController
+java/lang/reflect/ReflectPermission
+sun/reflect/ReflectionFactory$GetReflectionFactoryAction
+java/security/PrivilegedAction
+java/util/Stack
+sun/reflect/ReflectionFactory
+java/lang/ref/Reference$Lock
+java/lang/ref/Reference$ReferenceHandler
+java/lang/ref/Finalizer$FinalizerThread
+java/util/Hashtable$EmptyEnumerator
+java/util/Enumeration
+java/util/Hashtable$EmptyIterator
+java/util/Iterator
+java/util/Hashtable$Entry
+java/nio/charset/Charset
+sun/nio/cs/StandardCharsets
+sun/nio/cs/FastCharsetProvider
+java/nio/charset/spi/CharsetProvider
+sun/nio/cs/StandardCharsets$Aliases
+sun/util/PreHashedMap
+sun/nio/cs/StandardCharsets$Classes
+sun/nio/cs/StandardCharsets$Cache
+java/lang/ThreadLocal
+java/util/concurrent/atomic/AtomicInteger
+sun/misc/Unsafe
+java/lang/NoSuchMethodError
+java/lang/IncompatibleClassChangeError
+sun/reflect/Reflection
+java/util/Collections
+java/util/Collections$EmptySet
+java/util/AbstractSet
+java/util/Set
+java/util/Collections$EmptyList
+java/util/Collections$EmptyMap
+java/util/Collections$ReverseComparator
+java/util/Collections$SynchronizedMap
+java/lang/Class$3
+java/lang/reflect/Modifier
+java/lang/reflect/ReflectAccess
+sun/reflect/LangReflectAccess
+java/util/Arrays
+java/lang/Math
+sun/nio/cs/US_ASCII
+sun/nio/cs/HistoricallyNamedCharset
+sun/misc/VM
+java/lang/StringCoding
+java/lang/ThreadLocal$ThreadLocalMap
+java/lang/ThreadLocal$ThreadLocalMap$Entry
+java/lang/StringCoding$StringDecoder
+sun/nio/cs/US_ASCII$Decoder
+java/nio/charset/CharsetDecoder
+java/nio/charset/CodingErrorAction
+java/nio/ByteBuffer
+java/nio/HeapByteBuffer
+java/nio/Bits
+java/nio/ByteOrder
+java/nio/CharBuffer
+java/lang/Readable
+java/nio/HeapCharBuffer
+java/nio/charset/CoderResult
+java/nio/charset/CoderResult$1
+java/nio/charset/CoderResult$Cache
+java/nio/charset/CoderResult$2
+sun/misc/Version
+java/io/FileInputStream
+java/io/InputStream
+java/io/Closeable
+java/io/FileDescriptor
+java/io/FileOutputStream
+java/io/OutputStream
+java/io/Flushable
+java/io/BufferedInputStream
+java/io/FilterInputStream
+java/util/concurrent/atomic/AtomicReferenceFieldUpdater
+java/util/concurrent/atomic/AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl
+sun/reflect/misc/ReflectUtil
+java/io/PrintStream
+java/io/FilterOutputStream
+java/io/BufferedOutputStream
+java/io/OutputStreamWriter
+java/io/Writer
+sun/nio/cs/StreamEncoder
+sun/security/action/GetPropertyAction
+sun/nio/cs/US_ASCII$Encoder
+java/nio/charset/CharsetEncoder
+sun/nio/cs/Surrogate$Parser
+sun/nio/cs/Surrogate
+java/io/BufferedWriter
+java/lang/Runtime
+java/io/File
+java/io/FileSystem
+java/io/UnixFileSystem
+java/io/ExpiringCache
+java/io/ExpiringCache$1
+java/util/LinkedHashMap
+java/util/LinkedHashMap$Entry
+java/lang/StringBuilder
+java/io/File$1
+sun/misc/JavaIODeleteOnExitAccess
+sun/misc/SharedSecrets
+java/lang/ClassLoader$3
+java/lang/StringCoding$StringEncoder
+java/io/ExpiringCache$Entry
+java/lang/ClassLoader$NativeLibrary
+java/lang/Terminator
+java/lang/Terminator$1
+sun/misc/SignalHandler
+sun/misc/Signal
+sun/misc/NativeSignalHandler
+java/io/Console
+java/io/Console$1
+sun/misc/JavaIOAccess
+java/io/Console$1$1
+java/lang/Shutdown
+java/util/ArrayList
+java/lang/Shutdown$Lock
+java/lang/ApplicationShutdownHooks
+java/util/IdentityHashMap
+sun/misc/OSEnvironment
+java/lang/System$2
+sun/misc/JavaLangAccess
+java/lang/Compiler
+java/lang/Compiler$1
+sun/misc/Launcher
+sun/misc/Launcher$Factory
+java/net/URLStreamHandlerFactory
+sun/misc/Launcher$ExtClassLoader
+java/net/URLClassLoader
+java/security/SecureClassLoader
+sun/security/util/Debug
+java/net/URLClassLoader$7
+sun/misc/JavaNetAccess
+java/util/StringTokenizer
+sun/misc/Launcher$ExtClassLoader$1
+java/security/PrivilegedExceptionAction
+sun/misc/MetaIndex
+java/io/BufferedReader
+java/io/Reader
+java/io/FileReader
+java/io/InputStreamReader
+sun/nio/cs/StreamDecoder
+java/lang/reflect/Array
+sun/net/www/ParseUtil
+java/util/BitSet
+java/io/ObjectStreamClass
+java/net/URL
+java/util/Locale
+java/util/concurrent/ConcurrentHashMap
+java/util/concurrent/ConcurrentMap
+java/util/concurrent/ConcurrentHashMap$Segment
+java/util/concurrent/locks/ReentrantLock
+java/util/concurrent/locks/Lock
+java/util/concurrent/locks/ReentrantLock$NonfairSync
+java/util/concurrent/locks/ReentrantLock$Sync
+java/util/concurrent/locks/AbstractQueuedSynchronizer
+java/util/concurrent/locks/AbstractOwnableSynchronizer
+java/util/concurrent/locks/AbstractQueuedSynchronizer$Node
+java/util/concurrent/ConcurrentHashMap$HashEntry
+java/lang/CharacterDataLatin1
+java/net/Parts
+sun/net/www/protocol/file/Handler
+java/net/URLStreamHandler
+java/lang/Class$1
+sun/reflect/ReflectionFactory$1
+sun/reflect/NativeConstructorAccessorImpl
+sun/reflect/DelegatingConstructorAccessorImpl
+java/util/HashSet
+sun/misc/URLClassPath
+sun/net/www/protocol/jar/Handler
+sun/misc/Launcher$AppClassLoader
+sun/misc/Launcher$AppClassLoader$1
+java/lang/SystemClassLoaderAction
+java/net/URLClassLoader$1
+sun/misc/URLClassPath$3
+sun/misc/URLClassPath$JarLoader
+sun/misc/URLClassPath$Loader
+java/security/PrivilegedActionException
+sun/misc/URLClassPath$FileLoader
+sun/misc/URLClassPath$FileLoader$1
+sun/misc/Resource
+sun/nio/ByteBuffered
+java/security/CodeSource
+java/security/Permissions
+java/security/PermissionCollection
+sun/net/www/protocol/file/FileURLConnection
+sun/net/www/URLConnection
+java/net/URLConnection
+java/net/UnknownContentHandler
+java/net/ContentHandler
+sun/net/www/MessageHeader
+java/io/FilePermission
+java/io/FilePermission$1
+sun/security/provider/PolicyFile
+java/security/Policy
+java/security/Policy$UnsupportedEmptyCollection
+java/io/FilePermissionCollection
+java/security/AllPermission
+java/security/UnresolvedPermission
+java/security/BasicPermissionCollection
+java/security/Principal
+java/security/cert/Certificate
+java/util/AbstractList$Itr
+java/util/IdentityHashMap$KeySet
+java/util/IdentityHashMap$KeyIterator
+java/util/IdentityHashMap$IdentityHashMapIterator
+java/io/DeleteOnExitHook
+java/util/LinkedHashSet
+java/util/HashMap$KeySet
+java/util/LinkedHashMap$KeyIterator
+java/util/LinkedHashMap$LinkedHashIterator
+java/awt/Frame
+java/awt/MenuContainer
+java/awt/Window
+javax/accessibility/Accessible
+java/awt/Container
+java/awt/Component
+java/awt/image/ImageObserver
+java/lang/InterruptedException
+java/awt/Label
+java/util/logging/Logger
+java/util/logging/Handler
+java/util/logging/Level
+java/util/logging/LogManager
+java/util/logging/LogManager$1
+java/beans/PropertyChangeSupport
+java/util/logging/LogManager$LogNode
+java/util/logging/LoggingPermission
+java/util/logging/LogManager$Cleaner
+java/util/logging/LogManager$RootLogger
+java/util/logging/LogManager$2
+java/util/Properties$LineReader
+java/util/Hashtable$Enumerator
+java/beans/PropertyChangeEvent
+java/util/EventObject
+java/awt/Component$AWTTreeLock
+sun/awt/DebugHelper
+sun/awt/NativeLibLoader
+sun/security/action/LoadLibraryAction
+java/awt/GraphicsEnvironment
+java/awt/GraphicsEnvironment$1
+java/lang/ProcessEnvironment
+java/lang/ProcessEnvironment$Variable
+java/lang/ProcessEnvironment$ExternalData
+java/lang/ProcessEnvironment$Value
+java/lang/ProcessEnvironment$StringEnvironment
+java/util/Collections$UnmodifiableMap
+sun/awt/DebugHelperStub
+java/awt/Toolkit
+java/awt/Toolkit$3
+sun/util/CoreResourceBundleControl
+java/util/ResourceBundle$Control
+java/util/Arrays$ArrayList
+java/util/Collections$UnmodifiableRandomAccessList
+java/util/Collections$UnmodifiableList
+java/util/Collections$UnmodifiableCollection
+java/util/ResourceBundle
+java/util/ResourceBundle$1
+java/util/ResourceBundle$RBClassLoader
+java/util/ResourceBundle$RBClassLoader$1
+java/util/ResourceBundle$CacheKey
+java/util/ResourceBundle$LoaderReference
+java/util/ResourceBundle$CacheKeyReference
+java/util/ResourceBundle$SingleFormatControl
+sun/awt/resources/awt
+java/util/ListResourceBundle
+java/awt/Toolkit$1
+java/io/FileNotFoundException
+java/io/IOException
+java/awt/event/KeyEvent
+java/awt/event/InputEvent
+java/awt/event/ComponentEvent
+java/awt/AWTEvent
+java/awt/event/NativeLibLoader
+java/util/WeakHashMap
+java/util/WeakHashMap$Entry
+java/awt/Component$DummyRequestFocusController
+sun/awt/RequestFocusController
+java/awt/LayoutManager
+java/awt/LightweightDispatcher
+java/awt/event/AWTEventListener
+java/util/EventListener
+java/awt/Dimension
+java/awt/geom/Dimension2D
+java/util/concurrent/atomic/AtomicBoolean
+java/awt/ComponentOrientation
+java/awt/Component$2
+java/lang/NoSuchMethodException
+sun/awt/AppContext
+sun/awt/AppContext$1
+sun/awt/AppContext$2
+sun/awt/MostRecentKeyValue
+java/awt/Cursor
+sun/awt/X11GraphicsEnvironment
+sun/java2d/SunGraphicsEnvironment
+sun/java2d/FontSupport
+sun/awt/DisplayChangedListener
+sun/java2d/SunGraphicsEnvironment$TTFilter
+java/io/FilenameFilter
+sun/java2d/SunGraphicsEnvironment$T1Filter
+sun/awt/X11GraphicsEnvironment$1
+sun/awt/SunToolkit
+sun/awt/WindowClosingSupport
+sun/awt/WindowClosingListener
+sun/awt/ComponentFactory
+sun/awt/InputMethodSupport
+java/util/concurrent/locks/AbstractQueuedSynchronizer$ConditionObject
+java/util/concurrent/locks/Condition
+sun/awt/AWTAutoShutdown
+sun/awt/AWTAutoShutdown$PeerMap
+sun/awt/SunToolkit$6
+java/awt/Dialog$ModalExclusionType
+java/lang/Enum
+java/awt/Dialog
+java/awt/Dialog$ModalityType
+java/awt/ModalEventFilter
+java/awt/EventFilter
+sun/reflect/UnsafeFieldAccessorFactory
+sun/reflect/UnsafeQualifiedStaticObjectFieldAccessorImpl
+sun/reflect/UnsafeQualifiedStaticFieldAccessorImpl
+sun/awt/SunDisplayChanger
+sun/java2d/SunGraphicsEnvironment$1
+java/io/StreamTokenizer
+sun/font/FontManager
+sun/font/FileFont
+sun/font/PhysicalFont
+sun/font/Font2D
+sun/font/CompositeFont
+java/util/HashMap$Values
+java/util/HashMap$ValueIterator
+java/util/HashMap$HashIterator
+sun/font/FontManager$1
+java/awt/Font
+java/awt/geom/AffineTransform
+sun/font/AttributeValues
+sun/font/EAttribute
+java/text/AttributedCharacterIterator$Attribute
+java/lang/Class$4
+sun/reflect/NativeMethodAccessorImpl
+sun/reflect/DelegatingMethodAccessorImpl
+java/awt/font/TextAttribute
+java/lang/Integer$IntegerCache
+sun/font/TrueTypeFont
+java/awt/font/FontRenderContext
+java/awt/RenderingHints
+sun/awt/SunHints
+sun/awt/SunHints$Key
+java/awt/RenderingHints$Key
+sun/awt/SunHints$Value
+sun/awt/SunHints$LCDContrastKey
+sun/font/Type1Font
+java/awt/geom/Point2D$Float
+java/awt/geom/Point2D
+sun/font/StrikeMetrics
+java/awt/geom/Rectangle2D$Float
+java/awt/geom/Rectangle2D
+java/awt/geom/RectangularShape
+java/awt/Shape
+java/awt/geom/GeneralPath
+java/awt/geom/Path2D$Float
+java/awt/geom/Path2D
+sun/font/CharToGlyphMapper
+sun/font/PhysicalStrike
+sun/font/FontStrike
+sun/font/GlyphList
+sun/font/StrikeCache
+sun/java2d/Disposer
+sun/java2d/Disposer$1
+sun/font/StrikeCache$1
+sun/font/FontManager$FontRegistrationInfo
+sun/awt/motif/MFontConfiguration
+sun/awt/FontConfiguration
+sun/awt/FontDescriptor
+java/util/Scanner
+java/util/regex/Pattern
+java/util/regex/Pattern$8
+java/util/regex/Pattern$Node
+java/util/regex/Pattern$LastNode
+java/util/regex/Pattern$GroupHead
+java/util/regex/Pattern$CharPropertyNames
+java/util/regex/Pattern$CharPropertyNames$1
+java/util/regex/Pattern$CharPropertyNames$CharPropertyFactory
+java/util/regex/Pattern$CharPropertyNames$2
+java/util/regex/Pattern$CharPropertyNames$5
+java/util/regex/Pattern$CharPropertyNames$3
+java/util/regex/Pattern$CharPropertyNames$6
+java/util/regex/Pattern$CharPropertyNames$CloneableProperty
+java/util/regex/Pattern$CharProperty
+java/util/regex/Pattern$CharPropertyNames$4
+java/util/regex/Pattern$CharPropertyNames$7
+java/util/regex/Pattern$CharPropertyNames$8
+java/util/regex/Pattern$CharPropertyNames$9
+java/util/regex/Pattern$CharPropertyNames$10
+java/util/regex/Pattern$CharPropertyNames$11
+java/util/regex/Pattern$CharPropertyNames$12
+java/util/regex/Pattern$CharPropertyNames$13
+java/util/regex/Pattern$CharPropertyNames$14
+java/util/regex/Pattern$CharPropertyNames$15
+java/util/regex/Pattern$CharPropertyNames$16
+java/util/regex/Pattern$CharPropertyNames$17
+java/util/regex/Pattern$CharPropertyNames$18
+java/util/regex/Pattern$CharPropertyNames$19
+java/util/regex/Pattern$CharPropertyNames$20
+java/util/regex/Pattern$CharPropertyNames$21
+java/util/regex/Pattern$Curly
+java/util/regex/Pattern$Slice
+java/util/regex/Pattern$Begin
+java/util/regex/Pattern$First
+java/util/regex/Pattern$Start
+java/util/regex/Pattern$TreeInfo
+java/util/regex/Pattern$All
+java/util/regex/Pattern$BitClass
+java/util/regex/Pattern$BmpCharProperty
+java/util/regex/Pattern$6
+java/util/regex/Pattern$CharProperty$1
+java/util/regex/Pattern$10
+sun/nio/ch/FileChannelImpl
+java/nio/channels/FileChannel
+java/nio/channels/ByteChannel
+java/nio/channels/ReadableByteChannel
+java/nio/channels/Channel
+java/nio/channels/WritableByteChannel
+java/nio/channels/GatheringByteChannel
+java/nio/channels/ScatteringByteChannel
+java/nio/channels/spi/AbstractInterruptibleChannel
+java/nio/channels/InterruptibleChannel
+sun/nio/ch/Util
+sun/nio/ch/IOUtil
+sun/nio/ch/FileDispatcher
+sun/nio/ch/NativeDispatcher
+sun/nio/ch/Reflect
+java/nio/MappedByteBuffer
+sun/nio/ch/Reflect$1
+sun/nio/ch/NativeThreadSet
+java/nio/channels/Channels
+java/util/Scanner$1
+sun/misc/LRUCache
+java/util/regex/Matcher
+java/util/regex/MatchResult
+java/text/NumberFormat
+java/text/Format
+java/text/spi/NumberFormatProvider
+java/util/spi/LocaleServiceProvider
+sun/util/LocaleServiceProviderPool
+sun/util/LocaleServiceProviderPool$1
+java/util/ServiceLoader
+java/util/ServiceLoader$LazyIterator
+java/util/ServiceLoader$1
+java/util/HashMap$EntrySet
+java/util/LinkedHashMap$EntryIterator
+sun/misc/Launcher$1
+sun/misc/URLClassPath$2
+java/lang/ClassLoader$2
+sun/misc/URLClassPath$1
+java/net/URLClassLoader$3
+sun/misc/CompoundEnumeration
+sun/misc/URLClassPath$JarLoader$1
+sun/misc/FileURLMapper
+java/net/URLClassLoader$3$1
+sun/util/resources/LocaleData
+sun/util/resources/LocaleData$1
+sun/util/resources/LocaleData$LocaleDataResourceBundleControl
+sun/util/LocaleDataMetaInfo
+sun/text/resources/FormatData
+java/util/ResourceBundle$BundleReference
+sun/text/resources/FormatData_en
+sun/text/resources/FormatData_en_US
+java/text/DecimalFormatSymbols
+java/text/spi/DecimalFormatSymbolsProvider
+java/util/Currency
+java/util/Currency$1
+java/util/CurrencyData
+java/util/spi/CurrencyNameProvider
+sun/util/resources/CurrencyNames
+sun/util/resources/LocaleNamesBundle
+sun/util/resources/OpenListResourceBundle
+sun/util/resources/CurrencyNames_en_US
+java/text/DecimalFormat
+java/text/FieldPosition
+java/text/DigitList
+java/math/RoundingMode
+java/util/regex/Pattern$GroupTail
+java/util/regex/Pattern$Ctype
+java/util/regex/Pattern$Ques
+java/util/regex/Pattern$GroupCurly
+java/util/regex/Pattern$5
+java/util/regex/Pattern$Loop
+java/util/regex/Pattern$Prolog
+java/util/regex/Pattern$9
+java/util/regex/Pattern$BranchConn
+java/util/regex/Pattern$Branch
+java/nio/channels/spi/AbstractInterruptibleChannel$1
+sun/nio/ch/Interruptible
+sun/nio/ch/NativeThread
+sun/nio/ch/DirectBuffer
+java/nio/DirectByteBuffer
+java/nio/DirectByteBuffer$Deallocator
+sun/misc/Cleaner
+sun/nio/ch/IOStatus
+java/util/regex/ASCII
+java/io/DataInputStream
+java/io/DataInput
+java/lang/Short$ShortCache
+java/util/HashMap$KeyIterator
+sun/font/CompositeFontDescriptor
+sun/font/Font2DHandle
+sun/font/FontFamily
+java/awt/GraphicsDevice
+sun/awt/X11GraphicsDevice
+sun/awt/X11GraphicsConfig
+java/awt/GraphicsConfiguration
+java/awt/ImageCapabilities
+sun/java2d/x11/X11SurfaceData
+sun/java2d/SurfaceData
+java/awt/Transparency
+sun/java2d/DisposerTarget
+sun/java2d/InvalidPipeException
+java/lang/IllegalStateException
+sun/java2d/NullSurfaceData
+sun/java2d/loops/SurfaceType
+sun/awt/image/PixelConverter
+sun/awt/image/PixelConverter$Xrgb
+sun/awt/image/PixelConverter$Argb
+sun/awt/image/PixelConverter$ArgbPre
+sun/awt/image/PixelConverter$Xbgr
+sun/awt/image/PixelConverter$Rgba
+sun/awt/image/PixelConverter$RgbaPre
+sun/awt/image/PixelConverter$Ushort565Rgb
+sun/awt/image/PixelConverter$Ushort555Rgb
+sun/awt/image/PixelConverter$Ushort555Rgbx
+sun/awt/image/PixelConverter$Ushort4444Argb
+sun/awt/image/PixelConverter$ByteGray
+sun/awt/image/PixelConverter$UshortGray
+sun/awt/image/PixelConverter$Rgbx
+sun/awt/image/PixelConverter$Bgrx
+sun/awt/image/PixelConverter$ArgbBm
+java/awt/image/ColorModel
+java/awt/image/DirectColorModel
+java/awt/image/PackedColorModel
+java/awt/color/ColorSpace
+java/awt/color/ICC_Profile
+sun/awt/color/ProfileDeferralInfo
+sun/awt/color/ProfileDeferralMgr
+java/awt/color/ICC_ProfileRGB
+java/awt/color/ICC_Profile$1
+sun/awt/color/ProfileActivator
+java/awt/color/ICC_ColorSpace
+sun/java2d/pipe/NullPipe
+sun/java2d/pipe/PixelDrawPipe
+sun/java2d/pipe/PixelFillPipe
+sun/java2d/pipe/ShapeDrawPipe
+sun/java2d/pipe/TextPipe
+sun/java2d/pipe/DrawImagePipe
+java/awt/image/IndexColorModel
+sun/java2d/pipe/LoopPipe
+sun/java2d/pipe/OutlineTextRenderer
+sun/java2d/pipe/SolidTextRenderer
+sun/java2d/pipe/GlyphListLoopPipe
+sun/java2d/pipe/GlyphListPipe
+sun/java2d/pipe/AATextRenderer
+sun/java2d/pipe/LCDTextRenderer
+sun/java2d/pipe/AlphaColorPipe
+sun/java2d/pipe/CompositePipe
+sun/java2d/pipe/PixelToShapeConverter
+sun/java2d/pipe/TextRenderer
+sun/java2d/pipe/SpanClipRenderer
+sun/java2d/pipe/Region
+sun/java2d/pipe/RegionIterator
+sun/java2d/pipe/DuctusShapeRenderer
+sun/java2d/pipe/DuctusRenderer
+sun/java2d/pipe/AlphaPaintPipe
+sun/java2d/pipe/SpanShapeRenderer$Composite
+sun/java2d/pipe/SpanShapeRenderer
+sun/java2d/pipe/GeneralCompositePipe
+sun/java2d/pipe/DrawImage
+sun/java2d/loops/RenderCache
+sun/java2d/loops/RenderCache$Entry
+sun/java2d/loops/XORComposite
+java/awt/Composite
+sun/font/X11TextRenderer
+sun/java2d/loops/GraphicsPrimitive
+sun/java2d/x11/X11PMBlitLoops
+sun/java2d/loops/Blit
+sun/java2d/loops/GraphicsPrimitiveMgr
+sun/java2d/loops/CompositeType
+sun/java2d/SunGraphics2D
+sun/awt/ConstrainableGraphics
+java/awt/Graphics2D
+java/awt/Graphics
+java/awt/Color
+java/awt/Paint
+java/awt/AlphaComposite
+sun/java2d/loops/BlitBg
+sun/java2d/loops/ScaledBlit
+sun/java2d/loops/FillRect
+sun/java2d/loops/FillSpans
+sun/java2d/loops/DrawLine
+sun/java2d/loops/DrawRect
+sun/java2d/loops/DrawPolygons
+sun/java2d/loops/DrawPath
+sun/java2d/loops/FillPath
+sun/java2d/loops/MaskBlit
+sun/java2d/loops/MaskFill
+sun/java2d/loops/DrawGlyphList
+sun/java2d/loops/DrawGlyphListAA
+sun/java2d/loops/DrawGlyphListLCD
+sun/java2d/loops/TransformHelper
+java/awt/BasicStroke
+java/awt/Stroke
+sun/misc/PerformanceLogger
+sun/misc/PerformanceLogger$TimeData
+sun/java2d/pipe/ValidatePipe
+sun/java2d/loops/CustomComponent
+sun/java2d/loops/GraphicsPrimitiveProxy
+sun/java2d/loops/GeneralRenderer
+sun/java2d/loops/GraphicsPrimitiveMgr$1
+sun/java2d/loops/GraphicsPrimitiveMgr$2
+sun/java2d/x11/X11PMBlitLoops$DelegateBlitLoop
+sun/java2d/x11/X11PMBlitBgLoops
+sun/java2d/x11/X11SurfaceData$LazyPipe
+sun/awt/X11GraphicsConfig$X11GCDisposerRecord
+sun/java2d/DisposerRecord
+java/awt/BorderLayout
+java/awt/LayoutManager2
+java/awt/Rectangle
+java/awt/Toolkit$2
+sun/awt/X11/XToolkit
+sun/awt/X11/XConstants
+sun/awt/UNIXToolkit
+java/util/TreeMap
+java/util/NavigableMap
+java/util/SortedMap
+sun/awt/X11/XlibWrapper
+sun/awt/X11/XUtilConstants
+sun/awt/X11/XProtocolConstants
+sun/awt/X11/XCursorFontConstants
+sun/awt/X11/XlibWrapper$1
+sun/awt/X11/XToolkit$4
+sun/awt/X11/XModifierKeymap
+sun/awt/X11/XWrapperBase
+sun/awt/X11/Native
+sun/awt/X11/Native$1
+java/awt/EventQueue
+sun/awt/X11/XToolkit$7
+java/util/EmptyStackException
+java/lang/reflect/InvocationTargetException
+java/awt/EventDispatchThread
+java/awt/event/PaintEvent
+java/awt/event/MouseEvent
+sun/awt/PeerEvent
+java/awt/event/InvocationEvent
+java/awt/ActiveEvent
+java/awt/EventQueueItem
+sun/awt/X11/XToolkit$1
+sun/awt/X11/XToolkit$XErrorHandler
+sun/awt/X11/XToolkit$5
+sun/awt/X11/XEventDispatcher
+sun/awt/SunToolkit$ModalityListenerList
+sun/awt/ModalityListener
+sun/awt/SunToolkit$1
+java/util/MissingResourceException
+java/awt/Queue
+sun/awt/PostEventQueue
+java/util/LinkedList
+java/util/Deque
+java/util/Queue
+java/util/AbstractSequentialList
+java/util/LinkedList$Entry
+sun/awt/X11/AwtScreenData
+sun/awt/X11/XWM
+sun/awt/X11/MWMConstants
+sun/awt/X11/XAtom
+java/awt/Insets
+sun/awt/X11/XWM$1
+sun/awt/X11/XWM$2
+sun/awt/X11/XSetWindowAttributes
+sun/awt/X11/XErrorEvent
+sun/awt/X11/XNETProtocol
+sun/awt/X11/XStateProtocol
+sun/awt/X11/XLayerProtocol
+sun/awt/X11/XProtocol
+sun/awt/X11/XProtocol$1
+sun/awt/X11/WindowPropertyGetter
+sun/awt/X11/UnsafeXDisposerRecord
+sun/awt/X11/XPropertyCache
+sun/awt/X11/XWINProtocol
+sun/awt/X11/XAtomList
+sun/awt/X11/XToolkit$3
+sun/awt/X11/XAnyEvent
+sun/awt/X11/IXAnyEvent
+java/awt/Window$WindowDisposerRecord
+java/awt/KeyboardFocusManager
+java/awt/KeyEventDispatcher
+java/awt/KeyEventPostProcessor
+java/awt/AWTKeyStroke
+java/awt/AWTKeyStroke$1
+java/awt/DefaultKeyboardFocusManager
+java/awt/DefaultFocusTraversalPolicy
+java/awt/ContainerOrderFocusTraversalPolicy
+java/awt/FocusTraversalPolicy
+java/awt/MutableBoolean
+java/util/Collections$UnmodifiableSet
+sun/awt/HeadlessToolkit
+sun/awt/X11/XKeyboardFocusManagerPeer
+java/awt/peer/KeyboardFocusManagerPeer
+sun/awt/X11/XKeyboardFocusManagerPeer$1
+sun/awt/X11/XFramePeer
+java/awt/peer/FramePeer
+java/awt/peer/WindowPeer
+java/awt/peer/ContainerPeer
+java/awt/peer/ComponentPeer
+sun/awt/X11/XDecoratedPeer
+sun/awt/X11/XWindowPeer
+sun/awt/X11/XPanelPeer
+java/awt/peer/PanelPeer
+sun/awt/X11/XCanvasPeer
+java/awt/peer/CanvasPeer
+sun/awt/X11/XComponentPeer
+java/awt/dnd/peer/DropTargetPeer
+sun/awt/X11/XWindow
+sun/awt/X11ComponentPeer
+sun/awt/X11/XBaseWindow
+sun/awt/X11/XCreateWindowParams
+java/lang/Long$LongCache
+sun/awt/X11/XBaseWindow$InitialiseState
+sun/awt/X11/XBaseWindow$StateLock
+sun/awt/X11/AwtGraphicsConfigData
+sun/awt/X11/XVisualInfo
+java/awt/SystemColor
+sun/awt/X11/MotifColorUtilities
+java/lang/StrictMath
+sun/awt/X11/XRepaintArea
+sun/awt/RepaintArea
+sun/awt/X11/XWindowAttributesData
+java/util/concurrent/locks/LockSupport
+sun/awt/X11/WindowDimensions
+java/awt/Point
+java/util/TreeMap$Entry
+sun/nio/cs/UTF_8
+sun/nio/cs/Unicode
+sun/nio/cs/UTF_8$Encoder
+sun/nio/cs/UTF_8$Decoder
+sun/nio/cs/Surrogate$Generator
+sun/awt/X11/XPropertyEvent
+sun/awt/X11/XDropTargetEventProcessor
+sun/awt/X11/XDragSourceContextPeer
+sun/awt/X11/XDragSourceProtocolListener
+sun/awt/dnd/SunDragSourceContextPeer
+java/awt/dnd/peer/DragSourceContextPeer
+sun/awt/X11/XAwtState
+sun/awt/X11/XBaseWindow$1
+sun/awt/X11/XRootWindow
+sun/nio/cs/ISO_8859_1
+sun/nio/cs/ISO_8859_1$Encoder
+sun/nio/cs/ISO_8859_1$Decoder
+sun/java2d/x11/X11SurfaceData$X11WindowSurfaceData
+sun/java2d/loops/RenderLoops
+sun/java2d/loops/GraphicsPrimitiveMgr$PrimitiveSpec
+sun/java2d/DefaultDisposerRecord
+sun/java2d/x11/X11Renderer
+sun/awt/X11/XGlobalCursorManager
+sun/awt/GlobalCursorManager
+sun/awt/X11/XToolkit$6
+java/awt/Cursor$CursorDisposer
+java/awt/AWTException
+java/awt/HeadlessException
+java/lang/UnsupportedOperationException
+sun/reflect/UnsafeLongFieldAccessorImpl
+sun/reflect/UnsafeIntegerFieldAccessorImpl
+sun/awt/X11/XClientMessageEvent
+sun/awt/X11/XIconInfo
+sun/awt/X11/XAWTIcon32_java_icon16_png
+sun/awt/X11/XAWTIcon32_java_icon24_png
+sun/awt/X11/XAWTIcon32_java_icon32_png
+sun/awt/X11/XAWTIcon32_java_icon48_png
+sun/awt/X11/XSizeHints
+sun/awt/X11/XContentWindow
+sun/awt/X11/XFocusProxyWindow
+sun/awt/X11/XWMHints
+java/util/LinkedList$ListItr
+java/util/ListIterator
+sun/awt/SunToolkit$2
+java/awt/image/BufferStrategy
+java/awt/dnd/DropTarget
+java/awt/dnd/DropTargetListener
+java/awt/event/ComponentListener
+java/awt/event/FocusListener
+java/awt/event/HierarchyListener
+java/awt/event/HierarchyBoundsListener
+java/awt/event/KeyListener
+java/awt/event/MouseListener
+java/awt/event/MouseMotionListener
+java/awt/event/MouseWheelListener
+java/awt/event/InputMethodListener
+java/awt/Component$NativeInLightFixer
+java/awt/event/ContainerListener
+javax/accessibility/AccessibleContext
+sun/reflect/UnsafeObjectFieldAccessorImpl
+java/awt/peer/LightweightPeer
+sun/awt/X11/XLabelPeer
+java/awt/peer/LabelPeer
+sun/awt/X11/XMapEvent
+sun/awt/X11/XQueryTree
+sun/awt/X11/XConfigureEvent
+sun/awt/X11/PropMwmHints
+sun/awt/GlobalCursorManager$NativeUpdater
+javax/swing/JFrame
+javax/swing/WindowConstants
+javax/swing/RootPaneContainer
+javax/swing/TransferHandler$HasGetTransferHandler
+javax/swing/JLabel
+javax/swing/SwingConstants
+javax/swing/JComponent
+javax/swing/JComponent$1
+javax/swing/SwingUtilities
+javax/swing/JRootPane
+sun/security/action/GetBooleanAction
+javax/swing/event/EventListenerList
+javax/swing/JPanel
+java/awt/FlowLayout
+javax/swing/UIManager
+javax/swing/UIManager$LookAndFeelInfo
+sun/swing/SwingUtilities2
+sun/swing/SwingUtilities2$LSBCacheEntry
+javax/swing/UIManager$LAFState
+javax/swing/UIDefaults
+javax/swing/MultiUIDefaults
+javax/swing/UIManager$1
+javax/swing/plaf/metal/MetalLookAndFeel
+javax/swing/plaf/basic/BasicLookAndFeel
+javax/swing/LookAndFeel
+sun/swing/DefaultLookup
+javax/swing/plaf/metal/OceanTheme
+javax/swing/plaf/metal/DefaultMetalTheme
+javax/swing/plaf/metal/MetalTheme
+javax/swing/plaf/ColorUIResource
+javax/swing/plaf/UIResource
+sun/swing/PrintColorUIResource
+javax/swing/plaf/metal/DefaultMetalTheme$FontDelegate
+javax/swing/plaf/FontUIResource
+sun/swing/SwingLazyValue
+javax/swing/UIDefaults$LazyValue
+javax/swing/UIDefaults$ActiveValue
+javax/swing/plaf/InsetsUIResource
+sun/swing/SwingUtilities2$2
+javax/swing/plaf/basic/BasicLookAndFeel$2
+javax/swing/plaf/DimensionUIResource
+javax/swing/UIDefaults$LazyInputMap
+java/lang/Character$CharacterCache
+javax/swing/plaf/metal/MetalLookAndFeel$MetalLazyValue
+javax/swing/plaf/metal/MetalLookAndFeel$FontActiveValue
+java/awt/print/PrinterJob
+sun/swing/SwingUtilities2$AATextInfo
+sun/awt/X11/XAWTXSettings
+sun/awt/X11/XMSelectionListener
+sun/awt/XSettings
+sun/awt/X11/XMSelection
+sun/awt/X11/XMSelection$1
+javax/swing/plaf/metal/MetalLookAndFeel$AATextListener
+java/beans/PropertyChangeListener
+java/beans/PropertyChangeListenerProxy
+java/util/EventListenerProxy
+sun/awt/EventListenerAggregate
+javax/swing/UIDefaults$ProxyLazyValue
+javax/swing/plaf/metal/OceanTheme$1
+javax/swing/plaf/metal/OceanTheme$2
+javax/swing/plaf/metal/OceanTheme$3
+javax/swing/plaf/metal/OceanTheme$4
+javax/swing/plaf/metal/OceanTheme$5
+javax/swing/plaf/metal/OceanTheme$6
+javax/swing/RepaintManager
+javax/swing/RepaintManager$DisplayChangedHandler
+javax/swing/SwingPaintEventDispatcher
+sun/awt/PaintEventDispatcher
+javax/swing/UIManager$2
+javax/swing/UIManager$3
+java/awt/PopupMenu
+java/awt/Menu
+java/awt/MenuItem
+java/awt/MenuComponent
+java/io/ObjectOutputStream
+java/io/ObjectOutput
+java/io/DataOutput
+java/io/ObjectStreamConstants
+java/io/PrintWriter
+java/io/ObjectInputStream
+java/io/ObjectInput
+java/awt/Event
+java/awt/im/InputContext
+java/awt/event/MouseWheelEvent
+java/awt/BufferCapabilities
+sun/awt/CausedFocusEvent$Cause
+java/awt/PointerInfo
+java/awt/Component$BaselineResizeBehavior
+java/awt/FontMetrics
+java/awt/Image
+java/awt/image/ImageProducer
+java/awt/image/VolatileImage
+java/awt/im/InputMethodRequests
+java/awt/event/FocusEvent
+java/awt/event/InputMethodEvent
+java/awt/event/HierarchyEvent
+javax/accessibility/AccessibleStateSet
+com/sun/swing/internal/plaf/metal/resources/metal
+sun/util/ResourceBundleEnumeration
+com/sun/swing/internal/plaf/basic/resources/basic
+javax/swing/plaf/basic/BasicPanelUI
+javax/swing/plaf/PanelUI
+javax/swing/plaf/ComponentUI
+sun/reflect/misc/MethodUtil
+sun/reflect/misc/MethodUtil$1
+java/util/jar/JarFile
+java/util/zip/ZipFile
+java/util/zip/ZipConstants
+java/util/jar/JavaUtilJarAccessImpl
+sun/misc/JavaUtilJarAccess
+sun/misc/JarIndex
+java/util/zip/ZipEntry
+java/util/jar/JarFile$JarFileEntry
+java/util/jar/JarEntry
+sun/misc/URLClassPath$JarLoader$2
+sun/net/www/protocol/jar/JarURLConnection
+java/net/JarURLConnection
+sun/net/www/protocol/jar/JarFileFactory
+sun/net/www/protocol/jar/URLJarFile$URLJarFileCloseController
+java/net/HttpURLConnection
+sun/net/www/protocol/jar/URLJarFile
+sun/net/www/protocol/jar/URLJarFile$URLJarFileEntry
+sun/net/www/protocol/jar/JarURLConnection$JarURLInputStream
+java/util/zip/ZipFile$ZipFileInputStream
+java/security/AllPermissionCollection
+java/lang/IllegalAccessException
+javax/swing/JPasswordField
+javax/swing/JTextField
+javax/swing/text/JTextComponent
+javax/swing/Scrollable
+javax/swing/JLayeredPane
+javax/swing/JRootPane$1
+javax/swing/ArrayTable
+javax/swing/JInternalFrame
+javax/swing/JRootPane$RootLayout
+javax/swing/BufferStrategyPaintManager
+javax/swing/RepaintManager$PaintManager
+javax/swing/plaf/metal/MetalRootPaneUI
+javax/swing/plaf/basic/BasicRootPaneUI
+javax/swing/plaf/RootPaneUI
+javax/swing/plaf/basic/BasicRootPaneUI$RootPaneInputMap
+javax/swing/plaf/ComponentInputMapUIResource
+javax/swing/ComponentInputMap
+javax/swing/InputMap
+javax/swing/plaf/InputMapUIResource
+javax/swing/KeyStroke
+java/awt/VKCollection
+sun/reflect/UnsafeQualifiedStaticIntegerFieldAccessorImpl
+javax/swing/plaf/basic/LazyActionMap
+javax/swing/plaf/ActionMapUIResource
+javax/swing/ActionMap
+javax/swing/LayoutFocusTraversalPolicy
+javax/swing/SortingFocusTraversalPolicy
+javax/swing/InternalFrameFocusTraversalPolicy
+javax/swing/SwingContainerOrderFocusTraversalPolicy
+javax/swing/SwingDefaultFocusTraversalPolicy
+javax/swing/LayoutComparator
+javax/swing/plaf/metal/MetalLabelUI
+javax/swing/plaf/basic/BasicLabelUI
+javax/swing/plaf/LabelUI
+javax/swing/plaf/metal/DefaultMetalTheme$FontDelegate$1
+javax/swing/plaf/basic/BasicHTML
+javax/swing/SystemEventQueueUtilities
+javax/swing/SystemEventQueueUtilities$SystemEventQueue
+sun/awt/NullComponentPeer
+java/awt/event/WindowEvent
+java/awt/EventQueue$1
+java/awt/EventDispatchThread$1
+java/awt/Conditional
+java/awt/EventDispatchThread$HierarchyEventFilter
+java/awt/EventFilter$FilterAction
+sun/awt/dnd/SunDropTargetEvent
+java/awt/event/ActionEvent
+java/util/jar/Manifest
+java/io/ByteArrayInputStream
+java/util/jar/Attributes
+java/util/jar/Manifest$FastInputStream
+java/util/jar/Attributes$Name
+sun/misc/ASCIICaseInsensitiveComparator
+java/util/jar/JarVerifier
+java/io/ByteArrayOutputStream
+sun/misc/ExtensionDependency
+java/lang/Package
+sun/security/util/ManifestEntryVerifier
+sun/security/provider/Sun
+java/security/Provider
+java/security/Provider$ServiceKey
+java/security/Provider$EngineDescription
+sun/security/provider/Sun$1
+java/security/Security
+java/security/Security$1
+sun/misc/FloatingDecimal
+sun/misc/FloatingDecimal$1
+sun/security/provider/NativePRNG
+java/security/SecureRandomSpi
+sun/security/provider/NativePRNG$1
+sun/security/provider/NativePRNG$RandomIO
+sun/misc/BASE64Decoder
+sun/misc/CharacterDecoder
+sun/security/util/SignatureFileVerifier
+java/awt/event/KeyAdapter
+java/lang/NumberFormatException
+java/lang/IllegalArgumentException
+java/io/FileWriter
+java/net/Authenticator
+java/net/MalformedURLException
+javax/swing/text/Element
+javax/swing/text/Document
+javax/swing/text/PlainDocument
+javax/swing/text/AbstractDocument
+javax/swing/text/GapContent
+javax/swing/text/AbstractDocument$Content
+javax/swing/text/GapVector
+javax/swing/text/GapContent$MarkVector
+javax/swing/text/GapContent$MarkData
+javax/swing/text/StyleContext
+javax/swing/text/AbstractDocument$AttributeContext
+javax/swing/text/StyleConstants
+javax/swing/text/StyleConstants$CharacterConstants
+javax/swing/text/AttributeSet$CharacterAttribute
+javax/swing/text/StyleConstants$FontConstants
+javax/swing/text/AttributeSet$FontAttribute
+javax/swing/text/StyleConstants$ColorConstants
+javax/swing/text/AttributeSet$ColorAttribute
+javax/swing/text/StyleConstants$ParagraphConstants
+javax/swing/text/AttributeSet$ParagraphAttribute
+javax/swing/text/StyleContext$FontKey
+javax/swing/text/SimpleAttributeSet
+javax/swing/text/MutableAttributeSet
+javax/swing/text/AttributeSet
+javax/swing/text/SimpleAttributeSet$EmptyAttributeSet
+javax/swing/text/StyleContext$NamedStyle
+javax/swing/text/Style
+javax/swing/text/SimpleAttributeSet$1
+javax/swing/text/StyleContext$SmallAttributeSet
+javax/swing/text/AbstractDocument$BidiRootElement
+javax/swing/text/AbstractDocument$BranchElement
+javax/swing/text/AbstractDocument$AbstractElement
+javax/swing/tree/TreeNode
+javax/swing/text/AbstractDocument$1
+javax/swing/text/AbstractDocument$BidiElement
+javax/swing/text/AbstractDocument$LeafElement
+javax/swing/text/GapContent$StickyPosition
+javax/swing/text/Position
+javax/swing/text/StyleContext$KeyEnumeration
+javax/swing/text/GapContent$InsertUndo
+javax/swing/undo/AbstractUndoableEdit
+javax/swing/undo/UndoableEdit
+javax/swing/text/AbstractDocument$DefaultDocumentEvent
+javax/swing/event/DocumentEvent
+javax/swing/undo/CompoundEdit
+javax/swing/event/DocumentEvent$EventType
+javax/swing/text/Segment
+java/text/CharacterIterator
+javax/swing/text/Utilities
+javax/swing/text/SegmentCache
+javax/swing/text/SegmentCache$CachedSegment
+javax/swing/event/UndoableEditEvent
+javax/swing/text/AbstractDocument$ElementEdit
+javax/swing/event/DocumentEvent$ElementChange
+java/net/Socket
+java/net/InetAddress
+java/net/InetAddress$Cache
+java/net/InetAddress$Cache$Type
+java/net/InetAddressImplFactory
+java/net/Inet4AddressImpl
+java/net/InetAddressImpl
+java/net/InetAddress$1
+sun/net/spi/nameservice/NameService
+sun/net/util/IPAddressUtil
+java/util/RandomAccessSubList
+java/util/SubList
+java/util/SubList$1
+java/util/AbstractList$ListItr
+java/net/Inet4Address
+java/net/InetSocketAddress
+java/net/SocketAddress
+java/net/SocksSocketImpl
+java/net/SocksConsts
+java/net/PlainSocketImpl
+java/net/SocketImpl
+java/net/SocketOptions
+java/net/SocketException
+java/net/SocksSocketImpl$5
+java/net/ProxySelector
+sun/net/spi/DefaultProxySelector
+sun/net/spi/DefaultProxySelector$1
+sun/net/NetProperties
+sun/net/NetProperties$1
+sun/net/spi/DefaultProxySelector$NonProxyInfo
+java/net/Inet6Address
+java/net/URI
+java/net/URI$Parser
+java/net/Proxy
+java/net/Proxy$Type
+java/net/ConnectException
+javax/swing/JMenu
+javax/swing/MenuElement
+javax/swing/JMenuItem
+javax/swing/AbstractButton
+java/awt/ItemSelectable
+javax/swing/event/MenuListener
+javax/swing/JCheckBoxMenuItem
+javax/swing/Icon
+javax/swing/JButton
+java/awt/event/WindowListener
+java/net/URLClassLoader$2
+javax/swing/ImageIcon
+javax/swing/ImageIcon$1
+java/awt/MediaTracker
+sun/misc/SoftCache$ValueCell
+sun/awt/image/URLImageSource
+sun/awt/image/InputStreamImageSource
+sun/awt/image/ImageFetchable
+sun/awt/image/ToolkitImage
+java/awt/Image$1
+sun/awt/image/SurfaceManager$ImageAccessor
+sun/awt/image/SurfaceManager
+sun/awt/image/NativeLibLoader
+java/awt/ImageMediaEntry
+java/awt/MediaEntry
+sun/awt/image/ImageRepresentation
+java/awt/image/ImageConsumer
+sun/awt/image/ImageWatched
+sun/awt/image/ImageWatched$Link
+sun/awt/image/ImageWatched$WeakLink
+sun/awt/image/ImageConsumerQueue
+sun/awt/image/ImageFetcher
+sun/awt/image/FetcherInfo
+sun/awt/image/ImageFetcher$1
+sun/awt/image/GifImageDecoder
+sun/awt/image/ImageDecoder
+sun/awt/image/GifFrame
+java/awt/image/Raster
+java/awt/image/DataBufferByte
+java/awt/image/DataBuffer
+java/awt/image/PixelInterleavedSampleModel
+java/awt/image/ComponentSampleModel
+java/awt/image/SampleModel
+sun/awt/image/ByteInterleavedRaster
+sun/awt/image/ByteComponentRaster
+sun/awt/image/SunWritableRaster
+java/awt/image/WritableRaster
+java/awt/image/BufferedImage
+java/awt/image/WritableRenderedImage
+java/awt/image/RenderedImage
+sun/awt/image/IntegerComponentRaster
+sun/awt/image/BytePackedRaster
+java/awt/Canvas
+sun/font/FontDesignMetrics
+sun/font/FontStrikeDesc
+sun/font/CompositeStrike
+sun/font/FontStrikeDisposer
+sun/font/StrikeCache$SoftDisposerRef
+sun/font/StrikeCache$DisposableStrike
+sun/font/TrueTypeFont$TTDisposerRecord
+sun/font/TrueTypeFont$1
+java/io/RandomAccessFile
+java/nio/ByteBufferAsIntBufferB
+java/nio/IntBuffer
+sun/font/TrueTypeFont$DirectoryEntry
+java/nio/ByteBufferAsShortBufferB
+java/nio/ShortBuffer
+sun/nio/cs/UTF_16
+sun/nio/cs/UTF_16$Decoder
+sun/nio/cs/UnicodeDecoder
+sun/font/FileFontStrike
+sun/font/FileFont$FileFontDisposer
+sun/font/TrueTypeGlyphMapper
+sun/font/CMap
+sun/font/CMap$NullCMapClass
+sun/font/CMap$CMapFormat4
+java/nio/ByteBufferAsCharBufferB
+sun/font/FontDesignMetrics$KeyReference
+sun/awt/image/PNGImageDecoder
+sun/awt/image/PNGFilterInputStream
+java/util/zip/InflaterInputStream
+java/util/zip/Inflater
+sun/awt/EventQueueItem
+sun/awt/SunToolkit$3
+sun/awt/X11/XExposeEvent
+sun/awt/X11/ComponentAccessor
+sun/awt/X11/ComponentAccessor$1
+sun/reflect/UnsafeBooleanFieldAccessorImpl
+sun/awt/event/IgnorePaintEvent
+java/awt/image/DataBufferInt
+java/awt/image/SinglePixelPackedSampleModel
+sun/awt/image/IntegerInterleavedRaster
+sun/java2d/x11/X11RemoteOffScreenImage
+sun/awt/image/RemoteOffScreenImage
+sun/awt/image/OffScreenImage
+sun/java2d/x11/X11RemoteOffScreenImage$X11RemoteSurfaceManager
+sun/awt/image/OffScreenSurfaceManager
+sun/awt/image/CachingSurfaceManager
+sun/awt/image/RasterListener
+sun/awt/image/BufImgSurfaceData
+sun/java2d/opengl/GLXGraphicsConfig
+sun/java2d/opengl/OGLGraphicsConfig
+sun/java2d/x11/X11SurfaceData$X11PixmapSurfaceData
+sun/awt/image/WritableRasterNative
+sun/awt/image/DataBufferNative
+sun/java2d/SurfaceManagerFactory
+sun/java2d/x11/X11CachingSurfaceManager
+sun/java2d/opengl/GLXSurfaceData
+sun/java2d/opengl/OGLSurfaceData
+sun/font/CompositeGlyphMapper
+sun/java2d/loops/FontInfo
+java/util/Date
+sun/util/calendar/CalendarSystem
+sun/util/calendar/Gregorian
+sun/util/calendar/BaseCalendar
+sun/util/calendar/AbstractCalendar
+java/util/TimeZone
+java/lang/InheritableThreadLocal
+sun/util/calendar/ZoneInfo
+sun/util/calendar/ZoneInfoFile
+sun/util/calendar/ZoneInfoFile$1
+java/util/TimeZone$1
+sun/util/calendar/Gregorian$Date
+sun/util/calendar/BaseCalendar$Date
+sun/util/calendar/CalendarDate
+sun/util/calendar/CalendarUtils
+java/util/TimeZone$DisplayNames
+sun/util/TimeZoneNameUtility
+sun/util/resources/TimeZoneNames
+sun/util/resources/TimeZoneNamesBundle
+sun/util/resources/TimeZoneNames_en
+java/util/spi/TimeZoneNameProvider
+java/lang/ProcessBuilder
+java/lang/ProcessImpl
+java/lang/UNIXProcess
+java/lang/Process
+java/lang/UNIXProcess$Gate
+java/lang/UNIXProcess$1
+java/lang/UNIXProcess$1$1
+java/lang/UNIXProcess$1$1$1
+java/net/ServerSocket
+java/util/Random
+java/util/concurrent/atomic/AtomicLong
+java/lang/InternalError
+java/io/StringReader
+java/lang/SecurityException
+java/io/FilterReader
+java/lang/reflect/Proxy
+java/lang/reflect/InvocationHandler
+java/lang/NoSuchFieldException
+java/lang/InstantiationException
+java/lang/ArrayIndexOutOfBoundsException
+java/lang/IndexOutOfBoundsException
+javax/swing/JDialog
+sun/awt/X11/XClipboard
+sun/awt/datatransfer/SunClipboard
+java/awt/datatransfer/Clipboard
+java/awt/datatransfer/SystemFlavorMap
+java/awt/datatransfer/FlavorMap
+java/awt/datatransfer/FlavorTable
+java/awt/datatransfer/SystemFlavorMap$1
+sun/net/ProgressMonitor
+sun/net/DefaultProgressMeteringPolicy
+sun/net/ProgressMeteringPolicy
+java/awt/datatransfer/SystemFlavorMap$2
+java/awt/datatransfer/MimeType
+java/io/Externalizable
+java/awt/datatransfer/MimeTypeParameterList
+sun/awt/datatransfer/DataTransferer
+java/util/Collections$SynchronizedSet
+java/util/Collections$SynchronizedCollection
+java/awt/datatransfer/DataFlavor
+java/awt/datatransfer/DataFlavor$1
+sun/awt/datatransfer/DataTransferer$CharsetComparator
+sun/awt/datatransfer/DataTransferer$IndexedComparator
+sun/nio/cs/UTF_16LE
+sun/nio/cs/UTF_16BE
+sun/awt/datatransfer/DataTransferer$DataFlavorComparator
+java/rmi/Remote
+sun/awt/datatransfer/DataTransferer$1
+sun/awt/X11/XDataTransferer
+sun/awt/datatransfer/ToolkitThreadBlockedHandler
+javax/imageio/ImageTypeSpecifier
+sun/awt/X11/XSelection
+sun/security/action/GetIntegerAction
+sun/awt/X11/XSelection$IncrementalTransferHandler
+sun/awt/X11/XSelection$SelectionEventHandler
+java/awt/datatransfer/Transferable
+java/io/EOFException
+java/util/Vector$1
+java/util/zip/ZipFile$1
+java/util/zip/ZipFile$2
+java/util/jar/JarFile$1
+java/util/PropertyResourceBundle
+java/util/ResourceBundle$Control$1
+java/util/Hashtable$EntrySet
+java/lang/IllegalAccessError
+java/text/MessageFormat
+java/text/MessageFormat$Field
+java/text/Format$Field
+java/lang/CloneNotSupportedException
+sun/reflect/MethodAccessorGenerator
+sun/reflect/AccessorGenerator
+sun/reflect/ClassFileConstants
+java/lang/Void
+sun/reflect/ByteVectorFactory
+sun/reflect/ByteVectorImpl
+sun/reflect/ByteVector
+sun/reflect/ClassFileAssembler
+sun/reflect/UTF8
+sun/reflect/Label
+sun/reflect/Label$PatchInfo
+sun/reflect/MethodAccessorGenerator$1
+sun/reflect/ClassDefiner
+sun/reflect/ClassDefiner$1
+sun/reflect/BootstrapConstructorAccessorImpl
+java/awt/event/ActionListener
+javax/swing/Timer
+javax/swing/Timer$DoPostEvent
+javax/swing/TimerQueue
+javax/swing/TimerQueue$1
+javax/swing/ToolTipManager
+java/awt/event/MouseAdapter
+javax/swing/ToolTipManager$insideTimerAction
+javax/swing/ToolTipManager$outsideTimerAction
+javax/swing/ToolTipManager$stillInsideTimerAction
+javax/swing/ToolTipManager$Actions
+sun/swing/UIAction
+javax/swing/Action
+javax/swing/ToolTipManager$MoveBeforeEnterListener
+java/awt/event/MouseMotionAdapter
+java/util/Hashtable$ValueCollection
+javax/swing/event/CaretListener
+javax/swing/JToolBar
+javax/swing/JSplitPane
+javax/swing/border/Border
+javax/swing/JToggleButton
+javax/swing/border/EmptyBorder
+javax/swing/border/AbstractBorder
+javax/swing/DefaultButtonModel
+javax/swing/ButtonModel
+javax/swing/AbstractButton$Handler
+javax/swing/event/ChangeListener
+java/awt/event/ItemListener
+javax/swing/plaf/metal/MetalButtonUI
+javax/swing/plaf/basic/BasicButtonUI
+javax/swing/plaf/ButtonUI
+javax/swing/plaf/metal/MetalBorders
+javax/swing/plaf/BorderUIResource$CompoundBorderUIResource
+javax/swing/border/CompoundBorder
+javax/swing/plaf/metal/MetalBorders$ButtonBorder
+javax/swing/plaf/basic/BasicBorders$MarginBorder
+javax/swing/plaf/basic/BasicButtonListener
+java/awt/AWTEventMulticaster
+java/awt/event/WindowFocusListener
+java/awt/event/WindowStateListener
+java/awt/event/AdjustmentListener
+java/awt/event/TextListener
+javax/swing/event/AncestorListener
+java/beans/VetoableChangeListener
+javax/swing/ButtonGroup
+javax/swing/JToggleButton$ToggleButtonModel
+javax/swing/plaf/metal/MetalToggleButtonUI
+javax/swing/plaf/basic/BasicToggleButtonUI
+javax/swing/plaf/metal/MetalBorders$ToggleButtonBorder
+java/awt/CardLayout
+javax/swing/Box
+javax/swing/plaf/metal/MetalBorders$TextFieldBorder
+javax/swing/plaf/metal/MetalBorders$Flush3DBorder
+javax/swing/BoxLayout
+javax/swing/JMenuBar
+javax/swing/DefaultSingleSelectionModel
+javax/swing/SingleSelectionModel
+javax/swing/plaf/basic/BasicMenuBarUI
+javax/swing/plaf/MenuBarUI
+javax/swing/plaf/basic/DefaultMenuLayout
+javax/swing/plaf/metal/MetalBorders$MenuBarBorder
+javax/swing/plaf/basic/BasicMenuBarUI$Handler
+javax/swing/KeyboardManager
+javax/swing/event/MenuEvent
+javax/swing/JMenu$MenuChangeListener
+javax/swing/JMenuItem$MenuItemFocusListener
+javax/swing/plaf/basic/BasicMenuUI
+javax/swing/plaf/basic/BasicMenuItemUI
+javax/swing/plaf/MenuItemUI
+javax/swing/plaf/metal/MetalBorders$MenuItemBorder
+javax/swing/plaf/metal/MetalIconFactory
+javax/swing/plaf/metal/MetalIconFactory$MenuArrowIcon
+javax/swing/plaf/basic/BasicMenuUI$Handler
+javax/swing/event/MenuKeyListener
+javax/swing/plaf/basic/BasicMenuItemUI$Handler
+javax/swing/event/MenuDragMouseListener
+javax/swing/event/MouseInputListener
+javax/swing/event/ChangeEvent
+java/awt/event/ContainerEvent
+javax/swing/plaf/metal/MetalIconFactory$MenuItemArrowIcon
+javax/swing/JPopupMenu
+javax/swing/plaf/basic/BasicPopupMenuUI
+javax/swing/plaf/PopupMenuUI
+javax/swing/plaf/basic/BasicLookAndFeel$AWTEventHelper
+java/awt/event/AWTEventListenerProxy
+java/awt/Toolkit$SelectiveAWTEventListener
+java/awt/Toolkit$ToolkitEventMulticaster
+javax/swing/plaf/basic/BasicLookAndFeel$1
+javax/swing/plaf/metal/MetalBorders$PopupMenuBorder
+javax/swing/plaf/basic/BasicPopupMenuUI$BasicPopupMenuListener
+javax/swing/event/PopupMenuListener
+javax/swing/plaf/basic/BasicPopupMenuUI$BasicMenuKeyListener
+javax/swing/plaf/basic/BasicPopupMenuUI$MouseGrabber
+javax/swing/MenuSelectionManager
+javax/swing/plaf/basic/BasicPopupMenuUI$MenuKeyboardHelper
+javax/swing/plaf/basic/BasicPopupMenuUI$MenuKeyboardHelper$1
+java/awt/event/FocusAdapter
+javax/swing/JMenu$WinListener
+java/awt/event/WindowAdapter
+javax/swing/JPopupMenu$Separator
+javax/swing/JSeparator
+javax/swing/plaf/metal/MetalPopupMenuSeparatorUI
+javax/swing/plaf/metal/MetalSeparatorUI
+javax/swing/plaf/basic/BasicSeparatorUI
+javax/swing/plaf/SeparatorUI
+javax/swing/JComboBox
+javax/swing/event/ListDataListener
+javax/swing/event/CaretEvent
+javax/swing/text/TabExpander
+javax/swing/JScrollBar
+java/awt/Adjustable
+javax/swing/event/MouseInputAdapter
+javax/swing/JScrollBar$ModelListener
+javax/swing/DefaultBoundedRangeModel
+javax/swing/BoundedRangeModel
+javax/swing/plaf/metal/MetalScrollBarUI
+javax/swing/plaf/basic/BasicScrollBarUI
+javax/swing/plaf/ScrollBarUI
+javax/swing/plaf/metal/MetalBumps
+javax/swing/plaf/metal/MetalScrollButton
+javax/swing/plaf/basic/BasicArrowButton
+javax/swing/plaf/basic/BasicScrollBarUI$TrackListener
+javax/swing/plaf/basic/BasicScrollBarUI$ArrowButtonListener
+javax/swing/plaf/basic/BasicScrollBarUI$ModelListener
+javax/swing/plaf/metal/MetalScrollBarUI$ScrollBarListener
+javax/swing/plaf/basic/BasicScrollBarUI$PropertyChangeHandler
+javax/swing/plaf/basic/BasicScrollBarUI$Handler
+javax/swing/plaf/basic/BasicScrollBarUI$ScrollListener
+javax/swing/CellRendererPane
+java/util/HashMap$EntryIterator
+javax/swing/border/MatteBorder
+sun/font/StandardGlyphVector
+java/awt/font/GlyphVector
+sun/font/StandardGlyphVector$GlyphStrike
+sun/font/CoreMetrics
+sun/font/FontLineMetrics
+java/awt/font/LineMetrics
+javax/swing/ComboBoxModel
+javax/swing/ListModel
+javax/swing/ListCellRenderer
+javax/swing/DefaultComboBoxModel
+javax/swing/MutableComboBoxModel
+javax/swing/AbstractListModel
+javax/swing/JComboBox$1
+javax/swing/AncestorNotifier
+javax/swing/plaf/metal/MetalComboBoxUI
+javax/swing/plaf/basic/BasicComboBoxUI
+javax/swing/plaf/ComboBoxUI
+javax/swing/plaf/metal/MetalComboBoxUI$MetalComboBoxLayoutManager
+javax/swing/plaf/basic/BasicComboBoxUI$ComboBoxLayoutManager
+javax/swing/plaf/basic/BasicComboPopup
+javax/swing/plaf/basic/ComboPopup
+javax/swing/plaf/basic/BasicComboPopup$EmptyListModelClass
+javax/swing/border/LineBorder
+javax/swing/plaf/basic/BasicComboPopup$1
+javax/swing/JList
+javax/swing/DropMode
+javax/swing/DefaultListSelectionModel
+javax/swing/ListSelectionModel
+javax/swing/plaf/basic/BasicListUI
+javax/swing/plaf/ListUI
+javax/swing/plaf/basic/BasicListUI$ListTransferHandler
+javax/swing/TransferHandler
+javax/swing/TransferHandler$TransferAction
+javax/swing/DefaultListCellRenderer$UIResource
+javax/swing/DefaultListCellRenderer
+javax/swing/TransferHandler$SwingDropTarget
+java/awt/dnd/DropTargetContext
+javax/swing/TransferHandler$DropHandler
+javax/swing/TransferHandler$TransferSupport
+javax/swing/plaf/basic/BasicListUI$Handler
+javax/swing/event/ListSelectionListener
+javax/swing/plaf/basic/DragRecognitionSupport$BeforeDrag
+javax/swing/plaf/basic/BasicComboPopup$Handler
+javax/swing/JScrollPane
+javax/swing/ScrollPaneConstants
+javax/swing/ScrollPaneLayout$UIResource
+javax/swing/ScrollPaneLayout
+javax/swing/JViewport
+javax/swing/ViewportLayout
+javax/swing/plaf/basic/BasicViewportUI
+javax/swing/plaf/ViewportUI
+javax/swing/JScrollPane$ScrollBar
+javax/swing/JViewport$ViewListener
+java/awt/event/ComponentAdapter
+javax/swing/plaf/metal/MetalScrollPaneUI
+javax/swing/plaf/basic/BasicScrollPaneUI
+javax/swing/plaf/ScrollPaneUI
+javax/swing/plaf/metal/MetalBorders$ScrollPaneBorder
+javax/swing/plaf/basic/BasicScrollPaneUI$Handler
+javax/swing/plaf/metal/MetalScrollPaneUI$1
+javax/swing/plaf/basic/BasicComboBoxRenderer$UIResource
+javax/swing/plaf/basic/BasicComboBoxRenderer
+javax/swing/plaf/metal/MetalComboBoxEditor$UIResource
+javax/swing/plaf/metal/MetalComboBoxEditor
+javax/swing/plaf/basic/BasicComboBoxEditor
+javax/swing/ComboBoxEditor
+javax/swing/plaf/basic/BasicComboBoxEditor$BorderlessTextField
+javax/swing/JTextField$NotifyAction
+javax/swing/text/TextAction
+javax/swing/AbstractAction
+javax/swing/text/JTextComponent$MutableCaretEvent
+javax/swing/plaf/metal/MetalTextFieldUI
+javax/swing/plaf/basic/BasicTextFieldUI
+javax/swing/plaf/basic/BasicTextUI
+javax/swing/text/ViewFactory
+javax/swing/plaf/TextUI
+javax/swing/plaf/basic/BasicTextUI$BasicCursor
+javax/swing/text/DefaultEditorKit
+javax/swing/text/EditorKit
+javax/swing/text/DefaultEditorKit$InsertContentAction
+javax/swing/text/DefaultEditorKit$DeletePrevCharAction
+javax/swing/text/DefaultEditorKit$DeleteNextCharAction
+javax/swing/text/DefaultEditorKit$ReadOnlyAction
+javax/swing/text/DefaultEditorKit$DeleteWordAction
+javax/swing/text/DefaultEditorKit$WritableAction
+javax/swing/text/DefaultEditorKit$CutAction
+javax/swing/text/DefaultEditorKit$CopyAction
+javax/swing/text/DefaultEditorKit$PasteAction
+javax/swing/text/DefaultEditorKit$VerticalPageAction
+javax/swing/text/DefaultEditorKit$PageAction
+javax/swing/text/DefaultEditorKit$InsertBreakAction
+javax/swing/text/DefaultEditorKit$BeepAction
+javax/swing/text/DefaultEditorKit$NextVisualPositionAction
+javax/swing/text/DefaultEditorKit$BeginWordAction
+javax/swing/text/DefaultEditorKit$EndWordAction
+javax/swing/text/DefaultEditorKit$PreviousWordAction
+javax/swing/text/DefaultEditorKit$NextWordAction
+javax/swing/text/DefaultEditorKit$BeginLineAction
+javax/swing/text/DefaultEditorKit$EndLineAction
+javax/swing/text/DefaultEditorKit$BeginParagraphAction
+javax/swing/text/DefaultEditorKit$EndParagraphAction
+javax/swing/text/DefaultEditorKit$BeginAction
+javax/swing/text/DefaultEditorKit$EndAction
+javax/swing/text/DefaultEditorKit$DefaultKeyTypedAction
+javax/swing/text/DefaultEditorKit$InsertTabAction
+javax/swing/text/DefaultEditorKit$SelectWordAction
+javax/swing/text/DefaultEditorKit$SelectLineAction
+javax/swing/text/DefaultEditorKit$SelectParagraphAction
+javax/swing/text/DefaultEditorKit$SelectAllAction
+javax/swing/text/DefaultEditorKit$UnselectAction
+javax/swing/text/DefaultEditorKit$ToggleComponentOrientationAction
+javax/swing/text/DefaultEditorKit$DumpModelAction
+javax/swing/plaf/basic/BasicTextUI$TextTransferHandler
+javax/swing/text/Position$Bias
+javax/swing/plaf/basic/BasicTextUI$RootView
+javax/swing/text/View
+javax/swing/plaf/basic/BasicTextUI$UpdateHandler
+javax/swing/event/DocumentListener
+javax/swing/plaf/basic/BasicTextUI$DragListener
+javax/swing/plaf/basic/BasicComboBoxEditor$UIResource
+javax/swing/plaf/basic/BasicTextUI$BasicCaret
+javax/swing/text/DefaultCaret
+javax/swing/text/Caret
+javax/swing/text/DefaultCaret$Handler
+java/awt/datatransfer/ClipboardOwner
+javax/swing/plaf/basic/BasicTextUI$BasicHighlighter
+javax/swing/text/DefaultHighlighter
+javax/swing/text/LayeredHighlighter
+javax/swing/text/Highlighter
+javax/swing/text/Highlighter$Highlight
+javax/swing/text/DefaultHighlighter$DefaultHighlightPainter
+javax/swing/text/LayeredHighlighter$LayerPainter
+javax/swing/text/Highlighter$HighlightPainter
+javax/swing/text/DefaultHighlighter$SafeDamager
+javax/swing/text/FieldView
+javax/swing/text/PlainView
+javax/swing/text/JTextComponent$DefaultKeymap
+javax/swing/text/Keymap
+javax/swing/text/JTextComponent$KeymapWrapper
+javax/swing/text/JTextComponent$KeymapActionMap
+javax/swing/plaf/basic/BasicTextUI$FocusAction
+javax/swing/plaf/basic/BasicTextUI$TextActionWrapper
+javax/swing/JTextArea
+javax/swing/JEditorPane
+javax/swing/JTextField$ScrollRepainter
+javax/swing/plaf/metal/MetalComboBoxEditor$1
+javax/swing/plaf/metal/MetalComboBoxEditor$EditorBorder
+javax/swing/plaf/metal/MetalComboBoxUI$MetalPropertyChangeListener
+javax/swing/plaf/basic/BasicComboBoxUI$PropertyChangeHandler
+javax/swing/plaf/basic/BasicComboBoxUI$Handler
+javax/swing/plaf/metal/MetalComboBoxButton
+javax/swing/plaf/metal/MetalComboBoxIcon
+javax/swing/plaf/metal/MetalComboBoxButton$1
+javax/swing/plaf/basic/BasicComboBoxUI$DefaultKeySelectionManager
+javax/swing/JComboBox$KeySelectionManager
+javax/swing/JToolBar$DefaultToolBarLayout
+javax/swing/plaf/metal/MetalToolBarUI
+javax/swing/plaf/basic/BasicToolBarUI
+javax/swing/plaf/ToolBarUI
+javax/swing/plaf/metal/MetalBorders$ToolBarBorder
+javax/swing/plaf/metal/MetalLookAndFeel$MetalLazyValue$1
+javax/swing/plaf/metal/MetalBorders$RolloverButtonBorder
+javax/swing/plaf/metal/MetalBorders$RolloverMarginBorder
+javax/swing/plaf/basic/BasicBorders$RadioButtonBorder
+javax/swing/plaf/basic/BasicBorders$ButtonBorder
+javax/swing/plaf/basic/BasicBorders$RolloverMarginBorder
+javax/swing/plaf/metal/MetalToolBarUI$MetalDockingListener
+javax/swing/plaf/basic/BasicToolBarUI$DockingListener
+javax/swing/plaf/basic/BasicToolBarUI$Handler
+javax/swing/border/EtchedBorder
+javax/swing/JToolBar$Separator
+javax/swing/plaf/basic/BasicToolBarSeparatorUI
+sun/awt/color/CMM
+java/applet/Applet
+java/awt/Panel
+com/sun/awt/AWTUtilities
+javax/swing/KeyboardManager$ComponentKeyStrokePair
+sun/awt/EmbeddedFrame
+sun/awt/im/InputMethodContext
+java/awt/im/spi/InputMethodContext
+sun/awt/im/InputContext
+sun/awt/im/InputMethodManager
+sun/awt/im/ExecutableInputMethodManager
+sun/awt/X11/XInputMethodDescriptor
+sun/awt/X11InputMethodDescriptor
+java/awt/im/spi/InputMethodDescriptor
+sun/awt/im/InputMethodLocator
+sun/awt/im/ExecutableInputMethodManager$2
+sun/misc/Service
+sun/misc/Service$LazyIterator
+java/util/TreeSet
+java/util/NavigableSet
+java/util/SortedSet
+javax/swing/SizeRequirements
+javax/swing/plaf/basic/BasicGraphicsUtils
+java/awt/event/AdjustmentEvent
+java/awt/MenuBar
+sun/awt/X11/XComponentPeer$2
+java/awt/SequencedEvent
+java/beans/PropertyVetoException
+java/awt/DefaultKeyboardFocusManager$TypeAheadMarker
+java/awt/KeyboardFocusManager$HeavyweightFocusRequest
+java/awt/KeyboardFocusManager$LightweightFocusRequest
+sun/awt/KeyboardFocusManagerPeerImpl
+sun/awt/SunToolkit$7
+java/awt/Window$1DisposeAction
+java/awt/LightweightDispatcher$2
+sun/awt/X11/XReparentEvent
+sun/awt/X11/XWindowAttributes
+javax/swing/SystemEventQueueUtilities$ComponentWorkRequest
+sun/awt/X11/XFocusChangeEvent
+sun/awt/X11/XComponentPeer$1
+sun/awt/X11/XUnmapEvent
+java/io/StringWriter
+javax/swing/JWindow
+java/io/UnsupportedEncodingException
+java/net/UnknownHostException
+java/nio/channels/SocketChannel
+java/nio/channels/spi/AbstractSelectableChannel
+java/nio/channels/SelectableChannel
+java/net/SocketImplFactory
+javax/swing/UnsupportedLookAndFeelException
+java/lang/UnsatisfiedLinkError
+javax/swing/Box$Filler
+javax/swing/JComponent$2
+sun/net/www/MimeTable
+java/net/FileNameMap
+sun/net/www/MimeTable$1
+sun/net/www/MimeTable$2
+sun/net/www/MimeEntry
+java/net/URLConnection$1
+java/text/SimpleDateFormat
+java/text/DateFormat
+java/text/DateFormat$Field
+java/util/Calendar
+java/util/GregorianCalendar
+sun/util/resources/CalendarData
+sun/util/resources/CalendarData_en
+java/text/DateFormatSymbols
+java/text/spi/DateFormatSymbolsProvider
+java/text/DontCareFieldPosition
+java/text/DontCareFieldPosition$1
+java/text/Format$FieldDelegate
+javax/swing/plaf/BorderUIResource
+javax/swing/BorderFactory
+javax/swing/border/BevelBorder
+javax/swing/plaf/metal/MetalIconFactory$TreeFolderIcon
+javax/swing/plaf/metal/MetalIconFactory$FolderIcon16
+java/util/zip/ZipInputStream
+java/io/PushbackInputStream
+java/util/zip/CRC32
+java/util/zip/Checksum
+java/lang/Thread$State
+javax/swing/SwingUtilities$SharedOwnerFrame
+javax/swing/JTable
+javax/swing/event/TableModelListener
+javax/swing/event/TableColumnModelListener
+javax/swing/event/CellEditorListener
+javax/swing/event/RowSorterListener
+javax/swing/BufferStrategyPaintManager$BufferInfo
+java/awt/Component$BltSubRegionBufferStrategy
+sun/awt/SubRegionShowable
+java/awt/Component$BltBufferStrategy
+sun/awt/image/SunVolatileImage
+sun/awt/image/BufferedImageGraphicsConfig
+sun/print/PrinterGraphicsConfig
+sun/java2d/x11/X11VolatileSurfaceManager
+sun/awt/image/VolatileSurfaceManager
+java/awt/print/PrinterGraphics
+java/awt/PrintGraphics
+java/awt/GraphicsCallback$PaintCallback
+java/awt/GraphicsCallback
+sun/awt/SunGraphicsCallback
+javax/swing/JRadioButton
+java/lang/ClassFormatError
+javax/swing/JTabbedPane
+javax/swing/JTabbedPane$ModelListener
+javax/swing/plaf/metal/MetalTabbedPaneUI
+javax/swing/plaf/basic/BasicTabbedPaneUI
+javax/swing/plaf/TabbedPaneUI
+javax/swing/plaf/metal/MetalTabbedPaneUI$TabbedPaneLayout
+javax/swing/plaf/basic/BasicTabbedPaneUI$TabbedPaneLayout
+javax/swing/plaf/basic/BasicTabbedPaneUI$TabbedPaneScrollLayout
+javax/swing/plaf/basic/BasicTabbedPaneUI$Handler
+sun/swing/ImageIconUIResource
+javax/swing/GrayFilter
+java/awt/image/RGBImageFilter
+java/awt/image/ImageFilter
+java/awt/image/FilteredImageSource
+org/w3c/dom/Node
+org/xml/sax/SAXException
+javax/xml/parsers/ParserConfigurationException
+org/xml/sax/EntityResolver
+java/security/NoSuchAlgorithmException
+java/security/GeneralSecurityException
+java/util/zip/GZIPInputStream
+java/util/zip/DeflaterOutputStream
+org/xml/sax/InputSource
+javax/xml/parsers/DocumentBuilderFactory
+javax/xml/parsers/FactoryFinder
+javax/xml/parsers/SecuritySupport
+javax/xml/parsers/SecuritySupport$2
+javax/xml/parsers/SecuritySupport$5
+javax/xml/parsers/SecuritySupport$1
+javax/xml/parsers/SecuritySupport$4
+javax/xml/parsers/DocumentBuilder
+org/w3c/dom/Document
+org/xml/sax/helpers/DefaultHandler
+org/xml/sax/DTDHandler
+org/xml/sax/ContentHandler
+org/xml/sax/ErrorHandler
+org/xml/sax/SAXNotSupportedException
+org/xml/sax/Locator
+org/xml/sax/SAXNotRecognizedException
+org/xml/sax/SAXParseException
+org/w3c/dom/NodeList
+org/w3c/dom/events/EventTarget
+org/w3c/dom/traversal/DocumentTraversal
+org/w3c/dom/events/DocumentEvent
+org/w3c/dom/ranges/DocumentRange
+org/w3c/dom/Entity
+org/w3c/dom/Element
+org/w3c/dom/CharacterData
+org/w3c/dom/CDATASection
+org/w3c/dom/Text
+org/xml/sax/AttributeList
+org/w3c/dom/DOMException
+org/w3c/dom/Notation
+org/w3c/dom/DocumentType
+org/w3c/dom/Attr
+org/w3c/dom/EntityReference
+org/w3c/dom/ProcessingInstruction
+org/w3c/dom/Comment
+org/w3c/dom/DocumentFragment
+org/w3c/dom/events/Event
+org/w3c/dom/events/MutationEvent
+org/w3c/dom/traversal/TreeWalker
+org/w3c/dom/ranges/Range
+org/w3c/dom/traversal/NodeIterator
+org/w3c/dom/events/EventException
+org/w3c/dom/NamedNodeMap
+java/lang/StringIndexOutOfBoundsException
+java/awt/GridLayout
+javax/swing/plaf/metal/MetalRadioButtonUI
+javax/swing/plaf/basic/BasicRadioButtonUI
+javax/swing/plaf/basic/BasicBorders
+javax/swing/plaf/metal/MetalIconFactory$RadioButtonIcon
+java/awt/event/ItemEvent
+java/awt/CardLayout$Card
+javax/swing/JCheckBox
+javax/swing/event/ListSelectionEvent
+javax/swing/plaf/metal/MetalCheckBoxUI
+javax/swing/plaf/metal/MetalIconFactory$CheckBoxIcon
+java/lang/ExceptionInInitializerError
+com/sun/java/swing/plaf/windows/WindowsTabbedPaneUI
+javax/swing/JProgressBar
+javax/swing/JProgressBar$ModelListener
+javax/swing/plaf/metal/MetalProgressBarUI
+javax/swing/plaf/basic/BasicProgressBarUI
+javax/swing/plaf/ProgressBarUI
+javax/swing/plaf/BorderUIResource$LineBorderUIResource
+javax/swing/plaf/basic/BasicProgressBarUI$Handler
+javax/swing/tree/TreeModel
+javax/swing/table/TableCellRenderer
+javax/swing/table/JTableHeader
+javax/swing/event/TreeExpansionListener
+javax/swing/table/AbstractTableModel
+javax/swing/table/TableModel
+javax/swing/table/DefaultTableCellRenderer
+javax/swing/JTree
+javax/swing/tree/TreeSelectionModel
+javax/swing/tree/DefaultTreeCellRenderer
+javax/swing/tree/TreeCellRenderer
+javax/swing/table/TableCellEditor
+javax/swing/CellEditor
+javax/swing/JToolTip
+javax/swing/table/TableColumn
+javax/swing/table/DefaultTableColumnModel
+javax/swing/table/TableColumnModel
+javax/swing/table/DefaultTableModel
+javax/swing/event/TableModelEvent
+sun/swing/table/DefaultTableCellHeaderRenderer
+javax/swing/plaf/basic/BasicTableHeaderUI
+javax/swing/plaf/TableHeaderUI
+javax/swing/plaf/basic/BasicTableHeaderUI$1
+javax/swing/plaf/basic/BasicTableHeaderUI$MouseInputHandler
+javax/swing/DefaultCellEditor
+javax/swing/tree/TreeCellEditor
+javax/swing/AbstractCellEditor
+javax/swing/plaf/basic/BasicTableUI
+javax/swing/plaf/TableUI
+javax/swing/plaf/basic/BasicTableUI$TableTransferHandler
+javax/swing/plaf/basic/BasicTableUI$Handler
+javax/swing/tree/DefaultTreeSelectionModel
+javax/swing/tree/TreePath
+javax/swing/plaf/metal/MetalTreeUI
+javax/swing/plaf/basic/BasicTreeUI
+javax/swing/plaf/TreeUI
+javax/swing/plaf/basic/BasicTreeUI$Actions
+javax/swing/plaf/basic/BasicTreeUI$TreeTransferHandler
+javax/swing/plaf/metal/MetalTreeUI$LineListener
+javax/swing/plaf/basic/BasicTreeUI$Handler
+javax/swing/event/TreeModelListener
+javax/swing/event/TreeSelectionListener
+javax/swing/event/SwingPropertyChangeSupport
+javax/swing/tree/VariableHeightLayoutCache
+javax/swing/tree/AbstractLayoutCache
+javax/swing/tree/RowMapper
+javax/swing/plaf/basic/BasicTreeUI$NodeDimensionsHandler
+javax/swing/tree/AbstractLayoutCache$NodeDimensions
+javax/swing/JTree$TreeModelHandler
+javax/swing/tree/VariableHeightLayoutCache$TreeStateNode
+javax/swing/tree/DefaultMutableTreeNode
+javax/swing/tree/MutableTreeNode
+javax/swing/tree/DefaultMutableTreeNode$1
+javax/swing/tree/DefaultMutableTreeNode$PreorderEnumeration
+javax/swing/event/TableColumnModelEvent
+java/text/ParseException
+java/text/NumberFormat$Field
+javax/swing/event/UndoableEditListener
+javax/swing/filechooser/FileFilter
+javax/swing/tree/DefaultTreeModel
+javax/swing/tree/DefaultTreeCellEditor
+javax/swing/tree/DefaultTreeCellEditor$1
+javax/swing/tree/DefaultTreeCellEditor$DefaultTextField
+javax/swing/DefaultCellEditor$1
+javax/swing/DefaultCellEditor$EditorDelegate
+javax/swing/tree/DefaultTreeCellEditor$EditorContainer
+javax/swing/JTree$TreeSelectionRedirector
+javax/swing/event/TreeModelEvent
+javax/swing/plaf/metal/MetalSplitPaneUI
+javax/swing/plaf/basic/BasicSplitPaneUI
+javax/swing/plaf/SplitPaneUI
+javax/swing/plaf/basic/BasicSplitPaneDivider
+javax/swing/plaf/basic/BasicBorders$SplitPaneBorder
+javax/swing/plaf/metal/MetalSplitPaneDivider
+javax/swing/plaf/basic/BasicSplitPaneDivider$DividerLayout
+javax/swing/plaf/basic/BasicSplitPaneDivider$MouseHandler
+javax/swing/plaf/basic/BasicBorders$SplitPaneDividerBorder
+javax/swing/plaf/basic/BasicSplitPaneUI$BasicHorizontalLayoutManager
+javax/swing/plaf/basic/BasicSplitPaneUI$1
+javax/swing/plaf/basic/BasicSplitPaneUI$Handler
+javax/swing/plaf/metal/MetalSplitPaneDivider$1
+javax/swing/plaf/basic/BasicSplitPaneDivider$OneTouchActionHandler
+javax/swing/plaf/metal/MetalSplitPaneDivider$2
+javax/swing/border/TitledBorder
+javax/swing/plaf/basic/BasicTextAreaUI
+java/util/Collections$UnmodifiableCollection$1
+java/io/InterruptedIOException
+java/net/NoRouteToHostException
+java/net/BindException
+javax/swing/tree/PathPlaceHolder
+javax/swing/event/TreeSelectionEvent
+javax/swing/JList$3
+javax/swing/JList$ListSelectionHandler
+javax/swing/JSlider
+javax/swing/JSlider$ModelListener
+javax/swing/plaf/metal/MetalSliderUI
+javax/swing/plaf/basic/BasicSliderUI
+javax/swing/plaf/SliderUI
+javax/swing/plaf/basic/BasicSliderUI$Actions
+javax/swing/plaf/metal/MetalIconFactory$HorizontalSliderThumbIcon
+javax/swing/plaf/metal/MetalIconFactory$VerticalSliderThumbIcon
+javax/swing/plaf/basic/BasicSliderUI$TrackListener
+javax/swing/plaf/basic/BasicSliderUI$Handler
+javax/swing/plaf/basic/BasicSliderUI$ScrollListener
+javax/swing/plaf/metal/MetalSliderUI$MetalPropertyListener
+javax/swing/plaf/basic/BasicSliderUI$PropertyChangeHandler
+sun/java2d/HeadlessGraphicsEnvironment
+java/util/Hashtable$KeySet
+java/awt/FontFormatException
+sun/java2d/SunGraphicsEnvironment$2
+sun/font/Type1Font$1
+java/nio/channels/FileChannel$MapMode
+sun/nio/ch/FileChannelImpl$Unmapper
+sun/nio/ch/Util$3
+java/nio/DirectByteBufferR
+java/nio/charset/Charset$3
+sun/nio/cs/ext/ExtendedCharsets
+sun/nio/cs/AbstractCharsetProvider
+sun/nio/cs/ext/SJIS
+sun/nio/cs/ext/SJIS$Decoder
+sun/nio/cs/ext/DelegatableDecoder
+sun/nio/cs/ext/JIS_X_0208_Decoder
+sun/nio/cs/ext/DoubleByteDecoder
+sun/nio/cs/ext/JIS_X_0201$Decoder
+sun/nio/cs/SingleByteDecoder
+java/lang/CharacterData00
+javax/swing/DefaultListModel
+javax/swing/event/ListDataEvent
+javax/sound/sampled/DataLine
+javax/sound/sampled/Line
+javax/sound/sampled/Line$Info
+javax/sound/sampled/DataLine$Info
+javax/sound/sampled/Control$Type
+javax/sound/sampled/FloatControl$Type
+javax/sound/sampled/LineUnavailableException
+javax/sound/sampled/UnsupportedAudioFileException
+javax/swing/JRadioButtonMenuItem
+javax/swing/JMenuItem$AccessibleJMenuItem
+javax/swing/AbstractButton$AccessibleAbstractButton
+javax/accessibility/AccessibleAction
+javax/accessibility/AccessibleValue
+javax/accessibility/AccessibleText
+javax/accessibility/AccessibleExtendedComponent
+javax/accessibility/AccessibleComponent
+javax/swing/JComponent$AccessibleJComponent
+java/awt/Container$AccessibleAWTContainer
+java/awt/Component$AccessibleAWTComponent
+javax/accessibility/AccessibleRelationSet
+javax/accessibility/AccessibleState
+javax/accessibility/AccessibleBundle
+javax/swing/plaf/basic/BasicCheckBoxMenuItemUI
+javax/swing/plaf/metal/MetalIconFactory$CheckBoxMenuItemIcon
+javax/swing/JCheckBoxMenuItem$AccessibleJCheckBoxMenuItem
+javax/swing/plaf/basic/BasicRadioButtonMenuItemUI
+javax/swing/plaf/metal/MetalIconFactory$RadioButtonMenuItemIcon
+sun/awt/image/ImageDecoder$1
+javax/swing/JTabbedPane$Page
+java/net/DatagramSocket
+java/net/MulticastSocket
+java/net/DatagramPacket
+sun/net/InetAddressCachePolicy
+sun/net/InetAddressCachePolicy$1
+sun/net/InetAddressCachePolicy$2
+java/net/InetAddress$CacheEntry
+java/net/PlainDatagramSocketImpl
+java/net/DatagramSocketImpl
+java/net/NetworkInterface
+java/net/InterfaceAddress
+java/text/Collator
+java/text/spi/CollatorProvider
+sun/text/resources/CollationData
+sun/text/resources/CollationData_en
+sun/util/EmptyListResourceBundle
+java/text/RuleBasedCollator
+java/text/CollationRules
+java/text/RBCollationTables
+java/text/RBTableBuilder
+java/text/RBCollationTables$BuildAPI
+sun/text/IntHashtable
+sun/text/UCompactIntArray
+sun/text/normalizer/NormalizerImpl
+sun/text/normalizer/ICUData
+sun/text/normalizer/NormalizerDataReader
+sun/text/normalizer/ICUBinary$Authenticate
+sun/text/normalizer/ICUBinary
+sun/text/normalizer/NormalizerImpl$FCDTrieImpl
+sun/text/normalizer/Trie$DataManipulate
+sun/text/normalizer/NormalizerImpl$NormTrieImpl
+sun/text/normalizer/NormalizerImpl$AuxTrieImpl
+sun/text/normalizer/IntTrie
+sun/text/normalizer/Trie
+sun/text/normalizer/CharTrie
+sun/text/normalizer/CharTrie$FriendAgent
+sun/text/normalizer/UnicodeSet
+sun/text/normalizer/UnicodeMatcher
+sun/text/normalizer/NormalizerImpl$DecomposeArgs
+java/text/MergeCollation
+java/text/PatternEntry$Parser
+java/text/PatternEntry
+java/text/EntryPair
+sun/text/ComposedCharIter
+sun/text/normalizer/UTF16
+sun/net/www/protocol/http/Handler
+java/io/ObjectInputStream$BlockDataInputStream
+java/io/ObjectInputStream$PeekInputStream
+java/io/ObjectInputStream$HandleTable
+java/io/ObjectInputStream$ValidationList
+java/io/Bits
+java/io/ObjectStreamClass$Caches
+java/io/ObjectStreamClass$WeakClassKey
+java/io/ObjectStreamClass$EntryFuture
+java/io/ObjectStreamClass$2
+sun/reflect/SerializationConstructorAccessorImpl
+java/io/ObjectStreamClass$FieldReflectorKey
+java/io/ObjectStreamClass$FieldReflector
+java/io/ObjectStreamClass$1
+java/io/DataOutputStream
+java/io/ObjectStreamClass$MemberSignature
+java/io/ObjectStreamClass$3
+java/io/ObjectStreamClass$4
+java/io/ObjectStreamClass$5
+java/security/MessageDigest
+java/security/MessageDigestSpi
+sun/security/jca/GetInstance
+sun/security/jca/Providers
+sun/security/jca/ProviderList
+sun/security/jca/ProviderConfig
+sun/security/jca/ProviderList$3
+sun/security/jca/ProviderList$1
+sun/security/jca/ProviderList$2
+sun/security/jca/ProviderConfig$1
+sun/security/jca/ProviderConfig$3
+java/security/Provider$Service
+java/security/Provider$UString
+sun/security/provider/SHA
+sun/security/provider/DigestBase
+sun/security/jca/GetInstance$Instance
+java/security/MessageDigest$Delegate
+sun/security/provider/ByteArrayAccess
+java/io/ObjectStreamClass$ClassDataSlot
+java/io/ObjectInputStream$CallbackContext
+sun/reflect/UnsafeQualifiedStaticLongFieldAccessorImpl
+java/security/SignatureException
+java/security/InvalidKeyException
+java/security/KeyException
+java/security/Signature
+java/security/SignatureSpi
+java/io/ObjectOutputStream$BlockDataOutputStream
+sun/security/provider/DSAPublicKey
+java/security/interfaces/DSAPublicKey
+java/security/interfaces/DSAKey
+java/security/PublicKey
+java/security/Key
+sun/security/x509/X509Key
+java/io/ObjectOutputStream$HandleTable
+java/io/ObjectOutputStream$ReplaceTable
+sun/security/x509/AlgorithmId
+sun/security/util/DerEncoder
+sun/security/util/BitArray
+sun/security/util/DerOutputStream
+sun/security/util/DerValue
+java/math/BigInteger
+java/security/interfaces/DSAParams
+sun/security/util/DerInputStream
+sun/security/util/DerInputBuffer
+sun/security/util/ObjectIdentifier
+java/security/AlgorithmParameters
+java/security/AlgorithmParametersSpi
+sun/security/provider/DSAParameters
+sun/security/util/ByteArrayLexOrder
+sun/security/util/ByteArrayTagOrder
+sun/security/util/DerIndefLenConverter
+java/io/InvalidClassException
+java/io/ObjectStreamException
+java/io/ObjectInputStream$GetFieldImpl
+java/io/ObjectInputStream$GetField
+sun/security/jca/ServiceId
+sun/security/jca/ProviderList$ServiceList
+sun/security/jca/ProviderList$ServiceList$1
+java/security/Signature$Delegate
+java/security/interfaces/DSAPrivateKey
+java/security/PrivateKey
+sun/security/provider/DSA$SHA1withDSA
+sun/security/provider/DSA
+java/security/spec/DSAParameterSpec
+java/security/spec/AlgorithmParameterSpec
+java/math/MutableBigInteger
+java/math/SignedMutableBigInteger
+java/awt/EventQueue$1AWTInvocationLock
+javax/swing/SystemEventQueueUtilities$RunnableCanvas
+javax/swing/SystemEventQueueUtilities$RunnableCanvasGraphics
+java/awt/Component$FlipBufferStrategy
+java/awt/SentEvent
+sun/awt/X11/XDestroyWindowEvent
+sun/awt/X11/XDropTargetRegistry
+sun/awt/X11/XEmbeddedFramePeer
+sun/awt/X11/XDragAndDropProtocols
+sun/awt/X11/XDropTargetContextPeer
+sun/awt/dnd/SunDropTargetContextPeer
+java/awt/dnd/peer/DropTargetContextPeer
+sun/awt/X11/XDropTargetContextPeer$XDropTargetProtocolListenerImpl
+sun/awt/X11/XDropTargetProtocolListener
+sun/awt/X11/XDnDDragSourceProtocol
+sun/awt/X11/XDragSourceProtocol
+sun/awt/X11/MotifDnDDragSourceProtocol
+sun/awt/X11/XDnDDropTargetProtocol
+sun/awt/X11/XDropTargetProtocol
+sun/awt/X11/MotifDnDDropTargetProtocol
+sun/awt/X11/XDnDConstants
+sun/awt/X11/MotifDnDConstants
+javax/swing/JTable$2
+javax/swing/JTable$Resizable3
+javax/swing/JTable$Resizable2
+javax/swing/JTable$5
+javax/swing/event/AncestorEvent
+sun/font/FontDesignMetrics$MetricsKey
+java/awt/geom/Line2D$Float
+java/awt/geom/Line2D
+com/sun/java/swing/plaf/gtk/GTKLookAndFeel
+javax/swing/plaf/synth/SynthLookAndFeel
+javax/swing/plaf/synth/DefaultSynthStyleFactory
+javax/swing/plaf/synth/SynthStyleFactory
+sun/swing/BakedArrayList
+javax/swing/plaf/synth/SynthLookAndFeel$Handler
+javax/swing/plaf/synth/SynthDefaultLookup
+com/sun/java/swing/plaf/gtk/GTKEngine
+com/sun/java/swing/plaf/gtk/GTKDefaultEngine
+com/sun/java/swing/plaf/gtk/GTKEngine$Settings
+com/sun/java/swing/plaf/gtk/GTKStyleFactory
+com/sun/java/swing/plaf/gtk/PangoFonts
+sun/font/FontManager$FontConfigInfo
+com/sun/java/swing/plaf/gtk/GTKLookAndFeel$WeakPCL
+javax/swing/plaf/synth/Region
+javax/swing/plaf/synth/SynthLookAndFeel$AATextListener
+com/sun/java/swing/plaf/gtk/GTKNativeEngine
+com/sun/java/swing/plaf/gtk/GTKNativeEngine$WidgetType
+com/sun/java/swing/plaf/gtk/GTKRegion
+com/sun/java/swing/plaf/gtk/GTKDefaultStyle
+com/sun/java/swing/plaf/gtk/GTKStyle
+com/sun/java/swing/plaf/gtk/GTKConstants
+javax/swing/plaf/synth/SynthStyle
+javax/swing/plaf/synth/SynthGraphicsUtils
+com/sun/java/swing/plaf/gtk/GTKGraphicsUtils
+com/sun/java/swing/plaf/gtk/GTKStyle$GTKStockIcon
+sun/swing/plaf/synth/SynthIcon
+com/sun/java/swing/plaf/gtk/GTKColorType
+javax/swing/plaf/synth/ColorType
+com/sun/java/swing/plaf/gtk/resources/gtk
+com/sun/swing/internal/plaf/synth/resources/synth
+com/sun/java/swing/plaf/gtk/GTKStyle$GTKLazyValue
+com/sun/java/swing/plaf/gtk/GTKLookAndFeel$1FontLazyValue
+com/sun/java/swing/plaf/gtk/GTKLookAndFeel$2
+com/sun/java/swing/plaf/gtk/GTKLookAndFeel$3
+javax/swing/plaf/synth/SynthPanelUI
+javax/swing/plaf/synth/SynthConstants
+javax/swing/plaf/synth/SynthContext
+javax/swing/plaf/synth/SynthBorder
+javax/swing/plaf/synth/SynthRootPaneUI
+javax/swing/plaf/synth/SynthLabelUI
+javax/swing/plaf/synth/SynthButtonUI
+javax/swing/plaf/synth/SynthToggleButtonUI
+javax/swing/plaf/basic/BasicBorders$FieldBorder
+javax/swing/plaf/synth/SynthMenuBarUI
+javax/swing/plaf/synth/DefaultMenuLayout
+javax/swing/plaf/synth/SynthMenuUI
+javax/swing/plaf/synth/SynthUI
+com/sun/java/swing/plaf/gtk/GTKIconFactory
+com/sun/java/swing/plaf/gtk/GTKIconFactory$MenuArrowIcon
+com/sun/java/swing/plaf/gtk/GTKIconFactory$DelegatingIcon
+com/sun/java/swing/plaf/gtk/GTKConstants$ArrowType
+javax/swing/plaf/basic/BasicIconFactory
+javax/swing/plaf/basic/BasicIconFactory$MenuItemCheckIcon
+javax/swing/plaf/synth/SynthMenuItemUI
+javax/swing/plaf/synth/SynthPopupMenuUI
+javax/swing/plaf/synth/SynthSeparatorUI
+javax/swing/plaf/synth/SynthScrollBarUI
+javax/swing/plaf/synth/SynthArrowButton
+javax/swing/plaf/synth/SynthArrowButton$SynthArrowButtonUI
+javax/swing/plaf/synth/SynthComboBoxUI
+javax/swing/plaf/synth/SynthComboPopup
+javax/swing/plaf/synth/SynthListUI
+javax/swing/plaf/synth/SynthListUI$SynthListCellRenderer
+javax/swing/plaf/synth/SynthViewportUI
+javax/swing/plaf/synth/SynthScrollPaneUI
+javax/swing/plaf/synth/SynthScrollPaneUI$ViewportBorder
+javax/swing/plaf/synth/SynthComboBoxUI$SynthComboBoxRenderer
+javax/swing/plaf/synth/SynthComboBoxUI$SynthComboBoxEditor
+javax/swing/plaf/synth/SynthTextFieldUI
+javax/swing/plaf/synth/SynthToolBarUI
+javax/swing/plaf/synth/SynthToolBarUI$SynthToolBarLayoutManager
+com/sun/java/swing/plaf/gtk/GTKIconFactory$ToolBarHandleIcon
+com/sun/java/swing/plaf/gtk/GTKConstants$Orientation
+sun/awt/X11/XTranslateCoordinates
+com/sun/java/swing/plaf/gtk/GTKPainter
+javax/swing/plaf/synth/SynthPainter
+javax/swing/plaf/synth/SynthPainter$1
+com/sun/java/swing/plaf/gtk/GTKConstants$PositionType
+com/sun/java/swing/plaf/gtk/GTKConstants$ShadowType
+java/io/ObjectInputStream$HandleTable$HandleList
+sun/java2d/pipe/ShapeSpanIterator
+sun/java2d/pipe/SpanIterator
+sun/dc/path/PathConsumer
+sun/dc/pr/PathStroker
+sun/dc/pr/PathDasher
+java/awt/geom/LineIterator
+java/awt/geom/PathIterator
+sun/applet/Main
+sun/applet/AppletMessageHandler
+sun/applet/resources/MsgAppletViewer
+sun/applet/AppletSecurity
+sun/awt/AWTSecurityManager
+java/lang/SecurityManager
+java/security/DomainCombiner
+sun/applet/AppletSecurity$1
+java/lang/SecurityManager$1
+java/security/SecurityPermission
+java/util/PropertyPermission
+sun/applet/AppletViewer
+java/applet/AppletContext
+java/awt/print/Printable
+sun/security/util/SecurityConstants
+java/awt/AWTPermission
+java/net/NetPermission
+java/net/SocketPermission
+javax/security/auth/AuthPermission
+java/lang/Thread$1
+java/util/logging/LogManager$5
+java/util/logging/LogManager$6
+sun/applet/StdAppletViewerFactory
+sun/applet/AppletViewerFactory
+sun/applet/AppletViewer$UserActionListener
+sun/applet/AppletViewerPanel
+sun/applet/AppletPanel
+java/applet/AppletStub
+sun/misc/MessageUtils
+sun/applet/AppletPanel$10
+java/security/Policy$1
+sun/security/provider/PolicyFile$1
+sun/security/provider/PolicyInfo
+sun/security/provider/PolicyFile$3
+sun/security/util/PropertyExpander
+sun/security/provider/PolicyParser
+sun/security/util/PolicyUtil
+sun/security/provider/PolicyParser$GrantEntry
+sun/security/provider/PolicyParser$PermissionEntry
+sun/security/provider/PolicyFile$PolicyEntry
+sun/security/provider/PolicyFile$6
+sun/security/provider/PolicyFile$7
+sun/security/provider/SelfPermission
+java/net/SocketPermissionCollection
+java/util/PropertyPermissionCollection
+sun/applet/AppletPanel$9
+sun/applet/AppletClassLoader
+sun/applet/AppletClassLoader$4
+sun/applet/AppletThreadGroup
+sun/applet/AppContextCreator
+sun/applet/AppletPanel$1
+sun/awt/X11/XMenuBarPeer
+java/awt/peer/MenuBarPeer
+java/awt/peer/MenuComponentPeer
+sun/awt/X11/XBaseMenuWindow
+sun/awt/X11/XMenuPeer
+java/awt/peer/MenuPeer
+java/awt/peer/MenuItemPeer
+sun/awt/X11/XMenuItemPeer
+java/awt/MenuShortcut
+sun/awt/X11/XMenuWindow
+sun/awt/X11/XMenuBarPeer$1
+sun/awt/X11/XMenuItemPeer$TextMetrics
+sun/awt/AppContext$3
+sun/awt/MostRecentThreadAppContext
+sun/awt/X11/XMenuBarPeer$MappingData
+sun/awt/X11/XBaseMenuWindow$MappingData
+sun/applet/AppletViewer$1
+sun/applet/AppletViewer$1AppletEventListener
+sun/applet/AppletListener
+sun/applet/AppletEventMulticaster
+sun/misc/Queue
+sun/misc/QueueElement
+sun/applet/AppletEvent
+sun/applet/AppletClassLoader$1
+sun/awt/X11/XBaseMenuWindow$3
+java/awt/DefaultKeyboardFocusManager$DefaultKeyboardFocusManagerSentEvent
+sun/awt/CausedFocusEvent
+sun/awt/X11/XWindow$1
+java/net/URLClassLoader$4
+sun/applet/AppletClassLoader$2
+javax/swing/JApplet
+java/lang/ClassLoader$1
+sun/security/provider/PolicyFile$5
+java/security/PermissionsEnumerator
+java/util/Collections$1
+sun/applet/AppletPanel$11
+sun/applet/AppletPanel$8
+sun/applet/AppletPanel$2
+sun/applet/AppletPanel$3
+sun/applet/AppletPanel$6
+javax/swing/BufferStrategyPaintManager$1
+# f3ac8b467e7f8c49
diff --git a/jdk/src/bsd/doc/man/DO_NOT_EDIT--GENERATED_FILES b/jdk/src/bsd/doc/man/DO_NOT_EDIT--GENERATED_FILES
new file mode 100644
index 0000000..9b33f60
--- /dev/null
+++ b/jdk/src/bsd/doc/man/DO_NOT_EDIT--GENERATED_FILES
@@ -0,0 +1,2 @@
+These files are generated from docs/technotes/tools pages in the
+jdk/pubs subspace of the jdk workspace (adjacent to jdk/j2se).
diff --git a/jdk/src/bsd/doc/man/appletviewer.1 b/jdk/src/bsd/doc/man/appletviewer.1
new file mode 100644
index 0000000..3f6cd51
--- /dev/null
+++ b/jdk/src/bsd/doc/man/appletviewer.1
@@ -0,0 +1,66 @@
+." Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH appletviewer 1 "10 May 2011"
+
+.LP
+.SH "Name"
+appletviewer \- The Java Applet Viewer.
+.LP
+.LP
+The \f3appletviewer\fP command allows you to run applets outside of a web browser.
+.LP
+.SH "SYNOPSIS"
+.LP
+.LP
+\f4appletviewer\fP \f2[\fP \f2options\fP \f2] \fP\f2urls\fP ...
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3appletviewer\fP command connects to the documents or resources designated by \f2urls\fP and displays each applet referenced by the documents in its own window. Note: if the documents referred to by \f2urls\fP do not reference any applets with the \f2OBJECT\fP, \f2EMBED\fP, or \f2APPLET\fP tag, then \f3appletviewer\fP does nothing. For details on the HTML tags that \f3appletviewer\fP supports, see
+.na
+\f2AppletViewer Tags\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/appletviewertags.html.
+.LP
+.LP
+\f3Note:\fP The \f3appletviewer\fP requires encoded URLs according to the escaping mechanism defined in RFC2396. Only encoded URLs are supported. However, file names must be unencoded, as specified in RFC2396.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-debug
+Starts the applet viewer in the Java debugger, jdb(1), thus allowing you to debug the applets in the document.
+.TP 3
+\-encoding \  \ encoding name
+Specify the input HTML file encoding name.
+.TP 3
+\-Jjavaoption
+Passes through the string \f2javaoption\fP as a single argument to the Java interpreter which runs the appletviewer. The argument should not contain spaces. Multiple argument words must all begin with the prefix \f3\-J\fP, which is stripped. This is useful for adjusting the compiler's execution environment or memory usage.
+.RE
+
+.LP
+.LP
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/apt.1 b/jdk/src/bsd/doc/man/apt.1
new file mode 100644
index 0000000..1037a3b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/apt.1
@@ -0,0 +1,153 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH apt 1 "10 May 2011"
+
+.LP
+.SH "NAME"
+.LP
+.LP
+\f2apt\fP \- annotation processing tool
+.LP
+.SH "SYNOPSIS"
+.LP
+.LP
+\f2apt [\-classpath \fP\f2classpath\fP] [\-sourcepath \f2sourcepath\fP] [\-d \f2directory\fP] [\-s \f2directory\fP] [\-factorypath \f2path\fP] [\-factory \f2class\fP] [\-print] [\-nocompile] [\-A\f2key\fP[\f2=val\fP] ...] [\f2javac option\fP] sourcefiles [@files]
+.LP
+.SH "PARAMETERS"
+.LP
+.LP
+Options may be in any order. For a discussion of parameters which apply to a specific option, see OPTIONS below.
+.LP
+.RS 3
+.TP 3
+sourcefiles
+Zero or more source files to be processed.
+.TP 3
+@files
+One or more files that list source files or other options
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3Note\fP: The \f2apt\fP tool and its associated API contained in the package \f2com.sun.mirror\fP have been deprecated since JDK 7 and are planned to be removed in the next major JDK release. Use the options available in the \f2javac(1)\fP tool and the APIs contained in the packages \f2javax.annotation.processing\fP and \f2javax.lang.model\fP to process annotations.
+.LP
+.LP
+The tool \f2apt\fP, annotation processing tool, includes reflective APIs and supporting infrastructure to process program annotations. The \f2apt\fP reflective APIs provide a build\-time, source\-based, read\-only view of program structure. These reflective APIs are designed to cleanly model the Java(TM) programming language's type system after the addition of generics. First, \f2apt\fP runs annotation processors that can produce new source code and other files. Next, \f2apt\fP can cause compilation of both original and generated source files, easing development. The reflective APIs and other APIs used to interact with the tool are subpackages of \f2com.sun.mirror\fP.
+.LP
+.LP
+A fuller discussion of how the tool operates as well as instructions for developing with \f2apt\fP are in
+.na
+\f4Getting Started with \fP\f4apt\fP. @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/apt/GettingStarted.html
+.LP
+.SH "OPTIONS"
+.LP
+.SS
+apt specific options
+.LP
+.RS 3
+.TP 3
+\-s dir
+Specify the directory root under which processor\-generated source files will be placed; files are placed in subdirectories based on package namespace.
+.TP 3
+\-nocompile
+Do not compile source files to class files.
+.TP 3
+\-print
+Print out textual representation of specified types; perform no annotation processing or compilation.
+.TP 3
+\-A[key[=val]]
+Options to pass to annotation processors \-\- these are not interpreted by \f2apt\fP directly, but are made available for use by individual processors
+.TP 3
+\-factorypath path
+Specify where to find annotation processor factories; if this option is used, the classpath is \f2not\fP searched for factories.
+.TP 3
+\-factory classname
+Name of annotation processor factory to use; bypasses default discovery process
+.TP 3
+\-version
+Print version information.
+.TP 3
+\-X
+Display information about non\-standard options.
+.RE
+
+.LP
+.SS
+Options shared with javac
+.LP
+.RS 3
+.TP 3
+\-d dir
+Specify where to place processor and javac generated class files
+.TP 3
+\-cp path or \-classpath path
+Specify where to find user class files and annotation processor factories. If \f2\-factorypath\fP is given, the classpath is not searched for factories.
+.RE
+
+.LP
+.LP
+Consult the javac(1) man page for information on \f2javac\fP options.
+.LP
+.SS
+Non\-Standard Options
+.LP
+.RS 3
+.TP 3
+\-XListAnnotationTypes
+List found annotation types.
+.TP 3
+\-XListDeclarations
+List specified and included declarations.
+.TP 3
+\-XPrintAptRounds
+Print information about initial and recursive \f2apt\fP rounds.
+.TP 3
+\-XPrintFactoryInfo
+Print information about which annotations a factory is asked to process.
+.TP 3
+\-XclassesAsDecls
+Treat both class and source files as declarations to process.
+.RE
+
+.LP
+.LP
+\f3Note\fP: Because these options are non\-standard, they are subject to change without notice.
+.LP
+.SH "NOTES"
+.LP
+.LP
+The \f2apt\fP tool and its associated API contained in the package \f2com.sun.mirror\fP have been deprecated since JDK 7 and are planned to be removed in the next major JDK release. Use the options available in the \f2javac(1)\fP tool and the APIs contained in the packages \f2javax.annotation.processing\fP and \f2javax.lang.model\fP to process annotations.
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+javac(1), java(1)
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/extcheck.1 b/jdk/src/bsd/doc/man/extcheck.1
new file mode 100644
index 0000000..750a8e2
--- /dev/null
+++ b/jdk/src/bsd/doc/man/extcheck.1
@@ -0,0 +1,73 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH extcheck 1 "10 May 2011"
+
+.LP
+.SH "Name"
+extcheck \- A utility to detect jar conflicts
+.LP
+.LP
+\f3extcheck\fP detects version conflicts between a target jar file and currently installed extension jar files.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+extcheck [ \-verbose ] targetfile.jar
+.fl
+\fP
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3extcheck\fP utility checks a specified Jar file for title and version conflicts with any extensions installed in the Java(TM) SDK. Before installing an extension, you can use this utility to see if the same or a more recent version of the extension is already installed.
+.LP
+.LP
+The \f3extcheck\fP utility compares the \f2Specification\-title\fP and \f2Specification\-version\fP headers in the manifest of the \f2targetfile.jar\fP file against the corresponding headers in all Jar files currently installed in the extension directory. (The extension directory is \f2jre/lib/ext\fP by default.) The \f3extcheck\fP utility compares version numbers in the same way as the method \f2java.lang.Package.isCompatibleWith\fP.
+.LP
+.LP
+If no conflict is detected, the return code is \f20\fP.
+.LP
+.LP
+If the manifest of any jar file in the extensions directory has the same \f2Specification\-title\fP and the same or a newer \f2Specification\-version\fP number, a non\-zero error code is returned. A non\-zero error code is also returned if \f2targetfile.jar\fP does not have the \f2Specification\-title\fP or \f2Specification\-version\fP attributes in its manifest.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-verbose
+Lists Jar files in the extension directory as they are checked. Additionally, manifest attributes of the target jar file and any conflicting jar files are also reported.
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for the java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes.
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.LP
+jar(1)
+.LP
+
diff --git a/jdk/src/bsd/doc/man/idlj.1 b/jdk/src/bsd/doc/man/idlj.1
new file mode 100644
index 0000000..d73b62a
--- /dev/null
+++ b/jdk/src/bsd/doc/man/idlj.1
@@ -0,0 +1,739 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH idlj 1 "10 May 2011"
+
+.LP
+.SH "Name"
+idlj \- The IDL\-to\-Java Compiler
+.LP
+\f3idlj\fP generates Java bindings from a given IDL file.
+.SH "Synopsis"
+.LP
+.nf
+\f3
+.fl
+idlj [ \fP\f3options\fP\f3 ] \fP\f4idl\-file\fP\f3
+.fl
+\fP
+.fi
+
+.LP
+.LP
+where \f2idl\-file\fP is the name of a file containing Interface Definition Language (IDL) definitions. \f2Options\fP may appear in any order, but must precede the \f2idl\-file\fP.
+.LP
+.SH "Description"
+.LP
+.LP
+The IDL\-to\-Java Compiler generates the Java bindings for a given IDL file.\  For binding details, see the
+.na
+\f2OMG IDL to Java Language Language Mapping Specification\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/mapping/jidlMapping.html. Some previous releases of the IDL\-to\-Java compiler were named \f2idltojava\fP.
+.LP
+.SS
+Emitting Client and Server Bindings
+.LP
+.LP
+To generate Java bindings for an IDL file named My.idl:
+.LP
+.nf
+\f3
+.fl
+idlj My.idl
+.fl
+\fP
+.fi
+
+.LP
+.LP
+This generates the client\-side bindings and is equivalent to:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-fclient\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+The client\-side bindings do not include the server\-side skeleton. If you want to generate the server\-side bindings for the interfaces:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-fserver\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+Server\-side bindings include the client\-side bindings plus the skeleton, all of which are \f2POA\fP (that is, Inheritance Model) classes. If you want to generate both client and server\-side bindings, use one of the following (equivalent) commands:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-fclient \-fserver\fP My.idl
+.fl
+idlj \f3\-fall\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+There are two possible server\-side models: the Inheritance Model and the Tie Delegation Model.
+.LP
+.LP
+The default server\-side model is the \f2Portable Servant Inheritance Model\fP. Given an interface \f2My\fP defined in \f2My.idl\fP, the file \f2MyPOA.java\fP is generated. You must provide the implementation for \f2My\fP and it must inherit from \f2MyPOA\fP.
+.LP
+.LP
+\f2MyPOA.java\fP is a stream\-based skeleton that extends
+.na
+\f2org.omg.PortableServer.Servant\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/org/omg/PortableServer/Servant.html and implements the \f2InvokeHandler\fP interface and the operations interface associated with the IDL interface the skeleton implements.
+.LP
+.LP
+The \f2PortableServer\fP module for the
+.na
+\f2Portable Object Adapter (POA)\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/POA.html defines the native \f2Servant\fP type. In the Java programming language, the \f2Servant\fP type is mapped to the Java \f2org.omg.PortableServer.Servant\fP class. It serves as the base class for all POA servant implementations and provides a number of methods that may be invoked by the application programmer, as well as methods which are invoked by the POA itself and may be overridden by the user to control aspects of servant behavior.
+.LP
+.LP
+Another option for the Inheritance Model is to use the \f2\-oldImplBase\fP flag in order to generate server\-side bindings that are compatible with versions of the Java programming language prior to J2SE 1.4. Note that using the \f2\-oldImplBase\fP flag is non\-standard: these APIs are being deprecated. You would use this flag ONLY for compatibility with existing servers written in J2SE 1.3. In that case, you would need to modify an existing MAKEFILE to add the \f2\-oldImplBase\fP flag to the \f2idlj\fP compiler, otherwise POA\-based server\-side mappings will be generated. To generate server\-side bindings that are backwards compatible:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-fclient \-fserver\fP \f3\-oldImplBase\fP My.idl
+.fl
+idlj \f3\-fall\fP \f3\-oldImplBase\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+Given an interface \f2My\fP defined in \f2My.idl\fP, the file \f2_MyImplBase.java\fP is generated. You must provide the implementation for \f2My\fP and it must inherit from \f2_MyImplBase\fP.
+.LP
+.LP
+The other server\-side model is called the Tie Model. This is a delegation model. Because it is not possible to generate ties and skeletons at the same time, they must be generated separately. The following commands generate the bindings for the Tie Model:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-fall\fP My.idl
+.fl
+idlj \f3\-fallTIE\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+For the interface \f2My\fP, the second command generates \f2MyPOATie.java\fP. The constructor to \f2MyPOATie\fP takes a \f2delegate\fP. In this example, using the default POA model, the constructor also needs a \f2poa\fP. You must provide the implementation for \f2delegate\fP, but it does not have to inherit from any other class, only the interface \f2MyOperations\fP. But to use it with the ORB, you must wrap your implementation within \f2MyPOATie\fP. For instance:
+.LP
+.nf
+\f3
+.fl
+    ORB orb = ORB.init(args, System.getProperties());
+.fl
+
+.fl
+    // Get reference to rootpoa & activate the POAManager
+.fl
+    POA rootpoa = (POA)orb.resolve_initial_references("RootPOA");
+.fl
+    rootpoa.the_POAManager().activate();
+.fl
+
+.fl
+    // create servant and register it with the ORB
+.fl
+    MyServant myDelegate = new MyServant();
+.fl
+    myDelegate.setORB(orb);
+.fl
+
+.fl
+    // create a tie, with servant being the delegate.
+.fl
+    MyPOATie tie = new MyPOATie(myDelegate, rootpoa);
+.fl
+
+.fl
+    // obtain the objectRef for the tie
+.fl
+    My ref = tie._this(orb);
+.fl
+\fP
+.fi
+
+.LP
+.LP
+You might want to use the Tie model instead of the typical Inheritance model if your implementation must inherit from some other implementation. Java allows any number of interface inheritance, but there is only one slot for class inheritance. If you use the inheritance model, that slot is used up . By using the Tie Model, that slot is freed up for your own use. The drawback is that it introduces a level of indirection: one extra method call occurs when invoking a method.
+.LP
+.LP
+To generate server\-side, Tie model bindings that are compatible with versions of the IDL to Java language mapping in versions prior to J2SE 1.4.
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-oldImplBase\fP \f3\-fall\fP My.idl
+.fl
+idlj \f3\-oldImplBase\fP \f3\-fallTIE\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+For the interface \f2My\fP, this will generate \f2My_Tie.java\fP. The constructor to \f2My_Tie\fP takes a \f2impl\fP. You must provide the implementation for \f2impl\fP, but it does not have to inherit from any other class, only the interface \f2HelloOperations\fP. But to use it with the ORB, you must wrap your implementation within \f2My_Tie\fP. For instance:
+.LP
+.nf
+\f3
+.fl
+    ORB orb = ORB.init(args, System.getProperties());
+.fl
+
+.fl
+    // create servant and register it with the ORB
+.fl
+    MyServant myDelegate = new MyServant();
+.fl
+    myDelegate.setORB(orb);
+.fl
+
+.fl
+    // create a tie, with servant being the delegate.
+.fl
+    MyPOATie tie = new MyPOATie(myDelegate);
+.fl
+
+.fl
+    // obtain the objectRef for the tie
+.fl
+    My ref = tie._this(orb);
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Specifying Alternate Locations for Emitted Files
+.LP
+.LP
+If you want to direct the emitted files to a directory other than the current directory, invoke the compiler as:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-td /altdir\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+For the interface \f2My\fP, the bindings will be emitted to \f2/altdir/My.java\fP, etc., instead of \f2./My.java\fP.
+.LP
+.SS
+Specifying Alternate Locations for Include Files
+.LP
+.LP
+If \f2My.idl\fP included another idl file, \f2MyOther.idl\fP, the compiler assumes that \f2MyOther.idl\fP resides in the local directory. If it resides in \f2/includes\fP, for example, then you would invoke the compiler with the following command:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-i /includes\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+If \f2My.idl\fP also included \f2Another.idl\fP that resided in \f2/moreIncludes\fP, for example, then you would invoke the compiler with the following command:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-i /includes \-i /moreIncludes\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+Since this form of include can become irritatingly long, another means of indicating to the compiler where to search for included files is provided. This technique is similar to the idea of an environment variable. Create a file named \f2idl.config\fP in a directory that is listed in your CLASSPATH. Inside of \f2idl.config\fP, provide a line with the following form:
+.LP
+.nf
+\f3
+.fl
+includes=/includes;/moreIncludes
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The compiler will find this file and read in the includes list. Note that in this example the separator character between the two directories is a semicolon (;). This separator character is platform dependent. On the Windows platform, use a semicolon, on the Unix platform, use a colon, etc. For more information on \f2includes\fP, see the
+.na
+\f2Setting the Classpath\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#general.
+.LP
+.SS
+Emitting Bindings for Include Files
+.LP
+.LP
+By default, only those interfaces, structs, etc, that are defined in the idl file on the command line have Java bindings generated for them. The types defined in included files are not generated. For example, assume the following two idl files:
+.LP
+
+.LP
+.LP
+\f4My.idl\fP
+.LP
+.nf
+\f3
+.fl
+#include <MyOther.idl>
+.fl
+interface My
+.fl
+{
+.fl
+};
+.fl
+\fP
+.fi
+
+.LP
+
+.LP
+.LP
+\f4MyOther.idl\fP
+.LP
+.nf
+\f3
+.fl
+interface MyOther
+.fl
+{
+.fl
+};
+.fl
+\fP
+.fi
+
+.LP
+
+.LP
+.LP
+The following command will only generate the java bindings for \f2My\fP:
+.LP
+.nf
+\f3
+.fl
+idlj My.idl
+.fl
+\fP
+.fi
+
+.LP
+.LP
+To generate all of the types in \f2My.idl\fP and all of the types in the files that \f2My.idl\fP includes (in this example, \f2MyOther.idl\fP), use the following command:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-emitAll\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+There is a caveat to the default rule. \f2#include\fP statements which appear at global scope are treated as described. These \f2#include\fP statements can be thought of as import statements. \f2#include\fP statements which appear within some enclosing scope are treated as true \f2#include\fP statements, meaning that the code within the included file is treated as if it appeared in the original file and, therefore, Java bindings are emitted for it. Here is an example:
+.LP
+
+.LP
+.LP
+\f4My.idl\fP
+.LP
+.nf
+\f3
+.fl
+#include <MyOther.idl>
+.fl
+interface My
+.fl
+{
+.fl
+  #include <Embedded.idl>
+.fl
+};
+.fl
+\fP
+.fi
+
+.LP
+
+.LP
+.LP
+\f4MyOther.idl\fP
+.LP
+.nf
+\f3
+.fl
+interface MyOther
+.fl
+{
+.fl
+};
+.fl
+\fP
+.fi
+
+.LP
+
+.LP
+.LP
+\f4Embedded.idl\fP
+.LP
+.nf
+\f3
+.fl
+enum E {one, two, three};
+.fl
+\fP
+.fi
+
+.LP
+
+.LP
+.LP
+Running the following command:
+.LP
+.nf
+\f3
+.fl
+idlj My.idl
+.fl
+\fP
+.fi
+
+.LP
+.LP
+will generate the following list of Java files:
+.LP
+.nf
+\f3
+.fl
+./MyHolder.java
+.fl
+./MyHelper.java
+.fl
+./_MyStub.java
+.fl
+./MyPackage
+.fl
+./MyPackage/EHolder.java
+.fl
+./MyPackage/EHelper.java
+.fl
+./MyPackage/E.java
+.fl
+./My.java
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Notice that \f2MyOther.java\fP was not generated because it is defined in an import\-like \f2#include\fP. But \f2E.java\fP \f2was\fP generated because it was defined in a true \f2#include\fP. Also notice that since \f2Embedded.idl\fP was included within the scope of the interface \f2My\fP, it appears within the scope of \f2My\fP (that is,in \f2MyPackage\fP).
+.LP
+.LP
+If the \f2\-emitAll\fP flag had been used in the previous example, then all types in all included files would be emitted.
+.LP
+.SS
+Inserting Package Prefixes
+.LP
+.LP
+Suppose that you work for a company named ABC that has constructed the following IDL file:
+.LP
+
+.LP
+.LP
+\f4Widgets.idl\fP
+.LP
+.nf
+\f3
+.fl
+module Widgets
+.fl
+{
+.fl
+  interface W1 {...};
+.fl
+  interface W2 {...};
+.fl
+};
+.fl
+\fP
+.fi
+
+.LP
+
+.LP
+.LP
+Running this file through the IDL\-to\-Java compiler will place the Java bindings for \f2W1\fP and \f2W2\fP within the package \f2Widgets\fP. But there is an industry convention that states that a company's packages should reside within a package named \f2com.<company name>\fP. The \f2Widgets\fP package is not good enough. To follow convention, it should be \f2com.abc.Widgets\fP. To place this package prefix onto the \f2Widgets\fP module, execute the following:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-pkgPrefix Widgets com.abc\fP Widgets.idl
+.fl
+.fi
+
+.LP
+.LP
+If you have an IDL file which includes \f2Widgets.idl\fP, the \f2\-pkgPrefix\fP flag must appear in that command also. If it does not, then your IDL file will be looking for a \f2Widgets\fP package rather than a \f2com.abc.Widgets\fP package.
+.LP
+.LP
+If you have a number of these packages that require prefixes, it might be easier to place them into the \f2idl.config\fP file described above. Each package prefix line should be of the form:
+.LP
+.nf
+\f3
+.fl
+PkgPrefix.<type>=<prefix>
+.fl
+\fP
+.fi
+
+.LP
+So the line for the above example would be:
+.nf
+\f3
+.fl
+PkgPrefix.Widgets=com.abc
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The use of this option does not affect the Repository ID.
+.LP
+.SS
+Defining Symbols Before Compilation
+.LP
+.LP
+You may need to define a symbol for compilation that is not defined within the IDL file, perhaps to include debugging code in the bindings. The command
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-d\fP MYDEF My.idl
+.fl
+.fi
+
+.LP
+.LP
+is the equivalent of putting the line \f2#define MYDEF\fP inside \f2My.idl\fP.
+.LP
+.SS
+Preserving Pre\-Existing Bindings
+.LP
+.LP
+If the Java binding files already exist, the \f2\-keep\fP flag will keep the compiler from overwriting them. The default is to generate all files without considering if they already exist. If you've customized those files (which you should not do unless you are very comfortable with their contents), then the \f2\-keep\fP option is very useful. The command
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-keep\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+emits all client\-side bindings that do not already exist.
+.LP
+.SS
+Viewing Progress of Compilation
+.LP
+.LP
+The IDL\-to\-Java compiler will generate status messages as it progresses through its phases of execution. Use the \f2\-v\fP option to activate this "verbose" mode:
+.LP
+.nf
+\f3
+.fl
+idlj \fP\f3\-v\fP My.idl
+.fl
+.fi
+
+.LP
+.LP
+By default the compiler does not operate in verbose mode.
+.LP
+.SS
+Displaying Version Information
+.LP
+.LP
+To display the build version of the IDL\-to\-Java compiler, specify the \f2\-version\fP option on the command\-line:
+.LP
+.nf
+\f3
+.fl
+idlj \-version
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Version information also appears within the bindings generated by the compiler. Any additional options appearing on the command\-line are ignored.
+.LP
+.SH "Options"
+.LP
+.RS 3
+.TP 3
+\-d symbol
+This is equivalent to the following line in an IDL file:
+.nf
+\f3
+.fl
+#define \fP\f4symbol\fP\f3
+.fl
+\fP
+.fi
+.TP 3
+\-emitAll
+Emit all types, including those found in \f2#include\fP files.
+.TP 3
+\-fside
+Defines what bindings to emit. \f2side\fP is one of \f2client\fP, \f2server\fP, \f2serverTIE\fP, \f2all\fP, or \f2allTIE\fP. The \f2\-fserverTIE\fP and \f2\-fallTIE\fP options cause delegate model skeletons to be emitted. Assumes \f2\-fclient\fP if the flag is not specified.
+.TP 3
+\-i include\-path
+By default, the current directory is scanned for included files. This option adds another directory.
+.TP 3
+\-keep
+If a file to be generated already exists, do not overwrite it. By default it is overwritten.
+.TP 3
+\-noWarn
+Suppresses warning messages.
+.TP 3
+\-oldImplBase
+Generates skeletons compatible with pre\-1.4 JDK ORBs. By default, the POA Inheritance Model server\-side bindings are generated. This option provides backward\-compatibility with older versions of the Java programming language by generating server\-side bindings that are \f2ImplBase\fP Inheritance Model classes.
+.TP 3
+\-pkgPrefix type prefix
+Wherever \f2type\fP is encountered at file scope, prefix the generated Java package name with \f2prefix\fP for all files generated for that type. The \f2type\fP is the simple name of either a top\-level module, or an IDL type defined outside of any module.
+.TP 3
+\-pkgTranslate type package
+Whenever the module name \f2type\fP is encountered in an identifier, replace it in the identifier with \f2package\fP for all files in the generated Java package. Note that \f2pkgPrefix\fP changes are made first. \f2type\fP is the simple name of either a top\-level module, or an IDL type defined outside of any module, and must match the full package name exactly.
+.br
+.br
+If more than one translation matches an identifier, the longest match is chosen. For example, if the arguments include:
+.nf
+\f3
+.fl
+  \-pkgTranslate foo bar \-pkgTranslate foo.baz buzz.fizz
+.fl
+\fP
+.fi
+The following translations would occur:
+.nf
+\f3
+.fl
+foo          => bar
+.fl
+foo.boo      => bar.boo
+.fl
+foo.baz      => buzz.fizz
+.fl
+foo.baz.bar  => buzz.fizz.bar
+.fl
+\fP
+.fi
+The following package names cannot be translated:
+.RS 3
+.TP 2
+o
+\f2org\fP
+.TP 2
+o
+\f2org.omg\fP or any subpackages of \f2org.omg\fP
+.RE
+Any attempt to translate these packages will result in uncompilable code, and the use of these packages as the first argument after \f2\-pkgTranslate\fP will be treated as an error.
+.TP 3
+\-skeletonName xxx%yyy
+Use \f2xxx%yyy\fP as the pattern for naming the skeleton. The defaults are:
+.RS 3
+.TP 2
+o
+%POA for the \f2POA\fP base class (\f2\-fserver\fP or \f2\-fall\fP)
+.TP 2
+o
+_%ImplBase for the \f2oldImplBase\fP class (\f2\-oldImplBase\fP and (\f2\-fserver\fP or \f2\-fall\fP))
+.RE
+.TP 3
+\-td dir
+Use \f2dir\fP for the output directory instead of the current directory.
+.TP 3
+\-tieName xxx%yyy
+Name the tie according to the pattern. The defaults are:
+.RS 3
+.TP 2
+o
+%POATie for the \f2POA\fP tie base class (\f2\-fserverTie\fP or \f2\-fallTie\fP)
+.TP 2
+o
+%_Tie for the \f2oldImplBase\fP tie class (\f2\-oldImplBase\fP and (\f2\-fserverTie\fP or \f2\-fallTie\fP))
+.RE
+.TP 3
+\-nowarn, \-verbose
+Verbose mode.
+.TP 3
+\-version
+Display version information and terminate.
+.RE
+
+.LP
+.LP
+See the Description section for more option information.
+.LP
+.SH "Restrictions:"
+.LP
+.RS 3
+.TP 2
+o
+Escaped identifiers in the global scope may not have the same spelling as IDL primitive types, \f2Object\fP, or \f2ValueBase\fP. This is because the symbol table is pre\-loaded with these identifiers; allowing them to be redefined would overwrite their original definitions. (Possible permanent restriction).
+.TP 2
+o
+The \f2fixed\fP IDL type is not supported.
+.RE
+
+.LP
+.SH "Known Problems:"
+.LP
+.RS 3
+.TP 2
+o
+No import generated for global identifiers. If you invoke on an unexported local impl, you do get an exception, but it seems to be due to a \f2NullPointerException\fP in the \f2ServerDelegate\fP DSI code.
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/ja/appletviewer.1 b/jdk/src/bsd/doc/man/ja/appletviewer.1
new file mode 100644
index 0000000..750c64d
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/appletviewer.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH appletviewer 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/apt.1 b/jdk/src/bsd/doc/man/ja/apt.1
new file mode 100644
index 0000000..16d2205
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/apt.1
@@ -0,0 +1,27 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH apt 1 "07 May 2011"
+
+.LP
+.SH "NAME"
+.LP
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/extcheck.1 b/jdk/src/bsd/doc/man/ja/extcheck.1
new file mode 100644
index 0000000..14e16a0
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/extcheck.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH extcheck 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/idlj.1 b/jdk/src/bsd/doc/man/ja/idlj.1
new file mode 100644
index 0000000..4b74f10
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/idlj.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH idlj 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jar.1 b/jdk/src/bsd/doc/man/ja/jar.1
new file mode 100644
index 0000000..4eea8ef
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jar.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jar 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jarsigner.1 b/jdk/src/bsd/doc/man/ja/jarsigner.1
new file mode 100644
index 0000000..9c25cc2
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jarsigner.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jarsigner 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/java.1 b/jdk/src/bsd/doc/man/ja/java.1
new file mode 100644
index 0000000..68118ce
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/java.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH java 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/javac.1 b/jdk/src/bsd/doc/man/ja/javac.1
new file mode 100644
index 0000000..f37d661
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/javac.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javac 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/javadoc.1 b/jdk/src/bsd/doc/man/ja/javadoc.1
new file mode 100644
index 0000000..df7c4f4
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/javadoc.1
@@ -0,0 +1,22 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javadoc 1 "07 May 2011"
diff --git a/jdk/src/bsd/doc/man/ja/javah.1 b/jdk/src/bsd/doc/man/ja/javah.1
new file mode 100644
index 0000000..a47377f
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/javah.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javah 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/javap.1 b/jdk/src/bsd/doc/man/ja/javap.1
new file mode 100644
index 0000000..2449ca1
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/javap.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javap 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/javaws.1 b/jdk/src/bsd/doc/man/ja/javaws.1
new file mode 100644
index 0000000..a190ee9
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/javaws.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javaws 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jconsole.1 b/jdk/src/bsd/doc/man/ja/jconsole.1
new file mode 100644
index 0000000..aa244d7
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jconsole.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jconsole 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jdb.1 b/jdk/src/bsd/doc/man/ja/jdb.1
new file mode 100644
index 0000000..80fefaa
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jdb.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jdb 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jhat.1 b/jdk/src/bsd/doc/man/ja/jhat.1
new file mode 100644
index 0000000..2884f87
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jhat.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jhat 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jinfo.1 b/jdk/src/bsd/doc/man/ja/jinfo.1
new file mode 100644
index 0000000..2c4e53f
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jinfo.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jinfo 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jmap.1 b/jdk/src/bsd/doc/man/ja/jmap.1
new file mode 100644
index 0000000..106af9b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jmap.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jmap 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jps.1 b/jdk/src/bsd/doc/man/ja/jps.1
new file mode 100644
index 0000000..181eae8
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jps.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jps 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jrunscript.1 b/jdk/src/bsd/doc/man/ja/jrunscript.1
new file mode 100644
index 0000000..4d85287
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jrunscript.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jrunscript 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jsadebugd.1 b/jdk/src/bsd/doc/man/ja/jsadebugd.1
new file mode 100644
index 0000000..76199be
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jsadebugd.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jsadebugd 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jstack.1 b/jdk/src/bsd/doc/man/ja/jstack.1
new file mode 100644
index 0000000..35707b5
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jstack.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jstack 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jstat.1 b/jdk/src/bsd/doc/man/ja/jstat.1
new file mode 100644
index 0000000..f15d61b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jstat.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jstat 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/jstatd.1 b/jdk/src/bsd/doc/man/ja/jstatd.1
new file mode 100644
index 0000000..48ff98b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/jstatd.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jstatd 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/keytool.1 b/jdk/src/bsd/doc/man/ja/keytool.1
new file mode 100644
index 0000000..c57a0e0
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/keytool.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH keytool 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/kinit.1 b/jdk/src/bsd/doc/man/ja/kinit.1
new file mode 100644
index 0000000..e78964d
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/kinit.1
@@ -0,0 +1,25 @@
+'\" t
+.\"
+.\" Copyright 2002-2004 Sun Microsystems, Inc.  All Rights Reserved.
+.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+.\"
+.\" This code is free software; you can redistribute it and/or modify it
+.\" under the terms of the GNU General Public License version 2 only, as
+.\" published by the Free Software Foundation.
+.\"
+.\" This code is distributed in the hope that it will be useful, but WITHOUT
+.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+.\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+.\" version 2 for more details (a copy is included in the LICENSE file that
+.\" accompanied this code).
+.\"
+.\" You should have received a copy of the GNU General Public License version
+.\" 2 along with this work; if not, write to the Free Software Foundation,
+.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+.\"
+.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+.\" or visit www.oracle.com if you need additional information or have any
+.\" questions.
+.\"
+.\"
+.\"
diff --git a/jdk/src/bsd/doc/man/ja/klist.1 b/jdk/src/bsd/doc/man/ja/klist.1
new file mode 100644
index 0000000..5ab393b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/klist.1
@@ -0,0 +1,24 @@
+'\" t
+.\"
+.\" Copyright 2002-2004 Sun Microsystems, Inc.  All Rights Reserved.
+.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+.\"
+.\" This code is free software; you can redistribute it and/or modify it
+.\" under the terms of the GNU General Public License version 2 only, as
+.\" published by the Free Software Foundation.
+.\"
+.\" This code is distributed in the hope that it will be useful, but WITHOUT
+.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+.\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+.\" version 2 for more details (a copy is included in the LICENSE file that
+.\" accompanied this code).
+.\"
+.\" You should have received a copy of the GNU General Public License version
+.\" 2 along with this work; if not, write to the Free Software Foundation,
+.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+.\"
+.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+.\" or visit www.oracle.com if you need additional information or have any
+.\" questions.
+.\"
+.\"
diff --git a/jdk/src/bsd/doc/man/ja/ktab.1 b/jdk/src/bsd/doc/man/ja/ktab.1
new file mode 100644
index 0000000..5ab393b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/ktab.1
@@ -0,0 +1,24 @@
+'\" t
+.\"
+.\" Copyright 2002-2004 Sun Microsystems, Inc.  All Rights Reserved.
+.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+.\"
+.\" This code is free software; you can redistribute it and/or modify it
+.\" under the terms of the GNU General Public License version 2 only, as
+.\" published by the Free Software Foundation.
+.\"
+.\" This code is distributed in the hope that it will be useful, but WITHOUT
+.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+.\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+.\" version 2 for more details (a copy is included in the LICENSE file that
+.\" accompanied this code).
+.\"
+.\" You should have received a copy of the GNU General Public License version
+.\" 2 along with this work; if not, write to the Free Software Foundation,
+.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+.\"
+.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+.\" or visit www.oracle.com if you need additional information or have any
+.\" questions.
+.\"
+.\"
diff --git a/jdk/src/bsd/doc/man/ja/native2ascii.1 b/jdk/src/bsd/doc/man/ja/native2ascii.1
new file mode 100644
index 0000000..9ee9559
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/native2ascii.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH native2ascii 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/orbd.1 b/jdk/src/bsd/doc/man/ja/orbd.1
new file mode 100644
index 0000000..6a622be
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/orbd.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH orbd 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/pack200.1 b/jdk/src/bsd/doc/man/ja/pack200.1
new file mode 100644
index 0000000..105f86c
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/pack200.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH pack200 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/policytool.1 b/jdk/src/bsd/doc/man/ja/policytool.1
new file mode 100644
index 0000000..c03952c
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/policytool.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH policytool 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/rmic.1 b/jdk/src/bsd/doc/man/ja/rmic.1
new file mode 100644
index 0000000..aeb47f2
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/rmic.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH rmic 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/rmid.1 b/jdk/src/bsd/doc/man/ja/rmid.1
new file mode 100644
index 0000000..7ffc1ab
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/rmid.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH rmid 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/rmiregistry.1 b/jdk/src/bsd/doc/man/ja/rmiregistry.1
new file mode 100644
index 0000000..18475ca
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/rmiregistry.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH rmiregistry 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/schemagen.1 b/jdk/src/bsd/doc/man/ja/schemagen.1
new file mode 100644
index 0000000..1ea20d4
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/schemagen.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH schemagen 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/serialver.1 b/jdk/src/bsd/doc/man/ja/serialver.1
new file mode 100644
index 0000000..41a7792
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/serialver.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH serialver 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/servertool.1 b/jdk/src/bsd/doc/man/ja/servertool.1
new file mode 100644
index 0000000..79ffffe
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/servertool.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH servertool 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/tnameserv.1 b/jdk/src/bsd/doc/man/ja/tnameserv.1
new file mode 100644
index 0000000..6c31a65
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/tnameserv.1
@@ -0,0 +1,24 @@
+." Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH tnameserv 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/unpack200.1 b/jdk/src/bsd/doc/man/ja/unpack200.1
new file mode 100644
index 0000000..96e01db
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/unpack200.1
@@ -0,0 +1,24 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH unpack200 1 "07 May 2011"
+
+.LP
diff --git a/jdk/src/bsd/doc/man/ja/wsgen.1 b/jdk/src/bsd/doc/man/ja/wsgen.1
new file mode 100644
index 0000000..d55a3b8
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/wsgen.1
@@ -0,0 +1,22 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH wsgen 1 "07 May 2011"
diff --git a/jdk/src/bsd/doc/man/ja/wsimport.1 b/jdk/src/bsd/doc/man/ja/wsimport.1
new file mode 100644
index 0000000..6c9bbb4
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/wsimport.1
@@ -0,0 +1,22 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH wsimport 1 "07 May 2011"
diff --git a/jdk/src/bsd/doc/man/ja/xjc.1 b/jdk/src/bsd/doc/man/ja/xjc.1
new file mode 100644
index 0000000..142ef29
--- /dev/null
+++ b/jdk/src/bsd/doc/man/ja/xjc.1
@@ -0,0 +1,25 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH xjc 1 "07 May 2011"
+
+.LP
+.ad c
diff --git a/jdk/src/bsd/doc/man/jar.1 b/jdk/src/bsd/doc/man/jar.1
new file mode 100644
index 0000000..c358280
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jar.1
@@ -0,0 +1,579 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jar 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jar\-The Java Archive Tool
+.LP
+\f3jar\fP combines multiple files into a single JAR archive file.
+.SH "SYNOPSIS"
+.LP
+.RS 3
+.TP 3
+Create jar file
+\f4jar c\fP\f2[v0Mmfe] [\fP\f2manifest\fP\f2] [\fP\f2jarfile\fP\f2] [\fP\f2entrypoint\fP\f2] [\-C\fP \f2dir\fP\f2]\fP \f2inputfiles\fP \f2[\-J\fP\f2option\fP\f2]\fP
+.TP 3
+Update jar file
+\f4jar u\fP\f2[v0Mmfe] [\fP\f2manifest\fP\f2] [\fP\f2jarfile\fP\f2] [\fP\f2entrypoint\fP\f2] [\-C\fP \f2dir\fP\f2]\fP \f2inputfiles\fP \f2[\-J\fP\f2option\fP\f2]\fP
+.TP 3
+Extract jar file
+\f4jar x\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP
+.TP 3
+List table of contents of jar file
+\f4jar t\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP
+.TP 3
+Add index to jar file
+\f4jar i\fP \f2jarfile\fP \f2[\-J\fP\f2option\fP\f2]\fP
+.RE
+
+.LP
+.LP
+where:
+.LP
+.RS 3
+.TP 3
+cuxtiv0Mmfe
+Options that control the \f2jar\fP command.
+.TP 3
+jarfile
+Jar file to be created (\f2c\fP), updated (\f2u\fP), extracted (\f2x\fP), or have its table of contents viewed (\f2t\fP). The \f2\-f\fP option and filename \f2jarfile\fP are a pair \-\- if either is present, they must both appear. Note that omitting \f2f\fP and \f2jarfile\fP accepts a "jar file" from standard input (for x and t) or sends the "jar file" to standard output (for c and u).
+.TP 3
+inputfiles
+Files or directories, separated by spaces, to be combined into \f2jarfile\fP (for c and u), or to be extracted (for x) or listed (for t) from \f2jarfile\fP. All directories are processed recursively. The files are compressed unless option \f20\fP (zero) is used.
+.TP 3
+manifest
+Pre\-existing manifest file whose \f2name\fP\f2:\fP \f2value\fP pairs are to be included in MANIFEST.MF in the jar file. The \f2\-m\fP option and filename \f2manifest\fP are a pair \-\- if either is present, they must both appear. The letters \f3m\fP, \f3f\fP and \f3e\fP must appear in the same order that \f2manifest\fP, \f2jarfile\fP, \f2entrypoint\fP appear.
+.TP 3
+entrypoint
+The name of the class that set as the application entry point for stand\-alone applications bundled into executable jar file. The \f2\-e\fP option and entrypoint are a pair \-\- if either is present, they must both appear. The letters \f3m\fP, \f3f\fP and \f3e\fP must appear in the same order that \f2manifest\fP, \f2jarfile\fP, \f2entrypoint\fP appear.
+.TP 3
+\-C\ dir
+Temporarily changes directories to \f2dir\fP while processing the following \f2inputfiles\fP argument. Multiple \f2\-C\ \fP\f2dir\fP \f2inputfiles\fP sets are allowed.
+.TP 3
+\-Joption
+Option to be passed into the Java runtime environment. (There must be no space between \f2\-J\fP and \f2option\fP).
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+The \f3jar\fP tool combines multiple files into a single JAR archive file. \f3jar\fP is a general\-purpose archiving and compression tool, based on ZIP and the
+.na
+\f2ZLIB\fP @
+.fi
+http://www.gzip.org/zlib/ compression format. However, \f3jar\fP was designed mainly package java applets or applications into a single archive. When the components of an applet or application (files, images and sounds) are combined into a single archive, they can be downloaded by a java agent (like a browser) in a single HTTP transaction, rather than requiring a new connection for each piece. This dramatically improves download times. \f3jar\fP also compresses files and so further improves download time. In addition, it allows individual entries in a file to be signed by the applet author so that their origin can be authenticated. The syntax for the jar tool is almost identical to the syntax for the \f2tar\fP command. A \f3jar\fP archive can be used as a class path entry, whether or not it is compressed.
+.LP
+Typical usage to combine files into a jar file is:
+.LP
+.nf
+\f3
+.fl
+% jar cf myFile.jar *.class
+.fl
+\fP
+.fi
+
+.LP
+In this example, all the class files in the current directory are placed into the file named \f2myFile.jar\fP. The jar tool automatically generates a manifest file entry named \f2META\-INF/MANIFEST.MF\fP. It is always the first entry in the jar file. The manifest file declares meta\-information about the archive, and stores that data as \f2name\ :\ value\fP pairs. Refer to the
+.na
+\f2JAR file specification\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR%20Manifest for details explaining how the jar tool stores meta\-information in the manifest file.
+.LP
+If a jar file should include \f2name\ :\ value\fP pairs contained in an existing manifest file, specify that file using the \f2\-m\fP option:
+.LP
+.nf
+\f3
+.fl
+% jar cmf myManifestFile myFile.jar *.class
+.fl
+\fP
+.fi
+
+.LP
+An existing manifest file must end with a new line character.\  \f3jar\fP does not parse the last line of a manifest file if it does not end with a new line character.
+.br
+
+.LP
+.br
+
+.LP
+\f3Note:\ \fP A jar command that specifies \f2cfm\fP on the command line instead of \f2cmf\fP (the order of the m and \-f options are reversed), the \f3jar\fP command line must specify the name of the jar archive first, followed by the name of the manifest file:
+.nf
+\f3
+.fl
+% jar cfm myFile.jar myManifestFile *.class
+.fl
+\fP
+.fi
+
+.LP
+The manifest is in a text format inspired by RFC822 ASCII format, so it is easy to view and process manifest\-file contents.
+.LP
+To extract the files from a jar file, use \f2x\fP:
+.LP
+.nf
+\f3
+.fl
+% jar xf myFile.jar
+.fl
+\fP
+.fi
+
+.LP
+.LP
+To extract individual files from a jar file, supply their filenames:
+.LP
+.nf
+\f3
+.fl
+% jar xf myFile.jar foo bar
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Beginning with version 1.3 of the JDK, the \f2jar\fP utility supports
+.na
+\f2JarIndex\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Index, which allows application class loaders to load classes more efficiently from jar files. If an application or applet is bundled into multiple jar files,\  only the necessary jar files will be downloaded and opened to load classes. This performance optimization is enabled by running \f2jar\fP with the \f2\-i\fPoption. It will generate package location information for the specified main jar file and all the jar files it depends on, which need to be specified in the \f2Class\-Path\fP attribute of the main jar file's manifest.
+.LP
+.nf
+\f3
+.fl
+% jar i main.jar
+.fl
+\fP
+.fi
+
+.LP
+.LP
+In this example, an \f2INDEX.LIST\fP file is inserted into the \f2META\-INF\fP directory of \f2main.jar\fP.
+.br
+.br
+The application class loader uses the information stored in this file for efficient class loading.\  For details about how location information is stored in the index file, refer to the \f2JarIndex\fP specification.
+.br
+.br
+To copy directories, first compress files in \f2dir1\fP to \f2stdout\fP, then extract from \f2stdin\fP to \f2dir2\fP (omitting the \f2\-f\fP option from both \f2jar\fP commands):
+.LP
+.nf
+\f3
+.fl
+% (cd dir1; jar c .) | (cd dir2; jar x)
+.fl
+\fP
+.fi
+
+.LP
+.LP
+To review command samples which use \f2jar\fP to opeate on jar files and jar file manifests, see Examples, below. Also refer to the jar trail of the
+.na
+\f2Java Tutorial\fP @
+.fi
+http://download.oracle.com/javase/tutorial/deployment/jar.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+c
+Creates a new archive file named \f2jarfile\fP (if \f2f\fP is specified) or to standard output (if \f2f\fP and \f2jarfile\fP are omitted). Add to it the files and directories specified by \f2inputfiles\fP.
+.TP 3
+u
+Updates an existing file \f2jarfile\fP (when \f2f\fP is specified) by adding to it files and directories specified by \f2inputfiles\fP. For example:
+.nf
+\f3
+.fl
+jar uf foo.jar foo.class
+.fl
+\fP
+.fi
+would add the file \f2foo.class\fP to the existing jar file \f2foo.jar\fP. The \f2\-u\fP option can also update the manifest entry, as given by this example:
+.nf
+\f3
+.fl
+jar umf manifest foo.jar
+.fl
+\fP
+.fi
+updates the \f2foo.jar\fP manifest with the \f2name : value\fP pairs in \f2manifest\fP.
+.TP 3
+x
+Extracts files and directories from \f2jarfile\fP (if \f2f\fP is specified) or standard input (if \f2f\fP and \f2jarfile\fP are omitted). If \f2inputfiles\fP is specified, only those specified files and directories are extracted. Otherwise, all files and directories are extracted. The time and date of the extracted files are those given in the archive.
+.TP 3
+t
+Lists the table of contents from \f2jarfile\fP (if \f2f\fP is specified) or standard input (if \f2f\fP and \f2jarfile\fP are omitted). If \f2inputfiles\fP is specified, only those specified files and directories are listed. Otherwise, all files and directories are listed.
+.TP 3
+i
+Generate index information for the specified \f2jarfile\fP and its dependent jar files. For example:
+.nf
+\f3
+.fl
+jar i foo.jar
+.fl
+\fP
+.fi
+.LP
+would generate an \f2INDEX.LIST\fP file in \f2foo.jar\fP which contains location information for each package in \f2foo.jar\fP and all the jar files specified in the \f2Class\-Path\fP attribute of \f2foo.jar\fP. See the index example.
+.TP 3
+f
+Specifies the file \f2jarfile\fP to be created (\f2c\fP), updated (\f2u\fP), extracted (\f2x\fP), indexed (\f2i\fP), or viewed (\f2t\fP). The \f2\-f\fP option and filename \f2jarfile\fP are a pair \-\- if present, they must both appear. Omitting \f2f\fP and \f2jarfile\fP accepts a jar file name from \f2stdin\fP(for x and t) or sends jar file to \f2stdout\fP (for c and u).
+.TP 3
+v
+Generates verbose output to standard output. Examples shown below.
+.TP 3
+0
+(zero) Store without using ZIP compression.
+.TP 3
+M
+Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u).
+.TP 3
+m
+Includes \f2name : value\fP attribute pairs from the specified manifest file \f2manifest\fP in the file at \f2META\-INF/MANIFEST.MF\fP. \f2jar\fP adds a \f2name\ :\ value\fP pair unless an entry already exists with the same name, in which case \f2jar\fP updates its value.
+.br
+.br
+On the command line, the letters \f3m\fP and \f3f\fP must appear in the same order that \f2manifest\fP and \f2jarfile\fP appear. Example use:
+.nf
+\f3
+.fl
+jar cmf myManifestFile myFile.jar *.class
+.fl
+\fP
+.fi
+You can add special\-purpose \f2name\ :\ value\fP attribute pairs to the manifest that aren't contained in the default manifest. For example, you can add attributes specifying vendor information, version information, package sealing, or to make JAR\-bundled applications executable. See the
+.na
+\f2JAR Files\fP @
+.fi
+http://download.oracle.com/javase/tutorial/deployment/jar/ trail in the Java Tutorial  for examples of using the \f4\-m\fP option.
+.TP 3
+e
+Sets \f2entrypoint\fP as the application entry point for stand\-alone applications bundled into executable jar file. The use of this option creates or overrides the \f2Main\-Class\fP attribute value in the manifest file. This option can be used during creation of jar file or while updating the jar file. This option specifies the application entry point without editing or creating the manifest file.
+.br
+.br
+.br
+For example, this command creates \f2Main.jar\fP where the \f2Main\-Class\fP attribute value in the manifest is set to \f2Main\fP:
+.nf
+\f3
+.fl
+jar cfe Main.jar Main Main.class
+.fl
+\fP
+.fi
+The java runtime can directly invoke this application by running the following command:
+.nf
+\f3
+.fl
+java \-jar Main.jar
+.fl
+\fP
+.fi
+If the entrypoint class name is in a package it may use either a dot (".") or slash ("/") character as the delimiter. For example, if \f2Main.class\fP is in a package called \f2foo\fP the entry point can be specified in the following ways:
+.nf
+\f3
+.fl
+jar \-cfe Main.jar foo/Main foo/Main.class
+.fl
+\fP
+.fi
+or
+.nf
+\f3
+.fl
+jar \-cfe Main.jar foo.Main foo/Main.class
+.fl
+\fP
+.fi
+\f3Note:\ \fP specifying both \f2\-m\fP and \f2\-e\fP options together when the given manifest also contains the \f2Main\-Class\fP attribute results in an ambigous \f2Main.class\fP specification, leading to an error and the jar creation or update operation is aborted.
+.TP 3
+\-C\ dir
+Temporarily changes directories (\f2cd\fP\ \f2dir\fP) during execution of the \f2jar\fP command while processing the following \f2inputfiles\fP argument. Its operation is intended to be similar to the \f2\-C\fP option of the UNIX \f2tar\fP utility.
+.br
+.br
+For example, this command changes to the \f2classes\fP directory and adds the \f2bar.class\fP from that directory to \f2foo.jar\fP:
+.nf
+\f3
+.fl
+jar uf foo.jar \-C classes bar.class
+.fl
+\fP
+.fi
+This command changes to the \f2classes\fP directory and adds to \f2foo.jar\fP all files within the \f2classes\fP directory (without creating a classes directory in the jar file), then changes back to the original directory before changing to the \f2bin\fP directory to add \f2xyz.class\fP to \f2foo.jar\fP.
+.nf
+\f3
+.fl
+jar uf foo.jar \-C classes . \-C bin xyz.class
+.fl
+\fP
+.fi
+If \f2classes\fP holds files \f2bar1\fP and \f2bar2\fP, then here's what the jar file will contain using \f2jar tf foo.jar\fP:
+.nf
+\f3
+.fl
+META\-INF/
+.fl
+META\-INF/MANIFEST.MF
+.fl
+bar1
+.fl
+bar2
+.fl
+xyz.class
+.fl
+\fP
+.fi
+.LP
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java runtime environment, where \f2option\fP is one of the options described on the reference page for the java application launcher. For example, \f4\-J\-Xmx48M\fP sets the maximum memory to 48 megabytes. It is a common convention for \f2\-J\fP to pass options to the underlying runtime environment.
+.RE
+
+.LP
+.SH "COMMAND LINE ARGUMENT FILES"
+.LP
+To shorten or simplify the jar command line, you can specify one or more files that themselves contain arguments to the \f2jar\fP command (except \f2\-J\fP options). This enables you to create jar commands of any length, overcoming command line limits imposed by the operating system.
+.LP
+An argument file can include options and filenames. The arguments within a file can be space\-separated or newline\-separated. Filenames within an argument file are relative to the current directory, not relative to the location of the argument file. Wildcards (*) that might otherwise be expanded by the operating system shell are not expanded. Use of the \f2@\fP character to recursively interpret files is not supported. The \f2\-J\fP options are not supported because they are passed to the launcher, which does not support argument files.
+.LP
+.LP
+When executing \f2jar\fP, pass in the path and name of each argument file with the \f2@\fP leading character. When \f2jar\fP encounters an argument beginning with the character \f2@\fP, it expands the contents of that file into the argument list.
+.br
+.br
+The example below, \f2classes.list\fP holds the names of files output by a \f2find\fP command:
+.LP
+.nf
+\f3
+.fl
+% find \fP\f3.\fP \-name '*.class' \-print > classes.list
+.fl
+.fi
+
+.LP
+.LP
+You can then execute the \f2jar\fP command on \f2Classes.list\fP by passing it to \f2jar\fP using argfile syntax:
+.LP
+.nf
+\f3
+.fl
+% jar cf my.jar @classes.list
+.fl
+\fP
+.fi
+
+.LP
+An argument file can specify a path, but any filenames inside the argument file that have relative paths are relative to the current working directory, not to the path passed in. Here is an example:
+.nf
+\f3
+.fl
+% jar @path1/classes.list
+.fl
+\fP
+.fi
+
+.LP
+.LP
+
+.LP
+.SH "EXAMPLES"
+.LP
+To add all the files in a particular directory to an archive (overwriting contents if the archive already exists). Enumerating verbosely (with the \f2\-v\fP option) will tell you more information about the files in the archive, such as their size and last modified date.
+.nf
+\f3
+.fl
+% ls
+.fl
+1.au          Animator.class    monkey.jpg
+.fl
+2.au          Wave.class        spacemusic.au
+.fl
+3.au          at_work.gif
+.fl
+
+.fl
+% jar cvf bundle.jar *
+.fl
+added manifest
+.fl
+adding: 1.au(in = 2324) (out= 67)(deflated 97%)
+.fl
+adding: 2.au(in = 6970) (out= 90)(deflated 98%)
+.fl
+adding: 3.au(in = 11616) (out= 108)(deflated 99%)
+.fl
+adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
+.fl
+adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
+.fl
+adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
+.fl
+adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
+.fl
+adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
+.fl
+\fP
+.fi
+
+.LP
+If you already have separate subdirectories for images, audio files and classes, you can combine them into a single jar file:
+.nf
+\f3
+.fl
+% ls \-F
+.fl
+audio/ classes/ images/
+.fl
+
+.fl
+% jar cvf bundle.jar audio classes images
+.fl
+added manifest
+.fl
+adding: audio/(in = 0) (out= 0)(stored 0%)
+.fl
+adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
+.fl
+adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
+.fl
+adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
+.fl
+adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
+.fl
+adding: classes/(in = 0) (out= 0)(stored 0%)
+.fl
+adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
+.fl
+adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
+.fl
+adding: images/(in = 0) (out= 0)(stored 0%)
+.fl
+adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
+.fl
+adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)
+.fl
+
+.fl
+% ls \-F
+.fl
+audio/ bundle.jar classes/ images/
+.fl
+\fP
+.fi
+
+.LP
+To see the entry names in the jarfile, use the \f2t\fP option:
+.nf
+\f3
+.fl
+% jar tf bundle.jar
+.fl
+META\-INF/
+.fl
+META\-INF/MANIFEST.MF
+.fl
+audio/1.au
+.fl
+audio/2.au
+.fl
+audio/3.au
+.fl
+audio/spacemusic.au
+.fl
+classes/Animator.class
+.fl
+classes/Wave.class
+.fl
+images/monkey.jpg
+.fl
+images/at_work.gif
+.fl
+\fP
+.fi
+
+.LP
+.LP
+To add an index file to the jar file for speeding up class loading, use the \f2i\fP option.
+.br
+.br
+Example:
+.br
+
+.LP
+If you split the inter\-dependent classes for a stock trade application into three jar files: \f2main.jar\fP, \f2buy.jar\fP, and \f2sell.jar\fP.
+.br
+
+.LP
+.br
+
+.LP
+If you specify the \f2Class\-path\fP attribute in the \f2main.jar\fP manifest as:
+.nf
+\f3
+.fl
+Class\-Path: buy.jar sell.jar
+.fl
+\fP
+.fi
+
+.LP
+then you can use the \f2\-i\fP option to speed up the class loading time for your application:
+.nf
+\f3
+.fl
+% jar i main.jar
+.fl
+\fP
+.fi
+
+.LP
+An \f2INDEX.LIST\fP file is inserted to the \f2META\-INF\fP directory. This enables the application class loader to download the specified jar files when it is searching for classes or resources.
+.SH "SEE ALSO"
+.LP
+.LP
+.na
+\f2The Jar Overview\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jar/jarGuide.html
+.LP
+.LP
+.na
+\f2The Jar File Specification\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html
+.LP
+.LP
+.na
+\f2The JarIndex Spec\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Index
+.LP
+.LP
+.na
+\f2Jar Tutorial\fP @
+.fi
+http://download.oracle.com/javase/tutorial/deployment/jar/index.html
+.LP
+.LP
+pack200(1)
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jarsigner.1 b/jdk/src/bsd/doc/man/jarsigner.1
new file mode 100644
index 0000000..57dd4ed
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jarsigner.1
@@ -0,0 +1,1567 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jarsigner 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jarsigner \- JAR Signing and Verification Tool
+.LP
+.LP
+Generates signatures for Java ARchive (JAR) files, and verifies the signatures of signed JAR files.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jarsigner\fP [ options ] jar\-file alias
+.fl
+\f3jarsigner\fP \-verify [ options ] jar\-file [alias...]
+.fl
+.fi
+
+.LP
+.LP
+The jarsigner \-verify command can take zero or more keystore alias names after the jar filename. When specified, jarsigner will check that the certificate used to verify each signed entry in the jar file matches one of the keystore aliases. The aliases are defined in the keystore specified by \-keystore, or the default keystore.
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3jarsigner\fP tool is used for two purposes:
+.LP
+.RS 3
+.TP 3
+1.
+to sign Java ARchive (JAR) files, and
+.TP 3
+2.
+to verify the signatures and integrity of signed JAR files.
+.RE
+
+.LP
+.LP
+The JAR feature enables the packaging of class files, images, sounds, and other digital data in a single file for faster and easier distribution. A tool named jar(1) enables developers to produce JAR files. (Technically, any zip file can also be considered a JAR file, although when created by \f3jar\fP or processed by \f3jarsigner\fP, JAR files also contain a META\-INF/MANIFEST.MF file.)
+.LP
+.LP
+A \f2digital signature\fP is a string of bits that is computed from some data (the data being "signed") and the private key of an entity (a person, company, etc.). Like a handwritten signature, a digital signature has many useful characteristics:
+.LP
+.RS 3
+.TP 2
+o
+Its authenticity can be verified, via a computation that uses the public key corresponding to the private key used to generate the signature.
+.TP 2
+o
+It cannot be forged, assuming the private key is kept secret.
+.TP 2
+o
+It is a function of the data signed and thus can't be claimed to be the signature for other data as well.
+.TP 2
+o
+The signed data cannot be changed; if it is, the signature will no longer verify as being authentic.
+.RE
+
+.LP
+.LP
+In order for an entity's signature to be generated for a file, the entity must first have a public/private key pair associated with it, and also one or more certificates authenticating its public key. A \f2certificate\fP is a digitally signed statement from one entity, saying that the public key of some other entity has a particular value.
+.LP
+.LP
+\f3jarsigner\fP uses key and certificate information from a \f2keystore\fP to generate digital signatures for JAR files. A keystore is a database of private keys and their associated X.509 certificate chains authenticating the corresponding public keys. The keytool(1) utility is used to create and administer keystores.
+.LP
+.LP
+\f3jarsigner\fP uses an entity's private key to generate a signature. The signed JAR file contains, among other things, a copy of the certificate from the keystore for the public key corresponding to the private key used to sign the file. \f3jarsigner\fP can verify the digital signature of the signed JAR file using the certificate inside it (in its signature block file).
+.LP
+.LP
+\f3jarsigner\fP can generate signatures that include a timestamp, thus enabling systems/deployer (including Java Plug\-in) to check whether the JAR file was signed while the signing certificate was still valid. In addition, APIs will allow applications to obtain the timestamp information.
+.LP
+.LP
+At this time, \f3jarsigner\fP can only sign JAR files created by the SDK jar(1) tool or zip files. (JAR files are the same as zip files, except they also have a META\-INF/MANIFEST.MF file. Such a file will automatically be created when \f3jarsigner\fP signs a zip file.)
+.LP
+.LP
+The default \f3jarsigner\fP behavior is to \f2sign\fP a JAR (or zip) file. Use the \f2\-verify\fP option to instead have it \f2verify\fP a signed JAR file.
+.LP
+.SS
+Keystore Aliases
+.LP
+.LP
+All keystore entities are accessed via unique \f2aliases\fP.
+.LP
+.LP
+When using \f3jarsigner\fP to sign a JAR file, you must specify the alias for the keystore entry containing the private key needed to generate the signature. For example, the following will sign the JAR file named "MyJARFile.jar", using the private key associated with the alias "duke" in the keystore named "mystore" in the "working" directory. Since no output file is specified, it overwrites MyJARFile.jar with the signed JAR file.
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-keystore /working/mystore \-storepass \fP\f4<keystore password>\fP\f3
+.fl
+      \-keypass \fP\f4<private key password>\fP\f3 MyJARFile.jar duke
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Keystores are protected with a password, so the store password must be specified. You will be prompted for it if you don't specify it on the command line. Similarly, private keys are protected in a keystore with a password, so the private key's password must be specified, and you will be prompted for it if you don't specify it on the command line and it isn't the same as the store password.
+.LP
+.SS
+Keystore Location
+.LP
+.LP
+\f3jarsigner\fP has a \f2\-keystore\fP option for specifying the URL of the keystore to be used. The keystore is by default stored in a file named \f2.keystore\fP in the user's home directory, as determined by the \f2user.home\fP system property. On Solaris systems \f2user.home\fP defaults to the user's home directory.
+.LP
+.LP
+Note that the input stream from the \f2\-keystore\fP option is passed to the \f2KeyStore.load\fP method. If \f2NONE\fP is specified as the URL, then a null stream is passed to the \f2KeyStore.load\fP method. \f2NONE\fP should be specified if the \f2KeyStore\fP is not file\-based, for example, if it resides on a hardware token device.
+.LP
+.SS
+Keystore Implementation
+.LP
+.LP
+The \f2KeyStore\fP class provided in the \f2java.security\fP package supplies well\-defined interfaces to access and modify the information in a keystore. It is possible for there to be multiple different concrete implementations, where each implementation is that for a particular \f2type\fP of keystore.
+.LP
+.LP
+Currently, there are two command\-line tools that make use of keystore implementations (\f3keytool\fP and \f3jarsigner\fP), and also a GUI\-based tool named \f3Policy Tool\fP. Since \f2KeyStore\fP is publicly available, Java 2 SDK users can write additional security applications that use it.
+.LP
+.LP
+There is a built\-in default implementation, provided by Sun Microsystems. It implements the keystore as a file, utilizing a proprietary keystore type (format) named "JKS". It protects each private key with its individual password, and also protects the integrity of the entire keystore with a (possibly different) password.
+.LP
+.LP
+Keystore implementations are provider\-based. More specifically, the application interfaces supplied by \f2KeyStore\fP are implemented in terms of a "Service Provider Interface" (SPI). That is, there is a corresponding abstract \f2KeystoreSpi\fP class, also in the \f2java.security\fP package, which defines the Service Provider Interface methods that "providers" must implement. (The term "provider" refers to a package or a set of packages that supply a concrete implementation of a subset of services that can be accessed by the Java Security API.) Thus, to provide a keystore implementation, clients must implement a provider and supply a KeystoreSpi subclass implementation, as described in
+.na
+\f2How to Implement a Provider for the Java Cryptography Architecture\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/crypto/HowToImplAProvider.html.
+.LP
+.LP
+Applications can choose different \f2types\fP of keystore implementations from different providers, using the "getInstance" factory method supplied in the \f2KeyStore\fP class. A keystore type defines the storage and data format of the keystore information, and the algorithms used to protect private keys in the keystore and the integrity of the keystore itself. Keystore implementations of different types are not compatible.
+.LP
+.LP
+\f3keytool\fP works on any file\-based keystore implementation. (It treats the keystore location that is passed to it at the command line as a filename and converts it to a FileInputStream, from which it loads the keystore information.) The \f3jarsigner\fP and \f3policytool\fP tools, on the other hand, can read a keystore from any location that can be specified using a URL.
+.LP
+.LP
+For \f3jarsigner\fP and \f3keytool\fP, you can specify a keystore type at the command line, via the \f2\-storetype\fP option. For \f3Policy Tool\fP, you can specify a keystore type via the "Change Keystore" command in the Edit menu.
+.LP
+.LP
+If you don't explicitly specify a keystore type, the tools choose a keystore implementation based simply on the value of the \f2keystore.type\fP property specified in the security properties file. The security properties file is called \f2java.security\fP, and it resides in the SDK security properties directory, \f2java.home\fP/lib/security, where \f2java.home\fP is the runtime environment's directory (the \f2jre\fP directory in the SDK or the top\-level directory of the Java 2 Runtime Environment).
+.LP
+.LP
+Each tool gets the \f2keystore.type\fP value and then examines all the currently\-installed providers until it finds one that implements keystores of that type. It then uses the keystore implementation from that provider.
+.LP
+.LP
+The \f2KeyStore\fP class defines a static method named \f2getDefaultType\fP that lets applications and applets retrieve the value of the \f2keystore.type\fP property. The following line of code creates an instance of the default keystore type (as specified in the \f2keystore.type\fP property):
+.LP
+.nf
+\f3
+.fl
+    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The default keystore type is "jks" (the proprietary type of the keystore implementation provided by Sun). This is specified by the following line in the security properties file:
+.LP
+.nf
+\f3
+.fl
+    keystore.type=jks
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Note: Case doesn't matter in keystore type designations. For example, "JKS" would be considered the same as "jks".
+.LP
+.LP
+To have the tools utilize a keystore implementation other than the default, change that line to specify a different keystore type. For example, if you have a provider package that supplies a keystore implementation for a keystore type called "pkcs12", change the line to
+.LP
+.nf
+\f3
+.fl
+    keystore.type=pkcs12
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Note that if you us the PKCS#11 provider package, you should refer to the
+.na
+\f2KeyTool and JarSigner\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/p11guide.html#KeyToolJarSigner section of the Java PKCS#11 Reference Guide for details.
+.LP
+.SS
+Supported Algorithms
+.LP
+.LP
+By default, \f3jarsigner\fP signs a JAR file using one of the following:
+.LP
+.RS 3
+.TP 2
+o
+DSA (Digital Signature Algorithm) with the SHA1 digest algorithm
+.TP 2
+o
+RSA algorithm with the SHA256 digest algorithm.
+.TP 2
+o
+EC (Elliptic Curve) cryptography algorithm with the SHA256 with ECDSA (Elliptic Curve Digital Signature Algorithm).
+.RE
+
+.LP
+.LP
+That is, if the signer's public and private keys are DSA keys, \f3jarsigner\fP will sign the JAR file using the "SHA1withDSA" algorithm. If the signer's keys are RSA keys, \f3jarsigner\fP will attempt to sign the JAR file using the "SHA256withRSA" algorithm. If the signer's keys are EC keys, \f3jarsigner\fP will sign the JAR file using the "SHA256withECDSA" algorithm.
+.LP
+.LP
+These default signature algorithms can be overridden using the \f2\-sigalg\fP option.
+.LP
+.SS
+The Signed JAR File
+.LP
+.LP
+When \f3jarsigner\fP is used to sign a JAR file, the output signed JAR file is exactly the same as the input JAR file, except that it has two additional files placed in the META\-INF directory:
+.LP
+.RS 3
+.TP 2
+o
+a signature file, with a .SF extension, and
+.TP 2
+o
+a signature block file, with a .DSA, .RSA, or .EC extension.
+.RE
+
+.LP
+.LP
+The base file names for these two files come from the value of the \f2\-sigFile\fP option. For example, if the option appears as
+.LP
+.nf
+\f3
+.fl
+\-sigFile MKSIGN
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The files are named "MKSIGN.SF" and "MKSIGN.DSA".
+.LP
+.LP
+If no \f2\-sigfile\fP option appears on the command line, the base file name for the .SF and .DSA files will be the first 8 characters of the alias name specified on the command line, all converted to upper case. If the alias name has fewer than 8 characters, the full alias name is used. If the alias name contains any characters that are not allowed in a signature file name, each such character is converted to an underscore ("_") character in forming the file name. Legal characters include letters, digits, underscores, and hyphens.
+.LP
+\f3The Signature (.SF) File\fP
+.LP
+.LP
+A signature file (the .SF file) looks similar to the manifest file that is always included in a JAR file when \f3jarsigner\fP is used to sign the file. That is, for each source file included in the JAR file, the .SF file has three lines, just as in the manifest file, listing the following:
+.LP
+.RS 3
+.TP 2
+o
+the file name,
+.TP 2
+o
+the name of the digest algorithm used (SHA), and
+.TP 2
+o
+a SHA digest value.
+.RE
+
+.LP
+.LP
+In the manifest file, the SHA digest value for each source file is the digest (hash) of the binary data in the source file. In the .SF file, on the other hand, the digest value for a given source file is the hash of the three lines in the manifest file for the source file.
+.LP
+.LP
+The signature file also, by default, includes a header containing a hash of the whole manifest file. The presence of the header enables verification optimization, as described in JAR File Verification.
+.LP
+\f3The Signature Block File\fP
+.LP
+The .SF file is signed and the signature is placed in the signature block file. This file also contains, encoded inside it, the certificate or certificate chain from the keystore which authenticates the public key corresponding to the private key used for signing. The file has the extension .DSA, .RSA, or .EC depending on the digest algorithm used.
+.SS
+Signature Timestamp
+.LP
+.LP
+\f2jarsigner\fP tool can generate and store a signature timestamp when signing a JAR file. In addition, \f2jarsigner\fP supports alternative signing mechanisms. This behavior is optional and is controlled by the user at the time of signing through these options:
+.LP
+.RS 3
+.TP 2
+o
+\f2\-tsa url\fP
+.TP 2
+o
+\f2\-tsacert alias\fP
+.TP 2
+o
+\f2\-altsigner class\fP
+.TP 2
+o
+\f2\-altsignerpath classpathlist\fP
+.RE
+
+.LP
+.LP
+Each of these options is detailed in the Options section below.
+.LP
+.SS
+JAR File Verification
+.LP
+.LP
+A successful JAR file verification occurs if the signature(s) are valid, and none of the files that were in the JAR file when the signatures were generated have been changed since then. JAR file verification involves the following steps:
+.LP
+.RS 3
+.TP 3
+1.
+Verify the signature of the .SF file itself.
+.br
+.br
+That is, the verification ensures that the signature stored in each signature block (.DSA) file was in fact generated using the private key corresponding to the public key whose certificate (or certificate chain) also appears in the .DSA file. It also ensures that the signature is a valid signature of the corresponding signature (.SF) file, and thus the .SF file has not been tampered with.
+.TP 3
+2.
+Verify the digest listed in each entry in the .SF file with each corresponding section in the manifest.
+.br
+.br
+The .SF file by default includes a header containing a hash of the entire manifest file. When the header is present, then the verification can check to see whether or not the hash in the header indeed matches the hash of the manifest file. If that is the case, verification proceeds to the next step.
+.br
+.br
+If that is not the case, a less optimized verification is required to ensure that the hash in each source file information section in the .SF file equals the hash of its corresponding section in the manifest file (see The Signature (.SF) File).
+.br
+.br
+One reason the hash of the manifest file that is stored in the .SF file header may not equal the hash of the current manifest file would be because one or more files were added to the JAR file (using the \f2jar\fP tool) after the signature (and thus the .SF file) was generated. When the \f2jar\fP tool is used to add files, the manifest file is changed (sections are added to it for the new files), but the .SF file is not. A verification is still considered successful if none of the files that were in the JAR file when the signature was generated have been changed since then, which is the case if the hashes in the non\-header sections of the .SF file equal the hashes of the corresponding sections in the manifest file.
+.TP 3
+3.
+Read each file in the JAR file that has an entry in the .SF file. While reading, compute the file's digest, and then compare the result with the digest for this file in the manifest section. The digests should be the same, or verification fails.
+.RE
+
+.LP
+.LP
+If any serious verification failures occur during the verification process, the process is stopped and a security exception is thrown. It is caught and displayed by \f3jarsigner\fP.
+.LP
+.SS
+Multiple Signatures for a JAR File
+.LP
+.LP
+A JAR file can be signed by multiple people simply by running the \f3jarsigner\fP tool on the file multiple times, specifying the alias for a different person each time, as in:
+.LP
+.nf
+\f3
+.fl
+  jarsigner myBundle.jar susan
+.fl
+  jarsigner myBundle.jar kevin
+.fl
+\fP
+.fi
+
+.LP
+.LP
+When a JAR file is signed multiple times, there are multiple .SF and .DSA files in the resulting JAR file, one pair for each signature. Thus, in the example above, the output JAR file includes files with the following names:
+.LP
+.nf
+\f3
+.fl
+  SUSAN.SF
+.fl
+  SUSAN.DSA
+.fl
+  KEVIN.SF
+.fl
+  KEVIN.DSA
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Note: It is also possible for a JAR file to have mixed signatures, some generated by the JDK 1.1 \f3javakey\fP tool and others by \f3jarsigner\fP. That is, \f3jarsigner\fP can be used to sign JAR files already previously signed using \f3javakey\fP.
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+The various \f3jarsigner\fP options are listed and described below. Note:
+.LP
+.RS 3
+.TP 2
+o
+All option names are preceded by a minus sign (\-).
+.TP 2
+o
+The options may be provided in any order.
+.TP 2
+o
+Items in italics (option values) represent the actual values that must be supplied.
+.TP 2
+o
+The \f2\-keystore\fP, \f2\-storepass\fP, \f2\-keypass\fP, \f2\-sigfile\fP, \f2\-sigalg\fP, \f2\-digestalg\fP, and \f2\-signedjar\fP options are only relevant when signing a JAR file, not when verifying a signed JAR file. Similarly, an alias is only specified on the command line when signing a JAR file.
+.RE
+
+.LP
+.RS 3
+.TP 3
+\-keystore url
+Specifies the URL that tells the keystore location. This defaults to the file \f2.keystore\fP in the user's home directory, as determined by the "user.home" system property.
+.br
+.br
+A keystore is required when signing, so you must explicitly specify one if the default keystore does not exist (or you want to use one other than the default).
+.br
+.br
+A keystore is \f2not\fP required when verifying, but if one is specified, or the default exists, and the \f2\-verbose\fP option was also specified, additional information is output regarding whether or not any of the certificates used to verify the JAR file are contained in that keystore.
+.br
+.br
+Note: the \f2\-keystore\fP argument can actually be a file name (and path) specification rather than a URL, in which case it will be treated the same as a "file:" URL. That is,
+.nf
+\f3
+.fl
+  \-keystore \fP\f4filePathAndName\fP\f3
+.fl
+\fP
+.fi
+is treated as equivalent to
+.nf
+\f3
+.fl
+  \-keystore file:\fP\f4filePathAndName\fP\f3
+.fl
+\fP
+.fi
+If the Sun PKCS#11 provider has been configured in the \f2java.security\fP security properties file (located in the JRE's \f2$JAVA_HOME/lib/security\fP directory), then keytool and jarsigner can operate on the PKCS#11 token by specifying these options:
+.RS 3
+.TP 2
+o
+\f2\-keystore NONE\fP
+.TP 2
+o
+\f2\-storetype PKCS11\fP
+.RE
+For example, this command lists the contents of the configured PKCS#11 token:
+.nf
+\f3
+.fl
+   jarsigner \-keystore NONE \-storetype PKCS11 \-list
+.fl
+\fP
+.fi
+.TP 3
+\-storetype storetype
+Specifies the type of keystore to be instantiated. The default keystore type is the one that is specified as the value of the "keystore.type" property in the security properties file, which is returned by the static \f2getDefaultType\fP method in \f2java.security.KeyStore\fP.
+.br
+.br
+The PIN for a PCKS#11 token can also be specified using the \f2\-storepass\fP option. If none has been specified, keytool and jarsigner will prompt for the token PIN. If the token has a protected authentication path (such as a dedicated PIN\-pad or a biometric reader), then the \f2\-protected\fP option must be specified and no password options can be specified.
+.TP 3
+\-storepass[:env | :file] argument
+Specifies the password which is required to access the keystore. This is only needed when signing (not verifying) a JAR file. In that case, if a \f2\-storepass\fP option is not provided at the command line, the user is prompted for the password.
+.br
+.br
+If the modifier \f2env\fP or \f2file\fP is not specified, then the password has the value \f2argument\fP. Otherwise, the password is retrieved as follows:
+.RS 3
+.TP 2
+o
+\f2env\fP: Retrieve the password from the environment variable named \f2argument\fP
+.TP 2
+o
+\f2file\fP: Retrieve the password from the file named \f2argument\fP
+.RE
+Note: The password shouldn't be specified on the command line or in a script unless it is for testing purposes, or you are on a secure system.
+.TP 3
+\-keypass[:env | :file] argument
+Specifies the password used to protect the private key of the keystore entry addressed by the alias specified on the command line. The password is required when using \f3jarsigner\fP to sign a JAR file. If no password is provided on the command line, and the required password is different from the store password, the user is prompted for it.
+.br
+.br
+If the modifier \f2env\fP or \f2file\fP is not specified, then the password has the value \f2argument\fP. Otherwise, the password is retrieved as follows:
+.RS 3
+.TP 2
+o
+\f2env\fP: Retrieve the password from the environment variable named \f2argument\fP
+.TP 2
+o
+\f2file\fP: Retrieve the password from the file named \f2argument\fP
+.RE
+Note: The password shouldn't be specified on the command line or in a script unless it is for testing purposes, or you are on a secure system.
+.TP 3
+\-sigfile file
+Specifies the base file name to be used for the generated .SF and .DSA files. For example, if \f2file\fP is "DUKESIGN", the generated .SF and .DSA files will be named "DUKESIGN.SF" and "DUKESIGN.DSA", and will be placed in the "META\-INF" directory of the signed JAR file.
+.br
+.br
+The characters in \f2file\fP must come from the set "a\-zA\-Z0\-9_\-". That is, only letters, numbers, underscore, and hyphen characters are allowed. Note: All lowercase characters will be converted to uppercase for the .SF and .DSA file names.
+.br
+.br
+If no \f2\-sigfile\fP option appears on the command line, the base file name for the .SF and .DSA files will be the first 8 characters of the alias name specified on the command line, all converted to upper case. If the alias name has fewer than 8 characters, the full alias name is used. If the alias name contains any characters that are not legal in a signature file name, each such character is converted to an underscore ("_") character in forming the file name.
+.TP 3
+\-sigalg algorithm
+Specifies the name of the signature algorithm to use to sign the JAR file.
+.br
+.br
+See
+.na
+\f2Appendix A\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA of the Java Cryptography Architecture for a list of standard signature algorithm names. This algorithm must be compatible with the private key used to sign the JAR file. If this option is not specified, SHA1withDSA, SHA256withRSA, or SHA256withECDSA will be used depending on the type of private key. There must either be a statically installed provider supplying an implementation of the specified algorithm or the user must specify one with the \f2\-providerClass\fP option, otherwise the command will not succeed.
+.TP 3
+\-digestalg algorithm
+Specifies the name of the message digest algorithm to use when digesting the entries of a jar file.
+.br
+.br
+See
+.na
+\f2Appendix A\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA of the Java Cryptography Architecture for a list of standard message digest algorithm names. If this option is not specified, SHA256 will be used. There must either be a statically installed provider supplying an implementation of the specified algorithm or the user must specify one with the \f2\-providerClass\fP option, otherwise the command will not succeed.
+.TP 3
+\-signedjar file
+Specifies the name to be used for the signed JAR file.
+.br
+.br
+If no name is specified on the command line, the name used is the same as the input JAR file name (the name of the JAR file to be signed); in other words, that file is overwritten with the signed JAR file.
+.TP 3
+\-verify
+If this appears on the command line, the specified JAR file will be verified, not signed. If the verification is successful, "jar verified" will be displayed. If you try to verify an unsigned JAR file, or a JAR file signed with an unsupported algorithm (e.g., RSA when you don't have an RSA provider installed), the following is displayed: "jar is unsigned. (signatures missing or not parsable)"
+.br
+.br
+It is possible to verify JAR files signed using either \f3jarsigner\fP or the JDK 1.1 \f3javakey\fP tool, or both.
+.br
+.br
+For further information on verification, see JAR File Verification.
+.TP 3
+\-certs
+If this appears on the command line, along with the \f2\-verify\fP and \f2\-verbose\fP options, the output includes certificate information for each signer of the JAR file. This information includes
+.RS 3
+.TP 2
+o
+the name of the type of certificate (stored in the .DSA file) that certifies the signer's public key
+.TP 2
+o
+if the certificate is an X.509 certificate (more specifically, an instance of \f2java.security.cert.X509Certificate\fP): the distinguished name of the signer
+.RE
+The keystore is also examined. If no keystore value is specified on the command line, the default keystore file (if any) will be checked. If the public key certificate for a signer matches an entry in the keystore, then the following information will also be displayed:
+.RS 3
+.TP 2
+o
+in parentheses, the alias name for the keystore entry for that signer. If the signer actually comes from a JDK 1.1 identity database instead of from a keystore, the alias name will appear in brackets instead of parentheses.
+.RE
+.TP 3
+\-certchain file
+Specifies the certificate chain to be used, if the certificate chain associated with the private key of the keystore entry, addressed by the alias specified on the command line, is not complete. This may happen if the keystore is located on a hardware token where there is not enough capacity to hold a complete certificate chain. The file can be a sequence of X.509 certificates concatenated together, or a single PKCS#7 formatted data block, either in binary encoding format or in printable encoding format (also known as BASE64 encoding) as defined by the Internet RFC 1421 standard.
+.TP 3
+\-verbose
+If this appears on the command line, it indicates "verbose" mode, which causes \f3jarsigner\fP to output extra information as to the progress of the JAR signing or verification.
+.TP 3
+\-internalsf
+In the past, the .DSA (signature block) file generated when a JAR file was signed used to include a complete encoded copy of the .SF file (signature file) also generated. This behavior has been changed. To reduce the overall size of the output JAR file, the .DSA file by default doesn't contain a copy of the .SF file anymore. But if \f2\-internalsf\fP appears on the command line, the old behavior is utilized. \f3This option is mainly useful for testing; in practice, it should not be used, since doing so eliminates a useful optimization.\fP
+.TP 3
+\-sectionsonly
+If this appears on the command line, the .SF file (signature file) generated when a JAR file is signed does \f2not\fP include a header containing a hash of the whole manifest file. It just contains information and hashes related to each individual source file included in the JAR file, as described in The Signature (.SF) File .
+.br
+.br
+By default, this header is added, as an optimization. When the header is present, then whenever the JAR file is verified, the verification can first check to see whether or not the hash in the header indeed matches the hash of the whole manifest file. If so, verification proceeds to the next step. If not, it is necessary to do a less optimized verification that the hash in each source file information section in the .SF file equals the hash of its corresponding section in the manifest file.
+.br
+.br
+For further information, see JAR File Verification.
+.br
+.br
+\f3This option is mainly useful for testing; in practice, it should not be used, since doing so eliminates a useful optimization.\fP
+.TP 3
+\-protected
+Either \f2true\fP or \f2false\fP. This value should be specified as \f2true\fP if a password must be given via a protected authentication path such as a dedicated PIN reader.
+.TP 3
+\-providerClass provider\-class\-name
+Used to specify the name of cryptographic service provider's master class file when the service provider is not listed in the security properties file, \f2java.security\fP.
+.br
+.br
+Used in conjunction with the \f2\-providerArg\fP \f2ConfigFilePath\fP option, keytool and jarsigner will install the provider dynamically (where \f2ConfigFilePath\fP is the path to the token configuration file). Here's an example of a command to list a PKCS#11 keystore when the Sun PKCS#11 provider has not been configured in the security properties file.
+.nf
+\f3
+.fl
+jarsigner \-keystore NONE \-storetype PKCS11 \\
+.fl
+          \-providerClass sun.security.pkcs11.SunPKCS11 \\
+.fl
+          \-providerArg /foo/bar/token.config \\
+.fl
+          \-list
+.fl
+\fP
+.fi
+.TP 3
+\-providerName providerName
+If more than one provider has been configured in the \f2java.security\fP security properties file, you can use the \f2\-providerName\fP option to target a specific provider instance. The argument to this option is the name of the provider.
+.br
+.br
+For the Sun PKCS#11 provider, \f2providerName\fP is of the form \f2SunPKCS11\-\fP\f2TokenName\fP, where \f2TokenName\fP is the name suffix that the provider instance has been configured with, as detailed in the
+.na
+\f2configuration attributes table\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/p11guide.html#ATTRS. For example, the following command lists the contents of the PKCS#11 keystore provider instance with name suffix \f2SmartCard\fP:
+.nf
+\f3
+.fl
+jarsigner \-keystore NONE \-storetype PKCS11 \\
+.fl
+        \-providerName SunPKCS11\-SmartCard \\
+.fl
+        \-list
+.fl
+\fP
+.fi
+.TP 3
+\-Jjavaoption
+Passes through the specified \f2javaoption\fP string directly to the Java interpreter. (\f3jarsigner\fP is actually a "wrapper" around the interpreter.) This option should not contain any spaces. It is useful for adjusting the execution environment or memory usage. For a list of possible interpreter options, type \f2java \-h\fP or \f2java \-X\fP at the command line.
+.TP 3
+\-tsa url
+If \f2"\-tsa http://example.tsa.url"\fP appears on the command line when signing a JAR file then a timestamp is generated for the signature. The URL, \f2http://example.tsa.url\fP, identifies the location of the Time Stamping Authority (TSA). It overrides any URL found via the \f2\-tsacert\fP option. The \f2\-tsa\fP option does not require the TSA's public key certificate to be present in the keystore.
+.br
+.br
+To generate the timestamp, \f2jarsigner\fP communicates with the TSA using the Time\-Stamp Protocol (TSP) defined in
+.na
+\f2RFC 3161\fP @
+.fi
+http://www.ietf.org/rfc/rfc3161.txt. If successful, the timestamp token returned by the TSA is stored along with the signature in the signature block file.
+.TP 3
+\-tsacert alias
+If \f2"\-tsacert alias"\fP appears on the command line when signing a JAR file then a timestamp is generated for the signature. The \f2alias\fP identifies the TSA's public key certificate in the keystore that is currently in effect. The entry's certificate is examined for a Subject Information Access extension that contains a URL identifying the location of the TSA.
+.br
+.br
+The TSA's public key certificate must be present in the keystore when using \f2\-tsacert\fP.
+.TP 3
+\-altsigner class
+Specifies that an alternative signing mechanism be used. The fully\-qualified class name identifies a class file that extends the \f2com.sun.jarsigner.ContentSigner abstract class\fP. The path to this class file is defined by the \f2\-altsignerpath\fP option. If the \f2\-altsigner\fP option is used, \f2jarsigner\fP uses the signing mechanism provided by the specified class. Otherwise, \f2jarsigner\fP uses its default signing mechanism.
+.br
+.br
+For example, to use the signing mechanism provided by a class named \f2com.sun.sun.jarsigner.AuthSigner\fP, use the \f2jarsigner\fP option \f2"\-altsigner com.sun.jarsigner.AuthSigner"\fP
+.TP 3
+\-altsignerpath classpathlist
+Specifies the path to the class file (the class file name is specified with the \f2\-altsigner\fP option described above) and any JAR files it depends on. If the class file is in a JAR file, then this specifies the path to that JAR file, as shown in the example below.
+.br
+.br
+An absolute path or a path relative to the current directory may be specified. If \f2classpathlist\fP contains multiple paths or JAR files, they should be separated with a colon (\f2:\fP) on Solaris and a semi\-colon (\f2;\fP) on Windows. This option is not necessary if the class is already in the search path.
+.br
+.br
+Example of specifying the path to a jar file that contains the class file:
+.nf
+\f3
+.fl
+\-altsignerpath /home/user/lib/authsigner.jar
+.fl
+\fP
+.fi
+Note that the JAR file name is included.
+.br
+.br
+Example of specifying the path to the jar file that contains the class file:
+.nf
+\f3
+.fl
+\-altsignerpath /home/user/classes/com/sun/tools/jarsigner/
+.fl
+\fP
+.fi
+Note that the JAR file name is omitted.
+.TP 3
+\-strict
+During the signing or verifying process, some warning messages may be shown. If this option appears on the command line, the exit code of the tool will reflect the warning messages that are found. Read the "WARNINGS" section for details.
+.TP 3
+\-verbose:sub\-options
+For the verifying process, the \f2\-verbose\fP option takes sub\-options to determine how much information will be shown. If \f2\-certs\fP is also specified, the default mode (or sub\-option all) displays each entry as it is being processed and following that, the certificate information for each signer of the JAR file. If \f2\-certs\fP and the \f2\-verbose:grouped\fP sub\-option are specified, entries with the same signer info are grouped and displayed together along with their certificate information. If \f2\-certs\fP and the \f2\-verbose:summary\fP sub\-option are specified, then entries with the same signer info are grouped and displayed together along with their certificate information but details about each entry are summarized and displayed as "one entry (and more)". See the examples section for more information.
+.RE
+
+.LP
+.SH "EXAMPLES"
+.LP
+.SS
+Signing a JAR File
+.LP
+.LP
+Suppose you have a JAR file named "bundle.jar" and you'd like to sign it using the private key of the user whose keystore alias is "jane" in the keystore named "mystore" in the "working" directory. You can use the following to sign the JAR file and name the signed JAR file "sbundle.jar":
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-keystore /working/mystore \-storepass \fP\f4<keystore password>\fP\f3
+.fl
+      \-keypass \fP\f4<private key password>\fP\f3 \-signedjar sbundle.jar bundle.jar jane
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Note that there is no \f2\-sigfile\fP specified in the command above, so the generated .SF and .DSA files to be placed in the signed JAR file will have default names based on the alias name. That is, they will be named \f2JANE.SF\fP and \f2JANE.DSA\fP.
+.LP
+.LP
+If you want to be prompted for the store password and the private key password, you could shorten the above command to
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-keystore /working/mystore
+.fl
+      \-signedjar sbundle.jar bundle.jar jane
+.fl
+\fP
+.fi
+
+.LP
+.LP
+If the keystore to be used is the default keystore (the one named ".keystore" in your home directory), you don't need to specify a keystore, as in:
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-signedjar sbundle.jar bundle.jar jane
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Finally, if you want the signed JAR file to simply overwrite the input JAR file (\f2bundle.jar\fP), you don't need to specify a \f2\-signedjar\fP option:
+.LP
+.nf
+\f3
+.fl
+    jarsigner bundle.jar jane
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Verifying a Signed JAR File
+.LP
+.LP
+To verify a signed JAR file, that is, to verify that the signature is valid and the JAR file has not been tampered with, use a command such as the following:
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-verify sbundle.jar
+.fl
+\fP
+.fi
+
+.LP
+.LP
+If the verification is successful,
+.LP
+.nf
+\f3
+.fl
+    jar verified.
+.fl
+\fP
+.fi
+
+.LP
+.LP
+is displayed. Otherwise, an error message appears.
+.LP
+.LP
+You can get more information if you use the \f2\-verbose\fP option. A sample use of \f3jarsigner\fP with the \f2\-verbose\fP option is shown below, along with sample output:
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-verify \-verbose sbundle.jar
+.fl
+
+.fl
+           198 Fri Sep 26 16:14:06 PDT 1997 META\-INF/MANIFEST.MF
+.fl
+           199 Fri Sep 26 16:22:10 PDT 1997 META\-INF/JANE.SF
+.fl
+          1013 Fri Sep 26 16:22:10 PDT 1997 META\-INF/JANE.DSA
+.fl
+    smk   2752 Fri Sep 26 16:12:30 PDT 1997 AclEx.class
+.fl
+    smk    849 Fri Sep 26 16:12:46 PDT 1997 test.class
+.fl
+
+.fl
+      s = signature was verified
+.fl
+      m = entry is listed in manifest
+.fl
+      k = at least one certificate was found in keystore
+.fl
+
+.fl
+    jar verified.
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Verification with Certificate Information
+.LP
+.LP
+If you specify the \f2\-certs\fP option when verifying, along with the \f2\-verify\fP and \f2\-verbose\fP options, the output includes certificate information for each signer of the JAR file, including the certificate type, the signer distinguished name information (if and only if it's an X.509 certificate), and, in parentheses, the keystore alias for the signer if the public key certificate in the JAR file matches that in a keystore entry. For example,
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-keystore /working/mystore \-verify \-verbose \-certs myTest.jar
+.fl
+
+.fl
+           198 Fri Sep 26 16:14:06 PDT 1997 META\-INF/MANIFEST.MF
+.fl
+           199 Fri Sep 26 16:22:10 PDT 1997 META\-INF/JANE.SF
+.fl
+          1013 Fri Sep 26 16:22:10 PDT 1997 META\-INF/JANE.DSA
+.fl
+           208 Fri Sep 26 16:23:30 PDT 1997 META\-INF/JAVATEST.SF
+.fl
+          1087 Fri Sep 26 16:23:30 PDT 1997 META\-INF/JAVATEST.DSA
+.fl
+    smk   2752 Fri Sep 26 16:12:30 PDT 1997 Tst.class
+.fl
+
+.fl
+      X.509, CN=Test Group, OU=Java Software, O=Sun Microsystems, L=CUP, S=CA, C=US (javatest)
+.fl
+      X.509, CN=Jane Smith, OU=Java Software, O=Sun, L=cup, S=ca, C=us (jane)
+.fl
+
+.fl
+      s = signature was verified
+.fl
+      m = entry is listed in manifest
+.fl
+      k = at least one certificate was found in keystore
+.fl
+
+.fl
+    jar verified.
+.fl
+\fP
+.fi
+
+.LP
+.LP
+If the certificate for a signer is not an X.509 certificate, there is no distinguished name information. In that case, just the certificate type and the alias are shown. For example, if the certificate is a PGP certificate, and the alias is "bob", you'd get
+.LP
+.nf
+\f3
+.fl
+      PGP, (bob)
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Verification of a JAR File that Includes Identity Database Signers
+.LP
+.LP
+If a JAR file has been signed using the JDK 1.1 \f3javakey\fP tool, and thus the signer is an alias in an identity database, the verification output includes an "i" symbol. If the JAR file has been signed by both an alias in an identity database and an alias in a keystore, both "k" and "i" appear.
+.LP
+.LP
+When the \f2\-certs\fP option is used, any identity database aliases are shown in square brackets rather than the parentheses used for keystore aliases. For example:
+.LP
+.nf
+\f3
+.fl
+    jarsigner \-keystore /working/mystore \-verify \-verbose \-certs writeFile.jar
+.fl
+
+.fl
+           198 Fri Sep 26 16:14:06 PDT 1997 META\-INF/MANIFEST.MF
+.fl
+           199 Fri Sep 26 16:22:10 PDT 1997 META\-INF/JANE.SF
+.fl
+          1013 Fri Sep 26 16:22:10 PDT 1997 META\-INF/JANE.DSA
+.fl
+           199 Fri Sep 27 12:22:30 PDT 1997 META\-INF/DUKE.SF
+.fl
+          1013 Fri Sep 27 12:22:30 PDT 1997 META\-INF/DUKE.DSA
+.fl
+   smki   2752 Fri Sep 26 16:12:30 PDT 1997 writeFile.html
+.fl
+
+.fl
+      X.509, CN=Jane Smith, OU=Java Software, O=Sun, L=cup, S=ca, C=us (jane)
+.fl
+      X.509, CN=Duke, OU=Java Software, O=Sun, L=cup, S=ca, C=us [duke]
+.fl
+
+.fl
+      s = signature was verified
+.fl
+      m = entry is listed in manifest
+.fl
+      k = at least one certificate was found in keystore
+.fl
+      i = at least one certificate was found in identity scope
+.fl
+
+.fl
+    jar verified.
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Note that the alias "duke" is in brackets to denote that it is an identity database alias, not a keystore alias.
+.LP
+.SH "WARNINGS"
+.LP
+During the signing/verifying process, jarsigner may display various warnings. These warning codes are defined as follows:
+.nf
+\f3
+.fl
+         hasExpiringCert         2
+.fl
+             This jar contains entries whose signer certificate will expire within six months
+.fl
+
+.fl
+         hasExpiredCert          4
+.fl
+             This jar contains entries whose signer certificate has expired.
+.fl
+
+.fl
+         notYetValidCert         4
+.fl
+             This jar contains entries whose signer certificate is not yet valid.
+.fl
+
+.fl
+         chainNotValidated       4
+.fl
+             This jar contains entries whose certificate chain cannot be correctly validated.
+.fl
+
+.fl
+         badKeyUsage             8
+.fl
+             This jar contains entries whose signer certificate's KeyUsage extension doesn't allow code signing.
+.fl
+
+.fl
+         badExtendedKeyUsage     8
+.fl
+             This jar contains entries whose signer certificate's ExtendedKeyUsage extension
+.fl
+             doesn't allow code signing.
+.fl
+
+.fl
+         badNetscapeCertType     8
+.fl
+             This jar contains entries whose signer certificate's NetscapeCertType extension
+.fl
+             doesn't allow code signing.
+.fl
+
+.fl
+         hasUnsignedEntry        16
+.fl
+             This jar contains unsigned entries which have not been integrity\-checked.
+.fl
+
+.fl
+         notSignedByAlias        32
+.fl
+             This jar contains signed entries which are not signed by the specified alias(es)
+.fl
+
+.fl
+         aliasNotInStore         32
+.fl
+             This jar contains signed entries that are not signed by alias in this keystore
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+.LP
+When the \f2\-strict\fP option is provided, an OR\-value of warnings detected will be returned as the exit code of the tool. For example, if a certificate used to sign an entry is expired and has a keyUsage extension that does not allow it to sign a file, an exit code 12 (=4+8) will be returned.
+.LP
+.LP
+\f3Note\fP: Exit codes are reused because only 0\-255 is legal for Unix. In any case, if the signing/verifying process fails, the following exit code will be returned:
+.LP
+.nf
+\f3
+.fl
+failure                 1
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Compatibility with JDK 1.1
+.LP
+.LP
+The \f3keytool\fP and \f3jarsigner\fP tools completely replace the \f3javakey\fP tool provided in JDK 1.1. These new tools provide more features than \f3javakey\fP, including the ability to protect the keystore and private keys with passwords, and the ability to verify signatures in addition to generating them.
+.LP
+.LP
+The new keystore architecture replaces the identity database that \f3javakey\fP created and managed. There is no backwards compatibility between the keystore format and the database format used by \f3javakey\fP in 1.1. However,
+.LP
+.RS 3
+.TP 2
+o
+It is possible to import the information from an identity database into a keystore, via the \f3keytool\fP \f2\-identitydb\fP command.
+.TP 2
+o
+\f3jarsigner\fP can sign JAR files also previously signed using \f3javakey\fP.
+.TP 2
+o
+\f3jarsigner\fP can verify JAR files signed using \f3javakey\fP. Thus, it recognizes and can work with signer aliases that are from a JDK 1.1 identity database rather than a Java 2 SDK keystore.
+.RE
+
+.LP
+.LP
+The following table explains how JAR files that were signed in JDK 1.1.x are treated in the Java 2 platform.
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81 82 83 84
+.nr 34 \n(.lu
+.eo
+.am 82
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(82 .ll \n(82u
+.in 0
+\f3Trusted Identity imported into Java 2 Platform keystore from 1.1 database (4)\fP
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 83
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(83 .ll \n(83u
+.in 0
+\f3Policy File grants privileges to Identity/Alias\fP
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 84
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(84 .ll \n(84u
+.in 0
+Default privileges granted to all code.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 84
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(84 .ll \n(84u
+.in 0
+Default privileges granted to all code.
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 84
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(84 .ll \n(84u
+.in 0
+Default privileges granted to all code.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 84
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(84 .ll \n(84u
+.in 0
+Default privileges granted to all code. (3)
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 84
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(84 .ll \n(84u
+.in 0
+Default privileges granted to all code. (1,3)
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 84
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(84 .ll \n(84u
+.in 0
+Default privileges granted to all code plus privileges granted in policy file.
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 84
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/6u
+.if \n(.l<\n(84 .ll \n(84u
+.in 0
+Default privileges granted to all code plus privileges granted in policy file. (2)
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \w\f3JAR File Type\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wUnsigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSigned JAR
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Identity in 1.1 database\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNO
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNO
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNO
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wYES/Untrusted
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wYES/Untrusted
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNO
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wYES/Trusted
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wYES/Trusted
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wYES/Trusted
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wYES/Trusted
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 82 0
+.nr 38 \wNO
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wNO
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wYES
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wNO
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wNO
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wYES
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wYES
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wNO
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wYES
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \wNO
+.if \n(82<\n(38 .nr 82 \n(38
+.82
+.rm 82
+.nr 38 \n(a-
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 83 0
+.nr 38 \wNO
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wNO
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wNO
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wNO
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wYES
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wYES
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wYES
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wNO
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wNO
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 38 \wYES
+.if \n(83<\n(38 .nr 83 \n(38
+.83
+.rm 83
+.nr 38 \n(b-
+.if \n(83<\n(38 .nr 83 \n(38
+.nr 84 0
+.nr 38 \w\f3Privileges Granted\fP
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \wAll privileges
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \wAll privileges (1)
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \wAll privileges (1)
+.if \n(84<\n(38 .nr 84 \n(38
+.84
+.rm 84
+.nr 38 \n(c-
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \n(d-
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \n(e-
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \n(f-
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \n(g-
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \n(h-
+.if \n(84<\n(38 .nr 84 \n(38
+.nr 38 \n(i-
+.if \n(84<\n(38 .nr 84 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr 42 \n(81+(3*\n(38)
+.nr 82 +\n(42
+.nr 43 \n(82+(3*\n(38)
+.nr 83 +\n(43
+.nr 44 \n(83+(3*\n(38)
+.nr 84 +\n(44
+.nr TW \n(84
+.if t .if \n(TW>\n(.li .tm Table at line 1082 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ne \n(a|u+\n(.Vu
+.ne \n(b|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3JAR File Type\fP\h'|\n(41u'\f3Identity in 1.1 database\fP\h'|\n(42u'\h'|\n(43u'\h'|\n(44u'\f3Privileges Granted\fP
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(42u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(43u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'NO\h'|\n(42u'NO\h'|\n(43u'NO\h'|\n(44u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(44u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Unsigned JAR\h'|\n(41u'NO\h'|\n(42u'NO\h'|\n(43u'NO\h'|\n(44u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(44u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'NO\h'|\n(42u'YES\h'|\n(43u'NO\h'|\n(44u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(44u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'YES/Untrusted\h'|\n(42u'NO\h'|\n(43u'NO\h'|\n(44u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(44u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'YES/Untrusted\h'|\n(42u'NO\h'|\n(43u'YES\h'|\n(44u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(44u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'NO\h'|\n(42u'YES\h'|\n(43u'YES\h'|\n(44u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(44u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'YES/Trusted\h'|\n(42u'YES\h'|\n(43u'YES\h'|\n(44u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(44u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'YES/Trusted\h'|\n(42u'NO\h'|\n(43u'NO\h'|\n(44u'All privileges
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'YES/Trusted\h'|\n(42u'YES\h'|\n(43u'NO\h'|\n(44u'All privileges (1)
+.ta \n(80u \n(81u \n(82u \n(83u \n(84u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Signed JAR\h'|\n(41u'YES/Trusted\h'|\n(42u'NO\h'|\n(43u'YES\h'|\n(44u'All privileges (1)
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-42
+
+.LP
+.LP
+Notes:
+.LP
+.RS 3
+.TP 3
+1.
+If an identity/alias is mentioned in the policy file, it must be imported into the keystore for the policy file to have any effect on privileges granted.
+.TP 3
+2.
+The policy file/keystore combination has precedence over a trusted identity in the identity database.
+.TP 3
+3.
+Untrusted identities are ignored in the Java 2 platform.
+.TP 3
+4.
+Only trusted identities can be imported into Java 2 SDK keystores.
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+jar(1) tool documentation
+.TP 2
+o
+keytool(1) tool documentation
+.TP 2
+o
+the
+.na
+\f4Security\fP @
+.fi
+http://download.oracle.com/javase/tutorial/security/index.html trail of the
+.na
+\f4Java Tutorial\fP @
+.fi
+http://download.oracle.com/javase/tutorial/index.html for examples of the use of the \f3jarsigner\fP tool
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/java.1 b/jdk/src/bsd/doc/man/java.1
new file mode 100644
index 0000000..1092b70
--- /dev/null
+++ b/jdk/src/bsd/doc/man/java.1
@@ -0,0 +1,517 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH java 1 "10 May 2011"
+
+.LP
+.SH "Name"
+java \- the Java application launcher
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+    \fP\f3java\fP [ options ] class [ argument ... ]
+.fl
+    \f3java\fP [ options ] \f3\-jar\fP file.jar [ argument ... ]
+.fl
+.fi
+
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options.
+.TP 3
+class
+Name of the class to be invoked.
+.TP 3
+file.jar
+Name of the jar file to be invoked. Used only with \f2\-jar\fP.
+.TP 3
+argument
+Argument passed to the \f3main\fP function.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3java\fP tool launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class's \f3main\fP method.
+.LP
+.LP
+The method must be declared public and static, it must not return any value, and it must accept a \f2String\fP array as a parameter. The method declaration must look like the following:
+.LP
+.nf
+\f3
+.fl
+public static void main(String args[])
+.fl
+\fP
+.fi
+
+.LP
+.LP
+By default, the first non\-option argument is the name of the class to be invoked. A fully\-qualified class name should be used. If the \f3\-jar\fP option is specified, the first non\-option argument is the name of a \f3JAR\fP archive containing class and resource files for the application, with the startup class indicated by the \f3Main\-Class\fP manifest header.
+.LP
+.LP
+The Java runtime searches for the startup class, and other classes used, in three sets of locations: the bootstrap class path, the installed extensions, and the user class path.
+.LP
+.LP
+Non\-option arguments after the class name or JAR file name are passed to the \f3main\fP function.
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+The launcher has a set of standard options that are supported on the current runtime environment and will be supported in future releases. In addition, the current implementations of the virtual machines support a set of non\-standard options that are subject to change in future releases.
+.LP
+.SH "Standard Options"
+.LP
+.RS 3
+.TP 3
+\-client
+Select the Java HotSpot Client VM. A 64\-bit capable jdk currently ignores this option and instead uses the Java Hotspot Server VM.
+.br
+.br
+For default VM selection, see
+.na
+\f2Server\-Class Machine Detection\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/vm/server\-class.html
+.TP 3
+\-server
+Select the Java HotSpot Server VM. On a 64\-bit capable jdk only the Java Hotspot Server VM is supported so the \-server option is implicit.
+.br
+.br
+For default VM selection, see
+.na
+\f2Server\-Class Machine Detection\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/vm/server\-class.html
+.TP 3
+\-agentlib:libname[=options]
+Load native agent library \f2libname\fP, e.g.
+.br
+.br
+\-agentlib:hprof
+.br
+.br
+\-agentlib:jdwp=help
+.br
+.br
+\-agentlib:hprof=help
+.br
+.br
+For more information, see
+.na
+\f2JVMTI Agent Command Line Options\fP @
+.fi
+http://download.oracle.com/javase/7/docs/platform/jvmti/jvmti.html#starting.
+.TP 3
+\-agentpath:pathname[=options]
+Load a native agent library by full pathname. For more information, see
+.na
+\f2JVMTI Agent Command Line Options\fP @
+.fi
+http://download.oracle.com/javase/7/docs/platform/jvmti/jvmti.html#starting.
+.TP 3
+\-classpath classpath
+.TP 3
+\-cp classpath
+Specify a list of directories, JAR archives, and ZIP archives to search for class files. Class path entries are separated by colons (\f3:\fP). Specifying \f3\-classpath\fP or \f3\-cp\fP overrides any setting of the \f3CLASSPATH\fP environment variable.
+.br
+.br
+If \f3\-classpath\fP and \f3\-cp\fP are not used and \f3CLASSPATH\fP is not set, the user class path consists of the current directory (\f4.\fP).
+.br
+.br
+As a special convenience, a class path element containing a basename of \f2*\fP is considered equivalent to specifying a list of all the files in the directory with the extension \f2.jar\fP or \f2.JAR\fP (a java program cannot tell the difference between the two invocations).
+.br
+.br
+For example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to a \f2A.jar:b.JAR\fP, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of \f2*\fP expands to a list of all the jar files in the current directory. The \f2CLASSPATH\fP environment variable, where defined, will be similarly expanded. Any classpath wildcard expansion occurs before the Java virtual machine is started \-\- no Java program will ever see unexpanded wildcards except by querying the environment. For example; by invoking \f2System.getenv("CLASSPATH")\fP.
+.br
+.br
+For more information on class paths, see
+.na
+\f2Setting the Class Path\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#classpath.
+.TP 3
+\-Dproperty=value
+Set a system property value.
+.TP 3
+\-d32
+.TP 3
+\-d64
+Request that the program to be run in a 32\-bit or 64\-bit environment, respectively. If the requested environment is not installed or is not supported, an error is reported.
+.br
+.br
+Currently only the Java HotSpot Server VM supports 64\-bit operation, and the "\-server" option is implicit with the use of \-d64. And the "\-client" option is ignored with the use of \-d64. This is subject to change in a future release.
+.br
+.br
+If neither \f3\-d32\fP nor \f3\-d64\fP is specified, the default is to run in a 32\-bit environment, except for 64\-bit only systems. This is subject to change in a future release.
+.TP 3
+\-enableassertions[:<package name>"..." | :<class name> ]
+.TP 3
+\-ea[:<package name>"..." | :<class name> ]
+Enable assertions. Assertions are disabled by default.
+.br
+.br
+With no arguments, \f3enableassertions\fP or \f3\-ea\fP enables assertions. With one argument ending in \f2"..."\fP, the switch enables assertions in the specified package and any subpackages. If the argument is simply \f2"..."\fP, the switch enables assertions in the unnamed package in the current working directory. With one argument not ending in \f2"..."\fP, the switch enables assertions in the specified class.
+.br
+.br
+If a single command line contains multiple instances of these switches, they are processed in order before loading any classes. So, for example, to run a program with assertions enabled only in package \f2com.wombat.fruitbat\fP (and any subpackages), the following command could be used:
+.nf
+\f3
+.fl
+java \-ea:com.wombat.fruitbat... <Main Class>
+.fl
+\fP
+.fi
+The \f3\-enableassertions\fP and \f3\-ea\fP switches apply to \f2all\fP class loaders and to system classes (which do not have a class loader). There is one exception to this rule: in their no\-argument form, the switches do \f2not\fP apply to system. This makes it easy to turn on asserts in all classes except for system classes. A separate switch is provided to enable asserts in all system classes; see \f3\-enablesystemassertions\fP below.
+.TP 3
+\-disableassertions[:<package name>"..." | :<class name> ]
+.TP 3
+\-da[:<package name>"..." | :<class name> ]
+Disable assertions. This is the default.
+.br
+.br
+With no arguments, \f3disableassertions\fP or \f3\-da\fP disables assertions. With one argument ending in \f2"..."\fP, the switch disables assertions in the specified package and any subpackages. If the argument is simply \f2"..."\fP, the switch disables assertions in the unnamed package in the current working directory. With one argument not ending in \f2"..."\fP, the switch disables assertions in the specified class.
+.br
+.br
+To run a program with assertions enabled in package \f2com.wombat.fruitbat\fP but disabled in class \f2com.wombat.fruitbat.Brickbat\fP, the following command could be used:
+.nf
+\f3
+.fl
+java \-ea:com.wombat.fruitbat... \-da:com.wombat.fruitbat.Brickbat \fP\f4<Main Class>\fP\f3
+.fl
+\fP
+.fi
+The \f3\-disableassertions\fP and \f3\-da\fP switches apply to \f2all\fP class loaders and to system classes (which do not have a class loader). There is one exception to this rule: in their no\-argument form, the switches do \f2not\fP apply to system. This makes it easy to turn on asserts in all classes except for system classes. A separate switch is provided to enable asserts in all system classes; see \f3\-disablesystemassertions\fP below.
+.TP 3
+\-enablesystemassertions
+.TP 3
+\-esa
+Enable asserts in all system classes (sets the \f2default assertion status\fP for system classes to \f2true\fP).
+.TP 3
+\-disablesystemassertions
+.TP 3
+\-dsa
+Disables asserts in all system classes.
+.TP 3
+\-jar
+Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form \f3Main\-Class: \fP\f4classname\fP. Here, \f2classname\fP identifies the class having the \f2public\ static\ void\ main(String[]\ args)\fP method that serves as your application's starting point. See the jar(1) and the Jar trail of the
+.na
+\f2Java Tutorial\fP @
+.fi
+http://download.oracle.com/javase/tutorial/deployment/jar for information about working with Jar files and Jar\-file manifests.
+.br
+.br
+When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
+.br
+.br
+Note that JAR files that can be run with the "java \-jar" option can have their execute permissions set so they can be run without using "java \-jar". Refer to
+.na
+\f2Java Archive (JAR) Files\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jar/index.html.
+.TP 3
+\-javaagent:jarpath[=options]
+Load a Java programming language agent, see
+.na
+\f2java.lang.instrument\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/java/lang/instrument/package\-summary.html.
+.TP 3
+\-jre\-restrict\-search
+Include user\-private JREs in the version search.
+.TP 3
+\-no\-jre\-restrict\-search
+Exclude user\-private JREs in the version search.
+.TP 3
+\-verbose
+.TP 3
+\-verbose:class
+Display information about each class loaded.
+.TP 3
+\-verbose:gc
+Report on each garbage collection event.
+.TP 3
+\-verbose:jni
+Report information about use of native methods and other Java Native Interface activity.
+.TP 3
+\-version
+Display version information and exit.
+.TP 3
+\-version:release
+Specifies that the version specified by \f2release\fP is required by the class or jar file specified on the command line. If the version of the java command invoked does not meet this specification and an appropriate implementation is found on the system, the appropriate implementation will be used.
+.br
+.br
+\f2release\fP not only can specify an exact version, but can also specify a list of versions called a version string. A version string is an ordered list of version ranges separated by spaces. A version range is either a version\-id, a version\-id followed by a star (*), a version\-id followed by a plus sign (+) , or two version\-ranges combined using an ampersand (&). The star means prefix match, the plus sign means this version or greater, and the ampersand means the logical anding of the two version\-ranges. For example:
+.nf
+\f3
+.fl
+\-version:"1.6.0_13 1.6*&1.6.0_10+"
+.fl
+\fP
+.fi
+The meaning of the above is that the class or jar file requires either version 1.6.0_13, or a version with 1.6 as a version\-id prefix and that is not less than 1.6.0_10.. The exact syntax and definition of version strings may be found in Appendix A of the Java Network Launching Protocol & API Specification (JSR\-56).
+.br
+.br
+For jar files, the usual preference is to specify version requirements in the jar file manifest rather than on the command line.
+.br
+.br
+See the following NOTES section for important policy information on the use of this option.
+.TP 3
+\-showversion
+Display version information and continue.
+.TP 3
+\-?
+.TP 3
+\-help
+Display usage information and exit.
+.TP 3
+\-splash:imagepath
+Show splash screen with image specified by \f2imagepath\fP.
+.TP 3
+\-X
+Display information about non\-standard options and exit.
+.RE
+
+.LP
+.SS
+Non\-Standard Options
+.LP
+.RS 3
+.TP 3
+\-Xint
+Operate in interpreted\-only mode. Compilation to native code is disabled, and all bytecodes are executed by the interpreter. The performance benefits offered by the Java HotSpot VMs' adaptive compiler will not be present in this mode.
+.TP 3
+\-Xbatch
+Disable background compilation. Normally the VM will compile the method as a background task, running the method in interpreter mode until the background compilation is finished. The \f2\-Xbatch\fP flag disables background compilation so that compilation of all methods proceeds as a foreground task until completed.
+.TP 3
+\-Xbootclasspath:bootclasspath
+Specify a colon\-separated list of directories, JAR archives, and ZIP archives to search for boot class files. These are used in place of the boot class files included in the Java platform JDK. \f2Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java Runtime Environment binary code license.\fP
+.TP 3
+\-Xbootclasspath/a:path
+Specify a colon\-separated path of directires, JAR archives, and ZIP archives to append to the default bootstrap class path.
+.TP 3
+\-Xbootclasspath/p:path
+Specify a colon\-separated path of directires, JAR archives, and ZIP archives to prepend in front of the default bootstrap class path. \f2Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java Runtime Environment binary code license.\fP
+.TP 3
+\-Xcheck:jni
+Perform additional checks for Java Native Interface (JNI) functions. Specifically, the Java Virtual Machine validates the parameters passed to the JNI function as well as the runtime environment data before processing the JNI request. Any invalid data encountered indicates a problem in the native code, and the Java Virtual Machine will terminate with a fatal error in such cases. Expect a performance degradation when this option is used.
+.TP 3
+\-Xfuture
+Perform strict class\-file format checks. For purposes of backwards compatibility, the default format checks performed by the JDK's virtual machine are no stricter than the checks performed by 1.1.x versions of the JDK software. The \f3\-Xfuture\fP flag turns on stricter class\-file format checks that enforce closer conformance to the class\-file format specification. Developers are encouraged to use this flag when developing new code because the stricter checks will become the default in future releases of the Java application launcher.
+.TP 3
+\-Xnoclassgc
+Disable class garbage collection. Use of this option will prevent memory recovery from loaded classes thus increasing overall memory usage. This could cause OutOfMemoryError to be thrown in some applications.
+.TP 3
+\-Xincgc
+Enable the incremental garbage collector. The incremental garbage collector, which is off by default, will reduce the occasional long garbage\-collection pauses during program execution. The incremental garbage collector will at times execute concurrently with the program and during such times will reduce the processor capacity available to the program.
+.TP 3
+\-Xloggc:file
+Report on each garbage collection event, as with \-verbose:gc, but log this data to \f2file\fP. In addition to the information \f2\-verbose:gc\fP gives, each reported event will be preceeded by the time (in seconds) since the first garbage\-collection event.
+.br
+.br
+Always use a local file system for storage of this file to avoid stalling the JVM due to network latency. The file may be truncated in the case of a full file system and logging will continue on the truncated file. This option overrides \f2\-verbose:gc\fP if both are given on the command line.
+.TP 3
+\-Xmsn
+Specify the initial size, in bytes, of the memory allocation pool. This value must be a multiple of 1024 greater than 1MB. Append the letter \f2k\fP or \f2K\fP to indicate kilobytes, or \f2m\fP or \f2M\fP to indicate megabytes. The default value is chosen at runtime based on system configuration. For more information, see
+.na
+\f2HotSpot Ergonomics\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/vm/gc\-ergonomics.html
+.br
+.br
+Examples:
+.nf
+\f3
+.fl
+       \-Xms6291456
+.fl
+       \-Xms6144k
+.fl
+       \-Xms6m
+.fl
+
+.fl
+\fP
+.fi
+.TP 3
+\-Xmxn
+Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter \f2k\fP or \f2K\fP to indicate kilobytes, or \f2m\fP or \f2M\fP to indicate megabytes. The default value is chosen at runtime based on system configuration. For more information, see
+.na
+\f2HotSpot Ergonomics\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/vm/gc\-ergonomics.html
+.br
+.br
+Examples:
+.nf
+\f3
+.fl
+       \-Xmx83886080
+.fl
+       \-Xmx81920k
+.fl
+       \-Xmx80m
+.fl
+
+.fl
+\fP
+.fi
+On Solaris 7 and Solaris 8 SPARC platforms, the upper limit for this value is approximately 4000m minus overhead amounts. On Solaris 2.6 and x86 platforms, the upper limit is approximately 2000m minus overhead amounts. On Bsd platforms, the upper limit is approximately 2000m minus overhead amounts.
+.TP 3
+\-Xprof
+Profiles the running program, and sends profiling data to standard output. This option is provided as a utility that is useful in program development and is not intended to be used in production systems.
+.TP 3
+\-Xrs
+Reduces use of operating\-system signals by the Java virtual machine (JVM).
+.br
+.br
+In a previous release, the Shutdown Hooks facility was added to allow orderly shutdown of a Java application. The intent was to allow user cleanup code (such as closing database connections) to run at shutdown, even if the JVM terminates abruptly.
+.br
+.br
+Sun's JVM catches signals to implement shutdown hooks for abnormal JVM termination. The JVM uses SIGHUP, SIGINT, and SIGTERM to initiate the running of shutdown hooks.
+.br
+.br
+The JVM uses a similar mechanism to implement the pre\-1.2 feature of dumping thread stacks for debugging purposes. Sun's JVM uses SIGQUIT to perform thread dumps.
+.br
+.br
+Applications embedding the JVM frequently need to trap signals like SIGINT or SIGTERM, which can lead to interference with the JVM's own signal handlers. The \f3\-Xrs\fP command\-line option is available to address this issue. When \f3\-Xrs\fP is used on Sun's JVM, the signal masks for SIGINT, SIGTERM, SIGHUP, and SIGQUIT are not changed by the JVM, and signal handlers for these signals are not installed.
+.br
+.br
+There are two consequences of specifying \f3\-Xrs\fP:
+.RS 3
+.TP 2
+o
+SIGQUIT thread dumps are not available.
+.TP 2
+o
+User code is responsible for causing shutdown hooks to run, for example by calling System.exit() when the JVM is to be terminated.
+.RE
+.TP 3
+\-Xssn
+Set thread stack size.
+.TP 3
+\-XX:+UseAltSigs
+The VM uses \f2SIGUSR1\fP and \f2SIGUSR2\fP by default, which can sometimes conflict with applications that signal\-chain \f2SIGUSR1\fP and \f2SIGUSR2\fP. The \f2\-XX:+UseAltSigs\fP option will cause the VM to use signals other than \f2SIGUSR1\fP and \f2SIGUSR2\fP as the default.
+.RE
+
+.LP
+.SH "NOTES"
+.LP
+.LP
+The \f3\-version:\fP\f2release\fP command line option places no restrictions on the complexity of the release specification. However, only a restricted subset of the possible release specifications represent sound policy and only these are fully supported. These policies are:
+.LP
+.RS 3
+.TP 3
+1.
+Any version, represented by not using this option.
+.TP 3
+2.
+Any version greater than an arbitrarily precise version\-id. For example:
+.nf
+\f3
+.fl
+"1.6.0_10+"
+.fl
+\fP
+.fi
+This would utilize any version greater than \f21.6.0_10\fP. This is useful for a case where an interface was introduced (or a bug fixed) in the release specified.
+.TP 3
+3.
+A version greater than an arbitrarily precise version\-id, bounded by the upper bound of that release family. For example:
+.nf
+\f3
+.fl
+"1.6.0_10+&1.6*"
+.fl
+\fP
+.fi
+.TP 3
+4.
+"Or" expressions of items 2. or 3. above. For example:
+.nf
+\f3
+.fl
+"1.6.0_10+&1.6* 1.7+"
+.fl
+\fP
+.fi
+Similar to item 2. this is useful when a change was introduced in a release (1.7) but also made available in updates to previous releases.
+.RE
+
+.LP
+.SH "EXIT STATUS"
+.LP
+.LP
+The following exit values are generally returned by the launcher, typically when the launcher is called with the wrong arguments, serious errors, or exceptions thrown from the Java Virtual Machine. However, a Java application may choose to return any value using the API call \f2System.exit(exitValue)\fP.
+.LP
+.RS 3
+.TP 2
+o
+\f20\fP: Successful completion
+.TP 2
+o
+\f2>0\fP: An error occurred
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+javac(1)
+.TP 2
+o
+jdb(1)
+.TP 2
+o
+javah(1)
+.TP 2
+o
+jar(1)
+.TP 2
+o
+.na
+\f2The Java Extensions Framework\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/extensions/index.html
+.TP 2
+o
+.na
+\f2Security Features\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/index.html.
+.TP 2
+o
+.na
+\f2HotSpot VM Specific Options\fP @
+.fi
+http://java.sun.com/docs/hotspot/VMOptions.html.
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/javac.1 b/jdk/src/bsd/doc/man/javac.1
new file mode 100644
index 0000000..887621f
--- /dev/null
+++ b/jdk/src/bsd/doc/man/javac.1
@@ -0,0 +1,1205 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javac 1 "10 May 2011"
+
+.LP
+.SH "Name"
+javac \- Java programming language compiler
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+        \fP\f3javac\fP [ options ] [ sourcefiles ] [ classes ] [ @argfiles ]
+.fl
+
+.fl
+.fi
+
+.LP
+.LP
+Arguments may be in any order.
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options.
+.TP 3
+sourcefiles
+One or more source files to be compiled (such as MyClass.java).
+.TP 3
+classes
+One or more classes to be processed for annotations (such as MyPackage.MyClass).
+.TP 3
+@argfiles
+One or more files that lists options and source files. The \f2\-J\fP options are not allowed in these files.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3javac\fP tool reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files. It can also process annotations in Java source files and classes.
+.LP
+.LP
+There are two ways to pass source code file names to \f3javac\fP:
+.LP
+.RS 3
+.TP 2
+o
+For a small number of source files, simply list the file names on the command line.
+.TP 2
+o
+For a large number of source files, list the file names in a file, separated by blanks or line breaks. Then use the list file name on the \f3javac\fP command line, preceded by an \f3@\fP character.
+.RE
+
+.LP
+.LP
+Source code file names must have \f2.java\fP suffixes, class file names must have \f2.class\fP suffixes, and both source and class files must have root names that identify the class. For example, a class called \f2MyClass\fP would be written in a source file called \f2MyClass.java\fP and compiled into a bytecode class file called \f2MyClass.class\fP.
+.LP
+.LP
+Inner class definitions produce additional class files. These class files have names combining the inner and outer class names, such as \f2MyClass$MyInnerClass.class\fP.
+.LP
+.LP
+You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in \f3/workspace\fP, the source code for \f2com.mysoft.mypack.MyClass\fP should be in \f3/workspace/com/mysoft/mypack/MyClass.java\fP.
+.LP
+.LP
+By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with \f3\-d\fP (see Options, below).
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+The compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. An additional set of non\-standard options are specific to the current virtual machine and compiler implementations and are subject to change in the future. Non\-standard options begin with \f3\-X\fP.
+.LP
+.SS
+Standard Options
+.LP
+.RS 3
+.TP 3
+\-Akey[=value]
+Options to pass to annotation processors. These are not interpreted by javac directly, but are made available for use by individual processors. \f2key\fP should be one or more identifiers separated by ".".
+.TP 3
+\-cp path or \-classpath path
+Specify where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the \f3CLASSPATH\fP environment variable. If neither \f3CLASSPATH\fP, \f3\-cp\fP nor \f3\-classpath\fP is specified, the user class path consists of the current directory. See Setting the Class Path for more details.
+.br
+.br
+>If the \f3\-sourcepath\fP option is not specified, the user class path is also searched for source files.
+.br
+.br
+If the \f3\-processorpath\fP option is not specified, the class path is also searched for annotation processors.
+.TP 3
+\-Djava.ext.dirs=directories
+Override the location of installed extensions.
+.TP 3
+\-Djava.endorsed.dirs=directories
+Override the location of endorsed standards path.
+.TP 3
+\-d directory
+Set the destination directory for class files. The directory must already exist; \f3javac\fP will not create it. If a class is part of a package, \f3javac\fP puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-d /home/myclasses\fP and the class is called \f2com.mypackage.MyClass\fP, then the class file is called \f2/home/myclasses/com/mypackage/MyClass.class\fP.
+.br
+.br
+If \f3\-d\fP is not specified, \f3javac\fP puts each class files in the same directory as the source file from which it was generated.
+.br
+.br
+\f3Note:\fP The directory specified by \f3\-d\fP is not automatically added to your user class path.
+.TP 3
+\-deprecation
+Show a description of each use or override of a deprecated member or class. Without \f3\-deprecation\fP, \f3javac\fP shows a summary of the source files that use or override deprecated members or classes. \f3\-deprecation\fP is shorthand for \f3\-Xlint:deprecation\fP.
+.TP 3
+\-encoding encoding
+Set the source file encoding name, such as \f2EUC\-JP and UTF\-8\fP. If \f3\-encoding\fP is not specified, the platform default converter is used.
+.TP 3
+\-endorseddirs directories
+Override the location of endorsed standards path.
+.TP 3
+\-extdirs directories
+Overrides the location of the \f2ext\fP directory. The \f2directories\fP variable is a colon\-separated list of directories. Each JAR archive in the specified directories is searched for class files. All JAR archives found are automatically part of the class path.
+.br
+.br
+If you are cross\-compiling (compiling classes against bootstrap and extension classes of a different Java platform implementation), this option specifies the directories that contain the extension classes. See Cross\-Compilation Options for more information.
+.TP 3
+\-g
+Generate all debugging information, including local variables. By default, only line number and source file information is generated.
+.TP 3
+\-g:none
+Do not generate any debugging information.
+.TP 3
+\-g:{keyword list}
+Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
+.RS 3
+.TP 3
+source
+Source file debugging information
+.TP 3
+lines
+Line number debugging information
+.TP 3
+vars
+Local variable debugging information
+.RE
+.TP 3
+\-help
+Print a synopsis of standard options.
+.TP 3
+\-implicit:{class,none}
+Controls the generation of class files for implicitly loaded source files. To automatically generate class files, use \f3\-implicit:class\fP. To suppress class file generation, use \f3\-implicit:none\fP. If this option is not specified, the default is to automatically generate class files. In this case, the compiler will issue a warning if any such class files are generated when also doing annotation processing. The warning will not be issued if this option is set explicitly. See Searching For Types.
+.TP 3
+\-Joption
+Pass \f2option\fP to the \f3java\fP launcher called by \f3javac\fP. For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. It is a common convention for \f3\-J\fP to pass options to the underlying VM executing applications written in Java.
+.br
+.br
+\f3Note:\fP \f3CLASSPATH\fP, \f3\-classpath\fP, \f3\-bootclasspath\fP, and \f3\-extdirs\fP do \f2not\fP specify the classes used to run \f3javac\fP. Fiddling with the implementation of the compiler in this way is usually pointless and always risky. If you do need to do this, use the \f3\-J\fP option to pass through options to the underlying \f3java\fP launcher.
+.TP 3
+\-nowarn
+Disable warning messages. This has the same meaning as \f3\-Xlint:none\fP.
+.TP 3
+\-proc: {none,only}
+Controls whether annotation processing and/or compilation is done. \f3\-proc:none\fP means that compilation takes place without annotation processing. \f3\-proc:only\fP means that only annotation processing is done, without any subsequent compilation.
+.TP 3
+\-processor class1[,class2,class3...]
+Names of the annotation processors to run. This bypasses the default discovery process.
+.TP 3
+\-processorpath path
+Specify where to find annotation processors; if this option is not used, the class path will be searched for processors.
+.TP 3
+\-s dir
+Specify the directory where to place generated source files. The directory must already exist; \f3javac\fP will not create it. If a class is part of a package, the compiler puts the source file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-s /home/mysrc\fP and the class is called \f2com.mypackage.MyClass\fP, then the source file will be placed in \f2/home/mysrc/com/mypackage/MyClass.java\fP.
+.TP 3
+\-source release
+Specifies the version of source code accepted. The following values for \f2release\fP are allowed:
+.RS 3
+.TP 3
+1.3
+The compiler does \f2not\fP support assertions, generics, or other language features introduced after JDK 1.3.
+.TP 3
+1.4
+The compiler accepts code containing assertions, which were introduced in JDK 1.4.
+.TP 3
+1.5
+The compiler accepts code containing generics and other language features introduced in JDK 5.
+.TP 3
+5
+Synonym for 1.5.
+.TP 3
+1.6
+This is the default value. No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors, instead of warnings, as previously.
+.TP 3
+6
+Synonym for 1.6.
+.TP 3
+1.7
+The compiler accepts code with features introduced in JDK 7.
+.TP 3
+7
+Synonym for 1.7.
+.RE
+.TP 3
+\-sourcepath sourcepath
+Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.
+.br
+.br
+\f3Note:\fP Classes found through the class path may be subject to automatic recompilation if their sources are also found. See Searching For Types.
+.TP 3
+\-verbose
+Verbose output. This includes information about each class loaded and each source file compiled.
+.TP 3
+\-version
+Print version information.
+.TP 3
+\-Werror
+Terminate compilation if warnings occur.
+.TP 3
+\-X
+Display information about non\-standard options and exit.
+.RE
+
+.LP
+.SS
+Cross\-Compilation Options
+.LP
+.LP
+By default, classes are compiled against the bootstrap and extension classes of the platform that \f3javac\fP shipped with. But \f3javac\fP also supports \f2cross\-compiling\fP, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use \f3\-bootclasspath\fP and \f3\-extdirs\fP when cross\-compiling; see Cross\-Compilation Example below.
+.LP
+.RS 3
+.TP 3
+\-target version
+Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are \f31.1\fP \f31.2\fP \f31.3\fP \f31.4\fP \f31.5\fP (also \f35\fP) \f31.6\fP (also \f36\fP) and \f31.7\fP (also \f37\fP).
+.br
+.br
+The default for \f3\-target\fP depends on the value of \f3\-source\fP:
+.RS 3
+.TP 2
+o
+If \-source is \f3not specified\fP, the value of \-target is \f31.7\fP
+.TP 2
+o
+If \-source is \f31.2\fP, the value of \-target is \f31.4\fP
+.TP 2
+o
+If \-source is \f31.3\fP, the value of \-target is \f31.4\fP
+.TP 2
+o
+For \f3all other values\fP of \-source, the value of \f3\-target\fP is the value of \f3\-source\fP.
+.RE
+.TP 3
+\-bootclasspath bootclasspath
+Cross\-compile against the specified set of boot classes. As with the user class path, boot class path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives.
+.RE
+
+.LP
+.SS
+Non\-Standard Options
+.LP
+.RS 3
+.TP 3
+\-Xbootclasspath/p:path
+Prepend to the bootstrap class path.
+.TP 3
+\-Xbootclasspath/a:path
+Append to the bootstrap class path.
+.TP 3
+\-Xbootclasspath/:path
+Override location of bootstrap class files.
+.TP 3
+\-Xlint
+Enable all recommended warnings. In this release, enabling all available warnings is recommended.
+.TP 3
+\-Xlint:all
+Enable all recommended warnings. In this release, enabling all available warnings is recommended.
+.TP 3
+\-Xlint:none
+Disable all warnings.
+.TP 3
+\-Xlint:name
+Enable warning \f2name\fP. See the section Warnings That Can Be Enabled or Disabled with \-Xlint Option for a list of warnings you can enable with this option.
+.TP 3
+\-Xlint:\-name
+Disable warning \f2name\fP. See the section Warnings That Can Be Enabled or Disabled with \-Xlint Option for a list of warnings you can disable with this option.
+.TP 3
+\-Xmaxerrs number
+Set the maximum number of errors to print.
+.TP 3
+\-Xmaxwarns number
+Set the maximum number of warnings to print.
+.TP 3
+\-Xstdout filename
+Send compiler messages to the named file. By default, compiler messages go to \f2System.err\fP.
+.TP 3
+\-Xprefer:{newer,source}
+Specify which file to read when both a source file and class file are found for a type. (See Searching For Types). If \f2\-Xprefer:newer\fP is used, it reads the newer of the source or class file for a type (default). If the \f2\-Xprefer:source\fP option is used, it reads source file. Use \f2\-Xprefer:source\fP when you want to be sure that any annotation processors can access annotations declared with a retention policy of \f2SOURCE\fP.
+.TP 3
+\-Xpkginfo:{always,legacy,nonempty}
+Specify handling of package\-info files
+.TP 3
+\-Xprint
+Print out textual representation of specified types for debugging purposes; perform neither annotation processing nor compilation. The format of the output may change.
+.TP 3
+\-XprintProcessorInfo
+Print information about which annotations a processor is asked to process.
+.TP 3
+\-XprintRounds
+Print information about initial and subsequent annotation processing rounds.
+.RE
+
+.LP
+.SS
+Warnings That Can Be Enabled or Disabled with \-Xlint Option
+.LP
+.LP
+Enable warning \f2name\fP with the option \f3\-Xlint:\fP\f2name\fP, where \f2name\fP is one of the following warning names. Similarly, you can disable warning \f2name\fP with the option \f3\-Xlint:\-\fP\f2name\fP:
+.LP
+.RS 3
+.TP 3
+cast
+Warn about unnecessary and redundant casts. For example:
+.nf
+\f3
+.fl
+String s = (String)"Hello!"
+.fl
+\fP
+.fi
+.TP 3
+classfile
+Warn about issues related to classfile contents.
+.TP 3
+deprecation
+Warn about use of deprecated items. For example:
+.nf
+\f3
+.fl
+    java.util.Date myDate = new java.util.Date();
+.fl
+    int currentDay = myDate.getDay();
+.fl
+\fP
+.fi
+The method \f2java.util.Date.getDay\fP has been deprecated since JDK 1.1.
+.TP 3
+dep\-ann
+Warn about items that are documented with an \f2@deprecated\fP Javadoc comment, but do not have a \f2@Deprecated\fP annotation. For example:
+.nf
+\f3
+.fl
+  /**
+.fl
+   * @deprecated As of Java SE 7, replaced by {@link #newMethod()}
+.fl
+   */
+.fl
+
+.fl
+  public static void deprecatedMethood() { }
+.fl
+
+.fl
+  public static void newMethod() { }
+.fl
+\fP
+.fi
+.TP 3
+divzero
+Warn about division by constant integer 0. For example:
+.nf
+\f3
+.fl
+    int divideByZero = 42 / 0;
+.fl
+\fP
+.fi
+.TP 3
+empty
+Warn about empty statements after \f2if\fP statements. For example:
+.nf
+\f3
+.fl
+class E {
+.fl
+    void m() {
+.fl
+        if (true) ;
+.fl
+    }
+.fl
+}
+.fl
+\fP
+.fi
+.TP 3
+fallthrough
+Check \f2switch\fP blocks for fall\-through cases and provide a warning message for any that are found. Fall\-through cases are cases in a \f2switch\fP block, other than the last case in the block, whose code does not include a \f2break\fP statement, allowing code execution to "fall through" from that case to the next case. For example, the code following the \f2case 1\fP label in this \f2switch\fP block does not end with a \f2break\fP statement:
+.nf
+\f3
+.fl
+switch (x) {
+.fl
+case 1:
+.fl
+       System.out.println("1");
+.fl
+       //  No break statement here.
+.fl
+case 2:
+.fl
+       System.out.println("2");
+.fl
+}
+.fl
+\fP
+.fi
+If the \f2\-Xlint:fallthrough\fP flag were used when compiling this code, the compiler would emit a warning about "possible fall\-through into case," along with the line number of the case in question.
+.TP 3
+finally
+Warn about \f2finally\fP clauses that cannot complete normally. For example:
+.nf
+\f3
+.fl
+  public static int m() {
+.fl
+    try {
+.fl
+      throw new NullPointerException();
+.fl
+    } catch (NullPointerException e) {
+.fl
+      System.err.println("Caught NullPointerException.");
+.fl
+      return 1;
+.fl
+    } finally {
+.fl
+      return 0;
+.fl
+    }
+.fl
+  }
+.fl
+\fP
+.fi
+The compiler generates a warning for \f2finally\fP block in this example. When this method is called, it returns a value of \f20\fP, not \f21\fP. A \f2finally\fP block always executes when the \f2try\fP block exits. In this example, if control is transferred to the \f2catch\fP, then the method exits. However, the \f2finally\fP block must be executed, so it is executed, even though control has already been transferred outside the method.
+.TP 3
+options
+Warn about issues relating to the use of command line options. See Cross\-Compilation Example for an example of this kind of warning.
+.TP 3
+overrides
+Warn about issues regarding method overrides. For example, consider the following two classes:
+.nf
+\f3
+.fl
+public class ClassWithVarargsMethod {
+.fl
+  void varargsMethod(String... s) { }
+.fl
+}
+.fl
+\fP
+.fi
+.nf
+\f3
+.fl
+public class ClassWithOverridingMethod extends ClassWithVarargsMethod {
+.fl
+  @Override
+.fl
+  void varargsMethod(String[] s) { }
+.fl
+}
+.fl
+\fP
+.fi
+The compiler generates a warning similar to the following:
+.br
+.br
+\f2warning: [override] varargsMethod(String[]) in ClassWithOverridingMethod overrides varargsMethod(String...) in ClassWithVarargsMethod; overriding method is missing '...'\fP
+.br
+.br
+When the compiler encounters a varargs method, it translates the varargs formal parameter into an array. In the method \f2ClassWithVarargsMethod.varargsMethod\fP, the compiler translates the varargs formal parameter \f2String... s\fP to the formal parameter \f2String[] s\fP, an array, which matches the formal parameter of the method \f2ClassWithOverridingMethod.varargsMethod\fP. Consequently, this example compiles.
+.TP 3
+path
+Warn about invalid path elements and nonexistent path directories on the command line (with regards to the class path, the source path, and other paths). Such warnings cannot be suppressed with the \f2@SuppressWarnings\fP annotation. For example:
+.nf
+\f3
+.fl
+javac \-Xlint:path \-classpath /nonexistentpath Example.java
+.fl
+\fP
+.fi
+.TP 3
+processing
+Warn about issues regarding annotation processing. The compiler generates this warning if you have a class that has an annotation, and you use an annotation processor that cannot handle that type of exception. For example, the following is a simple annotation processor:
+.br
+.br
+\f3Source file \fP\f4AnnoProc.java\fP:
+.nf
+\f3
+.fl
+import java.util.*;
+.fl
+import javax.annotation.processing.*;
+.fl
+import javax.lang.model.*;
+.fl
+import javax.lang.model.element.*;
+.fl
+
+.fl
+@SupportedAnnotationTypes("NotAnno")
+.fl
+public class AnnoProc extends AbstractProcessor {
+.fl
+    public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv) {
+.fl
+        return true;
+.fl
+    }
+.fl
+
+.fl
+    public SourceVersion getSupportedSourceVersion() {
+.fl
+        return SourceVersion.latest();
+.fl
+    }
+.fl
+}
+.fl
+\fP
+.fi
+\f3Source file \fP\f4AnnosWithoutProcessors.java\fP\f3:\fP
+.nf
+\f3
+.fl
+@interface Anno { }
+.fl
+
+.fl
+@Anno
+.fl
+class AnnosWithoutProcessors { }
+.fl
+\fP
+.fi
+The following commands compile the annotation processor \f2AnnoProc\fP, then run this annotation processor against the source file \f2AnnosWithoutProcessors.java\fP:
+.nf
+\f3
+.fl
+% javac AnnoProc.java
+.fl
+% javac \-cp . \-Xlint:processing \-processor AnnoProc \-proc:only AnnosWithoutProcessors.java
+.fl
+\fP
+.fi
+When the compiler runs the annotation processor against the source file \f2AnnosWithoutProcessors.java\fP, it generates the following warning:
+.br
+.br
+\f2warning: [processing] No processor claimed any of these annotations: Anno\fP
+.br
+.br
+To resolve this issue, you can rename the annotation defined and used in the class \f2AnnosWithoutProcessors\fP from \f2Anno\fP to \f2NotAnno\fP.
+.TP 3
+rawtypes
+Warn about unchecked operations on raw types. The following statement generates a \f2rawtypes\fP warning:
+.nf
+\f3
+.fl
+void countElements(List l) { ... }
+.fl
+\fP
+.fi
+The following does not generate a \f2rawtypes\fP warning:
+.nf
+\f3
+.fl
+void countElements(List<?> l) { ... }
+.fl
+\fP
+.fi
+\f2List\fP is a raw type. However, \f2List<?>\fP is a unbounded wildcard parameterized type. Because \f2List\fP is a parameterized interface, you should always specify its type argument. In this example, the \f2List\fP formal argument is specified with a unbounded wildcard (\f2?\fP) as its formal type parameter, which means that the \f2countElements\fP method can accept any instantiation of the \f2List\fP interface.
+.TP 3
+serial
+Warn about missing \f2serialVersionUID\fP definitions on serializable classes. For example:
+.nf
+\f3
+.fl
+public class PersistentTime implements Serializable
+.fl
+{
+.fl
+  private Date time;
+.fl
+
+.fl
+   public PersistentTime() {
+.fl
+     time = Calendar.getInstance().getTime();
+.fl
+   }
+.fl
+
+.fl
+   public Date getTime() {
+.fl
+     return time;
+.fl
+   }
+.fl
+}
+.fl
+\fP
+.fi
+The compiler generates the following warning:
+.br
+.br
+\f2warning: [serial] serializable class PersistentTime has no definition of serialVersionUID\fP
+.br
+.br
+If a serializable class does not explicitly declare a field named \f2serialVersionUID\fP, then the serialization runtime will calculate a default \f2serialVersionUID\fP value for that class based on various aspects of the class, as described in the Java Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declare \f2serialVersionUID\fP values because the default process of computing \f2serialVersionUID\fP vales is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected \f2InvalidClassExceptions\fP during deserialization. Therefore, to guarantee a consistent \f2serialVersionUID\fP value across different Java compiler implementations, a serializable class must declare an explicit \f2serialVersionUID\fP value.
+.TP 3
+static
+Warn about issues relating to use of statics. For example:
+.nf
+\f3
+.fl
+class XLintStatic {
+.fl
+    static void m1() { }
+.fl
+    void m2() { this.m1(); }
+.fl
+}
+.fl
+\fP
+.fi
+The compiler generates the following warning:
+.nf
+\f3
+.fl
+warning: [static] static method should be qualified by type name, XLintStatic, instead of by an expression
+.fl
+\fP
+.fi
+To resolve this issue, you can call the static method \f2m1\fP as follows:
+.nf
+\f3
+.fl
+XLintStatic.m1();
+.fl
+\fP
+.fi
+Alternatively, you can remove the \f2static\fP keyword from the declaration of the method \f2m1\fP.
+.TP 3
+try
+Warn about issues relating to use of \f2try\fP blocks, including try\-with\-resources statements. For example, a warning is generated for the following statement because the resource \f2ac\fP declared in the \f2try\fP statement is not used:
+.nf
+\f3
+.fl
+try ( AutoCloseable ac = getResource() ) {
+.fl
+    // do nothing
+.fl
+}
+.fl
+\fP
+.fi
+.TP 3
+unchecked
+Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification. For example:
+.nf
+\f3
+.fl
+    List l = new ArrayList<Number>();
+.fl
+    List<String> ls = l;       // unchecked warning
+.fl
+\fP
+.fi
+During type erasure, the types \f2ArrayList<Number>\fP and \f2List<String>\fP become \f2ArrayList\fP and \f2List\fP, respectively.
+.br
+.br
+The variable \f2ls\fP has the parameterized type \f2List<String>\fP. When the \f2List\fP referenced by \f2l\fP is assigned to \f2ls\fP, the compiler generates an unchecked warning; the compiler is unable to determine at compile time, and moreover knows that the JVM will not be able to determine at runtime, if \f2l\fP refers to a \f2List<String>\fP type; it does not. Consequently, heap pollution occurs.
+.br
+.br
+In detail, a heap pollution situation occurs when the \f2List\fP object \f2l\fP, whose static type is \f2List<Number>\fP, is assigned to another \f2List\fP object, \f2ls\fP, that has a different static type, \f2List<String>\fP. However, the compiler still allows this assignment. It must allow this assignment to preserve backwards compatibility with versions of Java SE that do not support generics. Because of type erasure, \f2List<Number>\fP and \f2List<String>\fP both become \f2List\fP. Consequently, the compiler allows the assignment of the object \f2l\fP, which has a raw type of \f2List\fP, to the object \f2ls\fP.
+.TP 3
+varargs
+Warn about unsafe usages of variable arguments (varargs) methods, in particular, those that contain non\-reifiable arguments. For example:
+.nf
+\f3
+.fl
+public class ArrayBuilder {
+.fl
+  public static <T> void addToList (List<T> listArg, T... elements) {
+.fl
+    for (T x : elements) {
+.fl
+      listArg.add(x);
+.fl
+    }
+.fl
+  }
+.fl
+}
+.fl
+\fP
+.fi
+The compiler generates the following warning for the definition of the method \f2ArrayBuilder.addToList\fP:
+.nf
+\f3
+.fl
+warning: [varargs] Possible heap pollution from parameterized vararg type T
+.fl
+\fP
+.fi
+When the compiler encounters a varargs method, it translates the varargs formal parameter into an array. However, the Java programming language does not permit the creation of arrays of parameterized types. In the method \f2ArrayBuilder.addToList\fP, the compiler translates the varargs formal parameter \f2T... elements\fP to the formal parameter \f2T[] elements\fP, an array. However, because of type erasure, the compiler converts the varargs formal parameter to \f2Object[] elements\fP. Consequently, there is a possibility of heap pollution.
+.RE
+
+.LP
+.SH "COMMAND LINE ARGUMENT FILES"
+.LP
+.LP
+To shorten or simplify the javac command line, you can specify one or more files that themselves contain arguments to the \f2javac\fP command (except \f2\-J\fP options). This enables you to create javac commands of any length on any operating system.
+.LP
+.LP
+An argument file can include javac options and source filenames in any combination. The arguments within a file can be space\-separated or newline\-separated. If a filename contains embedded spaces, put the whole filename in double quotes.
+.LP
+.LP
+Filenames within an argument file are relative to the current directory, not the location of the argument file. Wildcards (*) are not allowed in these lists (such as for specifying \f2*.java\fP). Use of the '\f2@\fP' character to recursively interpret files is not supported. The \f2\-J\fP options are not supported because they are passed to the launcher, which does not support argument files.
+.LP
+.LP
+When executing javac, pass in the path and name of each argument file with the '\f2@\fP' leading character. When javac encounters an argument beginning with the character `\f2@\fP', it expands the contents of that file into the argument list.
+.LP
+.SS
+Example \- Single Arg File
+.LP
+.LP
+You could use a single argument file named "\f2argfile\fP" to hold all javac arguments:
+.LP
+.nf
+\f3
+.fl
+% \fP\f3javac @argfile\fP
+.fl
+.fi
+
+.LP
+.LP
+This argument file could contain the contents of both files shown in the next example.
+.LP
+.SS
+Example \- Two Arg Files
+.LP
+.LP
+You can create two argument files \-\- one for the javac options and the other for the source filenames: (Notice the following lists have no line\-continuation characters.)
+.LP
+.LP
+Create a file named "\f2options\fP" containing:
+.LP
+.nf
+\f3
+.fl
+     \-d classes
+.fl
+     \-g
+.fl
+     \-sourcepath /java/pubs/ws/1.3/src/share/classes
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Create a file named "\f2classes\fP" containing:
+.LP
+.nf
+\f3
+.fl
+     MyClass1.java
+.fl
+     MyClass2.java
+.fl
+     MyClass3.java
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+.LP
+You would then run \f3javac\fP with:
+.LP
+.nf
+\f3
+.fl
+  % \fP\f3javac @options @classes\fP
+.fl
+
+.fl
+.fi
+
+.LP
+.SS
+Example \- Arg Files with Paths
+.LP
+.LP
+The argument files can have paths, but any filenames inside the files are relative to the current working directory (not \f2path1\fP or \f2path2\fP):
+.LP
+.nf
+\f3
+.fl
+% \fP\f3javac @path1/options @path2/classes\fP
+.fl
+.fi
+
+.LP
+.SH "ANNOTATION PROCESSING"
+.LP
+.LP
+\f3javac\fP provides direct support for annotation processing, superseding the need for the separate annotation processing tool, \f3apt\fP.
+.LP
+.LP
+The API for annotation processors is defined in the \f2javax.annotation.processing\fP and \f2javax.lang.model\fP packages and subpackages.
+.LP
+.SS
+Overview of annotation processing
+.LP
+.LP
+Unless annotation processing is disabled with the \f3\-proc:none\fP option, the compiler searches for any annotation processors that are available. The search path can be specified with the \f3\-processorpath\fP option; if it is not given, the user class path is used. Processors are located by means of service provider\-configuration files named \f2META\-INF/services/javax.annotation.processing.Processor\fP on the search path. Such files should contain the names of any annotation processors to be used, listed one per line. Alternatively, processors can be specified explicitly, using the \f3\-processor\fP option.
+.LP
+.LP
+After scanning the source files and classes on the command line to determine what annotations are present, the compiler queries the processors to determine what annotations they process. When a match is found, the processor will be invoked. A processor may "claim" the annotations it processes, in which case no further attempt is made to find any processors for those annotations. Once all annotations have been claimed, the compiler does not look for additional processors.
+.LP
+.LP
+If any processors generate any new source files, another round of annotation processing will occur: any newly generated source files will be scanned, and the annotations processed as before. Any processors invoked on previous rounds will also be invoked on all subsequent rounds. This continues until no new source files are generated.
+.LP
+.LP
+After a round occurs where no new source files are generated, the annotation processors will be invoked one last time, to give them a chance to complete any work they may need to do. Finally, unless the \f3\-proc:only\fP option is used, the compiler will compile the original and all the generated source files.
+.LP
+.SS
+Implicitly loaded source files
+.LP
+.LP
+To compile a set of source files, the compiler may need to implicitly load additional source files. (See Searching For Types). Such files are currently not subject to annotation processing. By default, the compiler will give a warning if annotation processing has occurred and any implicitly loaded source files are compiled. See the \-implicit option for ways to suppress the warning.
+.LP
+.SH "SEARCHING FOR TYPES"
+.LP
+.LP
+When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance.
+.LP
+.LP
+For example, when you subclass \f3java.applet.Applet\fP, you are also using \f3Applet's\fP ancestor classes: \f3java.awt.Panel\fP, \f3java.awt.Container\fP, \f3java.awt.Component\fP, and \f3java.lang.Object\fP.
+.LP
+.LP
+When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the \f3CLASSPATH\fP environment variable or by using the \f3\-classpath\fP command line option. (For details, see Setting the Class Path).
+.LP
+.LP
+If you set the \-sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path for both class files and source files.
+.LP
+.LP
+You can specify different bootstrap or extension classes with the \f3\-bootclasspath\fP and \f3\-extdirs\fP options; see Cross\-Compilation Options below.
+.LP
+.LP
+A successful type search may produce a class file, a source file, or both. If both are found, you can use the \-Xprefer option to instruct the compiler which to use. If \f3newer\fP is given, the compiler will use the newer of the two files. If \f3source\fP is given, it will use the source file. The default is \f3newer\fP.
+.LP
+.LP
+If a type search finds a source file for a required type, either by itself, or as a result of the setting for \f3\-Xprefer\fP, the compiler will read the source file to get the information it needs. In addition, it will by default compile the source file as well. You can use the \-implicit option to specify the behavior. If \f3none\fP is given, no class files will be generated for the source file. If \f3class\fP is given, class files will be generated for the source file.
+.LP
+.LP
+The compiler may not discover the need for some type information until after annotation processing is complete. If the type information is found in a source file and no \f3\-implicit\fP option is given, the compiler will give a warning that the file is being compiled without being subject to annotation processing. To disable the warning, either specify the file on the command line (so that it will be subject to annotation processing) or use the \f3\-implicit\fP option to specify whether or not class files should be generated for such source files.
+.LP
+.SH "PROGRAMMATIC INTERFACE"
+.LP
+.LP
+\f3javac\fP supports the new Java Compiler API defined by the classes and interfaces in the \f2javax.tools\fP package.
+.LP
+.SS
+Example
+.LP
+.LP
+To perform a compilation using arguments as you would give on the command line, you can use the following:
+.LP
+.nf
+\f3
+.fl
+JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
+.fl
+int rc = javac.run(null, null, null, args);
+.fl
+\fP
+.fi
+
+.LP
+.LP
+This will write any diagnostics to the standard output stream, and return the exit code that \f3javac\fP would give when invoked from the command line.
+.LP
+.LP
+You can use other methods on the \f2javax.tools.JavaCompiler\fP interface to handle diagnostics, control where files are read from and written to, and so on.
+.LP
+.SS
+Old Interface
+.LP
+.LP
+\f3Note:\fP This API is retained for backwards compatibility only; all new code should use the Java Compiler API, described above.
+.LP
+.LP
+The \f2com.sun.tools.javac.Main\fP class provides two static methods to invoke the compiler from a program:
+.LP
+.nf
+\f3
+.fl
+public static int compile(String[] args);
+.fl
+public static int compile(String[] args, PrintWriter out);
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The \f2args\fP parameter represents any of the command line arguments that would normally be passed to the javac program and are outlined in the above Synopsis section.
+.LP
+.LP
+The \f2out\fP parameter indicates where the compiler's diagnostic output is directed.
+.LP
+.LP
+The return value is equivalent to the exit value from \f3javac\fP.
+.LP
+.LP
+Note that all \f3other\fP classes and methods found in a package whose name starts with \f2com.sun.tools.javac\fP (informally known as sub\-packages of \f2com.sun.tools.javac\fP) are strictly internal and subject to change at any time.
+.LP
+.SH "EXAMPLES"
+.LP
+.SS
+Compiling a Simple Program
+.LP
+.LP
+One source file, \f2Hello.java\fP, defines a class called \f3greetings.Hello\fP. The \f2greetings\fP directory is the package directory both for the source file and the class file and is off the current directory. This allows us to use the default user class path. It also makes it unnecessary to specify a separate destination directory with \f3\-d\fP.
+.LP
+.nf
+\f3
+.fl
+% \fP\f3ls\fP
+.fl
+greetings/
+.fl
+% \f3ls greetings\fP
+.fl
+Hello.java
+.fl
+% \f3cat greetings/Hello.java\fP
+.fl
+package greetings;
+.fl
+
+.fl
+public class Hello {
+.fl
+    public static void main(String[] args) {
+.fl
+        for (int i=0; i < args.length; i++) {
+.fl
+            System.out.println("Hello " + args[i]);
+.fl
+        }
+.fl
+    }
+.fl
+}
+.fl
+% \f3javac greetings/Hello.java\fP
+.fl
+% \f3ls greetings\fP
+.fl
+Hello.class   Hello.java
+.fl
+% \f3java greetings.Hello World Universe Everyone\fP
+.fl
+Hello World
+.fl
+Hello Universe
+.fl
+Hello Everyone
+.fl
+.fi
+
+.LP
+.SS
+Compiling Multiple Source Files
+.LP
+.LP
+This example compiles all the source files in the package \f2greetings\fP.
+.LP
+.nf
+\f3
+.fl
+% \fP\f3ls\fP
+.fl
+greetings/
+.fl
+% \f3ls greetings\fP
+.fl
+Aloha.java         GutenTag.java      Hello.java         Hi.java
+.fl
+% \f3javac greetings/*.java\fP
+.fl
+% \f3ls greetings\fP
+.fl
+Aloha.class         GutenTag.class      Hello.class         Hi.class
+.fl
+Aloha.java          GutenTag.java       Hello.java          Hi.java
+.fl
+.fi
+
+.LP
+.SS
+Specifying a User Class Path
+.LP
+.LP
+Having changed one of the source files in the previous example, we recompile it:
+.LP
+.nf
+\f3
+.fl
+% \fP\f3pwd\fP
+.fl
+/examples
+.fl
+% \f3javac greetings/Hi.java\fP
+.fl
+.fi
+
+.LP
+.LP
+Since \f2greetings.Hi\fP refers to other classes in the \f2greetings\fP package, the compiler needs to find these other classes. The example above works, because our default user class path happens to be the directory containing the package directory. But suppose we want to recompile this file and not worry about which directory we're in? Then we need to add \f2/examples\fP to the user class path. We can do this by setting \f3CLASSPATH\fP, but here we'll use the \f3\-classpath\fP option.
+.LP
+.nf
+\f3
+.fl
+% \fP\f3javac \-classpath /examples /examples/greetings/Hi.java\fP
+.fl
+.fi
+
+.LP
+.LP
+If we change \f2greetings.Hi\fP again, to use a banner utility, that utility also needs to be accessible through the user class path.
+.LP
+.nf
+\f3
+.fl
+% \fP\f3javac \-classpath /examples:/lib/Banners.jar \\
+.fl
+            /examples/greetings/Hi.java\fP
+.fl
+.fi
+
+.LP
+.LP
+To execute a class in \f2greetings\fP, we need access both to \f2greetings\fP and to the classes it uses.
+.LP
+.nf
+\f3
+.fl
+% \fP\f3java \-classpath /examples:/lib/Banners.jar greetings.Hi\fP
+.fl
+.fi
+
+.LP
+.SS
+Separating Source Files and Class Files
+.LP
+.LP
+It often makes sense to keep source files and class files in separate directories, especially on large projects. We use \f3\-d\fP to indicate the separate class file destination. Since the source files are not in the user class path, we use \f3\-sourcepath\fP to help the compiler find them.
+.LP
+.nf
+\f3
+.fl
+% \fP\f3ls\fP
+.fl
+classes/  lib/      src/
+.fl
+% \f3ls src\fP
+.fl
+farewells/
+.fl
+% \f3ls src/farewells\fP
+.fl
+Base.java      GoodBye.java
+.fl
+% \f3ls lib\fP
+.fl
+Banners.jar
+.fl
+% \f3ls classes\fP
+.fl
+% \f3javac \-sourcepath src \-classpath classes:lib/Banners.jar \\
+.fl
+            src/farewells/GoodBye.java \-d classes\fP
+.fl
+% \f3ls classes\fP
+.fl
+farewells/
+.fl
+% \f3ls classes/farewells\fP
+.fl
+Base.class      GoodBye.class
+.fl
+.fi
+
+.LP
+.LP
+\f3Note:\fP The compiler compiled \f2src/farewells/Base.java\fP, even though we didn't specify it on the command line. To trace automatic compiles, use the \f3\-verbose\fP option.
+.LP
+.SS
+Cross\-Compilation Example
+.LP
+.LP
+Here we use \f3javac\fP to compile code that will run on a 1.6 VM.
+.LP
+.nf
+\f3
+.fl
+% \fP\f3javac \-source 1.6 \-target 1.6 \-bootclasspath jdk1.6.0/lib/rt.jar \\
+.fl
+            \-extdirs "" OldCode.java\fP
+.fl
+.fi
+
+.LP
+.LP
+The \f2\-source 1.6\fP option specifies that version 1.6 (or 6) of the Java programming language be used to compile \f2OldCode.java\fP. The option \f3\-target 1.6\fP option ensures that the generated class files will be compatible with 1.6 VMs. Note that in most cases, the value of the \f3\-target\fP option is the value of the \f3\-source\fP option; in this example, you can omit the \f3\-target\fP option.
+.LP
+.LP
+You must specify the \f3\-bootclasspath\fP option to specify the correct version of the bootstrap classes (the \f2rt.jar\fP library). If not, the compiler generates a warning:
+.LP
+.nf
+\f3
+.fl
+% \fP\f3javac \-source 1.6 OldCode.java\fP
+.fl
+warning: [options] bootstrap class path not set in conjunction with \-source 1.6
+.fl
+.fi
+
+.LP
+.LP
+If you do not specify the correct version of bootstrap classes, the compiler will use the old language rules (in this example, it will use version 1.6 of the Java programming language) combined with the new bootstrap classes, which can result in class files that do not work on the older platform (in this case, Java SE 6) because reference to non\-existent methods can get included.
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+.na
+\f2The javac Guide\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/javac/index.html
+.TP 2
+o
+java(1) \- the Java Application Launcher
+.TP 2
+o
+jdb(1) \- Java Application Debugger
+.TP 2
+o
+javah(1) \- C Header and Stub File Generator
+.TP 2
+o
+javap(1) \- Class File Disassembler
+.TP 2
+o
+javadoc(1) \- API Documentation Generator
+.TP 2
+o
+jar(1) \- JAR Archive Tool
+.TP 2
+o
+.na
+\f2The Java Extensions Framework\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/extensions/index.html
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/javadoc.1 b/jdk/src/bsd/doc/man/javadoc.1
new file mode 100644
index 0000000..7ccc12b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/javadoc.1
@@ -0,0 +1,4226 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javadoc 1 "10 May 2011"
+.SH "Name"
+javadoc \- The Java API Documentation Generator
+.LP
+Generates HTML pages of API documentation from Java source files. This document contains Javadoc examples for Solaris.
+.SH "SYNOPSIS"
+.LP
+\f4javadoc\fP\f2\ [\ \fP\f2options\fP\f2\ ]\ [\ packagenames\ ]\ [\ sourcefilenames\ ]\ [\ \-subpackages\fP\ \f2pkg1:pkg2:...\fP\f2\ ]\ [\ \fP\f2@argfiles\fP\f2\ ]\fP
+.LP
+Arguments can be in any order. See processing of Source Files for details on how the Javadoc tool determines which "\f2.java\fP" files to process.
+.RS 3
+.TP 3
+options
+Command\-line options, as specified in this document. To see a typical use of javadoc options, see Real\-World Example.
+.TP 3
+packagenames
+A series of names of packages, separated by spaces, such as \f2java.lang\ java.lang.reflect\ java.awt\fP. You must separately specify each package you want to document. Wildcards are not allowed; use \-subpackages for recursion. The Javadoc tool uses \f2\-sourcepath\fP to look for these package names. See Example \- Documenting One or More Packages
+.TP 3
+sourcefilenames
+A series of source file names, separated by spaces, each of which can begin with a path and contain a wildcard such as asterisk (*). The Javadoc tool will process every file whose name ends with ".java", and whose name, when stripped of that suffix, is actually a legal class name (see the Java Language Specification). Therefore, you can name files with dashes (such as \f2X\-Buffer\fP), or other illegal characters, to prevent them from being documented. This is useful for test files and template files The path that precedes the source file name determines where javadoc will look for the file. (The Javadoc tool does \f2not\fP use \f2\-sourcepath\fP to look for these source file names.) Relative paths are relative to the current directory, so passing in \f2Button.java\fP is identical to \f2./Button.java\fP. A source file name with an absolute path and a wildcard, for example, is \f2/home/src/java/awt/Graphics*.java\fP. See Example\ \-\ Documenting One or More Classes. You can also mix packagenames and sourcefilenames, as in Example\ \-\ Documenting Both Packages and Classes
+.TP 3
+\-subpackages pkg1:pkg2:...
+Generates documentation from source files in the specified packages and recursively in their subpackages. An alternative to supplying packagenames or sourcefilenames.
+.TP 3
+@argfiles
+One or more files that contain a list of Javadoc options, packagenames and sourcefilenames in any order. Wildcards (*) and \f2\-J\fP options are not allowed in these files.
+.RE
+.SH "DESCRIPTION"
+.LP
+The \f3Javadoc\fP tool parses the declarations and documentation comments in a set of Java source files and produces a corresponding set of HTML pages describing (by default) the public and protected classes, nested classes (but not anonymous inner classes), interfaces, constructors, methods, and fields. You can use it to generate the API (Application Programming Interface) documentation or the implementation documentation for a set of source files.
+.LP
+You can run the Javadoc tool on entire packages, individual source files, or both. When documenting entire packages, you can either use \f2\-subpackages\fP for traversing recursively down from a top\-level directory, or pass in an explicit list of package names. When documenting individual source files, you pass in a list of source (\f2.java\fP) filenames. Examples are given at the end of this document. How Javadoc processes source files is covered next.
+.SS
+Processing of source files
+.LP
+The Javadoc tool processes files that end in "\f2.java\fP" plus other files described under Source Files. If you run the Javadoc tool by explicitly passing in individual source filenames, you can determine exactly which "\f2.java\fP" files are processed. However, that is not how most developers want to work, as it is simpler to pass in package names. The Javadoc tool can be run three ways without explicitly specifying the source filenames. You can (1) pass in package names, (2) use \f2\-subpackages\fP, and (3) use wildcards with source filenames (\f2*.java\fP). In these cases, the Javadoc tool processes a "\f2.java\fP" file only if it fulfills all of the following requirements:
+.RS 3
+.TP 2
+o
+Its name, after stripping off the "\f2.java\fP" suffix, is actually a legal class name (see the Java Language Specification for legal characters)
+.TP 2
+o
+Its directory path relative to the root of the source tree is actually a legal package name (after converting its separators to dots)
+.TP 2
+o
+Its package statement contains the legal package name (specified in the previous bullet)
+.RE
+.LP
+\f3Processing of links\fP \- During a run, the Javadoc tool automatically adds cross\-reference links to package, class and member names that are being documented as part of that run. Links appear in several places:
+.RS 3
+.TP 2
+o
+Declarations (return types, argument types, field types)
+.TP 2
+o
+"See Also" sections generated from \f2@see\fP tags
+.TP 2
+o
+In\-line text generated from \f2{@link}\fP tags
+.TP 2
+o
+Exception names generated from \f2@throws\fP tags
+.TP 2
+o
+"Specified by" links to members in interfaces and "Overrides" links to members in classes
+.TP 2
+o
+Summary tables listing packages, classes and members
+.TP 2
+o
+Package and class inheritance trees
+.TP 2
+o
+The index
+.RE
+.LP
+You can add hyperlinks to existing text for classes not included on the command line (but generated separately) by way of the \f2\-link\fP and \f2\-linkoffline\fP options.
+.LP
+\f3Other processing details\fP \- The Javadoc tool produces one complete document each time it is run; it cannot do incremental builds \-\- that is, it cannot modify or \f2directly\fP incorporate results from previous runs of the Javadoc tool. However, it can link to results from other runs, as just mentioned.
+.LP
+As implemented, the Javadoc tool requires and relies on the java compiler to do its job. The Javadoc tool calls part of \f2javac\fP to compile the declarations, ignoring the member implementation. It builds a rich internal representation of the classes, including the class hierarchy, and "use" relationships, then generates the HTML from that. The Javadoc tool also picks up user\-supplied documentation from documentation comments in the source code.
+.LP
+In fact, the Javadoc tool will run on \f2.java\fP source files that are pure stub files with no method bodies. This means you can write documentation comments and run the Javadoc tool in the earliest stages of design while creating the API, before writing the implementation.
+.LP
+Relying on the compiler ensures that the HTML output corresponds exactly with the actual implementation, which may rely on implicit, rather than explicit, source code. For example, the Javadoc tool documents default constructors (see Java Language Specification) that are present in the \f2.class\fP files but not in the source code.
+.LP
+In many cases, the Javadoc tool allows you to generate documentation for source files whose code is incomplete or erroneous. This is a benefit that enables you to generate documentation before all debugging and troubleshooting is done. For example, according to the \f2Java Language Specification\fP, a class that contains an abstract method should itself be declared abstract. The Javadoc tool does not check for this, and would proceed without a warning, whereas the javac compiler stops on this error. The Javadoc tool does do some primitive checking of doc comments. Use the DocCheck doclet to check the doc comments more thoroughly.
+.LP
+When the Javadoc tool builds its internal structure for the documentation, it loads all referenced classes. Because of this, the Javadoc tool must be able to find all referenced classes, whether bootstrap classes, extensions, or user classes. For more about this, see
+.na
+\f2How Classes Are Found\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/findingclasses.html. Generally speaking, classes you create must either be loaded as an extension or in the Javadoc tool's class path.
+.SS
+Javadoc Doclets
+.LP
+You can customize the content and format of the Javadoc tool's output by using doclets. The Javadoc tool has a default "built\-in" doclet, called the standard doclet, that generates HTML\-formatted API documentation. You can modify or subclass the standard doclet, or write your own doclet to generate HTML, XML, MIF, RTF or whatever output format you'd like. Information about doclets and their use is at the following locations:
+.RS 3
+.TP 2
+o
+.na
+\f2Javadoc Doclets\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/javadoc/index.html
+.TP 2
+o
+The \f2\-doclet\fP command\-line option
+.RE
+.LP
+When a custom doclet is not specified with the \f2\-doclet\fP command line option, the Javadoc tool will use the default standard doclet. The javadoc tool has several command line options that are available regardless of which doclet is being used. The standard doclet adds a supplementary set of command line options. Both sets of options are described below in the options section.
+.SS
+Related Documentation and Doclets
+.RS 3
+.TP 2
+o
+.na
+\f2Javadoc Enhancements\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/javadoc/index.html for details about improvements added in Javadoc.
+.TP 2
+o
+.na
+\f2Javadoc FAQ\fP @
+.fi
+http://java.sun.com/j2se/javadoc/faq/index.html for answers to common questions, information about Javadoc\-related tools, and workarounds for bugs.
+.TP 2
+o
+.na
+\f2How to Write Doc Comments for Javadoc\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html for more information about Sun conventions for writing documentation comments.
+.TP 2
+o
+.na
+\f2Requirements for Writing API Specifications\fP @
+.fi
+http://java.sun.com/j2se/javadoc/writingapispecs/index.html \- Standard requirements used when writing the Java SE Platform Specification. It can be useful whether you are writing API specifications in source file documentation comments or in other formats. It covers requirements for packages, classes, interfaces, fields and methods to satisfy testable assertions.
+.TP 2
+o
+.na
+\f2Documentation Comment Specification\fP @
+.fi
+http://java.sun.com/docs/books/jls/first_edition/html/18.doc.html \- The original specification on documentation comments, Chapter 18, Documentation Comments, in the \f2Java Language Specification\fP, First Edition, by James Gosling, Bill Joy, and Guy Steele. (This chapter was removed from the second edition.)
+.TP 2
+o
+.na
+\f2DocCheck Doclet\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-141437.html \- Checks doc comments in source files and generates a report listing the errors and irregularities it finds. It is part of the Doc Check Utilities.
+.TP 2
+o
+.na
+\f2MIF Doclet\fP @
+.fi
+http://java.sun.com/j2se/javadoc/mifdoclet/ \- Can automate the generation of API documentation in MIF, FrameMaker and PDF formats. MIF is Adobe FrameMaker's interchange format.
+.RE
+.SS
+Terminology
+.LP
+The terms \f2documentation comment\fP, \f2doc comment\fP, \f2main description\fP, \f2tag\fP, \f2block tag\fP, and \f2in\-line tag\fP are described at Documentation Comments. These other terms have specific meanings within the context of the Javadoc tool:
+.RS 3
+.TP 3
+generated document
+The document generated by the javadoc tool from the doc comments in Java source code. The default generated document is in HTML and is created by the standard doclet.
+.LP
+.TP 3
+name
+A name of a program element written in the Java Language \-\- that is, the name of a package, class, interface, field, constructor or method. A name can be fully\-qualified, such as \f2java.lang.String.equals(java.lang.Object)\fP, or partially\-qualified, such as \f2equals(Object)\fP.
+.LP
+.TP 3
+documented classes
+The classes and interfaces for which detailed documentation is generated during a javadoc run. To be documented, the source files must be available, their source filenames or package names must be passed into the javadoc command, and they must not be filtered out by their access modifier (public, protected, package\-private or private). We also refer to these as the classes included in the javadoc output, or the \f2included classes\fP.
+.LP
+.TP 3
+included classes
+Classes and interfaces whose details are documented during a run of the Javadoc tool. Same as \f2documented classes\fP.
+.LP
+.TP 3
+excluded classes
+Classes and interfaces whose details are \f2not\fP documented during a run of the Javadoc tool.
+.LP
+.TP 3
+referenced classes
+The classes and interfaces that are explicitly referred to in the definition (implementation) or doc comments of the documented classes and interfaces. Examples of references include return type, parameter type, cast type, extended class, implemented interface, imported classes, classes used in method bodies, @see, {@link}, {@linkplain}, and {@inheritDoc} tags. (Notice this definition has changed since
+.na
+\f21.3\fP @
+.fi
+http://download.oracle.com/javase/1.3/docs/tooldocs/solaris/javadoc.html#referencedclasses.) When the Javadoc tool is run, it should load into memory all of the referenced classes in javadoc's bootclasspath and classpath. (The Javadoc tool prints a "Class not found" warning for referenced classes not found.) The Javadoc tool can derive enough information from the .class files to determine their existence and the fully\-qualified names of their members.
+.LP
+.TP 3
+external referenced classes
+The referenced classes whose documentation is not being generated during a javadoc run. In other words, these classes are not passed into the Javadoc tool on the command line. Links in the generated documentation to those classes are said to be \f2external references\fP or \f2external links\fP. For example, if you run the Javadoc tool on only the \f2java.awt\fP package, then any class in \f2java.lang\fP, such as \f2Object\fP, is an external referenced class. External referenced classes can be linked to using the \f2\-link\fP and \f2\-linkoffline\fP options. An important property of an external referenced class is that its source comments are normally not available to the Javadoc run. In this case, these comments cannot be inherited.
+.RE
+.SH "SOURCE FILES"
+.LP
+The Javadoc tool will generate output originating from four different types of "source" files: Java language source files for classes (\f2.java\fP), package comment files, overview comment files, and miscellaneous unprocessed files. This section also covers test files and template files that can also be in the source tree, but which you want to be sure not to document.
+.SS
+Class Source Code Files
+.LP
+Each class or interface and its members can have their own documentation comments, contained in a \f2.java\fP file. For more details about these doc comments, see Documentation Comments.
+.SS
+Package Comment Files
+.LP
+Each package can have its own documentation comment, contained in its own "source" file, that the Javadoc tool will merge into the package summary page that it generates. You typically include in this comment any documentation that applies to the entire package.
+.LP
+To create a package comment file, you have a choice of two files to place your comments:
+.RS 3
+.TP 2
+o
+\f2package\-info.java\fP \- Can contain a package declaration, package annotations, package comments and Javadoc tags. This file is generally preferred over package.html.
+.TP 2
+o
+\f2package.html\fP \- Can contain only package comments and Javadoc tags, no package annotations.
+.RE
+.LP
+A package may have a single \f2package.html\fP file or a single \f2package\-info.java\fP file but not both. Place either file in the package directory in the source tree along with your \f2.java\fP files.
+.LP
+\f4package\-info.java\fP \- This file can contain a package comment of the following structure \-\- the comment is placed before the package declaration:
+.LP
+File: \f2java/applet/package\-info.java\fP
+.nf
+\f3
+.fl
+/**
+.fl
+ * Provides the classes necessary to create an
+.fl
+ * applet and the classes an applet uses
+.fl
+ * to communicate with its applet context.
+.fl
+ * <p>
+.fl
+ * The applet framework involves two entities:
+.fl
+ * the applet and the applet context.
+.fl
+ * An applet is an embeddable window (see the
+.fl
+ * {@link java.awt.Panel} class) with a few extra
+.fl
+ * methods that the applet context can use to
+.fl
+ * initialize, start, and stop the applet.
+.fl
+ *
+.fl
+ * @since 1.0
+.fl
+ * @see java.awt
+.fl
+ */
+.fl
+package java.lang.applet;
+.fl
+\fP
+.fi
+.LP
+Note that while the comment separators \f2/**\fP and \f2/*\fP must be present, the leading asterisks on the intermediate lines can be omitted.
+.LP
+\f4package.html\fP \- This file can contain a package comment of the following structure \-\- the comment is placed in the \f2<body>\fP element:
+.LP
+File: \f2java/applet/package.html\fP
+.nf
+\f3
+.fl
+<HTML>
+.fl
+<BODY>
+.fl
+Provides the classes necessary to create an applet and the
+.fl
+classes an applet uses to communicate with its applet context.
+.fl
+<p>
+.fl
+The applet framework involves two entities: the applet
+.fl
+and the applet context. An applet is an embeddable
+.fl
+window (see the {@link java.awt.Panel} class) with a
+.fl
+few extra methods that the applet context can use to
+.fl
+initialize, start, and stop the applet.
+.fl
+
+.fl
+@since 1.0
+.fl
+@see java.awt
+.fl
+</BODY>
+.fl
+</HTML>
+.fl
+\fP
+.fi
+.LP
+Notice this is just a normal HTML file and does not include a package declaration. The content of the package comment file is written in HTML, like all other comments, with one exception: The documentation comment should not include the comment separators \f2/**\fP and \f2*/\fP or leading asterisks. When writing the comment, you should make the first sentence a summary about the package, and not put a title or any other text between \f2<body>\fP and the first sentence. You can include package tags; as with any documentation comment, all block tags must appear after the main description. If you add a \f2@see\fP tag in a package comment file, it must have a fully\-qualified name. For more details, see the
+.na
+\f2example of \fP\f2package.html\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#packagecomments.
+.LP
+\f3Processing of package comment file\fP \- When the Javadoc tool runs, it will automatically look for the package comment file; if found, the Javadoc tool does the following:
+.RS 3
+.TP 2
+o
+Copies the comment for processing. (For \f2package.html\fP, copies all content between \f2<body>\fP and \f2</body>\fP HTML tags. You can include a \f2<head>\fP section to put a \f2<title>\fP, source file copyright statement, or other information, but none of these will appear in the generated documentation.)
+.TP 2
+o
+Processes any package tags that are present.
+.TP 2
+o
+Inserts the processed text at the bottom of the package summary page it generates, as shown in
+.na
+\f2Package Summary\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/java/applet/package\-summary.html.
+.TP 2
+o
+Copies the first sentence of the package comment to the top of the package summary page. It also adds the package name and this first sentence to the list of packages on the overview page, as shown in
+.na
+\f2Overview Summary\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/overview\-summary.html. The end\-of\-sentence is determined by the same rules used for the end of the first sentence of class and member main descriptions.
+.RE
+.SS
+Overview Comment File
+.LP
+Each application or set of packages that you are documenting can have its own overview documentation comment, kept in its own "source" file, that the Javadoc tool will merge into the overview page that it generates. You typically include in this comment any documentation that applies to the entire application or set of packages.
+.LP
+To create an overview comment file, you can name the file anything you want, typically \f4overview.html\fP and place it anywhere, typically at the top level of the source tree. For example, if the source files for the \f2java.applet\fP package are contained in \f2/home/user/src/java/applet\fP directory, you could create an overview comment file at \f2/home/user/src/overview.html\fP.
+.LP
+Notice you can have multiple overview comment files for the same set of source files, in case you want to run javadoc multiple times on different sets of packages. For example, you could run javadoc once with \-private for internal documentation and again without that option for public documentation. In this case, you could describe the documentation as public or internal in the first sentence of each overview comment file.
+.LP
+The content of the overview comment file is one big documentation comment, written in HTML, like the package comment file described previously. See that description for details. To re\-iterate, when writing the comment, you should make the first sentence a summary about the application or set of packages, and not put a title or any other text between \f2<body>\fP and the first sentence. You can include overview tags; as with any documentation comment, all tags except in\-line tags, such as \f2{@link}\fP, must appear after the main description. If you add a \f2@see\fP tag, it must have a fully\-qualified name.
+.LP
+When you run the Javadoc tool, you specify the overview comment file name with the \-overview option. The file is then processed similar to that of a package comment file.
+.RS 3
+.TP 2
+o
+Copies all content between \f2<body>\fP and \f2</body>\fP tags for processing.
+.TP 2
+o
+Processes any overview tags that are present.
+.TP 2
+o
+Inserts the processed text at the bottom of the overview page it generates, as shown in
+.na
+\f2Overview Summary\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/overview\-summary.html.
+.TP 2
+o
+Copies the first sentence of the overview comment to the top of the overview summary page.
+.RE
+.SS
+Miscellaneous Unprocessed Files
+.LP
+You can also include in your source any miscellaneous files that you want the Javadoc tool to copy to the destination directory. These typically includes graphic files, example Java source (.java) and class (.class) files, and self\-standing HTML files whose content would overwhelm the documentation comment of a normal Java source file.
+.LP
+To include unprocessed files, put them in a directory called \f4doc\-files\fP which can be a subdirectory of any package directory that contains source files. You can have one such subdirectory for each package. You might include images, example code, source files, .class files, applets and HTML files. For example, if you want to include the image of a button \f2button.gif\fP in the \f2java.awt.Button\fP class documentation, you place that file in the \f2/home/user/src/java/awt/doc\-files/\fP directory. Notice the \f2doc\-files\fP directory should not be located at \f2/home/user/src/java/doc\-files\fP because \f2java\fP is not a package \-\- that is, it does not directly contain any source files.
+.LP
+All links to these unprocessed files must be hard\-coded, because the Javadoc tool does not look at the files \-\- it simply copies the directory and all its contents to the destination. For example, the link in the \f2Button.java\fP doc comment might look like:
+.nf
+\f3
+.fl
+    /**
+.fl
+     * This button looks like this:
+.fl
+     * <img src="doc\-files/Button.gif">
+.fl
+     */
+.fl
+\fP
+.fi
+.SS
+Test Files and Template Files
+.LP
+Some developers have indicated they want to store test files and templates files in the source tree near their corresponding source files. That is, they would like to put them in the same directory, or a subdirectory, of those source files.
+.LP
+If you run the Javadoc tool by explicitly passing in individual source filenames, you can deliberately omit test and templates files and prevent them from being processed. However, if you are passing in package names or wildcards, you need to follow certain rules to ensure these test files and templates files are not processed.
+.LP
+Test files differ from template files in that the former are legal, compilable source files, while the latter are not, but may end with ".java".
+.LP
+\f3Test files\fP \- Often developers want to put compilable, runnable test files for a given package in the \f2same\fP directory as the source files for that package. But they want the test files to belong to a package other than the source file package, such as the unnamed package (so the test files have no package statement or a different package statement from the source). In this scenario, when the source is being documented by specifying its package name specified on the command line, the test files will cause warnings or errors. You need to put such test files in a subdirectory. For example, if you want to add test files for source files in \f2com.package1\fP, put them in a subdirectory that would be an invalid package name (because it contains a hyphen):
+.nf
+\f3
+.fl
+    com/package1/test\-files/
+.fl
+\fP
+.fi
+.LP
+The test directory will be skipped by the Javadoc tool with no warnings.
+.LP
+If your test files contain doc comments, you can set up a separate run of the Javadoc tool to produce documentation of the test files by passing in their test source filenames with wildcards, such as \f2com/package1/test\-files/*.java\fP.
+.LP
+\f3Templates for source files\fP \- Template files have names that often end in ".java" and are not compilable. If you have a template for a source file that you want to keep in the source directory, you can name it with a dash (such as \f2Buffer\-Template.java\fP), or any other illegal Java character, to prevent it from being processed. This relies on the fact that the Javadoc tool will only process source files whose name, when stripped of the ".java" suffix, is actually a legal class name (see information about Identifiers in the Java Language Specification).
+.SH "GENERATED FILES"
+.LP
+By default, javadoc uses a standard doclet that generates HTML\-formatted documentation. This doclet generates the following kinds of files (where each HTML "page" corresponds to a separate file). Note that javadoc generates files with two types of names: those named after classes/interfaces, and those that are not (such as \f2package\-summary.html\fP). Files in the latter group contain hyphens to prevent filename conflicts with those in the former group.
+.LP
+\f3Basic Content Pages\fP
+.RS 3
+.TP 2
+o
+One \f3class or interface page\fP (\f2classname\fP\f2.html\fP) for each class or interface it is documenting.
+.TP 2
+o
+One \f3package page\fP (\f2package\-summary.html\fP) for each package it is documenting. The Javadoc tool will include any HTML text provided in a file named \f2package.html\fP or \f2package\-info.java\fP in the package directory of the source tree.
+.TP 2
+o
+One \f3overview page\fP (\f2overview\-summary.html\fP) for the entire set of packages. This is the front page of the generated document. The Javadoc tool will include any HTML text provided in a file specified with the \f2\-overview\fP option. Note that this file is created only if you pass into javadoc two or more package names. For further explanation, see HTML Frames.)
+.RE
+.LP
+\f3Cross\-Reference Pages\fP
+.RS 3
+.TP 2
+o
+One \f3class hierarchy page for the entire set of packages\fP (\f2overview\-tree.html\fP). To view this, click on "Overview" in the navigation bar, then click on "Tree".
+.TP 2
+o
+One \f3class hierarchy page for each package\fP (\f2package\-tree.html\fP) To view this, go to a particular package, class or interface page; click "Tree" to display the hierarchy for that package.
+.TP 2
+o
+One \f3"use" page\fP for each package (\f2package\-use.html\fP) and a separate one for each class and interface (\f2class\-use/\fP\f2classname\fP\f2.html\fP). This page describes what packages, classes, methods, constructors and fields use any part of the given class, interface or package. Given a class or interface A, its "use" page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
+.TP 2
+o
+A \f3deprecated API page\fP (\f2deprecated\-list.html\fP) listing all deprecated names. (A deprecated name is not recommended for use, generally due to improvements, and a replacement name is usually given. Deprecated APIs may be removed in future implementations.)
+.TP 2
+o
+A \f3constant field values page\fP (\f2constant\-values.html\fP) for the values of static fields.
+.TP 2
+o
+A \f3serialized form page\fP (\f2serialized\-form.html\fP) for information about serializable and externalizable classes. Each such class has a description of its serialization fields and methods. This information is of interest to re\-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class comment. The standard doclet automatically generates a serialized form page: any class (public or non\-public) that implements Serializable is included, along with \f2readObject\fP and \f2writeObject\fP methods, the fields that are serialized, and the doc comments from the \f2@serial\fP, \f2@serialField\fP, and \f2@serialData\fP tags. Public serializable classes can be excluded by marking them (or their package) with \f2@serial exclude\fP, and package\-private serializable classes can be included by marking them (or their package) with \f2@serial include\fP. As of 1.4, you can generate the complete serialized form for public and private classes by running javadoc \f2without\fP specifying the \f2\-private\fP option.
+.TP 2
+o
+An \f3index\fP (\f2index\-*.html\fP) of all class, interface, constructor, field and method names, alphabetically arranged. This is internationalized for Unicode and can be generated as a single file or as a separate file for each starting character (such as A\-Z for English).
+.RE
+.LP
+\f3Support Files\fP
+.RS 3
+.TP 2
+o
+A \f3help page\fP (\f2help\-doc.html\fP) that describes the navigation bar and the above pages. You can provide your own custom help file to override the default using \f2\-helpfile\fP.
+.TP 2
+o
+One \f3index.html file\fP which creates the HTML frames for display. This is the file you load to display the front page with frames. This file itself contains no text content.
+.TP 2
+o
+Several \f3frame files\fP (\f2*\-frame.html\fP) containing lists of packages, classes and interfaces, used when HTML frames are being displayed.
+.TP 2
+o
+A \f3package list\fP file (\f2package\-list\fP), used by the \f2\-link\fP and \f2\-linkoffline\fP options. This is a text file, not HTML, and is not reachable through any links.
+.TP 2
+o
+A \f3style sheet\fP file (\f2stylesheet.css\fP) that controls a limited amount of color, font family, font size, font style and positioning on the generated pages.
+.TP 2
+o
+A \f3doc\-files\fP directory that holds any image, example, source code or other files that you want copied to the destination directory. These files are not processed by the Javadoc tool in any manner \-\- that is, any javadoc tags in them will be ignored. This directory is not generated unless it exists in the source tree.
+.RE
+.LP
+\f3HTML Frames\fP
+.LP
+The Javadoc tool will generate either two or three HTML frames, as shown in the figure below. It creates the minimum necessary number of frames by omitting the list of packages if there is only one package (or no packages). That is, when you pass a single package name or source files (*.java) belonging to a single package as arguments into the javadoc command, it will create only one frame (C) in the left\-hand column \-\- the list of classes. When you pass into javadoc two or more package names, it creates a third frame (P) listing all packages, as well as an overview page (Detail). This overview page has the filename \f2overview\-summary.html\fP. Thus, this file is created only if you pass in two or more package names. You can bypass frames by clicking on the "No Frames" link or entering at overview\-summary.html.
+.LP
+If you are unfamiliar with HTML frames, you should be aware that frames can have \f2focus\fP for printing and scrolling. To give a frame focus, click on it. Then on many browsers the arrow keys and page keys will scroll that frame, and the print menu command will print it.
+.LP
+Load one of the following two files as the starting page depending on whether you want HTML frames or not:
+.RS 3
+.TP 2
+o
+\f2index.html\fP (for frames)
+.TP 2
+o
+\f2overview\-summary.html\fP (for no frames)
+.RE
+.LP
+\f3Generated File Structure\fP
+.LP
+The generated class and interface files are organized in the same directory hierarchy that Java source files and class files are organized. This structure is one directory per subpackage.
+.LP
+For example, the document generated for the class \f2java.applet.Applet\fP class would be located at \f2java/applet/Applet.html\fP. The file structure for the java.applet package follows, given that the destination directory is named \f2apidocs\fP. All files that contain the word "frame" appear in the upper\-left or lower\-left frames, as noted. All other HTML files appear in the right\-hand frame.
+.LP
+NOTE \- Directories are shown in \f3bold\fP. The asterisks (\f2*\fP) indicate the files and directories that are \f2omitted\fP when the arguments to javadoc are source filenames (*.java) rather than package names. Also when arguments are source filenames, \f2package\-list\fP is created but is empty. The doc\-files directory will not be created in the destination unless it exists in the source tree.
+.nf
+\f3
+.fl
+
+.fl
+\fP\f3apidocs\fP                             Top directory
+.fl
+   index.html                       Initial page that sets up HTML frames
+.fl
+ * overview\-summary.html            Lists all packages with first sentence summaries
+.fl
+   overview\-tree.html               Lists class hierarchy for all packages
+.fl
+   deprecated\-list.html             Lists deprecated API for all packages
+.fl
+   constant\-values.html             Lists values of static fields for all packages
+.fl
+   serialized\-form.html             Lists serialized form for all packages
+.fl
+ * overview\-frame.html              Lists all packages, used in upper\-left frame
+.fl
+   allclasses\-frame.html            Lists all classes for all packages, used in lower\-left frame
+.fl
+   help\-doc.html                    Lists user help for how these pages are organized
+.fl
+   index\-all.html                   Default index created without \-splitindex option
+.fl
+   \f3index\-files\fP                      Directory created with \-splitindex option
+.fl
+       index\-<number>.html          Index files created with \-splitindex option
+.fl
+   package\-list                     Lists package names, used only for resolving external refs
+.fl
+   stylesheet.css                   HTML style sheet for defining fonts, colors and positions
+.fl
+   \f3java\fP                             Package directory
+.fl
+       \f3applet\fP                       Subpackage directory
+.fl
+            Applet.html             Page for Applet class
+.fl
+            AppletContext.html      Page for AppletContext interface
+.fl
+            AppletStub.html         Page for AppletStub interface
+.fl
+            AudioClip.html          Page for AudioClip interface
+.fl
+          * package\-summary.html    Lists classes with first sentence summaries for this package
+.fl
+          * package\-frame.html      Lists classes in this package, used in lower left\-hand frame
+.fl
+          * package\-tree.html       Lists class hierarchy for this package
+.fl
+            package\-use             Lists where this package is used
+.fl
+            \f3doc\-files\fP               Directory holding image and example files
+.fl
+            \f3class\-use\fP               Directory holding pages API is used
+.fl
+                Applet.html         Page for uses of Applet class
+.fl
+                AppletContext.html  Page for uses of AppletContext interface
+.fl
+                AppletStub.html     Page for uses of AppletStub interface
+.fl
+                AudioClip.html      Page for uses of AudioClip interface
+.fl
+   \f3src\-html\fP                         Source code directory
+.fl
+       \f3java\fP                         Package directory
+.fl
+           \f3applet\fP                   Subpackage directory
+.fl
+                Applet.html         Page for Applet source code
+.fl
+                AppletContext.html  Page for AppletContext source code
+.fl
+                AppletStub.html     Page for AppletStub source code
+.fl
+                AudioClip.html      Page for AudioClip source code
+.fl
+.fi
+.SS
+Generated API Declarations
+.LP
+The Javadoc tool generates a declaration at the start of each class, interface, field, constructor, and method description for that API item. For example, the declaration for the \f2Boolean\fP class is:
+.LP
+\f2public final class Boolean\fP
+.br
+\f2extends Object\fP
+.br
+\f2implements Serializable\fP
+.LP
+and the declaration for the \f2Boolean.valueOf\fPmethod is:
+.LP
+\f2public static Boolean valueOf(String s)\fP
+.LP
+The Javadoc tool can include the modifiers \f2public\fP, \f2protected\fP, \f2private\fP, \f2abstract\fP, \f2final\fP, \f2static\fP, \f2transient\fP, and \f2volatile\fP, but not \f2synchronized\fP or \f2native\fP. These last two modifiers are considered implementation detail and not part of the API specification.
+.LP
+Rather than relying on the keyword \f2synchronized\fP, APIs should document their concurrency semantics in the comment's main description, as in "a single \f2Enumeration\fP cannot be used by multiple threads concurrently". The document should not describe how to achieve these semantics. As another example, while \f2Hashtable\fP should be thread\-safe, there's no reason to specify that we achieve this by synchronizing all of its exported methods. We should reserve the right to synchronize internally at the bucket level, thus offering higher concurrency.
+.SH "DOCUMENTATION COMMENTS"
+.LP
+The original "Documentation Comment Specification" can be found under related documentation.
+.SS
+Commenting the Source Code
+.LP
+You can include \f2documentation comments\fP ("doc comments") in the source code, ahead of declarations for any class, interface, method, constructor, or field. You can also create doc comments for each package and another one for the overview, though their syntax is slightly different. Doc comments are also known informally as "Javadoc comments" (but this term violates its trademark usage). A doc comment consists of the characters between the characters \f2/**\fP that begin the comment and the characters \f2*/\fP that end it. Leading asterisks are allowed on each line and are described further below. The text in a comment can continue onto multiple lines.
+.nf
+\f3
+.fl
+/**
+.fl
+ * This is the typical format of a simple documentation comment
+.fl
+ * that spans two lines.
+.fl
+ */
+.fl
+\fP
+.fi
+.LP
+To save space you can put a comment on one line:
+.nf
+\f3
+.fl
+/** This comment takes up only one line. */
+.fl
+\fP
+.fi
+.LP
+\f3Placement of comments\fP \- Documentation comments are recognized only when placed immediately before class, interface, constructor, method, or field declarations \-\- see the class example, method example, and field example. Documentation comments placed in the body of a method are ignored. Only one documentation comment per declaration statement is recognized by the Javadoc tool.
+.LP
+A common mistake is to put an \f2import\fP statement between the class comment and the class declaration. Avoid this, as the Javadoc tool will ignore the class comment.
+.nf
+\f3
+.fl
+   /**
+.fl
+    * This is the class comment for the class Whatever.
+.fl
+    */
+.fl
+
+.fl
+    import com.sun;   // MISTAKE \- Important not to put import statement here
+.fl
+
+.fl
+    public class Whatever {
+.fl
+    }
+.fl
+\fP
+.fi
+.LP
+\f3A doc comment is composed of a \fP\f4main description\fP\f3 followed by a \fP\f4tag section\fP \- The \f2main description\fP begins after the starting delimiter \f2/**\fP and continues until the tag section. The \f2tag section\fP starts with the first block tag, which is defined by the first \f2@\fP character that begins a line (ignoring leading asterisks, white space, and leading separator \f2/**\fP). It is possible to have a comment with only a tag section and no main description. The main description cannot continue after the tag section begins. The argument to a tag can span multiple lines. There can be any number of tags \-\- some types of tags can be repeated while others cannot. For example, this \f2@see\fP starts the tag section:
+.nf
+\f3
+.fl
+/**
+.fl
+ * This sentence would hold the main description for this doc comment.
+.fl
+ * @see java.lang.Object
+.fl
+ */
+.fl
+\fP
+.fi
+.LP
+\f3Block tags and in\-line tags\fP \- A \f2tag\fP is a special keyword within a doc comment that the Javadoc tool can process. There are two kinds of tags: block tags, which appear as \f2@tag\fP (also known as "standalone tags"), and in\-line tags, which appear within curly braces, as \f2{@tag}\fP. To be interpreted, a block tag must appear at the beginning of a line, ignoring leading asterisks, white space, and separator (\f2/**\fP). This means you can use the \f2@\fP character elsewhere in the text and it will not be interpreted as the start of a tag. If you want to start a line with the \f2@\fP character and not have it be interpreted, use the HTML entity \f2&#064;\fP. Each block tag has associated text, which includes any text following the tag up to, but not including, either the next tag, or the end of the doc comment. This associated text can span multiple lines. An in\-line tag is allowed and interpreted anywhere that text is allowed. The following example contains the block tag \f2@deprecated\fP and in\-line tag \f2{@link}\fP.
+.nf
+\f3
+.fl
+/**
+.fl
+ * @deprecated  As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}
+.fl
+ */
+.fl
+\fP
+.fi
+.LP
+\f3Comments are written in HTML\fP \- The text must be written in HTML, in that they should use HTML entities and can use HTML tags. You can use whichever version of HTML your browser supports; we have written the standard doclet to generate HTML 3.2\-compliant code elsewhere (outside of the documentation comments) with the inclusion of cascading style sheets and frames. (We preface each generated file with "HTML 4.0" because of the frame sets.)
+.LP
+For example, entities for the less\-than (\f2<\fP) and greater\-than (\f2>\fP) symbols should be written \f2<\fP and \f2>\fP. Likewise, the ampersand (\f2&\fP) should be written \f2&\fP. The bold HTML tag \f2<b>\fP is shown in the following example.
+.LP
+Here is a doc comment:
+.nf
+\f3
+.fl
+/**
+.fl
+ * This is a <b>doc</b> comment.
+.fl
+ * @see java.lang.Object
+.fl
+ */
+.fl
+\fP
+.fi
+.LP
+\f3Leading asterisks\fP \- When javadoc parses a doc comment, leading asterisk (\f2*\fP) characters on each line are discarded; blanks and tabs preceding the initial asterisk (\f2*\fP) characters are also discarded. Starting with 1.4, if you omit the leading asterisk on a line, the leading white space is no longer removed. This enables you to paste code examples directly into a doc comment inside a \f2<PRE>\fP tag, and its indentation will be honored. Spaces are generally interpreted by browsers more uniformly than tabs. Indentation is relative to the left margin (rather than the separator \f2/**\fP or \f2<PRE>\fP tag).
+.LP
+\f3First sentence\fP \- The first sentence of each doc comment should be a summary sentence, containing a concise but complete description of the declared entity. This sentence ends at the first period that is followed by a blank, tab, or line terminator, or at the first block tag. The Javadoc tool copies this first sentence to the member summary at the top of the HTML page.
+.LP
+\f3Declaration with multiple fields\fP \- Java allows declaring multiple fields in a single statement, but this statement can have only one documentation comment, which is copied for all fields. Therefore if you want individual documentation comments for each field, you must declare each field in a separate statement. For example, the following documentation comment doesn't make sense written as a single declaration and would be better handled as two declarations:
+.nf
+\f3
+.fl
+/**
+.fl
+ * The horizontal and vertical distances of point (x,y)
+.fl
+ */
+.fl
+public int x, y;      // Avoid this
+.fl
+\fP
+.fi
+.LP
+The Javadoc tool generates the following documentation from the above code:
+.nf
+\f3
+.fl
+public int \fP\f3x\fP
+.fl
+.fi
+.RS 3
+The horizontal and vertical distances of point (x,y)
+.RE
+.nf
+\f3
+.fl
+public int \fP\f3y\fP
+.fl
+.fi
+.RS 3
+The horizontal and vertical distances of point (x,y)
+.RE
+.LP
+\f3Use header tags carefully\fP \- When writing documentation comments for members, it's best not to use HTML heading tags such as <H1> and <H2>, because the Javadoc tool creates an entire structured document and these structural tags might interfere with the formatting of the generated document. However, it is fine to use these headings in class and package comments to provide your own structure.
+.SS
+Automatic Copying of Method Comments
+.LP
+The Javadoc tool has the ability to copy or "inherit" method comments in classes and interfaces under the following two circumstances. Constructors, fields and nested classes do not inherit doc comments.
+.RS 3
+.TP 2
+o
+\f3Automatically inherit comment to fill in missing text\fP \- When a main description, or \f2@return\fP, \f2@param\fP or \f2@throws\fP  tag is missing from a method comment, the Javadoc tool copies the corresponding main description or tag comment from the method it overrides or implements (if any), according to the algorithm below.
+.LP
+More specifically, when a \f2@param\fP tag for a particular parameter is missing, then the comment for that parameter is copied from the method further up the inheritance hierarchy. When a \f2@throws\fP tag for a particular exception is missing, the \f2@throws\fP tag is copied \f2only if that exception is declared\fP.
+.LP
+This behavior contrasts with version 1.3 and earlier, where the presence of any main description or tag would prevent all comments from being inherited.
+.TP 2
+o
+\f3Explicitly inherit comment with {@inheritDoc} tag\fP \- Insert the inline tag \f2{@inheritDoc}\fP in a method main description or \f2@return\fP, \f2@param\fP or \f2@throws\fP tag comment \-\- the corresponding inherited main description or tag comment is copied into that spot.
+.RE
+.LP
+The source file for the inherited method need only be on the path specified by \-sourcepath for the doc comment to actually be available to copy. Neither the class nor its package needs to be passed in on the command line. This contrasts with 1.3.x and earlier releases, where the class had to be a documented class
+.LP
+\f3Inherit from classes and interfaces\fP \- Inheriting of comments occurs in all three possible cases of inheritance from classes and interfaces:
+.RS 3
+.TP 2
+o
+When a method in a class overrides a method in a superclass
+.TP 2
+o
+When a method in an interface overrides a method in a superinterface
+.TP 2
+o
+When a method in a class implements a method in an interface
+.RE
+.LP
+In the first two cases, for method overrides, the Javadoc tool generates a subheading "Overrides" in the documentation for the overriding method, with a link to the method it is overriding, whether or not the comment is inherited.
+.LP
+In the third case, when a method in a given class implements a method in an interface, the Javadoc tool generates a subheading "Specified by" in the documentation for the overriding method, with a link to the method it is implementing. This happens whether or not the comment is inherited.
+.LP
+\f3Algorithm for Inheriting Method Comments\fP \- If a method does not have a doc comment, or has an {@inheritDoc} tag, the Javadoc tool searches for an applicable comment using the following algorithm, which is designed to find the most specific applicable doc comment, giving preference to interfaces over superclasses:
+.RS 3
+.TP 3
+1.
+Look in each directly implemented (or extended) interface in the order they appear following the word implements (or extends) in the method declaration. Use the first doc comment found for this method.
+.TP 3
+2.
+If step 1 failed to find a doc comment, recursively apply this entire algorithm to each directly implemented (or extended) interface, in the same order they were examined in step 1.
+.TP 3
+3.
+If step 2 failed to find a doc comment and this is a class other than Object (not an interface):
+.RS 3
+.TP 3
+a.
+If the superclass has a doc comment for this method, use it.
+.TP 3
+b.
+If step 3a failed to find a doc comment, recursively apply this entire algorithm to the superclass.
+.RE
+.RE
+.SH "JAVADOC TAGS"
+.LP
+The Javadoc tool parses special tags when they are embedded within a Java doc comment. These doc tags enable you to autogenerate a complete, well\-formatted API from your source code. The tags start with an "at" sign (\f2@\fP) and are case\-sensitive \-\- they must be typed with the uppercase and lowercase letters as shown. A tag must start at the beginning of a line (after any leading spaces and an optional asterisk) or it is treated as normal text. By convention, tags with the same name are grouped together. For example, put all \f2@see\fP tags together.
+.LP
+Tags come in two types:
+.RS 3
+.TP 2
+o
+\f3Block tags\fP \- Can be placed only in the tag section that follows the main description. Block tags are of the form: \f2@tag\fP.
+.TP 2
+o
+\f3Inline tags\fP \- Can be placed anywhere in the main description or in the comments for block tags. Inline tags are denoted by curly braces: \f2{@tag}\fP.
+.RE
+.LP
+For information about tags we might introduce in future releases, see
+.na
+\f2Proposed Tags\fP @
+.fi
+http://java.sun.com/j2se/javadoc/proposed\-tags.html.
+.LP
+The current tags are:
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 80 0
+.nr 38 \w\f3Tag\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@author\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2{@code}\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2{@docRoot}\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@deprecated\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@exception\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2{@inheritDoc}\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2{@link}\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2{@linkplain}\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2{@literal}\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@param\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@return\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@see\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@serial\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@serialData\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@serialField\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@since\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@throws\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2{@value}\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f2@version\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Introduced in JDK/SDK\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.0
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.5
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.3
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.0
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.0
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.4
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.2
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.4
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.5
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.0
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.0
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.0
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.2
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.2
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.2
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.1
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.2
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.4
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \w1.0
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 873 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Tag\fP\h'|\n(41u'\f3Introduced in JDK/SDK\fP
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@author\fP\h'|\n(41u'1.0
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2{@code}\fP\h'|\n(41u'1.5
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2{@docRoot}\fP\h'|\n(41u'1.3
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@deprecated\fP\h'|\n(41u'1.0
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@exception\fP\h'|\n(41u'1.0
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2{@inheritDoc}\fP\h'|\n(41u'1.4
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2{@link}\fP\h'|\n(41u'1.2
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2{@linkplain}\fP\h'|\n(41u'1.4
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2{@literal}\fP\h'|\n(41u'1.5
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@param\fP\h'|\n(41u'1.0
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@return\fP\h'|\n(41u'1.0
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@see\fP\h'|\n(41u'1.0
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@serial\fP\h'|\n(41u'1.2
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@serialData\fP\h'|\n(41u'1.2
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@serialField\fP\h'|\n(41u'1.2
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@since\fP\h'|\n(41u'1.1
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@throws\fP\h'|\n(41u'1.2
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2{@value}\fP\h'|\n(41u'1.4
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f2@version\fP\h'|\n(41u'1.0
+.fc
+.nr T. 1
+.T# 1
+.35
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-42
+.LP
+For custom tags, see the \-tag option.
+.RS 3
+.TP 3
+@author\  name\-text
+Adds an "Author" entry with the specified \f2name\-text\fP to the generated docs when the \-author option is used. A doc comment may contain multiple \f2@author\fP tags. You can specify one name per \f2@author\fP tag or multiple names per tag. In the former case, the Javadoc tool inserts a comma (\f2,\fP) and space between names. In the latter case, the entire text is simply copied to the generated document without being parsed. Therefore, you can use multiple names per line if you want a localized name separator other than comma.
+.RE
+.LP
+For more details, see Where Tags Can Be Used and
+.na
+\f2writing @author tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#@author.
+.LP
+.RS 3
+.TP 3
+@deprecated\  deprecated\-text Note: You can deprecate a program element using the @Deprecated annotation.
+.RE
+.LP
+Adds a comment indicating that this API should no longer be used (even though it may continue to work). The Javadoc tool moves the \f2deprecated\-text\fP ahead of the main description, placing it in italics and preceding it with a bold warning: "Deprecated". This tag is valid in all doc comments: overview, package, class, interface, constructor, method and field.
+.LP
+The first sentence of \f2deprecated\-text\fP should at least tell the user when the API was deprecated and what to use as a replacement. The Javadoc tool copies just the first sentence to the summary section and index. Subsequent sentences can also explain why it has been deprecated. You should include a \f2{@link}\fP tag (for Javadoc 1.2 or later) that points to the replacement API:
+.LP
+For more details, see
+.na
+\f2writing @deprecated tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#@deprecated.
+.RS 3
+.TP 2
+o
+For Javadoc 1.2 and later, use a \f2{@link}\fP tag. This creates the link in\-line, where you want it. For example:
+.nf
+\f3
+.fl
+/**
+.fl
+ * @deprecated  As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}
+.fl
+ */
+.fl
+
+.fl
+\fP
+.fi
+.TP 2
+o
+For Javadoc 1.1, the standard format is to create a \f2@see\fP tag (which cannot be in\-line) for each \f2@deprecated\fP tag.
+.RE
+.LP
+For more about deprecation, see
+.na
+\f2The @deprecated tag\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/javadoc/deprecation/index.html.
+.LP
+.RS 3
+.TP 3
+{@code\  text}
+Equivalent to \f2<code>{@literal}</code>\fP.
+.LP
+Displays \f2text\fP in \f2code\fP font without interpreting the text as HTML markup or nested javadoc tags. This enables you to use regular angle brackets (\f2<\fP and \f2>\fP) instead of the HTML entities (\f2<\fP and \f2>\fP) in doc comments, such as in parameter types (\f2<Object>\fP), inequalities (\f23 < 4\fP), or arrows (\f2<\-\fP). For example, the doc comment text:
+.nf
+\f3
+.fl
+     \fP\f4{@code A<B>C}\fP\f3
+.fl
+
+.fl
+\fP
+.fi
+.LP
+displays in the generated HTML page unchanged, as:
+.nf
+\f3
+.fl
+     \fP\f4A<B>C\fP\f3
+.fl
+
+.fl
+\fP
+.fi
+.LP
+The noteworthy point is that the \f2<B>\fP is not interpreted as bold and is in code font.
+.LP
+If you want the same functionality without the code font, use \f2{@literal}\fP.
+.LP
+.TP 3
+{@docRoot}
+Represents the relative path to the generated document's (destination) root directory from any generated page. It is useful when you want to include a file, such as a copyright page or company logo, that you want to reference from all generated pages. Linking to the copyright page from the bottom of each page is common.
+.LP
+This \f2{@docRoot}\fP tag can be used both on the command line and in a doc comment: This tag is valid in all doc comments: overview, package, class, interface, constructor, method and field, including the text portion of any tag (such as @return, @param and @deprecated).
+.RS 3
+.TP 3
+1.
+On the command line, where the header/footer/bottom are defined:
+.nf
+\f3
+.fl
+   javadoc \-bottom '<a href="{@docRoot}/copyright.html">Copyright</a>'
+.fl
+
+.fl
+\fP
+.fi
+.LP
+NOTE \- When using \f2{@docRoot}\fP this way in a make file, some makefile programs require special escaping for the brace {} characters. For example, the Inprise MAKE version 5.2 running on Windows requires double braces: \f2{{@docRoot}}\fP. It also requires double (rather than single) quotes to enclose arguments to options such as \f2\-bottom\fP (with the quotes around the \f2href\fP argument omitted).
+.TP 3
+2.
+In a doc comment:
+.nf
+\f3
+.fl
+   /**
+.fl
+    * See the <a href="{@docRoot}/copyright.html">Copyright</a>.
+.fl
+    */
+.fl
+
+.fl
+\fP
+.fi
+.RE
+.LP
+The reason this tag is needed is because the generated docs are in hierarchical directories, as deep as the number of subpackages. This expression:
+.nf
+\f3
+.fl
+  <a href="{@docRoot}/copyright.html">
+.fl
+
+.fl
+\fP
+.fi
+.LP
+would resolve to:
+.nf
+\f3
+.fl
+  <a href="../../copyright.html">      for java/lang/Object.java
+.fl
+
+.fl
+\fP
+.fi
+.LP
+and
+.nf
+\f3
+.fl
+  <a href="../../../copyright.html">   for java/lang/ref/Reference.java
+.fl
+
+.fl
+\fP
+.fi
+.LP
+.TP 3
+@exception\  class\-name\  description
+The \f2@exception\fP tag is a synonym for \f2@throws\fP.
+.LP
+.TP 3
+{@inheritDoc}\
+Inherits (copies) documentation from the "nearest" inheritable class or implementable interface into the current doc comment at this tag's location. This allows you to write more general comments higher up the inheritance tree, and to write around the copied text.
+.LP
+This tag is valid only in these places in a doc comment:
+.RS 3
+.TP 2
+o
+In the main description block of a method. In this case, the main description is copied from a class or interface up the hierarchy.
+.TP 2
+o
+In the text arguments of the @return, @param and @throws tags of a method. In this case, the tag text is copied from the corresponding tag up the hierarchy.
+.RE
+.LP
+See Automatic Copying of Method Comments for a more precise description of how comments are found in the inheritance hierarchy. Note that if this tag is missing, the comment is or is not automatically inherited according to rules described in that section.
+.LP
+.TP 3
+{@link\  package.class#member\  label}
+Inserts an in\-line link with visible text \f2label\fP that points to the documentation for the specified package, class or member name of a referenced class. This tag is valid in all doc comments: overview, package, class, interface, constructor, method and field, including the text portion of any tag (such as @return, @param and @deprecated).
+.LP
+This tag is very simliar to \f2@see\fP \-\- both require the same references and accept exactly the same syntax for \f2package.class\fP\f2#\fP\f2member\fP and \f2label\fP. The main difference is that \f2{@link}\fP generates an in\-line link rather than placing the link in the "See Also" section. Also, the \f2{@link}\fP tag begins and ends with curly braces to separate it from the rest of the in\-line text. If you need to use "}" inside the label, use the HTML entity notation &#125;
+.LP
+There is no limit to the number of \f2{@link}\fP tags allowed in a sentence. You can use this tag in the main description part of any documentation comment or in the text portion of any tag (such as @deprecated, @return or @param).
+.LP
+For example, here is a comment that refers to the \f2getComponentAt(int, int)\fP method:
+.nf
+\f3
+.fl
+Use the {@link #getComponentAt(int, int) getComponentAt} method.
+.fl
+
+.fl
+\fP
+.fi
+.LP
+From this, the standard doclet would generate the following HTML (assuming it refers to another class in the same package):
+.nf
+\f3
+.fl
+Use the <a href="Component.html#getComponentAt(int, int)">getComponentAt</a> method.
+.fl
+
+.fl
+\fP
+.fi
+.LP
+Which appears on the web page as:
+.nf
+\f3
+.fl
+Use the getComponentAt method.
+.fl
+
+.fl
+\fP
+.fi
+.LP
+You can extend \f2{@link}\fP to link to classes not being documented by using the \f2\-link\fP option.
+.LP
+For more details, see
+.na
+\f2writing {@link} tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#{@link}.
+.LP
+.TP 3
+{@linkplain\  package.class#member\  label}
+Identical to \f2{@link}\fP, except the link's label is displayed in plain text than code font. Useful when the label is plain text. Example:
+.nf
+\f3
+.fl
+     Refer to {@linkplain add() the overridden method}.
+.fl
+
+.fl
+\fP
+.fi
+.LP
+This would display as:
+.LP
+Refer to the overridden method.
+.LP
+.TP 3
+{@literal\  text}
+Displays \f2text\fP without interpreting the text as HTML markup or nested javadoc tags. This enables you to use regular angle brackets (\f2<\fP and \f2>\fP) instead of the HTML entities (\f2<\fP and \f2>\fP) in doc comments, such as in parameter types (\f2<Object>\fP), inequalities (\f23 < 4\fP), or arrows (\f2<\-\fP). For example, the doc comment text:
+.nf
+\f3
+.fl
+     \fP\f4{@literal A<B>C}\fP\f3
+.fl
+
+.fl
+\fP
+.fi
+.LP
+displays unchanged in the generated HTML page in your browser, as:
+.LP
+\f2\ \ \ \ \ \fPA<B>C
+.LP
+The noteworthy point is that the \f2<B>\fP is not interpreted as bold (and it is not in code font).
+.LP
+If you want the same functionality but with the text in code font, use \f2{@code}\fP.
+.LP
+.TP 3
+@param\  parameter\-name description
+Adds a parameter with the specified \f2parameter\-name\fP followed by the specified \f2description\fP to the "Parameters" section. When writing the doc comment, you may continue the \f2description\fP onto multiple lines. This tag is valid only in a doc comment for a method, constructor or class.
+.LP
+The \f2parameter\-name\fP can be the name of a parameter in a method or constructor, or the name of a type parameter of a class, method or constructor. Use angle brackets around this parameter name to specify the use of a type parameter.
+.LP
+Example of a type parameter of a class:
+.nf
+\f3
+.fl
+     /**
+.fl
+      * @param <E> Type of element stored in a list
+.fl
+      */
+.fl
+     public interface List<E> extends Collection<E> {
+.fl
+     }
+.fl
+
+.fl
+\fP
+.fi
+.LP
+Example of a type parameter of a method:
+.nf
+\f3
+.fl
+     /**
+.fl
+      * @param string  the string to be converted
+.fl
+      * @param type    the type to convert the string to
+.fl
+      * @param <T>     the type of the element
+.fl
+      * @param <V>     the value of the element
+.fl
+      */
+.fl
+     <T, V extends T> V convert(String string, Class<T> type) {
+.fl
+     }
+.fl
+
+.fl
+\fP
+.fi
+.LP
+For more details, see
+.na
+\f2writing @param tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#@param.
+.LP
+.TP 3
+@return\  description
+Adds a "Returns" section with the \f2description\fP text. This text should describe the return type and permissible range of values. This tag is valid only in a doc comment for a method.
+.LP
+For more details, see
+.na
+\f2writing @return tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#@return.
+.LP
+.TP 3
+@see\  reference
+Adds a "See Also" heading with a link or text entry that points to \f2reference\fP. A doc comment may contain any number of \f2@see\fP tags, which are all grouped under the same heading. The \f2@see\fP tag has three variations; the third form below is the most common. This tag is valid in any doc comment: overview, package, class, interface, constructor, method or field. For inserting an in\-line link within a sentence to a package, class or member, see \f2{@link}\fP.
+.RS 3
+.TP 3
+@see "string"
+Adds a text entry for \f2string\fP. No link is generated. The \f2string\fP is a book or other reference to information not available by URL. The Javadoc tool distinguishes this from the previous cases by looking for a double\-quote (\f2"\fP) as the first character. For example:
+.nf
+\f3
+.fl
+     @see "The Java Programming Language"
+.fl
+
+.fl
+\fP
+.fi
+.LP
+This generates text such as:
+.RE
+.RE
+.RS 3
+.RS 3
+.RS 3
+.RS 3
+.TP 3
+See Also:
+"The Java Programming Language"
+.RE
+.RE
+.TP 3
+@see <a href="URL#value">label</a>
+Adds a link as defined by \f2URL\fP#\f2value\fP. The \f2URL\fP#\f2value\fP is a relative or absolute URL. The Javadoc tool distinguishes this from other cases by looking for a less\-than symbol (\f2<\fP) as the first character. For example:
+.nf
+\f3
+.fl
+     @see <a href="spec.html#section">Java Spec</a>
+.fl
+\fP
+.fi
+This generates a link such as:
+.RS 3
+.TP 3
+See Also:
+Java Spec
+.RE
+.TP 3
+@see\  package.class#member\  label
+Adds a link, with visible text \f2label\fP, that points to the documentation for the specified name in the Java Language that is referenced. The \f2label\fP is optional; if omitted, the name appears instead as the visible text, suitably shortened \-\- see How a name is displayed. Use \-noqualifier to globally remove the package name from this visible text. Use the label when you want the visible text to be different from the auto\-generated visible text.
+.LP
+Only in version 1.2, just the name but not the label would automatically appear in <code> HTML tags, Starting with 1.2.2, the <code> is always included around the visible text, whether or not a label is used.
+.LP
+.RS 3
+.TP 2
+o
+\f4package.class\fP\f4#\fP\f4member\fP is any valid program element name that is referenced \-\- a package, class, interface, constructor, method or field name \-\- except that the character ahead of the member name should be a hash character (\f2#\fP). The \f2class\fP represents any top\-level or nested class or interface. The \f2member\fP represents any constructor, method or field (not a nested class or interface). If this name is in the documented classes, the Javadoc tool will automatically create a link to it. To create links to external referenced classes, use the \f2\-link\fP option. Use either of the other two \f2@see\fP forms for referring to documentation of a name that does not belong to a referenced class. This argument is described at greater length below under Specifying a Name.
+.TP 2
+o
+\f4label\fP is optional text that is visible as the link's label. The \f2label\fP can contain whitespace. If \f2label\fP is omitted, then \f2package.class.member\fP will appear, suitably shortened relative to the current class and package \-\- see How a name is displayed.
+.TP 2
+o
+A space is the delimiter between \f2package.class\fP\f2#\fP\f2member\fP and \f2label\fP. A space inside parentheses does not indicate the start of a label, so spaces may be used between parameters in a method.
+.RE
+.LP
+\f3Example\fP \- In this example, an \f2@see\fP tag (in the \f2Character\fP class) refers to the \f2equals\fP method in the \f2String\fP class. The tag includes both arguments: the name "\f2String#equals(Object)\fP" and the label "\f2equals\fP".
+.nf
+\f3
+.fl
+ /**
+.fl
+  * @see String#equals(Object) equals
+.fl
+  */
+.fl
+\fP
+.fi
+The standard doclet produces HTML something like this:
+.nf
+\f3
+.fl
+<dl>
+.fl
+<dt><b>See Also:</b>
+.fl
+<dd><a href="../../java/lang/String#equals(java.lang.Object)"><code>equals<code></a>
+.fl
+</dl>
+.fl
+\fP
+.fi
+Which looks something like this in a browser, where the label is the visible link text:
+.RS 3
+.TP 3
+See Also:
+equals
+.RE
+.LP
+\f3Specifying a name\fP \- This \f2package.class\fP\f2#\fP\f2member\fP name can be either fully\-qualified, such as \f2java.lang.String#toUpperCase()\fP or not, such as \f2String#toUpperCase()\fP or \f2#toUpperCase()\fP. If less than fully\-qualified, the Javadoc tool uses the normal Java compiler search order to find it, further described below in Search order for @see. The name can contain whitespace within parentheses, such as between method arguments.
+.LP
+Of course the advantage of providing shorter, "partially\-qualified" names is that they are shorter to type and there is less clutter in the source code. The following table shows the different forms of the name, where \f2Class\fP can be a class or interface, \f2Type\fP can be a class, interface, array, or primitive, and \f2method\fP can be a method or constructor.
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80
+.nr 34 \n(.lu
+.eo
+.am 80
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/2u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f3Typical\ forms\ for\ \fP\f4@see\fP\f3\ \fP\f4package.class#member\fP
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/2u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f3Referencing\ a\ member\ of\ the\ current\ class\fP
+.br
+\f2@see\fP\ \f2#\fP\f2field\fP
+.br
+\f2@see\fP\ \f2#\fP\f2method(Type,\ Type,...)\fP
+.br
+\f2@see\fP\ \f2#\fP\f2method(Type\ argname,\ Type\ argname,...)\fP
+.br
+\f2@see\fP\ \f2#\fP\f2constructor(Type,\ Type,...)\fP
+.br
+\f2@see\fP\ \f2#\fP\f2constructor(Type\ argname,\ Type\ argname,...)\fP
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/2u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f3Referencing\ another\ class\ in\ the\ current\ or\ imported\ packages\fP
+.br
+\f2@see\fP\ \f2Class\fP\f2#\fP\f2field\fP
+.br
+\f2@see\fP\ \f2Class\fP\f2#\fP\f2method(Type,\ Type,...)\fP
+.br
+\f2@see\fP\ \f2Class\fP\f2#\fP\f2method(Type\ argname,\ Type\ argname,...)\fP
+.br
+\f2@see\fP\ \f2Class\fP\f2#\fP\f2constructor(Type,\ Type,...)\fP
+.br
+\f2@see\fP\ \f2Class\fP\f2#\fP\f2constructor(Type\ argname,\ Type\ argname,...)\fP
+.br
+\f2@see\fP\ \f2Class.NestedClass\fP
+.br
+\f2@see\fP\ \f2Class\fP
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/2u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f3Referencing\ an\ element\ in\ another\ package\fP\ (fully qualified)
+.br
+\f2@see\fP\ \f2package.Class\fP\f2#\fP\f2field\fP
+.br
+\f2@see\fP\ \f2package.Class\fP\f2#\fP\f2method(Type,\ Type,...)\fP
+.br
+\f2@see\fP\ \f2package.Class\fP\f2#\fP\f2method(Type\ argname,\ Type\ argname,...)\fP
+.br
+\f2@see\fP\ \f2package.Class\fP\f2#\fP\f2constructor(Type,\ Type,...)\fP
+.br
+\f2@see\fP\ \f2package.Class\fP\f2#\fP\f2constructor(Type\ argname,\ Type\ argname,...)\fP
+.br
+\f2@see\fP\ \f2package.Class.NestedClass\fP
+.br
+\f2@see\fP\ \f2package.Class\fP
+.br
+\f2@see\fP\ \f2package\fP
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.80
+.rm 80
+.nr 38 \n(a-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(b-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(c-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(d-
+.if \n(80<\n(38 .nr 80 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr TW \n(80
+.if t .if \n(TW>\n(.li .tm Table at line 1364 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-58
+.LP
+The following notes apply to the above table:
+.RS 3
+.TP 2
+o
+The first set of forms (with no class or package) will cause the Javadoc tool to search only through the current class's hierarchy. It will find a member of the current class or interface, one of its superclasses or superinterfaces, or one of its enclosing classes or interfaces (search steps 1\-3). It will not search the rest of the current package or other packages (search steps 4\-5).
+.TP 2
+o
+If any method or constructor is entered as a name with no parentheses, such as \f2getValue\fP, and if there is no field with the same name, the Javadoc tool will correctly create a link to it, but will print a warning message reminding you to add the parentheses and arguments. If this method is overloaded, the Javadoc tool will link to the first method its search encounters, which is unspecified.
+.TP 2
+o
+Nested classes must be specified as \f2outer\fP\f2.\fP\f2inner\fP, not simply \f2inner\fP, for all forms.
+.TP 2
+o
+As stated, the hash character (\f2#\fP), rather than a dot (\f2.\fP) separates a member from its class. This enables the Javadoc tool to resolve ambiguities, since the dot also separates classes, nested classes, packages, and subpackages. However, the Javadoc tool is generally lenient and will properly parse a dot if you know there is no ambiguity, though it will print a warning.
+.RE
+.LP
+\f3Search order for @see\fP \- the Javadoc tool will process a \f2@see\fP tag that appears in a source file (.java), package file (package.html or package\-info.java) or overview file (overview.html). In the latter two files, you must fully\-qualify the name you supply with \f2@see\fP. In a source file, you can specify a name that is fully\-qualified or partially\-qualified.
+.LP
+When the Javadoc tool encounters a \f2@see\fP tag in a \f2.java\fP file that is \f2not\fP fully qualified, it searches for the specified name in the same order as the Java compiler would (except the Javadoc tool will not detect certain namespace ambiguities, since it assumes the source code is free of these errors). This search order is formally defined in the \f2Java Language Specification\fP. The Javadoc tool searches for that name through all related and imported classes and packages. In particular, it searches in this order:
+.RS 3
+.TP 3
+1.
+the current class or interface
+.TP 3
+2.
+any enclosing classes and interfaces, searching closest first
+.TP 3
+3.
+any superclasses and superinterfaces, searching closest first
+.TP 3
+4.
+the current package
+.TP 3
+5.
+any imported packages, classes and interfaces, searching in the order of the import statement
+.RE
+.LP
+The Javadoc tool continues to search recursively through steps 1\-3 for each class it encounters until it finds a match. That is, after it searches through the current class and its enclosing class E, it will search through E's superclasses before E's enclosing classes.  In steps 4 and 5, the Javadoc tool does not search classes or interfaces within a package in any specified order (that order depends on the particular compiler). In step 5, the Javadoc tool looks in java.lang, since that is automatically imported by all programs.
+.LP
+The Javadoc tool does not necessarily look in subclasses, nor will it look in other packages even if their documentation is being generated in the same run. For example, if the \f2@see\fP tag is in the \f2java.awt.event.KeyEvent\fP class and refers to a name in the \f2java.awt\fP package, javadoc does not look in that package unless that class imports it.
+.LP
+\f3How a name is displayed\fP \- If \f2label\fP is omitted, then \f2package.class.member\fP appears. In general, it is suitably shortened relative to the current class and package. By "shortened", we mean the Javadoc tool displays only the minimum name necessary. For example, if the \f2String.toUpperCase()\fP method contains references to a member of the same class and to a member of a different class, the class name is displayed only in the latter case, as shown in the following table.
+.LP
+Use \-noqualifier to globally remove the package names.
+.br
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81 82
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+\f3Example in \fP\f4String.toUpperCase()\fP
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f2@see\fP tag refers to member of the same class, same package
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 82
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(82 .ll \n(82u
+.in 0
+\f2toLowerCase()\fP (omits the package and class names)
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f2@see\fP tag refers to member of a different class, same package
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+\f2@see Character#toLowerCase(char)\fP
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 82
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(82 .ll \n(82u
+.in 0
+\f2Character.toLowerCase(char)\fP (omits the package name, includes the class name)
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f2@see\fP tag refers to member of a different class, different package
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+\f2@see java.io.File#exists()\fP
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 82
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(82 .ll \n(82u
+.in 0
+\f2java.io.File.exists()\fP (includes the package and class names)
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \w\f3Type of Reference\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 38 \n(b-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(d-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(g-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 81 0
+.nr 38 \w\f2@see String#toLowerCase()\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 82 0
+.nr 38 \w\f3Displays As\fP
+.if \n(82<\n(38 .nr 82 \n(38
+.82
+.rm 82
+.nr 38 \n(c-
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \n(f-
+.if \n(82<\n(38 .nr 82 \n(38
+.nr 38 \n(i-
+.if \n(82<\n(38 .nr 82 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr 42 \n(81+(3*\n(38)
+.nr 82 +\n(42
+.nr TW \n(82
+.if t .if \n(TW>\n(.li .tm Table at line 1440 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Type of Reference\fP\h'|\n(41u'\h'|\n(42u'\f3Displays As\fP
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.ne \n(c|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'\f2@see String#toLowerCase()\fP\h'|\n(42u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(42u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.ne \n(e|u+\n(.Vu
+.ne \n(f|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'\h'|\n(42u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(42u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.ne \n(h|u+\n(.Vu
+.ne \n(i|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'\h'|\n(42u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(42u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-28
+.LP
+\f3Examples of @see\fP
+.br
+The comment to the right shows how the name would be displayed if the \f2@see\fP tag is in a class in another package, such as \f2java.applet.Applet\fP.
+.nf
+\f3
+.fl
+                                           See also:
+.fl
+@see java.lang.String                   //  String                          \fP\f3
+.fl
+@see java.lang.String The String class  //  The String class                \fP\f3
+.fl
+@see String                             //  String                          \fP\f3
+.fl
+@see String#equals(Object)              //  String.equals(Object)           \fP\f3
+.fl
+@see String#equals                      //  String.equals(java.lang.Object) \fP\f3
+.fl
+@see java.lang.Object#wait(long)        //  java.lang.Object.wait(long)     \fP\f3
+.fl
+@see Character#MAX_RADIX                //  Character.MAX_RADIX             \fP\f3
+.fl
+@see <a href="spec.html">Java Spec</a>  //  Java Spec           \fP\f3
+.fl
+@see "The Java Programming Language"    //  "The Java Programming Language"        \fP\f3
+.fl
+\fP
+.fi
+You can extend \f2@see\fP to link to classes not being documented by using the \f2\-link\fP option.
+.LP
+For more details, see
+.na
+\f2writing @see tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#@see.
+.RE
+.RE
+.LP
+.RS 3
+.TP 3
+@serial\  field\-description | include | exclude
+Used in the doc comment for a default serializable field.
+.LP
+An optional \f2field\-description\fP should explain the meaning of the field and list the acceptable values. If needed, the description can span multiple lines. The standard doclet adds this information to the serialized form page.
+.LP
+If a serializable field was added to a class some time after the class was made serializable, a statement should be added to its main description to identify at which version it was added.
+.LP
+The \f2include\fP and \f2exclude\fP arguments identify whether a class or package should be included or excluded from the serialized form page. They work as follows:
+.RS 3
+.TP 2
+o
+A public or protected class that implements \f2Serializable\fP is \f2included\fP unless that class (or its package) is marked \f2@serial exclude\fP.
+.TP 2
+o
+A private or package\-private class that implements \f2Serializable\fP is \f2excluded\fP unless that class (or its package) is marked \f2@serial include\fP.
+.RE
+.LP
+Examples: The \f2javax.swing\fP package is marked \f2@serial exclude\fP (in \f2package.html\fP or \f2package\-info.java\fP). The public class \f2java.security.BasicPermission\fP is marked \f2@serial exclude\fP. The package\-private class \f2java.util.PropertyPermissionCollection\fP is marked \f2@serial include\fP.
+.LP
+The tag @serial at a class level overrides @serial at a package level.
+.LP
+For more information about how to use these tags, along with an example, see "
+.na
+\f2Documenting Serializable Fields and Data for a Class\fP @
+.fi
+http://download.oracle.com/javase/7/docs/platform/serialization/spec/serial\-arch.html," Section 1.6 of the \f2Java Object Serialization Specification\fP. Also see the
+.na
+\f2Serialization FAQ\fP @
+.fi
+http://java.sun.com/javase/technologies/core/basic/serializationFAQ.jsp#javadoc_warn_missing, which covers common questions, such as "Why do I see javadoc warnings stating that I am missing @serial tags for private fields if I am not running javadoc with the \-private switch?". Also see
+.na
+\f2Sun's criteria\fP @
+.fi
+http://java.sun.com/j2se/javadoc/writingapispecs/serialized\-criteria.html for including classes in the serialized form specification.
+.LP
+.TP 3
+@serialField\  field\-name\  field\-type\  field\-description
+Documents an \f2ObjectStreamField\fP component of a \f2Serializable\fP class's \f2serialPersistentFields\fP member. One \f2@serialField\fP tag should be used for each \f2ObjectStreamField\fP component.
+.LP
+.TP 3
+@serialData\  data\-description
+The \f2data\-description\fP documents the types and order of data in the serialized form. Specifically, this data includes the optional data written by the \f2writeObject\fP method and all data (including base classes) written by the \f2Externalizable.writeExternal\fP method.
+.LP
+The \f2@serialData\fP tag can be used in the doc comment for the \f2writeObject\fP, \f2readObject\fP, \f2writeExternal\fP, \f2readExternal\fP, \f2writeReplace\fP, and \f2readResolve\fP methods.
+.LP
+.TP 3
+@since\  since\-text
+Adds a "Since" heading with the specified \f2since\-text\fP to the generated documentation. The text has no special internal structure. This tag is valid in any doc comment: overview, package, class, interface, constructor, method or field. This tag means that this change or feature has existed since the software release specified by the \f2since\-text\fP. For example:
+.nf
+\f3
+.fl
+    @since 1.5
+.fl
+
+.fl
+\fP
+.fi
+.LP
+For source code in the Java platform, this tag indicates the version of the Java platform API specification (not necessarily when it was added to the reference implementation). Multiple @since tags are allowed and are treated like multiple @author tags. You could use multiple tags if the prgram element is used by more than one API.
+.LP
+.TP 3
+@throws\  class\-name\  description
+The \f2@throws\fP and \f2@exception\fP tags are synonyms. Adds a "Throws" subheading to the generated documentation, with the \f2class\-name\fP and \f2description\fP text. The \f2class\-name\fP is the name of the exception that may be thrown by the method. This tag is valid only in the doc comment for a method or constructor. If this class is not fully\-specified, the Javadoc tool uses the search order to look up this class. Multiple \f2@throws\fP tags can be used in a given doc comment for the same or different exceptions.
+.LP
+To ensure that all checked exceptions are documented, if a \f2@throws\fP tag does not exist for an exception in the throws clause, the Javadoc tool automatically adds that exception to the HTML output (with no description) as if it were documented with @throws tag.
+.LP
+The \f2@throws\fP documentation is copied from an overridden method to a subclass only when the exception is explicitly declared in the overridden method. The same is true for copying from an interface method to an implementing method. You can use {@inheritDoc} to force @throws to inherit documentation.
+.LP
+For more details, see
+.na
+\f2writing @throws tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#@exception.
+.LP
+.TP 3
+{@value\  package.class#field}
+When \f2{@value}\fP is used (without any argument) in the doc comment of a static field, it displays the value of that constant:
+.nf
+\f3
+.fl
+    /**
+.fl
+     * The value of this constant is {@value}.
+.fl
+     */
+.fl
+    public static final String SCRIPT_START = "<script>"
+.fl
+
+.fl
+\fP
+.fi
+.LP
+When used with argument \f2package.class#field\fP in any doc comment, it displays the value of the specified constant:
+.nf
+\f3
+.fl
+    /**
+.fl
+     * Evaluates the script starting with {@value #SCRIPT_START}.
+.fl
+     */
+.fl
+    public String evalScript(String script) {
+.fl
+    }
+.fl
+
+.fl
+\fP
+.fi
+.LP
+The argument \f2package.class#field\fP takes a form identical to that of the @see argument, except that the member must be a static field.
+.LP
+These values of these constants are also displayed on the
+.na
+\f2Constant Field Values\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/constant\-values.html page.
+.LP
+.TP 3
+@version\  version\-text
+Adds a "Version" subheading with the specified \f2version\-text\fP to the generated docs when the \-version option is used. This tag is intended to hold the current version number of the software that this code is part of (as opposed to @since, which holds the version number where this code was introduced). The \f2version\-text\fP has no special internal structure. To see where the version tag can be used, see Where Tags Can Be Used.
+.LP
+A doc comment may contain multiple \f2@version\fP tags. If it makes sense, you can specify one version number per \f2@version\fP tag or multiple version numbers per tag. In the former case, the Javadoc tool inserts a comma (\f2,\fP) and space between names. In the latter case, the entire text is simply copied to the generated document without being parsed. Therefore, you can use multiple names per line if you want a localized name separator other than comma.
+.LP
+For more details, see
+.na
+\f2writing @version tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#@version.
+.RE
+.SS
+Where Tags Can Be Used
+.LP
+The following sections describe where the tags can be used. Note that these tags can be used in all doc comments: \f2@see\fP, \f2@since\fP, \f2@deprecated\fP, \f2{@link}\fP, \f2{@linkplain}\fP, and \f2{@docroot}\fP.
+.SS
+Overview Documentation Tags
+.LP
+Overview tags are tags that can appear in the documentation comment for the overview page (which resides in the source file typically named \f2overview.html\fP). Like in any other documentation comments, these tags must appear after the main description.
+.LP
+\f3NOTE\fP \- The \f2{@link}\fP tag has a bug in overview documents in version 1.2 \-\- the text appears properly but has no link. The \f2{@docRoot}\fP tag does not currently work in overview documents.
+.LP
+\f3Overview Tags\fP
+.RS 3
+.TP 2
+o
+\f2@see\fP
+.TP 2
+o
+\f2@since\fP
+.TP 2
+o
+\f2@author\fP
+.TP 2
+o
+\f2@version\fP
+.TP 2
+o
+\f2{@link}\fP
+.TP 2
+o
+\f2{@linkplain}\fP
+.TP 2
+o
+\f2{@docRoot}\fP
+.RE
+.SS
+Package Documentation Tags
+.LP
+Package tags are tags that can appear in the documentation comment for a package (which resides in the source file named \f2package.html\fP or \f2package\-info.java\fP). The \f2@serial\fP tag can only be used here with the \f2include\fP or \f2exclude\fP argument.
+.LP
+\f3Package Tags\fP
+.RS 3
+.TP 2
+o
+\f2@see\fP
+.TP 2
+o
+\f2@since\fP
+.TP 2
+o
+\f2@serial\fP
+.TP 2
+o
+\f2@author\fP
+.TP 2
+o
+\f2@version\fP
+.TP 2
+o
+\f2{@link}\fP
+.TP 2
+o
+\f2{@linkplain}\fP
+.TP 2
+o
+\f2{@docRoot}\fP
+.RE
+.SS
+Class and Interface Documentation Tags
+.LP
+The following are tags that can appear in the documentation comment for a class or interface. The \f2@serial\fP tag can only be used here with the \f2include\fP or \f2exclude\fP argument.
+.LP
+\f3Class/Interface Tags\fP
+.RS 3
+.TP 2
+o
+\f2@see\fP
+.TP 2
+o
+\f2@since\fP
+.TP 2
+o
+\f2@deprecated\fP
+.TP 2
+o
+\f2@serial\fP
+.TP 2
+o
+\f2@author\fP
+.TP 2
+o
+\f2@version\fP
+.TP 2
+o
+\f2{@link}\fP
+.TP 2
+o
+\f2{@linkplain}\fP
+.TP 2
+o
+\f2{@docRoot}\fP
+.RE
+\f3An example of a class comment:\fP
+.nf
+\f3
+.fl
+/**
+.fl
+ * A class representing a window on the screen.
+.fl
+ * For example:
+.fl
+ * <pre>
+.fl
+ *    Window win = new Window(parent);
+.fl
+ *    win.show();
+.fl
+ * </pre>
+.fl
+ *
+.fl
+ * @author  Sami Shaio
+.fl
+ * @version 1.13, 06/08/06
+.fl
+ * @see     java.awt.BaseWindow
+.fl
+ * @see     java.awt.Button
+.fl
+ */
+.fl
+class Window extends BaseWindow {
+.fl
+   ...
+.fl
+}
+.fl
+\fP
+.fi
+.SS
+Field Documentation Tags
+.LP
+The following are the tags that can appear in
+.LP
+\f3Field Tags\fP
+.RS 3
+.TP 2
+o
+\f2@see\fP
+.TP 2
+o
+\f2@since\fP
+.TP 2
+o
+\f2@deprecated\fP
+.TP 2
+o
+\f2@serial\fP
+.TP 2
+o
+\f2@serialField\fP
+.TP 2
+o
+\f2{@link}\fP
+.TP 2
+o
+\f2{@linkplain}\fP
+.TP 2
+o
+\f2{@docRoot}\fP
+.TP 2
+o
+\f2{@value}\fP
+.RE
+\f3An example of a field comment:\fP
+.nf
+\f3
+.fl
+    /**
+.fl
+     * The X\-coordinate of the component.
+.fl
+     *
+.fl
+     * @see #getLocation()
+.fl
+     */
+.fl
+    int x = 1263732;
+.fl
+\fP
+.fi
+.SS
+Constructor and Method Documentation Tags
+.LP
+The following are the tags that can appear in the documentation comment for a constructor or method, except for \f2@return\fP, which cannot appear in a constructor, and \f2{@inheritDoc}\fP, which has certain restrictions. The \f2@serialData\fP tag can only be used in the doc comment for certain serialization methods.
+.LP
+\f3Method/Constructor Tags\fP
+.RS 3
+.TP 2
+o
+\f2@see\fP
+.TP 2
+o
+\f2@since\fP
+.TP 2
+o
+\f2@deprecated\fP
+.TP 2
+o
+\f2@param\fP
+.TP 2
+o
+\f2@return\fP
+.TP 2
+o
+\f2@throws\fP and \f2@exception\fP
+.TP 2
+o
+\f2@serialData\fP
+.TP 2
+o
+\f2{@link}\fP
+.TP 2
+o
+\f2{@linkplain}\fP
+.TP 2
+o
+\f2{@inheritDoc}\fP
+.TP 2
+o
+\f2{@docRoot}\fP
+.RE
+\f3An example of a method doc comment:\fP
+.nf
+\f3
+.fl
+    /**
+.fl
+     * Returns the character at the specified index. An index
+.fl
+     * ranges from <code>0</code> to <code>length() \- 1</code>.
+.fl
+     *
+.fl
+     * @param     index  the index of the desired character.
+.fl
+     * @return    the desired character.
+.fl
+     * @exception StringIndexOutOfRangeException
+.fl
+     *              if the index is not in the range <code>0</code>
+.fl
+     *              to <code>length()\-1</code>.
+.fl
+     * @see       java.lang.Character#charValue()
+.fl
+     */
+.fl
+    public char charAt(int index) {
+.fl
+       ...
+.fl
+    }
+.fl
+\fP
+.fi
+.SH "OPTIONS"
+.LP
+The javadoc tool uses doclets to determine its output. The Javadoc tool uses the default standard doclet unless a custom doclet is specified with the \-doclet option. The Javadoc tool provides a set of command\-line options that can be used with any doclet \-\- these options are described below under the sub\-heading Javadoc Options. The standard doclet provides an additional set of command\-line options that are described below under the sub\-heading Options Provided by the Standard Doclet. All option names are case\-insensitive, though their arguments can be case\-sensitive.
+.LP
+The options are:
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81 82
+.nr 34 \n(.lu
+.eo
+.am 80
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\-\f21.1\fP
+.br
+\-author
+.br
+\-\f2bootclasspath\fP
+.br
+\-bottom
+.br
+\-\f2breakiterator\fP
+.br
+\-charset
+.br
+\-\f2classpath\fP
+.br
+\-d
+.br
+\-docencoding
+.br
+\-docfilessubdirs
+.br
+\-\f2doclet\fP
+.br
+\-\f2docletpath\fP
+.br
+\-doctitle
+.br
+\-\f2encoding\fP
+.br
+\-\f2exclude\fP
+.br
+\-excludedocfilessubdir
+.br
+\-\f2extdirs\fP
+.br
+\-footer
+.br
+\-group
+.br
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+\-header
+.br
+\-\f2help\fP
+.br
+\-helpfile
+.br
+\-\f2J\fP
+.br
+\-keywords
+.br
+\-link
+.br
+\-linkoffline
+.br
+\-linksource
+.br
+\-\f2locale\fP
+.br
+\-nocomment
+.br
+\-nodeprecated
+.br
+\-nodeprecatedlist
+.br
+\-nohelp
+.br
+\-noindex
+.br
+\-nonavbar
+.br
+\-noqualifier
+.br
+\-nosince
+.br
+\-notimestamp
+.br
+\-notree
+.br
+\-\f2overview\fP
+.br
+\-\f2package\fP
+.br
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 82
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/4u
+.if \n(.l<\n(82 .ll \n(82u
+.in 0
+\-\f2private\fP
+.br
+\-\f2protected\fP
+.br
+\-\f2public\fP
+.br
+\-\f2quiet\fP
+.br
+\-serialwarn
+.br
+\-\f2source\fP
+.br
+\-\f2sourcepath\fP
+.br
+\-sourcetab
+.br
+\-splitindex
+.br
+\-stylesheetfile
+.br
+\-\f2subpackages\fP
+.br
+\-tag
+.br
+\-taglet
+.br
+\-tagletpath
+.br
+\-top
+.br
+\-title
+.br
+\-use
+.br
+\-\f2verbose\fP
+.br
+\-version
+.br
+\-windowtitle
+.br
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.80
+.rm 80
+.nr 38 \n(a-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 81 0
+.81
+.rm 81
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 82 0
+.82
+.rm 82
+.nr 38 \n(c-
+.if \n(82<\n(38 .nr 82 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr 42 \n(81+(3*\n(38)
+.nr 82 +\n(42
+.nr TW \n(82
+.if t .if \n(TW>\n(.li .tm Table at line 2015 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ne \n(a|u+\n(.Vu
+.ne \n(b|u+\n(.Vu
+.ne \n(c|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u \n(82u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'\h'|\n(42u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(42u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-127
+.LP
+Options shown in \f2italic\fP are the Javadoc core options, which are provided by the front end of the Javadoc tool and are available to all doclets. The standard doclet itself provides the non\-italic options.
+.SS
+Javadoc Options
+.RS 3
+.TP 3
+\-overview \ path/filename
+Specifies that javadoc should retrieve the text for the overview documentation from the "source" file specified by \f2path/filename\fP and place it on the Overview page (\f2overview\-summary.html\fP). The \f2path/filename\fP is relative to the current directory.
+.br
+.br
+While you can use any name you want for \f2filename\fP and place it anywhere you want for \f2path\fP, a typical thing to do is to name it \f2overview.html\fP and place it in the source tree at the directory that contains the topmost package directories. In this location, no \f2path\fP is needed when documenting packages, since \f2\-sourcepath\fP will point to this file. For example, if the source tree for the \f2java.lang\fP package is \f2/src/classes/java/lang/\fP, then you could place the overview file at \f2/src/classes/overview.html\fP. See Real World Example.
+.br
+.br
+For information about the file specified by \f2path/filename\fP, see overview comment file.
+.br
+.br
+Note that the overview page is created only if you pass into javadoc two or more package names. For further explanation, see HTML Frames.)
+.br
+.br
+The title on the overview page is set by \f2\-doctitle\fP.
+.TP 3
+\-public
+Shows only public classes and members.
+.TP 3
+\-protected
+Shows only protected and public classes and members. This is the default.
+.TP 3
+\-package
+Shows only package, protected, and public classes and members.
+.TP 3
+\-private
+Shows all classes and members.
+.TP 3
+\-help
+Displays the online help, which lists these javadoc and doclet command line options.
+.TP 3
+\-doclet\  class
+Specifies the class file that starts the doclet used in generating the documentation. Use the fully\-qualified name. This doclet defines the content and formats the output. If the \f4\-doclet\fP option is not used, javadoc uses the standard doclet for generating the default HTML format. This class must contain the \f2start(Root)\fP method. The path to this starting class is defined by the \f2\-docletpath\fP option.
+.br
+.br
+For example, to call the MIF doclet, use:
+.nf
+\f3
+.fl
+    \-doclet com.sun.tools.doclets.mif.MIFDoclet
+.fl
+\fP
+.fi
+For full, working examples of running a particular doclet, see the
+.na
+\f2MIF Doclet documentation\fP @
+.fi
+http://java.sun.com/j2se/javadoc/mifdoclet/docs/mifdoclet.html.
+.TP 3
+\-docletpath\  classpathlist
+Specifies the path to the doclet starting class file (specified with the \f2\-doclet\fP option) and any jar files it depends on. If the starting class file is in a jar file, then this specifies the path to that jar file, as shown in the example below. You can specify an absolute path or a path relative to the current directory. If \f2classpathlist\fP contains multiple paths or jar files, they should be separated with a colon (:) on Solaris and a semi\-colon (;) on Windows. This option is not necessary if the doclet starting class is already in the search path.
+.br
+.br
+Example of path to jar file that contains the starting doclet class file. Notice the jar filename is included.
+.nf
+\f3
+.fl
+   \-docletpath /home/user/mifdoclet/lib/mifdoclet.jar
+.fl
+\fP
+.fi
+Example of path to starting doclet class file. Notice the class filename is omitted.
+.nf
+\f3
+.fl
+   \-docletpath /home/user/mifdoclet/classes/com/sun/tools/doclets/mif/
+.fl
+\fP
+.fi
+For full, working examples of running a particular doclet, see the
+.na
+\f2MIF Doclet documentation\fP @
+.fi
+http://java.sun.com/j2se/javadoc/mifdoclet/docs/mifdoclet.html.
+.TP 3
+\-1.1
+\f2This feature has been removed from Javadoc 1.4. There is no replacement for it. This option created documentation with the appearance and functionality of documentation generated by Javadoc 1.1 (it never supported nested classes). If you need this option, use Javadoc 1.2 or 1.3 instead.\fP
+.TP 3
+\-source release
+Specifies the version of source code accepted. The following values for \f2release\fP are allowed:
+.RS 3
+.TP 2
+o
+\f31.5\fP \- javadoc accepts code containing generics and other language features introduced in JDK 1.5. The compiler defaults to the 1.5 behavior if the \f3\-source\fP flag is not used.
+.TP 2
+o
+\f31.4\fP \- javadoc accepts code containing assertions, which were introduced in JDK 1.4.
+.TP 2
+o
+\f31.3\fP \- javadoc does \f2not\fP support assertions, generics, or other language features introduced after JDK 1.3.
+.RE
+Use the value of \f2release\fP corresponding to that used when compiling the code with javac.
+.TP 3
+\-sourcepath\  sourcepathlist
+Specifies the search paths for finding source files (\f2.java\fP) when passing package names or \f2\-subpackages\fP into the \f2javadoc\fP command. The \f2sourcepathlist\fP can contain multiple paths by separating them with a colon (\f2:\fP). The Javadoc tool will search in all subdirectories of the specified paths. Note that this option is not only used to locate the source files being documented, but also to find source files that are not being documented but whose comments are inherited by the source files being documented.
+.br
+.br
+Note that you can use the \f2\-sourcepath\fP option only when passing package names into the javadoc command \-\- it will not locate \f2.java\fP files passed into the \f2javadoc\fP command. (To locate \f2.java\fP files, cd to that directory or include the path ahead of each file, as shown at Documenting One or More Classes.) If \f2\-sourcepath\fP is omitted, javadoc uses the class path to find the source files (see \-classpath). Therefore, the default \-sourcepath is the value of class path. If \-classpath is omitted and you are passing package names into javadoc, it looks in the current directory (and subdirectories) for the source files.
+.br
+.br
+Set \f2sourcepathlist\fP to the root directory of the source tree for the package you are documenting. For example, suppose you want to document a package called \f2com.mypackage\fP whose source files are located at:
+.nf
+\f3
+.fl
+  /home/user/src/com/mypackage/*.java
+.fl
+\fP
+.fi
+In this case you would specify the \f2sourcepath\fP to \f2/home/user/src\fP, the directory that contains \f2com/mypackage\fP, and then supply the package name \f2com.mypackage\fP:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-sourcepath /home/user/src/ com.mypackage\fP
+.fl
+.fi
+This is easy to remember by noticing that if you concatenate the value of sourcepath and the package name together and change the dot to a slash "/", you end up with the full path to the package: \f2/home/user/src/com/mypackage\fP.
+.br
+.br
+To point to two source paths:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-sourcepath /home/user1/src:/home/user2/src com.mypackage\fP
+.fl
+.fi
+.TP 3
+\-classpath\  classpathlist
+Specifies the paths where javadoc will look for referenced classes (\f2.class\fP files) \-\- these are the documented classes plus any classes referenced by those classes. The \f2classpathlist\fP can contain multiple paths by separating them with a colon (\f2:\fP). The Javadoc tool will search in all subdirectories of the specified paths. Follow the instructions in
+.na
+\f2class path\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#general documentation for specifying \f2classpathlist\fP.
+.br
+.br
+If \f2\-sourcepath\fP is omitted, the Javadoc tool uses \f2\-classpath\fP to find the source files as well as class files (for backward compatibility). Therefore, if you want to search for source and class files in separate paths, use both \f2\-sourcepath\fP and \f2\-classpath\fP.
+.br
+.br
+For example, if you want to document \f2com.mypackage\fP, whose source files reside in the directory \f2/home/user/src/com/mypackage\fP, and if this package relies on a library in \f2/home/user/lib\fP, you would specify:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-classpath /home/user/lib \-sourcepath /home/user/src com.mypackage\fP
+.fl
+.fi
+As with other tools, if you do not specify \f2\-classpath\fP, the Javadoc tool uses the CLASSPATH environment variable, if it is set. If both are not set, the Javadoc tool searches for classes from the current directory.
+.br
+.br
+For an in\-depth description of how the Javadoc tool uses \f2\-classpath\fP to find user classes as it relates to extension classes and bootstrap classes, see
+.na
+\f2How Classes Are Found\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/findingclasses.html.
+.br
+.br
+As a special convenience, a class path element containing a basename of \f2*\fP is considered equivalent to specifying a list of all the files in the directory with the extension \f2.jar\fP or \f2.JAR\fP (a Java program cannot tell the difference between the two invocations).
+.br
+.br
+For example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to a \f2A.jar:b.JAR\fP, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of \f2*\fP expands to a list of all the jar files in the current directory. The \f2CLASSPATH\fP environment variable, where defined, will be similarly expanded. Any classpath wildcard expansion occurs before the Java virtual machine is started \-\- no Java program will ever see unexpanded wildcards except by querying the environment. For example; by invoking \f2System.getenv("CLASSPATH")\fP.
+.TP 3
+\-subpackages\ \ package1:package2:...
+Generates documentation from source files in the specified packages and recursively in their subpackages. This option is useful when adding new subpackages to the source code, as they are automatically included. Each \f2package\fP argument is any top\-level subpackage (such as \f2java\fP) or fully qualified package (such as \f2javax.swing\fP) that does not need to contain source files. Arguments are separated by colons (on all operating systmes). Wildcards are not needed or allowed. Use \f2\-sourcepath\fP to specify where to find the packages. This option is smart about not processing source files that are in the source tree but do not belong to the packages, as described at processing of source files.
+.br
+.br
+For example:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d docs \-sourcepath /home/user/src \-subpackages java:javax.swing\fP
+.fl
+.fi
+This command generates documentation for packages named "java" and "javax.swing" and all their subpackages.
+.br
+.br
+You can use \f2\-subpackages\fP in conjunction with \f2\-exclude\fP to exclude specific packages.
+.TP 3
+\-exclude\ \ packagename1:packagename2:...
+Unconditionally excludes the specified packages and their subpackages from the list formed by \f2\-subpackages\fP. It excludes those packages even if they would otherwise be included by some previous or later \f2\-subpackages\fP option. For example:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-sourcepath /home/user/src \-subpackages java \-exclude java.net:java.lang\fP
+.fl
+.fi
+would include \f2java.io\fP, \f2java.util\fP, and \f2java.math\fP (among others), but would exclude packages rooted at \f2java.net\fP and \f2java.lang\fP. Notice this excludes \f2java.lang.ref\fP, a subpackage of \f2java.lang\fP).
+.TP 3
+\-bootclasspath\  classpathlist
+Specifies the paths where the boot classes reside. These are nominally the Java platform classes. The bootclasspath is part of the search path the Javadoc tool will use to look up source and class files. See
+.na
+\f2How Classes Are Found\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/findingclasses.html#srcfiles. for more details. Separate directories in \f2classpathlist\fP with colons (:).
+.TP 3
+\-extdirs\  dirlist
+Specifies the directories where extension classes reside. These are any classes that use the Java Extension mechanism. The extdirs is part of the search path the Javadoc tool will use to look up source and class files. See \f2\-classpath\fP (above) for more details. Separate directories in \f2dirlist\fP with colons (:).
+.TP 3
+\-verbose
+Provides more detailed messages while javadoc is running. Without the verbose option, messages appear for loading the source files, generating the documentation (one message per source file), and sorting. The verbose option causes the printing of additional messages specifying the number of milliseconds to parse each java source file.
+.TP 3
+\-quiet
+Shuts off non\-error and non\-warning messages, leaving only the warnings and errors appear, making them easier to view. Also suppresses the version string.
+.TP 3
+\-breakiterator\
+Uses the internationalized sentence boundary of
+.na
+\f2java.text.BreakIterator\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/java/text/BreakIterator.html to determine the end of the first sentence for English (all other locales already use \f2BreakIterator\fP), rather than an English language, locale\-specific algorithm. By \f2first sentence\fP, we mean the first sentence in the main description of a package, class or member. This sentence is copied to the package, class or member summary, and to the alphabetic index.
+.br
+.br
+From JDK 1.2 forward, the BreakIterator class is already used to determine the end of sentence for all languages but English. Therefore, the \f2\-breakiterator\fP option has no effect except for English from 1.2 forward. English has its own default algorithm:
+.RS 3
+.TP 2
+o
+English default sentence\-break algorithm \- Stops at a period followed by a space or a HTML block tag, such as \f2<P>\fP.
+.TP 2
+o
+Breakiterator sentence\-break algorithm \- In general, stops at a period, question mark or exclamation mark followed by a space if the next word starts with a capital letter. This is meant to handle most abbreviations (such as "The serial no. is valid", but won't handle "Mr. Smith"). Doesn't stop at HTML tags or sentences that begin with numbers or symbols. Stops at the last period in "../filename", even if embedded in an HTML tag.
+.RE
+NOTE: We have removed from 1.5.0 the breakiterator warning messages that were in 1.4.x and have left the default sentence\-break algorithm unchanged. That is, the \-breakiterator option is not the default in 1.5.0, nor do we expect it to become the default. This is a reversal from our former intention that the default would change in the "next major release" (1.5.0). This means if you have not modified your source code to eliminate the breakiterator warnings in 1.4.x, then you don't have to do anything, and the warnings go away starting with 1.5.0. The reason for this reversal is because any benefit to having breakiterator become the default would be outweighed by the incompatible source change it would require. We regret any extra work and confusion this has caused.
+.TP 3
+\-locale\  language_country_variant
+\f3Important\fP \- The \f2\-locale\fP option must be placed \f2ahead\fP (to the left) of any options provided by the standard doclet or any other doclet. Otherwise, the navigation bars will appear in English. This is the only command\-line option that is order\-dependent.
+.br
+.br
+Specifies the locale that javadoc uses when generating documentation. The argument is the name of the locale, as described in java.util.Locale documentation, such as \f2en_US\fP (English, United States) or \f2en_US_WIN\fP (Windows variant).
+.br
+.br
+Specifying a locale causes javadoc to choose the resource files of that locale for messages (strings in the navigation bar, headings for lists and tables, help file contents, comments in stylesheet.css, and so forth). It also specifies the sorting order for lists sorted alphabetically, and the sentence separator to determine the end of the first sentence. It does not determine the locale of the doc comment text specified in the source files of the documented classes.
+.TP 3
+\-encoding\  name
+Specifies the encoding name of the source files, such as \f2EUCJIS/SJIS\fP. If this option is not specified, the platform default converter is used.
+.br
+.br
+Also see \-docencoding and \-charset.
+.TP 3
+\-Jflag
+Passes \f2flag\fP directly to the runtime system java that runs javadoc. Notice there must be no space between the \f2J\fP and the \f2flag\fP. For example, if you need to ensure that the system sets aside 32 megabytes of memory in which to process the generated documentation, then you would call the \f2\-Xmx\fP option of java as follows (\f2\-Xms\fP is optional, as it only sets the size of initial memory, which is useful if you know the minimum amount of memory required):
+.nf
+\f3
+.fl
+   % \fP\f3javadoc \-J\-Xmx32m \-J\-Xms32m\fP \f3com.mypackage\fP
+.fl
+.fi
+To tell what version of javadoc you are using, call the "\f2\-version\fP" option of java:
+.nf
+\f3
+.fl
+   % \fP\f3javadoc \-J\-version\fP
+.fl
+   java version "1.2"
+.fl
+   Classic VM (build JDK\-1.2\-V, green threads, sunwjit)
+.fl
+.fi
+(The version number of the standard doclet appears in its output stream.)
+.RE
+.SS
+Options Provided by the Standard Doclet
+.RS 3
+.TP 3
+\-d\  directory
+Specifies the destination directory where javadoc saves the generated HTML files. (The "d" means "destination.") Omitting this option causes the files to be saved to the current directory. The value \f2directory\fP can be absolute, or relative to the current working directory. As of 1.4, the destination directory is automatically created when javadoc is run.
+.br
+.br
+For example, the following generates the documentation for the package \f2com.mypackage\fP and saves the results in the \f2/home/user/doc/\fP directory:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d /home/user/doc com.mypackage\fP
+.fl
+.fi
+.TP 3
+\-use
+Includes one "Use" page for each documented class and package. The page describes what packages, classes, methods, constructors and fields use any API of the given class or package. Given class C, things that use class C would include subclasses of C, fields declared as C, methods that return C, and methods and constructors with parameters of type C.
+.br
+.br
+For example, let us look at what might appear on the "Use" page for String. The \f2getName()\fP method in the \f2java.awt.Font\fP class returns type \f2String\fP. Therefore, \f2getName()\fP uses \f2String\fP, and you will find that method on the "Use" page for \f2String\fP.
+.br
+.br
+Note that this documents only uses of the API, not the implementation. If a method uses \f2String\fP in its implementation but does not take a string as an argument or return a string, that is not considered a "use" of \f2String\fP.
+.br
+.br
+You can access the generated "Use" page by first going to the class or package, then clicking on the "Use" link in the navigation bar.
+.TP 3
+\-version
+Includes the @version text in the generated docs. This text is omitted by default. To tell what version of the Javadoc tool you are using, use the \f2\-J\-version\fP option.
+.TP 3
+\-author
+Includes the @author text in the generated docs.
+.TP 3
+\-splitindex
+Splits the index file into multiple files, alphabetically, one file per letter, plus a file for any index entries that start with non\-alphabetical characters.
+.TP 3
+\-windowtitle\  title
+Specifies the title to be placed in the HTML <title> tag. This appears in the window title and in any browser bookmarks (favorite places) that someone creates for this page. This title should not contain any HTML tags, as the browser will not properly interpret them. Any internal quotation marks within \f2title\fP may have to be escaped. If \-windowtitle is omitted, the Javadoc tool uses the value of \-doctitle for this option.
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-windowtitle "Java SE Platform" com.mypackage\fP
+.fl
+.fi
+.TP 3
+\-doctitle\  title
+Specifies the title to be placed near the top of the overview summary file. The title will be placed as a centered, level\-one heading directly beneath the upper navigation bar. The \f2title\fP may contain html tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within \f2title\fP may have to be escaped.
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-doctitle "Java(TM)" com.mypackage\fP
+.fl
+.fi
+.TP 3
+\-title\  title
+\f3This option no longer exists.\fP It existed only in Beta versions of Javadoc 1.2. It has been renamed to \f2\-doctitle\fP. This option is being renamed to make it clear that it defines the document title rather than the window title.
+.TP 3
+\-header\  header
+Specifies the header text to be placed at the top of each output file. The header will be placed to the right of the upper navigation bar. \f2header\fP may contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within \f2header\fP may have to be escaped.
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-header "<b>Java 2 Platform </b><br>v1.4" com.mypackage\fP
+.fl
+.fi
+.TP 3
+\-footer\  footer
+Specifies the footer text to be placed at the bottom of each output file. The footer will be placed to the right of the lower navigation bar. \f2footer\fP may contain html tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within \f2footer\fP may have to be escaped.
+.TP 3
+\-top
+Specifies the text to be placed at the top of each output file.
+.TP 3
+\-bottom\  text
+Specifies the text to be placed at the bottom of each output file. The text will be placed at the bottom of the page, below the lower navigation bar. The \f2text\fP may contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within \f2text\fP may have to be escaped.
+.TP 3
+\-link\  extdocURL
+Creates links to existing javadoc\-generated documentation of external referenced classes. It takes one argument:
+.RS 3
+.TP 2
+o
+\f4extdocURL\fP is the absolute or relative URL of the directory containing the external javadoc\-generated documentation you want to link to. Examples are shown below. The package\-list file must be found in this directory (otherwise, use \f2\-linkoffline\fP). The Javadoc tool reads the package names from the \f2package\-list\fP file and then links to those packages at that URL. When the Javadoc tool is run, the \f2extdocURL\fP value is copied literally into the \f2<A HREF>\fP links that are created. Therefore, \f2extdocURL\fP must be the URL to the \f2directory\fP, not to a file.
+.br
+.br
+You can use an absolute link for \f2extdocURL\fP to enable your docs to link to a document on any website, or can use a relative link to link only to a relative location. If relative, the value you pass in should be the relative path from the destination directory (specified with \f2\-d\fP) to the directory containing the packages being linked to.
+.br
+.br
+When specifying an absolute link you normally use an \f2http:\fP link. However, if you want to link to a file system that has no web server, you can use a \f2file:\fP link \-\- however, do this only if everyone wanting to access the generated documentation shares the same file system.
+.br
+.br
+In all cases, and on all operating systems, you should use a forward slash as the separator, whether the URL is absolute or relative, and "http:" or "file:" based (as specified in the
+.na
+\f2URL Memo\fP @
+.fi
+http://www.ietf.org/rfc/rfc1738.txt).
+.RS 3
+.TP 3
+Absolute http: based link:
+\f2\-link http://<host>/<directory>/<directory>/.../<name>\fP
+.TP 3
+Absolute file: based link:
+\f2\-link file://<host>/<directory>/<directory>/.../<name>\fP
+.TP 3
+Relative link:
+\f2\-link <directory>/<directory>/.../<name>\fP
+.RE
+.RE
+You can specify multiple \f2\-link\fP options in a given javadoc run to link to multiple documents.
+.br
+.br
+\f3Choosing between \-linkoffline and \-link\fP:
+.br
+.br
+Use \f2\-link\fP:
+.RS 3
+.TP 2
+o
+when using a relative path to the external API document, or
+.TP 2
+o
+when using an absolute URL to the external API document, if your shell allows a program to open a connection to that URL for reading.
+.RE
+Use \f2\-linkoffline\fP:
+.RS 3
+.TP 2
+o
+when using an absolute URL to the external API document, if your shell \f2does not allow\fP a program to open a connection to that URL for reading. This can occur if you are behind a firewall and the document you want to link to is on the other side.
+.RE
+.br
+.br
+\f3Example using absolute links to the external docs\fP \- Let us say you want to link to the \f2java.lang\fP, \f2java.io\fP and other Java Platform packages at
+.na
+\f2http://download.oracle.com/javase/7/docs/api/\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/. The following command generates documentation for the package \f2com.mypackage\fP with links to the Java SE Platform packages. The generated documentation will contain links to the \f2Object\fP class, for example, in the class trees. (Other options, such as \f2\-sourcepath\fP and \f2\-d\fP, are not shown.)
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-link http://download.oracle.com/javase/7/docs/api/ com.mypackage\fP
+.fl
+.fi
+\f3Example using relative links to the external docs\fP \- Let us say you have two packages whose docs are generated in different runs of the Javadoc tool, and those docs are separated by a relative path. In this example, the packages are \f2com.apipackage\fP, an API, and \f2com.spipackage\fP, an SPI (Service Provide Interface). You want the documentation to reside in \f2docs/api/com/apipackage\fP and \f2docs/spi/com/spipackage\fP. Assuming the API package documentation is already generated, and that \f2docs\fP is the current directory, you would document the SPI package with links to the API documentation by running:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d ./spi \-link ../api com.spipackage\fP
+.fl
+.fi
+Notice the \f2\-link\fP argument is relative to the destination directory (\f2docs/spi\fP).
+.br
+.br
+\f3Details\fP \- The \f2\-link\fP option enables you to link to classes referenced to by your code but \f2not\fP documented in the current javadoc run. For these links to go to valid pages, you must know where those HTML pages are located, and specify that location with \f2extdocURL\fP. This allows, for instance, third party documentation to link to \f2java.*\fP documentation on \f2http://java.sun.com\fP.
+.br
+.br
+Omit the \f2\-link\fP option for javadoc to create links only to API within the documentation it is generating in the current run. (Without the \f2\-link\fP option, the Javadoc tool does not create links to documentation for external references, because it does not know if or where that documentation exists.)
+.br
+.br
+This option can create links in several places in the generated documentation.
+.br
+.br
+Another use is for cross\-links between sets of packages: Execute javadoc on one set of packages, then run javadoc again on another set of packages, creating links both ways between both sets.
+.br
+.br
+\f3How a Class Must be Referenced\fP \- For a link to an external referenced class to actually appear (and not just its text label), the class must be referenced in the following way. It is not sufficient for it to be referenced in the body of a method. It must be referenced in either an \f2import\fP statement or in a declaration. Here are examples of how the class \f2java.io.File\fP can be referenced:
+.RS 3
+.TP 2
+o
+In any kind of \f2import\fP statement: by wildcard import, import explicitly by name, or automatically import for \f2java.lang.*\fP. For example, this would suffice:
+.br
+\f2import java.io.*;\fP
+.br
+In 1.3.x and 1.2.x, only an explicit import by name works \-\- a wildcard import statement does not work, nor does the automatic import \f2java.lang.*\fP.
+.TP 2
+o
+In a declaration:
+.br
+\f2void foo(File f) {}\fP
+.br
+The reference and be in the return type or parameter type of a method, constructor, field, class or interface, or in an \f2implements\fP, \f2extends\fP or \f2throws\fP statement.
+.RE
+An important corollary is that when you use the \f2\-link\fP option, there may be many links that unintentionally do not appear due to this constraint. (The text would appear without a hypertext link.) You can detect these by the warnings they emit. The most innocuous way to properly reference a class and thereby add the link would be to import that class, as shown above.
+.br
+.br
+\f3Package List\fP \- The \f2\-link\fP option requires that a file named \f2package\-list\fP, which is generated by the Javadoc tool, exist at the URL you specify with \f2\-link\fP. The \f2package\-list\fP file is a simple text file that lists the names of packages documented at that location. In the earlier example, the Javadoc tool looks for a file named \f2package\-list\fP at the given URL, reads in the package names and then links to those packages at that URL.
+.br
+.br
+For example, the package list for the Java SE 6 API is located at
+.na
+\f2http://download.oracle.com/javase/7/docs/api/package\-list\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/package\-list. and starts as follows:
+.nf
+\f3
+.fl
+  java.applet
+.fl
+  java.awt
+.fl
+  java.awt.color
+.fl
+  java.awt.datatransfer
+.fl
+  java.awt.dnd
+.fl
+  java.awt.event
+.fl
+  java.awt.font
+.fl
+  etc.
+.fl
+\fP
+.fi
+When javadoc is run without the \f2\-link\fP option, when it encounters a name that belongs to an external referenced class, it prints the name with no link. However, when the \f2\-link\fP option is used, the Javadoc tool searches the \f2package\-list\fP file at the specified \f2extdocURL\fP location for that package name. If it finds the package name, it prefixes the name with \f2extdocURL\fP.
+.br
+.br
+In order for there to be no broken links, all of the documentation for the external references must exist at the specified URLs. The Javadoc tool will not check that these pages exist \-\- only that the package\-list exists.
+.br
+.br
+\f3Multiple Links\fP \- You can supply multiple \f2\-link\fP options to link to any number of external generated documents. \  Javadoc 1.2 has a known bug which prevents you from supplying more than one \f2\-link\fP command. This was fixed in 1.2.2.
+.br
+.br
+Specify a different link option for each external document to link to:
+.br
+.br
+\ \  \f2% \fP\f4javadoc \-link\fP \f2extdocURL1\fP \f4\-link\fP \f2extdocURL2\fP \f2... \fP\f4\-link\fP \f2extdocURLn\fP \f4com.mypackage\fP
+.br
+.br
+where \f2extdocURL1\fP,\  \f2extdocURL2\fP,\  ... \f2extdocURLn\fP point respectively to the roots of external documents, each of which contains a file named \f2package\-list\fP.
+.br
+.br
+\f3Cross\-links\fP \- Note that "bootstrapping" may be required when cross\-linking two or more documents that have not previously been generated. In other words, if \f2package\-list\fP does not exist for either document, when you run the Javadoc tool on the first document, the \f2package\-list\fP will not yet exist for the second document. Therefore, to create the external links, you must re\-generate the first document after generating the second document.
+.br
+.br
+In this case, the purpose of first generating a document is to create its \f2package\-list\fP (or you can create it by hand it if you're certain of the package names). Then generate the second document with its external links. The Javadoc tool prints a warning if a needed external \f2package\-list\fP file does not exist.
+.TP 3
+\-linkoffline\  extdocURL\  packagelistLoc
+This option is a variation of \f2\-link\fP; they both create links to javadoc\-generated documentation for external referenced classes. Use the \f2\-linkoffline\fP option when linking to a document on the web when the Javadoc tool itself is "offline" \-\- that is, it cannot access the document through a web connection.
+.br
+.br
+More specifically, use \f2\-linkoffline\fP if the external document's \f2package\-list\fP file is not accessible or does not exist at the \f2extdocURL\fP location but does exist at a different location, which can be specified by \f2packageListLoc\fP (typically local). Thus, if \f2extdocURL\fP is accessible only on the World Wide Web, \f2\-linkoffline\fP removes the constraint that the Javadoc tool have a web connection when generating the documentation.
+.br
+.br
+Another use is as a "hack" to update docs: After you have run javadoc on a full set of packages, then you can run javadoc again on onlya smaller set of changed packages, so that the updated files can be inserted back into the original set. Examples are given below.
+.br
+.br
+The \f2\-linkoffline\fP option takes two arguments \-\- the first for the string to be embedded in the \f2<a href>\fP links, the second telling it where to find \f2package\-list\fP:
+.RS 3
+.TP 2
+o
+\f4extdocURL\fP is the absolute or relative URL of the directory containing the external javadoc\-generated documentation you want to link to. If relative, the value should be the relative path from the destination directory (specified with \f2\-d\fP) to the root of the packages being linked to. For more details, see \f2extdocURL\fP in the \f2\-link\fP option.
+.TP 2
+o
+\f4packagelistLoc\fP is the path or URL to the directory containing the \f2package\-list\fP file for the external documentation. This can be a URL (http: or file:) or file path, and can be absolute or relative. If relative, make it relative to the \f2current\fP directory from where javadoc was run. Do not include the \f2package\-list\fP filename.
+.RE
+You can specify multiple \f2\-linkoffline\fP options in a given javadoc run. (Prior to 1.2.2, it could be specified only once.)
+.br
+.br
+\f3Example using absolute links to the external docs\fP \- Let us say you want to link to the \f2java.lang\fP, \f2java.io\fP and other Java SE Platform packages at \f2http://download.oracle.com/javase/7/docs/api/\fP, but your shell does not have web access. You could open the \f2package\-list\fP file in a browser at
+.na
+\f2http://download.oracle.com/javase/7/docs/api/package\-list\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/package\-list, save it to a local directory, and point to this local copy with the second argument, \f2packagelistLoc\fP. In this example, the package list file has been saved to the current directory "\f2.\fP" . The following command generates documentation for the package \f2com.mypackage\fP with links to the Java SE Platform packages. The generated documentation will contain links to the \f2Object\fP class, for example, in the class trees. (Other necessary options, such as \f2\-sourcepath\fP, are not shown.)
+.nf
+\f3
+.fl
+% \fP\f3javadoc \-linkoffline http://download.oracle.com/javase/7/docs/api/ . com.mypackage\fP
+.fl
+.fi
+\f3Example using relative links to the external docs\fP \- It's not very common to use \f2\-linkoffline\fP with relative paths, for the simple reason that \f2\-link\fP usually suffices. When using \f2\-linkoffline\fP, the \f2package\-list\fP file is generally local, and when using relative links, the file you are linking to is also generally local. So it is usually unnecessary to give a different path for the two arguments to \f2\-linkoffline\fP. When the two arguments are identical, you can use \f2\-link\fP. See the \f2\-link\fP relative example.
+.br
+.br
+\f3Manually Creating a \fP\f4package\-list\fP\f3 File\fP \- If a \f2package\-list\fP file does not yet exist, but you know what package names your document will link to, you can create your own copy of this file by hand and specify its path with \f2packagelistLoc\fP. An example would be the previous case where the package list for \f2com.spipackage\fP did not exist when \f2com.apipackage\fP was first generated. This technique is useful when you need to generate documentation that links to new external documentation whose package names you know, but which is not yet published. This is also a way of creating \f2package\-list\fP files for packages generated with Javadoc 1.0 or 1.1, where \f2package\-list\fP files were not generated. Likewise, two companies can share their unpublished \f2package\-list\fP files, enabling them to release their cross\-linked documentation simultaneously.
+.br
+.br
+\f3Linking to Multiple Documents\fP \- You can include \f2\-linkoffline\fP once for each generated document you want to refer to (each option is shown on a separate line for clarity):
+.br
+.br
+\f2% \fP\f4javadoc \-linkoffline\fP \f2extdocURL1\fP \f2packagelistLoc1\fP \f2\\\fP
+.br
+\f2\ \ \ \ \ \ \ \ \ \ \fP\f4\-linkoffline\fP \f2extdocURL2\fP \f2packagelistLoc2\fP \f2\\\fP
+.br
+\f2\ \ \ \ \ \ \ \ \ \ ...\fP
+.br
+.br
+\f3Updating docs\fP \- Another use for \f2\-linkoffline\fP option is useful if your project has dozens or hundreds of packages, if you have already run javadoc on the entire tree, and now, in a separate run, you want to quickly make some small changes and re\-run javadoc on just a small portion of the source tree. This is somewhat of a hack in that it works properly only if your changes are only to doc comments and not to declarations. If you were to add, remove or change any declarations from the source code, then broken links could show up in the index, package tree, inherited member lists, use page, and other places.
+.br
+.br
+First, you create a new destination directory (call it \f2update\fP) for this new small run. Let us say the original destination directory was named \f2html\fP. In the simplest example, cd to the parent of \f2html\fP. Set the first argument of \f2\-linkoffline\fP to the current directory "." and set the second argument to the relative path to \f2html\fP, where it can find \f2package\-list\fP, and pass in only the package names of the packages you want to update:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d update \-linkoffline . html com.mypackage\fP
+.fl
+.fi
+When the Javadoc tool is done, copy these generated class pages in \f2update/com/package\fP (not the overview or index), over the original files in \f2html/com/package\fP.
+.TP 3
+\-linksource\
+Creates an HTML version of each source file (with line numbers) and adds links to them from the standard HTML documentation. Links are created for classes, interfaces, constructors, methods and fields whose declarations are in a source file. Otherwise, links are not created, such as for default constructors and generated classes.
+.br
+.br
+\f3This option exposes \fP\f4all\fP\f3 private implementation details in the included source files, including private classes, private fields, and the bodies of private methods, \fP\f4regardless of the \fP\f4\-public\fP\f3, \fP\f4\-package\fP\f3, \fP\f4\-protected\fP\f3 and \fP\f4\-private\fP\f3 options.\fP Unless you also use the \f2\-private\fP option, not all private classes or interfaces will necessarily be accessible via links.
+.br
+.br
+Each link appears on the name of the identifier in its declaration. For example, the link to the source code of the \f2Button\fP class would be on the word "Button":
+.nf
+\f3
+.fl
+    public class Button
+.fl
+    extends Component
+.fl
+    implements Accessible
+.fl
+\fP
+.fi
+and the link to the source code of the \f2getLabel()\fP method in the Button class would be on the word "getLabel":
+.nf
+\f3
+.fl
+    public String getLabel()
+.fl
+\fP
+.fi
+.TP 3
+\-group\  groupheading\  packagepattern:packagepattern:...
+Separates packages on the overview page into whatever groups you specify, one group per table. You specify each group with a different \f2\-group\fP option. The groups appear on the page in the order specified on the command line; packages are alphabetized within a group. For a given \f2\-group\fP option, the packages matching the list of \f2packagepattern\fP expressions appear in a table with the heading \f2groupheading\fP.
+.RS 3
+.TP 2
+o
+\f4groupheading\fP can be any text, and can include white space. This text is placed in the table heading for the group.
+.TP 2
+o
+\f4packagepattern\fP can be any package name, or can be the start of any package name followed by an asterisk (\f2*\fP). The asterisk is a wildcard meaning "match any characters". This is the only wildcard allowed. Multiple patterns can be included in a group by separating them with colons (\f2:\fP).
+.RE
+\f3NOTE: If using an asterisk in a pattern or pattern list, the pattern list must be inside quotes, such as \fP\f4"java.lang*:java.util"\fP
+.br
+.br
+If you do not supply any \f2\-group\fP option, all packages are placed in one group with the heading "Packages". If the all groups do not include all documented packages, any leftover packages appear in a separate group with the heading "Other Packages".
+.br
+.br
+For example, the following option separates the four documented packages into core, extension and other packages. Notice the trailing "dot" does not appear in "java.lang*" \-\- including the dot, such as "java.lang.*" would omit the java.lang package.
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-group "Core Packages" "java.lang*:java.util"
+.fl
+            \-group "Extension Packages" "javax.*"
+.fl
+            java.lang java.lang.reflect java.util javax.servlet java.new\fP
+.fl
+.fi
+This results in the groupings:
+.RS 3
+.TP 3
+Core Packages
+\f2java.lang\fP
+\f2java.lang.reflect\fP
+\f2java.util\fP
+.TP 3
+Extension Packages
+\f2javax.servlet\fP
+.TP 3
+Other Packages
+\f2java.new\fP
+.RE
+.TP 3
+\-nodeprecated
+Prevents the generation of any deprecated API at all in the documentation. This does what \-nodeprecatedlist does, plus it does not generate any deprecated API throughout the rest of the documentation. This is useful when writing code and you don't want to be distracted by the deprecated code.
+.TP 3
+\-nodeprecatedlist
+Prevents the generation of the file containing the list of deprecated APIs (deprecated\-list.html) and the link in the navigation bar to that page. (However, javadoc continues to generate the deprecated API throughout the rest of the document.) This is useful if your source code contains no deprecated API, and you want to make the navigation bar cleaner.
+.TP 3
+\-nosince
+Omits from the generated docs the "Since" sections associated with the @since tags.
+.TP 3
+\-notree
+Omits the class/interface hierarchy pages from the generated docs. These are the pages you reach using the "Tree" button in the navigation bar. The hierarchy is produced by default.
+.TP 3
+\-noindex
+Omits the index from the generated docs. The index is produced by default.
+.TP 3
+\-nohelp
+Omits the HELP link in the navigation bars at the top and bottom of each page of output.
+.TP 3
+\-nonavbar
+Prevents the generation of the navigation bar, header and footer, otherwise found at the top and bottom of the generated pages. Has no affect on the "bottom" option. The \f2\-nonavbar\fP option is useful when you are interested only in the content and have no need for navigation, such as converting the files to PostScript or PDF for print only.
+.TP 3
+\-helpfile\  path/filename
+Specifies the path of an alternate help file \f2path/filename\fP that the HELP link in the top and bottom navigation bars link to. Without this option, the Javadoc tool automatically creates a help file \f2help\-doc.html\fP that is hard\-coded in the Javadoc tool. This option enables you to override this default. The \f2filename\fP can be any name and is not restricted to \f2help\-doc.html\fP \-\- the Javadoc tool will adjust the links in the navigation bar accordingly. For example:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-helpfile /home/user/myhelp.html java.awt\fP
+.fl
+.fi
+.TP 3
+\-stylesheetfile\  path/filename
+Specifies the path of an alternate HTML stylesheet file. Without this option, the Javadoc tool automatically creates a stylesheet file \f2stylesheet.css\fP that is hard\-coded in the Javadoc tool. This option enables you to override this default. The \f2filename\fP can be any name and is not restricted to \f2stylesheet.css\fP. For example:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-stylesheetfile /home/user/mystylesheet.css com.mypackage\fP
+.fl
+.fi
+.TP 3
+\-serialwarn
+Generates compile\-time warnings for missing @serial tags. By default, Javadoc 1.2.2 (and later versions) generates no serial warnings. (This is a reversal from earlier versions.) Use this option to display the serial warnings, which helps to properly document default serializable fields and \f2writeExternal\fP methods.
+.TP 3
+\-charset\  name
+Specifies the HTML character set for this document. The name should be a preferred MIME name as given in the
+.na
+\f2IANA Registry\fP @
+.fi
+http://www.iana.org/assignments/character\-sets. For example:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-charset "iso\-8859\-1" mypackage\fP
+.fl
+.fi
+would insert the following line in the head of every generated page:
+.nf
+\f3
+.fl
+   <META http\-equiv="Content\-Type" content="text/html; charset=ISO\-8859\-1">
+.fl
+\fP
+.fi
+This META tag is described in the
+.na
+\f2HTML standard\fP @
+.fi
+http://www.w3.org/TR/REC\-html40/charset.html#h\-5.2.2. (4197265 and 4137321)
+.br
+.br
+Also see \-encoding and \-docencoding.
+.TP 3
+\-docencoding\  name
+Specifies the encoding of the generated HTML files. The name should be a preferred MIME name as given in the
+.na
+\f2IANA Registry\fP @
+.fi
+http://www.iana.org/assignments/character\-sets. If you omit this option but use \-encoding, then the encoding of the generated HTML files is determined by \-encoding. Example:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-docencoding "ISO\-8859\-1" mypackage\fP
+.fl
+.fi
+Also see \-encoding and \-charset.
+.TP 3
+\-keywords
+Adds HTML meta keyword tags to the generated file for each class. These tags can help the page be found by search engines that look for meta tags. (Most search engines that search the entire Internet do not look at meta tags, because pages can misuse them; but search engines offered by companies that confine their search to their own website can benefit by looking at meta tags.)
+.br
+.br
+The meta tags include the fully qualified name of the class and the unqualified names of the fields and methods. Constructors are not included because they are identical to the class name. For example, the class String starts with these keywords:
+.nf
+\f3
+.fl
+     <META NAME="keywords" CONTENT="java.lang.String class">
+.fl
+     <META NAME="keywords" CONTENT="CASE_INSENSITIVE_ORDER">
+.fl
+     <META NAME="keywords" CONTENT="length()">
+.fl
+     <META NAME="keywords" CONTENT="charAt()">
+.fl
+\fP
+.fi
+.TP 3
+\-tag\ \ tagname:Xaoptcmf:"taghead"
+Enables the Javadoc tool to interpret a simple, one\-argument custom block tag \f2@\fP\f2tagname\fP in doc comments. So the Javadoc tool can "spell\-check" tag names, it is important to include a \f2\-tag\fP option for every custom tag that is present in the source code, disabling (with \f2X\fP) those that are not being output in the current run.
+.br
+.br
+The colon (\f4:\fP) is always the separator. To use a colon in \f2tagname\fP, see Use of Colon in Tag Name.
+.br
+.br
+The \f2\-tag\fP option outputs the tag's heading \f2taghead\fP in bold, followed on the next line by the text from its single argument, as shown in the example below. Like any block tag, this argument's text can contain inline tags, which are also interpreted. The output is similar to standard one\-argument tags, such as \f2@return\fP and \f2@author\fP. Omitting \f2taghead\fP causes \f2tagname\fP to appear as the heading.
+.br
+.br
+\f3Placement of tags\fP \- The \f4Xaoptcmf\fP part of the argument determines where in the source code the tag is allowed to be placed, and whether the tag can be disabled (using \f2X\fP). You can supply either \f4a\fP, to allow the tag in all places, or any combination of the other letters:
+.br
+.br
+\f4X\fP (disable tag)
+.br
+\f4a\fP (all)
+.br
+\f4o\fP (overview)
+.br
+\f4p\fP (packages)
+.br
+\f4t\fP (types, that is classes and interfaces)
+.br
+\f4c\fP (constructors)
+.br
+\f4m\fP (methods)
+.br
+\f4f\fP (fields)
+.br
+.br
+\f3Examples of single tags\fP \- An example of a tag option for a tag that can be used anywhere in the source code is:
+.nf
+\f3
+.fl
+    \-tag todo:a:"To Do:"
+.fl
+\fP
+.fi
+If you wanted @todo to be used only with constructors, methods and fields, you would use:
+.nf
+\f3
+.fl
+    \-tag todo:cmf:"To Do:"
+.fl
+\fP
+.fi
+Notice the last colon (\f2:\fP) above is not a parameter separator, but is part of the heading text (as shown below). You would use either tag option for source code that contains the tag \f2@todo\fP, such as:
+.nf
+\f3
+.fl
+     @todo The documentation for this method needs work.
+.fl
+\fP
+.fi
+\f3Use of Colon in Tag Name\fP \- A colon can be used in a tag name if it is escaped with a backslash. For this doc comment:
+.nf
+\f3
+.fl
+    /**
+.fl
+     * @ejb:bean
+.fl
+     */
+.fl
+\fP
+.fi
+use this tag option:
+.nf
+\f3
+.fl
+    \-tag ejb\\\\:bean:a:"EJB Bean:"
+.fl
+\fP
+.fi
+\f3Spell\-checking tag names (Disabling tags)\fP \- Some developers put custom tags in the source code that they don't always want to output. In these cases, it is important to list all tags that are present in the source code, enabling the ones you want to output and disabling the ones you don't want to output. The presence of \f2X\fP disables the tag, while its absence enables the tag. This gives the Javadoc tool enough information to know if a tag it encounters is unknown, probably the results of a typo or a misspelling. It prints a warning in these cases.
+.br
+.br
+You can add \f2X\fP to the placement values already present, so that when you want to enable the tag, you can simply delete the \f2X\fP. For example, if @todo is a tag that you want to suppress on output, you would use:
+.nf
+\f3
+.fl
+    \-tag todo:Xcmf:"To Do:"
+.fl
+\fP
+.fi
+or, if you'd rather keep it simple:
+.nf
+\f3
+.fl
+    \-tag todo:X
+.fl
+\fP
+.fi
+The syntax \f2\-tag todo:X\fP works even if \f2@todo\fP is defined by a taglet.
+.br
+.br
+\f3Order of tags\fP \- The order of the \f2\-tag\fP (and \f2\-taglet\fP) options determine the order the tags are output. You can mix the custom tags with the standard tags to intersperse them. The tag options for standard tags are placeholders only for determining the order \-\- they take only the standard tag's name. (Subheadings for standard tags cannot be altered.) This is illustrated in the following example.
+.br
+.br
+If \f2\-tag\fP is missing, then the position of \f2\-taglet\fP determines its order. If they are both present, then whichever appears last on the command line determines its order. (This happens because the tags and taglets are processed in the order that they appear on the command line. For example, if \f2\-taglet\fP and \f2\-tag\fP both have the name "todo", the one that appears last on the command line will determine its order.
+.br
+.br
+\f3Example of a complete set of tags\fP \- This example inserts "To Do" after "Parameters" and before "Throws" in the output. By using "X", it also specifies that @example is a tag that might be encountered in the source code that should not be output during this run. Notice that if you use @argfile, you can put the tags on separate lines in an argument file like this (no line continuation characters needed):
+.nf
+\f3
+.fl
+   \-tag param
+.fl
+   \-tag return
+.fl
+   \-tag todo:a:"To Do:"
+.fl
+   \-tag throws
+.fl
+   \-tag see
+.fl
+   \-tag example:X
+.fl
+\fP
+.fi
+When javadoc parses the doc comments, any tag encountered that is neither a standard tag nor passed in with \f2\-tag\fP or \f2\-taglet\fP is considered unknown, and a warning is thrown.
+.br
+.br
+The standard tags are initially stored internally in a list in their default order. Whenever \f2\-tag\fP options are used, those tags get appended to this list \-\- standard tags are moved from their default position. Therefore, if a \f2\-tag\fP option is omitted for a standard tag, it remains in its default position.
+.br
+.br
+\f3Avoiding Conflicts\fP \- If you want to slice out your own namespace, you can use a dot\-separated naming convention similar to that used for packages: \f2com.mycompany.todo\fP. Oracle will continue to create standard tags whose names do not contain dots. Any tag you create will override the behavior of a tag by the same name defined by Oracle. In other words, if you create a tag or taglet \f2@todo\fP, it will always have the same behavior you define, even if Oracle later creates a standard tag of the same name.
+.br
+.br
+\f3Annotations vs. Javadoc Tags\fP \- In general, if the markup you want to add is intended to affect or produce documentation, it should probably be a javadoc tag; otherwise, it should be an annotation. See
+.na
+\f2Comparing Annotations and Javadoc Tags\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html#annotations<
+.br
+.br
+You can also create more complex block tags, or custom inline tags with the \-taglet option.
+.TP 3
+\-taglet\ \ class
+Specifies the class file that starts the taglet used in generating the documentation for that tag. Use the fully\-qualified name for \f2class\fP. This taglet also defines the number of text arguments that the custom tag has. The taglet accepts those arguments, processes them, and generates the output. For extensive documentation with example taglets, see:
+.RS 3
+.TP 2
+o
+.na
+\f2Taglet Overview\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/javadoc/taglet/overview.html
+.RE
+Taglets are useful for block or inline tags. They can have any number of arguments and implement custom behavior, such as making text bold, formatting bullets, writing out the text to a file, or starting other processes.
+.br
+.br
+Taglets can only determine where a tag should appear and in what form. All other decisions are made by the doclet. So a taglet cannot do things such as remove a class name from the list of included classes. However, it can execute side effects, such as printing the tag's text to a file or triggering another process.
+.br
+.br
+Use the \f2\-tagletpath\fP option to specify the path to the taglet. Here is an example that inserts the "To Do" taglet after "Parameters" and ahead of "Throws" in the generated pages:
+.nf
+\f3
+.fl
+    \-taglet com.sun.tools.doclets.ToDoTaglet
+.fl
+    \-tagletpath /home/taglets
+.fl
+    \-tag return
+.fl
+    \-tag param
+.fl
+    \-tag todo
+.fl
+    \-tag throws
+.fl
+    \-tag see
+.fl
+\fP
+.fi
+Alternatively, you can use the \f2\-taglet\fP option in place of its \f2\-tag\fP option, but that may be harder to read.
+.TP 3
+\-tagletpath\ \ tagletpathlist
+Specifies the search paths for finding taglet class files (.class). The \f2tagletpathlist\fP can contain multiple paths by separating them with a colon (\f2:\fP). The Javadoc tool will search in all subdirectories of the specified paths.
+.TP 3
+\-docfilessubdirs\
+Enables deep copying of "\f2doc\-files\fP" directories. In other words, subdirectories and all contents are recursively copied to the destination. For example, the directory \f2doc\-files/example/images\fP and all its contents would now be copied. There is also an option to exclude subdirectories.
+.TP 3
+\-excludedocfilessubdir\ \ name1:name2...
+Excludes any "\f2doc\-files\fP" subdirectories with the given names. This prevents the copying of SCCS and other source\-code\-control subdirectories.
+.TP 3
+\-noqualifier\ \ all\  | \ packagename1:packagename2:...
+Omits qualifying package name from ahead of class names in output. The argument to \f2\-noqualifier\fP is either "\f2all\fP" (all package qualifiers are omitted) or a colon\-separate list of packages, with wildcards, to be removed as qualifiers. The package name is removed from places where class or interface names appear.
+.br
+.br
+The following example omits all package qualifiers:
+.nf
+\f3
+.fl
+    \-noqualifier all
+.fl
+\fP
+.fi
+The following example omits "java.lang" and "java.io" package qualifiers:
+.nf
+\f3
+.fl
+    \-noqualifier java.lang:java.io
+.fl
+\fP
+.fi
+The following example omits package qualifiers starting with "java", and "com.sun" subpackages (but not "javax"):
+.nf
+\f3
+.fl
+    \-noqualifier java.*:com.sun.*
+.fl
+\fP
+.fi
+Where a package qualifier would appear due to the above behavior, the name can be suitably shortened \-\- see How a name is displayed. This rule is in effect whether or not \f2\-noqualifier\fP is used.
+.TP 3
+\-notimestamp\
+Suppresses the timestamp, which is hidden in an HTML comment in the generated HTML near the top of each page. Useful when you want to run javadoc on two source bases and diff them, as it prevents timestamps from causing a diff (which would otherwise be a diff on every page). The timestamp includes the javadoc version number, and currently looks like this:
+.nf
+\f3
+.fl
+     <!\-\- Generated by javadoc (build 1.5.0_01) on Thu Apr 02 14:04:52 IST 2009 \-\->
+.fl
+\fP
+.fi
+.TP 3
+\-nocomment\
+Suppress the entire comment body, including the main description and all tags, generating only declarations. This option enables re\-using source files originally intended for a different purpose, to produce skeleton HTML documentation at the early stages of a new project.
+.TP 3
+\-sourcetab tabLength
+Specify the number of spaces each tab takes up in the source.
+.RE
+.SH "COMMAND LINE ARGUMENT FILES"
+.LP
+To shorten or simplify the javadoc command line, you can specify one or more files that themselves contain arguments to the \f2javadoc\fP command (except \f2\-J\fP options). This enables you to create javadoc commands of any length on any operating system.
+.LP
+An argument file can include javac options and source filenames in any combination. The arguments within a file can be space\-separated or newline\-separated. If a filename contains embedded spaces, put the whole filename in double quotes.
+.LP
+Filenames within an argument file are relative to the current directory, not the location of the argument file. Wildcards (*) are not allowed in these lists (such as for specifying \f2*.java\fP). Use of the '\f2@\fP' character to recursively interpret files is not supported. The \f2\-J\fP options are not supported because they are passed to the launcher, which does not support argument files.
+.LP
+When executing javadoc, pass in the path and name of each argument file with the '\f2@\fP' leading character. When javadoc encounters an argument beginning with the character `\f2@\fP', it expands the contents of that file into the argument list.
+.SS
+Example \- Single Arg File
+.LP
+You could use a single argument file named "\f2argfile\fP" to hold all Javadoc arguments:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc @argfile\fP
+.fl
+.fi
+.LP
+This argument file could contain the contents of both files shown in the next example.
+.SS
+Example \- Two Arg Files
+.LP
+You can create two argument files \-\- one for the Javadoc options and the other for the package names or source filenames: (Notice the following lists have no line\-continuation characters.)
+.LP
+Create a file named "\f2options\fP" containing:
+.nf
+\f3
+.fl
+     \-d docs\-filelist
+.fl
+     \-use
+.fl
+     \-splitindex
+.fl
+     \-windowtitle 'Java SE 7 API Specification'
+.fl
+     \-doctitle 'Java SE 7 API Specification'
+.fl
+     \-header '<b>Java(TM) SE 7</b>'
+.fl
+     \-bottom 'Copyright &copy; 1993\-2011 Oracle and/or its affiliates. All rights reserved.'
+.fl
+     \-group "Core Packages" "java.*"
+.fl
+     \-overview /java/pubs/ws/1.7.0/src/share/classes/overview\-core.html
+.fl
+     \-sourcepath /java/pubs/ws/1.7.0/src/share/classes
+.fl
+\fP
+.fi
+.LP
+Create a file named "\f2packages\fP" containing:
+.nf
+\f3
+.fl
+     com.mypackage1
+.fl
+     com.mypackage2
+.fl
+     com.mypackage3
+.fl
+\fP
+.fi
+.LP
+You would then run javadoc with:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc @options @packages\fP
+.fl
+.fi
+.SS
+Example \- Arg Files with Paths
+.LP
+The argument files can have paths, but any filenames inside the files are relative to the current working directory (not \f2path1\fP or \f2path2\fP):
+.nf
+\f3
+.fl
+  % \fP\f3javadoc @path1/options @path2/packages\fP
+.fl
+.fi
+.SS
+Example \- Option Arguments
+.LP
+Here's an example of saving just an argument to a javadoc option in an argument file. We'll use the \f2\-bottom\fP option, since it can have a lengthy argument. You could create a file named "\f2bottom\fP" containing its text argument:
+.nf
+\f3
+.fl
+<font size="\-1">
+.fl
+      <a href="http://bugreport.sun.com/bugreport/">Submit a bug or feature</a><br/>
+.fl
+      Copyright &copy; 1993, 2011, Oracle and/or its affiliates. All rights reserved.<br/>
+.fl
+      Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
+.fl
+      Other names may be trademarks of their respective owners.</font>
+.fl
+\fP
+.fi
+.LP
+Then run the Javadoc tool with:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-bottom @bottom @packages\fP
+.fl
+.fi
+.LP
+Or you could include the \f2\-bottom\fP option at the start of the argument file, and then just run it as:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc @bottom @packages\fP
+.fl
+.fi
+.SH "Name"
+Running
+.SH "RUNNING JAVADOC"
+.LP
+\f3Version Numbers\fP \- The version number of javadoc can be determined using \f3javadoc \-J\-version\fP. The version number of the standard doclet appears in its output stream. It can be turned off with \f2\-quiet\fP.
+.LP
+\f3Public programmatic interface\fP \- To invoke the Javadoc tool from within programs written in the Java language. This interface is in \f2com.sun.tools.javadoc.Main\fP (and javadoc is re\-entrant). For more details, see
+.na
+\f2Standard Doclet\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/javadoc/standard\-doclet.html#runningprogrammatically.
+.LP
+\f3Running Doclets\fP \- The instructions given below are for invoking the standard HTML doclet. To invoke a custom doclet, use the \-doclet and \-docletpath options. For full, working examples of running a particular doclet, see the
+.na
+\f2MIF Doclet documentation\fP @
+.fi
+http://java.sun.com/j2se/javadoc/mifdoclet/docs/mifdoclet.html.
+.SH "SIMPLE EXAMPLES"
+.LP
+You can run javadoc on entire packages or individual source files. Each package name has a corresponding directory name. In the following examples, the source files are located at \f2/home/src/java/awt/*.java\fP. The destination directory is \f2/home/html\fP.
+.SS
+Documenting One or More Packages
+.LP
+To document a package, the source files (\f2*.java\fP) for that package must be located in a directory having the same name as the package. If a package name is made up of several identifiers (separated by dots, such as \f2java.awt.color\fP), each subsequent identifier must correspond to a deeper subdirectory (such as \f2java/awt/color\fP). You may split the source files for a single package among two such directory trees located at different places, as long as \f2\-sourcepath\fP points to them both \-\- for example \f2src1/java/awt/color\fP and \f2src2/java/awt/color\fP.
+.LP
+You can run javadoc either by changing directories (with \f2cd\fP) or by using \f2\-sourcepath\fP option. The examples below illustrate both alternatives.
+.RS 3
+.TP 2
+o
+\f3Case 1 \- Run recursively starting from one or more packages\fP \- This example uses \-sourcepath so javadoc can be run from any directory and \-subpackages (a new 1.4 option) for recursion. It traverses the subpackages of the \f2java\fP directory excluding packages rooted at \f2java.net\fP and \f2java.lang\fP. Notice this excludes \f2java.lang.ref\fP, a subpackage of \f2java.lang\fP).
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \fP\f3\-d\fP\f3 /home/html \fP\f3\-sourcepath\fP\f3 /home/src \fP\f3\-subpackages\fP\f3 java \fP\f3\-exclude\fP\f3 java.net:java.lang\fP
+.fl
+.fi
+.LP
+To also traverse down other package trees, append their names to the \f2\-subpackages\fP argument, such as \f2java:javax:org.xml.sax\fP.
+.TP 2
+o
+\f3Case 2 \- Run on explicit packages after changing to the "root" source directory\fP \- Change to the parent directory of the fully\-qualified package. Then run javadoc, supplying names of one or more packages you want to document:
+.nf
+\f3
+.fl
+  % \fP\f3cd /home/src/\fP
+.fl
+  % \f3javadoc \-d /home/html java.awt java.awt.event\fP
+.fl
+.fi
+.TP 2
+o
+\f3Case 3 \- Run from any directory on explicit packages in a single directory tree\fP \- In this case, it doesn't matter what the current directory is. Run javadoc supplying \f2\-sourcepath\fP with the parent directory of the top\-level package, and supplying names of one or more packages you want to document:
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d /home/html \-sourcepath /home/src java.awt java.awt.event\fP
+.fl
+.fi
+.TP 2
+o
+\f3Case 4 \- Run from any directory on explicit packages in multiple directory trees\fP \- This is the same as case 3, but for packages in separate directory trees. Run javadoc supplying \f2\-sourcepath\fP with the path to each tree's root (colon\-separated) and supply names of one or more packages you want to document. All source files for a given package do not need to be located under a single root directory \-\- they just need to be found somewhere along the sourcepath.
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d /home/html \-sourcepath /home/src1:/home/src2 java.awt java.awt.event\fP
+.fl
+.fi
+.RE
+.LP
+Result: All cases generate HTML\-formatted documentation for the public and protected classes and interfaces in packages \f2java.awt\fP and \f2java.awt.event\fP and save the HTML files in the specified destination directory (\f2/home/html\fP). Because two or more packages are being generated, the document has three HTML frames \-\- for the list of packages, the list of classes, and the main class pages.
+.SS
+Documenting One or More Classes
+.LP
+The second way to run the Javadoc tool is by passing in one or more source files (\f2.java\fP). You can run javadoc either of the following two ways \-\- by changing directories (with \f2cd\fP) or by fully\-specifying the path to the \f2.java\fP files. Relative paths are relative to the current directory. The \f2\-sourcepath\fP option is ignored when passing in source files. You can use command line wildcards, such as asterisk (*), to specify groups of classes.
+.RS 3
+.TP 2
+o
+\f3Case 1 \- Changing to the source directory\fP \- Change to the directory holding the \f2.java\fP files. Then run javadoc, supplying names of one or more source files you want to document.
+.nf
+\f3
+.fl
+  % \fP\f3cd /home/src/java/awt\fP
+.fl
+  % \f3javadoc \-d /home/html Button.java Canvas.java Graphics*.java\fP
+.fl
+.fi
+This example generates HTML\-formatted documentation for the classes \f2Button\fP, \f2Canvas\fP and classes beginning with \f2Graphics\fP. Because source files rather than package names were passed in as arguments to javadoc, the document has two frames \-\- for the list of classes and the main page.
+.TP 2
+o
+\f3Case 2 \- Changing to the package root directory\fP \- This is useful for documenting individual source files from different subpackages off the same root. Change to the package root directory, and supply the source files with paths from the root.
+.nf
+\f3
+.fl
+  % \fP\f3cd /home/src/\fP
+.fl
+  % \f3javadoc \-d /home/html java/awt/Button.java java/applet/Applet.java\fP
+.fl
+.fi
+This example generates HTML\-formatted documentation for the classes \f2Button\fP and \f2Applet\fP.
+.TP 2
+o
+\f3Case 3 \- From any directory\fP \- In this case, it doesn't matter what the current directory is. Run javadoc supplying the absolute path (or path relative to the current directory) to the \f2.java\fP files you want to document.
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d /home/html /home/src/java/awt/Button.java /home/src/java/awt/Graphics*.java\fP
+.fl
+.fi
+This example generates HTML\-formatted documentation for the class \f2Button\fP and classes beginning with \f2Graphics\fP.
+.RE
+.SS
+Documenting Both Packages and Classes
+.LP
+You can document entire packages and individual classes at the same time. Here's an example that mixes two of the previous examples. You can use \f2\-sourcepath\fP for the path to the packages but not for the path to the individual classes.
+.nf
+\f3
+.fl
+  % \fP\f3javadoc \-d /home/html \-sourcepath /home/src java.awt /home/src/java/applet/Applet.java\fP
+.fl
+.fi
+.LP
+This example generates HTML\-formatted documentation for the package \f2java.awt\fP and class \f2Applet\fP. (The Javadoc tool determines the package name for \f2Applet\fP from the package declaration, if any, in the \f2Applet.java\fP source file.)
+.SH "REAL WORLD EXAMPLE"
+.LP
+The Javadoc tool has many useful options, some of which are more commonly used than others. Here is effectively the command we use to run the Javadoc tool on the Java platform API. We use 180MB of memory to generate the documentation for the 1500 (approx.) public and protected classes in the Java SE Platform, Standard Edition, v1.2.
+.LP
+The same example is shown twice \-\- first as executed on the command line, then as executed from a makefile. It uses absolute paths in the option arguments, which enables the same \f2javadoc\fP command to be run from any directory.
+.SS
+Command Line Example
+.LP
+The following example may be too long for some shells such as DOS. You can use a command line argument file (or write a shell script) to workaround this limitation.
+.nf
+\f3
+.fl
+% javadoc \-sourcepath /java/jdk/src/share/classes \\
+.fl
+    \-overview /java/jdk/src/share/classes/overview.html \\
+.fl
+    \-d /java/jdk/build/api \\
+.fl
+    \-use \\
+.fl
+    \-splitIndex \\
+.fl
+    \-windowtitle 'Java Platform, Standard Edition 7 API Specification' \\
+.fl
+    \-doctitle 'Java Platform, Standard Edition 7 API Specification' \\
+.fl
+    \-header '<b>Java(TM) SE 7</b>' \\
+.fl
+    \-bottom '<font size="\-1">
+.fl
+      <a href="http://bugreport.sun.com/bugreport/">Submit a bug or feature</a><br/>
+.fl
+      Copyright &copy; 1993, 2011, Oracle and/or its affiliates. All rights reserved.<br/>
+.fl
+      Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
+.fl
+      Other names may be trademarks of their respective owners.</font>' \\
+.fl
+    \-group "Core Packages" "java.*:com.sun.java.*:org.omg.*" \\
+.fl
+    \-group "Extension Packages" "javax.*" \\
+.fl
+    \-J\-Xmx180m \\
+.fl
+    @packages
+.fl
+\fP
+.fi
+.LP
+where \f2packages\fP is the name of a file containing the packages to process, such as \f2java.applet java.lang\fP. None of the options should contain any newline characters between the single quotes. (For example, if you copy and paste this example, delete the newline characters from the \f2\-bottom\fP option.) See the other notes listed below.
+.SS
+Makefile Example
+.LP
+This is an example of a GNU makefile. For an example of a Windows makefile, see
+.na
+\f2creating a makefile for Windows\fP @
+.fi
+http://java.sun.com/j2se/javadoc/faq/index.html#makefiles.
+.nf
+\f3
+.fl
+javadoc \-\fP\f3sourcepath\fP\f3 $(SRCDIR)              \\   /* Sets path for source files     */
+.fl
+        \-\fP\f3overview\fP\f3 $(SRCDIR)/overview.html  \\   /* Sets file for overview text    */
+.fl
+        \-\fP\f3d\fP\f3 /java/jdk/build/api             \\   /* Sets destination directory     */
+.fl
+        \-\fP\f3use\fP\f3                               \\   /* Adds "Use" files               */
+.fl
+        \-\fP\f3splitIndex\fP\f3                        \\   /* Splits index A\-Z               */
+.fl
+        \-\fP\f3windowtitle\fP\f3 $(WINDOWTITLE)        \\   /* Adds a window title            */
+.fl
+        \-\fP\f3doctitle\fP\f3 $(DOCTITLE)              \\   /* Adds a doc title               */
+.fl
+        \-\fP\f3header\fP\f3 $(HEADER)                  \\   /* Adds running header text       */
+.fl
+        \-\fP\f3bottom\fP\f3 $(BOTTOM)                  \\   /* Adds text at bottom            */
+.fl
+        \-\fP\f3group\fP\f3 $(GROUPCORE)                \\   /* 1st subhead on overview page   */
+.fl
+        \-\fP\f3group\fP\f3 $(GROUPEXT)                 \\   /* 2nd subhead on overview page   */
+.fl
+        \-\fP\f3J\fP\f3\-Xmx180m                         \\   /* Sets memory to 180MB           */
+.fl
+        java.lang java.lang.reflect        \\   /* Sets packages to document      */
+.fl
+        java.util java.io java.net         \\
+.fl
+        java.applet
+.fl
+
+.fl
+WINDOWTITLE = 'Java(TM) SE 7 API Specification'
+.fl
+DOCTITLE = 'Java(TM) Platform Standard Edition 7 API Specification'
+.fl
+HEADER = '<b>Java(TM) SE 7</font>'
+.fl
+BOTTOM = '<font size="\-1">
+.fl
+      <a href="http://bugreport.sun.com/bugreport/">Submit a bug or feature</a><br/>
+.fl
+      Copyright &copy; 1993, 2011, Oracle and/or its affiliates. All rights reserved.<br/>
+.fl
+      Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
+.fl
+      Other names may be trademarks of their respective owners.</font>'
+.fl
+GROUPCORE = '"Core Packages" "java.*:com.sun.java.*:org.omg.*"'
+.fl
+GROUPEXT  = '"Extension Packages" "javax.*"'
+.fl
+SRCDIR = '/java/jdk/1.7.0/src/share/classes'
+.fl
+\fP
+.fi
+.LP
+Single quotes are used to surround makefile arguments.
+.LP
+\f3NOTES\fP
+.RS 3
+.TP 2
+o
+If you omit the \f2\-windowtitle\fP option, the Javadoc tool copies the doc title to the window title. The \f2\-windowtitle\fP text is basically the same as the \f2\-doctitle\fP but without HTML tags, to prevent those tags from appearing as raw text in the window title.
+.TP 2
+o
+If you omit the \f2\-footer\fP option, as done here, the Javadoc tool copies the header text to the footer.
+.TP 2
+o
+Other important options you might want to use but not needed in this example are \-\f2classpath\fP and \-\f2link\fP.
+.RE
+.SH "TROUBLESHOOTING"
+.SS
+General Troubleshooting
+.RS 3
+.TP 2
+o
+\f3Javadoc FAQ\fP \- Commonly\-encountered bugs and troubleshooting tips can be found on the
+.na
+\f2Javadoc FAQ\fP @
+.fi
+http://java.sun.com/j2se/javadoc/faq/index.html#B
+.TP 2
+o
+\f3Bugs and Limitations\fP \- You can also see some bugs listed at Important Bug Fixes and Changes.
+.TP 2
+o
+\f3Version number\fP \- See version numbers.
+.TP 2
+o
+\f3Documents only legal classes\fP \- When documenting a package, javadoc only reads files whose names are composed of legal class names. You can prevent javadoc from parsing a file by including, for example, a hyphen "\-" in its filename.
+.RE
+.SS
+Errors and Warnings
+.LP
+Error and warning messages contain the filename and line number to the declaration line rather than to the particular line in the doc comment.
+.RS 3
+.TP 2
+o
+\f2"error: cannot read: Class1.java"\fP the Javadoc tool is trying to load the class Class1.java in the current directory. The class name is shown with its path (absolute or relative), which in this case is the same as \f2./Class1.java\fP.
+.RE
+.SH "ENVIRONMENT"
+.RS 3
+.TP 3
+CLASSPATH
+Environment variable that provides the path which javadoc uses to find user class files. This environment variable is overridden by the \f2\-classpath\fP option. Separate directories with a colon, for example:
+.:/home/classes:/usr/local/java/classes
+.RE
+.SH "SEE ALSO"
+.RS 3
+.TP 2
+o
+javac(1)
+.TP 2
+o
+java(1)
+.TP 2
+o
+jdb(1)
+.TP 2
+o
+javah(1)
+.TP 2
+o
+javap(1)
+.TP 2
+o
+.na
+\f2Javadoc Home Page\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-jsp\-135444.html
+.TP 2
+o
+.na
+\f2How to Write Doc Comments for Javadoc\fP @
+.fi
+http://www.oracle.com/technetwork/java/javase/documentation/index\-137868.html
+.TP 2
+o
+.na
+\f2Setting the Class Path\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#general
+.TP 2
+o
+.na
+\f2How Javac and Javadoc Find Classes\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/findingclasses.html#srcfiles (tools.jar)
+.RE
+
diff --git a/jdk/src/bsd/doc/man/javah.1 b/jdk/src/bsd/doc/man/javah.1
new file mode 100644
index 0000000..792435e
--- /dev/null
+++ b/jdk/src/bsd/doc/man/javah.1
@@ -0,0 +1,138 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javah 1 "10 May 2011"
+
+.LP
+.SH "Name"
+javah \- C Header and Stub File Generator
+.LP
+.LP
+\f3javah\fP produces C header files and C source files from a Java class. These files provide the connective glue that allow your Java and C code to interact.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+javah [ \fP\f3options\fP\f3 ] fully\-qualified\-classname. . .
+.fl
+\fP
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3javah\fP generates C header and source files that are needed to implement native methods. The generated header and source files are used by C programs to reference an object's instance variables from native source code. The .h file contains a struct definition whose layout parallels the layout of the corresponding class. The fields in the struct correspond to instance variables in the class.
+.LP
+.LP
+The name of the header file and the structure declared within it are derived from the name of the class. If the class passed to \f3javah\fP is inside a package, the package name is prepended to both the header file name and the structure name. Underscores (_) are used as name delimiters.
+.LP
+.LP
+By default \f3javah\fP creates a header file for each class listed on the command line and puts the files in the current directory. Use the \f2\-stubs\fP option to create source files. Use the \f2\-o\fP option to concatenate the results for all listed classes into a single file.
+.LP
+.LP
+The new native method interface, Java Native Interface (JNI), does not require header information or stub files. \f3javah\fP can still be used to generate native method function proptotypes needed for JNI\-style native methods. \f3javah\fP produces JNI\-style output by default, and places the result in the .h file.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-o outputfile
+Concatenates the resulting header or source files for all the classes listed on the command line into \f2outputfile\fP. Only one of \f3\-o\fP or \f3\-d\fP may be used.
+.TP 3
+\-d directory
+Sets the directory where \f3javah\fP saves the header files or the stub files. Only one of \f3\-d\fP or \f3\-o\fP may be used.
+.TP 3
+\-stubs
+Causes \f3javah\fP to generate C declarations from the Java object file.
+.TP 3
+\-verbose
+Indicates verbose output and causes \f3javah\fP to print a message to stdout concerning the status of the generated files.
+.TP 3
+\-help
+Print help message for \f3javah\fP usage.
+.TP 3
+\-version
+Print out \f3javah\fP version information.
+.TP 3
+\-jni
+Causes \f3javah\fP to create an output file containing JNI\-style native method function prototypes. This is the default output, so use of \f3\-jni\fP is optional.
+.TP 3
+\-classpath path
+Specifies the path \f3javah\fP uses to look up classes. Overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by colons. Thus the general format for \f2path\fP is:
+.nf
+\f3
+.fl
+   .:<your_path>
+.fl
+\fP
+.fi
+For example:
+.nf
+\f3
+.fl
+   .:/home/avh/classes:/usr/local/java/classes
+.fl
+\fP
+.fi
+As a special convenience, a class path element containing a basename of \f2*\fP is considered equivalent to specifying a list of all the files in the directory with the extension \f2.jar\fP or \f2.JAR\fP (a java program cannot tell the difference between the two invocations).
+.br
+.br
+For example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to a \f2A.jar:b.JAR\fP, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of \f2*\fP expands to a list of all the jar files in the current directory. The \f2CLASSPATH\fP environment variable, where defined, will be similarly expanded. Any classpath wildcard expansion occurs before the Java virtual machine is started \-\- no Java program will ever see unexpanded wildcards except by querying the environment. For example; by invoking \f2System.getenv("CLASSPATH")\fP.
+.TP 3
+\-bootclasspath path
+Specifies path from which to load bootstrap classes. By default, the bootstrap classes are the classes implementing the core Java 2 platform located in \f2jre/lib/rt.jar\fP and several other jar files.
+.TP 3
+\-old
+Specifies that old JDK1.0\-style header files should be generated.
+.TP 3
+\-force
+Specifies that output files should always be written.
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for the java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes.
+.RE
+
+.LP
+.SH "ENVIRONMENT VARIABLES"
+.LP
+.RS 3
+.TP 3
+CLASSPATH
+Used to provide the system a path to user\-defined classes. Directories are separated by colons, for example,
+.nf
+\f3
+.fl
+.:/home/avh/classes:/usr/local/java/classes
+.fl
+\fP
+.fi
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.LP
+javac(1), java(1), jdb(1), javap(1), javadoc(1)
+.LP
+
diff --git a/jdk/src/bsd/doc/man/javap.1 b/jdk/src/bsd/doc/man/javap.1
new file mode 100644
index 0000000..cf177d7
--- /dev/null
+++ b/jdk/src/bsd/doc/man/javap.1
@@ -0,0 +1,317 @@
+." Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javap 1 "10 May 2011"
+
+.LP
+.SH "Name"
+javap \- The Java Class File Disassembler
+.LP
+.LP
+Disassembles class files.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+javap [ \fP\f3options\fP\f3 ] classes
+.fl
+\fP
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3javap\fP command disassembles one or more class files. Its output depends on the options used. If no options are used, \f3javap\fP prints out the package, protected, and public fields and methods of the classes passed to it. \f3javap\fP prints its output to stdout.
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options.
+.TP 3
+classes
+List of one or more classes (separated by spaces) to be processed for annotations (such as \f2DocFooter.class\fP). You may specify a class that can be found in the class path, by its file name (for example, \f2/home/user/myproject/src/DocFooter.class\fP), or with a URL (for example, \f2file:///home/user/myproject/src/DocFooter.class\fP).
+.RE
+
+.LP
+.LP
+For example, compile the following class declaration:
+.LP
+.nf
+\f3
+.fl
+import java.awt.*;
+.fl
+import java.applet.*;
+.fl
+
+.fl
+public class DocFooter extends Applet {
+.fl
+        String date;
+.fl
+        String email;
+.fl
+
+.fl
+        public void init() {
+.fl
+                resize(500,100);
+.fl
+                date = getParameter("LAST_UPDATED");
+.fl
+                email = getParameter("EMAIL");
+.fl
+        }
+.fl
+
+.fl
+        public void paint(Graphics g) {
+.fl
+                g.drawString(date + " by ",100, 15);
+.fl
+                g.drawString(email,290,15);
+.fl
+        }
+.fl
+}
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The output from \f3javap DocFooter.class\fP yields:
+.LP
+.nf
+\f3
+.fl
+Compiled from "DocFooter.java"
+.fl
+public class DocFooter extends java.applet.Applet {
+.fl
+  java.lang.String date;
+.fl
+  java.lang.String email;
+.fl
+  public DocFooter();
+.fl
+  public void init();
+.fl
+  public void paint(java.awt.Graphics);
+.fl
+}
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The output from \f3javap \-c DocFooter.class\fP yields:
+.LP
+.nf
+\f3
+.fl
+Compiled from "DocFooter.java"
+.fl
+public class DocFooter extends java.applet.Applet {
+.fl
+  java.lang.String date;
+.fl
+
+.fl
+  java.lang.String email;
+.fl
+
+.fl
+  public DocFooter();
+.fl
+    Code:
+.fl
+       0: aload_0
+.fl
+       1: invokespecial #1                  // Method java/applet/Applet."<init>":()V
+.fl
+       4: return
+.fl
+
+.fl
+  public void init();
+.fl
+    Code:
+.fl
+       0: aload_0
+.fl
+       1: sipush        500
+.fl
+       4: bipush        100
+.fl
+       6: invokevirtual #2                  // Method resize:(II)V
+.fl
+       9: aload_0
+.fl
+      10: aload_0
+.fl
+      11: ldc           #3                  // String LAST_UPDATED
+.fl
+      13: invokevirtual #4                  // Method getParameter:(Ljava/lang/String;)Ljava/lang/String;
+.fl
+      16: putfield      #5                  // Field date:Ljava/lang/String;
+.fl
+      19: aload_0
+.fl
+      20: aload_0
+.fl
+      21: ldc           #6                  // String EMAIL
+.fl
+      23: invokevirtual #4                  // Method getParameter:(Ljava/lang/String;)Ljava/lang/String;
+.fl
+      26: putfield      #7                  // Field email:Ljava/lang/String;
+.fl
+      29: return
+.fl
+
+.fl
+  public void paint(java.awt.Graphics);
+.fl
+    Code:
+.fl
+       0: aload_1
+.fl
+       1: new           #8                  // class java/lang/StringBuilder
+.fl
+       4: dup
+.fl
+       5: invokespecial #9                  // Method java/lang/StringBuilder."<init>":()V
+.fl
+       8: aload_0
+.fl
+       9: getfield      #5                  // Field date:Ljava/lang/String;
+.fl
+      12: invokevirtual #10                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+.fl
+      15: ldc           #11                 // String  by
+.fl
+      17: invokevirtual #10                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+.fl
+      20: invokevirtual #12                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+.fl
+      23: bipush        100
+.fl
+      25: bipush        15
+.fl
+      27: invokevirtual #13                 // Method java/awt/Graphics.drawString:(Ljava/lang/String;II)V
+.fl
+      30: aload_1
+.fl
+      31: aload_0
+.fl
+      32: getfield      #7                  // Field email:Ljava/lang/String;
+.fl
+      35: sipush        290
+.fl
+      38: bipush        15
+.fl
+      40: invokevirtual #13                 // Method java/awt/Graphics.drawString:(Ljava/lang/String;II)V
+.fl
+      43: return
+.fl
+}
+.fl
+\fP
+.fi
+
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-help \-\-help \-?
+Prints out help message for \f3javap\fP.
+.TP 3
+\-version
+Prints out version information.
+.TP 3
+\-l
+Prints out line and local variable tables.
+.TP 3
+\-public
+Shows only public classes and members.
+.TP 3
+\-protected
+Shows only protected and public classes and members.
+.TP 3
+\-package
+Shows only package, protected, and public classes and members. This is the default.
+.TP 3
+\-private \-p
+Shows all classes and members.
+.TP 3
+\-Jflag
+Pass \f2flag\fP directly to the runtime system. Some examples:
+.nf
+\f3
+.fl
+javap \-J\-version
+.fl
+javap \-J\-Djava.security.manager \-J\-Djava.security.policy=MyPolicy MyClassName
+.fl
+\fP
+.fi
+.TP 3
+\-s
+Prints internal type signatures.
+.TP 3
+\-sysinfo
+Shows system information (path, size, date, MD5 hash) of the class being processed.
+.TP 3
+\-constants
+Shows static final constants.
+.TP 3
+\-c
+Prints out disassembled code, i.e., the instructions that comprise the Java bytecodes, for each of the methods in the class. These are documented in the
+.na
+\f2Java Virtual Machine Specification\fP @
+.fi
+http://java.sun.com/docs/books/vmspec/.
+.TP 3
+\-verbose
+Prints stack size, number of \f2locals\fP and \f2args\fP for methods.
+.TP 3
+\-classpath path
+Specifies the path \f3javap\fP uses to look up classes. Overrides the default or the CLASSPATH environment variable if it is set.
+.TP 3
+\-bootclasspath path
+Specifies path from which to load bootstrap classes. By default, the bootstrap classes are the classes implementing the core Java platform located in \f2jre/lib/rt.jar\fP and several other jar files.
+.TP 3
+\-extdirs dirs
+Overrides location at which installed extensions are searched for. The default location for extensions is the value of \f2java.ext.dirs\fP.
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.LP
+javac(1), java(1), jdb(1), javah(1), javadoc(1)
+.LP
+
diff --git a/jdk/src/bsd/doc/man/javaws.1 b/jdk/src/bsd/doc/man/javaws.1
new file mode 100644
index 0000000..8213a8a
--- /dev/null
+++ b/jdk/src/bsd/doc/man/javaws.1
@@ -0,0 +1,222 @@
+." Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH javaws 1 "10 May 2011"
+
+.LP
+.SH "Name"
+\f2javaws\fP Command Line
+.LP
+.SH "NAME"
+.LP
+.LP
+\f2javaws\fP \- Java Web Start launcher command
+.LP
+.SH "SYNOPSIS"
+.LP
+.LP
+\f2javaws [run\-options] <jnlp>\fP
+.LP
+.LP
+\f2javaws [control\-options]\fP
+.LP
+.SH "PARAMETERS"
+.LP
+.LP
+\f2[run\-options]\fP
+.LP
+.LP
+Command\-line run\-options. run\-options may be in any order. For a discussion of the various run\-options, see RUN\-OPTIONS below.
+.LP
+.LP
+\f2<jnlp>\fP
+.LP
+.LP
+This can be either the path of, or the Uniform Resource Locater (URL) of the JNLP (Java Network Launching Protocol) file.
+.LP
+.LP
+\f2[control\-options]\fP
+.LP
+.LP
+Command\-line control\-options. control\-options may be in any order. For a discussion of the various control\-options, see CONTROL\-OPTIONS below.
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f2javaws\fP command launches Java Web Start, which is the reference implementation of the Java Network Launching Protocol (JNLP). Java Web Start launches Java applications/applets hosted on a network.
+.LP
+.LP
+If a JNLP file is specified, \f2javaws\fP will launch the Java application/applet specified in the JNLP file.
+.LP
+.LP
+The \f2javaws\fP launcher has a set of options that are supported in the current release. However, the options may be removed in a future release.
+.LP
+.SH "RUN\-OPTIONS"
+.LP
+.LP
+\f2\-offline\fP
+.LP
+.LP
+Run Java Web Start in offline mode.
+.LP
+.LP
+\f2\-Xnosplash\fP
+.LP
+.LP
+Do not display the initial splash screen.
+.LP
+.LP
+\f2\-open <arguments>\fP
+.LP
+.LP
+If specified, replaces the arguments in the jnlp file with \f2\-open <arguments>\fP.
+.LP
+.LP
+\f2\-print <arguments>\fP
+.LP
+.LP
+If specified, replaces the arguments in the jnlp file with \f2\-print <arguments>\fP.
+.LP
+.LP
+\f2\-online\fP
+.LP
+.LP
+Use online mode (default behavior).
+.LP
+.LP
+\f2\-wait\fP
+.LP
+.LP
+If specified, the \f2javaws\fP process will not exit until the application exits. This option does not function as described on Windows platforms.
+.LP
+.LP
+\f2\-verbose\fP
+.LP
+.LP
+Display additional output.
+.LP
+.LP
+\f2\-J<option>\fP
+.LP
+.LP
+Supply options to the VM.
+.LP
+.LP
+\f2\-system\fP
+.LP
+.LP
+Run the application from the system cache only.
+.LP
+.SH "CONTROL\-OPTIONS"
+.LP
+.LP
+\f2\-viewer\fP
+.LP
+.LP
+Show the Cache Viewer in the Java Control Panel.
+.LP
+.LP
+\f2\-clearcache\fP
+.LP
+.LP
+Remove all non\-installed applications from the cache.
+.LP
+.LP
+\f2\-userConfig <property name>\fP
+.LP
+.LP
+Clear the specified deployment property.
+.LP
+.LP
+\f2\-userConfig <property name> <property value>\fP
+.LP
+.LP
+Set the specified deployment property to the specified value.
+.LP
+.LP
+\f2\-uninstall\fP
+.LP
+.LP
+Remove all applications from the cache.
+.LP
+.LP
+\f2\-uninstall <jnlp>\fP
+.LP
+.LP
+Remove the application from the cache.
+.LP
+.LP
+\f2\-import [import\-options] <jnlp>\fP
+.LP
+.LP
+Import the application to the cache.
+.LP
+.SH "IMPORT\-OPTIONS"
+.LP
+.LP
+\f2\-silent\fP
+.LP
+.LP
+Import silently (with no user interface).
+.LP
+.LP
+\f2\-system\fP
+.LP
+.LP
+Import application to the system cache.
+.LP
+.LP
+\f2\-codebase <url>\fP
+.LP
+.LP
+Retrieve resources from the given codebase.
+.LP
+.LP
+\f2\-shortcut\fP
+.LP
+.LP
+Install shortcuts as if user allowed prompt. This option has no effect unless \f2\-silent\fP option is also used.
+.LP
+.LP
+\f2\-association\fP
+.LP
+.LP
+Install associations as if user allowed prompt. This option has no effect unless \f2\-silent\fP option is also used.
+.LP
+.SH "FILES"
+.LP
+.LP
+For information about the user and system cache and deployment.properties files, see
+.na
+\f2System\- and User\-Level Properties\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/deployment/deployment\-guide/properties.html.
+.LP
+.SH "MORE INFORMATION"
+.LP
+.LP
+For more information about Java Web Start, see
+.na
+\f2Java Web Start\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/javaws/index.html.
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jconsole.1 b/jdk/src/bsd/doc/man/jconsole.1
new file mode 100644
index 0000000..d92b2fa
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jconsole.1
@@ -0,0 +1,137 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jconsole 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jconsole \- Java Monitoring and Management Console
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jconsole\fP [ \f2options\fP ] [ connection ... ]
+.fl
+
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+options
+Options, if used, should follow immediately after the command name.
+.TP 3
+connection = pid | host:port | jmxUrl
+.RS 3
+.TP 2
+o
+\f2pid\fP Process ID of a local Java VM. The Java VM must be running with the same user ID as the user ID running jconsole. See
+.na
+\f2JMX Monitoring and Management\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/management/agent.html for details.
+.TP 2
+o
+\f2host\fP:\f2port\fP Name of the host system on which the Java VM is running and the port number specified by the system property \f2com.sun.management.jmxremote.port\fP when the Java VM was started. See
+.na
+\f2JMX Monitoring and Management\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/management/agent.html for details.
+.TP 2
+o
+\f2jmxUrl\fP Address of the JMX agent to be connected to as described in
+.na
+\f2JMXServiceURL\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/javax/management/remote/JMXServiceURL.html.
+.RE
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3jconsole\fP command launches a graphical console tool that enables you to monitor and manage Java applications and virtual machines on a local or remote machine.
+.LP
+.LP
+On Windows, \f3jconsole\fP does not associate with a console window. It will, however, display a dialog box with error information if the \f3jconsole\fP command fails for some reason.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-interval=n
+Set the update interval to \f2n\fP seconds (default is 4 seconds).
+.TP 3
+\-notile
+Do not tile windows initially (for two or more connections).
+.TP 3
+\-pluginpath plugins
+Specify a list of directories or JAR files which are searched for JConsole plugins. The \f2plugins\fP path should contain a provider\-configuration file named:
+.br
+.nf
+\f3
+.fl
+   META\-INF/services/com.sun.tools.jconsole.JConsolePlugin
+.fl
+\fP
+.fi
+containing one line for each plugin specifying the fully qualified class name of the class implementing the
+.na
+\f2com.sun.tools.jconsole.JConsolePlugin\fP @
+.fi
+http://download.oracle.com/javase/7/docs/jdk/api/jconsole/spec/com/sun/tools/jconsole/JConsolePlugin.html class.
+.TP 3
+\-version
+Output version information and exit.
+.TP 3
+\-help
+Output help message and exit.
+.TP 3
+\-J<flag>
+Pass <flag> to the Java virtual machine on which jconsole is run.
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+.na
+\f2Using JConsole\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html
+.TP 2
+o
+.na
+\f2Monitoring and Management for Java Platform\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/management/index.html
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jdb.1 b/jdk/src/bsd/doc/man/jdb.1
new file mode 100644
index 0000000..1cddcfc
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jdb.1
@@ -0,0 +1,330 @@
+." Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jdb 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jdb \- The Java Debugger
+.LP
+.LP
+\f3jdb\fP helps you find and fix bugs in Java language programs.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jdb\fP [ options ] [ class ] [ arguments ]
+.fl
+.fi
+
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options, as specified below.
+.TP 3
+class
+Name of the class to begin debugging.
+.TP 3
+arguments
+Arguments passed to the \f2main()\fP method of \f2class\fP.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The Java Debugger, \f3jdb\fP, is a simple command\-line debugger for Java classes. It is a demonstration of the
+.na
+\f2Java Platform Debugger Architecture\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jpda/index.html that provides inspection and debugging of a local or remote Java Virtual Machine.
+.LP
+.SS
+Starting a jdb Session
+.LP
+.LP
+There are many ways to start a jdb session. The most frequently used way is to have \f3jdb\fP launch a new Java Virtual Machine (VM) with the main class of the application to be debugged. This is done by substituting the command \f3jdb\fP for \f3java\fP in the command line. For example, if your application's main class is MyClass, you use the following command to debug it under JDB:
+.LP
+.nf
+\f3
+.fl
+ % jdb MyClass
+.fl
+\fP
+.fi
+
+.LP
+.LP
+When started this way, \f3jdb\fP invokes a second Java VM with any specified parameters, loads the specified class, and stops the VM before executing that class's first instruction.
+.LP
+.LP
+Another way to use \f3jdb\fP is by attaching it to a Java VM that is already running. Syntax for Starting a VM to which jdb will attach when the VM is running is as follows. This loads in\-process debugging libraries and specifies the kind of connection to be made.
+.LP
+.nf
+\f3
+.fl
+\-agentlib:jdwp=transport=dt_socket,server=y,suspend=n
+.fl
+\fP
+.fi
+
+.LP
+.LP
+For example, the following command will run the MyClass application, and allow \f3jdb\fP to connect to it at a later time.
+.LP
+.nf
+\f3
+.fl
+ % java \-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass
+.fl
+\fP
+.fi
+
+.LP
+.LP
+You can then attach \f3jdb\fP to the VM with the following commmand:
+.LP
+.nf
+\f3
+.fl
+ % jdb \-attach 8000
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Note that "MyClass" is not specified in the \f3jdb\fP command line in this case because \f3jdb\fP is connecting to an existing VM instead of launching a new one.
+.LP
+.LP
+There are many other ways to connect the debugger to a VM, and all of them are supported by \f3jdb\fP. The Java Platform Debugger Architecture has additional
+.na
+\f2documentation\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html on these connection options. For information on starting a J2SE 1.4.2 or early VM for use with \f3jdb\fP see the
+.na
+\f21.4.2 documentation\fP @
+.fi
+http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html
+.LP
+.SS
+Basic jdb Commands
+.LP
+.LP
+The following is a list of the basic \f3jdb\fP commands. The Java debugger supports other commands which you can list using \f3jdb\fP's \f2help\fP command.
+.LP
+.RS 3
+.TP 3
+help, or ?
+The most important \f3jdb\fP command, \f2help\fP displays the list of recognized commands with a brief description.
+.TP 3
+run
+After starting \f3jdb\fP, and setting any necessary breakpoints, you can use this command to start the execution the debugged application. This command is available only when \f3jdb\fP launches the debugged application (as opposed to attaching to an existing VM).
+.TP 3
+cont
+Continues execution of the debugged application after a breakpoint, exception, or step.
+.TP 3
+print
+Displays Java objects and primitive values. For variables or fields of primitive types, the actual value is printed. For objects, a short description is printed. See the \f2dump\fP command below for getting more information about an object.
+.br
+.br
+\f2NOTE: To display local variables, the containing class must have been compiled with the \fP\f2javac(1)\fP\f2 \fP\f2\-g\fP option.
+.br
+.br
+\f2print\fP supports many simple Java expressions including those with method invocations, for example:
+.RS 3
+.TP 2
+o
+\f2print MyClass.myStaticField\fP
+.TP 2
+o
+\f2print myObj.myInstanceField\fP
+.TP 2
+o
+\f2print i + j + k\fP \f2(i, j, k are primities and either fields or local variables)\fP
+.TP 2
+o
+\f2print myObj.myMethod()\fP \f2(if myMethod returns a non\-null)\fP
+.TP 2
+o
+\f2print new java.lang.String("Hello").length()\fP
+.RE
+.TP 3
+dump
+For primitive values, this command is identical to \f2print\fP. For objects, it prints the current value of each field defined in the object. Static and instance fields are included.
+.br
+.br
+The \f2dump\fP command supports the same set of expressions as the \f2print\fP command.
+.TP 3
+threads
+List the threads that are currently running. For each thread, its name and current status are printed, as well as an index that can be used for other commands, for example:
+.nf
+\f3
+.fl
+4. (java.lang.Thread)0x1 main      running
+.fl
+\fP
+.fi
+In this example, the thread index is 4, the thread is an instance of java.lang.Thread, the thread name is "main", and it is currently running,
+.TP 3
+thread
+Select a thread to be the current thread. Many \f3jdb\fP commands are based on the setting of the current thread. The thread is specified with the thread index described in the \f2threads\fP command above.
+.TP 3
+where
+\f2where\fP with no arguments dumps the stack of the current thread. \f2where all\fP dumps the stack of all threads in the current thread group. \f2where\fP \f2threadindex\fP dumps the stack of the specified thread.
+.br
+.br
+If the current thread is suspended (either through an event such as a breakpoint or through the \f2suspend\fP command), local variables and fields can be displayed with the \f2print\fP and \f2dump\fP commands. The \f2up\fP and \f2down\fP commands select which stack frame is current.
+.RE
+
+.LP
+.SS
+Breakpoints
+.LP
+.LP
+Breakpoints can be set in \f3jdb\fP at line numbers or at the first instruction of a method, for example:
+.LP
+.RS 3
+.TP 2
+o
+\f2stop at MyClass:22\fP \f2(sets a breakpoint at the first instruction for line 22 of the source file containing MyClass)\fP
+.TP 2
+o
+\f2stop in java.lang.String.length\fP \f2(sets a breakpoint at the beginnig of the method \fP\f2java.lang.String.length\fP)
+.TP 2
+o
+\f2stop in MyClass.<init>\fP \f2(<init> identifies the MyClass constructor)\fP
+.TP 2
+o
+\f2stop in MyClass.<clinit>\fP \f2(<clinit> identifies the static initialization code for MyClass)\fP
+.RE
+
+.LP
+.LP
+If a method is overloaded, you must also specify its argument types so that the proper method can be selected for a breakpoint. For example, "\f2MyClass.myMethod(int,java.lang.String)\fP", or "\f2MyClass.myMethod()\fP".
+.LP
+.LP
+The \f2clear\fP command removes breakpoints using a syntax as in "\f2clear\ MyClass:45\fP". Using the \f2clear\fP or command with no argument displays a list of all breakpoints currently set. The \f2cont\fP command continues execution.
+.LP
+.SS
+Stepping
+.LP
+.LP
+The \f2step\fP commands advances execution to the next line whether it is in the current stack frame or a called method. The \f2next\fP command advances execution to the next line in the current stack frame.
+.LP
+.SS
+Exceptions
+.LP
+.LP
+When an exception occurs for which there isn't a catch statement anywhere in the throwing thread's call stack, the VM normally prints an exception trace and exits. When running under \f3jdb\fP, however, control returns to \f3jdb\fP at the offending throw. You can then use \f3jdb\fP to diagnose the cause of the exception.
+.LP
+.LP
+Use the \f2catch\fP command to cause the debugged application to stop at other thrown exceptions, for example: "\f2catch java.io.FileNotFoundException\fP" or "\f2catch mypackage.BigTroubleException\fP. Any exception which is an instance of the specifield class (or of a subclass) will stop the application at the point where it is thrown.
+.LP
+.LP
+The \f2ignore\fP command negates the effect of a previous \f2catch\fP command.
+.LP
+.LP
+\f2NOTE: The \fP\f2ignore\fP command does not cause the debugged VM to ignore specific exceptions, only the debugger.
+.LP
+.SH "Command Line Options"
+.LP
+.LP
+When you use \f3jdb\fP in place of the Java application launcher on the command line, \f3jdb\fP accepts many of the same options as the java command, including \f2\-D\fP, \f2\-classpath\fP, and \f2\-X<option>\fP.
+.LP
+.LP
+The following additional options are accepted by \f3jdb\fP:
+.LP
+.RS 3
+.TP 3
+\-help
+Displays a help message.
+.TP 3
+\-sourcepath <dir1:dir2:...>
+Uses the given path in searching for source files in the specified path. If this option is not specified, the default path of "." is used.
+.TP 3
+\-attach <address>
+Attaches the debugger to previously running VM using the default connection mechanism.
+.TP 3
+\-listen <address>
+Waits for a running VM to connect at the specified address using standard connector.
+.TP 3
+\-listenany
+Waits for a running VM to connect at any available address using standard connector.
+.TP 3
+\-launch
+Launches the debugged application immediately upon startup of jdb. This option removes the need for using the \f2run\fP command. The debuged application is launched and then stopped just before the initial application class is loaded. At that point you can set any necessary breakpoints and use the \f2cont\fP to continue execution.
+.TP 3
+\-listconnectors
+List the connectors available in this VM
+.TP 3
+\-connect <connector\-name>:<name1>=<value1>,...
+Connects to target VM using named connector with listed argument values.
+.TP 3
+\-dbgtrace [flags]
+Prints info for debugging jdb.
+.TP 3
+\-tclient
+Runs the application in the Java HotSpot(tm) VM (Client).
+.TP 3
+\-tserver
+Runs the application in the Java HotSpot(tm) VM (Server).
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine used to run jdb. (Options for the application Java virtual machine are passed to the \f3run\fP command.) For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes.
+.RE
+
+.LP
+.LP
+Other options are supported for alternate mechanisms for connecting the debugger and the VM it is to debug. The Java Platform Debugger Architecture has additional
+.na
+\f2documentation\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html on these connection alternatives.
+.LP
+.SS
+Options Forwarded to Debuggee Process
+.LP
+.RS 3
+.TP 3
+\-v \-verbose[:class|gc|jni]
+Turns on verbose mode.
+.TP 3
+\-D<name>=<value>
+Sets a system property.
+.TP 3
+\-classpath <directories separated by ":">
+Lists directories in which to look for classes.
+.TP 3
+\-X<option>
+Non\-standard target VM option
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.LP
+javac(1), java(1), javah(1), javap(1), javadoc(1).
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jhat.1 b/jdk/src/bsd/doc/man/jhat.1
new file mode 100644
index 0000000..7c9fad6
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jhat.1
@@ -0,0 +1,141 @@
+." Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jhat 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jhat \- Java Heap Analysis Tool
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jhat\fP [ \f2options\fP ] <heap\-dump\-file>
+.fl
+
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+options
+Options, if used, should follow immediately after the command name.
+.TP 3
+heap\-dump\-file
+Java binary heap dump file to be browsed. For a dump file that contains multiple heap dumps, you may specify which dump in the file by appending "#<number> to the file name, i.e. "foo.hprof#3".
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3jhat\fP command parses a java heap dump file and launches a webserver. jhat enables you to browse heap dumps using your favorite webbrowser. jhat supports pre\-designed queries (such as 'show all instances of a known class "Foo"') as well as \f3OQL\fP (\f3O\fPbject \f3Q\fPuery \f3L\fPanguage) \- a SQL\-like query language to query heap dumps. Help on OQL is available from the OQL help page shown by jhat. With the default port, OQL help is available at http://localhost:7000/oqlhelp/
+.LP
+.LP
+There are several ways to generate a java heap dump:
+.LP
+.RS 3
+.TP 2
+o
+Use jmap(1) \-dump option to obtain a heap dump at runtime;
+.TP 2
+o
+Use jconsole(1) option to obtain a heap dump via
+.na
+\f2HotSpotDiagnosticMXBean\fP @
+.fi
+http://download.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/HotSpotDiagnosticMXBean.html at runtime;
+.TP 2
+o
+Heap dump will be generated when OutOfMemoryError is thrown by specifying \-XX:+HeapDumpOnOutOfMemoryError VM option;
+.TP 2
+o
+Use
+.na
+\f2hprof\fP @
+.fi
+http://java.sun.com/developer/technicalArticles/Programming/HPROF.html.
+.RE
+
+.LP
+.LP
+\f3NOTE:\fP This tool is \f3experimental\fP and may \f3not\fP be available in future versions of the JDK.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-stack false/true
+Turn off tracking object allocation call stack. Note that if allocation site information is not available in the heap dump, you have to set this flag to false. Default is true.
+.TP 3
+\-refs false/true
+Turn off tracking of references to objects. Default is true. By default, back pointers (objects pointing to a given object a.k.a referrers or in\-coming references) are calculated for all objects in the heap.
+.TP 3
+\-port port\-number
+Set the port for the jhat's HTTP server. Default is 7000.
+.TP 3
+\-exclude exclude\-file
+Specify a file that lists data members that should be excluded from the "reachable objects" query. For example, if the file lists \f2java.lang.String.value\fP, then, whenever list of objects reachable from a specific object "o" are calculated, reference paths involving \f2java.lang.String.value\fP field will not considered.
+.TP 3
+\-baseline baseline\-dump\-file
+Specify a baseline heap dump. Objects in both heap dumps with the same object ID will be marked as not being "new". Other objects will be marked as "new". This is useful while comparing two different heap dumps.
+.TP 3
+\-debug int
+Set debug level for this tool. 0 means no debug output. Set higher values for more verbose modes.
+.TP 3
+\-version
+Report version number and exit.
+.TP 3
+\-h
+Output help message and exit.
+.TP 3
+\-help
+Output help message and exit.
+.TP 3
+\-J<flag>
+Pass <flag> to the Java virtual machine on which jhat is run. For example, \-J\-Xmx512m to use a maximum heap size of 512MB.
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+jmap(1)
+.TP 2
+o
+jconsole(1)
+.TP 2
+o
+.na
+\f2hprof \- Heap and CPU profiling tool\fP @
+.fi
+http://java.sun.com/developer/technicalArticles/Programming/HPROF.html
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jinfo.1 b/jdk/src/bsd/doc/man/jinfo.1
new file mode 100644
index 0000000..5355d54
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jinfo.1
@@ -0,0 +1,147 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jinfo 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jinfo \- Configuration Info
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jinfo\fP [ option ] pid
+.fl
+\f3jinfo\fP [ option ] executable core
+.fl
+\f3jinfo\fP [ option ] [server\-id@]remote\-hostname\-or\-IP
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+option
+Options are mutually exclusive. Option, if used, should follow immediately after the command name.
+.RE
+
+.LP
+.RS 3
+.TP 3
+pid
+process id for which the configuration info is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, jps(1) may be used.
+.RE
+
+.LP
+.RS 3
+.TP 3
+executable
+Java executable from which the core dump was produced.
+.RE
+
+.LP
+.RS 3
+.TP 3
+core
+core file for which the configuration info is to be printed.
+.RE
+
+.LP
+.RS 3
+.TP 3
+remote\-hostname\-or\-IP
+remote debug server's (see jsadebugd(1)) hostname or IP address.
+.RE
+
+.LP
+.RS 3
+.TP 3
+server\-id
+optional unique id, if multiple debug servers are running on the same remote host.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3jinfo\fP prints Java configuration information for a given Java process or core file or a remote debug server. Configuration information includes Java System properties and Java virtual machine command line flags. If the given process is running on a 64\-bit VM, you may need to specify the \f2\-J\-d64\fP option, e.g.:
+.br
+jinfo \-J\-d64 \-sysprops pid
+.LP
+.LP
+\f3NOTE \- This utility is unsupported and may or may not be available in future versions of the JDK. In Windows Systems where dbgeng.dll is not present, 'Debugging Tools For Windows' need to be installed to have these tools working. Also, \fP\f4PATH\fP\f3 environment variable should contain the location of \fP\f4jvm.dll\fP\f3 used by the target process or the location from which the Crash Dump file was produced.\fP
+.LP
+.LP
+\f3For example, \fP\f4set PATH=<jdk>\\jre\\bin\\client;%PATH%\fP
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+<no option>
+prints both command line flags as well as System properties name, value pairs.
+.br
+.TP 3
+\-flag name
+prints the name and value of the given command line flag.
+.br
+.TP 3
+\-flag [+|\-]name
+enables or disables the given boolean command line flag.
+.br
+.TP 3
+\-flag name=value
+sets the given command line flag to the specified value.
+.br
+.TP 3
+\-flags
+prints command line flags passed to the JVM. pairs.
+.br
+.TP 3
+\-sysprops
+prints Java System properties as name, value pairs.
+.br
+.TP 3
+\-h
+prints a help message
+.TP 3
+\-help
+prints a help message
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+jps(1)
+.TP 2
+o
+jsadebugd(1)
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jmap.1 b/jdk/src/bsd/doc/man/jmap.1
new file mode 100644
index 0000000..2bb0ffc
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jmap.1
@@ -0,0 +1,160 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jmap 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jmap \- Memory Map
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jmap\fP [ option ] pid
+.fl
+\f3jmap\fP [ option ] executable core
+.fl
+\f3jmap\fP [ option ] [server\-id@]remote\-hostname\-or\-IP
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+option
+Options are mutually exclusive. Option, if used, should follow immediately after the command name.
+.TP 3
+pid
+process id for which the memory map is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, jps(1) may be used.
+.br
+.TP 3
+executable
+Java executable from which the core dump was produced.
+.br
+.TP 3
+core
+core file for which the memory map is to be printed.
+.br
+.TP 3
+remote\-hostname\-or\-IP
+remote debug server's (see jsadebugd(1)) hostname or IP address.
+.br
+.TP 3
+server\-id
+optional unique id, if multiple debug servers are running on the same remote host.
+.br
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3jmap\fP prints shared object memory maps or heap memory details of a given process or core file or a remote debug server. If the given process is running on a 64\-bit VM, you may need to specify the \f2\-J\-d64\fP option, e.g.:
+.LP
+.nf
+\f3
+.fl
+jmap \-J\-d64 \-heap pid
+.fl
+\fP
+.fi
+
+.LP
+.LP
+\f3NOTE: This utility is unsupported and may or may not be available in future versions of the JDK. In Windows Systems where dbgeng.dll is not present, 'Debugging Tools For Windows' needs to be installed to have these tools working. Also, \fP\f4PATH\fP\f3 environment variable should contain the location of \fP\f4jvm.dll\fP\f3 used by the target process or the location from which the Crash Dump file was produced.\fP
+.LP
+.LP
+\f3For example, \fP\f4set PATH=<jdk>\\jre\\bin\\client;%PATH%\fP
+.LP
+.br
+
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+<no option>
+When no option is used jmap prints shared object mappings. For each shared object loaded in the target VM, start address, the size of the mapping, and the full path of the shared object file are printed. This is similar to the Solaris \f3pmap\fP utility.
+.br
+.TP 3
+\-dump:[live,]format=b,file=<filename>
+Dumps the Java heap in hprof binary format to filename. The \f2live\fP suboption is optional. If specified, only the live objects in the heap are dumped. To browse the heap dump, you can use jhat(1) (Java Heap Analysis Tool) to read the generated file.
+.br
+.TP 3
+\-finalizerinfo
+Prints information on objects awaiting finalization.
+.br
+.TP 3
+\-heap
+Prints a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed.
+.br
+.TP 3
+\-histo[:live]
+Prints a histogram of the heap. For each Java class, number of objects, memory size in bytes, and fully qualified class names are printed. VM internal class names are printed with '*' prefix. If the \f2live\fP suboption is specified, only live objects are counted.
+.br
+.TP 3
+\-permstat
+Prints class loader wise statistics of permanent generation of Java heap. For each class loader, its name, liveness, address, parent class loader, and the number and size of classes it has loaded are printed. In addition, the number and size of interned Strings are printed.
+.br
+.TP 3
+\-F
+Force. Use with jmap \-dump or jmap \-histo option if the pid does not respond. The \f2live\fP suboption is not supported in this mode.
+.br
+.TP 3
+\-h
+Prints a help message.
+.br
+.br
+.TP 3
+\-help
+Prints a help message.
+.br
+.br
+.TP 3
+\-J<flag>
+Passes <flag> to the Java virtual machine on which jmap is run.
+.br
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+pmap(1)
+.TP 2
+o
+jhat(1)
+.TP 2
+o
+jps(1)
+.TP 2
+o
+jsadebugd(1)
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jps.1 b/jdk/src/bsd/doc/man/jps.1
new file mode 100644
index 0000000..37d110e
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jps.1
@@ -0,0 +1,250 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jps 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jps \- Java Virtual Machine Process Status Tool
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jps\fP [ \f2options\fP ] [ \f2hostid\fP ]
+.br
+
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options.
+.TP 3
+hostid
+The host identifier of the host for which the process report should be generated. The \f2hostid\fP may include optional components that indicate the communications protocol, port number, and other implementation specific data.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3jps\fP tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. The tool is limited to reporting information on JVMs for which it has the access permissions.
+.LP
+.LP
+If \f3jps\fP is run without specifying a \f2hostid\fP, it will look for instrumented JVMs on the local host. If started with a \f2hostid\fP, it will look for JVMs on the indicated host, using the specified protocol and port. A \f3jstatd\fP process is assumed to be running on the target host.
+.LP
+.LP
+The \f3jps\fP command will report the local VM identifier, or \f2lvmid\fP, for each instrumented JVM found on the target system. The \f3lvmid\fP is typically, but not necessarily, the operating system's process identifier for the JVM process. With no options, \f3jps\fP will list each Java application's \f2lvmid\fP followed by the short form of the application's class name or jar file name. The short form of the class name or JAR file name omits the class's package information or the JAR files path information.
+.LP
+.LP
+The \f3jps\fP command uses the \f3java\fP launcher to find the class name and arguments passed to the \f2main\fP method. If the target JVM is started with a custom launcher, the class name (or JAR file name) and the arguments to the \f2main\fP method will not be available. In this case, the \f3jps\fP command will output the string \f2Unknown\fP for the class name or JAR file name and for the arguments to the main method.
+.LP
+.LP
+The list of JVMs produced by the \f3jps\fP command may be limited by the permissions granted to the principal running the command. The command will only list the JVMs for which the principle has access rights as determined by operating system specific access control mechanisms.
+.LP
+.LP
+\f3NOTE:\fP This utility is unsupported and may not be available in future versions of the JDK. It is not currently available on Windows 98 and Windows ME platforms.
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+The \f3jps\fP command supports a number of options that modify the output of the command. These options are subject to change or removal in the future.
+.LP
+.RS 3
+.TP 3
+\-q
+Suppress the output of the class name, JAR file name, and arguments passed to the \f2main\fP method, producing only a list of local VM identifiers.
+.TP 3
+\-m
+Output the arguments passed to the main method. The output may be null for embedded JVMs.
+.TP 3
+\-l
+Output the full package name for the application's main class or the full path name to the application's JAR file.
+.TP 3
+\-v
+Output the arguments passed to the JVM.
+.TP 3
+\-V
+Output the arguments passed to the JVM through the flags file (the .hotspotrc file or the file specified by the \-XX:Flags=<\f2filename\fP> argument).
+.TP 3
+\-Joption
+Pass \f2option\fP to the \f3java\fP launcher called by \f3jps\fP. For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. It is a common convention for \f3\-J\fP to pass options to the underlying VM executing applications written in Java.
+.RE
+
+.LP
+.SS
+HOST IDENTIFIER
+.LP
+.LP
+The host identifier, or \f2hostid\fP is a string that indicates the target system. The syntax of the \f2hostid\fP string largely corresponds to the syntax of a URI:
+.LP
+.nf
+\f3
+.fl
+[\fP\f4protocol\fP\f3:][[//]\fP\f4hostname\fP\f3][:\fP\f4port\fP\f3][/\fP\f4servername\fP\f3]\fP
+.br
+\f3
+.fl
+\fP
+.fi
+
+.LP
+.RS 3
+.TP 3
+protocol
+The communications protocol. If the \f2protocol\fP is omitted and a \f2hostname\fP is not specified, the default protocol is a platform specific, optimized, local protocol. If the \f2protocol\fP is omitted and a \f2hostname\fP is specified, then the default protocol is \f3rmi\fP.
+.TP 3
+hostname
+A hostname or IP address indicating the target host. If \f2hostname\fP is omitted, then the target host is the local host.
+.TP 3
+port
+The default port for communicating with the remote server. If the \f2hostname\fP is omitted or the \f2protocol\fP specifies an optimized, local protocol, then \f2port\fP is ignored. Otherwise, treatment of the \f2port\fP parameter is implementation specific. For the default \f3rmi\fP protocol the \f2port\fP indicates the port number for the rmiregistry on the remote host. If \f2port\fP is omitted, and \f2protocol\fP indicates \f3rmi\fP, then the default rmiregistry port (1099) is used.
+.TP 3
+servername
+The treatment of this parameter depends on the implementation. For the optimized, local protocol, this field is ignored. For the \f3rmi\fP protocol, this parameter is a string representing the name of the RMI remote object on the remote host. See the \f3\-n\fP option for the jstatd(1) command.
+.RE
+
+.LP
+.SH "OUTPUT FORMAT"
+.LP
+.LP
+The output of the \f3jps\fP command follows the following pattern:
+.LP
+.nf
+\f3
+.fl
+\fP\f4lvmid\fP\f3 [ [ \fP\f4classname\fP\f3 | \fP\f4JARfilename\fP\f3 | "Unknown"] [ \fP\f4arg\fP\f3* ] [ \fP\f4jvmarg\fP\f3* ] ]\fP
+.br
+\f3
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Where all output tokens are separated by white space. An \f2arg\fP that includes embedded white space will introduce ambiguity when attempting to map arguments to their actual positional parameters.
+.br
+.br
+\f3NOTE\fP: You are advised not to write scripts to parse \f3jps\fP output since the format may change in future releases. If you choose to write scripts that parse \f3jps\fP output, expect to modify them for future releases of this tool.
+.br
+
+.LP
+.SH "EXAMPLES"
+.LP
+.LP
+This section provides examples of the \f3jps\fP command.
+.LP
+.LP
+Listing the instrumented JVMs on the local host:
+.LP
+.nf
+\f3
+.fl
+\fP\f3jps\fP
+.br
+
+.fl
+18027 Java2Demo.JAR
+.br
+
+.fl
+18032 jps
+.br
+
+.fl
+18005 jstat
+.br
+
+.fl
+.fi
+
+.LP
+.LP
+Listing the instrumented JVMs on a remote host:
+.LP
+.LP
+This example assumes that the \f3jstat\fP server and either the its internal RMI registry or a separate external \f3rmiregistry\fP process are running on the remote host on the default port (port 1099). It also assumes that the local host has appropriate permissions to access the remote host. This example also includes the \f2\-l\fP option to output the long form of the class names or JAR file names.
+.LP
+.nf
+\f3
+.fl
+\fP\f3jps \-l remote.domain\fP
+.br
+
+.fl
+3002 /opt/jdk1.7.0/demo/jfc/Java2D/Java2Demo.JAR
+.br
+
+.fl
+2857 sun.tools.jstatd.jstatd
+.br
+
+.fl
+.fi
+
+.LP
+.LP
+Listing the instrumented JVMs on a remote host with a non\-default port for the RMI registry
+.LP
+.LP
+This example assumes that the \f3jstatd\fP server, with an internal RMI registry bound to port 2002, is running on the remote host. This example also uses the \f2\-m\fP option to include the arguments passed to the \f2main\fP method of each of the listed Java applications.
+.LP
+.nf
+\f3
+.fl
+\fP\f3jps \-m remote.domain:2002\fP
+.br
+
+.fl
+3002 /opt/jdk1.7.0/demo/jfc/Java2D/Java2Demo.JAR
+.br
+
+.fl
+3102 sun.tools.jstatd.jstatd \-p 2002
+.fl
+.fi
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+java(1) \- the Java Application Launcher
+.TP 2
+o
+jstat(1) \- the Java virtual machine Statistics Monitoring Tool
+.TP 2
+o
+jstatd(1) \- the jstat daemon
+.TP 2
+o
+rmiregistry(1) \- the Java Remote Object Registry
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jrunscript.1 b/jdk/src/bsd/doc/man/jrunscript.1
new file mode 100644
index 0000000..4f46404
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jrunscript.1
@@ -0,0 +1,187 @@
+." Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jrunscript 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jrunscript \- command line script shell
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jrunscript\fP [ \f2options\fP ] [ arguments... ]
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+options
+Options, if used, should follow immediately after the command name.
+.TP 3
+arguments
+Arguments, if used, should follow immediately after options or command name.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3jrunscript\fP is a command line script shell. jrunscript supports both an interactive (read\-eval\-print) mode and a batch (\-f option) mode of script execution. This is a scripting language independent shell. By default, JavaScript is the language used, but the \-l option can be used to specify a different language. Through Java to scripting language communication, jrunscript supports "exploratory programming" style.
+.LP
+.LP
+\f3NOTE:\fP This tool is \f3experimental\fP and may \f3not\fP be available in future versions of the JDK.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-classpath path
+Specify where to find the user's .class files that are accessed by the script.
+.TP 3
+\-cp path
+This is a synonym for \-classpath \f2path\fP
+.TP 3
+\-Dname=value
+Set a Java system property.
+.TP 3
+\-J<flag>
+Pass <flag> directly to the Java virtual machine on which jrunscript is run.
+.TP 3
+\-l language
+Use the specified scripting language. By default, JavaScript is used. Note that to use other scripting languages, you also need to specify the corresponding script engine's jar file using \-cp or \-classpath option.
+.TP 3
+\-e script
+Evaluate the given script. This option can be used to run "one liner" scripts specified completely on the command line.
+.TP 3
+\-encoding encoding
+Specify the character encoding used while reading script files.
+.TP 3
+\-f script\-file
+Evaluate the given script file (batch mode).
+.TP 3
+\-f \-
+Read and evaluate a script from standard input (interactive mode).
+.TP 3
+\-help\
+Output help message and exit.
+.TP 3
+\-?\
+Output help message and exit.
+.TP 3
+\-q\
+List all script engines available and exit.
+.RE
+
+.LP
+.SH "ARGUMENTS"
+.LP
+.LP
+If [arguments...] are present and if no \f3\-e\fP or \f3\-f\fP option is used, then the first argument is the script file and the rest of the arguments, if any, are passed as script arguments. If [arguments..] and \f3\-e\fP or \f3\-f\fP option are used, then all [arguments..] are passed as script arguments. If [arguments..], \f3\-e\fP and \f3\-f\fP are missing, interactive mode is used. Script arguments are available to a script in an engine variable named "arguments" of type String array.
+.LP
+.SH "EXAMPLES"
+.LP
+.SS
+Executing inline scripts
+.LP
+.nf
+\f3
+.fl
+jrunscript \-e "print('hello world')"
+.fl
+jrunscript \-e "cat('http://java.sun.com')"
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Use specified language and evaluate given script file
+.LP
+.nf
+\f3
+.fl
+jrunscript \-l js \-f test.js
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Interactive mode
+.LP
+.nf
+\f3
+.fl
+jrunscript
+.fl
+js> print('Hello World\\n');
+.fl
+Hello World
+.fl
+js> 34 + 55
+.fl
+89.0
+.fl
+js> t = new java.lang.Thread(function() { print('Hello World\\n'); })
+.fl
+Thread[Thread\-0,5,main]
+.fl
+js> t.start()
+.fl
+js> Hello World
+.fl
+
+.fl
+js>
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Run script file with script arguments
+.LP
+.nf
+\f3
+.fl
+jrunscript test.js arg1 arg2 arg3
+.fl
+\fP
+.fi
+
+.LP
+test.js is script file to execute and arg1, arg2 and arg3 are passed to script as script arguments. Script can access these using "arguments" array.
+.SH "SEE ALSO"
+.LP
+.LP
+If JavaScript is used, then before evaluating any user defined script, jrunscript initializes certain built\-in functions and objects. These JavaScript built\-ins are documented in
+.na
+\f2jsdocs\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/share/jsdocs/allclasses\-noframe.html.
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jsadebugd.1 b/jdk/src/bsd/doc/man/jsadebugd.1
new file mode 100644
index 0000000..acef5ee
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jsadebugd.1
@@ -0,0 +1,109 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jsadebugd 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jsadebugd \- Serviceability Agent Debug Daemon
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jsadebugd\fP pid [ server\-id ]
+.fl
+\f3jsadebugd\fP executable core [ server\-id ]
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+pid
+process id of the process to which the debug server should attach. The process must be a Java process. To get a list of Java processes running on a machine, jps(1) may be used. At most one instance of the debug server may be attached to a single process.
+.TP 3
+executable
+Java executable from which the core dump was produced
+.TP 3
+core
+Core file to which the debug server should attach.
+.TP 3
+server\-id
+Optional unique id, needed if multiple debug servers are started on the same machine. This ID must be used by remote clients to identify the particular debug server to attach. Within a single machine, this ID must be unique.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3jsadebugd\fP attaches to a Java process or core file and acts as a debug server. Remote clients such as jstack(1), jmap(1), and jinfo(1) can attach to the server using Java Remote Method Invocation (RMI). Before starting \f2jsadebugd\fP,
+.na
+\f2rmiregistry\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#rmi must be started with:
+.LP
+.nf
+\f3
+.fl
+\fP\f4rmiregistry \-J\-Xbootclasspath/p:$JAVA_HOME/lib/sajdi.jar\fP\f3
+.fl
+\fP
+.fi
+
+.LP
+.LP
+where \f2$JAVA_HOME\fP is the JDK installation directory. If rmiregistry was not started, jsadebugd will start an rmiregistry in a standard (1099) port internally. Debug server may be stopped by sending SIGINT (pressing Ctrl\-C) to it.
+.LP
+.LP
+\f3NOTE\fP \- This utility is unsupported and may or may not be available in future versions of the JDK. In Windows Systems where dbgeng.dll is not present, 'Debugging Tools For Windows' needs to be installed to have these tools working. Also, \f2PATH\fP environment variable should contain the location of \f2jvm.dll\fP used by the target process or the location from which the Crash Dump file was produced.
+.LP
+.LP
+For example, \f2set PATH=<jdk>\\jre\\bin\\client;%PATH%\fP
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+jinfo(1)
+.TP 2
+o
+jmap(1)
+.TP 2
+o
+jps(1)
+.TP 2
+o
+jstack(1)
+.TP 2
+o
+.na
+\f2rmiregistry\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#rmi
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jstack.1 b/jdk/src/bsd/doc/man/jstack.1
new file mode 100644
index 0000000..add01de
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jstack.1
@@ -0,0 +1,148 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jstack 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jstack \- Stack Trace
+.br
+
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jstack\fP [ option ] pid
+.fl
+\f3jstack\fP [ option ] executable core
+.fl
+\f3jstack\fP [ option ] [server\-id@]remote\-hostname\-or\-IP
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.LP
+Options are mutually exclusive. Option, if used, should follow immediately after the command name. See OPTIONS.
+.LP
+.RS 3
+.TP 3
+pid
+process id for which the stack trace is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, jps(1) may be used.
+.RE
+
+.LP
+.RS 3
+.TP 3
+executable
+Java executable from which the core dump was produced.
+.br
+.TP 3
+core
+core file for which the stack trace is to be printed.
+.br
+.TP 3
+remote\-hostname\-or\-IP
+remote debug server's (see jsadebugd(1)) hostname or IP address.
+.br
+.TP 3
+server\-id
+optional unique id, if multiple debug servers are running on the same remote host.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3jstack\fP prints Java stack traces of Java threads for a given Java process or core file or a remote debug server. For each Java frame, the full class name, method name, 'bci' (byte code index) and line number, if available, are printed. With the \-m option, jstack prints both Java and native frames of all threads along with the 'pc' (program counter). For each native frame, the closest native symbol to 'pc', if available, is printed. C++ mangled names are not demangled. To demangle C++ names, the output of this command may be piped to \f3c++filt\fP. If the given process is running on a 64\-bit VM, you may need to specify the \f2\-J\-d64\fP option, e.g.:
+.br
+
+.LP
+.nf
+\f3
+.fl
+jstack \-J\-d64 \-m pid
+.fl
+\fP
+.fi
+
+.LP
+.LP
+\f3NOTE\fP \- This utility is unsupported and may or may not be available in future versions of the JDK. In Windows Systems where dbgeng.dll is not present, 'Debugging Tools For Windows' needs to be installed to have these tools working. Also, \f2PATH\fP environment variable should contain the location of \f2jvm.dll\fP used by the target process or the location from which the Crash Dump file was produced.
+.LP
+.LP
+For example, \f2set PATH=<jdk>\\jre\\bin\\client;%PATH%\fP
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-F
+Force a stack dump when 'jstack [\-l] pid' does not respond.
+.TP 3
+\-l
+Long listing. Prints additional information about locks such as list of owned java.util.concurrent
+.na
+\f2ownable synchronizers\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/java/util/concurrent/locks/AbstractOwnableSynchronizer.html.
+.TP 3
+\-m
+prints mixed mode (both Java and native C/C++ frames) stack trace.
+.TP 3
+\-h
+prints a help message.
+.br
+.br
+.TP 3
+\-help
+prints a help message
+.br
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+pstack(1)
+.TP 2
+o
+c++filt(1)
+.TP 2
+o
+jps(1)
+.TP 2
+o
+jsadebugd(1)
+.RE
+
+.LP
+.SH "KNOWN BUGS"
+.LP
+.LP
+Mixed mode stack trace, the \-m option, does not work with the remote debug server.
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jstat.1 b/jdk/src/bsd/doc/man/jstat.1
new file mode 100644
index 0000000..9c6fe7b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jstat.1
@@ -0,0 +1,5329 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jstat 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jstat \- Java Virtual Machine Statistics Monitoring Tool
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3jstat\fP [ \f2generalOption\fP | \f2outputOptions\fP \f2vmid\fP [\f2interval\fP[s|ms] [\f2count\fP]] ]
+.fl
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+generalOption
+A single general command\-line option (\-help, \-options, or \-version)
+.TP 3
+outputOptions
+One or more output options, consisting of a single \f2statOption\fP, plus any of the \-t, \-h, and \-J options.
+.TP 3
+vmid
+Virtual machine identifier, a string indicating the target Java virtual machine (JVM). The general syntax is
+.nf
+\f3
+.fl
+[\fP\f4protocol\fP\f3:][//]\fP\f4lvmid\fP[@\f2hostname\fP[:\f2port\fP]/\f2servername\fP]
+.fl
+.fi
+The syntax of the vmid string largely corresponds to the syntax of a URI. The \f2vmid\fP can vary from a simple integer representing a local JVM to a more complex construction specifying a communications protocol, port number, and other implementation\-specific values. See Virtual Machine Identifier for details.
+.TP 3
+interval[s|ms]
+Sampling interval in the specified units, seconds (s) or milliseconds (ms). Default units are milliseconds. Must be a positive integer. If specified, \f3jstat\fP will produce its output at each interval.
+.TP 3
+count
+Number of samples to display. Default value is infinity; that is, \f3jstat\fP displays statistics until the target JVM terminates or the \f3jstat\fP command is terminated. Must be a positive integer.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3jstat\fP tool displays performance statistics for an instrumented HotSpot Java virtual machine (JVM). The target JVM is identified by its virtual machine identifier, or \f2vmid\fP option described below.
+.LP
+.LP
+\f3NOTE\fP: This utility is unsupported and may not be available in future versions of the JDK. It is not currently available on Windows 98 and Windows ME. platforms.
+.br
+
+.LP
+.SS
+VIRTUAL MACHINE IDENTIFIER
+.LP
+.LP
+The syntax of the \f2vmid\fP string largely corresponds to the syntax of a URI:
+.LP
+.nf
+\f3
+.fl
+[\fP\f4protocol\fP\f3:][//]\fP\f4lvmid\fP[@\f2hostname\fP][:\f2port\fP][/\f2servername\fP]
+.fl
+.fi
+
+.LP
+.RS 3
+.TP 3
+protocol
+The communications protocol. If the \f2protocol\fP is omitted and a \f2hostname\fP is not specified, the default protocol is a platform specific optimized local protocol. If the \f2protocol\fP is omitted and a \f2hostname\fP is specified, then the default protocol is \f3rmi\fP.
+.TP 3
+lvmid
+The local virtual machine identifier for the target JVM. The \f2lvmid\fP is a platform\-specific value that uniquely identifies a JVM on a system. The \f2lvmid\fP is the only required component of a virtual machine identifier. The \f2lvmid\fP is typically, but not necessarily, the operating system's process identifier for the target JVM process. You can use the jps(1) command to determine the \f2lvmid\fP. Also, you can determine \f2lvmid\fP on Unix platforms with the \f3ps\fP command, and on Windows with the Windows Task Manager.
+.TP 3
+hostname
+A hostname or IP address indicating the target host. If \f2hostname\fP is omitted, then the target host is the local host.
+.TP 3
+port
+The default port for communicating with the remote server. If the \f2hostname\fP is omitted or the \f2protocol\fP specifies an optimized, local protocol, then \f2port\fP is ignored. Otherwise, treatment of the \f2port\fP parameter is implementation specific. For the default \f3rmi\fP protocol, the \f2port\fP indicates the port number for the rmiregistry on the remote host. If \f2port\fP is omitted, and \f2protocol\fP indicates \f3rmi\fP, then the default rmiregistry port (1099) is used.
+.TP 3
+servername
+The treatment of this parameter depends on implementation. For the optimized local protocol, this field is ignored. For the \f3rmi\fP protocol, it represents the name of the RMI remote object on the remote host.
+.RE
+
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+The \f3jstat\fP command supports two types of options, general options and output options. General options cause \f3jstat\fP to display simple usage and version information. Output options determine the content and format of the statistical output.
+.br
+
+.LP
+.LP
+\f3NOTE\fP: All options, and their functionality are subject to change or removal in future releases.
+.LP
+.SS
+GENERAL OPTIONS
+.LP
+.LP
+If you specify one of the general options, you cannot specify any other option or parameter.
+.LP
+.RS 3
+.TP 3
+\-help
+Display help message.
+.TP 3
+\-version
+Display version information.
+.TP 3
+\-options
+Display list of statistics options. See the Output Options section below.
+.RE
+
+.LP
+.SS
+OUTPUT OPTIONS
+.LP
+.LP
+If you do not specify a general option, then you can specify output options. Output options determine the content and format of \f3jstat\fP's output, and consist of a single \f2statOption\fP, plus any of the other output options (\-h, \-t, and \-J). The \f2statOption\fP must come first.
+.LP
+.LP
+Output is formatted as a table, with columns are separated by spaces. A header row with titles describes the columns. Use the \f3\-h\fP option to set the frequency at which the header is displayed. Column header names are generally consistent between the different options. In general, if two options provide a column with the same name, then the data source for the two columns are the same.
+.LP
+.LP
+Use the \f3\-t\fP option to display a time stamp column, labeled \f2Timestamp\fP as the first column of output. The \f2Timestamp\fP column contains the elapsed time, in seconds, since startup of the target JVM. The resolution of the time stamp is dependent on various factors and is subject to variation due to delayed thread scheduling on heavily loaded systems.
+.LP
+.LP
+Use the \f2interval\fP and \f2count\fP parameters to determine how frequently and how many times, respectively, \f3jstat\fP displays its output.
+.LP
+.LP
+\f3NOTE\fP: You are advised not to write scripts to parse \f3jstat's\fP output since the format may change in future releases. If you choose to write scripts that parse \f3jstat\fP output, expect to modify them for future releases of this tool.
+.LP
+.RS 3
+.TP 3
+\-statOption
+Determines the statistics information that \f3jstat\fP displays. The following table lists the available options. Use the \f3\-options\fP general option to display the list of options for a particular platform installation.
+.br
+.br
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics on the behavior of the class loader.
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the behavior of the HotSpot Just\-in\-Time compiler.
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the behavior of the garbage collected heap.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the capacities of the generations and their corresponding spaces.
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Summary of garbage collection statistics (same as \f3\-gcutil\fP), with the cause of the last and current (if applicable) garbage collection events.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the behavior of the new generation.
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the sizes of the new generations and its corresponding spaces.
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the behavior of the old and permanent generations.
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the sizes of the old generation.
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Statistics of the sizes of the permanent generation.
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di k+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Summary of garbage collection statistics.
+.br
+.di
+.nr k| \n(dn
+.nr k- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di l+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+HotSpot compilation method statistics.
+.br
+.di
+.nr l| \n(dn
+.nr l- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \w\f3Option\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wclass
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wcompiler
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgc
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgccapacity
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgccause
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgcnew
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgcnewcapacity
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgcold
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgcoldcapacity
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgcpermcapacity
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wgcutil
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wprintcompilation
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Displays...\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(k-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(l-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 215 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Option\fP\h'|\n(41u'\f3Displays...\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'class\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'compiler\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gc\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gccapacity\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gccause\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gcnew\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gcnewcapacity\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gcold\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gcoldcapacity\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(j|u+\n(.Vu
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gcpermcapacity\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(k|u+\n(.Vu
+.if (\n(k|+\n(#^-1v)>\n(#- .nr #- +(\n(k|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'gcutil\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.k+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(l|u+\n(.Vu
+.if (\n(l|+\n(#^-1v)>\n(#- .nr #- +(\n(l|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'printcompilation\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.l+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.rm k+
+.rm l+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-52
+.TP 3
+\-h n
+Display a column header every \f2n\fP samples (output rows), where \f2n\fP is a positive integer. Default value is 0, which displays the column header above the first row of data.
+.TP 3
+\-t n
+Display a timestamp column as the first column of output. The timestamp is the time since the start time of the target JVM.
+.TP 3
+\-JjavaOption
+Pass \f2javaOption\fP to the \f3java\fP application launcher. For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. For a complete list of options, see java(1)
+.RE
+
+.LP
+.SS
+STATOPTIONS AND OUTPUT
+.LP
+.LP
+The following tables summarize the columns that \f3jstat\fP outputs for each \f2statOption\fP.
+.br
+
+.LP
+.SS
+\-class Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of classes unloaded.
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of Kbytes unloaded.
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Time spent performing class load and unload operations.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wClass Loader Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wLoaded
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wBytes
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wUnloaded
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wBytes
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wTime
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of classes loaded.
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of Kbytes loaded.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 261 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Class Loader Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Loaded\h'|\n(41u'Number of classes loaded.
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Bytes\h'|\n(41u'Number of Kbytes loaded.
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Unloaded\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Bytes\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Time\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-21
+
+.LP
+.SS
+\-compiler Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of compilation tasks performed.
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of compilation tasks that failed.
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of compilation tasks that were invalidated.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Time spent performing compilation tasks.
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Compile type of the last failed compilation.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Class name and method for the last failed compilation.
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wHotSpot Just\-In\-Time Compiler Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wCompiled
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFailed
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wInvalid
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wTime
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFailedType
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFailedMethod
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 297 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'HotSpot Just\-In\-Time Compiler Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Compiled\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Failed\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Invalid\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Time\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FailedType\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FailedMethod\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-29
+
+.LP
+.SS
+\-gc Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 0 capacity (KB).
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 1 capacity (KB).
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Survivor space 0 utilization (KB).
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Survivor space 1 utilization (KB).
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current eden space capacity (KB).
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Eden space utilization (KB).
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current old space capacity (KB).
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Old space utilization (KB).
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current permanent space capacity (KB).
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Permanent space utilization (KB).
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di k+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of young generation GC Events.
+.br
+.di
+.nr k| \n(dn
+.nr k- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di l+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Young generation garbage collection time.
+.br
+.di
+.nr l| \n(dn
+.nr l- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di m+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Full garbage collection time.
+.br
+.di
+.nr m| \n(dn
+.nr m- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di n+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Total garbage collection time.
+.br
+.di
+.nr n| \n(dn
+.nr n- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wGarbage\-collected heap statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0U
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1U
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wEC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wEU
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOU
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPU
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of full GC events.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(k-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(l-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(m-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(n-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 367 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Garbage\-collected heap statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0U\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1U\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'EC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'EU\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OU\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(j|u+\n(.Vu
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PU\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(k|u+\n(.Vu
+.if (\n(k|+\n(#^-1v)>\n(#- .nr #- +(\n(k|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.k+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(l|u+\n(.Vu
+.if (\n(l|+\n(#^-1v)>\n(#- .nr #- +(\n(l|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.l+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGC\h'|\n(41u'Number of full GC events.
+.ne \n(m|u+\n(.Vu
+.if (\n(m|+\n(#^-1v)>\n(#- .nr #- +(\n(m|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.m+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(n|u+\n(.Vu
+.if (\n(n|+\n(#^-1v)>\n(#- .nr #- +(\n(n|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'GCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.n+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.rm k+
+.rm l+
+.rm m+
+.rm n+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-63
+
+.LP
+.SS
+\-gccapacity Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Minimum new generation capacity (KB).
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum new generation capacity (KB).
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current new generation capacity (KB).
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 0 capacity (KB).
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 1 capacity (KB).
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current eden space capacity (KB).
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Minimum old generation capacity (KB).
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum old generation capacity (KB).
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current old generation capacity (KB).
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current old space capacity (KB).
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di k+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Minimum permanent generation capacity (KB).
+.br
+.di
+.nr k| \n(dn
+.nr k- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di l+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum Permanent generation capacity (KB).
+.br
+.di
+.nr l| \n(dn
+.nr l- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di m+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current Permanent generation capacity (KB).
+.br
+.di
+.nr m| \n(dn
+.nr m- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di n+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current Permanent space capacity (KB).
+.br
+.di
+.nr n| \n(dn
+.nr n- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di o+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of Young generation GC Events.
+.br
+.di
+.nr o| \n(dn
+.nr o- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wMemory Pool Generation and Space Capacities
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wNGCMN
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wNGCMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wNGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wEC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOGCMN
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOGCMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPGCMN
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPGCMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGC
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of Full GC Events.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(k-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(l-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(m-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(n-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(o-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 441 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Memory Pool Generation and Space Capacities\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'NGCMN\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'NGCMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'NGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'EC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OGCMN\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OGCMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(j|u+\n(.Vu
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(k|u+\n(.Vu
+.if (\n(k|+\n(#^-1v)>\n(#- .nr #- +(\n(k|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PGCMN\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.k+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(l|u+\n(.Vu
+.if (\n(l|+\n(#^-1v)>\n(#- .nr #- +(\n(l|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PGCMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.l+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(m|u+\n(.Vu
+.if (\n(m|+\n(#^-1v)>\n(#- .nr #- +(\n(m|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.m+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(n|u+\n(.Vu
+.if (\n(n|+\n(#^-1v)>\n(#- .nr #- +(\n(n|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.n+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(o|u+\n(.Vu
+.if (\n(o|+\n(#^-1v)>\n(#- .nr #- +(\n(o|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.o+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGC\h'|\n(41u'Number of Full GC Events.
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.rm k+
+.rm l+
+.rm m+
+.rm n+
+.rm o+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-67
+
+.LP
+.SS
+\-gccause Option
+.LP
+.LP
+This option displays the same summary of garbage collection statistics as the \f3\-gcutil\fP option, but includes the causes of the last garbage collection event and (if applicable) the current garbage collection event. In addition to the columns listed for \f3\-gcutil\fP, this option adds the following columns:
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Cause of last Garbage Collection.
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Cause of current Garbage Collection.
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wGarbage Collection Statistics, Including GC Events
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wLGCC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wGCC
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 464 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Garbage Collection Statistics, Including GC Events\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'LGCC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'GCC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-13
+
+.LP
+.SS
+\-gcnew Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 0 capacity (KB).
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 1 capacity (KB).
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Survivor space 0 utilization (KB).
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Survivor space 1 utilization (KB).
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum tenuring threshold.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Desired survivor size (KB).
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current eden space capacity (KB).
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Eden space utilization (KB).
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of young generation GC events.
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Young generation garbage collection time.
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wNew Generation Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0U
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1U
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wTT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wMTT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wDSS
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wEC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wEU
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wTenuring threshold.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 518 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'New Generation Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0U\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1U\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'TT\h'|\n(41u'Tenuring threshold.
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'MTT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'DSS\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'EC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'EU\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(j|u+\n(.Vu
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-47
+
+.LP
+.SS
+\-gcnewcapacity Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Minimum new generation capacity (KB).
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum new generation capacity (KB).
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current new generation capacity (KB).
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum survivor space 0 capacity (KB).
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 0 capacity (KB).
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum survivor space 1 capacity (KB).
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current survivor space 1 capacity (KB).
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum eden space capacity (KB).
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current eden space capacity (KB).
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of young generation GC events.
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wNew Generation Space Size Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wNGCMN
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wNGCMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wNGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0CMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1CMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1C
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wECMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wEC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGC
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of Full GC Events.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 572 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'New Generation Space Size Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'NGCMN\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'NGCMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'NGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0CMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1CMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1C\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'ECMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'EC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(j|u+\n(.Vu
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGC\h'|\n(41u'Number of Full GC Events.
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-47
+
+.LP
+.SS
+\-gcold Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current permanent space capacity (KB).
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Permanent space utilization (KB).
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current old space capacity (KB).
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+old space utilization (KB).
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of young generation GC events.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Full garbage collection time.
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Total garbage collection time.
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wOld and Permanent Generation Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPU
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOU
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of full GC events.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 614 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Old and Permanent Generation Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PU\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OU\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGC\h'|\n(41u'Number of full GC events.
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'GCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-35
+
+.LP
+.SS
+\-gcoldcapacity Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Minimum old generation capacity (KB).
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum old generation capacity (KB).
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current old generation capacity (KB).
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current old space capacity (KB).
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of young generation GC events.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Full garbage collection time.
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Total garbage collection time.
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wOld Generation Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOGCMN
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOGCMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wOC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of full GC events.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 656 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Old Generation Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OGCMN\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OGCMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'OC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGC\h'|\n(41u'Number of full GC events.
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'GCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-35
+
+.LP
+.SS
+\-gcpermcapacity Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Minimum permanent generation capacity (KB).
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Maximum permanent generation capacity (KB).
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current permanent generation capacity (KB).
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Current permanent space capacity (KB).
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of young generation GC events.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Full garbage collection time.
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Total garbage collection time.
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wPermanent Generation Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPGCMN
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPGCMX
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wPC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of full GC events.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 698 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Permanent Generation Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PGCMN\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PGCMX\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'PC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGC\h'|\n(41u'Number of full GC events.
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'GCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-35
+
+.LP
+.SS
+\-gcutil Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Survivor space 0 utilization as a percentage of the space's current capacity.
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Survivor space 1 utilization as a percentage of the space's current capacity.
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Eden space utilization as a percentage of the space's current capacity.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Old space utilization as a percentage of the space's current capacity.
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Permanent space utilization as a percentage of the space's current capacity.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of young generation GC events.
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Young generation garbage collection time.
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Full garbage collection time.
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Total garbage collection time.
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wSummary of Garbage Collection Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS0
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wS1
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wE
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wO
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wYGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGC
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wFGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wGCT
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wNumber of full GC events.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 748 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Summary of Garbage Collection Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S0\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'S1\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'E\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'O\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'P\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGC\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'YGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGC\h'|\n(41u'Number of full GC events.
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'FGCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'GCT\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-43
+
+.LP
+.SS
+\-printcompilation Option
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of compilation tasks performed.
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Number of bytes of bytecode for the method.
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Class name and method name identifying the compiled method. Class name uses "/" instead of "." as namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot \- \f3XX:+PrintComplation\fP option.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \wHotSpot Compiler Method Statistics
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3Column\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wCompiled
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSize
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wType
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wMethod
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wCompilation type.
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 774 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'HotSpot Compiler Method Statistics\h'|\n(41u'
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Column\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Compiled\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Size\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Type\h'|\n(41u'Compilation type.
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'Method\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-19
+
+.LP
+.SH "EXAMPLES"
+.LP
+.LP
+This section presents some examples of monitoring a local JVM with a \f2lvmid\fP of 21891.
+.LP
+.SS
+Using the gcutil option
+.LP
+.LP
+This example attaches to \f2lvmid\fP 21891 and takes 7 samples at 250 millisecond intervals and displays the output as specified by the \f3\-gcutil\fP option.
+.LP
+.nf
+\f3
+.fl
+\fP\f3jstat \-gcutil 21891 250 7\fP
+.br
+
+.fl
+  S0     S1     E      O      P     YGC    YGCT    FGC    FGCT     GCT
+.br
+
+.fl
+ 12.44   0.00  27.20   9.49  96.70    78    0.176     5    0.495    0.672
+.br
+
+.fl
+ 12.44   0.00  62.16   9.49  96.70    78    0.176     5    0.495    0.672
+.br
+
+.fl
+ 12.44   0.00  83.97   9.49  96.70    78    0.176     5    0.495    0.672
+.br
+
+.fl
+  0.00   7.74   0.00   9.51  96.70    79    0.177     5    0.495    0.673
+.br
+
+.fl
+  0.00   7.74  23.37   9.51  96.70    79    0.177     5    0.495    0.673
+.br
+
+.fl
+  0.00   7.74  43.82   9.51  96.70    79    0.177     5    0.495    0.673
+.br
+
+.fl
+  0.00   7.74  58.11   9.51  96.71    79    0.177     5    0.495    0.673
+.br
+
+.fl
+.fi
+
+.LP
+.LP
+The output of this example shows that a young generation collection occurred between the 3rd and 4th sample. The collection took 0.001 seconds and promoted objects from the eden space (E) to the old space (O), resulting in an increase of old space utilization from 9.49% to 9.51%. Before the collection, the survivor space was 12.44% utilized, but after this collection it is only 7.74% utilized.
+.LP
+.SS
+Repeating the column header string
+.LP
+.LP
+This example attaches to \f2lvmid\fP 21891 and takes samples at 250 millisecond intervals and displays the output as specified by \f3\-gcutil\fP option. In addition, it uses the \f3\-h3\fP option to output the column header after every 3 lines of data.
+.LP
+.nf
+\f3
+.fl
+\fP\f3jstat \-gcnew \-h3 21891 250\fP
+.br
+
+.fl
+ S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
+.br
+
+.fl
+  64.0   64.0    0.0   31.7 31  31   32.0    512.0    178.6    249    0.203
+.br
+
+.fl
+  64.0   64.0    0.0   31.7 31  31   32.0    512.0    355.5    249    0.203
+.br
+
+.fl
+  64.0   64.0   35.4    0.0  2  31   32.0    512.0     21.9    250    0.204
+.br
+
+.fl
+ S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
+.br
+
+.fl
+  64.0   64.0   35.4    0.0  2  31   32.0    512.0    245.9    250    0.204
+.br
+
+.fl
+  64.0   64.0   35.4    0.0  2  31   32.0    512.0    421.1    250    0.204
+.br
+
+.fl
+  64.0   64.0    0.0   19.0 31  31   32.0    512.0     84.4    251    0.204
+.br
+
+.fl
+ S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
+.br
+
+.fl
+  64.0   64.0    0.0   19.0 31  31   32.0    512.0    306.7    251    0.204
+.br
+
+.fl
+.fi
+
+.LP
+.LP
+In addition to showing the repeating header string, this example shows that between the 2nd and 3rd samples, a young GC occurred. Its duration was 0.001 seconds. The collection found enough live data that the survivor space 0 utilization (S0U) would would have exceeded the desired survivor Size (DSS). As a result, objects were promoted to the old generation (not visible in this output), and the tenuring threshold (TT) was lowered from 31 to 2.
+.LP
+.LP
+Another collection occurs between the 5th and 6th samples. This collection found very few survivors and returned the tenuring threshold to 31.
+.LP
+.SS
+Including a time stamp for each sample
+.LP
+.LP
+This example attaches to \f2lvmid\fP 21891 and takes 3 samples at 250 millisecond intervals. The \f3\-t\fP option is used to generate a time stamp for each sample in the first column.
+.LP
+.nf
+\f3
+.fl
+\fP\f3jstat \-gcoldcapacity \-t 21891 250 3\fP
+.br
+
+.fl
+Timestamp          OGCMN        OGCMX         OGC           OC       YGC   FGC    FGCT    GCT
+.br
+
+.fl
+          150.1       1408.0      60544.0      11696.0      11696.0   194    80    2.874   3.799
+.br
+
+.fl
+          150.4       1408.0      60544.0      13820.0      13820.0   194    81    2.938   3.863
+.br
+
+.fl
+          150.7       1408.0      60544.0      13820.0      13820.0   194    81    2.938   3.863
+.br
+
+.fl
+.fi
+
+.LP
+.LP
+The \f2Timestamp\fP column reports the elapsed time in seconds since the start of the target JVM. In addition, the \f3\-gcoldcapacity\fP output shows the old generation capacity (OGC) and the old space capacity (OC) increasing as the heap expands to meet allocation and/or promotion demands. The old generation capacity (OGC) has grown to from 11696 KB to 13820 KB after the 81st Full GC (FGC). The maximum capacity of the generation (and space) is 60544 KB (OGCMX), so it still has room to expand.
+.LP
+.SS
+Monitor instrumentation for a remote JVM
+.LP
+.LP
+This example attaches to \f2lvmid\fP 40496 on the system named \f2remote.domain\fP using the \f3\-gcutil\fP option, with samples taken every second indefinitely.
+.LP
+.nf
+\f3
+.fl
+\fP\f3jstat \-gcutil 40496@remote.domain 1000\fP
+.br
+
+.fl
+... \f2output omitted\fP
+.br
+
+.fl
+.fi
+
+.LP
+.LP
+The \f2lvmid\fP is combined with the name of the remote host to construct a \f2vmid\fP of \f240496@remote.domain\fP. This \f2vmid\fP results in the use of the \f3rmi\fP protocol to communicate to the default \f3jstatd\fP server on the remote host. The \f3jstatd\fP server is located using the \f3rmiregistry\fP on \f2remote.domain\fP that is bound to the default \f3rmiregistry\fP port (port 1099).
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+java(1) \- the Java Application Launcher
+.TP 2
+o
+jps(1) \- the Java Process Status Application
+.TP 2
+o
+jstatd(1) \- the jvmstat daemon
+.TP 2
+o
+rmiregistry(1) \- the Java Remote Object Registry
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/jstatd.1 b/jdk/src/bsd/doc/man/jstatd.1
new file mode 100644
index 0000000..fb28260
--- /dev/null
+++ b/jdk/src/bsd/doc/man/jstatd.1
@@ -0,0 +1,257 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH jstatd 1 "10 May 2011"
+
+.LP
+.SH "Name"
+jstatd \- Virtual Machine jstat Daemon
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+jstatd [ \fP\f4options\fP\f3 ]\fP
+.br
+\f3
+.fl
+\fP
+.fi
+
+.LP
+.SH "PARAMETERS"
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options. The options may be in any order. If there are redundant or contradictory options, the last option specified will take precedence.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3jstatd\fP tool is an RMI server application that monitors for the creation and termination of instrumented HotSpot Java virtual machines (JVMs) and provides a interface to allow remote monitoring tools to attach to JVMs running on the local host.
+.LP
+.LP
+The \f3jstatd\fP server requires the presence of an RMI registry on the local host. The \f3jstatd\fP server will attempt to attach to the RMI registry on the default port, or on the port indicated by the \f2\-p port\fP option. If an RMI registry is not found, one will be created within the \f3jstatd\fP application bound to the port indicated by the \f2\-p port\fP option or to the default RMI registry port if \f2\-p port\fP is omitted. Creation of an internal RMI registry can be inhibited by specifying the \f2\-nr\fP option.
+.LP
+.LP
+\f3NOTE:\fP This utility is unsupported and may or may not be available in future versions of the JDK. It is not currently available on the Windows 98 and Windows ME platforms.
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+The \f3jstatd\fP command supports the following options:
+.LP
+.RS 3
+.TP 3
+\-nr
+Do not attempt to create an internal RMI registry within the \f2jstatd\fP process when an existing RMI registry is not found.
+.TP 3
+\-p\  port
+Port number where the RMI registry is expected to be found, or, if not found, created if \f2\-nr\fP is not specified.
+.TP 3
+\-n\  rminame
+Name to which the remote RMI object is bound in the RMI registry. The default name is \f2JStatRemoteHost\fP. If multiple \f3jstatd\fP servers are started on the same host, the name of the exported RMI object for each server can be made unique by specifying this option. However, doing so will require that the unique server name be included in the monitoring client's \f2hostid\fP and \f2vmid\fP strings.
+.TP 3
+\-Joption
+Pass \f2option\fP to the \f3java\fP launcher called by \f3javac\fP. For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. It is a common convention for \f3\-J\fP to pass options to the underlying VM executing applications written in Java.
+.RE
+
+.LP
+.SH "SECURITY"
+.LP
+.LP
+The \f3jstatd\fP server can only monitor JVMs for which it has the appropriate native access permissions. Therefor the \f3jstatd\fP process must be running with the same user credentials as the target JVMs. Some user credentials, such as the \f2root\fP user in UNIX(TM) based systems, have permission to access the instrumentation exported by any JVM on the system. A \f3jstatd\fP process running with such credentials can monitor any JVM on the system, but introduces additional security concerns.
+.LP
+.LP
+The \f3jstatd\fP server does not provide any authentication of remote clients. Therefore, running a \f3jstatd\fP server process exposes the instrumentation export by all JVMs for which the \f3jstatd\fP process has access permissions to any user on the network. This exposure may be undesireable in your environment and local security policies should be considered before starting the \f3jstatd\fP process, particularly in production environments or on unsecure networks.
+.LP
+.LP
+The \f3jstatd\fP server installs an instance of RMISecurityPolicy if no other security manager has been installed and therefore requires a security policy file to be specified. The policy file must conform to the default policy implementation's
+.na
+\f2Policy File Syntax\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html.
+.LP
+.LP
+The following policy file will allow the \f3jstatd\fP server to run without any security exceptions. This policy is less liberal then granting all permissions to all codebases, but is more liberal than a policy that grants the minimal permissions to run the \f3jstatd\fP server.
+.LP
+.nf
+\f3
+.fl
+grant codebase "file:${java.home}/../lib/tools.jar" {\fP
+.br
+\f3
+.fl
+   permission java.security.AllPermission;\fP
+.br
+\f3
+.fl
+};\fP
+.br
+\f3
+.fl
+\fP
+.fi
+
+.LP
+.LP
+To use this policy, copy the text into a file called \f2jstatd.all.policy\fP and run the \f3jstatd\fP server as follows:
+.LP
+.nf
+\f3
+.fl
+jstatd \-J\-Djava.security.policy=jstatd.all.policy\fP
+.br
+\f3
+.fl
+\fP
+.fi
+
+.LP
+.LP
+For sites with more restrictive security practices, it is possible to use a custom policy file to limit access to specific trusted hosts or networks, though such techniques are subject to IP addreess spoofing attacks. If your security concerns cannot be addressed with a customized policy file, then the safest action is to not run the \f3jstatd\fP server and use the \f3jstat\fP and \f3jps\fP tools locally.
+.LP
+.SH "REMOTE INTERFACE"
+.LP
+.LP
+The interface exported by the \f3jstatd\fP process is proprietary and is guaranteed to change. Users and developers are discouraged from writing to this interface.
+.LP
+.SH "EXAMPLES"
+.LP
+.LP
+Here are some examples of starting \f3jstatd\fP. Note that the \f3jstatd\fP scripts automatically start the server in the background.
+.LP
+.SS
+Using Internal RMI Registry
+.LP
+.LP
+This example demonstrates starting \f3jstatd\fP with an internal RMI registry. This example assumes that no other server is bound to the default RMI Registry port (port 1099).
+.LP
+.nf
+\f3
+.fl
+jstatd \-J\-Djava.security.policy=all.policy
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Using External RMI Registry
+.LP
+.LP
+This example demonstrates starting \f3jstatd\fP with a external RMI registry.
+.LP
+.nf
+\f3
+.fl
+rmiregistry&
+.fl
+jstatd \-J\-Djava.security.policy=all.policy
+.fl
+\fP
+.fi
+
+.LP
+.LP
+This example demonstrates starting \f3jstatd\fP with an external RMI registry server on port 2020.
+.LP
+.nf
+\f3
+.fl
+rmiregistry 2020&
+.fl
+jstatd \-J\-Djava.security.policy=all.policy \-p 2020
+.fl
+\fP
+.fi
+
+.LP
+.LP
+This example demonstrates starting \f3jstatd\fP with an external RMI registry on port 2020, bound to name AlternateJstatdServerName.
+.LP
+.nf
+\f3
+.fl
+rmiregistry 2020&
+.fl
+jstatd \-J\-Djava.security.policy=all.policy \-p 2020 \-n AlternateJstatdServerName
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Inhibiting creation of an in\-process RMI registry
+.LP
+.LP
+This example demonstrates starting \f3jstatd\fP such that it will not create a RMI registry if one is not found. This example assumes an RMI registry is already running. If it is not, an appropriate error message is emitted.
+.LP
+.nf
+\f3
+.fl
+jstatd \-J\-Djava.security.policy=all.policy \-nr
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Enabling RMI logging capabilities.
+.LP
+.LP
+This example demonstrates starting \f3jstatd\fP with RMI logging capabilities enabled. This technique is useful as a troubleshooting aid or for monitoring server activities.
+.LP
+.nf
+\f3
+.fl
+jstatd \-J\-Djava.security.policy=all.policy \-J\-Djava.rmi.server.logCalls=true
+.fl
+\fP
+.fi
+
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+java(1) \- the Java Application Launcher
+.TP 2
+o
+jps(1) \- the Java Process Status Application
+.TP 2
+o
+jstat(1) \- the Java Virtual Machine Statistics Monitoring Tool
+.TP 2
+o
+.na
+\f2rmiregistry\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#rmi \- the Java Remote Object Registry
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/keytool.1 b/jdk/src/bsd/doc/man/keytool.1
new file mode 100644
index 0000000..c5f6229
--- /dev/null
+++ b/jdk/src/bsd/doc/man/keytool.1
@@ -0,0 +1,1765 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH keytool 1 "10 May 2011"
+
+.LP
+.SH "Name"
+keytool \- Key and Certificate Management Tool
+.LP
+.LP
+Manages a keystore (database) of cryptographic keys, X.509 certificate chains, and trusted certificates.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3keytool\fP [ commands ]
+.fl
+.fi
+
+.LP
+.LP
+The keytool command interface has changed in Java SE 6. See the Changes Section for a detailed description. Note that previously defined commands are still supported.
+.LP
+.SH "DESCRIPTION"
+.LP
+\f3keytool\fP is a key and certificate management utility. It allows users to administer their own public/private key pairs and associated certificates for use in self\-authentication (where the user authenticates himself/herself to other users/services) or data integrity and authentication services, using digital signatures. It also allows users to cache the public keys (in the form of certificates) of their communicating peers.
+.LP
+A \f2certificate\fP is a digitally signed statement from one entity (person, company, etc.), saying that the public key (and some other information) of some other entity has a particular value. (See Certificates.) When data is digitally signed, the signature can be verified to check the data integrity and authenticity. \f2Integrity\fP means that the data has not been modified or tampered with, and \f2authenticity\fP means the data indeed comes from whoever claims to have created and signed it.
+.LP
+.LP
+\f3keytool\fP also enables users to administer secret keys used in symmetric encryption/decryption (e.g. DES).
+.LP
+.LP
+\f3keytool\fP stores the keys and certificates in a \f2keystore\fP.
+.LP
+.SH "COMMAND AND OPTION NOTES"
+.LP
+.LP
+The various commands and their options are listed and described below. Note:
+.LP
+.RS 3
+.TP 2
+o
+All command and option names are preceded by a minus sign (\-).
+.TP 2
+o
+The options for each command may be provided in any order.
+.TP 2
+o
+All items not italicized or in braces or square brackets are required to appear as is.
+.TP 2
+o
+Braces surrounding an option generally signify that a default value will be used if the option is not specified on the command line. Braces are also used around the \f2\-v\fP, \f2\-rfc\fP, and \f2\-J\fP options, which only have meaning if they appear on the command line (that is, they don't have any "default" values other than not existing).
+.TP 2
+o
+Brackets surrounding an option signify that the user is prompted for the value(s) if the option is not specified on the command line. (For a \f2\-keypass\fP option, if you do not specify the option on the command line, \f3keytool\fP will first attempt to use the keystore password to recover the private/secret key, and if this fails, will then prompt you for the private/secret key password.)
+.TP 2
+o
+Items in italics (option values) represent the actual values that must be supplied. For example, here is the format of the \f2\-printcert\fP command:
+.nf
+\f3
+.fl
+  keytool \-printcert {\-file \fP\f4cert_file\fP\f3} {\-v}
+.fl
+\fP
+.fi
+.LP
+When specifying a \f2\-printcert\fP command, replace \f2cert_file\fP with the actual file name, as in:
+.nf
+\f3
+.fl
+  keytool \-printcert \-file VScert.cer
+.fl
+\fP
+.fi
+.TP 2
+o
+Option values must be quoted if they contain a blank (space).
+.TP 2
+o
+The \f2\-help\fP command is the default. Thus, the command line
+.nf
+\f3
+.fl
+  keytool
+.fl
+\fP
+.fi
+.LP
+is equivalent to
+.nf
+\f3
+.fl
+  keytool \-help
+.fl
+\fP
+.fi
+.RE
+
+.LP
+.SS
+Option Defaults
+.LP
+.LP
+Below are the defaults for various option values.
+.LP
+.nf
+\f3
+.fl
+\-alias "mykey"
+.fl
+
+.fl
+\-keyalg
+.fl
+    "DSA" (when using \fP\f3\-genkeypair\fP\f3)
+.fl
+    "DES" (when using \fP\f3\-genseckey\fP\f3)
+.fl
+
+.fl
+\-keysize
+.fl
+    2048 (when using \fP\f3\-genkeypair\fP\f3 and \-keyalg is "RSA")
+.fl
+    1024 (when using \fP\f3\-genkeypair\fP\f3 and \-keyalg is "DSA")
+.fl
+    256 (when using \fP\f3\-genkeypair\fP\f3 and \-keyalg is "EC")
+.fl
+    56 (when using \fP\f3\-genseckey\fP\f3 and \-keyalg is "DES")
+.fl
+    168 (when using \fP\f3\-genseckey\fP\f3 and \-keyalg is "DESede")
+.fl
+
+.fl
+
+.fl
+\-validity 90
+.fl
+
+.fl
+\-keystore the file named \fP\f4.keystore\fP\f3 in the user's home directory
+.fl
+
+.fl
+\-storetype the value of the "keystore.type" property in the security properties file,
+.fl
+           which is returned by the static \fP\f4getDefaultType\fP\f3 method in
+.fl
+           \fP\f4java.security.KeyStore\fP\f3
+.fl
+
+.fl
+\-file stdin if reading, stdout if writing
+.fl
+
+.fl
+\-protected false
+.fl
+\fP
+.fi
+
+.LP
+.LP
+In generating a public/private key pair, the signature algorithm (\f2\-sigalg\fP option) is derived from the algorithm of the underlying private key:
+.LP
+.RS 3
+.TP 2
+o
+If the underlying private key is of type "DSA", the \f2\-sigalg\fP option defaults to "SHA1withDSA"
+.TP 2
+o
+If the underlying private key is of type "RSA", the \f2\-sigalg\fP option defaults to "SHA256withRSA".
+.TP 2
+o
+If the underlying private key is of type "EC", the \f2\-sigalg\fP option defaults to "SHA256withECDSA".
+.RE
+
+.LP
+.LP
+Please consult the
+.na
+\f2Java Cryptography Architecture API Specification & Reference\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA for a full list of \f2\-keyalg\fP and \f2\-sigalg\fP you can choose from.
+.LP
+.SS
+Common Options
+.LP
+.LP
+The \f2\-v\fP option can appear for all commands except \f2\-help\fP. If it appears, it signifies "verbose" mode; more information will be provided in the output.
+.LP
+.LP
+There is also a \f2\-J\fP\f2javaoption\fP option that may appear for any command. If it appears, the specified \f2javaoption\fP string is passed through directly to the Java interpreter. This option should not contain any spaces. It is useful for adjusting the execution environment or memory usage. For a list of possible interpreter options, type \f2java \-h\fP or \f2java \-X\fP at the command line.
+.LP
+.LP
+These options may appear for all commands operating on a keystore:
+.LP
+.RS 3
+.TP 3
+\-storetype storetype
+.LP
+This qualifier specifies the type of keystore to be instantiated.
+.TP 3
+\-keystore keystore
+.LP
+The keystore location.
+.LP
+If the JKS storetype is used and a keystore file does not yet exist, then certain \f3keytool\fP commands may result in a new keystore file being created. For example, if \f2keytool \-genkeypair\fP is invoked and the \f2\-keystore\fP option is not specified, the default keystore file named \f2.keystore\fP in the user's home directory will be created if it does not already exist. Similarly, if the \f2\-keystore \fP\f2ks_file\fP option is specified but \f2ks_file\fP does not exist, then it will be created
+.LP
+Note that the input stream from the \f2\-keystore\fP option is passed to the \f2KeyStore.load\fP method. If \f2NONE\fP is specified as the URL, then a null stream is passed to the \f2KeyStore.load\fP method. \f2NONE\fP should be specified if the \f2KeyStore\fP is not file\-based (for example, if it resides on a hardware token device).
+.TP 3
+\-storepass[:env|:file] argument
+.LP
+The password which is used to protect the integrity of the keystore.
+.LP
+If the modifier \f2env\fP or \f2file\fP is not specified, then the password has the value \f2argument\fP, which must be at least 6 characters long. Otherwise, the password is retrieved as follows:
+.RS 3
+.TP 2
+o
+\f2env\fP: Retrieve the password from the environment variable named \f2argument\fP
+.TP 2
+o
+\f2file\fP: Retrieve the password from the file named \f2argument\fP
+.RE
+.LP
+\f3Note\fP: All other options that require passwords, such as \f2\-keypass\fP, \f2\-srckeypass\fP, \f2\-destkeypass\fP \f2\-srcstorepass\fP, and \f2\-deststorepass\fP, accept the \f2env\fP and \f2file\fP modifiers. (Remember to separate the password option and the modifier with a colon, (\f2:\fP).)
+.LP
+The password must be provided to all commands that access the keystore contents. For such commands, if a \f2\-storepass\fP option is not provided at the command line, the user is prompted for it.
+.LP
+When retrieving information from the keystore, the password is optional; if no password is given, the integrity of the retrieved information cannot be checked and a warning is displayed.
+.TP 3
+\-providerName provider_name
+.LP
+Used to identify a cryptographic service provider's name when listed in the security properties file.
+.TP 3
+\-providerClass provider_class_name
+.LP
+Used to specify the name of cryptographic service provider's master class file when the service provider is not listed in the security properties file.
+.TP 3
+\-providerArg provider_arg
+.LP
+Used in conjunction with \f2\-providerClass\fP. Represents an optional string input argument for the constructor of \f2provider_class_name\fP.
+.TP 3
+\-protected
+.LP
+Either \f2true\fP or \f2false\fP. This value should be specified as \f2true\fP if a password must be given via a protected authentication path such as a dedicated PIN reader.
+.LP
+Note: Since there are two keystores involved in \f2\-importkeystore\fP command, two options, namely, \f2\-srcprotected\fP and \f2\-destprotected\fP are provided for the source keystore and the destination keystore respectively.
+.TP 3
+\-ext {name{:critical}{=value}}
+.LP
+Denotes an X.509 certificate extension. The option can be used in \-genkeypair and \-gencert to embed extensions into the certificate generated, or in \f2\-certreq\fP to show what extensions are requested in the certificate request. The option can appear multiple times. name can be a supported extension name (see below) or an arbitrary OID number. value, if provided, denotes the parameter for the extension; if omitted, denotes the default value (if defined) of the extension or the extension requires no parameter. The \f2:critical\fP modifier, if provided, means the extension's isCritical attribute is true; otherwise, false. You may use \f2:c\fP in place of \f2:critical\fP.
+.RE
+
+.LP
+.LP
+Currently keytool supports these named extensions (case\-insensitive):
+.LP
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+The full form: "ca:{true|false}[,pathlen:<len>]"; or, <len>, a shorthand for "ca:true,pathlen:<len>"; or omitted, means "ca:true"
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+usage(,usage)*, usage can be one of digitalSignature, nonRepudiation (contentCommitment), keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign, encipherOnly, decipherOnly. Usage can be abbreviated with the first few letters (say, dig for digitalSignature) or in camel\-case style (say, dS for digitalSignature, cRLS for cRLSign), as long as no ambiguity is found. Usage is case\-insensitive.
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+usage(,usage)*, usage can be one of anyExtendedKeyUsage, serverAuth, clientAuth, codeSigning, emailProtection, timeStamping, OCSPSigning, or any OID string. Named usage can be abbreviated with the first few letters or in camel\-case style, as long as no ambiguity is found. Usage is case\-insensitive.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+SAN or SubjectAlternativeName
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+type:value(,type:value)*, type can be EMAIL, URI, DNS, IP, or OID, value is the string format value for the type.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+IAN or IssuerAlternativeName
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+same as SubjectAlternativeName
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+method:location\-type:location\-value (,method:location\-type:location\-value)*, method can be "timeStamping", "caRepository" or any OID. location\-type and location\-value can be any type:value supported by the SubjectAlternativeName extension.
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+AIA or AuthorityInfoAccess
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+same as SubjectInfoAccess. method can be "ocsp","caIssuers" or any OID.
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \w\f3Name\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wBC or BasicConstraints
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wKU or KeyUsage
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wEKU or ExtendedkeyUsage
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \wSIA or SubjectInfoAccess
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 38 \n(d-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(f-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(i-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 81 0
+.nr 38 \w\f3Value\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 319 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Name\fP\h'|\n(41u'\f3Value\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'BC or BasicConstraints\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'KU or KeyUsage\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'EKU or ExtendedkeyUsage\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.ne \n(e|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.ne \n(g|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'SIA or SubjectInfoAccess\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.ne \n(j|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-38
+
+.LP
+.LP
+For name as OID, value is the HEX dumped DER encoding of the extnValue for the extension excluding the OCTET STRING type and length bytes. Any extra character other than standard HEX numbers (0\-9, a\-f, A\-F) are ignored in the HEX string. Therefore, both \f2"01:02:03:04"\fP and \f2"01020304"\fP are accepted as identical values. If there's no value, the extension has an empty value field then.
+.LP
+.LP
+A special name \f2'honored'\fP, used in \f2\-gencert\fP only, denotes how the extensions included in the certificate request should be honored. The value for this name is a comma separated list of \f2"all"\fP (all requested extensions are honored), \f2"name{:[critical|non\-critical]}"\fP (the named extension is honored, but using a different isCritical attribute) and \f2"\-name"\fP (used with all, denotes an exception). Requested extensions are not honored by default.
+.LP
+.LP
+If, besides the \-ext honored option, another named or OID \-ext option is provided, this extension will be added to those already honored. However, if this name (or OID) also appears in the honored value, its value and criticality overrides the one in the request.
+.LP
+.LP
+The subjectKeyIdentifier extension is always created. For non self\-signed certificates, the authorityKeyIdentifier is always created.
+.LP
+.LP
+\f3Note:\fP Users should be aware that some combinations of extensions (and other certificate fields) may not conform to the Internet standard. See Warning Regarding Certificate Conformance for details.
+.LP
+.SH "COMMANDS"
+.LP
+.SS
+Creating or Adding Data to the Keystore
+.LP
+.RS 3
+.TP 3
+\-gencert {\-rfc} {\-infile infile} {\-outfile outfile} {\-alias alias} {\-sigalg sigalg} {\-dname dname} {\-startdate startdate {\-ext ext}* {\-validity valDays} [\-keypass keypass] {\-keystore keystore} [\-storepass storepass] {\-storetype storetype} {\-providername provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Generates a certificate as a response to a certificate request file (which can be created by the \f2keytool \-certreq\fP command). The command reads the request from \f2infile\fP (if omitted, from the standard input), signs it using alias's private key, and output the X.509 certificate into \f2outfile\fP (if omitted, to the standard output). If \f2\-rfc\fP is specified, output format is BASE64\-encoded PEM; otherwise, a binary DER is created.
+.LP
+\f2sigalg\fP specifies the algorithm that should be used to sign the certificate. \f2startdate\fP is the start time/date that the certificate is valid. \f2valDays\fP tells the number of days for which the certificate should be considered valid.
+.LP
+If \f2dname\fP is provided, it's used as the subject of the generated certificate. Otherwise, the one from the certificate request is used.
+.LP
+\f2ext\fP shows what X.509 extensions will be embedded in the certificate. Read Common Options for the grammar of \f2\-ext\fP.
+.LP
+The \f2\-gencert\fP command enables you to create certificate chains. The following example creates a certificate, \f2e1\fP, that contains three certificates in its certificate chain.
+.LP
+The following commands creates four key pairs named \f2ca\fP, \f2ca1\fP, \f2ca2\fP, and \f2e1\fP:
+.nf
+\f3
+.fl
+keytool \-alias ca \-dname CN=CA \-genkeypair
+.fl
+keytool \-alias ca1 \-dname CN=CA \-genkeypair
+.fl
+keytool \-alias ca2 \-dname CN=CA \-genkeypair
+.fl
+keytool \-alias e1 \-dname CN=E1 \-genkeypair
+.fl
+\fP
+.fi
+.LP
+The following two commands create a chain of signed certificates; \f2ca\fP signs ca1 and \f2ca1 signs ca2\fP, all of which are self\-issued:
+.nf
+\f3
+.fl
+keytool \-alias ca1 \-certreq | keytool \-alias ca \-gencert \-ext san=dns:ca1 | keytool \-alias ca1 \-importcert
+.fl
+keytool \-alias ca2 \-certreq | $KT \-alias ca1 \-gencert \-ext san=dns:ca2 | $KT \-alias ca2 \-importcert
+.fl
+\fP
+.fi
+.LP
+The following command creates the certificate \f2e1\fP and stores it in the file \f2e1.cert\fP, which is signed by \f2ca2\fP. As a result, \f2e1\fP should contain \f2ca\fP, \f2ca1\fP, and \f2ca2\fP in its certificate chain:
+.nf
+\f3
+.fl
+keytool \-alias e1 \-certreq | keytool \-alias ca2 \-gencert > e1.cert
+.fl
+\fP
+.fi
+.TP 3
+\-genkeypair {\-alias alias} {\-keyalg keyalg} {\-keysize keysize} {\-sigalg sigalg} [\-dname dname] [\-keypass keypass] {\-startdate value} {\-ext ext}* {\-validity valDays} {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Generates a key pair (a public key and associated private key). Wraps the public key into an X.509 v3 self\-signed certificate, which is stored as a single\-element certificate chain. This certificate chain and the private key are stored in a new keystore entry identified by \f2alias\fP.
+.LP
+\f2keyalg\fP specifies the algorithm to be used to generate the key pair, and \f2keysize\fP specifies the size of each key to be generated. \f2sigalg\fP specifies the algorithm that should be used to sign the self\-signed certificate; this algorithm must be compatible with \f2keyalg\fP.
+.LP
+\f2dname\fP specifies the X.500 Distinguished Name to be associated with \f2alias\fP, and is used as the \f2issuer\fP and \f2subject\fP fields in the self\-signed certificate. If no distinguished name is provided at the command line, the user will be prompted for one.
+.LP
+\f2keypass\fP is a password used to protect the private key of the generated key pair. If no password is provided, the user is prompted for it. If you press RETURN at the prompt, the key password is set to the same password as that used for the keystore. \f2keypass\fP must be at least 6 characters long.
+.LP
+\f2startdate\fP specifies the issue time of the certificate, also known as the "Not Before" value of the X.509 certificate's Validity field.
+.LP
+The option value can be set in one of these two forms:
+.RS 3
+.TP 3
+1.
+([+\-]\f2nnn\fP[ymdHMS])+
+.TP 3
+2.
+[yyyy/mm/dd] [HH:MM:SS]
+.RE
+.LP
+With the first form, the issue time is shifted by the specified value from the current time. The value is a concatenation of a sequence of sub values. Inside each sub value, the plus sign ("+") means shifting forward, and the minus sign ("\-") means shifting backward. The time to be shifted is \f2nnn\fP units of years, months, days, hours, minutes, or seconds (denoted by a single character of "y", "m", "d", "H", "M", or "S" respectively). The exact value of the issue time is calculated using the \f2java.util.GregorianCalendar.add(int field, int amount)\fP method on each sub value, from left to right. For example, by specifying \f2"\-startdate \-1y+1m\-1d"\fP, the issue time will be:
+.nf
+\f3
+.fl
+   Calendar c = new GregorianCalendar();
+.fl
+   c.add(Calendar.YEAR, \-1);
+.fl
+   c.add(Calendar.MONTH, 1);
+.fl
+   c.add(Calendar.DATE, \-1);
+.fl
+   return c.getTime()
+.fl
+\fP
+.fi
+.LP
+With the second form, the user sets the exact issue time in two parts, year/month/day and hour:minute:second (using the local time zone). The user may provide only one part, which means the other part is the same as the current date (or time). User must provide the exact number of digits as shown in the format definition (padding with 0 if shorter). When both the date and time are provided, there is one (and only one) space character between the two parts. The hour should always be provided in 24 hour format.
+.LP
+When the option is not provided, the start date is the current time. The option can be provided at most once.
+.LP
+\f2valDays\fP specifies the number of days (starting at the date specified by \f2\-startdate\fP, or the current date if \f2\-startdate\fP is not specified) for which the certificate should be considered valid.
+.LP
+This command was named \f2\-genkey\fP in previous releases. This old name is still supported in this release and will be supported in future releases, but for clarity the new name, \f2\-genkeypair\fP, is preferred going forward.
+.TP 3
+\-genseckey {\-alias alias} {\-keyalg keyalg} {\-keysize keysize} [\-keypass keypass] {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Generates a secret key and stores it in a new \f2KeyStore.SecretKeyEntry\fP identified by \f2alias\fP.
+.LP
+\f2keyalg\fP specifies the algorithm to be used to generate the secret key, and \f2keysize\fP specifies the size of the key to be generated. \f2keypass\fP is a password used to protect the secret key. If no password is provided, the user is prompted for it. If you press RETURN at the prompt, the key password is set to the same password as that used for the keystore. \f2keypass\fP must be at least 6 characters long.
+.TP 3
+\-importcert {\-alias alias} {\-file cert_file} [\-keypass keypass] {\-noprompt} {\-trustcacerts} {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Reads the certificate or certificate chain (where the latter is supplied in a PKCS#7 formatted reply or a sequence of X.509 certificates) from the file \f2cert_file\fP, and stores it in the keystore entry identified by \f2alias\fP. If no file is given, the certificate or certificate chain is read from stdin.
+.LP
+\f3keytool\fP can import X.509 v1, v2, and v3 certificates, and PKCS#7 formatted certificate chains consisting of certificates of that type. The data to be imported must be provided either in binary encoding format, or in printable encoding format (also known as Base64 encoding) as defined by the Internet RFC 1421 standard. In the latter case, the encoding must be bounded at the beginning by a string that starts with "\-\-\-\-\-BEGIN", and bounded at the end by a string that starts with "\-\-\-\-\-END".
+.LP
+You import a certificate for two reasons:
+.RS 3
+.TP 3
+1.
+to add it to the list of trusted certificates, or
+.TP 3
+2.
+to import a certificate reply received from a CA as the result of submitting a Certificate Signing Request (see the \-certreq command) to that CA.
+.RE
+.LP
+Which type of import is intended is indicated by the value of the \f2\-alias\fP option:
+.RS 3
+.TP 3
+1.
+\f3If the alias does not point to a key entry\fP, then \f3keytool\fP assumes you are adding a trusted certificate entry. In this case, the alias should not already exist in the keystore. If the alias does already exist, then \f3keytool\fP outputs an error, since there is already a trusted certificate for that alias, and does not import the certificate.
+.TP 3
+2.
+\f3If the alias points to a key entry\fP, then \f3keytool\fP assumes you are importing a certificate reply.
+.RE
+\f3Importing a New Trusted Certificate\fP
+.LP
+Before adding the certificate to the keystore, \f3keytool\fP tries to verify it by attempting to construct a chain of trust from that certificate to a self\-signed certificate (belonging to a root CA), using trusted certificates that are already available in the keystore.
+.LP
+If the \f2\-trustcacerts\fP option has been specified, additional certificates are considered for the chain of trust, namely the certificates in a file named "cacerts".
+.LP
+If \f3keytool\fP fails to establish a trust path from the certificate to be imported up to a self\-signed certificate (either from the keystore or the "cacerts" file), the certificate information is printed out, and the user is prompted to verify it, e.g., by comparing the displayed certificate fingerprints with the fingerprints obtained from some other (trusted) source of information, which might be the certificate owner himself/herself. Be very careful to ensure the certificate is valid prior to importing it as a "trusted" certificate! \-\- see WARNING Regarding Importing Trusted Certificates. The user then has the option of aborting the import operation. If the \f2\-noprompt\fP option is given, however, there will be no interaction with the user.
+\f3Importing a Certificate Reply\fP
+.LP
+When importing a certificate reply, the certificate reply is validated using trusted certificates from the keystore, and optionally using the certificates configured in the "cacerts" keystore file (if the \f2\-trustcacerts\fP option was specified).
+.LP
+The methods of determining whether the certificate reply is trusted are described in the following:
+.RS 3
+.TP 2
+o
+\f3If the reply is a single X.509 certificate\fP, \f3keytool\fP attempts to establish a trust chain, starting at the certificate reply and ending at a self\-signed certificate (belonging to a root CA). The certificate reply and the hierarchy of certificates used to authenticate the certificate reply form the new certificate chain of \f2alias\fP. If a trust chain cannot be established, the certificate reply is not imported. In this case, \f3keytool\fP does not print out the certificate and prompt the user to verify it, because it is very hard (if not impossible) for a user to determine the authenticity of the certificate reply.
+.TP 2
+o
+\f3If the reply is a PKCS#7 formatted certificate chain or a sequence of X.509 certificates\fP, the chain is ordered with the user certificate first followed by zero or more CA certificates. If the chain ends with a self\-signed root CA certificate and \f2\-trustcacerts\fP option was specified, \f3keytool\fP will attempt to match it with any of the trusted certificates in the keystore or the "cacerts" keystore file. If the chain does not end with a self\-signed root CA certificate and the \f2\-trustcacerts\fP option was specified, \f3keytool\fP will try to find one from the trusted certificates in the keystore or the "cacerts" keystore file and add it to the end of the chain. If the certificate is not found and \f2\-noprompt\fP option is not specified, the information of the last certificate in the chain is printed out, and the user is prompted to verify it.
+.RE
+.LP
+If the public key in the certificate reply matches the user's public key already stored with under \f2alias\fP, the old certificate chain is replaced with the new certificate chain in the reply. The old chain can only be replaced if a valid \f2keypass\fP, the password used to protect the private key of the entry, is supplied. If no password is provided, and the private key password is different from the keystore password, the user is prompted for it.
+.LP
+This command was named \f2\-import\fP in previous releases. This old name is still supported in this release and will be supported in future releases, but for clarify the new name, \f2\-importcert\fP, is preferred going forward.
+.TP 3
+\-importkeystore \-srckeystore srckeystore \-destkeystore destkeystore {\-srcstoretype srcstoretype} {\-deststoretype deststoretype} [\-srcstorepass srcstorepass] [\-deststorepass deststorepass] {\-srcprotected} {\-destprotected} {\-srcalias srcalias {\-destalias destalias} [\-srckeypass srckeypass] [\-destkeypass destkeypass] } {\-noprompt} {\-srcProviderName src_provider_name} {\-destProviderName dest_provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Imports a single entry or all entries from a source keystore to a destination keystore.
+.LP
+When the \f2srcalias\fP option is provided, the command imports the single entry identified by the alias to the destination keystore. If a destination alias is not provided with \f2destalias\fP, then \f2srcalias\fP is used as the destination alias. If the source entry is protected by a password, \f2srckeypass\fP will be used to recover the entry. If \f2srckeypass\fP is not provided, then \f3keytool\fP will attempt to use \f2srcstorepass\fP to recover the entry. If \f2srcstorepass\fP is either not provided or is incorrect, the user will be prompted for a password. The destination entry will be protected using \f2destkeypass\fP. If \f2destkeypass\fP is not provided, the destination entry will be protected with the source entry password.
+.LP
+If the \f2srcalias\fP option is not provided, then all entries in the source keystore are imported into the destination keystore. Each destination entry will be stored under the alias from the source entry. If the source entry is protected by a password, \f2srcstorepass\fP will be used to recover the entry. If \f2srcstorepass\fP is either not provided or is incorrect, the user will be prompted for a password. If a source keystore entry type is not supported in the destination keystore, or if an error occurs while storing an entry into the destination keystore, the user will be prompted whether to skip the entry and continue, or to quit. The destination entry will be protected with the source entry password.
+.LP
+If the destination alias already exists in the destination keystore, the user is prompted to either overwrite the entry, or to create a new entry under a different alias name.
+.LP
+Note that if \f2\-noprompt\fP is provided, the user will not be prompted for a new destination alias. Existing entries will automatically be overwritten with the destination alias name. Finally, entries that can not be imported are automatically skipped and a warning is output.
+.TP 3
+\-printcertreq {\-file file}
+.LP
+Prints the content of a PKCS #10 format certificate request, which can be generated by the keytool \-certreq command. The command reads the request from file; if omitted, from the standard input.
+.RE
+
+.LP
+.SS
+Exporting Data
+.LP
+.RS 3
+.TP 3
+\-certreq {\-alias alias} {\-dname dname} {\-sigalg sigalg} {\-file certreq_file} [\-keypass keypass] {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Generates a Certificate Signing Request (CSR), using the PKCS#10 format.
+.LP
+A CSR is intended to be sent to a certificate authority (CA). The CA will authenticate the certificate requestor (usually off\-line) and will return a certificate or certificate chain, used to replace the existing certificate chain (which initially consists of a self\-signed certificate) in the keystore.
+.LP
+The private key associated with \f2alias\fP is used to create the PKCS#10 certificate request. In order to access the private key, the appropriate password must be provided, since private keys are protected in the keystore with a password. If \f2keypass\fP is not provided at the command line, and is different from the password used to protect the integrity of the keystore, the user is prompted for it. If dname is provided, it's used as the subject in the CSR. Otherwise, the X.500 Distinguished Name associated with alias is used.
+.LP
+\f2sigalg\fP specifies the algorithm that should be used to sign the CSR.
+.LP
+The CSR is stored in the file \f2certreq_file\fP. If no file is given, the CSR is output to stdout.
+.LP
+Use the \f2importcert\fP command to import the response from the CA.
+.TP 3
+\-exportcert {\-alias alias} {\-file cert_file} {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-rfc} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Reads (from the keystore) the certificate associated with \f2alias\fP, and stores it in the file \f2cert_file\fP.
+.LP
+If no file is given, the certificate is output to stdout.
+.LP
+The certificate is by default output in binary encoding, but will instead be output in the printable encoding format, as defined by the Internet RFC 1421 standard, if the \f2\-rfc\fP option is specified.
+.LP
+If \f2alias\fP refers to a trusted certificate, that certificate is output. Otherwise, \f2alias\fP refers to a key entry with an associated certificate chain. In that case, the first certificate in the chain is returned. This certificate authenticates the public key of the entity addressed by \f2alias\fP.
+.LP
+This command was named \f2\-export\fP in previous releases. This old name is still supported in this release and will be supported in future releases, but for clarify the new name, \f2\-exportcert\fP, is preferred going forward.
+.RE
+
+.LP
+.SS
+Displaying Data
+.LP
+.RS 3
+.TP 3
+\-list {\-alias alias} {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v | \-rfc} {\-protected} {\-Jjavaoption}
+.LP
+Prints (to stdout) the contents of the keystore entry identified by \f2alias\fP. If no alias is specified, the contents of the entire keystore are printed.
+.LP
+This command by default prints the SHA1 fingerprint of a certificate. If the \f2\-v\fP option is specified, the certificate is printed in human\-readable format, with additional information such as the owner, issuer, serial number, and any extensions. If the \f2\-rfc\fP option is specified, certificate contents are printed using the printable encoding format, as defined by the Internet RFC 1421 standard
+.LP
+You cannot specify both \f2\-v\fP and \f2\-rfc\fP.
+.TP 3
+\-printcert {\-file cert_file | \-sslserver host[:port]} {\-jarfile JAR_file {\-rfc} {\-v} {\-Jjavaoption}
+.LP
+Reads the certificate from the file \f2cert_file\fP, the SSL server located at \f2host:port\fP, or the signed JAR file \f2JAR_file\fP (with the option \f2\-jarfile\fP and prints its contents in a human\-readable format. When no port is specified, the standard HTTPS port 443 is assumed. Note that \f2\-sslserver\fP and \f2\-file\fP options cannot be provided at the same time. Otherwise, an error is reported. If neither option is given, the certificate is read from stdin.
+.LP
+If \f2\-rfc\fP is specified, keytool prints the certificate in PEM mode as defined by the Internet RFC 1421 standard.
+.LP
+If the certificate is read from a file or stdin, it may be either binary encoded or in printable encoding format, as defined by the Internet RFC 1421 standard
+.LP
+If the SSL server is behind a firewall, \f2\-J\-Dhttps.proxyHost=proxyhost\fP and \f2\-J\-Dhttps.proxyPort=proxyport\fP can be specified on the command line for proxy tunneling. See the
+.na
+\f2JSSE Reference Guide\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/jsse/JSSERefGuide.html for more information.
+.LP
+\f3Note\fP: This option can be used independently of a keystore.
+.TP 3
+\-printcrl \-file crl_ {\-v}
+.LP
+Reads the certificate revocation list (CRL) from the file \f2crl_file\fP.
+.LP
+A Certificate Revocation List (CRL) is a list of digital certificates which have been revoked by the Certificate Authority (CA) that issued them. The CA generates \f2crl_file\fP.
+.LP
+\f3Note\fP: This option can be used independently of a keystore.
+.RE
+
+.LP
+.SS
+Managing the Keystore
+.LP
+.RS 3
+.TP 3
+\-storepasswd [\-new new_storepass] {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-Jjavaoption}
+.LP
+Changes the password used to protect the integrity of the keystore contents. The new password is \f2new_storepass\fP, which must be at least 6 characters long.
+.TP 3
+\-keypasswd {\-alias alias} [\-keypass old_keypass] [\-new new_keypass] {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-Jjavaoption}
+.LP
+Changes the password under which the private/secret key identified by \f2alias\fP is protected, from \f2old_keypass\fP to \f2new_keypass\fP, which must be at least 6 characters long.
+.LP
+If the \f2\-keypass\fP option is not provided at the command line, and the key password is different from the keystore password, the user is prompted for it.
+.LP
+If the \f2\-new\fP option is not provided at the command line, the user is prompted for it.
+.TP 3
+\-delete [\-alias alias] {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Deletes from the keystore the entry identified by \f2alias\fP. The user is prompted for the alias, if no alias is provided at the command line.
+.TP 3
+\-changealias {\-alias alias} [\-destalias destalias] [\-keypass keypass] {\-storetype storetype} {\-keystore keystore} [\-storepass storepass] {\-providerName provider_name} {\-providerClass provider_class_name {\-providerArg provider_arg}} {\-v} {\-protected} {\-Jjavaoption}
+.LP
+Move an existing keystore entry from the specified \f2alias\fP to a new alias, \f2destalias\fP. If no destination alias is provided, the command will prompt for one. If the original entry is protected with an entry password, the password can be supplied via the "\-keypass" option. If no key password is provided, the \f2storepass\fP (if given) will be attempted first. If that attempt fails, the user will be prompted for a password.
+.RE
+
+.LP
+.SS
+Getting Help
+.LP
+.RS 3
+.TP 3
+\-help
+.LP
+Lists the basic commands and their options.
+.LP
+For more information about a specific command, enter the following, where \f2command_name\fP is the name of the command:
+.nf
+\f3
+.fl
+    keytool \-\fP\f4command_name\fP\f3 \-help
+.fl
+\fP
+.fi
+.RE
+
+.LP
+.SH "EXAMPLES"
+.LP
+.LP
+Suppose you want to create a keystore for managing your public/private key pair and certificates from entities you trust.
+.LP
+.SS
+Generating Your Key Pair
+.LP
+.LP
+The first thing you need to do is create a keystore and generate the key pair. You could use a command such as the following:
+.LP
+.nf
+\f3
+.fl
+    keytool \-genkeypair \-dname "cn=Mark Jones, ou=Java, o=Oracle, c=US"
+.fl
+      \-alias business \-keypass \fP\f4<new password for private key>\fP\f3 \-keystore /working/mykeystore
+.fl
+      \-storepass \fP\f4<new password for keystore>\fP\f3 \-validity 180
+.fl
+\fP
+.fi
+
+.LP
+.LP
+(Please note: This must be typed as a single line. Multiple lines are used in the examples just for legibility purposes.)
+.LP
+.LP
+This command creates the keystore named "mykeystore" in the "working" directory (assuming it doesn't already exist), and assigns it the password specified by \f2<new password for keystore>\fP. It generates a public/private key pair for the entity whose "distinguished name" has a common name of "Mark Jones", organizational unit of "Java", organization of "Oracle" and two\-letter country code of "US". It uses the default "DSA" key generation algorithm to create the keys, both 1024 bits long.
+.LP
+.LP
+It creates a self\-signed certificate (using the default "SHA1withDSA" signature algorithm) that includes the public key and the distinguished name information. This certificate will be valid for 180 days, and is associated with the private key in a keystore entry referred to by the alias "business". The private key is assigned the password specified by \f2<new password for private key>\fP.
+.LP
+.LP
+The command could be significantly shorter if option defaults were accepted. As a matter of fact, no options are required; defaults are used for unspecified options that have default values, and you are prompted for any required values. Thus, you could simply have the following:
+.LP
+.nf
+\f3
+.fl
+    keytool \-genkeypair
+.fl
+\fP
+.fi
+
+.LP
+.LP
+In this case, a keystore entry with alias "mykey" is created, with a newly\-generated key pair and a certificate that is valid for 90 days. This entry is placed in the keystore named ".keystore" in your home directory. (The keystore is created if it doesn't already exist.) You will be prompted for the distinguished name information, the keystore password, and the private key password.
+.LP
+.LP
+The rest of the examples assume you executed the \f2\-genkeypair\fP command without options specified, and that you responded to the prompts with values equal to those given in the first \f2\-genkeypair\fP command, above (for example, a distinguished name of "cn=Mark Jones, ou=Java, o=Oracle, c=US").
+.LP
+.SS
+Requesting a Signed Certificate from a Certification Authority
+.LP
+.LP
+So far all we've got is a self\-signed certificate. A certificate is more likely to be trusted by others if it is signed by a Certification Authority (CA). To get such a signature, you first generate a Certificate Signing Request (CSR), via the following:
+.LP
+.nf
+\f3
+.fl
+    keytool \-certreq \-file MarkJ.csr
+.fl
+\fP
+.fi
+
+.LP
+.LP
+This creates a CSR (for the entity identified by the default alias "mykey") and puts the request in the file named "MarkJ.csr". Submit this file to a CA, such as VeriSign, Inc. The CA will authenticate you, the requestor (usually off\-line), and then will return a certificate, signed by them, authenticating your public key. (In some cases, they will actually return a chain of certificates, each one authenticating the public key of the signer of the previous certificate in the chain.)
+.LP
+.SS
+Importing a Certificate for the CA
+.LP
+.LP
+You need to replace your self\-signed certificate with a certificate chain, where each certificate in the chain authenticates the public key of the signer of the previous certificate in the chain, up to a "root" CA.
+.LP
+.LP
+Before you import the certificate reply from a CA, you need one or more "trusted certificates" in your keystore or in the \f2cacerts\fP keystore file (which is described in importcert command):
+.LP
+.RS 3
+.TP 2
+o
+If the certificate reply is a certificate chain, you just need the top certificate of the chain (that is, the "root" CA certificate authenticating that CA's public key).
+.TP 2
+o
+If the certificate reply is a single certificate, you need a certificate for the issuing CA (the one that signed it), and if that certificate is not self\-signed, you need a certificate for its signer, and so on, up to a self\-signed "root" CA certificate.
+.RE
+
+.LP
+.LP
+The "cacerts" keystore file ships with several VeriSign root CA certificates, so you probably won't need to import a VeriSign certificate as a trusted certificate in your keystore. But if you request a signed certificate from a different CA, and a certificate authenticating that CA's public key hasn't been added to "cacerts", you will need to import a certificate from the CA as a "trusted certificate".
+.LP
+.LP
+A certificate from a CA is usually either self\-signed, or signed by another CA (in which case you also need a certificate authenticating that CA's public key). Suppose company ABC, Inc., is a CA, and you obtain a file named "ABCCA.cer" that is purportedly a self\-signed certificate from ABC, authenticating that CA's public key.
+.LP
+.LP
+Be very careful to ensure the certificate is valid prior to importing it as a "trusted" certificate! View it first (using the \f3keytool\fP \f2\-printcert\fP command, or the \f3keytool\fP \f2\-importcert\fP command without the \f2\-noprompt\fP option), and make sure that the displayed certificate fingerprint(s) match the expected ones. You can call the person who sent the certificate, and compare the fingerprint(s) that you see with the ones that they show (or that a secure public key repository shows). Only if the fingerprints are equal is it guaranteed that the certificate has not been replaced in transit with somebody else's (for example, an attacker's) certificate. If such an attack took place, and you did not check the certificate before you imported it, you would end up trusting anything the attacker has signed.
+.LP
+.LP
+If you trust that the certificate is valid, then you can add it to your keystore via the following:
+.LP
+.nf
+\f3
+.fl
+    keytool \-importcert \-alias abc \-file ABCCA.cer
+.fl
+\fP
+.fi
+
+.LP
+.LP
+This creates a "trusted certificate" entry in the keystore, with the data from the file "ABCCA.cer", and assigns the alias "abc" to the entry.
+.LP
+.SS
+Importing the Certificate Reply from the CA
+.LP
+.LP
+Once you've imported a certificate authenticating the public key of the CA you submitted your certificate signing request to (or there's already such a certificate in the "cacerts" file), you can import the certificate reply and thereby replace your self\-signed certificate with a certificate chain. This chain is the one returned by the CA in response to your request (if the CA reply is a chain), or one constructed (if the CA reply is a single certificate) using the certificate reply and trusted certificates that are already available in the keystore where you import the reply or in the "cacerts" keystore file.
+.LP
+.LP
+For example, suppose you sent your certificate signing request to VeriSign. You can then import the reply via the following, which assumes the returned certificate is named "VSMarkJ.cer":
+.LP
+.nf
+\f3
+.fl
+    keytool \-importcert \-trustcacerts \-file VSMarkJ.cer
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Exporting a Certificate Authenticating Your Public Key
+.LP
+.LP
+Suppose you have used the jarsigner(1) tool to sign a Java ARchive (JAR) file. Clients that want to use the file will want to authenticate your signature.
+.LP
+.LP
+One way they can do this is by first importing your public key certificate into their keystore as a "trusted" entry. You can export the certificate and supply it to your clients. As an example, you can copy your certificate to a file named \f2MJ.cer\fP via the following, assuming the entry is aliased by "mykey":
+.LP
+.nf
+\f3
+.fl
+    keytool \-exportcert \-alias mykey \-file MJ.cer
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Given that certificate, and the signed JAR file, a client can use the \f3jarsigner\fP tool to authenticate your signature.
+.LP
+.SS
+Importing Keystore
+.LP
+.LP
+The command "importkeystore" is used to import an entire keystore into another keystore, which means all entries from the source keystore, including keys and certificates, are all imported to the destination keystore within a single command. You can use this command to import entries from a different type of keystore. During the import, all new entries in the destination keystore will have the same alias names and protection passwords (for secret keys and private keys). If \f3keytool\fP has difficulties recover the private keys or secret keys from the source keystore, it will prompt you for a password. If it detects alias duplication, it will ask you for a new one, you can specify a new alias or simply allow \f3keytool\fP to overwrite the existing one.
+.LP
+.LP
+For example, to import entries from a normal JKS type keystore key.jks into a PKCS #11 type hardware based keystore, you can use the command:
+.LP
+.nf
+\f3
+.fl
+  keytool \-importkeystore
+.fl
+    \-srckeystore key.jks \-destkeystore NONE
+.fl
+    \-srcstoretype JKS \-deststoretype PKCS11
+.fl
+    \-srcstorepass \fP\f4<source keystore password>\fP\f3 \-deststorepass \fP\f4<destination keystore password>\fP\f3
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The importkeystore command can also be used to import a single entry from a source keystore to a destination keystore. In this case, besides the options you see in the above example, you need to specify the alias you want to import. With the srcalias option given, you can also specify the destination alias name in the command line, as well as protection password for a secret/private key and the destination protection password you want. The following command demonstrates this:
+.LP
+.nf
+\f3
+.fl
+  keytool \-importkeystore
+.fl
+    \-srckeystore key.jks \-destkeystore NONE
+.fl
+    \-srcstoretype JKS \-deststoretype PKCS11
+.fl
+    \-srcstorepass \fP\f4<source keystore password>\fP\f3 \-deststorepass \fP\f4<destination keystore password>\fP\f3
+.fl
+    \-srcalias myprivatekey \-destalias myoldprivatekey
+.fl
+    \-srckeypass \fP\f4<source entry password>\fP\f3 \-destkeypass \fP\f4<destination entry password>\fP\f3
+.fl
+    \-noprompt
+.fl
+\fP
+.fi
+
+.LP
+.SS
+Generating Certificates for a Typical SSL Server
+.LP
+.LP
+The following are keytool commands to generate keypairs and certificates for three entities, namely, Root CA (root), Intermediate CA (ca), and SSL server (server). Ensure that you store all the certificates in the same keystore. In these examples, it is recommended that you specify RSA as the key algorithm.
+.LP
+.nf
+\f3
+.fl
+keytool \-genkeypair \-keystore root.jks \-alias root \-ext bc:c
+.fl
+keytool \-genkeypair \-keystore ca.jks \-alias ca \-ext bc:c
+.fl
+keytool \-genkeypair \-keystore server.jks \-alias server
+.fl
+
+.fl
+keytool \-keystore root.jks \-alias root \-exportcert \-rfc > root.pem
+.fl
+
+.fl
+keytool \-storepass \fP\f4<storepass>\fP\f3 \-keystore ca.jks \-certreq \-alias ca | keytool \-storepass \fP\f4<storepass>\fP\f3 \-keystore root.jks \-gencert \-alias root \-ext BC=0 \-rfc > ca.pem
+.fl
+keytool \-keystore ca.jks \-importcert \-alias ca \-file ca.pem
+.fl
+
+.fl
+keytool \-storepass \fP\f4<storepass>\fP\f3 \-keystore server.jks \-certreq \-alias server | keytool \-storepass \fP\f4<storepass>\fP\f3 \-keystore ca.jks \-gencert \-alias ca \-ext ku:c=dig,kE \-rfc > server.pem
+.fl
+cat root.pem ca.pem server.pem | keytool \-keystore server.jks \-importcert \-alias server
+.fl
+\fP
+.fi
+
+.LP
+.SH "TERMINOLOGY and WARNINGS"
+.LP
+.SS
+KeyStore
+.LP
+.LP
+A keystore is a storage facility for cryptographic keys and certificates.
+.LP
+.RS 3
+.TP 2
+o
+\f3KeyStore Entries\fP
+.LP
+Keystores may have different types of entries. The two most applicable entry types for \f3keytool\fP include:
+.RS 3
+.TP 3
+1.
+\f3key entries\fP \- each holds very sensitive cryptographic key information, which is stored in a protected format to prevent unauthorized access. Typically, a key stored in this type of entry is a secret key, or a private key accompanied by the certificate "chain" for the corresponding public key. The \f3keytool\fP can handle both types of entries, while the \f3jarsigner\fP tool only handle the latter type of entry, that is private keys and their associated certificate chains.
+.TP 3
+2.
+\f3trusted certificate entries\fP \- each contains a single public key certificate belonging to another party. It is called a "trusted certificate" because the keystore owner trusts that the public key in the certificate indeed belongs to the identity identified by the "subject" (owner) of the certificate. The issuer of the certificate vouches for this, by signing the certificate.
+.RE
+.TP 2
+o
+\f3KeyStore Aliases\fP
+.LP
+All keystore entries (key and trusted certificate entries) are accessed via unique \f2aliases\fP.
+.LP
+An alias is specified when you add an entity to the keystore using the \-genseckey command to generate a secret key, \-genkeypair command to generate a key pair (public and private key) or the \-importcert command to add a certificate or certificate chain to the list of trusted certificates. Subsequent \f3keytool\fP commands must use this same alias to refer to the entity.
+.LP
+For example, suppose you use the alias \f2duke\fP to generate a new public/private key pair and wrap the public key into a self\-signed certificate (see Certificate Chains) via the following command:
+.nf
+\f3
+.fl
+    keytool \-genkeypair \-alias duke \-keypass dukekeypasswd
+.fl
+\fP
+.fi
+.LP
+This specifies an initial password of "dukekeypasswd" required by subsequent commands to access the private key associated with the alias \f2duke\fP. If you later want to change duke's private key password, you use a command like the following:
+.nf
+\f3
+.fl
+    keytool \-keypasswd \-alias duke \-keypass dukekeypasswd \-new newpass
+.fl
+\fP
+.fi
+.LP
+This changes the password from "dukekeypasswd" to "newpass".
+.LP
+Please note: A password should not actually be specified on a command line or in a script unless it is for testing purposes, or you are on a secure system. If you don't specify a required password option on a command line, you will be prompted for it.
+.TP 2
+o
+\f3KeyStore Implementation\fP
+.LP
+The \f2KeyStore\fP class provided in the \f2java.security\fP package supplies well\-defined interfaces to access and modify the information in a keystore. It is possible for there to be multiple different concrete implementations, where each implementation is that for a particular \f2type\fP of keystore.
+.LP
+Currently, two command\-line tools (\f3keytool\fP and \f3jarsigner\fP) and a GUI\-based tool named \f3Policy Tool\fP make use of keystore implementations. Since \f2KeyStore\fP is publicly available, users can write additional security applications that use it.
+.LP
+There is a built\-in default implementation, provided by Oracle. It implements the keystore as a file, utilizing a proprietary keystore type (format) named "JKS". It protects each private key with its individual password, and also protects the integrity of the entire keystore with a (possibly different) password.
+.LP
+Keystore implementations are provider\-based. More specifically, the application interfaces supplied by \f2KeyStore\fP are implemented in terms of a "Service Provider Interface" (SPI). That is, there is a corresponding abstract \f2KeystoreSpi\fP class, also in the \f2java.security\fP package, which defines the Service Provider Interface methods that "providers" must implement. (The term "provider" refers to a package or a set of packages that supply a concrete implementation of a subset of services that can be accessed by the Java Security API.) Thus, to provide a keystore implementation, clients must implement a "provider" and supply a KeystoreSpi subclass implementation, as described in
+.na
+\f2How to Implement a Provider for the Java Cryptography Architecture\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/crypto/HowToImplAProvider.html.
+.LP
+Applications can choose different \f2types\fP of keystore implementations from different providers, using the "getInstance" factory method supplied in the \f2KeyStore\fP class. A keystore type defines the storage and data format of the keystore information, and the algorithms used to protect private/secret keys in the keystore and the integrity of the keystore itself. Keystore implementations of different types are not compatible.
+.LP
+\f3keytool\fP works on any file\-based keystore implementation. (It treats the keystore location that is passed to it at the command line as a filename and converts it to a FileInputStream, from which it loads the keystore information.) The \f3jarsigner\fP and \f3policytool\fP tools, on the other hand, can read a keystore from any location that can be specified using a URL.
+.LP
+For \f3keytool\fP and \f3jarsigner\fP, you can specify a keystore type at the command line, via the \f2\-storetype\fP option. For \f3Policy Tool\fP, you can specify a keystore type via the "Keystore" menu.
+.LP
+If you don't explicitly specify a keystore type, the tools choose a keystore implementation based simply on the value of the \f2keystore.type\fP property specified in the security properties file. The security properties file is called \f2java.security\fP, and it resides in the security properties directory, \f2java.home\fP/lib/security, where \f2java.home\fP is the runtime environment's directory (the \f2jre\fP directory in the SDK or the top\-level directory of the Java 2 Runtime Environment).
+.LP
+Each tool gets the \f2keystore.type\fP value and then examines all the currently\-installed providers until it finds one that implements keystores of that type. It then uses the keystore implementation from that provider.
+.LP
+The \f2KeyStore\fP class defines a static method named \f2getDefaultType\fP that lets applications and applets retrieve the value of the \f2keystore.type\fP property. The following line of code creates an instance of the default keystore type (as specified in the \f2keystore.type\fP property):
+.nf
+\f3
+.fl
+    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+.fl
+\fP
+.fi
+.LP
+The default keystore type is "jks" (the proprietary type of the keystore implementation provided by Oracle). This is specified by the following line in the security properties file:
+.nf
+\f3
+.fl
+    keystore.type=jks
+.fl
+\fP
+.fi
+.LP
+To have the tools utilize a keystore implementation other than the default, you can change that line to specify a different keystore type.
+.LP
+For example, if you have a provider package that supplies a keystore implementation for a keystore type called "pkcs12", change the line to
+.nf
+\f3
+.fl
+    keystore.type=pkcs12
+.fl
+\fP
+.fi
+.LP
+Note: case doesn't matter in keystore type designations. For example, "JKS" would be considered the same as "jks".
+.RE
+
+.LP
+.SS
+Certificate
+.LP
+A \f3certificate\fP (also known as a \f3public\-key certificate\fP) is a digitally signed statement from one entity (the \f2issuer\fP), saying that the public key (and some other information) of another entity (the \f2subject\fP) has some specific value.
+.RS 3
+.TP 2
+o
+\f3Certificate Terms\fP
+.RS 3
+.TP 3
+Public Keys
+.LP
+These are numbers associated with a particular entity, and are intended to be known to everyone who needs to have trusted interactions with that entity. Public keys are used to verify signatures.
+.TP 3
+Digitally Signed
+.LP
+If some data is \f2digitally signed\fP it has been stored with the "identity" of an entity, and a signature that proves that entity knows about the data. The data is rendered unforgeable by signing with the entity's private key.
+.TP 3
+Identity
+.LP
+A known way of addressing an entity. In some systems the identity is the public key, in others it can be anything from a Unix UID to an Email address to an X.509 Distinguished Name.
+.TP 3
+Signature
+.LP
+A signature is computed over some data using the private key of an entity (the \f2signer\fP, which in the case of a certificate is also known as the \f2issuer\fP).
+.TP 3
+Private Keys
+.LP
+These are numbers, each of which is supposed to be known only to the particular entity whose private key it is (that is, it's supposed to be kept secret). Private and public keys exist in pairs in all public key cryptography systems (also referred to as "public key crypto systems"). In a typical public key crypto system, such as DSA, a private key corresponds to exactly one public key. Private keys are used to compute signatures.
+.TP 3
+Entity
+.LP
+An entity is a person, organization, program, computer, business, bank, or something else you are trusting to some degree.
+.RE
+.LP
+Basically, public key cryptography requires access to users' public keys. In a large\-scale networked environment it is impossible to guarantee that prior relationships between communicating entities have been established or that a trusted repository exists with all used public keys. Certificates were invented as a solution to this public key distribution problem. Now a \f2Certification Authority\fP (CA) can act as a trusted third party. CAs are entities (for example, businesses) that are trusted to sign (issue) certificates for other entities. It is assumed that CAs will only create valid and reliable certificates, as they are bound by legal agreements. There are many public Certification Authorities, such as
+.na
+\f2VeriSign\fP @
+.fi
+http://www.verisign.com/,
+.na
+\f2Thawte\fP @
+.fi
+http://www.thawte.com/,
+.na
+\f2Entrust\fP @
+.fi
+http://www.entrust.com/, and so on. You can also run your own Certification Authority using products such as Microsoft Certificate Server or the Entrust CA product for your organization.
+.LP
+Using \f3keytool\fP, it is possible to display, import, and export certificates. It is also possible to generate self\-signed certificates.
+.LP
+\f3keytool\fP currently handles X.509 certificates.
+.TP 2
+o
+\f3X.509 Certificates\fP
+.LP
+The X.509 standard defines what information can go into a certificate, and describes how to write it down (the data format). All the data in a certificate is encoded using two related standards called ASN.1/DER. \f2Abstract Syntax Notation 1\fP describes data. The \f2Definite Encoding Rules\fP describe a single way to store and transfer that data.
+.LP
+All X.509 certificates have the following data, in addition to the signature:
+.RS 3
+.TP 3
+Version
+.LP
+This identifies which version of the X.509 standard applies to this certificate, which affects what information can be specified in it. Thus far, three versions are defined. \f3keytool\fP can import and export v1, v2, and v3 certificates. It generates v3 certificates.
+.LP
+\f2X.509 Version 1\fP has been available since 1988, is widely deployed, and is the most generic.
+.LP
+\f2X.509 Version 2\fP introduced the concept of subject and issuer unique identifiers to handle the possibility of reuse of subject and/or issuer names over time. Most certificate profile documents strongly recommend that names not be reused, and that certificates should not make use of unique identifiers. Version 2 certificates are not widely used.
+.LP
+\f2X.509 Version 3\fP is the most recent (1996) and supports the notion of extensions, whereby anyone can define an extension and include it in the certificate. Some common extensions in use today are: \f2KeyUsage\fP (limits the use of the keys to particular purposes such as "signing\-only") and \f2AlternativeNames\fP (allows other identities to also be associated with this public key, e.g. DNS names, Email addresses, IP addresses). Extensions can be marked \f2critical\fP to indicate that the extension should be checked and enforced/used. For example, if a certificate has the KeyUsage extension marked critical and set to "keyCertSign" then if this certificate is presented during SSL communication, it should be rejected, as the certificate extension indicates that the associated private key should only be used for signing certificates and not for SSL use.
+.TP 3
+Serial Number
+.LP
+The entity that created the certificate is responsible for assigning it a serial number to distinguish it from other certificates it issues. This information is used in numerous ways, for example when a certificate is revoked its serial number is placed in a Certificate Revocation List (CRL).
+.TP 3
+Signature Algorithm Identifier
+.LP
+This identifies the algorithm used by the CA to sign the certificate.
+.TP 3
+Issuer Name
+.LP
+The X.500 Distinguished Name of the entity that signed the certificate. This is normally a CA. Using this certificate implies trusting the entity that signed this certificate. (Note that in some cases, such as \f2root or top\-level\fP CA certificates, the issuer signs its own certificate.)
+.TP 3
+Validity Period
+.LP
+Each certificate is valid only for a limited amount of time. This period is described by a start date and time and an end date and time, and can be as short as a few seconds or almost as long as a century. The validity period chosen depends on a number of factors, such as the strength of the private key used to sign the certificate or the amount one is willing to pay for a certificate. This is the expected period that entities can rely on the public value, if the associated private key has not been compromised.
+.TP 3
+Subject Name
+.LP
+The name of the entity whose public key the certificate identifies. This name uses the X.500 standard, so it is intended to be unique across the Internet. This is the X.500 Distinguished Name (DN) of the entity, for example,
+.nf
+\f3
+.fl
+    CN=Java Duke, OU=Java Software Division, O=Oracle Corporation, C=US
+.fl
+\fP
+.fi
+.LP
+(These refer to the subject's Common Name, Organizational Unit, Organization, and Country.)
+.TP 3
+Subject Public Key Information
+.LP
+This is the public key of the entity being named, together with an algorithm identifier which specifies which public key crypto system this key belongs to and any associated key parameters.
+.RE
+.TP 2
+o
+\f3Certificate Chains\fP
+.LP
+\f3keytool\fP can create and manage keystore "key" entries that each contain a private key and an associated certificate "chain". The first certificate in the chain contains the public key corresponding to the private key.
+.LP
+When keys are first generated (see the \-genkeypair command), the chain starts off containing a single element, a \f2self\-signed certificate\fP. A self\-signed certificate is one for which the issuer (signer) is the same as the subject (the entity whose public key is being authenticated by the certificate). Whenever the \f2\-genkeypair\fP command is called to generate a new public/private key pair, it also wraps the public key into a self\-signed certificate.
+.LP
+Later, after a Certificate Signing Request (CSR) has been generated (see the \-certreq command) and sent to a Certification Authority (CA), the response from the CA is imported (see \-importcert), and the self\-signed certificate is replaced by a chain of certificates. At the bottom of the chain is the certificate (reply) issued by the CA authenticating the subject's public key. The next certificate in the chain is one that authenticates the \f2CA\fP's public key.
+.LP
+In many cases, this is a self\-signed certificate (that is, a certificate from the CA authenticating its own public key) and the last certificate in the chain. In other cases, the CA may return a chain of certificates. In this case, the bottom certificate in the chain is the same (a certificate signed by the CA, authenticating the public key of the key entry), but the second certificate in the chain is a certificate signed by a \f2different\fP CA, authenticating the public key of the CA you sent the CSR to. Then, the next certificate in the chain will be a certificate authenticating the second CA's key, and so on, until a self\-signed "root" certificate is reached. Each certificate in the chain (after the first) thus authenticates the public key of the signer of the previous certificate in the chain.
+.LP
+Many CAs only return the issued certificate, with no supporting chain, especially when there is a flat hierarchy (no intermediates CAs). In this case, the certificate chain must be established from trusted certificate information already stored in the keystore.
+.LP
+A different reply format (defined by the PKCS#7 standard) also includes the supporting certificate chain, in addition to the issued certificate. Both reply formats can be handled by \f3keytool\fP.
+.LP
+The top\-level (root) CA certificate is self\-signed. However, the trust into the root's public key does not come from the root certificate itself (anybody could generate a self\-signed certificate with the distinguished name of say, the VeriSign root CA!), but from other sources like a newspaper. The root CA public key is widely known. The only reason it is stored in a certificate is because this is the format understood by most tools, so the certificate in this case is only used as a "vehicle" to transport the root CA's public key. Before you add the root CA certificate to your keystore, you should view it (using the \f2\-printcert\fP option) and compare the displayed fingerprint with the well\-known fingerprint (obtained from a newspaper, the root CA's Web page, etc.).
+.TP 2
+o
+\f3The cacerts Certificates File\fP
+.LP
+A certificates file named \f3"cacerts"\fP resides in the security properties directory, \f2java.home\fP/lib/security, where \f2java.home\fP is the runtime environment's directory (the \f2jre\fP directory in the SDK or the top\-level directory of the Java 2 Runtime Environment).
+.LP
+The "cacerts" file represents a system\-wide keystore with CA certificates. System administrators can configure and manage that file using \f3keytool\fP, specifying "jks" as the keystore type. The "cacerts" keystore file ships with a default set of root CA certificates; list them with the following command:
+.nf
+\f3
+.fl
+keytool \-list \-keystore \fP\f4java.home\fP\f3/lib/security/cacerts
+.fl
+\fP
+.fi
+.LP
+The initial password of the "cacerts" keystore file is "changeit". System administrators should change that password and the default access permission of that file upon installing the SDK.
+.LP
+\f3IMPORTANT: Verify Your \fP\f4cacerts\fP\f3 File\fP: Since you trust the CAs in the \f2cacerts\fP file as entities for signing and issuing certificates to other entities, you must manage the \f2cacerts\fP file carefully. The \f2cacerts\fP file should contain only certificates of the CAs you trust. It is your responsibility to verify the trusted root CA certificates bundled in the \f2cacerts\fP file and make your own trust decisions. To remove an untrusted CA certificate from the \f2cacerts\fP file, use the delete option of the \f2keytool\fP command. You can find the \f2cacerts\fP file in the JRE installation directory. Contact your system administrator if you do not have permission to edit this file.
+.TP 2
+o
+\f3The Internet RFC 1421 Certificate Encoding Standard\fP
+.LP
+Certificates are often stored using the printable encoding format defined by the Internet RFC 1421 standard, instead of their binary encoding. This certificate format, also known as "Base 64 encoding", facilitates exporting certificates to other applications by email or through some other mechanism.
+.LP
+Certificates read by the \f2\-importcert\fP and \f2\-printcert\fP commands can be in either this format or binary encoded.
+.LP
+The \f2\-exportcert\fP command by default outputs a certificate in binary encoding, but will instead output a certificate in the printable encoding format, if the \f2\-rfc\fP option is specified.
+.LP
+The \f2\-list\fP command by default prints the SHA1 fingerprint of a certificate. If the \f2\-v\fP option is specified, the certificate is printed in human\-readable format, while if the \f2\-rfc\fP option is specified, the certificate is output in the printable encoding format.
+.LP
+In its printable encoding format, the encoded certificate is bounded at the beginning by
+.nf
+\f3
+.fl
+\-\-\-\-\-BEGIN CERTIFICATE\-\-\-\-\-
+.fl
+\fP
+.fi
+.LP
+and at the end by
+.nf
+\f3
+.fl
+\-\-\-\-\-END CERTIFICATE\-\-\-\-\-
+.fl
+\fP
+.fi
+.RE
+
+.LP
+.SS
+X.500 Distinguished Names
+.LP
+.LP
+X.500 Distinguished Names are used to identify entities, such as those which are named by the \f2subject\fP and \f2issuer\fP (signer) fields of X.509 certificates. \f3keytool\fP supports the following subparts:
+.LP
+.RS 3
+.TP 2
+o
+\f2commonName\fP \- common name of a person, e.g., "Susan Jones"
+.TP 2
+o
+\f2organizationUnit\fP \- small organization (e.g., department or division) name, e.g., "Purchasing"
+.TP 2
+o
+\f2organizationName\fP \- large organization name, e.g., "ABCSystems, Inc."
+.TP 2
+o
+\f2localityName\fP \- locality (city) name, e.g., "Palo Alto"
+.TP 2
+o
+\f2stateName\fP \- state or province name, e.g., "California"
+.TP 2
+o
+\f2country\fP \- two\-letter country code, e.g., "CH"
+.RE
+
+.LP
+.LP
+When supplying a distinguished name string as the value of a \f2\-dname\fP option, as for the \f2\-genkeypair\fP  command, the string must be in the following format:
+.LP
+.nf
+\f3
+.fl
+CN=\fP\f4cName\fP\f3, OU=\fP\f4orgUnit\fP\f3, O=\fP\f4org\fP\f3, L=\fP\f4city\fP\f3, S=\fP\f4state\fP\f3, C=\fP\f4countryCode\fP\f3
+.fl
+\fP
+.fi
+
+.LP
+.LP
+where all the italicized items represent actual values and the above keywords are abbreviations for the following:
+.LP
+.nf
+\f3
+.fl
+        CN=commonName
+.fl
+        OU=organizationUnit
+.fl
+        O=organizationName
+.fl
+        L=localityName
+.fl
+        S=stateName
+.fl
+        C=country
+.fl
+\fP
+.fi
+
+.LP
+.LP
+A sample distinguished name string is
+.LP
+.nf
+\f3
+.fl
+CN=Mark Smith, OU=Java, O=Oracle, L=Cupertino, S=California, C=US
+.fl
+\fP
+.fi
+
+.LP
+.LP
+and a sample command using such a string is
+.LP
+.nf
+\f3
+.fl
+keytool \-genkeypair \-dname "CN=Mark Smith, OU=Java, O=Oracle, L=Cupertino,
+.fl
+S=California, C=US" \-alias mark
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Case does not matter for the keyword abbreviations. For example, "CN", "cn", and "Cn" are all treated the same.
+.LP
+.LP
+Order matters; each subcomponent must appear in the designated order. However, it is not necessary to have all the subcomponents. You may use a subset, for example:
+.LP
+.nf
+\f3
+.fl
+CN=Steve Meier, OU=Java, O=Oracle, C=US
+.fl
+\fP
+.fi
+
+.LP
+.LP
+If a distinguished name string value contains a comma, the comma must be escaped by a "\\" character when you specify the string on a command line, as in
+.LP
+.nf
+\f3
+.fl
+   cn=Peter Schuster, ou=Java\\, Product Development, o=Oracle, c=US
+.fl
+\fP
+.fi
+
+.LP
+.LP
+It is never necessary to specify a distinguished name string on a command line. If it is needed for a command, but not supplied on the command line, the user is prompted for each of the subcomponents. In this case, a comma does not need to be escaped by a "\\".
+.LP
+.SS
+WARNING Regarding Importing Trusted Certificates
+.LP
+.LP
+IMPORTANT: Be sure to check a certificate very carefully before importing it as a trusted certificate!
+.LP
+.LP
+View it first (using the \f2\-printcert\fP command, or the \f2\-importcert\fP command without the \f2\-noprompt\fP option), and make sure that the displayed certificate fingerprint(s) match the expected ones. For example, suppose someone sends or emails you a certificate, and you put it in a file named \f2/tmp/cert\fP. Before you consider adding the certificate to your list of trusted certificates, you can execute a \f2\-printcert\fP command to view its fingerprints, as in
+.LP
+.nf
+\f3
+.fl
+  keytool \-printcert \-file /tmp/cert
+.fl
+    Owner: CN=ll, OU=ll, O=ll, L=ll, S=ll, C=ll
+.fl
+    Issuer: CN=ll, OU=ll, O=ll, L=ll, S=ll, C=ll
+.fl
+    Serial Number: 59092b34
+.fl
+    Valid from: Thu Sep 25 18:01:13 PDT 1997 until: Wed Dec 24 17:01:13 PST 1997
+.fl
+    Certificate Fingerprints:
+.fl
+         MD5:  11:81:AD:92:C8:E5:0E:A2:01:2E:D4:7A:D7:5F:07:6F
+.fl
+         SHA1: 20:B6:17:FA:EF:E5:55:8A:D0:71:1F:E8:D6:9D:C0:37:13:0E:5E:FE
+.fl
+         SHA256: 90:7B:70:0A:EA:DC:16:79:92:99:41:FF:8A:FE:EB:90:
+.fl
+                 17:75:E0:90:B2:24:4D:3A:2A:16:A6:E4:11:0F:67:A4
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Then call or otherwise contact the person who sent the certificate, and compare the fingerprint(s) that you see with the ones that they show. Only if the fingerprints are equal is it guaranteed that the certificate has not been replaced in transit with somebody else's (for example, an attacker's) certificate. If such an attack took place, and you did not check the certificate before you imported it, you would end up trusting anything the attacker has signed (for example, a JAR file with malicious class files inside).
+.LP
+.LP
+Note: it is not required that you execute a \f2\-printcert\fP command prior to importing a certificate, since before adding a certificate to the list of trusted certificates in the keystore, the \f2\-importcert\fP command prints out the certificate information and prompts you to verify it. You then have the option of aborting the import operation. Note, however, this is only the case if you invoke the \f2\-importcert\fP command without the \f2\-noprompt\fP option. If the \f2\-noprompt\fP option is given, there is no interaction with the user.
+.LP
+.SS
+Warning Regarding Passwords
+.LP
+.LP
+Most commands operating on a keystore require the store password. Some commands require a private/secret key password.
+.LP
+.LP
+Passwords can be specified on the command line (in the \f2\-storepass\fP and \f2\-keypass\fP options, respectively). However, a password should not be specified on a command line or in a script unless it is for testing purposes, or you are on a secure system.
+.LP
+.LP
+If you don't specify a required password option on a command line, you will be prompted for it.
+.LP
+.SS
+Warning Regarding Certificate Conformance
+.LP
+.LP
+The Internet standard
+.na
+\f2RFC 5280\fP @
+.fi
+http://tools.ietf.org/rfc/rfc5280.txt has defined a profile on conforming X.509 certificates, which includes what values and value combinations are valid for certificate fields and extensions. \f3keytool\fP has not enforced all these rules so it can generate certificates which do not conform to the standard, and these certificates might be rejected by JRE or other applications. Users should make sure that they provide the correct options for \f2\-dname\fP, \f2\-ext\fP, etc.
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+jar(1) tool documentation
+.TP 2
+o
+jarsigner(1) tool documentation
+.TP 2
+o
+the
+.na
+\f4Security\fP @
+.fi
+http://download.oracle.com/javase/tutorial/security/index.html trail of the
+.na
+\f4Java Tutorial\fP @
+.fi
+http://download.oracle.com/javase/tutorial/ for examples of the use of \f3keytool\fP
+.RE
+
+.LP
+.SH "CHANGES"
+.LP
+.LP
+The command interface for keytool changed in Java SE 6.
+.LP
+.LP
+\f3keytool\fP no longer displays password input when entered by users. Since password input can no longer be viewed when entered, users will be prompted to re\-enter passwords any time a password is being set or changed (for example, when setting the initial keystore password, or when changing a key password).
+.LP
+.LP
+Some commands have simply been renamed, and other commands deemed obsolete are no longer listed in this document. All previous commands (both renamed and obsolete) are still supported in this release and will continue to be supported in future releases. The following summarizes all of the changes made to the keytool command interface:
+.LP
+.LP
+Renamed commands:
+.LP
+.RS 3
+.TP 2
+o
+\f2\-export\fP, renamed to \f2\-exportcert\fP
+.TP 2
+o
+\f2\-genkey\fP, renamed to \f2\-genkeypair\fP
+.TP 2
+o
+\f2\-import\fP, renamed to \f2\-importcert\fP
+.RE
+
+.LP
+.LP
+Commands deemed obsolete and no longer documented:
+.LP
+.RS 3
+.TP 2
+o
+.na
+\f2\-keyclone\fP @
+.fi
+http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/keytool.html#keycloneCmd
+.TP 2
+o
+.na
+\f2\-identitydb\fP @
+.fi
+http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/keytool.html#identitydbCmd
+.TP 2
+o
+.na
+\f2\-selfcert\fP @
+.fi
+http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/keytool.html#selfcertCmd
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/native2ascii.1 b/jdk/src/bsd/doc/man/native2ascii.1
new file mode 100644
index 0000000..b433198
--- /dev/null
+++ b/jdk/src/bsd/doc/man/native2ascii.1
@@ -0,0 +1,72 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH native2ascii 1 "10 May 2011"
+
+.LP
+.SH "Name"
+native2ascii \- Native\-to\-ASCII Converter
+.LP
+.LP
+Converts a file with characters in any supported character encoding to one with ASCII and/or Unicode escapes, or visa versa.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f4native2ascii\fP\f2 [options] [inputfile [outputfile]]\fP
+.fl
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f2native2ascii\fP converts files that are encoded to any character encoding that is supported by the Java runtime environment to files encoded in ASCII, using Unicode escapes ("\\uxxxx" notation) for all characters that are not part of the ASCII character set. This process is required for properties files containing characters not in ISO\-8859\-1 character sets. The tool can also perform the reverse conversion.
+.LP
+.LP
+If \f2outputfile\fP is omitted, standard output is used for output. If, in addition, \f2inputfile\fP is omitted, standard input is used for input.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-reverse
+Perform the reverse operation: Convert a file encoded in ISO\-8859\-1 with Unicode escapes to a file in any character encoding supported by the Java runtime environment.
+.br
+.br
+.TP 3
+\-encoding encoding_name
+Specifies the name of the character encoding to be used by the conversion procedure. If this option is not present, the default character encoding (as determined by the \f2java.nio.charset.Charset.defaultCharset\fP method) is used. The \f2encoding_name\fP string must be the name of a character encoding that is supported by the Java runtime environment \- see the
+.na
+\f4Supported Encodings\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html document.
+.br
+.br
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for the java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes.
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/orbd.1 b/jdk/src/bsd/doc/man/orbd.1
new file mode 100644
index 0000000..95a68b2
--- /dev/null
+++ b/jdk/src/bsd/doc/man/orbd.1
@@ -0,0 +1,368 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH orbd 1 "10 May 2011"
+
+.LP
+.SH "Name"
+orbd \- The Object Request Broker Daemon
+.LP
+.LP
+\f3orbd\fP is used to enable clients to transparently locate and invoke persistent objects on servers in the CORBA environment.
+.LP
+.LP
+\f3See also:\fP
+.na
+\f2Naming Service\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+orbd <\fP\f3options\fP\f3>
+.fl
+\fP
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The Server Manager included with the \f3orbd\fP tool is used to enable clients to transparently locate and invoke persistent objects on servers in the CORBA environment. The persistent servers, while publishing the persistent object references in the Naming Service, include the port number of the ORBD in the object reference instead of the port number of the Server. The inclusion of an ORBD port number in the object reference for persistent object references has the following advantages:
+.LP
+.RS 3
+.TP 2
+o
+The object reference in the Naming Service remains independent of the server life cycle. For example, the object reference could be published by the server in the Naming Service when it is first installed, and then, independent of how many times the server is started or shutdown, the ORBD will always return the correct object reference to the invoking client.
+.TP 2
+o
+The client needs to lookup the object reference in the Naming Service only once, and can keep re\-using this reference independent of the changes introduced due to server life cycle.
+.RE
+
+.LP
+.LP
+To access ORBD's Server Manager, the server must be started using servertool(1), which is a command\-line interface for application programmers to register, unregister, startup, and shutdown a persistent server. For more information on the Server Manager, see the section in this document titled \f2Server Manager\fP.
+.LP
+.LP
+When \f2orbd\fP starts up, it also starts a naming service. For more information on the naming service, link to
+.na
+\f2Naming Service\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html.
+.LP
+.SH "OPTIONS"
+.LP
+.SS
+Required Options
+.LP
+.RS 3
+.TP 3
+\-ORBInitialPort nameserverport
+Specifies the port on which the name server should be started. Once started, \f2orbd\fP will listen for incoming requests on this port. Note that when using Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024. (required)
+.RE
+
+.LP
+.LP
+
+.LP
+.SS
+OTHER OPTIONS
+.LP
+.RS 3
+.TP 3
+\-port port
+Specifies the activation port where ORBD should be started, and where ORBD will be accepting requests for persistent objects. The default value for this port is 1049. This port number is added to the port field of the persistent Interoperable Object References (IOR). (optional)
+.RE
+
+.LP
+.RS 3
+.TP 3
+\-defaultdb directory
+Specifies the base where the ORBD persistent storage directory \f2orb.db\fP is created. If this option is not specified, the default value is "./orb.db". (optional)
+.RE
+
+.LP
+.RS 3
+.TP 3
+\-serverPollingTime milliseconds
+Specifies how often ORBD checks for the health of persistent servers registered via \f2servertool\fP. The default value is 1,000 ms. The value specified for \f2milliseconds\fP must be a valid positive integer. (optional)
+.RE
+
+.LP
+.RS 3
+.TP 3
+\-serverStartupDelay milliseconds
+Specifies how long ORBD waits before sending a location forward exception after a persistent server that is registered via \f2servertool\fP is restarted. The default value is 1,000 ms. The value specified for \f2milliseconds\fP must be a valid positive integer. (optional)
+.RE
+
+.LP
+.RS 3
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. It is a common convention for \f3\-J\fP to pass options to the underlying virtual machine.
+.TP 3
+
+.RE
+
+.LP
+.SH "Starting and Stopping the Naming Service"
+.LP
+.LP
+A Naming Service is a CORBA service that allows
+.na
+\f2CORBA objects\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlGlossary.html#CORBA%20object to be named by means of binding a name to an object reference. The
+.na
+\f2name binding\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlGlossary.html#name%20binding may be stored in the naming service, and a client may supply the name to obtain the desired object reference.
+.LP
+.LP
+Prior to running a client or a server, you will start ORBD. ORBD includes a persistent Naming Service and a transient Naming Service, both of which are an implementation of the COS Naming Service.
+.LP
+.LP
+The \f4Persistent\fP\f3 Naming Service\fP provides persistence for naming contexts. This means that this information is persistent across service shutdowns and startups, and is recoverable in the event of a service failure. If ORBD is restarted, the Persistent Naming Service will restore the naming context graph, so that the binding of all clients' and servers' names remains intact (persistent).
+.LP
+.LP
+\
+.LP
+.LP
+For backward compatibility, \f2tnameserv\fP, a \f4Transient\fP\f3 Naming Service\fP shipped with older versions of the JDK, is also included in this release of J2SE. A transient naming service retains naming contexts as long as it is running. If there is a service interruption, the naming context graph is lost.
+.LP
+.LP
+The \f2\-ORBInitialPort\fP argument is a required command\-line argument for \f2orbd\fP, and is used to set the port number on which the Naming Service will run. The following instructions assume you can use port 1050 for the Java\ IDL Object Request Broker Daemon. When using Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024. You can substitute a different port if necessary.
+.LP
+.LP
+To start \f2orbd\fP from a UNIX command shell, enter:
+.LP
+.nf
+\f3
+.fl
+  orbd \-ORBInitialPort 1050&
+.fl
+\fP
+.fi
+
+.LP
+.LP
+From an MS\-DOS system prompt (Windows), enter:
+.LP
+.nf
+\f3
+.fl
+  start orbd \-ORBInitialPort 1050
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Now that ORBD is running, you can run your server and client applications. When running the client and server applications, they must be made aware of the port number (and machine name, if applicable) where the Naming Service is running. One way to do this is to add the following code to your application:
+.LP
+.nf
+\f3
+.fl
+        Properties props = new Properties();
+.fl
+        props.put("org.omg.CORBA.ORBInitialPort", "1050");
+.fl
+        props.put("org.omg.CORBA.ORBInitialHost", "MyHost");
+.fl
+        ORB orb = ORB.init(args, props);
+.fl
+\fP
+.fi
+
+.LP
+.LP
+In this example, the Naming Service is running on port 1050 on host "MyHost". Another way is to specify the port number and/or machine name when running the server or client application from the command line. For example, you would start your "HelloApplication" with the following command line:
+.LP
+.nf
+\f3
+.fl
+     java HelloApplication \-ORBInitialPort 1050 \-ORBInitialHost MyHost
+.fl
+\fP
+.fi
+
+.LP
+.LP
+To stop the naming service, use the relevant operating system command, such as \f2pkill orbd\fP on Solaris, or \f2Ctrl+C\fP in the DOS window in which \f2orbd\fP is running. Note that names registered with the naming service may disappear when the service is terminated if the naming service is transient. The Java IDL naming service will run until it is explicitly stopped.
+.LP
+.LP
+For more information on the Naming Service included with ORBD, see
+.na
+\f2Naming Service\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html.
+.LP
+.SH "Server Manager"
+.LP
+.LP
+To access ORBD's Server Manager and run a persistent server, the server must be started using servertool(1), which is a command\-line interface for application programmers to register, unregister, startup, and shutdown a persistent server. When a server is started using \f2servertool\fP, it must be started on the same host and port on which \f2orbd\fP is executing. If the server is run on a different port, the information stored in the database for local contexts will be invalid and the service will not work properly.
+.LP
+.SS
+Server Manager: an Example
+.LP
+.LP
+Using the
+.na
+\f2sample tutorial\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlExample.html for our demonstration, you would run the \f2idlj\fP compiler and \f2javac\fP compiler as shown in the tutorial. To run the Server Manager, follow these steps for running the application:
+.LP
+.LP
+Start \f2orbd\fP.
+.LP
+.LP
+To start \f2orbd\fP from a UNIX command shell, enter:
+.LP
+.LP
+\
+.LP
+.nf
+\f3
+.fl
+  orbd \-ORBInitialPort 1050
+.fl
+\fP
+.fi
+
+.LP
+.LP
+From an MS\-DOS system prompt (Windows), enter:
+.LP
+.nf
+\f3
+.fl
+  start orbd \-ORBInitialPort 1050
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Note that \f21050\fP is the port on which you want the name server to run. \f2\-ORBInitialPort\fP is a required command\-line argument. When using Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024.
+.LP
+.LP
+Start the \f2servertool\fP:
+.LP
+.LP
+To start the Hello server, enter:
+.LP
+.nf
+\f3
+.fl
+  servertool \-ORBInitialPort 1050
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Make sure the name server (\f2orbd\fP) port is the same as in the previous step, for example, \f2\-ORBInitialPort 1050\fP. The \f2servertool\fP must be started on the same port as the name server.
+.LP
+.LP
+The \f2servertool\fP command line interface appears.
+.LP
+.LP
+
+.LP
+.LP
+Start the Hello server from the \f2servertool\fP prompt:
+.LP
+.nf
+\f3
+.fl
+  servertool  > register \-server HelloServer \-classpath . \-applicationName
+.fl
+                HelloServerApName
+.fl
+\fP
+.fi
+
+.LP
+.LP
+The \f2servertool\fP registers the server, assigns it the name of "HelloServerApName", and displays its server id, along with a listing of all registered servers.
+.LP
+.LP
+
+.LP
+.LP
+Run the client application from another terminal window or prompt:
+.LP
+.LP
+\
+.LP
+.nf
+\f3
+.fl
+  java HelloClient \-ORBInitialPort 1050 \-ORBInitialHost localhost
+.fl
+\fP
+.fi
+
+.LP
+.LP
+For this example, you can omit \f2\-ORBInitialHost localhost\fP since the name server is running on the same host as the Hello client. If the name server is running on a different host, use \f2\-ORBInitialHost\fP \f2nameserverhost\fP to specify the host on which the IDL name server is running.
+.LP
+.LP
+Specify the name server (\f2orbd\fP) port as done in the previous step, for example, \f2\-ORBInitialPort 1050\fP.
+.LP
+.LP
+\
+.LP
+.LP
+\
+.LP
+.LP
+When you have finished experimenting with the Server Manager, be sure to shut down or kill the name server (\f2orbd\fP) and \f2servertool\fP.
+.LP
+.LP
+To shut down \f2orbd\fP from a DOS prompt, select the window that is running the server and enter \f2Ctrl+C\fP to shut it down. To shut down \f2orbd\fPfrom a Unix shell, find the process, and kill it. The server will continue to wait for invocations until it is explicitly stopped.
+.LP
+.LP
+To shut down the \f2servertool\fP, type \f2quit\fP and press the \f2Enter\fP key on the keyboard.
+.LP
+.SH "See Also"
+.LP
+.RS 3
+.TP 2
+o
+.na
+\f2Naming Service\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html
+.br
+.TP 2
+o
+servertool(1)
+.RE
+
+.LP
+.br
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/pack200.1 b/jdk/src/bsd/doc/man/pack200.1
new file mode 100644
index 0000000..71bfe87
--- /dev/null
+++ b/jdk/src/bsd/doc/man/pack200.1
@@ -0,0 +1,340 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH pack200 1 "10 May 2011"
+
+.LP
+.SH "Name"
+pack200 \- JAR Packing tool
+.LP
+.SH "SYNOPSIS"
+.LP
+.LP
+\f4pack200\fP\f2 [ \fP\f2options\fP ] \f2output\-file\fP \f2JAR\-file\fP
+.LP
+.LP
+Options may be in any order. The last option on the command line or in a properties file supersedes all previously specified options.
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options.
+.TP 3
+output\-file
+Name of the output file.
+.TP 3
+JAR\-file
+Name of the input file.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f2pack200\fP tool is a Java application that transforms a JAR file into a compressed \f2pack200\fP file using the Java \f2gzip\fP compressor. The \f2pack200\fP files are highly compressed files that can be directly deployed, saving bandwidth and reducing download time.
+.LP
+.LP
+The \f2pack200\fP tool uses several options to fine\-tune and set the compression engine.
+.LP
+.SS
+Typical usage:
+.LP
+.LP
+\f2% pack200 myarchive.pack.gz myarchive.jar\fP
+.LP
+.LP
+In this example, \f2myarchive.pack.gz\fP is produced using the default \f2pack200\fP settings.
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+\f4\-r \-\-repack\fP
+.LP
+.LP
+Produces a JAR file by packing the file \f2myarchive.jar\fP and unpacking it. The resulting file can be used as an input to the \f2jarsigner(1)\fP tool.
+.LP
+.LP
+\f2% pack200 \-\-repack myarchive\-packer.jar myarchive.jar\fP
+.LP
+.LP
+\f2% pack200 \-\-repack myarchive.jar\fP
+.LP
+.LP
+\f4\-g \-\-no\-gzip\fP
+.LP
+.LP
+Produces a \f2pack200\fP file. With this option a suitable compressor must be used, and the target system must use a corresponding decompresser.
+.LP
+.LP
+\f2% pack200 \-\-no\-gzip myarchive.pack myarchive.jar\fP
+.LP
+.LP
+\f4\-G \-\-strip\-debug\fP
+.LP
+.LP
+Strips attributes used for debugging from the output. These include \f2SourceFile\fP, \f2LineNumberTable\fP, \f2LocalVariableTable\fP and \f2LocalVariableTypeTable\fP. Removing these attributes reduces the size of both downloads and installations but reduces the usefulness of debuggers.
+.LP
+.LP
+\f4\-\-keep\-file\-order\fP
+.LP
+.LP
+Preserve the order of files in the input file; this is the default behavior.
+.LP
+.LP
+\f4\-O \-\-no\-keep\-file\-order\fP
+.LP
+.LP
+The packer will reorder and transmit all elements. Additionally, the packer may remove JAR directory names. This will reduce the download size; however, certain JAR file optimizations, such as indexing, may not work correctly.
+.LP
+.LP
+\f4\-Svalue \-\-segment\-limit=\fP\f2value\fP
+.LP
+.LP
+The value is the estimated target size N (in bytes) of each archive segment. If a single input file requires
+.br
+more than N bytes, it will be given its own archive segment. As a special case, a value of \f2\-1\fP will produce a single large segment with all input files, while a value of \f20\fP will produce one segment for each class. Larger archive segments result in less fragmentation and better compression, but processing them requires more memory.
+.LP
+.LP
+The size of each segment is estimated by counting the size of each input file to be transmitted in the segment, along with the size of its name and other transmitted properties.
+.LP
+.LP
+The default is \-1, which means the packer will always create a single segment output file. In cases where extremely large output files are generated, users are strongly encouraged to use segmenting or break up the input file into smaller JARs.
+.LP
+.LP
+A 10MB JAR packed without this limit will typically pack about 10% smaller, but the packer may require a larger Java heap (about ten times the segment limit).
+.LP
+.LP
+\f4\-Evalue \-\-effort=\fP\f2value\fP
+.LP
+.LP
+If the value is set to a single decimal digit, the packer will use the indicated amount of effort in compressing the archive. Level \f21\fP may produce somewhat larger size and faster compression speed, while level \f29\fP will take much longer but may produce better compression. The special value \f20\fP instructs the packer to copy through the original JAR file directly with no compression. The JSR 200 standard requires any unpacker to understand this special case as a pass\-through of the entire archive.
+.LP
+.LP
+The default is \f25\fP, investing a modest amount of time to produce reasonable compression.
+.LP
+.LP
+\f4\-Hvalue \-\-deflate\-hint=\fP\f2value\fP
+.LP
+.LP
+Overrides the default, which preserves the input information, but may cause the transmitted archive to be larger. The possible values are:
+.LP
+.RS 3
+.TP 3
+true
+.TP 3
+false
+In either case, the packer will set the deflation hint accordingly in the output archive, and will not transmit the individual deflation hints of archive elements.
+.RE
+
+.LP
+.RS 3
+.TP 3
+keep
+Preserve deflation hints observed in the input JAR. (This is the default.)
+.RE
+
+.LP
+.LP
+\f4\-mvalue \-\-modification\-time=\fP\f2value\fP
+.LP
+.LP
+The possible values are:
+.LP
+.RS 3
+.TP 3
+latest
+The packer will attempt to determine the latest modification time, among all the available entries in the original archive, or the latest modification time of all the available entries in that segment. This single value will be transmitted as part of the segment and applied to all the entries in each segment. This can marginally decrease the transmitted size of the archive at the expense of setting all installed files to a single date.
+.TP 3
+keep
+Preserves modification times observed in the input JAR. (This is the default.)
+.RE
+
+.LP
+.LP
+\f4\-Pfile \-\-pass\-file=\fP\f2file\fP
+.LP
+.LP
+Indicates that a file should be passed through bytewise with no compression. By repeating the option, multiple files may be specified. There is no pathname transformation, except that the system file separator is replaced by the JAR file separator "\f2/\fP". The resulting file names must match exactly as strings with their occurrences in the JAR file. If file is a directory name, all files under that directory will be passed.
+.LP
+.LP
+\f4\-Uaction \-\-unknown\-attribute=\fP\f2action\fP
+.LP
+.LP
+Overrides the default behavior; i.e., the classfile containing the unknown attribute will be passed through with the specified action. The possible values for actions are:
+.LP
+.RS 3
+.TP 3
+error
+The \f2pack200\fP operation as a whole will fail with a suitable explanation.
+.TP 3
+strip
+The attribute will be dropped. Note: Removing the required VM attributes may cause Class Loader failures.
+.TP 3
+pass
+Upon encountering this attribute, the entire class will be transmitted as though it is a resource.
+.RE
+
+.LP
+.LP
+\f4\-Cattribute\-name=\fP\f2layout\fP \f3\-\-class\-attribute=\fP\f2attribute\-name=action\fP
+.br
+\f4\-Fattribute\-name=\fP\f2layout\fP \f3\-\-field\-attribute=\fP\f2attribute\-name=action\fP
+.br
+\f4\-Mattribute\-name=\fP\f2layout\fP \f3\-\-method\-attribute=\fP\f2attribute\-name=action\fP
+.br
+\f4\-Dattribute\-name=\fP\f2layout\fP \f3\-\-code\-attribute=\fP\f2attribute\-name=action\fP
+.LP
+.LP
+With the above four options, the attribute layout can be specified for a class entity, such as Class attribute, Field attribute, Method attribute, and Code attribute. The attribute\-name is the name of the attribute for which the layout or action is being defined. The possible values for action are:
+.LP
+.RS 3
+.TP 3
+some\-layout\-string
+The layout language is defined in the JSR 200 specification.
+.LP
+Example: \f2\-\-class\-attribute=SourceFile=RUH\fP
+.TP 3
+error
+Upon encountering this attribute, the pack200 operation will fail with a suitable explanation.
+.TP 3
+strip
+Upon encountering this attribute, the attribute will be removed from the output. Note: removing VM\-required attributes may cause Class Loader failures.
+.RE
+
+.LP
+.LP
+Example: \f2\-\-class\-attribute=CompilationID=pass\fP will cause the class file containing this attribute to be passed through without further action by the packer.
+.LP
+.LP
+\f4\-f\fP\f2 \fP\f2pack.properties\fP \f3\-\-config\-file=\fP\f2pack.properties\fP
+.LP
+.LP
+A configuration file, containing Java properties to initialize the packer, may be specified on the command line.
+.LP
+.LP
+\f2% pack200 \-f pack.properties myarchive.pack.gz myarchive.jar\fP
+.br
+\f2% more pack.properties\fP
+.br
+\f2# Generic properties for the packer.\fP
+.br
+\f2modification.time=latest\fP
+.br
+\f2deflate.hint=false\fP
+.br
+\f2keep.file.order=false\fP
+.br
+\f2# This option will cause the files bearing new attributes to\fP
+.br
+\f2# be reported as an error rather than passed uncompressed.\fP
+.br
+\f2unknown.attribute=error\fP
+.br
+\f2# Change the segment limit to be unlimited.\fP
+.br
+\f2segment.limit=\-1\fP
+.LP
+.LP
+\f4\-v \-\-verbose\fP
+.LP
+.LP
+Outputs minimal messages. Multiple specification of this option will output more verbose messages.
+.LP
+.LP
+\f4\-q \-\-quiet\fP
+.LP
+.LP
+Specifies quiet operation with no messages.
+.LP
+.LP
+\f4\-lfilename \-\-log\-file=\fP\f2filename\fP
+.LP
+.LP
+Specifies a log file to output messages.
+.LP
+.LP
+\f4\-? \-h \-\-help\fP
+.LP
+.LP
+Prints help information about this command.
+.LP
+.LP
+\f4\-V \-\-version\fP
+.LP
+.LP
+Prints version information about this command.
+.LP
+.LP
+\f4\-J\fP\f2option\fP
+.LP
+.LP
+Passes \f2option\fP to the Java launcher called by \f2pack200\fP. For example, \f2\-J\-Xms48m\fP sets the startup memory to 48 megabytes. Although it does not begin with \f2\-X\fP, it is not a standard option of \f2pack200\fP. It is a common convention for \f2\-J\fP to pass options to the underlying VM executing applications written in Java.
+.LP
+.SH "EXIT STATUS"
+.LP
+.LP
+The following exit values are returned:
+.LP
+.LP
+\f2\ 0\fP for successful completion;
+.LP
+.LP
+\f2>0\fP if an error occurs.
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+unpack200(1)
+.TP 2
+o
+.na
+\f2Java SE Documentation\fP @
+.fi
+http://download.oracle.com/javase/7/docs/index.html
+.TP 2
+o
+.na
+\f2Java Deployment Guide \- Pack200\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/deployment/deployment\-guide/pack200.html
+.TP 2
+o
+jar(1) \- Java Archive Tool
+.TP 2
+o
+jarsigner(1) \- JAR Signer tool
+.TP 2
+o
+\f2attributes(5)\fP man page
+.RE
+
+.LP
+.SH "NOTES"
+.LP
+.LP
+This command should not be confused with \f2pack(1)\fP. They are distinctly separate products.
+.LP
+.LP
+The Java SE API Specification provided with the JDK is the superseding authority, in case of discrepancies.
+.LP
+
diff --git a/jdk/src/bsd/doc/man/policytool.1 b/jdk/src/bsd/doc/man/policytool.1
new file mode 100644
index 0000000..eac0d68
--- /dev/null
+++ b/jdk/src/bsd/doc/man/policytool.1
@@ -0,0 +1,89 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH policytool 1 "10 May 2011"
+
+.LP
+.SH "Name"
+policytool \- PolicyTool Administration GUI Utility
+.LP
+\f3policytool\fP reads and writes a plain text policy file based on user input via the utility GUI.
+.SH "SYNOPSIS"
+.LP
+.RS 3
+.TP 3
+\
+.TP 3
+Run the policytool Administrator's utility
+\f4policytool\fP
+.TP 3
+Run policytool and load the specified policy file
+\f4policytool\fP\f2[\-file\ \fP\f2filename\fP\f2]\fP
+.TP 3
+\
+.TP 3
+where:
+.RS 3
+.TP 3
+file
+directs \f2policytool\fP to load a local policy file
+.TP 3
+filename
+The file name
+.RE
+.SH "DESCRIPTION"
+.LP
+\f3policytool\fP is a GUI that allows users to create and manage policy files. For details, see
+.na
+\f2the Policytool Users Guide\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/PolicyGuide.html.
+.SH "OPTIONS"
+.RS 3
+.TP 3
+file
+Loads \f2filename\fP.
+.SH "SEE ALSO"
+.na
+\f2Default Policy Implementation and Syntax\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html
+.br
+.na
+\f2Policy Tool Users' Guide\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/PolicyGuide.html
+.br
+.na
+\f2Security Permissions\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/permissions.html
+.br
+.na
+\f2Security Overview\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/security/overview/jsoverview.html
+.br
+.RE
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/rmic.1 b/jdk/src/bsd/doc/man/rmic.1
new file mode 100644
index 0000000..2e8fd3f
--- /dev/null
+++ b/jdk/src/bsd/doc/man/rmic.1
@@ -0,0 +1,227 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH rmic 1 "10 May 2011"
+
+.LP
+.SH "Name"
+rmic \- The Java RMI Compiler
+.LP
+.LP
+\f3rmic\fP generates stub, skeleton, and tie classes for remote objects using either the JRMP or IIOP protocols. Also generates OMG IDL.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+rmic [ \fP\f3options\fP\f3 ] \fP\f4package\-qualified\-class\-name(s)\fP\f3
+.fl
+\fP
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3rmic\fP compiler generates stub and skeleton class files (JRMP protocol) and stub and tie class files (IIOP protocol) for remote objects. These classes files are generated from compiled Java programming language classes that are remote object implementation classes. A remote implementation class is a class that implements the interface \f2java.rmi.Remote\fP. The class names in the \f3rmic\fP command must be for classes that have been compiled successfully with the \f3javac\fP command and must be fully package qualified. For example, running \f3rmic\fP on the class file name \f2HelloImpl\fP as shown here:
+.LP
+.nf
+\f3
+.fl
+rmic hello.HelloImpl
+.fl
+\fP
+.fi
+
+.LP
+.LP
+creates the \f2HelloImpl_Stub.class\fP file in the \f2hello\fP subdirectory (named for the class's package).
+.LP
+.LP
+A \f2skeleton\fP for a remote object is a JRMP protocol server\-side entity that has a method that dispatches calls to the actual remote object implementation.
+.LP
+.LP
+A \f2tie\fP for a remote object is a server\-side entity similar to a skeleton, but which communicates with the client using the IIOP protocol.
+.LP
+.LP
+A \f2stub\fP is a client\-side proxy for a remote object which is responsible for communicating method invocations on remote objects to the server where the actual remote object implementation resides. A client's reference to a remote object, therefore, is actually a reference to a local stub.
+.LP
+.LP
+By default, \f3rmic\fP generates stub classes that use the 1.2 JRMP stub protocol version only, as if the \f2\-v1.2\fP option had been specified. (Note that the \f2\-vcompat\fP option was the default in releases prior to 5.0.) Use the \f2\-iiop\fP option to generate stub and tie classes for the IIOP protocol.
+.LP
+.LP
+A stub implements only the remote interfaces, not any local interfaces that the remote object also implements. Because a JRMP stub implements the same set of remote interfaces as the remote object itself, a client can use the Java programming language's built\-in operators for casting and type checking. For IIOP, the \f2PortableRemoteObject.narrow\fP method must be used.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-bootclasspath path
+Overrides location of bootstrap class files
+.TP 3
+\-classpath path
+Specifies the path \f3rmic\fP uses to look up classes. This option overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by colons. Thus the general format for \f2path\fP is:
+.nf
+\f3
+.fl
+.:<your_path>
+.fl
+\fP
+.fi
+For example:
+.nf
+\f3
+.fl
+.:/usr/local/java/classes
+.fl
+\fP
+.fi
+.TP 3
+\-d directory
+Specifies the root destination directory for the generated class hierarchy. You can use this option to specify a destination directory for the stub, skeleton, and tie files. For example, the command
+.nf
+\f3
+.fl
+% rmic \-d /java/classes foo.MyClass
+.fl
+\fP
+.fi
+would place the stub and skeleton classes derived from \f2MyClass\fP into the directory \f2/java/classes/foo\fP. If the \f2\-d\fP option is not specified, the default behavior is as if \f2"\-d\ ."\fP were specified: the package hierarchy of the target class is created in the current directory, and stub/tie/skeleton files are placed within it. (Note that in some previous versions of \f3rmic\fP, if \f2\-d\fP was not specified, then the package hierarchy was \f2not\fP created, and all of the output files were placed directly in the current directory.)
+.br
+\
+.TP 3
+\-extdirs path
+Overrides location of installed extensions
+.TP 3
+\-g
+Enables generation of all debugging information, including local variables. By default, only line number information is generated.
+.TP 3
+\-idl
+Causes \f2rmic\fP to generate OMG IDL for the classes specified and any classes referenced. IDL provides a purely declarative, programming language\-independent way of specifying an object's API. The IDL is used as a specification for methods and data that can be written in and invoked from any language that provides CORBA bindings. This includes Java and C++ among others. See the
+.na
+\f2Java Language to IDL Mapping\fP @
+.fi
+http://www.omg.org/technology/documents/formal/java_language_mapping_to_omg_idl.htm (OMG) document for a complete description.
+.br
+.br
+When the \f2\-idl\fP option is used, other options also include:
+.RS 3
+.TP 3
+\-always or \-alwaysgenerate
+Forces re\-generation even when existing stubs/ties/IDL are newer than the input class.
+.TP 3
+\-factory
+Uses factory keyword in generated IDL.
+.TP 3
+\-idlModule\  fromJavaPackage[.class]\  toIDLModule
+Specifies IDLEntity package mapping. For example:\  \f2\-idlModule foo.bar my::real::idlmod\fP.
+.TP 3
+\-idlFile\  fromJavaPackage[.class]\  toIDLFile
+Specifies IDLEntity file mapping. For example:\  \f2\-idlFile test.pkg.X TEST16.idl\fP.\
+.RE
+.TP 3
+\-iiop
+Causes \f2rmic\fP to generate IIOP stub and tie classes, rather than JRMP stub and skeleton classes. A stub class is a local proxy for a remote object and is used by clients to send calls to a server. Each remote interface requires a stub class, which implements that remote interface. A client's reference to a remote object is actually a reference to a stub. Tie classes are used on the server side to process incoming calls, and dispatch the calls to the proper implementation class. Each implementation class requires a tie class.
+.br
+.br
+Invoking \f2rmic\fP with the \f2\-iiop\fP generates stubs and ties that conform to this naming convention:
+.nf
+\f3
+.fl
+_<implementationName>_stub.class
+.fl
+_<interfaceName>_tie.class
+.fl
+\fP
+.fi
+When the \f2\-iiop\fP option is used, other options also include:
+.RS 3
+.TP 3
+\-always or \-alwaysgenerate
+Forces re\-generation even when existing stubs/ties/IDL are newer than the input class.
+.TP 3
+\-nolocalstubs
+Do not create stubs optimized for same\-process clients and servers.
+.TP 3
+\-noValueMethods
+Must be used with the \f2\-idl\fP option. Prevents addition of \f2valuetype\fP methods and initializers to emitted IDL. These methods and initializers are optional for \f2valuetype\fPs, and are generated unless the \f2\-noValueMethods\fP option is specified when using the \f2\-idl\fP option.
+.TP 3
+\-poa
+Changes the inheritance from \f2org.omg.CORBA_2_3.portable.ObjectImpl\fP to \f2org.omg.PortableServer.Servant\fP. The \f2PortableServer\fP module for the
+.na
+\f2Portable Object Adapter\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/POA.html (POA) defines the native \f2Servant\fP type. In the Java programming language, the \f2Servant\fP type is mapped to the Java \f2org.omg.PortableServer.Servant\fP class. It serves as the base class for all POA servant implementations and provides a number of methods that may be invoked by the application programmer, as well as methods which are invoked by the POA itself and may be overridden by the user to control aspects of servant behavior. Based on the OMG IDL to Java Language Mapping Specification, CORBA V 2.3.1 ptc/00\-01\-08.pdf.
+.RE
+.TP 3
+\-J
+Used in conjunction with any \f2java\fP option, it passes the option following the \f2\-J\fP (no spaces between the \-J and the option) on to the \f2java\fP interpreter.
+.TP 3
+\-keep or \-keepgenerated
+Retains the generated \f2.java\fP source files for the stub, skeleton, and/or tie classes and writes them to the same directory as the \f2.class\fP files.
+.TP 3
+\-nowarn
+Turns off warnings. If used the compiler does not print out any warnings.
+.TP 3
+\-nowrite
+Does not write compiled classes to the file system.
+.TP 3
+\-vcompat
+Generates stub and skeleton classes compatible with both the 1.1 and 1.2 JRMP stub protocol versions. (This option was the default in releases prior to 5.0.) The generated stub classes will use the 1.1 stub protocol version when loaded in a JDK 1.1 virtual machine and will use the 1.2 stub protocol version when loaded into a 1.2 (or later) virtual machine. The generated skeleton classes will support both 1.1 and 1.2 stub protocol versions. The generated classes are relatively large in order to support both modes of operation.
+.TP 3
+\-verbose
+Causes the compiler and linker to print out messages about what classes are being compiled and what class files are being loaded.
+.TP 3
+\-v1.1
+Generates stub and skeleton classes for the 1.1 JRMP stub protocol version only. Note that this option is only useful for generating stub classes that are serialization\-compatible with pre\-existing, statically\-deployed stub classes that were generated by the \f3rmic\fP tool from JDK 1.1 and that cannot be upgraded (and dynamic class loading is not being used).
+.TP 3
+\-v1.2
+(default) Generates stub classes for the 1.2 JRMP stub protocol version only. No skeleton classes are generated with this option because skeleton classes are not used with the 1.2 stub protocol version. The generated stub classes will not work if they are loaded into a JDK 1.1 virtual machine.
+.RE
+
+.LP
+.SH "ENVIRONMENT VARIABLES"
+.LP
+.RS 3
+.TP 3
+CLASSPATH
+Used to provide the system a path to user\-defined classes. Directories are separated by colons. For example,
+.nf
+\f3
+.fl
+.:/usr/local/java/classes
+.fl
+\fP
+.fi
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.LP
+java(1), javac(1),
+.na
+\f2CLASSPATH\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#classpath
+.LP
+
diff --git a/jdk/src/bsd/doc/man/rmid.1 b/jdk/src/bsd/doc/man/rmid.1
new file mode 100644
index 0000000..833311a
--- /dev/null
+++ b/jdk/src/bsd/doc/man/rmid.1
@@ -0,0 +1,328 @@
+." Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH rmid 1 "10 May 2011"
+
+.LP
+.SH "Name"
+rmid \- The Java RMI Activation System Daemon
+.LP
+.LP
+\f3rmid\fP starts the activation system daemon that allows objects to be registered and activated in a virtual machine (VM).
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+rmid [options]
+.fl
+\fP
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3rmid\fP tool starts the activation system daemon. The activation system daemon must be started before activatable objects can be either registered with the activation system or activated in a VM. See the
+.na
+\f2Java RMI Specification\fP @
+.fi
+http://download.oracle.com/javase/7/docs/platform/rmi/spec/rmiTOC.html and
+.na
+\f2Activation tutorials\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/rmi/activation/overview.html for details on how to write programs that use activatable remote objects.
+.LP
+.LP
+The daemon can be started by executing the \f2rmid\fP command, and specifying a security policy file, as follows:
+.LP
+.nf
+\f3
+.fl
+    rmid \-J\-Djava.security.policy=rmid.policy
+.fl
+\fP
+.fi
+
+.LP
+.LP
+\f3Note:\fP When running Sun's implementation of \f2rmid\fP, by default you will need to specify a security policy file so that \f2rmid\fP can verify whether or not the information in each \f2ActivationGroupDesc\fP is allowed to be used to launch a VM for an activation group. Specifically, the command and options specified by the \f2CommandEnvironment\fP and any \f2Properties\fP passed to an \f2ActivationGroupDesc\fP's constructor must now be explicitly allowed in the security policy file for \f2rmid\fP. The value of the \f2sun.rmi.activation.execPolicy\fP property dictates the policy that \f2rmid\fP uses to determine whether or not the information in an \f2ActivationGroupDesc\fP may be used to launch a VM for an activation group.
+.LP
+.LP
+Executing \f2rmid\fP by default
+.LP
+.RS 3
+.TP 2
+o
+starts the Activator and an internal registry on the default port, 1098, and
+.TP 2
+o
+binds an \f2ActivationSystem\fP to the name \f2java.rmi.activation.ActivationSystem\fP in this internal registry.
+.RE
+
+.LP
+.LP
+To specify an alternate port for the registry, you must specify the \f2\-port\fP option when starting up \f2rmid\fP. For example,
+.LP
+.nf
+\f3
+.fl
+    rmid \-J\-Djava.security.policy=rmid.policy \-port 1099
+.fl
+\fP
+.fi
+
+.LP
+.LP
+starts the activation system daemon and a registry on the registry's default port, 1099.
+.LP
+.SS
+Starting rmid from inetd/xinetd
+.LP
+.LP
+An alternative to starting \f2rmid\fP from the command line is to configure \f2inetd\fP (Solaris) or \f2xinetd\fP (Bsd) to start \f2rmid\fP on demand.
+.LP
+.LP
+When \f2rmid\fP starts up, it attempts to obtain an inherited channel (inherited from \f2inetd\fP/\f2xinetd\fP) by invoking the \f2System.inheritedChannel\fP method. If the inherited channel is \f2null\fP or not an instance of \f2java.nio.channels.ServerSocketChannel\fP, then \f2rmid\fP assumes that it was not started by \f2inetd\fP/\f2xinetd\fP, and it starts up as described above.
+.LP
+.LP
+If the inherited channel is a \f2ServerSocketChannel\fP instance, then \f2rmid\fP uses the \f2java.net.ServerSocket\fP obtained from the \f2ServerSocketChannel\fP as the server socket that accepts requests for the remote objects it exports, namely the registry in which the \f2java.rmi.activation.ActivationSystem\fP is bound and the \f2java.rmi.activation.Activator\fP remote object. In this mode, \f2rmid\fP behaves the same as when it is started from the command line, \f2except\fP:
+.LP
+.RS 3
+.TP 2
+o
+Output printed to \f2System.err\fP is redirected to a file. This file is located in the directory specified by the \f2java.io.tmpdir\fP system property (typically \f2/var/tmp\fP or \f2/tmp\fP) with the prefix \f2"rmid\-err"\fP and the suffix \f2"tmp"\fP.
+.TP 2
+o
+The \f2\-port\fP option is disallowed. If this option is specified, \f2rmid\fP will exit with an error message.
+.TP 2
+o
+The \f2\-log\fP option is required. If this option is not specified, \f2rmid\fP will exit with an error message.
+.RE
+
+.LP
+.LP
+See the man pages for \f2inetd\fP (Solaris) or \f2xinetd\fP (Bsd) for details on how to configure services to be started on demand.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-C<someCommandLineOption>
+Specifies an option that is passed as a command\-line argument to each child process (activation group) of \f2rmid\fP when that process is created. For example, you could pass a property to each virtual machine spawned by the activation system daemon:
+.nf
+\f3
+.fl
+    rmid \-C\-Dsome.property=value
+.fl
+\fP
+.fi
+This ability to pass command\-line arguments to child processes can be useful for debugging. For example, the following command:
+.nf
+\f3
+.fl
+    rmid \-C\-Djava.rmi.server.logCalls=true
+.fl
+\fP
+.fi
+will enable server\-call logging in all child VMs.
+.LP
+.TP 3
+\-J<someCommandLineOption>
+Specifies an option that is passed to the \f2java\fP interpreter running \f2rmid\fP. For example, to specify that \f2rmid\fP use a policy file named \f2rmid.policy\fP, the \f2\-J\fP option can be used to define the \f2java.security.policy\fP property on \f2rmid\fP's command line, for example:
+.nf
+\f3
+.fl
+    rmid \-J\-Djava.security.policy=rmid.policy
+.fl
+\fP
+.fi
+.TP 3
+\-J\-Dsun.rmi.activation.execPolicy=<policy>
+Specifies the policy that \f2rmid\fP employs to check commands and command\-line options used to launch the VM in which an activation group runs. Please note that this option exists only in Sun's implementation of the Java RMI activation daemon. If this property is not specified on the command line, the result is the same as if \f2\-J\-Dsun.rmi.activation.execPolicy=default\fP were specified. The possible values of \f2<policy>\fP can be \f2default\fP, \f2<policyClassName>\fP, or \f2none\fP:
+.RS 3
+.TP 2
+o
+\f3default (or if this property is \fP\f4unspecified\fP\f3)\fP
+.LP
+The default \f2execPolicy\fP allows \f2rmid\fP to execute commands with specific command\-line options only if \f2rmid\fP has been granted permission to execute those commands and options in the security policy file that \f2rmid\fP uses. Only the default activation group implementation can be used with the \f2default\fP execution policy.
+.LP
+\f2rmid\fP launches a VM for an activation group using the information in the group's registered activation group descriptor, an \f2ActivationGroupDesc\fP. The group descriptor specifies an optional \f2ActivationGroupDesc.CommandEnvironment\fP which includes the \f2command\fP to execute to start the activation group as well as any command line \f2options\fP to be added to the command line. By default, \f2rmid\fP uses the \f2java\fP command found in \f2java.home\fP. The group descriptor also contains \f2properties\fP overrides that are added to the command line as options defined as:
+.nf
+\f3
+.fl
+    \-D\fP\f4<property>\fP\f3=\fP\f4<value>\fP\f3
+.fl
+\fP
+.fi
+.LP
+The permission \f2com.sun.rmi.rmid.ExecPermission\fP is used to grant \f2rmid\fP permission to execute a command, specified in the group descriptor's \f2CommandEnvironment\fP to launch an activation group. The permission \f2com.sun.rmi.rmid.ExecOptionPermission\fP is used to allow \f2rmid\fP to use command\-line options, specified as properties overrides in the group descriptor or as options in the \f2CommandEnvironment\fP, when launching the activation group.
+.LP
+When granting \f2rmid\fP permission to execute various commands and options, the permissions \f2ExecPermission\fP and \f2ExecOptionPermission\fP need to be granted universally (i.e., granted to all code sources).
+.RS 3
+.TP 3
+ExecPermission
+The \f2ExecPermission\fP class represents permission for \f2rmid\fP to execute a specific \f2command\fP to launch an activation group.
+.LP
+\f3Syntax\fP
+.br
+The \f2name\fP of an \f2ExecPermission\fP is the path name of a command to grant \f2rmid\fP permission to execute. A path name that ends in "/*" indicates all the files contained in that directory (where "/" is the file\-separator character, \f2File.separatorChar\fP). A path name that ends with "/\-" indicates all files and subdirectories contained in that directory (recursively). A path name consisting of the special token "<<ALL FILES>>" matches \f3any\fP file.
+.LP
+\f3Note:\fP A path name consisting of a single "*" indicates all the files in the current directory, while a path name consisting of a single "\-" indicates all the files in the current directory and (recursively) all files and subdirectories contained in the current directory.
+.TP 3
+ExecOptionPermission
+The \f2ExecOptionPermission\fP class represents permission for \f2rmid\fP to use a specific command\-line \f2option\fP when launching an activation group. The \f2name\fP of an \f2ExecOptionPermission\fP is the value of a command line option.
+.LP
+\f3Syntax\fP
+.br
+Options support a limited wildcard scheme. An asterisk signifies a wildcard match, and it may appear as the option name itself (i.e., it matches any option), or an asterisk may appear at the end of the option name only if the asterisk follows either a "." or "=".
+.LP
+For example: "*" or "\-Dfoo.*" or "\-Da.b.c=*" is valid, "*foo" or "\-Da*b" or "ab*" is not.
+.TP 3
+Policy file for rmid
+When granting \f2rmid\fP permission to execute various commands and options, the permissions \f2ExecPermission\fP and \f2ExecOptionPermission\fP need to be granted universally (i.e., granted to all code sources). It is safe to grant these permissions universally because only \f2rmid\fP checks these permissions.
+.LP
+An example policy file that grants various execute permissions to \f2rmid\fP is:
+.nf
+\f3
+.fl
+grant {
+.fl
+    permission com.sun.rmi.rmid.ExecPermission
+.fl
+        "/files/apps/java/jdk1.7.0/solaris/bin/java";
+.fl
+
+.fl
+    permission com.sun.rmi.rmid.ExecPermission
+.fl
+        "/files/apps/rmidcmds/*";
+.fl
+
+.fl
+    permission com.sun.rmi.rmid.ExecOptionPermission
+.fl
+        "\-Djava.security.policy=/files/policies/group.policy";
+.fl
+
+.fl
+    permission com.sun.rmi.rmid.ExecOptionPermission
+.fl
+        "\-Djava.security.debug=*";
+.fl
+
+.fl
+    permission com.sun.rmi.rmid.ExecOptionPermission
+.fl
+        "\-Dsun.rmi.*";
+.fl
+};
+.fl
+\fP
+.fi
+The first permission granted allow \f2rmid\fP to execute the 1.7.0 version of the \f2java\fP command, specified by its explicit path name. Note that by default, the version of the \f2java\fP command found in \f2java.home\fP is used (the same one that \f2rmid\fP uses), and does not need to be specified in the policy file. The second permission allows \f2rmid\fP to execute any command in the directory \f2/files/apps/rmidcmds\fP.
+.LP
+The third permission granted, an \f2ExecOptionPermission\fP, allows \f2rmid\fP to launch an activation group that defines the security policy file to be \f2/files/policies/group.policy\fP. The next permission allows the \f2java.security.debug\fP property to be used by an activation group. The last permission allows any property in the \f2sun.rmi\fP property name hierarchy to be used by activation groups.
+.LP
+To start \f2rmid\fP with a policy file, the \f2java.security.policy\fP property needs to be specified on \f2rmid\fP's command line, for example:
+.LP
+\f2rmid \-J\-Djava.security.policy=rmid.policy\fP
+.RE
+.TP 2
+o
+\f4<policyClassName>\fP
+.LP
+If the default behavior is not flexible enough, an administrator can provide, when starting \f2rmid\fP, the name of a class whose \f2checkExecCommand\fP method is executed in order to check commands to be executed by rmid.
+.LP
+The \f2policyClassName\fP specifies a public class with a public, no\-argument constructor and an implementation of the following \f2checkExecCommand\fP method:
+.nf
+\f3
+.fl
+    public void checkExecCommand(ActivationGroupDesc desc,
+.fl
+                                 String[] command)
+.fl
+        throws SecurityException;
+.fl
+\fP
+.fi
+Before launching an activation group, \f2rmid\fP calls the policy's \f2checkExecCommand\fP method, passing it the activation group descriptor and an array containing the complete command to launch the activation group. If the \f2checkExecCommand\fP throws a \f2SecurityException\fP, \f2rmid\fP will not launch the activation group and an \f2ActivationException\fP will be thrown to the caller attempting to activate the object.
+.TP 2
+o
+\f3none\fP
+.LP
+If the \f2sun.rmi.activation.execPolicy\fP property value is "none", then \f2rmid\fP will not perform any validation of commands to launch activation groups.
+.RE
+.LP
+.TP 3
+\-log dir
+Specifies the name of the directory the activation system daemon uses to write its database and associated information. The log directory defaults to creating a directory, \f2log\fP, in the directory in which the \f2rmid\fP command was executed.
+.LP
+.TP 3
+\-port port
+Specifies the port \f2rmid\fP's registry uses. The activation system daemon binds the \f2ActivationSystem\fP, with the name \f2java.rmi.activation.ActivationSystem\fP, in this registry. Thus, the \f2ActivationSystem\fP on the local machine can be obtained using the following \f2Naming.lookup\fP method call:
+.nf
+\f3
+.fl
+    import java.rmi.*;
+.fl
+    import java.rmi.activation.*;
+.fl
+
+.fl
+    ActivationSystem system; system = (ActivationSystem)
+.fl
+    Naming.lookup("//:\fP\f4port\fP/java.rmi.activation.ActivationSystem");
+.fl
+.fi
+.TP 3
+\-stop
+Stops the current invocation of \f2rmid\fP, for a port specified by the \f2\-port\fP option. If no port is specified, it will stop the \f2rmid\fP running on port 1098.
+.RE
+
+.LP
+.SH "ENVIRONMENT VARIABLES"
+.LP
+.RS 3
+.TP 3
+CLASSPATH
+Used to provide the system a path to user\-defined classes. Directories are separated by colons. For example:
+.nf
+\f3
+.fl
+    .:/usr/local/java/classes
+.fl
+\fP
+.fi
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+.LP
+rmic(1),
+.na
+\f2CLASSPATH\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/tools/index.html#classpath, java(1)
+.LP
+
diff --git a/jdk/src/bsd/doc/man/rmiregistry.1 b/jdk/src/bsd/doc/man/rmiregistry.1
new file mode 100644
index 0000000..559ab6b
--- /dev/null
+++ b/jdk/src/bsd/doc/man/rmiregistry.1
@@ -0,0 +1,83 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH rmiregistry 1 "10 May 2011"
+
+.LP
+.SH "Name"
+rmiregistry \- The Java Remote Object Registry
+.LP
+.RS 3
+The \f3rmiregistry\fP command starts a remote object registry on the specified port on the current host.
+.RE
+
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+rmiregistry [\fP\f4port\fP\f3]
+.fl
+\fP
+.fi
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f3rmiregistry\fP command creates and starts a remote object registry on the specified \f2port\fP on the current host. If \f2port\fP is omitted, the registry is started on port 1099. The \f3rmiregistry\fP command produces no output and is typically run in the background. For example:
+.LP
+.LP
+\f2rmiregistry &\fP
+.LP
+.LP
+A remote object registry is a bootstrap naming service that is used by RMI servers on the same host to bind remote objects to names. Clients on local and remote hosts can then look up remote objects and make remote method invocations.
+.LP
+.LP
+The registry is typically used to locate the first remote object on which an application needs to invoke methods. That object in turn will provide application\-specific support for finding other objects.
+.LP
+.LP
+The methods of the \f2java.rmi.registry.LocateRegistry\fP class are used to get a registry operating on the local host or local host and port.
+.LP
+.LP
+The URL\-based methods of the \f2java.rmi.Naming\fP class operate on a registry and can be used to look up a remote object on any host, and on the local host: bind a simple (string) name to a remote object, rebind a new name to a remote object (overriding the old binding), unbind a remote object, and list the URLs bound in the registry.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-J
+Used in conjunction with any \f2java\fP option, it passes the option following the \f2\-J\fP (no spaces between the \-J and the option) on to the \f2java\fP interpreter.
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+java(1),
+.na
+\f2java.rmi.registry.LocateRegistry\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/java/rmi/registry/LocateRegistry.html and
+.na
+\f2java.rmi.Naming\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/java/rmi/Naming.html
diff --git a/jdk/src/bsd/doc/man/schemagen.1 b/jdk/src/bsd/doc/man/schemagen.1
new file mode 100644
index 0000000..69cfb8c
--- /dev/null
+++ b/jdk/src/bsd/doc/man/schemagen.1
@@ -0,0 +1,127 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH schemagen 1 "10 May 2011"
+
+.LP
+.SH "Name"
+schemagen \- Java(TM) Architecture for XML Binding Schema Generator
+.LP
+.LP
+\f3Specification Version:\fP 2.1
+.br
+\f3Implementation Version:\fP 2.1.3
+.LP
+.SH "Launching schemagen"
+.LP
+.LP
+The schema generator can be launched using the appropriate \f2schemagen\fP shell script in the \f2bin\fP directory for your platform.
+.LP
+.LP
+The current schema generator can process either Java source files or class files.
+.LP
+.LP
+We also provide an Ant task to run the schema generator \- see the instructions for
+.na
+\f2using schemagen with Ant\fP @
+.fi
+https://jaxb.dev.java.net/nonav/2.1.3/docs/schemagenTask.html.
+.LP
+.nf
+\f3
+.fl
+% schemagen.sh Foo.java Bar.java ...
+.fl
+Note: Writing schema1.xsd
+.fl
+\fP
+.fi
+
+.LP
+.LP
+If your java sources/classes reference other classes, they must be accessable on your system CLASSPATH environment variable, or they need to be given to the tool by using the \f2\-classpath\fP/\f2\-cp\fP options. Otherwise you will see errors when generating your schema.
+.LP
+.SS
+Command Line Options
+.LP
+.nf
+\f3
+.fl
+Usage: schemagen [\-options ...] <java files>
+.fl
+
+.fl
+Options:
+.fl
+    \-d <path>             : specify where to place processor and javac generated class files
+.fl
+    \-cp <path>            : specify where to find user specified files
+.fl
+    \-classpath <path>     : specify where to find user specified files
+.fl
+    \-encoding <encoding>  : specify encoding to be used for apt/javac invocation
+.fl
+
+.fl
+    \-episode <file>       : generate episode file for separate compilation
+.fl
+    \-version              : display version information
+.fl
+    \-help                 : display this usage message
+.fl
+\fP
+.fi
+
+.LP
+.SH "Generated Resource Files"
+.LP
+.LP
+The current schema generator simply creates a schema file for each namespace referenced in your Java classes. There is no way to control the name of the generated schema files at this time. For that purpose, use
+.na
+\f2the schema generator ant task\fP @
+.fi
+https://jaxb.dev.java.net/nonav/2.1.3/docs/schemagenTask.html.
+.LP
+.SH "Name"
+See Also
+.LP
+.RS 3
+.TP 2
+o
+Running the schema generator (schemagen): [
+.na
+\f2command\-line instructions\fP @
+.fi
+https://jaxb.dev.java.net/nonav/2.1.3/docs/schemagen.html,
+.na
+\f2using the SchemaGen Ant task\fP @
+.fi
+https://jaxb.dev.java.net/nonav/2.1.3/docs/schemagenTask.html]
+.TP 2
+o
+.na
+\f2Java Architecture for XML Binding (JAXB)\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/xml/jaxb/index.html
+.RE
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/serialver.1 b/jdk/src/bsd/doc/man/serialver.1
new file mode 100644
index 0000000..b1f9cf2
--- /dev/null
+++ b/jdk/src/bsd/doc/man/serialver.1
@@ -0,0 +1,97 @@
+." Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH serialver 1 "10 May 2011"
+
+.LP
+.SH "Name"
+serialver \- The Serial Version Command
+.LP
+.LP
+The \f3serialver\fP command returns the \f2serialVersionUID\fP.
+.LP
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+\fP\f3serialver\fP [ options ] [ classnames ]
+.fl
+.fi
+
+.LP
+.RS 3
+.TP 3
+options
+Command\-line options, as specified in this document.
+.TP 3
+classnames
+One or more class names
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f3serialver\fP returns the \f2serialVersionUID\fP for one or more classes in a form suitable for copying into an evolving class. When invoked with no arguments it prints a usage line.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-classpath <directories and zip/jar files separated by :>
+Set search path for application classes and resources.
+.RE
+
+.LP
+.RS 3
+.TP 3
+\-show
+Displays a simple user interface. Enter the full class name and press either the Enter key or the Show button to display the serialVersionUID.
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for the java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes.
+.RE
+
+.LP
+.SH "NOTES"
+.LP
+.LP
+The \f3serialver\fP command loads and initializes the specified classes in its virtual machine, and by default, it does not set a security manager. If \f3serialver\fP is to be run with untrusted classes, a security manager can be set with the following option:
+.LP
+.LP
+\f2\-J\-Djava.security.manager\fP
+.LP
+.LP
+and, if necessary, a security policy can be specified with the following option:
+.LP
+.LP
+\f2\-J\-Djava.security.policy=<policy file>\fP
+.LP
+.SH "SEE ALSO"
+.LP
+.LP
+.na
+\f2java.io.ObjectStreamClass\fP @
+.fi
+http://download.oracle.com/javase/7/docs/api/java/io/ObjectStreamClass.html
+.LP
+
diff --git a/jdk/src/bsd/doc/man/servertool.1 b/jdk/src/bsd/doc/man/servertool.1
new file mode 100644
index 0000000..a0ae4ac
--- /dev/null
+++ b/jdk/src/bsd/doc/man/servertool.1
@@ -0,0 +1,113 @@
+." Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH servertool 1 "10 May 2011"
+
+.LP
+.SH "Name"
+servertool \- The Java(TM) IDL Server Tool
+.LP
+\f3servertool\fP provides a command\-line interface for application programmers to register, unregister, startup, and shutdown a persistent server.
+.SH "SYNOPSIS"
+.LP
+.nf
+\f3
+.fl
+servertool \-ORBInitialPort \fP\f4nameserverport\fP\f3 \fP\f3options\fP\f3 [ \fP\f3commands\fP\f3 ]
+.fl
+\fP
+.fi
+
+.LP
+.LP
+If you did not enter a command when starting \f2servertool\fP, the command\-line tool displays with a \f2servertool >\fP prompt. Enter commands at the \f2servertool >\fP prompt.
+.LP
+.LP
+If you enter a command when starting \f2servertool\fP, the Java IDL Server Tool starts, runs the command, and exits.
+.LP
+.LP
+The \f2\-ORBInitialPort\fP \f2nameserverport\fP option is \f3required\fP. The value for \f2nameserverport\fP must specify the port on which \f2orbd\fP is running and listening for incoming requests. When using Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024 for the \f2nameserverport\fP.
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+The \f2servertool\fP provides the command\-line interface for the application programmers to register, unregister, startup, and shutdown a persistent server. Other commands are provided to obtain various statistical information about the server.
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-ORBInitialHost nameserverhost
+Specifies the host machine on which the name server is running and listening for incoming requests. The \f2nameserverhost\fP defaults to \f2localhost\fP if this option is not specified. If \f2orbd\fP and \f2servertool\fP are running on different machines, you must specify the name or IP address of the host on which \f2orbd\fP is running.
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. It is a common convention for \f3\-J\fP to pass options to the underlying virtual machine.
+.RE
+
+.LP
+.SH "COMMANDS"
+.LP
+.RS 3
+.TP 3
+register \-server\ <server\ class\ name> \ \-classpath\ <classpath\ to\ server> [\ \-applicationName\ <application\ name> \-args\ <args\ to\ server> \-vmargs\ <flags\ to\ be\ passed\ to\ Java\ VM> \ ]
+Register a new persistent server with the Object Request Broker Daemon (ORBD). If the server is not already registered, it is registered and activated. This command causes an install method to be invoked in the main class of the server identified by the \f2\-server\fP option. The install method must be \f2public static void install(org.omg.CORBA.ORB)\fP. The install method is optional and enables the developer to provide their own server installation behavior (for example, creating database schema).
+.TP 3
+unregister \-serverid\ <server\ id\ >\ | \-applicationName\ <application\ name>
+Unregister a server from the ORBD by using either its server id or its application name. This command causes an uninstall method to be invoked in the main class of the server identified by the \f2\-server\fP option. The uninstall method must be \f2public static void uninstall(org.omg.CORBA.ORB)\fP. The uninstall method is optional and enables the developer to provide their own server uninstall behavior (for example, undoing the behavior of the install method).
+.TP 3
+getserverid \-applicationName\ <application\ name>
+Return the server id that corresponds with an application.
+.TP 3
+list
+List information about all persistent servers registered with the ORBD.
+.TP 3
+listappnames
+List the application names for all servers currently registered with the ORBD.
+.TP 3
+listactive
+List information about all persistent servers that have been launched by the ORBD and are currently running.
+.TP 3
+locate \-serverid\ <server\ id\ >\ | \-applicationName\ <application\ name> [\-endpointType\ <endpointType>\ ]
+Locate the endpoints (ports) of a specific type for all ORBs created by a registered server. If a server is not already running, it is activated. If an endpoint type is not specified, then the plain/non\-protected endpoint associated with each ORB in a server is returned.
+.TP 3
+locateperorb \-serverid\ <server\ id\ >\ | \-applicationName\ <application\ name> [\-orbid\ <ORB\ name>\ ]
+Locate all the endpoints (ports) registered by a specific ORB of registered server. If a server is not already running, then it is activated. If an \f2orbid\fP is not specified, the default value of "" is assigned to the \f2orbid\fP. If any ORBs are created with an \f2orbid\fP of empty string, all ports registered by it are returned.
+.TP 3
+orblist \-serverid\ <server\ id\ >\ | \-applicationName\ <application\ name>
+Lists the ORBId of the ORBs defined on a server. An ORBId is the string name for the ORB created by the server. If the server is not already running, it is activated.
+.TP 3
+shutdown \-serverid\ <server\ id\ >\ | \-applicationName\ <application\ name>
+Shutdown an active server that is registered with ORBD. During execution of this command, the \f2shutdown()\fP method defined in the class specified by either the \f2\-serverid\fP or \f2\-applicationName\fP parameter is also invoked to shutdown the server process appropriately.
+.TP 3
+startup \-serverid\ <server\ id\ >\ | \-applicationName\ <application\ name>
+Startup or activate a server that is registered with ORBD. If the server is not running, this command launches the server. If the server is already running, an error message is returned to the user.
+.TP 3
+help
+List all the commands available to the server through the server tool.
+.TP 3
+quit
+Exit the server tool.
+.RE
+
+.LP
+.SH "SEE ALSO"
+.LP
+orbd(1)
diff --git a/jdk/src/bsd/doc/man/tnameserv.1 b/jdk/src/bsd/doc/man/tnameserv.1
new file mode 100644
index 0000000..1b378ea
--- /dev/null
+++ b/jdk/src/bsd/doc/man/tnameserv.1
@@ -0,0 +1,494 @@
+." Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH tnameserv 1 "10 May 2011"
+
+.LP
+.SH "Name"
+Java IDL: Transient Naming Service \- \f2tnameserv\fP
+.LP
+.LP
+This document discusses using the Java IDL Transient Naming Service, \f2tnameserv\fP. Java IDL also includes the Object Request Broker Daemon (ORBD). ORBD is a daemon process containing a Bootstrap Service, a Transient Naming Service, a \f3Persistent\fP Naming Service, and a Server Manager. The Java IDL tutorials all use ORBD, however, you can substitute \f2tnameserv\fP for \f2orbd\fP in any of the examples that use a Transient Naming Service. For documentation on the \f2orbd\fP tool, link to its orbd(1) or the
+.na
+\f2Java IDL Naming Service Included with ORBD\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html topic.
+.LP
+.LP
+Topics in this section include:
+.LP
+.RS 3
+.TP 2
+o
+Java\ IDL Transient Naming Service
+.TP 2
+o
+Starting the Java\ IDL Transient Naming Service
+.TP 2
+o
+Stopping the Java\ IDL Transient Naming Service
+.TP 2
+o
+Sample Client: Adding Objects to the Namespace
+.TP 2
+o
+Sample Client: Browsing the Namespace
+.RE
+
+.LP
+.SH "Java\ IDL Transient Naming Service"
+.LP
+.LP
+The CORBA COS (Common Object Services) Naming Service provides a tree\-like directory for object references much like a filesystem provides a directory structure for files. The Transient Naming Service provided with Java IDL, \f2tnameserv\fP, is a simple implementation of the COS Naming Service specification.
+.LP
+.LP
+Object references are stored in the namespace by name and each object reference\-name pair is called a name \f2binding\fP. Name bindings may be organized under \f2naming contexts\fP. Naming contexts are themselves name bindings and serve the same organizational function as a file system subdirectory. All bindings are stored under the \f2initial naming context\fP. The initial naming context is the only persistent binding in the namespace; the rest of the namespace is lost if the Java IDL naming service process halts and restarts.
+.LP
+.LP
+For an applet or application to use COS naming, its ORB must know the port of a host running a naming service or have access to a stringified initial naming context for that naming service. The naming service can either be the Java\ IDL naming service or another COS\-compliant naming service.
+.LP
+.SH "Starting the Java\ IDL Transient Naming Service"
+.LP
+.LP
+You must start the Java\ IDL naming service before an application or applet that uses its naming service. Installation of the Java\ IDL product creates a script (Solaris: \f2tnameserv\fP) or executable file (Windows NT: \f2tnameserv.exe\fP) that starts the Java\ IDL naming service. Start the naming service so it runs in the background.
+.LP
+.LP
+If you do not specify otherwise, the Java\ IDL naming service listens on port 900 for the bootstrap protocol used to implement the ORB \f2resolve_initial_references()\fP and \f2list_initial_references()\fP methods, as follows:
+.LP
+.nf
+\f3
+.fl
+        tnameserv \-ORBInitialPort \fP\f4nameserverport\fP\f3&
+.fl
+\fP
+.fi
+
+.LP
+.LP
+If you do not specify the name server port, port 900 is used by default. When running Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024. To specify a different port, for example, 1050, and to run the naming service in the background, from a UNIX command shell, enter:
+.LP
+.nf
+\f3
+.fl
+        tnameserv \-ORBInitialPort 1050&
+.fl
+\fP
+.fi
+
+.LP
+.LP
+From an MS\-DOS system prompt (Windows), enter:
+.LP
+.nf
+\f3
+.fl
+        start tnameserv \-ORBInitialPort 1050
+.fl
+\fP
+.fi
+
+.LP
+.LP
+Clients of the name server must be made aware of the new port number. Do this by setting the \f2org.omg.CORBA.ORBInitialPort\fP property to the new port number when creating the ORB object.
+.LP
+.SS
+Running the server and client on different hosts
+.LP
+.LP
+In most of the Java IDL and RMI\-IIOP tutorials, the Naming Service, Server, and Client are all running on the development machine. In real world deployment, it is likely that the client and server will run on different host machines than the Naming Service.
+.LP
+.LP
+For the client and server to find the Naming Service, they must be made aware of the port number and host on which the naming service is running. Do this by setting the \f2org.omg.CORBA.ORBInitialPort\fP and \f2org.omg.CORBA.ORBInitialHost\fP properties in the client and server files to the machine name and port number on which the Naming Service is running. An example of this is shown in
+.na
+\f2The Hello World Example Using RMI\-IIOP\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/rmi\-iiop/rmiiiopexample.html. You could also use the command line options \f2\-ORBInitialPort\fP \f2nameserverport#\fP and \f2\-ORBInitialHost\fP \f2nameserverhostname\fP to tell the client and server where to find the Naming Service.
+.na
+\f2Java IDL: Running the Hello World Example on TWO Machines\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/idl/tutorial/jidl2machines.html shows one way of doing this using the command line option.
+.LP
+.LP
+For example, suppose the Transient Naming Service, \f2tnameserv\fP is running on port 1050 on host \f2nameserverhost\fP. The client is running on host \f2clienthost\fP and the server is running on host \f2serverhost\fP.
+.LP
+.RS 3
+.TP 2
+o
+Start \f2tnameserv\fP on the host \f2nameserverhost\fP, as follows:
+.nf
+\f3
+.fl
+     tnameserv \-ORBInitialPort 1050
+.fl
+
+.fl
+\fP
+.fi
+.TP 2
+o
+Start the server on the \f2serverhost\fP, as follows:
+.nf
+\f3
+.fl
+     java Server \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
+.fl
+\fP
+.fi
+.TP 2
+o
+Start the client on the \f2clienthost\fP, as follows:
+.nf
+\f3
+.fl
+     java Client \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
+.fl
+\fP
+.fi
+.RE
+
+.LP
+.SS
+The \-J option
+.LP
+This command\-line option is available for use with \f2tnameserve\fP:
+.RS 3
+.TP 3
+\-Joption
+Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. It is a common convention for \f3\-J\fP to pass options to the underlying virtual machine.
+.RE
+
+.LP
+.SH "Stopping the Java\ IDL Transient Naming Service"
+.LP
+.LP
+To stop the Java\ IDL naming service, use the relevant operating system command, such as \f2kill\fP for a Unix process, or \f2Ctrl\-C\fP for a Windows process. The naming service will continue to wait for invocations until it is explicitly shutdown. Note that names registered with the Java\ IDL naming service disappear when the service is terminated.
+.LP
+.SH "Sample Client: Adding Objects to the Namespace"
+.LP
+.LP
+The following sample program illustrates how to add names to the namespace. It is a self\-contained Transient Naming Service client that creates the following simple tree.
+.LP
+.RS 3
+.TP 2
+o
+\f4Initial Naming Context\fP
+.RS 3
+.TP 2
+*
+\f3plans\fP
+.TP 2
+*
+\f4Personal\fP
+.RS 3
+.TP 2
+-
+\f3calendar\fP
+.TP 2
+-
+\f3schedule\fP
+.RE
+.RE
+.RE
+
+.LP
+.LP
+In this example, \f3plans\fP is an object reference and \f3Personal\fP is a naming context that contains two object references: \f3calendar\fP and \f3schedule\fP.
+.LP
+.nf
+\f3
+.fl
+import java.util.Properties;
+.fl
+import org.omg.CORBA.*;
+.fl
+import org.omg.CosNaming.*;
+.fl
+
+.fl
+public class NameClient
+.fl
+{
+.fl
+   public static void main(String args[])
+.fl
+   {
+.fl
+      try {
+.fl
+\fP
+.fi
+
+.LP
+In the above section, Starting the Java IDL Transient Naming Service, the nameserver was started on port 1050. The following code ensures that the client program is aware of this port number.
+.nf
+\f3
+.fl
+        Properties props = new Properties();
+.fl
+        props.put("org.omg.CORBA.ORBInitialPort", "1050");
+.fl
+        ORB orb = ORB.init(args, props);
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+This code obtains the initial naming context and assigns it to \f3ctx\fP. The second line copies \f3ctx\fP into a dummy object reference \f3objref\fP that we'll attach to various names and add into the namespace.
+.nf
+\f3
+.fl
+        NamingContext ctx =
+.fl
+NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
+.fl
+        NamingContext objref = ctx;
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+This code creates a name "plans" of type "text" and binds it to our dummy object reference. "plans" is then added under the initial naming context using \f2rebind\fP. The \f2rebind\fP method allows us to run this program over and over again without getting the exceptions we'd get from using \f2bind\fP.
+.nf
+\f3
+.fl
+        NameComponent nc1 = new NameComponent("plans", "text");
+.fl
+        NameComponent[] name1 = {nc1};
+.fl
+        ctx.rebind(name1, objref);
+.fl
+        System.out.println("plans rebind sucessful!");
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+This code creates a naming context called "Personal" of type "directory". The resulting object reference, \f3ctx2\fP, is bound to the name and added under the initial naming context.
+.nf
+\f3
+.fl
+        NameComponent nc2 = new NameComponent("Personal", "directory");
+.fl
+        NameComponent[] name2 = {nc2};
+.fl
+        NamingContext ctx2 = ctx.bind_new_context(name2);
+.fl
+        System.out.println("new naming context added..");
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+The remainder of the code binds the dummy object reference using the names "schedule" and "calendar" under the "Personal" naming context (\f3ctx2\fP).
+.nf
+\f3
+.fl
+        NameComponent nc3 = new NameComponent("schedule", "text");
+.fl
+        NameComponent[] name3 = {nc3};
+.fl
+        ctx2.rebind(name3, objref);
+.fl
+        System.out.println("schedule rebind sucessful!");
+.fl
+
+.fl
+        NameComponent nc4 = new NameComponent("calender", "text");
+.fl
+        NameComponent[] name4 = {nc4};
+.fl
+        ctx2.rebind(name4, objref);
+.fl
+        System.out.println("calender rebind sucessful!");
+.fl
+
+.fl
+
+.fl
+    } catch (Exception e) {
+.fl
+        e.printStackTrace(System.err);
+.fl
+    }
+.fl
+  }
+.fl
+}
+.fl
+\fP
+.fi
+
+.LP
+.SH "Sample Client: Browsing the Namespace"
+.LP
+.LP
+The following sample program illustrates how to browse the namespace.
+.LP
+.nf
+\f3
+.fl
+import java.util.Properties;
+.fl
+import org.omg.CORBA.*;
+.fl
+import org.omg.CosNaming.*;
+.fl
+
+.fl
+public class NameClientList
+.fl
+{
+.fl
+   public static void main(String args[])
+.fl
+   {
+.fl
+      try {
+.fl
+\fP
+.fi
+
+.LP
+In the above section, Starting the Java IDL Transient Naming Service, the nameserver was started on port 1050. The following code ensures that the client program is aware of this port number.
+.nf
+\f3
+.fl
+
+.fl
+        Properties props = new Properties();
+.fl
+        props.put("org.omg.CORBA.ORBInitialPort", "1050");
+.fl
+        ORB orb = ORB.init(args, props);
+.fl
+
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+The following code obtains the intial naming context.
+.nf
+\f3
+.fl
+        NamingContext nc =
+.fl
+NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+The \f2list\fP method lists the bindings in the naming context. In this case, up to 1000 bindings from the initial naming context will be returned in the BindingListHolder; any remaining bindings are returned in the BindingIteratorHolder.
+.nf
+\f3
+.fl
+        BindingListHolder bl = new BindingListHolder();
+.fl
+        BindingIteratorHolder blIt= new BindingIteratorHolder();
+.fl
+        nc.list(1000, bl, blIt);
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+This code gets the array of bindings out of the returned BindingListHolder. If there are no bindings, the program ends.
+.nf
+\f3
+.fl
+        Binding bindings[] = bl.value;
+.fl
+        if (bindings.length == 0) return;
+.fl
+
+.fl
+\fP
+.fi
+
+.LP
+The remainder of the code loops through the bindings and prints the names out.
+.nf
+\f3
+.fl
+        for (int i=0; i < bindings.length; i++) {
+.fl
+
+.fl
+            // get the object reference for each binding
+.fl
+            org.omg.CORBA.Object obj = nc.resolve(bindings[i].binding_name);
+.fl
+            String objStr = orb.object_to_string(obj);
+.fl
+            int lastIx = bindings[i].binding_name.length\-1;
+.fl
+
+.fl
+            // check to see if this is a naming context
+.fl
+            if (bindings[i].binding_type == BindingType.ncontext) {
+.fl
+              System.out.println( "Context: " +
+.fl
+bindings[i].binding_name[lastIx].id);
+.fl
+            } else {
+.fl
+                System.out.println("Object: " +
+.fl
+bindings[i].binding_name[lastIx].id);
+.fl
+            }
+.fl
+        }
+.fl
+
+.fl
+       } catch (Exception e) {
+.fl
+        e.printStackTrace(System.err);
+.fl
+       }
+.fl
+   }
+.fl
+}
+.fl
+\fP
+.fi
+
+.LP
+
diff --git a/jdk/src/bsd/doc/man/unpack200.1 b/jdk/src/bsd/doc/man/unpack200.1
new file mode 100644
index 0000000..53dd6a6
--- /dev/null
+++ b/jdk/src/bsd/doc/man/unpack200.1
@@ -0,0 +1,156 @@
+." Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH unpack200 1 "10 May 2011"
+
+.LP
+.SH "Name"
+unpack200 \- JAR Unpacking tool
+.LP
+.SH "SYNOPSIS"
+.LP
+.LP
+\f4unpack200\fP\f2 [ \fP\f2options\fP ] \f2input\-file\fP \f2JAR\-file\fP
+.LP
+.LP
+Options may be in any order. The last option on the command line supersedes all previously specified options.
+.LP
+.RS 3
+.TP 3
+input\-file
+Name of the input file, which can be a pack200 gzip file or a pack200 file. The input could also be JAR file produced by pack200(1) with an effort of 0. In this case the contents of the input file will be copied to the output JAR file with the Pack200 marker.
+.TP 3
+JAR\-file
+Name of the output JAR file.
+.RE
+
+.LP
+.SH "DESCRIPTION"
+.LP
+.LP
+\f2unpack200\fP is a native implementation that transforms a packed file produced by \f2pack200\fP(1) into a JAR file. Typical usage:
+.LP
+.LP
+\f2% unpack200 myarchive.pack.gz myarchive.jar\fP
+.LP
+.LP
+In this example, the \f2myarchive.jar\fP is produced from \f2myarchive.pack.gz\fP using the default \f2unpack200\fP settings.
+.LP
+.SH "OPTIONS"
+.LP
+.LP
+\f4\-Hvalue \-\-deflate\-hint=\fP\f2value\fP
+.LP
+.LP
+Sets the deflation to be \f2true\fP, \f2false\fP, or \f2keep\fP on all entries within a JAR file. The default mode is \f2keep\fP. If \f2true\fP or \f2false\fP, overrides the default behavior and sets the deflation mode on all entries within the output JAR file.
+.LP
+.LP
+\f4\-r \-\-remove\-pack\-file\fP
+.LP
+.LP
+Removes the input packed file.
+.LP
+.LP
+\f4\-v \-\-verbose\fP
+.LP
+.LP
+Outputs minimal messages. Multiple specification of this option will output more verbose messages.
+.LP
+.LP
+\f4\-q \-\-quiet\fP
+.LP
+.LP
+Specifies quiet operation with no messages.
+.LP
+.LP
+\f4\-lfilename \-\-log\-file=\fP\f2filename\fP
+.LP
+.LP
+Specifies a log file to output messages.
+.LP
+.LP
+\f4\-? \-h \-\-help\fP
+.LP
+.LP
+Prints help information about this command.
+.LP
+.LP
+\f4\-V \-\-version\fP
+.LP
+.LP
+Prints version information about this command.
+.LP
+.LP
+\f4\-J\fP\f2option\fP
+.LP
+.LP
+Passes \f2option\fP to the Java launcher called by \f2unpack200\fP.
+.LP
+.SH "EXIT STATUS"
+.LP
+.LP
+The following exit values are returned:
+.LP
+.LP
+\f2\ 0\fP if successful completion;
+.LP
+.LP
+\f2>0\fP if an error occurred.
+.LP
+.SH "SEE ALSO"
+.LP
+.RS 3
+.TP 2
+o
+pack200(1)
+.TP 2
+o
+.na
+\f2Java SE Documentation\fP @
+.fi
+http://download.oracle.com/javase/7/docs/index.html
+.TP 2
+o
+.na
+\f2Java Deployment Guide \- Pack200\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/deployment/deployment\-guide/pack200.html
+.TP 2
+o
+jar(1) \- Java Archive Tool
+.TP 2
+o
+jarsigner(1) \- JAR Signer tool
+.TP 2
+o
+\f2attributes(5)\fP man page
+.RE
+
+.LP
+.SH "NOTES"
+.LP
+.LP
+This command should not be confused with \f2unpack(1)\fP. They are distinctly separate products.
+.LP
+.LP
+The Java SE API Specification provided with the JDK is the superseding authority, in case of discrepancies.
+.LP
+
diff --git a/jdk/src/bsd/doc/man/wsgen.1 b/jdk/src/bsd/doc/man/wsgen.1
new file mode 100644
index 0000000..07ffe43
--- /dev/null
+++ b/jdk/src/bsd/doc/man/wsgen.1
@@ -0,0 +1,596 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH wsgen 1 "10 May 2011"
+.SH "Name"
+wsgen \- Java(TM) API for XML Web Services (JAX\-WS) 2.0
+.LP
+\f3Specification Version:\fP 2.1
+.br
+\f3Implementation Version:\fP 2.1.1
+.LP
+The \f2wsgen\fP tool generates JAX\-WS portable artifacts used in JAX\-WS web services. The tool reads a web service endpoint implementation class (SEI) and generates all the required artifacts for web service deployment, and invocation
+.SH "Overview"
+.LP
+The \f2wsgen\fP tool generates JAX\-WS portable artifacts used in JAX\-WS web services. The tool reads a web service endpoint class and generates all the required artifacts for web service deployment, and invocation. JAXWS 2.1.1 RI also provides a wsgen ant task, see
+.na
+\f2Wsgen ant task\fP @
+.fi
+https://jax\-ws.dev.java.net/nonav/2.1.1/docs/wsgenant.html for details.
+.LP
+.SH "Launching wsgen"
+.RS 3
+.TP 2
+o
+\f3Solaris/Bsd\fP
+.RS 3
+.TP 2
+*
+\f2export JAXWS_HOME=/pathto/jaxws\-ri\fP
+.TP 2
+*
+\f2$JAXWS_HOME/bin/wsgen.sh \-help\fP
+.RE
+.TP 2
+o
+\f3Windows\fP
+.RS 3
+.TP 2
+*
+\f2set JAXWS_HOME=c:\\pathto\\jaxws\-ri\fP
+.TP 2
+*
+\f2%JAXWS_HOME%\\bin\\wsgen.bat \-help\fP
+.RE
+.RE
+
+.LP
+.SH "Syntax"
+.nf
+\f3
+.fl
+wsgen [options] <SEI>\fP
+.br
+\f3
+.fl
+\fP
+.fi
+.LP
+The following table lists the \f2wsgen\fP options.
+.br
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify where to find input class files
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Same as \f2\-classpath <path>\fP
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify where to place generated output files
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+allow vendor extensions (functionality not specified by the specification). Use of extensions may result in applications that are not portable or may not interoperate with other implementations
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Used only in conjunction with the \-wsdl option. Specify where to place generated resource files such as WSDLs
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify where to place generated source files
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Output messages about what the compiler is doing
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Print version information. Use of this option will ONLY print version information. Normal processing will not occur.
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+By default \f2wsgen\fP does not generate a WSDL file. This flag is optional and will cause \f2wsgen\fP to generate a WSDL file and is usually only used so that the developer can look at the WSDL before the endpoint is deploy. The \f2protocol\fP is optional and is used to specify what protocol should be used in the \f2wsdl:binding\fP. Valid protocols include: \f2soap1.1\fP and \f2Xsoap1.2\fP. The default is \f2soap1.1\fP. \f2Xsoap1.2\fP is not standard and can only be used in conjunction with the \f2\-extension\fP option.
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Used only in conjunction with the \f2\-wsdl\fP option. Used to specify a particular \f2wsdl:service\fP name to be generated in the WSDL. Example, \f2\-servicename "{http://mynamespace/}MyService"\fP
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di k+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Used only in conjunction with the \f2\-wsdl\fP option. Used to specify a particular \f2wsdl:port\fP name to be generated in the WSDL. Example, \f2\-portname "{http://mynamespace/}MyPort"\fP
+.br
+.br
+.di
+.nr k| \n(dn
+.nr k- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \w\f3Option\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-classpath <path>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-cp <path>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-d <directory>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-extension\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-help\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-keep\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-r <directory>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-s <directory>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-verbose\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-version\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-wsdl[:protocol]\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-servicename <name>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f4\-portname <name>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wDisplay help
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wKeep generated files
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(k-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 133 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Option\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-classpath <path>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-cp <path>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-d <directory>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-extension\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-help\fP\h'|\n(41u'Display help
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-keep\fP\h'|\n(41u'Keep generated files
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-r <directory>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-s <directory>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(g|u+\n(.Vu
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-verbose\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-version\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-wsdl[:protocol]\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(j|u+\n(.Vu
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-servicename <name>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(k|u+\n(.Vu
+.if (\n(k|+\n(#^-1v)>\n(#- .nr #- +(\n(k|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f4\-portname <name>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.k+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.rm k+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-53
+
+.LP
+.SH "Example"
+.nf
+\f3
+.fl
+\fP\f3wsgen \-d stock \-cp myclasspath stock.StockService\fP
+.fl
+.fi
+.LP
+This will generate the wrapper classes needed for StockService annotated with @WebService annotation inside \f3stock\fPdirectory.
+.nf
+\f3
+.fl
+\fP\f3wsgen \-wsdl \-d stock \-cp myclasspath stock.StockService\fP
+.fl
+.fi
+.LP
+This will generate a SOAP 1.1 WSDL and schema for your Java class stock.StockService annotated with @WebService annotation.
+.nf
+\f3
+.fl
+\fP\f3wsgen \-wsdl:Xsoap1.2 \-d stock \-cp myclasspath stock.StockService\fP
+.fl
+.fi
+.LP
+Will generate a SOAP 1.2 WSDL.
+.LP
+Note that you do not have to generate WSDL at the development time as JAXWS runtime will automatically generate a WSDL for you when you deploy your service.
diff --git a/jdk/src/bsd/doc/man/wsimport.1 b/jdk/src/bsd/doc/man/wsimport.1
new file mode 100644
index 0000000..92f8002
--- /dev/null
+++ b/jdk/src/bsd/doc/man/wsimport.1
@@ -0,0 +1,975 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH wsimport 1 "10 May 2011"
+.SH "Name"
+wsimport \- Java(TM) API for XML Web Services (JAX\-WS) 2.0
+.LP
+\f3Specification Version:\fP 2.1
+.br
+\f3Implementation Version:\fP 2.1.1
+.br
+.SH "Overview"
+.LP
+The \f2wsimport\fP tool generates JAX\-WS portable artifacts, such as:
+.RS 3
+.TP 2
+o
+Service Endpoint Interface (SEI)
+.TP 2
+o
+Service
+.TP 2
+o
+Exception class mapped from wsdl:fault (if any)
+.TP 2
+o
+Async Reponse Bean derived from response wsdl:message (if any)
+.TP 2
+o
+JAXB generated value types (mapped java classes from schema types)
+.RE
+.LP
+These artifacts can be packaged in a WAR file with the WSDL and schema documents along with the endpoint implementation to be deployed. also provides wsimport ant task, see
+.na
+\f2Wsimport ant task\fP @
+.fi
+https://jax\-ws.dev.java.net/nonav/2.1.1/docs/wsimportant.html.
+.br
+
+.LP
+.SH "Launching wsimport"
+.RS 3
+.TP 2
+o
+\f3Solaris/Bsd\fP
+.RS 3
+.TP 2
+*
+\f2/bin/wsimport.sh \-help\fP
+.RE
+.TP 2
+o
+\f3Windows\fP
+.RS 3
+.TP 2
+*
+\f2\\bin\\wsimport.bat \-help\fP
+.RE
+.RE
+
+.LP
+.SH "Syntax"
+.nf
+\f3
+.fl
+wsimport [options] <wsdl>
+.fl
+\fP
+.fi
+.LP
+The following table lists the \f2wsimport\fP options.
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify where to place generated output files
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify external JAX\-WS or JAXB binding files (Each \f2<file>\fP must have its own \f2\-b\fP)
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Pass this option to JAXB schema compiler
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify catalog file to resolve external entity references, it supports TR9401, XCatalog, and OASIS XML Catalog format. Please read the documentation of
+.na
+\f2catalog\fP @
+.fi
+https://jax\-ws.dev.java.net/nonav/2.1.1/docs/catalog\-support.html and see \f3catalog\fP sample.
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Allow vendor extensions (functionality not specified by the specification). Use of extensions may result in applications that are not portable or may not interoperate with other implementations
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f3\-httpproxy:<host>:<port> \fP
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di g+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify an HTTP proxy server (port defaults to 8080)
+.br
+.di
+.nr g| \n(dn
+.nr g- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di h+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specifying a target package via this command\-line option, overrides any wsdl and schema binding customization for package name and the default package name algorithm defined in the specification
+.br
+.di
+.nr h| \n(dn
+.nr h- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di i+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Specify where to place generated source files
+.br
+.di
+.nr i| \n(dn
+.nr i- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di j+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Output messages about what the compiler is doing
+.br
+.di
+.nr j| \n(dn
+.nr j- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di k+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Print version information
+.br
+.di
+.nr k| \n(dn
+.nr k- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di l+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f3\-wsdllocation <location>\fP
+.br
+.di
+.nr l| \n(dn
+.nr l- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di m+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+\f2@WebServiceClient.wsdlLocation\fP value
+.br
+.di
+.nr m| \n(dn
+.nr m- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di n+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Generate code as per the given JAX\-WS specification version. version 2.0 will generate compliant code for JAX\-WS 2.0 spec.
+.br
+.di
+.nr n| \n(dn
+.nr n- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \w\f3Option\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-d <directory> \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-b <path> \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-B <jaxbOption>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-catalog\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-extension \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-help \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-keep \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-p \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-s <directory> \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-verbose \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-version \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-target \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-quiet \fP
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 38 \n(f-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \n(l-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wDisplay help
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wKeep generated files
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \wSuppress wsimport output
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(d-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(g-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(h-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(i-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(j-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(k-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(m-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(n-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 157 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Option\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-d <directory> \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-b <path> \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-B <jaxbOption>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-catalog\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(e|u+\n(.Vu
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-extension \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-help \fP\h'|\n(41u'Display help
+.ne \n(f|u+\n(.Vu
+.ne \n(g|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.if (\n(g|+\n(#^-1v)>\n(#- .nr #- +(\n(g|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.g+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-keep \fP\h'|\n(41u'Keep generated files
+.ne \n(h|u+\n(.Vu
+.if (\n(h|+\n(#^-1v)>\n(#- .nr #- +(\n(h|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-p \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.h+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(i|u+\n(.Vu
+.if (\n(i|+\n(#^-1v)>\n(#- .nr #- +(\n(i|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-s <directory> \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.i+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(j|u+\n(.Vu
+.if (\n(j|+\n(#^-1v)>\n(#- .nr #- +(\n(j|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-verbose \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.j+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(k|u+\n(.Vu
+.if (\n(k|+\n(#^-1v)>\n(#- .nr #- +(\n(k|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-version \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.k+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(l|u+\n(.Vu
+.ne \n(m|u+\n(.Vu
+.if (\n(l|+\n(#^-1v)>\n(#- .nr #- +(\n(l|+\n(#^-\n(#--1v)
+.if (\n(m|+\n(#^-1v)>\n(#- .nr #- +(\n(m|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.l+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.m+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(n|u+\n(.Vu
+.if (\n(n|+\n(#^-1v)>\n(#- .nr #- +(\n(n|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-target \fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.n+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-quiet \fP\h'|\n(41u'Suppress wsimport output
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.rm g+
+.rm h+
+.rm i+
+.rm j+
+.rm k+
+.rm l+
+.rm m+
+.rm n+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-66
+.LP
+Multiple JAX\-WS and JAXB binding files can be specified using \f2\-b\fP option and they can be used to customize various things like package names, bean names, etc. More information on JAX\-WS and JAXB binding files can be found in the
+.na
+\f2customization documentation\fP @
+.fi
+https://jax\-ws.dev.java.net/nonav/2.1.1/docs/customizations.html.
+.LP
+The following table lists \f2wsimport\fP non\-standard options:
+.LP
+.if \n+(b.=1 .nr d. \n(.c-\n(c.-1
+.de 35
+.ps \n(.s
+.vs \n(.vu
+.in \n(.iu
+.if \n(.u .fi
+.if \n(.j .ad
+.if \n(.j=0 .na
+..
+.nf
+.nr #~ 0
+.if n .nr #~ 0.6n
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.fc
+.nr 33 \n(.s
+.rm 80 81
+.nr 34 \n(.lu
+.eo
+.am 81
+.br
+.di a+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Map headers not bound to request or response message to Java method parameters.
+.br
+.di
+.nr a| \n(dn
+.nr a- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di b+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+WSDL URI that specifies the file that contains authorization information; this URI is in the following format: http://\f2<user name>\fP:\f2<password>\fP@\f2<host name>\fP/\f2<Web service name>\fP?wsdl
+.br
+.di
+.nr b| \n(dn
+.nr b- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di c+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Print debugging information.
+.br
+.di
+.nr c| \n(dn
+.nr c- \n(dl
+..
+.ec \
+.eo
+.am 80
+.br
+.di d+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(80 .ll \n(80u
+.in 0
+\f3\-Xno\-addressing\-databinding\fP
+.br
+.di
+.nr d| \n(dn
+.nr d- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di e+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Enable binding of W3C \f2EndpointReferenceType\fP to Java.
+.br
+.di
+.nr e| \n(dn
+.nr e- \n(dl
+..
+.ec \
+.eo
+.am 81
+.br
+.di f+
+.35
+.ft \n(.f
+.ll \n(34u*1u/3u
+.if \n(.l<\n(81 .ll \n(81u
+.in 0
+Do not compile generated Java files.
+.br
+.di
+.nr f| \n(dn
+.nr f- \n(dl
+..
+.ec \
+.35
+.nf
+.ll \n(34u
+.nr 80 0
+.nr 38 \w\f3Option\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-XadditionalHeaders\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-Xauthfile <file>\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-Xdebug\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 38 \w\f3\-Xnocompile\fP
+.if \n(80<\n(38 .nr 80 \n(38
+.80
+.rm 80
+.nr 38 \n(d-
+.if \n(80<\n(38 .nr 80 \n(38
+.nr 81 0
+.nr 38 \w\f3Description\fP
+.if \n(81<\n(38 .nr 81 \n(38
+.81
+.rm 81
+.nr 38 \n(a-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(b-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(c-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(e-
+.if \n(81<\n(38 .nr 81 \n(38
+.nr 38 \n(f-
+.if \n(81<\n(38 .nr 81 \n(38
+.35
+.nf
+.ll \n(34u
+.nr 38 1n
+.nr 79 0
+.nr 40 \n(79+(0*\n(38)
+.nr 80 +\n(40
+.nr 41 \n(80+(3*\n(38)
+.nr 81 +\n(41
+.nr TW \n(81
+.if t .if \n(TW>\n(.li .tm Table at line 193 file Input is too wide - \n(TW units
+.fc  
+.nr #T 0-1
+.nr #a 0-1
+.eo
+.de T#
+.ds #d .d
+.if \(ts\n(.z\(ts\(ts .ds #d nl
+.mk ##
+.nr ## -1v
+.ls 1
+.ls
+..
+.ec
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3Option\fP\h'|\n(41u'\f3Description\fP
+.ne \n(a|u+\n(.Vu
+.if (\n(a|+\n(#^-1v)>\n(#- .nr #- +(\n(a|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-XadditionalHeaders\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.a+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(b|u+\n(.Vu
+.if (\n(b|+\n(#^-1v)>\n(#- .nr #- +(\n(b|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-Xauthfile <file>\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.b+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(c|u+\n(.Vu
+.if (\n(c|+\n(#^-1v)>\n(#- .nr #- +(\n(c|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-Xdebug\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.c+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(d|u+\n(.Vu
+.ne \n(e|u+\n(.Vu
+.if (\n(d|+\n(#^-1v)>\n(#- .nr #- +(\n(d|+\n(#^-\n(#--1v)
+.if (\n(e|+\n(#^-1v)>\n(#- .nr #- +(\n(e|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(40u
+.in +\n(37u
+.d+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.e+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.ne \n(f|u+\n(.Vu
+.if (\n(f|+\n(#^-1v)>\n(#- .nr #- +(\n(f|+\n(#^-\n(#--1v)
+.ta \n(80u \n(81u
+.nr 31 \n(.f
+.nr 35 1m
+\&\h'|\n(40u'\f3\-Xnocompile\fP\h'|\n(41u'
+.mk ##
+.nr 31 \n(##
+.sp |\n(##u-1v
+.nr 37 \n(41u
+.in +\n(37u
+.f+
+.in -\n(37u
+.mk 32
+.if \n(32>\n(31 .nr 31 \n(32
+.sp |\n(31u
+.fc
+.nr T. 1
+.T# 1
+.35
+.rm a+
+.rm b+
+.rm c+
+.rm d+
+.rm e+
+.rm f+
+.if \n-(b.=0 .nr c. \n(.c-\n(d.-26
+
+.LP
+.SH "Example"
+.nf
+\f3
+.fl
+\fP\f3wsimport \-p stockquote http://stockquote.example.com/quote?wsdl\fP
+.fl
+.fi
+.LP
+This will generate the Java artifacts and compile them by importing the \f2http://stockquote.example.com/quote?wsdl\fP.
+.br
+
diff --git a/jdk/src/bsd/doc/man/xjc.1 b/jdk/src/bsd/doc/man/xjc.1
new file mode 100644
index 0000000..068def7
--- /dev/null
+++ b/jdk/src/bsd/doc/man/xjc.1
@@ -0,0 +1,297 @@
+." Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+."
+." This code is free software; you can redistribute it and/or modify it
+." under the terms of the GNU General Public License version 2 only, as
+." published by the Free Software Foundation.
+."
+." This code is distributed in the hope that it will be useful, but WITHOUT
+." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+." version 2 for more details (a copy is included in the LICENSE file that
+." accompanied this code).
+."
+." You should have received a copy of the GNU General Public License version
+." 2 along with this work; if not, write to the Free Software Foundation,
+." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+."
+." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+." or visit www.oracle.com if you need additional information or have any
+." questions.
+."
+.TH xjc 1 "10 May 2011"
+
+.LP
+.SH "Name"
+xjc \- Java(TM) Architecture for XML Binding
+.br
+Binding Compiler
+.LP
+.LP
+\f3Specification Version:\fP 2.1
+.br
+\f3Reference Implementation (RI) Version:\fP 2.1.3
+.LP
+.SH "Launching xjc"
+.LP
+.LP
+The binding compiler can be launched using the appropriate \f2xjc\fP shell script in the \f2bin\fP directory for your platform. We also provide an Ant task to run the binding complier \- see the instructions for
+.na
+\f2using the XJC Ant task\fP @
+.fi
+https://jaxb.dev.java.net/nonav/2.1.3/docs/xjcTask.html.
+.LP
+.LP
+\f2% xjc \-help\fP
+.LP
+.SS
+Output
+.LP
+.nf
+\f3
+.fl
+Usage: xjc [\-options ...] <schema file/URL/dir/jar> ... [\-b <bindinfo>] ...
+.fl
+If dir is specified, all schema files in it will be compiled.
+.fl
+If jar is specified, /META\-INF/sun\-jaxb.episode binding file will be compiled.
+.fl
+Options:
+.fl
+  \-nv                :  do not perform strict validation of the input schema(s)
+.fl
+  \-extension         :  allow vendor extensions \- do not strictly follow the Compatibility Rules and App E.2 from the JAXB Spec
+.fl
+  \-b <file/dir>      :  specify external bindings files (each <file> must have its own \-b); if a directory is given, **/*.xjb is searched
+.fl
+  \-d <dir>           :  generated files will go into this directory
+.fl
+  \-p <pkg>           :  specifies the target package
+.fl
+  \-httpproxy <proxy> :  set HTTP/HTTPS proxy; format is [user[:password]@]proxyHost:proxyPort
+.fl
+  \-httpproxyfile <f> :  works like \-httpproxy but takes the argument in a file to protect password
+.fl
+  \-classpath <arg>   :  specify where to find user class files
+.fl
+  \-catalog <file>    :  specify catalog files to resolve external entity references; support TR9401, XCatalog, and OASIS XML Catalog format
+.fl
+  \-readOnly          :  generated files will be in read\-only mode
+.fl
+  \-npa               :  suppress generation of package level annotations (**/package\-info.java)
+.fl
+  \-no\-header         :  suppress generation of a file header with timestamp
+.fl
+  \-target 2.0        :  behave like XJC 2.0 and generate code that doesnt use any 2.1 features
+.fl
+  \-xmlschema         :  treat input as W3C XML Schema (default)
+.fl
+  \-relaxng           :  treat input as RELAX NG (experimental,unsupported)
+.fl
+  \-relaxng\-compact   :  treat input as RELAX NG compact syntax (experimental,unsupported)
+.fl
+  \-dtd               :  treat input as XML DTD (experimental,unsupported)
+.fl
+  \-wsdl              :  treat input as WSDL and compile schemas inside it (experimental,unsupported)
+.fl
+  \-verbose           :  be extra verbose
+.fl
+  \-quiet             :  suppress compiler output
+.fl
+  \-help              :  display this help message
+.fl
+  \-version           :  display version information
+.fl
+
+.fl
+
+.fl
+Extensions:
+.fl
+  \-Xlocator          :  enable source location support for generated code
+.fl
+  \-Xsync\-methods     :  generate accessor methods with the 'synchronized' keyword
+.fl
+  \-mark\-generated    :  mark the generated code as @javax.annotation.Generated
+.fl
+  \-episode <FILE>    :  generate the episode file for separate compilation
+.fl
+\fP
+.fi
+
+.LP
+.SH "OPTIONS"
+.LP
+.RS 3
+.TP 3
+\-nv
+By default, the XJC binding compiler performs strict validation of the source schema before processing it. Use this option to disable strict schema validation. This does not mean that the binding compiler will not perform any validation, it simply means that it will perform less\-strict validation.
+.TP 3
+\-extension
+By default, the XJC binding compiler strictly enforces the rules outlined in the Compatibility chapter of the JAXB Specification. Appendix E.2 defines a set of W3C XML Schema features that are not completely supported by JAXB v1.0. In some cases, you may be allowed to use them in the "\-extension" mode enabled by this switch. In the default (strict) mode, you are also limited to using only the binding customizations defined in the specification. By using the "\-extension" switch, you will be allowed to use the JAXB Vendor Extensions
+.TP 3
+\-b <file>
+Specify one or more external binding files to process. (Each binding file must have its own \f2"\-b"\fP switch.) The syntax of the external binding files is extremely flexible. You may have a single binding file that contains customizations for multiple schemas or you can break the customizations into multiple bindings files: \f2xjc schema1.xsd schema2.xsd schema3.xsd \-b bindings123.xjb\fP
+.br
+\f2xjc schema1.xsd schema2.xsd schema3.xsd \-b bindings1.xjb \-b bindings2.xjb \-b bindings3.xjb\fP In addition, the ordering of the schema files and binding files on the command line does not matter.
+.TP 3
+\-d <dir>
+By default, the XJC binding compiler will generate the Java content classes in the current directory. Use this option to specify an alternate output directory. The output directory must already exist, the XJC binding compiler will not create it for you.
+.TP 3
+\-p <pkg>
+Specifying a target package via this command\-line option overrides any binding customization for package name and the default package name algorithm defined in the specification.
+.TP 3
+\-httpproxy <proxy>
+Specify the HTTP/HTTPS proxy. The format is [user[:password]@]proxyHost[:proxyPort]. The old \f2\-host\fP and \f2\-port\fP are still supported by the RI for backwards compatibility, but they have been deprecated. Note that the password specified with this option is an argument that is visible to other users who use the \f2top\fP command, for example. For greater security, use \f2\-httpproxyfile\fP, below.
+.TP 3
+\-httpproxyfile <file>
+Specify the HTTP/HTTPS proxy using a file. Same format as above, but the password specified in the file is not visible to other users.
+.TP 3
+\-classpath <arg>
+Specify where to find client application class files used by the \f2<jxb:javaType>\fP and \f2<xjc:superClass>\fP customizations.
+.TP 3
+\-catalog <file>
+Specify catalog files to resolve external entity references. Supports TR9401, XCatalog, and OASIS XML Catalog format. Please read the XML Entity and URI Resolvers document or the \f2catalog\-resolver\fP sample application.
+.TP 3
+\-readOnly
+By default, the XJC binding compiler does not write\-protect the Java source files it generates. Use this option to force the XJC binding compiler to mark the generated Java sources read\-only.
+.TP 3
+\-npa
+Supress the generation of package level annotations into **/package\-info.java. Using this switch causes the generated code to internalize those annotations into the other generated classes.
+.TP 3
+\-no\-header
+Supress the generation of a file header comment that includes some note and timestamp. Using this makes the generated code more diff\-friendly.
+.TP 3
+\-target 2.0
+Avoid generating code that relies on any JAXB 2.1 features. This will allow the generated code to run with JAXB 2.0 runtime (such as JavaSE 6.)
+.TP 3
+\-xmlschema
+Treat input schemas as W3C XML Schema (default). If you do not specify this switch, your input schemas will be treated as W3C XML Schema.
+.TP 3
+\-relaxng
+Treat input schemas as RELAX NG (experimental, unsupported). Support for RELAX NG schemas is provided as a JAXB Vendor Extension.
+.TP 3
+\-relaxng\-compact
+Treat input schemas as RELAX NG compact syntax(experimental, unsupported). Support for RELAX NG schemas is provided as a JAXB Vendor Extension.
+.TP 3
+\-dtd
+Treat input schemas as XML DTD (experimental, unsupported). Support for RELAX NG schemas is provided as a JAXB Vendor Extension.
+.TP 3
+\-wsdl
+Treat input as WSDL and compile schemas inside it (experimental,unsupported).
+.TP 3
+\-quiet
+Suppress compiler output, such as progress information and warnings.
+.TP 3
+\-verbose
+Be extra verbose, such as printing informational messages or displaying stack traces upon some errors.
+.TP 3
+\-help
+Display a brief summary of the compiler switches.
+.TP 3
+\-version
+Display the compiler version information.
+.TP 3
+<schema file/URL/dir>
+Specify one or more schema files to compile. If you specify a directory, then xjc will scan it for all schema files and compile them.
+.RE
+
+.LP
+.SS
+Non\-Standard Command Line Options
+.LP
+.RS 3
+.TP 3
+\-Xlocator
+Causes the generated code to expose SAX Locator information about the source XML in the Java bean instances after unmarshalling.
+.TP 3
+\-Xsync\-methods
+Causes all of the generated method signatures to include the \f2synchronized\fP keyword.
+.TP 3
+\-mark\-generated
+Mark the generated code with the annotation \f2@javax.annotation.Generated\fP.
+.TP 3
+\-episode <file>
+Generate the specified episode file for separate compilation.
+.RE
+
+.LP
+.SS
+Deprecated and Removed Command Line Options
+.LP
+.RS 3
+.TP 3
+\-host & \-port
+These options have been deprecated and replaced with the \f3\-httpproxy\fP option. For backwards compatibility, we will continue to support these options, but they will no longer be documented and may be removed from future releases.
+.TP 3
+\-use\-runtime
+Since the JAXB 2.0 specification has defined a portable runtime, it is no longer necessary for the JAXB RI to generate **/impl/runtime packages. Therefore, this switch is obsolete and has been removed.
+.TP 3
+\-source
+The \-source compatibility switch was introduced in the first JAXB 2.0 Early Access release. We have decided to remove this switch from future releases of JAXB 2.0. If you need to generate 1.0.x code, please use an installation of the 1.0.x codebase.
+.RE
+
+.LP
+.SS
+Compiler Restrictions
+.LP
+.LP
+In general, it is safest to compile all related schemas as a single unit with the same binding compiler switches.
+.LP
+.LP
+Please keep the following list of restrictions in mind when running xjc. Most of these issues only apply when compiling multiple schemas with multiple invocations of xjc.
+.LP
+.RS 3
+.TP 2
+o
+To compile multiple schemas at the same time, keep the following precedence rules for the target Java package name in mind:
+.RS 3
+.TP 3
+1.
+The "\f2\-p\fP" command line option takes the highest precedence.
+.TP 3
+2.
+<\f2jaxb:package\fP> customization
+.TP 3
+3.
+If \f2targetNamespace\fP is declared, apply \f2targetNamespace\fP \-> Java package name algorithm defined in the specification.
+.TP 3
+4.
+If no \f2targetNamespace\fP is declared, use a hardcoded package named "generated".
+.RE
+.TP 2
+o
+It is not legal to have more than one <\f2jaxb:schemaBindings\fP> per namespace, so it is impossible to have two schemas in the same target namespace compiled into different Java packages.
+.TP 2
+o
+All schemas being compiled into the same Java package must be submitted to the XJC binding compiler at the same time \- they cannot be compiled independently and work as expected.
+.TP 2
+o
+Element substitution groups spread across multiple schema files must be compiled at the same time.
+.RE
+
+.LP
+.SH "See Also"
+.LP
+.RS 3
+.TP 2
+o
+Running the binding compiler (XJC): [
+.na
+\f2command\-line instructions\fP @
+.fi
+https://jaxb.dev.java.net/nonav/2.1.3/docs/xjc.html,
+.na
+\f2using the XJC Ant task\fP @
+.fi
+https://jaxb.dev.java.net/nonav/2.1.3/docs/xjcTask.html]
+.TP 2
+o
+.na
+\f2Java Architecture for XML Binding (JAXB)\fP @
+.fi
+http://download.oracle.com/javase/7/docs/technotes/guides/xml/jaxb/index.html
+.RE
+
+.LP
+
diff --git a/jdk/src/macosx/bundle/JDK-Info.plist b/jdk/src/macosx/bundle/JDK-Info.plist
new file mode 100644
index 0000000..d057e83
--- /dev/null
+++ b/jdk/src/macosx/bundle/JDK-Info.plist
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>CFBundleDevelopmentRegion</key>
+        <string>English</string>
+        <key>CFBundleExecutable</key>
+        <string>libjli.dylib</string>
+        <key>CFBundleGetInfoString</key>
+        <string>@@INFO@@</string>
+        <key>CFBundleIdentifier</key>
+        <string>@@ID@@</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>7.0</string>
+        <key>CFBundleName</key>
+        <string>@@NAME@@</string>
+        <key>CFBundlePackageType</key>
+        <string>BNDL</string>
+        <key>CFBundleShortVersionString</key>
+        <string>1.0</string>
+        <key>CFBundleSignature</key>
+        <string>????</string>
+        <key>CFBundleVersion</key>
+        <string>@@VERSION@@</string>
+        <key>JavaVM</key>
+        <dict>
+                <key>JVMCapabilities</key>
+                <array>
+                        <string>CommandLine</string>
+                </array>
+                <key>JVMMinimumFrameworkVersion</key>
+                <string>13.2.9</string>
+                <key>JVMMinimumSystemVersion</key>
+                <string>10.6.0</string>
+                <key>JVMPlatformVersion</key>
+                <string>@@PLATFORM_VERSION@@</string>
+                <key>JVMVendor</key>
+                <string>@@VENDOR@@</string>
+                <key>JVMVersion</key>
+                <string>@@VERSION@@</string>
+        </dict>
+</dict>
+</plist>
diff --git a/jdk/src/macosx/bundle/JRE-Info.plist b/jdk/src/macosx/bundle/JRE-Info.plist
new file mode 100644
index 0000000..b9d045e
--- /dev/null
+++ b/jdk/src/macosx/bundle/JRE-Info.plist
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>CFBundleDevelopmentRegion</key>
+        <string>English</string>
+        <key>CFBundleExecutable</key>
+        <string>libjli.dylib</string>
+        <key>CFBundleGetInfoString</key>
+        <string>@@INFO@@</string>
+        <key>CFBundleIdentifier</key>
+        <string>@@ID@@</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>7.0</string>
+        <key>CFBundleName</key>
+        <string>@@NAME@@</string>
+        <key>CFBundlePackageType</key>
+        <string>BNDL</string>
+        <key>CFBundleShortVersionString</key>
+        <string>1.0</string>
+        <key>CFBundleSignature</key>
+        <string>????</string>
+        <key>CFBundleVersion</key>
+        <string>@@VERSION@@</string>
+        <key>JavaVM</key>
+        <dict>
+                <key>JVMMinimumFrameworkVersion</key>
+                <string>13.2.9</string>
+                <key>JVMMinimumSystemVersion</key>
+                <string>10.6.0</string>
+                <key>JVMPlatformVersion</key>
+                <string>@@PLATFORM_VERSION@@</string>
+                <key>JVMVendor</key>
+                <string>@@VENDOR@@</string>
+                <key>JVMVersion</key>
+                <string>@@VERSION@@</string>
+        </dict>
+</dict>
+</plist>
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/JavaAppLauncher.xcodeproj/project.pbxproj b/jdk/src/macosx/bundle/JavaAppLauncher/JavaAppLauncher.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..b51cbefb
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/JavaAppLauncher.xcodeproj/project.pbxproj
@@ -0,0 +1,318 @@
+// !$*UTF8*$!
+{
+        archiveVersion = 1;
+        classes = {
+        };
+        objectVersion = 45;
+        objects = {
+
+/* Begin PBXBuildFile section */
+                2C483E05143512EB00F2AEFD /* 1.7.0.jre in Copy PlugIns */ = {isa = PBXBuildFile; fileRef = 2C483E04143512EB00F2AEFD /* 1.7.0.jre */; };
+                89D3CD32142EEB2200A08AED /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 89D3CD29142EEB2200A08AED /* InfoPlist.strings */; };
+                89D3CD33142EEB2200A08AED /* GenericApp.icns in Resources */ = {isa = PBXBuildFile; fileRef = 89D3CD2B142EEB2200A08AED /* GenericApp.icns */; };
+                89D3CD35142EEB2200A08AED /* JVMArgs.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D3CD30142EEB2200A08AED /* JVMArgs.m */; };
+                89D3CD36142EEB2200A08AED /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D3CD31142EEB2200A08AED /* main.m */; };
+                89D3D365143041F000A08AED /* JavaAppLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D3D364143041F000A08AED /* JavaAppLauncher.m */; };
+                8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+                2C48F06614350F0F00F2AEFD /* Copy PlugIns */ = {
+                        isa = PBXCopyFilesBuildPhase;
+                        buildActionMask = 2147483647;
+                        dstPath = "";
+                        dstSubfolderSpec = 13;
+                        files = (
+                                2C483E05143512EB00F2AEFD /* 1.7.0.jre in Copy PlugIns */,
+                        );
+                        name = "Copy PlugIns";
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+                1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
+                2C483E04143512EB00F2AEFD /* 1.7.0.jre */ = {isa = PBXFileReference; lastKnownFileType = folder; name = 1.7.0.jre; path = "../../../../../build/macosx-universal/j2sdk-bundle/1.7.0.jdk/Contents/Home/1.7.0.jre"; sourceTree = SOURCE_ROOT; };
+                2C48F06714350F8300F2AEFD /* 1.7.0.jdk */ = {isa = PBXFileReference; lastKnownFileType = folder; name = 1.7.0.jdk; path = "../../../../../build/macosx-universal/j2sdk-bundle/1.7.0.jdk"; sourceTree = SOURCE_ROOT; };
+                2CB5DA5E14355FCA00D3A656 /* classfile_constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = classfile_constants.h; sourceTree = "<group>"; };
+                2CB5DA6014355FCA00D3A656 /* jawt_md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jawt_md.h; sourceTree = "<group>"; };
+                2CB5DA6114355FCA00D3A656 /* jni_md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jni_md.h; sourceTree = "<group>"; };
+                2CB5DA6214355FCA00D3A656 /* jawt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jawt.h; sourceTree = "<group>"; };
+                2CB5DA6314355FCA00D3A656 /* jdwpTransport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jdwpTransport.h; sourceTree = "<group>"; };
+                2CB5DA6414355FCA00D3A656 /* jni.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jni.h; sourceTree = "<group>"; };
+                2CB5DA6514355FCA00D3A656 /* jvmti.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jvmti.h; sourceTree = "<group>"; };
+                2CB5DA6614355FCA00D3A656 /* jvmticmlr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jvmticmlr.h; sourceTree = "<group>"; };
+                89D3CD2A142EEB2200A08AED /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+                89D3CD2B142EEB2200A08AED /* GenericApp.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = GenericApp.icns; path = /System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/GenericApp.icns; sourceTree = "<absolute>"; };
+                89D3CD2C142EEB2200A08AED /* JavaAppLauncher-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "JavaAppLauncher-Info.plist"; sourceTree = "<group>"; };
+                89D3CD2E142EEB2200A08AED /* JavaAppLauncher_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaAppLauncher_Prefix.pch; sourceTree = "<group>"; };
+                89D3CD2F142EEB2200A08AED /* JVMArgs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JVMArgs.h; sourceTree = "<group>"; };
+                89D3CD30142EEB2200A08AED /* JVMArgs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JVMArgs.m; sourceTree = "<group>"; };
+                89D3CD31142EEB2200A08AED /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+                89D3D363143041F000A08AED /* JavaAppLauncher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaAppLauncher.h; sourceTree = "<group>"; };
+                89D3D364143041F000A08AED /* JavaAppLauncher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JavaAppLauncher.m; sourceTree = "<group>"; };
+                8D1107320486CEB800E47090 /* JavaAppLauncher.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JavaAppLauncher.app; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+                8D11072E0486CEB800E47090 /* Frameworks */ = {
+                        isa = PBXFrameworksBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+                1058C7A0FEA54F0111CA2CBB /* frameworks */ = {
+                        isa = PBXGroup;
+                        children = (
+                                1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
+                        );
+                        name = frameworks;
+                        sourceTree = "<group>";
+                };
+                19C28FACFE9D520D11CA2CBB /* Products */ = {
+                        isa = PBXGroup;
+                        children = (
+                                8D1107320486CEB800E47090 /* JavaAppLauncher.app */,
+                        );
+                        name = Products;
+                        sourceTree = "<group>";
+                };
+                29B97314FDCFA39411CA2CEA /* JavaAppLauncher */ = {
+                        isa = PBXGroup;
+                        children = (
+                                89D3CD2D142EEB2200A08AED /* src */,
+                                89D3CD28142EEB2200A08AED /* resources */,
+                                29B97323FDCFA39411CA2CEA /* linking */,
+                                19C28FACFE9D520D11CA2CBB /* Products */,
+                        );
+                        name = JavaAppLauncher;
+                        sourceTree = "<group>";
+                };
+                29B97323FDCFA39411CA2CEA /* linking */ = {
+                        isa = PBXGroup;
+                        children = (
+                                2C48F06714350F8300F2AEFD /* 1.7.0.jdk */,
+                                2C483E04143512EB00F2AEFD /* 1.7.0.jre */,
+                                2CB5DA5D14355FCA00D3A656 /* include */,
+                                1058C7A0FEA54F0111CA2CBB /* frameworks */,
+                        );
+                        name = linking;
+                        sourceTree = "<group>";
+                };
+                2CB5DA5D14355FCA00D3A656 /* include */ = {
+                        isa = PBXGroup;
+                        children = (
+                                2CB5DA5E14355FCA00D3A656 /* classfile_constants.h */,
+                                2CB5DA5F14355FCA00D3A656 /* darwin */,
+                                2CB5DA6214355FCA00D3A656 /* jawt.h */,
+                                2CB5DA6314355FCA00D3A656 /* jdwpTransport.h */,
+                                2CB5DA6414355FCA00D3A656 /* jni.h */,
+                                2CB5DA6514355FCA00D3A656 /* jvmti.h */,
+                                2CB5DA6614355FCA00D3A656 /* jvmticmlr.h */,
+                        );
+                        name = include;
+                        path = "../../../../../build/macosx-universal/j2sdk-bundle/1.7.0.jdk/Contents/Home/include";
+                        sourceTree = "<group>";
+                };
+                2CB5DA5F14355FCA00D3A656 /* darwin */ = {
+                        isa = PBXGroup;
+                        children = (
+                                2CB5DA6014355FCA00D3A656 /* jawt_md.h */,
+                                2CB5DA6114355FCA00D3A656 /* jni_md.h */,
+                        );
+                        path = darwin;
+                        sourceTree = "<group>";
+                };
+                89D3CD28142EEB2200A08AED /* resources */ = {
+                        isa = PBXGroup;
+                        children = (
+                                89D3CD29142EEB2200A08AED /* InfoPlist.strings */,
+                                89D3CD2B142EEB2200A08AED /* GenericApp.icns */,
+                                89D3CD2C142EEB2200A08AED /* JavaAppLauncher-Info.plist */,
+                        );
+                        path = resources;
+                        sourceTree = "<group>";
+                };
+                89D3CD2D142EEB2200A08AED /* src */ = {
+                        isa = PBXGroup;
+                        children = (
+                                89D3CD31142EEB2200A08AED /* main.m */,
+                                89D3D363143041F000A08AED /* JavaAppLauncher.h */,
+                                89D3D364143041F000A08AED /* JavaAppLauncher.m */,
+                                89D3CD2F142EEB2200A08AED /* JVMArgs.h */,
+                                89D3CD30142EEB2200A08AED /* JVMArgs.m */,
+                                89D3CD2E142EEB2200A08AED /* JavaAppLauncher_Prefix.pch */,
+                        );
+                        path = src;
+                        sourceTree = "<group>";
+                };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+                8D1107260486CEB800E47090 /* JavaAppLauncher */ = {
+                        isa = PBXNativeTarget;
+                        buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "JavaAppLauncher" */;
+                        buildPhases = (
+                                8D1107290486CEB800E47090 /* Resources */,
+                                2C48F06614350F0F00F2AEFD /* Copy PlugIns */,
+                                8D11072C0486CEB800E47090 /* Sources */,
+                                8D11072E0486CEB800E47090 /* Frameworks */,
+                        );
+                        buildRules = (
+                        );
+                        dependencies = (
+                        );
+                        name = JavaAppLauncher;
+                        productInstallPath = "$(HOME)/Applications";
+                        productName = JavaAppLauncher;
+                        productReference = 8D1107320486CEB800E47090 /* JavaAppLauncher.app */;
+                        productType = "com.apple.product-type.application";
+                };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+                29B97313FDCFA39411CA2CEA /* Project object */ = {
+                        isa = PBXProject;
+                        buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "JavaAppLauncher" */;
+                        compatibilityVersion = "Xcode 3.1";
+                        developmentRegion = English;
+                        hasScannedForEncodings = 1;
+                        knownRegions = (
+                                en,
+                                English,
+                        );
+                        mainGroup = 29B97314FDCFA39411CA2CEA /* JavaAppLauncher */;
+                        projectDirPath = "";
+                        projectRoot = "";
+                        targets = (
+                                8D1107260486CEB800E47090 /* JavaAppLauncher */,
+                        );
+                };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+                8D1107290486CEB800E47090 /* Resources */ = {
+                        isa = PBXResourcesBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                89D3CD32142EEB2200A08AED /* InfoPlist.strings in Resources */,
+                                89D3CD33142EEB2200A08AED /* GenericApp.icns in Resources */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+                8D11072C0486CEB800E47090 /* Sources */ = {
+                        isa = PBXSourcesBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                89D3CD35142EEB2200A08AED /* JVMArgs.m in Sources */,
+                                89D3CD36142EEB2200A08AED /* main.m in Sources */,
+                                89D3D365143041F000A08AED /* JavaAppLauncher.m in Sources */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+                89D3CD29142EEB2200A08AED /* InfoPlist.strings */ = {
+                        isa = PBXVariantGroup;
+                        children = (
+                                89D3CD2A142EEB2200A08AED /* English */,
+                        );
+                        name = InfoPlist.strings;
+                        sourceTree = "<group>";
+                };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+                C01FCF4B08A954540054247B /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = NO;
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_ENABLE_FIX_AND_CONTINUE = YES;
+                                GCC_MODEL_TUNING = G5;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
+                                GCC_PREFIX_HEADER = src/JavaAppLauncher_Prefix.pch;
+                                INFOPLIST_FILE = "resources/JavaAppLauncher-Info.plist";
+                                INSTALL_PATH = "$(HOME)/Applications";
+                                LIBRARY_SEARCH_PATHS = "$(inherited)";
+                                PRODUCT_NAME = JavaAppLauncher;
+                        };
+                        name = Debug;
+                };
+                C01FCF4C08A954540054247B /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = NO;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                GCC_MODEL_TUNING = G5;
+                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
+                                GCC_PREFIX_HEADER = src/JavaAppLauncher_Prefix.pch;
+                                INFOPLIST_FILE = "resources/JavaAppLauncher-Info.plist";
+                                INSTALL_PATH = "$(HOME)/Applications";
+                                LIBRARY_SEARCH_PATHS = "$(inherited)";
+                                PRODUCT_NAME = JavaAppLauncher;
+                        };
+                        name = Release;
+                };
+                C01FCF4F08A954540054247B /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+                                GCC_C_LANGUAGE_STANDARD = gnu99;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                ONLY_ACTIVE_ARCH = YES;
+                                PREBINDING = NO;
+                                SDKROOT = "";
+                        };
+                        name = Debug;
+                };
+                C01FCF5008A954540054247B /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+                                GCC_C_LANGUAGE_STANDARD = gnu99;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                PREBINDING = NO;
+                                SDKROOT = "";
+                        };
+                        name = Release;
+                };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+                C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "JavaAppLauncher" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                C01FCF4B08A954540054247B /* Debug */,
+                                C01FCF4C08A954540054247B /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                C01FCF4E08A954540054247B /* Build configuration list for PBXProject "JavaAppLauncher" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                C01FCF4F08A954540054247B /* Debug */,
+                                C01FCF5008A954540054247B /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+/* End XCConfigurationList section */
+        };
+        rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
+}
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/resources/English.lproj/InfoPlist.strings b/jdk/src/macosx/bundle/JavaAppLauncher/resources/English.lproj/InfoPlist.strings
new file mode 100644
index 0000000..477b28f
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/resources/English.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/resources/JavaAppLauncher-Info.plist b/jdk/src/macosx/bundle/JavaAppLauncher/resources/JavaAppLauncher-Info.plist
new file mode 100644
index 0000000..a3268bb
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/resources/JavaAppLauncher-Info.plist
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>CFBundleDevelopmentRegion</key>
+        <string>English</string>
+        <key>CFBundleExecutable</key>
+        <string>${EXECUTABLE_NAME}</string>
+        <key>CFBundleIconFile</key>
+        <string>GenericApp.icns</string>
+        <key>CFBundleIdentifier</key>
+        <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
+        <key>CFBundleDisplayName</key>
+        <string>Your Cool App</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>6.0</string>
+        <key>CFBundleName</key>
+        <string>${PRODUCT_NAME}</string>
+        <key>CFBundlePackageType</key>
+        <string>APPL</string>
+        <key>CFBundleShortVersionString</key>
+        <string>1.0</string>
+        <key>CFBundleSignature</key>
+        <string>????</string>
+        <key>CFBundleVersion</key>
+        <string>1</string>
+        <key>LSMinimumSystemVersion</key>
+        <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+        <key>NSHumanReadableCopyright</key>
+        <string>Copyright © 2011 Your Company Inc. All Rights Reserved.</string>
+        <key>JVMInfo</key>
+        <dict>
+                <key>JRE</key>
+                <string>1.7.0.jre</string>
+                <key>ClassPath</key>
+                <array/>
+                <key>Properties</key>
+                <dict>
+                        <key>apple.laf.useScreenMenuBar</key>
+                        <string>true</string>
+                </dict>
+                <key>MainClass</key>
+                <string>com.yourcompany.yourapp.mainclass</string>
+                <key>Arguments</key>
+                <array/>
+        </dict>
+</dict>
+</plist>
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/src/JVMArgs.h b/jdk/src/macosx/bundle/JavaAppLauncher/src/JVMArgs.h
new file mode 100644
index 0000000..4a39db3
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/src/JVMArgs.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#import "jni.h"
+
+
+@interface JVMArgs : NSObject {
+@public
+    NSBundle *jreBundle;
+    char *preferredJVMLib;
+    JavaVMInitArgs vm_args;
+    BOOL startOnFirstThread;
+    BOOL debug;
+
+    NSDictionary *appInfo;
+    NSMutableDictionary *jvmInfo;
+
+    NSString *userHome;
+    NSString *appPackage;
+    NSString *javaRoot;
+}
+
+@property (retain, nonatomic) NSBundle *jreBundle;
+@property (nonatomic) char *preferredJVMLib;
+@property (nonatomic) JavaVMInitArgs vm_args;
+@property (nonatomic) BOOL startOnFirstThread;
+@property (nonatomic) BOOL debug;
+
+@property (retain, nonatomic) NSDictionary *appInfo;
+@property (retain, nonatomic) NSMutableDictionary *jvmInfo;
+
+@property (retain, nonatomic) NSString *userHome;
+@property (retain, nonatomic) NSString *appPackage;
+@property (retain, nonatomic) NSString *javaRoot;
+
++ (JVMArgs *)jvmArgsForBundle:(NSBundle *)appBundle argc:(int)argc argv:(char *[])argv;
+
+@end
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/src/JVMArgs.m b/jdk/src/macosx/bundle/JavaAppLauncher/src/JVMArgs.m
new file mode 100644
index 0000000..a2a357e
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/src/JVMArgs.m
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "JVMArgs.h"
+
+
+#define kArgsFailure "JVMArgsFailure"
+
+NSString *kArgumentsKey = @"Arguments";
+
+NSString *kClassPathKey = @"ClassPath";
+#ifdef __i386__
+NSString *kArchClassPathKey = @"ClassPath.i386";
+#elif __x86_64__
+NSString *kArchClassPathKey = @"ClassPath.x86_64";
+#endif
+
+NSString *kVMOptionsKey = @"VMOptions";
+#ifdef __i386__
+NSString *kArchVMOptionsKey = @"VMOptions.i386";
+#elif __x86_64__
+NSString *kArchVMOptionsKey = @"VMOptions.x86_64";
+#endif
+
+
+@implementation JVMArgs
+
+@synthesize jreBundle;
+@synthesize preferredJVMLib;
+@synthesize vm_args;
+@synthesize startOnFirstThread;
+@synthesize debug;
+
+@synthesize appInfo;
+@synthesize jvmInfo;
+
+@synthesize userHome;
+@synthesize appPackage;
+@synthesize javaRoot;
+
+- (void) dealloc {
+    self.jreBundle = nil;
+    if (self.preferredJVMLib) free(self.preferredJVMLib);
+
+    self.appInfo = nil;
+    self.jvmInfo = nil;
+
+    self.userHome = nil;
+    self.appPackage = nil;
+    self.javaRoot = nil;
+
+    [super dealloc];
+}
+
+
+NSString *GetJavaRoot(NSDictionary *jvmInfoDict) {
+    NSObject *javaRoot = [jvmInfoDict objectForKey:@"$JAVAROOT"];
+    if (![javaRoot isKindOfClass:[NSString class]]) return @"$APP_PACKAGE/Contents/Java";
+    return (NSString *)javaRoot;
+}
+
+// Replaces occurances of $JAVAROOT, $APP_PACKAGE, and $USER_HOME
+- (NSString *) expandMacros:(NSString *)str {
+    if ([str rangeOfString:@"$JAVAROOT"].length == 0 && [str rangeOfString:@"$APP_PACKAGE"].length == 0 && [str rangeOfString:@"$USER_HOME"].length == 0) return str;
+
+    // expand $JAVAROOT first, because it can contain $APP_PACKAGE
+    NSMutableString *mutable = [str mutableCopy];
+    [mutable replaceOccurrencesOfString:@"$JAVAROOT" withString:javaRoot options:0 range:NSMakeRange(0, [str length])];
+    [mutable replaceOccurrencesOfString:@"$APP_PACKAGE" withString:appPackage options:0 range:NSMakeRange(0, [str length])];
+    [mutable replaceOccurrencesOfString:@"$USER_HOME" withString:userHome options:0 range:NSMakeRange(0, [str length])];
+    return mutable;
+}
+
+- (NSArray *) arrayFrom:(id) obj delimitedBy:(NSString *)delimiter withErrKey:(NSString *)key {
+    if (obj == nil) return nil;
+    if ([obj isKindOfClass:[NSArray class]]) return obj;
+    if (![obj isKindOfClass:[NSString class]]) {
+        [NSException raise:@kArgsFailure format:@"%@", [NSString stringWithFormat:@"Failed to find '%@' array in JVMInfo Info.plist"]];
+    }
+
+    // split
+    return [(NSString *)obj componentsSeparatedByString:delimiter];
+}
+
+- (void) buildArgsForBundle:(NSBundle *)appBundle argc:(int)argc argv:(char *[])argv {
+    // for verbose logging
+    self.debug = NULL != getenv("JAVA_LAUNCHER_VERBOSE");
+
+    self.appInfo = [appBundle infoDictionary];
+
+    // all apps must have a JVMInfo dictionary inside their Info.plist
+    self.jvmInfo = [[self.appInfo objectForKey:@"JVMInfo"] mutableCopy];
+    if (![jvmInfo isKindOfClass:[NSDictionary class]]) {
+        [NSException raise:@kArgsFailure format:@"Failed to find 'JVMInfo' dictionary in Info.plist"];
+    }
+
+    // initialize macro expansion values
+    self.userHome = NSHomeDirectory();
+    self.appPackage = [appBundle bundlePath];
+    self.javaRoot = GetJavaRoot(jvmInfo);
+    self.javaRoot = [self expandMacros:self.javaRoot]; // dereference $APP_PACKAGE
+
+    // if the 'Arguments' key is defined, those override the ones that came into main()
+    NSArray *jvmInfoArgs = [jvmInfo valueForKey:kArgumentsKey];
+    if (jvmInfoArgs != nil) {
+        // substitute all the variables in the 'Arguments' array/string
+        jvmInfoArgs = [self arrayFrom:jvmInfoArgs delimitedBy:@" " withErrKey:kArgumentsKey];
+        NSMutableArray *arguments = [NSMutableArray arrayWithCapacity:[jvmInfoArgs count]];
+        [jvmInfoArgs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+            [arguments replaceObjectAtIndex:idx withObject:[self expandMacros:[obj description]]];
+        }];
+        [jvmInfo setObject:arguments forKey:kArgumentsKey];
+    } else if (argc != 0) {
+        // put the (macro expanded) args to main() in an NSArray
+        NSMutableArray *arguments = [NSMutableArray arrayWithCapacity:argc];
+        for (int i = 0; i < argc; i++) {
+            [arguments addObject:[self expandMacros:[NSString stringWithUTF8String:(argv[i])]]];
+        }
+        [jvmInfo setObject:arguments forKey:kArgumentsKey];
+    }
+
+    // all JVMInfo's must have a JRE or JDK key
+    NSString *jreBundleName = [jvmInfo objectForKey:@"JRE"];
+    if (!jreBundleName) jreBundleName = [jvmInfo objectForKey:@"JDK"];
+    if (![jreBundleName isKindOfClass:[NSString class]]) {
+        [NSException raise:@kArgsFailure format:@"Failed to find 'JRE' or 'JDK' string in Info.plist JVMInfo"];
+    }
+
+    // the JRE/JDK must be loadable from the ($APP_PACKAGE)/Contents/PlugIns/ directory
+    NSURL *jreBundleURL = [[appBundle builtInPlugInsURL] URLByAppendingPathComponent:jreBundleName];
+    self.jreBundle = [NSBundle bundleWithURL:jreBundleURL];
+    if (!self.jreBundle) {
+        [NSException raise:@kArgsFailure format:@"Failed to find JRE/JDK at: %@", jreBundleURL];
+    }
+
+    // if the app prefers 'client' or 'server', use the JVM key
+    NSString *JVMLib = [jvmInfo objectForKey:@"JVM"];
+    if (JVMLib != nil) self.preferredJVMLib = strdup([JVMLib UTF8String]);
+
+    // sniff for StartOnFirstThread
+    if ([[jvmInfo objectForKey:@"StartOnFirstThread"] boolValue]) {
+        self.startOnFirstThread = YES;
+    } else if ([[jvmInfo objectForKey:@"StartOnMainThread"] boolValue]) {
+        // for key compatability with the Apple JavaApplicationStub's 'Java' dictionary
+        self.startOnFirstThread = YES;
+    }
+
+    // add $JAVAROOT directory to the JNI library search path
+    setenv("JAVA_LIBRARY_PATH", [javaRoot UTF8String], 1);
+
+    // 'WorkingDirectory' key changes current working directory
+    NSString *javaWorkingDir = [jvmInfo objectForKey:@"WorkingDirectory"];
+    if (javaWorkingDir == nil) javaWorkingDir = @"$APP_PACKAGE/..";
+    javaWorkingDir = [self expandMacros:javaWorkingDir];
+    if (chdir([javaWorkingDir UTF8String]) == -1) {
+        NSLog(@kArgsFailure " chdir() failed, could not change the current working directory to %s\n", [javaWorkingDir UTF8String]);
+    }
+
+    NSMutableArray *classpath = [NSMutableArray array];
+
+    // 'Jar' key sets exactly one classpath entry
+    NSString *jarFile = [jvmInfo objectForKey:@"Jar"];
+    if (jarFile != nil) {
+        [jvmInfo setObject:[self expandMacros:jarFile] forKey:@"Jar"];
+        [classpath addObject:jarFile];
+    }
+
+    // 'ClassPath' key allows arbitrary classpath
+    [classpath addObjectsFromArray:[self arrayFrom:[jvmInfo objectForKey:kClassPathKey] delimitedBy:@":" withErrKey:kClassPathKey]];
+    [classpath addObjectsFromArray:[self arrayFrom:[jvmInfo objectForKey:kArchClassPathKey] delimitedBy:@":" withErrKey:kArchClassPathKey]];
+
+    // Sum up all the classpath entries into one big JVM arg
+    NSMutableString *classpathOption = [NSMutableString stringWithString:@"-Djava.class.path="];
+    [classpath enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+        if (idx > 1) [classpathOption appendString:@":"];
+        [classpathOption appendString:obj];
+    }];
+
+    NSMutableArray *jvmOptions = [NSMutableArray arrayWithObject:classpathOption];
+
+    // 'VMOptions' key allows arbitary VM start up options
+    [jvmOptions addObjectsFromArray:[self arrayFrom:[jvmInfo objectForKey:kVMOptionsKey] delimitedBy:@" " withErrKey:kVMOptionsKey]];
+    [jvmOptions addObjectsFromArray:[self arrayFrom:[jvmInfo objectForKey:kArchVMOptionsKey] delimitedBy:@" " withErrKey:kArchVMOptionsKey]];
+
+    // 'Properties' key is a sub-dictionary transfered to initial System.properties
+    NSDictionary *properties = [jvmInfo objectForKey:@"Properties"];
+    if (properties != nil) {
+        if (![properties isKindOfClass:[NSDictionary class]]) {
+            [NSException raise:@kArgsFailure format:@"Failed to find 'Properties' dictionary in Info.plist JVMInfo"];
+        }
+
+        [properties enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
+            [jvmOptions addObject:[NSString stringWithFormat:@"-D%@=%@", key, obj]];
+        }];
+    }
+
+    // build the real JVM init args struct
+    vm_args.version = JNI_VERSION_1_6;
+    vm_args.ignoreUnrecognized = JNI_TRUE;
+    vm_args.nOptions = [jvmOptions count];
+    vm_args.options = calloc(vm_args.nOptions, sizeof(JavaVMOption));
+    [jvmOptions enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+        NSString *expanded = [self expandMacros:[obj description]]; // turn everything into a string, and expand macros
+        vm_args.options[idx].optionString = strdup([expanded UTF8String]);
+    }];
+}
+
++ (JVMArgs *)jvmArgsForBundle:(NSBundle *)appBundle argc:(int)argc argv:(char *[])argv {
+    JVMArgs *args = [JVMArgs new];
+    [args buildArgsForBundle:appBundle argc:argc argv:argv];
+    return [args autorelease];
+}
+
+@end
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher.h b/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher.h
new file mode 100644
index 0000000..5998fb6
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#import "jni.h"
+
+#import "JVMArgs.h"
+
+
+@interface JavaAppLauncher : NSObject {
+    JVMArgs *args;
+    JavaVM *jvm;
+}
+
+@property (retain) JVMArgs *args;
+
+- (void) findAndLoadJVM;
+- (void) invokeBundledAppJavaLauncherWithEnv:(JNIEnv *)env;
+
+@end
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher.m b/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher.m
new file mode 100644
index 0000000..b392cb6
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher.m
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "JavaAppLauncher.h"
+
+#import <dlfcn.h>
+
+#import "jni.h"
+
+#define kLaunchFailure "JavaAppLauncherFailure"
+
+
+typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);
+typedef void (JNICALL *SetPreferredJVM_t)(const char *prefJVM);
+
+
+@implementation JavaAppLauncher
+
+@synthesize args;
+
+- (void) findAndLoadJVM {
+    NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+    @try {
+        // load the libjli.dylib of the embedded JRE (or JDK) bundle
+        NSURL *jreBundleURL = [args.jreBundle bundleURL];
+        CFBundleRef jreBundle = CFBundleCreate(NULL, (CFURLRef)jreBundleURL);
+
+        NSError *err = nil;
+        Boolean jreBundleLoaded = CFBundleLoadExecutableAndReturnError(jreBundle, (CFErrorRef *)&err);
+        if (err != nil || !jreBundleLoaded) {
+            [NSException raise:@kLaunchFailure format:@"could not load the JRE/JDK: %@", err];
+        }
+
+        // if there is a preferred libjvm to load, set it here
+        if (args.preferredJVMLib != NULL) {
+            SetPreferredJVM_t setPrefJVMFxnPtr = CFBundleGetFunctionPointerForName(jreBundle, CFSTR("JLI_SetPreferredJVM"));
+            if (setPrefJVMFxnPtr != NULL) {
+                setPrefJVMFxnPtr(args.preferredJVMLib);
+            } else {
+                NSLog(@"No JLI_SetPreferredJVM in JRE/JDK primary executable, failed to set preferred JVM library to: %s", args->preferredJVMLib);
+            }
+        }
+
+        // pull the JNI_CreateJavaVM function pointer out of the primary executable of the JRE/JDK bundle
+        CreateJavaVM_t createJVMFxnPtr = CFBundleGetFunctionPointerForName(jreBundle, CFSTR("JNI_CreateJavaVM"));
+        if (createJVMFxnPtr == NULL) {
+            [NSException raise:@kLaunchFailure format:@"null JNI_CreateJavaVM fxn ptr from: %@", jreBundle];
+        }
+
+        // instantiate the JVM
+        JNIEnv *env;
+        jint createJVMStatus = createJVMFxnPtr(&jvm, (void **)&env, &(args->vm_args));
+        if (createJVMStatus != JNI_OK) {
+            [NSException raise:@kLaunchFailure format:@"failed to JNI_CreateJavaVM (%d): %@", createJVMStatus, jreBundle];
+        }
+
+        // check the app needs to run the Java main() on the main thread
+        if (args.startOnFirstThread) {
+            dispatch_sync(dispatch_get_main_queue(), ^(void) {
+                JNIEnv *mainThreadEnv;
+                (*jvm)->AttachCurrentThread(jvm, (void **)&mainThreadEnv, NULL);
+                [self invokeBundledAppJavaLauncherWithEnv:mainThreadEnv];
+                (*jvm)->DetachCurrentThread(jvm);
+            });
+        } else {
+            [self invokeBundledAppJavaLauncherWithEnv:env];
+        }
+
+    } @catch (NSException *e) {
+        NSLog(@"%@: %@", e, [e callStackSymbols]);
+    }
+
+    if (jvm) {
+        (*jvm)->DetachCurrentThread(jvm);
+        (*jvm)->DestroyJavaVM(jvm);
+    }
+
+    [pool drain];
+}
+
+static const char kLauncherClassName[] = "apple/launcher/JavaAppLauncher";
+
+- (void) invokeBundledAppJavaLauncherWithEnv:(JNIEnv *)env {
+    // hand off control to the apple.launcher.JavaAppLauncher class
+
+    jclass mainClass = (*env)->FindClass(env, kLauncherClassName);
+    if (mainClass == NULL) {
+        fprintf(stderr, kLaunchFailure " FindClass() failed for class %s:\n", kLauncherClassName);
+        (*env)->ExceptionDescribe(env);
+        return;
+    }
+
+    jmethodID mainMethod = (*env)->GetStaticMethodID(env, mainClass, "launch", "(JZ)V");
+    if ((mainMethod == NULL) || (*env)->ExceptionOccurred(env)) {
+        fprintf(stderr, kLaunchFailure " GetStaticMethodID() failed for launch() method");
+        (*env)->ExceptionDescribe(env);
+        return;
+    }
+
+    CFDictionaryRef jvmInfo = CFRetain(args.jvmInfo);
+
+    (*env)->CallStaticVoidMethod(env, mainClass, mainMethod, (jlong)jvmInfo, (jboolean)args.debug);
+    if ((*env)->ExceptionOccurred(env)) {
+        fprintf(stderr, kLaunchFailure " CallStaticVoidMethod() threw an exception\n");
+        (*env)->ExceptionDescribe(env);
+        return;
+    }
+}
+
+@end
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher_Prefix.pch b/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher_Prefix.pch
new file mode 100644
index 0000000..0453be7
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/src/JavaAppLauncher_Prefix.pch
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//
+// Prefix header for all source files of the 'JavaAppLauncher' target in the 'JavaAppLauncher' project
+//
+
+#ifdef __OBJC__
+    #import <Cocoa/Cocoa.h>
+#endif
diff --git a/jdk/src/macosx/bundle/JavaAppLauncher/src/main.m b/jdk/src/macosx/bundle/JavaAppLauncher/src/main.m
new file mode 100644
index 0000000..e3cf497
--- /dev/null
+++ b/jdk/src/macosx/bundle/JavaAppLauncher/src/main.m
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#import "JVMArgs.h"
+#import "JavaAppLauncher.h"
+
+
+static void dummyTimer(CFRunLoopTimerRef timer, void *info) {}
+static void ParkEventLoop() {
+    // RunLoop needs at least one source, and 1e20 is pretty far into the future
+    CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, 1.0e20, 0.0, 0, 0, dummyTimer, NULL);
+    CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode);
+    CFRelease(t);
+
+    // Park this thread in the main run loop.
+    int32_t result;
+    do {
+        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, false);
+    } while (result != kCFRunLoopRunFinished);
+}
+
+int main(int argc, char *argv[]) {
+    NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+    @try {
+        NSBundle *mainBundle = [NSBundle mainBundle];
+
+        // pick apart the Info.plist, and release all the temporary objects
+        NSAutoreleasePool *argParsingPool = [NSAutoreleasePool new];
+        JVMArgs *args = [JVMArgs jvmArgsForBundle:mainBundle argc:argc argv:argv];
+        JavaAppLauncher *launcher = [JavaAppLauncher new];
+        launcher.args = args;
+        [argParsingPool drain];
+
+        // kick off a new thread to instantiate the JVM on
+        NSThread *thread = [[NSThread alloc] initWithTarget:launcher selector:@selector(findAndLoadJVM) object:nil];
+        struct rlimit limit;
+        int err = getrlimit(RLIMIT_STACK, &limit);
+        if (err == 0 && limit.rlim_cur != 0LL) {
+            [thread setStackSize:limit.rlim_cur];
+        }
+        [thread start];
+        [thread release];
+
+        [launcher release];
+
+        ParkEventLoop();
+
+    } @catch (NSException *e) {
+        NSLog(@"%@: %@", e, [e callStackSymbols]);
+    }
+
+    [pool drain];
+
+    return 0;
+}
diff --git a/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java b/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java
new file mode 100644
index 0000000..06a20d7
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java
@@ -0,0 +1,388 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.applescript;
+
+import java.io.*;
+import java.util.*;
+import java.util.Map.Entry;
+
+import javax.script.*;
+
+/**
+ * AppleScriptEngine implements JSR 223 for AppleScript on Mac OS X
+ */
+public class AppleScriptEngine implements ScriptEngine {
+    private static native void initNative();
+
+    private static native long createContextFrom(final Object object);
+    private static native Object createObjectFrom(final long context);
+    private static native void disposeContext(final long context);
+
+    private static native long evalScript(final String script, long contextptr);
+    private static native long evalScriptFromURL(final String filename, long contextptr);
+
+    static {
+        System.loadLibrary("AppleScriptEngine");
+        initNative();
+        TRACE("<static-init>");
+    }
+
+    static void checkSecurity() {
+        final SecurityManager securityManager = System.getSecurityManager();
+        if (securityManager != null) securityManager.checkExec("/usr/bin/osascript");
+    }
+
+    static void TRACE(final String str) {
+//        System.out.println(AppleScriptEngine.class.getName() + "." + str);
+    }
+
+    /**
+     * Accessor for the ScriptEngine's long name variable
+     * @return the long name of the ScriptEngine
+     */
+    protected static String getEngine() {
+        TRACE("getEngine()");
+        return AppleScriptEngineFactory.ENGINE_NAME;
+    }
+
+    /**
+     * Accessor for the ScriptEngine's version
+     * @return the version of the ScriptEngine
+     */
+    protected static String getEngineVersion() {
+        TRACE("getEngineVersion()");
+        return AppleScriptEngineFactory.ENGINE_VERSION;
+    }
+
+    /**
+     * Accessor for the ScriptEngine's short name
+     * @return the short name of the ScriptEngine
+     */
+    protected static String getName() {
+        TRACE("getName()");
+        return AppleScriptEngineFactory.ENGINE_SHORT_NAME;
+    }
+
+    /**
+     * Accessor for the ScriptEngine's supported language name
+     * @return the language the ScriptEngine supports
+     */
+    protected static String getLanguage() {
+        TRACE("getLanguage()");
+        return AppleScriptEngineFactory.LANGUAGE;
+    }
+
+    /**
+     * The no argument constructor sets up the object with default members,
+     * a factory for the engine and a fresh context.
+     * @see com.apple.applescript.AppleScriptEngine#init()
+     */
+    public AppleScriptEngine() {
+        TRACE("<ctor>()");
+        // set our parent factory to be a new factory
+        factory = AppleScriptEngineFactory.getFactory();
+
+        // set up our noarg bindings
+        setContext(new SimpleScriptContext());
+        put(ARGV, "");
+
+        init();
+    }
+
+    /**
+     * All AppleScriptEngines share the same ScriptEngineFactory
+     */
+    private final ScriptEngineFactory factory;
+
+    /**
+     * The local context for the AppleScriptEngine
+     */
+    private ScriptContext context;
+
+    /**
+     * The constructor taking a factory as an argument sets the parent factory for
+     * this engine to be the passed factory, and sets up the engine with a fresh context
+     * @param factory
+     * @see com.apple.applescript.AppleScriptEngine#init()
+     */
+    public AppleScriptEngine(final ScriptEngineFactory factory) {
+        // inherit the factory passed to us
+        this.factory = factory;
+
+        // set up our noarg bindings
+        setContext(new SimpleScriptContext());
+        put(ARGV, "");
+
+        init();
+    }
+
+    /**
+     * The initializer populates the local context with some useful predefined variables:
+     * <ul><li><code>javax_script_language_version</code> - the version of AppleScript that the AppleScriptEngine supports.</li>
+     * <li><code>javax_script_language</code> - "AppleScript" -- the language supported by the AppleScriptEngine.</li>
+     * <li><code>javax_script_engine</code> - "AppleScriptEngine" -- the name of the ScriptEngine.</li>
+     * <li><code>javax_script_engine_version</code> - the version of the AppleScriptEngine</li>
+     * <li><code>javax_script_argv</code> - "" -- AppleScript does not take arguments from the command line</li>
+     * <li><code>javax_script_filename</code> - "" -- the currently executing filename</li>
+     * <li><code>javax_script_name</code> - "AppleScriptEngine" -- the short name of the AppleScriptEngine</li>
+     * <li><code>THREADING</code> - null -- the AppleScriptEngine does not support concurrency, you will have to implement thread-safeness yourself.</li></ul>
+     */
+    private void init() {
+        TRACE("init()");
+        // set up our context
+/* TODO -- name of current executable?  bad java documentation at:
+ * http://java.sun.com/javase/6/docs/api/javax/script/ScriptEngine.html#FILENAME */
+        put(ScriptEngine.FILENAME, "");
+        put(ScriptEngine.ENGINE, getEngine());
+        put(ScriptEngine.ENGINE_VERSION, getEngineVersion());
+        put(ScriptEngine.NAME, getName());
+        put(ScriptEngine.LANGUAGE, getLanguage());
+        put(ScriptEngine.LANGUAGE_VERSION, getLanguageVersion());
+
+        // TODO -- for now, err on the side of caution and say that we are NOT thread-safe
+        put("THREADING", null);
+    }
+
+    /**
+     * Uses the AppleScriptEngine to get the local AppleScript version
+     * @return the version of AppleScript running on the system
+     */
+    protected String getLanguageVersion() {
+        TRACE("AppleScriptEngine.getLanguageVersion()");
+        try {
+            final Object result = eval("get the version of AppleScript");
+            if (result instanceof String) return (String)result;
+        } catch (final ScriptException e) { e.printStackTrace(); }
+        return "unknown";
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Returns the factory parent of this AppleScriptEngine
+     */
+    public ScriptEngineFactory getFactory() {
+        return factory;
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Return the engine's context
+     * @return this ScriptEngine's context
+     */
+    public ScriptContext getContext() {
+        return context;
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Set a new context for the engine
+     * @param context the new context to install in the engine
+     */
+    public void setContext(final ScriptContext context) {
+        this.context = context;
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Create and return a new set of simple bindings.
+     * @return a new and empty set of bindings
+     */
+    public Bindings createBindings() {
+        return new SimpleBindings();
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Return the engines bindings for the context indicated by the argument.
+     * @param scope contextual scope to return.
+     * @return the bindings in the engine for the scope indicated by the parameter
+     */
+    public Bindings getBindings(final int scope) {
+        return context.getBindings(scope);
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Sets the bindings for the indicated scope
+     * @param bindings a set of bindings to assign to the engine
+     * @param scope the scope that the passed bindings should be assigned to
+     */
+    public void setBindings(final Bindings bindings, final int scope) {
+        context.setBindings(bindings, scope);
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Insert a key and value into the engine's bindings (scope: engine)
+     * @param key the key of the pair
+     * @param value the value of the pair
+     */
+    public void put(final String key, final Object value) {
+        getBindings(ScriptContext.ENGINE_SCOPE).put(key, value);
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Get a value from the engine's bindings using a key (scope: engine)
+     * @param key the key of the pair
+     * @return the value of the pair
+     */
+    public Object get(final String key) {
+        return getBindings(ScriptContext.ENGINE_SCOPE).get(key);
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Passes the Reader argument, as well as the engine's context to a lower evaluation function.<br />
+     * Prefers FileReader or BufferedReader wrapping FileReader as argument.
+     * @param reader a Reader to AppleScript source or compiled AppleScript
+     * @return an Object corresponding to the return value of the script
+     * @see com.apple.applescript.AppleScriptEngine#eval(Reader, ScriptContext)
+     */
+    public Object eval(final Reader reader) throws ScriptException {
+        return eval(reader, getContext());
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Uses the passed bindings as the context for executing the passed script.
+     * @param reader a stream to AppleScript source or compiled AppleScript
+     * @param bindings a Bindings object representing the contexts to execute inside
+     * @return the return value of the script
+     * @see com.apple.applescript.AppleScriptEngine#eval(Reader, ScriptContext)
+     */
+    public Object eval(final Reader reader, final Bindings bindings) throws ScriptException {
+        final Bindings tmp = getContext().getBindings(ScriptContext.ENGINE_SCOPE);
+        getContext().setBindings(bindings, ScriptContext.ENGINE_SCOPE);
+        final Object retval = eval(reader);
+        getContext().setBindings(tmp, ScriptContext.ENGINE_SCOPE);
+        return retval;
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * This function can execute either AppleScript source or compiled AppleScript and functions by writing the
+     * contents of the Reader to a temporary file and then executing it with the engine's context.
+     * @param reader
+     * @param scriptContext
+     * @return an Object corresponding to the return value of the script
+     */
+    public Object eval(final Reader reader, final ScriptContext context) throws ScriptException {
+        checkSecurity();
+
+        // write our passed reader to a temporary file
+        File tmpfile;
+        FileWriter tmpwrite;
+        try {
+            tmpfile = File.createTempFile("AppleScriptEngine.", ".scpt");
+            tmpwrite = new FileWriter(tmpfile);
+
+            // read in our input and write directly to tmpfile
+            /* TODO -- this may or may not be avoidable for certain Readers,
+             * if a filename can be grabbed, it would be faster to get that and
+             * use the underlying file than writing a temp file.
+             */
+            int data;
+            while ((data = reader.read()) != -1) {
+                tmpwrite.write(data);
+            }
+            tmpwrite.close();
+
+            // set up our context business
+            final long contextptr = scriptContextToNSDictionary(context);
+            try {
+                final long retCtx = evalScriptFromURL("file://" + tmpfile.getCanonicalPath(), contextptr);
+                Object retVal = (retCtx == 0) ? null : createObjectFrom(retCtx);
+                disposeContext(retCtx);
+                return retVal;
+            } finally {
+                disposeContext(contextptr);
+                tmpfile.delete();
+            }
+        } catch (final IOException e) {
+            throw new ScriptException(e);
+        }
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Evaluate an AppleScript script passed as a source string. Using the engine's built in context.
+     * @param script the string to execute.
+     * @return an Object representing the return value of the script
+     * @see com.apple.applescript.AppleScriptEngine#eval(String, ScriptContext)
+     */
+    public Object eval(final String script) throws ScriptException {
+        return eval(script, getContext());
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent<br />
+     * Evaluate an AppleScript script passed as a source string with a custom ScriptContext.
+     * @param script the AppleScript source to compile and execute.
+     * @param scriptContext the context to execute the script under
+     * @see com.apple.applescript.AppleScriptEngine#eval(String, ScriptContext)
+     */
+    public Object eval(final String script, final Bindings bindings) throws ScriptException {
+        final Bindings tmp = getContext().getBindings(ScriptContext.ENGINE_SCOPE);
+        getContext().setBindings(bindings, ScriptContext.ENGINE_SCOPE);
+
+        final Object retval = eval(script);
+        getContext().setBindings(tmp, ScriptContext.ENGINE_SCOPE);
+
+        return retval;
+    }
+
+    /**
+     * Implementation required by ScriptEngine parent
+     * @param script
+     * @param scriptContext
+     */
+    public Object eval(final String script, final ScriptContext context) throws ScriptException {
+        checkSecurity();
+        final long ctxPtr = scriptContextToNSDictionary(context);
+        try {
+            final long retCtx = evalScript(script, ctxPtr);
+            Object retVal = (retCtx == 0) ? null : createObjectFrom(retCtx);
+            disposeContext(retCtx);
+            return retVal;
+        } finally {
+            disposeContext(ctxPtr);
+        }
+    }
+
+    /**
+     * Converts a ScriptContext into an NSDictionary
+     * @param context ScriptContext for the engine
+     * @return a pointer to an NSDictionary
+     */
+    private long scriptContextToNSDictionary(final ScriptContext context) throws ScriptException {
+        final Map<String, Object> contextAsMap = new HashMap<String, Object>();
+        for (final Entry<String, Object> e : context.getBindings(ScriptContext.ENGINE_SCOPE).entrySet()) {
+            contextAsMap.put(e.getKey().replaceAll("\\.", "_"), e.getValue());
+        }
+        return createContextFrom(contextAsMap);
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/applescript/AppleScriptEngineFactory.java b/jdk/src/macosx/classes/apple/applescript/AppleScriptEngineFactory.java
new file mode 100644
index 0000000..c8fa48d
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/applescript/AppleScriptEngineFactory.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.applescript;
+
+import java.security.*;
+import java.util.*;
+import javax.script.*;
+
+public class AppleScriptEngineFactory implements ScriptEngineFactory {
+    private static native void initNative();
+
+    static {
+        java.awt.Toolkit.getDefaultToolkit();
+        System.loadLibrary("AppleScriptEngine");
+        initNative();
+        TRACE("<static-init>");
+    }
+
+    static void TRACE(final String str) {
+//        System.out.println(AppleScriptEngineFactory.class.getName() + "." + str);
+    }
+
+    /**
+     * The name of this ScriptEngine
+     */
+    static final String ENGINE_NAME = "AppleScriptEngine";
+
+    /**
+     * The version of this ScriptEngine
+     */
+    static final String ENGINE_VERSION = "1.1";
+
+    /**
+     * The name of this ScriptEngine (yes, again)
+     */
+    static final String ENGINE_SHORT_NAME = ENGINE_NAME;
+
+    /**
+     * The name of the language supported by this ScriptEngine
+     */
+    static final String LANGUAGE = "AppleScript";
+
+    static ScriptEngineFactory getFactory() {
+        TRACE("getFactory()");
+        return new AppleScriptEngineFactory();
+    }
+
+    /**
+     * Initialize a new AppleScriptEngineFactory, replete with a member AppleScriptEngine
+     */
+    public AppleScriptEngineFactory() {
+        TRACE("<ctor>()");
+    }
+
+    /**
+     * Returns the full name of the ScriptEngine.
+     *
+     * @return full name of the ScriptEngine
+     */
+    public String getEngineName() {
+        TRACE("getEngineName()");
+        return ENGINE_NAME;
+    }
+
+    /**
+     * Returns the version of the ScriptEngine.
+     *
+     * @return version of the ScriptEngine
+     */
+    public String getEngineVersion() {
+        TRACE("getEngineVersion()");
+        return ENGINE_VERSION;
+    }
+
+    /**
+     * Returns the name of the scripting language supported by this ScriptEngine.
+     *
+     * @return name of the language supported by the ScriptEngine(Factory)
+     */
+    public String getLanguageName() {
+        TRACE("getLanguageName()");
+        return LANGUAGE;
+    }
+
+    /**
+     * Returns the version of the scripting language supported by this ScriptEngine(Factory).
+     *
+     * @return language version supported by the ScriptEngine(Factory)
+     */
+    public String getLanguageVersion() {
+        TRACE("getLanguageVersion()");
+        return AccessController.doPrivileged(new PrivilegedAction<String>() {
+            public String run() {
+                final AppleScriptEngine engine = new AppleScriptEngine(AppleScriptEngineFactory.this);
+                return engine.getLanguageVersion();
+            }
+        });
+    }
+
+    /**
+     * Returns an immutable list of filename extensions, which generally identify
+     * scripts written in the language supported by this ScriptEngine.
+     *
+     * @return ArrayList of file extensions AppleScript associates with
+     */
+    public List<String> getExtensions() {
+        TRACE("getExtensions()");
+        return Arrays.asList("scpt", "applescript", "app");
+    }
+
+    /**
+     * Returns an immutable list of mimetypes, associated with scripts
+     * that can be executed by the engine.
+     *
+     * @return ArrayList of mimetypes that AppleScript associates with
+     */
+    public List<String> getMimeTypes() {
+        TRACE("getMimeTypes()");
+        return Arrays.asList("application/x-applescript", "text/plain", "text/applescript");
+    }
+
+    /**
+     * Returns an immutable list of short names for the ScriptEngine,
+     * which may be used to identify the ScriptEngine by the ScriptEngineManager.
+     *
+     * @return
+     */
+    public List<String> getNames() {
+        TRACE("getNames()");
+        return Arrays.asList("AppleScriptEngine", "AppleScript", "OSA");
+    }
+
+    /**
+     * Returns a String which can be used to invoke a method of a Java
+     * object using the syntax of the supported scripting language.
+     *
+     * @param obj
+     *            unused -- AppleScript does not support objects
+     * @param m
+     *            function name
+     * @param args
+     *            arguments to the function
+     * @return the AppleScript string calling the method
+     */
+    public String getMethodCallSyntax(final String obj, final String fname, final String ... args) {
+//        StringBuilder builder = new StringBuilder();
+//        builder.append("my " + fname + "(");
+//        // TODO -- do
+//        builder.append(")\n");
+//        return builder.toString();
+
+        return null;
+    }
+
+    /**
+     * Returns a String that can be used as a statement to display the specified String using the syntax of the supported scripting language.
+     *
+     * @param toDisplay
+     * @return
+     */
+    public String getOutputStatement(final String toDisplay) {
+        // TODO -- this might even be good enough? XD
+        return getMethodCallSyntax(null, "print", toDisplay);
+    }
+
+    /**
+     * Returns the value of an attribute whose meaning may be implementation-specific.
+     *
+     * @param key
+     *            the key to look up
+     * @return the static preseeded value for the key in the ScriptEngine, if it exists, otherwise <code>null</code>
+     */
+    public Object getParameter(final String key) {
+        final AppleScriptEngine engine = new AppleScriptEngine(this);
+        if (!engine.getBindings(ScriptContext.ENGINE_SCOPE).containsKey(key)) return null;
+        return engine.getBindings(ScriptContext.ENGINE_SCOPE).get(key);
+    }
+
+    /**
+     * Returns A valid scripting language executable program with given statements.
+     *
+     * @param statements
+     * @return
+     */
+    public String getProgram(final String ... statements) {
+        final StringBuilder program = new StringBuilder();
+        for (final String statement : statements) {
+            program.append(statement + "\n");
+        }
+        return program.toString();
+    }
+
+    /**
+     * Returns an instance of the ScriptEngine associated with this ScriptEngineFactory.
+     *
+     * @return new AppleScriptEngine with this factory as it's parent
+     */
+    public ScriptEngine getScriptEngine() {
+        AppleScriptEngine.checkSecurity();
+        return new AppleScriptEngine(this);
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/laf/AquaLookAndFeel.java b/jdk/src/macosx/classes/apple/laf/AquaLookAndFeel.java
new file mode 100644
index 0000000..ab4eaf0
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/laf/AquaLookAndFeel.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.laf;
+
+/*
+ * This class is essentially a placeholder since
+ * "apple.laf.AquaLookAndFeel" is so widely used, documented,
+ * and hard coded that it is impractical to remove it.
+ */
+public class AquaLookAndFeel extends com.apple.laf.AquaLookAndFeel { }
diff --git a/jdk/src/macosx/classes/apple/laf/JRSUIConstants.java b/jdk/src/macosx/classes/apple/laf/JRSUIConstants.java
new file mode 100644
index 0000000..37d1c5d
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/laf/JRSUIConstants.java
@@ -0,0 +1,835 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.laf;
+
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
+
+public final class JRSUIConstants {
+    private static native long getPtrForConstant(final int constant);
+
+    static class Key {
+        protected static final int _value = 20;
+        public static final Key VALUE = new Key(_value);
+
+        protected static final int _thumbProportion = 24;
+        public static final Key THUMB_PROPORTION = new Key(_thumbProportion);
+
+        protected static final int _thumbStart = 25;
+        public static final Key THUMB_START = new Key(_thumbStart);
+
+        protected static final int _windowTitleBarHeight = 28;
+        public static final Key WINDOW_TITLE_BAR_HEIGHT = new Key(_windowTitleBarHeight);
+
+        protected static final int _animationFrame = 23;
+        public static final Key ANIMATION_FRAME = new Key(_animationFrame);
+
+        final int constant;
+        private long ptr;
+
+        private Key(final int constant) {
+            this.constant = constant;
+        }
+
+        long getConstantPtr() {
+            if (ptr != 0) return ptr;
+            ptr = getPtrForConstant(constant);
+            if (ptr != 0) return ptr;
+            throw new RuntimeException("Constant not implemented in native: " + this);
+        }
+
+        public String toString() {
+            return getConstantName(this) + (ptr == 0 ? "(unlinked)" : "");
+        }
+    }
+
+    static class DoubleValue {
+        protected static final byte TYPE_CODE = 1;
+
+        final double doubleValue;
+
+        DoubleValue(final double doubleValue) {
+            this.doubleValue = doubleValue;
+        }
+
+        public byte getTypeCode() {
+            return TYPE_CODE;
+        }
+
+        public void putValueInBuffer(final ByteBuffer buffer) {
+            buffer.putDouble(doubleValue);
+        }
+
+        public boolean equals(final Object obj) {
+            return (obj instanceof DoubleValue) && (((DoubleValue)obj).doubleValue == doubleValue);
+        }
+
+        public int hashCode() {
+            final long bits = Double.doubleToLongBits(doubleValue);
+            return (int)(bits ^ (bits >>> 32));
+        }
+
+        public String toString() {
+            return Double.toString(doubleValue);
+        }
+    }
+
+
+    static class PropertyEncoding {
+        final long mask;
+        final byte shift;
+
+        PropertyEncoding(final long mask, final byte shift) {
+            this.mask = mask;
+            this.shift = shift;
+        }
+    }
+
+    static class Property {
+        final PropertyEncoding encoding;
+        final long value;
+        final byte ordinal;
+
+        Property(final PropertyEncoding encoding, final byte ordinal) {
+            this.encoding = encoding;
+            this.value = ((long)ordinal) << encoding.shift;
+            this.ordinal = ordinal;
+        }
+
+        /**
+         * Applies this property value to the provided state
+         * @param encodedState the incoming JRSUI encoded state
+         * @return the composite of the provided JRSUI encoded state and this value
+         */
+        public long apply(final long encodedState) {
+            return (encodedState & ~encoding.mask) | value;
+        }
+
+        public String toString() {
+            return getConstantName(this);
+        }
+    }
+
+    public static class Size extends Property {
+        private static final byte SHIFT = 0;
+        private static final byte SIZE = 3;
+        private static final long MASK = (long)0x7 << SHIFT;
+        private static final PropertyEncoding size = new PropertyEncoding(MASK, SHIFT);
+
+        Size(final byte value) {
+            super(size, value);
+        }
+
+        private static final byte _mini = 1;
+        public static final Size MINI = new Size(_mini);
+        private static final byte _small = 2;
+        public static final Size SMALL = new Size(_small);
+        private static final byte _regular = 3;
+        public static final Size REGULAR = new Size(_regular);
+        private static final byte _large = 4;
+        public static final Size LARGE = new Size(_large);
+    }
+
+    public static class State extends Property {
+        private static final byte SHIFT = Size.SHIFT + Size.SIZE;
+        private static final byte SIZE = 4;
+        private static final long MASK = (long)0xF << SHIFT;
+        private static final PropertyEncoding state = new PropertyEncoding(MASK, SHIFT);
+
+        State(final byte value) {
+            super(state, value);
+        }
+
+        private static final byte _active = 1;
+        public static final State ACTIVE = new State(_active);
+        private static final byte _inactive = 2;
+        public static final State INACTIVE = new State(_inactive);
+        private static final byte _disabled = 3;
+        public static final State DISABLED = new State(_disabled);
+        private static final byte _pressed = 4;
+        public static final State PRESSED = new State(_pressed);
+        private static final byte _pulsed = 5;
+        public static final State PULSED = new State(_pulsed);
+        private static final byte _rollover = 6;
+        public static final State ROLLOVER = new State(_rollover);
+        private static final byte _drag = 7;
+        public static final State DRAG = new State(_drag);
+    }
+
+    public static class Direction extends Property {
+        private static final byte SHIFT = State.SHIFT + State.SIZE;
+        private static final byte SIZE = 4;
+        private static final long MASK = (long)0xF << SHIFT;
+        private static final PropertyEncoding direction = new PropertyEncoding(MASK, SHIFT);
+
+        Direction(final byte value) {
+            super(direction, value);
+        }
+
+        private static final byte _none = 1;
+        public static final Direction NONE = new Direction(_none);
+        private static final byte _up = 2;
+        public static final Direction UP = new Direction(_up);
+        private static final byte _down = 3;
+        public static final Direction DOWN = new Direction(_down);
+        private static final byte _left = 4;
+        public static final Direction LEFT = new Direction(_left);
+        private static final byte _right = 5;
+        public static final Direction RIGHT = new Direction(_right);
+        private static final byte _north = 6;
+        public static final Direction NORTH = new Direction(_north);
+        private static final byte _south = 7;
+        public static final Direction SOUTH = new Direction(_south);
+        private static final byte _east = 8;
+        public static final Direction EAST = new Direction(_east);
+        private static final byte _west = 9;
+        public static final Direction WEST = new Direction(_west);
+    }
+
+    public static class Orientation extends Property {
+        private static final byte SHIFT = Direction.SHIFT + Direction.SIZE;
+        private static final byte SIZE = 2;
+        private static final long MASK = (long)0x3 << SHIFT;
+        private static final PropertyEncoding orientation = new PropertyEncoding(MASK, SHIFT);
+
+        Orientation(final byte value) {
+            super(orientation, value);
+        }
+
+        private static final byte _horizontal = 1;
+        public static final Orientation HORIZONTAL = new Orientation(_horizontal);
+        private static final byte _vertical = 2;
+        public static final Orientation VERTICAL = new Orientation(_vertical);
+    }
+
+    public static class AlignmentVertical extends Property {
+        private static final byte SHIFT = Orientation.SHIFT + Orientation.SIZE;
+        private static final byte SIZE = 2;
+        private static final long MASK = (long)0x3 << SHIFT;
+        private static final PropertyEncoding alignmentVertical = new PropertyEncoding(MASK, SHIFT);
+
+        AlignmentVertical(final byte value){
+            super(alignmentVertical, value);
+        }
+
+        private static final byte _top = 1;
+        public static final AlignmentVertical TOP = new AlignmentVertical(_top);
+        private static final byte _center = 2;
+        public static final AlignmentVertical CENTER = new AlignmentVertical(_center);
+        private static final byte _bottom = 3;
+        public static final AlignmentVertical BOTTOM = new AlignmentVertical(_bottom);
+    }
+
+    public static class AlignmentHorizontal extends Property {
+        private static final byte SHIFT = AlignmentVertical.SHIFT + AlignmentVertical.SIZE;
+        private static final byte SIZE = 2;
+        private static final long MASK = (long)0x3 << SHIFT;
+        private static final PropertyEncoding alignmentHorizontal = new PropertyEncoding(MASK, SHIFT);
+
+        AlignmentHorizontal(final byte value){
+            super(alignmentHorizontal, value);
+        }
+
+        private static final byte _left = 1;
+        public static final AlignmentHorizontal LEFT = new AlignmentHorizontal(_left);
+        private static final byte _center =  2;
+        public static final AlignmentHorizontal CENTER = new AlignmentHorizontal(_center);
+        private static final byte _right = 3;
+        public static final AlignmentHorizontal RIGHT = new AlignmentHorizontal(_right);
+    }
+
+    public static class SegmentPosition extends Property {
+        private static final byte SHIFT = AlignmentHorizontal.SHIFT + AlignmentHorizontal.SIZE;
+        private static final byte SIZE = 3;
+        private static final long MASK = (long)0x7 << SHIFT;
+        private static final PropertyEncoding segmentPosition = new PropertyEncoding(MASK, SHIFT);
+
+        SegmentPosition(final byte value) {
+            super(segmentPosition, value);
+        }
+
+        private static final byte _first = 1;
+        public static final SegmentPosition FIRST = new SegmentPosition(_first);
+        private static final byte _middle = 2;
+        public static final SegmentPosition MIDDLE = new SegmentPosition(_middle);
+        private static final byte _last = 3;
+        public static final SegmentPosition LAST = new SegmentPosition(_last);
+        private static final byte _only = 4;
+        public static final SegmentPosition ONLY = new SegmentPosition(_only);
+    }
+
+    public static class ScrollBarPart extends Property {
+        private static final byte SHIFT = SegmentPosition.SHIFT + SegmentPosition.SIZE;
+        private static final byte SIZE = 4;
+        private static final long MASK = (long)0xF << SHIFT;
+        private static final PropertyEncoding scrollBarPart = new PropertyEncoding(MASK, SHIFT);
+
+        ScrollBarPart(final byte value) {
+            super(scrollBarPart, value);
+        }
+
+        private static final byte _none = 1;
+        public static final ScrollBarPart NONE = new ScrollBarPart(_none);
+        private static final byte _thumb = 2;
+        public static final ScrollBarPart THUMB = new ScrollBarPart(_thumb);
+        private static final byte _arrowMin = 3;
+        public static final ScrollBarPart ARROW_MIN = new ScrollBarPart(_arrowMin);
+        private static final byte _arrowMax = 4;
+        public static final ScrollBarPart ARROW_MAX = new ScrollBarPart(_arrowMax);
+        private static final byte _arrowMaxInside = 5;
+        public static final ScrollBarPart ARROW_MAX_INSIDE = new ScrollBarPart(_arrowMaxInside);
+        private static final byte _arrowMinInside = 6;
+        public static final ScrollBarPart ARROW_MIN_INSIDE = new ScrollBarPart(_arrowMinInside);
+        private static final byte _trackMin = 7;
+        public static final ScrollBarPart TRACK_MIN = new ScrollBarPart(_trackMin);
+        private static final byte _trackMax = 8;
+        public static final ScrollBarPart TRACK_MAX = new ScrollBarPart(_trackMax);
+    }
+
+    public static class Variant extends Property {
+        private static final byte SHIFT = ScrollBarPart.SHIFT + ScrollBarPart.SIZE;
+        private static final byte SIZE = 4;
+        private static final long MASK = (long)0xF << SHIFT;
+        private static final PropertyEncoding variant = new PropertyEncoding(MASK, SHIFT);
+
+        Variant(final byte value) {
+            super(variant, value);
+        }
+
+        private static final byte _menuGlyph = 1;
+        public static final Variant MENU_GLYPH = new Variant(_menuGlyph);
+        private static final byte _menuPopup = Variant._menuGlyph + 1;
+        public static final Variant MENU_POPUP = new Variant(_menuPopup);
+        private static final byte _menuPulldown = Variant._menuPopup + 1;
+        public static final Variant MENU_PULLDOWN = new Variant(_menuPulldown);
+        private static final byte _menuHierarchical = Variant._menuPulldown + 1;
+        public static final Variant MENU_HIERARCHICAL = new Variant(_menuHierarchical);
+
+        private static final byte _gradientListBackgroundEven = Variant._menuHierarchical + 1;
+        public static final Variant GRADIENT_LIST_BACKGROUND_EVEN = new Variant(_gradientListBackgroundEven);
+        private static final byte _gradientListBackgroundOdd = Variant._gradientListBackgroundEven + 1;
+        public static final Variant GRADIENT_LIST_BACKGROUND_ODD = new Variant(_gradientListBackgroundOdd);
+        private static final byte _gradientSideBar = Variant._gradientListBackgroundOdd + 1;
+        public static final Variant GRADIENT_SIDE_BAR = new Variant(_gradientSideBar);
+        private static final byte _gradientSideBarSelection = Variant._gradientSideBar + 1;
+        public static final Variant GRADIENT_SIDE_BAR_SELECTION = new Variant(_gradientSideBarSelection);
+        private static final byte _gradientSideBarFocusedSelection = Variant._gradientSideBarSelection + 1;
+        public static final Variant GRADIENT_SIDE_BAR_FOCUSED_SELECTION = new Variant(_gradientSideBarFocusedSelection);
+    }
+
+    public static class WindowType extends Property {
+        private static final byte SHIFT = Variant.SHIFT + Variant.SIZE;
+        private static final byte SIZE = 2;
+        private static final long MASK = (long)0x3 << SHIFT;
+        private static final PropertyEncoding windowType = new PropertyEncoding(MASK, SHIFT);
+
+        WindowType(final byte value){
+            super(windowType, value);
+        }
+
+        private static final byte _document = 1;
+        public static final WindowType DOCUMENT = new WindowType(_document);
+        private static final byte _utility = 2;
+        public static final WindowType UTILITY = new WindowType(_utility);
+        private static final byte _titlelessUtility = 3;
+        public static final WindowType TITLELESS_UTILITY = new WindowType(_titlelessUtility);
+    }
+
+    public static class Focused extends Property {
+        private static final byte SHIFT = WindowType.SHIFT + WindowType.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding focused = new PropertyEncoding(MASK, SHIFT);
+
+        Focused(final byte value) {
+            super(focused, value);
+        }
+
+        private static final byte _no = 0;
+        public static final Focused NO = new Focused(_no);
+        private static final byte _yes = 1;
+        public static final Focused YES = new Focused(_yes);
+    }
+
+    public static class IndicatorOnly extends Property {
+        private static final byte SHIFT = Focused.SHIFT + Focused.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding indicatorOnly = new PropertyEncoding(MASK, SHIFT);
+
+        IndicatorOnly(final byte value) {
+            super(indicatorOnly, value);
+        }
+
+        private static final byte _no = 0;
+        public static final IndicatorOnly NO = new IndicatorOnly(_no);
+        private static final byte _yes = 1;
+        public static final IndicatorOnly YES = new IndicatorOnly(_yes);
+    }
+
+    public static class NoIndicator extends Property {
+        private static final byte SHIFT = IndicatorOnly.SHIFT + IndicatorOnly.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding noIndicator = new PropertyEncoding(MASK, SHIFT);
+
+        NoIndicator(final byte value) {
+            super(noIndicator, value);
+        }
+
+        private static final byte _no = 0;
+        public static final NoIndicator NO = new NoIndicator(_no);
+        private static final byte _yes = 1;
+        public static final NoIndicator YES = new NoIndicator(_yes);
+    }
+
+    public static class ArrowsOnly extends Property {
+        private static final byte SHIFT = NoIndicator.SHIFT + NoIndicator.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding focused = new PropertyEncoding(MASK, SHIFT);
+
+        ArrowsOnly(final byte value) {
+            super(focused, value);
+        }
+
+        private static final byte _no = 0;
+        public static final ArrowsOnly NO = new ArrowsOnly(_no);
+        private static final byte _yes = 1;
+        public static final ArrowsOnly YES = new ArrowsOnly(_yes);
+    }
+
+    public static class FrameOnly extends Property {
+        private static final byte SHIFT = ArrowsOnly.SHIFT + ArrowsOnly.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding focused = new PropertyEncoding(MASK, SHIFT);
+
+        FrameOnly(final byte value) {
+            super(focused, value);
+        }
+
+        private static final byte _no = 0;
+        public static final FrameOnly NO = new FrameOnly(_no);
+        private static final byte _yes = 1;
+        public static final FrameOnly YES = new FrameOnly(_yes);
+    }
+
+    public static class SegmentTrailingSeparator extends Property {
+        private static final byte SHIFT = FrameOnly.SHIFT + FrameOnly.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding focused = new PropertyEncoding(MASK, SHIFT);
+
+        SegmentTrailingSeparator(final byte value) {
+            super(focused, value);
+        }
+
+        private static final byte _no = 0;
+        public static final SegmentTrailingSeparator NO = new SegmentTrailingSeparator(_no);
+        private static final byte _yes = 1;
+        public static final SegmentTrailingSeparator YES = new SegmentTrailingSeparator(_yes);
+    }
+
+    public static class SegmentLeadingSeparator extends Property {
+        private static final byte SHIFT = SegmentTrailingSeparator.SHIFT + SegmentTrailingSeparator.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding leadingSeparator = new PropertyEncoding(MASK, SHIFT);
+
+        SegmentLeadingSeparator(final byte value) {
+            super(leadingSeparator, value);
+        }
+
+        private static final byte _no = 0;
+        public static final SegmentLeadingSeparator NO = new SegmentLeadingSeparator(_no);
+        private static final byte _yes = 1;
+        public static final SegmentLeadingSeparator YES = new SegmentLeadingSeparator(_yes);
+    }
+
+    public static class NothingToScroll extends Property {
+        private static final byte SHIFT = SegmentLeadingSeparator.SHIFT + SegmentLeadingSeparator.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding focused = new PropertyEncoding(MASK, SHIFT);
+
+        NothingToScroll(final byte value) {
+            super(focused, value);
+        }
+
+        private static final byte _no = 0;
+        public static final NothingToScroll NO = new NothingToScroll(_no);
+        private static final byte _yes = 1;
+        public static final NothingToScroll YES = new NothingToScroll(_yes);
+    }
+
+    public static class WindowTitleBarSeparator extends Property {
+        private static final byte SHIFT = NothingToScroll.SHIFT + NothingToScroll.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding focused = new PropertyEncoding(MASK, SHIFT);
+
+        WindowTitleBarSeparator(final byte value) {
+            super(focused, value);
+        }
+
+        private static final byte _no = 0;
+        public static final WindowTitleBarSeparator NO = new WindowTitleBarSeparator(_no);
+        private static final byte _yes = 1;
+        public static final WindowTitleBarSeparator YES = new WindowTitleBarSeparator(_yes);
+    }
+
+    public static class WindowClipCorners extends Property {
+        private static final byte SHIFT = WindowTitleBarSeparator.SHIFT + WindowTitleBarSeparator.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding focused = new PropertyEncoding(MASK, SHIFT);
+
+        WindowClipCorners(final byte value) {
+            super(focused, value);
+        }
+
+        private static final byte _no = 0;
+        public static final WindowClipCorners NO = new WindowClipCorners(_no);
+        private static final byte _yes = 1;
+        public static final WindowClipCorners YES = new WindowClipCorners(_yes);
+    }
+
+    public static class ShowArrows extends Property {
+        private static final byte SHIFT = WindowClipCorners.SHIFT + WindowClipCorners.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding showArrows = new PropertyEncoding(MASK, SHIFT);
+
+        ShowArrows(final byte value) {
+            super(showArrows, value);
+        }
+
+        private static final byte _no = 0;
+        public static final ShowArrows NO = new ShowArrows(_no);
+        private static final byte _yes = 1;
+        public static final ShowArrows YES = new ShowArrows(_yes);
+    }
+
+    public static class BooleanValue extends Property {
+        private static final byte SHIFT = ShowArrows.SHIFT + ShowArrows.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding booleanValue = new PropertyEncoding(MASK, SHIFT);
+
+        BooleanValue(final byte value) {
+            super(booleanValue, value);
+        }
+
+        private static final byte _no = 0;
+        public static final BooleanValue NO = new BooleanValue(_no);
+        private static final byte _yes = 1;
+        public static final BooleanValue YES = new BooleanValue(_yes);
+    }
+
+    public static class Animating extends Property {
+        private static final byte SHIFT = BooleanValue.SHIFT + BooleanValue.SIZE;
+        private static final byte SIZE = 1;
+        private static final long MASK = (long)0x1 << SHIFT;
+        private static final PropertyEncoding animating = new PropertyEncoding(MASK, SHIFT);
+
+        Animating(final byte value) {
+            super(animating, value);
+        }
+
+        private static final byte _no = 0;
+        public static final Animating NO = new Animating(_no);
+        private static final byte _yes = 1;
+        public static final Animating YES = new Animating(_yes);
+    }
+
+    public static class Widget extends Property {
+        private static final byte SHIFT = Animating.SHIFT + Animating.SIZE;
+        private static final byte SIZE = 7;
+        private static final long MASK = (long)0x7F << SHIFT;
+        private static final PropertyEncoding widget = new PropertyEncoding(MASK, SHIFT);
+
+        Widget(final byte constant) {
+            super(widget, constant);
+        }
+
+        private static final byte _background = 1;
+        public static final Widget BACKGROUND = new Widget(_background);
+
+        private static final byte _buttonBevel = _background + 1;
+        public static final Widget BUTTON_BEVEL = new Widget(_buttonBevel);
+        private static final byte _buttonBevelInset = _buttonBevel + 1;
+        public static final Widget BUTTON_BEVEL_INSET = new Widget(_buttonBevelInset);
+        private static final byte _buttonBevelRound = _buttonBevelInset + 1;
+        public static final Widget BUTTON_BEVEL_ROUND = new Widget(_buttonBevelRound);
+
+        private static final byte _buttonCheckBox = _buttonBevelRound + 1;
+        public static final Widget BUTTON_CHECK_BOX = new Widget(_buttonCheckBox);
+
+        private static final byte _buttonComboBox = _buttonCheckBox + 1;
+        public static final Widget BUTTON_COMBO_BOX = new Widget(_buttonComboBox);
+        private static final byte _buttonComboBoxInset = _buttonComboBox + 1;
+        public static final Widget BUTTON_COMBO_BOX_INSET = new Widget(_buttonComboBoxInset); // not hooked up in JRSUIConstants.m
+
+        private static final byte _buttonDisclosure = _buttonComboBoxInset + 1;
+        public static final Widget BUTTON_DISCLOSURE = new Widget(_buttonDisclosure);
+
+        private static final byte _buttonListHeader = _buttonDisclosure + 1;
+        public static final Widget BUTTON_LIST_HEADER = new Widget(_buttonListHeader);
+
+        private static final byte _buttonLittleArrows = _buttonListHeader + 1;
+        public static final Widget BUTTON_LITTLE_ARROWS = new Widget(_buttonLittleArrows);
+
+        private static final byte _buttonPopDown = _buttonLittleArrows + 1;
+        public static final Widget BUTTON_POP_DOWN = new Widget(_buttonPopDown);
+        private static final byte _buttonPopDownInset = _buttonPopDown + 1;
+        public static final Widget BUTTON_POP_DOWN_INSET = new Widget(_buttonPopDownInset);
+        private static final byte _buttonPopDownSquare = _buttonPopDownInset + 1;
+        public static final Widget BUTTON_POP_DOWN_SQUARE = new Widget(_buttonPopDownSquare);
+
+        private static final byte _buttonPopUp = _buttonPopDownSquare + 1;
+        public static final Widget BUTTON_POP_UP = new Widget(_buttonPopUp);
+        private static final byte _buttonPopUpInset = _buttonPopUp + 1;
+        public static final Widget BUTTON_POP_UP_INSET = new Widget(_buttonPopUpInset);
+        private static final byte _buttonPopUpSquare = _buttonPopUpInset + 1;
+        public static final Widget BUTTON_POP_UP_SQUARE = new Widget(_buttonPopUpSquare);
+
+        private static final byte _buttonPush = _buttonPopUpSquare + 1;
+        public static final Widget BUTTON_PUSH = new Widget(_buttonPush);
+        private static final byte _buttonPushScope = _buttonPush + 1;
+        public static final Widget BUTTON_PUSH_SCOPE = new Widget(_buttonPushScope);
+        private static final byte _buttonPushScope2 = _buttonPushScope + 1;
+        public static final Widget BUTTON_PUSH_SCOPE2 = new Widget(_buttonPushScope2);
+        private static final byte _buttonPushTextured = _buttonPushScope2 + 1;
+        public static final Widget BUTTON_PUSH_TEXTURED = new Widget(_buttonPushTextured);
+        private static final byte _buttonPushInset = _buttonPushTextured + 1;
+        public static final Widget BUTTON_PUSH_INSET = new Widget(_buttonPushInset);
+        private static final byte _buttonPushInset2 = _buttonPushInset + 1;
+        public static final Widget BUTTON_PUSH_INSET2 = new Widget(_buttonPushInset2);
+
+        private static final byte _buttonRadio = _buttonPushInset2 + 1;
+        public static final Widget BUTTON_RADIO = new Widget(_buttonRadio);
+
+        private static final byte _buttonRound = _buttonRadio + 1;
+        public static final Widget BUTTON_ROUND = new Widget(_buttonRound);
+        private static final byte _buttonRoundHelp = _buttonRound + 1;
+        public static final Widget BUTTON_ROUND_HELP = new Widget(_buttonRoundHelp);
+        private static final byte _buttonRoundInset = _buttonRoundHelp + 1;
+        public static final Widget BUTTON_ROUND_INSET = new Widget(_buttonRoundInset);
+        private static final byte _buttonRoundInset2 =_buttonRoundInset + 1;
+        public static final Widget BUTTON_ROUND_INSET2 = new Widget(_buttonRoundInset2);
+
+        private static final byte _buttonSearchFieldCancel = _buttonRoundInset2 + 1;
+        public static final Widget BUTTON_SEARCH_FIELD_CANCEL = new Widget(_buttonSearchFieldCancel);
+        private static final byte _buttonSearchFieldFind = _buttonSearchFieldCancel + 1;
+        public static final Widget BUTTON_SEARCH_FIELD_FIND = new Widget(_buttonSearchFieldFind);
+
+        private static final byte _buttonSegmented = _buttonSearchFieldFind + 1;
+        public static final Widget BUTTON_SEGMENTED = new Widget(_buttonSegmented);
+        private static final byte _buttonSegmentedInset = _buttonSegmented + 1;
+        public static final Widget BUTTON_SEGMENTED_INSET = new Widget(_buttonSegmentedInset);
+        private static final byte _buttonSegmentedInset2 = _buttonSegmentedInset + 1;
+        public static final Widget BUTTON_SEGMENTED_INSET2 = new Widget(_buttonSegmentedInset2);
+        private static final byte _buttonSegmentedSCurve = _buttonSegmentedInset2 + 1;
+        public static final Widget BUTTON_SEGMENTED_SCURVE = new Widget(_buttonSegmentedSCurve);
+        private static final byte _buttonSegmentedTextured = _buttonSegmentedSCurve + 1;
+        public static final Widget BUTTON_SEGMENTED_TEXTURED = new Widget(_buttonSegmentedTextured);
+        private static final byte _buttonSegmentedToolbar = _buttonSegmentedTextured + 1;
+        public static final Widget BUTTON_SEGMENTED_TOOLBAR = new Widget(_buttonSegmentedToolbar);
+
+        private static final byte _dial = _buttonSegmentedToolbar + 1;
+        public static final Widget DIAL = new Widget(_dial);
+
+        private static final byte _disclosureTriangle = _dial + 1;
+        public static final Widget DISCLOSURE_TRIANGLE = new Widget(_disclosureTriangle);
+
+        private static final byte _dividerGrabber = _disclosureTriangle + 1;
+        public static final Widget DIVIDER_GRABBER = new Widget(_dividerGrabber);
+        private static final byte _dividerSeparatorBar = _dividerGrabber + 1;
+        public static final Widget DIVIDER_SEPARATOR_BAR = new Widget(_dividerSeparatorBar);
+        private static final byte _dividerSplitter = _dividerSeparatorBar + 1;
+        public static final Widget DIVIDER_SPLITTER = new Widget(_dividerSplitter);
+
+        private static final byte _focus = _dividerSplitter + 1;
+        public static final Widget FOCUS = new Widget(_focus);
+
+        private static final byte _frameGroupBox = _focus + 1;
+        public static final Widget FRAME_GROUP_BOX = new Widget(_frameGroupBox);
+        private static final byte _frameGroupBoxSecondary = _frameGroupBox + 1;
+        public static final Widget FRAME_GROUP_BOX_SECONDARY = new Widget(_frameGroupBoxSecondary);
+
+        private static final byte _frameListBox = _frameGroupBoxSecondary + 1;
+        public static final Widget FRAME_LIST_BOX = new Widget(_frameListBox);
+
+        private static final byte _framePlacard = _frameListBox + 1;
+        public static final Widget FRAME_PLACARD = new Widget(_framePlacard);
+
+        private static final byte _frameTextField = _framePlacard + 1;
+        public static final Widget FRAME_TEXT_FIELD = new Widget(_frameTextField);
+        private static final byte _frameTextFieldRound = _frameTextField + 1;
+        public static final Widget FRAME_TEXT_FIELD_ROUND = new Widget(_frameTextFieldRound);
+
+        private static final byte _frameWell = _frameTextFieldRound + 1;
+        public static final Widget FRAME_WELL = new Widget(_frameWell);
+
+        private static final byte _growBox = _frameWell + 1;
+        public static final Widget GROW_BOX = new Widget(_growBox);
+        private static final byte _growBoxTextured = _growBox + 1;
+        public static final Widget GROW_BOX_TEXTURED = new Widget(_growBoxTextured);
+
+        private static final byte _gradient = _growBoxTextured + 1;
+        public static final Widget GRADIENT = new Widget(_gradient);
+
+        private static final byte _menu = _gradient + 1;
+        public static final Widget MENU = new Widget(_menu);
+        private static final byte _menuItem = _menu + 1;
+        public static final Widget MENU_ITEM = new Widget(_menuItem);
+        private static final byte _menuBar = _menuItem + 1;
+        public static final Widget MENU_BAR = new Widget(_menuBar);
+        private static final byte _menuTitle = _menuBar + 1;
+        public static final Widget MENU_TITLE = new Widget(_menuTitle);
+
+        private static final byte _progressBar = _menuTitle + 1;
+        public static final Widget PROGRESS_BAR = new Widget(_progressBar);
+        private static final byte _progressIndeterminateBar = _progressBar + 1;
+        public static final Widget PROGRESS_INDETERMINATE_BAR = new Widget(_progressIndeterminateBar);
+        private static final byte _progressRelevance = _progressIndeterminateBar + 1;
+        public static final Widget PROGRESS_RELEVANCE = new Widget(_progressRelevance);
+        private static final byte _progressSpinner = _progressRelevance + 1;
+        public static final Widget PROGRESS_SPINNER = new Widget(_progressSpinner);
+
+        private static final byte _scrollBar = _progressSpinner + 1;
+        public static final Widget SCROLL_BAR = new Widget(_scrollBar);
+
+        private static final byte _scrollColumnSizer = _scrollBar + 1;
+        public static final Widget SCROLL_COLUMN_SIZER = new Widget(_scrollColumnSizer);
+
+        private static final byte _slider = _scrollColumnSizer + 1;
+        public static final Widget SLIDER = new Widget(_slider);
+        private static final byte _sliderThumb = _slider + 1;
+        public static final Widget SLIDER_THUMB = new Widget(_sliderThumb);
+
+        private static final byte _synchronization = _sliderThumb + 1;
+        public static final Widget SYNCHRONIZATION = new Widget(_synchronization);
+
+        private static final byte _tab = _synchronization + 1;
+        public static final Widget TAB = new Widget(_tab);
+
+        private static final byte _titleBarCloseBox = _tab + 1;
+        public static final Widget TITLE_BAR_CLOSE_BOX = new Widget(_titleBarCloseBox);
+        private static final byte _titleBarCollapseBox = _titleBarCloseBox + 1;
+        public static final Widget TITLE_BAR_COLLAPSE_BOX = new Widget(_titleBarCollapseBox);
+        private static final byte _titleBarZoomBox = _titleBarCollapseBox + 1;
+        public static final Widget TITLE_BAR_ZOOM_BOX = new Widget(_titleBarZoomBox);
+
+        private static final byte _titleBarToolbarButton = _titleBarZoomBox + 1;
+        public static final Widget TITLE_BAR_TOOLBAR_BUTTON = new Widget(_titleBarToolbarButton);
+
+        private static final byte _toolbarItemWell = _titleBarToolbarButton + 1;
+        public static final Widget TOOLBAR_ITEM_WELL = new Widget(_toolbarItemWell);
+
+        private static final byte _windowFrame = _toolbarItemWell + 1;
+        public static final Widget WINDOW_FRAME = new Widget(_windowFrame);
+    }
+
+    public static class Hit {
+        private static final int _unknown = -1;
+        public static final Hit UNKNOWN = new Hit(_unknown);
+        private static final int _none = 0;
+        public static final Hit NONE = new Hit(_none);
+        private static final int _hit = 1;
+        public static final Hit HIT = new Hit(_hit);
+
+        final int hit;
+        Hit(final int hit) { this.hit = hit; }
+
+        public boolean isHit() {
+            return hit > 0;
+        }
+
+        public String toString() {
+            return getConstantName(this);
+        }
+    }
+
+    public static class ScrollBarHit extends Hit {
+        private static final int _thumb = 2;
+        public static final ScrollBarHit THUMB = new ScrollBarHit(_thumb);
+
+        private static final int _trackMin = 3;
+        public static final ScrollBarHit TRACK_MIN = new ScrollBarHit(_trackMin);
+        private static final int _trackMax = 4;
+        public static final ScrollBarHit TRACK_MAX = new ScrollBarHit(_trackMax);
+
+        private static final int _arrowMin = 5;
+        public static final ScrollBarHit ARROW_MIN = new ScrollBarHit(_arrowMin);
+        private static final int _arrowMax = 6;
+        public static final ScrollBarHit ARROW_MAX = new ScrollBarHit(_arrowMax);
+        private static final int _arrowMaxInside = 7;
+        public static final ScrollBarHit ARROW_MAX_INSIDE = new ScrollBarHit(_arrowMaxInside);
+        private static final int _arrowMinInside = 8;
+        public static final ScrollBarHit ARROW_MIN_INSIDE = new ScrollBarHit(_arrowMinInside);
+
+        ScrollBarHit(final int hit) { super(hit); }
+    }
+
+    static Hit getHit(final int hit) {
+        switch (hit) {
+            case Hit._none:
+                return Hit.NONE;
+            case Hit._hit:
+                return Hit.HIT;
+
+            case ScrollBarHit._thumb:
+                return ScrollBarHit.THUMB;
+            case ScrollBarHit._trackMin:
+                return ScrollBarHit.TRACK_MIN;
+            case ScrollBarHit._trackMax:
+                return ScrollBarHit.TRACK_MAX;
+            case ScrollBarHit._arrowMin:
+                return ScrollBarHit.ARROW_MIN;
+            case ScrollBarHit._arrowMax:
+                return ScrollBarHit.ARROW_MAX;
+            case ScrollBarHit._arrowMaxInside:
+                return ScrollBarHit.ARROW_MAX_INSIDE;
+            case ScrollBarHit._arrowMinInside:
+                return ScrollBarHit.ARROW_MIN_INSIDE;
+        }
+        return Hit.UNKNOWN;
+    }
+
+    static String getConstantName(final Object object) {
+        final Class<? extends Object> clazz = object.getClass();
+        try {
+            for (final Field field : clazz.getFields()) {
+                if (field.get(null) == object) {
+                    return field.getName();
+                }
+            }
+        } catch (final Exception e) {}
+        return clazz.getSimpleName();
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/laf/JRSUIControl.java b/jdk/src/macosx/classes/apple/laf/JRSUIControl.java
new file mode 100644
index 0000000..f36bbcd
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/laf/JRSUIControl.java
@@ -0,0 +1,351 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.laf;
+
+import java.nio.*;
+import java.util.*;
+
+import apple.laf.JRSUIConstants.*;
+
+public final class JRSUIControl {
+    private static native int initNativeJRSUI();
+
+    private static native long getPtrOfBuffer(ByteBuffer byteBuffer);
+    private static native long getCFDictionary(boolean flipped);
+    private static native void disposeCFDictionary(long cfDictionaryPtr);
+
+    private static native int syncChanges(long cfDictionaryPtr, long byteBufferPtr);
+
+//    private static native int paint(long cfDictionaryPtr, long oldProperties, long newProperties, OSXSurfaceData osxsd, double x, double y, double w, double h);
+//    private static native int paintChanges(long cfDictionaryPtr, long byteBufferPtr, long oldProperties, long newProperties, OSXSurfaceData osxsd, double x, double y, double w, double h);
+
+    private static native int paintToCGContext                    (long cgContext,    long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h);
+    private static native int paintChangesToCGContext            (long cgContext,    long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, long byteBufferPtr);
+
+    private static native int paintImage        (int[] data, int imgW, int imgH,    long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h);
+    private static native int paintChangesImage    (int[] data, int imgW, int imgH,    long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, long byteBufferPtr);
+
+    private static native int getNativeHitPart(                            long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, double hitX, double hitY);
+    private static native void getNativePartBounds(final double[] rect,    long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, int part);
+    private static native double getNativeScrollBarOffsetChange(        long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, int offset, int visibleAmount, int extent);
+
+    private static final int INCOHERENT = 2;
+    private static final int NOT_INIT = 1;
+    private static final int SUCCESS = 0;
+    private static final int NULL_PTR = -1;
+    private static final int NULL_CG_REF = -2;
+
+    private static int nativeJRSInitialized = NOT_INIT;
+
+
+    public static void initJRSUI() {
+        if (nativeJRSInitialized == SUCCESS) return;
+        nativeJRSInitialized = initNativeJRSUI();
+        if (nativeJRSInitialized != SUCCESS) throw new RuntimeException("JRSUI could not be initialized (" + nativeJRSInitialized + ").");
+    }
+
+    private static final int NIO_BUFFER_SIZE = 128;
+    private static class ThreadLocalByteBuffer {
+        final ByteBuffer buffer;
+        final long ptr;
+
+        public ThreadLocalByteBuffer() {
+            buffer = ByteBuffer.allocateDirect(NIO_BUFFER_SIZE);
+            buffer.order(ByteOrder.nativeOrder());
+            ptr = getPtrOfBuffer(buffer);
+        }
+    }
+
+    private static final ThreadLocal<ThreadLocalByteBuffer> threadLocal = new ThreadLocal<ThreadLocalByteBuffer>();
+    private static ThreadLocalByteBuffer getThreadLocalBuffer() {
+        ThreadLocalByteBuffer byteBuffer = threadLocal.get();
+        if (byteBuffer != null) return byteBuffer;
+
+        byteBuffer = new ThreadLocalByteBuffer();
+        threadLocal.set(byteBuffer);
+        return byteBuffer;
+    }
+
+    private final HashMap<Key, DoubleValue> nativeMap;
+    private final HashMap<Key, DoubleValue> changes;
+    private long cfDictionaryPtr;
+
+    private long priorEncodedProperties;
+    private long currentEncodedProperties;
+    private final boolean flipped;
+
+    public JRSUIControl(final boolean flipped){
+        this.flipped = flipped;
+        cfDictionaryPtr = getCFDictionary(flipped);
+        if (cfDictionaryPtr == 0) throw new RuntimeException("Unable to create native representation");
+        nativeMap = new HashMap<Key, DoubleValue>();
+        changes = new HashMap<Key, DoubleValue>();
+    }
+
+    JRSUIControl(final JRSUIControl other) {
+        flipped = other.flipped;
+        cfDictionaryPtr = getCFDictionary(flipped);
+        if (cfDictionaryPtr == 0) throw new RuntimeException("Unable to create native representation");
+        nativeMap = new HashMap<Key, DoubleValue>();
+        changes = new HashMap<Key, DoubleValue>(other.nativeMap);
+        changes.putAll(other.changes);
+    }
+
+    protected synchronized final void finalize() throws Throwable {
+        if (cfDictionaryPtr == 0) return;
+        disposeCFDictionary(cfDictionaryPtr);
+        cfDictionaryPtr = 0;
+    }
+
+
+    enum BufferState {
+        NO_CHANGE,
+        ALL_CHANGES_IN_BUFFER,
+        SOME_CHANGES_IN_BUFFER,
+        CHANGE_WONT_FIT_IN_BUFFER;
+    }
+
+    private BufferState loadBufferWithChanges(final ThreadLocalByteBuffer localByteBuffer) {
+        final ByteBuffer buffer = localByteBuffer.buffer;
+        buffer.rewind();
+
+        for (final JRSUIConstants.Key key : new HashSet<JRSUIConstants.Key>(changes.keySet())) {
+            final int changeIndex = buffer.position();
+            final JRSUIConstants.DoubleValue value = changes.get(key);
+
+            try {
+                buffer.putLong(key.getConstantPtr());
+                buffer.put(value.getTypeCode());
+                value.putValueInBuffer(buffer);
+            } catch (final BufferOverflowException e) {
+                return handleBufferOverflow(buffer, changeIndex);
+            } catch (final RuntimeException e) {
+                System.err.println(this);
+                throw e;
+            }
+
+            if (buffer.position() >= NIO_BUFFER_SIZE - 8) {
+                return handleBufferOverflow(buffer, changeIndex);
+            }
+
+            changes.remove(key);
+            nativeMap.put(key, value);
+        }
+
+        buffer.putLong(0);
+        return BufferState.ALL_CHANGES_IN_BUFFER;
+    }
+
+    private BufferState handleBufferOverflow(final ByteBuffer buffer, final int changeIndex) {
+        if (changeIndex == 0) {
+            buffer.putLong(0, 0);
+            return BufferState.CHANGE_WONT_FIT_IN_BUFFER;
+        }
+
+        buffer.putLong(changeIndex, 0);
+        return BufferState.SOME_CHANGES_IN_BUFFER;
+    }
+
+    private synchronized void set(final JRSUIConstants.Key key, final JRSUIConstants.DoubleValue value) {
+        final JRSUIConstants.DoubleValue existingValue = nativeMap.get(key);
+
+        if (existingValue != null && existingValue.equals(value)) {
+            changes.remove(key);
+            return;
+        }
+
+        changes.put(key, value);
+    }
+
+    public void set(final JRSUIState state) {
+        state.apply(this);
+    }
+
+    void setEncodedState(final long state) {
+        currentEncodedProperties = state;
+    }
+
+    void set(final JRSUIConstants.Key key, final double value) {
+        set(key, new JRSUIConstants.DoubleValue(value));
+    }
+
+//    private static final Color blue = new Color(0x00, 0x00, 0xFF, 0x40);
+//    private static void paintDebug(Graphics2D g, double x, double y, double w, double h) {
+//        final Color prev = g.getColor();
+//        g.setColor(blue);
+//        g.drawRect((int)x, (int)y, (int)w, (int)h);
+//        g.setColor(prev);
+//    }
+
+//    private static int paintsWithNoChange = 0;
+//    private static int paintsWithChangesThatFit = 0;
+//    private static int paintsWithChangesThatOverflowed = 0;
+
+    public void paint(final int[] data, final int imgW, final int imgH, final double x, final double y, final double w, final double h) {
+        paintImage(data, imgW, imgH, x, y, w, h);
+        priorEncodedProperties = currentEncodedProperties;
+    }
+
+    private synchronized int paintImage(final int[] data, final int imgW, final int imgH, final double x, final double y, final double w, final double h) {
+        if (changes.isEmpty()) {
+//            paintsWithNoChange++;
+            return paintImage(data, imgW, imgH, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h);
+        }
+
+        final ThreadLocalByteBuffer localByteBuffer = getThreadLocalBuffer();
+        BufferState bufferState = loadBufferWithChanges(localByteBuffer);
+
+        // fast tracking this, since it's the likely scenario
+        if (bufferState == BufferState.ALL_CHANGES_IN_BUFFER) {
+//            paintsWithChangesThatFit++;
+            return paintChangesImage(data, imgW, imgH, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
+        }
+
+        while (bufferState == BufferState.SOME_CHANGES_IN_BUFFER) {
+            final int status = syncChanges(cfDictionaryPtr, localByteBuffer.ptr);
+            if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
+            bufferState = loadBufferWithChanges(localByteBuffer);
+        }
+
+        if (bufferState == BufferState.CHANGE_WONT_FIT_IN_BUFFER) {
+            throw new RuntimeException("JRSUI failed to sync changes to the native buffer, because some change was too big: " + this);
+        }
+
+        // implicitly ALL_CHANGES_IN_BUFFER, now that we sync'd the buffer down to native a few times
+//        paintsWithChangesThatOverflowed++;
+        return paintChangesImage(data, imgW, imgH, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
+    }
+
+    public void paint(final long cgContext, final double x, final double y, final double w, final double h) {
+        paintToCGContext(cgContext, x, y, w, h);
+        priorEncodedProperties = currentEncodedProperties;
+    }
+
+    private synchronized int paintToCGContext(final long cgContext, final double x, final double y, final double w, final double h) {
+        if (changes.isEmpty()) {
+//            paintsWithNoChange++;
+            return paintToCGContext(cgContext, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h);
+        }
+
+        final ThreadLocalByteBuffer localByteBuffer = getThreadLocalBuffer();
+        BufferState bufferState = loadBufferWithChanges(localByteBuffer);
+
+        // fast tracking this, since it's the likely scenario
+        if (bufferState == BufferState.ALL_CHANGES_IN_BUFFER) {
+//            paintsWithChangesThatFit++;
+            return paintChangesToCGContext(cgContext, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
+        }
+
+        while (bufferState == BufferState.SOME_CHANGES_IN_BUFFER) {
+            final int status = syncChanges(cfDictionaryPtr, localByteBuffer.ptr);
+            if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
+            bufferState = loadBufferWithChanges(localByteBuffer);
+        }
+
+        if (bufferState == BufferState.CHANGE_WONT_FIT_IN_BUFFER) {
+            throw new RuntimeException("JRSUI failed to sync changes to the native buffer, because some change was too big: " + this);
+        }
+
+        // implicitly ALL_CHANGES_IN_BUFFER, now that we sync'd the buffer down to native a few times
+//        paintsWithChangesThatOverflowed++;
+        return paintChangesToCGContext(cgContext, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
+    }
+
+
+    Hit getHitForPoint(final double x, final double y, final double w, final double h, final double hitX, final double hitY) {
+        sync();
+        // reflect hitY about the midline of the control before sending to native
+        final Hit hit = JRSUIConstants.getHit(getNativeHitPart(cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, hitX, 2 * y + h - hitY));
+        priorEncodedProperties = currentEncodedProperties;
+        return hit;
+    }
+
+    void getPartBounds(final double[] rect, final double x, final double y, final double w, final double h, final int part) {
+        if (rect == null) throw new NullPointerException("Cannot load null rect");
+        if (rect.length != 4) throw new IllegalArgumentException("Rect must have four elements");
+
+        sync();
+        getNativePartBounds(rect, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, part);
+        priorEncodedProperties = currentEncodedProperties;
+    }
+
+    double getScrollBarOffsetChange(final double x, final double y, final double w, final double h, final int offset, final int visibleAmount, final int extent) {
+        sync();
+        final double offsetChange = getNativeScrollBarOffsetChange(cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, offset, visibleAmount, extent);
+        priorEncodedProperties = currentEncodedProperties;
+        return offsetChange;
+    }
+
+    private void sync() {
+        if (changes.isEmpty()) return;
+
+        final ThreadLocalByteBuffer localByteBuffer = getThreadLocalBuffer();
+        BufferState bufferState = loadBufferWithChanges(localByteBuffer);
+        if (bufferState == BufferState.ALL_CHANGES_IN_BUFFER) {
+            final int status = syncChanges(cfDictionaryPtr, localByteBuffer.ptr);
+            if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
+            return;
+        }
+
+        while (bufferState == BufferState.SOME_CHANGES_IN_BUFFER) {
+            final int status = syncChanges(cfDictionaryPtr, localByteBuffer.ptr);
+            if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
+            bufferState = loadBufferWithChanges(localByteBuffer);
+        }
+
+        if (bufferState == BufferState.CHANGE_WONT_FIT_IN_BUFFER) {
+            throw new RuntimeException("JRSUI failed to sync changes to the native buffer, because some change was too big: " + this);
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        int bits = (int)(currentEncodedProperties ^ (currentEncodedProperties >>> 32));
+        bits ^= nativeMap.hashCode();
+        bits ^= changes.hashCode();
+        return bits;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (!(obj instanceof JRSUIControl)) return false;
+        final JRSUIControl other = (JRSUIControl)obj;
+        if (currentEncodedProperties != other.currentEncodedProperties) return false;
+        if (!nativeMap.equals(other.nativeMap)) return false;
+        if (!changes.equals(other.changes)) return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder("JRSUIControl[inNative:");
+        builder.append(Arrays.toString(nativeMap.entrySet().toArray()));
+        builder.append(", changes:");
+        builder.append(Arrays.toString(changes.entrySet().toArray()));
+        builder.append("]");
+        return builder.toString();
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/laf/JRSUIFocus.java b/jdk/src/macosx/classes/apple/laf/JRSUIFocus.java
new file mode 100644
index 0000000..2b40bc5
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/laf/JRSUIFocus.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.laf;
+
+public class JRSUIFocus {
+    private static final int SUCCESS = 0;
+    private static final int NULL_PTR = -1;
+    private static final int NULL_CG_REF = -2;
+
+    // from HITheme.h
+    public static final int RING_ONLY = 0;
+    public static final int RING_ABOVE = 1;
+    public static final int RING_BELOW = 2;
+
+    private static native int beginNativeFocus(final long cgContext, final int ringStyle);
+    private static native int endNativeFocus(final long cgContext);
+
+    final long cgContext;
+    public JRSUIFocus(final long cgContext) {
+        this.cgContext = cgContext;
+    }
+
+    public void beginFocus(final int ringStyle) {
+        testForFailure(beginNativeFocus(cgContext, ringStyle));
+    }
+
+    public void endFocus() {
+        testForFailure(endNativeFocus(cgContext));
+    }
+
+    static void testForFailure(final int status) {
+        if (status == SUCCESS) return;
+
+        switch(status) {
+            case NULL_PTR: throw new RuntimeException("Null pointer exception in native JRSUI");
+            case NULL_CG_REF: throw new RuntimeException("Null CG reference in native JRSUI");
+            default: throw new RuntimeException("JRSUI draw focus problem: " + status);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/laf/JRSUIState.java b/jdk/src/macosx/classes/apple/laf/JRSUIState.java
new file mode 100644
index 0000000..3d95fe4
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/laf/JRSUIState.java
@@ -0,0 +1,264 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.laf;
+
+import apple.laf.JRSUIConstants.*;
+
+@SuppressWarnings("unchecked")
+public class JRSUIState {
+//    static HashSet<JRSUIState> states = new HashSet<JRSUIState>();
+
+    final long encodedState;
+    long derivedEncodedState;
+
+    static JRSUIState prototype = new JRSUIState(0);
+    public static JRSUIState getInstance() {
+        return prototype.derive();
+    }
+
+    JRSUIState(final Widget widget) {
+        this(widget.apply(0));
+    }
+
+    JRSUIState(final long encodedState) {
+        this.encodedState = derivedEncodedState = encodedState;
+    }
+
+    boolean isDerivationSame() {
+        return encodedState == derivedEncodedState;
+    }
+
+    public <T extends JRSUIState> T derive() {
+        if (isDerivationSame()) return (T)this;
+        final T derivation = (T)createDerivation();
+
+//        if (!states.add(derivation)) {
+//            System.out.println("dupe: " + states.size());
+//        }
+
+        return derivation;
+    }
+
+    public <T extends JRSUIState> T createDerivation() {
+        return (T)new JRSUIState(derivedEncodedState);
+    }
+
+    public void reset() {
+        derivedEncodedState = encodedState;
+    }
+
+    public void set(final Property property) {
+        derivedEncodedState = property.apply(derivedEncodedState);
+    }
+
+    public void apply(final JRSUIControl control) {
+        control.setEncodedState(encodedState);
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (!(obj instanceof JRSUIState)) return false;
+        return encodedState == ((JRSUIState)obj).encodedState && getClass().equals(obj.getClass());
+    }
+
+    public boolean is(Property property) {
+        return (byte)((derivedEncodedState & property.encoding.mask) >> property.encoding.shift) == property.ordinal;
+    }
+
+    @Override
+    public int hashCode() {
+        return (int)(encodedState ^ (encodedState >>> 32)) ^ getClass().hashCode();
+    }
+
+    public static class AnimationFrameState extends JRSUIState {
+        final int animationFrame;
+        int derivedAnimationFrame;
+
+        AnimationFrameState(final long encodedState, final int animationFrame) {
+            super(encodedState);
+            this.animationFrame = derivedAnimationFrame = animationFrame;
+        }
+
+        @Override
+        boolean isDerivationSame() {
+            return super.isDerivationSame() && (animationFrame == derivedAnimationFrame);
+        }
+
+        @Override
+        public <T extends JRSUIState> T createDerivation() {
+            return (T)new AnimationFrameState(derivedEncodedState, derivedAnimationFrame);
+        }
+
+        @Override
+        public void reset() {
+            super.reset();
+            derivedAnimationFrame = animationFrame;
+        }
+
+        public void setAnimationFrame(final int frame) {
+            this.derivedAnimationFrame = frame;
+        }
+
+        @Override
+        public void apply(final JRSUIControl control) {
+            super.apply(control);
+            control.set(Key.ANIMATION_FRAME, animationFrame);
+        }
+
+        @Override
+        public boolean equals(final Object obj) {
+            if (!(obj instanceof AnimationFrameState)) return false;
+            return animationFrame == ((AnimationFrameState)obj).animationFrame && super.equals(obj);
+        }
+
+        @Override
+        public int hashCode() {
+            return super.hashCode() ^ animationFrame;
+        }
+    }
+
+    public static class ValueState extends JRSUIState {
+        final double value;
+        double derivedValue;
+
+        ValueState(final long encodedState, final double value) {
+            super(encodedState);
+            this.value = derivedValue = value;
+        }
+
+        @Override
+        boolean isDerivationSame() {
+            return super.isDerivationSame() && (value == derivedValue);
+        }
+
+        @Override
+        public <T extends JRSUIState> T createDerivation() {
+            return (T)new ValueState(derivedEncodedState, derivedValue);
+        }
+
+        @Override
+        public void reset() {
+            super.reset();
+            derivedValue = value;
+        }
+
+        public void setValue(final double value) {
+            derivedValue = value;
+        }
+
+        @Override
+        public void apply(final JRSUIControl control) {
+            super.apply(control);
+            control.set(Key.VALUE, value);
+        }
+
+        @Override
+        public boolean equals(final Object obj) {
+            if (!(obj instanceof ValueState)) return false;
+            return value == ((ValueState)obj).value && super.equals(obj);
+        }
+
+        @Override
+        public int hashCode() {
+            final long bits = Double.doubleToRawLongBits(value);
+            return super.hashCode() ^ (int)bits ^ (int)(bits >>> 32);
+        }
+    }
+
+    public static class TitleBarHeightState extends ValueState {
+        TitleBarHeightState(final long encodedState, final double value) {
+            super(encodedState, value);
+        }
+
+        @Override
+        public <T extends JRSUIState> T createDerivation() {
+            return (T)new TitleBarHeightState(derivedEncodedState, derivedValue);
+        }
+
+        @Override
+        public void apply(final JRSUIControl control) {
+            super.apply(control);
+            control.set(Key.WINDOW_TITLE_BAR_HEIGHT, value);
+        }
+    }
+
+    public static class ScrollBarState extends ValueState {
+        final double thumbProportion;
+        double derivedThumbProportion;
+        final double thumbStart;
+        double derivedThumbStart;
+
+        ScrollBarState(final long encodedState, final double value, final double thumbProportion, final double thumbStart) {
+            super(encodedState, value);
+            this.thumbProportion = derivedThumbProportion = thumbProportion;
+            this.thumbStart = derivedThumbStart = thumbStart;
+        }
+
+        @Override
+        boolean isDerivationSame() {
+            return super.isDerivationSame() && (thumbProportion == derivedThumbProportion) && (thumbStart == derivedThumbStart);
+        }
+
+        @Override
+        public <T extends JRSUIState> T createDerivation() {
+            return (T)new ScrollBarState(derivedEncodedState, derivedValue, derivedThumbProportion, derivedThumbStart);
+        }
+
+        @Override
+        public void reset() {
+            super.reset();
+            derivedThumbProportion = thumbProportion;
+            derivedThumbStart = thumbStart;
+        }
+
+        public void setThumbPercent(final double thumbPercent) {
+            derivedThumbProportion = thumbPercent;
+        }
+
+        public void setThumbStart(final double thumbStart) {
+            derivedThumbStart = thumbStart;
+        }
+
+        @Override
+        public void apply(final JRSUIControl control) {
+            super.apply(control);
+            control.set(Key.THUMB_PROPORTION, thumbProportion);
+            control.set(Key.THUMB_START, thumbStart);
+        }
+
+        @Override
+        public boolean equals(final Object obj) {
+            if (!(obj instanceof ScrollBarState)) return false;
+            return (thumbProportion == ((ScrollBarState)obj).thumbProportion) && (thumbStart == ((ScrollBarState)obj).thumbStart) && super.equals(obj);
+        }
+
+        @Override
+        public int hashCode() {
+            final long bits = Double.doubleToRawLongBits(thumbProportion) ^ Double.doubleToRawLongBits(thumbStart);
+            return super.hashCode() ^ (int)bits ^ (int)(bits >>> 32);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/laf/JRSUIStateFactory.java b/jdk/src/macosx/classes/apple/laf/JRSUIStateFactory.java
new file mode 100644
index 0000000..81429ae
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/laf/JRSUIStateFactory.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.laf;
+
+import apple.laf.JRSUIConstants.*;
+import apple.laf.JRSUIState.*;
+
+public class JRSUIStateFactory {
+    public static JRSUIState getSliderTrack() {
+        return new JRSUIState(Widget.SLIDER.apply(NoIndicator.YES.apply(0)));
+    }
+
+    public static JRSUIState getSliderThumb() {
+        return new JRSUIState(Widget.SLIDER_THUMB.apply(0));
+    }
+
+    public static JRSUIState getSpinnerArrows() {
+        return new JRSUIState(Widget.BUTTON_LITTLE_ARROWS.apply(0));
+    }
+
+    public static JRSUIState getSplitPaneDivider() {
+        return new JRSUIState(Widget.DIVIDER_SPLITTER.apply(0));
+    }
+
+    public static JRSUIState getTab() {
+        return new JRSUIState(Widget.TAB.apply(SegmentTrailingSeparator.YES.apply(0)));
+    }
+
+    public static AnimationFrameState getDisclosureTriangle() {
+        return new AnimationFrameState(Widget.DISCLOSURE_TRIANGLE.apply(0), 0);
+    }
+
+    public static ScrollBarState getScrollBar() {
+        return new ScrollBarState(Widget.SCROLL_BAR.apply(0), 0, 0, 0);
+    }
+
+    public static TitleBarHeightState getTitleBar() {
+        return new TitleBarHeightState(Widget.WINDOW_FRAME.apply(0), 0);
+    }
+
+    public static ValueState getProgressBar() {
+        return new ValueState(0, 0);
+    }
+
+    public static ValueState getLabeledButton() {
+        return new ValueState(0, 0);
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/laf/JRSUIUtils.java b/jdk/src/macosx/classes/apple/laf/JRSUIUtils.java
new file mode 100644
index 0000000..4a5ef38
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/laf/JRSUIUtils.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.laf;
+
+import com.apple.laf.AquaImageFactory.NineSliceMetrics;
+
+import apple.laf.JRSUIConstants.*;
+
+public class JRSUIUtils {
+    static boolean isLeopard = isMacOSXLeopard();
+    static boolean isSnowLeopardOrBelow = isMacOSXSnowLeopardOrBelow();
+
+    static boolean isMacOSXLeopard() {
+        return isCurrentMacOSXVersion(5);
+    }
+
+    static boolean isMacOSXSnowLeopardOrBelow() {
+        return currentMacOSXVersionMatchesGivenVersionRange(6, true, true, false);
+    }
+
+    static boolean isCurrentMacOSXVersion(final int version) {
+        return currentMacOSXVersionMatchesGivenVersionRange(version, true, false, false);
+    }
+
+    static boolean currentMacOSXVersionMatchesGivenVersionRange(final int version, final boolean inclusive, final boolean matchBelow, final boolean matchAbove) {
+        // split the "10.x.y" version number
+        String osVersion = System.getProperty("os.version");
+        String[] fragments = osVersion.split("\\.");
+
+        // sanity check the "10." part of the version
+        if (!fragments[0].equals("10")) return false;
+        if (fragments.length < 2) return false;
+
+        // check if os.version matches the given version using the given match method
+        try {
+            int minorVers = Integer.parseInt(fragments[1]);
+
+            if (inclusive && minorVers == version) return true;
+            if (matchBelow && minorVers < version) return true;
+            if (matchAbove && minorVers > version) return true;
+
+        } catch (NumberFormatException e) {
+            // was not an integer
+        }
+        return false;
+    }
+
+    public static class TabbedPane {
+        public static boolean useLegacyTabs() {
+            return isLeopard;
+        }
+        public static boolean shouldUseTabbedPaneContrastUI() {
+            return !isSnowLeopardOrBelow;
+        }
+    }
+
+    public static class InternalFrame {
+        public static boolean shouldUseLegacyBorderMetrics() {
+            return isSnowLeopardOrBelow;
+        }
+    }
+
+    public static class Tree {
+        public static boolean useLegacyTreeKnobs() {
+            return isLeopard;
+        }
+    }
+
+    public static class ScrollBar {
+        private static native boolean shouldUseScrollToClick();
+
+        public static boolean useScrollToClick() {
+            return shouldUseScrollToClick();
+        }
+
+        public static void getPartBounds(final double[] rect, final JRSUIControl control, final double x, final double y, final double w, final double h, final ScrollBarPart part) {
+            control.getPartBounds(rect, x, y, w, h, part.ordinal);
+        }
+
+        public static double getNativeOffsetChange(final JRSUIControl control, final double x, final double y, final double w, final double h, final int offset, final int visibleAmount, final int extent) {
+            return control.getScrollBarOffsetChange(x, y, w, h, offset, visibleAmount, extent);
+        }
+    }
+
+    public static class Images {
+        public static boolean shouldUseLegacySecurityUIPath() {
+            return isSnowLeopardOrBelow;
+        }
+    }
+
+    public static class HitDetection {
+        public static Hit getHitForPoint(final JRSUIControl control, final double x, final double y, final double w, final double h, final double hitX, final double hitY) {
+            return control.getHitForPoint(x, y, w, h, hitX, hitY);
+        }
+    }
+
+    public interface NineSliceMetricsProvider {
+        public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state);
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/launcher/JavaAppLauncher.java b/jdk/src/macosx/classes/apple/launcher/JavaAppLauncher.java
new file mode 100644
index 0000000..599a575
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/launcher/JavaAppLauncher.java
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.launcher;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.security.PrivilegedAction;
+import java.text.MessageFormat;
+import java.util.*;
+import java.util.jar.*;
+
+import javax.swing.*;
+
+class JavaAppLauncher implements Runnable {
+    static {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osx"));
+    }
+
+    private static native <T> T nativeConvertAndRelease(final long ptr);
+    private static native void nativeInvokeNonPublic(Class<? extends Method> cls, Method m, String[] args);
+
+    // entry point from native
+    static void launch(final long javaDictionaryPtr, final boolean verbose) {
+        final Map<String, ?> javaDictionary = nativeConvertAndRelease(javaDictionaryPtr);
+        (new JavaAppLauncher(javaDictionary, verbose)).run();
+    }
+
+        // these are the values for the enumeration JavaFailureMode
+        static final String kJavaFailureMainClassNotSpecified = "MainClassNotSpecified";
+        static final String kJavaFailureMainClassNotFound = "CannotLoadMainClass";
+        static final String kJavaFailureMainClassHasNoMain = "NoMainMethod";
+        static final String kJavaFailureMainClassMainNotStatic = "MainNotStatic";
+        static final String kJavaFailureMainThrewException = "MainThrewException";
+        static final String kJavaFailureMainInitializerException = "MainInitializerException";
+
+        final boolean verbose; // Normally set by environment variable JAVA_LAUNCHER_VERBOSE.
+        final Map<String, ?> javaDictionary;
+
+        JavaAppLauncher(final Map<String, ?> javaDictionary, final boolean verbose) {
+                this.verbose = verbose;
+                this.javaDictionary = javaDictionary;
+        }
+
+        @Override
+        public void run() {
+                final Method m = loadMainMethod(getMainMethod());
+                final String methodName = m.getDeclaringClass().getName() + ".main(String[])";
+                try {
+                        log("Calling " + methodName + " method");
+                        m.invoke(null, new Object[] { getArguments() });
+                        log(methodName + " has returned");
+                } catch (final IllegalAccessException x) {
+                        try {
+                                nativeInvokeNonPublic(m.getClass(), m, getArguments());
+                        } catch (final Throwable excpt) {
+                                logError(methodName + " threw an exception:");
+                                if ((excpt instanceof UnsatisfiedLinkError) && excpt.getMessage().equals("nativeInvokeNonPublic")) {
+                                        showFailureAlertAndKill(kJavaFailureMainThrewException, "nativeInvokeNonPublic not registered");
+                                } else {
+                                        excpt.printStackTrace();
+                                        showFailureAlertAndKill(kJavaFailureMainThrewException, excpt.toString());
+                                }
+                        }
+                } catch (final InvocationTargetException invokeExcpt) {
+                        logError(methodName + " threw an exception:");
+                        invokeExcpt.getTargetException().printStackTrace();
+                        showFailureAlertAndKill(kJavaFailureMainThrewException, invokeExcpt.getTargetException().toString());
+                }
+        }
+
+        Method loadMainMethod(final String mainClassName) {
+                try {
+                        final Class<?> mainClass = Class.forName(mainClassName, true, sun.misc.Launcher.getLauncher().getClassLoader());
+                        final Method mainMethod = mainClass.getDeclaredMethod("main", new Class[] { String[].class });
+                        if ((mainMethod.getModifiers() & Modifier.STATIC) == 0) {
+                                logError("The main(String[]) method of class " + mainClassName + " is not static!");
+                                showFailureAlertAndKill(kJavaFailureMainClassMainNotStatic, mainClassName);
+                        }
+                        return mainMethod;
+                } catch (final ExceptionInInitializerError x) {
+                        logError("The main class \"" + mainClassName + "\" had a static initializer throw an exception.");
+                        x.getException().printStackTrace();
+                        showFailureAlertAndKill(kJavaFailureMainInitializerException, x.getException().toString());
+                } catch (final ClassNotFoundException x) {
+                        logError("The main class \"" + mainClassName + "\" could not be found.");
+                        showFailureAlertAndKill(kJavaFailureMainClassNotFound, mainClassName);
+                } catch (final NoSuchMethodException x) {
+                        logError("The main class \"" + mainClassName + "\" has no static main(String[]) method.");
+                        showFailureAlertAndKill(kJavaFailureMainClassHasNoMain, mainClassName);
+                } catch (final NullPointerException x) {
+                        logError("No main class specified");
+                        showFailureAlertAndKill(kJavaFailureMainClassNotSpecified, null);
+                }
+
+                return null;
+        }
+
+        // get main class name from 'Jar' key, or 'MainClass' key
+        String getMainMethod() {
+                final Object javaJar = javaDictionary.get("Jar");
+                if (javaJar != null) {
+                        if (!(javaJar instanceof String)) {
+                                logError("'Jar' key in 'Java' sub-dictionary of Info.plist requires a string value");
+                                return null;
+                        }
+
+                        final String jarPath = (String)javaJar;
+                        if (jarPath.length() == 0) {
+                                log("'Jar' key of sub-dictionary 'Java' of Info.plist key is empty");
+                        } else {
+                                // extract main class from manifest of this jar
+                                final String main = getMainFromManifest(jarPath);
+                                if (main == null) {
+                                        logError("jar file '" + jarPath + "' does not have Main-Class: attribute in its manifest");
+                                        return null;
+                                }
+
+                                log("Main class " + main + " found in jar manifest");
+                                return main;
+                        }
+                }
+
+                final Object javaMain = javaDictionary.get("MainClass");
+                if (!(javaMain instanceof String)) {
+                        logError("'MainClass' key in 'Java' sub-dictionary of Info.plist requires a string value");
+                        return null;
+                }
+
+                final String main = (String)javaMain;
+                if (main.length() == 0) {
+                        log("'MainClass' key of sub-dictionary 'Java' of Info.plist key is empty");
+                        return null;
+                }
+
+                log("Main class " + (String)javaMain + " found via 'MainClass' key of sub-dictionary 'Java' of Info.plist key");
+                return (String)javaMain;
+        }
+
+        // get arguments for main(String[]) out of Info.plist and command line
+        String[] getArguments() {
+                // check for 'Arguments' key, which contains the main() args if not defined in Info.plist
+                final Object javaArguments = javaDictionary.get("Arguments");
+                if (javaArguments == null) {
+                        // no arguments
+                        log("No arguments for main(String[]) specified");
+                        return new String[0];
+                }
+
+                if (javaArguments instanceof List) {
+                        final List<?> args = (List<?>)javaArguments;
+                        final int count = args.size();
+                        log("Arguments to main(String[" + count + "]):");
+
+                        final String[] result = new String[count];
+                        for (int i = 0; i < count; ++i) {
+                                final Object element = args.get(i);
+                                if (element instanceof String) {
+                                        result[i] = (String)element;
+                                } else {
+                                        logError("Found non-string in array");
+                                }
+                                log("   arg[" + i + "]=" + result[i]);
+                        }
+                        return result;
+                }
+
+                logError("'Arguments' key in 'Java' sub-dictionary of Info.plist requires a string value or an array of strings");
+                return new String[0];
+        }
+
+        // returns name of main class, or null
+        String getMainFromManifest(final String jarpath) {
+                JarFile jar = null;
+                try {
+                        jar = new JarFile(jarpath);
+                        final Manifest man = jar.getManifest();
+                        final Attributes attr = man.getMainAttributes();
+                        return attr.getValue("Main-Class");
+                } catch (final IOException x) {
+                        // shrug
+                } finally {
+                        if (jar != null) {
+                                try {
+                                        jar.close();
+                                } catch (final IOException x) { }
+                        }
+                }
+                return null;
+        }
+
+        void log(final String s) {
+                if (!verbose) return;
+                System.out.println("[LaunchRunner] " + s);
+        }
+
+        static void logError(final String s) {
+                System.err.println("[LaunchRunner Error] " + s);
+        }
+
+        // This kills the app and does not return!
+        static void showFailureAlertAndKill(final String msg, String arg) {
+                if (arg == null) arg = "<<null>>";
+                JOptionPane.showMessageDialog(null, getMessage(msg, arg), "", JOptionPane.ERROR_MESSAGE);
+                System.exit(-1);
+        }
+
+        static String getMessage(final String msgKey, final Object ... args) {
+            final String msg = ResourceBundle.getBundle("appLauncherErrors").getString(msgKey);
+            return MessageFormat.format(msg, args);
+        }
+}
diff --git a/jdk/src/macosx/classes/apple/launcher/appLauncherErrors.properties b/jdk/src/macosx/classes/apple/launcher/appLauncherErrors.properties
new file mode 100644
index 0000000..9f880b7
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/launcher/appLauncherErrors.properties
@@ -0,0 +1,6 @@
+MainClassNotSpecified=No main class specified.
+CannotLoadMainClass=The main class \u201C{0}\u201D could not be loaded.
+NoMainMethod=The main class \u201C{0}\u201D has no \u201Cvoid main(String[])\u201D method.
+MainNotStatic=The \u201Cmain(String[])\u201D method of class \u201C{0}\u201D is not static.
+MainThrewException=Uncaught exception in main method: {0}
+MainInitializerException=A static initializer of the main class threw an exception: {0}
diff --git a/jdk/src/macosx/classes/apple/security/AppleProvider.java b/jdk/src/macosx/classes/apple/security/AppleProvider.java
new file mode 100644
index 0000000..d016edb
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/security/AppleProvider.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.security;
+
+import java.security.*;
+
+/**
+ * The Apple Security Provider.
+ */
+
+/**
+ * Defines the Apple provider.
+ *
+ * This provider only exists to provide access to the Apple keychain-based KeyStore implementation
+ */
+
+public final class AppleProvider extends Provider {
+
+    private static final String info = "Apple Provider";
+
+    public AppleProvider() {
+        /* We are the Apple provider */
+        super("Apple", 1.1, info);
+
+        AccessController.<Object>doPrivileged(new java.security.PrivilegedAction<Object>() {
+            public Object run() {
+
+                /*
+                 * KeyStore
+                 */
+                put("KeyStore.KeychainStore", "apple.security.KeychainStore");
+
+                return null;
+            }
+        });
+    }
+}
diff --git a/jdk/src/macosx/classes/apple/security/KeychainStore.java b/jdk/src/macosx/classes/apple/security/KeychainStore.java
new file mode 100644
index 0000000..6291943
--- /dev/null
+++ b/jdk/src/macosx/classes/apple/security/KeychainStore.java
@@ -0,0 +1,1124 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package apple.security;
+
+import java.io.*;
+import java.security.*;
+import java.security.cert.*;
+import java.security.cert.Certificate;
+import java.security.spec.*;
+import java.util.*;
+
+import javax.crypto.*;
+import javax.crypto.spec.*;
+import javax.security.auth.x500.*;
+
+import sun.security.pkcs.*;
+import sun.security.pkcs.EncryptedPrivateKeyInfo;
+import sun.security.util.*;
+import sun.security.x509.*;
+
+/**
+ * This class provides the keystore implementation referred to as "KeychainStore".
+ * It uses the current user's keychain as its backing storage, and does NOT support
+ * a file-based implementation.
+ */
+
+public final class KeychainStore extends KeyStoreSpi {
+
+    // Private keys and their supporting certificate chains
+    // If a key came from the keychain it has a SecKeyRef and one or more
+    // SecCertificateRef.  When we delete the key we have to delete all of the corresponding
+    // native objects.
+    class KeyEntry {
+        Date date; // the creation date of this entry
+        byte[] protectedPrivKey;
+        char[] password;
+        long keyRef;  // SecKeyRef for this key
+        Certificate chain[];
+        long chainRefs[];  // SecCertificateRefs for this key's chain.
+    };
+
+    // Trusted certificates
+    class TrustedCertEntry {
+        Date date; // the creation date of this entry
+
+        Certificate cert;
+        long certRef;  // SecCertificateRef for this key
+    };
+
+    /**
+     * Entries that have been deleted.  When something calls engineStore we'll
+     * remove them from the keychain.
+     */
+    private Hashtable deletedEntries = new Hashtable();
+
+    /**
+     * Entries that have been added.  When something calls engineStore we'll
+     * add them to the keychain.
+     */
+    private Hashtable addedEntries = new Hashtable();
+
+    /**
+     * Private keys and certificates are stored in a hashtable.
+     * Hash entries are keyed by alias names.
+     */
+    private Hashtable entries = new Hashtable();
+
+    /**
+     * Algorithm identifiers and corresponding OIDs for the contents of the PKCS12 bag we get from the Keychain.
+     */
+    private static final int keyBag[]  = {1, 2, 840, 113549, 1, 12, 10, 1, 2};
+    private static final int pbeWithSHAAnd3KeyTripleDESCBC[] =     {1, 2, 840, 113549, 1, 12, 1, 3};
+    private static ObjectIdentifier PKCS8ShroudedKeyBag_OID;
+    private static ObjectIdentifier pbeWithSHAAnd3KeyTripleDESCBC_OID;
+
+    /**
+     * Constnats used in PBE decryption.
+     */
+    private static final int iterationCount = 1024;
+    private static final int SALT_LEN = 20;
+
+    static {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osx"));
+        try {
+            PKCS8ShroudedKeyBag_OID = new ObjectIdentifier(keyBag);
+            pbeWithSHAAnd3KeyTripleDESCBC_OID = new ObjectIdentifier(pbeWithSHAAnd3KeyTripleDESCBC);
+        } catch (IOException ioe) {
+            // should not happen
+        }
+    }
+
+    private static void permissionCheck() {
+        SecurityManager sec = System.getSecurityManager();
+
+        if (sec != null) {
+            sec.checkPermission(new RuntimePermission("useKeychainStore"));
+        }
+    }
+
+
+    /**
+     * Verify the Apple provider in the constructor.
+     *
+     * @exception SecurityException if fails to verify
+     * its own integrity
+     */
+    public KeychainStore() { }
+
+    /**
+        * Returns the key associated with the given alias, using the given
+     * password to recover it.
+     *
+     * @param alias the alias name
+     * @param password the password for recovering the key
+     *
+     * @return the requested key, or null if the given alias does not exist
+     * or does not identify a <i>key entry</i>.
+     *
+     * @exception NoSuchAlgorithmException if the algorithm for recovering the
+     * key cannot be found
+     * @exception UnrecoverableKeyException if the key cannot be recovered
+     * (e.g., the given password is wrong).
+     */
+    public Key engineGetKey(String alias, char[] password)
+        throws NoSuchAlgorithmException, UnrecoverableKeyException
+    {
+        permissionCheck();
+
+        Object entry = entries.get(alias.toLowerCase());
+
+        if (entry == null || !(entry instanceof KeyEntry)) {
+            return null;
+        }
+
+        // This call gives us a PKCS12 bag, with the key inside it.
+        byte[] exportedKeyInfo = _getEncodedKeyData(((KeyEntry)entry).keyRef, password);
+        if (exportedKeyInfo == null) {
+            return null;
+        }
+
+        PrivateKey returnValue = null;
+
+        try {
+            byte[] pkcs8KeyData = fetchPrivateKeyFromBag(exportedKeyInfo);
+            byte[] encryptedKey;
+            AlgorithmParameters algParams;
+            ObjectIdentifier algOid;
+            try {
+                // get the encrypted private key
+                EncryptedPrivateKeyInfo encrInfo = new EncryptedPrivateKeyInfo(pkcs8KeyData);
+                encryptedKey = encrInfo.getEncryptedData();
+
+                // parse Algorithm parameters
+                DerValue val = new DerValue(encrInfo.getAlgorithm().encode());
+                DerInputStream in = val.toDerInputStream();
+                algOid = in.getOID();
+                algParams = parseAlgParameters(in);
+
+            } catch (IOException ioe) {
+                UnrecoverableKeyException uke =
+                new UnrecoverableKeyException("Private key not stored as "
+                                              + "PKCS#8 EncryptedPrivateKeyInfo: " + ioe);
+                uke.initCause(ioe);
+                throw uke;
+            }
+
+            // Use JCE to decrypt the data using the supplied password.
+            SecretKey skey = getPBEKey(password);
+            Cipher cipher = Cipher.getInstance(algOid.toString());
+            cipher.init(Cipher.DECRYPT_MODE, skey, algParams);
+            byte[] decryptedPrivateKey = cipher.doFinal(encryptedKey);
+            PKCS8EncodedKeySpec kspec = new PKCS8EncodedKeySpec(decryptedPrivateKey);
+
+             // Parse the key algorithm and then use a JCA key factory to create the private key.
+            DerValue val = new DerValue(decryptedPrivateKey);
+            DerInputStream in = val.toDerInputStream();
+
+            // Ignore this -- version should be 0.
+            int i = in.getInteger();
+
+            // Get the Algorithm ID next
+            DerValue[] value = in.getSequence(2);
+            AlgorithmId algId = new AlgorithmId(value[0].getOID());
+            String algName = algId.getName();
+
+            // Get a key factory for this algorithm.  It's likely to be 'RSA'.
+            KeyFactory kfac = KeyFactory.getInstance(algName);
+            returnValue = kfac.generatePrivate(kspec);
+        } catch (Exception e) {
+            UnrecoverableKeyException uke =
+            new UnrecoverableKeyException("Get Key failed: " +
+                                          e.getMessage());
+            uke.initCause(e);
+            throw uke;
+        }
+
+        return returnValue;
+    }
+
+    private native byte[] _getEncodedKeyData(long secKeyRef, char[] password);
+
+    /**
+     * Returns the certificate chain associated with the given alias.
+     *
+     * @param alias the alias name
+     *
+     * @return the certificate chain (ordered with the user's certificate first
+                                      * and the root certificate authority last), or null if the given alias
+     * does not exist or does not contain a certificate chain (i.e., the given
+                                                               * alias identifies either a <i>trusted certificate entry</i> or a
+                                                               * <i>key entry</i> without a certificate chain).
+     */
+    public Certificate[] engineGetCertificateChain(String alias) {
+        permissionCheck();
+
+        Object entry = entries.get(alias.toLowerCase());
+
+        if (entry != null && entry instanceof KeyEntry) {
+            if (((KeyEntry)entry).chain == null) {
+                return null;
+            } else {
+                return (Certificate[])((KeyEntry)entry).chain.clone();
+            }
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Returns the certificate associated with the given alias.
+     *
+     * <p>If the given alias name identifies a
+     * <i>trusted certificate entry</i>, the certificate associated with that
+     * entry is returned. If the given alias name identifies a
+     * <i>key entry</i>, the first element of the certificate chain of that
+     * entry is returned, or null if that entry does not have a certificate
+     * chain.
+     *
+     * @param alias the alias name
+     *
+     * @return the certificate, or null if the given alias does not exist or
+     * does not contain a certificate.
+     */
+    public Certificate engineGetCertificate(String alias) {
+        permissionCheck();
+
+        Object entry = entries.get(alias.toLowerCase());
+
+        if (entry != null) {
+            if (entry instanceof TrustedCertEntry) {
+                return ((TrustedCertEntry)entry).cert;
+            } else {
+                if (((KeyEntry)entry).chain == null) {
+                    return null;
+                } else {
+                    return ((KeyEntry)entry).chain[0];
+                }
+            }
+        } else {
+            return null;
+        }
+    }
+
+    /**
+        * Returns the creation date of the entry identified by the given alias.
+     *
+     * @param alias the alias name
+     *
+     * @return the creation date of this entry, or null if the given alias does
+     * not exist
+     */
+    public Date engineGetCreationDate(String alias) {
+        permissionCheck();
+
+        Object entry = entries.get(alias.toLowerCase());
+
+        if (entry != null) {
+            if (entry instanceof TrustedCertEntry) {
+                return new Date(((TrustedCertEntry)entry).date.getTime());
+            } else {
+                return new Date(((KeyEntry)entry).date.getTime());
+            }
+        } else {
+            return null;
+        }
+    }
+
+    /**
+        * Assigns the given key to the given alias, protecting it with the given
+     * password.
+     *
+     * <p>If the given key is of type <code>java.security.PrivateKey</code>,
+     * it must be accompanied by a certificate chain certifying the
+     * corresponding public key.
+     *
+     * <p>If the given alias already exists, the keystore information
+     * associated with it is overridden by the given key (and possibly
+                                                          * certificate chain).
+     *
+     * @param alias the alias name
+     * @param key the key to be associated with the alias
+     * @param password the password to protect the key
+     * @param chain the certificate chain for the corresponding public
+     * key (only required if the given key is of type
+            * <code>java.security.PrivateKey</code>).
+     *
+     * @exception KeyStoreException if the given key cannot be protected, or
+     * this operation fails for some other reason
+     */
+    public void engineSetKeyEntry(String alias, Key key, char[] password,
+                                  Certificate[] chain)
+        throws KeyStoreException
+    {
+        permissionCheck();
+
+        synchronized(entries) {
+            try {
+                KeyEntry entry = new KeyEntry();
+                entry.date = new Date();
+
+                if (key instanceof PrivateKey) {
+                    if ((key.getFormat().equals("PKCS#8")) ||
+                        (key.getFormat().equals("PKCS8"))) {
+                        entry.protectedPrivKey = encryptPrivateKey(key.getEncoded(), password);
+                        entry.password = password.clone();
+                    } else {
+                        throw new KeyStoreException("Private key is not encoded as PKCS#8");
+                    }
+                } else {
+                    throw new KeyStoreException("Key is not a PrivateKey");
+                }
+
+                // clone the chain
+                if (chain != null) {
+                    if ((chain.length > 1) && !validateChain(chain)) {
+                        throw new KeyStoreException("Certificate chain does not validate");
+                    }
+
+                    entry.chain = (Certificate[])chain.clone();
+                    entry.chainRefs = new long[entry.chain.length];
+                }
+
+                String lowerAlias = alias.toLowerCase();
+                if (entries.get(lowerAlias) != null) {
+                    deletedEntries.put(lowerAlias, entries.get(lowerAlias));
+                }
+
+                entries.put(lowerAlias, entry);
+                addedEntries.put(lowerAlias, entry);
+            } catch (Exception nsae) {
+                KeyStoreException ke = new KeyStoreException("Key protection algorithm not found: " + nsae);
+                ke.initCause(nsae);
+                throw ke;
+            }
+        }
+    }
+
+    /**
+        * Assigns the given key (that has already been protected) to the given
+     * alias.
+     *
+     * <p>If the protected key is of type
+     * <code>java.security.PrivateKey</code>, it must be accompanied by a
+     * certificate chain certifying the corresponding public key. If the
+     * underlying keystore implementation is of type <code>jks</code>,
+     * <code>key</code> must be encoded as an
+     * <code>EncryptedPrivateKeyInfo</code> as defined in the PKCS #8 standard.
+     *
+     * <p>If the given alias already exists, the keystore information
+     * associated with it is overridden by the given key (and possibly
+                                                          * certificate chain).
+     *
+     * @param alias the alias name
+     * @param key the key (in protected format) to be associated with the alias
+     * @param chain the certificate chain for the corresponding public
+     * key (only useful if the protected key is of type
+            * <code>java.security.PrivateKey</code>).
+     *
+     * @exception KeyStoreException if this operation fails.
+     */
+    public void engineSetKeyEntry(String alias, byte[] key,
+                                  Certificate[] chain)
+        throws KeyStoreException
+    {
+        permissionCheck();
+
+        synchronized(entries) {
+            // key must be encoded as EncryptedPrivateKeyInfo as defined in
+            // PKCS#8
+            KeyEntry entry = new KeyEntry();
+            try {
+                EncryptedPrivateKeyInfo privateKey = new EncryptedPrivateKeyInfo(key);
+                entry.protectedPrivKey = privateKey.getEncoded();
+            } catch (IOException ioe) {
+                throw new KeyStoreException("key is not encoded as "
+                                            + "EncryptedPrivateKeyInfo");
+            }
+
+            entry.date = new Date();
+
+            if ((chain != null) &&
+                (chain.length != 0)) {
+                entry.chain = (Certificate[])chain.clone();
+                entry.chainRefs = new long[entry.chain.length];
+            }
+
+            String lowerAlias = alias.toLowerCase();
+            if (entries.get(lowerAlias) != null) {
+                deletedEntries.put(lowerAlias, entries.get(alias));
+            }
+            entries.put(lowerAlias, entry);
+            addedEntries.put(lowerAlias, entry);
+        }
+    }
+
+    /**
+        * Assigns the given certificate to the given alias.
+     *
+     * <p>If the given alias already exists in this keystore and identifies a
+     * <i>trusted certificate entry</i>, the certificate associated with it is
+     * overridden by the given certificate.
+     *
+     * @param alias the alias name
+     * @param cert the certificate
+     *
+     * @exception KeyStoreException if the given alias already exists and does
+     * not identify a <i>trusted certificate entry</i>, or this operation
+     * fails for some other reason.
+     */
+    public void engineSetCertificateEntry(String alias, Certificate cert)
+        throws KeyStoreException
+    {
+        permissionCheck();
+
+        synchronized(entries) {
+
+            Object entry = entries.get(alias.toLowerCase());
+            if ((entry != null) && (entry instanceof KeyEntry)) {
+                throw new KeyStoreException
+                ("Cannot overwrite key entry with certificate");
+            }
+
+            // This will be slow, but necessary.  Enumerate the values and then see if the cert matches the one in the trusted cert entry.
+            // Security framework doesn't support the same certificate twice in a keychain.
+            Collection allValues = entries.values();
+
+            for (Object value : allValues) {
+                if (value instanceof TrustedCertEntry) {
+                    TrustedCertEntry tce = (TrustedCertEntry)value;
+                    if (tce.cert.equals(cert)) {
+                        throw new KeyStoreException("Keychain does not support mulitple copies of same certificate.");
+                    }
+                }
+            }
+
+            TrustedCertEntry trustedCertEntry = new TrustedCertEntry();
+            trustedCertEntry.cert = cert;
+            trustedCertEntry.date = new Date();
+            String lowerAlias = alias.toLowerCase();
+            if (entries.get(lowerAlias) != null) {
+                deletedEntries.put(lowerAlias, entries.get(lowerAlias));
+            }
+            entries.put(lowerAlias, trustedCertEntry);
+            addedEntries.put(lowerAlias, trustedCertEntry);
+        }
+    }
+
+    /**
+        * Deletes the entry identified by the given alias from this keystore.
+     *
+     * @param alias the alias name
+     *
+     * @exception KeyStoreException if the entry cannot be removed.
+     */
+    public void engineDeleteEntry(String alias)
+        throws KeyStoreException
+    {
+        permissionCheck();
+
+        synchronized(entries) {
+            Object entry = entries.remove(alias.toLowerCase());
+            deletedEntries.put(alias.toLowerCase(), entry);
+        }
+    }
+
+    /**
+        * Lists all the alias names of this keystore.
+     *
+     * @return enumeration of the alias names
+     */
+    public Enumeration engineAliases() {
+        permissionCheck();
+        return entries.keys();
+    }
+
+    /**
+        * Checks if the given alias exists in this keystore.
+     *
+     * @param alias the alias name
+     *
+     * @return true if the alias exists, false otherwise
+     */
+    public boolean engineContainsAlias(String alias) {
+        permissionCheck();
+        return entries.containsKey(alias.toLowerCase());
+    }
+
+    /**
+        * Retrieves the number of entries in this keystore.
+     *
+     * @return the number of entries in this keystore
+     */
+    public int engineSize() {
+        permissionCheck();
+        return entries.size();
+    }
+
+    /**
+        * Returns true if the entry identified by the given alias is a
+     * <i>key entry</i>, and false otherwise.
+     *
+     * @return true if the entry identified by the given alias is a
+     * <i>key entry</i>, false otherwise.
+     */
+    public boolean engineIsKeyEntry(String alias) {
+        permissionCheck();
+        Object entry = entries.get(alias.toLowerCase());
+        if ((entry != null) && (entry instanceof KeyEntry)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+        * Returns true if the entry identified by the given alias is a
+     * <i>trusted certificate entry</i>, and false otherwise.
+     *
+     * @return true if the entry identified by the given alias is a
+     * <i>trusted certificate entry</i>, false otherwise.
+     */
+    public boolean engineIsCertificateEntry(String alias) {
+        permissionCheck();
+        Object entry = entries.get(alias.toLowerCase());
+        if ((entry != null) && (entry instanceof TrustedCertEntry)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+        * Returns the (alias) name of the first keystore entry whose certificate
+     * matches the given certificate.
+     *
+     * <p>This method attempts to match the given certificate with each
+     * keystore entry. If the entry being considered
+     * is a <i>trusted certificate entry</i>, the given certificate is
+     * compared to that entry's certificate. If the entry being considered is
+     * a <i>key entry</i>, the given certificate is compared to the first
+     * element of that entry's certificate chain (if a chain exists).
+     *
+     * @param cert the certificate to match with.
+     *
+     * @return the (alias) name of the first entry with matching certificate,
+     * or null if no such entry exists in this keystore.
+     */
+    public String engineGetCertificateAlias(Certificate cert) {
+        permissionCheck();
+        Certificate certElem;
+
+        for (Enumeration e = entries.keys(); e.hasMoreElements(); ) {
+            String alias = (String)e.nextElement();
+            Object entry = entries.get(alias);
+            if (entry instanceof TrustedCertEntry) {
+                certElem = ((TrustedCertEntry)entry).cert;
+            } else if (((KeyEntry)entry).chain != null) {
+                certElem = ((KeyEntry)entry).chain[0];
+            } else {
+                continue;
+            }
+            if (certElem.equals(cert)) {
+                return alias;
+            }
+        }
+        return null;
+    }
+
+    /**
+        * Stores this keystore to the given output stream, and protects its
+     * integrity with the given password.
+     *
+     * @param stream Ignored. the output stream to which this keystore is written.
+     * @param password the password to generate the keystore integrity check
+     *
+     * @exception IOException if there was an I/O problem with data
+     * @exception NoSuchAlgorithmException if the appropriate data integrity
+     * algorithm could not be found
+     * @exception CertificateException if any of the certificates included in
+     * the keystore data could not be stored
+     */
+    public void engineStore(OutputStream stream, char[] password)
+        throws IOException, NoSuchAlgorithmException, CertificateException
+    {
+        permissionCheck();
+
+        // Delete items that do have a keychain item ref.
+        for (Enumeration e = deletedEntries.keys(); e.hasMoreElements(); ) {
+            String alias = (String)e.nextElement();
+            Object entry = deletedEntries.get(alias);
+            if (entry instanceof TrustedCertEntry) {
+                if (((TrustedCertEntry)entry).certRef != 0) {
+                    _removeItemFromKeychain(((TrustedCertEntry)entry).certRef);
+                    _releaseKeychainItemRef(((TrustedCertEntry)entry).certRef);
+                }
+            } else {
+                Certificate certElem;
+                KeyEntry keyEntry = (KeyEntry)entry;
+
+                if (keyEntry.chain != null) {
+                    for (int i = 0; i < keyEntry.chain.length; i++) {
+                        if (keyEntry.chainRefs[i] != 0) {
+                            _removeItemFromKeychain(keyEntry.chainRefs[i]);
+                            _releaseKeychainItemRef(keyEntry.chainRefs[i]);
+                        }
+                    }
+
+                    if (keyEntry.keyRef != 0) {
+                        _removeItemFromKeychain(keyEntry.keyRef);
+                        _releaseKeychainItemRef(keyEntry.keyRef);
+                    }
+                }
+            }
+        }
+
+        // Add all of the certs or keys in the added entries.
+        // No need to check for 0 refs, as they are in the added list.
+        for (Enumeration e = addedEntries.keys(); e.hasMoreElements(); ) {
+            String alias = (String)e.nextElement();
+            Object entry = addedEntries.get(alias);
+            if (entry instanceof TrustedCertEntry) {
+                TrustedCertEntry tce = (TrustedCertEntry)entry;
+                Certificate certElem;
+                certElem = tce.cert;
+                tce.certRef = addCertificateToKeychain(alias, certElem);
+            } else {
+                KeyEntry keyEntry = (KeyEntry)entry;
+
+                if (keyEntry.chain != null) {
+                    for (int i = 0; i < keyEntry.chain.length; i++) {
+                        keyEntry.chainRefs[i] = addCertificateToKeychain(alias, keyEntry.chain[i]);
+                    }
+
+                    keyEntry.keyRef = _addItemToKeychain(alias, false, keyEntry.protectedPrivKey, keyEntry.password);
+                }
+            }
+        }
+
+        // Clear the added and deletedEntries hashtables here, now that we're done with the updates.
+        // For the deleted entries, we freed up the native references above.
+        deletedEntries.clear();
+        addedEntries.clear();
+    }
+
+    private long addCertificateToKeychain(String alias, Certificate cert) {
+        byte[] certblob = null;
+        long returnValue = 0;
+
+        try {
+            certblob = cert.getEncoded();
+            returnValue = _addItemToKeychain(alias, true, certblob, null);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return returnValue;
+    }
+
+    private native long _addItemToKeychain(String alias, boolean isCertificate, byte[] datablob, char[] password);
+    private native int _removeItemFromKeychain(long certRef);
+    private native void _releaseKeychainItemRef(long keychainItemRef);
+
+    /**
+      * Loads the keystore from the Keychain.
+     *
+     * @param stream Ignored - here for API compatibility.
+     * @param password Ignored - if user needs to unlock keychain Security
+     * framework will post any dialogs.
+     *
+     * @exception IOException if there is an I/O or format problem with the
+     * keystore data
+     * @exception NoSuchAlgorithmException if the algorithm used to check
+     * the integrity of the keystore cannot be found
+     * @exception CertificateException if any of the certificates in the
+     * keystore could not be loaded
+     */
+    public void engineLoad(InputStream stream, char[] password)
+        throws IOException, NoSuchAlgorithmException, CertificateException
+    {
+        permissionCheck();
+
+        // Release any stray keychain references before clearing out the entries.
+        synchronized(entries) {
+            for (Enumeration e = entries.keys(); e.hasMoreElements(); ) {
+                String alias = (String)e.nextElement();
+                Object entry = entries.get(alias);
+                if (entry instanceof TrustedCertEntry) {
+                    if (((TrustedCertEntry)entry).certRef != 0) {
+                        _releaseKeychainItemRef(((TrustedCertEntry)entry).certRef);
+                    }
+                } else {
+                    KeyEntry keyEntry = (KeyEntry)entry;
+
+                    if (keyEntry.chain != null) {
+                        for (int i = 0; i < keyEntry.chain.length; i++) {
+                            if (keyEntry.chainRefs[i] != 0) {
+                                _releaseKeychainItemRef(keyEntry.chainRefs[i]);
+                            }
+                        }
+
+                        if (keyEntry.keyRef != 0) {
+                            _releaseKeychainItemRef(keyEntry.keyRef);
+                        }
+                    }
+                }
+            }
+
+            entries.clear();
+            _scanKeychain();
+        }
+    }
+
+    private native void _scanKeychain();
+
+    /**
+     * Callback method from _scanKeychain.  If a trusted certificate is found, this method will be called.
+     */
+    private void createTrustedCertEntry(String alias, long keychainItemRef, long creationDate, byte[] derStream) {
+        TrustedCertEntry tce = new TrustedCertEntry();
+
+        try {
+            CertificateFactory cf = CertificateFactory.getInstance("X.509");
+            InputStream input = new ByteArrayInputStream(derStream);
+            X509Certificate cert = (X509Certificate) cf.generateCertificate(input);
+            input.close();
+            tce.cert = cert;
+            tce.certRef = keychainItemRef;
+
+            // Make a creation date.
+            if (creationDate != 0)
+                tce.date = new Date(creationDate);
+            else
+                tce.date = new Date();
+
+            int uniqueVal = 1;
+            String originalAlias = alias;
+
+            while (entries.containsKey(alias.toLowerCase())) {
+                alias = originalAlias + " " + uniqueVal;
+                uniqueVal++;
+            }
+
+            entries.put(alias.toLowerCase(), tce);
+        } catch (Exception e) {
+            // The certificate will be skipped.
+            System.err.println("KeychainStore Ignored Exception: " + e);
+        }
+    }
+
+    /**
+     * Callback method from _scanKeychain.  If an identity is found, this method will be called to create Java certificate
+     * and private key objects from the keychain data.
+     */
+    private void createKeyEntry(String alias, long creationDate, long secKeyRef, long[] secCertificateRefs, byte[][] rawCertData)
+        throws IOException, NoSuchAlgorithmException, UnrecoverableKeyException {
+        KeyEntry ke = new KeyEntry();
+
+        // First, store off the private key information.  This is the easy part.
+        ke.protectedPrivKey = null;
+        ke.keyRef = secKeyRef;
+
+        // Make a creation date.
+        if (creationDate != 0)
+            ke.date = new Date(creationDate);
+        else
+            ke.date = new Date();
+
+        // Next, create X.509 Certificate objects from the raw data.  This is complicated
+        // because a certificate's public key may be too long for Java's default encryption strength.
+        List createdCerts = new ArrayList();
+
+        try {
+            CertificateFactory cf = CertificateFactory.getInstance("X.509");
+
+            for (int i = 0; i < rawCertData.length; i++) {
+                try {
+                    InputStream input = new ByteArrayInputStream(rawCertData[i]);
+                    X509Certificate cert = (X509Certificate) cf.generateCertificate(input);
+                    input.close();
+
+                    // We successfully created the certificate, so track it and its corresponding SecCertificateRef.
+                    createdCerts.add(new CertKeychainItemPair(secCertificateRefs[i], cert));
+                } catch (CertificateException e) {
+                    // The certificate will be skipped.
+                    System.err.println("KeychainStore Ignored Exception: " + e);
+                }
+            }
+        } catch (CertificateException e) {
+            e.printStackTrace();
+        } catch (IOException ioe) {
+            ioe.printStackTrace();  // How would this happen?
+        }
+
+        // We have our certificates in the List, so now extract them into an array of
+        // Certificates and SecCertificateRefs.
+        Object[] objArray = createdCerts.toArray();
+        Certificate[] certArray = new Certificate[objArray.length];
+        long[] certRefArray = new long[objArray.length];
+
+        for (int i = 0; i < objArray.length; i++) {
+            CertKeychainItemPair addedItem = (CertKeychainItemPair)objArray[i];
+            certArray[i] = addedItem.mCert;
+            certRefArray[i] = addedItem.mCertificateRef;
+        }
+
+        ke.chain = certArray;
+        ke.chainRefs = certRefArray;
+
+        // If we don't have already have an item with this item's alias
+        // create a new one for it.
+        int uniqueVal = 1;
+        String originalAlias = alias;
+
+        while (entries.containsKey(alias.toLowerCase())) {
+            alias = originalAlias + " " + uniqueVal;
+            uniqueVal++;
+        }
+
+        entries.put(alias.toLowerCase(), ke);
+    }
+
+    private class CertKeychainItemPair {
+        long mCertificateRef;
+        Certificate mCert;
+
+        CertKeychainItemPair(long inCertRef, Certificate cert) {
+            mCertificateRef = inCertRef;
+            mCert = cert;
+        }
+    }
+
+    /*
+     * Validate Certificate Chain
+     */
+    private boolean validateChain(Certificate[] certChain)
+    {
+        for (int i = 0; i < certChain.length-1; i++) {
+            X500Principal issuerDN =
+            ((X509Certificate)certChain[i]).getIssuerX500Principal();
+            X500Principal subjectDN =
+                ((X509Certificate)certChain[i+1]).getSubjectX500Principal();
+            if (!(issuerDN.equals(subjectDN)))
+                return false;
+        }
+        return true;
+    }
+
+    private byte[] fetchPrivateKeyFromBag(byte[] privateKeyInfo) throws IOException, NoSuchAlgorithmException, CertificateException
+    {
+        byte[] returnValue = null;
+        DerValue val = new DerValue(new ByteArrayInputStream(privateKeyInfo));
+        DerInputStream s = val.toDerInputStream();
+        int version = s.getInteger();
+
+        if (version != 3) {
+            throw new IOException("PKCS12 keystore not in version 3 format");
+        }
+
+        /*
+            * Read the authSafe.
+         */
+        byte[] authSafeData;
+        ContentInfo authSafe = new ContentInfo(s);
+        ObjectIdentifier contentType = authSafe.getContentType();
+
+        if (contentType.equals(ContentInfo.DATA_OID)) {
+            authSafeData = authSafe.getData();
+        } else /* signed data */ {
+            throw new IOException("public key protected PKCS12 not supported");
+        }
+
+        DerInputStream as = new DerInputStream(authSafeData);
+        DerValue[] safeContentsArray = as.getSequence(2);
+        int count = safeContentsArray.length;
+
+        /*
+         * Spin over the ContentInfos.
+         */
+        for (int i = 0; i < count; i++) {
+            byte[] safeContentsData;
+            ContentInfo safeContents;
+            DerInputStream sci;
+            byte[] eAlgId = null;
+
+            sci = new DerInputStream(safeContentsArray[i].toByteArray());
+            safeContents = new ContentInfo(sci);
+            contentType = safeContents.getContentType();
+            safeContentsData = null;
+
+            if (contentType.equals(ContentInfo.DATA_OID)) {
+                safeContentsData = safeContents.getData();
+            } else if (contentType.equals(ContentInfo.ENCRYPTED_DATA_OID)) {
+                // The password was used to export the private key from the keychain.
+                // The Keychain won't export the key with encrypted data, so we don't need
+                // to worry about it.
+                continue;
+            } else {
+                throw new IOException("public key protected PKCS12" +
+                                      " not supported");
+            }
+            DerInputStream sc = new DerInputStream(safeContentsData);
+            returnValue = extractKeyData(sc);
+        }
+
+        return returnValue;
+    }
+
+    private byte[] extractKeyData(DerInputStream stream)
+        throws IOException, NoSuchAlgorithmException, CertificateException
+    {
+        byte[] returnValue = null;
+        DerValue[] safeBags = stream.getSequence(2);
+        int count = safeBags.length;
+
+        /*
+         * Spin over the SafeBags.
+         */
+        for (int i = 0; i < count; i++) {
+            ObjectIdentifier bagId;
+            DerInputStream sbi;
+            DerValue bagValue;
+            Object bagItem = null;
+
+            sbi = safeBags[i].toDerInputStream();
+            bagId = sbi.getOID();
+            bagValue = sbi.getDerValue();
+            if (!bagValue.isContextSpecific((byte)0)) {
+                throw new IOException("unsupported PKCS12 bag value type "
+                                      + bagValue.tag);
+            }
+            bagValue = bagValue.data.getDerValue();
+            if (bagId.equals(PKCS8ShroudedKeyBag_OID)) {
+                // got what we were looking for.  Return it.
+                returnValue = bagValue.toByteArray();
+            } else {
+                // log error message for "unsupported PKCS12 bag type"
+                System.out.println("Unsupported bag type '" + bagId + "'");
+            }
+        }
+
+        return returnValue;
+    }
+
+    /*
+        * Generate PBE Algorithm Parameters
+     */
+    private AlgorithmParameters getAlgorithmParameters(String algorithm)
+        throws IOException
+    {
+        AlgorithmParameters algParams = null;
+
+        // create PBE parameters from salt and iteration count
+        PBEParameterSpec paramSpec =
+            new PBEParameterSpec(getSalt(), iterationCount);
+        try {
+            algParams = AlgorithmParameters.getInstance(algorithm);
+            algParams.init(paramSpec);
+        } catch (Exception e) {
+            IOException ioe =
+            new IOException("getAlgorithmParameters failed: " +
+                            e.getMessage());
+            ioe.initCause(e);
+            throw ioe;
+        }
+        return algParams;
+    }
+
+    // the source of randomness
+    private SecureRandom random;
+
+    /*
+     * Generate random salt
+     */
+    private byte[] getSalt()
+    {
+        // Generate a random salt.
+        byte[] salt = new byte[SALT_LEN];
+        if (random == null) {
+            random = new SecureRandom();
+        }
+        salt = random.generateSeed(SALT_LEN);
+        return salt;
+    }
+
+    /*
+     * parse Algorithm Parameters
+     */
+    private AlgorithmParameters parseAlgParameters(DerInputStream in)
+        throws IOException
+    {
+        AlgorithmParameters algParams = null;
+        try {
+            DerValue params;
+            if (in.available() == 0) {
+                params = null;
+            } else {
+                params = in.getDerValue();
+                if (params.tag == DerValue.tag_Null) {
+                    params = null;
+                }
+            }
+            if (params != null) {
+                algParams = AlgorithmParameters.getInstance("PBE");
+                algParams.init(params.toByteArray());
+            }
+        } catch (Exception e) {
+            IOException ioe =
+            new IOException("parseAlgParameters failed: " +
+                            e.getMessage());
+            ioe.initCause(e);
+            throw ioe;
+        }
+        return algParams;
+    }
+
+    /*
+     * Generate PBE key
+     */
+    private SecretKey getPBEKey(char[] password) throws IOException
+    {
+        SecretKey skey = null;
+
+        try {
+            PBEKeySpec keySpec = new PBEKeySpec(password);
+            SecretKeyFactory skFac = SecretKeyFactory.getInstance("PBE");
+            skey = skFac.generateSecret(keySpec);
+        } catch (Exception e) {
+            IOException ioe = new IOException("getSecretKey failed: " +
+                                              e.getMessage());
+            ioe.initCause(e);
+            throw ioe;
+        }
+        return skey;
+    }
+
+    /*
+     * Encrypt private key using Password-based encryption (PBE)
+     * as defined in PKCS#5.
+     *
+     * NOTE: Currently pbeWithSHAAnd3-KeyTripleDES-CBC algorithmID is
+     *       used to derive the key and IV.
+     *
+     * @return encrypted private key encoded as EncryptedPrivateKeyInfo
+     */
+    private byte[] encryptPrivateKey(byte[] data, char[] password)
+        throws IOException, NoSuchAlgorithmException, UnrecoverableKeyException
+    {
+        byte[] key = null;
+
+        try {
+            // create AlgorithmParameters
+            AlgorithmParameters algParams =
+            getAlgorithmParameters("PBEWithSHA1AndDESede");
+
+            // Use JCE
+            SecretKey skey = getPBEKey(password);
+            Cipher cipher = Cipher.getInstance("PBEWithSHA1AndDESede");
+            cipher.init(Cipher.ENCRYPT_MODE, skey, algParams);
+            byte[] encryptedKey = cipher.doFinal(data);
+
+            // wrap encrypted private key in EncryptedPrivateKeyInfo
+            // as defined in PKCS#8
+            AlgorithmId algid =
+                new AlgorithmId(pbeWithSHAAnd3KeyTripleDESCBC_OID, algParams);
+            EncryptedPrivateKeyInfo encrInfo =
+                new EncryptedPrivateKeyInfo(algid, encryptedKey);
+            key = encrInfo.getEncoded();
+        } catch (Exception e) {
+            UnrecoverableKeyException uke =
+            new UnrecoverableKeyException("Encrypt Private Key failed: "
+                                          + e.getMessage());
+            uke.initCause(e);
+            throw uke;
+        }
+
+        return ((byte[])key);
+    }
+
+
+}
+
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/Dispatch.java b/jdk/src/macosx/classes/com/apple/concurrent/Dispatch.java
new file mode 100644
index 0000000..9c5d9a2
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/Dispatch.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.concurrent;
+
+import java.util.concurrent.*;
+
+/**
+ * Factory for {@link Executor}s and {@link ExecutorService}s backed by
+ * libdispatch.
+ *
+ * Access is controlled through the Dispatch.getInstance() method, because
+ * performed tasks occur on threads owned by libdispatch. These threads are
+ * not owned by any particular AppContext or have any specific context
+ * classloader installed.
+ *
+ * @since Java for Mac OS X 10.6 Update 2
+ */
+public final class Dispatch {
+        /**
+         * The priorities of the three default asynchronous queues.
+         */
+        public enum Priority {
+                LOW(-2), NORMAL(0), HIGH(2); // values from <dispatch/queue.h>
+
+                final int nativePriority;
+                Priority(final int nativePriority) { this.nativePriority = nativePriority; }
+        };
+
+        final static Dispatch instance = new Dispatch();
+
+        /**
+         * Factory method returns an instnace of Dispatch if supported by the
+         * underlying operating system, and if the caller's security manager
+         * permits "canInvokeInSystemThreadGroup".
+         *
+         * @return a factory instance of Dispatch, or null if not available
+         */
+        public static Dispatch getInstance() {
+                checkSecurity();
+                if (!LibDispatchNative.nativeIsDispatchSupported()) return null;
+
+                return instance;
+        }
+
+        private static void checkSecurity() {
+        final SecurityManager security = System.getSecurityManager();
+        if (security != null) security.checkPermission(new RuntimePermission("canInvokeInSystemThreadGroup"));
+    }
+
+        private Dispatch() { }
+
+        /**
+         * Creates an {@link Executor} that performs tasks asynchronously. The {@link Executor}
+         * cannot be shutdown, and enqueued {@link Runnable}s cannot be canceled. Passing null
+         * returns the {@link Priority.NORMAL} {@link Executor}.
+         *
+         * @param priority - the priority of the returned {@link Executor}
+         * @return an asynchronous {@link Executor}
+         */
+        public Executor getAsyncExecutor(Priority priority) {
+                if (priority == null) priority = Priority.NORMAL;
+                final long nativeQueue = LibDispatchNative.nativeCreateConcurrentQueue(priority.nativePriority);
+                if (nativeQueue == 0L) return null;
+                return new LibDispatchConcurrentQueue(nativeQueue);
+        }
+
+        int queueIndex = 0;
+        /**
+         * Creates an {@link ExecutorService} that performs tasks synchronously in FIFO order.
+         * Useful to protect a resource against concurrent modification, in lieu of a lock.
+         * Passing null returns an {@link ExecutorService} with a uniquely labeled queue.
+         *
+         * @param label - a label to name the queue, shown in several debugging tools
+         * @return a synchronous {@link ExecutorService}
+         */
+        public ExecutorService createSerialExecutor(String label) {
+                if (label == null) label = "";
+                if (label.length() > 256) label = label.substring(0, 256);
+                String queueName = "com.apple.java.concurrent.";
+                if ("".equals(label)) {
+                        synchronized (this) {
+                                queueName += queueIndex++;
+                        }
+                } else {
+                        queueName += label;
+                }
+
+                final long nativeQueue = LibDispatchNative.nativeCreateSerialQueue(queueName);
+                if (nativeQueue == 0) return null;
+                return new LibDispatchSerialQueue(nativeQueue);
+        }
+
+        Executor nonBlockingMainQueue = null;
+        /**
+         * Returns an {@link Executor} that performs the provided Runnables on the main queue of the process.
+         * Runnables submitted to this {@link Executor} will not run until the AWT is started or another native toolkit is running a CFRunLoop or NSRunLoop on the main thread.
+         *
+         * Submitting a Runnable to this {@link Executor} does not wait for the Runnable to complete.
+         * @return an asynchronous {@link Executor} that is backed by the main queue
+         */
+        public synchronized Executor getNonBlockingMainQueueExecutor() {
+                if (nonBlockingMainQueue != null) return nonBlockingMainQueue;
+                return nonBlockingMainQueue = new LibDispatchMainQueue.ASync();
+        }
+
+        Executor blockingMainQueue = null;
+        /**
+         * Returns an {@link Executor} that performs the provided Runnables on the main queue of the process.
+         * Runnables submitted to this {@link Executor} will not run until the AWT is started or another native toolkit is running a CFRunLoop or NSRunLoop on the main thread.
+         *
+         * Submitting a Runnable to this {@link Executor} will block until the Runnable has completed.
+         * @return an {@link Executor} that is backed by the main queue
+         */
+        public synchronized Executor getBlockingMainQueueExecutor() {
+                if (blockingMainQueue != null) return blockingMainQueue;
+                return blockingMainQueue = new LibDispatchMainQueue.Sync();
+        }
+}
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchConcurrentQueue.java b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchConcurrentQueue.java
new file mode 100644
index 0000000..0a885df
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchConcurrentQueue.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.concurrent;
+
+import java.util.concurrent.Executor;
+
+class LibDispatchConcurrentQueue extends LibDispatchQueue implements Executor {
+        LibDispatchConcurrentQueue(final long queuePtr) {
+                super(queuePtr);
+        }
+
+        @Override
+        public void execute(final Runnable task) {
+                LibDispatchNative.nativeExecuteAsync(ptr, task);
+        }
+
+        @Override
+        protected synchronized void dispose() {
+                // should not dispose the default concurrent queues
+        }
+}
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchMainQueue.java b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchMainQueue.java
new file mode 100644
index 0000000..b988a20
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchMainQueue.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.concurrent;
+
+import java.util.concurrent.Executor;
+
+abstract class LibDispatchMainQueue extends LibDispatchQueue implements Executor {
+        public LibDispatchMainQueue() {
+                super(LibDispatchNative.nativeGetMainQueue());
+        }
+
+        @Override
+        protected synchronized void dispose() {
+                // should not dispose the main queue
+        }
+
+        static class Sync extends LibDispatchMainQueue {
+                @Override
+                public void execute(final Runnable task) {
+                        LibDispatchNative.nativeExecuteSync(ptr, task);
+                }
+        }
+
+        static class ASync extends LibDispatchMainQueue {
+                @Override
+                public void execute(final Runnable task) {
+                        LibDispatchNative.nativeExecuteAsync(ptr, task);
+                }
+        }
+}
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchNative.java b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchNative.java
new file mode 100644
index 0000000..470027f
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchNative.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.concurrent;
+
+final class LibDispatchNative {
+        static {
+                java.security.AccessController.doPrivileged((java.security.PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osx"));
+        }
+
+        static native boolean nativeIsDispatchSupported();
+        static native long nativeGetMainQueue();
+        static native long nativeCreateConcurrentQueue(int priority);
+        static native long nativeCreateSerialQueue(String name);
+        static native void nativeReleaseQueue(long nativeQueue);
+        static native void nativeExecuteAsync(long nativeQueue, Runnable task);
+        static native void nativeExecuteSync(long nativeQueue, Runnable task);
+
+        private LibDispatchNative() { }
+}
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchQueue.java b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchQueue.java
new file mode 100644
index 0000000..5e89d21
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchQueue.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.concurrent;
+
+class LibDispatchQueue extends LibDispatchRetainedResource {
+        LibDispatchQueue(final long queuePtr) {
+                super(queuePtr);
+        }
+}
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchRetainedResource.java b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchRetainedResource.java
new file mode 100644
index 0000000..c9439bb
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchRetainedResource.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.concurrent;
+
+class LibDispatchRetainedResource {
+        protected long ptr;
+
+        protected LibDispatchRetainedResource(final long ptr) {
+                this.ptr = ptr;
+        }
+
+        protected synchronized void dispose() {
+                if (ptr != 0) LibDispatchNative.nativeReleaseQueue(ptr);
+                ptr = 0;
+        }
+
+        protected void finalize() throws Throwable {
+                dispose();
+        }
+}
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchSerialQueue.java b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchSerialQueue.java
new file mode 100644
index 0000000..daf9db1
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/LibDispatchSerialQueue.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.concurrent;
+
+import java.util.List;
+import java.util.concurrent.*;
+
+class LibDispatchSerialQueue extends AbstractExecutorService {
+        static final int RUNNING    = 0;
+    static final int SHUTDOWN   = 1;
+//  static final int STOP       = 2; // not supported by GCD
+    static final int TERMINATED = 3;
+
+    final Object lock = new Object();
+        LibDispatchQueue nativeQueueWrapper;
+    volatile int runState;
+
+        LibDispatchSerialQueue(final long queuePtr) {
+                nativeQueueWrapper = new LibDispatchQueue(queuePtr);
+        }
+
+        @Override
+        public void execute(final Runnable task) {
+                if (nativeQueueWrapper == null) return;
+                LibDispatchNative.nativeExecuteAsync(nativeQueueWrapper.ptr, task);
+        }
+
+        @Override
+        public boolean isShutdown() {
+                return runState != RUNNING;
+        }
+
+        @Override
+        public boolean isTerminated() {
+                return runState == TERMINATED;
+        }
+
+        @Override
+        public void shutdown() {
+                synchronized (lock) {
+                        if (runState != RUNNING) return;
+
+                        runState = SHUTDOWN;
+                        execute(new Runnable() {
+                                public void run() {
+                                        synchronized (lock) {
+                                                runState = TERMINATED;
+                                                lock.notifyAll(); // for the benefit of awaitTermination()
+                                        }
+                                }
+                        });
+                        nativeQueueWrapper = null;
+                }
+        }
+
+        @Override
+        public List<Runnable> shutdownNow() {
+                shutdown();
+                return null;
+        }
+
+        @Override
+        public boolean awaitTermination(final long timeout, final TimeUnit unit) throws InterruptedException {
+                if (runState == TERMINATED) return true;
+
+                final long millis = unit.toMillis(timeout);
+                if (millis <= 0) return false;
+
+                synchronized (lock) {
+                        if (runState == TERMINATED) return true;
+                        lock.wait(timeout);
+                        if (runState == TERMINATED) return true;
+                }
+
+                return false;
+        }
+}
diff --git a/jdk/src/macosx/classes/com/apple/concurrent/package.html b/jdk/src/macosx/classes/com/apple/concurrent/package.html
new file mode 100644
index 0000000..003a7a2
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/concurrent/package.html
@@ -0,0 +1,7 @@
+<html>
+<head>
+</head>
+<body bgcolor="white">
+Apple-specific implementations of the java.util.concurrent.* API based on libdispatch.
+</body>
+</html>
diff --git a/jdk/src/macosx/classes/com/apple/eawt/AboutHandler.java b/jdk/src/macosx/classes/com/apple/eawt/AboutHandler.java
new file mode 100644
index 0000000..4bc7185
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/AboutHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.AboutEvent;
+
+/**
+ * An implementor receives notification when the app is asked to show it's about dialog.
+ *
+ * @see Application#setAboutHandler(AboutHandler)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface AboutHandler {
+    /**
+     * Called when the application is asked to show it's about dialog.
+     * @param e the request to show the about dialog.
+     */
+    public void handleAbout(final AboutEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/AppEvent.java b/jdk/src/macosx/classes/com/apple/eawt/AppEvent.java
new file mode 100644
index 0000000..8a1e36a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/AppEvent.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.io.File;
+import java.net.URI;
+import java.util.*;
+import java.awt.Window;
+
+/**
+ * AppEvents are sent to listeners and handlers installed on the {@link Application}.
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public abstract class AppEvent extends EventObject {
+    AppEvent() {
+        super(Application.getApplication());
+    }
+
+    /**
+     * Contains a list of files.
+     */
+    public abstract static class FilesEvent extends AppEvent {
+        final List<File> files;
+
+        FilesEvent(final List<File> files) {
+            this.files = files;
+        }
+
+        /**
+         * @return the list of files
+         */
+        public List<File> getFiles() {
+            return files;
+        }
+    }
+
+    /**
+     * Event sent when the app is asked to open a list of files.
+     *
+     * @see OpenFilesHandler#openFiles(OpenFilesEvent)
+     */
+    public static class OpenFilesEvent extends FilesEvent {
+        final String searchTerm;
+
+        OpenFilesEvent(final List<File> files, final String searchTerm) {
+            super(files);
+            this.searchTerm = searchTerm;
+        }
+
+        /**
+         * If the files were opened using the Spotlight search menu or a Finder search window, this method obtains the search term used to find the files.
+         * This is useful for highlighting the search term in the documents when they are opened.
+         * @return the search term used to find the files
+         */
+        public String getSearchTerm() {
+            return searchTerm;
+        }
+    }
+
+    /**
+     * Event sent when the app is asked to print a list of files.
+     *
+     * @see PrintFilesHandler#printFiles(PrintFilesEvent)
+     */
+    public static class PrintFilesEvent extends FilesEvent {
+        PrintFilesEvent(final List<File> files) {
+            super(files);
+        }
+    }
+
+    /**
+     * Event sent when the app is asked to open a URI.
+     *
+     * @see OpenURIHandler#openURI(OpenURIEvent)
+     */
+    public static class OpenURIEvent extends AppEvent {
+        final URI uri;
+
+        OpenURIEvent(final URI uri) {
+            this.uri = uri;
+        }
+
+        /**
+         * @return the URI the app was asked to open
+         */
+        public URI getURI() {
+            return uri;
+        }
+    }
+
+    /**
+     * Event sent when the application is asked to open it's about window.
+     *
+     * @see AboutHandler#handleAbout()
+     */
+    public static class AboutEvent extends AppEvent { AboutEvent() { } }
+
+    /**
+     * Event sent when the application is asked to open it's preferences window.
+     *
+     * @see PreferencesHandler#handlePreferences()
+     */
+    public static class PreferencesEvent extends AppEvent { PreferencesEvent() { } }
+
+    /**
+     * Event sent when the application is asked to quit.
+     *
+     * @see QuitHandler#handleQuitRequestWith(QuitEvent, QuitResponse)
+     */
+    public static class QuitEvent extends AppEvent { QuitEvent() { } }
+
+    /**
+     * Event sent when the application is asked to re-open itself.
+     *
+     * @see AppReOpenedListener#appReOpened(AppReOpenedEvent)
+     */
+    public static class AppReOpenedEvent extends AppEvent { AppReOpenedEvent() { } }
+
+    /**
+     * Event sent when the application has become the foreground app, and when it has resigned being the foreground app.
+     *
+     * @see AppForegroundListener#appRaisedToForeground(AppForegroundEvent)
+     * @see AppForegroundListener#appMovedToBackground(AppForegroundEvent)
+     */
+    public static class AppForegroundEvent extends AppEvent { AppForegroundEvent() { } }
+
+    /**
+     * Event sent when the application has been hidden or shown.
+     *
+     * @see AppHiddenListener#appHidden(AppHiddenEvent)
+     * @see AppHiddenListener#appUnhidden(AppHiddenEvent)
+     */
+    public static class AppHiddenEvent extends AppEvent { AppHiddenEvent() { } }
+
+    /**
+     * Event sent when the user session has been changed via Fast User Switching.
+     *
+     * @see UserSessionListener#userSessionActivated(UserSessionEvent)
+     * @see UserSessionListener#userSessionDeactivated(UserSessionEvent)
+     */
+    public static class UserSessionEvent extends AppEvent { UserSessionEvent() { } }
+
+    /**
+     * Event sent when the displays attached to the system enter and exit power save sleep.
+     *
+     * @see ScreenSleepListener#screenAboutToSleep(ScreenSleepEvent)
+     * @see ScreenSleepListener#screenAwoke(ScreenSleepEvent)
+     */
+    public static class ScreenSleepEvent extends AppEvent { ScreenSleepEvent() { } }
+
+    /**
+     * Event sent when the system enters and exits power save sleep.
+     *
+     * @see SystemSleepListener#systemAboutToSleep(SystemSleepEvent)
+     * @see SystemSleepListener#systemAwoke(SystemSleepEvent)
+     */
+    public static class SystemSleepEvent extends AppEvent { SystemSleepEvent() { } }
+
+    /**
+     * Event sent when a window is entering/exiting or has entered/exited full screen state.
+     *
+     * @see FullScreenUtilities
+     *
+     * @since Java for Mac OS X 10.7 Update 1
+     */
+    public static class FullScreenEvent extends AppEvent {
+        final Window window;
+
+        FullScreenEvent(final Window window) {
+            this.window = window;
+        }
+
+        /**
+         * @return window transitioning between full screen states
+         */
+        public Window getWindow() {
+            return window;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/AppEventListener.java b/jdk/src/macosx/classes/com/apple/eawt/AppEventListener.java
new file mode 100644
index 0000000..5685bff
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/AppEventListener.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+/**
+ * Common interface for all event listener sub-types.
+ * Implementors may implement multiple sub-types, but only need to call {@link Application#addAppEventListener(AppEventListener)} once to receive all notifications.
+ *
+ * @see AppReOpenedListener
+ * @see AppForegroundListener
+ * @see AppHiddenListener
+ * @see ScreenSleepListener
+ * @see SystemSleepListener
+ * @see UserSessionListener
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface AppEventListener { }
diff --git a/jdk/src/macosx/classes/com/apple/eawt/AppForegroundListener.java b/jdk/src/macosx/classes/com/apple/eawt/AppForegroundListener.java
new file mode 100644
index 0000000..7892540
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/AppForegroundListener.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.AppForegroundEvent;
+
+/**
+ * Implementors are notified when the app becomes the foreground app and when it resigns being the foreground app.
+ * This notification is useful for hiding and showing transient UI like palette windows which should be hidden when the app is in the background.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface AppForegroundListener extends AppEventListener {
+    /**
+     * Called when the app becomes the foreground app.
+     * @param e the app became foreground notification.
+     */
+    public void appRaisedToForeground(final AppForegroundEvent e);
+
+    /**
+     * Called when the app resigns to the background and another app becomes the foreground app.
+     * @param e the app resigned foreground notification.
+     */
+    public void appMovedToBackground(final AppForegroundEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/AppHiddenListener.java b/jdk/src/macosx/classes/com/apple/eawt/AppHiddenListener.java
new file mode 100644
index 0000000..39761f4
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/AppHiddenListener.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.AppHiddenEvent;
+
+/**
+ * Implementors are notified when the app is hidden or shown by the user.
+ * This notification is helpful for discontinuing a costly animation if it's not visible to the user.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface AppHiddenListener extends AppEventListener {
+    /**
+     * Called the app is hidden.
+     * @param e
+     */
+    public void appHidden(final AppHiddenEvent e);
+
+    /**
+     * Called when the hidden app is shown again (but not necessarily brought to the foreground).
+     * @param e
+     */
+    public void appUnhidden(final AppHiddenEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/AppReOpenedListener.java b/jdk/src/macosx/classes/com/apple/eawt/AppReOpenedListener.java
new file mode 100644
index 0000000..655e04b
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/AppReOpenedListener.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.AppReOpenedEvent;
+
+/**
+ * Implementors receive notification when the app has been asked to open again.
+ * Re-open events occur when the user clicks on the running app's Dock icon.
+ * Re-open events also occur when the app is double-clicked in the Finder and the app is already running.
+ *
+ * This notification is useful for showing a new document when your app has no open windows.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface AppReOpenedListener extends AppEventListener {
+    /**
+     * Called when the app has been re-opened (it's Dock icon was clicked on, or was double-clicked in the Finder)
+     * @param e the request to re-open the app
+     */
+    public void appReOpened(final AppReOpenedEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/Application.java b/jdk/src/macosx/classes/com/apple/eawt/Application.java
new file mode 100644
index 0000000..f4657d6
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/Application.java
@@ -0,0 +1,564 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.*;
+import java.awt.peer.*;
+import java.beans.Beans;
+import java.security.PrivilegedAction;
+
+import javax.swing.JMenuBar;
+
+import sun.lwawt.*;
+import sun.lwawt.macosx.*;
+
+/**
+ * The <code>Application</code> class allows you to integrate your Java application with the native Mac OS X environment.
+ * You can provide your Mac OS X users a greatly enhanced experience by implementing a few basic handlers for standard system events.
+ *
+ * For example:
+ * <ul>
+ * <li>Open an about dialog when a user chooses About from the application menu.</li>
+ * <li>Open a preferences window when the users chooses Preferences from the application menu.</li>
+ * <li>Create a new document when the user clicks on your Dock icon, and no windows are open.</li>
+ * <li>Open a document that the user double-clicked on in the Finder.</li>
+ * <li>Open a custom URL scheme when a user clicks on link in a web browser.</li>
+ * <li>Reconnect to network services after the system has awoke from sleep.</li>
+ * <li>Cleanly shutdown your application when the user chooses Quit from the application menu, Dock icon, or types Command-Q.</li>
+ * <li>Cancel shutdown/logout if the user has unsaved changes in your application.</li>
+ * </ul>
+ *
+ * @since 1.4
+ */
+public class Application {
+    private static native void nativeInitializeApplicationDelegate();
+
+    static Application sApplication = null;
+
+    static {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("awt"));
+
+        checkSecurity();
+        if (!Beans.isDesignTime()) {
+            nativeInitializeApplicationDelegate();
+        }
+
+        sApplication = new Application();
+    }
+
+    private static void checkSecurity() {
+        final SecurityManager security = System.getSecurityManager();
+        if (security == null) return;
+        security.checkPermission(new RuntimePermission("canProcessApplicationEvents"));
+    }
+
+    /**
+     * @return the singleton representing this Mac OS X Application
+     *
+     * @since 1.4
+     */
+    public static Application getApplication() {
+        checkSecurity();
+        return sApplication;
+    }
+
+    // some singletons, since they get called back into from native
+    final _AppEventHandler eventHandler = _AppEventHandler.getInstance();
+    final _AppMenuBarHandler menuBarHandler = _AppMenuBarHandler.getInstance();
+    final _AppDockIconHandler iconHandler = new _AppDockIconHandler();
+
+    /**
+     * Creates an Application instance. Should only be used in JavaBean environments.
+     * @deprecated use {@link #getApplication()}
+     *
+     * @since 1.4
+     */
+    @Deprecated
+    public Application() {
+        checkSecurity();
+    }
+
+    /**
+     * Adds sub-types of {@link AppEventListener} to listen for notifications from the native Mac OS X system.
+     *
+     * @see AppForegroundListener
+     * @see AppHiddenListener
+     * @see AppReOpenedListener
+     * @see ScreenSleepListener
+     * @see SystemSleepListener
+     * @see UserSessionListener
+     *
+     * @param listener
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void addAppEventListener(final AppEventListener listener) {
+        eventHandler.addListener(listener);
+    }
+
+    /**
+     * Removes sub-types of {@link AppEventListener} from listening for notifications from the native Mac OS X system.
+     *
+     * @see AppForegroundListener
+     * @see AppHiddenListener
+     * @see AppReOpenedListener
+     * @see ScreenSleepListener
+     * @see SystemSleepListener
+     * @see UserSessionListener
+     *
+     * @param listener
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void removeAppEventListener(final AppEventListener listener) {
+        eventHandler.removeListener(listener);
+    }
+
+    /**
+     * Installs a handler to show a custom About window for your application.
+     *
+     * Setting the {@link AboutHandler} to <code>null</code> reverts it to the default Cocoa About window.
+     *
+     * @param aboutHandler the handler to respond to the {@link AboutHandler#handleAbout()} message
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void setAboutHandler(final AboutHandler aboutHandler) {
+        eventHandler.aboutDispatcher.setHandler(aboutHandler);
+    }
+
+    /**
+     * Installs a handler to create the Preferences menu item in your application's app menu.
+     *
+     * Setting the {@link PreferencesHandler} to <code>null</code> will remove the Preferences item from the app menu.
+     *
+     * @param preferencesHandler
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void setPreferencesHandler(final PreferencesHandler preferencesHandler) {
+        eventHandler.preferencesDispatcher.setHandler(preferencesHandler);
+    }
+
+    /**
+     * Installs the handler which is notified when the application is asked to open a list of files.
+     * The {@link OpenFilesHandler#openFiles(AppEvent.OpenFilesEvent)} notifications are only sent if the Java app is a bundled application, with a <code>CFBundleDocumentTypes</code> array present in it's Info.plist.
+     * See the <a href="http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference">Info.plist Key Reference</a> for more information about adding a <code>CFBundleDocumentTypes</code> key to your app's Info.plist.
+     *
+     * @param openFileHandler
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
+        eventHandler.openFilesDispatcher.setHandler(openFileHandler);
+    }
+
+    /**
+     * Installs the handler which is notified when the application is asked to print a list of files.
+     * The {@link PrintFilesHandler#printFiles(AppEvent.PrintFilesEvent)} notifications are only sent if the Java app is a bundled application, with a <code>CFBundleDocumentTypes</code> array present in it's Info.plist.
+     * See the <a href="http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference">Info.plist Key Reference</a> for more information about adding a <code>CFBundleDocumentTypes</code> key to your app's Info.plist.
+     *
+     * @param printFileHandler
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void setPrintFileHandler(final PrintFilesHandler printFileHandler) {
+        eventHandler.printFilesDispatcher.setHandler(printFileHandler);
+    }
+
+    /**
+     * Installs the handler which is notified when the application is asked to open a URL.
+     * The {@link OpenURIHandler#openURI(AppEvent.OpenURIEvent)} notifications are only sent if the Java app is a bundled application, with a <code>CFBundleURLTypes</code> array present in it's Info.plist.
+     * See the <a href="http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference">Info.plist Key Reference</a> for more information about adding a <code>CFBundleURLTypes</code> key to your app's Info.plist.
+     *
+     * Setting the handler to <code>null</code> causes all {@link OpenURIHandler#openURI(AppEvent.OpenURIEvent)} requests to be enqueued until another handler is set.
+     *
+     * @param openURIHandler
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
+        eventHandler.openURIDispatcher.setHandler(openURIHandler);
+    }
+
+    /**
+     * Installs the handler which determines if the application should quit.
+     * The handler is passed a one-shot {@link QuitResponse} which can cancel or proceed with the quit.
+     * Setting the handler to <code>null</code> causes all quit requests to directly perform the default {@link QuitStrategy}.
+     *
+     * @param quitHandler the handler that is called when the application is asked to quit
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void setQuitHandler(final QuitHandler quitHandler) {
+        eventHandler.quitDispatcher.setHandler(quitHandler);
+    }
+
+    /**
+     * Sets the default strategy used to quit this application. The default is calling SYSTEM_EXIT_0.
+     *
+     * The quit strategy can also be set with the "apple.eawt.quitStrategy" system property.
+     *
+     * @param strategy the way this application should be shutdown
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void setQuitStrategy(final QuitStrategy strategy) {
+        eventHandler.setDefaultQuitStrategy(strategy);
+    }
+
+    /**
+     * Enables this application to be suddenly terminated.
+     *
+     * Call this method to indicate your application's state is saved, and requires no notification to be terminated.
+     * Letting your application remain terminatable improves the user experience by avoiding re-paging in your application when it's asked to quit.
+     *
+     * <b>Note: enabling sudden termination will allow your application to be quit without notifying your QuitHandler, or running any shutdown hooks.</b>
+     * User initiated Cmd-Q, logout, restart, or shutdown requests will effectively "kill -KILL" your application.
+     *
+     * This call has no effect on Mac OS X versions prior to 10.6.
+     *
+     * @see <a href="http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSProcessInfo_Class">NSProcessInfo class references</a> for more information about Sudden Termination.
+     * @see Application#disableSuddenTermination()
+     *
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void enableSuddenTermination() {
+        _AppMiscHandlers.enableSuddenTermination();
+    }
+
+    /**
+     * Prevents this application from being suddenly terminated.
+     *
+     * Call this method to indicate that your application has unsaved state, and may not be terminated without notification.
+     *
+     * This call has no effect on Mac OS X versions prior to 10.6.
+     *
+     * @see <a href="http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSProcessInfo_Class">NSProcessInfo class references</a> for more information about Sudden Termination.
+     * @see Application#enableSuddenTermination()
+     *
+     * @since Java for Mac OS X 10.6 Update 3
+     * @since Java for Mac OS X 10.5 Update 8
+     */
+    public void disableSuddenTermination() {
+        _AppMiscHandlers.disableSuddenTermination();
+    }
+
+    /**
+     * Requests this application to move to the foreground.
+     *
+     * @param allWindows if all windows of this application should be moved to the foreground, or only the foremost one
+     *
+     * @since Java for Mac OS X 10.6 Update 1
+     * @since Java for Mac OS X 10.5 Update 6 - 1.6, 1.5
+     */
+    public void requestForeground(final boolean allWindows) {
+        _AppMiscHandlers.requestActivation(allWindows);
+    }
+
+    /**
+     * Requests user attention to this application (usually through bouncing the Dock icon). Critical
+     * requests will continue to bounce the Dock icon until the app is activated. An already active
+     * application requesting attention does nothing.
+     *
+     * @param critical if this is an important request
+     *
+     * @since Java for Mac OS X 10.6 Update 1
+     * @since Java for Mac OS X 10.5 Update 6 - 1.6, 1.5
+     */
+    public void requestUserAttention(final boolean critical) {
+        _AppMiscHandlers.requestUserAttention(critical);
+    }
+
+    /**
+     * Opens the native help viewer application if a Help Book has been added to the
+     * application bundler and registered in the Info.plist with CFBundleHelpBookFolder.
+     *
+     * See http://developer.apple.com/qa/qa2001/qa1022.html for more information.
+     *
+     * @since Java for Mac OS X 10.5 - 1.5
+     * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public void openHelpViewer() {
+        _AppMiscHandlers.openHelpViewer();
+    }
+
+    /**
+     * Attaches the contents of the provided PopupMenu to the application's Dock icon.
+     *
+     * @param menu the PopupMenu to attach to this application's Dock icon
+     *
+     * @since Java for Mac OS X 10.5 - 1.5
+     * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public void setDockMenu(final PopupMenu menu) {
+        iconHandler.setDockMenu(menu);
+    }
+
+    /**
+     * @return the PopupMenu used to add items to this application's Dock icon
+     *
+     * @since Java for Mac OS X 10.5 - 1.5
+     * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public PopupMenu getDockMenu() {
+        return iconHandler.getDockMenu();
+    }
+
+    /**
+     * Changes this application's Dock icon to the provided image.
+     *
+     * @param image
+     *
+     * @since Java for Mac OS X 10.5 - 1.5
+     * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public void setDockIconImage(final Image image) {
+        iconHandler.setDockIconImage(image);
+    }
+
+    /**
+     * Obtains an image of this application's Dock icon.
+     *
+     * @return an image of this application's Dock icon
+     *
+     * @since Java for Mac OS X 10.5 - 1.5
+     * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public Image getDockIconImage() {
+        return iconHandler.getDockIconImage();
+    }
+
+    /**
+     * Affixes a small system provided badge to this application's Dock icon. Usually a number.
+     *
+     * @param badge textual label to affix to the Dock icon
+     *
+     * @since Java for Mac OS X 10.5 - 1.5
+     * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public void setDockIconBadge(final String badge) {
+        iconHandler.setDockIconBadge(badge);
+    }
+
+    /**
+     * Sets the default menu bar to use when there are no active frames.
+     * Only used when the system property "apple.laf.useScreenMenuBar" is "true", and
+     * the Aqua Look and Feel is active.
+     *
+     * @param menuBar to use when no other frames are active
+     *
+     * @since Java for Mac OS X 10.6 Update 1
+     * @since Java for Mac OS X 10.5 Update 6 - 1.6, 1.5
+     */
+    public void setDefaultMenuBar(final JMenuBar menuBar) {
+        menuBarHandler.setDefaultMenuBar(menuBar);
+    }
+
+    /**
+     * Requests that a {@link Window} should animate into or out of full screen mode.
+     * Only {@link Window}s marked as full screenable by {@link FullScreenUtilities#setWindowCanFullScreen(Window, boolean)} can be toggled.
+     *
+     * @param window to animate into or out of full screen mode
+     *
+     * @since Java for Mac OS X 10.7 Update 1
+     */
+    @SuppressWarnings("deprecation")
+    public void requestToggleFullScreen(final Window window) {
+        final ComponentPeer peer = window.getPeer();
+
+        if (!(peer instanceof LWWindowPeer)) return;
+        Object platformWindow = ((LWWindowPeer) peer).getPlatformWindow();
+        if (!(platformWindow instanceof CPlatformWindow)) return;
+        ((CPlatformWindow)platformWindow).toggleFullScreen();
+    }
+
+
+    // -- DEPRECATED API --
+
+    /**
+     * Adds the specified ApplicationListener as a receiver of callbacks from this class.
+     * This method throws a RuntimeException if the newer About, Preferences, Quit, etc handlers are installed.
+     *
+     * @param listener an implementation of ApplicationListener that handles ApplicationEvents
+     *
+     * @deprecated register individual handlers for each task (About, Preferences, Open, Print, Quit, etc)
+     * @since 1.4
+     */
+    @SuppressWarnings("deprecation")
+    @Deprecated
+    public void addApplicationListener(final ApplicationListener listener) {
+        eventHandler.legacyHandler.addLegacyAppListener(listener);
+    }
+
+    /**
+     * Removes the specified ApplicationListener from being a receiver of callbacks from this class.
+     * This method throws a RuntimeException if the newer About, Preferences, Quit, etc handlers are installed.
+     *
+     * @param listener an implementation of ApplicationListener that had previously been registered to handle ApplicationEvents
+     *
+     * @deprecated unregister individual handlers for each task (About, Preferences, Open, Print, Quit, etc)
+     * @since 1.4
+     */
+    @SuppressWarnings("deprecation")
+    @Deprecated
+    public void removeApplicationListener(final ApplicationListener listener) {
+        eventHandler.legacyHandler.removeLegacyAppListener(listener);
+    }
+
+    /**
+     * Enables the Preferences item in the application menu. The ApplicationListener receives a callback for
+     * selection of the Preferences item in the application menu only if this is set to <code>true</code>.
+     *
+     * If a Preferences item isn't present, this method adds and enables it.
+     *
+     * @param enable specifies whether the Preferences item in the application menu should be enabled (<code>true</code>) or not (<code>false</code>)
+     *
+     * @deprecated no replacement
+     * @since 1.4
+     */
+    @Deprecated
+    public void setEnabledPreferencesMenu(final boolean enable) {
+        menuBarHandler.setPreferencesMenuItemVisible(true);
+        menuBarHandler.setPreferencesMenuItemEnabled(enable);
+    }
+
+    /**
+     * Enables the About item in the application menu. The ApplicationListener receives a callback for
+     * selection of the About item in the application menu only if this is set to <code>true</code>. Because AWT supplies
+     * a standard About window when an application may not, by default this is set to <code>true</code>.
+     *
+     * If the About item isn't present, this method adds and enables it.
+     *
+     * @param enable specifies whether the About item in the application menu should be enabled (<code>true</code>) or not (<code>false</code>)
+     *
+     * @deprecated no replacement
+     * @since 1.4
+     */
+    @Deprecated
+    public void setEnabledAboutMenu(final boolean enable) {
+        menuBarHandler.setAboutMenuItemEnabled(enable);
+    }
+
+    /**
+     * Determines if the Preferences item of the application menu is enabled.
+     *
+     * @deprecated no replacement
+     * @since 1.4
+     */
+    @Deprecated
+    public boolean getEnabledPreferencesMenu() {
+        return menuBarHandler.isPreferencesMenuItemEnabled();
+    }
+
+    /**
+     * Determines if the About item of the application menu is enabled.
+     *
+     * @deprecated no replacement
+     * @since 1.4
+     */
+    @Deprecated
+    public boolean getEnabledAboutMenu() {
+        return menuBarHandler.isAboutMenuItemEnabled();
+    }
+
+    /**
+     * Determines if the About item of the application menu is present.
+     *
+     * @deprecated no replacement
+     * @since 1.4
+     */
+    @Deprecated
+    public boolean isAboutMenuItemPresent() {
+        return menuBarHandler.isAboutMenuItemVisible();
+    }
+
+    /**
+     * Adds the About item to the application menu if the item is not already present.
+     *
+     * @deprecated use {@link #setAboutHandler(AboutHandler)} with a non-null {@link AboutHandler} parameter
+     * @since 1.4
+     */
+    @Deprecated
+    public void addAboutMenuItem() {
+        menuBarHandler.setAboutMenuItemVisible(true);
+    }
+
+    /**
+     * Removes the About item from the application menu if  the item is present.
+     *
+     * @deprecated use {@link #setAboutHandler(AboutHandler)} with a null parameter
+     * @since 1.4
+     */
+    @Deprecated
+    public void removeAboutMenuItem() {
+        menuBarHandler.setAboutMenuItemVisible(false);
+    }
+
+    /**
+     * Determines if the About Preferences of the application menu is present. By default there is no Preferences menu item.
+     *
+     * @deprecated no replacement
+     * @since 1.4
+     */
+    @Deprecated
+    public boolean isPreferencesMenuItemPresent() {
+        return menuBarHandler.isPreferencesMenuItemVisible();
+    }
+
+    /**
+     * Adds the Preferences item to the application menu if the item is not already present.
+     *
+     * @deprecated use {@link #setPreferencesHandler(PreferencesHandler)} with a non-null {@link PreferencesHandler} parameter
+     * @since 1.4
+     */
+    @Deprecated
+    public void addPreferencesMenuItem() {
+        menuBarHandler.setPreferencesMenuItemVisible(true);
+    }
+
+    /**
+     * Removes the Preferences item from the application menu if that item is present.
+     *
+     * @deprecated use {@link #setPreferencesHandler(PreferencesHandler)} with a null parameter
+     * @since 1.4
+     */
+    @Deprecated
+    public void removePreferencesMenuItem() {
+        menuBarHandler.setPreferencesMenuItemVisible(false);
+    }
+
+    /**
+     * @deprecated Use <code>java.awt.MouseInfo.getPointerInfo().getLocation()</code>.
+     *
+     * @since 1.4
+     */
+    @Deprecated
+    public static Point getMouseLocationOnScreen() {
+        return java.awt.MouseInfo.getPointerInfo().getLocation();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/ApplicationAdapter.java b/jdk/src/macosx/classes/com/apple/eawt/ApplicationAdapter.java
new file mode 100644
index 0000000..73a96d7
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/ApplicationAdapter.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+/**
+ * An abstract adapter class for receiving <code>ApplicationEvents</code>.
+ *
+ * ApplicationEvents are deprecated. Use individual app event listeners or handlers instead.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @see AboutHandler
+ * @see PreferencesHandler
+ * @see OpenURIHandler
+ * @see OpenFilesHandler
+ * @see PrintFilesHandler
+ * @see QuitHandler
+ *
+ * @see AppReOpenedListener
+ * @see AppForegroundListener
+ * @see AppHiddenListener
+ * @see UserSessionListener
+ * @see ScreenSleepListener
+ * @see SystemSleepListener
+ *
+ * @deprecated replaced by {@link AboutHandler}, {@link PreferencesHandler}, {@link AppReOpenedListener}, {@link OpenFilesHandler}, {@link PrintFilesHandler}, {@link QuitHandler}, {@link QuitResponse}.
+ * @since 1.4
+ */
+@SuppressWarnings("deprecation")
+@Deprecated
+public class ApplicationAdapter implements ApplicationListener {
+    @Deprecated
+    public void handleAbout(final ApplicationEvent event) { }
+
+    @Deprecated
+    public void handleOpenApplication(final ApplicationEvent event) { }
+
+    @Deprecated
+    public void handleOpenFile(final ApplicationEvent event) { }
+
+    @Deprecated
+    public void handlePreferences(final ApplicationEvent event) { }
+
+    @Deprecated
+    public void handlePrintFile(final ApplicationEvent event) { }
+
+    @Deprecated
+    public void handleQuit(final ApplicationEvent event) { }
+
+    @Deprecated
+    public void handleReOpenApplication(final ApplicationEvent event) { }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/ApplicationBeanInfo.java b/jdk/src/macosx/classes/com/apple/eawt/ApplicationBeanInfo.java
new file mode 100644
index 0000000..ee960f6
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/ApplicationBeanInfo.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.*;
+import java.beans.SimpleBeanInfo;
+
+/**
+ * This class is used by JavaBeans tools and should not be used directly by applications.
+ */
+public class ApplicationBeanInfo extends SimpleBeanInfo {
+    public Image getIcon(final int iconKind) {
+        return Toolkit.getDefaultToolkit().getImage("NSImage://NSGenericApplication");
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/ApplicationEvent.java b/jdk/src/macosx/classes/com/apple/eawt/ApplicationEvent.java
new file mode 100644
index 0000000..72bb391
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/ApplicationEvent.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.util.EventObject;
+
+/**
+ * The class of events sent to the deprecated ApplicationListener callbacks.
+ *
+ * @deprecated replaced by {@link AboutHandler}, {@link PreferencesHandler}, {@link AppReOpenedListener}, {@link OpenFilesHandler}, {@link PrintFilesHandler}, {@link QuitHandler}, {@link QuitResponse}
+ * @since 1.4
+ */
+@Deprecated
+public class ApplicationEvent extends EventObject {
+    private String fFilename = null;
+    private boolean fHandled = false;
+
+    ApplicationEvent(final Object source) {
+        super(source);
+    }
+
+    ApplicationEvent(final Object source, final String filename) {
+        super(source);
+        fFilename = filename;
+    }
+
+    /**
+     * Determines whether an ApplicationListener has acted on a particular event.
+     * An event is marked as having been handled with <code>setHandled(true)</code>.
+     *
+     * @return <code>true</code> if the event has been handled, otherwise <code>false</code>
+     *
+     * @since 1.4
+     * @deprecated
+     */
+    @Deprecated
+    public boolean isHandled() {
+        return fHandled;
+    }
+
+    /**
+     * Marks the event as handled.
+     * After this method handles an ApplicationEvent, it may be useful to specify that it has been handled.
+     * This is usually used in conjunction with <code>getHandled()</code>.
+     * Set to <code>true</code> to designate that this event has been handled. By default it is <code>false</code>.
+     *
+     * @param state <code>true</code> if the event has been handled, otherwise <code>false</code>.
+     *
+     * @since 1.4
+     * @deprecated
+     */
+    @Deprecated
+    public void setHandled(final boolean state) {
+        fHandled = state;
+    }
+
+    /**
+     * Provides the filename associated with a particular AppleEvent.
+     * When the ApplicationEvent corresponds to an AppleEvent that needs to act on a particular file, the ApplicationEvent carries the name of the specific file with it.
+     * For example, the Print and Open events refer to specific files.
+     * For these cases, this returns the appropriate file name.
+     *
+     * @return the full path to the file associated with the event, if applicable, otherwise <code>null</code>
+     *
+     * @since 1.4
+     * @deprecated use {@link OpenFilesHandler} or {@link PrintFilesHandler} instead
+     */
+    @Deprecated
+    public String getFilename() {
+        return fFilename;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/ApplicationListener.java b/jdk/src/macosx/classes/com/apple/eawt/ApplicationListener.java
new file mode 100644
index 0000000..ebb2ad8
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/ApplicationListener.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.util.EventListener;
+
+/**
+ * ApplicationEvents are deprecated. Use individual AppEvent listeners or handlers instead.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @see AboutHandler
+ * @see PreferencesHandler
+ * @see OpenURIHandler
+ * @see OpenFilesHandler
+ * @see PrintFilesHandler
+ * @see QuitHandler
+ *
+ * @see AppReOpenedListener
+ * @see AppForegroundListener
+ * @see AppHiddenListener
+ * @see UserSessionListener
+ * @see ScreenSleepListener
+ * @see SystemSleepListener
+ *
+ * @since 1.4
+ * @deprecated replaced by {@link AboutHandler}, {@link PreferencesHandler}, {@link AppReOpenedListener}, {@link OpenFilesHandler}, {@link PrintFilesHandler}, {@link QuitHandler}, {@link QuitResponse}
+ */
+@SuppressWarnings("deprecation")
+@Deprecated
+public interface ApplicationListener extends EventListener {
+    /**
+     * Called when the user selects the About item in the application menu. If <code>event</code> is not handled by
+     * setting <code>isHandled(true)</code>, a default About window consisting of the application's name and icon is
+     * displayed. To display a custom About window, designate the <code>event</code> as being handled and display the
+     * appropriate About window.
+     *
+     * @param event an ApplicationEvent initiated by the user choosing About in the application menu
+     * @deprecated use {@link AboutHandler}
+     */
+    @Deprecated
+    public void handleAbout(ApplicationEvent event);
+
+    /**
+     * Called when the application receives an Open Application event from the Finder or another application. Usually
+     * this will come from the Finder when a user double-clicks your application icon. If there is any special code
+     * that you want to run when you user launches your application from the Finder or by sending an Open Application
+     * event from another application, include that code as part of this handler. The Open Application event is sent
+     * after AWT has been loaded.
+     *
+     * @param event the Open Application event
+     * @deprecated no replacement
+     */
+    @Deprecated
+    public void handleOpenApplication(ApplicationEvent event);
+
+    /**
+     * Called when the application receives an Open Document event from the Finder or another application. This event
+     * is generated when a user double-clicks a document in the Finder. If the document is registered as belonging
+     * to your application, this event is sent to your application. Documents are bound to a particular application based
+     * primarily on their suffix. In the Finder, a user selects a document and then from the File Menu chooses Get Info.
+     * The Info window allows users to bind a document to a particular application.
+     *
+     * These events are sent only if the bound application has file types listed in the Info.plist entries Document Types
+     * or CFBundleDocumentTypes.
+     *
+     * The ApplicationEvent sent to this handler holds a reference to the file being opened.
+     *
+     * @param event an Open Document event with reference to the file to be opened
+     * @deprecated use {@link OpenFilesHandler}
+     */
+    @Deprecated
+    public void handleOpenFile(ApplicationEvent event);
+
+    /**
+     * Called when the Preference item in the application menu is selected. Native Mac OS X applications make their
+     * Preferences window available through the application menu. Java applications are automatically given an application
+     * menu in Mac OS X. By default, the Preferences item is disabled in that menu. If you are deploying an application
+     * on Mac OS X, you should enable the preferences item with <code>setEnabledPreferencesMenu(true)</code> in the
+     * Application object and then display your Preferences window in this handler.
+     *
+     * @param event triggered when the user selects Preferences from the application menu
+     * @deprecated use {@link PreferencesHandler}
+     */
+    @Deprecated
+    public void handlePreferences(ApplicationEvent event);
+
+    /**
+     * Called when the application is sent a request to print a particular file or files. You can allow other applications to
+     * print files with your application by implementing this handler. If another application sends a Print Event along
+     * with the name of a file that your application knows how to process, you can use this handler to determine what to
+     * do with that request. You might open your entire application, or just invoke your printing classes.
+     *
+     * These events are sent only if the bound application has file types listed in the Info.plist entries Document Types
+     * or CFBundleDocumentTypes.
+     *
+     * The ApplicationEvent sent to this handler holds a reference to the file being opened.
+     *
+     * @param event a Print Document event with a reference to the file(s) to be printed
+     * @deprecated use {@link PrintFilesHandler}
+     */
+    @Deprecated
+    public void handlePrintFile(ApplicationEvent event);
+
+    /**
+     * Called when the application is sent the Quit event. This event is generated when the user selects Quit from the
+     * application menu, when the user types Command-Q, or when the user control clicks on your application icon in the
+     * Dock and chooses Quit. You can either accept or reject the request to quit. You might want to reject the request
+     * to quit if the user has unsaved work. Reject the request, move into your code to save changes, then quit your
+     * application. To accept the request to quit, and terminate the application, set <code>isHandled(true)</code> for the
+     * <code>event</code>. To reject the quit, set <code>isHandled(false)</code>.
+     *
+     * @param event a Quit Application event
+     * @deprecated use {@link QuitHandler} and {@link QuitResponse}
+     */
+    @Deprecated
+    public void handleQuit(ApplicationEvent event);
+
+    /**
+     * Called when the application receives a Reopen Application event from the Finder or another application. Usually
+     * this will come when a user clicks on your application icon in the Dock. If there is any special code
+     * that needs to run when your user clicks on your application icon in the Dock or when a Reopen Application
+     * event is sent from another application, include that code as part of this handler.
+     *
+     * @param event the Reopen Application event
+     * @deprecated use {@link AppReOpenedListener}
+     */
+    @Deprecated
+    public void handleReOpenApplication(ApplicationEvent event);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/FullScreenAdapter.java b/jdk/src/macosx/classes/com/apple/eawt/FullScreenAdapter.java
new file mode 100644
index 0000000..3900c2e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/FullScreenAdapter.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.FullScreenEvent;
+
+/**
+ * Abstract adapter class for receiving fullscreen events. This class is provided
+ * as a convenience for creating listeners.
+ *
+ * Subclasses registered with {@link FullScreenUtilities#addFullScreenListenerTo(javax.swing.RootPaneContainer, FullScreenListener)}
+ * will receive all entering/entered/exiting/exited full screen events.
+ *
+ * @see FullScreenUtilities
+ *
+ * @since Java for Mac OS X 10.7 Update 1
+ */
+public abstract class FullScreenAdapter implements FullScreenListener {
+        public void windowEnteringFullScreen(final FullScreenEvent e) {}
+        public void windowEnteredFullScreen(final FullScreenEvent e) {}
+        public void windowExitingFullScreen(final FullScreenEvent e) {}
+        public void windowExitedFullScreen(final FullScreenEvent e) {}
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/FullScreenHandler.java b/jdk/src/macosx/classes/com/apple/eawt/FullScreenHandler.java
new file mode 100644
index 0000000..8b8c2a5
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/FullScreenHandler.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.RootPaneContainer;
+
+import com.apple.eawt.AppEvent.FullScreenEvent;
+
+final class FullScreenHandler {
+    private static final String CLIENT_PROPERTY = "com.apple.eawt.event.internalFullScreenHandler";
+
+    static final int FULLSCREEN_WILL_ENTER = 1;
+    static final int FULLSCREEN_DID_ENTER = 2;
+    static final int FULLSCREEN_WILL_EXIT = 3;
+    static final int FULLSCREEN_DID_EXIT = 4;
+
+    // installs a private instance of the handler, if necessary
+    static void addFullScreenListenerTo(final RootPaneContainer window, final FullScreenListener listener) {
+        final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
+        if (value instanceof FullScreenHandler) {
+            ((FullScreenHandler)value).addListener(listener);
+            return;
+        }
+
+        if (value != null) return; // some other garbage is in our client property
+
+        final FullScreenHandler newHandler = new FullScreenHandler();
+        newHandler.addListener(listener);
+        window.getRootPane().putClientProperty(CLIENT_PROPERTY, newHandler);
+    }
+
+    // asks the installed FullScreenHandler to remove it's listener (does not uninstall the FullScreenHandler)
+    static void removeFullScreenListenerFrom(final RootPaneContainer window, final FullScreenListener listener) {
+        final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
+        if (!(value instanceof FullScreenHandler)) return;
+        ((FullScreenHandler)value).removeListener(listener);
+    }
+
+    static FullScreenHandler getHandlerFor(final RootPaneContainer window) {
+        final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
+        if (value instanceof FullScreenHandler) return (FullScreenHandler)value;
+        return null;
+    }
+
+    // called from native
+    static void handleFullScreenEventFromNative(final Window window, final int type) {
+        if (!(window instanceof RootPaneContainer)) return; // handles null
+
+        EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                final FullScreenHandler handler = getHandlerFor((RootPaneContainer)window);
+                if (handler != null) handler.notifyListener(new FullScreenEvent(window), type);
+            }
+        });
+    }
+
+
+    final List<FullScreenListener> listeners = new LinkedList<FullScreenListener>();
+
+    FullScreenHandler() { }
+
+    void addListener(final FullScreenListener listener) {
+        listeners.add(listener);
+    }
+
+    void removeListener(final FullScreenListener listener) {
+        listeners.remove(listener);
+    }
+
+    void notifyListener(final FullScreenEvent e, final int op) {
+        for (final FullScreenListener listener : listeners) {
+                switch (op) {
+                case FULLSCREEN_WILL_ENTER:
+                        listener.windowEnteringFullScreen(e);
+                    return;
+                case FULLSCREEN_DID_ENTER:
+                        listener.windowEnteredFullScreen(e);
+                    return;
+                case FULLSCREEN_WILL_EXIT:
+                        listener.windowExitingFullScreen(e);
+                    return;
+                case FULLSCREEN_DID_EXIT:
+                        listener.windowExitedFullScreen(e);
+                    return;
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/FullScreenListener.java b/jdk/src/macosx/classes/com/apple/eawt/FullScreenListener.java
new file mode 100644
index 0000000..8b1b442
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/FullScreenListener.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.util.EventListener;
+
+import com.apple.eawt.AppEvent.FullScreenEvent;
+
+/**
+ *
+ *
+ * @since Java for Mac OS X 10.7 Update 1
+ */
+public interface FullScreenListener extends EventListener {
+        /**
+     * Invoked when a window has started to enter full screen.
+     * @param event containing the specific window entering full screen.
+     */
+        public void windowEnteringFullScreen(final FullScreenEvent e);
+
+        /**
+     * Invoked when a window has fully entered full screen.
+     * @param event containing the specific window which has entered full screen.
+     */
+        public void windowEnteredFullScreen(final FullScreenEvent e);
+
+        /**
+     * Invoked when a window has started to exit full screen.
+     * @param event containing the specific window exiting full screen.
+     */
+        public void windowExitingFullScreen(final FullScreenEvent e);
+
+        /**
+     * Invoked when a window has fully exited full screen.
+     * @param event containing the specific window which has exited full screen.
+     */
+        public void windowExitedFullScreen(final FullScreenEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/FullScreenUtilities.java b/jdk/src/macosx/classes/com/apple/eawt/FullScreenUtilities.java
new file mode 100644
index 0000000..bd02d70
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/FullScreenUtilities.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.*;
+
+import javax.swing.RootPaneContainer;
+
+import sun.lwawt.macosx.*;
+
+import com.apple.eawt.event.GestureUtilities;
+
+/**
+ * Utility class perform animated full screen actions to top-level {@link Window}s.
+ *
+ * This class manages the relationship between {@link Windows}s and the {@link FullScreenListener}s
+ * attached to them. It's design is similar to the Java SE 6u10 {@link com.sun.awt.AWTUtilities}
+ * class which adds additional functionality to AWT Windows, without adding new API to the
+ * {@link java.awt.Window} class.
+ *
+ * Full screen operations can only be performed on top-level {@link Window}s that are also {@link RootPaneContainer}s.
+ *
+ * @see FullScreenAdapter
+ * @see GestureUtilities
+ * @see com.sun.awt.AWTUtilities
+ *
+ * @since Java for Mac OS X 10.7 Update 1
+ */
+public final class FullScreenUtilities {
+    FullScreenUtilities() {
+        // package private
+    }
+
+    /**
+     * Marks a {@link Window} as able to animate into or out of full screen mode.
+     *
+     * Only top-level {@link Window}s which are {@link RootPaneContainer}s are able to be animated into and out of full screen mode.
+     * The {@link Window} must be marked as full screen-able before the native peer is created with {@link Component#addNotify()}.
+     *
+     * @param window
+     * @param canFullScreen
+     * @throws IllegalArgumentException if window is not a {@link RootPaneContainer}
+     */
+    public static void setWindowCanFullScreen(final Window window, final boolean canFullScreen) {
+        if (!(window instanceof RootPaneContainer)) throw new IllegalArgumentException("Can't mark a non-RootPaneContainer as full screen-able");
+        final RootPaneContainer rpc = (RootPaneContainer)window;
+        rpc.getRootPane().putClientProperty(CPlatformWindow.WINDOW_FULLSCREENABLE, Boolean.valueOf(canFullScreen));
+    }
+
+    /**
+     * Attaches a {@link FullScreenListener} to the specified top-level {@link Window}.
+     * @param window to attach the {@link FullScreenListener} to
+     * @param listener to be notified when a full screen event occurs
+     * @throws IllegalArgumentException if window is not a {@link RootPaneContainer}
+     */
+    public static void addFullScreenListenerTo(final Window window, final FullScreenListener listener) {
+        if (!(window instanceof RootPaneContainer)) throw new IllegalArgumentException("Can't attach FullScreenListener to a non-RootPaneContainer");
+        if (listener == null) throw new NullPointerException();
+        FullScreenHandler.addFullScreenListenerTo((RootPaneContainer)window, listener);
+    }
+
+    /**
+     * Removes a {@link FullScreenListener} from the specified top-level {@link Window}.
+     * @param window to remove the {@link FullScreenListener} from
+     * @param listener to be removed
+     * @throws IllegalArgumentException if window is not a {@link RootPaneContainer}
+     */
+    public static void removeFullScreenListenerFrom(final Window window, final FullScreenListener listener) {
+        if (!(window instanceof RootPaneContainer)) throw new IllegalArgumentException("Can't remove FullScreenListener from non-RootPaneContainer");
+        if (listener == null) throw new NullPointerException();
+        FullScreenHandler.removeFullScreenListenerFrom((RootPaneContainer)window, listener);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/OpenFilesHandler.java b/jdk/src/macosx/classes/com/apple/eawt/OpenFilesHandler.java
new file mode 100644
index 0000000..f7c8327
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/OpenFilesHandler.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.OpenFilesEvent;
+
+/**
+ * An implementor is notified when the application is asked to open a list of files.
+ * This message is only sent if the application has registered that it handles CFBundleDocumentTypes in it's Info.plist.
+ *
+ * @see Application#setOpenFileHandler(OpenFilesHandler)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface OpenFilesHandler {
+    /**
+     * Called when the application is asked to open a list of files.
+     * @param e the request to open a list of files, and the search term used to find them, if any.
+     */
+    public void openFiles(final OpenFilesEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/OpenURIHandler.java b/jdk/src/macosx/classes/com/apple/eawt/OpenURIHandler.java
new file mode 100644
index 0000000..398c82d
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/OpenURIHandler.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.OpenURIEvent;
+
+/**
+ * An implementor is notified when the application is asked to open a URI.
+ * The application only sends {@link com.apple.eawt.EAWTEvent.OpenURIEvent}s when it has been launched as a bundled Mac application, and it's Info.plist claims URL schemes in it's <code>CFBundleURLTypes</code> entry.
+ * See the <a href="http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference">Info.plist Key Reference</a> for more information about adding a <code>CFBundleURLTypes</code> key to your app's Info.plist.
+ *
+ * @see Application#setOpenURIHandler(OpenURIHandler)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface OpenURIHandler {
+    /**
+     * Called when the application is asked to open a URI
+     * @param e the request to open a URI
+     */
+    public void openURI(final OpenURIEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/PreferencesHandler.java b/jdk/src/macosx/classes/com/apple/eawt/PreferencesHandler.java
new file mode 100644
index 0000000..a3871fc
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/PreferencesHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.PreferencesEvent;
+
+/**
+ * An implementor is notified when the app is asked to show it's preferences UI.
+ *
+ * @see Application#setPreferencesHandler(PreferencesHandler)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface PreferencesHandler {
+    /**
+     * Called when the app is asked to show it's preferences UI.
+     * @param e the request to show preferences.
+     */
+    public void handlePreferences(final PreferencesEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/PrintFilesHandler.java b/jdk/src/macosx/classes/com/apple/eawt/PrintFilesHandler.java
new file mode 100644
index 0000000..f76ca4a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/PrintFilesHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.PrintFilesEvent;
+
+/**
+ * An implementor can respond to requests to print documents that the app has been registered to handle.
+ *
+ * @see Application#setPrintFileHandler(PrintFilesHandler)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface PrintFilesHandler {
+    /**
+     * Called when the application is asked to print a list of files.
+     * @param e the request to print a list of files.
+     */
+    public void printFiles(final PrintFilesEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/QuitHandler.java b/jdk/src/macosx/classes/com/apple/eawt/QuitHandler.java
new file mode 100644
index 0000000..d211b16
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/QuitHandler.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.QuitEvent;
+
+/**
+ * An implementor determines if requests to quit this application should proceed or cancel.
+ *
+ * @see Application#setQuitHandler(QuitHandler)
+ * @see Application#setQuitStrategy(QuitStrategy)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface QuitHandler {
+    /**
+     * Invoked when the application is asked to quit.
+     *
+     * Implementors must call either {@link QuitResponse#cancelQuit()}, {@link QuitResponse#performQuit()}, or ensure the application terminates.
+     * The process (or log-out) requesting this app to quit will be blocked until the {@link QuitResponse} is handled.
+     * Apps that require complex UI to shutdown may call the {@link QuitResponse} from any thread.
+     * Your app may be asked to quit multiple times before you have responded to the initial request.
+     * This handler is called each time a quit is requested, and the same {@link QuitResponse} object is passed until it is handled.
+     * Once used, the {@link QuitResponse} cannot be used again to change the decision.
+     *
+     * @param e the request to quit this application.
+     * @param response the one-shot response object used to cancel or proceed with the quit action.
+     */
+    public void handleQuitRequestWith(final QuitEvent e, final QuitResponse response);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/QuitResponse.java b/jdk/src/macosx/classes/com/apple/eawt/QuitResponse.java
new file mode 100644
index 0000000..6c181ee
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/QuitResponse.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+/**
+ * Used to respond to a request to quit the application.
+ * The QuitResponse may be used after the {@link QuitHandler#handleQuitRequestWith(AppEvent.QuitEvent, QuitResponse)} method has returned, and may be used from any thread.
+ *
+ * @see Application#setQuitHandler(QuitHandler)
+ * @see QuitHandler
+ * @see Application#setQuitStrategy(QuitStrategy)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public class QuitResponse {
+    final _AppEventHandler appEventHandler;
+
+    QuitResponse(final _AppEventHandler appEventHandler) {
+        this.appEventHandler = appEventHandler;
+    }
+
+    /**
+     * Notifies the external quit requester that the quit will proceed, and performs the default {@link QuitStrategy}.
+     */
+    public void performQuit() {
+        if (appEventHandler.currentQuitResponse != this) return;
+        appEventHandler.performQuit();
+    }
+
+    /**
+     * Notifies the external quit requester that the user has explicitly canceled the pending quit, and leaves the application running.
+     * <b>Note: this will cancel a pending log-out, restart, or shutdown.</b>
+     */
+    public void cancelQuit() {
+        if (appEventHandler.currentQuitResponse != this) return;
+        appEventHandler.cancelQuit();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/QuitStrategy.java b/jdk/src/macosx/classes/com/apple/eawt/QuitStrategy.java
new file mode 100644
index 0000000..2aa310e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/QuitStrategy.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+/**
+ * The strategy use to shut down the application, if Sudden Termination is not enabled.
+ *
+ * @see Application#setQuitHandler(QuitHandler)
+ * @see Application#setQuitStrategy(QuitStrategy)
+ * @see Application#enableSuddenTermination()
+ * @see Application#disableSuddenTermination()
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public enum QuitStrategy {
+    /**
+     * Shuts down the application by calling <code>System.exit(0)</code>. This is the default strategy.
+     */
+    SYSTEM_EXIT_0,
+
+    /**
+     * Shuts down the application by closing each window from back-to-front.
+     */
+    CLOSE_ALL_WINDOWS
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/ScreenSleepListener.java b/jdk/src/macosx/classes/com/apple/eawt/ScreenSleepListener.java
new file mode 100644
index 0000000..565f92e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/ScreenSleepListener.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.ScreenSleepEvent;
+
+/**
+ * Implementors receive notification when the displays attached to the system have entered power save sleep.
+ *
+ * This notification is useful for discontinuing a costly animation, or indicating that the user is no longer present on a network service.
+ *
+ * This message is not sent on Mac OS X versions prior to 10.6.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface ScreenSleepListener extends AppEventListener {
+    /**
+     * Called when the system displays have entered power save sleep.
+     * @param e the screen sleep event
+     */
+    public void screenAboutToSleep(final ScreenSleepEvent e);
+
+    /**
+     * Called when the system displays have awoke from power save sleep.
+     * @param e the screen sleep event
+     */
+    public void screenAwoke(final ScreenSleepEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/SystemSleepListener.java b/jdk/src/macosx/classes/com/apple/eawt/SystemSleepListener.java
new file mode 100644
index 0000000..68f6823
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/SystemSleepListener.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.SystemSleepEvent;
+
+/**
+ * Implementors receive notification as the system is entering sleep, and after the system wakes.
+ *
+ * This notification is useful for disconnecting from network services prior to sleep, or re-establishing a connection if the network configuration has changed during sleep.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface SystemSleepListener extends AppEventListener {
+    /**
+     * Called when the system is about to sleep.
+     * Note: This message may not be delivered prior to the actual system sleep, and may be processed after the corresponding wake has occurred.
+     * @param e the system sleep event
+     */
+    public void systemAboutToSleep(final SystemSleepEvent e);
+
+    /**
+     * Called after the system has awoke from sleeping.
+     * @param e the system sleep event
+     */
+    public void systemAwoke(final SystemSleepEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/UserSessionListener.java b/jdk/src/macosx/classes/com/apple/eawt/UserSessionListener.java
new file mode 100644
index 0000000..f74c23a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/UserSessionListener.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import com.apple.eawt.AppEvent.UserSessionEvent;
+
+/**
+ * Implementors receive notification when Fast User Switching changes the user session.
+ *
+ * This notification is useful for discontinuing a costly animation, or indicating that the user is no longer present on a network service.
+ *
+ * @see Application#addAppEventListener(AppEventListener)
+ *
+ * @since Java for Mac OS X 10.6 Update 3
+ * @since Java for Mac OS X 10.5 Update 8
+ */
+public interface UserSessionListener extends AppEventListener {
+    /**
+     * Called when the user session has been switched away.
+     * @param e the user session switch event
+     */
+    public void userSessionDeactivated(final UserSessionEvent e);
+
+    /**
+     * Called when the user session has been switched to.
+     * @param e the user session switch event
+     */
+    public void userSessionActivated(final UserSessionEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/_AppDockIconHandler.java b/jdk/src/macosx/classes/com/apple/eawt/_AppDockIconHandler.java
new file mode 100644
index 0000000..acb01eb
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/_AppDockIconHandler.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.*;
+import java.lang.reflect.*;
+
+import sun.lwawt.macosx.*;
+import sun.lwawt.macosx.CImage.Creator;
+
+class _AppDockIconHandler {
+    private static native void nativeSetDockMenu(final long cmenu);
+    private static native void nativeSetDockIconImage(final long image);
+    private static native long nativeGetDockIconImage();
+    private static native void nativeSetDockIconBadge(final String badge);
+
+    PopupMenu fDockMenu = null;
+
+    _AppDockIconHandler() { }
+
+    @SuppressWarnings("deprecation")
+    public void setDockMenu(final PopupMenu menu) {
+        fDockMenu = menu;
+
+        // clear the menu if explicitly passed null
+        if (menu == null) {
+            nativeSetDockMenu(0);
+            return;
+        }
+
+        // check if the menu needs a parent (8343136)
+        final MenuContainer container = menu.getParent();
+        if (container == null) {
+            final MenuBar newParent = new MenuBar();
+            newParent.add(menu);
+            newParent.addNotify();
+        }
+
+        // instantiate the menu peer and set the native fDockMenu ivar
+        menu.addNotify();
+        final long nsMenuPtr = ((CMenu)fDockMenu.getPeer()).getNativeMenu();
+        nativeSetDockMenu(nsMenuPtr);
+    }
+
+    public PopupMenu getDockMenu() {
+        return fDockMenu;
+    }
+
+    public void setDockIconImage(final Image image) {
+        try {
+            final CImage cImage = getCImageCreator().createFromImage(image);
+            final long nsImagePtr = getNSImagePtrFrom(cImage);
+            nativeSetDockIconImage(nsImagePtr);
+        } catch (final Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    Image getDockIconImage() {
+        try {
+            final long dockNSImage = nativeGetDockIconImage();
+            if (dockNSImage == 0) return null;
+            return getCImageCreator().createImageUsingNativeSize(dockNSImage);
+        } catch (final Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    void setDockIconBadge(final String badge) {
+        nativeSetDockIconBadge(badge);
+    }
+
+    static Creator getCImageCreator() {
+        try {
+            final Method getCreatorMethod = CImage.class.getDeclaredMethod("getCreator", new Class[] {});
+            getCreatorMethod.setAccessible(true);
+            return (Creator)getCreatorMethod.invoke(null, new Object[] {});
+        } catch (final Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    static long getNSImagePtrFrom(final CImage cImage) {
+        if (cImage == null) return 0;
+
+        try {
+            final Field cImagePtrField = CFRetainedResource.class.getDeclaredField("ptr");
+            cImagePtrField.setAccessible(true);
+            return cImagePtrField.getLong(cImage);
+        } catch (final Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/_AppEventHandler.java b/jdk/src/macosx/classes/com/apple/eawt/_AppEventHandler.java
new file mode 100644
index 0000000..e94b66d
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/_AppEventHandler.java
@@ -0,0 +1,548 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.*;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.net.*;
+import java.util.*;
+import java.util.List;
+
+import com.apple.eawt.AppEvent.*;
+
+class _AppEventHandler {
+    private static final int NOTIFY_ABOUT = 1;
+    private static final int NOTIFY_PREFS = 2;
+    private static final int NOTIFY_OPEN_APP = 3;
+    private static final int NOTIFY_REOPEN_APP = 4;
+    private static final int NOTIFY_QUIT = 5;
+    private static final int NOTIFY_SHUTDOWN = 6;
+    private static final int NOTIFY_ACTIVE_APP_GAINED = 7;
+    private static final int NOTIFY_ACTIVE_APP_LOST = 8;
+    private static final int NOTIFY_APP_HIDDEN = 9;
+    private static final int NOTIFY_APP_SHOWN = 10;
+    private static final int NOTIFY_USER_SESSION_ACTIVE = 11;
+    private static final int NOTIFY_USER_SESSION_INACTIVE = 12;
+    private static final int NOTIFY_SCREEN_SLEEP = 13;
+    private static final int NOTIFY_SCREEN_WAKE = 14;
+    private static final int NOTIFY_SYSTEM_SLEEP = 15;
+    private static final int NOTIFY_SYSTEM_WAKE = 16;
+
+    private static final int REGISTER_USER_SESSION = 1;
+    private static final int REGISTER_SCREEN_SLEEP = 2;
+    private static final int REGISTER_SYSTEM_SLEEP = 3;
+
+    private static native void nativeOpenCocoaAboutWindow();
+    private static native void nativeReplyToAppShouldTerminate(final boolean shouldTerminate);
+    private static native void nativeRegisterForNotification(final int notification);
+
+    final static _AppEventHandler instance = new _AppEventHandler();
+    static _AppEventHandler getInstance() {
+        return instance;
+    }
+
+    // single shot dispatchers (some queuing, others not)
+    final _AboutDispatcher aboutDispatcher = new _AboutDispatcher();
+    final _PreferencesDispatcher preferencesDispatcher = new _PreferencesDispatcher();
+    final _OpenFileDispatcher openFilesDispatcher = new _OpenFileDispatcher();
+    final _PrintFileDispatcher printFilesDispatcher = new _PrintFileDispatcher();
+    final _OpenURIDispatcher openURIDispatcher = new _OpenURIDispatcher();
+    final _QuitDispatcher quitDispatcher = new _QuitDispatcher();
+    final _OpenAppDispatcher openAppDispatcher = new _OpenAppDispatcher();
+
+    // multiplexing dispatchers (contains listener lists)
+    final _AppReOpenedDispatcher reOpenAppDispatcher = new _AppReOpenedDispatcher();
+    final _AppForegroundDispatcher foregroundAppDispatcher = new _AppForegroundDispatcher();
+    final _HiddenAppDispatcher hiddenAppDispatcher = new _HiddenAppDispatcher();
+    final _UserSessionDispatcher userSessionDispatcher = new _UserSessionDispatcher();
+    final _ScreenSleepDispatcher screenSleepDispatcher = new _ScreenSleepDispatcher();
+    final _SystemSleepDispatcher systemSleepDispatcher = new _SystemSleepDispatcher();
+
+    final _AppEventLegacyHandler legacyHandler = new _AppEventLegacyHandler(this);
+
+    QuitStrategy defaultQuitAction = QuitStrategy.SYSTEM_EXIT_0;
+
+    _AppEventHandler() {
+        final String strategyProp = System.getProperty("apple.eawt.quitStrategy");
+        if (strategyProp == null) return;
+
+        if ("CLOSE_ALL_WINDOWS".equals(strategyProp)) {
+            setDefaultQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
+        } else if ("SYSTEM_EXIT_O".equals(strategyProp)) {
+            setDefaultQuitStrategy(QuitStrategy.SYSTEM_EXIT_0);
+        } else {
+            System.err.println("unrecognized apple.eawt.quitStrategy: " + strategyProp);
+        }
+    }
+
+    void addListener(final AppEventListener listener) {
+        if (listener instanceof AppReOpenedListener) reOpenAppDispatcher.addListener((AppReOpenedListener)listener);
+        if (listener instanceof AppForegroundListener) foregroundAppDispatcher.addListener((AppForegroundListener)listener);
+        if (listener instanceof AppHiddenListener) hiddenAppDispatcher.addListener((AppHiddenListener)listener);
+        if (listener instanceof UserSessionListener) userSessionDispatcher.addListener((UserSessionListener)listener);
+        if (listener instanceof ScreenSleepListener) screenSleepDispatcher.addListener((ScreenSleepListener)listener);
+        if (listener instanceof SystemSleepListener) systemSleepDispatcher.addListener((SystemSleepListener)listener);
+    }
+
+    void removeListener(final AppEventListener listener) {
+        if (listener instanceof AppReOpenedListener) reOpenAppDispatcher.removeListener((AppReOpenedListener)listener);
+        if (listener instanceof AppForegroundListener) foregroundAppDispatcher.removeListener((AppForegroundListener)listener);
+        if (listener instanceof AppHiddenListener) hiddenAppDispatcher.removeListener((AppHiddenListener)listener);
+        if (listener instanceof UserSessionListener) userSessionDispatcher.removeListener((UserSessionListener)listener);
+        if (listener instanceof ScreenSleepListener) screenSleepDispatcher.removeListener((ScreenSleepListener)listener);
+        if (listener instanceof SystemSleepListener) systemSleepDispatcher.removeListener((SystemSleepListener)listener);
+    }
+
+    void openCocoaAboutWindow() {
+        nativeOpenCocoaAboutWindow();
+    }
+
+    void setDefaultQuitStrategy(final QuitStrategy defaultQuitAction) {
+        this.defaultQuitAction = defaultQuitAction;
+    }
+
+    QuitResponse currentQuitResponse;
+    synchronized QuitResponse obtainQuitResponse() {
+        if (currentQuitResponse != null) return currentQuitResponse;
+        return currentQuitResponse = new QuitResponse(this);
+    }
+
+    synchronized void cancelQuit() {
+        currentQuitResponse = null;
+        nativeReplyToAppShouldTerminate(false);
+    }
+
+    synchronized void performQuit() {
+        currentQuitResponse = null;
+
+        try {
+            if (defaultQuitAction == QuitStrategy.SYSTEM_EXIT_0) System.exit(0);
+
+            if (defaultQuitAction != QuitStrategy.CLOSE_ALL_WINDOWS) {
+                throw new RuntimeException("Unknown quit action");
+            }
+
+            EventQueue.invokeLater(new Runnable() {
+                public void run() {
+                    // walk frames from back to front
+                    final Frame[] allFrames = Frame.getFrames();
+                    for (int i = allFrames.length - 1; i >= 0; i--) {
+                        final Frame frame = allFrames[i];
+                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
+                    }
+                }
+            });
+        } finally {
+            nativeReplyToAppShouldTerminate(true);
+        }
+    }
+
+    /*
+     * callbacks from native delegate
+     */
+    private static void handlePrintFiles(final List<String> filenames) {
+        instance.printFilesDispatcher.dispatch(new _NativeEvent(filenames));
+    }
+
+    private static void handleOpenFiles(final List<String> filenames, final String searchTerm) {
+        instance.openFilesDispatcher.dispatch(new _NativeEvent(filenames, searchTerm));
+    }
+
+    private static void handleOpenURI(final String uri) {
+        instance.openURIDispatcher.dispatch(new _NativeEvent(uri));
+    }
+
+    // default funnel for non-complex events
+    private static void handleNativeNotification(final int code) {
+//        System.out.println(code);
+
+        switch (code) {
+            case NOTIFY_ABOUT:
+                instance.aboutDispatcher.dispatch(new _NativeEvent());
+                break;
+            case NOTIFY_PREFS:
+                instance.preferencesDispatcher.dispatch(new _NativeEvent());
+                break;
+            case NOTIFY_OPEN_APP:
+                instance.openAppDispatcher.dispatch(new _NativeEvent());
+                break;
+            case NOTIFY_REOPEN_APP:
+                instance.reOpenAppDispatcher.dispatch(new _NativeEvent());
+                break;
+            case NOTIFY_QUIT:
+                instance.quitDispatcher.dispatch(new _NativeEvent());
+                break;
+            case NOTIFY_SHUTDOWN:
+                // do nothing for now
+                break;
+            case NOTIFY_ACTIVE_APP_GAINED:
+                instance.foregroundAppDispatcher.dispatch(new _NativeEvent(Boolean.TRUE));
+                break;
+            case NOTIFY_ACTIVE_APP_LOST:
+                instance.foregroundAppDispatcher.dispatch(new _NativeEvent(Boolean.FALSE));
+                break;
+            case NOTIFY_APP_HIDDEN:
+                instance.hiddenAppDispatcher.dispatch(new _NativeEvent(Boolean.TRUE));
+                break;
+            case NOTIFY_APP_SHOWN:
+                instance.hiddenAppDispatcher.dispatch(new _NativeEvent(Boolean.FALSE));
+                break;
+            case NOTIFY_USER_SESSION_ACTIVE:
+                instance.userSessionDispatcher.dispatch(new _NativeEvent(Boolean.TRUE));
+                break;
+            case NOTIFY_USER_SESSION_INACTIVE:
+                instance.userSessionDispatcher.dispatch(new _NativeEvent(Boolean.FALSE));
+                break;
+            case NOTIFY_SCREEN_SLEEP:
+                instance.screenSleepDispatcher.dispatch(new _NativeEvent(Boolean.TRUE));
+                break;
+            case NOTIFY_SCREEN_WAKE:
+                instance.screenSleepDispatcher.dispatch(new _NativeEvent(Boolean.FALSE));
+                break;
+            case NOTIFY_SYSTEM_SLEEP:
+                instance.systemSleepDispatcher.dispatch(new _NativeEvent(Boolean.TRUE));
+                break;
+            case NOTIFY_SYSTEM_WAKE:
+                instance.systemSleepDispatcher.dispatch(new _NativeEvent(Boolean.FALSE));
+                break;
+            default:
+                System.err.println("EAWT unknown native notification: " + code);
+                break;
+        }
+    }
+
+
+    class _AboutDispatcher extends _AppEventDispatcher<AboutHandler> {
+        void performDefaultAction(final _NativeEvent event) {
+            openCocoaAboutWindow(); // if the handler is null, fall back to showing the Cocoa default
+        }
+
+        void performUsing(final AboutHandler handler, final _NativeEvent event) {
+            handler.handleAbout(new AboutEvent());
+        }
+    }
+
+    class _PreferencesDispatcher extends _AppEventDispatcher<PreferencesHandler> {
+        synchronized void setHandler(final PreferencesHandler handler) {
+            super.setHandler(handler);
+
+            _AppMenuBarHandler.getInstance().setPreferencesMenuItemVisible(handler != null);
+            _AppMenuBarHandler.getInstance().setPreferencesMenuItemEnabled(handler != null);
+        }
+
+        void performUsing(final PreferencesHandler handler, final _NativeEvent event) {
+            handler.handlePreferences(new PreferencesEvent());
+        }
+    }
+
+    class _OpenAppDispatcher extends _QueuingAppEventDispatcher<com.apple.eawt._OpenAppHandler> {
+        void performUsing(com.apple.eawt._OpenAppHandler handler, _NativeEvent event) {
+            handler.handleOpenApp();
+        }
+    }
+
+    class _AppReOpenedDispatcher extends _AppEventMultiplexor<AppReOpenedListener> {
+        void performOnListeners(final List<AppReOpenedListener> listeners, final _NativeEvent event) {
+            final AppReOpenedEvent e = new AppReOpenedEvent();
+            for (final AppReOpenedListener listener : listeners) {
+                listener.appReOpened(e);
+            }
+        }
+    }
+
+    class _AppForegroundDispatcher extends _BooleanAppEventMultiplexor<AppForegroundListener, AppForegroundEvent> {
+        AppForegroundEvent createEvent(final boolean isTrue) { return new AppForegroundEvent(); }
+
+        void performFalseEventOn(final AppForegroundListener listener, final AppForegroundEvent e) {
+            listener.appMovedToBackground(e);
+        }
+
+        void performTrueEventOn(final AppForegroundListener listener, final AppForegroundEvent e) {
+            listener.appRaisedToForeground(e);
+        }
+    }
+
+    class _HiddenAppDispatcher extends _BooleanAppEventMultiplexor<AppHiddenListener, AppHiddenEvent> {
+        AppHiddenEvent createEvent(final boolean isTrue) { return new AppHiddenEvent(); }
+
+        void performFalseEventOn(final AppHiddenListener listener, final AppHiddenEvent e) {
+            listener.appUnhidden(e);
+        }
+
+        void performTrueEventOn(final AppHiddenListener listener, final AppHiddenEvent e) {
+            listener.appHidden(e);
+        }
+    }
+
+    class _UserSessionDispatcher extends _BooleanAppEventMultiplexor<UserSessionListener, UserSessionEvent> {
+        UserSessionEvent createEvent(final boolean isTrue) { return new UserSessionEvent(); }
+
+        void performFalseEventOn(final UserSessionListener listener, final UserSessionEvent e) {
+            listener.userSessionDeactivated(e);
+        }
+
+        void performTrueEventOn(final UserSessionListener listener, final UserSessionEvent e) {
+            listener.userSessionActivated(e);
+        }
+
+        void registerNativeListener() {
+            nativeRegisterForNotification(REGISTER_USER_SESSION);
+        }
+    }
+
+    class _ScreenSleepDispatcher extends _BooleanAppEventMultiplexor<ScreenSleepListener, ScreenSleepEvent> {
+        ScreenSleepEvent createEvent(final boolean isTrue) { return new ScreenSleepEvent(); }
+
+        void performFalseEventOn(final ScreenSleepListener listener, final ScreenSleepEvent e) {
+            listener.screenAwoke(e);
+        }
+
+        void performTrueEventOn(final ScreenSleepListener listener, final ScreenSleepEvent e) {
+            listener.screenAboutToSleep(e);
+        }
+
+        void registerNativeListener() {
+            nativeRegisterForNotification(REGISTER_SCREEN_SLEEP);
+        }
+    }
+
+    class _SystemSleepDispatcher extends _BooleanAppEventMultiplexor<SystemSleepListener, SystemSleepEvent> {
+        SystemSleepEvent createEvent(final boolean isTrue) { return new SystemSleepEvent(); }
+
+        void performFalseEventOn(final SystemSleepListener listener, final SystemSleepEvent e) {
+            listener.systemAwoke(e);
+        }
+
+        void performTrueEventOn(final SystemSleepListener listener, final SystemSleepEvent e) {
+            listener.systemAboutToSleep(e);
+        }
+
+        void registerNativeListener() {
+            nativeRegisterForNotification(REGISTER_SYSTEM_SLEEP);
+        }
+    }
+
+    class _OpenFileDispatcher extends _QueuingAppEventDispatcher<OpenFilesHandler> {
+        void performUsing(final OpenFilesHandler handler, final _NativeEvent event) {
+            // create file list from fileNames
+            final List<String> fileNameList = event.get(0);
+            final ArrayList<File> files = new ArrayList<File>(fileNameList.size());
+            for (final String fileName : fileNameList) files.add(new File(fileName));
+
+            // populate the properties map
+            final String searchTerm = event.get(1);
+            handler.openFiles(new OpenFilesEvent(files, searchTerm));
+        }
+    }
+
+    class _PrintFileDispatcher extends _QueuingAppEventDispatcher<PrintFilesHandler> {
+        void performUsing(final PrintFilesHandler handler, final _NativeEvent event) {
+            // create file list from fileNames
+            final List<String> fileNameList = event.get(0);
+            final ArrayList<File> files = new ArrayList<File>(fileNameList.size());
+            for (final String fileName : fileNameList) files.add(new File(fileName));
+
+            handler.printFiles(new PrintFilesEvent(files));
+        }
+    }
+
+    // Java URLs can't handle unknown protocol types, which is why we use URIs
+    class _OpenURIDispatcher extends _QueuingAppEventDispatcher<OpenURIHandler> {
+        void performUsing(final OpenURIHandler handler, final _NativeEvent event) {
+            final String urlString = event.get(0);
+            try {
+                handler.openURI(new OpenURIEvent(new URI(urlString)));
+            } catch (final URISyntaxException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    class _QuitDispatcher extends _AppEventDispatcher<QuitHandler> {
+        void performDefaultAction(final _NativeEvent event) {
+            obtainQuitResponse().performQuit();
+        }
+
+        void performUsing(final QuitHandler handler, final _NativeEvent event) {
+            final QuitResponse response = obtainQuitResponse(); // obtains the "current" quit response
+            handler.handleQuitRequestWith(new QuitEvent(), response);
+        }
+    }
+
+
+// -- ABSTRACT QUEUE/EVENT/LISTENER HELPERS --
+
+    // generic little "raw event" that's constructed easily from the native callbacks
+    static class _NativeEvent {
+        Object[] args;
+
+        public _NativeEvent(final Object... args) {
+            this.args = args;
+        }
+
+        @SuppressWarnings("unchecked")
+        <T> T get(final int i) {
+            if (args == null) return null;
+            return (T)args[i];
+        }
+    }
+
+    abstract class _AppEventMultiplexor<L> {
+        final List<L> _listeners = new ArrayList<L>(0);
+        boolean nativeListenerRegistered;
+
+        // called from AppKit Thread-0
+        void dispatch(final _NativeEvent event, final Object... args) {
+            // grab a local ref to the listeners
+            final List<L> localListeners;
+            synchronized (this) {
+                if (_listeners.size() == 0) return;
+                localListeners = new ArrayList<L>(_listeners);
+            }
+
+            EventQueue.invokeLater(new Runnable() {
+                public void run() {
+                    performOnListeners(localListeners, event);
+                }
+            });
+        }
+
+        synchronized void addListener(final L listener) {
+            if (!nativeListenerRegistered) {
+                registerNativeListener();
+                nativeListenerRegistered = true;
+            }
+            _listeners.add(listener);
+        }
+
+        synchronized void removeListener(final L listener) {
+            _listeners.remove(listener);
+        }
+
+        abstract void performOnListeners(final List<L> listeners, final _NativeEvent event);
+        void registerNativeListener() { }
+    }
+
+    abstract class _BooleanAppEventMultiplexor<L, E> extends _AppEventMultiplexor<L> {
+        @Override
+        void performOnListeners(final List<L> listeners, final _NativeEvent event) {
+            final boolean isTrue = Boolean.TRUE.equals(event.get(0));
+            final E e = createEvent(isTrue);
+            if (isTrue) {
+                for (final L listener : listeners) performTrueEventOn(listener, e);
+            } else {
+                for (final L listener : listeners) performFalseEventOn(listener, e);
+            }
+        }
+
+        abstract E createEvent(final boolean isTrue);
+        abstract void performTrueEventOn(final L listener, final E e);
+        abstract void performFalseEventOn(final L listener, final E e);
+    }
+
+    /*
+     * Ensures that setting and obtaining an app event handler is done in
+     * both a thread-safe manner, and that user code is performed on the
+     * AWT EventQueue thread.
+     *
+     * Allows native to blindly lob new events into the dispatcher,
+     * knowing that they will only be dispatched once a handler is set.
+     *
+     * User code is not (and should not be) run under any synchronized lock.
+     */
+    abstract class _AppEventDispatcher<H> {
+        H _handler;
+
+        // called from AppKit Thread-0
+        void dispatch(final _NativeEvent event) {
+            EventQueue.invokeLater(new Runnable() {
+                public void run() {
+                    // grab a local ref to the handler
+                    final H localHandler;
+                    synchronized (_AppEventDispatcher.this) {
+                        localHandler = _handler;
+                    }
+
+                    // invoke the handler outside of the synchronized block
+                    if (localHandler == null) {
+                        performDefaultAction(event);
+                    } else {
+                        performUsing(localHandler, event);
+                    }
+                }
+            });
+        }
+
+        synchronized void setHandler(final H handler) {
+            this._handler = handler;
+
+            // if a new handler is installed, block addition of legacy ApplicationListeners
+            if (handler == legacyHandler) return;
+            legacyHandler.blockLegacyAPI();
+        }
+
+        void performDefaultAction(final _NativeEvent event) { } // by default, do nothing
+        abstract void performUsing(final H handler, final _NativeEvent event);
+    }
+
+    abstract class _QueuingAppEventDispatcher<H> extends _AppEventDispatcher<H> {
+        List<_NativeEvent> queuedEvents = new LinkedList<_NativeEvent>();
+
+        @Override
+        void dispatch(final _NativeEvent event) {
+            synchronized (this) {
+                // dispatcher hasn't started yet
+                if (queuedEvents != null) {
+                    queuedEvents.add(event);
+                    return;
+                }
+            }
+
+            super.dispatch(event);
+        }
+
+        synchronized void setHandler(final H handler) {
+            this._handler = handler;
+
+            // dispatch any events in the queue
+            if (queuedEvents != null) {
+                // grab a local ref to the queue, so the real one can be nulled out
+                final java.util.List<_NativeEvent> localQueuedEvents = queuedEvents;
+                queuedEvents = null;
+                if (localQueuedEvents.size() != 0) {
+                    for (final _NativeEvent arg : localQueuedEvents) {
+                        dispatch(arg);
+                    }
+                }
+            }
+
+            // if a new handler is installed, block addition of legacy ApplicationListeners
+            if (handler == legacyHandler) return;
+            legacyHandler.blockLegacyAPI();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/_AppEventLegacyHandler.java b/jdk/src/macosx/classes/com/apple/eawt/_AppEventLegacyHandler.java
new file mode 100644
index 0000000..c870f79
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/_AppEventLegacyHandler.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.Toolkit;
+import java.io.File;
+import java.util.*;
+
+import com.apple.eawt.AppEvent.*;
+
+interface _OpenAppHandler {
+    void handleOpenApp();
+}
+
+@SuppressWarnings("deprecation")
+class _AppEventLegacyHandler implements AboutHandler, PreferencesHandler, _OpenAppHandler, AppReOpenedListener, OpenFilesHandler, PrintFilesHandler, QuitHandler {
+    final _AppEventHandler parent;
+    final Vector<ApplicationListener> legacyAppListeners = new Vector<ApplicationListener>();
+    boolean blockLegacyAPI;
+    boolean initializedParentDispatchers;
+
+    _AppEventLegacyHandler(final _AppEventHandler parent) {
+        this.parent = parent;
+    }
+
+    void blockLegacyAPI() {
+        blockLegacyAPI = true;
+    }
+
+    void checkIfLegacyAPIBlocked() {
+        if (!blockLegacyAPI) return;
+        throw new IllegalStateException("Cannot add com.apple.eawt.ApplicationListener after installing an app event handler");
+    }
+
+    void addLegacyAppListener(final ApplicationListener listener) {
+        checkIfLegacyAPIBlocked();
+
+        if (!initializedParentDispatchers) {
+            final _AppMenuBarHandler menuBarHandler = Application.getApplication().menuBarHandler;
+            final boolean prefsMenuAlreadyExplicitlySet = menuBarHandler.prefsMenuItemExplicitlySet;
+
+            parent.aboutDispatcher.setHandler(this);
+            parent.preferencesDispatcher.setHandler(this);
+            if (!prefsMenuAlreadyExplicitlySet) {
+                menuBarHandler.setPreferencesMenuItemVisible(false); // default behavior is not to have a preferences item
+            }
+            parent.openAppDispatcher.setHandler(this);
+            parent.reOpenAppDispatcher.addListener(this);
+            parent.openFilesDispatcher.setHandler(this);
+            parent.printFilesDispatcher.setHandler(this);
+            parent.quitDispatcher.setHandler(this);
+
+            initializedParentDispatchers = true;
+        }
+
+        synchronized (legacyAppListeners) {
+            legacyAppListeners.addElement(listener);
+        }
+    }
+
+    public void removeLegacyAppListener(final ApplicationListener listener) {
+        checkIfLegacyAPIBlocked();
+
+        synchronized (legacyAppListeners) {
+            legacyAppListeners.removeElement(listener);
+        }
+    }
+
+    @Override
+    public void handleAbout(final AboutEvent e) {
+        final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit());
+        sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
+            public void dispatchEvent(final ApplicationListener listener) {
+                listener.handleAbout(ae);
+            }
+        });
+
+        if (ae.isHandled()) return;
+        parent.openCocoaAboutWindow();
+    }
+
+    @Override
+    public void handlePreferences(final PreferencesEvent e) {
+        final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit());
+        sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
+            public void dispatchEvent(final ApplicationListener listener) {
+                listener.handlePreferences(ae);
+            }
+        });
+    }
+
+    @Override
+    public void handleOpenApp() {
+        final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit());
+        sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
+            public void dispatchEvent(final ApplicationListener listener) {
+                listener.handleOpenApplication(ae);
+            }
+        });
+    }
+
+    @Override
+    public void appReOpened(final AppReOpenedEvent e) {
+        final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit());
+        sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
+            public void dispatchEvent(final ApplicationListener listener) {
+                listener.handleReOpenApplication(ae);
+            }
+        });
+    }
+
+    @Override
+    public void openFiles(final OpenFilesEvent e) {
+        final List<File> files = e.getFiles();
+        for (final File file : files) { // legacy ApplicationListeners only understood one file at a time
+            final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit(), file.getAbsolutePath());
+            sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
+                public void dispatchEvent(final ApplicationListener listener) {
+                    listener.handleOpenFile(ae);
+                }
+            });
+        }
+    }
+
+    @Override
+    public void printFiles(PrintFilesEvent e) {
+        final List<File> files = e.getFiles();
+        for (final File file : files) { // legacy ApplicationListeners only understood one file at a time
+            final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit(), file.getAbsolutePath());
+            sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
+                public void dispatchEvent(final ApplicationListener listener) {
+                    listener.handlePrintFile(ae);
+                }
+            });
+        }
+    }
+
+    @Override
+    public void handleQuitRequestWith(final QuitEvent e, final QuitResponse response) {
+        final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit());
+        sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
+            public void dispatchEvent(final ApplicationListener listener) {
+                listener.handleQuit(ae);
+            }
+        });
+
+        if (ae.isHandled()) {
+            parent.performQuit();
+        } else {
+            parent.cancelQuit();
+        }
+    }
+
+    interface EventDispatcher {
+        void dispatchEvent(final ApplicationListener listener);
+    }
+
+    // helper that cycles through the loop and aborts if the event is handled, or there are no listeners
+    void sendEventToEachListenerUntilHandled(final ApplicationEvent event, final EventDispatcher dispatcher) {
+        synchronized (legacyAppListeners) {
+            if (legacyAppListeners.size() == 0) return;
+
+            final Enumeration<ApplicationListener> e = legacyAppListeners.elements();
+            while (e.hasMoreElements() && !event.isHandled()) {
+                dispatcher.dispatchEvent(e.nextElement());
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/_AppMenuBarHandler.java b/jdk/src/macosx/classes/com/apple/eawt/_AppMenuBarHandler.java
new file mode 100644
index 0000000..f432bd8
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/_AppMenuBarHandler.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+import java.awt.Frame;
+import java.awt.peer.MenuComponentPeer;
+
+import javax.swing.*;
+import javax.swing.plaf.MenuBarUI;
+
+import sun.lwawt.macosx.CMenuBar;
+
+import com.apple.laf.AquaMenuBarUI;
+
+class _AppMenuBarHandler {
+    private static final int MENU_ABOUT = 1;
+    private static final int MENU_PREFS = 2;
+
+    private static native void nativeSetMenuState(final int menu, final boolean visible, final boolean enabled);
+    private static native void nativeSetDefaultMenuBar(final long menuBarPeer);
+
+    static final _AppMenuBarHandler instance = new _AppMenuBarHandler();
+    static _AppMenuBarHandler getInstance() {
+        return instance;
+    }
+
+    // callback from the native delegate -init function
+    private static void initMenuStates(final boolean aboutMenuItemVisible, final boolean aboutMenuItemEnabled, final boolean prefsMenuItemVisible, final boolean prefsMenuItemEnabled) {
+        synchronized (instance) {
+            instance.aboutMenuItemVisible = aboutMenuItemVisible;
+            instance.aboutMenuItemEnabled = aboutMenuItemEnabled;
+            instance.prefsMenuItemVisible = prefsMenuItemVisible;
+            instance.prefsMenuItemEnabled = prefsMenuItemEnabled;
+        }
+    }
+
+    _AppMenuBarHandler() { }
+
+    boolean aboutMenuItemVisible;
+    boolean aboutMenuItemEnabled;
+
+    boolean prefsMenuItemVisible;
+    boolean prefsMenuItemEnabled;
+    boolean prefsMenuItemExplicitlySet;
+
+    void setDefaultMenuBar(final JMenuBar menuBar) {
+        installDefaultMenuBar(menuBar);
+
+        // scan the current frames, and see if any are foreground
+        final Frame[] frames = Frame.getFrames();
+        for (final Frame frame : frames) {
+            if (frame.isVisible() && !isFrameMinimized(frame)) return;
+        }
+
+        // if we have no foreground frames, then we have to "kick" the menubar
+        final JFrame pingFrame = new JFrame();
+        pingFrame.getRootPane().putClientProperty("Window.alpha", new Float(0.0f));
+        pingFrame.setVisible(true);
+        pingFrame.toFront();
+        pingFrame.setVisible(false);
+        pingFrame.dispose();
+    }
+
+    static boolean isFrameMinimized(final Frame frame) {
+        return (frame.getExtendedState() & Frame.ICONIFIED) != 0;
+    }
+
+    @SuppressWarnings("deprecation")
+    static void installDefaultMenuBar(final JMenuBar menuBar) {
+        if (menuBar == null) {
+            // intentionally clearing the default menu
+            nativeSetDefaultMenuBar(0);
+            return;
+        }
+
+        final MenuBarUI ui = menuBar.getUI();
+        if (!(ui instanceof AquaMenuBarUI)) {
+            // Aqua was not installed
+            throw new IllegalStateException("Application.setDefaultMenuBar() only works with the Aqua Look and Feel");
+        }
+/* TODO: disabled until ScreenMenuBar is working
+
+        final AquaMenuBarUI aquaUI = (AquaMenuBarUI)ui;
+        final ScreenMenuBar screenMenuBar = aquaUI.getScreenMenuBar();
+        if (screenMenuBar == null) {
+            // Aqua is installed, but we aren't using the screen menu bar
+            throw new IllegalStateException("Application.setDefaultMenuBar() only works if apple.laf.useScreenMenuBar=true");
+        }
+
+        screenMenuBar.addNotify();
+        final MenuComponentPeer peer = screenMenuBar.getPeer();
+        if (!(peer instanceof CMenuBar)) {
+            // such a thing should not be possible
+            throw new IllegalStateException("Unable to determine native menu bar from provided JMenuBar");
+        }
+
+        // grab the pointer to the CMenuBar, and retain it in native
+        nativeSetDefaultMenuBar(((CMenuBar)peer).getNativeMenuBarPeer());
+*/
+    }
+
+    void setAboutMenuItemVisible(final boolean present) {
+        synchronized (this) {
+            if (aboutMenuItemVisible == present) return;
+            aboutMenuItemVisible = present;
+        }
+
+        nativeSetMenuState(MENU_ABOUT, aboutMenuItemVisible, aboutMenuItemEnabled);
+    }
+
+    void setPreferencesMenuItemVisible(final boolean present) {
+        synchronized (this) {
+            prefsMenuItemExplicitlySet = true;
+            if (prefsMenuItemVisible == present) return;
+            prefsMenuItemVisible = present;
+        }
+        nativeSetMenuState(MENU_PREFS, prefsMenuItemVisible, prefsMenuItemEnabled);
+    }
+
+    void setAboutMenuItemEnabled(final boolean enable) {
+        synchronized (this) {
+            if (aboutMenuItemEnabled == enable) return;
+            aboutMenuItemEnabled = enable;
+        }
+        nativeSetMenuState(MENU_ABOUT, aboutMenuItemVisible, aboutMenuItemEnabled);
+    }
+
+    void setPreferencesMenuItemEnabled(final boolean enable) {
+        synchronized (this) {
+            prefsMenuItemExplicitlySet = true;
+            if (prefsMenuItemEnabled == enable) return;
+            prefsMenuItemEnabled = enable;
+        }
+        nativeSetMenuState(MENU_PREFS, prefsMenuItemVisible, prefsMenuItemEnabled);
+    }
+
+    boolean isAboutMenuItemVisible() {
+        return aboutMenuItemVisible;
+    }
+
+    boolean isPreferencesMenuItemVisible() {
+        return prefsMenuItemVisible;
+    }
+
+    boolean isAboutMenuItemEnabled() {
+        return aboutMenuItemEnabled;
+    }
+
+    boolean isPreferencesMenuItemEnabled() {
+        return prefsMenuItemEnabled;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/_AppMiscHandlers.java b/jdk/src/macosx/classes/com/apple/eawt/_AppMiscHandlers.java
new file mode 100644
index 0000000..0e1755e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/_AppMiscHandlers.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt;
+
+class _AppMiscHandlers {
+    private static native void nativeOpenHelpViewer();
+
+    private static native void nativeRequestActivation(final boolean allWindows);
+    private static native void nativeRequestUserAttention(final boolean critical);
+
+    private static native void nativeEnableSuddenTermination();
+    private static native void nativeDisableSuddenTermination();
+
+    static void openHelpViewer() {
+        nativeOpenHelpViewer();
+    }
+
+    static void requestActivation(final boolean allWindows) {
+        nativeRequestActivation(allWindows);
+    }
+
+    static void requestUserAttention(final boolean critical) {
+        nativeRequestUserAttention(critical);
+    }
+
+    static void enableSuddenTermination() {
+        nativeEnableSuddenTermination();
+    }
+
+    static void disableSuddenTermination() {
+        nativeDisableSuddenTermination();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/GestureAdapter.java b/jdk/src/macosx/classes/com/apple/eawt/event/GestureAdapter.java
new file mode 100644
index 0000000..5cb50dd
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/GestureAdapter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Abstract adapter class for receiving gesture events. This class is provided
+ * as a convenience for creating listeners.
+ *
+ * Subclasses registered with {@link GestureUtilities#addGestureListenerTo()}
+ * will receive all phase, magnification, rotation, and swipe events.
+ *
+ * @see GestureUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public abstract class GestureAdapter implements GesturePhaseListener, MagnificationListener, RotationListener, SwipeListener {
+    public void gestureBegan(final GesturePhaseEvent e) { }
+    public void gestureEnded(final GesturePhaseEvent e) { }
+    public void magnify(final MagnificationEvent e) { }
+    public void rotate(final RotationEvent e) { }
+    public void swipedDown(final SwipeEvent e) { }
+    public void swipedLeft(final SwipeEvent e) { }
+    public void swipedRight(final SwipeEvent e) { }
+    public void swipedUp(final SwipeEvent e) { }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/GestureEvent.java b/jdk/src/macosx/classes/com/apple/eawt/event/GestureEvent.java
new file mode 100644
index 0000000..f13306b
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/GestureEvent.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+import java.awt.*;
+
+/**
+ * Abstract event all gestures inherit from.
+ *
+ * Note: GestureEvent is not subclass of {@link AWTEvent} and is not dispatched
+ * directly from the {@link EventQueue}. This is an intentional design decision
+ * to prevent collision with an official java.awt.* gesture event types subclassing
+ * {@link InputEvent}.
+ *
+ * {@link GestureListener}s are only notified from the AWT Event Dispatch thread.
+ *
+ * @see GestureUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public abstract class GestureEvent {
+    boolean consumed;
+
+    GestureEvent() {
+        // package private
+    }
+
+    /**
+     * Consuming an event prevents listeners later in the chain or higher in the
+     * component hierarchy from receiving the event.
+     */
+    public void consume() {
+        consumed = true;
+    }
+
+    /**
+     * @return if the event has been consumed
+     */
+    protected boolean isConsumed() {
+        return consumed;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/GestureHandler.java b/jdk/src/macosx/classes/com/apple/eawt/event/GestureHandler.java
new file mode 100644
index 0000000..eb636f4
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/GestureHandler.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+import java.awt.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.*;
+
+final class GestureHandler {
+    private static final String CLIENT_PROPERTY = "com.apple.eawt.event.internalGestureHandler";
+
+    // native constants for the supported types of high-level gestures
+    static final int PHASE = 1;
+    static final int ROTATE = 2;
+    static final int MAGNIFY = 3;
+    static final int SWIPE = 4;
+
+    // installs a private instance of GestureHandler, if necessary
+    static void addGestureListenerTo(final JComponent component, final GestureListener listener) {
+        final Object value = component.getClientProperty(CLIENT_PROPERTY);
+        if (value instanceof GestureHandler) {
+            ((GestureHandler)value).addListener(listener);
+            return;
+        }
+
+        if (value != null) return; // some other garbage is in our client property
+
+        final GestureHandler newHandler = new GestureHandler();
+        newHandler.addListener(listener);
+        component.putClientProperty(CLIENT_PROPERTY, newHandler);
+    }
+
+    // asks the installed GestureHandler to remove it's listener (does not uninstall the GestureHandler)
+    static void removeGestureListenerFrom(final JComponent component, final GestureListener listener) {
+        final Object value = component.getClientProperty(CLIENT_PROPERTY);
+        if (!(value instanceof GestureHandler)) return;
+        ((GestureHandler)value).removeListener(listener);
+    }
+
+
+    // called from native - finds the deepest component with an installed GestureHandler,
+    // creates a single event, and dispatches it to a recursive notifier
+    static void handleGestureFromNative(final Window window, final int type, final double x, final double y, final double a, final double b) {
+        if (window == null) return; // should never happen...
+
+        EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                final Component component = SwingUtilities.getDeepestComponentAt(window, (int)x, (int)y);
+
+                final PerComponentNotifier firstNotifier;
+                if (component instanceof RootPaneContainer) {
+                    firstNotifier = getNextNotifierForComponent(((RootPaneContainer)component).getRootPane());
+                } else {
+                    firstNotifier = getNextNotifierForComponent(component);
+                }
+                if (firstNotifier == null) return;
+
+                switch (type) {
+                    case PHASE:
+                        firstNotifier.recursivelyHandlePhaseChange(a, new GesturePhaseEvent());
+                        return;
+                    case ROTATE:
+                        firstNotifier.recursivelyHandleRotate(new RotationEvent(a));
+                        return;
+                    case MAGNIFY:
+                        firstNotifier.recursivelyHandleMagnify(new MagnificationEvent(a));
+                        return;
+                    case SWIPE:
+                        firstNotifier.recursivelyHandleSwipe(a, b, new SwipeEvent());
+                        return;
+                }
+            }
+        });
+    }
+
+
+    final List<GesturePhaseListener> phasers = new LinkedList<GesturePhaseListener>();
+    final List<RotationListener> rotaters = new LinkedList<RotationListener>();
+    final List<MagnificationListener> magnifiers = new LinkedList<MagnificationListener>();
+    final List<SwipeListener> swipers = new LinkedList<SwipeListener>();
+
+    GestureHandler() { }
+
+    void addListener(final GestureListener listener) {
+        if (listener instanceof GesturePhaseListener) phasers.add((GesturePhaseListener)listener);
+        if (listener instanceof RotationListener) rotaters.add((RotationListener)listener);
+        if (listener instanceof MagnificationListener) magnifiers.add((MagnificationListener)listener);
+        if (listener instanceof SwipeListener) swipers.add((SwipeListener)listener);
+    }
+
+    void removeListener(final GestureListener listener) {
+        phasers.remove(listener);
+        rotaters.remove(listener);
+        magnifiers.remove(listener);
+        swipers.remove(listener);
+    }
+
+    // notifies all listeners in a particular component/handler pair
+    // and recursively notifies up the component hierarchy
+    static class PerComponentNotifier {
+        final Component component;
+        final GestureHandler handler;
+
+        public PerComponentNotifier(final Component component, final GestureHandler handler) {
+            this.component = component;
+            this.handler = handler;
+        }
+
+        void recursivelyHandlePhaseChange(final double phase, final GesturePhaseEvent e) {
+            for (final GesturePhaseListener listener : handler.phasers) {
+                if (phase < 0) {
+                    listener.gestureBegan(e);
+                } else {
+                    listener.gestureEnded(e);
+                }
+                if (e.isConsumed()) return;
+            }
+
+            final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
+            if (next != null) next.recursivelyHandlePhaseChange(phase, e);
+        }
+
+        void recursivelyHandleRotate(final RotationEvent e) {
+            for (final RotationListener listener : handler.rotaters) {
+                listener.rotate(e);
+                if (e.isConsumed()) return;
+            }
+
+            final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
+            if (next != null) next.recursivelyHandleRotate(e);
+        }
+
+        void recursivelyHandleMagnify(final MagnificationEvent e) {
+            for (final MagnificationListener listener : handler.magnifiers) {
+                listener.magnify(e);
+                if (e.isConsumed()) return;
+            }
+
+            final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
+            if (next != null) next.recursivelyHandleMagnify(e);
+        }
+
+        void recursivelyHandleSwipe(final double x, final double y, final SwipeEvent e) {
+            for (final SwipeListener listener : handler.swipers) {
+                if (x < 0) listener.swipedLeft(e);
+                if (x > 0) listener.swipedRight(e);
+                if (y < 0) listener.swipedDown(e);
+                if (y > 0) listener.swipedUp(e);
+                if (e.isConsumed()) return;
+            }
+
+            final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
+            if (next != null) next.recursivelyHandleSwipe(x, y, e);
+        }
+    }
+
+    // helper function to get a handler from a Component
+    static GestureHandler getHandlerForComponent(final Component c) {
+        if (!(c instanceof JComponent)) return null;
+        final Object value = ((JComponent)c).getClientProperty(CLIENT_PROPERTY);
+        if (!(value instanceof GestureHandler)) return null;
+        return (GestureHandler)value;
+    }
+
+    // recursive helper to find the next component/handler pair
+    static PerComponentNotifier getNextNotifierForComponent(final Component c) {
+        if (c == null) return null;
+
+        final GestureHandler handler = getHandlerForComponent(c);
+        if (handler != null) {
+            return new PerComponentNotifier(c, handler);
+        }
+
+        return getNextNotifierForComponent(c.getParent());
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/GestureListener.java b/jdk/src/macosx/classes/com/apple/eawt/event/GestureListener.java
new file mode 100644
index 0000000..b831cd7
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/GestureListener.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+import java.util.EventListener;
+
+/**
+ * Marker interface for all gesture sub-types.
+ *
+ * @see GesturePhaseListener
+ * @see MagnificationListener
+ * @see RotationListener
+ * @see SwipeListener
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public interface GestureListener extends EventListener {
+
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/GesturePhaseEvent.java b/jdk/src/macosx/classes/com/apple/eawt/event/GesturePhaseEvent.java
new file mode 100644
index 0000000..06cc8a1
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/GesturePhaseEvent.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Event indicating the user has started or stopped a continuous gesture.
+ *
+ * @see GesturePhaseListener
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public class GesturePhaseEvent extends GestureEvent {
+    GesturePhaseEvent() {
+        // package private
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/GesturePhaseListener.java b/jdk/src/macosx/classes/com/apple/eawt/event/GesturePhaseListener.java
new file mode 100644
index 0000000..f10c4f7
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/GesturePhaseListener.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Listener interface for receiving notification that a continuous gesture
+ * (like rotate or scale) has started or stopped.
+ *
+ * @see MagnificationListener
+ * @see RotationListener
+ * @see GesturePhaseEvent
+ * @see GestureUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public interface GesturePhaseListener extends GestureListener {
+    /**
+     * Invoked when the user has started a continuous gesture.
+     * @param event representing the start of a continuous gesture.
+     */
+    public void gestureBegan(final GesturePhaseEvent e);
+
+    /**
+     * Invoked when the user has stopped a continuous gesture.
+     * @param event representing the end of a continuous gesture.
+     */
+    public void gestureEnded(final GesturePhaseEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/GestureUtilities.java b/jdk/src/macosx/classes/com/apple/eawt/event/GestureUtilities.java
new file mode 100644
index 0000000..704cb28
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/GestureUtilities.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+import javax.swing.*;
+
+/**
+ * Registration utility class to add {@link GestureListener}s to Swing components.
+ *
+ * This class manages the relationship between {@link JComponent}s and the {@link GestureListener}s
+ * attached to them. It's design is similar to the Java SE 6u10 {@link com.sun.awt.AWTUtilities}
+ * class which adds additional functionality to AWT Windows, without adding new API to the
+ * {@link java.awt.Window} class.
+ *
+ * To add a {@link GestureListener} to a top-level Swing window, use the {@link JRootPane} of the
+ * top-level window type.
+ *
+ * @see GestureAdapter
+ * @see JFrame#getRootPane()
+ * @see com.sun.awt.AWTUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public final class GestureUtilities {
+    GestureUtilities() {
+        // package private
+    }
+
+    /**
+     * Attaches a {@link GestureListener} to the specified {@link JComponent}.
+     * @param component to attach the {@link GestureListener} to
+     * @param listener to be notified when a gesture occurs
+     */
+    public static void addGestureListenerTo(final JComponent component, final GestureListener listener) {
+        if (component == null || listener == null) throw new NullPointerException();
+        GestureHandler.addGestureListenerTo(component, listener);
+    }
+
+    /**
+     * Removes a {@link GestureListener} from the specified {@link JComponent}
+     * @param component to remove the {@link GestureListener} from
+     * @param listener to be removed
+     */
+    public static void removeGestureListenerFrom(final JComponent component, final GestureListener listener) {
+        if (component == null || listener == null) throw new NullPointerException();
+        GestureHandler.removeGestureListenerFrom(component, listener);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/MagnificationEvent.java b/jdk/src/macosx/classes/com/apple/eawt/event/MagnificationEvent.java
new file mode 100644
index 0000000..eb7d135
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/MagnificationEvent.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Event encapsulating a relative magnification scale performed by the user.
+ *
+ * @see MagnificationListener
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public class MagnificationEvent extends GestureEvent {
+    final double magnification;
+
+    MagnificationEvent(final double magnification) {
+        // package private
+        this.magnification = magnification;
+    }
+
+    /**
+     * @return an abstract measure of magnification scale (both positive and negative)
+     */
+    public double getMagnification() {
+        return magnification;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/MagnificationListener.java b/jdk/src/macosx/classes/com/apple/eawt/event/MagnificationListener.java
new file mode 100644
index 0000000..fcacffe
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/MagnificationListener.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Listener interface for receiving magnification events.
+ *
+ * @see MagnificationEvent
+ * @see GesturePhaseListener
+ * @see GestureUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public interface MagnificationListener extends GestureListener {
+    /**
+     * Invoked when a magnification gesture is performed by the user.
+     * @param event containing the scale of the magnification.
+     */
+    public void magnify(final MagnificationEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/RotationEvent.java b/jdk/src/macosx/classes/com/apple/eawt/event/RotationEvent.java
new file mode 100644
index 0000000..ff4b064
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/RotationEvent.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Event encapsulating a relative rotation performed by the user.
+ *
+ * @see RotationListener
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public class RotationEvent extends GestureEvent {
+    final double rotation;
+
+    RotationEvent(final double rotation) {
+        // package private
+        this.rotation = rotation;
+    }
+
+    /**
+     * @return an abstract measure of rotation (clockwise is negative)
+     */
+    public double getRotation() {
+        return rotation;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/RotationListener.java b/jdk/src/macosx/classes/com/apple/eawt/event/RotationListener.java
new file mode 100644
index 0000000..8d89beb
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/RotationListener.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Listener interface for receiving rotation events.
+ *
+ * @see RotationEvent
+ * @see GesturePhaseListener
+ * @see GestureUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public interface RotationListener extends GestureListener {
+    /**
+     * Invoked when a rotation gesture is performed by the user.
+     * @param event containing an abstract measure of rotation.
+     */
+    public void rotate(final RotationEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/SwipeEvent.java b/jdk/src/macosx/classes/com/apple/eawt/event/SwipeEvent.java
new file mode 100644
index 0000000..2b09e34
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/SwipeEvent.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Event indicating a swipe was performed by the user.
+ *
+ * @see SwipeListener
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public class SwipeEvent extends GestureEvent {
+    SwipeEvent() {
+        // package private
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/SwipeListener.java b/jdk/src/macosx/classes/com/apple/eawt/event/SwipeListener.java
new file mode 100644
index 0000000..f198bc9
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/SwipeListener.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Listener interface for receiving swipe events. A single swipe event
+ * may be both vertical and horizontal simultaneously, invoking both
+ * a vertical and horizontal method.
+ *
+ * @see SwipeEvent
+ * @see GestureUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public interface SwipeListener extends GestureListener {
+    /**
+     * Invoked when an upwards swipe gesture is performed by the user.
+     * @param event representing the occurrence of a swipe.
+     */
+    public void swipedUp(final SwipeEvent e);
+
+    /**
+     * Invoked when a downward swipe gesture is performed by the user.
+     * @param event representing the occurrence of a swipe.
+     */
+    public void swipedDown(final SwipeEvent e);
+
+    /**
+     * Invoked when a leftward swipe gesture is performed by the user.
+     * @param event representing the occurrence of a swipe.
+     */
+    public void swipedLeft(final SwipeEvent e);
+
+    /**
+     * Invoked when a rightward swipe gesture is performed by the user.
+     * @param event representing the occurrence of a swipe.
+     */
+    public void swipedRight(final SwipeEvent e);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eawt/event/package.html b/jdk/src/macosx/classes/com/apple/eawt/event/package.html
new file mode 100644
index 0000000..9c05d88
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/event/package.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+</head>
+<body bgcolor="white">
+Classes for receiving gesture events.
+
+Provides a mechanism to receive various gesture events on JComponents. Gesture notifications are relayed up the component hierarchy from the deepest component under the cursor to the top-level container. Events may be consumed by deeper components to prevent them from propagating to higher components.
+
+Gesture listeners are added to components using the GestureUtilities helper class.
+</body>
+</html>
diff --git a/jdk/src/macosx/classes/com/apple/eawt/package.html b/jdk/src/macosx/classes/com/apple/eawt/package.html
new file mode 100644
index 0000000..e11ed40
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eawt/package.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+</head>
+<body bgcolor="white">
+Provides classes for integrating Java applications with the native application environment.
+
+These classes provide a simple way to implement native features to fine tune Java applications on Mac OS X. These listeners and handlers can help make Java applications behaviors and user interface indistinguishable from native applications. For further information on the Mac OS X user interface, consult the <a target=_blank href="http://developer.apple.com/mac/library/documentation/UserExperience/Conceptual/AppleHIGuidelines"> Aqua Human Interface Guidelines</a>.</body>
+</html>
diff --git a/jdk/src/macosx/classes/com/apple/eio/FileManager.java b/jdk/src/macosx/classes/com/apple/eio/FileManager.java
new file mode 100644
index 0000000..12eb47a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eio/FileManager.java
@@ -0,0 +1,393 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eio;
+
+import java.io.*;
+
+/**
+ * Provides functionality to query and modify Mac-specific file attributes. The methods in this class are based on Finder
+ * attributes. These attributes in turn are dependent on HFS and HFS+ file systems. As such, it is important to recognize
+ * their limitation when writing code that must function well across multiple platforms.<p>
+ *
+ * In addition to file name suffixes, Mac OS X can use Finder attributes like file <code>type</code> and <code>creator</code> codes to
+ * identify and handle files. These codes are unique 4-byte identifiers. The file <code>type</code> is a string that describes the
+ * contents of a file. For example, the file type <code>APPL</code> identifies the file as an application and therefore
+ * executable. A file type of <code>TEXT</code>  means that the file contains raw text. Any application that can read raw
+ * text can open a file of type <code>TEXT</code>. Applications that use proprietary file types might assign their files a proprietary
+ * file <code>type</code> code.
+ * <p>
+ * To identify the application that can handle a document, the Finder can look at the <code>creator</code>. For example, if a user
+ * double-clicks on a document with the <code>ttxt</code> <code>creator</code>, it opens up in Text Edit, the application registered
+ * with the <code>ttxt</code> <code>creator</code> code. Note that the <code>creator</code>
+ * code can be set to any application, not necessarily the application that created it. For example, if you
+ * use an editor to create an HTML document, you might want to assign a browser's <code>creator</code> code for the file rather than
+ * the HTML editor's <code>creator</code> code. Double-clicking on the document then opens the appropriate browser rather than the
+ *HTML editor.
+ *<p>
+ * If you plan to publicly distribute your application, you must register its creator and any proprietary file types with the Apple
+ * Developer Connection to avoid collisions with codes used by other developers. You can register a codes online at the
+ * <a target=_blank href=http://developer.apple.com/dev/cftype/>Creator Code Registration</a> site.
+ *
+ * @since 1.4
+ */
+public class FileManager {
+    static {
+        java.security.AccessController.doPrivileged((java.security.PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osx"));
+    }
+
+    /**
+     * The default
+     * @since Java for Mac OS X 10.5 - 1.5
+         * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public final static short kOnAppropriateDisk = -32767;
+    /**
+     * Read-only system hierarchy.
+     * @since Java for Mac OS X 10.5 - 1.5
+         * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public final static short kSystemDomain = -32766;
+    /**
+     * All users of a single machine have access to these resources.
+     * @since Java for Mac OS X 10.5 - 1.5
+         * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public final static short kLocalDomain = -32765;
+    /**
+     * All users configured to use a common network server has access to these resources.
+     * @since Java for Mac OS X 10.5 - 1.5
+         * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public final static short kNetworkDomain = -32764;
+    /**
+     * Read/write. Resources that are private to the user.
+     * @since Java for Mac OS X 10.5 - 1.5
+         * @since Java for Mac OS X 10.5 Update 1 - 1.6
+     */
+    public final static short kUserDomain = -32763;
+
+
+        /**
+         * Converts an OSType (e.g. "macs" from <CarbonCore/Folders.h>) into an int.
+         *
+         * @param type the 4 character type to convert.
+         * @return an int representing the 4 character value
+         *
+         * @since Java for Mac OS X 10.5 - 1.5
+         * @since Java for Mac OS X 10.5 Update 1 - 1.6
+         */
+    @SuppressWarnings("deprecation")
+        public static int OSTypeToInt(String type) {
+        int result = 0;
+
+                byte b[] = { (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
+                int len = type.length();
+                if (len > 0) {
+                        if (len > 4) len = 4;
+                        type.getBytes(0, len, b, 4 - len);
+                }
+
+                for (int i = 0;  i < len;  i++)  {
+                        if (i > 0) result <<= 8;
+                        result |= (b[i] & 0xff);
+                }
+
+        return result;
+    }
+
+    /**
+         * Sets the file <code>type</code> and <code>creator</code> codes for a file or folder.
+         *
+         * @since 1.4
+         */
+    public static void setFileTypeAndCreator(String filename, int type, int creator) throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkWrite(filename);
+        }
+        _setFileTypeAndCreator(filename, type, creator);
+    }
+        private static native void _setFileTypeAndCreator(String filename, int type, int creator) throws IOException;
+
+    /**
+         * Sets the file <code>type</code> code for a file or folder.
+         *
+         * @since 1.4
+         */
+    public static void setFileType(String filename, int type) throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkWrite(filename);
+        }
+        _setFileType(filename, type);
+        }
+    private static native void _setFileType(String filename, int type) throws IOException;
+
+    /**
+         * Sets the file <code>creator</code> code for a file or folder.
+         *
+         * @since 1.4
+         */
+    public static void setFileCreator(String filename, int creator) throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkWrite(filename);
+        }
+        _setFileCreator(filename, creator);
+    }
+    private static native void _setFileCreator(String filename, int creator) throws IOException;
+
+    /**
+         * Obtains the file <code>type</code> code for a file or folder.
+         *
+         * @since 1.4
+         */
+    public static int getFileType(String filename) throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkRead(filename);
+        }
+        return _getFileType(filename);
+    }
+    private static native int _getFileType(String filename) throws IOException;
+
+    /**
+         * Obtains the file <code>creator</code> code for a file or folder.
+         *
+         * @since 1.4
+         */
+    public static int getFileCreator(String filename) throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkRead(filename);
+        }
+        return _getFileCreator(filename);
+    }
+    private static native int _getFileCreator(String filename) throws IOException;
+
+
+    /**
+         * Locates a folder of a particular type. Mac OS X recognizes certain specific folders that have distinct purposes.
+         * For example, the user's desktop or temporary folder. These folders have corresponding codes. Given one of these codes,
+         * this method returns the path to that particular folder. Certain folders of a given type may appear in more than
+         * one domain. For example, although there is only one <code>root</code> folder, there are multiple <code>pref</code>
+         * folders. If this method is called to find the <code>pref</code> folder, it will return the first one it finds,
+         * the user's preferences folder in <code>~/Library/Preferences</code>. To explicitly locate a folder in a certain
+         * domain use <code>findFolder(short domain, int folderType)</code> or <code>findFolder(short domain, int folderType,
+         * boolean createIfNeeded)</code>.
+         *
+         * @return the path to the folder searched for
+         *
+         * @since 1.4
+         */
+        public static String findFolder(int folderType) throws FileNotFoundException {
+                return findFolder(kOnAppropriateDisk, folderType);
+        }
+
+    /**
+         * Locates a folder of a particular type, within a given domain. Similar to <code>findFolder(int folderType)</code>
+         * except that the domain to look in can be specified. Valid values for <code>domain</code>include:
+         * <dl>
+         * <dt>user</dt>
+         * <dd>The User domain contains resources specific to the user who is currently logged in</dd>
+         * <dt>local</dt>
+         * <dd>The Local domain contains resources shared by all users of the system but are not needed for the system
+         * itself to run.</dd>
+         * <dt>network</dt>
+         * <dd>The Network domain contains resources shared by users of a local area network.</dd>
+         * <dt>system</dt>
+         * <dd>The System domain contains the operating system resources installed by Apple.</dd>
+         * </dl>
+         *
+         * @return the path to the folder searched for
+         *
+         * @since 1.4
+         */
+        public static String findFolder(short domain, int folderType) throws FileNotFoundException {
+                return findFolder(domain, folderType, false);
+        }
+
+    /**
+         * Locates a folder of a particular type within a given domain and optionally creating the folder if it does
+         * not exist. The behavior is similar to <code>findFolder(int folderType)</code> and
+         * <code>findFolder(short domain, int folderType)</code> except that it can create the folder if it does not already exist.
+         *
+         * @param createIfNeeded
+         *            set to <code>true</code>, by setting to <code>false</code> the behavior will be the
+         *            same as <code>findFolder(short domain, int folderType, boolean createIfNeeded)</code>
+         * @return the path to the folder searched for
+         *
+         * @since 1.4
+         */
+    public static String findFolder(short domain, int folderType, boolean createIfNeeded) throws FileNotFoundException {
+        final SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkPermission(new RuntimePermission("canExamineFileSystem"));
+        }
+
+        final String foundFolder = _findFolder(domain, folderType, createIfNeeded);
+        if (foundFolder == null) throw new FileNotFoundException("Can't find folder: " + Integer.toHexString(folderType));
+        return foundFolder;
+    }
+    private static native String _findFolder(short domain, int folderType, boolean createIfNeeded);
+
+
+    /**
+         * Opens the path specified by a URL in the appropriate application for that URL. HTTP URL's (<code>http://</code>)
+         * open in the default browser as set in the Internet pane of System Preferences. File (<code>file://</code>) and
+         * FTP URL's (<code>ftp://</code>) open in the Finder. Note that opening an FTP URL will prompt the user for where
+         * they want to save the downloaded file(s).
+         *
+         * @param url
+         *            the URL for the file you want to open, it can either be an HTTP, FTP, or file url
+         *
+         * @deprecated this functionality has been superseded by java.awt.Desktop.browse() and java.awt.Desktop.open()
+         *
+         * @since 1.4
+         */
+    @Deprecated
+    public static void openURL(String url) throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkPermission(new RuntimePermission("canOpenURLs"));
+        }
+        _openURL(url);
+    }
+    private static native void _openURL(String url) throws IOException;
+
+    /**
+         * @return full pathname for the resource identified by a given name.
+         *
+         * @since 1.4
+         */
+        public static String getResource(String resourceName) throws FileNotFoundException {
+                return getResourceFromBundle(resourceName, null, null);
+        }
+
+        /**
+         * @return full pathname for the resource identified by a given name and located in the specified bundle subdirectory.
+         *
+         * @since 1.4
+         */
+        public static String getResource(String resourceName, String subDirName) throws FileNotFoundException {
+                return getResourceFromBundle(resourceName, subDirName, null);
+        }
+
+        /**
+         * Returns the full pathname for the resource identified by the given name and file extension
+         * and located in the specified bundle subdirectory.
+         *
+         * If extension is an empty string or null, the returned pathname is the first one encountered where the
+         * file name exactly matches name.
+         *
+         * If subpath is null, this method searches the top-level nonlocalized resource directory (typically Resources)
+         * and the top-level of any language-specific directories. For example, suppose you have a modern bundle and
+         * specify "Documentation" for the subpath parameter. This method would first look in the
+         * Contents/Resources/Documentation directory of the bundle, followed by the Documentation subdirectories of
+         * each language-specific .lproj directory. (The search order for the language-specific directories
+         * corresponds to the user's preferences.) This method does not recurse through any other subdirectories at
+         * any of these locations. For more details see the AppKit NSBundle documentation.
+         *
+         * @return full pathname for the resource identified by the given name and file extension and located in the specified bundle subdirectory.
+         *
+         * @since 1.4
+         */
+        public static String getResource(String resourceName, String subDirName, String type) throws FileNotFoundException {
+                return getResourceFromBundle(resourceName, subDirName, type);
+        }
+
+        private static native String getNativeResourceFromBundle(String resourceName, String subDirName, String type) throws FileNotFoundException;
+        private static String getResourceFromBundle(String resourceName, String subDirName, String type) throws FileNotFoundException {
+                final SecurityManager security = System.getSecurityManager();
+                if (security != null) security.checkPermission(new RuntimePermission("canReadBundle"));
+
+                final String resourceFromBundle = getNativeResourceFromBundle(resourceName, subDirName, type);
+                if (resourceFromBundle == null) throw new FileNotFoundException(resourceName);
+                return resourceFromBundle;
+        }
+
+        /**
+         * Obtains the path to the current application's NSBundle, may not
+         * return a valid path if Java was launched from the command line.
+         *
+         * @return full pathname of the NSBundle of the current application executable.
+         *
+         * @since Java for Mac OS X 10.5 Update 1 - 1.6
+         * @since Java for Mac OS X 10.5 Update 2 - 1.5
+         */
+        public static String getPathToApplicationBundle() {
+                SecurityManager security = System.getSecurityManager();
+                if (security != null) security.checkPermission(new RuntimePermission("canReadBundle"));
+                return getNativePathToApplicationBundle();
+        }
+
+        private static native String getNativePathToApplicationBundle();
+
+        /**
+         * Moves the specified file to the Trash
+         *
+         * @param file
+         * @return returns true if the NSFileManager successfully moved the file to the Trash.
+         * @throws FileNotFoundException
+         *
+         * @since Java for Mac OS X 10.6 Update 1 - 1.6
+         * @since Java for Mac OS X 10.5 Update 6 - 1.6, 1.5
+         */
+        public static boolean moveToTrash(final File file) throws FileNotFoundException {
+                if (file == null || !file.exists()) throw new FileNotFoundException();
+                final String fileName = file.getAbsolutePath();
+
+                final SecurityManager security = System.getSecurityManager();
+                if (security != null) security.checkWrite(fileName);
+
+                return _moveToTrash(fileName);
+        }
+
+        private static native boolean _moveToTrash(String fileName);
+
+        /**
+         * Reveals the specified file in the Finder
+         *
+         * @param file
+         *            the file to reveal
+         * @return returns true if the NSFileManager successfully revealed the file in the Finder.
+         * @throws FileNotFoundException
+         *
+         * @since Java for Mac OS X 10.6 Update 1 - 1.6
+         * @since Java for Mac OS X 10.5 Update 6 - 1.6, 1.5
+         */
+        public static boolean revealInFinder(final File file) throws FileNotFoundException {
+                if (file == null || !file.exists()) throw new FileNotFoundException();
+                final String fileName = file.getAbsolutePath();
+
+                final SecurityManager security = System.getSecurityManager();
+                if (security != null) security.checkRead(fileName);
+
+                return _revealInFinder(fileName);
+        }
+
+        private static native boolean _revealInFinder(String fileName);
+}
diff --git a/jdk/src/macosx/classes/com/apple/eio/package.html b/jdk/src/macosx/classes/com/apple/eio/package.html
new file mode 100644
index 0000000..922b5b4
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/eio/package.html
@@ -0,0 +1,7 @@
+<html>
+<head>
+</head>
+<body bgcolor="white">
+Provides classes to allow you to take advantage of functionality of the underlying Mac OS X operating system.
+The classes in this package provide access to features of Mac OS X that may or may not be present on other platforms. It should be noted that depending on any of these features ties Java applications to Mac OS X. For more thorough explanation of some of the topics discussed here, please refer to <a target=_blank href="http://developer.apple.com/techpubs/macosx/Essentials/SystemOverview/index.html">Inside Mac OS X: System Overview</a>.</body>
+</html>
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaBorder.java
new file mode 100644
index 0000000..640cafe
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaBorder.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.UIResource;
+import javax.swing.text.JTextComponent;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+
+public abstract class AquaBorder implements Border, UIResource {
+    protected final AquaPainter<? extends JRSUIState> painter;
+    protected final SizeDescriptor sizeDescriptor;
+    protected SizeVariant sizeVariant;
+
+    protected AquaBorder(final SizeDescriptor sizeDescriptor) {
+        this.sizeDescriptor = sizeDescriptor;
+        this.sizeVariant = sizeDescriptor.get(Size.REGULAR);
+        this.painter = createPainter();
+    }
+
+    protected AquaPainter<? extends JRSUIState> createPainter() {
+        final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIState.getInstance());
+        painter.state.set(AlignmentVertical.CENTER);
+        painter.state.set(AlignmentHorizontal.CENTER);
+        return painter;
+    }
+
+    protected AquaBorder(final AquaBorder other) {
+        this.sizeDescriptor = other.sizeDescriptor;
+        this.sizeVariant = other.sizeVariant;
+        this.painter = AquaPainter.create(other.painter.state.derive());
+        painter.state.set(AlignmentVertical.CENTER);
+        painter.state.set(AlignmentHorizontal.CENTER);
+    }
+
+    protected void setSize(final Size size) {
+        sizeVariant = sizeDescriptor.get(size);
+        painter.state.set(size);
+    }
+
+    public Insets getBorderInsets(final Component c) {
+        return sizeVariant.margins;
+    }
+
+    protected AquaBorder deriveBorderForSize(final Size size) {
+        try {
+            final Class<? extends AquaBorder> clazz = getClass();
+            final AquaBorder border = clazz.getConstructor(new Class[] { clazz }).newInstance(new Object[] { this });
+            border.setSize(size);
+            return border;
+        } catch (final Throwable e) {
+            return null;
+        }
+    }
+
+    public static void repaintBorder(final JComponent c) {
+        JComponent borderedComponent = c;
+        Border border = c.getBorder();
+        if (border == null) {
+            // See if it's inside a JScrollpane or something
+            final Container p = c.getParent();
+            if (p instanceof JViewport) {
+                borderedComponent = (JComponent)p.getParent();
+                if (borderedComponent != null) border = borderedComponent.getBorder();
+            }
+        }
+
+        // If we really don't have a border, then bail
+        // It might be a compound border with a ThemeBorder inside
+        // The check for that case is tricky, so we just go ahead and repaint any border
+        if (border == null || borderedComponent == null) return;
+
+        final int width = borderedComponent.getWidth();
+        final int height = borderedComponent.getHeight();
+        final Insets i = borderedComponent.getInsets();
+
+        borderedComponent.repaint(0, 0, width, i.top); // Top edge
+        borderedComponent.repaint(0, 0, i.left, height); // Left edge
+        borderedComponent.repaint(0, height - i.bottom, width, i.bottom); // Bottom edge
+        borderedComponent.repaint(width - i.right, 0, i.right, height); // Right edge
+    }
+
+    // The JScrollPane doesn't let us know if its viewport view has focus
+    protected boolean isFocused(final Component c) {
+        // Being really paranoid in case this Component isn't a Swing component
+        Component focusable = c;
+
+        if (c instanceof JScrollPane) {
+            final JViewport vp = ((JScrollPane)c).getViewport();
+            if (vp != null) {
+                focusable = vp.getView();
+                // Lists, Tables & Trees get focus rings, TextAreas don't (JBuilder puts TextField border on TextAreas)
+                if (focusable instanceof JTextComponent) return false;
+            }
+        } else if (focusable instanceof JTextComponent) {
+            // non-editable text areas don't draw the focus ring
+            if (!((javax.swing.text.JTextComponent)focusable).isEditable()) return false;
+        }
+
+        return (focusable != null && focusable instanceof JComponent && ((JComponent)focusable).hasFocus());
+    }
+
+    public boolean isBorderOpaque() { return false; }
+
+    public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
+        painter.paint(g, c, x, y, w, h);
+    }
+
+    static class Default extends AquaBorder {
+        Default() { super(new SizeDescriptor(new SizeVariant())); }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaButtonBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaButtonBorder.java
new file mode 100644
index 0000000..b45b0ce
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonBorder.java
@@ -0,0 +1,313 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.*;
+
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.*;
+
+public abstract class AquaButtonBorder extends AquaBorder implements Border, UIResource {
+    public static final RecyclableSingleton<Dynamic> fDynamic = new RecyclableSingletonFromDefaultConstructor<Dynamic>(Dynamic.class);
+    static public AquaButtonBorder getDynamicButtonBorder() {
+        return fDynamic.get();
+    }
+
+    private static final RecyclableSingleton<Toggle> fToggle = new RecyclableSingletonFromDefaultConstructor<Toggle>(Toggle.class);
+    static public AquaButtonBorder getToggleButtonBorder() {
+        return fToggle.get();
+    }
+
+    public static final RecyclableSingleton<Toolbar> fToolBar = new RecyclableSingletonFromDefaultConstructor<Toolbar>(Toolbar.class);
+    static public Border getToolBarButtonBorder() {
+        return fToolBar.get();
+    }
+
+    public static final RecyclableSingleton<Named> fBevel = new RecyclableSingleton<Named>() {
+        protected Named getInstance() {
+            return new Named(Widget.BUTTON_BEVEL, new SizeDescriptor(new SizeVariant().alterMargins(2, 4, 2, 4)));
+        }
+    };
+    public static AquaButtonBorder getBevelButtonBorder() {
+        return fBevel.get();
+    }
+
+    public AquaButtonBorder(final SizeDescriptor sizeDescriptor) {
+        super(sizeDescriptor);
+    }
+
+    public AquaButtonBorder(final AquaButtonBorder other) {
+        super(other);
+    }
+
+    public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+        // for now we don't paint a border. We let the button paint it since there
+        // needs to be a strict ordering for aqua components.
+        //paintButton(c, g, x, y, width, height);
+    }
+
+    public void paintButton(final Component c, final Graphics g, int x, int y, int width, int height) {
+        final AbstractButton b = (AbstractButton)c;
+        final ButtonModel model = b.getModel();
+
+        final State state = getButtonState(b, model);
+        painter.state.set(state);
+        painter.state.set((state != State.DISABLED && state != State.INACTIVE) && b.isFocusPainted() && isFocused(b) ? Focused.YES : Focused.NO);
+
+        final Insets subInsets = sizeVariant.insets;
+        x += subInsets.left;
+        y += subInsets.top;
+        width -= (subInsets.left + subInsets.right);
+        height -= (subInsets.top + subInsets.bottom);
+
+//        g.setColor(Color.magenta);
+//        g.drawRect(x, y, width - 1, height - 1);
+
+        doButtonPaint(b, model, g, x, y, width, height);
+    }
+
+    protected void doButtonPaint(final AbstractButton b, final ButtonModel model, final Graphics g, final int x, final int y, final int width, final int height) {
+        painter.paint(g, b, x, y, width, height);
+    }
+
+    protected State getButtonState(final AbstractButton b, final ButtonModel model) {
+        if (!b.isEnabled()) return State.DISABLED;
+
+        // The default button shouldn't draw its color when the window is inactive.
+        // Changed for <rdar://problem/3614421>: Aqua LAF Buttons are incorrectly drawn disabled
+        // all we need to do is make sure we aren't the default button any more and that
+        // we aren't active, but we still are enabled if the button is enabled.
+        // if we set dimmed we would appear disabled despite being enabled and click through
+        // works so this now matches the text drawing and most importantly the HIG
+        if (!AquaFocusHandler.isActive(b)) return State.INACTIVE;
+
+        if (model.isArmed() && model.isPressed()) return State.PRESSED;
+        if (model.isSelected() && isSelectionPressing()) return State.PRESSED;
+        if ((b instanceof JButton) && ((JButton)b).isDefaultButton()) return State.PULSED;
+
+        return State.ACTIVE;
+    }
+
+    protected boolean isSelectionPressing() {
+        return true;
+    }
+
+    public boolean hasSmallerInsets(final JComponent c) {
+        final Insets inset = c.getInsets();
+        final Insets margin = sizeVariant.margins;
+
+        if (margin.equals(inset)) return false;
+
+        return (
+            (inset.top < margin.top) ||
+            (inset.left < margin.left) ||
+            (inset.right < margin.right) ||
+            (inset.bottom < margin.bottom)
+        );
+    }
+
+    /**
+     * Returns the insets of the border.
+     * @param c the component for which this border insets value applies
+     */
+    public Insets getBorderInsets(final Component c) {
+        if (c == null || !(c instanceof AbstractButton)) return new Insets(0, 0, 0, 0);
+
+        Insets margin = ((AbstractButton)c).getMargin();
+        margin = (margin == null) ? new InsetsUIResource(0, 0, 0, 0) : (Insets)margin.clone();
+
+        margin.top += sizeVariant.margins.top;
+        margin.bottom += sizeVariant.margins.bottom;
+        margin.left += sizeVariant.margins.left;
+        margin.right += sizeVariant.margins.right;
+
+        return margin;
+    }
+
+    public Insets getContentInsets(final AbstractButton b, final int w, final int h) {
+        return null;
+    }
+
+    public void alterPreferredSize(final Dimension d) {
+        if (sizeVariant.h > 0 && sizeVariant.h > d.height) d.height = sizeVariant.h;
+        if (sizeVariant.w > 0 && sizeVariant.w > d.width) d.width = sizeVariant.w;
+    }
+
+    /**
+     * Returns whether or not the border is opaque.  If the border
+     * is opaque, it is responsible for filling in it's own
+     * background when painting.
+     */
+    public boolean isBorderOpaque() {
+        return false;
+    }
+
+    static class SizeConstants {
+        protected static final int fNormalButtonHeight = 29;
+        protected static final int fNormalMinButtonWidth = 40;
+        protected static final int fSquareButtonHeightThreshold = 23;
+        protected static final int fSquareButtonWidthThreshold = 16;
+    }
+
+    public static class Dynamic extends AquaButtonBorder {
+        final Insets ALTERNATE_PUSH_INSETS = new Insets(3, 12, 5, 12);
+        final Insets ALTERNATE_BEVEL_INSETS = new Insets(0, 5, 0, 5);
+        final Insets ALTERNATE_SQUARE_INSETS = new Insets(0, 2, 0, 2);
+        public Dynamic() {
+            super(new SizeDescriptor(new SizeVariant(75, 29).alterMargins(3, 20, 5, 20)) {
+                public SizeVariant deriveSmall(final SizeVariant v) {
+                    return super.deriveSmall(v.alterMinSize(0, -2).alterMargins(0, -3, 0, -3).alterInsets(-3, -3, -4, -3));
+                }
+                public SizeVariant deriveMini(final SizeVariant v) {
+                    return super.deriveMini(v.alterMinSize(0, -2).alterMargins(0, -3, 0, -3).alterInsets(-3, -3, -1, -3));
+                }
+            });
+        }
+
+        public Dynamic(final Dynamic other) {
+            super(other);
+        }
+
+        protected State getButtonState(final AbstractButton b, final ButtonModel model) {
+            final State state = super.getButtonState(b, model);
+            painter.state.set(state == State.PULSED ? Animating.YES : Animating.NO);
+            return state;
+        }
+
+        public Insets getContentInsets(final AbstractButton b, final int width, final int height) {
+            final Size size = AquaUtilControlSize.getUserSizeFrom(b);
+            final Widget style = getStyleForSize(b, size, width, height);
+
+            if (style == Widget.BUTTON_PUSH) {
+                return ALTERNATE_PUSH_INSETS;
+            }
+            if (style == Widget.BUTTON_BEVEL_ROUND) {
+                return ALTERNATE_BEVEL_INSETS;
+            }
+            if (style == Widget.BUTTON_BEVEL) {
+                return ALTERNATE_SQUARE_INSETS;
+            }
+
+            return null;
+        }
+
+        protected void doButtonPaint(final AbstractButton b, final ButtonModel model, final Graphics g, int x, int y, int width, int height) {
+            final Size size = AquaUtilControlSize.getUserSizeFrom(b);
+            painter.state.set(size);
+
+            final Widget style = getStyleForSize(b, size, width, height);
+            painter.state.set(style);
+
+            // custom adjusting
+            if (style == Widget.BUTTON_PUSH && y % 2 == 0) {
+                if (size == Size.REGULAR) { y += 1; height -= 1; }
+                if (size == Size.MINI) { height -= 1; x += 4; width -= 8; }
+            }
+
+            super.doButtonPaint(b, model, g, x, y, width, height);
+        }
+
+        protected Widget getStyleForSize(final AbstractButton b, final Size size, final int width, final int height) {
+            if (size != null && size != Size.REGULAR) {
+                return Widget.BUTTON_PUSH;
+            }
+
+            if (height < SizeConstants.fSquareButtonHeightThreshold || width < SizeConstants.fSquareButtonWidthThreshold) {
+                return Widget.BUTTON_BEVEL;
+            }
+
+            if (height <= SizeConstants.fNormalButtonHeight + 3 && width < SizeConstants.fNormalMinButtonWidth) {
+                return Widget.BUTTON_BEVEL;
+            }
+
+            if ((height > SizeConstants.fNormalButtonHeight + 3) || (b.getIcon() != null) || hasSmallerInsets(b)){
+                return Widget.BUTTON_BEVEL_ROUND;
+            }
+
+            return Widget.BUTTON_PUSH;
+        }
+    }
+
+    public static class Toggle extends AquaButtonBorder {
+        public Toggle() {
+            super(new SizeDescriptor(new SizeVariant().alterMargins(6, 6, 6, 6)));
+        }
+
+        public Toggle(final Toggle other) {
+            super(other);
+        }
+
+        protected void doButtonPaint(final AbstractButton b, final ButtonModel model, final Graphics g, final int x, final int y, final int width, final int height) {
+            if (height < SizeConstants.fSquareButtonHeightThreshold || width < SizeConstants.fSquareButtonWidthThreshold) {
+                painter.state.set(Widget.BUTTON_BEVEL);
+                super.doButtonPaint(b, model, g, x, y, width, height);
+                return;
+            }
+
+            painter.state.set(Widget.BUTTON_BEVEL_ROUND);
+            super.doButtonPaint(b, model, g, x, y + 1, width, height - 1);
+        }
+    }
+
+    public static class Named extends AquaButtonBorder {
+        public Named(final Widget widget, final SizeDescriptor sizeDescriptor) {
+            super(sizeDescriptor);
+            painter.state.set(widget);
+        }
+
+        // called by reflection
+        public Named(final Named sizeDescriptor) {
+            super(sizeDescriptor);
+        }
+
+        protected void doButtonPaint(final AbstractButton b, final ButtonModel model, final Graphics g, final int x, final int y, final int width, final int height) {
+            painter.state.set(model.isSelected() ? BooleanValue.YES : BooleanValue.NO);
+            super.doButtonPaint(b, model, g, x, y, width, height);
+        }
+    }
+
+    public static class Toolbar extends AquaButtonBorder {
+        public Toolbar() {
+            super(new SizeDescriptor(new SizeVariant().alterMargins(5, 5, 5, 5)));
+            painter.state.set(Widget.TOOLBAR_ITEM_WELL);
+        }
+
+        public Toolbar(final Toolbar other) {
+            super(other);
+        }
+
+        protected void doButtonPaint(final AbstractButton b, final ButtonModel model, final Graphics g, final int x, final int y, final int w, final int h) {
+            if (!model.isSelected()) return; // only paint when the toolbar button is selected
+            super.doButtonPaint(b, model, g, x, y, w, h);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaButtonCheckBoxUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaButtonCheckBoxUI.java
new file mode 100644
index 0000000..a022eca
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonCheckBoxUI.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.*;
+
+public class AquaButtonCheckBoxUI extends AquaButtonLabeledUI {
+    protected static final RecyclableSingleton<AquaButtonCheckBoxUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaButtonCheckBoxUI>(AquaButtonCheckBoxUI.class);
+    protected static final RecyclableSingleton<ImageIcon> sizingIcon = new RecyclableSingleton<ImageIcon>() {
+        protected ImageIcon getInstance() {
+            return new ImageIcon(AquaNativeResources.getRadioButtonSizerImage());
+        }
+    };
+
+    public static ComponentUI createUI(final JComponent b) {
+        return instance.get();
+    }
+
+    public static Icon getSizingCheckBoxIcon() {
+        return sizingIcon.get();
+    }
+
+    public String getPropertyPrefix() {
+        return "CheckBox" + ".";
+    }
+
+    protected AquaButtonBorder getPainter() {
+        return new CheckBoxButtonBorder();
+    }
+
+    public static class CheckBoxButtonBorder extends LabeledButtonBorder {
+        public CheckBoxButtonBorder() {
+            super(new SizeDescriptor(new SizeVariant().replaceMargins("CheckBox.margin")));
+            painter.state.set(Widget.BUTTON_CHECK_BOX);
+        }
+
+        public CheckBoxButtonBorder(final CheckBoxButtonBorder sizeDescriptor) {
+            super(sizeDescriptor);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java b/jdk/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java
new file mode 100644
index 0000000..14350ad
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.Insets;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+/**
+ * All the "magic numbers" in this class should go away once
+ * <rdar://problem/4613866> "default font" and sizes for controls in Java Aqua Look and Feel
+ * has been addressed, and we can cull widget metrics from the native system.
+ */
+public class AquaButtonExtendedTypes {
+    protected static Border getBorderForPosition(final AbstractButton c, final Object type, final Object logicalPosition) {
+        final String name = (logicalPosition == null ? (String)type : type + "-" + getRealPositionForLogicalPosition((String)logicalPosition, c.getComponentOrientation().isLeftToRight()));
+        final TypeSpecifier specifier = getSpecifierByName(name);
+        if (specifier == null) return null;
+
+        final Border border = specifier.getBorder();
+        if (!(border instanceof AquaBorder)) return border;
+
+        return ((AquaBorder)border).deriveBorderForSize(AquaUtilControlSize.getUserSizeFrom(c));
+    }
+
+    protected static String getRealPositionForLogicalPosition(String logicalPosition, boolean leftToRight) {
+        if (!leftToRight) {
+            if ("first".equalsIgnoreCase(logicalPosition)) return "last";
+            if ("last".equalsIgnoreCase(logicalPosition)) return "first";
+        }
+        return logicalPosition;
+    }
+
+    static abstract class TypeSpecifier {
+        final String name;
+        final boolean setIconFont;
+
+        TypeSpecifier(final String name, final boolean setIconFont) {
+            this.name = name; this.setIconFont = setIconFont;
+        }
+
+        abstract Border getBorder();
+    }
+
+    static class BorderDefinedTypeSpecifier extends TypeSpecifier {
+        final AquaBorder border;
+
+        BorderDefinedTypeSpecifier(final String name, final Widget widget, final SizeVariant variant) {
+            this(name, widget, variant, 0, 0, 0, 0);
+        }
+
+        BorderDefinedTypeSpecifier(final String name, final Widget widget, final SizeVariant variant, final int smallW, final int smallH, final int miniW, final int miniH) {
+            super(name, false);
+            border = initBorder(widget, new SizeDescriptor(variant) {
+                public SizeVariant deriveSmall(final SizeVariant v) {
+                    v.alterMinSize(smallW, smallH);
+                    return super.deriveSmall(v);
+                }
+                public SizeVariant deriveMini(final SizeVariant v) {
+                    v.alterMinSize(miniW, miniH);
+                    return super.deriveMini(v);
+                }
+            });
+            patchUp(border.sizeDescriptor);
+        }
+
+        Border getBorder() { return border; }
+        void patchUp(final SizeDescriptor descriptor) {}
+
+        AquaBorder initBorder(final Widget widget, final SizeDescriptor desc) {
+            return new AquaButtonBorder.Named(widget, desc);
+        }
+    }
+
+    static class SegmentedBorderDefinedTypeSpecifier extends BorderDefinedTypeSpecifier {
+        public SegmentedBorderDefinedTypeSpecifier(final String name, final Widget widget, final SegmentPosition position, final SizeVariant variant) {
+            this(name, widget, position, variant, 0, 0, 0, 0);
+        }
+
+        public SegmentedBorderDefinedTypeSpecifier(final String name, final Widget widget, final SegmentPosition position, final SizeVariant variant, final int smallW, final int smallH, final int miniW, final int miniH) {
+            super(name, widget, variant, smallW, smallH, miniW, miniH);
+            border.painter.state.set(SegmentTrailingSeparator.YES);
+            border.painter.state.set(position);
+        }
+
+        AquaBorder initBorder(final Widget widget, final SizeDescriptor desc) {
+            return new SegmentedNamedBorder(widget, desc);
+        }
+    }
+
+    public static class SegmentedNamedBorder extends AquaButtonBorder.Named {
+        public SegmentedNamedBorder(final SegmentedNamedBorder sizeDescriptor) {
+            super(sizeDescriptor);
+        }
+
+        public SegmentedNamedBorder(final Widget widget, final SizeDescriptor sizeDescriptor) {
+            super(widget, sizeDescriptor);
+        }
+
+        protected boolean isSelectionPressing() {
+            return false;
+        }
+    }
+
+    protected static TypeSpecifier getSpecifierByName(final String name) {
+        return typeDefinitions.get().get(name);
+    }
+
+    protected final static RecyclableSingleton<Map<String, TypeSpecifier>> typeDefinitions = new RecyclableSingleton<Map<String, TypeSpecifier>>() {
+        protected Map<String, TypeSpecifier> getInstance() {
+            return getAllTypes();
+        }
+    };
+
+    protected static Map<String, TypeSpecifier> getAllTypes() {
+        final Map<String, TypeSpecifier> specifiersByName = new HashMap<String, TypeSpecifier>();
+
+        final Insets focusInsets = new Insets(4, 4, 4, 4);
+
+        final TypeSpecifier[] specifiers = {
+            new TypeSpecifier("toolbar", true) {
+                Border getBorder() { return AquaButtonBorder.getToolBarButtonBorder(); }
+            },
+            new TypeSpecifier("icon", true) {
+                Border getBorder() { return AquaButtonBorder.getToggleButtonBorder(); }
+            },
+            new TypeSpecifier("text", false) {
+                Border getBorder() { return UIManager.getBorder("Button.border"); }
+            },
+            new TypeSpecifier("toggle", false) {
+                Border getBorder() { return AquaButtonBorder.getToggleButtonBorder(); }
+            },
+            new BorderDefinedTypeSpecifier("combobox", Widget.BUTTON_POP_DOWN, new SizeVariant().alterMargins(7, 10, 6, 30).alterInsets(1, 2, 0, 2).alterMinSize(0, 29), 0, -3, 0, -6) {
+                void patchUp(final SizeDescriptor descriptor) { descriptor.small.alterMargins(0, 0, 0, -4); descriptor.mini.alterMargins(0, 0, 0, -6); }
+            },
+            new BorderDefinedTypeSpecifier("comboboxInternal", Widget.BUTTON_POP_DOWN, new SizeVariant().alterInsets(1, 2, 0, 2).alterMinSize(0, 29), 0, -3, 0, -6),
+            new BorderDefinedTypeSpecifier("comboboxEndCap", Widget.BUTTON_COMBO_BOX, new SizeVariant().alterMargins(5, 10, 6, 10).alterInsets(1, 2, 0, 2).alterMinSize(0, 29), 0, -3, 0, -6){
+                void patchUp(final SizeDescriptor descriptor) { border.painter.state.set(IndicatorOnly.YES); }
+            },
+
+            new BorderDefinedTypeSpecifier("square", Widget.BUTTON_BEVEL, new SizeVariant(16, 16).alterMargins(5, 7, 5, 7).replaceInsets(focusInsets)),
+            new BorderDefinedTypeSpecifier("gradient", Widget.BUTTON_BEVEL_INSET, new SizeVariant(18, 18).alterMargins(8, 9, 8, 9).replaceInsets(focusInsets)) {
+                void patchUp(SizeDescriptor descriptor) { descriptor.small.alterMargins(0, 0, 0, 0); }
+            },
+            new BorderDefinedTypeSpecifier("bevel", Widget.BUTTON_BEVEL_ROUND, new SizeVariant(22, 22).alterMargins(7, 8, 9, 8).alterInsets(0, 0, 0, 0)),
+
+            new BorderDefinedTypeSpecifier("textured", Widget.BUTTON_PUSH_TEXTURED, new SizeVariant(28, 28).alterMargins(5, 10, 6, 10).alterInsets(1, 2, 0, 2)),
+            new BorderDefinedTypeSpecifier("roundRect", Widget.BUTTON_PUSH_INSET, new SizeVariant(28, 28).alterMargins(4, 14, 4, 14).replaceInsets(focusInsets)),
+            new BorderDefinedTypeSpecifier("recessed", Widget.BUTTON_PUSH_SCOPE, new SizeVariant(28, 28).alterMargins(4, 14, 4, 14).replaceInsets(focusInsets)),
+
+            new BorderDefinedTypeSpecifier("well", Widget.FRAME_WELL, new SizeVariant(32, 32)),
+
+            new BorderDefinedTypeSpecifier("help", Widget.BUTTON_ROUND_HELP, new SizeVariant().alterInsets(2, 0, 0, 0).alterMinSize(28, 28), -3, -3, -3, -3),
+            new BorderDefinedTypeSpecifier("round", Widget.BUTTON_ROUND, new SizeVariant().alterInsets(2, 0, 0, 0).alterMinSize(28, 28), -3, -3, -3, -3),
+            new BorderDefinedTypeSpecifier("texturedRound", Widget.BUTTON_ROUND_INSET, new SizeVariant().alterInsets(0, 0, 0, 0).alterMinSize(26, 26), -2, -2, 0, 0),
+
+            new SegmentedBorderDefinedTypeSpecifier("segmented-first", Widget.BUTTON_SEGMENTED, SegmentPosition.FIRST, new SizeVariant().alterMargins(6, 16, 6, 10).alterInsets(5, 3, 5, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmented-middle", Widget.BUTTON_SEGMENTED, SegmentPosition.MIDDLE, new SizeVariant().alterMargins(6, 9, 6, 10).alterInsets(5, 0, 5, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmented-last", Widget.BUTTON_SEGMENTED, SegmentPosition.LAST, new SizeVariant().alterMargins(6, 9, 6, 16).alterInsets(5, 0, 5, 3).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmented-only", Widget.BUTTON_SEGMENTED, SegmentPosition.ONLY, new SizeVariant().alterMargins(6, 16, 6, 16).alterInsets(5, 3, 5, 3).alterMinSize(34, 28), 0, -3, 0, -3),
+
+            new SegmentedBorderDefinedTypeSpecifier("segmentedRoundRect-first", Widget.BUTTON_SEGMENTED_INSET, SegmentPosition.FIRST, new SizeVariant().alterMargins(6, 12, 6, 8).alterInsets(5, 2, 5, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedRoundRect-middle", Widget.BUTTON_SEGMENTED_INSET, SegmentPosition.MIDDLE, new SizeVariant().alterMargins(6, 8, 6, 8).alterInsets(5, 0, 5, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedRoundRect-last", Widget.BUTTON_SEGMENTED_INSET, SegmentPosition.LAST, new SizeVariant().alterMargins(6, 8, 6, 12).alterInsets(5, 0, 5, 2).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedRoundRect-only", Widget.BUTTON_SEGMENTED_INSET, SegmentPosition.ONLY, new SizeVariant().alterMargins(6, 12, 6, 12).alterInsets(5, 2, 5, 2).alterMinSize(0, 28), 0, -3, 0, -3),
+
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTexturedRounded-first", Widget.BUTTON_SEGMENTED_SCURVE, SegmentPosition.FIRST, new SizeVariant().alterMargins(6, 12, 6, 8).alterInsets(5, 2, 5, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTexturedRounded-middle", Widget.BUTTON_SEGMENTED_SCURVE, SegmentPosition.MIDDLE, new SizeVariant().alterMargins(6, 8, 6, 8).alterInsets(5, 0, 5, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTexturedRounded-last", Widget.BUTTON_SEGMENTED_SCURVE, SegmentPosition.LAST, new SizeVariant().alterMargins(6, 8, 6, 12).alterInsets(5, 0, 5, 2).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTexturedRounded-only", Widget.BUTTON_SEGMENTED_SCURVE, SegmentPosition.ONLY, new SizeVariant().alterMargins(6, 12, 6, 12).alterInsets(5, 2, 5, 2).alterMinSize(0, 28), 0, -3, 0, -3),
+
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTextured-first", Widget.BUTTON_SEGMENTED_TEXTURED, SegmentPosition.FIRST, new SizeVariant().alterMargins(6, 12, 6, 8).alterInsets(6, 3, 6, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTextured-middle", Widget.BUTTON_SEGMENTED_TEXTURED, SegmentPosition.MIDDLE, new SizeVariant().alterMargins(6, 8, 6, 8).alterInsets(6, 0, 6, 0).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTextured-last", Widget.BUTTON_SEGMENTED_TEXTURED, SegmentPosition.LAST, new SizeVariant().alterMargins(6, 8, 6, 12).alterInsets(6, 0, 6, 3).alterMinSize(0, 28), 0, -3, 0, -3),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedTextured-only", Widget.BUTTON_SEGMENTED_TEXTURED, SegmentPosition.ONLY, new SizeVariant().alterMargins(6, 12, 6, 12).alterInsets(6, 3, 6, 3).alterMinSize(0, 28), 0, -3, 0, -3),
+
+            new SegmentedBorderDefinedTypeSpecifier("segmentedCapsule-first", Widget.BUTTON_SEGMENTED_TOOLBAR, SegmentPosition.FIRST, new SizeVariant().alterMargins(6, 12, 6, 8).alterInsets(5, 2, 5, 0).alterMinSize(0, 28), 0, 0, 0, 0),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedCapsule-middle", Widget.BUTTON_SEGMENTED_TOOLBAR, SegmentPosition.MIDDLE, new SizeVariant().alterMargins(6, 8, 6, 8).alterInsets(5, 0, 5, 0).alterMinSize(0, 28), 0, 0, 0, 0),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedCapsule-last", Widget.BUTTON_SEGMENTED_TOOLBAR, SegmentPosition.LAST, new SizeVariant().alterMargins(6, 8, 6, 12).alterInsets(5, 0, 5, 2).alterMinSize(0, 28), 0, 0, 0, 0),
+            new SegmentedBorderDefinedTypeSpecifier("segmentedCapsule-only", Widget.BUTTON_SEGMENTED_TOOLBAR, SegmentPosition.ONLY, new SizeVariant().alterMargins(6, 12, 6, 12).alterInsets(5, 2, 5, 2).alterMinSize(34, 28), 0, 0, 0, 0),
+
+            new BorderDefinedTypeSpecifier("segmentedGradient-first", Widget.BUTTON_BEVEL_INSET, new SizeVariant(18, 18).alterMargins(4, 5, 4, 5).replaceInsets(new Insets(-2,-0,-2,-0))),
+            new BorderDefinedTypeSpecifier("segmentedGradient-middle", Widget.BUTTON_BEVEL_INSET, new SizeVariant(18, 18).alterMargins(4, 5, 4, 5).replaceInsets(new Insets(-2,-1,-2,-0))),
+            new BorderDefinedTypeSpecifier("segmentedGradient-last", Widget.BUTTON_BEVEL_INSET, new SizeVariant(18, 18).alterMargins(4, 5, 4, 5).replaceInsets(new Insets(-2,-1,-2,-0))),
+            new BorderDefinedTypeSpecifier("segmentedGradient-only", Widget.BUTTON_BEVEL_INSET, new SizeVariant(18, 18).alterMargins(4, 5, 4, 5).replaceInsets(new Insets(-2,-1,-2,-1))),
+
+            new BorderDefinedTypeSpecifier("disclosure", Widget.BUTTON_DISCLOSURE, new SizeVariant().alterMargins(10, 10, 10, 10).replaceInsets(focusInsets).alterMinSize(27, 27), -1, -1, -1, -1),
+
+            //new BorderDefinedTypeSpecifier("disclosureTriangle", false, Widget.DISCLOSURE_TRIANGLE, new SizeVariant()),
+            new BorderDefinedTypeSpecifier("scrollColumnSizer", Widget.SCROLL_COLUMN_SIZER, new SizeVariant(14, 14)),
+        };
+
+        for (final TypeSpecifier specifier : specifiers) {
+            specifiersByName.put(specifier.name, specifier);
+        }
+
+        return specifiersByName;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaButtonLabeledUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaButtonLabeledUI.java
new file mode 100644
index 0000000..95503c8
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonLabeledUI.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.basic.BasicHTML;
+import javax.swing.text.View;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+import apple.laf.JRSUIState.ValueState;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public abstract class AquaButtonLabeledUI extends AquaButtonToggleUI implements Sizeable {
+    protected static RecyclableSizingIcon regularIcon = new RecyclableSizingIcon(18);
+    protected static RecyclableSizingIcon smallIcon = new RecyclableSizingIcon(16);
+    protected static RecyclableSizingIcon miniIcon = new RecyclableSizingIcon(14);
+
+    protected static class RecyclableSizingIcon extends RecyclableSingleton<Icon> {
+        final int iconSize;
+        public RecyclableSizingIcon(final int iconSize) { this.iconSize = iconSize; }
+
+        protected Icon getInstance() {
+            return new ImageIcon(new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_ARGB_PRE));
+        }
+    }
+
+    protected AquaButtonBorder widgetBorder;
+
+    public AquaButtonLabeledUI() {
+        widgetBorder = getPainter();
+    }
+
+    public void applySizeFor(final JComponent c, final Size newSize) {
+        super.applySizeFor(c, newSize);
+        widgetBorder = (AquaButtonBorder)widgetBorder.deriveBorderForSize(newSize);
+    }
+
+    public Icon getDefaultIcon(final JComponent c) {
+        final Size componentSize = AquaUtilControlSize.getUserSizeFrom(c);
+        if (componentSize == Size.REGULAR) return regularIcon.get();
+        if (componentSize == Size.SMALL) return smallIcon.get();
+        if (componentSize == Size.MINI) return miniIcon.get();
+        return regularIcon.get();
+    }
+
+    protected void setThemeBorder(final AbstractButton b) {
+        super.setThemeBorder(b);
+
+        // Set the correct border
+        b.setBorder(AquaButtonBorder.getBevelButtonBorder());
+    }
+
+    protected abstract AquaButtonBorder getPainter();
+
+    public synchronized void paint(final Graphics g, final JComponent c) {
+        final AbstractButton b = (AbstractButton)c;
+        final ButtonModel model = b.getModel();
+
+        final Font f = c.getFont();
+        g.setFont(f);
+        final FontMetrics fm = g.getFontMetrics();
+
+        Dimension size = b.getSize();
+
+        final Insets i = c.getInsets();
+
+        Rectangle viewRect = new Rectangle(b.getWidth(), b.getHeight());
+        Rectangle iconRect = new Rectangle();
+        Rectangle textRect = new Rectangle();
+
+        Icon altIcon = b.getIcon();
+
+        final boolean isCellEditor = c.getParent() instanceof CellRendererPane;
+
+        // This was erroneously removed to fix [3155996] but really we wanted the controls to just be
+        // opaque. So we put this back in to fix [3179839] (radio buttons not being translucent)
+        if (b.isOpaque() || isCellEditor) {
+            g.setColor(b.getBackground());
+            g.fillRect(0, 0, size.width, size.height);
+        }
+
+        // only do this if borders are on!
+        if (((AbstractButton)c).isBorderPainted() && !isCellEditor) {
+            final Border border = c.getBorder();
+            if (border instanceof AquaButtonBorder) {
+                ((AquaButtonBorder)border).paintButton(c, g, viewRect.x, viewRect.y, viewRect.width, viewRect.height);
+            }
+        }
+
+        viewRect.x = i.left;
+        viewRect.y = i.top;
+        viewRect.width = b.getWidth() - (i.right + viewRect.x);
+        viewRect.height = b.getHeight() - (i.bottom + viewRect.y);
+
+        // normal size ??
+        // at some point we substitute the small icon instead of the normal icon
+        // we should base this on height. Use normal unless we are under a certain size
+        // see our button code!
+
+        final String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(b), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : b.getIconTextGap());
+
+        // fill background
+
+        // draw the native radio button stuff here.
+        if (altIcon == null) {
+            widgetBorder.paintButton(c, g, iconRect.x, iconRect.y, iconRect.width, iconRect.height);
+        } else {
+            // Paint the button
+            if (!model.isEnabled()) {
+                if (model.isSelected()) {
+                    altIcon = b.getDisabledSelectedIcon();
+                } else {
+                    altIcon = b.getDisabledIcon();
+                }
+            } else if (model.isPressed() && model.isArmed()) {
+                altIcon = b.getPressedIcon();
+                if (altIcon == null) {
+                    // Use selected icon
+                    altIcon = b.getSelectedIcon();
+                }
+            } else if (model.isSelected()) {
+                if (b.isRolloverEnabled() && model.isRollover()) {
+                    altIcon = b.getRolloverSelectedIcon();
+                    if (altIcon == null) {
+                        altIcon = b.getSelectedIcon();
+                    }
+                } else {
+                    altIcon = b.getSelectedIcon();
+                }
+            } else if (b.isRolloverEnabled() && model.isRollover()) {
+                altIcon = b.getRolloverIcon();
+            }
+
+            if (altIcon == null) {
+                altIcon = b.getIcon();
+            }
+
+            altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
+        }
+
+        // Draw the Text
+        if (text != null) {
+            final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
+            if (v != null) {
+                v.paint(g, textRect);
+            } else {
+                paintText(g, b, textRect, text);
+            }
+        }
+    }
+
+    /**
+     * The preferred size of the button
+     */
+    public Dimension getPreferredSize(final JComponent c) {
+        if (c.getComponentCount() > 0) { return null; }
+
+        final AbstractButton b = (AbstractButton)c;
+
+        final String text = b.getText();
+
+        Icon buttonIcon = b.getIcon();
+        if (buttonIcon == null) {
+            buttonIcon = getDefaultIcon(b);
+        }
+
+        final Font font = b.getFont();
+        final FontMetrics fm = b.getFontMetrics(font);
+
+        Rectangle prefViewRect = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);
+        Rectangle prefIconRect = new Rectangle();
+        Rectangle prefTextRect = new Rectangle();
+
+        SwingUtilities.layoutCompoundLabel(c, fm, text, buttonIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), prefViewRect, prefIconRect, prefTextRect, text == null ? 0 : b.getIconTextGap());
+
+        // find the union of the icon and text rects (from Rectangle.java)
+        final int x1 = Math.min(prefIconRect.x, prefTextRect.x);
+        final int x2 = Math.max(prefIconRect.x + prefIconRect.width, prefTextRect.x + prefTextRect.width);
+        final int y1 = Math.min(prefIconRect.y, prefTextRect.y);
+        final int y2 = Math.max(prefIconRect.y + prefIconRect.height, prefTextRect.y + prefTextRect.height);
+        int width = x2 - x1;
+        int height = y2 - y1;
+
+        Insets prefInsets = b.getInsets();
+        width += prefInsets.left + prefInsets.right;
+        height += prefInsets.top + prefInsets.bottom;
+        return new Dimension(width, height);
+    }
+
+    public static abstract class LabeledButtonBorder extends AquaButtonBorder {
+        public LabeledButtonBorder(final SizeDescriptor sizeDescriptor) {
+            super(sizeDescriptor);
+        }
+
+        public LabeledButtonBorder(final LabeledButtonBorder other) {
+            super(other);
+        }
+
+        @Override
+        protected AquaPainter<? extends JRSUIState> createPainter() {
+            final AquaPainter<ValueState> painter = AquaPainter.create(JRSUIStateFactory.getLabeledButton());
+            painter.state.set(AlignmentVertical.CENTER);
+            painter.state.set(AlignmentHorizontal.CENTER);
+            return painter;
+        }
+
+        protected void doButtonPaint(final AbstractButton b, final ButtonModel model, final Graphics g, final int x, final int y, final int width, final int height) {
+            painter.state.set(AquaUtilControlSize.getUserSizeFrom(b));
+            ((ValueState)painter.state).setValue(model.isSelected() ? isIndeterminate(b) ? 2 : 1 : 0); // 2=mixed, 1=on, 0=off
+            super.doButtonPaint(b, model, g, x, y, width, height);
+        }
+
+        protected State getButtonState(final AbstractButton b, final ButtonModel model) {
+            final State state = super.getButtonState(b, model);
+
+            if (state == State.INACTIVE) return State.INACTIVE;
+            if (state == State.DISABLED) return State.DISABLED;
+            if (model.isArmed() && model.isPressed()) return State.PRESSED;
+            if (model.isSelected()) return State.ACTIVE;
+
+            return state;
+        }
+
+        static boolean isIndeterminate(final AbstractButton b) {
+            return "indeterminate".equals(b.getClientProperty("JButton.selectedState"));
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaButtonRadioUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaButtonRadioUI.java
new file mode 100644
index 0000000..ebe6306
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonRadioUI.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.*;
+
+public class AquaButtonRadioUI extends AquaButtonLabeledUI {
+    protected static final RecyclableSingleton<AquaButtonRadioUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaButtonRadioUI>(AquaButtonRadioUI.class);
+    protected static final RecyclableSingleton<ImageIcon> sizingIcon = new RecyclableSingleton<ImageIcon>() {
+        protected ImageIcon getInstance() {
+            return new ImageIcon(AquaNativeResources.getRadioButtonSizerImage());
+        }
+    };
+
+    public static ComponentUI createUI(final JComponent b) {
+        return instance.get();
+    }
+
+    public static Icon getSizingRadioButtonIcon(){
+        return sizingIcon.get();
+    }
+
+    protected String getPropertyPrefix() {
+        return "RadioButton" + ".";
+    }
+
+    protected AquaButtonBorder getPainter() {
+        return new RadioButtonBorder();
+    }
+
+    public static class RadioButtonBorder extends LabeledButtonBorder {
+        public RadioButtonBorder() {
+            super(new SizeDescriptor(new SizeVariant().replaceMargins("RadioButton.margin")));
+            painter.state.set(Widget.BUTTON_RADIO);
+        }
+
+        public RadioButtonBorder(final RadioButtonBorder other) {
+            super(other);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaButtonToggleUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaButtonToggleUI.java
new file mode 100644
index 0000000..067aa2f
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonToggleUI.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import javax.swing.JComponent;
+import javax.swing.plaf.ComponentUI;
+
+import com.apple.laf.AquaUtils.*;
+
+public class AquaButtonToggleUI extends AquaButtonUI {
+    // Create PLAF
+    static final RecyclableSingleton<AquaButtonToggleUI> aquaToggleButtonUI = new RecyclableSingletonFromDefaultConstructor<AquaButtonToggleUI>(AquaButtonToggleUI.class);
+    public static ComponentUI createUI(final JComponent b) {
+        return aquaToggleButtonUI.get();
+    }
+
+    protected String getPropertyPrefix() {
+        return "ToggleButton" + ".";
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaButtonUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaButtonUI.java
new file mode 100644
index 0000000..7f002d6
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonUI.java
@@ -0,0 +1,597 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.PropertyChangeEvent;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.*;
+import javax.swing.text.View;
+
+import sun.swing.SwingUtilities2;
+
+import apple.laf.JRSUIConstants.Size;
+
+import com.apple.laf.AquaButtonExtendedTypes.TypeSpecifier;
+import com.apple.laf.AquaUtilControlSize.Sizeable;
+import com.apple.laf.AquaUtils.*;
+
+public class AquaButtonUI extends BasicButtonUI implements Sizeable {
+    private static final String BUTTON_TYPE = "JButton.buttonType";
+    private static final String SEGMENTED_BUTTON_POSITION = "JButton.segmentPosition";
+
+    protected static final RecyclableSingleton<AquaButtonUI> buttonUI = new RecyclableSingletonFromDefaultConstructor<AquaButtonUI>(AquaButtonUI.class);
+    public static ComponentUI createUI(final JComponent c) {
+        return buttonUI.get();
+    }
+
+    // Has the shared instance defaults been initialized?
+    private boolean defaults_initialized = false;
+    private Color defaultDisabledTextColor = null;
+
+    protected void installDefaults(final AbstractButton b) {
+        // load shared instance defaults
+        final String pp = getPropertyPrefix();
+
+        if (!defaults_initialized) {
+            defaultDisabledTextColor = UIManager.getColor(pp + "disabledText");
+            defaults_initialized = true;
+        }
+
+        setButtonMarginIfNeeded(b, UIManager.getInsets(pp + "margin"));
+
+        LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font");
+        LookAndFeel.installProperty(b, "opaque", UIManager.getBoolean(pp + "opaque"));
+
+        final Object borderProp = b.getClientProperty(BUTTON_TYPE);
+        boolean hasBorder = false;
+
+        if (borderProp != null) {
+            hasBorder = setButtonType(b, borderProp);
+        }
+        if (!hasBorder) setThemeBorder(b);
+
+        final Object segmentProp = b.getClientProperty(SEGMENTED_BUTTON_POSITION);
+        if (segmentProp != null) {
+            final Border border = b.getBorder();
+            if (!(border instanceof AquaBorder)) return;
+
+            b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, b.getClientProperty(BUTTON_TYPE), segmentProp));
+        }
+    }
+
+    public void applySizeFor(final JComponent c, final Size size) {
+        // this space intentionally left blank
+        // (subclasses need to do work here)
+     }
+
+    protected void setThemeBorder(final AbstractButton b) {
+        // Set the correct border
+        final ButtonUI genericUI = b.getUI();
+        if (!(genericUI instanceof AquaButtonUI)) return;
+        final AquaButtonUI ui = (AquaButtonUI)genericUI;
+
+        Border border = b.getBorder();
+        if (!ui.isBorderFromProperty(b) && (border == null || border instanceof UIResource || border instanceof AquaButtonBorder)) {
+            // See BasicGraphicsUtils.getPreferredButtonSize - it returns null for preferred size,
+            // causing it to use the subcomponent's size, which doesn't allow space for Aqua pushbuttons
+            boolean iconFont = true;
+            if (isOnToolbar(b)) {
+                if (b instanceof JToggleButton) {
+                    border = AquaButtonBorder.getToolBarButtonBorder();
+                } else {
+                    border = AquaButtonBorder.getBevelButtonBorder();
+                }
+            } else if (b.getIcon() != null || b.getComponentCount() > 0) {
+                // radar 3308129 && (b.getText() == null || b.getText().equals("")))
+                // we used to only do this for buttons that had images and no text
+                // now we do it for all buttons that have any images - they cannot
+                // be a default button.
+                border = AquaButtonBorder.getToggleButtonBorder();
+            } else {
+                border = UIManager.getBorder(getPropertyPrefix() + "border");
+                iconFont = false;
+            }
+
+            b.setBorder(border);
+
+            final Font currentFont = b.getFont();
+            if (iconFont && (currentFont == null || currentFont instanceof UIResource)) {
+                b.setFont(UIManager.getFont("IconButton.font"));
+            }
+        }
+    }
+
+    protected static boolean isOnToolbar(final AbstractButton b) {
+        Component parent = b.getParent();
+        while (parent != null) {
+            if (parent instanceof JToolBar) return true;
+            parent = parent.getParent();
+        }
+        return false;
+    }
+
+    // A state that affects border has changed.  Make sure we have the right one
+    protected static void updateBorder(final AbstractButton b) {
+        // See if the button has overridden the automatic button type
+        final Object prop = b.getClientProperty(BUTTON_TYPE);
+        if (prop != null) return;
+
+        final ButtonUI ui = b.getUI();
+        if (!(ui instanceof AquaButtonUI)) return;
+        if (b.getBorder() != null) ((AquaButtonUI)ui).setThemeBorder(b);
+    }
+
+    protected void setButtonMarginIfNeeded(final AbstractButton b, final Insets insets) {
+        final Insets margin = b.getMargin();
+        if (margin == null || (margin instanceof UIResource)) {
+            b.setMargin(insets);
+        }
+    }
+
+    public boolean isBorderFromProperty(final AbstractButton button) {
+        return button.getClientProperty(BUTTON_TYPE) != null;
+    }
+
+    protected boolean setButtonType(final AbstractButton b, final Object prop) {
+        if (!(prop instanceof String)) {
+            b.putClientProperty(BUTTON_TYPE, null); // so we know to use the automatic button type
+            return false;
+        }
+
+        final String buttonType = (String)prop;
+        boolean iconFont = true;
+
+        final TypeSpecifier specifier = AquaButtonExtendedTypes.getSpecifierByName(buttonType);
+        if (specifier != null) {
+            b.setBorder(specifier.getBorder());
+            iconFont = specifier.setIconFont;
+        }
+
+        final Font currentFont = b.getFont();
+        if (currentFont == null || currentFont instanceof UIResource) {
+            b.setFont(UIManager.getFont(iconFont ? "IconButton.font" : "Button.font"));
+        }
+
+        return true;
+    }
+
+    protected void installListeners(final AbstractButton b) {
+        final AquaButtonListener listener = createButtonListener(b);
+        if (listener != null) {
+            // put the listener in the button's client properties so that
+            // we can get at it later
+            b.putClientProperty(this, listener);
+
+            b.addMouseListener(listener);
+            b.addMouseMotionListener(listener);
+            b.addFocusListener(listener);
+            b.addPropertyChangeListener(listener);
+            b.addChangeListener(listener);
+            b.addAncestorListener(listener);
+        }
+        installHierListener(b);
+        AquaUtilControlSize.addSizePropertyListener(b);
+    }
+
+    protected void installKeyboardActions(final AbstractButton b) {
+        final BasicButtonListener listener = (BasicButtonListener)b.getClientProperty(this);
+        if (listener != null) listener.installKeyboardActions(b);
+    }
+
+    // Uninstall PLAF
+    public void uninstallUI(final JComponent c) {
+        uninstallKeyboardActions((AbstractButton)c);
+        uninstallListeners((AbstractButton)c);
+        uninstallDefaults((AbstractButton)c);
+        //BasicHTML.updateRenderer(c, "");
+    }
+
+    protected void uninstallKeyboardActions(final AbstractButton b) {
+        final BasicButtonListener listener = (BasicButtonListener)b.getClientProperty(this);
+        if (listener != null) listener.uninstallKeyboardActions(b);
+    }
+
+    protected void uninstallListeners(final AbstractButton b) {
+        final AquaButtonListener listener = (AquaButtonListener)b.getClientProperty(this);
+        b.putClientProperty(this, null);
+        if (listener != null) {
+            b.removeMouseListener(listener);
+            b.removeMouseListener(listener);
+            b.removeMouseMotionListener(listener);
+            b.removeFocusListener(listener);
+            b.removeChangeListener(listener);
+            b.removePropertyChangeListener(listener);
+            b.removeAncestorListener(listener);
+        }
+        uninstallHierListener(b);
+        AquaUtilControlSize.addSizePropertyListener(b);
+    }
+
+    protected void uninstallDefaults(final AbstractButton b) {
+        LookAndFeel.uninstallBorder(b);
+        defaults_initialized = false;
+    }
+
+    // Create Listeners
+    protected AquaButtonListener createButtonListener(final AbstractButton b) {
+        return new AquaButtonListener(b);
+    }
+
+    // Paint Methods
+    public void paint(final Graphics g, final JComponent c) {
+        final AbstractButton b = (AbstractButton)c;
+        final ButtonModel model = b.getModel();
+
+        final Insets i = c.getInsets();
+
+        Rectangle viewRect = new Rectangle(b.getWidth(), b.getHeight());
+        Rectangle iconRect = new Rectangle();
+        Rectangle textRect = new Rectangle();
+
+        // we are overdrawing here with translucent colors so we get
+        // a darkening effect. How can we avoid it. Try clear rect?
+        if (b.isOpaque()) {
+            g.setColor(c.getBackground());
+            g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
+        }
+
+        AquaButtonBorder aquaBorder = null;
+        if (((AbstractButton)c).isBorderPainted()) {
+            final Border border = c.getBorder();
+
+            if (border instanceof AquaButtonBorder) {
+                // only do this if borders are on!
+                // this also takes care of focus painting.
+                aquaBorder = (AquaButtonBorder)border;
+                aquaBorder.paintButton(c, g, viewRect.x, viewRect.y, viewRect.width, viewRect.height);
+            }
+        } else {
+            if (b.isOpaque()) {
+                viewRect.x = i.left - 2;
+                viewRect.y = i.top - 2;
+                viewRect.width = b.getWidth() - (i.right + viewRect.x) + 4;
+                viewRect.height = b.getHeight() - (i.bottom + viewRect.y) + 4;
+                if (b.isContentAreaFilled() || model.isSelected()) {
+                    if (model.isSelected()) // Toggle buttons
+                    g.setColor(c.getBackground().darker());
+                    else g.setColor(c.getBackground());
+                    g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
+                }
+            }
+
+            // needs focus to be painted
+            // for now we don't know exactly what to do...we'll see!
+            if (b.isFocusPainted() && b.hasFocus()) {
+                // paint UI specific focus
+                paintFocus(g, b, viewRect, textRect, iconRect);
+            }
+        }
+
+        // performs icon and text rect calculations
+        final String text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
+
+        // Paint the Icon
+        if (b.getIcon() != null) {
+            paintIcon(g, b, iconRect);
+        }
+
+        if (textRect.width == 0) {
+            textRect.width = 50;
+        }
+
+        if (text != null && !text.equals("")) {
+            final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
+            if (v != null) {
+                v.paint(g, textRect);
+            } else {
+                paintText(g, b, textRect, text);
+            }
+        }
+    }
+
+    protected String layoutAndGetText(final Graphics g, final AbstractButton b, final AquaButtonBorder aquaBorder, final Insets i, Rectangle viewRect, Rectangle iconRect, Rectangle textRect) {
+        // re-initialize the view rect to the selected insets
+        viewRect.x = i.left;
+        viewRect.y = i.top;
+        viewRect.width = b.getWidth() - (i.right + viewRect.x);
+        viewRect.height = b.getHeight() - (i.bottom + viewRect.y);
+
+        // reset the text and icon rects
+        textRect.x = textRect.y = textRect.width = textRect.height = 0;
+        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
+
+        // setup the font
+        g.setFont(b.getFont());
+        final FontMetrics fm = g.getFontMetrics();
+
+        // layout the text and icon
+        final String originalText = b.getText();
+        final String text = SwingUtilities.layoutCompoundLabel(b, fm, originalText, b.getIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, originalText == null ? 0 : b.getIconTextGap());
+        if (text == originalText || aquaBorder == null) return text; // everything fits
+
+        // if the text didn't fit - check if the aqua border has alternate Insets that are more adhering
+        final Insets alternateContentInsets = aquaBorder.getContentInsets(b, b.getWidth(), b.getHeight());
+        if (alternateContentInsets != null) {
+            // recursively call and don't pass AquaBorder
+            return layoutAndGetText(g, b, null, alternateContentInsets, viewRect, iconRect, textRect);
+        }
+
+        // there is no Aqua border, go with what we've got
+        return text;
+    }
+
+    protected void paintIcon(final Graphics g, final AbstractButton b, final Rectangle localIconRect) {
+        final ButtonModel model = b.getModel();
+        Icon icon = b.getIcon();
+        Icon tmpIcon = null;
+
+        if (icon == null) return;
+
+        if (!model.isEnabled()) {
+            if (model.isSelected()) {
+                tmpIcon = b.getDisabledSelectedIcon();
+            } else {
+                tmpIcon = b.getDisabledIcon();
+            }
+        } else if (model.isPressed() && model.isArmed()) {
+            tmpIcon = b.getPressedIcon();
+            if (tmpIcon == null) {
+                if (icon instanceof ImageIcon) {
+                    tmpIcon = new ImageIcon(AquaUtils.generateSelectedDarkImage(((ImageIcon)icon).getImage()));
+                }
+            }
+        } else if (b.isRolloverEnabled() && model.isRollover()) {
+            if (model.isSelected()) {
+                tmpIcon = b.getRolloverSelectedIcon();
+            } else {
+                tmpIcon = b.getRolloverIcon();
+            }
+        } else if (model.isSelected()) {
+            tmpIcon = b.getSelectedIcon();
+        }
+
+        if (model.isEnabled() && b.isFocusOwner() && b.getBorder() instanceof AquaButtonBorder.Toolbar) {
+            if (tmpIcon == null) tmpIcon = icon;
+            if (tmpIcon instanceof ImageIcon) {
+                tmpIcon = AquaFocus.createFocusedIcon(tmpIcon, b, 3);
+                tmpIcon.paintIcon(b, g, localIconRect.x - 3, localIconRect.y - 3);
+                return;
+            }
+        }
+
+        if (tmpIcon != null) {
+            icon = tmpIcon;
+        }
+
+        icon.paintIcon(b, g, localIconRect.x, localIconRect.y);
+    }
+
+    /**
+     * As of Java 2 platform v 1.4 this method should not be used or overriden.
+     * Use the paintText method which takes the AbstractButton argument.
+     */
+    protected void paintText(final Graphics g, final JComponent c, final Rectangle localTextRect, final String text) {
+        final Graphics2D g2d = g instanceof Graphics2D ? (Graphics2D)g : null;
+
+        final AbstractButton b = (AbstractButton)c;
+        final ButtonModel model = b.getModel();
+        final FontMetrics fm = g.getFontMetrics();
+        final int mnemonicIndex = AquaMnemonicHandler.isMnemonicHidden() ? -1 : b.getDisplayedMnemonicIndex();
+
+        /* Draw the Text */
+        if (model.isEnabled()) {
+            /*** paint the text normally */
+            g.setColor(b.getForeground());
+        } else {
+            /*** paint the text disabled ***/
+            g.setColor(defaultDisabledTextColor);
+        }
+        SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, localTextRect.x, localTextRect.y + fm.getAscent());
+    }
+
+    protected void paintText(final Graphics g, final AbstractButton b, final Rectangle localTextRect, final String text) {
+        paintText(g, (JComponent)b, localTextRect, text);
+    }
+
+    protected void paintButtonPressed(final Graphics g, final AbstractButton b) {
+        paint(g, b);
+    }
+
+    // Layout Methods
+    public Dimension getMinimumSize(final JComponent c) {
+        final Dimension d = getPreferredSize(c);
+        final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
+        if (v != null) {
+            d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
+        }
+        return d;
+    }
+
+    public Dimension getPreferredSize(final JComponent c) {
+        final AbstractButton b = (AbstractButton)c;
+
+        // fix for Radar #3134273
+        final Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
+        if (d == null) return null;
+
+        final Border border = b.getBorder();
+        if (border instanceof AquaButtonBorder) {
+            ((AquaButtonBorder)border).alterPreferredSize(d);
+        }
+
+        return d;
+    }
+
+    public Dimension getMaximumSize(final JComponent c) {
+        final Dimension d = getPreferredSize(c);
+
+        final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
+        if (v != null) {
+            d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
+        }
+
+        return d;
+    }
+
+    final static RecyclableSingleton<AquaHierarchyButtonListener> fHierListener = new RecyclableSingletonFromDefaultConstructor<AquaHierarchyButtonListener>(AquaHierarchyButtonListener.class);
+    static AquaHierarchyButtonListener getAquaHierarchyButtonListener() {
+        return fHierListener.get();
+    }
+
+    // We need to know when ordinary JButtons are put on JToolbars, but not JComboBoxButtons
+    // JToggleButtons always have the same border
+
+    private boolean shouldInstallHierListener(final AbstractButton b) {
+        return  (b instanceof JButton || b instanceof JToggleButton && !(b instanceof AquaComboBoxButton) && !(b instanceof JCheckBox) && !(b instanceof JRadioButton));
+    }
+
+    protected void installHierListener(final AbstractButton b) {
+        if (shouldInstallHierListener(b)) {
+            // super put the listener in the button's client properties
+            b.addHierarchyListener(getAquaHierarchyButtonListener());
+        }
+    }
+
+    protected void uninstallHierListener(final AbstractButton b) {
+        if (shouldInstallHierListener(b)) {
+            b.removeHierarchyListener(getAquaHierarchyButtonListener());
+        }
+    }
+
+    static class AquaHierarchyButtonListener implements HierarchyListener {
+        // Everytime a hierarchy is change we need to check if the button if moved on or from
+        // a toolbar. If that is the case, we need to re-set the border of the button.
+        public void hierarchyChanged(final HierarchyEvent e) {
+            if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == 0) return;
+
+            final Object o = e.getSource();
+            if (!(o instanceof AbstractButton)) return;
+
+            final AbstractButton b = (AbstractButton)o;
+            final ButtonUI ui = b.getUI();
+            if (!(ui instanceof AquaButtonUI)) return;
+
+            if (!(b.getBorder() instanceof UIResource)) return; // if the border is not one of ours, or null
+            ((AquaButtonUI)ui).setThemeBorder(b);
+        }
+    }
+
+    class AquaButtonListener extends BasicButtonListener implements AncestorListener {
+        protected final AbstractButton b;
+
+        public AquaButtonListener(final AbstractButton b) {
+            super(b);
+            this.b = b;
+        }
+
+        public void focusGained(final FocusEvent e) {
+            ((Component)e.getSource()).repaint();
+        }
+
+        public void focusLost(final FocusEvent e) {
+            // 10-06-03 VL: [Radar 3187049]
+            // If focusLost arrives while the button has been left-clicked this would disarm the button,
+            // causing actionPerformed not to fire on mouse release!
+            //b.getModel().setArmed(false);
+            ((Component)e.getSource()).repaint();
+        }
+
+        public void propertyChange(final PropertyChangeEvent e) {
+            super.propertyChange(e);
+
+            final String propertyName = e.getPropertyName();
+
+            // Repaint the button, since its border needs to handle the new state.
+            if (AquaFocusHandler.FRAME_ACTIVE_PROPERTY.equals(propertyName)) {
+                b.repaint();
+                return;
+            }
+
+            if ("icon".equals(propertyName) || "text".equals(propertyName)) {
+                setThemeBorder(b);
+                return;
+            }
+
+            if (BUTTON_TYPE.equals(propertyName)) {
+                // Forced border types
+                final String value = (String)e.getNewValue();
+
+                final Border border = AquaButtonExtendedTypes.getBorderForPosition(b, value, b.getClientProperty(SEGMENTED_BUTTON_POSITION));
+                if (border != null) {
+                    b.setBorder(border);
+                }
+
+                return;
+            }
+
+            if (SEGMENTED_BUTTON_POSITION.equals(propertyName)) {
+                final Border border = b.getBorder();
+                if (!(border instanceof AquaBorder)) return;
+
+                b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, b.getClientProperty(BUTTON_TYPE), e.getNewValue()));
+            }
+
+            if ("componentOrientation".equals(propertyName)) {
+                final Border border = b.getBorder();
+                if (!(border instanceof AquaBorder)) return;
+
+                Object buttonType = b.getClientProperty(BUTTON_TYPE);
+                Object buttonPosition = b.getClientProperty(SEGMENTED_BUTTON_POSITION);
+                if (buttonType != null && buttonPosition != null) {
+                    b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, buttonType, buttonPosition));
+                }
+            }
+        }
+
+        public void ancestorMoved(final AncestorEvent e) {}
+
+        public void ancestorAdded(final AncestorEvent e) {
+            updateDefaultButton();
+        }
+
+        public void ancestorRemoved(final AncestorEvent e) {
+            updateDefaultButton();
+        }
+
+        protected void updateDefaultButton() {
+            if (!(b instanceof JButton)) return;
+            if (!((JButton)b).isDefaultButton()) return;
+
+            final JRootPane rootPane = b.getRootPane();
+            if (rootPane == null) return;
+
+            final RootPaneUI ui = rootPane.getUI();
+            if (!(ui instanceof AquaRootPaneUI)) return;
+            ((AquaRootPaneUI)ui).updateDefaultButton(rootPane);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaCaret.java b/jdk/src/macosx/classes/com/apple/laf/AquaCaret.java
new file mode 100644
index 0000000..949e87c
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaCaret.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.Rectangle2D;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.UIResource;
+import javax.swing.text.*;
+
+public class AquaCaret extends DefaultCaret implements UIResource, PropertyChangeListener {
+    final boolean isMultiLineEditor;
+    final JTextComponent c;
+
+    boolean mFocused = false;
+
+    public AquaCaret(final Window inParentWindow, final JTextComponent inComponent) {
+        super();
+        c = inComponent;
+        isMultiLineEditor = (c instanceof JTextArea || c instanceof JEditorPane);
+        inComponent.addPropertyChangeListener(this);
+    }
+
+    protected Highlighter.HighlightPainter getSelectionPainter() {
+        return AquaHighlighter.getInstance();
+    }
+
+    /**
+     * Only show the flashing caret if the selection range is zero
+     */
+    public void setVisible(boolean e) {
+        if (e) e = getDot() == getMark();
+        super.setVisible(e);
+    }
+
+    public void setSelectionVisible(final boolean vis) {
+        if (isMultiLineEditor) {
+            super.setSelectionVisible(true);
+            c.repaint();
+            return;
+        }
+        super.setSelectionVisible(vis);
+    }
+
+    protected void fireStateChanged() {
+        // If we have focus the caret should only flash if the range length is zero
+        if (mFocused) setVisible(getComponent().isEditable());
+
+        super.fireStateChanged();
+    }
+
+    public void propertyChange(final PropertyChangeEvent evt) {
+        final String propertyName = evt.getPropertyName();
+
+        if (AquaFocusHandler.FRAME_ACTIVE_PROPERTY.equals(propertyName)) {
+            final JTextComponent comp = ((JTextComponent)evt.getSource());
+
+            if (evt.getNewValue() == Boolean.TRUE) {
+                setVisible(comp.hasFocus());
+            } else {
+                setVisible(false);
+            }
+
+            if (getDot() != getMark()) comp.getUI().damageRange(comp, getDot(), getMark());
+        }
+    }
+
+    // --- FocusListener methods --------------------------
+
+    private boolean shouldSelectAllOnFocus = true;
+    public void focusGained(final FocusEvent e) {
+        final JTextComponent component = getComponent();
+        if (!component.isEnabled() || !component.isEditable()) {
+            super.focusGained(e);
+            return;
+        }
+
+        mFocused = true;
+        if (!shouldSelectAllOnFocus) {
+            shouldSelectAllOnFocus = true;
+            super.focusGained(e);
+            return;
+        }
+
+        if (isMultiLineEditor) {
+            super.focusGained(e);
+            return;
+        }
+
+        final int end = component.getDocument().getLength();
+        final int dot = getDot();
+        final int mark = getMark();
+        if (dot == mark) {
+            if (dot == 0) {
+                component.setCaretPosition(end);
+                component.moveCaretPosition(0);
+            } else if (dot == end) {
+                component.setCaretPosition(0);
+                component.moveCaretPosition(end);
+            }
+        }
+
+        super.focusGained(e);
+    }
+
+    public void focusLost(final FocusEvent e) {
+        mFocused = false;
+        shouldSelectAllOnFocus = true;
+        super.focusLost(e);
+    }
+
+    // This fixes the problem where when on the mac you have to ctrl left click to
+    // get popup triggers the caret has code that only looks at button number.
+    // see radar # 3125390
+    public void mousePressed(final MouseEvent e) {
+        if (!e.isPopupTrigger()) {
+            super.mousePressed(e);
+            shouldSelectAllOnFocus = false;
+        }
+    }
+
+    /**
+     * Damages the area surrounding the caret to cause
+     * it to be repainted in a new location.  If paint()
+     * is reimplemented, this method should also be
+     * reimplemented.  This method should update the
+     * caret bounds (x, y, width, and height).
+     *
+     * @param r  the current location of the caret
+     * @see #paint
+     */
+    protected synchronized void damage(final Rectangle r) {
+        if (r == null || fPainting) return;
+
+        x = r.x - 4;
+        y = r.y;
+        width = 10;
+        height = r.height;
+
+        // Don't damage the border area.  We can't paint a partial border, so get the
+        // intersection of the caret rectangle and the component less the border, if any.
+        final Rectangle caretRect = new Rectangle(x, y, width, height);
+        final Border border = getComponent().getBorder();
+        if (border != null) {
+            final Rectangle alloc = getComponent().getBounds();
+            alloc.x = alloc.y = 0;
+            final Insets borderInsets = border.getBorderInsets(getComponent());
+            alloc.x += borderInsets.left;
+            alloc.y += borderInsets.top;
+            alloc.width -= borderInsets.left + borderInsets.right;
+            alloc.height -= borderInsets.top + borderInsets.bottom;
+            Rectangle2D.intersect(caretRect, alloc, caretRect);
+        }
+        x = caretRect.x;
+        y = caretRect.y;
+        width = Math.max(caretRect.width, 1);
+        height = Math.max(caretRect.height, 1);
+        repaint();
+    }
+
+    boolean fPainting = false;
+
+    // See <rdar://problem/3833837> 1.4.2_05-141.3: JTextField performance with Aqua L&F
+    // We are getting into a circular condition with the BasicCaret paint code since it doesn't know about the fact that our
+    // damage routine above elminates the border. Sadly we can't easily change either one, so we will
+    // add a painting flag and not damage during a repaint.
+    public void paint(final Graphics g) {
+        if (isVisible()) {
+            fPainting = true;
+            super.paint(g);
+            fPainting = false;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxButton.java b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxButton.java
new file mode 100644
index 0000000..355447e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxButton.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.UIResource;
+
+import apple.laf.JRSUIState;
+import apple.laf.JRSUIConstants.*;
+
+class AquaComboBoxButton extends JButton {
+    final protected JComboBox comboBox;
+    final protected JList list;
+    final protected CellRendererPane rendererPane;
+    final protected AquaComboBoxUI ui;
+
+    protected final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIState.getInstance());
+    boolean isPopDown;
+    boolean isSquare;
+
+    protected AquaComboBoxButton(final AquaComboBoxUI ui, final JComboBox comboBox, final CellRendererPane rendererPane, final JList list) {
+        super("");
+        putClientProperty("JButton.buttonType", "comboboxInternal");
+
+        this.ui = ui;
+        this.comboBox = comboBox;
+        this.rendererPane = rendererPane;
+        this.list = list;
+
+        setModel(new DefaultButtonModel() {
+            public void setArmed(final boolean armed) {
+                super.setArmed(isPressed() ? true : armed);
+            }
+        });
+
+        setEnabled(comboBox.isEnabled());
+    }
+
+    public boolean isEnabled() {
+        return comboBox == null ? true : comboBox.isEnabled();
+    }
+
+    public boolean isFocusTraversable() {
+        return false;
+    }
+
+    protected void setIsPopDown(final boolean isPopDown) {
+        this.isPopDown = isPopDown;
+        repaint();
+    }
+
+    protected void setIsSquare(final boolean isSquare) {
+        this.isSquare = isSquare;
+        repaint();
+    }
+
+    protected State getState(final ButtonModel buttonModel) {
+        if (!comboBox.isEnabled()) return State.DISABLED;
+        if (!AquaFocusHandler.isActive(comboBox)) return State.INACTIVE;
+        if (buttonModel.isArmed()) return State.PRESSED;
+        return State.ACTIVE;
+    }
+
+    public void paintComponent(final Graphics g) {
+        // Don't Paint the button as usual
+        // super.paintComponent( g );
+        final boolean editable = comboBox.isEditable();
+
+        int top = 0;
+        int left = 0;
+        int width = getWidth();
+        int height = getHeight();
+
+        if (comboBox.isOpaque()) {
+            g.setColor(getBackground());
+            g.fillRect(0, 0, width, height);
+        }
+
+        final Size size = AquaUtilControlSize.getUserSizeFrom(comboBox);
+        painter.state.set(size == null ? Size.REGULAR : size);
+
+        final ButtonModel buttonModel = getModel();
+        painter.state.set(getState(buttonModel));
+
+        painter.state.set(AlignmentVertical.CENTER);
+
+        if (AquaComboBoxUI.isTableCellEditor(comboBox)) {
+            painter.state.set(AlignmentHorizontal.RIGHT);
+            painter.state.set(Widget.BUTTON_POP_UP);
+            painter.state.set(ArrowsOnly.YES);
+            painter.paint(g, this, left, top, width, height);
+            doRendererPaint(g, buttonModel, editable, getInsets(), left, top, width, height);
+            return;
+        }
+
+        painter.state.set(AlignmentHorizontal.CENTER);
+        final Insets insets = getInsets();
+        if (!editable) {
+            top += insets.top;
+            left += insets.left;
+            width -= insets.left + insets.right;
+            height -= insets.top + insets.bottom;
+        }
+
+        if (height <= 0 || width <= 0) {
+            return;
+        }
+
+        boolean hasFocus = comboBox.hasFocus();
+        if (editable) {
+            painter.state.set(Widget.BUTTON_COMBO_BOX);
+            painter.state.set(IndicatorOnly.YES);
+            painter.state.set(AlignmentHorizontal.LEFT);
+            hasFocus |= comboBox.getEditor().getEditorComponent().hasFocus();
+        } else {
+            painter.state.set(IndicatorOnly.NO);
+            painter.state.set(AlignmentHorizontal.CENTER);
+            if (isPopDown) {
+                painter.state.set(isSquare ? Widget.BUTTON_POP_DOWN_SQUARE : Widget.BUTTON_POP_DOWN);
+            } else {
+                painter.state.set(isSquare ? Widget.BUTTON_POP_UP_SQUARE : Widget.BUTTON_POP_UP);
+            }
+        }
+        painter.state.set(hasFocus ? Focused.YES : Focused.NO);
+
+        if (isSquare) {
+            painter.paint(g, comboBox, left + 2, top - 1, width - 4, height);
+        } else {
+            painter.paint(g, comboBox, left, top, width, height);
+        }
+
+        // Let the renderer paint
+        if (!editable && comboBox != null) {
+            doRendererPaint(g, buttonModel, editable, insets, left, top, width, height);
+        }
+    }
+
+    protected void doRendererPaint(final Graphics g, final ButtonModel buttonModel, final boolean editable, final Insets insets, int left, int top, int width, int height) {
+        final ListCellRenderer renderer = comboBox.getRenderer();
+
+        // fake it out! not renderPressed
+        final Component c = renderer.getListCellRendererComponent(list, comboBox.getSelectedItem(), -1, false, false);
+        // System.err.println("Renderer: " + renderer);
+
+        if (!editable && !AquaComboBoxUI.isTableCellEditor(comboBox)) {
+            final int indentLeft = 10;
+            final int buttonWidth = 24;
+
+            // hardcoded for now. We should adjust as necessary.
+            top += 1;
+            height -= 4;
+            left += indentLeft;
+            width -= (indentLeft + buttonWidth);
+        }
+
+        c.setFont(rendererPane.getFont());
+
+        if (buttonModel.isArmed() && buttonModel.isPressed()) {
+            if (isOpaque()) {
+                c.setBackground(UIManager.getColor("Button.select"));
+            }
+            c.setForeground(comboBox.getForeground());
+        } else if (!comboBox.isEnabled()) {
+            if (isOpaque()) {
+                c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
+            }
+            c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
+        } else {
+            c.setForeground(comboBox.getForeground());
+            c.setBackground(comboBox.getBackground());
+        }
+
+        // Sun Fix for 4238829: should lay out the JPanel.
+        boolean shouldValidate = false;
+        if (c instanceof JPanel) {
+            shouldValidate = true;
+        }
+
+        final int iconWidth = 0;
+        final int cWidth = width - (insets.right + iconWidth);
+
+        // fix for 3156483 we need to crop images that are too big.
+        // if (height > 18)
+        // always crop.
+        {
+            top = height / 2 - 8;
+            height = 19;
+        }
+
+        // It doesn't need to draw its background, we handled it
+        final Color bg = c.getBackground();
+        final boolean inhibitBackground = bg instanceof UIResource;
+        if (inhibitBackground) c.setBackground(new Color(0, 0, 0, 0));
+
+        rendererPane.paintComponent(g, c, this, left, top, cWidth, height, shouldValidate); // h - (insets.top + insets.bottom) );
+
+        if (inhibitBackground) c.setBackground(bg);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxPopup.java b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxPopup.java
new file mode 100644
index 0000000..75864f9
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxPopup.java
@@ -0,0 +1,375 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import javax.swing.*;
+import javax.swing.plaf.basic.BasicComboPopup;
+
+import sun.lwawt.macosx.CPlatformWindow;
+
+class AquaComboBoxPopup extends BasicComboPopup {
+    static final int FOCUS_RING_PAD_LEFT = 6;
+    static final int FOCUS_RING_PAD_RIGHT = 6;
+    static final int FOCUS_RING_PAD_BOTTOM = 5;
+
+    protected Component topStrut;
+    protected Component bottomStrut;
+    protected boolean isPopDown = false;
+
+    public AquaComboBoxPopup(final JComboBox cBox) {
+        super(cBox);
+    }
+
+    @Override
+    protected void configurePopup() {
+        super.configurePopup();
+
+        setBorderPainted(false);
+        setBorder(null);
+        updateContents(false);
+
+        // TODO: CPlatformWindow?
+        putClientProperty(CPlatformWindow.WINDOW_FADE_OUT, new Integer(150));
+    }
+
+    public void updateContents(final boolean remove) {
+        // for more background on this issue, see AquaMenuBorder.getBorderInsets()
+
+        isPopDown = isPopdown();
+        if (isPopDown) {
+            if (remove) {
+                if (topStrut != null) {
+                    this.remove(topStrut);
+                }
+                if (bottomStrut != null) {
+                    this.remove(bottomStrut);
+                }
+            } else {
+                add(scroller);
+            }
+        } else {
+            if (topStrut == null) {
+                topStrut = Box.createVerticalStrut(4);
+                bottomStrut = Box.createVerticalStrut(4);
+            }
+
+            if (remove) remove(scroller);
+
+            this.add(topStrut);
+            this.add(scroller);
+            this.add(bottomStrut);
+        }
+    }
+
+    protected Dimension getBestPopupSizeForRowCount(final int maxRowCount) {
+        final int currentElementCount = comboBox.getModel().getSize();
+        final int rowCount = Math.min(maxRowCount, currentElementCount);
+
+        final Dimension popupSize = new Dimension();
+        final ListCellRenderer renderer = list.getCellRenderer();
+
+        for (int i = 0; i < rowCount; i++) {
+            final Object value = list.getModel().getElementAt(i);
+            final Component c = renderer.getListCellRendererComponent(list, value, i, false, false);
+
+            final Dimension prefSize = c.getPreferredSize();
+            popupSize.height += prefSize.height;
+            popupSize.width = Math.max(prefSize.width, popupSize.width);
+        }
+
+        popupSize.width += 10;
+
+        return popupSize;
+    }
+
+    protected boolean shouldScroll() {
+        return comboBox.getItemCount() > comboBox.getMaximumRowCount();
+    }
+
+    protected boolean isPopdown() {
+        return shouldScroll() || AquaComboBoxUI.isPopdown(comboBox);
+    }
+
+    @Override
+    public void show() {
+        final int startItemCount = comboBox.getItemCount();
+
+        final Rectangle popupBounds = adjustPopupAndGetBounds();
+        if (popupBounds == null) return; // null means don't show
+
+        comboBox.firePopupMenuWillBecomeVisible();
+        show(comboBox, popupBounds.x, popupBounds.y);
+
+        // hack for <rdar://problem/4905531> JComboBox does not fire popupWillBecomeVisible if item count is 0
+        final int afterShowItemCount = comboBox.getItemCount();
+        if (afterShowItemCount == 0) {
+            hide();
+            return;
+        }
+
+        if (startItemCount != afterShowItemCount) {
+            final Rectangle newBounds = adjustPopupAndGetBounds();
+            list.setSize(newBounds.width, newBounds.height);
+            pack();
+
+            final Point newLoc = comboBox.getLocationOnScreen();
+            setLocation(newLoc.x + newBounds.x, newLoc.y + newBounds.y);
+        }
+        // end hack
+
+        list.requestFocusInWindow();
+    }
+
+    @Override
+    protected JList createList() {
+        return new JList(comboBox.getModel()) {
+            @Override
+            public void processMouseEvent(MouseEvent e) {
+                if (e.isMetaDown()) {
+                    e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(), e.getModifiers() ^ InputEvent.META_MASK, e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), MouseEvent.NOBUTTON);
+                }
+                super.processMouseEvent(e);
+            }
+        };
+    }
+
+    protected Rectangle adjustPopupAndGetBounds() {
+        if (isPopDown != isPopdown()) {
+            updateContents(true);
+        }
+
+        final Dimension popupSize = getBestPopupSizeForRowCount(comboBox.getMaximumRowCount());
+        final Rectangle popupBounds = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
+        if (popupBounds == null) return null; // returning null means don't show anything
+
+        final Dimension realPopupSize = popupBounds.getSize();
+        scroller.setMaximumSize(realPopupSize);
+        scroller.setPreferredSize(realPopupSize);
+        scroller.setMinimumSize(realPopupSize);
+        list.invalidate();
+
+        final int selectedIndex = comboBox.getSelectedIndex();
+        if (selectedIndex == -1) {
+            list.clearSelection();
+        } else {
+            list.setSelectedIndex(selectedIndex);
+        }
+        list.ensureIndexIsVisible(list.getSelectedIndex());
+
+        return popupBounds;
+    }
+
+    // Get the bounds of the screen where the menu should appear
+    // p is the origin of the combo box in screen bounds
+    Rectangle getBestScreenBounds(final Point p) {
+        //System.err.println("GetBestScreenBounds p: "+ p.x + ", " + p.y);
+        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        final GraphicsDevice[] gs = ge.getScreenDevices();
+        //System.err.println("  gs.length = " + gs.length);
+        final Rectangle comboBoxBounds = comboBox.getBounds();
+        if (gs.length == 1) {
+            final Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
+
+            //System.err.println("  scrSize: "+ scrSize);
+
+            // If the combo box is totally off screen, don't show a popup
+            if ((p.x + comboBoxBounds.width < 0) || (p.y + comboBoxBounds.height < 0) || (p.x > scrSize.width) || (p.y > scrSize.height)) {
+                return null;
+            }
+            return new Rectangle(0, 22, scrSize.width, scrSize.height - 22);
+        }
+
+        for (final GraphicsDevice gd : gs) {
+            final GraphicsConfiguration[] gc = gd.getConfigurations();
+            for (final GraphicsConfiguration element0 : gc) {
+                final Rectangle gcBounds = element0.getBounds();
+                if (gcBounds.contains(p)) return gcBounds;
+            }
+        }
+
+        // Hmm.  Origin's off screen, but is any part on?
+        comboBoxBounds.setLocation(p);
+        for (final GraphicsDevice gd : gs) {
+            final GraphicsConfiguration[] gc = gd.getConfigurations();
+            for (final GraphicsConfiguration element0 : gc) {
+                final Rectangle gcBounds = element0.getBounds();
+                if (gcBounds.intersects(comboBoxBounds)) return gcBounds;
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
+        final int itemCount = comboBox.getModel().getSize();
+        final boolean isPopdown = isPopdown();
+        final boolean isTableCellEditor = AquaComboBoxUI.isTableCellEditor(comboBox);
+        if (isPopdown && !isTableCellEditor) {
+            // place the popup just below the button, which is
+            // near the center of a large combo box
+            py = Math.min((py / 2) + 9, py); // if py is less than new y we have a clipped combo, so leave it alone.
+        }
+
+        // px & py are relative to the combo box
+
+        // **** Common calculation - applies to the scrolling and menu-style ****
+        final Point p = new Point(0, 0);
+        SwingUtilities.convertPointToScreen(p, comboBox);
+        //System.err.println("First Converting from point to screen: 0,0 is now " + p.x + ", " + p.y);
+        final Rectangle scrBounds = getBestScreenBounds(p);
+        //System.err.println("BestScreenBounds is " + scrBounds);
+
+        // If the combo box is totally off screen, do whatever super does
+        if (scrBounds == null) return super.computePopupBounds(px, py, pw, ph);
+
+        // line up with the bottom of the text field/button (or top, if we have to go above it)
+        // and left edge if left-to-right, right edge if right-to-left
+        final Insets comboBoxInsets = comboBox.getInsets();
+        final Rectangle comboBoxBounds = comboBox.getBounds();
+
+        if (shouldScroll()) {
+            pw += 15;
+        }
+
+        if (isPopdown) {
+            pw += 4;
+        }
+
+        // the popup should be wide enough for the items but not wider than the screen it's on
+        final int minWidth = comboBoxBounds.width - (comboBoxInsets.left + comboBoxInsets.right);
+        pw = Math.max(minWidth, pw);
+
+        final boolean leftToRight = AquaUtils.isLeftToRight(comboBox);
+        if (leftToRight) {
+            px += comboBoxInsets.left;
+            if (!isPopDown) px -= FOCUS_RING_PAD_LEFT;
+        } else {
+            px = comboBoxBounds.width - pw - comboBoxInsets.right;
+            if (!isPopDown) px += FOCUS_RING_PAD_RIGHT;
+        }
+        py -= (comboBoxInsets.bottom); //sja fix was +kInset
+
+        // Make sure it's all on the screen - shift it by the amount it's off
+        p.x += px;
+        p.y += py; // Screen location of px & py
+        if (p.x < scrBounds.x) px -= (p.x + scrBounds.x);
+        if (p.y < scrBounds.y) py -= (p.y + scrBounds.y);
+
+        final Point top = new Point(0, 0);
+        SwingUtilities.convertPointFromScreen(top, comboBox);
+        //System.err.println("Converting from point to screen: 0,0 is now " + top.x + ", " + top.y);
+
+        // Since the popup is at zero in this coord space, the maxWidth == the X coord of the screen right edge
+        // (it might be wider than the screen, if the combo is off the left edge)
+        final int maxWidth = Math.min(scrBounds.width, top.x + scrBounds.x + scrBounds.width) - 2; // subtract some buffer space
+
+        pw = Math.min(maxWidth, pw);
+        if (pw < minWidth) {
+            px -= (minWidth - pw);
+            pw = minWidth;
+        }
+
+        // this is a popup window, and will continue calculations below
+        if (!isPopdown) {
+            // popup windows are slightly inset from the combo end-cap
+            pw -= 6;
+            return computePopupBoundsForMenu(px, py, pw, ph, itemCount, scrBounds);
+        }
+
+        // don't attempt to inset table cell editors
+        if (!isTableCellEditor) {
+            pw -= (FOCUS_RING_PAD_LEFT + FOCUS_RING_PAD_RIGHT);
+            if (leftToRight) {
+                px += FOCUS_RING_PAD_LEFT;
+            }
+        }
+
+        final Rectangle r = new Rectangle(px, py, pw, ph);
+        // Check whether it goes below the bottom of the screen, if so flip it
+        if (r.y + r.height < top.y + scrBounds.y + scrBounds.height) return r;
+
+        return new Rectangle(px, -r.height + comboBoxInsets.top, r.width, r.height);
+    }
+
+    // The one to use when itemCount <= maxRowCount.  Size never adjusts for arrows
+    // We want it positioned so the selected item is right above the combo box
+    protected Rectangle computePopupBoundsForMenu(final int px, final int py, final int pw, final int ph, final int itemCount, final Rectangle scrBounds) {
+        //System.err.println("computePopupBoundsForMenu: " + px + "," + py + " " +  pw + "," + ph);
+        //System.err.println("itemCount: " +itemCount +" src: "+ scrBounds);
+        int elementSize = 0; //kDefaultItemSize;
+        if (list != null && itemCount > 0) {
+            final Rectangle cellBounds = list.getCellBounds(0, 0);
+            if (cellBounds != null) elementSize = cellBounds.height;
+        }
+
+        int offsetIndex = comboBox.getSelectedIndex();
+        if (offsetIndex < 0) offsetIndex = 0;
+        list.setSelectedIndex(offsetIndex);
+
+        final int selectedLocation = elementSize * offsetIndex;
+
+        final Point top = new Point(0, scrBounds.y);
+        final Point bottom = new Point(0, scrBounds.y + scrBounds.height - 20); // Allow some slack
+        SwingUtilities.convertPointFromScreen(top, comboBox);
+        SwingUtilities.convertPointFromScreen(bottom, comboBox);
+
+        final Rectangle popupBounds = new Rectangle(px, py, pw, ph);// Relative to comboBox
+
+        final int theRest = ph - selectedLocation;
+
+        // If the popup fits on the screen and the selection appears under the mouse w/o scrolling, cool!
+        // If the popup won't fit on the screen, adjust its position but not its size
+        // and rewrite this to support arrows - JLists always move the contents so they all show
+
+        // Test to see if it extends off the screen
+        final boolean extendsOffscreenAtTop = selectedLocation > -top.y;
+        final boolean extendsOffscreenAtBottom = theRest > bottom.y;
+
+        if (extendsOffscreenAtTop) {
+            popupBounds.y = top.y + 1;
+            // Round it so the selection lines up with the combobox
+            popupBounds.y = (popupBounds.y / elementSize) * elementSize;
+        } else if (extendsOffscreenAtBottom) {
+            // Provide blank space at top for off-screen stuff to scroll into
+            popupBounds.y = bottom.y - popupBounds.height; // popupBounds.height has already been adjusted to fit
+        } else { // fits - position it so the selectedLocation is under the mouse
+            popupBounds.y = -selectedLocation;
+        }
+
+        // Center the selected item on the combobox
+        final int height = comboBox.getHeight();
+        final Insets insets = comboBox.getInsets();
+        final int buttonSize = height - (insets.top + insets.bottom);
+        final int diff = (buttonSize - elementSize) / 2 + insets.top;
+        popupBounds.y += diff - FOCUS_RING_PAD_BOTTOM;
+
+        return popupBounds;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxRenderer.java b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxRenderer.java
new file mode 100644
index 0000000..4b31dfff
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxRenderer.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.UIResource;
+
+import sun.swing.SwingUtilities2;
+
+class AquaComboBoxRenderer extends AquaComboBoxRendererInternal implements UIResource {
+    public AquaComboBoxRenderer(final JComboBox comboBox) {
+        super(comboBox);
+    }
+}
+
+class AquaComboBoxRendererInternal extends JLabel implements ListCellRenderer {
+    final JComboBox fComboBox;
+    boolean fSelected;
+    boolean fChecked;
+    boolean fInList;
+    boolean fEditable;
+    boolean fDrawCheckedItem = true;
+
+    // Provides space for a checkbox, and is translucent
+    public AquaComboBoxRendererInternal(final JComboBox comboBox) {
+        super();
+        fComboBox = comboBox;
+    }
+
+    // Don't include checkIcon space, because this is also used for button size calculations
+    // - the popup-size calc will get checkIcon space from getInsets
+    public Dimension getPreferredSize() {
+        // From BasicComboBoxRenderer - trick to avoid zero-height items
+        final Dimension size;
+
+        final String text = getText();
+        if ((text == null) || ("".equals(text))) {
+            setText(" ");
+            size = super.getPreferredSize();
+            setText("");
+        } else {
+            size = super.getPreferredSize();
+        }
+        return size;
+    }
+
+    // Don't paint the border here, it gets painted by the UI
+    protected void paintBorder(final Graphics g) {
+
+    }
+
+    public int getBaseline(int width, int height) {
+        return super.getBaseline(width, height) - 1;
+    }
+
+    // Really means is the one with the mouse over it
+    public Component getListCellRendererComponent(final JList list, final Object value, int index, final boolean isSelected, final boolean cellHasFocus) {
+        fInList = (index >= 0); // When the button wants the item painted, it passes in -1
+        fSelected = isSelected;
+        if (index < 0) {
+            index = fComboBox.getSelectedIndex();
+        }
+
+        // changed this to not ask for selected index but directly compare the current item and selected item
+        // different from basic because basic has no concept of checked, just has the last one selected,
+        // and the user changes selection. We have selection and a check mark.
+        // we used to call fComboBox.getSelectedIndex which ends up being a very bad call for large checkboxes
+        // it does a linear compare of every object in the checkbox until it finds the selected one, so if
+        // we have a 5000 element list we will 5000 * (selected index) .equals() of objects.
+        // See Radar #3141307
+
+        // Fix for Radar # 3204287 where we ask for an item at a negative index!
+        if (index >= 0) {
+            final Object item = fComboBox.getItemAt(index);
+            fChecked = fInList && item != null && item.equals(fComboBox.getSelectedItem());
+        } else {
+            fChecked = false;
+        }
+
+        fEditable = fComboBox.isEditable();
+        if (isSelected) {
+            if (fEditable) {
+                setBackground(UIManager.getColor("List.selectionBackground"));
+                setForeground(UIManager.getColor("List.selectionForeground"));
+            } else {
+                setBackground(list.getSelectionBackground());
+                setForeground(list.getSelectionForeground());
+            }
+        } else {
+            if (fEditable) {
+                setBackground(UIManager.getColor("List.background"));
+                setForeground(UIManager.getColor("List.foreground"));
+            } else {
+                setBackground(list.getBackground());
+                setForeground(list.getForeground());
+            }
+        }
+
+        setFont(list.getFont());
+
+        if (value instanceof Icon) {
+            setIcon((Icon)value);
+        } else {
+            setText((value == null) ? " " : value.toString());
+        }
+        return this;
+    }
+
+    public Insets getInsets(Insets insets) {
+        if (insets == null) insets = new Insets(0, 0, 0, 0);
+        insets.top = 1;
+        insets.bottom = 1;
+        insets.right = 5;
+        insets.left = (fInList && !fEditable ? 16 + 7 : 5);
+        return insets;
+    }
+
+    protected void setDrawCheckedItem(final boolean drawCheckedItem) {
+        this.fDrawCheckedItem = drawCheckedItem;
+    }
+
+    // Paint this component, and a checkbox if it's the selected item and not in the button
+    protected void paintComponent(final Graphics g) {
+        if (fInList) {
+            if (fSelected && !fEditable) {
+                AquaMenuPainter.instance().paintSelectedMenuItemBackground(g, getWidth(), getHeight());
+            } else {
+                g.setColor(getBackground());
+                g.fillRect(0, 0, getWidth(), getHeight());
+            }
+
+            if (fChecked && !fEditable && fDrawCheckedItem) {
+                final int y = getHeight() - 4;
+                g.setColor(getForeground());
+                SwingUtilities2.drawString(fComboBox, g, "\u2713", 6, y);
+            }
+        }
+        super.paintComponent(g);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxUI.java
new file mode 100644
index 0000000..02ab200
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaComboBoxUI.java
@@ -0,0 +1,604 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import javax.accessibility.*;
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.*;
+import com.apple.laf.ClientPropertyApplicator;
+import com.apple.laf.ClientPropertyApplicator.Property;
+import apple.laf.JRSUIConstants.Size;
+
+import com.apple.laf.AquaUtilControlSize.Sizeable;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+// Inspired by MetalComboBoxUI, which also has a combined text-and-arrow button for noneditables
+public class AquaComboBoxUI extends BasicComboBoxUI implements Sizeable {
+    static final String POPDOWN_CLIENT_PROPERTY_KEY = "JComboBox.isPopDown";
+    static final String ISSQUARE_CLIENT_PROPERTY_KEY = "JComboBox.isSquare";
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaComboBoxUI();
+    }
+
+    private boolean wasOpaque;
+    public void installUI(final JComponent c) {
+        super.installUI(c);
+
+        // this doesn't work right now, because the JComboBox.init() method calls
+        // .setOpaque(false) directly, and doesn't allow the LaF to decided. Bad Sun!
+        LookAndFeel.installProperty(c, "opaque", Boolean.FALSE);
+
+        wasOpaque = c.isOpaque();
+        c.setOpaque(false);
+    }
+
+    public void uninstallUI(final JComponent c) {
+        c.setOpaque(wasOpaque);
+        super.uninstallUI(c);
+    }
+
+    protected void installListeners() {
+        super.installListeners();
+        AquaUtilControlSize.addSizePropertyListener(comboBox);
+    }
+
+    protected void uninstallListeners() {
+        AquaUtilControlSize.removeSizePropertyListener(comboBox);
+        super.uninstallListeners();
+    }
+
+    protected void installComponents() {
+        super.installComponents();
+
+        // client properties must be applied after the components have been installed,
+        // because isSquare and isPopdown are applied to the installed button
+        getApplicator().attachAndApplyClientProperties(comboBox);
+    }
+
+    protected void uninstallComponents() {
+        getApplicator().removeFrom(comboBox);
+        super.uninstallComponents();
+    }
+
+    protected ItemListener createItemListener() {
+        return new ItemListener() {
+            long lastBlink = 0L;
+            public void itemStateChanged(final ItemEvent e) {
+                if (e.getStateChange() != ItemEvent.SELECTED) return;
+                if (!popup.isVisible()) return;
+
+                // sometimes, multiple selection changes can occur while the popup is up,
+                // and blinking more than "once" (in a second) is not desirable
+                final long now = System.currentTimeMillis();
+                if (now - 1000 < lastBlink) return;
+                lastBlink = now;
+
+                final JList itemList = popup.getList();
+                final ListUI listUI = itemList.getUI();
+                if (!(listUI instanceof AquaListUI)) return;
+                final AquaListUI aquaListUI = (AquaListUI)listUI;
+
+                final int selectedIndex = comboBox.getSelectedIndex();
+                final ListModel dataModel = itemList.getModel();
+                if (dataModel == null) return;
+
+                final Object value = dataModel.getElementAt(selectedIndex);
+                AquaUtils.blinkMenu(new AquaUtils.Selectable() {
+                    public void paintSelected(final boolean selected) {
+                        aquaListUI.repaintCell(value, selectedIndex, selected);
+                    }
+                });
+            }
+        };
+    }
+
+    public void paint(final Graphics g, final JComponent c) {
+        // this space intentionally left blank
+    }
+
+    protected ListCellRenderer createRenderer() {
+        return new AquaComboBoxRenderer(comboBox);
+    }
+
+    protected ComboPopup createPopup() {
+        return new AquaComboBoxPopup(comboBox);
+    }
+
+    protected JButton createArrowButton() {
+        return new AquaComboBoxButton(this, comboBox, currentValuePane, listBox);
+    }
+
+    protected ComboBoxEditor createEditor() {
+        return new AquaComboBoxEditor();
+    }
+
+    class AquaComboBoxEditor extends BasicComboBoxEditor implements UIResource, DocumentListener {
+        protected AquaComboBoxEditor() {
+            super();
+            editor = new AquaCustomComboTextField();
+            editor.addFocusListener(this);
+            editor.getDocument().addDocumentListener(this);
+        }
+
+        public void focusGained(final FocusEvent e) {
+            arrowButton.repaint();
+        }
+
+        public void focusLost(final FocusEvent e) {
+            arrowButton.repaint();
+        }
+
+        public void changedUpdate(final DocumentEvent e) {
+            editorTextChanged();
+        }
+
+        public void insertUpdate(final DocumentEvent e) {
+            editorTextChanged();
+        }
+
+        public void removeUpdate(final DocumentEvent e) {
+            editorTextChanged();
+        }
+
+        protected void editorTextChanged() {
+            if (!popup.isVisible()) return;
+
+            final Object text = editor.getText();
+
+            final ListModel model = listBox.getModel();
+            final int items = model.getSize();
+            for (int i = 0; i < items; i++) {
+                final Object element = model.getElementAt(i);
+                if (element == null) continue;
+
+                final String asString = element.toString();
+                if (asString == null || !asString.equals(text)) continue;
+
+                popup.getList().setSelectedIndex(i);
+                return;
+            }
+
+            popup.getList().clearSelection();
+        }
+    }
+
+    class AquaCustomComboTextField extends JTextField {
+        public AquaCustomComboTextField() {
+            final InputMap inputMap = getInputMap();
+            inputMap.put(KeyStroke.getKeyStroke("DOWN"), highlightNextAction);
+            inputMap.put(KeyStroke.getKeyStroke("KP_DOWN"), highlightNextAction);
+            inputMap.put(KeyStroke.getKeyStroke("UP"), highlightPreviousAction);
+            inputMap.put(KeyStroke.getKeyStroke("KP_UP"), highlightPreviousAction);
+
+            inputMap.put(KeyStroke.getKeyStroke("HOME"), highlightFirstAction);
+            inputMap.put(KeyStroke.getKeyStroke("END"), highlightLastAction);
+            inputMap.put(KeyStroke.getKeyStroke("PAGE_UP"), highlightPageUpAction);
+            inputMap.put(KeyStroke.getKeyStroke("PAGE_DOWN"), highlightPageDownAction);
+
+            final Action action = getActionMap().get(JTextField.notifyAction);
+            inputMap.put(KeyStroke.getKeyStroke("ENTER"), new AbstractAction() {
+                public void actionPerformed(final ActionEvent e) {
+                    if (popup.isVisible()) {
+                        triggerSelectionEvent(comboBox, e);
+
+                        if (editor instanceof AquaCustomComboTextField) {
+                            ((AquaCustomComboTextField)editor).selectAll();
+                        }
+                    } else {
+                        action.actionPerformed(e);
+                    }
+                }
+            });
+        }
+
+        // workaround for 4530952
+        public void setText(final String s) {
+            if (getText().equals(s)) {
+                return;
+            }
+            super.setText(s);
+        }
+    }
+
+    /**
+     * This listener hides the popup when the focus is lost.  It also repaints
+     * when focus is gained or lost.
+     *
+     * This override is necessary because the Basic L&F for the combo box is working
+     * around a Solaris-only bug that we don't have on Mac OS X.  So, remove the lightweight
+     * popup check here. rdar://Problem/3518582
+     */
+    protected FocusListener createFocusListener() {
+        return new BasicComboBoxUI.FocusHandler() {
+            public void focusLost(final FocusEvent e) {
+                hasFocus = false;
+                if (!e.isTemporary()) {
+                    setPopupVisible(comboBox, false);
+                }
+                comboBox.repaint();
+
+                // Notify assistive technologies that the combo box lost focus
+                final AccessibleContext ac = ((Accessible)comboBox).getAccessibleContext();
+                if (ac != null) {
+                    ac.firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY, AccessibleState.FOCUSED, null);
+                }
+            }
+        };
+    }
+
+    protected void installKeyboardActions() {
+        super.installKeyboardActions();
+
+        final ActionMap actionMap = comboBox.getActionMap();
+        actionMap.put("aquaSelectNext", highlightNextAction);
+        actionMap.put("aquaSelectPrevious", highlightPreviousAction);
+        actionMap.put("aquaEnterPressed", triggerSelectionAction);
+        actionMap.put("aquaSpacePressed", toggleSelectionAction);
+
+        actionMap.put("aquaSelectHome", highlightFirstAction);
+        actionMap.put("aquaSelectEnd", highlightLastAction);
+        actionMap.put("aquaSelectPageUp", highlightPageUpAction);
+        actionMap.put("aquaSelectPageDown", highlightPageDownAction);
+    }
+
+    abstract class ComboBoxAction extends AbstractAction {
+        public void actionPerformed(final ActionEvent e) {
+            if (!comboBox.isEnabled() || !comboBox.isShowing()) return;
+
+            if (comboBox.isPopupVisible()) {
+                final AquaComboBoxUI ui = (AquaComboBoxUI)comboBox.getUI();
+                performComboBoxAction(ui);
+            } else {
+                comboBox.setPopupVisible(true);
+            }
+        }
+
+        abstract void performComboBoxAction(final AquaComboBoxUI ui);
+    }
+
+    /**
+     * Hilight _but do not select_ the next item in the list.
+     */
+    Action highlightNextAction = new ComboBoxAction() {
+        @Override
+        public void performComboBoxAction(AquaComboBoxUI ui) {
+            final int si = listBox.getSelectedIndex();
+
+            if (si < comboBox.getModel().getSize() - 1) {
+                listBox.setSelectedIndex(si + 1);
+                listBox.ensureIndexIsVisible(si + 1);
+            }
+            comboBox.repaint();
+        }
+    };
+
+    /**
+     * Hilight _but do not select_ the previous item in the list.
+     */
+    Action highlightPreviousAction = new ComboBoxAction() {
+        @Override
+        void performComboBoxAction(final AquaComboBoxUI ui) {
+            final int si = listBox.getSelectedIndex();
+            if (si > 0) {
+                listBox.setSelectedIndex(si - 1);
+                listBox.ensureIndexIsVisible(si - 1);
+            }
+            comboBox.repaint();
+        }
+    };
+
+    Action highlightFirstAction = new ComboBoxAction() {
+        @Override
+        void performComboBoxAction(final AquaComboBoxUI ui) {
+            listBox.setSelectedIndex(0);
+            listBox.ensureIndexIsVisible(0);
+        }
+    };
+
+    Action highlightLastAction = new ComboBoxAction() {
+        @Override
+        void performComboBoxAction(final AquaComboBoxUI ui) {
+            final int size = listBox.getModel().getSize();
+            listBox.setSelectedIndex(size - 1);
+            listBox.ensureIndexIsVisible(size - 1);
+        }
+    };
+
+    Action highlightPageUpAction = new ComboBoxAction() {
+        @Override
+        void performComboBoxAction(final AquaComboBoxUI ui) {
+            final int current = listBox.getSelectedIndex();
+            final int first = listBox.getFirstVisibleIndex();
+
+            if (current != first) {
+                listBox.setSelectedIndex(first);
+                return;
+            }
+
+            final int page = listBox.getVisibleRect().height / listBox.getCellBounds(0, 0).height;
+            int target = first - page;
+            if (target < 0) target = 0;
+
+            listBox.ensureIndexIsVisible(target);
+            listBox.setSelectedIndex(target);
+        }
+    };
+
+    Action highlightPageDownAction = new ComboBoxAction() {
+        @Override
+        void performComboBoxAction(final AquaComboBoxUI ui) {
+            final int current = listBox.getSelectedIndex();
+            final int last = listBox.getLastVisibleIndex();
+
+            if (current != last) {
+                listBox.setSelectedIndex(last);
+                return;
+            }
+
+            final int page = listBox.getVisibleRect().height / listBox.getCellBounds(0, 0).height;
+            final int end = listBox.getModel().getSize() - 1;
+            int target = last + page;
+            if (target > end) target = end;
+
+            listBox.ensureIndexIsVisible(target);
+            listBox.setSelectedIndex(target);
+        }
+    };
+
+    // For <rdar://problem/3759984> Java 1.4.2_5: Serializing Swing components not working
+    // Inner classes were using a this reference and then trying to serialize the AquaComboBoxUI
+    // We shouldn't do that. But we need to be able to get the popup from other classes, so we need
+    // a public accessor.
+    public ComboPopup getPopup() {
+        return popup;
+    }
+
+    protected LayoutManager createLayoutManager() {
+        return new AquaComboBoxLayoutManager();
+    }
+
+    class AquaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
+        public void layoutContainer(final Container parent) {
+            if (arrowButton != null && !comboBox.isEditable()) {
+                final Insets insets = comboBox.getInsets();
+                final int width = comboBox.getWidth();
+                final int height = comboBox.getHeight();
+                arrowButton.setBounds(insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom));
+                return;
+            }
+
+            final JComboBox cb = (JComboBox)parent;
+            final int width = cb.getWidth();
+            final int height = cb.getHeight();
+
+            final Insets insets = getInsets();
+            final int buttonHeight = height - (insets.top + insets.bottom);
+            final int buttonWidth = 20;
+
+            if (arrowButton != null) {
+                arrowButton.setBounds(width - (insets.right + buttonWidth), insets.top, buttonWidth, buttonHeight);
+            }
+
+            if (editor != null) {
+                final Rectangle editorRect = rectangleForCurrentValue();
+                editorRect.width += 4;
+                editor.setBounds(editorRect);
+            }
+        }
+    }
+
+    // This is here because Sun can't use protected like they should!
+    protected static final String IS_TABLE_CELL_EDITOR = "JComboBox.isTableCellEditor";
+
+    protected static boolean isTableCellEditor(final JComponent c) {
+        return Boolean.TRUE.equals(c.getClientProperty(AquaComboBoxUI.IS_TABLE_CELL_EDITOR));
+    }
+
+    protected static boolean isPopdown(final JComboBox c) {
+        return c.isEditable() || Boolean.TRUE.equals(c.getClientProperty(AquaComboBoxUI.POPDOWN_CLIENT_PROPERTY_KEY));
+    }
+
+    protected static void triggerSelectionEvent(final JComboBox comboBox, final ActionEvent e) {
+        if (!comboBox.isEnabled()) return;
+
+        final AquaComboBoxUI aquaUi = (AquaComboBoxUI)comboBox.getUI();
+
+        if (aquaUi.getPopup().getList().getSelectedIndex() < 0) {
+            comboBox.setPopupVisible(false);
+        }
+
+        if (isTableCellEditor(comboBox)) {
+            // Forces the selection of the list item if the combo box is in a JTable
+            comboBox.setSelectedIndex(aquaUi.getPopup().getList().getSelectedIndex());
+            return;
+        }
+
+        if (comboBox.isPopupVisible()) {
+            comboBox.setSelectedIndex(aquaUi.getPopup().getList().getSelectedIndex());
+            comboBox.setPopupVisible(false);
+            return;
+        }
+
+        // Call the default button binding.
+        // This is a pretty messy way of passing an event through to the root pane
+        final JRootPane root = SwingUtilities.getRootPane(comboBox);
+        if (root == null) return;
+
+        final InputMap im = root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
+        final ActionMap am = root.getActionMap();
+        if (im == null || am == null) return;
+
+        final Object obj = im.get(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
+        if (obj == null) return;
+
+        final Action action = am.get(obj);
+        if (action == null) return;
+
+        action.actionPerformed(new ActionEvent(root, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()));
+    }
+
+    // This is somewhat messy.  The difference here from BasicComboBoxUI.EnterAction is that
+    // arrow up or down does not automatically select the
+    static final Action triggerSelectionAction = new AbstractAction() {
+        public void actionPerformed(final ActionEvent e) {
+            triggerSelectionEvent((JComboBox)e.getSource(), e);
+        }
+    };
+
+    static final Action toggleSelectionAction = new AbstractAction() {
+        public void actionPerformed(final ActionEvent e) {
+            final JComboBox comboBox = (JComboBox)e.getSource();
+            if (!comboBox.isEnabled()) return;
+            if (comboBox.isEditable()) return;
+
+            final AquaComboBoxUI aquaUi = (AquaComboBoxUI)comboBox.getUI();
+
+            if (comboBox.isPopupVisible()) {
+                comboBox.setSelectedIndex(aquaUi.getPopup().getList().getSelectedIndex());
+                comboBox.setPopupVisible(false);
+                return;
+            }
+
+            comboBox.setPopupVisible(true);
+        }
+    };
+
+    public void applySizeFor(final JComponent c, final Size size) {
+        if (arrowButton == null) return;
+        final Border border = arrowButton.getBorder();
+        if (!(border instanceof AquaButtonBorder)) return;
+        final AquaButtonBorder aquaBorder = (AquaButtonBorder)border;
+        arrowButton.setBorder(aquaBorder.deriveBorderForSize(size));
+    }
+
+    public Dimension getMinimumSize(final JComponent c) {
+        if (!isMinimumSizeDirty) {
+            return new Dimension(cachedMinimumSize);
+        }
+
+        final boolean editable = comboBox.isEditable();
+
+        final Dimension size;
+        if (!editable && arrowButton != null && arrowButton instanceof AquaComboBoxButton) {
+            final AquaComboBoxButton button = (AquaComboBoxButton)arrowButton;
+            final Insets buttonInsets = button.getInsets();
+            //  Insets insets = comboBox.getInsets();
+            final Insets insets = new Insets(0, 5, 0, 25);//comboBox.getInsets();
+
+            size = getDisplaySize();
+            size.width += insets.left + insets.right;
+            size.width += buttonInsets.left + buttonInsets.right;
+            size.width += buttonInsets.right + 10;
+            size.height += insets.top + insets.bottom;
+            size.height += buttonInsets.top + buttonInsets.bottom;
+            // Min height = Height of arrow button plus 2 pixels fuzz above plus 2 below.  23 + 2 + 2
+            size.height = Math.max(27, size.height);
+        } else if (editable && arrowButton != null && editor != null) {
+            size = super.getMinimumSize(c);
+            final Insets margin = arrowButton.getMargin();
+            size.height += margin.top + margin.bottom;
+        } else {
+            size = super.getMinimumSize(c);
+        }
+
+        final Border border = c.getBorder();
+        if (border != null) {
+            final Insets insets = border.getBorderInsets(c);
+            size.height += insets.top + insets.bottom;
+            size.width += insets.left + insets.right;
+        }
+
+        cachedMinimumSize.setSize(size.width, size.height);
+        isMinimumSizeDirty = false;
+
+        return new Dimension(cachedMinimumSize);
+    }
+
+    @SuppressWarnings("unchecked")
+    static final RecyclableSingleton<ClientPropertyApplicator<JComboBox, AquaComboBoxUI>> APPLICATOR = new RecyclableSingleton<ClientPropertyApplicator<JComboBox, AquaComboBoxUI>>() {
+        @Override
+        protected ClientPropertyApplicator<JComboBox, AquaComboBoxUI> getInstance() {
+            return new ClientPropertyApplicator<JComboBox, AquaComboBoxUI>(
+                new Property<AquaComboBoxUI>(AquaFocusHandler.FRAME_ACTIVE_PROPERTY) {
+                    public void applyProperty(final AquaComboBoxUI target, final Object value) {
+                        if (Boolean.FALSE.equals(value)) {
+                            if (target.comboBox != null) target.comboBox.hidePopup();
+                        }
+                        if (target.listBox != null) target.listBox.repaint();
+                    }
+                },
+                new Property<AquaComboBoxUI>("editable") {
+                    public void applyProperty(final AquaComboBoxUI target, final Object value) {
+                        if (target.comboBox == null) return;
+                        target.comboBox.repaint();
+                    }
+                },
+                new Property<AquaComboBoxUI>("background") {
+                    public void applyProperty(final AquaComboBoxUI target, final Object value) {
+                        final Color color = (Color)value;
+                        if (target.arrowButton != null) target.arrowButton.setBackground(color);
+                        if (target.listBox != null) target.listBox.setBackground(color);
+                    }
+                },
+                new Property<AquaComboBoxUI>("foreground") {
+                    public void applyProperty(final AquaComboBoxUI target, final Object value) {
+                        final Color color = (Color)value;
+                        if (target.arrowButton != null) target.arrowButton.setForeground(color);
+                        if (target.listBox != null) target.listBox.setForeground(color);
+                    }
+                },
+                new Property<AquaComboBoxUI>(POPDOWN_CLIENT_PROPERTY_KEY) {
+                    public void applyProperty(final AquaComboBoxUI target, final Object value) {
+                        if (!(target.arrowButton instanceof AquaComboBoxButton)) return;
+                        ((AquaComboBoxButton)target.arrowButton).setIsPopDown(Boolean.TRUE.equals(value));
+                    }
+                },
+                new Property<AquaComboBoxUI>(ISSQUARE_CLIENT_PROPERTY_KEY) {
+                    public void applyProperty(final AquaComboBoxUI target, final Object value) {
+                        if (!(target.arrowButton instanceof AquaComboBoxButton)) return;
+                        ((AquaComboBoxButton)target.arrowButton).setIsSquare(Boolean.TRUE.equals(value));
+                    }
+                }
+            ) {
+                public AquaComboBoxUI convertJComponentToTarget(final JComboBox combo) {
+                    final ComboBoxUI comboUI = combo.getUI();
+                    if (comboUI instanceof AquaComboBoxUI) return (AquaComboBoxUI)comboUI;
+                    return null;
+                }
+            };
+        }
+    };
+    static ClientPropertyApplicator<JComboBox, AquaComboBoxUI> getApplicator() {
+        return APPLICATOR.get();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaEditorPaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaEditorPaneUI.java
new file mode 100644
index 0000000..b1bf7d3
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaEditorPaneUI.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.FocusListener;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicEditorPaneUI;
+import javax.swing.text.*;
+
+public class AquaEditorPaneUI extends BasicEditorPaneUI {
+    public static ComponentUI createUI(final JComponent c){
+        return new AquaEditorPaneUI();
+    }
+
+    boolean oldDragState = false;
+    protected void installDefaults(){
+        super.installDefaults();
+        if(!GraphicsEnvironment.isHeadless()){
+            oldDragState = getComponent().getDragEnabled();
+            getComponent().setDragEnabled(true);
+        }
+    }
+
+    protected void uninstallDefaults(){
+        if(!GraphicsEnvironment.isHeadless()){
+            getComponent().setDragEnabled(oldDragState);
+        }
+        super.uninstallDefaults();
+    }
+
+    FocusListener focusListener;
+    protected void installListeners(){
+        super.installListeners();
+        focusListener = createFocusListener();
+        getComponent().addFocusListener(focusListener);
+    }
+
+    protected void installKeyboardActions() {
+        super.installKeyboardActions();
+        AquaKeyBindings bindings = AquaKeyBindings.instance();
+        bindings.setDefaultAction(getKeymapName());
+        final JTextComponent c = getComponent();
+        bindings.installAquaUpDownActions(c);
+    }
+
+    protected void uninstallListeners(){
+        getComponent().removeFocusListener(focusListener);
+        super.uninstallListeners();
+    }
+
+    protected FocusListener createFocusListener(){
+        return new AquaFocusHandler();
+    }
+
+    protected Caret createCaret(){
+        final Window owningWindow = SwingUtilities.getWindowAncestor(getComponent());
+        final AquaCaret returnValue = new AquaCaret(owningWindow, getComponent());
+        return returnValue;
+    }
+
+    protected Highlighter createHighlighter(){
+        return new AquaHighlighter();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaFileChooserUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaFileChooserUI.java
new file mode 100644
index 0000000..f5dba5b
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaFileChooserUI.java
@@ -0,0 +1,2319 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.io.File;
+import java.net.URI;
+import java.text.DateFormat;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.event.*;
+import javax.swing.filechooser.*;
+import javax.swing.plaf.*;
+import javax.swing.table.*;
+
+import sun.swing.SwingUtilities2;
+
+public class AquaFileChooserUI extends FileChooserUI {
+    /* FileView icons */
+    protected Icon directoryIcon = null;
+    protected Icon fileIcon = null;
+    protected Icon computerIcon = null;
+    protected Icon hardDriveIcon = null;
+    protected Icon floppyDriveIcon = null;
+
+    protected Icon upFolderIcon = null;
+    protected Icon homeFolderIcon = null;
+    protected Icon listViewIcon = null;
+    protected Icon detailsViewIcon = null;
+
+    protected int saveButtonMnemonic = 0;
+    protected int openButtonMnemonic = 0;
+    protected int cancelButtonMnemonic = 0;
+    protected int updateButtonMnemonic = 0;
+    protected int helpButtonMnemonic = 0;
+    protected int chooseButtonMnemonic = 0;
+
+    private String saveTitleText = null;
+    private String openTitleText = null;
+    String newFolderTitleText = null;
+
+    protected String saveButtonText = null;
+    protected String openButtonText = null;
+    protected String cancelButtonText = null;
+    protected String updateButtonText = null;
+    protected String helpButtonText = null;
+    protected String newFolderButtonText = null;
+    protected String chooseButtonText = null;
+
+    //private String newFolderErrorSeparator = null;
+    String newFolderErrorText = null;
+    String newFolderExistsErrorText = null;
+    protected String fileDescriptionText = null;
+    protected String directoryDescriptionText = null;
+
+    protected String saveButtonToolTipText = null;
+    protected String openButtonToolTipText = null;
+    protected String cancelButtonToolTipText = null;
+    protected String updateButtonToolTipText = null;
+    protected String helpButtonToolTipText = null;
+    protected String chooseItemButtonToolTipText = null; // Choose anything
+    protected String chooseFolderButtonToolTipText = null; // Choose folder
+    protected String directoryComboBoxToolTipText = null;
+    protected String filenameTextFieldToolTipText = null;
+    protected String filterComboBoxToolTipText = null;
+    protected String openDirectoryButtonToolTipText = null;
+
+    protected String cancelOpenButtonToolTipText = null;
+    protected String cancelSaveButtonToolTipText = null;
+    protected String cancelChooseButtonToolTipText = null;
+    protected String cancelNewFolderButtonToolTipText = null;
+
+    protected String desktopName = null;
+    String newFolderDialogPrompt = null;
+    String newFolderDefaultName = null;
+    private String newFileDefaultName = null;
+    String createButtonText = null;
+
+    JFileChooser filechooser = null;
+
+    private MouseListener doubleClickListener = null;
+    private PropertyChangeListener propertyChangeListener = null;
+    private AncestorListener ancestorListener = null;
+    private DropTarget dragAndDropTarget = null;
+
+    private final AcceptAllFileFilter acceptAllFileFilter = new AcceptAllFileFilter();
+
+    private AquaFileSystemModel model;
+
+    final AquaFileView fileView = new AquaFileView(this);
+
+    boolean selectionInProgress = false;
+
+    // The accessoryPanel is a container to place the JFileChooser accessory component
+    private JPanel accessoryPanel = null;
+
+    //
+    // ComponentUI Interface Implementation methods
+    //
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaFileChooserUI((JFileChooser)c);
+    }
+
+    public AquaFileChooserUI(final JFileChooser filechooser) {
+        super();
+    }
+
+    public void installUI(final JComponent c) {
+        accessoryPanel = new JPanel(new BorderLayout());
+        filechooser = (JFileChooser)c;
+
+        createModel();
+
+        installDefaults(filechooser);
+        installComponents(filechooser);
+        installListeners(filechooser);
+
+        AquaUtils.enforceComponentOrientation(filechooser, ComponentOrientation.getOrientation(Locale.getDefault()));
+    }
+
+    public void uninstallUI(final JComponent c) {
+        uninstallListeners(filechooser);
+        uninstallComponents(filechooser);
+        uninstallDefaults(filechooser);
+
+        if (accessoryPanel != null) {
+            accessoryPanel.removeAll();
+        }
+
+        accessoryPanel = null;
+        getFileChooser().removeAll();
+    }
+
+    protected void installListeners(final JFileChooser fc) {
+        doubleClickListener = createDoubleClickListener(fc, fFileList);
+        fFileList.addMouseListener(doubleClickListener);
+
+        propertyChangeListener = createPropertyChangeListener(fc);
+        if (propertyChangeListener != null) {
+            fc.addPropertyChangeListener(propertyChangeListener);
+        }
+        if (model != null) fc.addPropertyChangeListener(model);
+
+        ancestorListener = new AncestorListener(){
+            public void ancestorAdded(final AncestorEvent e) {
+                // Request defaultness for the appropriate button based on mode
+                setFocusForMode(getFileChooser());
+                // Request defaultness for the appropriate button based on mode
+                setDefaultButtonForMode(getFileChooser());
+            }
+
+            public void ancestorRemoved(final AncestorEvent e) {
+            }
+
+            public void ancestorMoved(final AncestorEvent e) {
+            }
+        };
+        fc.addAncestorListener(ancestorListener);
+
+        fc.registerKeyboardAction(new CancelSelectionAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+        dragAndDropTarget = new DropTarget(fc, DnDConstants.ACTION_COPY, new DnDHandler(), true);
+        fc.setDropTarget(dragAndDropTarget);
+    }
+
+    protected void uninstallListeners(final JFileChooser fc) {
+        if (propertyChangeListener != null) {
+            fc.removePropertyChangeListener(propertyChangeListener);
+        }
+        fFileList.removeMouseListener(doubleClickListener);
+        fc.removePropertyChangeListener(model);
+        fc.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
+        fc.removeAncestorListener(ancestorListener);
+        fc.setDropTarget(null);
+        ancestorListener = null;
+    }
+
+    protected void installDefaults(final JFileChooser fc) {
+        installIcons(fc);
+        installStrings(fc);
+        setPackageIsTraversable(fc.getClientProperty(PACKAGE_TRAVERSABLE_PROPERTY));
+        setApplicationIsTraversable(fc.getClientProperty(APPLICATION_TRAVERSABLE_PROPERTY));
+    }
+
+    protected void installIcons(final JFileChooser fc) {
+        directoryIcon = UIManager.getIcon("FileView.directoryIcon");
+        fileIcon = UIManager.getIcon("FileView.fileIcon");
+        computerIcon = UIManager.getIcon("FileView.computerIcon");
+        hardDriveIcon = UIManager.getIcon("FileView.hardDriveIcon");
+    }
+
+    String getString(final String uiKey, final String fallback) {
+        final String result = UIManager.getString(uiKey);
+        return (result == null ? fallback : result);
+    }
+
+    protected void installStrings(final JFileChooser fc) {
+        // Exist in basic.properties (though we might want to override)
+        fileDescriptionText = UIManager.getString("FileChooser.fileDescriptionText");
+        directoryDescriptionText = UIManager.getString("FileChooser.directoryDescriptionText");
+        newFolderErrorText = getString("FileChooser.newFolderErrorText", "Error occured during folder creation");
+
+        saveButtonText = UIManager.getString("FileChooser.saveButtonText");
+        openButtonText = UIManager.getString("FileChooser.openButtonText");
+        cancelButtonText = UIManager.getString("FileChooser.cancelButtonText");
+        updateButtonText = UIManager.getString("FileChooser.updateButtonText");
+        helpButtonText = UIManager.getString("FileChooser.helpButtonText");
+
+        saveButtonMnemonic = UIManager.getInt("FileChooser.saveButtonMnemonic");
+        openButtonMnemonic = UIManager.getInt("FileChooser.openButtonMnemonic");
+        cancelButtonMnemonic = UIManager.getInt("FileChooser.cancelButtonMnemonic");
+        updateButtonMnemonic = UIManager.getInt("FileChooser.updateButtonMnemonic");
+        helpButtonMnemonic = UIManager.getInt("FileChooser.helpButtonMnemonic");
+        chooseButtonMnemonic = UIManager.getInt("FileChooser.chooseButtonMnemonic");
+
+        saveButtonToolTipText = UIManager.getString("FileChooser.saveButtonToolTipText");
+        openButtonToolTipText = UIManager.getString("FileChooser.openButtonToolTipText");
+        cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText");
+        updateButtonToolTipText = UIManager.getString("FileChooser.updateButtonToolTipText");
+        helpButtonToolTipText = UIManager.getString("FileChooser.helpButtonToolTipText");
+
+        // Mac-specific, but fallback to basic if it's missing
+        saveTitleText = getString("FileChooser.saveTitleText", saveButtonText);
+        openTitleText = getString("FileChooser.openTitleText", openButtonText);
+
+        // Mac-specific, required
+        newFolderExistsErrorText = getString("FileChooser.newFolderExistsErrorText", "That name is already taken");
+        chooseButtonText = getString("FileChooser.chooseButtonText", "Choose");
+        newFolderButtonText = getString("FileChooser.newFolderButtonText", "New");
+        newFolderTitleText = getString("FileChooser.newFolderTitleText", "New Folder");
+
+        if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
+            fileNameLabelText = getString("FileChooser.saveDialogFileNameLabelText", "Save As:");
+        } else {
+            fileNameLabelText = getString("FileChooser.fileNameLabelText", "Name:");
+        }
+
+        filesOfTypeLabelText = getString("FileChooser.filesOfTypeLabelText", "Format:");
+
+        desktopName = getString("FileChooser.desktopName", "Desktop");
+        newFolderDialogPrompt = getString("FileChooser.newFolderPromptText", "Name of new folder:");
+        newFolderDefaultName = getString("FileChooser.untitledFolderName", "untitled folder");
+        newFileDefaultName = getString("FileChooser.untitledFileName", "untitled");
+        createButtonText = getString("FileChooser.createButtonText", "Create");
+
+        fColumnNames[1] = getString("FileChooser.byDateText", "Date Modified");
+        fColumnNames[0] = getString("FileChooser.byNameText", "Name");
+
+        // Mac-specific, optional
+        chooseItemButtonToolTipText = UIManager.getString("FileChooser.chooseItemButtonToolTipText");
+        chooseFolderButtonToolTipText = UIManager.getString("FileChooser.chooseFolderButtonToolTipText");
+        openDirectoryButtonToolTipText = UIManager.getString("FileChooser.openDirectoryButtonToolTipText");
+
+        directoryComboBoxToolTipText = UIManager.getString("FileChooser.directoryComboBoxToolTipText");
+        filenameTextFieldToolTipText = UIManager.getString("FileChooser.filenameTextFieldToolTipText");
+        filterComboBoxToolTipText = UIManager.getString("FileChooser.filterComboBoxToolTipText");
+
+        cancelOpenButtonToolTipText = UIManager.getString("FileChooser.cancelOpenButtonToolTipText");
+        cancelSaveButtonToolTipText = UIManager.getString("FileChooser.cancelSaveButtonToolTipText");
+        cancelChooseButtonToolTipText = UIManager.getString("FileChooser.cancelChooseButtonToolTipText");
+        cancelNewFolderButtonToolTipText = UIManager.getString("FileChooser.cancelNewFolderButtonToolTipText");
+
+        newFolderTitleText = UIManager.getString("FileChooser.newFolderTitleText");
+        newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText");
+        newFolderAccessibleName = getString("FileChooser.newFolderAccessibleName", newFolderTitleText);
+    }
+
+    protected void uninstallDefaults(final JFileChooser fc) {
+        uninstallIcons(fc);
+        uninstallStrings(fc);
+    }
+
+    protected void uninstallIcons(final JFileChooser fc) {
+        directoryIcon = null;
+        fileIcon = null;
+        computerIcon = null;
+        hardDriveIcon = null;
+        floppyDriveIcon = null;
+
+        upFolderIcon = null;
+        homeFolderIcon = null;
+        detailsViewIcon = null;
+        listViewIcon = null;
+    }
+
+    protected void uninstallStrings(final JFileChooser fc) {
+        saveTitleText = null;
+        openTitleText = null;
+        newFolderTitleText = null;
+
+        saveButtonText = null;
+        openButtonText = null;
+        cancelButtonText = null;
+        updateButtonText = null;
+        helpButtonText = null;
+        newFolderButtonText = null;
+        chooseButtonText = null;
+
+        cancelOpenButtonToolTipText = null;
+        cancelSaveButtonToolTipText = null;
+        cancelChooseButtonToolTipText = null;
+        cancelNewFolderButtonToolTipText = null;
+
+        saveButtonToolTipText = null;
+        openButtonToolTipText = null;
+        cancelButtonToolTipText = null;
+        updateButtonToolTipText = null;
+        helpButtonToolTipText = null;
+        chooseItemButtonToolTipText = null;
+        chooseFolderButtonToolTipText = null;
+        openDirectoryButtonToolTipText = null;
+        directoryComboBoxToolTipText = null;
+        filenameTextFieldToolTipText = null;
+        filterComboBoxToolTipText = null;
+
+        newFolderDefaultName = null;
+        newFileDefaultName = null;
+
+        desktopName = null;
+    }
+
+    protected void createModel() {
+    }
+
+    AquaFileSystemModel getModel() {
+        return model;
+    }
+
+    /*
+     * Listen for filechooser property changes, such as
+     * the selected file changing, or the type of the dialog changing.
+     */
+    // Taken almost verbatim from Metal
+    protected PropertyChangeListener createPropertyChangeListener(final JFileChooser fc) {
+        return new PropertyChangeListener(){
+            public void propertyChange(final PropertyChangeEvent e) {
+                final String prop = e.getPropertyName();
+                if (prop.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
+                    final File f = (File)e.getNewValue();
+                    if (f != null) {
+                        // Select the file in the list if the selected file didn't change as
+                        // a result of a list click.
+                        if (!selectionInProgress && getModel().contains(f)) {
+                            fFileList.setSelectedIndex(getModel().indexOf(f));
+                        }
+
+                        // [3643835] Need to populate the text field here.  No-op on Open dialogs
+                        // Note that this was removed for 3514735, but should not have been.
+                        if (!f.isDirectory()) {
+                            setFileName(getFileChooser().getName(f));
+                        }
+                    }
+                    updateButtonState(getFileChooser());
+                } else if (prop.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
+                    fFileList.clearSelection();
+                    final File currentDirectory = getFileChooser().getCurrentDirectory();
+                    if (currentDirectory != null) {
+                        fDirectoryComboBoxModel.addItem(currentDirectory);
+                        // Enable the newFolder action if the current directory
+                        // is writable.
+                        // PENDING(jeff) - broken - fix
+                        getAction(kNewFolder).setEnabled(currentDirectory.canWrite());
+                    }
+                    updateButtonState(getFileChooser());
+                } else if (prop.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
+                    fFileList.clearSelection();
+                    setBottomPanelForMode(getFileChooser()); // Also updates approve button
+                } else if (prop == JFileChooser.ACCESSORY_CHANGED_PROPERTY) {
+                    if (getAccessoryPanel() != null) {
+                        if (e.getOldValue() != null) {
+                            getAccessoryPanel().remove((JComponent)e.getOldValue());
+                        }
+                        final JComponent accessory = (JComponent)e.getNewValue();
+                        if (accessory != null) {
+                            getAccessoryPanel().add(accessory, BorderLayout.CENTER);
+                        }
+                    }
+                } else if (prop == JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) {
+                    updateApproveButton(getFileChooser());
+                    getFileChooser().invalidate();
+                } else if (prop == JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY) {
+                    if (getFileChooser().getDialogType() == JFileChooser.SAVE_DIALOG) {
+                        fileNameLabelText = getString("FileChooser.saveDialogFileNameLabelText", "Save As:");
+                    } else {
+                        fileNameLabelText = getString("FileChooser.fileNameLabelText", "Name:");
+                    }
+                    fTextFieldLabel.setText(fileNameLabelText);
+
+                    // Mac doesn't show the text field or "new folder" button in 'Open' dialogs
+                    setBottomPanelForMode(getFileChooser()); // Also updates approve button
+                } else if (prop.equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) {
+                    getApproveButton(getFileChooser()).setMnemonic(getApproveButtonMnemonic(getFileChooser()));
+                } else if (prop.equals(PACKAGE_TRAVERSABLE_PROPERTY)) {
+                    setPackageIsTraversable(e.getNewValue());
+                } else if (prop.equals(APPLICATION_TRAVERSABLE_PROPERTY)) {
+                    setApplicationIsTraversable(e.getNewValue());
+                } else if (prop.equals(JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY)) {
+                    if (getFileChooser().isMultiSelectionEnabled()) {
+                        fFileList.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+                    } else {
+                        fFileList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+                    }
+                } else if (prop.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) {
+                    doControlButtonsChanged(e);
+                }
+            }
+        };
+    }
+
+    void setPackageIsTraversable(final Object o) {
+        int newProp = -1;
+        if (o != null && o instanceof String) newProp = parseTraversableProperty((String)o);
+        if (newProp != -1) fPackageIsTraversable = newProp;
+        else fPackageIsTraversable = sGlobalPackageIsTraversable;
+    }
+
+    void setApplicationIsTraversable(final Object o) {
+        int newProp = -1;
+        if (o != null && o instanceof String) newProp = parseTraversableProperty((String)o);
+        if (newProp != -1) fApplicationIsTraversable = newProp;
+        else fApplicationIsTraversable = sGlobalApplicationIsTraversable;
+    }
+
+    void doControlButtonsChanged(final PropertyChangeEvent e) {
+        if (getFileChooser().getControlButtonsAreShown()) {
+            fBottomPanel.add(fDirectoryPanelSpacer);
+            fBottomPanel.add(fDirectoryPanel);
+        } else {
+            fBottomPanel.remove(fDirectoryPanelSpacer);
+            fBottomPanel.remove(fDirectoryPanel);
+        }
+    }
+
+    public String getFileName() {
+        if (filenameTextField != null) { return filenameTextField.getText(); }
+        return null;
+    }
+
+    public String getDirectoryName() {
+        // PENDING(jeff) - get the name from the directory combobox
+        return null;
+    }
+
+    public void setFileName(final String filename) {
+        if (filenameTextField != null) {
+            filenameTextField.setText(filename);
+        }
+    }
+
+    public void setDirectoryName(final String dirname) {
+        // PENDING(jeff) - set the name in the directory combobox
+    }
+
+    public void rescanCurrentDirectory(final JFileChooser fc) {
+        getModel().invalidateFileCache();
+        getModel().validateFileCache();
+    }
+
+    public void ensureFileIsVisible(final JFileChooser fc, final File f) {
+        if (f == null) {
+            fFileList.requestFocusInWindow();
+            fFileList.ensureIndexIsVisible(-1);
+            return;
+        }
+
+        getModel().runWhenDone(new Runnable() {
+            public void run() {
+                fFileList.requestFocusInWindow();
+                fFileList.ensureIndexIsVisible(getModel().indexOf(f));
+            }
+        });
+    }
+
+    public JFileChooser getFileChooser() {
+        return filechooser;
+    }
+
+    public JPanel getAccessoryPanel() {
+        return accessoryPanel;
+    }
+
+    protected JButton getApproveButton(final JFileChooser fc) {
+        return fApproveButton;
+    }
+
+    public int getApproveButtonMnemonic(final JFileChooser fc) {
+        return fSubPanel.getApproveButtonMnemonic(fc);
+    }
+
+    public String getApproveButtonToolTipText(final JFileChooser fc) {
+        return fSubPanel.getApproveButtonToolTipText(fc);
+    }
+
+    public String getApproveButtonText(final JFileChooser fc) {
+        return fSubPanel.getApproveButtonText(fc);
+    }
+
+    protected String getCancelButtonToolTipText(final JFileChooser fc) {
+        return fSubPanel.getCancelButtonToolTipText(fc);
+    }
+
+    // If the item's not selectable, it'll be visible but disabled in the list
+    boolean isSelectableInList(final File f) {
+        return fSubPanel.isSelectableInList(getFileChooser(), f);
+    }
+
+    // Is this a file that the JFileChooser wants?
+    // Directories can be selected in the list regardless of mode
+    boolean isSelectableForMode(final JFileChooser fc, final File f) {
+        if (f == null) return false;
+        final int mode = fc.getFileSelectionMode();
+        if (mode == JFileChooser.FILES_AND_DIRECTORIES) return true;
+        boolean traversable = fc.isTraversable(f);
+        if (mode == JFileChooser.DIRECTORIES_ONLY) return traversable;
+        return !traversable;
+    }
+
+    // ********************************************
+    // ************ Create Listeners **************
+    // ********************************************
+
+    // From Basic
+    public ListSelectionListener createListSelectionListener(final JFileChooser fc) {
+        return new SelectionListener();
+    }
+
+    protected class SelectionListener implements ListSelectionListener {
+        public void valueChanged(final ListSelectionEvent e) {
+            if (e.getValueIsAdjusting()) return;
+
+            File f = null;
+            final int selectedRow = fFileList.getSelectedRow();
+            final JFileChooser chooser = getFileChooser();
+            boolean isSave = (chooser.getDialogType() == JFileChooser.SAVE_DIALOG);
+            if (selectedRow >= 0) {
+                f = (File)fFileList.getValueAt(selectedRow, 0);
+            }
+
+            // Save dialog lists can't be multi select, because all we're selecting is the next folder to open
+            selectionInProgress = true;
+            if (!isSave && chooser.isMultiSelectionEnabled()) {
+                final int[] rows = fFileList.getSelectedRows();
+                int selectableCount = 0;
+                // Double-check that all the list selections are valid for this mode
+                // Directories can be selected in the list regardless of mode
+                if (rows.length > 0) {
+                    for (final int element : rows) {
+                        if (isSelectableForMode(chooser, (File)fFileList.getValueAt(element, 0))) selectableCount++;
+                    }
+                }
+                if (selectableCount > 0) {
+                    final File[] files = new File[selectableCount];
+                    for (int i = 0, si = 0; i < rows.length; i++) {
+                        f = (File)fFileList.getValueAt(rows[i], 0);
+                        if (isSelectableForMode(chooser, f)) {
+                            if (fileView.isAlias(f)) {
+                                f = fileView.resolveAlias(f);
+                            }
+                            files[si++] = f;
+                        }
+                    }
+                    chooser.setSelectedFiles(files);
+                } else {
+                    chooser.setSelectedFiles(null);
+                }
+            } else {
+                chooser.setSelectedFiles(null);
+                chooser.setSelectedFile(f);
+            }
+            selectionInProgress = false;
+        }
+    }
+
+    // When the Save textfield has the focus, the button should say "Save"
+    // Otherwise, it depends on the list selection
+    protected class SaveTextFocusListener implements FocusListener {
+        public void focusGained(final FocusEvent e) {
+            updateButtonState(getFileChooser());
+        }
+
+        // Do nothing, we might be losing focus due to window deactivation
+        public void focusLost(final FocusEvent e) {
+
+        }
+    }
+
+    // When the Save textfield is empty and the button says "Save", it should be disabled
+    // Otherwise, it depends on the list selection
+    protected class SaveTextDocumentListener implements DocumentListener {
+        public void insertUpdate(final DocumentEvent e) {
+            textChanged();
+        }
+
+        public void removeUpdate(final DocumentEvent e) {
+            textChanged();
+        }
+
+        public void changedUpdate(final DocumentEvent e) {
+
+        }
+
+        void textChanged() {
+            updateButtonState(getFileChooser());
+        }
+    }
+
+    // Opens the File object if it's a traversable directory
+    protected boolean openDirectory(final File f) {
+        if (getFileChooser().isTraversable(f)) {
+            fFileList.clearSelection();
+            // Resolve any aliases
+            final File original = fileView.resolveAlias(f);
+            getFileChooser().setCurrentDirectory(original);
+            updateButtonState(getFileChooser());
+            return true;
+        }
+        return false;
+    }
+
+    // From Basic
+    protected class DoubleClickListener extends MouseAdapter {
+        JTableExtension list;
+
+        public DoubleClickListener(final JTableExtension list) {
+            this.list = list;
+        }
+
+        public void mouseClicked(final MouseEvent e) {
+            if (e.getClickCount() != 2) return;
+
+            final int index = list.locationToIndex(e.getPoint());
+            if (index < 0) return;
+
+            final File f = (File)((AquaFileSystemModel)list.getModel()).getElementAt(index);
+            if (openDirectory(f)) return;
+
+            if (!isSelectableInList(f)) return;
+            getFileChooser().approveSelection();
+        }
+    }
+
+    protected MouseListener createDoubleClickListener(final JFileChooser fc, final JTableExtension list) {
+        return new DoubleClickListener(list);
+    }
+
+    // listens for drag events onto the JFileChooser and sets the selected file or directory
+    class DnDHandler extends DropTargetAdapter {
+        public void dragEnter(final DropTargetDragEvent dtde) {
+            tryToAcceptDrag(dtde);
+        }
+
+        public void dragOver(final DropTargetDragEvent dtde) {
+            tryToAcceptDrag(dtde);
+        }
+
+        public void dropActionChanged(final DropTargetDragEvent dtde) {
+            tryToAcceptDrag(dtde);
+        }
+
+        public void drop(final DropTargetDropEvent dtde) {
+            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
+                handleFileDropEvent(dtde);
+                return;
+            }
+
+            if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+                handleStringDropEvent(dtde);
+                return;
+            }
+        }
+
+        protected void tryToAcceptDrag(final DropTargetDragEvent dtde) {
+            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+                dtde.acceptDrag(DnDConstants.ACTION_COPY);
+                return;
+            }
+
+            dtde.rejectDrag();
+        }
+
+        protected void handleFileDropEvent(final DropTargetDropEvent dtde) {
+            dtde.acceptDrop(dtde.getDropAction());
+            final Transferable transferable = dtde.getTransferable();
+
+            try {
+                final java.util.List<File> fileList = (java.util.List<File>)transferable.getTransferData(DataFlavor.javaFileListFlavor);
+                dropFiles(fileList.toArray(new File[fileList.size()]));
+                dtde.dropComplete(true);
+            } catch (final Exception e) {
+                dtde.dropComplete(false);
+            }
+        }
+
+        protected void handleStringDropEvent(final DropTargetDropEvent dtde) {
+            dtde.acceptDrop(dtde.getDropAction());
+            final Transferable transferable = dtde.getTransferable();
+
+            final String stringData;
+            try {
+                stringData = (String)transferable.getTransferData(DataFlavor.stringFlavor);
+            } catch (final Exception e) {
+                dtde.dropComplete(false);
+                return;
+            }
+
+            try {
+                final File fileAsPath = new File(stringData);
+                if (fileAsPath.exists()) {
+                    dropFiles(new File[] {fileAsPath});
+                    dtde.dropComplete(true);
+                    return;
+                }
+            } catch (final Exception e) {
+                // try again
+            }
+
+            try {
+                final File fileAsURI = new File(new URI(stringData));
+                if (fileAsURI.exists()) {
+                    dropFiles(new File[] {fileAsURI});
+                    dtde.dropComplete(true);
+                    return;
+                }
+            } catch (final Exception e) {
+                // nothing more to do
+            }
+
+            dtde.dropComplete(false);
+        }
+
+        protected void dropFiles(final File[] files) {
+            final JFileChooser jfc = getFileChooser();
+
+            if (files.length == 1) {
+                if (files[0].isDirectory()) {
+                    jfc.setCurrentDirectory(files[0]);
+                    return;
+                }
+
+                if (!isSelectableForMode(jfc, files[0])) {
+                    return;
+                }
+            }
+
+            jfc.setSelectedFiles(files);
+            for (final File file : files) {
+                jfc.ensureFileIsVisible(file);
+            }
+            getModel().runWhenDone(new Runnable() {
+                public void run() {
+                    final AquaFileSystemModel fileSystemModel = getModel();
+                    for (final File element : files) {
+                        final int index = fileSystemModel.indexOf(element);
+                        if (index >= 0) fFileList.addRowSelectionInterval(index, index);
+                    }
+                }
+            });
+        }
+    }
+
+    // FileChooser UI PLAF methods
+
+    /**
+     * Returns the default accept all file filter
+     */
+    public FileFilter getAcceptAllFileFilter(final JFileChooser fc) {
+        return acceptAllFileFilter;
+    }
+
+    public FileView getFileView(final JFileChooser fc) {
+        return fileView;
+    }
+
+    /**
+     * Returns the title of this dialog
+     */
+    public String getDialogTitle(final JFileChooser fc) {
+        if (fc.getDialogTitle() == null) {
+            if (getFileChooser().getDialogType() == JFileChooser.OPEN_DIALOG) {
+                return openTitleText;
+            } else if (getFileChooser().getDialogType() == JFileChooser.SAVE_DIALOG) { return saveTitleText; }
+        }
+        return fc.getDialogTitle();
+    }
+
+    // Utility to get the first selected item regardless of whether we're single or multi select
+    File getFirstSelectedItem() {
+        // Get the selected item
+        File selectedFile = null;
+        final int index = fFileList.getSelectedRow();
+        if (index >= 0) {
+            selectedFile = (File)((AquaFileSystemModel)fFileList.getModel()).getElementAt(index);
+        }
+        return selectedFile;
+    }
+
+    // Make a file from the filename
+    File makeFile(final JFileChooser fc, final String filename) {
+        File selectedFile = null;
+        // whitespace is legal on Macs, even on beginning and end of filename
+        if (filename != null && !filename.equals("")) {
+            final FileSystemView fs = fc.getFileSystemView();
+            selectedFile = fs.createFileObject(filename);
+            if (!selectedFile.isAbsolute()) {
+                selectedFile = fs.createFileObject(fc.getCurrentDirectory(), filename);
+            }
+        }
+        return selectedFile;
+    }
+
+    // Utility to tell if the textfield has anything in it
+    boolean textfieldIsValid() {
+        final String s = getFileName();
+        return (s != null && !s.equals(""));
+    }
+
+    // Action to attach to the file list so we can override the default action
+    // of the table for the return key, which is to select the next line.
+    protected class DefaultButtonAction extends AbstractAction {
+        public void actionPerformed(final ActionEvent e) {
+            final JRootPane root = AquaFileChooserUI.this.getFileChooser().getRootPane();
+            final JFileChooser fc = AquaFileChooserUI.this.getFileChooser();
+            final JButton owner = root.getDefaultButton();
+            if (owner != null && SwingUtilities.getRootPane(owner) == root && owner.isEnabled()) {
+                owner.doClick(20);
+            } else if (!fc.getControlButtonsAreShown()) {
+                final JButton defaultButton = AquaFileChooserUI.this.fSubPanel.getDefaultButton(fc);
+
+                if (defaultButton != null) {
+                    defaultButton.doClick(20);
+                }
+            } else {
+                Toolkit.getDefaultToolkit().beep();
+            }
+        }
+
+        public boolean isEnabled() {
+            return true;
+        }
+    }
+
+    /**
+     * Creates a new folder.
+     */
+    protected class NewFolderAction extends AbstractAction {
+        protected NewFolderAction() {
+            super(newFolderAccessibleName);
+        }
+
+        // Muchlike showInputDialog, but we give it options instead of selectionValues
+        private Object showNewFolderDialog(final Component parentComponent, final Object message, final String title, final int messageType, final Icon icon, final Object[] options, final Object initialSelectionValue) {
+            final JOptionPane pane = new JOptionPane(message, messageType, JOptionPane.OK_CANCEL_OPTION, icon, options, null);
+
+            pane.setWantsInput(true);
+            pane.setInitialSelectionValue(initialSelectionValue);
+
+            final JDialog dialog = pane.createDialog(parentComponent, title);
+
+            pane.selectInitialValue();
+            dialog.setVisible(true);
+            dialog.dispose();
+
+            final Object value = pane.getValue();
+
+            if (value == null || value.equals(cancelButtonText)) {
+                return null;
+            }
+            return pane.getInputValue();
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            final JFileChooser fc = getFileChooser();
+            final File currentDirectory = fc.getCurrentDirectory();
+            File newFolder = null;
+            final String[] options = {createButtonText, cancelButtonText};
+            final String filename = (String)showNewFolderDialog(fc, //parentComponent
+                    newFolderDialogPrompt, // message
+                    newFolderTitleText, // title
+                    JOptionPane.PLAIN_MESSAGE, // messageType
+                    null, // icon
+                    options, // selectionValues
+                    newFolderDefaultName); // initialSelectionValue
+
+            if (filename != null) {
+                try {
+                    newFolder = fc.getFileSystemView().createFileObject(currentDirectory, filename);
+                    if (newFolder.exists()) {
+                        JOptionPane.showMessageDialog(fc, newFolderExistsErrorText, "", JOptionPane.ERROR_MESSAGE);
+                        return;
+                    }
+
+                    newFolder.mkdirs();
+                } catch(final Exception exc) {
+                    JOptionPane.showMessageDialog(fc, newFolderErrorText, "", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+
+                openDirectory(newFolder);
+            }
+        }
+    }
+
+    /**
+     * Responds to an Open, Save, or Choose request
+     */
+    protected class ApproveSelectionAction extends AbstractAction {
+        public void actionPerformed(final ActionEvent e) {
+            fSubPanel.approveSelection(getFileChooser());
+        }
+    }
+
+    /**
+     * Responds to an OpenDirectory request
+     */
+    protected class OpenSelectionAction extends AbstractAction {
+        public void actionPerformed(final ActionEvent e) {
+            final int index = fFileList.getSelectedRow();
+            if (index >= 0) {
+                final File selectedFile = (File)((AquaFileSystemModel)fFileList.getModel()).getElementAt(index);
+                if (selectedFile != null) openDirectory(selectedFile);
+            }
+        }
+    }
+
+    /**
+     * Responds to a cancel request.
+     */
+    protected class CancelSelectionAction extends AbstractAction {
+        public void actionPerformed(final ActionEvent e) {
+            getFileChooser().cancelSelection();
+        }
+
+        public boolean isEnabled() {
+            return getFileChooser().isEnabled();
+        }
+    }
+
+    /**
+     * Rescans the files in the current directory
+     */
+    protected class UpdateAction extends AbstractAction {
+        public void actionPerformed(final ActionEvent e) {
+            final JFileChooser fc = getFileChooser();
+            fc.setCurrentDirectory(fc.getFileSystemView().createFileObject(getDirectoryName()));
+            fc.rescanCurrentDirectory();
+        }
+    }
+
+    // *****************************************
+    // ***** default AcceptAll file filter *****
+    // *****************************************
+    protected class AcceptAllFileFilter extends FileFilter {
+        public AcceptAllFileFilter() {
+        }
+
+        public boolean accept(final File f) {
+            return true;
+        }
+
+        public String getDescription() {
+            return UIManager.getString("FileChooser.acceptAllFileFilterText");
+        }
+    }
+
+    // Penultimate superclass is JLabel
+    protected class MacFCTableCellRenderer extends DefaultTableCellRenderer {
+        boolean fIsSelected = false;
+
+        public MacFCTableCellRenderer(final Font f) {
+            super();
+            setFont(f);
+            setIconTextGap(10);
+        }
+
+        public Component getTableCellRendererComponent(final JTable list, final Object value, final boolean isSelected, final boolean cellHasFocus, final int index, final int col) {
+            super.getTableCellRendererComponent(list, value, isSelected, false, index, col); // No focus border, thanks
+            fIsSelected = isSelected;
+            return this;
+        }
+
+        public boolean isSelected() {
+            return fIsSelected && isEnabled();
+        }
+
+        protected String layoutCL(final JLabel label, final FontMetrics fontMetrics, final String text, final Icon icon, final Rectangle viewR, final Rectangle iconR, final Rectangle textR) {
+            return SwingUtilities.layoutCompoundLabel(label, fontMetrics, text, icon, label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(), viewR, iconR, textR, label.getIconTextGap());
+        }
+
+        protected void paintComponent(final Graphics g) {
+            final String text = getText();
+            Icon icon = getIcon();
+            if (icon != null && !isEnabled()) {
+                final Icon disabledIcon = getDisabledIcon();
+                if (disabledIcon != null) icon = disabledIcon;
+            }
+
+            if ((icon == null) && (text == null)) { return; }
+
+            // from ComponentUI update
+            g.setColor(getBackground());
+            g.fillRect(0, 0, getWidth(), getHeight());
+
+            // from BasicLabelUI paint
+            final FontMetrics fm = g.getFontMetrics();
+            Insets paintViewInsets = getInsets(null);
+            paintViewInsets.left += 10;
+
+            Rectangle paintViewR = new Rectangle(paintViewInsets.left, paintViewInsets.top, getWidth() - (paintViewInsets.left + paintViewInsets.right), getHeight() - (paintViewInsets.top + paintViewInsets.bottom));
+
+            Rectangle paintIconR = new Rectangle();
+            Rectangle paintTextR = new Rectangle();
+
+            final String clippedText = layoutCL(this, fm, text, icon, paintViewR, paintIconR, paintTextR);
+
+            if (icon != null) {
+                icon.paintIcon(this, g, paintIconR.x + 5, paintIconR.y);
+            }
+
+            if (text != null) {
+                final int textX = paintTextR.x;
+                final int textY = paintTextR.y + fm.getAscent() + 1;
+                if (isEnabled()) {
+                    // Color background = fIsSelected ? getForeground() : getBackground();
+                    final Color background = getBackground();
+
+                    g.setColor(background);
+                    g.fillRect(textX - 1, paintTextR.y, paintTextR.width + 2, fm.getAscent() + 2);
+
+                    g.setColor(getForeground());
+                    SwingUtilities2.drawString(filechooser, g, clippedText, textX, textY);
+                } else {
+                    final Color background = getBackground();
+                    g.setColor(background);
+                    g.fillRect(textX - 1, paintTextR.y, paintTextR.width + 2, fm.getAscent() + 2);
+
+                    g.setColor(background.brighter());
+                    SwingUtilities2.drawString(filechooser, g, clippedText, textX, textY);
+                    g.setColor(background.darker());
+                    SwingUtilities2.drawString(filechooser, g, clippedText, textX + 1, textY + 1);
+                }
+            }
+        }
+
+    }
+
+    protected class FileRenderer extends MacFCTableCellRenderer {
+        public FileRenderer(final Font f) {
+            super(f);
+        }
+
+        public Component getTableCellRendererComponent(final JTable list, final Object value, final boolean isSelected, final boolean cellHasFocus, final int index, final int col) {
+            super.getTableCellRendererComponent(list, value, isSelected, false, index, col); // No focus border, thanks
+            final File file = (File)value;
+            final JFileChooser fc = getFileChooser();
+            setText(fc.getName(file));
+            setIcon(fc.getIcon(file));
+            setEnabled(isSelectableInList(file));
+            return this;
+        }
+    }
+
+    protected class DateRenderer extends MacFCTableCellRenderer {
+        public DateRenderer(final Font f) {
+            super(f);
+        }
+
+        public Component getTableCellRendererComponent(final JTable list, final Object value, final boolean isSelected, final boolean cellHasFocus, final int index, final int col) {
+            super.getTableCellRendererComponent(list, value, isSelected, false, index, col);
+            final File file = (File)fFileList.getValueAt(index, 0);
+            setEnabled(isSelectableInList(file));
+            final DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT);
+            final Date date = (Date)value;
+
+            if (date != null) {
+                setText(formatter.format(date));
+            } else {
+                setText("");
+            }
+
+            return this;
+        }
+    }
+
+    public Dimension getPreferredSize(final JComponent c) {
+        return PREF_SIZE;
+    }
+
+    public Dimension getMinimumSize(final JComponent c) {
+        return MIN_SIZE;
+    }
+
+    public Dimension getMaximumSize(final JComponent c) {
+        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
+    }
+
+    protected ListCellRenderer createDirectoryComboBoxRenderer(final JFileChooser fc) {
+        return new AquaComboBoxRendererInternal(directoryComboBox) {
+            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
+                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+                final File directory = (File)value;
+                if (directory == null) {
+                    setText("");
+                    return this;
+                }
+
+                final JFileChooser chooser = getFileChooser();
+                setText(chooser.getName(directory));
+                setIcon(chooser.getIcon(directory));
+                return this;
+            }
+        };
+    }
+
+    //
+    // DataModel for DirectoryComboxbox
+    //
+    protected DirectoryComboBoxModel createDirectoryComboBoxModel(final JFileChooser fc) {
+        return new DirectoryComboBoxModel();
+    }
+
+    /**
+     * Data model for a type-face selection combo-box.
+     */
+    protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
+        Vector<File> fDirectories = new Vector<File>();
+        int topIndex = -1;
+        int fPathCount = 0;
+
+        File fSelectedDirectory = null;
+
+        public DirectoryComboBoxModel() {
+            super();
+            // Add the current directory to the model, and make it the
+            // selectedDirectory
+            addItem(getFileChooser().getCurrentDirectory());
+        }
+
+        /**
+         * Removes the selected directory, and clears out the
+         * path file entries leading up to that directory.
+         */
+        private void removeSelectedDirectory() {
+            fDirectories.removeAllElements();
+            fPathCount = 0;
+            fSelectedDirectory = null;
+            // dump();
+        }
+
+        /**
+         * Adds the directory to the model and sets it to be selected,
+         * additionally clears out the previous selected directory and
+         * the paths leading up to it, if any.
+         */
+        void addItem(final File directory) {
+            if (directory == null) { return; }
+            if (fSelectedDirectory != null) {
+                removeSelectedDirectory();
+            }
+
+            // create File instances of each directory leading up to the top
+            File f = directory.getAbsoluteFile();
+            final Vector<File> path = new Vector<File>(10);
+            while (f.getParent() != null) {
+                path.addElement(f);
+                f = getFileChooser().getFileSystemView().createFileObject(f.getParent());
+            };
+
+            // Add root file (the desktop) to the model
+            final File[] roots = getFileChooser().getFileSystemView().getRoots();
+            for (final File element : roots) {
+                path.addElement(element);
+            }
+            fPathCount = path.size();
+
+            // insert all the path fDirectories leading up to the
+            // selected directory in reverse order (current directory at top)
+            for (int i = 0; i < path.size(); i++) {
+                fDirectories.addElement(path.elementAt(i));
+            }
+
+            setSelectedItem(fDirectories.elementAt(0));
+
+            // dump();
+        }
+
+        public void setSelectedItem(final Object selectedDirectory) {
+            this.fSelectedDirectory = (File)selectedDirectory;
+            fireContentsChanged(this, -1, -1);
+        }
+
+        public Object getSelectedItem() {
+            return fSelectedDirectory;
+        }
+
+        public int getSize() {
+            return fDirectories.size();
+        }
+
+        public Object getElementAt(final int index) {
+            return fDirectories.elementAt(index);
+        }
+    }
+
+    //
+    // Renderer for Types ComboBox
+    //
+    protected ListCellRenderer createFilterComboBoxRenderer() {
+        return new AquaComboBoxRendererInternal(filterComboBox) {
+            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
+                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+                final FileFilter filter = (FileFilter)value;
+                if (filter != null) setText(filter.getDescription());
+                return this;
+            }
+        };
+    }
+
+    //
+    // DataModel for Types Comboxbox
+    //
+    protected FilterComboBoxModel createFilterComboBoxModel() {
+        return new FilterComboBoxModel();
+    }
+
+    /**
+     * Data model for a type-face selection combo-box.
+     */
+    protected class FilterComboBoxModel extends DefaultListModel implements ComboBoxModel, PropertyChangeListener {
+        int selectedIndex = -1;
+
+        protected FilterComboBoxModel() {
+            super();
+            final FileFilter filters[] = getFileChooser().getChoosableFileFilters();
+            for (int i = 0; i < filters.length; i++) {
+                this.add(i, filters[i]);
+            }
+        }
+
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String prop = e.getPropertyName();
+            if (prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
+                this.clear();
+                final FileFilter filters[] = (FileFilter[])e.getNewValue();
+
+                for (int i = 0; i < filters.length; i++) {
+                    this.add(i, filters[i]);
+                }
+
+                fireContentsChanged(this, -1, -1);
+            } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
+                final FileFilter currentFilter = (FileFilter)e.getNewValue();
+                FileFilter filters[] = getFileChooser().getChoosableFileFilters();
+
+                boolean found = false;
+                if (currentFilter != null) {
+                    for (final FileFilter element : filters) {
+                        if (element == currentFilter) {
+                            found = true;
+                        }
+                    }
+                    if (found == false) {
+                        getFileChooser().addChoosableFileFilter(currentFilter);
+                    }
+                }
+
+                filters = getFileChooser().getChoosableFileFilters();
+                setSelectedItem(e.getNewValue());
+            }
+        }
+
+        public void setSelectedItem(final Object filter) {
+            if (filter != null) {
+                selectedIndex = this.indexOf(filter);
+                fireContentsChanged(this, -1, -1);
+            }
+        }
+
+        public Object getSelectedItem() {
+            final Object returnValue = null;
+
+            if (this.size() > 0) {
+                if ((selectedIndex != -1) && (selectedIndex < size())) { return this.get(selectedIndex); }
+            }
+
+            return returnValue;
+        }
+    }
+
+    /**
+     * Acts when FilterComboBox has changed the selected item.
+     */
+    protected class FilterComboBoxAction extends AbstractAction {
+        protected FilterComboBoxAction() {
+            super("FilterComboBoxAction");
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            getFileChooser().setFileFilter((FileFilter)filterComboBox.getSelectedItem());
+        }
+    }
+
+    /**
+     * Acts when DirectoryComboBox has changed the selected item.
+     */
+    protected class DirectoryComboBoxAction extends AbstractAction {
+        protected DirectoryComboBoxAction() {
+            super("DirectoryComboBoxAction");
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            getFileChooser().setCurrentDirectory((File)directoryComboBox.getSelectedItem());
+        }
+    }
+
+    // Sorting Table operations
+    class JSortingTableHeader extends JTableHeader {
+        public JSortingTableHeader(final TableColumnModel cm) {
+            super(cm);
+            setReorderingAllowed(true); // This causes mousePress to call setDraggedColumn
+        }
+
+        // One sort state for each column.  Both are ascending by default
+        final boolean fSortAscending[] = {true, true};
+
+        // Instead of dragging, it selects which one to sort by
+        public void setDraggedColumn(final TableColumn aColumn) {
+            if (aColumn != null) {
+                final int colIndex = aColumn.getModelIndex();
+                if (colIndex != fSortColumn) {
+                    filechooser.firePropertyChange(AquaFileSystemModel.SORT_BY_CHANGED, fSortColumn, colIndex);
+                    fSortColumn = colIndex;
+                } else {
+                    fSortAscending[colIndex] = !fSortAscending[colIndex];
+                    filechooser.firePropertyChange(AquaFileSystemModel.SORT_ASCENDING_CHANGED, !fSortAscending[colIndex], fSortAscending[colIndex]);
+                }
+                // Need to repaint the highlighted column.
+                repaint();
+            }
+        }
+
+        // This stops mouseDrags from moving the column
+        public TableColumn getDraggedColumn() {
+            return null;
+        }
+
+        protected TableCellRenderer createDefaultRenderer() {
+            final DefaultTableCellRenderer label = new AquaTableCellRenderer();
+            label.setHorizontalAlignment(SwingConstants.LEFT);
+            return label;
+        }
+
+        class AquaTableCellRenderer extends DefaultTableCellRenderer implements UIResource {
+            public Component getTableCellRendererComponent(final JTable localTable, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
+                if (localTable != null) {
+                    final JTableHeader header = localTable.getTableHeader();
+                    if (header != null) {
+                        setForeground(header.getForeground());
+                        setBackground(header.getBackground());
+                        setFont(UIManager.getFont("TableHeader.font"));
+                    }
+                }
+
+                setText((value == null) ? "" : value.toString());
+
+                // Modify the table "border" to draw smaller, and with the titles in the right position
+                // and sort indicators, just like an NSSave/Open panel.
+                final AquaTableHeaderBorder cellBorder = AquaTableHeaderBorder.getListHeaderBorder();
+                cellBorder.setSelected(column == fSortColumn);
+                final int horizontalShift = (column == 0 ? 35 : 10);
+                cellBorder.setHorizontalShift(horizontalShift);
+
+                if (column == fSortColumn) {
+                    cellBorder.setSortOrder(fSortAscending[column] ? AquaTableHeaderBorder.SORT_ASCENDING : AquaTableHeaderBorder.SORT_DECENDING);
+                } else {
+                    cellBorder.setSortOrder(AquaTableHeaderBorder.SORT_NONE);
+                }
+                setBorder(cellBorder);
+                return this;
+            }
+        }
+    }
+
+    public void installComponents(final JFileChooser fc) {
+        JPanel tPanel; // temp panel
+        // set to a Y BoxLayout. The chooser will be laid out top to bottom.
+        fc.setLayout(new BoxLayout(fc, BoxLayout.Y_AXIS));
+        fc.add(Box.createRigidArea(vstrut10));
+
+        // construct the top panel
+
+        final JPanel topPanel = new JPanel();
+        topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
+        fc.add(topPanel);
+        fc.add(Box.createRigidArea(vstrut10));
+
+        // Add the textfield pane
+
+        fTextfieldPanel = new JPanel();
+        fTextfieldPanel.setLayout(new BorderLayout());
+        // setBottomPanelForMode will make this visible if we need it
+        fTextfieldPanel.setVisible(false);
+        topPanel.add(fTextfieldPanel);
+
+        tPanel = new JPanel();
+        tPanel.setLayout(new BoxLayout(tPanel, BoxLayout.Y_AXIS));
+        final JPanel labelArea = new JPanel();
+        labelArea.setLayout(new FlowLayout(FlowLayout.CENTER));
+        fTextFieldLabel = new JLabel(fileNameLabelText);
+        labelArea.add(fTextFieldLabel);
+
+        // text field
+        filenameTextField = new JTextField();
+        fTextFieldLabel.setLabelFor(filenameTextField);
+        filenameTextField.addActionListener(getAction(kOpen));
+        filenameTextField.addFocusListener(new SaveTextFocusListener());
+        final Dimension minSize = filenameTextField.getMinimumSize();
+        Dimension d = new Dimension(250, (int)minSize.getHeight());
+        filenameTextField.setPreferredSize(d);
+        filenameTextField.setMaximumSize(d);
+        labelArea.add(filenameTextField);
+        final File f = fc.getSelectedFile();
+        if (f != null) {
+            setFileName(fc.getName(f));
+        } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
+            setFileName(newFileDefaultName);
+        }
+
+        tPanel.add(labelArea);
+        // separator line
+        final JSeparator sep = new JSeparator(){
+            public Dimension getPreferredSize() {
+                return new Dimension(((JComponent)getParent()).getWidth(), 3);
+            }
+        };
+        tPanel.add(Box.createRigidArea(new Dimension(1, 8)));
+        tPanel.add(sep);
+        tPanel.add(Box.createRigidArea(new Dimension(1, 7)));
+        fTextfieldPanel.add(tPanel, BorderLayout.CENTER);
+
+        // DirectoryComboBox, left-justified, 200x20 not including drop shadow
+        directoryComboBox = new JComboBox();
+        directoryComboBox.putClientProperty("JComboBox.lightweightKeyboardNavigation", "Lightweight");
+        fDirectoryComboBoxModel = createDirectoryComboBoxModel(fc);
+        directoryComboBox.setModel(fDirectoryComboBoxModel);
+        directoryComboBox.addActionListener(directoryComboBoxAction);
+        directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
+        directoryComboBox.setToolTipText(directoryComboBoxToolTipText);
+        d = new Dimension(250, (int)directoryComboBox.getMinimumSize().getHeight());
+        directoryComboBox.setPreferredSize(d);
+        directoryComboBox.setMaximumSize(d);
+        topPanel.add(directoryComboBox);
+
+        // ************************************** //
+        // ** Add the directory/Accessory pane ** //
+        // ************************************** //
+        final JPanel centerPanel = new JPanel(new BorderLayout());
+        fc.add(centerPanel);
+
+        // Accessory pane (equiv to Preview pane in NavServices)
+        final JComponent accessory = fc.getAccessory();
+        if (accessory != null) {
+            getAccessoryPanel().add(accessory);
+        }
+        centerPanel.add(getAccessoryPanel(), BorderLayout.LINE_START);
+
+        // Directory list(table), right-justified, resizable
+        final JPanel p = createList(fc);
+        p.setMinimumSize(LIST_MIN_SIZE);
+        centerPanel.add(p, BorderLayout.CENTER);
+
+        // ********************************** //
+        // **** Construct the bottom panel ** //
+        // ********************************** //
+        fBottomPanel = new JPanel();
+        fBottomPanel.setLayout(new BoxLayout(fBottomPanel, BoxLayout.Y_AXIS));
+        fc.add(fBottomPanel);
+
+        // Filter label and combobox.
+        // I know it's unMaclike, but the filter goes on Directory_only too.
+        tPanel = new JPanel();
+        tPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
+        tPanel.setBorder(AquaGroupBorder.getTitlelessBorder());
+        final JLabel formatLabel = new JLabel(filesOfTypeLabelText);
+        tPanel.add(formatLabel);
+
+        // Combobox
+        filterComboBoxModel = createFilterComboBoxModel();
+        fc.addPropertyChangeListener(filterComboBoxModel);
+        filterComboBox = new JComboBox(filterComboBoxModel);
+        formatLabel.setLabelFor(filterComboBox);
+        filterComboBox.setRenderer(createFilterComboBoxRenderer());
+        d = new Dimension(220, (int)filterComboBox.getMinimumSize().getHeight());
+        filterComboBox.setPreferredSize(d);
+        filterComboBox.setMaximumSize(d);
+        filterComboBox.addActionListener(filterComboBoxAction);
+        filterComboBox.setOpaque(false);
+        tPanel.add(filterComboBox);
+
+        fBottomPanel.add(tPanel);
+
+        // fDirectoryPanel: New, Open, Cancel, Approve buttons, right-justified, 82x22
+        // (sometimes the NewFolder and OpenFolder buttons are invisible)
+        fDirectoryPanel = new JPanel();
+        fDirectoryPanel.setLayout(new BoxLayout(fDirectoryPanel, BoxLayout.PAGE_AXIS));
+        JPanel directoryPanel = new JPanel(new BorderLayout());
+        JPanel newFolderButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
+        newFolderButtonPanel.add(Box.createHorizontalStrut(20));
+        fNewFolderButton = createNewFolderButton(); // Because we hide it depending on style
+        newFolderButtonPanel.add(fNewFolderButton);
+        directoryPanel.add(newFolderButtonPanel, BorderLayout.LINE_START);
+        JPanel approveCancelButtonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 0, 0));
+        fOpenButton = createButton(kOpenDirectory, openButtonText);
+        approveCancelButtonPanel.add(fOpenButton);
+        approveCancelButtonPanel.add(Box.createHorizontalStrut(8));
+        fCancelButton = createButton(kCancel, null);
+        approveCancelButtonPanel.add(fCancelButton);
+        approveCancelButtonPanel.add(Box.createHorizontalStrut(8));
+        // The ApproveSelection button
+        fApproveButton = new JButton();
+        fApproveButton.addActionListener(fApproveSelectionAction);
+        approveCancelButtonPanel.add(fApproveButton);
+        approveCancelButtonPanel.add(Box.createHorizontalStrut(20));
+        directoryPanel.add(approveCancelButtonPanel, BorderLayout.LINE_END);
+        fDirectoryPanel.add(Box.createVerticalStrut(5));
+        fDirectoryPanel.add(directoryPanel);
+        fDirectoryPanel.add(Box.createVerticalStrut(12));
+        fDirectoryPanelSpacer = Box.createRigidArea(hstrut10);
+
+        if (fc.getControlButtonsAreShown()) {
+            fBottomPanel.add(fDirectoryPanelSpacer);
+            fBottomPanel.add(fDirectoryPanel);
+        }
+
+        setBottomPanelForMode(fc); // updates ApproveButtonText etc
+
+        // don't create til after the FCSubpanel and buttons are made
+        filenameTextField.getDocument().addDocumentListener(new SaveTextDocumentListener());
+    }
+
+    void setDefaultButtonForMode(final JFileChooser fc) {
+        final JButton defaultButton = fSubPanel.getDefaultButton(fc);
+        final JRootPane root = defaultButton.getRootPane();
+        if (root != null) {
+            root.setDefaultButton(defaultButton);
+        }
+    }
+
+    // Macs start with their focus in text areas if they have them,
+    // lists otherwise (the other plafs start with the focus on approveButton)
+    void setFocusForMode(final JFileChooser fc) {
+        final JComponent focusComponent = fSubPanel.getFocusComponent(fc);
+        if (focusComponent != null) {
+            focusComponent.requestFocus();
+        }
+    }
+
+    // Enable/disable buttons as needed for the current selection/focus state
+    void updateButtonState(final JFileChooser fc) {
+        fSubPanel.updateButtonState(fc, getFirstSelectedItem());
+        updateApproveButton(fc);
+    }
+
+    void updateApproveButton(final JFileChooser chooser) {
+        fApproveButton.setText(getApproveButtonText(chooser));
+        fApproveButton.setToolTipText(getApproveButtonToolTipText(chooser));
+        fApproveButton.setMnemonic(getApproveButtonMnemonic(chooser));
+        fCancelButton.setToolTipText(getCancelButtonToolTipText(chooser));
+    }
+
+    // Lazy-init the subpanels
+    synchronized FCSubpanel getSaveFilePanel() {
+        if (fSaveFilePanel == null) fSaveFilePanel = new SaveFilePanel();
+        return fSaveFilePanel;
+    }
+
+    synchronized FCSubpanel getOpenFilePanel() {
+        if (fOpenFilePanel == null) fOpenFilePanel = new OpenFilePanel();
+        return fOpenFilePanel;
+    }
+
+    synchronized FCSubpanel getOpenDirOrAnyPanel() {
+        if (fOpenDirOrAnyPanel == null) fOpenDirOrAnyPanel = new OpenDirOrAnyPanel();
+        return fOpenDirOrAnyPanel;
+    }
+
+    synchronized FCSubpanel getCustomFilePanel() {
+        if (fCustomFilePanel == null) fCustomFilePanel = new CustomFilePanel();
+        return fCustomFilePanel;
+    }
+
+    synchronized FCSubpanel getCustomDirOrAnyPanel() {
+        if (fCustomDirOrAnyPanel == null) fCustomDirOrAnyPanel = new CustomDirOrAnyPanel();
+        return fCustomDirOrAnyPanel;
+    }
+
+    void setBottomPanelForMode(final JFileChooser fc) {
+        if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) fSubPanel = getSaveFilePanel();
+        else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
+            if (fc.getFileSelectionMode() == JFileChooser.FILES_ONLY) fSubPanel = getOpenFilePanel();
+            else fSubPanel = getOpenDirOrAnyPanel();
+        } else if (fc.getDialogType() == JFileChooser.CUSTOM_DIALOG) {
+            if (fc.getFileSelectionMode() == JFileChooser.FILES_ONLY) fSubPanel = getCustomFilePanel();
+            else fSubPanel = getCustomDirOrAnyPanel();
+        }
+
+        fSubPanel.installPanel(fc, true);
+        updateApproveButton(fc);
+        updateButtonState(fc);
+        setDefaultButtonForMode(fc);
+        setFocusForMode(fc);
+        fc.invalidate();
+    }
+
+    // fTextfieldPanel and fDirectoryPanel both have NewFolder buttons; only one should be visible at a time
+    JButton createNewFolderButton() {
+        final JButton b = new JButton(newFolderButtonText);
+        b.setToolTipText(newFolderToolTipText);
+        b.getAccessibleContext().setAccessibleName(newFolderAccessibleName);
+        b.setHorizontalTextPosition(SwingConstants.LEFT);
+        b.setAlignmentX(Component.LEFT_ALIGNMENT);
+        b.setAlignmentY(Component.CENTER_ALIGNMENT);
+        b.addActionListener(getAction(kNewFolder));
+        return b;
+    }
+
+    JButton createButton(final int which, String label) {
+        if (label == null) label = UIManager.getString(sDataPrefix + sButtonKinds[which] + sButtonData[0]);
+        final int mnemonic = UIManager.getInt(sDataPrefix + sButtonKinds[which] + sButtonData[1]);
+        final String tipText = UIManager.getString(sDataPrefix + sButtonKinds[which] + sButtonData[2]);
+        final JButton b = new JButton(label);
+        b.setMnemonic(mnemonic);
+        b.setToolTipText(tipText);
+        b.addActionListener(getAction(which));
+        return b;
+    }
+
+    AbstractAction getAction(final int which) {
+        return fButtonActions[which];
+    }
+
+    public void uninstallComponents(final JFileChooser fc) { //$ Metal (on which this is based) doesn't uninstall its components.
+    }
+
+    // Consistent with the AppKit NSSavePanel, clicks on a file (not a directory) should populate the text field
+    // with that file's display name.
+    protected class FileListMouseListener extends MouseAdapter {
+        public void mouseClicked(final MouseEvent e) {
+            final Point p = e.getPoint();
+            final int row = fFileList.rowAtPoint(p);
+            final int column = fFileList.columnAtPoint(p);
+
+            // The autoscroller can generate drag events outside the Table's range.
+            if ((column == -1) || (row == -1)) { return; }
+
+            final File clickedFile = (File)(fFileList.getValueAt(row, 0));
+
+            // rdar://problem/3734130 -- don't populate the text field if this file isn't selectable in this mode.
+            if (isSelectableForMode(getFileChooser(), clickedFile)) {
+                // [3188387] Populate the file name field with the selected file name
+                // [3484163] It should also use the display name, not the actual name.
+                setFileName(fileView.getName(clickedFile));
+            }
+        }
+    }
+
+    protected JPanel createList(final JFileChooser fc) {
+        // The first part is similar to MetalFileChooserUI.createList - same kind of listeners
+        final JPanel p = new JPanel(new BorderLayout());
+        fFileList = new JTableExtension();
+        fFileList.setToolTipText(null); // Workaround for 2487689
+        fFileList.addMouseListener(new FileListMouseListener());
+        model = new AquaFileSystemModel(fc, fFileList, fColumnNames);
+        final MacListSelectionModel listSelectionModel = new MacListSelectionModel(model);
+
+        if (getFileChooser().isMultiSelectionEnabled()) {
+            listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+        } else {
+            listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        }
+
+        fFileList.setModel(model);
+        fFileList.setSelectionModel(listSelectionModel);
+        fFileList.getSelectionModel().addListSelectionListener(createListSelectionListener(fc));
+
+        // Now we're different, because we're a table, not a list
+        fc.addPropertyChangeListener(model);
+        fFileList.addFocusListener(new SaveTextFocusListener());
+        final JTableHeader th = new JSortingTableHeader(fFileList.getColumnModel());
+        fFileList.setTableHeader(th);
+        fFileList.setRowMargin(0);
+        fFileList.setIntercellSpacing(new Dimension(0, 1));
+        fFileList.setShowVerticalLines(false);
+        fFileList.setShowHorizontalLines(false);
+        final Font f = fFileList.getFont(); //ThemeFont.GetThemeFont(AppearanceConstants.kThemeViewsFont);
+        //fc.setFont(f);
+        //fFileList.setFont(f);
+        fFileList.setDefaultRenderer(File.class, new FileRenderer(f));
+        fFileList.setDefaultRenderer(Date.class, new DateRenderer(f));
+        final FontMetrics fm = fFileList.getFontMetrics(f);
+
+        // Row height isn't based on the renderers.  It defaults to 16 so we have to set it
+        fFileList.setRowHeight(Math.max(fm.getHeight(), fileIcon.getIconHeight() + 2));
+
+        // Add a binding for the file list that triggers return and escape
+        fFileList.registerKeyboardAction(new CancelSelectionAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED);
+        // Add a binding for the file list that triggers the default button (see DefaultButtonAction)
+        fFileList.registerKeyboardAction(new DefaultButtonAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
+        fFileList.setDropTarget(dragAndDropTarget);
+
+        final JScrollPane scrollpane = new JScrollPane(fFileList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+        scrollpane.setComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
+        scrollpane.setCorner(ScrollPaneConstants.UPPER_TRAILING_CORNER, new ScrollPaneCornerPanel());
+        p.add(scrollpane, BorderLayout.CENTER);
+        return p;
+    }
+
+    protected class ScrollPaneCornerPanel extends JPanel {
+        final Border border = UIManager.getBorder("TableHeader.cellBorder");
+
+        protected void paintComponent(final Graphics g) {
+            border.paintBorder(this, g, 0, 0, getWidth() + 1, getHeight());
+        }
+    }
+
+    JComboBox directoryComboBox;
+    DirectoryComboBoxModel fDirectoryComboBoxModel;
+    private final Action directoryComboBoxAction = new DirectoryComboBoxAction();
+
+    JTextField filenameTextField;
+
+    JTableExtension fFileList;
+
+    private FilterComboBoxModel filterComboBoxModel;
+    JComboBox filterComboBox;
+    private final Action filterComboBoxAction = new FilterComboBoxAction();
+
+    private static final Dimension hstrut10 = new Dimension(10, 1);
+    private static final Dimension vstrut10 = new Dimension(1, 10);
+
+    private static final int PREF_WIDTH = 550;
+    private static final int PREF_HEIGHT = 400;
+    private static final Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
+
+    private static final int MIN_WIDTH = 400;
+    private static final int MIN_HEIGHT = 250;
+    private static final Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
+
+    private static final int LIST_MIN_WIDTH = 400;
+    private static final int LIST_MIN_HEIGHT = 100;
+    private static final Dimension LIST_MIN_SIZE = new Dimension(LIST_MIN_WIDTH, LIST_MIN_HEIGHT);
+
+    static String fileNameLabelText = null;
+    JLabel fTextFieldLabel = null;
+
+    private static String filesOfTypeLabelText = null;
+
+    private static String newFolderToolTipText = null;
+    static String newFolderAccessibleName = null;
+
+    private static final String[] fColumnNames = new String[2];
+
+    JPanel fTextfieldPanel; // Filename textfield for Save or Custom
+    private JPanel fDirectoryPanel; // NewFolder/OpenFolder/Cancel/Approve buttons
+    private Component fDirectoryPanelSpacer;
+    private JPanel fBottomPanel; // The panel that holds fDirectoryPanel and filterComboBox
+
+    private FCSubpanel fSaveFilePanel = null;
+    private FCSubpanel fOpenFilePanel = null;
+    private FCSubpanel fOpenDirOrAnyPanel = null;
+    private FCSubpanel fCustomFilePanel = null;
+    private FCSubpanel fCustomDirOrAnyPanel = null;
+
+    FCSubpanel fSubPanel = null; // Current FCSubpanel
+
+    JButton fApproveButton; // mode-specific behavior is managed by FCSubpanel.approveSelection
+    JButton fOpenButton; // for Directories
+    JButton fNewFolderButton; // for fDirectoryPanel
+
+    // ToolTip text varies with type of dialog
+    private JButton fCancelButton;
+
+    private final ApproveSelectionAction fApproveSelectionAction = new ApproveSelectionAction();
+    protected int fSortColumn = 0;
+    protected int fPackageIsTraversable = -1;
+    protected int fApplicationIsTraversable = -1;
+
+    protected static final int sGlobalPackageIsTraversable;
+    protected static final int sGlobalApplicationIsTraversable;
+
+    protected static final String PACKAGE_TRAVERSABLE_PROPERTY = "JFileChooser.packageIsTraversable";
+    protected static final String APPLICATION_TRAVERSABLE_PROPERTY = "JFileChooser.appBundleIsTraversable";
+    protected static final String[] sTraversableProperties = {"always", // Bundle is always traversable
+            "never", // Bundle is never traversable
+            "conditional"}; // Bundle is traversable on command click
+    protected static final int kOpenAlways = 0, kOpenNever = 1, kOpenConditional = 2;
+
+    AbstractAction[] fButtonActions = {fApproveSelectionAction, fApproveSelectionAction, new CancelSelectionAction(), new OpenSelectionAction(), null, new NewFolderAction()};
+
+    static int parseTraversableProperty(final String s) {
+        if (s == null) return -1;
+        for (int i = 0; i < sTraversableProperties.length; i++) {
+            if (s.equals(sTraversableProperties[i])) return i;
+        }
+        return -1;
+    }
+
+    static {
+        Object o = UIManager.get(PACKAGE_TRAVERSABLE_PROPERTY);
+        if (o != null && o instanceof String) sGlobalPackageIsTraversable = parseTraversableProperty((String)o);
+        else sGlobalPackageIsTraversable = kOpenConditional;
+
+        o = UIManager.get(APPLICATION_TRAVERSABLE_PROPERTY);
+        if (o != null && o instanceof String) sGlobalApplicationIsTraversable = parseTraversableProperty((String)o);
+        else sGlobalApplicationIsTraversable = kOpenConditional;
+    }
+    static final String sDataPrefix = "FileChooser.";
+    static final String[] sButtonKinds = {"openButton", "saveButton", "cancelButton", "openDirectoryButton", "helpButton", "newFolderButton"};
+    static final String[] sButtonData = {"Text", "Mnemonic", "ToolTipText"};
+    static final int kOpen = 0, kSave = 1, kCancel = 2, kOpenDirectory = 3, kHelp = 4, kNewFolder = 5;
+
+    /*-------
+
+     Possible states: Save, {Open, Custom}x{Files, File and Directory, Directory}
+     --------- */
+
+    // This class returns the values for the Custom type, to avoid duplicating code in the two Custom subclasses
+    abstract class FCSubpanel {
+        // Install the appropriate panels for this mode
+        abstract void installPanel(JFileChooser fc, boolean controlButtonsAreShown);
+
+        abstract void updateButtonState(JFileChooser fc, File f);
+
+        // Can this item be selected?
+        // if not, it's disabled in the list
+        boolean isSelectableInList(final JFileChooser fc, final File f) {
+            if (f == null) return false;
+            if (fc.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) return fc.isTraversable(f);
+            return fc.accept(f);
+        }
+
+        void approveSelection(final JFileChooser fc) {
+            fc.approveSelection();
+        }
+
+        JButton getDefaultButton(final JFileChooser fc) {
+            return fApproveButton;
+        }
+
+        // Default to the textfield, panels without one should subclass
+        JComponent getFocusComponent(final JFileChooser fc) {
+            return filenameTextField;
+        }
+
+        String getApproveButtonText(final JFileChooser fc) {
+            // Fallback to "choose"
+            return this.getApproveButtonText(fc, chooseButtonText);
+        }
+
+        // Try to get the custom text.  If none, use the fallback
+        String getApproveButtonText(final JFileChooser fc, final String fallbackText) {
+            final String buttonText = fc.getApproveButtonText();
+            if (buttonText != null) {
+                buttonText.trim();
+                if (!buttonText.equals("")) return buttonText;
+            }
+            return fallbackText;
+        }
+
+        int getApproveButtonMnemonic(final JFileChooser fc) {
+            // Don't use a default
+            return fc.getApproveButtonMnemonic();
+        }
+
+        // No fallback
+        String getApproveButtonToolTipText(final JFileChooser fc) {
+            return getApproveButtonToolTipText(fc, null);
+        }
+
+        String getApproveButtonToolTipText(final JFileChooser fc, final String fallbackText) {
+            final String tooltipText = fc.getApproveButtonToolTipText();
+            if (tooltipText != null) {
+                tooltipText.trim();
+                if (!tooltipText.equals("")) return tooltipText;
+            }
+            return fallbackText;
+        }
+
+        String getCancelButtonToolTipText(final JFileChooser fc) {
+            return cancelChooseButtonToolTipText;
+        }
+    }
+
+    // Custom FILES_ONLY dialog
+    /*
+     NavServices Save appearance with Open behavior
+     Approve button label = Open when list has focus and a directory is selected, Custom otherwise
+     No OpenDirectory button - Approve button is overloaded
+     Default button / double click = Approve
+     Has text field
+     List - everything is enabled
+     */
+    class CustomFilePanel extends FCSubpanel {
+        void installPanel(final JFileChooser fc, final boolean controlButtonsAreShown) {
+            fTextfieldPanel.setVisible(true); // do we really want one in multi-select?  It's confusing
+            fOpenButton.setVisible(false);
+            fNewFolderButton.setVisible(true);
+        }
+
+        // If the list has focus, the mode depends on the selection
+        // - directory = open, file = approve
+        // If something else has focus and we have text, it's approve
+        // otherwise, it depends on selection again.
+        boolean inOpenDirectoryMode(final JFileChooser fc, final File f) {
+            final boolean selectionIsDirectory = (f != null && fc.isTraversable(f));
+            if (fFileList.hasFocus()) return selectionIsDirectory;
+            else if (textfieldIsValid()) return false;
+            return selectionIsDirectory;
+        }
+
+        // The approve button is overloaded to mean OpenDirectory or Save
+        void approveSelection(final JFileChooser fc) {
+            File f = getFirstSelectedItem();
+            if (inOpenDirectoryMode(fc, f)) {
+                openDirectory(f);
+            } else {
+                f = makeFile(fc, getFileName());
+                if (f != null) {
+                    selectionInProgress = true;
+                    getFileChooser().setSelectedFile(f);
+                    selectionInProgress = false;
+                }
+                getFileChooser().approveSelection();
+            }
+        }
+
+        // The approve button should be enabled
+        // - if something in the list can be opened
+        // - if the textfield has something in it
+        void updateButtonState(final JFileChooser fc, final File f) {
+            boolean enabled = true;
+            if (!inOpenDirectoryMode(fc, f)) {
+                enabled = (f != null) || textfieldIsValid();
+            }
+            getApproveButton(fc).setEnabled(enabled);
+
+            // The OpenDirectory button should be disabled if there's no directory selected
+            fOpenButton.setEnabled(f != null && fc.isTraversable(f));
+
+            // Update the default button, since we may have disabled the current default.
+            setDefaultButtonForMode(fc);
+        }
+
+        // everything's enabled, because we don't know what they're doing with them
+        boolean isSelectableInList(final JFileChooser fc, final File f) {
+            if (f == null) return false;
+            return fc.accept(f);
+        }
+
+        String getApproveButtonToolTipText(final JFileChooser fc) {
+            // The approve Button should have openDirectoryButtonToolTipText when the selection is a folder...
+            if (inOpenDirectoryMode(fc, getFirstSelectedItem())) return openDirectoryButtonToolTipText;
+            return super.getApproveButtonToolTipText(fc);
+        }
+    }
+
+    // All Save dialogs
+    /*
+     NavServices Save
+     Approve button label = Open when list has focus and a directory is selected, Save otherwise
+     No OpenDirectory button - Approve button is overloaded
+     Default button / double click = Approve
+     Has text field
+     Has NewFolder button (by text field)
+     List - only traversables are enabled
+     List is always SINGLE_SELECT
+     */
+    // Subclasses CustomFilePanel because they look alike and have some common behavior
+    class SaveFilePanel extends CustomFilePanel {
+        void installPanel(final JFileChooser fc, final boolean controlButtonsAreShown) {
+            fTextfieldPanel.setVisible(true);
+            fOpenButton.setVisible(false);
+            fNewFolderButton.setVisible(true);
+        }
+
+        // only traversables are enabled, regardless of mode
+        // because all you can do is select the next folder to open
+        boolean isSelectableInList(final JFileChooser fc, final File f) {
+            return fc.accept(f) && fc.isTraversable(f);
+        }
+
+        // The approve button means 'approve the file name in the text field.'
+        void approveSelection(final JFileChooser fc) {
+            final File f = makeFile(fc, getFileName());
+            if (f != null) {
+                selectionInProgress = true;
+                getFileChooser().setSelectedFile(f);
+                selectionInProgress = false;
+                getFileChooser().approveSelection();
+            }
+        }
+
+        // The approve button should be enabled if the textfield has something in it
+        void updateButtonState(final JFileChooser fc, final File f) {
+            final boolean enabled = textfieldIsValid();
+            getApproveButton(fc).setEnabled(enabled);
+        }
+
+        String getApproveButtonText(final JFileChooser fc) {
+            // Get the custom text, or fallback to "Save"
+            return this.getApproveButtonText(fc, saveButtonText);
+        }
+
+        int getApproveButtonMnemonic(final JFileChooser fc) {
+            return saveButtonMnemonic;
+        }
+
+        String getApproveButtonToolTipText(final JFileChooser fc) {
+            // The approve Button should have openDirectoryButtonToolTipText when the selection is a folder...
+            if (inOpenDirectoryMode(fc, getFirstSelectedItem())) return openDirectoryButtonToolTipText;
+            return this.getApproveButtonToolTipText(fc, saveButtonToolTipText);
+        }
+
+        String getCancelButtonToolTipText(final JFileChooser fc) {
+            return cancelSaveButtonToolTipText;
+        }
+    }
+
+    // Open FILES_ONLY
+    /*
+     NSOpenPanel-style
+     Approve button label = Open
+     Default button / double click = Approve
+     No text field
+     No NewFolder button
+     List - all items are enabled
+     */
+    class OpenFilePanel extends FCSubpanel {
+        void installPanel(final JFileChooser fc, final boolean controlButtonsAreShown) {
+            fTextfieldPanel.setVisible(false);
+            fOpenButton.setVisible(false);
+            fNewFolderButton.setVisible(false);
+            setDefaultButtonForMode(fc);
+        }
+
+        boolean inOpenDirectoryMode(final JFileChooser fc, final File f) {
+            return (f != null && fc.isTraversable(f));
+        }
+
+        // Default to the list
+        JComponent getFocusComponent(final JFileChooser fc) {
+            return fFileList;
+        }
+
+        void updateButtonState(final JFileChooser fc, final File f) {
+            // Button is disabled if there's nothing selected
+            final boolean enabled = (f != null) && !fc.isTraversable(f);
+            getApproveButton(fc).setEnabled(enabled);
+        }
+
+        // all items are enabled
+        boolean isSelectableInList(final JFileChooser fc, final File f) {
+            return f != null && fc.accept(f);
+        }
+
+        String getApproveButtonText(final JFileChooser fc) {
+            // Get the custom text, or fallback to "Open"
+            return this.getApproveButtonText(fc, openButtonText);
+        }
+
+        int getApproveButtonMnemonic(final JFileChooser fc) {
+            return openButtonMnemonic;
+        }
+
+        String getApproveButtonToolTipText(final JFileChooser fc) {
+            return this.getApproveButtonToolTipText(fc, openButtonToolTipText);
+        }
+
+        String getCancelButtonToolTipText(final JFileChooser fc) {
+            return cancelOpenButtonToolTipText;
+        }
+    }
+
+    // used by open and custom panels for Directory only or files and directories
+    abstract class DirOrAnyPanel extends FCSubpanel {
+        void installPanel(final JFileChooser fc, final boolean controlButtonsAreShown) {
+            fOpenButton.setVisible(false);
+        }
+
+        JButton getDefaultButton(final JFileChooser fc) {
+            return getApproveButton(fc);
+        }
+
+        void updateButtonState(final JFileChooser fc, final File f) {
+            // Button is disabled if there's nothing selected
+            // Approve button is handled by the subclasses
+            // getApproveButton(fc).setEnabled(f != null);
+
+            // The OpenDirectory button should be disabled if there's no directory selected
+            // - we only check the first item
+
+            fOpenButton.setEnabled(false);
+            setDefaultButtonForMode(fc);
+        }
+    }
+
+    // Open FILES_AND_DIRECTORIES or DIRECTORIES_ONLY
+    /*
+     NavServices Choose
+     Approve button label = Choose/Custom
+     Has OpenDirectory button
+     Default button / double click = OpenDirectory
+     No text field
+     List - files are disabled in DIRECTORIES_ONLY
+     */
+    class OpenDirOrAnyPanel extends DirOrAnyPanel {
+        void installPanel(final JFileChooser fc, final boolean controlButtonsAreShown) {
+            super.installPanel(fc, controlButtonsAreShown);
+            fTextfieldPanel.setVisible(false);
+            fNewFolderButton.setVisible(false);
+        }
+
+        // Default to the list
+        JComponent getFocusComponent(final JFileChooser fc) {
+            return fFileList;
+        }
+
+        int getApproveButtonMnemonic(final JFileChooser fc) {
+            return chooseButtonMnemonic;
+        }
+
+        String getApproveButtonToolTipText(final JFileChooser fc) {
+            String fallbackText;
+            if (fc.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) fallbackText = chooseFolderButtonToolTipText;
+            else fallbackText = chooseItemButtonToolTipText;
+            return this.getApproveButtonToolTipText(fc, fallbackText);
+        }
+
+        void updateButtonState(final JFileChooser fc, final File f) {
+            // Button is disabled if there's nothing selected
+            getApproveButton(fc).setEnabled(f != null);
+            super.updateButtonState(fc, f);
+        }
+    }
+
+    // Custom FILES_AND_DIRECTORIES or DIRECTORIES_ONLY
+    /*
+     No NavServices equivalent
+     Approve button label = user defined or Choose
+     Has OpenDirectory button
+     Default button / double click = OpenDirectory
+     Has text field
+     Has NewFolder button (by text field)
+     List - files are disabled in DIRECTORIES_ONLY
+     */
+    class CustomDirOrAnyPanel extends DirOrAnyPanel {
+        void installPanel(final JFileChooser fc, final boolean controlButtonsAreShown) {
+            super.installPanel(fc, controlButtonsAreShown);
+            fTextfieldPanel.setVisible(true);
+            fNewFolderButton.setVisible(true);
+        }
+
+        // If there's text, make a file and select it
+        void approveSelection(final JFileChooser fc) {
+            final File f = makeFile(fc, getFileName());
+            if (f != null) {
+                selectionInProgress = true;
+                getFileChooser().setSelectedFile(f);
+                selectionInProgress = false;
+            }
+            getFileChooser().approveSelection();
+        }
+
+        void updateButtonState(final JFileChooser fc, final File f) {
+            // Button is disabled if there's nothing selected
+            getApproveButton(fc).setEnabled(f != null || textfieldIsValid());
+            super.updateButtonState(fc, f);
+        }
+    }
+
+    // See FileRenderer - documents in Save dialogs draw disabled, so they shouldn't be selected
+    class MacListSelectionModel extends DefaultListSelectionModel {
+        AquaFileSystemModel fModel;
+
+        MacListSelectionModel(final AquaFileSystemModel model) {
+            fModel = model;
+        }
+
+        // Can the file be selected in this mode?
+        // (files are visible even if they can't be selected)
+        boolean isSelectableInListIndex(final int index) {
+            final File file = (File)fModel.getValueAt(index, 0);
+            return (file != null && isSelectableInList(file));
+        }
+
+        // Make sure everything in the selection interval is valid
+        void verifySelectionInterval(int index0, int index1, boolean isSetSelection) {
+            if (index0 > index1) {
+                final int tmp = index1;
+                index1 = index0;
+                index0 = tmp;
+            }
+            int start = index0;
+            int end;
+            do {
+                // Find the first selectable file in the range
+                for (; start <= index1; start++) {
+                    if (isSelectableInListIndex(start)) break;
+                }
+                end = -1;
+                // Find the last selectable file in the range
+                for (int i = start; i <= index1; i++) {
+                    if (!isSelectableInListIndex(i)) {
+                        break;
+                    }
+                    end = i;
+                }
+                // Select the range
+                if (end >= 0) {
+                    // If setting the selection, do "set" the first time to clear the old one
+                    // after that do "add" to extend it
+                    if (isSetSelection) {
+                        super.setSelectionInterval(start, end);
+                        isSetSelection = false;
+                    } else {
+                        super.addSelectionInterval(start, end);
+                    }
+                    start = end + 1;
+                } else {
+                    break;
+                }
+            } while (start <= index1);
+        }
+
+        public void setAnchorSelectionIndex(final int anchorIndex) {
+            if (isSelectableInListIndex(anchorIndex)) super.setAnchorSelectionIndex(anchorIndex);
+        }
+
+        public void setLeadSelectionIndex(final int leadIndex) {
+            if (isSelectableInListIndex(leadIndex)) super.setLeadSelectionIndex(leadIndex);
+        }
+
+        public void setSelectionInterval(final int index0, final int index1) {
+            if (index0 == -1 || index1 == -1) { return; }
+
+            if ((getSelectionMode() == SINGLE_SELECTION) || (index0 == index1)) {
+                if (isSelectableInListIndex(index1)) super.setSelectionInterval(index1, index1);
+            } else {
+                verifySelectionInterval(index0, index1, true);
+            }
+        }
+
+        public void addSelectionInterval(final int index0, final int index1) {
+            if (index0 == -1 || index1 == -1) { return; }
+
+            if (index0 == index1) {
+                if (isSelectableInListIndex(index1)) super.addSelectionInterval(index1, index1);
+                return;
+            }
+
+            if (getSelectionMode() != MULTIPLE_INTERVAL_SELECTION) {
+                setSelectionInterval(index0, index1);
+                return;
+            }
+
+            verifySelectionInterval(index0, index1, false);
+        }
+    }
+
+    // Convenience, to translate from the JList directory view to the Mac-style JTable
+    //   & minimize diffs between this and BasicFileChooserUI
+    class JTableExtension extends JTable {
+        public void setSelectedIndex(final int index) {
+            getSelectionModel().setSelectionInterval(index, index);
+        }
+
+        public void removeSelectedIndex(final int index) {
+            getSelectionModel().removeSelectionInterval(index, index);
+        }
+
+        public void ensureIndexIsVisible(final int index) {
+            final Rectangle cellBounds = getCellRect(index, 0, false);
+            if (cellBounds != null) {
+                scrollRectToVisible(cellBounds);
+            }
+        }
+
+        public int locationToIndex(final Point location) {
+            return rowAtPoint(location);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaFileSystemModel.java b/jdk/src/macosx/classes/com/apple/laf/AquaFileSystemModel.java
new file mode 100644
index 0000000..d41b036
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaFileSystemModel.java
@@ -0,0 +1,472 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.beans.*;
+import java.io.File;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.event.ListDataEvent;
+import javax.swing.filechooser.FileSystemView;
+import javax.swing.table.AbstractTableModel;
+
+/**
+ * NavServices-like implementation of a file Table
+ *
+ * Some of it came from BasicDirectoryModel
+ */
+class AquaFileSystemModel extends AbstractTableModel implements PropertyChangeListener {
+    private final JTable fFileList;
+    private LoadFilesThread loadThread = null;
+    private Vector<File> files = null;
+
+    JFileChooser filechooser = null;
+    Vector<SortableFile> fileCache = null;
+    Object fileCacheLock;
+
+    Vector<File> directories = null;
+    int fetchID = 0;
+
+    private final boolean fSortAscending[] = {true, true};
+    // private boolean fSortAscending = true;
+    private boolean fSortNames = true;
+    private final String[] fColumnNames;
+    public final static String SORT_BY_CHANGED = "sortByChanged";
+    public final static String SORT_ASCENDING_CHANGED = "sortAscendingChanged";
+
+    public AquaFileSystemModel(final JFileChooser filechooser, final JTable filelist, final String[] colNames) {
+        fileCacheLock = new Object();
+        this.filechooser = filechooser;
+        fFileList = filelist;
+        fColumnNames = colNames;
+        validateFileCache();
+        updateSelectionMode();
+    }
+
+    void updateSelectionMode() {
+        // Save dialog lists can't be multi select, because all we're selecting is the next folder to open
+        final boolean b = filechooser.isMultiSelectionEnabled() && filechooser.getDialogType() != JFileChooser.SAVE_DIALOG;
+        fFileList.setSelectionMode(b ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION);
+    }
+
+    public void propertyChange(final PropertyChangeEvent e) {
+        final String prop = e.getPropertyName();
+        if (prop == JFileChooser.DIRECTORY_CHANGED_PROPERTY || prop == JFileChooser.FILE_VIEW_CHANGED_PROPERTY || prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY || prop == JFileChooser.FILE_HIDING_CHANGED_PROPERTY) {
+            invalidateFileCache();
+            validateFileCache();
+        } else if (prop.equals(JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY)) {
+            updateSelectionMode();
+        } else if (prop == JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY) {
+            invalidateFileCache();
+            validateFileCache();
+        }
+        if (prop == SORT_BY_CHANGED) {// $ Ought to just resort
+            fSortNames = (((Integer)e.getNewValue()).intValue() == 0);
+            invalidateFileCache();
+            validateFileCache();
+            fFileList.repaint();
+        }
+        if (prop == SORT_ASCENDING_CHANGED) {
+            final int sortColumn = (fSortNames ? 0 : 1);
+            fSortAscending[sortColumn] = ((Boolean)e.getNewValue()).booleanValue();
+            invalidateFileCache();
+            validateFileCache();
+            fFileList.repaint();
+        }
+    }
+
+    public void invalidateFileCache() {
+        files = null;
+        directories = null;
+
+        synchronized(fileCacheLock) {
+            if (fileCache != null) {
+                final int lastRow = fileCache.size();
+                fileCache = null;
+                fireTableRowsDeleted(0, lastRow);
+            }
+        }
+    }
+
+    public Vector<File> getDirectories() {
+        if (directories != null) { return directories; }
+        return directories;
+    }
+
+    public Vector<File> getFiles() {
+        if (files != null) { return files; }
+        files = new Vector<File>();
+        directories = new Vector<File>();
+        directories.addElement(filechooser.getFileSystemView().createFileObject(filechooser.getCurrentDirectory(), ".."));
+
+        synchronized(fileCacheLock) {
+            for (int i = 0; i < fileCache.size(); i++) {
+                final SortableFile sf = fileCache.elementAt(i);
+                final File f = sf.fFile;
+                if (filechooser.isTraversable(f)) {
+                    directories.addElement(f);
+                } else {
+                    files.addElement(f);
+                }
+            }
+        }
+
+        return files;
+    }
+
+    public void runWhenDone(final Runnable runnable){
+         synchronized (fileCacheLock) {
+             if (loadThread != null) {
+                 if (loadThread.isAlive()) {
+                     loadThread.queuedTasks.add(runnable);
+                     return;
+                 }
+             }
+
+             SwingUtilities.invokeLater(runnable);
+         }
+     }
+
+    public void validateFileCache() {
+        final File currentDirectory = filechooser.getCurrentDirectory();
+
+        if (currentDirectory == null) {
+            invalidateFileCache();
+            return;
+        }
+
+        if (loadThread != null) {
+            // interrupt
+            loadThread.interrupt();
+        }
+
+        fetchID++;
+
+        // PENDING(jeff) pick the size more sensibly
+        invalidateFileCache();
+        synchronized(fileCacheLock) {
+            fileCache = new Vector<SortableFile>(50);
+        }
+
+        loadThread = new LoadFilesThread(currentDirectory, fetchID);
+        loadThread.start();
+    }
+
+    public int getColumnCount() {
+        return 2;
+    }
+
+    public String getColumnName(final int col) {
+        return fColumnNames[col];
+    }
+
+    public Class<? extends Object> getColumnClass(final int col) {
+        if (col == 0) return File.class;
+        return Date.class;
+    }
+
+    public int getRowCount() {
+        synchronized(fileCacheLock) {
+            if (fileCache != null) {
+                return fileCache.size();
+            }
+            return 0;
+        }
+    }
+
+    // SAK: Part of fix for 3168263. The fileCache contains
+    // SortableFiles, so when finding a file in the list we need to
+    // first create a sortable file.
+    public boolean contains(final File o) {
+        synchronized(fileCacheLock) {
+            if (fileCache != null) {
+                return fileCache.contains(new SortableFile(o));
+            }
+            return false;
+        }
+    }
+
+    public int indexOf(final File o) {
+        synchronized(fileCacheLock) {
+            if (fileCache != null) {
+                final boolean isAscending = fSortNames ? fSortAscending[0] : fSortAscending[1];
+                final int row = fileCache.indexOf(new SortableFile(o));
+                return isAscending ? row : fileCache.size() - row - 1;
+            }
+            return 0;
+        }
+    }
+
+    // AbstractListModel interface
+    public Object getElementAt(final int row) {
+        return getValueAt(row, 0);
+    }
+
+    // AbstractTableModel interface
+
+    public Object getValueAt(int row, final int col) {
+        if (row < 0 || col < 0) return null;
+        final boolean isAscending = fSortNames ? fSortAscending[0] : fSortAscending[1];
+        synchronized(fileCacheLock) {
+            if (fileCache != null) {
+                if (!isAscending) row = fileCache.size() - row - 1;
+                return fileCache.elementAt(row).getValueAt(col);
+            }
+            return null;
+        }
+    }
+
+    // PENDING(jeff) - implement
+    public void intervalAdded(final ListDataEvent e) {
+    }
+
+    // PENDING(jeff) - implement
+    public void intervalRemoved(final ListDataEvent e) {
+    }
+
+    protected void sort(final Vector<Object> v) {
+        if (fSortNames) sSortNames.quickSort(v, 0, v.size() - 1);
+        else sSortDates.quickSort(v, 0, v.size() - 1);
+    }
+
+    // Liberated from the 1.1 SortDemo
+    //
+    // This is a generic version of C.A.R Hoare's Quick Sort
+    // algorithm. This will handle arrays that are already
+    // sorted, and arrays with duplicate keys.<BR>
+    //
+    // If you think of a one dimensional array as going from
+    // the lowest index on the left to the highest index on the right
+    // then the parameters to this function are lowest index or
+    // left and highest index or right. The first time you call
+    // this function it will be with the parameters 0, a.length - 1.
+    //
+    // @param a an integer array
+    // @param lo0 left boundary of array partition
+    // @param hi0 right boundary of array partition
+    abstract class QuickSort {
+        final void quickSort(final Vector<Object> v, final int lo0, final int hi0) {
+            int lo = lo0;
+            int hi = hi0;
+            SortableFile mid;
+
+            if (hi0 > lo0) {
+                // Arbitrarily establishing partition element as the midpoint of
+                // the array.
+                mid = (SortableFile)v.elementAt((lo0 + hi0) / 2);
+
+                // loop through the array until indices cross
+                while (lo <= hi) {
+                    // find the first element that is greater than or equal to
+                    // the partition element starting from the left Index.
+                    //
+                    // Nasty to have to cast here. Would it be quicker
+                    // to copy the vectors into arrays and sort the arrays?
+                    while ((lo < hi0) && lt((SortableFile)v.elementAt(lo), mid)) {
+                        ++lo;
+                    }
+
+                    // find an element that is smaller than or equal to
+                    // the partition element starting from the right Index.
+                    while ((hi > lo0) && lt(mid, (SortableFile)v.elementAt(hi))) {
+                        --hi;
+                    }
+
+                    // if the indexes have not crossed, swap
+                    if (lo <= hi) {
+                        swap(v, lo, hi);
+                        ++lo;
+                        --hi;
+                    }
+                }
+
+                // If the right index has not reached the left side of array
+                // must now sort the left partition.
+                if (lo0 < hi) {
+                    quickSort(v, lo0, hi);
+                }
+
+                // If the left index has not reached the right side of array
+                // must now sort the right partition.
+                if (lo < hi0) {
+                    quickSort(v, lo, hi0);
+                }
+
+            }
+        }
+
+        private final void swap(final Vector<Object> a, final int i, final int j) {
+            final Object T = a.elementAt(i);
+            a.setElementAt(a.elementAt(j), i);
+            a.setElementAt(T, j);
+        }
+
+        protected abstract boolean lt(SortableFile a, SortableFile b);
+    }
+
+    class QuickSortNames extends QuickSort {
+        protected boolean lt(final SortableFile a, final SortableFile b) {
+            final String aLower = a.fName.toLowerCase();
+            final String bLower = b.fName.toLowerCase();
+            return aLower.compareTo(bLower) < 0;
+        }
+    }
+
+    class QuickSortDates extends QuickSort {
+        protected boolean lt(final SortableFile a, final SortableFile b) {
+            return a.fDateValue < b.fDateValue;
+        }
+    }
+
+    // for speed in sorting, displaying
+    class SortableFile /* extends FileView */{
+        File fFile;
+        String fName;
+        long fDateValue;
+        Date fDate;
+
+        SortableFile(final File f) {
+            fFile = f;
+            fName = fFile.getName();
+            fDateValue = fFile.lastModified();
+            fDate = new Date(fDateValue);
+        }
+
+        public Object getValueAt(final int col) {
+            if (col == 0) return fFile;
+            return fDate;
+        }
+
+        public boolean equals(final Object other) {
+            final SortableFile otherFile = (SortableFile)other;
+            return otherFile.fFile.equals(fFile);
+        }
+    }
+
+    class LoadFilesThread extends Thread {
+        Vector<Runnable> queuedTasks = new Vector<Runnable>();
+        File currentDirectory = null;
+        int fid;
+
+        public LoadFilesThread(final File currentDirectory, final int fid) {
+            super("Aqua L&F File Loading Thread");
+            this.currentDirectory = currentDirectory;
+            this.fid = fid;
+        }
+
+        public void run() {
+            final Vector<DoChangeContents> runnables = new Vector<DoChangeContents>(10);
+            final FileSystemView fileSystem = filechooser.getFileSystemView();
+
+            final File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled());
+
+            final Vector<Object> acceptsList = new Vector<Object>();
+
+            for (final File element : list) {
+                // Return all files to the file chooser. The UI will disable or enable
+                // the file name if the current filter approves.
+                acceptsList.addElement(new SortableFile(element));
+            }
+
+            // Sort based on settings.
+            sort(acceptsList);
+
+            // Don't separate directories from files
+            Vector<SortableFile> chunk = new Vector<SortableFile>(10);
+            final int listSize = acceptsList.size();
+            // run through list grabbing file/dirs in chunks of ten
+            for (int i = 0; i < listSize;) {
+                SortableFile f;
+                for (int j = 0; j < 10 && i < listSize; j++, i++) {
+                    f = (SortableFile)acceptsList.elementAt(i);
+                    chunk.addElement(f);
+                }
+                final DoChangeContents runnable = new DoChangeContents(chunk, fid);
+                runnables.addElement(runnable);
+                SwingUtilities.invokeLater(runnable);
+                chunk = new Vector<SortableFile>(10);
+                if (isInterrupted()) {
+                    // interrupted, cancel all runnables
+                    cancelRunnables(runnables);
+                    return;
+                }
+            }
+
+            synchronized (fileCacheLock) {
+                for (final Runnable r : queuedTasks) {
+                    SwingUtilities.invokeLater(r);
+                }
+            }
+        }
+
+        public void cancelRunnables(final Vector<DoChangeContents> runnables) {
+            for (int i = 0; i < runnables.size(); i++) {
+                runnables.elementAt(i).cancel();
+            }
+        }
+    }
+
+    class DoChangeContents implements Runnable {
+        private Vector<SortableFile> contentFiles;
+        private boolean doFire = true;
+        private final Object lock = new Object();
+        private final int fid;
+
+        public DoChangeContents(final Vector<SortableFile> files, final int fid) {
+            this.contentFiles = files;
+            this.fid = fid;
+        }
+
+        synchronized void cancel() {
+            synchronized(lock) {
+                doFire = false;
+            }
+        }
+
+        public void run() {
+            if (fetchID == fid) {
+                synchronized(lock) {
+                    if (doFire) {
+                        synchronized(fileCacheLock) {
+                            if (fileCache != null) {
+                                for (int i = 0; i < contentFiles.size(); i++) {
+                                    fileCache.addElement(contentFiles.elementAt(i));
+                                    fireTableRowsInserted(i, i);
+                                }
+                            }
+                        }
+                    }
+                    contentFiles = null;
+                    directories = null;
+                }
+            }
+        }
+    }
+
+    final QuickSortNames sSortNames = new QuickSortNames();
+    final QuickSortDates sSortDates = new QuickSortDates();
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaFileView.java b/jdk/src/macosx/classes/com/apple/laf/AquaFileView.java
new file mode 100644
index 0000000..258b10b
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaFileView.java
@@ -0,0 +1,341 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.io.*;
+import java.security.PrivilegedAction;
+import java.util.*;
+import java.util.Map.Entry;
+
+import javax.swing.Icon;
+import javax.swing.filechooser.FileView;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+class AquaFileView extends FileView {
+    private static final boolean DEBUG = false;
+
+    private static final int UNINITALIZED_LS_INFO = -1;
+
+    // Constants from LaunchServices.h
+    static final int kLSItemInfoIsPlainFile        = 0x00000001; /* Not a directory, volume, or symlink*/
+    static final int kLSItemInfoIsPackage          = 0x00000002; /* Packaged directory*/
+    static final int kLSItemInfoIsApplication      = 0x00000004; /* Single-file or packaged application*/
+    static final int kLSItemInfoIsContainer        = 0x00000008; /* Directory (includes packages) or volume*/
+    static final int kLSItemInfoIsAliasFile        = 0x00000010; /* Alias file (includes sym links)*/
+    static final int kLSItemInfoIsSymlink          = 0x00000020; /* UNIX sym link*/
+    static final int kLSItemInfoIsInvisible        = 0x00000040; /* Invisible by any known mechanism*/
+    static final int kLSItemInfoIsNativeApp        = 0x00000080; /* Carbon or Cocoa native app*/
+    static final int kLSItemInfoIsClassicApp       = 0x00000100; /* CFM/68K Classic app*/
+    static final int kLSItemInfoAppPrefersNative   = 0x00000200; /* Carbon app that prefers to be launched natively*/
+    static final int kLSItemInfoAppPrefersClassic  = 0x00000400; /* Carbon app that prefers to be launched in Classic*/
+    static final int kLSItemInfoAppIsScriptable    = 0x00000800; /* App can be scripted*/
+    static final int kLSItemInfoIsVolume           = 0x00001000; /* Item is a volume*/
+    static final int kLSItemInfoExtensionIsHidden  = 0x00100000; /* Item has a hidden extension*/
+
+    static {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osxui"));
+    }
+
+    // TODO: Un-comment this out when the native version exists
+    //private static native String getNativePathToRunningJDKBundle();
+    private static native String getNativePathToSharedJDKBundle();
+
+    private static native String getNativeMachineName();
+    private static native String getNativeDisplayName(final byte[] pathBytes, final boolean isDirectory);
+    private static native int getNativeLSInfo(final byte[] pathBytes, final boolean isDirectory);
+    private static native String getNativePathForResolvedAlias(final byte[] absolutePath, final boolean isDirectory);
+
+    static final RecyclableSingleton<String> machineName = new RecyclableSingleton<String>() {
+        @Override
+        protected String getInstance() {
+            return getNativeMachineName();
+        }
+    };
+    private static String getMachineName() {
+        return machineName.get();
+    }
+
+    protected static String getPathToRunningJDKBundle() {
+        // TODO: Return empty string for now
+        return "";//getNativePathToRunningJDKBundle();
+    }
+
+    protected static String getPathToSharedJDKBundle() {
+        return getNativePathToSharedJDKBundle();
+    }
+
+    static class FileInfo {
+        final boolean isDirectory;
+        final String absolutePath;
+        byte[] pathBytes;
+
+        String displayName;
+        Icon icon;
+        int launchServicesInfo = UNINITALIZED_LS_INFO;
+
+        FileInfo(final File file){
+            isDirectory = file.isDirectory();
+            absolutePath = file.getAbsolutePath();
+            try {
+                pathBytes = absolutePath.getBytes("UTF-8");
+            } catch (final UnsupportedEncodingException e) {
+                pathBytes = new byte[0];
+            }
+        }
+    }
+
+    final int MAX_CACHED_ENTRIES = 256;
+    protected final Map<File, FileInfo> cache = new LinkedHashMap<File, FileInfo>(){
+        protected boolean removeEldestEntry(final Entry<File, FileInfo> eldest) {
+            return size() > MAX_CACHED_ENTRIES;
+        }
+    };
+
+    FileInfo getFileInfoFor(final File file) {
+        final FileInfo info = cache.get(file);
+        if (info != null) return info;
+        final FileInfo newInfo = new FileInfo(file);
+        cache.put(file, newInfo);
+        return newInfo;
+    }
+
+
+    final AquaFileChooserUI fFileChooserUI;
+    public AquaFileView(final AquaFileChooserUI fileChooserUI) {
+        fFileChooserUI = fileChooserUI;
+    }
+
+    String _directoryDescriptionText() {
+        return fFileChooserUI.directoryDescriptionText;
+    }
+
+    String _fileDescriptionText() {
+        return fFileChooserUI.fileDescriptionText;
+    }
+
+    boolean _packageIsTraversable() {
+        return fFileChooserUI.fPackageIsTraversable == AquaFileChooserUI.kOpenAlways;
+    }
+
+    boolean _applicationIsTraversable() {
+        return fFileChooserUI.fApplicationIsTraversable == AquaFileChooserUI.kOpenAlways;
+    }
+
+    public String getName(final File f) {
+        final FileInfo info = getFileInfoFor(f);
+        if (info.displayName != null) return info.displayName;
+
+        final String nativeDisplayName = getNativeDisplayName(info.pathBytes, info.isDirectory);
+        if (nativeDisplayName != null) {
+            info.displayName = nativeDisplayName;
+            return nativeDisplayName;
+        }
+
+        final String displayName = f.getName();
+        if (f.isDirectory() && fFileChooserUI.getFileChooser().getFileSystemView().isRoot(f)) {
+            final String localMachineName = getMachineName();
+            info.displayName = localMachineName;
+            return localMachineName;
+        }
+
+        info.displayName = displayName;
+        return displayName;
+    }
+
+    public String getDescription(final File f) {
+        return f.getName();
+    }
+
+    public String getTypeDescription(final File f) {
+        if (f.isDirectory()) return _directoryDescriptionText();
+        return _fileDescriptionText();
+    }
+
+    public Icon getIcon(final File f) {
+        final FileInfo info = getFileInfoFor(f);
+        if (info.icon != null) return info.icon;
+
+        if (f == null) {
+            info.icon = AquaIcon.SystemIcon.getDocumentIconUIResource();
+        } else {
+            // Look for the document's icon
+            final AquaIcon.FileIcon fileIcon = new AquaIcon.FileIcon(f);
+            info.icon = fileIcon;
+            if (!fileIcon.hasIconRef()) {
+                // Fall back on the default icons
+                if (f.isDirectory()) {
+                    if (fFileChooserUI.getFileChooser().getFileSystemView().isRoot(f)) {
+                        info.icon = AquaIcon.SystemIcon.getComputerIconUIResource();
+                    } else if (f.getParent() == null || f.getParent().equals("/")) {
+                        info.icon = AquaIcon.SystemIcon.getHardDriveIconUIResource();
+                    } else {
+                        info.icon = AquaIcon.SystemIcon.getFolderIconUIResource();
+                    }
+                } else {
+                    info.icon = AquaIcon.SystemIcon.getDocumentIconUIResource();
+                }
+            }
+        }
+
+        return info.icon;
+    }
+
+    // aliases are traversable though they aren't directories
+    public Boolean isTraversable(final File f) {
+        if (f.isDirectory()) {
+            // Doesn't matter if it's a package or app, because they're traversable
+            if (_packageIsTraversable() && _applicationIsTraversable()) {
+                return Boolean.TRUE;
+            } else if (!_packageIsTraversable() && !_applicationIsTraversable()) {
+                if (isPackage(f) || isApplication(f)) return Boolean.FALSE;
+            } else if (!_applicationIsTraversable()) {
+                if (isApplication(f)) return Boolean.FALSE;
+            } else if (!_packageIsTraversable()) {
+                // [3101730] All applications are packages, but not all packages are applications.
+                if (isPackage(f) && !isApplication(f)) return Boolean.FALSE;
+            }
+
+            // We're allowed to traverse it
+            return Boolean.TRUE;
+        }
+
+        if (isAlias(f)) {
+            final File realFile = resolveAlias(f);
+            return realFile.isDirectory() ? Boolean.TRUE : Boolean.FALSE;
+        }
+
+        return Boolean.FALSE;
+    }
+
+    int getLSInfoFor(final File f) {
+        final FileInfo info = getFileInfoFor(f);
+
+        if (info.launchServicesInfo == UNINITALIZED_LS_INFO) {
+            info.launchServicesInfo = getNativeLSInfo(info.pathBytes, info.isDirectory);
+        }
+
+        return info.launchServicesInfo;
+    }
+
+    boolean isAlias(final File f) {
+        final int lsInfo = getLSInfoFor(f);
+        return ((lsInfo & kLSItemInfoIsAliasFile) != 0) && ((lsInfo & kLSItemInfoIsSymlink) == 0);
+    }
+
+    boolean isApplication(final File f) {
+        return (getLSInfoFor(f) & kLSItemInfoIsApplication) != 0;
+    }
+
+    boolean isPackage(final File f) {
+        return (getLSInfoFor(f) & kLSItemInfoIsPackage) != 0;
+    }
+
+    /**
+     * Things that need to be handled:
+     * -Change getFSRef to use CFURLRef instead of FSPathMakeRef
+     * -Use the HFS-style path from CFURLRef in resolveAlias() to avoid
+     *      path length limitations
+     * -In resolveAlias(), simply resolve immediately if this is an alias
+     */
+
+    /**
+     * Returns the actual file represented by this object.  This will
+     * resolve any aliases in the path, including this file if it is an
+     * alias.  No alias resolution requiring user interaction (e.g.
+     * mounting servers) will occur.  Note that aliases to servers may
+     * take a significant amount of time to resolve.  This method
+     * currently does not have any provisions for a more fine-grained
+     * timeout for alias resolution beyond that used by the system.
+     *
+     * In the event of a path that does not contain any aliases, or if the file
+     *  does not exist, this method will return the file that was passed in.
+     *    @return    The canonical path to the file
+     *    @throws    IOException    If an I/O error occurs while attempting to
+     *                            construct the path
+     */
+    File resolveAlias(final File mFile) {
+        // If the file exists and is not an alias, there aren't
+        // any aliases along its path, so the standard version
+        // of getCanonicalPath() will work.
+        if (mFile.exists() && !isAlias(mFile)) {
+            if (DEBUG) System.out.println("not an alias");
+            return mFile;
+        }
+
+        // If it doesn't exist, either there's an alias in the
+        // path or this is an alias.  Traverse the path and
+        // resolve all aliases in it.
+        final LinkedList<String> components = getPathComponents(mFile);
+        if (components == null) {
+            if (DEBUG) System.out.println("getPathComponents is null ");
+            return mFile;
+        }
+
+        File file = new File("/");
+        for (final String nextComponent : components) {
+            file = new File(file, nextComponent);
+            final FileInfo info = getFileInfoFor(file);
+
+            // If any point along the way doesn't exist,
+            // just return the file.
+            if (!file.exists()) { return mFile; }
+
+            if (isAlias(file)) {
+                // Resolve it!
+                final String path = getNativePathForResolvedAlias(info.pathBytes, info.isDirectory);
+
+                // <rdar://problem/3582601> If the alias doesn't resolve (on a non-existent volume, for example)
+                // just return the file.
+                if (path == null) return mFile;
+
+                file = new File(path);
+            }
+        }
+
+        return file;
+    }
+
+    /**
+     * Returns a linked list of Strings consisting of the components of
+     * the path of this file, in order, including the filename as the
+     * last element.  The first element in the list will be the first
+     * directory in the path, or "".
+     *    @return A linked list of the components of this file's path
+     */
+    private static LinkedList<String> getPathComponents(final File mFile) {
+        final LinkedList<String> componentList = new LinkedList<String>();
+        String parent;
+
+        File file = new File(mFile.getAbsolutePath());
+        componentList.add(0, file.getName());
+        while ((parent = file.getParent()) != null) {
+            file = new File(parent);
+            componentList.add(0, file.getName());
+        }
+        return componentList;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaFocus.java b/jdk/src/macosx/classes/com/apple/laf/AquaFocus.java
new file mode 100644
index 0000000..d21f348
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaFocus.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//
+//  AquaFocus.java
+//  Copyright (c) 2009 Apple Inc. All rights reserved.
+//
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+
+import sun.java2d.*;
+import apple.laf.JRSUIFocus;
+
+import com.apple.laf.AquaUtils.Painter;
+
+public class AquaFocus {
+    interface Drawable {
+        public void draw(final Graphics2D sg2d);
+    }
+
+    static boolean paintFocus(final Graphics g, final Drawable drawable) {
+        // TODO: requires OSXSurfaceData
+        return false;
+        /*if (!(g instanceof SunGraphics2D)) return false;
+        final SunGraphics2D sg2d = (SunGraphics2D)g;
+
+        final SurfaceData surfaceData = sg2d.getSurfaceData();
+        if (!(surfaceData instanceof OSXSurfaceData)) return false;
+
+        try {
+            ((OSXSurfaceData)surfaceData).performCocoaDrawing(sg2d, new OSXSurfaceData.CGContextDrawable() {
+                @Override
+                public void drawIntoCGContext(final long cgContext) {
+                    final JRSUIFocus focus = new JRSUIFocus(cgContext);
+                    focus.beginFocus(JRSUIFocus.RING_BELOW);
+                    drawable.draw(sg2d);
+                    focus.endFocus();
+                }
+            });
+        } finally {
+            sg2d.dispose();
+        }
+        return true;*/
+    }
+
+    public static Icon createFocusedIcon(final Icon tmpIcon, final Component c, final int slack) {
+        return new FocusedIcon(tmpIcon, slack);
+    }
+
+/* -- disabled until we can get the real JRSUI focus painter working
+
+    static class FocusedIcon implements Icon {
+        final Icon icon;
+        final int slack;
+
+        public FocusedIcon(final Icon icon, final int slack) {
+            this.icon = icon;
+            this.slack = slack;
+        }
+
+        @Override
+        public int getIconHeight() {
+            return icon.getIconHeight() + slack + slack;
+        }
+
+        @Override
+        public int getIconWidth() {
+            return icon.getIconWidth() + slack + slack;
+        }
+
+        @Override
+        public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
+            final boolean painted = paintFocus(g, new Drawable() {
+                @Override
+                public void draw(SunGraphics2D sg2d) {
+                    icon.paintIcon(c, sg2d, x + slack, y + slack);
+                }
+            });
+            if (!painted) {
+                icon.paintIcon(c, g, x + slack, y + slack);
+            }
+        }
+    }
+ */
+
+    static class FocusedIcon extends AquaUtils.ShadowBorder implements Icon {
+        final Icon icon;
+        final int slack;
+
+        public FocusedIcon(final Icon icon, final int slack) {
+            super(
+                new Painter() {
+                    public void paint(Graphics g, int x, int y, int w, int h) {
+                        Graphics2D imgG = (Graphics2D)g;
+                        imgG.setComposite(AlphaComposite.Src);
+                        imgG.setColor(UIManager.getColor("Focus.color"));
+                        imgG.fillRect(x, y, w - (slack * 2), h - (slack * 2));
+                        imgG.setComposite(AlphaComposite.DstAtop);
+                        icon.paintIcon(null, imgG, x, y);
+                    }
+                },
+                new Painter() {
+                    public void paint(Graphics g, int x, int y, int w, int h) {
+                        ((Graphics2D)g).setComposite(AlphaComposite.SrcAtop);
+                        icon.paintIcon(null, g, x, y);
+                    }
+                },
+                slack, slack, 0.0f, 1.8f, 7
+            );
+            this.icon = icon;
+            this.slack = slack;
+        }
+
+        @Override
+        public int getIconHeight() {
+            return icon.getIconHeight() + slack + slack;
+        }
+
+        @Override
+        public int getIconWidth() {
+            return icon.getIconWidth() + slack + slack;
+        }
+
+        @Override
+        public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
+            paintBorder(c, g, x, y, getIconWidth(), getIconHeight());
+            icon.paintIcon(c, g, x + slack, y + slack);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaFocusHandler.java b/jdk/src/macosx/classes/com/apple/laf/AquaFocusHandler.java
new file mode 100644
index 0000000..4ce9c38
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaFocusHandler.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.plaf.UIResource;
+
+/**
+ * This class is used by the text components, AquaEditorPaneUI, AquaTextAreaUI, AquaTextFieldUI and AquaTextPaneUI to control painting of the
+ * component's border.  NOTE: It is assumed that this handler is added to components that extend JComponent.
+ */
+public class AquaFocusHandler implements FocusListener, PropertyChangeListener {
+    // Flag to help focusGained() determine whether the origin focus loss was due to a temporary focus loss or not.
+    private boolean wasTemporary = false;
+
+    // Flag to track when a border needs a repaint due to a window becoming activate/inactive.
+    private boolean repaintBorder = false;
+
+    protected static final String FRAME_ACTIVE_PROPERTY = "Frame.active";
+
+    public void focusGained(final FocusEvent ev) {
+        // If we gained focus and it wasn't due to a previous temporary focus loss
+        // or the frame became active again, then repaint the border on the component.
+        if (!wasTemporary || repaintBorder) {
+            AquaBorder.repaintBorder((JComponent)ev.getSource());
+            repaintBorder = false;
+        }
+        wasTemporary = false;
+    }
+
+    public void focusLost(final FocusEvent ev) {
+        wasTemporary = ev.isTemporary();
+
+        // If we lost focus due to a permanent focus loss then repaint the border on the component.
+        if (!wasTemporary) {
+            AquaBorder.repaintBorder((JComponent)ev.getSource());
+        }
+    }
+
+    public void propertyChange(final PropertyChangeEvent ev) {
+        if (!FRAME_ACTIVE_PROPERTY.equals(ev.getPropertyName())) return;
+
+        if (Boolean.TRUE.equals(ev.getNewValue())) {
+            // The FRAME_ACTIVE_PROPERTY change event is sent before a component gains focus.
+            // We set a flag to help the focusGained() determine when they should be repainting
+            // the components focus.
+            repaintBorder = true;
+        } else if (wasTemporary) {
+            // The FRAME_ACTIVE_PROPERTY change event is sent after a component loses focus.
+            // We use the wasTemporary flag to determine if we need to repaint the border.
+            AquaBorder.repaintBorder((JComponent)ev.getSource());
+        }
+    }
+
+    protected static boolean isActive(final JComponent c) {
+        if (c == null) return true;
+        final Object activeObj = c.getClientProperty(AquaFocusHandler.FRAME_ACTIVE_PROPERTY);
+        if (Boolean.FALSE.equals(activeObj)) return false;
+        return true;
+    }
+
+    static final PropertyChangeListener REPAINT_LISTENER = new PropertyChangeListener() {
+        public void propertyChange(final PropertyChangeEvent evt) {
+            final Object source = evt.getSource();
+            if (source instanceof JComponent) {
+                ((JComponent)source).repaint();
+            }
+        }
+    };
+
+    protected static void install(final JComponent c) {
+        c.addPropertyChangeListener(FRAME_ACTIVE_PROPERTY, REPAINT_LISTENER);
+    }
+
+    protected static void uninstall(final JComponent c) {
+        c.removePropertyChangeListener(FRAME_ACTIVE_PROPERTY, REPAINT_LISTENER);
+    }
+
+    static void swapSelectionColors(final String prefix, final JTree c, final Object value) {
+        // <rdar://problem/8166173> JTree: selection color does not dim when window becomes inactive
+        // TODO inject our colors into the DefaultTreeCellRenderer
+    }
+
+    static void swapSelectionColors(final String prefix, final JTable c, final Object value) {
+        if (!isComponentValid(c)) return;
+
+        final Color bg = c.getSelectionBackground();
+        final Color fg = c.getSelectionForeground();
+        if (!(bg instanceof UIResource) || !(fg instanceof UIResource)) return;
+
+        if (Boolean.FALSE.equals(value)) {
+            setSelectionColors(c, "Table.selectionInactiveForeground", "Table.selectionInactiveBackground");
+            return;
+        }
+
+        if (Boolean.TRUE.equals(value)) {
+            setSelectionColors(c, "Table.selectionForeground", "Table.selectionBackground");
+            return;
+        }
+    }
+
+    static void setSelectionColors(final JTable c, final String fgName, final String bgName) {
+        c.setSelectionForeground(UIManager.getColor(fgName));
+        c.setSelectionBackground(UIManager.getColor(bgName));
+    }
+
+    static void swapSelectionColors(final String prefix, final JList c, final Object value) {
+        if (!isComponentValid(c)) return;
+
+        final Color bg = c.getSelectionBackground();
+        final Color fg = c.getSelectionForeground();
+        if (!(bg instanceof UIResource) || !(fg instanceof UIResource)) return;
+
+        if (Boolean.FALSE.equals(value)) {
+            setSelectionColors(c, "List.selectionInactiveForeground", "List.selectionInactiveBackground");
+            return;
+        }
+
+        if (Boolean.TRUE.equals(value)) {
+            setSelectionColors(c, "List.selectionForeground", "List.selectionBackground");
+            return;
+        }
+    }
+
+    static void setSelectionColors(final JList c, final String fgName, final String bgName) {
+        c.setSelectionForeground(UIManager.getColor(fgName));
+        c.setSelectionBackground(UIManager.getColor(bgName));
+    }
+
+    static boolean isComponentValid(final JComponent c) {
+        if (c == null) return false;
+        final Window window = SwingUtilities.getWindowAncestor(c);
+        if (window == null) return false;
+        return true;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaFonts.java b/jdk/src/macosx/classes/com/apple/laf/AquaFonts.java
new file mode 100644
index 0000000..4924c12
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaFonts.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.Font;
+import java.awt.geom.AffineTransform;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.util.Map;
+
+import javax.swing.plaf.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaFonts {
+    private static final String MAC_DEFAULT_FONT_NAME = "Lucida Grande";
+
+    private static final RecyclableSingleton<FontUIResource> lucida9Pt = new RecyclableSingleton<FontUIResource>() {
+        @Override
+        protected FontUIResource getInstance() {
+            return new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.PLAIN, 9);
+        }
+    };
+    //private static final FontUIResource lucida10Pt = new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.PLAIN, 10);
+    private static final RecyclableSingleton<FontUIResource> lucida11Pt = new RecyclableSingleton<FontUIResource>() {
+        @Override
+        protected FontUIResource getInstance() {
+            return new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.PLAIN, 11);
+        }
+    };
+    private static final RecyclableSingleton<FontUIResource> lucida12Pt = new RecyclableSingleton<FontUIResource>() {
+        @Override
+        protected FontUIResource getInstance() {
+            return new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.PLAIN, 12);
+        }
+    };
+    private static final RecyclableSingleton<FontUIResource> lucida13Pt = new RecyclableSingleton<FontUIResource>() {
+        @Override
+        protected FontUIResource getInstance() {
+            return new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.PLAIN, 13);
+        }
+    };
+    private static final RecyclableSingleton<FontUIResource> lucida14Pt = new RecyclableSingleton<FontUIResource>() {
+        @Override
+        protected FontUIResource getInstance() {
+            return new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.PLAIN, 14);
+        }
+    };
+
+    private static final RecyclableSingleton<FontUIResource> lucida13PtBold = new RecyclableSingleton<FontUIResource>() {
+        @Override
+        protected FontUIResource getInstance() {
+            return new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.BOLD, 13);
+        }
+    };
+    private static final RecyclableSingleton<FontUIResource> lucida14PtBold = new RecyclableSingleton<FontUIResource>() {
+        @Override
+        protected FontUIResource getInstance() {
+            return new DerivedUIResourceFont(MAC_DEFAULT_FONT_NAME, Font.BOLD, 14);
+        }
+    };
+
+    protected static FontUIResource getMiniControlTextFont() {
+        return lucida9Pt.get();
+    }
+
+    protected static FontUIResource getSmallControlTextFont() {
+        return lucida11Pt.get();
+    }
+
+    public static FontUIResource getControlTextFont() {
+        return lucida13Pt.get();
+    }
+
+    public static FontUIResource getControlTextSmallFont() {
+        return lucida11Pt.get();
+    }
+
+    public static FontUIResource getMenuFont() {
+        return lucida14Pt.get();
+    }
+
+    public static Font getDockIconFont() {
+        return lucida14PtBold.get();
+    }
+
+    public static FontUIResource getAlertHeaderFont() {
+        return lucida13PtBold.get();
+    }
+
+    public static FontUIResource getAlertMessageFont() {
+        return lucida11Pt.get();
+    }
+
+    public static FontUIResource getViewFont() {
+        return lucida12Pt.get();
+    }
+
+    /**
+     * All fonts derived from this type will also be of this type, and not a plain java.awt.Font
+     */
+    static class DerivedUIResourceFont extends FontUIResource implements UIResource {
+        public DerivedUIResourceFont(final Font font) {
+            super(font);
+        }
+
+        public DerivedUIResourceFont(final String name, final int style, final int size) {
+            super(name, style, size);
+        }
+
+        public Font deriveFont(final AffineTransform trans) {
+            return new DerivedUIResourceFont(super.deriveFont(trans));
+        }
+
+        public Font deriveFont(final float derivedSize) {
+            return new DerivedUIResourceFont(super.deriveFont(derivedSize));
+        }
+
+        public Font deriveFont(final int derivedStyle) {
+            return new DerivedUIResourceFont(super.deriveFont(derivedStyle));
+        }
+
+        public Font deriveFont(final int derivedStyle, final AffineTransform trans) {
+            return new DerivedUIResourceFont(super.deriveFont(derivedStyle, trans));
+        }
+
+        public Font deriveFont(final int derivedStyle, final float derivedSize) {
+            return new DerivedUIResourceFont(super.deriveFont(derivedStyle, derivedSize));
+        }
+
+        public Font deriveFont(final Map<? extends Attribute, ?> attributes) {
+            return new DerivedUIResourceFont(super.deriveFont(attributes));
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaGroupBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaGroupBorder.java
new file mode 100644
index 0000000..ab24677
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaGroupBorder.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.border.Border;
+
+import apple.laf.JRSUIConstants.Widget;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public abstract class AquaGroupBorder extends AquaBorder {
+    static final RecyclableSingletonFromDefaultConstructor<? extends Border> tabbedPaneGroupBorder = new RecyclableSingletonFromDefaultConstructor<TabbedPane>(TabbedPane.class);
+    public static Border getTabbedPaneGroupBorder() {
+        return tabbedPaneGroupBorder.get();
+    }
+
+    static final RecyclableSingletonFromDefaultConstructor<? extends Border> titleBorderGroupBorder = new RecyclableSingletonFromDefaultConstructor<Titled>(Titled.class);
+    public static Border getBorderForTitledBorder() {
+        return titleBorderGroupBorder.get();
+    }
+
+    static final RecyclableSingletonFromDefaultConstructor<? extends Border> titlelessGroupBorder = new RecyclableSingletonFromDefaultConstructor<Titleless>(Titleless.class);
+    public static Border getTitlelessBorder() {
+        return titlelessGroupBorder.get();
+    }
+
+    protected AquaGroupBorder(final SizeVariant sizeVariant) {
+        super(new SizeDescriptor(sizeVariant));
+        painter.state.set(Widget.FRAME_GROUP_BOX);
+    }
+
+    public void paintBorder(final Component c, final Graphics g, int x, int y, int width, int height) {
+        // sg2d.setColor(Color.MAGENTA);
+        // sg2d.drawRect(x, y, width - 1, height - 1);
+
+        final Insets internalInsets = sizeVariant.insets;
+        x += internalInsets.left;
+        y += internalInsets.top;
+        width -= (internalInsets.left + internalInsets.right);
+        height -= (internalInsets.top + internalInsets.bottom);
+
+        painter.paint(g, c, x, y, width, height);
+        // sg2d.setColor(Color.ORANGE);
+        // sg2d.drawRect(x, y, width, height);
+    }
+
+    protected static class TabbedPane extends AquaGroupBorder {
+        public TabbedPane() {
+            super(new SizeVariant().alterMargins(8, 12, 8, 12).alterInsets(5, 5, 7, 5));
+        }
+    }
+
+    protected static class Titled extends AquaGroupBorder {
+        public Titled() {
+            super(new SizeVariant().alterMargins(16, 20, 16, 20).alterInsets(16, 5, 4, 5));
+        }
+    }
+
+    protected static class Titleless extends AquaGroupBorder {
+        public Titleless() {
+            super(new SizeVariant().alterMargins(8, 12, 8, 12).alterInsets(3, 5, 1, 5));
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaHighlighter.java b/jdk/src/macosx/classes/com/apple/laf/AquaHighlighter.java
new file mode 100644
index 0000000..bdef431
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaHighlighter.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//  Based on 1.3.1's AquaHighlighter, with the main difference that an inactive selection should be gray
+//  rather than a darker version of the current highlight color.
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.UIResource;
+import javax.swing.text.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaHighlighter extends DefaultHighlighter implements UIResource {
+    static final RecyclableSingleton<LayerPainter> instance = new RecyclableSingleton<LayerPainter>() {
+        protected LayerPainter getInstance() {
+            return new AquaHighlightPainter(null);
+        }
+    };
+
+    protected static LayeredHighlighter.LayerPainter getInstance() {
+        return instance.get();
+    }
+
+    public static class AquaHighlightPainter extends DefaultHighlightPainter {
+        Color selectionColor;
+        Color disabledSelectionColor;
+
+        public AquaHighlightPainter(final Color c) {
+            super(c);
+        }
+
+        public Color getColor() {
+            return selectionColor == null ? super.getColor() : selectionColor;
+        }
+
+
+        protected Color getInactiveSelectionColor() {
+            if (disabledSelectionColor != null) return disabledSelectionColor;
+            return disabledSelectionColor = UIManager.getColor("TextComponent.selectionBackgroundInactive");
+        }
+
+        void setColor(final JTextComponent c) {
+            selectionColor = super.getColor();
+
+            if (selectionColor == null) selectionColor = c.getSelectionColor();
+
+            final Window owningWindow = SwingUtilities.getWindowAncestor(c);
+
+            // If window is not currently active selection color is a gray with RGB of (212, 212, 212).
+            if (owningWindow != null && !owningWindow.isActive()) {
+                selectionColor = getInactiveSelectionColor();
+            }
+
+            if (!c.hasFocus()) {
+                selectionColor = getInactiveSelectionColor();
+            }
+        }
+
+        public void paint(final Graphics g, final int offs0, final int offs1, final Shape bounds, final JTextComponent c) {
+            setColor(c);
+            super.paint(g, offs0, offs1, bounds, c);
+        }
+
+        public Shape paintLayer(final Graphics g, final int offs0, final int offs1, final Shape bounds, final JTextComponent c, final View view) {
+            setColor(c);
+            return super.paintLayer(g, offs0, offs1, bounds, c, view);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaIcon.java b/jdk/src/macosx/classes/com/apple/laf/AquaIcon.java
new file mode 100644
index 0000000..7ef8392
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaIcon.java
@@ -0,0 +1,301 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+
+import javax.swing.*;
+import javax.swing.plaf.*;
+
+import apple.laf.JRSUIConstants.Size;
+import apple.laf.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaIcon {
+    interface InvertableIcon extends Icon {
+        public Icon getInvertedIcon();
+    }
+
+    static UIResource getIconFor(final JRSUIControlSpec spec, final int width, final int height) {
+        return new CachableJRSUIIcon(width, height) {
+            public void initIconPainter(final AquaPainter<JRSUIState> painter) {
+                spec.initIconPainter(painter);
+            }
+        };
+    }
+
+    // converts an object that is an icon into an image so we can hand it off to AppKit
+    public static Image getImageForIcon(final Icon i) {
+        if (i instanceof ImageIcon) return ((ImageIcon)i).getImage();
+
+        final int w = i.getIconWidth();
+        final int h = i.getIconHeight();
+
+        if (w <= 0 || h <= 0) return null;
+
+        // This could be any kind of icon, so we need to make a buffer for it, draw it and then pass the new image off to appkit.
+        final BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+        final Graphics g = image.getGraphics();
+        i.paintIcon(null, g, 0, 0);
+        g.dispose();
+        return image;
+    }
+
+    public interface JRSUIControlSpec {
+        public void initIconPainter(final AquaPainter<? extends JRSUIState> painter);
+    }
+
+    static abstract class JRSUIIcon implements Icon, UIResource {
+        protected final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIState.getInstance());
+
+        public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
+            painter.paint(g, c, x, y, getIconWidth(), getIconHeight());
+        }
+    }
+
+    static abstract class DynamicallySizingJRSUIIcon extends JRSUIIcon {
+        protected final SizeDescriptor sizeDescriptor;
+        protected SizeVariant sizeVariant;
+
+        public DynamicallySizingJRSUIIcon(final SizeDescriptor sizeDescriptor) {
+            this.sizeDescriptor = sizeDescriptor;
+            this.sizeVariant = sizeDescriptor.regular;
+            initJRSUIState();
+        }
+
+        public abstract void initJRSUIState();
+
+        public int getIconHeight() {
+            return sizeVariant == null ? 0 : sizeVariant.h;
+        }
+
+        public int getIconWidth() {
+            return sizeVariant == null ? 0 : sizeVariant.w;
+        }
+
+        public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
+            final Size size = c instanceof JComponent ? AquaUtilControlSize.getUserSizeFrom((JComponent)c) : Size.REGULAR;
+            sizeVariant = sizeDescriptor.get(size);
+            painter.state.set(size);
+            super.paintIcon(c, g, x, y);
+        }
+    }
+
+    static abstract class CachingScalingIcon implements Icon, UIResource {
+        int width;
+        int height;
+        Image image;
+
+        public CachingScalingIcon(final int width, final int height) {
+            this.width = width;
+            this.height = height;
+        }
+
+        void setSize(final int width, final int height) {
+            this.width = width;
+            this.height = height;
+            this.image = null;
+        }
+
+        Image getImage() {
+            if (image != null) return image;
+
+            if (!GraphicsEnvironment.isHeadless()) {
+                image = getOptimizedImage();
+            }
+
+            return image;
+        }
+
+        private Image getOptimizedImage() {
+            final Image img = createImage();
+            // TODO: no RuntimeOptions for now
+            //if (RuntimeOptions.getRenderer(null) != RuntimeOptions.Sun) return img;
+            return getProgressiveOptimizedImage(img, getIconWidth(), getIconHeight());
+        }
+
+        static Image getProgressiveOptimizedImage(final Image img, final int w, final int h) {
+            if (img == null) return null;
+
+            final int halfImgW = img.getWidth(null) / 2;
+            final int halfImgH = img.getHeight(null) / 2;
+            if (w * 2 > halfImgW && h * 2 > halfImgH) return img;
+
+            final BufferedImage halfImage = new BufferedImage(halfImgW, halfImgH, BufferedImage.TYPE_INT_ARGB);
+            final Graphics g = halfImage.getGraphics();
+            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+            g.drawImage(img, 0, 0, halfImgW, halfImgH, null);
+            g.dispose();
+
+            return getProgressiveOptimizedImage(halfImage, w, h);
+        }
+
+        abstract Image createImage();
+
+        public boolean hasIconRef() {
+            return getImage() != null;
+        }
+
+        public void paintIcon(final Component c, Graphics g, final int x, final int y) {
+            g = g.create();
+
+            if (g instanceof Graphics2D) {
+                // improves icon rendering quality in Quartz
+                ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+            }
+
+            final Image myImage = getImage();
+            if (myImage != null) {
+                g.drawImage(myImage, x, y, getIconWidth(), getIconHeight(), null);
+            }
+
+            g.dispose();
+        }
+
+        public int getIconWidth() {
+            return width;
+        }
+
+        public int getIconHeight() {
+            return height;
+        }
+
+    }
+
+    static abstract class CachableJRSUIIcon extends CachingScalingIcon implements UIResource {
+        public CachableJRSUIIcon(final int width, final int height) {
+            super(width, height);
+        }
+
+        Image createImage() {
+            final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIState.getInstance());
+            initIconPainter(painter);
+
+            final BufferedImage img = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
+            final Graphics g = img.getGraphics();
+            g.setClip(new Rectangle(0, 0, getIconWidth(), getIconHeight()));
+            painter.paint(g, null, 0, 0, getIconWidth(), getIconHeight());
+            g.dispose();
+            return img;
+        }
+
+        public abstract void initIconPainter(final AquaPainter<JRSUIState> painter);
+    }
+
+    static class FileIcon extends CachingScalingIcon {
+        final File file;
+
+        public FileIcon(final File file, final int width, final int height) {
+            super(width, height);
+            this.file = file;
+        }
+
+        public FileIcon(final File file) {
+            this(file, 16, 16);
+        }
+
+        Image createImage() {
+            return AquaUtils.getCImageCreator().createImageOfFile(file.getAbsolutePath(), getIconWidth(), getIconHeight());
+        }
+    }
+
+    static class SystemIconSingleton extends RecyclableSingleton<SystemIcon> {
+        final String selector;
+
+        public SystemIconSingleton(String selector) {
+            this.selector = selector;
+        }
+
+        @Override
+        protected SystemIcon getInstance() {
+            return new SystemIcon(selector);
+        }
+    }
+
+    static class SystemIconUIResourceSingleton extends RecyclableSingleton<IconUIResource> {
+        final String selector;
+
+        public SystemIconUIResourceSingleton(String selector) {
+            this.selector = selector;
+        }
+
+        @Override
+        protected IconUIResource getInstance() {
+            return new IconUIResource(new SystemIcon(selector));
+        }
+    }
+
+    static class SystemIcon extends CachingScalingIcon {
+        private static final SystemIconUIResourceSingleton folderIcon = new SystemIconUIResourceSingleton("fldr");
+        static IconUIResource getFolderIconUIResource() { return folderIcon.get(); }
+
+        private static final SystemIconUIResourceSingleton openFolderIcon = new SystemIconUIResourceSingleton("ofld");
+        static IconUIResource getOpenFolderIconUIResource() { return openFolderIcon.get(); }
+
+        private static final SystemIconUIResourceSingleton desktopIcon = new SystemIconUIResourceSingleton("desk");
+        static IconUIResource getDesktopIconUIResource() { return desktopIcon.get(); }
+
+        private static final SystemIconUIResourceSingleton computerIcon = new SystemIconUIResourceSingleton("FNDR");
+        static IconUIResource getComputerIconUIResource() { return computerIcon.get(); }
+
+        private static final SystemIconUIResourceSingleton documentIcon = new SystemIconUIResourceSingleton("docu");
+        static IconUIResource getDocumentIconUIResource() { return documentIcon.get(); }
+
+        private static final SystemIconUIResourceSingleton hardDriveIcon = new SystemIconUIResourceSingleton("hdsk");
+        static IconUIResource getHardDriveIconUIResource() { return hardDriveIcon.get(); }
+
+        private static final SystemIconUIResourceSingleton floppyIcon = new SystemIconUIResourceSingleton("flpy");
+        static IconUIResource getFloppyIconUIResource() { return floppyIcon.get(); }
+
+        //private static final SystemIconUIResourceSingleton noteIcon = new SystemIconUIResourceSingleton("note");
+        //static IconUIResource getNoteIconUIResource() { return noteIcon.get(); }
+
+        private static final SystemIconSingleton caut = new SystemIconSingleton("caut");
+        static SystemIcon getCautionIcon() { return caut.get(); }
+
+        private static final SystemIconSingleton stop = new SystemIconSingleton("stop");
+        static SystemIcon getStopIcon() { return stop.get(); }
+
+        final String selector;
+
+        public SystemIcon(final String iconSelector, final int width, final int height) {
+            super(width, height);
+            selector = iconSelector;
+        }
+
+        public SystemIcon(final String iconSelector) {
+            this(iconSelector, 16, 16);
+        }
+
+        Image createImage() {
+            return AquaUtils.getCImageCreator().createSystemImageFromSelector(selector, getIconWidth(), getIconHeight());
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaImageFactory.java b/jdk/src/macosx/classes/com/apple/laf/AquaImageFactory.java
new file mode 100644
index 0000000..56f4a70
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaImageFactory.java
@@ -0,0 +1,486 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.security.PrivilegedAction;
+
+import javax.swing.*;
+import javax.swing.plaf.*;
+
+import sun.lwawt.macosx.LWCToolkit;
+import apple.laf.JRSUIConstants.AlignmentHorizontal;
+import apple.laf.JRSUIConstants.AlignmentVertical;
+import apple.laf.JRSUIConstants.Direction;
+import apple.laf.JRSUIConstants.State;
+import apple.laf.JRSUIConstants.Widget;
+import apple.laf.*;
+
+import com.apple.eio.FileManager;
+import com.apple.laf.AquaIcon.InvertableIcon;
+import com.apple.laf.AquaIcon.JRSUIControlSpec;
+import com.apple.laf.AquaIcon.SystemIcon;
+import com.apple.laf.AquaUtils.RecyclableObject;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaImageFactory {
+    public static IconUIResource getConfirmImageIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+
+        return new IconUIResource(new AquaIcon.CachingScalingIcon(kAlertIconSize, kAlertIconSize) {
+            Image createImage() {
+                return getThisApplicationsIcon(kAlertIconSize, kAlertIconSize);
+            }
+        });
+    }
+
+    public static IconUIResource getCautionImageIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return getAppIconCompositedOn(AquaIcon.SystemIcon.getCautionIcon());
+    }
+
+    public static IconUIResource getStopImageIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return getAppIconCompositedOn(AquaIcon.SystemIcon.getStopIcon());
+    }
+
+    public static IconUIResource getLockImageIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        if (JRSUIUtils.Images.shouldUseLegacySecurityUIPath()) {
+            final Image lockIcon = AquaUtils.getCImageCreator().createImageFromFile("/System/Library/CoreServices/SecurityAgent.app/Contents/Resources/Security.icns", kAlertIconSize, kAlertIconSize);
+            return getAppIconCompositedOn(lockIcon);
+        }
+
+        final Image lockIcon = Toolkit.getDefaultToolkit().getImage("NSImage://NSSecurity");
+        return getAppIconCompositedOn(lockIcon);
+    }
+
+    static Image getThisApplicationsIcon(final int width, final int height) {
+        final String path = getPathToThisApplication();
+
+        if (path == null) {
+            return getGenericJavaIcon();
+        }
+
+        if (path.endsWith("/Home/bin")) {
+            return getGenericJavaIcon();
+        }
+
+        if (path.startsWith("/usr/bin")) {
+            return getGenericJavaIcon();
+        }
+
+        return AquaUtils.getCImageCreator().createImageOfFile(path, height, width);
+    }
+
+    static Image getGenericJavaIcon() {
+        return java.security.AccessController.doPrivileged(new PrivilegedAction<Image>() {
+            public Image run() {
+                return com.apple.eawt.Application.getApplication().getDockIconImage();
+            }
+        });
+    }
+
+    static String getPathToThisApplication() {
+        return java.security.AccessController.doPrivileged(new PrivilegedAction<String>() {
+            public String run() {
+                return FileManager.getPathToApplicationBundle();
+            }
+        });
+    }
+
+    static IconUIResource getAppIconCompositedOn(final SystemIcon systemIcon) {
+        systemIcon.setSize(kAlertIconSize, kAlertIconSize);
+        return getAppIconCompositedOn(systemIcon.createImage());
+    }
+
+    private static final int kAlertIconSize = 64;
+    static IconUIResource getAppIconCompositedOn(final Image background) {
+        final double scaleFactor = 1.0; // revise for HiDPI
+
+        final int kAlertSubIconSize = (int)(kAlertIconSize * 0.5 * scaleFactor);
+        final int kAlertSubIconInset = (int)(kAlertIconSize * scaleFactor) - kAlertSubIconSize;
+        final Icon smallAppIconScaled = new AquaIcon.CachingScalingIcon(kAlertSubIconSize, kAlertSubIconSize) {
+            Image createImage() {
+                return getThisApplicationsIcon(kAlertSubIconSize, kAlertSubIconSize);
+            }
+        };
+
+        final BufferedImage image = new BufferedImage(kAlertIconSize, kAlertIconSize, BufferedImage.TYPE_INT_ARGB);
+        final Graphics g = image.getGraphics();
+        g.drawImage(background, 0, 0, (int)(kAlertIconSize * scaleFactor), (int)(kAlertIconSize * scaleFactor), null);
+        if (g instanceof Graphics2D) {
+            // improves icon rendering quality in Quartz
+            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+        }
+
+        smallAppIconScaled.paintIcon(null, g, kAlertSubIconInset, kAlertSubIconInset);
+        g.dispose();
+
+        return new IconUIResource(new ImageIcon(image));
+    }
+
+    public static IconUIResource getTreeFolderIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return AquaIcon.SystemIcon.getFolderIconUIResource();
+    }
+
+    public static IconUIResource getTreeOpenFolderIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return AquaIcon.SystemIcon.getOpenFolderIconUIResource();
+    }
+
+    public static IconUIResource getTreeDocumentIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return AquaIcon.SystemIcon.getDocumentIconUIResource();
+    }
+
+    public static UIResource getTreeExpandedIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return AquaIcon.getIconFor(new JRSUIControlSpec() {
+            public void initIconPainter(final AquaPainter<? extends JRSUIState> painter) {
+                painter.state.set(Widget.DISCLOSURE_TRIANGLE);
+                painter.state.set(State.ACTIVE);
+                painter.state.set(Direction.DOWN);
+                painter.state.set(AlignmentHorizontal.CENTER);
+                painter.state.set(AlignmentVertical.CENTER);
+            }
+        }, 20, 20);
+    }
+
+    public static UIResource getTreeCollapsedIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return AquaIcon.getIconFor(new JRSUIControlSpec() {
+            public void initIconPainter(final AquaPainter<? extends JRSUIState> painter) {
+                painter.state.set(Widget.DISCLOSURE_TRIANGLE);
+                painter.state.set(State.ACTIVE);
+                painter.state.set(Direction.RIGHT);
+                painter.state.set(AlignmentHorizontal.CENTER);
+                painter.state.set(AlignmentVertical.CENTER);
+            }
+        }, 20, 20);
+    }
+
+    public static UIResource getTreeRightToLeftCollapsedIcon() {
+        // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
+        return AquaIcon.getIconFor(new JRSUIControlSpec() {
+            public void initIconPainter(final AquaPainter<? extends JRSUIState> painter) {
+                painter.state.set(Widget.DISCLOSURE_TRIANGLE);
+                painter.state.set(State.ACTIVE);
+                painter.state.set(Direction.LEFT);
+                painter.state.set(AlignmentHorizontal.CENTER);
+                painter.state.set(AlignmentVertical.CENTER);
+            }
+        }, 20, 20);
+    }
+
+    static class NamedImageSingleton extends RecyclableSingleton<Image> {
+        final String namedImage;
+
+        NamedImageSingleton(final String namedImage) {
+            this.namedImage = namedImage;
+        }
+
+        @Override
+        protected Image getInstance() {
+            return Toolkit.getDefaultToolkit().getImage("NSImage://" + namedImage);
+        }
+    }
+
+    static class IconUIResourceSingleton extends RecyclableSingleton<IconUIResource> {
+        final NamedImageSingleton holder;
+
+        public IconUIResourceSingleton(final NamedImageSingleton holder) {
+            this.holder = holder;
+        }
+
+        @Override
+        protected IconUIResource getInstance() {
+            return new IconUIResource(new ImageIcon(holder.get()));
+        }
+    }
+
+    static class InvertableImageIcon extends ImageIcon implements InvertableIcon, UIResource {
+        Icon invertedImage;
+        public InvertableImageIcon(final Image image) {
+            super(image);
+        }
+
+        @Override
+        public Icon getInvertedIcon() {
+            if (invertedImage != null) return invertedImage;
+            return invertedImage = new IconUIResource(new ImageIcon(AquaUtils.generateLightenedImage(getImage(), 100)));
+        }
+    }
+
+    protected static final NamedImageSingleton northArrow = new NamedImageSingleton("NSMenuScrollUp");
+    protected static final IconUIResourceSingleton northArrowIcon = new IconUIResourceSingleton(northArrow);
+    protected static final NamedImageSingleton southArrow = new NamedImageSingleton("NSMenuScrollDown");
+    protected static final IconUIResourceSingleton southArrowIcon = new IconUIResourceSingleton(southArrow);
+    protected static final NamedImageSingleton westArrow = new NamedImageSingleton("NSMenuSubmenuLeft");
+    protected static final IconUIResourceSingleton westArrowIcon = new IconUIResourceSingleton(westArrow);
+    protected static final NamedImageSingleton eastArrow = new NamedImageSingleton("NSMenuSubmenu");
+    protected static final IconUIResourceSingleton eastArrowIcon = new IconUIResourceSingleton(eastArrow);
+
+    static Image getArrowImageForDirection(final int direction) {
+        switch(direction) {
+            case SwingConstants.NORTH: return northArrow.get();
+            case SwingConstants.SOUTH: return southArrow.get();
+            case SwingConstants.EAST: return eastArrow.get();
+            case SwingConstants.WEST: return westArrow.get();
+        }
+        return null;
+    }
+
+    static Icon getArrowIconForDirection(int direction) {
+        switch(direction) {
+            case SwingConstants.NORTH: return northArrowIcon.get();
+            case SwingConstants.SOUTH: return southArrowIcon.get();
+            case SwingConstants.EAST: return eastArrowIcon.get();
+            case SwingConstants.WEST: return westArrowIcon.get();
+        }
+        return null;
+    }
+
+    public static Icon getMenuArrowIcon() {
+        return new InvertableImageIcon(AquaUtils.generateLightenedImage(eastArrow.get(), 25));
+    }
+
+    public static Icon getMenuItemCheckIcon() {
+        return new InvertableImageIcon(AquaUtils.generateLightenedImage(Toolkit.getDefaultToolkit().getImage("NSImage://NSMenuItemSelection"), 25));
+    }
+
+    public static Icon getMenuItemDashIcon() {
+        return new InvertableImageIcon(AquaUtils.generateLightenedImage(Toolkit.getDefaultToolkit().getImage("NSImage://NSMenuMixedState"), 25));
+    }
+
+    public static class NineSliceMetrics {
+        public final int wCut, eCut, nCut, sCut;
+        public final int minW, minH;
+        public final boolean showMiddle, stretchH, stretchV;
+
+        public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut) {
+            this(minWidth, minHeight, westCut, eastCut, northCut, southCut, true);
+        }
+
+        public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean showMiddle) {
+            this(minWidth, minHeight, westCut, eastCut, northCut, southCut, showMiddle, true, true);
+        }
+
+        public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean showMiddle, final boolean stretchHorizontally, final boolean stretchVertically) {
+            this.wCut = westCut; this.eCut = eastCut; this.nCut = northCut; this.sCut = southCut;
+            this.minW = minWidth; this.minH = minHeight;
+            this.showMiddle = showMiddle; this.stretchH = stretchHorizontally; this.stretchV = stretchVertically;
+        }
+    }
+
+    /*
+     * A "paintable" which holds nine images, which represent a sliced up initial
+     * image that can be streched from its middles.
+     */
+    public static class SlicedImageControl {
+        final BufferedImage NW, N, NE;
+        final BufferedImage W, C, E;
+        final BufferedImage SW, S, SE;
+
+        final NineSliceMetrics metrics;
+
+        final int totalWidth, totalHeight;
+        final int centerColWidth, centerRowHeight;
+
+        public SlicedImageControl(final Image img, final int westCut, final int eastCut, final int northCut, final int southCut) {
+            this(img, westCut, eastCut, northCut, southCut, true);
+        }
+
+        public SlicedImageControl(final Image img, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean useMiddle) {
+            this(img, westCut, eastCut, northCut, southCut, useMiddle, true, true);
+        }
+
+        public SlicedImageControl(final Image img, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean useMiddle, final boolean stretchHorizontally, final boolean stretchVertically) {
+            this(img, new NineSliceMetrics(img.getWidth(null), img.getHeight(null), westCut, eastCut, northCut, southCut, useMiddle, stretchHorizontally, stretchVertically));
+        }
+
+        public SlicedImageControl(final Image img, final NineSliceMetrics metrics) {
+            this.metrics = metrics;
+
+            if (img.getWidth(null) != metrics.minW || img.getHeight(null) != metrics.minH) {
+                throw new IllegalArgumentException("SlicedImageControl: template image and NineSliceMetrics don't agree on minimum dimensions");
+            }
+
+            totalWidth = metrics.minW;
+            totalHeight = metrics.minH;
+            centerColWidth = totalWidth - metrics.wCut - metrics.eCut;
+            centerRowHeight = totalHeight - metrics.nCut - metrics.sCut;
+
+            NW = createSlice(img, 0, 0, metrics.wCut, metrics.nCut);
+            N = createSlice(img, metrics.wCut, 0, centerColWidth, metrics.nCut);
+            NE = createSlice(img, totalWidth - metrics.eCut, 0, metrics.eCut, metrics.nCut);
+            W = createSlice(img, 0, metrics.nCut, metrics.wCut, centerRowHeight);
+            C = metrics.showMiddle ? createSlice(img, metrics.wCut, metrics.nCut, centerColWidth, centerRowHeight) : null;
+            E = createSlice(img, totalWidth - metrics.eCut, metrics.nCut, metrics.eCut, centerRowHeight);
+            SW = createSlice(img, 0, totalHeight - metrics.sCut, metrics.wCut, metrics.sCut);
+            S = createSlice(img, metrics.wCut, totalHeight - metrics.sCut, centerColWidth, metrics.sCut);
+            SE = createSlice(img, totalWidth - metrics.eCut, totalHeight - metrics.sCut, metrics.eCut, metrics.sCut);
+        }
+
+        static BufferedImage createSlice(final Image img, final int x, final int y, final int w, final int h) {
+            if (w == 0 || h == 0) return null;
+
+            final BufferedImage slice = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
+            final Graphics2D g2d = slice.createGraphics();
+            g2d.drawImage(img, 0, 0, w, h, x, y, x + w, y + h, null);
+            g2d.dispose();
+
+            return slice;
+        }
+
+        public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
+            g.translate(x, y);
+
+            if (w < totalWidth || h < totalHeight) {
+                paintCompressed(g, w, h);
+            } else {
+                paintStretchedMiddles(g, w, h);
+            }
+
+            g.translate(-x, -y);
+        }
+
+        void paintStretchedMiddles(final Graphics g, final int w, final int h) {
+            int baseX = metrics.stretchH ? 0 : ((w / 2) - (totalWidth / 2));
+            int baseY = metrics.stretchV ? 0 : ((h / 2) - (totalHeight / 2));
+            int adjustedWidth = metrics.stretchH ? w : totalWidth;
+            int adjustedHeight = metrics.stretchV ? h : totalHeight;
+
+            if (NW != null) g.drawImage(NW, baseX, baseY, null);
+            if (N != null) g.drawImage(N, baseX + metrics.wCut, baseY, adjustedWidth - metrics.eCut - metrics.wCut, metrics.nCut, null);
+            if (NE != null) g.drawImage(NE, baseX + adjustedWidth - metrics.eCut, baseY, null);
+            if (W != null) g.drawImage(W, baseX, baseY + metrics.nCut, metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut, null);
+            if (C != null) g.drawImage(C, baseX + metrics.wCut, baseY + metrics.nCut, adjustedWidth - metrics.eCut - metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut, null);
+            if (E != null) g.drawImage(E, baseX + adjustedWidth - metrics.eCut, baseY + metrics.nCut, metrics.eCut, adjustedHeight - metrics.nCut - metrics.sCut, null);
+            if (SW != null) g.drawImage(SW, baseX, baseY + adjustedHeight - metrics.sCut, null);
+            if (S != null) g.drawImage(S, baseX + metrics.wCut, baseY + adjustedHeight - metrics.sCut, adjustedWidth - metrics.eCut - metrics.wCut, metrics.sCut, null);
+            if (SE != null) g.drawImage(SE, baseX + adjustedWidth - metrics.eCut, baseY + adjustedHeight - metrics.sCut, null);
+
+            /*
+            if (NW != null) {g.setColor(Color.GREEN); g.fillRect(baseX, baseY, NW.getWidth(), NW.getHeight());}
+            if (N != null) {g.setColor(Color.RED); g.fillRect(baseX + metrics.wCut, baseY, adjustedWidth - metrics.eCut - metrics.wCut, metrics.nCut);}
+            if (NE != null) {g.setColor(Color.BLUE); g.fillRect(baseX + adjustedWidth - metrics.eCut, baseY, NE.getWidth(), NE.getHeight());}
+            if (W != null) {g.setColor(Color.PINK); g.fillRect(baseX, baseY + metrics.nCut, metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut);}
+            if (C != null) {g.setColor(Color.ORANGE); g.fillRect(baseX + metrics.wCut, baseY + metrics.nCut, adjustedWidth - metrics.eCut - metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut);}
+            if (E != null) {g.setColor(Color.CYAN); g.fillRect(baseX + adjustedWidth - metrics.eCut, baseY + metrics.nCut, metrics.eCut, adjustedHeight - metrics.nCut - metrics.sCut);}
+            if (SW != null) {g.setColor(Color.MAGENTA); g.fillRect(baseX, baseY + adjustedHeight - metrics.sCut, SW.getWidth(), SW.getHeight());}
+            if (S != null) {g.setColor(Color.DARK_GRAY); g.fillRect(baseX + metrics.wCut, baseY + adjustedHeight - metrics.sCut, adjustedWidth - metrics.eCut - metrics.wCut, metrics.sCut);}
+            if (SE != null) {g.setColor(Color.YELLOW); g.fillRect(baseX + adjustedWidth - metrics.eCut, baseY + adjustedHeight - metrics.sCut, SE.getWidth(), SE.getHeight());}
+            */
+        }
+
+        void paintCompressed(final Graphics g, final int w, final int h) {
+            final double heightRatio = h > totalHeight ? 1.0 : (double)h / (double)totalHeight;
+            final double widthRatio = w > totalWidth ? 1.0 : (double)w / (double)totalWidth;
+
+            final int northHeight = (int)(metrics.nCut * heightRatio);
+            final int southHeight = (int)(metrics.sCut * heightRatio);
+            final int centerHeight = h - northHeight - southHeight;
+
+            final int westWidth = (int)(metrics.wCut * widthRatio);
+            final int eastWidth = (int)(metrics.eCut * widthRatio);
+            final int centerWidth = w - westWidth - eastWidth;
+
+            if (NW != null) g.drawImage(NW, 0, 0, westWidth, northHeight, null);
+            if (N != null) g.drawImage(N, westWidth, 0, centerWidth, northHeight, null);
+            if (NE != null) g.drawImage(NE, w - eastWidth, 0, eastWidth, northHeight, null);
+            if (W != null) g.drawImage(W, 0, northHeight, westWidth, centerHeight, null);
+            if (C != null) g.drawImage(C, westWidth, northHeight, centerWidth, centerHeight, null);
+            if (E != null) g.drawImage(E, w - eastWidth, northHeight, eastWidth, centerHeight, null);
+            if (SW != null) g.drawImage(SW, 0, h - southHeight, westWidth, southHeight, null);
+            if (S != null) g.drawImage(S, westWidth, h - southHeight, centerWidth, southHeight, null);
+            if (SE != null) g.drawImage(SE, w - eastWidth, h - southHeight, eastWidth, southHeight, null);
+        }
+    }
+
+    public abstract static class RecyclableSlicedImageControl extends RecyclableObject<SlicedImageControl> {
+        final NineSliceMetrics metrics;
+
+        public RecyclableSlicedImageControl(final NineSliceMetrics metrics) {
+            this.metrics = metrics;
+        }
+
+        @Override
+        protected SlicedImageControl create() {
+            return new SlicedImageControl(createTemplateImage(metrics.minW, metrics.minH), metrics);
+        }
+
+        protected abstract Image createTemplateImage(final int width, final int height);
+    }
+
+    // when we use SystemColors, we need to proxy the color with something that implements UIResource,
+    // so that it will be uninstalled when the look and feel is changed.
+    private static class SystemColorProxy extends Color implements UIResource {
+        final Color color;
+        public SystemColorProxy(final Color color) {
+            super(color.getRGB());
+            this.color = color;
+        }
+
+        public int getRGB() {
+            return color.getRGB();
+        }
+    }
+
+    public static Color getWindowBackgroundColorUIResource() {
+        return AquaNativeResources.getWindowBackgroundColorUIResource();
+    }
+
+    public static Color getTextSelectionBackgroundColorUIResource() {
+        return new SystemColorProxy(SystemColor.textHighlight);
+    }
+
+    public static Color getTextSelectionForegroundColorUIResource() {
+        return new SystemColorProxy(SystemColor.textHighlightText);
+    }
+
+    public static Color getSelectionBackgroundColorUIResource() {
+        return new SystemColorProxy(SystemColor.controlHighlight);
+    }
+
+    public static Color getSelectionForegroundColorUIResource() {
+        return new SystemColorProxy(SystemColor.controlLtHighlight);
+    }
+
+    public static Color getFocusRingColorUIResource() {
+        return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.KEYBOARD_FOCUS_COLOR));
+    }
+
+    public static Color getSelectionInactiveBackgroundColorUIResource() {
+        return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.INACTIVE_SELECTION_BACKGROUND_COLOR));
+    }
+
+    public static Color getSelectionInactiveForegroundColorUIResource() {
+        return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.INACTIVE_SELECTION_FOREGROUND_COLOR));
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameBorder.java
new file mode 100644
index 0000000..66e726b
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameBorder.java
@@ -0,0 +1,498 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.beans.PropertyVetoException;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.UIResource;
+
+import sun.swing.SwingUtilities2;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+import apple.laf.JRSUIState.TitleBarHeightState;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaInternalFrameBorderMetrics;
+
+public class AquaInternalFrameBorder implements Border, UIResource {
+    private static final int kCloseButton = 0;
+    private static final int kIconButton = 1;
+    private static final int kGrowButton = 2;
+
+    private static final int sMaxIconWidth = 15;
+    private static final int sMaxIconHeight = sMaxIconWidth;
+    private static final int sAfterButtonPad = 11;
+    private static final int sAfterIconPad = 5;
+    private static final int sRightSideTitleClip = 0;
+
+    private static final int kContentTester = 100; // For getting region insets
+
+    static final RecyclableSingleton<AquaInternalFrameBorder> documentWindowFrame = new RecyclableSingleton<AquaInternalFrameBorder>() {
+        protected AquaInternalFrameBorder getInstance() {
+            return new AquaInternalFrameBorder(WindowType.DOCUMENT);
+        }
+    };
+    protected static AquaInternalFrameBorder window() {
+        return documentWindowFrame.get();
+    }
+
+    static final RecyclableSingleton<AquaInternalFrameBorder> utilityWindowFrame = new RecyclableSingleton<AquaInternalFrameBorder>() {
+        protected AquaInternalFrameBorder getInstance() {
+            return new AquaInternalFrameBorder(WindowType.UTILITY);
+        }
+    };
+    protected static AquaInternalFrameBorder utility() {
+        return utilityWindowFrame.get();
+    }
+
+    static final RecyclableSingleton<AquaInternalFrameBorder> dialogWindowFrame = new RecyclableSingleton<AquaInternalFrameBorder>() {
+        protected AquaInternalFrameBorder getInstance() {
+            return new AquaInternalFrameBorder(WindowType.DOCUMENT);
+        }
+    };
+    protected static AquaInternalFrameBorder dialog() {
+        return dialogWindowFrame.get();
+    }
+
+    private final AquaInternalFrameBorderMetrics metrics;
+
+    private final int fThisButtonSpan;
+    private final int fThisLeftSideTotal;
+
+    private final boolean fIsUtility;
+
+    // Instance variables
+    private final WindowType fWindowKind; // Which kind of window to draw
+    private Insets fBorderInsets; // Cached insets object
+
+    private Color selectedTextColor;
+    private Color notSelectedTextColor;
+
+    private Rectangle fInBounds; // Cached bounds rect object
+
+    protected final AquaPainter<TitleBarHeightState> titleBarPainter = AquaPainter.create(JRSUIStateFactory.getTitleBar());
+    protected final AquaPainter<JRSUIState> widgetPainter = AquaPainter.create(JRSUIState.getInstance());
+
+    protected AquaInternalFrameBorder(final WindowType kind) {
+        fWindowKind = kind;
+
+        titleBarPainter.state.set(WindowClipCorners.YES);
+        if (fWindowKind == WindowType.UTILITY) {
+            fIsUtility = true;
+            metrics = AquaInternalFrameBorderMetrics.getMetrics(true);
+
+            widgetPainter.state.set(WindowType.UTILITY);
+            titleBarPainter.state.set(WindowType.UTILITY);
+        } else {
+            fIsUtility = false;
+            metrics = AquaInternalFrameBorderMetrics.getMetrics(false);
+
+            widgetPainter.state.set(WindowType.DOCUMENT);
+            titleBarPainter.state.set(WindowType.DOCUMENT);
+        }
+        titleBarPainter.state.setValue(metrics.titleBarHeight);
+        titleBarPainter.state.set(WindowTitleBarSeparator.YES);
+        widgetPainter.state.set(AlignmentVertical.CENTER);
+
+        fThisButtonSpan = (metrics.buttonWidth * 3) + (metrics.buttonPadding * 2);
+        fThisLeftSideTotal = metrics.leftSidePadding + fThisButtonSpan + sAfterButtonPad;
+    }
+
+    public void setColors(final Color inSelectedTextColor, final Color inNotSelectedTextColor) {
+        selectedTextColor = inSelectedTextColor;
+        notSelectedTextColor = inNotSelectedTextColor;
+    }
+
+    // Utility to lazy-init and fill in fInBounds
+    protected void setInBounds(final int x, final int y, final int w, final int h) {
+        if (fInBounds == null) fInBounds = new Rectangle();
+
+        fInBounds.x = x;
+        fInBounds.y = y;
+        fInBounds.width = w;
+        fInBounds.height = h;
+    }
+
+    // Border interface
+    public boolean isBorderOpaque() {
+        return false;
+    }
+
+    // Border interface
+    public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
+        // For expanded InternalFrames, the frame & component are the same object
+        paintBorder((JInternalFrame)c, c, g, x, y, w, h);
+    }
+
+    protected void paintTitleContents(final Graphics g, final JInternalFrame frame, final int x, final int y, final int w, final int h) {
+        final boolean isSelected = frame.isSelected();
+        final Font f = g.getFont();
+
+        g.setFont(metrics.font);
+
+        // Center text vertically.
+        final FontMetrics fm = g.getFontMetrics();
+        final int baseline = (metrics.titleBarHeight + fm.getAscent() - fm.getLeading() - fm.getDescent()) / 2;
+
+        // max button is the rightmost so use it
+        final int usedWidth = fThisLeftSideTotal + sRightSideTitleClip;
+        int iconWidth = getIconWidth(frame);
+        if (iconWidth > 0) iconWidth += sAfterIconPad;
+
+        final int totalWidth = w;
+
+        // window title looks like: | 0 0 0(sAfterButtonPad)IconWidth Title(right pad) |
+        final int availTextWidth = totalWidth - usedWidth - iconWidth - sAfterButtonPad;
+
+        final String title = frame.getTitle();
+
+        String text = title;
+        int totalTextWidth = 0;
+
+        int startXPosition = fThisLeftSideTotal;
+        boolean wasTextShortened = false;
+        // shorten the string to fit in the
+        if ((text != null) && !(text.equals(""))) {
+            totalTextWidth = SwingUtilities.computeStringWidth(fm, text);
+            final String clipString = "\u2026";
+            if (totalTextWidth > availTextWidth) {
+                wasTextShortened = true;
+                totalTextWidth = SwingUtilities.computeStringWidth(fm, clipString);
+                int nChars;
+                for (nChars = 0; nChars < text.length(); nChars++) {
+                    final int nextCharWidth = fm.charWidth(text.charAt(nChars));
+                    if ((totalTextWidth + nextCharWidth) > availTextWidth) {
+                        break;
+                    }
+                    totalTextWidth += nextCharWidth;
+                }
+                text = text.substring(0, nChars) + clipString;
+            }
+
+            if (!wasTextShortened) {
+                // center it!
+                startXPosition = (totalWidth - (totalTextWidth + iconWidth)) / 2;
+                if (startXPosition < fThisLeftSideTotal) {
+                    startXPosition = fThisLeftSideTotal;
+                }
+            }
+
+            if (isSelected || fIsUtility) {
+                g.setColor(Color.lightGray);
+            } else {
+                g.setColor(Color.white);
+            }
+            SwingUtilities2.drawString(frame, g, text, x + startXPosition + iconWidth, y + baseline + 1);
+
+            if (isSelected || fIsUtility) {
+                g.setColor(selectedTextColor);
+            } else {
+                g.setColor(notSelectedTextColor);
+            }
+
+            SwingUtilities2.drawString(frame, g, text, x + startXPosition + iconWidth, y + baseline);
+            g.setFont(f);
+        }
+
+        // sja fix x & y
+        final int iconYPostion = (metrics.titleBarHeight - getIconHeight(frame)) / 2;
+        paintTitleIcon(g, frame, x + startXPosition, y + iconYPostion);
+    }
+
+    public int getWhichButtonHit(final JInternalFrame frame, final int x, final int y) {
+        int buttonHit = -1;
+
+        final Insets i = frame.getInsets();
+        int startX = i.left + metrics.leftSidePadding - 1;
+        if (isInsideYButtonArea(i, y) && x >= startX) {
+            if (x <= (startX + metrics.buttonWidth)) {
+                if (frame.isClosable()) {
+                    buttonHit = kCloseButton;
+                }
+            } else {
+                startX += metrics.buttonWidth + metrics.buttonPadding;
+                if (x >= startX && x <= (startX + metrics.buttonWidth)) {
+                    if (frame.isIconifiable()) {
+                        buttonHit = kIconButton;
+                    }
+                } else {
+                    startX += metrics.buttonWidth + metrics.buttonPadding;
+                    if (x >= startX && x <= (startX + metrics.buttonWidth)) {
+                        if (frame.isMaximizable()) {
+                            buttonHit = kGrowButton;
+                        }
+                    }
+                }
+            }
+        }
+
+        return buttonHit;
+    }
+
+    public void doButtonAction(final JInternalFrame frame, final int whichButton) {
+        switch (whichButton) {
+            case kCloseButton:
+                frame.doDefaultCloseAction();
+                break;
+
+            case kIconButton:
+                if (frame.isIconifiable()) {
+                    if (!frame.isIcon()) {
+                        try {
+                            frame.setIcon(true);
+                        } catch(final PropertyVetoException e1) {}
+                    } else {
+                        try {
+                            frame.setIcon(false);
+                        } catch(final PropertyVetoException e1) {}
+                    }
+                }
+                break;
+
+            case kGrowButton:
+                if (frame.isMaximizable()) {
+                    if (!frame.isMaximum()) {
+                        try {
+                            frame.setMaximum(true);
+                        } catch(final PropertyVetoException e5) {}
+                    } else {
+                        try {
+                            frame.setMaximum(false);
+                        } catch(final PropertyVetoException e6) {}
+                    }
+                }
+                break;
+
+            default:
+                System.err.println("AquaInternalFrameBorder should never get here!!!!");
+                Thread.dumpStack();
+                break;
+        }
+    }
+
+    public boolean isInsideYButtonArea(final Insets i, final int y) {
+        final int startY = (i.top - metrics.titleBarHeight / 2) - (metrics.buttonHeight / 2) - 1;
+        final int endY = startY + metrics.buttonHeight;
+        return y >= startY && y <= endY;
+    }
+
+    public boolean getWithinRolloverArea(final Insets i, final int x, final int y) {
+        final int startX = i.left + metrics.leftSidePadding;
+        final int endX = startX + fThisButtonSpan;
+        return isInsideYButtonArea(i, y) && x >= startX && x <= endX;
+    }
+
+    protected void paintTitleIcon(final Graphics g, final JInternalFrame frame, final int x, final int y) {
+        Icon icon = frame.getFrameIcon();
+        if (icon == null) icon = UIManager.getIcon("InternalFrame.icon");
+        if (icon == null) return;
+
+        // Resize to 16x16 if necessary.
+        if (icon instanceof ImageIcon && (icon.getIconWidth() > sMaxIconWidth || icon.getIconHeight() > sMaxIconHeight)) {
+            final Image img = ((ImageIcon)icon).getImage();
+            ((ImageIcon)icon).setImage(img.getScaledInstance(sMaxIconWidth, sMaxIconHeight, Image.SCALE_SMOOTH));
+        }
+
+        icon.paintIcon(frame, g, x, y);
+    }
+
+    protected int getIconWidth(final JInternalFrame frame) {
+        int width = 0;
+
+        Icon icon = frame.getFrameIcon();
+        if (icon == null) {
+            icon = UIManager.getIcon("InternalFrame.icon");
+        }
+
+        if (icon != null && icon instanceof ImageIcon) {
+            // Resize to 16x16 if necessary.
+            width = Math.min(icon.getIconWidth(), sMaxIconWidth);
+        }
+
+        return width;
+    }
+
+    protected int getIconHeight(final JInternalFrame frame) {
+        int height = 0;
+
+        Icon icon = frame.getFrameIcon();
+        if (icon == null) {
+            icon = UIManager.getIcon("InternalFrame.icon");
+        }
+
+        if (icon != null && icon instanceof ImageIcon) {
+            // Resize to 16x16 if necessary.
+            height = Math.min(icon.getIconHeight(), sMaxIconHeight);
+        }
+
+        return height;
+    }
+
+    public void drawWindowTitle(final Graphics g, final JInternalFrame frame, final int inX, final int inY, final int inW, final int inH) {
+        final int x = inX;
+        final int y = inY;
+        final int w = inW;
+        int h = inH;
+
+        h = metrics.titleBarHeight + inH;
+
+        // paint the background
+        titleBarPainter.state.set(frame.isSelected() ? State.ACTIVE : State.INACTIVE);
+        titleBarPainter.paint(g, frame, x, y, w, h);
+
+        // now the title and the icon
+        paintTitleContents(g, frame, x, y, w, h);
+
+        // finally the widgets
+        drawAllWidgets(g, frame); // rollover is last attribute
+    }
+
+    // Component could be a JInternalFrame or a JDesktopIcon
+    void paintBorder(final JInternalFrame frame, final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
+        if (fBorderInsets == null) getBorderInsets(c);
+        // Set the contentRect - inset by border size
+        setInBounds(x + fBorderInsets.left, y + fBorderInsets.top, w - (fBorderInsets.right + fBorderInsets.left), h - (fBorderInsets.top + fBorderInsets.bottom));
+
+        // Set parameters
+        setMetrics(frame, c);
+
+        // Draw the frame
+        drawWindowTitle(g, frame, x, y, w, h);
+    }
+
+    // defaults to false
+    boolean isDirty(final JInternalFrame frame) {
+        final Object dirty = frame.getClientProperty("windowModified");
+        if (dirty == null || dirty == Boolean.FALSE) return false;
+        return true;
+    }
+
+    // Border interface
+    public Insets getBorderInsets(final Component c) {
+        if (fBorderInsets == null) fBorderInsets = new Insets(0, 0, 0, 0);
+
+        // Paranoia check
+        if (!(c instanceof JInternalFrame)) return fBorderInsets;
+
+        final JInternalFrame frame = (JInternalFrame)c;
+
+        // Set the contentRect to an arbitrary value (in case the current real one is too small)
+        setInBounds(0, 0, kContentTester, kContentTester);
+
+        // Set parameters
+        setMetrics(frame, c);
+
+        fBorderInsets.left = 0;
+        fBorderInsets.top = metrics.titleBarHeight;
+        fBorderInsets.right = 0;
+        fBorderInsets.bottom = 0;
+
+        return fBorderInsets;
+    }
+
+    public void repaintButtonArea(final JInternalFrame frame) {
+        final Insets i = frame.getInsets();
+        final int x = i.left + metrics.leftSidePadding;
+        final int y = i.top - metrics.titleBarHeight + 1;
+        frame.repaint(x, y, fThisButtonSpan, metrics.titleBarHeight - 2);
+    }
+
+    // Draw all the widgets this frame supports
+    void drawAllWidgets(final Graphics g, final JInternalFrame frame) {
+        int x = metrics.leftSidePadding;
+        int y = (metrics.titleBarHeight - metrics.buttonHeight) / 2 - metrics.titleBarHeight;
+
+        final Insets insets = frame.getInsets();
+        x += insets.left;
+        y += insets.top + metrics.downShift;
+
+        final AquaInternalFrameUI ui = (AquaInternalFrameUI)frame.getUI();
+        final int buttonPressedIndex = ui.getWhichButtonPressed();
+        final boolean overButton = ui.getMouseOverPressedButton();
+        final boolean rollover = ui.getRollover();
+
+        final boolean frameSelected = frame.isSelected() || fIsUtility;
+        final boolean generalActive = rollover || frameSelected;
+
+        final boolean dirty = isDirty(frame);
+
+        paintButton(g, frame, x, y, kCloseButton, buttonPressedIndex, overButton, frame.isClosable(), generalActive, rollover, dirty);
+
+        x += metrics.buttonPadding + metrics.buttonWidth;
+        paintButton(g, frame, x, y, kIconButton, buttonPressedIndex, overButton, frame.isIconifiable(), generalActive, rollover, false);
+
+        x += metrics.buttonPadding + metrics.buttonWidth;
+        paintButton(g, frame, x, y, kGrowButton, buttonPressedIndex, overButton, frame.isMaximizable(), generalActive, rollover, false);
+    }
+
+    public void paintButton(final Graphics g, final JInternalFrame frame, final int x, final int y, final int buttonType, final int buttonPressedIndex, final boolean overButton, final boolean enabled, final boolean active, final boolean anyRollover, final boolean dirty) {
+        widgetPainter.state.set(getWidget(frame, buttonType));
+        widgetPainter.state.set(getState(buttonPressedIndex == buttonType && overButton, anyRollover, active, enabled));
+        widgetPainter.state.set(dirty ? BooleanValue.YES : BooleanValue.NO);
+        widgetPainter.paint(g, frame, x, y, metrics.buttonWidth, metrics.buttonHeight);
+    }
+
+    static Widget getWidget(final JInternalFrame frame, final int buttonType) {
+        switch (buttonType) {
+            case kIconButton: return Widget.TITLE_BAR_COLLAPSE_BOX;
+            case kGrowButton: return Widget.TITLE_BAR_ZOOM_BOX;
+        }
+
+        return Widget.TITLE_BAR_CLOSE_BOX;
+    }
+
+    static State getState(final boolean pressed, final boolean rollover, final boolean active, final boolean enabled) {
+        if (!enabled) return State.DISABLED;
+        if (!active) return State.INACTIVE;
+        if (pressed) return State.PRESSED;
+        if (rollover) return State.ROLLOVER;
+        return State.ACTIVE;
+    }
+
+    protected void setMetrics(final JInternalFrame frame, final Component window) {
+        final String title = frame.getTitle();
+        final FontMetrics fm = frame.getFontMetrics(UIManager.getFont("InternalFrame.titleFont"));
+        int titleWidth = 0;
+        int titleHeight = fm.getAscent();
+        if (title != null) {
+            titleWidth = SwingUtilities.computeStringWidth(fm, title);
+        }
+        // Icon space
+        final Icon icon = frame.getFrameIcon();
+        if (icon != null) {
+            titleWidth += icon.getIconWidth();
+            titleHeight = Math.max(titleHeight, icon.getIconHeight());
+        }
+    }
+
+    protected int getTitleHeight() {
+        return metrics.titleBarHeight;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameBorderMetrics.java b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameBorderMetrics.java
new file mode 100644
index 0000000..3f489b9
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameBorderMetrics.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.Font;
+
+import apple.laf.JRSUIUtils;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public abstract class AquaInternalFrameBorderMetrics {
+    private static final boolean useLegacyBorderMetrics = JRSUIUtils.InternalFrame.shouldUseLegacyBorderMetrics();
+
+    public Font font;
+    public int titleBarHeight;
+    public int leftSidePadding;
+    public int buttonHeight;
+    public int buttonWidth;
+    public int buttonPadding;
+    public int downShift;
+
+    private AquaInternalFrameBorderMetrics() {
+        initialize();
+    }
+
+    protected abstract void initialize();
+
+    public static AquaInternalFrameBorderMetrics getMetrics(boolean isUtility) {
+        if (useLegacyBorderMetrics) {
+            return isUtility ? legacyUtilityMetrics.get() : legacyStandardMetrics.get();
+        } else {
+            return isUtility ? utilityMetrics.get() : standardMetrics.get();
+        }
+    }
+
+    private static final RecyclableSingleton<AquaInternalFrameBorderMetrics> standardMetrics = new RecyclableSingleton<AquaInternalFrameBorderMetrics>() {
+        @Override
+        protected AquaInternalFrameBorderMetrics getInstance() {
+            return new AquaInternalFrameBorderMetrics() {
+                protected void initialize() {
+                    font = new Font("Lucida Grande", Font.PLAIN, 13);
+                    titleBarHeight = 22;
+                    leftSidePadding = 7;
+                    buttonHeight = 15;
+                    buttonWidth = 15;
+                    buttonPadding = 5;
+                    downShift = 0;
+                }
+            };
+        }
+    };
+
+    private static final RecyclableSingleton<AquaInternalFrameBorderMetrics> utilityMetrics = new RecyclableSingleton<AquaInternalFrameBorderMetrics>() {
+        @Override
+        protected AquaInternalFrameBorderMetrics getInstance() {
+            return new AquaInternalFrameBorderMetrics() {
+                protected void initialize() {
+                    font = new Font("Lucida Grande", Font.PLAIN, 11);
+                    titleBarHeight = 16;
+                    leftSidePadding = 6;
+                    buttonHeight = 12;
+                    buttonWidth = 12;
+                    buttonPadding = 6;
+                    downShift = 0;
+                }
+            };
+        }
+    };
+
+    private static final RecyclableSingleton<AquaInternalFrameBorderMetrics> legacyStandardMetrics = new RecyclableSingleton<AquaInternalFrameBorderMetrics>() {
+        @Override
+        protected AquaInternalFrameBorderMetrics getInstance() {
+            return new AquaInternalFrameBorderMetrics() {
+                protected void initialize() {
+                    font = new Font("Lucida Grande", Font.PLAIN, 13);
+                    titleBarHeight = 22;
+                    leftSidePadding = 8;
+                    buttonHeight = 15;
+                    buttonWidth = 15;
+                    buttonPadding = 6;
+                    downShift = 1;
+                }
+            };
+        }
+    };
+
+    private static final RecyclableSingleton<AquaInternalFrameBorderMetrics> legacyUtilityMetrics = new RecyclableSingleton<AquaInternalFrameBorderMetrics>() {
+        @Override
+        protected AquaInternalFrameBorderMetrics getInstance() {
+            return new AquaInternalFrameBorderMetrics() {
+                protected void initialize() {
+                    font = new Font("Lucida Grande", Font.PLAIN, 11);
+                    titleBarHeight = 16;
+                    leftSidePadding = 5;
+                    buttonHeight = 13;
+                    buttonWidth = 13;
+                    buttonPadding = 5;
+                    downShift = 0;
+                }
+            };
+        }
+    };
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameDockIconUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameDockIconUI.java
new file mode 100644
index 0000000..43b7661a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameDockIconUI.java
@@ -0,0 +1,312 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.beans.PropertyVetoException;
+
+import javax.swing.*;
+import javax.swing.plaf.*;
+
+import sun.swing.SwingUtilities2;
+
+/**
+ * From MacDockIconUI
+ *
+ * A JRSUI L&F implementation of JInternalFrame.JDesktopIcon
+ * @author
+ * @version
+ */
+public class AquaInternalFrameDockIconUI extends DesktopIconUI implements MouseListener, MouseMotionListener, ComponentListener {
+    private static final String CACHED_FRAME_ICON_KEY = "apple.laf.internal.frameIcon";
+
+    protected JInternalFrame.JDesktopIcon fDesktopIcon;
+    protected JInternalFrame fFrame;
+    protected ScaledImageLabel fIconPane;
+    protected DockLabel fDockLabel;
+    protected boolean fTrackingIcon = false;
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaInternalFrameDockIconUI();
+    }
+
+    public void installUI(final JComponent c) {
+        fDesktopIcon = (JInternalFrame.JDesktopIcon)c;
+        installComponents();
+        installListeners();
+    }
+
+    public void uninstallUI(final JComponent c) {
+        uninstallComponents();
+        uninstallListeners();
+        fDesktopIcon = null;
+        fFrame = null;
+    }
+
+    protected void installComponents() {
+        fFrame = fDesktopIcon.getInternalFrame();
+        fIconPane = new ScaledImageLabel();
+        fDesktopIcon.setLayout(new BorderLayout());
+        fDesktopIcon.add(fIconPane, BorderLayout.CENTER);
+    }
+
+    protected void uninstallComponents() {
+        fDesktopIcon.setLayout(null);
+        fDesktopIcon.remove(fIconPane);
+    }
+
+    protected void installListeners() {
+        fDesktopIcon.addMouseListener(this);
+        fDesktopIcon.addMouseMotionListener(this);
+        fFrame.addComponentListener(this);
+    }
+
+    protected void uninstallListeners() {
+        fFrame.removeComponentListener(this);
+        fDesktopIcon.removeMouseMotionListener(this);
+        fDesktopIcon.removeMouseListener(this);
+    }
+
+    public Dimension getMinimumSize(final JComponent c) {
+        return new Dimension(32, 32);
+    }
+
+    public Dimension getMaximumSize(final JComponent c) {
+        return new Dimension(128, 128);
+    }
+
+    public Dimension getPreferredSize(final JComponent c) {
+        return new Dimension(64, 64); //$ Dock preferred size
+    }
+
+    public Insets getInsets(final JComponent c) {
+        return new Insets(0, 0, 0, 0);
+    }
+
+    void updateIcon() {
+        fIconPane.updateIcon();
+    }
+
+    public void mousePressed(final MouseEvent e) {
+        fTrackingIcon = fIconPane.mouseInIcon(e);
+        if (fTrackingIcon) fIconPane.repaint();
+    }
+
+    public void mouseReleased(final MouseEvent e) {// only when it's actually in the image
+        if (fFrame.isIconifiable() && fFrame.isIcon()) {
+            if (fTrackingIcon) {
+                fTrackingIcon = false;
+                if (fIconPane.mouseInIcon(e)) {
+                    if (fDockLabel != null) fDockLabel.hide();
+                    try {
+                        fFrame.setIcon(false);
+                    } catch(final PropertyVetoException e2) {}
+                } else {
+                    fIconPane.repaint();
+                }
+            }
+        }
+
+        // if the mouse was completely outside fIconPane, hide the label
+        if (fDockLabel != null && !fIconPane.getBounds().contains(e.getX(), e.getY())) fDockLabel.hide();
+    }
+
+    public void mouseEntered(final MouseEvent e) {
+        if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) return;
+        String title = fFrame.getTitle();
+        if (title == null || title.equals("")) title = "Untitled";
+        fDockLabel = new DockLabel(title);
+        fDockLabel.show(fDesktopIcon);
+    }
+
+    public void mouseExited(final MouseEvent e) {
+        if (fDockLabel != null && (e.getModifiers() & InputEvent.BUTTON1_MASK) == 0) fDockLabel.hide();
+    }
+
+    public void mouseClicked(final MouseEvent e) { }
+
+    public void mouseDragged(final MouseEvent e) { }
+
+    public void mouseMoved(final MouseEvent e) { }
+
+    public void componentHidden(final ComponentEvent e) { }
+
+    public void componentMoved(final ComponentEvent e) { }
+
+    public void componentResized(final ComponentEvent e) {
+        fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, null);
+    }
+
+    public void componentShown(final ComponentEvent e) {
+        fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, null);
+    }
+
+    class ScaledImageLabel extends JLabel {
+        ScaledImageLabel() {
+            super(null, null, CENTER);
+        }
+
+        void updateIcon() {
+            final Object priorIcon = fFrame.getClientProperty(CACHED_FRAME_ICON_KEY);
+            if (priorIcon instanceof ImageIcon) {
+                setIcon((ImageIcon)priorIcon);
+                return;
+            }
+
+            int width = fFrame.getWidth();
+            int height = fFrame.getHeight();
+
+            // Protect us from unsized frames, like in JCK test DefaultDesktopManager2008
+            if (width <= 0 || height <= 0) {
+                width = 128;
+                height = 128;
+            }
+
+            final Image fImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
+            final Graphics g = fImage.getGraphics();
+            fFrame.paint(g);
+            g.dispose();
+
+            final float scale = (float)fDesktopIcon.getWidth() / (float)Math.max(width, height) * 0.89f;
+            // Sending in -1 for width xor height causes it to maintain aspect ratio
+            final ImageIcon icon = new ImageIcon(fImage.getScaledInstance((int)(width * scale), -1, Image.SCALE_SMOOTH));
+            fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, icon);
+            setIcon(icon);
+        }
+
+        public void paint(final Graphics g) {
+            if (getIcon() == null) updateIcon();
+
+            g.translate(0, 2);
+
+            if (!fTrackingIcon) {
+                super.paint(g);
+                return;
+            }
+
+            final ImageIcon prev = (ImageIcon)getIcon();
+            final ImageIcon pressedIcon = new ImageIcon(AquaUtils.generateSelectedDarkImage(prev.getImage()));
+            setIcon(pressedIcon);
+            super.paint(g);
+            setIcon(prev);
+        }
+
+        boolean mouseInIcon(final MouseEvent e) {
+            return getBounds().contains(e.getX(), e.getY());
+        }
+
+        public Dimension getPreferredSize() {
+            return new Dimension(64, 64); //$ Dock preferred size
+        }
+    }
+
+    class DockLabel extends JLabel {
+        final static int NUB_HEIGHT = 7;
+        final static int ROUND_ADDITIONAL_HEIGHT = 8;
+        final static int ROUND_ADDITIONAL_WIDTH = 12;
+
+        DockLabel(final String text) {
+            super(text);
+            setBorder(null);
+            setOpaque(false);
+            setFont(AquaFonts.getDockIconFont());
+
+            final FontMetrics metrics = getFontMetrics(getFont());
+            setSize(SwingUtilities.computeStringWidth(metrics, getText()) + ROUND_ADDITIONAL_WIDTH * 2, metrics.getAscent() + NUB_HEIGHT + ROUND_ADDITIONAL_HEIGHT);
+        }
+
+        public void paint(final Graphics g) {
+            final int width = getWidth();
+            final int height = getHeight();
+
+            final Font font = getFont();
+            final FontMetrics metrics = getFontMetrics(font);
+            g.setFont(font);
+
+            final String text = getText().trim();
+            final int ascent = metrics.getAscent();
+
+            final Rectangle2D stringBounds = metrics.getStringBounds(text, g);
+            final int halfway = width / 2;
+
+            final int x = (halfway - (int)stringBounds.getWidth() / 2);
+
+            final Graphics2D g2d = g instanceof Graphics2D ? (Graphics2D)g : null;
+            if (g2d != null) {
+                g.setColor(UIManager.getColor("DesktopIcon.labelBackground"));
+                final Object origAA = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+                final int roundHeight = height - ROUND_ADDITIONAL_HEIGHT + 1;
+                g.fillRoundRect(0, 0, width, roundHeight, roundHeight, roundHeight);
+
+                final int[] xpts = { halfway, halfway + NUB_HEIGHT, halfway - NUB_HEIGHT };
+                final int[] ypts = { height, height - NUB_HEIGHT, height - NUB_HEIGHT };
+                g.fillPolygon(xpts, ypts, 3);
+
+                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, origAA);
+            }
+
+            g.setColor(Color.black);
+            SwingUtilities2.drawString(this, g, text, x, 2 + ascent);
+            g.setColor(Color.white);
+            SwingUtilities2.drawString(this, g, text, x, 1 + ascent);
+        }
+
+        public void show(final Component invoker) {
+            final int desiredLocationX = (invoker.getWidth() - getWidth()) / 2;
+            final int desiredLocationY = -(getHeight() + 6);
+
+            Container parent = invoker.getParent();
+
+            for (Container p = parent; p != null; p = p.getParent()) {
+                if (p instanceof JRootPane) {
+                    if (p.getParent() instanceof JInternalFrame) continue;
+                    parent = ((JRootPane)p).getLayeredPane();
+                    for (p = parent.getParent(); p != null && (!(p instanceof java.awt.Window)); p = p.getParent());
+                    break;
+                }
+            }
+
+            final Point p = SwingUtilities.convertPoint(invoker, desiredLocationX, desiredLocationY, parent);
+            setLocation(p.x, p.y);
+            if (parent instanceof JLayeredPane) {
+                ((JLayeredPane)parent).add(this, JLayeredPane.POPUP_LAYER, 0);
+            }
+        }
+
+        public void hide() {
+            final Container parent = getParent();
+            final Rectangle r = this.getBounds();
+            if (parent == null) return;
+            parent.remove(this);
+            parent.repaint(r.x, r.y, r.width, r.height);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameManager.java b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameManager.java
new file mode 100644
index 0000000..ccefa0f
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameManager.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.beans.PropertyVetoException;
+import java.util.Vector;
+
+import javax.swing.*;
+
+/**
+ * Based on AquaInternalFrameManager
+ *
+ * DesktopManager implementation for Aqua
+ *
+ * Mac is more like Windows than it's like Motif/Basic
+ *
+ *    From WindowsDesktopManager:
+ *
+ * This class implements a DesktopManager which more closely follows
+ * the MDI model than the DefaultDesktopManager.  Unlike the
+ * DefaultDesktopManager policy, MDI requires that the selected
+ * and activated child frames are the same, and that that frame
+ * always be the top-most window.
+ * <p>
+ * The maximized state is managed by the DesktopManager with MDI,
+ * instead of just being a property of the individual child frame.
+ * This means that if the currently selected window is maximized
+ * and another window is selected, that new window will be maximized.
+ *
+ * @see com.sun.java.swing.plaf.windows.WindowsDesktopManager
+ */
+public class AquaInternalFrameManager extends DefaultDesktopManager {
+    // Variables
+
+    /* The frame which is currently selected/activated.
+     * We store this value to enforce Mac's single-selection model.
+     */
+    JInternalFrame fCurrentFrame;
+    JInternalFrame fInitialFrame;
+    AquaInternalFramePaneUI fCurrentPaneUI;
+
+    /* The list of frames, sorted by order of creation.
+     * This list is necessary because by default the order of
+     * child frames in the JDesktopPane changes during frame
+     * activation (the activated frame is moved to index 0).
+     * We preserve the creation order so that "next" and "previous"
+     * frame actions make sense.
+     */
+    Vector<JInternalFrame> fChildFrames = new Vector<JInternalFrame>(1);
+
+    public void closeFrame(final JInternalFrame f) {
+        if (f == fCurrentFrame) {
+            activateNextFrame();
+        }
+        fChildFrames.removeElement(f);
+        super.closeFrame(f);
+    }
+
+    public void deiconifyFrame(final JInternalFrame f) {
+        JInternalFrame.JDesktopIcon desktopIcon;
+
+        desktopIcon = f.getDesktopIcon();
+        // If the icon moved, move the frame to that spot before expanding it
+        // reshape does delta checks for us
+        f.reshape(desktopIcon.getX(), desktopIcon.getY(), f.getWidth(), f.getHeight());
+        super.deiconifyFrame(f);
+    }
+
+    void addIcon(final Container c, final JInternalFrame.JDesktopIcon desktopIcon) {
+        c.add(desktopIcon);
+    }
+
+    /** Removes the frame from its parent and adds its desktopIcon to the parent. */
+    public void iconifyFrame(final JInternalFrame f) {
+        // Same as super except doesn't deactivate it
+        JInternalFrame.JDesktopIcon desktopIcon;
+        Container c;
+
+        desktopIcon = f.getDesktopIcon();
+        // Position depends on *current* position of frame, unlike super which reuses the first position
+        final Rectangle r = getBoundsForIconOf(f);
+        desktopIcon.setBounds(r.x, r.y, r.width, r.height);
+
+        c = f.getParent();
+        if (c == null) return;
+
+        c.remove(f);
+        addIcon(c, desktopIcon);
+        c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
+    }
+
+    // WindowsDesktopManager code
+    public void activateFrame(final JInternalFrame f) {
+        try {
+            if (f != null) super.activateFrame(f);
+
+            // If this is the first activation, add to child list.
+            if (fChildFrames.indexOf(f) == -1) {
+                fChildFrames.addElement(f);
+            }
+
+            if (fCurrentFrame != null && f != fCurrentFrame) {
+                if (fCurrentFrame.isSelected()) {
+                    fCurrentFrame.setSelected(false);
+                }
+            }
+
+            if (f != null && !f.isSelected()) {
+                f.setSelected(true);
+            }
+
+            fCurrentFrame = f;
+        } catch(final PropertyVetoException e) {}
+    }
+
+    private void switchFrame(final boolean next) {
+        if (fCurrentFrame == null) {
+            // initialize first frame we find
+            if (fInitialFrame != null) activateFrame(fInitialFrame);
+            return;
+        }
+
+        final int count = fChildFrames.size();
+        if (count <= 1) {
+            // No other child frames.
+            return;
+        }
+
+        final int currentIndex = fChildFrames.indexOf(fCurrentFrame);
+        if (currentIndex == -1) {
+            // the "current frame" is no longer in the list
+            fCurrentFrame = null;
+            return;
+        }
+
+        int nextIndex;
+        if (next) {
+            nextIndex = currentIndex + 1;
+            if (nextIndex == count) {
+                nextIndex = 0;
+            }
+        } else {
+            nextIndex = currentIndex - 1;
+            if (nextIndex == -1) {
+                nextIndex = count - 1;
+            }
+        }
+        final JInternalFrame f = fChildFrames.elementAt(nextIndex);
+        activateFrame(f);
+        fCurrentFrame = f;
+    }
+
+    /**
+     * Activate the next child JInternalFrame, as determined by
+     * the frames' Z-order.  If there is only one child frame, it
+     * remains activated.  If there are no child frames, nothing
+     * happens.
+     */
+    public void activateNextFrame() {
+        switchFrame(true);
+    }
+
+    /** same as above but will activate a frame if none
+     *  have been selected
+     */
+    public void activateNextFrame(final JInternalFrame f) {
+        fInitialFrame = f;
+        switchFrame(true);
+    }
+
+    /**
+     * Activate the previous child JInternalFrame, as determined by
+     * the frames' Z-order.  If there is only one child frame, it
+     * remains activated.  If there are no child frames, nothing
+     * happens.
+     */
+    public void activatePreviousFrame() {
+        switchFrame(false);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFramePaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFramePaneUI.java
new file mode 100644
index 0000000..466c779
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFramePaneUI.java
@@ -0,0 +1,241 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.PropertyVetoException;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicDesktopPaneUI;
+
+public class AquaInternalFramePaneUI extends BasicDesktopPaneUI implements MouseListener {
+
+    JComponent fDock;
+    DockLayoutManager fLayoutMgr;
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaInternalFramePaneUI();
+    }
+
+    public void update(final Graphics g, final JComponent c) {
+        if (c.isOpaque()) {
+            super.update(g, c);
+            return;
+        }
+        paint(g, c);
+    }
+
+    public void installUI(final JComponent c) {
+        super.installUI(c);
+        fLayoutMgr = new DockLayoutManager();
+        c.setLayout(fLayoutMgr);
+
+        c.addMouseListener(this);
+    }
+
+    public void uninstallUI(final JComponent c) {
+        c.removeMouseListener(this);
+
+        if (fDock != null) {
+            c.remove(fDock);
+            fDock = null;
+        }
+        if (fLayoutMgr != null) {
+            c.setLayout(null);
+            fLayoutMgr = null;
+        }
+        super.uninstallUI(c);
+    }
+
+    // Our superclass hardcodes DefaultDesktopManager - how rude!
+    protected void installDesktopManager() {
+        if (desktop.getDesktopManager() == null) {
+            desktopManager = new AquaDockingDesktopManager();
+            desktop.setDesktopManager(desktopManager);
+        }
+    }
+
+    protected void uninstallDesktopManager() {
+        final DesktopManager manager = desktop.getDesktopManager();
+        if (manager instanceof AquaDockingDesktopManager) {
+            desktop.setDesktopManager(null);
+        }
+    }
+
+    JComponent getDock() {
+        if (fDock == null) {
+            fDock = new Dock(desktop);
+            desktop.add(fDock, new Integer(399)); // Just below the DRAG_LAYER
+        }
+        return fDock;
+    }
+
+    class DockLayoutManager implements LayoutManager {
+        public void addLayoutComponent(final String name, final Component comp) {
+        }
+
+        public void removeLayoutComponent(final Component comp) {
+        }
+
+        public Dimension preferredLayoutSize(final Container parent) {
+            return parent.getSize();
+        }
+
+        public Dimension minimumLayoutSize(final Container parent) {
+            return parent.getSize();
+        }
+
+        public void layoutContainer(final Container parent) {
+            if (fDock != null) ((Dock)fDock).updateSize();
+        }
+    }
+
+    class Dock extends JComponent implements Border {
+        static final int DOCK_EDGE_SLACK = 8;
+
+        Dock(final JComponent parent) {
+            setBorder(this);
+            setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
+            setVisible(false);
+        }
+
+        public void removeNotify() {
+            fDock = null;
+            super.removeNotify();
+        }
+
+        void updateSize() {
+            final Dimension d = getPreferredSize();
+            setBounds((getParent().getWidth() - d.width) / 2, getParent().getHeight() - d.height, d.width, d.height);
+        }
+
+        public Component add(final Component c) {
+            super.add(c);
+            if (!isVisible()) {
+                setVisible(true);
+            }
+
+            updateSize();
+            validate();
+            return c;
+        }
+
+        public void remove(final Component c) {
+            super.remove(c);
+            if (getComponentCount() == 0) {
+                setVisible(false);
+            } else {
+                updateSize();
+                validate();
+            }
+        }
+
+        public Insets getBorderInsets(final Component c) {
+            return new Insets(DOCK_EDGE_SLACK / 4, DOCK_EDGE_SLACK, 0, DOCK_EDGE_SLACK);
+        }
+
+        public boolean isBorderOpaque() {
+            return false;
+        }
+
+        public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
+            if (!(g instanceof Graphics2D)) return;
+            final Graphics2D g2d = (Graphics2D)g;
+
+            final int height = getHeight();
+            final int width = getWidth();
+
+            final Object priorAA = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+            g2d.setColor(UIManager.getColor("DesktopIcon.borderColor"));
+            g2d.fillRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);
+
+            g2d.setColor(UIManager.getColor("DesktopIcon.borderRimColor"));
+            g2d.setStroke(new BasicStroke(2.0f));
+            g2d.drawRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);
+
+            if (priorAA != null) g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, priorAA);
+        }
+    }
+
+    class AquaDockingDesktopManager extends AquaInternalFrameManager {
+        public void openFrame(final JInternalFrame f) {
+            final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
+            final Container dock = desktopIcon.getParent();
+            if (dock == null) return;
+
+            if (dock.getParent() != null) dock.getParent().add(f);
+            removeIconFor(f);
+        }
+
+        public void deiconifyFrame(final JInternalFrame f) {
+            final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
+            final Container dock = desktopIcon.getParent();
+            if (dock == null) return;
+
+            if (dock.getParent() != null) dock.getParent().add(f);
+            removeIconFor(f);
+            // <rdar://problem/3712485> removed f.show(). show() is now deprecated and
+            // it wasn't sending our frame to front nor selecting it. Now, we move it
+            // to front and select it manualy. (vm)
+            f.moveToFront();
+            try {
+                f.setSelected(true);
+            } catch(final PropertyVetoException pve) { /* do nothing */ }
+        }
+
+        public void iconifyFrame(final JInternalFrame f) {
+            final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
+            // paint the frame onto the icon before hiding the frame, else the contents won't show
+            ((AquaInternalFrameDockIconUI)desktopIcon.getUI()).updateIcon();
+            super.iconifyFrame(f);
+        }
+
+        void addIcon(final Container c, final JInternalFrame.JDesktopIcon desktopIcon) {
+            final DesktopPaneUI ui = ((JDesktopPane)c).getUI();
+            ((AquaInternalFramePaneUI)ui).getDock().add(desktopIcon);
+        }
+    }
+
+    public void mousePressed(final MouseEvent e) {
+        JInternalFrame selectedFrame = desktop.getSelectedFrame();
+        if (selectedFrame != null) {
+            try {
+                selectedFrame.setSelected(false);
+            } catch (PropertyVetoException ex) {}
+            desktop.getDesktopManager().deactivateFrame(selectedFrame);
+        }
+    }
+
+    public void mouseReleased(final MouseEvent e) { }
+    public void mouseClicked(final MouseEvent e) { }
+    public void mouseEntered(final MouseEvent e) { }
+    public void mouseExited(final MouseEvent e) { }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java
new file mode 100644
index 0000000..c10ba57
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java
@@ -0,0 +1,963 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.event.MouseInputAdapter;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicInternalFrameUI;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtils.*;
+import com.apple.laf.AquaUtils.Painter;
+
+import sun.lwawt.macosx.CPlatformWindow;
+
+/**
+ * From AquaInternalFrameUI
+ *
+ * InternalFrame implementation for Aqua LAF
+ *
+ * We want to inherit most of the inner classes, but not the base class,
+ * so be very careful about subclassing so you know you get what you want
+ *
+ */
+public class AquaInternalFrameUI extends BasicInternalFrameUI implements SwingConstants {
+    protected static final String IS_PALETTE_PROPERTY = "JInternalFrame.isPalette";
+    private static final String FRAME_TYPE = "JInternalFrame.frameType";
+    private static final String NORMAL_FRAME = "normal";
+    private static final String PALETTE_FRAME = "palette";
+    private static final String OPTION_DIALOG = "optionDialog";
+
+    // Instance variables
+    PropertyChangeListener fPropertyListener;
+
+    protected Color fSelectedTextColor;
+    protected Color fNotSelectedTextColor;
+
+    AquaInternalFrameBorder fAquaBorder;
+
+    // for button tracking
+    boolean fMouseOverPressedButton;
+    int fWhichButtonPressed = -1;
+    boolean fRollover = false;
+    boolean fDocumentEdited = false; // to indicate whether we should use the dirty document red dot.
+    boolean fIsPallet;
+
+    public int getWhichButtonPressed() {
+        return fWhichButtonPressed;
+    }
+
+    public boolean getMouseOverPressedButton() {
+        return fMouseOverPressedButton;
+    }
+
+    public boolean getRollover() {
+        return fRollover;
+    }
+
+    // ComponentUI Interface Implementation methods
+    public static ComponentUI createUI(final JComponent b) {
+        return new AquaInternalFrameUI((JInternalFrame)b);
+    }
+
+    public AquaInternalFrameUI(final JInternalFrame b) {
+        super(b);
+    }
+
+    /// Inherit  (but be careful to check everything they call):
+    public void installUI(final JComponent c) {
+//        super.installUI(c);  // Swing 1.1.1 has a bug in installUI - it doesn't check for null northPane
+        frame = (JInternalFrame)c;
+        frame.add(frame.getRootPane(), "Center");
+
+        installDefaults();
+        installListeners();
+        installComponents();
+        installKeyboardActions();
+
+        Object paletteProp = c.getClientProperty(IS_PALETTE_PROPERTY);
+        if (paletteProp != null) {
+            setPalette(((Boolean)paletteProp).booleanValue());
+        } else {
+            paletteProp = c.getClientProperty(FRAME_TYPE);
+            if (paletteProp != null) {
+                setFrameType((String)paletteProp);
+            } else {
+                setFrameType(NORMAL_FRAME);
+            }
+        }
+
+        // We only have a southPane, for grow box room, created in setFrameType
+        frame.setMinimumSize(new Dimension(fIsPallet ? 120 : 150, fIsPallet ? 39 : 65));
+        frame.setOpaque(false);
+
+        c.setBorder(new CompoundUIBorder(fIsPallet ? paletteWindowShadow.get() : documentWindowShadow.get(), c.getBorder()));
+    }
+
+    protected void installDefaults() {
+        super.installDefaults();
+        fSelectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
+        fNotSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
+    }
+
+    public void setSouthPane(final JComponent c) {
+        if (southPane != null) {
+            frame.remove(southPane);
+            deinstallMouseHandlers(southPane);
+        }
+        if (c != null) {
+            frame.add(c);
+            installMouseHandlers(c);
+        }
+        southPane = c;
+    }
+
+    static final RecyclableSingleton<Icon> closeIcon = new RecyclableSingleton<Icon>() {
+        protected Icon getInstance() {
+            return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_CLOSE_BOX);
+        }
+    };
+    public static Icon exportCloseIcon() {
+        return closeIcon.get();
+    }
+
+    static final RecyclableSingleton<Icon> minimizeIcon = new RecyclableSingleton<Icon>() {
+        protected Icon getInstance() {
+            return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_COLLAPSE_BOX);
+        }
+    };
+    public static Icon exportMinimizeIcon() {
+        return minimizeIcon.get();
+    }
+
+    static final RecyclableSingleton<Icon> zoomIcon = new RecyclableSingleton<Icon>() {
+        protected Icon getInstance() {
+            return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_ZOOM_BOX);
+        }
+    };
+    public static Icon exportZoomIcon() {
+        return zoomIcon.get();
+    }
+
+    static class AquaInternalFrameButtonIcon extends AquaIcon.JRSUIIcon {
+        public AquaInternalFrameButtonIcon(final Widget widget) {
+            painter.state.set(widget);
+        }
+
+        public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
+            painter.state.set(getStateFor(c));
+            super.paintIcon(c, g, x, y);
+        }
+
+        State getStateFor(final Component c) {
+            return State.ROLLOVER;
+        }
+
+        public int getIconWidth() {
+            return 19;
+        }
+
+        public int getIconHeight() {
+            return 19;
+        }
+    }
+
+    protected void installKeyboardActions() {
+    } //$ Not Mac-ish - should we support?
+
+    protected ResizeBox resizeBox;
+    protected void installComponents() {
+        final JLayeredPane layeredPane = frame.getLayeredPane();
+        if (resizeBox != null) {
+            resizeBox.removeListeners();
+            layeredPane.removeComponentListener(resizeBox);
+            layeredPane.remove(resizeBox);
+            resizeBox = null;
+        }
+
+        resizeBox = new ResizeBox(layeredPane);
+        resizeBox.repositionResizeBox();
+
+        layeredPane.add(resizeBox);
+        layeredPane.setLayer(resizeBox, JLayeredPane.DRAG_LAYER);
+        layeredPane.addComponentListener(resizeBox);
+
+        resizeBox.addListeners();
+        resizeBox.setVisible(frame.isResizable());
+    }
+
+    /// Inherit all the listeners - that's the main reason we subclass Basic!
+    protected void installListeners() {
+        fPropertyListener = new PropertyListener();
+        frame.addPropertyChangeListener(fPropertyListener);
+        super.installListeners();
+    }
+
+    // uninstallDefaults
+    // uninstallComponents
+    protected void uninstallListeners() {
+        super.uninstallListeners();
+        frame.removePropertyChangeListener(fPropertyListener);
+    }
+
+    protected void uninstallKeyboardActions() {
+    }
+
+    // Called when a DesktopIcon replaces an InternalFrame & vice versa
+    //protected void replacePane(JComponent currentPane, JComponent newPane) {}
+    protected void installMouseHandlers(final JComponent c) {
+        c.addMouseListener(borderListener);
+        c.addMouseMotionListener(borderListener);
+    }
+
+    protected void deinstallMouseHandlers(final JComponent c) {
+        c.removeMouseListener(borderListener);
+        c.removeMouseMotionListener(borderListener);
+    }
+
+    ActionMap createActionMap() {
+        final ActionMap map = new ActionMapUIResource();
+        // add action for the system menu
+        // Set the ActionMap's parent to the Auditory Feedback Action Map
+        final AquaLookAndFeel lf = (AquaLookAndFeel)UIManager.getLookAndFeel();
+        final ActionMap audioMap = lf.getAudioActionMap();
+        map.setParent(audioMap);
+        return map;
+    }
+
+    public Dimension minimumLayoutSize(final Container c) {
+        // The minimum size of the internal frame only takes into account the
+        // title pane since you are allowed to resize the frames to the point
+        // where just the title pane is visible.
+        Dimension result = new Dimension();
+        if (getNorthPane() != null) {
+            result = new Dimension(getNorthPane().getMinimumSize());
+        }
+        final Insets i = frame.getInsets();
+        result.width += i.left + i.right;
+        result.height += i.top + i.bottom;
+
+        return result;
+    }
+
+    public void setNorthPane(final JComponent c) {
+        replacePane(northPane, c);
+        northPane = c;
+    }
+
+    /**
+     * Installs necessary mouse handlers on <code>newPane</code>
+     * and adds it to the frame.
+     * Reverse process for the <code>currentPane</code>.
+     */
+    protected void replacePane(final JComponent currentPane, final JComponent newPane) {
+        if (currentPane != null) {
+            deinstallMouseHandlers(currentPane);
+            frame.remove(currentPane);
+        }
+        if (newPane != null) {
+            frame.add(newPane);
+            installMouseHandlers(newPane);
+        }
+    }
+
+    // Our "Border" listener is shared by the AquaDesktopIcon
+    protected MouseInputAdapter createBorderListener(final JInternalFrame w) {
+        return new AquaBorderListener();
+    }
+
+    /**
+     * Mac-specific stuff begins here
+     */
+    void setFrameType(final String frameType) {
+        // Basic sets the background of the contentPane to null so it can inherit JInternalFrame.setBackground
+        // but if *that's* null, we get the JDesktop, which makes ours look invisible!
+        // So JInternalFrame has to have a background color
+        // See Sun bugs 4268949 & 4320889
+        final Color bg = frame.getBackground();
+        final boolean replaceColor = (bg == null || bg instanceof UIResource);
+
+        final Font font = frame.getFont();
+        final boolean replaceFont = (font == null || font instanceof UIResource);
+
+        boolean isPalette = false;
+        if (frameType.equals(OPTION_DIALOG)) {
+            fAquaBorder = AquaInternalFrameBorder.dialog();
+            if (replaceColor) frame.setBackground(UIManager.getColor("InternalFrame.optionDialogBackground"));
+            if (replaceFont) frame.setFont(UIManager.getFont("InternalFrame.optionDialogTitleFont"));
+        } else if (frameType.equals(PALETTE_FRAME)) {
+            fAquaBorder = AquaInternalFrameBorder.utility();
+            if (replaceColor) frame.setBackground(UIManager.getColor("InternalFrame.paletteBackground"));
+            if (replaceFont) frame.setFont(UIManager.getFont("InternalFrame.paletteTitleFont"));
+            isPalette = true;
+        } else {
+            fAquaBorder = AquaInternalFrameBorder.window();
+            if (replaceColor) frame.setBackground(UIManager.getColor("InternalFrame.background"));
+            if (replaceFont) frame.setFont(UIManager.getFont("InternalFrame.titleFont"));
+        }
+        // We don't get the borders from UIManager, in case someone changes them - this class will not work with
+        // different borders.  If they want different ones, they have to make their own InternalFrameUI class
+
+        fAquaBorder.setColors(fSelectedTextColor, fNotSelectedTextColor);
+        frame.setBorder(fAquaBorder);
+
+        fIsPallet = isPalette;
+    }
+
+    public void setPalette(final boolean isPalette) {
+        setFrameType(isPalette ? PALETTE_FRAME : NORMAL_FRAME);
+    }
+
+    public boolean isDocumentEdited() {
+        return fDocumentEdited;
+    }
+
+    public void setDocumentEdited(final boolean flag) {
+        fDocumentEdited = flag;
+    }
+
+/*
+    // helpful debug drawing, shows component and content bounds
+    public void paint(final Graphics g, final JComponent c) {
+        super.paint(g, c);
+
+        g.setColor(Color.green);
+        g.drawRect(0, 0, frame.getWidth() - 1, frame.getHeight() - 1);
+
+        final Insets insets = frame.getInsets();
+        g.setColor(Color.orange);
+        g.drawRect(insets.left - 2, insets.top - 2, frame.getWidth() - insets.left - insets.right + 4, frame.getHeight() - insets.top - insets.bottom + 4);
+    }
+*/
+
+    // Border Listener Class
+    /**
+     * Listens for border adjustments.
+     */
+    protected class AquaBorderListener extends MouseInputAdapter {
+        // _x & _y are the mousePressed location in absolute coordinate system
+        int _x, _y;
+        // __x & __y are the mousePressed location in source view's coordinate system
+        int __x, __y;
+        Rectangle startingBounds;
+        boolean fDraggingFrame;
+        int resizeDir;
+
+        protected final int RESIZE_NONE = 0;
+        private boolean discardRelease = false;
+
+        public void mouseClicked(final MouseEvent e) {
+            if (didForwardEvent(e)) return;
+
+            if (e.getClickCount() <= 1 || e.getSource() != getNorthPane()) return;
+
+            if (frame.isIconifiable() && frame.isIcon()) {
+                try {
+                    frame.setIcon(false);
+                } catch(final PropertyVetoException e2) {}
+            } else if (frame.isMaximizable()) {
+                if (!frame.isMaximum()) try {
+                    frame.setMaximum(true);
+                } catch(final PropertyVetoException e2) {}
+                else try {
+                    frame.setMaximum(false);
+                } catch(final PropertyVetoException e3) {}
+            }
+        }
+
+        public void updateRollover(final MouseEvent e) {
+            final boolean oldRollover = fRollover;
+            final Insets i = frame.getInsets();
+            fRollover = (isTitleBarDraggableArea(e) && fAquaBorder.getWithinRolloverArea(i, e.getX(), e.getY()));
+            if (fRollover != oldRollover) {
+                repaintButtons();
+            }
+        }
+
+        public void repaintButtons() {
+            fAquaBorder.repaintButtonArea(frame);
+        }
+
+        public void mouseReleased(final MouseEvent e) {
+            if (didForwardEvent(e)) return;
+
+            fDraggingFrame = false;
+
+            if (fWhichButtonPressed != -1) {
+                final int newButton = fAquaBorder.getWhichButtonHit(frame, e.getX(), e.getY());
+
+                final int buttonPresed = fWhichButtonPressed;
+                fWhichButtonPressed = -1;
+                fMouseOverPressedButton = false;
+
+                if (buttonPresed == newButton) {
+                    fMouseOverPressedButton = false;
+                    fRollover = false; // not sure if this is needed?
+
+                    fAquaBorder.doButtonAction(frame, buttonPresed);
+                }
+
+                updateRollover(e);
+                repaintButtons();
+                return;
+            }
+
+            if (discardRelease) {
+                discardRelease = false;
+                return;
+            }
+            if (resizeDir == RESIZE_NONE) getDesktopManager().endDraggingFrame(frame);
+            else {
+                final Container c = frame.getTopLevelAncestor();
+                if (c instanceof JFrame) {
+                    ((JFrame)frame.getTopLevelAncestor()).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+
+                    ((JFrame)frame.getTopLevelAncestor()).getGlassPane().setVisible(false);
+                } else if (c instanceof JApplet) {
+                    ((JApplet)c).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+                    ((JApplet)c).getGlassPane().setVisible(false);
+                } else if (c instanceof JWindow) {
+                    ((JWindow)c).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+                    ((JWindow)c).getGlassPane().setVisible(false);
+                } else if (c instanceof JDialog) {
+                    ((JDialog)c).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+                    ((JDialog)c).getGlassPane().setVisible(false);
+                }
+                getDesktopManager().endResizingFrame(frame);
+            }
+            _x = 0;
+            _y = 0;
+            __x = 0;
+            __y = 0;
+            startingBounds = null;
+            resizeDir = RESIZE_NONE;
+        }
+
+        public void mousePressed(final MouseEvent e) {
+            if (didForwardEvent(e)) return;
+
+            final Point p = SwingUtilities.convertPoint((Component)e.getSource(), e.getX(), e.getY(), null);
+            __x = e.getX();
+            __y = e.getY();
+            _x = p.x;
+            _y = p.y;
+            startingBounds = frame.getBounds();
+            resizeDir = RESIZE_NONE;
+
+            if (updatePressed(e)) { return; }
+
+            if (!frame.isSelected()) {
+                try {
+                    frame.setSelected(true);
+                } catch(final PropertyVetoException e1) {}
+            }
+
+            if (isTitleBarDraggableArea(e)) {
+                getDesktopManager().beginDraggingFrame(frame);
+                fDraggingFrame = true;
+                return;
+            }
+
+            if (e.getSource() == getNorthPane()) {
+                getDesktopManager().beginDraggingFrame(frame);
+                return;
+            }
+
+            if (!frame.isResizable()) { return; }
+
+            if (e.getSource() == frame) {
+                discardRelease = true;
+                return;
+            }
+        }
+
+        // returns true if we have handled the pressed
+        public boolean updatePressed(final MouseEvent e) {
+            // get the component.
+            fWhichButtonPressed = getButtonHit(e);
+            fMouseOverPressedButton = true;
+            repaintButtons();
+            return (fWhichButtonPressed >= 0);
+            // e.getX(), e.getY()
+        }
+
+        public int getButtonHit(final MouseEvent e) {
+            return fAquaBorder.getWhichButtonHit(frame, e.getX(), e.getY());
+        }
+
+        public boolean isTitleBarDraggableArea(final MouseEvent e) {
+            if (e.getSource() != frame) return false;
+
+            final Point point = e.getPoint();
+            final Insets insets = frame.getInsets();
+
+            if (point.y < insets.top - fAquaBorder.getTitleHeight()) return false;
+            if (point.y > insets.top) return false;
+            if (point.x < insets.left) return false;
+            if (point.x > frame.getWidth() - insets.left - insets.right) return false;
+
+            return true;
+        }
+
+        public void mouseDragged(final MouseEvent e) {
+// do not forward drags
+//            if (didForwardEvent(e)) return;
+
+            if (startingBounds == null) {
+                // (STEVE) Yucky work around for bug ID 4106552
+                return;
+            }
+
+            if (fWhichButtonPressed != -1) {
+                // track the button we started on.
+                final int newButton = getButtonHit(e);
+                fMouseOverPressedButton = (fWhichButtonPressed == newButton);
+                repaintButtons();
+                return;
+            }
+
+            final Point p = SwingUtilities.convertPoint((Component)e.getSource(), e.getX(), e.getY(), null);
+            final int deltaX = _x - p.x;
+            final int deltaY = _y - p.y;
+            int newX, newY;
+
+            // Handle a MOVE
+            if (!fDraggingFrame && e.getSource() != getNorthPane()) return;
+
+            if (frame.isMaximum() || ((e.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK)) {
+                // don't allow moving of frames if maximixed or left mouse
+                // button was not used.
+                return;
+            }
+
+            final Dimension s = frame.getParent().getSize();
+            final int pWidth = s.width;
+            final int pHeight = s.height;
+
+            final Insets i = frame.getInsets();
+            newX = startingBounds.x - deltaX;
+            newY = startingBounds.y - deltaY;
+
+            // Make sure we stay in-bounds
+            if (newX + i.left <= -__x) newX = -__x - i.left;
+            if (newY + i.top <= -__y) newY = -__y - i.top;
+            if (newX + __x + i.right > pWidth) newX = pWidth - __x - i.right;
+            if (newY + __y + i.bottom > pHeight) newY = pHeight - __y - i.bottom;
+
+            getDesktopManager().dragFrame(frame, newX, newY);
+            return;
+        }
+
+        public void mouseMoved(final MouseEvent e) {
+            if (didForwardEvent(e)) return;
+            updateRollover(e);
+        }
+
+        // guards against accidental infinite recursion
+        boolean isTryingToForwardEvent = false;
+        boolean didForwardEvent(final MouseEvent e) {
+            if (isTryingToForwardEvent) return true; // we didn't actually...but we wound up back where we started.
+
+            isTryingToForwardEvent = true;
+            final boolean didForwardEvent = didForwardEventInternal(e);
+            isTryingToForwardEvent = false;
+
+            return didForwardEvent;
+        }
+
+        boolean didForwardEventInternal(final MouseEvent e) {
+            if (fDraggingFrame) return false;
+
+            final Point originalPoint = e.getPoint();
+            if (!isEventInWindowShadow(originalPoint)) return false;
+
+            final Container parent = frame.getParent();
+            if (!(parent instanceof JDesktopPane)) return false;
+            final JDesktopPane pane = (JDesktopPane)parent;
+            final Point parentPoint = SwingUtilities.convertPoint(frame, originalPoint, parent);
+
+        /*     // debug drawing
+            Graphics g = parent.getGraphics();
+            g.setColor(Color.red);
+            g.drawLine(parentPoint.x, parentPoint.y, parentPoint.x, parentPoint.y);
+        */
+
+            final Component hitComponent = findComponentToHitBehindMe(pane, parentPoint);
+            if (hitComponent == null || hitComponent == frame) return false;
+
+            final Point hitComponentPoint = SwingUtilities.convertPoint(pane, parentPoint, hitComponent);
+            hitComponent.dispatchEvent(new MouseEvent(hitComponent, e.getID(), e.getWhen(), e.getModifiers(), hitComponentPoint.x, hitComponentPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getButton()));
+            return true;
+        }
+
+        Component findComponentToHitBehindMe(final JDesktopPane pane, final Point parentPoint) {
+            final JInternalFrame[] allFrames = pane.getAllFrames();
+
+            boolean foundSelf = false;
+            for (final JInternalFrame f : allFrames) {
+                if (f == frame) { foundSelf = true; continue; }
+                if (!foundSelf) continue;
+
+                final Rectangle bounds = f.getBounds();
+                if (bounds.contains(parentPoint)) return f;
+            }
+
+            return pane;
+        }
+
+        boolean isEventInWindowShadow(final Point point) {
+            final Rectangle bounds = frame.getBounds();
+            final Insets insets = frame.getInsets();
+            insets.top -= fAquaBorder.getTitleHeight();
+
+            if (point.x < insets.left) return true;
+            if (point.x > bounds.width - insets.right) return true;
+            if (point.y < insets.top) return true;
+            if (point.y > bounds.height - insets.bottom) return true;
+
+            return false;
+        }
+    }
+
+    static void updateComponentTreeUIActivation(final Component c, final Object active) {
+        if (c instanceof javax.swing.JComponent) {
+            ((javax.swing.JComponent)c).putClientProperty(AquaFocusHandler.FRAME_ACTIVE_PROPERTY, active);
+        }
+
+        Component[] children = null;
+
+        if (c instanceof javax.swing.JMenu) {
+            children = ((javax.swing.JMenu)c).getMenuComponents();
+        } else if (c instanceof Container) {
+            children = ((Container)c).getComponents();
+        }
+
+        if (children != null) {
+            for (final Component element : children) {
+                updateComponentTreeUIActivation(element, active);
+            }
+        }
+    }
+
+    class PropertyListener implements PropertyChangeListener {
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String name = e.getPropertyName();
+            if (FRAME_TYPE.equals(name)) {
+                if (e.getNewValue() instanceof String) {
+                    setFrameType((String)e.getNewValue());
+                }
+            } else if (IS_PALETTE_PROPERTY.equals(name)) {
+                if (e.getNewValue() != null) {
+                    setPalette(((Boolean)e.getNewValue()).booleanValue());
+                } else {
+                    setPalette(false);
+                }
+                // TODO: CPlatformWindow?
+            } else if ("windowModified".equals(name) || CPlatformWindow.WINDOW_DOCUMENT_MODIFIED.equals(name)) {
+                // repaint title bar
+                setDocumentEdited(((Boolean)e.getNewValue()).booleanValue());
+                frame.repaint(0, 0, frame.getWidth(), frame.getBorder().getBorderInsets(frame).top);
+            } else if ("resizable".equals(name) || "state".equals(name) || "iconable".equals(name) || "maximizable".equals(name) || "closable".equals(name)) {
+                if ("resizable".equals(name)) {
+                    frame.revalidate();
+                }
+                frame.repaint();
+            } else if ("title".equals(name)) {
+                frame.repaint();
+            } else if ("componentOrientation".equals(name)) {
+                frame.revalidate();
+                frame.repaint();
+            } else if (JInternalFrame.IS_SELECTED_PROPERTY.equals(name)) {
+                final Component source = (Component)(e.getSource());
+                updateComponentTreeUIActivation(source, frame.isSelected() ? Boolean.TRUE : Boolean.FALSE);
+            }
+
+        }
+    } // end class PaletteListener
+
+    static final InternalFrameShadow documentWindowShadow = new InternalFrameShadow() {
+        Border getForegroundShadowBorder() {
+            return new AquaUtils.SlicedShadowBorder(new Painter() {
+                public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
+                    g.setColor(new Color(0, 0, 0, 196));
+                    g.fillRoundRect(x, y, w, h, 16, 16);
+                    g.fillRect(x, y + h - 16, w, 16);
+                }
+            }, new Painter() {
+                public void paint(final Graphics g, int x, int y, int w, int h) {
+                    g.setColor(new Color(0, 0, 0, 64));
+                    g.drawLine(x + 2, y - 8, x + w - 2, y - 8);
+                }
+            },
+            0, 7, 1.1f, 1.0f, 24, 51, 51, 25, 25, 25, 25);
+        }
+
+        Border getBackgroundShadowBorder() {
+            return new AquaUtils.SlicedShadowBorder(new Painter() {
+                public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
+                    g.setColor(new Color(0, 0, 0, 128));
+                    g.fillRoundRect(x - 3, y - 8, w + 6, h, 16, 16);
+                    g.fillRect(x - 3, y + h - 20, w + 6, 19);
+                }
+            }, new Painter() {
+                public void paint(final Graphics g, int x, int y, int w, int h) {
+                    g.setColor(new Color(0, 0, 0, 32));
+                    g.drawLine(x, y - 11, x + w - 1, y - 11);
+                }
+            },
+            0, 0, 3.0f, 1.0f, 10, 51, 51, 25, 25, 25, 25);
+        }
+    };
+
+    static final InternalFrameShadow paletteWindowShadow = new InternalFrameShadow() {
+        Border getForegroundShadowBorder() {
+            return new AquaUtils.SlicedShadowBorder(new Painter() {
+                public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
+                    g.setColor(new Color(0, 0, 0, 128));
+                    g.fillRect(x, y + 3, w, h - 3);
+                }
+            }, null,
+            0, 3, 1.0f, 1.0f, 10, 25, 25, 12, 12, 12, 12);
+        }
+
+        Border getBackgroundShadowBorder() {
+            return getForegroundShadowBorder();
+        }
+    };
+
+    static class CompoundUIBorder extends CompoundBorder implements UIResource {
+        public CompoundUIBorder(final Border inside, final Border outside) { super(inside, outside); }
+    }
+
+    abstract static class InternalFrameShadow extends RecyclableSingleton<Border> {
+        abstract Border getForegroundShadowBorder();
+        abstract Border getBackgroundShadowBorder();
+
+        protected Border getInstance() {
+            final Border fgShadow = getForegroundShadowBorder();
+            final Border bgShadow = getBackgroundShadowBorder();
+
+            return new Border() {
+                public Insets getBorderInsets(final Component c) {
+                    return fgShadow.getBorderInsets(c);
+                }
+
+                public boolean isBorderOpaque() {
+                    return false;
+                }
+
+                public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
+                    if (((JInternalFrame)c).isSelected()) {
+                        fgShadow.paintBorder(c, g, x, y, w, h);
+                    } else {
+                        bgShadow.paintBorder(c, g, x, y, w, h);
+                    }
+                }
+            };
+        }
+    }
+
+    static final RecyclableSingleton<Icon> RESIZE_ICON = new RecyclableSingleton<Icon>() {
+        protected Icon getInstance() {
+            return new AquaIcon.CachableJRSUIIcon(11, 11) {
+                public void initIconPainter(final AquaPainter<JRSUIState> iconState) {
+                    iconState.state.set(Widget.GROW_BOX_TEXTURED);
+                    iconState.state.set(WindowType.UTILITY);
+                }
+            };
+        }
+    };
+
+    class ResizeBox extends JLabel implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener, PropertyChangeListener, UIResource {
+        final JLayeredPane layeredPane;
+        Dimension originalSize;
+        Point originalLocation;
+
+        public ResizeBox(final JLayeredPane layeredPane) {
+            super(RESIZE_ICON.get());
+            setSize(11, 11);
+            this.layeredPane = layeredPane;
+
+            addMouseListener(this);
+            addMouseMotionListener(this);
+            addMouseWheelListener(this);
+        }
+
+        void addListeners() {
+            frame.addPropertyChangeListener("resizable", this);
+        }
+
+        void removeListeners() {
+            frame.removePropertyChangeListener("resizable", this);
+        }
+
+        void repositionResizeBox() {
+            if (frame == null) { setSize(0, 0); } else { setSize(11, 11); }
+            setLocation(layeredPane.getWidth() - 12, layeredPane.getHeight() - 12);
+        }
+
+        void resizeInternalFrame(final Point pt) {
+            if (originalLocation == null || frame == null) return;
+
+            final Container parent = frame.getParent();
+            if (!(parent instanceof JDesktopPane)) return;
+
+            final Point newPoint = SwingUtilities.convertPoint(this, pt, frame);
+            int deltaX = originalLocation.x - newPoint.x;
+            int deltaY = originalLocation.y - newPoint.y;
+            final Dimension min = frame.getMinimumSize();
+            final Dimension max = frame.getMaximumSize();
+
+            final int newX = frame.getX();
+            final int newY = frame.getY();
+            int newW = frame.getWidth();
+            int newH = frame.getHeight();
+
+            final Rectangle parentBounds = parent.getBounds();
+
+            if (originalSize.width - deltaX < min.width) {
+                deltaX = originalSize.width - min.width;
+            }  else if (originalSize.width - deltaX > max.width) {
+                deltaX = -(max.width - originalSize.width);
+            }
+
+            if (newX + originalSize.width - deltaX > parentBounds.width) {
+                deltaX = newX + originalSize.width - parentBounds.width;
+            }
+
+            if (originalSize.height - deltaY < min.height) {
+                deltaY = originalSize.height - min.height;
+            }  else if (originalSize.height - deltaY > max.height) {
+                deltaY = -(max.height - originalSize.height);
+            }
+
+            if (newY + originalSize.height - deltaY > parentBounds.height) {
+                deltaY = newY + originalSize.height - parentBounds.height;
+            }
+
+            newW = originalSize.width - deltaX;
+            newH = originalSize.height - deltaY;
+
+            getDesktopManager().resizeFrame(frame, newX, newY, newW, newH);
+        }
+
+        boolean testGrowboxPoint(final int x, final int y, final int w, final int h) {
+            return (w - x) + (h - y) < 12;
+        }
+
+        void forwardEventToFrame(final MouseEvent e) {
+            final Point pt = new Point();
+            final Component c = getComponentToForwardTo(e, pt);
+            if (c == null) return;
+            c.dispatchEvent(new MouseEvent(c, e.getID(), e.getWhen(), e.getModifiers(), pt.x, pt.y, e.getClickCount(), e.isPopupTrigger(), e.getButton()));
+        }
+
+        Component getComponentToForwardTo(final MouseEvent e, final Point dst) {
+            if (frame == null) return null;
+            final Container contentPane = frame.getContentPane();
+            if (contentPane == null) return null;
+            Point pt = SwingUtilities.convertPoint(this, e.getPoint(), contentPane);
+            final Component c = SwingUtilities.getDeepestComponentAt(contentPane, pt.x, pt.y);
+            if (c == null) return null;
+            pt = SwingUtilities.convertPoint(contentPane, pt, c);
+            if (dst != null) dst.setLocation(pt);
+            return c;
+        }
+
+        public void mouseClicked(final MouseEvent e) {
+            forwardEventToFrame(e);
+        }
+
+        public void mouseEntered(final MouseEvent e) { }
+
+        public void mouseExited(final MouseEvent e) { }
+
+        public void mousePressed(final MouseEvent e) {
+            if (frame == null) return;
+
+            if (frame.isResizable() && !frame.isMaximum() && testGrowboxPoint(e.getX(), e.getY(), getWidth(), getHeight())) {
+                originalLocation = SwingUtilities.convertPoint(this, e.getPoint(), frame);
+                originalSize = frame.getSize();
+                getDesktopManager().beginResizingFrame(frame, SwingConstants.SOUTH_EAST);
+                return;
+            }
+
+            forwardEventToFrame(e);
+        }
+
+        public void mouseReleased(final MouseEvent e) {
+            if (originalLocation != null) {
+                resizeInternalFrame(e.getPoint());
+                originalLocation = null;
+                getDesktopManager().endResizingFrame(frame);
+                return;
+            }
+
+            forwardEventToFrame(e);
+        }
+
+        public void mouseDragged(final MouseEvent e) {
+            resizeInternalFrame(e.getPoint());
+            repositionResizeBox();
+        }
+
+        public void mouseMoved(final MouseEvent e) { }
+
+        public void mouseWheelMoved(final MouseWheelEvent e) {
+            final Point pt = new Point();
+            final Component c = getComponentToForwardTo(e, pt);
+            if (c == null) return;
+            c.dispatchEvent(new MouseWheelEvent(c, e.getID(), e.getWhen(), e.getModifiers(), pt.x, pt.y, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation()));
+        }
+
+        public void componentResized(final ComponentEvent e) {
+            repositionResizeBox();
+        }
+
+        public void componentShown(final ComponentEvent e) {
+            repositionResizeBox();
+        }
+
+        public void componentMoved(final ComponentEvent e) {
+            repositionResizeBox();
+        }
+
+        public void componentHidden(final ComponentEvent e) { }
+
+        public void propertyChange(final PropertyChangeEvent evt) {
+            if (!"resizable".equals(evt.getPropertyName())) return;
+            setVisible(Boolean.TRUE.equals(evt.getNewValue()));
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaKeyBindings.java b/jdk/src/macosx/classes/com/apple/laf/AquaKeyBindings.java
new file mode 100644
index 0000000..bbb804a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaKeyBindings.java
@@ -0,0 +1,576 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.event.ActionEvent;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.UIDefaults.LazyValue;
+import javax.swing.text.*;
+import javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaKeyBindings {
+    static final RecyclableSingleton<AquaKeyBindings> instance = new RecyclableSingletonFromDefaultConstructor<AquaKeyBindings>(AquaKeyBindings.class);
+    static AquaKeyBindings instance() {
+        return instance.get();
+    }
+
+    final DefaultKeyTypedAction defaultKeyTypedAction = new DefaultKeyTypedAction();
+    void setDefaultAction(final String keymapName) {
+        final javax.swing.text.Keymap map = JTextComponent.getKeymap(keymapName);
+        map.setDefaultAction(defaultKeyTypedAction);
+    }
+
+    static final String upMultilineAction = "aqua-move-up";
+    static final String downMultilineAction = "aqua-move-down";
+    static final String pageUpMultiline = "aqua-page-up";
+    static final String pageDownMultiline = "aqua-page-down";
+
+    final String[] commonTextEditorBindings = {
+        "ENTER", JTextField.notifyAction,
+        "COPY", DefaultEditorKit.copyAction,
+        "CUT", DefaultEditorKit.cutAction,
+        "PASTE", DefaultEditorKit.pasteAction,
+        "meta A", DefaultEditorKit.selectAllAction,
+        "meta C", DefaultEditorKit.copyAction,
+        "meta V", DefaultEditorKit.pasteAction,
+        "meta X", DefaultEditorKit.cutAction,
+        "meta BACK_SLASH", "unselect",
+
+        "DELETE", DefaultEditorKit.deleteNextCharAction,
+        "alt DELETE", "delete-next-word",
+        "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
+        "alt BACK_SPACE", "delete-previous-word",
+
+        "LEFT", DefaultEditorKit.backwardAction,
+        "KP_LEFT", DefaultEditorKit.backwardAction,
+        "RIGHT", DefaultEditorKit.forwardAction,
+        "KP_RIGHT", DefaultEditorKit.forwardAction,
+        "shift LEFT", DefaultEditorKit.selectionBackwardAction,
+        "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,
+        "shift RIGHT", DefaultEditorKit.selectionForwardAction,
+        "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,
+        "meta LEFT", DefaultEditorKit.beginLineAction,
+        "meta KP_LEFT", DefaultEditorKit.beginLineAction,
+        "meta RIGHT", DefaultEditorKit.endLineAction,
+        "meta KP_RIGHT", DefaultEditorKit.endLineAction,
+        "shift meta LEFT", DefaultEditorKit.selectionBeginLineAction,
+        "shift meta KP_LEFT", DefaultEditorKit.selectionBeginLineAction,
+        "shift meta RIGHT", DefaultEditorKit.selectionEndLineAction,
+        "shift meta KP_RIGHT", DefaultEditorKit.selectionEndLineAction,
+        "alt LEFT", DefaultEditorKit.previousWordAction,
+        "alt KP_LEFT", DefaultEditorKit.previousWordAction,
+        "alt RIGHT", DefaultEditorKit.nextWordAction,
+        "alt KP_RIGHT", DefaultEditorKit.nextWordAction,
+        "shift alt LEFT", DefaultEditorKit.selectionPreviousWordAction,
+        "shift alt KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,
+        "shift alt RIGHT", DefaultEditorKit.selectionNextWordAction,
+        "shift alt KP_RIGHT", DefaultEditorKit.selectionNextWordAction,
+
+        "control A", DefaultEditorKit.beginLineAction,
+        "control B", DefaultEditorKit.backwardAction,
+        "control D", DefaultEditorKit.deleteNextCharAction,
+        "control E", DefaultEditorKit.endLineAction,
+        "control F", DefaultEditorKit.forwardAction,
+        "control H", DefaultEditorKit.deletePrevCharAction,
+        "control W", "delete-previous-word",
+        "control shift O", "toggle-componentOrientation",
+
+        "END", DefaultEditorKit.endAction,
+        "HOME", DefaultEditorKit.beginAction,
+        "shift END", DefaultEditorKit.selectionEndAction,
+        "shift HOME", DefaultEditorKit.selectionBeginAction,
+
+        "PAGE_DOWN", pageDownMultiline,
+        "PAGE_UP", pageUpMultiline,
+        "shift PAGE_DOWN", "selection-page-down",
+        "shift PAGE_UP", "selection-page-up",
+        "meta shift PAGE_DOWN", "selection-page-right",
+        "meta shift PAGE_UP", "selection-page-left",
+
+        "meta DOWN", DefaultEditorKit.endAction,
+        "meta KP_DOWN", DefaultEditorKit.endAction,
+        "meta UP", DefaultEditorKit.beginAction,
+        "meta KP_UP", DefaultEditorKit.beginAction,
+        "shift meta DOWN", DefaultEditorKit.selectionEndAction,
+        "shift meta KP_DOWN", DefaultEditorKit.selectionEndAction,
+        "shift meta UP", DefaultEditorKit.selectionBeginAction,
+        "shift meta KP_UP", DefaultEditorKit.selectionBeginAction,
+    };
+
+    LateBoundInputMap getTextFieldInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(commonTextEditorBindings), new SimpleBinding(new String[] {
+            "DOWN", DefaultEditorKit.endLineAction,
+            "KP_DOWN", DefaultEditorKit.endLineAction,
+            "UP", DefaultEditorKit.beginLineAction,
+            "KP_UP", DefaultEditorKit.beginLineAction,
+            "shift DOWN", DefaultEditorKit.selectionEndLineAction,
+            "shift KP_DOWN", DefaultEditorKit.selectionEndLineAction,
+            "shift UP", DefaultEditorKit.selectionBeginLineAction,
+            "shift KP_UP", DefaultEditorKit.selectionBeginLineAction,
+
+            "control P", DefaultEditorKit.beginAction,
+            "control N", DefaultEditorKit.endAction,
+            "control V", DefaultEditorKit.endAction,
+        }));
+    }
+
+    LateBoundInputMap getMultiLineTextInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(commonTextEditorBindings), new SimpleBinding(new String[] {
+            "ENTER", DefaultEditorKit.insertBreakAction,
+            "DOWN", downMultilineAction,
+            "KP_DOWN", downMultilineAction,
+            "UP", upMultilineAction,
+            "KP_UP", upMultilineAction,
+            "shift DOWN", DefaultEditorKit.selectionDownAction,
+            "shift KP_DOWN", DefaultEditorKit.selectionDownAction,
+            "shift UP", DefaultEditorKit.selectionUpAction,
+            "shift KP_UP", DefaultEditorKit.selectionUpAction,
+            "alt shift DOWN", DefaultEditorKit.selectionEndParagraphAction,
+            "alt shift KP_DOWN", DefaultEditorKit.selectionEndParagraphAction,
+            "alt shift UP", DefaultEditorKit.selectionBeginParagraphAction,
+            "alt shift KP_UP", DefaultEditorKit.selectionBeginParagraphAction,
+
+            "control P", DefaultEditorKit.upAction,
+            "control N", DefaultEditorKit.downAction,
+            "control V", pageDownMultiline,
+
+            "TAB", DefaultEditorKit.insertTabAction,
+            "meta SPACE", "activate-link-action",
+            "meta T", "next-link-action",
+            "meta shift T", "previous-link-action",
+
+            "END", DefaultEditorKit.endAction,
+            "HOME", DefaultEditorKit.beginAction,
+            "shift END", DefaultEditorKit.selectionEndAction,
+            "shift HOME", DefaultEditorKit.selectionBeginAction,
+
+            "PAGE_DOWN", pageDownMultiline,
+            "PAGE_UP", pageUpMultiline,
+            "shift PAGE_DOWN", "selection-page-down",
+            "shift PAGE_UP", "selection-page-up",
+            "meta shift PAGE_DOWN", "selection-page-right",
+            "meta shift PAGE_UP", "selection-page-left",
+        }));
+    }
+
+    LateBoundInputMap getFormattedTextFieldInputMap() {
+        return new LateBoundInputMap(getTextFieldInputMap(), new SimpleBinding(new String[] {
+            "UP", "increment",
+            "KP_UP", "increment",
+            "DOWN", "decrement",
+            "KP_DOWN", "decrement",
+
+            "ESCAPE", "reset-field-edit",
+        }));
+    }
+
+    LateBoundInputMap getComboBoxInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "ESCAPE", "hidePopup",
+            "PAGE_UP", "aquaSelectPageUp",
+            "PAGE_DOWN", "aquaSelectPageDown",
+            "HOME", "aquaSelectHome",
+            "END", "aquaSelectEnd",
+            "ENTER", "aquaEnterPressed",
+            "UP", "aquaSelectPrevious",
+            "KP_UP", "aquaSelectPrevious",
+            "DOWN", "aquaSelectNext",
+            "KP_DOWN", "aquaSelectNext",
+            "SPACE", "aquaSpacePressed" // "spacePopup"
+        }));
+    }
+
+    LateBoundInputMap getListInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "meta C", "copy",
+            "meta V", "paste",
+            "meta X", "cut",
+            "COPY", "copy",
+            "PASTE", "paste",
+            "CUT", "cut",
+            "UP", "selectPreviousRow",
+            "KP_UP", "selectPreviousRow",
+            "shift UP", "selectPreviousRowExtendSelection",
+            "shift KP_UP", "selectPreviousRowExtendSelection",
+            "DOWN", "selectNextRow",
+            "KP_DOWN", "selectNextRow",
+            "shift DOWN", "selectNextRowExtendSelection",
+            "shift KP_DOWN", "selectNextRowExtendSelection",
+            "LEFT", "selectPreviousColumn",
+            "KP_LEFT", "selectPreviousColumn",
+            "shift LEFT", "selectPreviousColumnExtendSelection",
+            "shift KP_LEFT", "selectPreviousColumnExtendSelection",
+            "RIGHT", "selectNextColumn",
+            "KP_RIGHT", "selectNextColumn",
+            "shift RIGHT", "selectNextColumnExtendSelection",
+            "shift KP_RIGHT", "selectNextColumnExtendSelection",
+            "meta A", "selectAll",
+
+            // aquaHome and aquaEnd are new actions that just move the view so the first or last item is visible.
+            "HOME", "aquaHome",
+            "shift HOME", "selectFirstRowExtendSelection",
+            "END", "aquaEnd",
+            "shift END", "selectLastRowExtendSelection",
+
+            // Unmodified PAGE_UP and PAGE_DOWN are handled by their scroll pane, if any.
+            "shift PAGE_UP", "scrollUpExtendSelection",
+            "shift PAGE_DOWN", "scrollDownExtendSelection"
+        }));
+    }
+
+    LateBoundInputMap getScrollBarInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "RIGHT", "positiveUnitIncrement",
+            "KP_RIGHT", "positiveUnitIncrement",
+            "DOWN", "positiveUnitIncrement",
+            "KP_DOWN", "positiveUnitIncrement",
+            "PAGE_DOWN", "positiveBlockIncrement",
+            "LEFT", "negativeUnitIncrement",
+            "KP_LEFT", "negativeUnitIncrement",
+            "UP", "negativeUnitIncrement",
+            "KP_UP", "negativeUnitIncrement",
+            "PAGE_UP", "negativeBlockIncrement",
+            "HOME", "minScroll",
+            "END", "maxScroll"
+        }));
+    }
+
+    LateBoundInputMap getScrollBarRightToLeftInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "RIGHT", "negativeUnitIncrement",
+            "KP_RIGHT", "negativeUnitIncrement",
+            "LEFT", "positiveUnitIncrement",
+            "KP_LEFT", "positiveUnitIncrement"
+        }));
+    }
+
+    LateBoundInputMap getScrollPaneInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "RIGHT", "unitScrollRight",
+            "KP_RIGHT", "unitScrollRight",
+            "DOWN", "unitScrollDown",
+            "KP_DOWN", "unitScrollDown",
+            "LEFT", "unitScrollLeft",
+            "KP_LEFT", "unitScrollLeft",
+            "UP", "unitScrollUp",
+            "KP_UP", "unitScrollUp",
+            "PAGE_UP", "scrollUp",
+            "PAGE_DOWN", "scrollDown",
+            "HOME", "scrollHome",
+            "END", "scrollEnd"
+        }));
+    }
+
+    LateBoundInputMap getSliderInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "RIGHT", "positiveUnitIncrement",
+            "KP_RIGHT", "positiveUnitIncrement",
+            "DOWN", "negativeUnitIncrement",
+            "KP_DOWN", "negativeUnitIncrement",
+            "PAGE_DOWN", "negativeBlockIncrement",
+            "LEFT", "negativeUnitIncrement",
+            "KP_LEFT", "negativeUnitIncrement",
+            "UP", "positiveUnitIncrement",
+            "KP_UP", "positiveUnitIncrement",
+            "PAGE_UP", "positiveBlockIncrement",
+            "HOME", "minScroll",
+            "END", "maxScroll"
+        }));
+    }
+
+    LateBoundInputMap getSliderRightToLeftInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "RIGHT", "negativeUnitIncrement",
+            "KP_RIGHT", "negativeUnitIncrement",
+            "LEFT", "positiveUnitIncrement",
+            "KP_LEFT", "positiveUnitIncrement"
+        }));
+    }
+
+    LateBoundInputMap getSpinnerInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "UP", "increment",
+            "KP_UP", "increment",
+            "DOWN", "decrement",
+            "KP_DOWN", "decrement"
+        }));
+    }
+
+    LateBoundInputMap getTableInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "meta C", "copy",
+            "meta V", "paste",
+            "meta X", "cut",
+            "COPY", "copy",
+            "PASTE", "paste",
+            "CUT", "cut",
+            "RIGHT", "selectNextColumn",
+            "KP_RIGHT", "selectNextColumn",
+            "LEFT", "selectPreviousColumn",
+            "KP_LEFT", "selectPreviousColumn",
+            "DOWN", "selectNextRow",
+            "KP_DOWN", "selectNextRow",
+            "UP", "selectPreviousRow",
+            "KP_UP", "selectPreviousRow",
+            "shift RIGHT", "selectNextColumnExtendSelection",
+            "shift KP_RIGHT", "selectNextColumnExtendSelection",
+            "shift LEFT", "selectPreviousColumnExtendSelection",
+            "shift KP_LEFT", "selectPreviousColumnExtendSelection",
+            "shift DOWN", "selectNextRowExtendSelection",
+            "shift KP_DOWN", "selectNextRowExtendSelection",
+            "shift UP", "selectPreviousRowExtendSelection",
+            "shift KP_UP", "selectPreviousRowExtendSelection",
+            "PAGE_UP", "scrollUpChangeSelection",
+            "PAGE_DOWN", "scrollDownChangeSelection",
+            "HOME", "selectFirstColumn",
+            "END", "selectLastColumn",
+            "shift PAGE_UP", "scrollUpExtendSelection",
+            "shift PAGE_DOWN", "scrollDownExtendSelection",
+            "shift HOME", "selectFirstColumnExtendSelection",
+            "shift END", "selectLastColumnExtendSelection",
+            "TAB", "selectNextColumnCell",
+            "shift TAB", "selectPreviousColumnCell",
+            "meta A", "selectAll",
+            "ESCAPE", "cancel",
+            "ENTER", "selectNextRowCell",
+            "shift ENTER", "selectPreviousRowCell",
+            "alt TAB", "focusHeader",
+            "alt shift TAB", "focusHeader"
+        }));
+    }
+
+    LateBoundInputMap getTableRightToLeftInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "RIGHT", "selectPreviousColumn",
+            "KP_RIGHT", "selectPreviousColumn",
+            "LEFT", "selectNextColumn",
+            "KP_LEFT", "selectNextColumn",
+            "shift RIGHT", "selectPreviousColumnExtendSelection",
+            "shift KP_RIGHT", "selectPreviousColumnExtendSelection",
+            "shift LEFT", "selectNextColumnExtendSelection",
+            "shift KP_LEFT", "selectNextColumnExtendSelection",
+            "ctrl PAGE_UP", "scrollRightChangeSelection",
+            "ctrl PAGE_DOWN", "scrollLeftChangeSelection",
+            "ctrl shift PAGE_UP", "scrollRightExtendSelection",
+            "ctrl shift PAGE_DOWN", "scrollLeftExtendSelection"
+        }));
+    }
+
+    LateBoundInputMap getTreeInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "meta C", "copy",
+            "meta V", "paste",
+            "meta X", "cut",
+            "COPY", "copy",
+            "PASTE", "paste",
+            "CUT", "cut",
+            "UP", "selectPrevious",
+            "KP_UP", "selectPrevious",
+            "shift UP", "selectPreviousExtendSelection",
+            "shift KP_UP", "selectPreviousExtendSelection",
+            "DOWN", "selectNext",
+            "KP_DOWN", "selectNext",
+            "shift DOWN", "selectNextExtendSelection",
+            "shift KP_DOWN", "selectNextExtendSelection",
+            "RIGHT", "aquaExpandNode",
+            "KP_RIGHT", "aquaExpandNode",
+            "LEFT", "aquaCollapseNode",
+            "KP_LEFT", "aquaCollapseNode",
+            "shift RIGHT", "aquaExpandNode",
+            "shift KP_RIGHT", "aquaExpandNode",
+            "shift LEFT", "aquaCollapseNode",
+            "shift KP_LEFT", "aquaCollapseNode",
+            "ctrl LEFT", "aquaCollapseNode",
+            "ctrl KP_LEFT", "aquaCollapseNode",
+            "ctrl RIGHT", "aquaExpandNode",
+            "ctrl KP_RIGHT", "aquaExpandNode",
+            "alt RIGHT", "aquaFullyExpandNode",
+            "alt KP_RIGHT", "aquaFullyExpandNode",
+            "alt LEFT", "aquaFullyCollapseNode",
+            "alt KP_LEFT", "aquaFullyCollapseNode",
+            "meta A", "selectAll",
+            "RETURN", "startEditing"
+        }));
+    }
+
+    LateBoundInputMap getTreeRightToLeftInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(new String[] {
+            "RIGHT", "aquaCollapseNode",
+            "KP_RIGHT", "aquaCollapseNode",
+            "LEFT", "aquaExpandNode",
+            "KP_LEFT", "aquaExpandNode",
+            "shift RIGHT", "aquaCollapseNode",
+            "shift KP_RIGHT", "aquaCollapseNode",
+            "shift LEFT", "aquaExpandNode",
+            "shift KP_LEFT", "aquaExpandNode",
+            "ctrl LEFT", "aquaExpandNode",
+            "ctrl KP_LEFT", "aquaExpandNode",
+            "ctrl RIGHT", "aquaCollapseNode",
+            "ctrl KP_RIGHT", "aquaCollapseNode"
+        }));
+    }
+
+    // common interface between a string array, and a dynamic provider of string arrays ;-)
+    interface BindingsProvider {
+        public String[] getBindings();
+    }
+
+    // wraps basic string arrays
+    static class SimpleBinding implements BindingsProvider {
+        final String[] bindings;
+        public SimpleBinding(final String[] bindings) { this.bindings = bindings; }
+        public String[] getBindings() { return bindings; }
+    }
+
+    // patches all providers together at the moment the UIManager needs the real InputMap
+    static class LateBoundInputMap implements LazyValue, BindingsProvider {
+        private final BindingsProvider[] providerList;
+        private String[] mergedBindings;
+
+        public LateBoundInputMap(final BindingsProvider ... providerList) {
+            this.providerList = providerList;
+        }
+
+        public Object createValue(final UIDefaults table) {
+            return LookAndFeel.makeInputMap(getBindings());
+        }
+
+        public String[] getBindings() {
+            if (mergedBindings != null) return mergedBindings;
+
+            final String[][] bindingsList = new String[providerList.length][];
+            int size = 0;
+            for (int i = 0; i < providerList.length; i++) {
+                bindingsList[i] = providerList[i].getBindings();
+                size += bindingsList[i].length;
+            }
+
+            if (bindingsList.length == 1) {
+                return mergedBindings = bindingsList[0];
+            }
+
+            final ArrayList<String> unifiedList = new ArrayList<String>(size);
+            Collections.addAll(unifiedList, bindingsList[0]); // System.arrayCopy() the first set
+
+            for (int i = 1; i < providerList.length; i++) {
+                mergeBindings(unifiedList, bindingsList[i]);
+            }
+
+            return mergedBindings = unifiedList.toArray(new String[unifiedList.size()]);
+        }
+
+        static void mergeBindings(final ArrayList<String> unifiedList, final String[] overrides) {
+            for (int i = 0; i < overrides.length; i+=2) {
+                final String key = overrides[i];
+                final String value = overrides[i+1];
+
+                final int keyIndex = unifiedList.indexOf(key);
+                if (keyIndex == -1) {
+                    unifiedList.add(key);
+                    unifiedList.add(value);
+                } else {
+                    unifiedList.set(keyIndex, key);
+                    unifiedList.set(keyIndex + 1, value);
+                }
+            }
+        }
+    }
+
+    void installAquaUpDownActions(final JTextComponent component) {
+        final ActionMap actionMap = component.getActionMap();
+        actionMap.put(upMultilineAction, moveUpMultilineAction);
+        actionMap.put(downMultilineAction, moveDownMultilineAction);
+        actionMap.put(pageUpMultiline, pageUpMultilineAction);
+        actionMap.put(pageDownMultiline, pageDownMultilineAction);
+    }
+
+    // extracted and adapted from DefaultEditorKit in 1.6
+    static abstract class DeleteWordAction extends TextAction {
+        public DeleteWordAction(final String name) { super(name); }
+
+        public void actionPerformed(final ActionEvent e) {
+            if (e == null) return;
+
+            final JTextComponent target = getTextComponent(e);
+            if (target == null) return;
+
+            if (!target.isEditable() || !target.isEnabled()) {
+                UIManager.getLookAndFeel().provideErrorFeedback(target);
+                return;
+            }
+
+            try {
+                final int start = target.getSelectionStart();
+                final Element line = Utilities.getParagraphElement(target, start);
+                final int end = getEnd(target, line, start);
+
+                final int offs = Math.min(start, end);
+                final int len = Math.abs(end - start);
+                if (offs >= 0) {
+                    target.getDocument().remove(offs, len);
+                    return;
+                }
+            } catch (final BadLocationException ignore) {}
+            UIManager.getLookAndFeel().provideErrorFeedback(target);
+        }
+
+        abstract int getEnd(final JTextComponent target, final Element line, final int start) throws BadLocationException;
+    }
+
+    final TextAction moveUpMultilineAction = new AquaMultilineAction(upMultilineAction, DefaultEditorKit.upAction, DefaultEditorKit.beginAction);
+    final TextAction moveDownMultilineAction = new AquaMultilineAction(downMultilineAction, DefaultEditorKit.downAction, DefaultEditorKit.endAction);
+    final TextAction pageUpMultilineAction = new AquaMultilineAction(pageUpMultiline, DefaultEditorKit.pageUpAction, DefaultEditorKit.beginAction);
+    final TextAction pageDownMultilineAction = new AquaMultilineAction(pageDownMultiline, DefaultEditorKit.pageDownAction, DefaultEditorKit.endAction);
+
+    static class AquaMultilineAction extends TextAction {
+        final String targetActionName;
+        final String proxyActionName;
+
+        public AquaMultilineAction(final String actionName, final String targetActionName, final String proxyActionName) {
+            super(actionName);
+            this.targetActionName = targetActionName;
+            this.proxyActionName = proxyActionName;
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            final JTextComponent c = getTextComponent(e);
+            final ActionMap actionMap = c.getActionMap();
+            final Action targetAction = actionMap.get(targetActionName);
+
+            final int startPosition = c.getCaretPosition();
+            targetAction.actionPerformed(e);
+            if (startPosition != c.getCaretPosition()) return;
+
+            final Action proxyAction = actionMap.get(proxyActionName);
+            proxyAction.actionPerformed(e);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaLabelUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaLabelUI.java
new file mode 100644
index 0000000..cef2488
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaLabelUI.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.*;
+
+import sun.swing.SwingUtilities2;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaLabelUI extends BasicLabelUI {
+    protected static final  RecyclableSingleton<AquaLabelUI> aquaLabelUI = new RecyclableSingletonFromDefaultConstructor<AquaLabelUI>(AquaLabelUI.class);
+
+    public static ComponentUI createUI(final JComponent c) {
+        return aquaLabelUI.get();
+    }
+
+    protected void installListeners(final JLabel c) {
+        super.installListeners(c);
+        AquaUtilControlSize.addSizePropertyListener(c);
+    }
+
+    protected void uninstallListeners(final JLabel c) {
+        AquaUtilControlSize.removeSizePropertyListener(c);
+        super.uninstallListeners(c);
+    }
+
+    protected void paintEnabledText(final JLabel l, final Graphics g, final String s, final int textX, final int textY) {
+        int mnemIndex = l.getDisplayedMnemonicIndex();
+        if (AquaMnemonicHandler.isMnemonicHidden()) {
+            mnemIndex = -1;
+        }
+
+        g.setColor(l.getForeground());
+        SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex, textX, textY);
+    }
+
+    /**
+     * Paint clippedText at textX, textY with background.lighter() and then
+     * shifted down and to the right by one pixel with background.darker().
+     *
+     * @see #paint
+     * @see #paintEnabledText
+     */
+    protected void paintDisabledText(final JLabel l, final Graphics g, final String s, final int textX, final int textY) {
+        int accChar = l.getDisplayedMnemonicIndex();
+        if (AquaMnemonicHandler.isMnemonicHidden()) {
+            accChar = -1;
+        }
+
+        final Color background = l.getBackground();
+
+        // if our background is still something we set then we can use our happy background color.
+        if (background instanceof UIResource) {
+            g.setColor(getDisabledLabelColor(l));
+            SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar, textX, textY);
+        } else {
+            super.paintDisabledText(l, g, s, textX, textY);
+        }
+    }
+
+    static final String DISABLED_COLOR_KEY = "Label.disabledForegroundColor";
+    protected Color getDisabledLabelColor(final JLabel label) {
+        final Color fg = label.getForeground();
+
+        final Object colorProperty = label.getClientProperty(DISABLED_COLOR_KEY);
+        if (colorProperty instanceof Color) {
+            final Color disabledColor = (Color)colorProperty;
+            if ((fg.getRGB() << 8) == (disabledColor.getRGB() << 8)) return disabledColor;
+        }
+
+        final Color newDisabledColor = new Color(fg.getRed(), fg.getGreen(), fg.getBlue(), fg.getAlpha() / 2);
+        label.putClientProperty(DISABLED_COLOR_KEY, newDisabledColor);
+        return newDisabledColor;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaListUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaListUI.java
new file mode 100644
index 0000000..661e1f0
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaListUI.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.event.MouseInputListener;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicListUI;
+
+import apple.laf.JRSUIConstants.*;
+
+/**
+ * A Mac L&F implementation of JList
+ *
+ * All this does is look for a ThemeBorder and invalidate it when the focus changes
+ */
+public class AquaListUI extends BasicListUI {
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaListUI();
+    }
+
+    /**
+     * Creates the focus listener to repaint the focus ring
+     */
+    protected FocusListener createFocusListener() {
+        return new AquaListUI.FocusHandler();
+    }
+
+    /**
+     * Creates a delegate that implements MouseInputListener.
+     */
+    protected MouseInputListener createMouseInputListener() {
+        return new AquaListUI.MouseInputHandler();
+    }
+
+    protected void installKeyboardActions() {
+        super.installKeyboardActions();
+        list.getActionMap().put("aquaHome", new AquaHomeEndAction(true));
+        list.getActionMap().put("aquaEnd", new AquaHomeEndAction(false));
+    }
+
+    static class AquaHomeEndAction extends AbstractAction {
+        private boolean fHomeAction = false;
+
+        protected AquaHomeEndAction(final boolean isHomeAction) {
+            fHomeAction = isHomeAction;
+        }
+
+        /**
+         * For a Home action, scrolls to the top. Otherwise, scroll to the end.
+         */
+        public void actionPerformed(final ActionEvent e) {
+            final JList list = (JList)e.getSource();
+
+            if (fHomeAction) {
+                list.ensureIndexIsVisible(0);
+            } else {
+                final int size = list.getModel().getSize();
+                list.ensureIndexIsVisible(size - 1);
+            }
+        }
+    }
+
+    /**
+     * This inner class is marked &quot;public&quot; due to a compiler bug. This class should be treated as a
+     * &quot;protected&quot; inner class. Instantiate it only within subclasses of BasicListUI.
+     */
+    class FocusHandler extends BasicListUI.FocusHandler {
+        public void focusGained(final FocusEvent e) {
+            super.focusGained(e);
+            AquaBorder.repaintBorder(getComponent());
+        }
+
+        public void focusLost(final FocusEvent e) {
+            super.focusLost(e);
+            AquaBorder.repaintBorder(getComponent());
+        }
+    }
+
+    protected PropertyChangeListener createPropertyChangeListener() {
+        return new AquaPropertyChangeHandler();
+    }
+
+    class AquaPropertyChangeHandler extends PropertyChangeHandler {
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String prop = e.getPropertyName();
+            if (AquaFocusHandler.FRAME_ACTIVE_PROPERTY.equals(prop)) {
+                AquaBorder.repaintBorder(getComponent());
+                AquaFocusHandler.swapSelectionColors("List", getComponent(), e.getNewValue());
+            } else {
+                super.propertyChange(e);
+            }
+        }
+    }
+
+    // TODO: Using default handler for now, need to handle cmd-key
+
+    // Replace the mouse event with one that returns the cmd-key state when asked
+    // for the control-key state, which super assumes is what everyone does to discontiguously extend selections
+    class MouseInputHandler extends BasicListUI.MouseInputHandler {
+        /*public void mousePressed(final MouseEvent e) {
+            super.mousePressed(new SelectionMouseEvent(e));
+        }
+        public void mouseDragged(final MouseEvent e) {
+            super.mouseDragged(new SelectionMouseEvent(e));
+        }*/
+    }
+
+    JList getComponent() {
+        return list;
+    }
+
+    // this is used for blinking combobox popup selections when they are selected
+    protected void repaintCell(final Object value, final int selectedIndex, final boolean selected) {
+        final Rectangle rowBounds = getCellBounds(list, selectedIndex, selectedIndex);
+        if (rowBounds == null) return;
+
+        final ListCellRenderer renderer = list.getCellRenderer();
+        if (renderer == null) return;
+
+        final Component rendererComponent = renderer.getListCellRendererComponent(list, value, selectedIndex, selected, true);
+        if (rendererComponent == null) return;
+
+        final AquaComboBoxRenderer aquaRenderer = renderer instanceof AquaComboBoxRenderer ? (AquaComboBoxRenderer)renderer : null;
+        if (aquaRenderer != null) aquaRenderer.setDrawCheckedItem(false);
+        rendererPane.paintComponent(list.getGraphics().create(), rendererComponent, list, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height, true);
+        if (aquaRenderer != null) aquaRenderer.setDrawCheckedItem(true);
+    }
+
+    /*
+    Insert note on JIDESoft naughtiness
+    */
+    public static Border getSourceListBackgroundPainter() {
+        final AquaBorder border = new ComponentPainter();
+        border.painter.state.set(Widget.GRADIENT);
+        border.painter.state.set(Variant.GRADIENT_SIDE_BAR);
+        return border;
+    }
+
+    public static Border getSourceListSelectionBackgroundPainter() {
+        final AquaBorder border = new ComponentPainter();
+        border.painter.state.set(Widget.GRADIENT);
+        border.painter.state.set(Variant.GRADIENT_SIDE_BAR_SELECTION);
+        return border;
+    }
+
+    public static Border getSourceListFocusedSelectionBackgroundPainter() {
+        final AquaBorder border = new ComponentPainter();
+        border.painter.state.set(Widget.GRADIENT);
+        border.painter.state.set(Variant.GRADIENT_SIDE_BAR_FOCUSED_SELECTION);
+        return border;
+    }
+
+    public static Border getListEvenBackgroundPainter() {
+        final AquaBorder border = new ComponentPainter();
+        border.painter.state.set(Widget.GRADIENT);
+        border.painter.state.set(Variant.GRADIENT_LIST_BACKGROUND_EVEN);
+        return border;
+    }
+
+    public static Border getListOddBackgroundPainter() {
+        final AquaBorder border = new ComponentPainter();
+        border.painter.state.set(Widget.GRADIENT);
+        border.painter.state.set(Variant.GRADIENT_LIST_BACKGROUND_ODD);
+        return border;
+    }
+
+    static class ComponentPainter extends AquaBorder.Default {
+        public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
+            final JComponent jc = c instanceof JComponent ? (JComponent)c : null;
+            if (jc != null && !AquaFocusHandler.isActive(jc)) {
+                painter.state.set(State.INACTIVE);
+            } else {
+                painter.state.set(State.ACTIVE);
+            }
+            super.paintBorder(c, g, x, y, w, h);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaLookAndFeel.java b/jdk/src/macosx/classes/com/apple/laf/AquaLookAndFeel.java
new file mode 100644
index 0000000..f95de47
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaLookAndFeel.java
@@ -0,0 +1,1086 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.security.PrivilegedAction;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicLookAndFeel;
+
+import sun.swing.*;
+import apple.laf.*;
+
+import com.apple.resources.MacOSXResourceBundle;
+
+public class AquaLookAndFeel extends BasicLookAndFeel {
+    static final String sOldPropertyPrefix = "com.apple.macos."; // old prefix for things like 'useScreenMenuBar'
+    static final String sPropertyPrefix = "apple.laf."; // new prefix for things like 'useScreenMenuBar'
+
+    // for lazy initalizers. Following the pattern from metal.
+    private static final String PKG_PREFIX = "com.apple.laf.";
+    private static final String kAquaImageFactoryName = PKG_PREFIX + "AquaImageFactory";
+    private static final String kAquaFontsName = PKG_PREFIX + "AquaFonts";
+
+    /**
+     * Return a short string that identifies this look and feel, e.g.
+     * "CDE/Motif".  This string should be appropriate for a menu item.
+     * Distinct look and feels should have different names, e.g.
+     * a subclass of MotifLookAndFeel that changes the way a few components
+     * are rendered should be called "CDE/Motif My Way"; something
+     * that would be useful to a user trying to select a L&F from a list
+     * of names.
+     */
+    public String getName() {
+        return "Mac OS X";
+    }
+
+    /**
+     * Return a string that identifies this look and feel.  This string
+     * will be used by applications/services that want to recognize
+     * well known look and feel implementations.  Presently
+     * the well known names are "Motif", "Windows", "Mac", "Metal".  Note
+     * that a LookAndFeel derived from a well known superclass
+     * that doesn't make any fundamental changes to the look or feel
+     * shouldn't override this method.
+     */
+    public String getID() {
+        return "Aqua";
+    }
+
+    /**
+     * Return a one line description of this look and feel implementation,
+     * e.g. "The CDE/Motif Look and Feel".   This string is intended for
+     * the user, e.g. in the title of a window or in a ToolTip message.
+     */
+    public String getDescription() {
+        return "Aqua Look and Feel for Mac OS X";
+    }
+
+    /**
+     * Returns true if the <code>LookAndFeel</code> returned
+     * <code>RootPaneUI</code> instances support providing Window decorations
+     * in a <code>JRootPane</code>.
+     * <p>
+     * The default implementation returns false, subclasses that support
+     * Window decorations should override this and return true.
+     *
+     * @return True if the RootPaneUI instances created support client side
+     *             decorations
+     * @see JDialog#setDefaultLookAndFeelDecorated
+     * @see JFrame#setDefaultLookAndFeelDecorated
+     * @see JRootPane#setWindowDecorationStyle
+     * @since 1.4
+     */
+    public boolean getSupportsWindowDecorations() {
+        return false;
+    }
+
+    /**
+     * If the underlying platform has a "native" look and feel, and this
+     * is an implementation of it, return true.
+     */
+    public boolean isNativeLookAndFeel() {
+        return true;
+    }
+
+    /**
+     * Return true if the underlying platform supports and or permits
+     * this look and feel.  This method returns false if the look
+     * and feel depends on special resources or legal agreements that
+     * aren't defined for the current platform.
+     *
+     * @see UIManager#setLookAndFeel
+     */
+    public boolean isSupportedLookAndFeel() {
+        return true;
+    }
+
+    /**
+     * UIManager.setLookAndFeel calls this method before the first
+     * call (and typically the only call) to getDefaults().  Subclasses
+     * should do any one-time setup they need here, rather than
+     * in a static initializer, because look and feel class objects
+     * may be loaded just to discover that isSupportedLookAndFeel()
+     * returns false.
+     *
+     * @see #uninitialize
+     * @see UIManager#setLookAndFeel
+     */
+    public void initialize() {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osxui"));
+        java.security.AccessController.doPrivileged(new PrivilegedAction<Object>(){
+            @Override
+            public Object run() {
+                JRSUIControl.initJRSUI();
+                return null;
+            }
+        });
+
+        super.initialize();
+        final ScreenPopupFactory spf = new ScreenPopupFactory();
+        spf.setActive(true);
+        PopupFactory.setSharedInstance(spf);
+
+        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(AquaMnemonicHandler.getInstance());
+    }
+
+    /**
+     * UIManager.setLookAndFeel calls this method just before we're
+     * replaced by a new default look and feel.   Subclasses may
+     * choose to free up some resources here.
+     *
+     * @see #initialize
+     */
+    public void uninitialize() {
+        KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventPostProcessor(AquaMnemonicHandler.getInstance());
+
+        final PopupFactory popupFactory = PopupFactory.getSharedInstance();
+        if (popupFactory != null && popupFactory instanceof ScreenPopupFactory) {
+            ((ScreenPopupFactory)popupFactory).setActive(false);
+        }
+
+        super.uninitialize();
+    }
+
+    /**
+     * Returns an <code>ActionMap</code>.
+     * <P>
+     * This <code>ActionMap</code> contains <code>Actions</code> that
+     * embody the ability to render an auditory cue. These auditory
+     * cues map onto user and system activities that may be useful
+     * for an end user to know about (such as a dialog box appearing).
+     * <P>
+     * At the appropriate time in a <code>JComponent</code> UI's lifecycle,
+     * the ComponentUI is responsible for getting the appropriate
+     * <code>Action</code> out of the <code>ActionMap</code> and passing
+     * it on to <code>playSound</code>.
+     * <P>
+     * The <code>Actions</code> in this <code>ActionMap</code> are
+     * created by the <code>createAudioAction</code> method.
+     *
+     * @return      an ActionMap containing Actions
+     *              responsible for rendering auditory cues
+     * @see #createAudioAction
+     * @see #playSound(Action)
+     * @since 1.4
+     */
+    protected ActionMap getAudioActionMap() {
+        ActionMap audioActionMap = (ActionMap)UIManager.get("AuditoryCues.actionMap");
+        if (audioActionMap != null) return audioActionMap;
+
+        final Object[] acList = (Object[])UIManager.get("AuditoryCues.cueList");
+        if (acList != null) {
+            audioActionMap = new ActionMapUIResource();
+            for (int counter = acList.length - 1; counter >= 0; counter--) {
+                audioActionMap.put(acList[counter], createAudioAction(acList[counter]));
+            }
+        }
+        UIManager.getLookAndFeelDefaults().put("AuditoryCues.actionMap", audioActionMap);
+
+        return audioActionMap;
+    }
+
+    /**
+     * We override getDefaults() so we can install our own debug defaults
+     * if needed for testing
+     */
+    public UIDefaults getDefaults() {
+        final UIDefaults table = new UIDefaults();
+        // use debug defaults if you want to see every query into the defaults object.
+        //UIDefaults table = new DebugDefaults();
+        try {
+            // PopupFactory.getSharedInstance().setPopupType(2);
+            initClassDefaults(table);
+
+            // Here we install all the Basic defaults in case we missed some in our System color
+            // or component defaults that follow. Eventually we will take this out.
+            // This is a big negative to performance so we want to get it out as soon
+            // as we are comfortable with the Aqua defaults.
+            super.initSystemColorDefaults(table);
+            super.initComponentDefaults(table);
+
+            // Because the last elements added win in precedence we add all of our aqua elements here.
+            initSystemColorDefaults(table);
+            initComponentDefaults(table);
+        } catch(final Exception e) {
+            e.printStackTrace();
+        }
+        return table;
+    }
+
+    /**
+     * Initialize the defaults table with the name of the ResourceBundle
+     * used for getting localized defaults.  Also initialize the default
+     * locale used when no locale is passed into UIDefaults.get().  The
+     * default locale should generally not be relied upon. It is here for
+     * compatability with releases prior to 1.4.
+     */
+    private void initResourceBundle(final UIDefaults table) {
+        table.setDefaultLocale(Locale.getDefault());
+        try {
+            final ResourceBundle aquaProperties = MacOSXResourceBundle.getMacResourceBundle(PKG_PREFIX + "resources.aqua");
+            final Enumeration<String> propertyKeys = aquaProperties.getKeys();
+
+            while (propertyKeys.hasMoreElements()) {
+                final String key = propertyKeys.nextElement();
+                table.put(key, aquaProperties.getString(key));
+            }
+        } catch (final Exception e) {
+            table.addResourceBundle(PKG_PREFIX + "resources.aqua");
+        }
+    }
+
+    /**
+     * This is the last step in the getDefaults routine usually called from our superclass
+     */
+    protected void initComponentDefaults(final UIDefaults table) {
+        initResourceBundle(table);
+
+        final InsetsUIResource zeroInsets = new InsetsUIResource(0, 0, 0, 0);
+        final InsetsUIResource menuItemMargin = zeroInsets;
+
+        // <rdar://problem/5189013> Entire Java application window refreshes when moving off Shortcut menu item
+        final Boolean useOpaqueComponents = Boolean.TRUE;
+
+        final Boolean buttonShouldBeOpaque = AquaUtils.shouldUseOpaqueButtons() ? Boolean.TRUE : Boolean.FALSE;
+
+        // *** List value objects
+        final Object listCellRendererActiveValue = new UIDefaults.ActiveValue(){
+            public Object createValue(UIDefaults defaultsTable) {
+                return new DefaultListCellRenderer.UIResource();
+            }
+        };
+
+        // SJA - I'm basing this on what is in the MetalLookAndFeel class, but
+        // without being based on BasicLookAndFeel. We want more flexibility.
+        // The key to doing this well is to use Lazy initializing classes as
+        // much as possible.
+
+        // Here I want to go to native and get all the values we'd need for colors etc.
+        final Border toolTipBorder = new BorderUIResource.EmptyBorderUIResource(2, 0, 2, 0);
+        final ColorUIResource toolTipBackground = new ColorUIResource(255, 255, (int)(255.0 * 0.80));
+        final ColorUIResource black = new ColorUIResource(Color.black);
+        final ColorUIResource white = new ColorUIResource(Color.white);
+        final ColorUIResource smokyGlass = new ColorUIResource(new Color(0, 0, 0, 152));
+        final ColorUIResource dockIconRim = new ColorUIResource(new Color(192, 192, 192, 192));
+        final ColorUIResource mediumTranslucentBlack = new ColorUIResource(new Color(0, 0, 0, 100));
+        final ColorUIResource translucentWhite = new ColorUIResource(new Color(255, 255, 255, 254));
+    //    final ColorUIResource lightGray = new ColorUIResource(232, 232, 232);
+        final ColorUIResource disabled = new ColorUIResource(0.5f, 0.5f, 0.5f);
+        final ColorUIResource disabledShadow = new ColorUIResource(0.25f, 0.25f, 0.25f);
+        final ColorUIResource selected = new ColorUIResource(1.0f, 0.4f, 0.4f);
+
+        // Contrast tab UI colors
+
+        final ColorUIResource selectedTabTitlePressedColor = new ColorUIResource(240, 240, 240);
+        final ColorUIResource selectedTabTitleDisabledColor = new ColorUIResource(new Color(1, 1, 1, 0.55f));
+        final ColorUIResource selectedTabTitleNormalColor = white;
+        final ColorUIResource selectedTabTitleShadowDisabledColor = new ColorUIResource(new Color(0, 0, 0, 0.25f));
+        final ColorUIResource selectedTabTitleShadowNormalColor = mediumTranslucentBlack;
+        final ColorUIResource nonSelectedTabTitleNormalColor = black;
+
+        final ColorUIResource toolbarDragHandleColor = new ColorUIResource(140, 140, 140);
+
+        // sja todo Make these lazy values so we only get them when required - if we deem it necessary
+        // it may be the case that we think the overhead of a proxy lazy value is not worth delaying
+        // creating the object if we think that most swing apps will use this.
+        // the lazy value is useful for delaying initialization until this default value is actually
+        // accessed by the LAF instead of at init time, so making it lazy should speed up
+        // our launch times of Swing apps.
+
+        // *** Text value objects
+        final Object marginBorder = new SwingLazyValue("javax.swing.plaf.basic.BasicBorders$MarginBorder");
+
+        final Object zero = new Integer(0);
+        final Object editorMargin = zeroInsets; // this is not correct - look at TextEdit to determine the right margin
+        final Object textCaretBlinkRate = new Integer(500);
+        final Object textFieldBorder = new SwingLazyValue(PKG_PREFIX + "AquaTextFieldBorder", "getTextFieldBorder");
+        final Object textAreaBorder = marginBorder; // text areas have no real border - radar 311073
+
+        final Object scollListBorder = new SwingLazyValue(PKG_PREFIX + "AquaScrollRegionBorder", "getScrollRegionBorder");
+        final Object aquaTitledBorder = new SwingLazyValue(PKG_PREFIX + "AquaGroupBorder", "getBorderForTitledBorder");
+        final Object aquaInsetBorder = new SwingLazyValue(PKG_PREFIX + "AquaGroupBorder", "getTitlelessBorder");
+
+        final Border listHeaderBorder = AquaTableHeaderBorder.getListHeaderBorder();
+        final Border zeroBorder = new BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0);
+
+        // we can't seem to proxy Colors
+        final Color selectionBackground = AquaImageFactory.getSelectionBackgroundColorUIResource();
+        final Color selectionForeground = AquaImageFactory.getSelectionForegroundColorUIResource();
+        final Color selectionInactiveBackground = AquaImageFactory.getSelectionInactiveBackgroundColorUIResource();
+        final Color selectionInactiveForeground = AquaImageFactory.getSelectionInactiveForegroundColorUIResource();
+
+        final Color textHighlightText = AquaImageFactory.getTextSelectionForegroundColorUIResource();
+        final Color textHighlight = AquaImageFactory.getTextSelectionBackgroundColorUIResource();
+        final Color textHighlightInactive = new ColorUIResource(212, 212, 212);
+
+        final Color textInactiveText = disabled;
+        final Color textForeground = black;
+        final Color textBackground = white;
+        final Color textInactiveBackground = white;
+
+        final Color textPasswordFieldCapsLockIconColor = mediumTranslucentBlack;
+
+        final Object internalFrameBorder = new SwingLazyValue("javax.swing.plaf.basic.BasicBorders", "getInternalFrameBorder");
+        final Color desktopBackgroundColor = new ColorUIResource(new Color(65, 105, 170));//SystemColor.desktop
+
+        final Color focusRingColor = AquaImageFactory.getFocusRingColorUIResource();
+        final Border focusCellHighlightBorder = new BorderUIResource.LineBorderUIResource(focusRingColor);
+
+        final Color windowBackgroundColor = AquaImageFactory.getWindowBackgroundColorUIResource();
+        final Color panelBackgroundColor = windowBackgroundColor;
+        final Color tabBackgroundColor = windowBackgroundColor;
+        final Color controlBackgroundColor = windowBackgroundColor;
+
+        final Object controlFont = new SwingLazyValue(kAquaFontsName, "getControlTextFont");
+        final Object controlSmallFont = new SwingLazyValue(kAquaFontsName, "getControlTextSmallFont");
+        final Object alertHeaderFont = new SwingLazyValue(kAquaFontsName, "getAlertHeaderFont");
+        final Object menuFont = new SwingLazyValue(kAquaFontsName, "getMenuFont");
+        final Object viewFont = new SwingLazyValue(kAquaFontsName, "getViewFont");
+
+        final Color menuBackgroundColor = new ColorUIResource(Color.white);
+        final Color menuForegroundColor = black;
+
+        final Color menuSelectedForegroundColor = white;
+        final Color menuSelectedBackgroundColor = focusRingColor;
+
+        final Color menuDisabledBackgroundColor = menuBackgroundColor;
+        final Color menuDisabledForegroundColor = disabled;
+
+        final Color menuAccelForegroundColor = black;
+        final Color menuAccelSelectionForegroundColor = black;
+
+        final Border menuBorder = new AquaMenuBorder();
+
+        final UIDefaults.LazyInputMap controlFocusInputMap = new UIDefaults.LazyInputMap(new Object[]{
+            "SPACE", "pressed",
+            "released SPACE", "released"
+        });
+
+        // sja testing
+        final Object confirmIcon = new SwingLazyValue(kAquaImageFactoryName, "getConfirmImageIcon"); // AquaImageFactory.getConfirmImageIcon();
+        final Object cautionIcon = new SwingLazyValue(kAquaImageFactoryName, "getCautionImageIcon"); // AquaImageFactory.getCautionImageIcon();
+        final Object stopIcon = new SwingLazyValue(kAquaImageFactoryName, "getStopImageIcon"); // AquaImageFactory.getStopImageIcon();
+        final Object securityIcon = new SwingLazyValue(kAquaImageFactoryName, "getLockImageIcon"); // AquaImageFactory.getLockImageIcon();
+
+        final AquaKeyBindings aquaKeyBindings = AquaKeyBindings.instance();
+
+        final Object[] defaults = {
+            "control", windowBackgroundColor, /* Default color for controls (buttons, sliders, etc) */
+
+            // Buttons
+            "Button.background", controlBackgroundColor,
+            "Button.foreground", black,
+            "Button.disabledText", disabled,
+            "Button.select", selected,
+            "Button.border", new SwingLazyValue(PKG_PREFIX + "AquaButtonBorder", "getDynamicButtonBorder"),
+            "Button.font", controlFont,
+            "Button.textIconGap", new Integer(4),
+            "Button.textShiftOffset", zero, // radar 3308129 - aqua doesn't move images when pressed.
+            "Button.focusInputMap", controlFocusInputMap,
+            "Button.margin", new InsetsUIResource(0, 2, 0, 2),
+            "Button.opaque", buttonShouldBeOpaque,
+
+            "CheckBox.background", controlBackgroundColor,
+            "CheckBox.foreground", black,
+            "CheckBox.disabledText", disabled,
+            "CheckBox.select", selected,
+            "CheckBox.icon", new SwingLazyValue(PKG_PREFIX + "AquaButtonCheckBoxUI", "getSizingCheckBoxIcon"),
+            "CheckBox.font", controlFont,
+            "CheckBox.border", AquaButtonBorder.getBevelButtonBorder(),
+            "CheckBox.margin", new InsetsUIResource(1, 1, 0, 1),
+            // radar 3583849. This property never gets
+            // used. The border for the Checkbox gets overridden
+            // by AquaRadiButtonUI.setThemeBorder(). Needs refactoring. (vm)
+            // why is button focus commented out?
+            //"CheckBox.focus", getFocusColor(),
+            "CheckBox.focusInputMap", controlFocusInputMap,
+
+            "CheckBoxMenuItem.font", menuFont,
+            "CheckBoxMenuItem.acceleratorFont", menuFont,
+            "CheckBoxMenuItem.background", menuBackgroundColor,
+            "CheckBoxMenuItem.foreground", menuForegroundColor,
+            "CheckBoxMenuItem.selectionBackground", menuSelectedBackgroundColor,
+            "CheckBoxMenuItem.selectionForeground", menuSelectedForegroundColor,
+            "CheckBoxMenuItem.disabledBackground", menuDisabledBackgroundColor,
+            "CheckBoxMenuItem.disabledForeground", menuDisabledForegroundColor,
+            "CheckBoxMenuItem.acceleratorForeground", menuAccelForegroundColor,
+            "CheckBoxMenuItem.acceleratorSelectionForeground", menuAccelSelectionForegroundColor,
+            "CheckBoxMenuItem.acceleratorDelimiter", "",
+            "CheckBoxMenuItem.border", menuBorder, // for inset calculation
+            "CheckBoxMenuItem.margin", menuItemMargin,
+            "CheckBoxMenuItem.borderPainted", Boolean.TRUE,
+            "CheckBoxMenuItem.checkIcon", new SwingLazyValue(kAquaImageFactoryName, "getMenuItemCheckIcon"),
+            "CheckBoxMenuItem.dashIcon", new SwingLazyValue(kAquaImageFactoryName, "getMenuItemDashIcon"),
+            //"CheckBoxMenuItem.arrowIcon", null,
+
+            "ColorChooser.background", panelBackgroundColor,
+
+            // *** ComboBox
+            "ComboBox.font", controlFont,
+            "ComboBox.background", controlBackgroundColor, //menuBackgroundColor, // "menu" when it has no scrollbar, "listView" when it does
+            "ComboBox.foreground", menuForegroundColor,
+            "ComboBox.selectionBackground", menuSelectedBackgroundColor,
+            "ComboBox.selectionForeground", menuSelectedForegroundColor,
+            "ComboBox.disabledBackground", menuDisabledBackgroundColor,
+            "ComboBox.disabledForeground", menuDisabledForegroundColor,
+            "ComboBox.ancestorInputMap", aquaKeyBindings.getComboBoxInputMap(),
+
+            "DesktopIcon.border", internalFrameBorder,
+            "DesktopIcon.borderColor", smokyGlass,
+            "DesktopIcon.borderRimColor", dockIconRim,
+            "DesktopIcon.labelBackground", mediumTranslucentBlack,
+            "Desktop.background", desktopBackgroundColor,
+
+            "EditorPane.focusInputMap", aquaKeyBindings.getMultiLineTextInputMap(),
+            "EditorPane.font", controlFont,
+            "EditorPane.background", textBackground,
+            "EditorPane.foreground", textForeground,
+            "EditorPane.selectionBackground", textHighlight,
+            "EditorPane.selectionForeground", textHighlightText,
+            "EditorPane.caretForeground", textForeground,
+            "EditorPane.caretBlinkRate", textCaretBlinkRate,
+            "EditorPane.inactiveForeground", textInactiveText,
+            "EditorPane.inactiveBackground", textInactiveBackground,
+            "EditorPane.border", textAreaBorder,
+            "EditorPane.margin", editorMargin,
+
+            "FileChooser.newFolderIcon", AquaIcon.SystemIcon.getFolderIconUIResource(),
+            "FileChooser.upFolderIcon", AquaIcon.SystemIcon.getFolderIconUIResource(),
+            "FileChooser.homeFolderIcon", AquaIcon.SystemIcon.getDesktopIconUIResource(),
+            "FileChooser.detailsViewIcon", AquaIcon.SystemIcon.getComputerIconUIResource(),
+            "FileChooser.listViewIcon", AquaIcon.SystemIcon.getComputerIconUIResource(),
+
+            "FileView.directoryIcon", AquaIcon.SystemIcon.getFolderIconUIResource(),
+            "FileView.fileIcon", AquaIcon.SystemIcon.getDocumentIconUIResource(),
+            "FileView.computerIcon", AquaIcon.SystemIcon.getDesktopIconUIResource(),
+            "FileView.hardDriveIcon", AquaIcon.SystemIcon.getHardDriveIconUIResource(),
+            "FileView.floppyDriveIcon", AquaIcon.SystemIcon.getFloppyIconUIResource(),
+
+            // File View
+            "FileChooser.cancelButtonMnemonic", zero,
+            "FileChooser.saveButtonMnemonic", zero,
+            "FileChooser.openButtonMnemonic", zero,
+            "FileChooser.updateButtonMnemonic", zero,
+            "FileChooser.helpButtonMnemonic", zero,
+            "FileChooser.directoryOpenButtonMnemonic", zero,
+
+            "FileChooser.lookInLabelMnemonic", zero,
+            "FileChooser.fileNameLabelMnemonic", zero,
+            "FileChooser.filesOfTypeLabelMnemonic", zero,
+
+            "Focus.color", focusRingColor,
+
+            "FormattedTextField.focusInputMap", aquaKeyBindings.getFormattedTextFieldInputMap(),
+            "FormattedTextField.font", controlFont,
+            "FormattedTextField.background", textBackground,
+            "FormattedTextField.foreground", textForeground,
+            "FormattedTextField.inactiveForeground", textInactiveText,
+            "FormattedTextField.inactiveBackground", textInactiveBackground,
+            "FormattedTextField.selectionBackground", textHighlight,
+            "FormattedTextField.selectionForeground", textHighlightText,
+            "FormattedTextField.caretForeground", textForeground,
+            "FormattedTextField.caretBlinkRate", textCaretBlinkRate,
+            "FormattedTextField.border", textFieldBorder,
+            "FormattedTextField.margin", zeroInsets,
+
+            "IconButton.font", controlSmallFont,
+
+            "InternalFrame.titleFont", menuFont,
+            "InternalFrame.background", windowBackgroundColor,
+            "InternalFrame.borderColor", windowBackgroundColor,
+            "InternalFrame.borderShadow", Color.red,
+            "InternalFrame.borderDarkShadow", Color.green,
+            "InternalFrame.borderHighlight", Color.blue,
+            "InternalFrame.borderLight", Color.yellow,
+            "InternalFrame.opaque", Boolean.FALSE,
+            "InternalFrame.border", null, //internalFrameBorder,
+            "InternalFrame.icon", null,
+
+            "InternalFrame.paletteBorder", null,//internalFrameBorder,
+            "InternalFrame.paletteTitleFont", menuFont,
+            "InternalFrame.paletteBackground", windowBackgroundColor,
+
+            "InternalFrame.optionDialogBorder", null,//internalFrameBorder,
+            "InternalFrame.optionDialogTitleFont", menuFont,
+            "InternalFrame.optionDialogBackground", windowBackgroundColor,
+
+            /* Default frame icons are undefined for Basic. */
+
+            "InternalFrame.closeIcon", new SwingLazyValue(PKG_PREFIX + "AquaInternalFrameUI", "exportCloseIcon"),
+            "InternalFrame.maximizeIcon", new SwingLazyValue(PKG_PREFIX + "AquaInternalFrameUI", "exportZoomIcon"),
+            "InternalFrame.iconifyIcon", new SwingLazyValue(PKG_PREFIX + "AquaInternalFrameUI", "exportMinimizeIcon"),
+            "InternalFrame.minimizeIcon", new SwingLazyValue(PKG_PREFIX + "AquaInternalFrameUI", "exportMinimizeIcon"),
+            // this could be either grow or icon
+            // we decided to make it icon so that anyone who uses
+            // these for ui will have different icons for max and min
+            // these icons are pretty crappy to use in Mac OS X since
+            // they really are interactive but we have to return a static
+            // icon for now.
+
+            // InternalFrame Auditory Cue Mappings
+            "InternalFrame.closeSound", null,
+            "InternalFrame.maximizeSound", null,
+            "InternalFrame.minimizeSound", null,
+            "InternalFrame.restoreDownSound", null,
+            "InternalFrame.restoreUpSound", null,
+
+            "InternalFrame.activeTitleBackground", windowBackgroundColor,
+            "InternalFrame.activeTitleForeground", textForeground,
+            "InternalFrame.inactiveTitleBackground", windowBackgroundColor,
+            "InternalFrame.inactiveTitleForeground", textInactiveText,
+            "InternalFrame.windowBindings", new Object[]{
+                "shift ESCAPE", "showSystemMenu",
+                "ctrl SPACE", "showSystemMenu",
+                "ESCAPE", "hideSystemMenu"
+            },
+
+            // Radar [3543438]. We now define the TitledBorder properties for font and color.
+            // Aqua HIG doesn't define TitledBorders as Swing does. Eventually, we might want to
+            // re-think TitledBorder to behave more like a Box (NSBox). (vm)
+            "TitledBorder.font", controlFont,
+            "TitledBorder.titleColor", black,
+        //    "TitledBorder.border", -- we inherit this property from BasicLookAndFeel (etched border)
+            "TitledBorder.aquaVariant", aquaTitledBorder, // this is the border that matches what aqua really looks like
+            "InsetBorder.aquaVariant", aquaInsetBorder, // this is the title-less variant
+
+            // *** Label
+            "Label.font", controlFont, // themeLabelFont is for small things like ToolbarButtons
+            "Label.background", controlBackgroundColor,
+            "Label.foreground", black,
+            "Label.disabledForeground", disabled,
+            "Label.disabledShadow", disabledShadow,
+            "Label.opaque", useOpaqueComponents,
+            "Label.border", null,
+
+            "List.font", viewFont, // [3577901] Aqua HIG says "default font of text in lists and tables" should be 12 point (vm).
+            "List.background", white,
+            "List.foreground", black,
+            "List.selectionBackground", selectionBackground,
+            "List.selectionForeground", selectionForeground,
+            "List.selectionInactiveBackground", selectionInactiveBackground,
+            "List.selectionInactiveForeground", selectionInactiveForeground,
+            "List.focusCellHighlightBorder", focusCellHighlightBorder,
+            "List.border", null,
+            "List.cellRenderer", listCellRendererActiveValue,
+
+            "List.sourceListBackgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaListUI", "getSourceListBackgroundPainter"),
+            "List.sourceListSelectionBackgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaListUI", "getSourceListSelectionBackgroundPainter"),
+            "List.sourceListFocusedSelectionBackgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaListUI", "getSourceListFocusedSelectionBackgroundPainter"),
+            "List.evenRowBackgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaListUI", "getListEvenBackgroundPainter"),
+            "List.oddRowBackgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaListUI", "getListOddBackgroundPainter"),
+
+            // <rdar://Problem/3743210> The modifier for the Mac is meta, not control.
+            "List.focusInputMap", aquaKeyBindings.getListInputMap(),
+
+            //"List.scrollPaneBorder", listBoxBorder, // Not used in Swing1.1
+            //"ListItem.border", ThemeMenu.listItemBorder(), // for inset calculation
+
+            // *** Menus
+            "Menu.font", menuFont,
+            "Menu.acceleratorFont", menuFont,
+            "Menu.background", menuBackgroundColor,
+            "Menu.foreground", menuForegroundColor,
+            "Menu.selectionBackground", menuSelectedBackgroundColor,
+            "Menu.selectionForeground", menuSelectedForegroundColor,
+            "Menu.disabledBackground", menuDisabledBackgroundColor,
+            "Menu.disabledForeground", menuDisabledForegroundColor,
+            "Menu.acceleratorForeground", menuAccelForegroundColor,
+            "Menu.acceleratorSelectionForeground", menuAccelSelectionForegroundColor,
+            //"Menu.border", ThemeMenu.menuItemBorder(), // for inset calculation
+            "Menu.border", menuBorder,
+            "Menu.borderPainted", Boolean.FALSE,
+            "Menu.margin", menuItemMargin,
+            //"Menu.checkIcon", emptyCheckIcon, // A non-drawing GlyphIcon to make the spacing consistent
+            "Menu.arrowIcon", new SwingLazyValue(kAquaImageFactoryName, "getMenuArrowIcon"),
+            "Menu.consumesTabs", Boolean.TRUE,
+            "Menu.menuPopupOffsetY", new Integer(1),
+            "Menu.submenuPopupOffsetY", new Integer(-4),
+
+            "MenuBar.font", menuFont,
+            "MenuBar.background", menuBackgroundColor, // not a menu item, not selected
+            "MenuBar.foreground", menuForegroundColor,
+            "MenuBar.border", new AquaMenuBarBorder(), // sja make lazy!
+            "MenuBar.margin", new InsetsUIResource(0, 8, 0, 8), // sja make lazy!
+            "MenuBar.selectionBackground", menuSelectedBackgroundColor, // not a menu item, is selected
+            "MenuBar.selectionForeground", menuSelectedForegroundColor,
+            "MenuBar.disabledBackground", menuDisabledBackgroundColor, //ThemeBrush.GetThemeBrushForMenu(false, false), // not a menu item, not selected
+            "MenuBar.disabledForeground", menuDisabledForegroundColor,
+            "MenuBar.backgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaMenuPainter", "getMenuBarPainter"),
+            "MenuBar.selectedBackgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaMenuPainter", "getSelectedMenuBarItemPainter"),
+
+            "MenuItem.font", menuFont,
+            "MenuItem.acceleratorFont", menuFont,
+            "MenuItem.background", menuBackgroundColor,
+            "MenuItem.foreground", menuForegroundColor,
+            "MenuItem.selectionBackground", menuSelectedBackgroundColor,
+            "MenuItem.selectionForeground", menuSelectedForegroundColor,
+            "MenuItem.disabledBackground", menuDisabledBackgroundColor,
+            "MenuItem.disabledForeground", menuDisabledForegroundColor,
+            "MenuItem.acceleratorForeground", menuAccelForegroundColor,
+            "MenuItem.acceleratorSelectionForeground", menuAccelSelectionForegroundColor,
+            "MenuItem.acceleratorDelimiter", "",
+            "MenuItem.border", menuBorder,
+            "MenuItem.margin", menuItemMargin,
+            "MenuItem.borderPainted", Boolean.TRUE,
+            //"MenuItem.checkIcon", emptyCheckIcon, // A non-drawing GlyphIcon to make the spacing consistent
+            //"MenuItem.arrowIcon", null,
+            "MenuItem.selectedBackgroundPainter", new SwingLazyValue(PKG_PREFIX + "AquaMenuPainter", "getSelectedMenuItemPainter"),
+
+            // *** OptionPane
+            // You can additionaly define OptionPane.messageFont which will
+            // dictate the fonts used for the message, and
+            // OptionPane.buttonFont, which defines the font for the buttons.
+            "OptionPane.font", alertHeaderFont,
+            "OptionPane.messageFont", controlFont,
+            "OptionPane.buttonFont", controlFont,
+            "OptionPane.background", windowBackgroundColor,
+            "OptionPane.foreground", black,
+            "OptionPane.messageForeground", black,
+            "OptionPane.border", new BorderUIResource.EmptyBorderUIResource(12, 21, 17, 21),
+            "OptionPane.messageAreaBorder", zeroBorder,
+            "OptionPane.buttonAreaBorder", new BorderUIResource.EmptyBorderUIResource(13, 0, 0, 0),
+            "OptionPane.minimumSize", new DimensionUIResource(262, 90),
+
+            "OptionPane.errorIcon", stopIcon,
+            "OptionPane.informationIcon", confirmIcon,
+            "OptionPane.warningIcon", cautionIcon,
+            "OptionPane.questionIcon", confirmIcon,
+            "_SecurityDecisionIcon", securityIcon,
+            "OptionPane.windowBindings", new Object[]{"ESCAPE", "close"},
+            // OptionPane Auditory Cue Mappings
+            "OptionPane.errorSound", null,
+            "OptionPane.informationSound", null, // Info and Plain
+            "OptionPane.questionSound", null,
+            "OptionPane.warningSound", null,
+            "OptionPane.buttonClickThreshhold", new Integer(500),
+            "OptionPane.yesButtonMnemonic", "",
+            "OptionPane.noButtonMnemonic", "",
+            "OptionPane.okButtonMnemonic", "",
+            "OptionPane.cancelButtonMnemonic", "",
+
+            "Panel.font", controlFont,
+            "Panel.background", panelBackgroundColor, //new ColorUIResource(0.5647f, 0.9957f, 0.5059f),
+            "Panel.foreground", black,
+            "Panel.opaque", useOpaqueComponents,
+
+            "PasswordField.focusInputMap", aquaKeyBindings.getTextFieldInputMap(),
+            "PasswordField.font", controlFont,
+            "PasswordField.background", textBackground,
+            "PasswordField.foreground", textForeground,
+            "PasswordField.inactiveForeground", textInactiveText,
+            "PasswordField.inactiveBackground", textInactiveBackground,
+            "PasswordField.selectionBackground", textHighlight,
+            "PasswordField.selectionForeground", textHighlightText,
+            "PasswordField.caretForeground", textForeground,
+            "PasswordField.caretBlinkRate", textCaretBlinkRate,
+            "PasswordField.border", textFieldBorder,
+            "PasswordField.margin", zeroInsets,
+            "PasswordField.echoChar", new Character((char)0x25CF),
+            "PasswordField.capsLockIconColor", textPasswordFieldCapsLockIconColor,
+
+            "PopupMenu.font", menuFont,
+            "PopupMenu.background", menuBackgroundColor,
+            "PopupMenu.translucentBackground", translucentWhite,
+            "PopupMenu.foreground", menuForegroundColor,
+            "PopupMenu.selectionBackground", menuSelectedBackgroundColor,
+            "PopupMenu.selectionForeground", menuSelectedForegroundColor,
+            "PopupMenu.border", menuBorder,
+//            "PopupMenu.margin",
+
+            "ProgressBar.font", controlFont,
+            "ProgressBar.foreground", black,
+            "ProgressBar.background", controlBackgroundColor,
+            "ProgressBar.selectionForeground", black,
+            "ProgressBar.selectionBackground", white,
+            "ProgressBar.border", new BorderUIResource(BorderFactory.createEmptyBorder()),
+            "ProgressBar.repaintInterval", new Integer(20),
+
+            "RadioButton.background", controlBackgroundColor,
+            "RadioButton.foreground", black,
+            "RadioButton.disabledText", disabled,
+            "RadioButton.select", selected,
+            "RadioButton.icon", new SwingLazyValue(PKG_PREFIX + "AquaButtonRadioUI", "getSizingRadioButtonIcon"),
+            "RadioButton.font", controlFont,
+            "RadioButton.border", AquaButtonBorder.getBevelButtonBorder(),
+            "RadioButton.margin", new InsetsUIResource(1, 1, 0, 1),
+            "RadioButton.focusInputMap", controlFocusInputMap,
+
+            "RadioButtonMenuItem.font", menuFont,
+            "RadioButtonMenuItem.acceleratorFont", menuFont,
+            "RadioButtonMenuItem.background", menuBackgroundColor,
+            "RadioButtonMenuItem.foreground", menuForegroundColor,
+            "RadioButtonMenuItem.selectionBackground", menuSelectedBackgroundColor,
+            "RadioButtonMenuItem.selectionForeground", menuSelectedForegroundColor,
+            "RadioButtonMenuItem.disabledBackground", menuDisabledBackgroundColor,
+            "RadioButtonMenuItem.disabledForeground", menuDisabledForegroundColor,
+            "RadioButtonMenuItem.acceleratorForeground", menuAccelForegroundColor,
+            "RadioButtonMenuItem.acceleratorSelectionForeground", menuAccelSelectionForegroundColor,
+            "RadioButtonMenuItem.acceleratorDelimiter", "",
+            "RadioButtonMenuItem.border", menuBorder, // for inset calculation
+            "RadioButtonMenuItem.margin", menuItemMargin,
+            "RadioButtonMenuItem.borderPainted", Boolean.TRUE,
+            "RadioButtonMenuItem.checkIcon", new SwingLazyValue(kAquaImageFactoryName, "getMenuItemCheckIcon"),
+            "RadioButtonMenuItem.dashIcon", new SwingLazyValue(kAquaImageFactoryName, "getMenuItemDashIcon"),
+            //"RadioButtonMenuItem.arrowIcon", null,
+
+            "Separator.background", null,
+            "Separator.foreground", new ColorUIResource(0xD4, 0xD4, 0xD4),
+
+            "ScrollBar.border", null,
+            "ScrollBar.focusInputMap", aquaKeyBindings.getScrollBarInputMap(),
+            "ScrollBar.focusInputMap.RightToLeft", aquaKeyBindings.getScrollBarRightToLeftInputMap(),
+            "ScrollBar.width", new Integer(16),
+            "ScrollBar.background", white,
+            "ScrollBar.foreground", black,
+
+            "ScrollPane.font", controlFont,
+            "ScrollPane.background", white,
+            "ScrollPane.foreground", black, //$
+            "ScrollPane.border", scollListBorder,
+            "ScrollPane.viewportBorder", null,
+
+            "ScrollPane.ancestorInputMap", aquaKeyBindings.getScrollPaneInputMap(),
+            "ScrollPane.ancestorInputMap.RightToLeft", new UIDefaults.LazyInputMap(new Object[]{}),
+
+            "Viewport.font", controlFont,
+            "Viewport.background", white, // The background for tables, lists, etc
+            "Viewport.foreground", black,
+
+            // *** Slider
+            "Slider.foreground", black, "Slider.background", controlBackgroundColor,
+            "Slider.font", controlSmallFont,
+            //"Slider.highlight", table.get("controlLtHighlight"),
+            //"Slider.shadow", table.get("controlShadow"),
+            //"Slider.focus", table.get("controlDkShadow"),
+            "Slider.tickColor", new ColorUIResource(Color.GRAY),
+            "Slider.border", null,
+            "Slider.focusInsets", new InsetsUIResource(2, 2, 2, 2),
+            "Slider.focusInputMap", aquaKeyBindings.getSliderInputMap(),
+            "Slider.focusInputMap.RightToLeft", aquaKeyBindings.getSliderRightToLeftInputMap(),
+
+            // *** Spinner
+            "Spinner.font", controlFont,
+            "Spinner.background", controlBackgroundColor,
+            "Spinner.foreground", black,
+            "Spinner.border", null,
+            "Spinner.arrowButtonSize", new Dimension(16, 5),
+            "Spinner.ancestorInputMap", aquaKeyBindings.getSpinnerInputMap(),
+            "Spinner.editorBorderPainted", Boolean.TRUE,
+            "Spinner.editorAlignment", SwingConstants.TRAILING,
+
+            // *** SplitPane
+            //"SplitPane.highlight", table.get("controlLtHighlight"),
+            //"SplitPane.shadow", table.get("controlShadow"),
+            "SplitPane.background", panelBackgroundColor,
+            "SplitPane.border", scollListBorder,
+            "SplitPane.dividerSize", new Integer(9), //$
+            "SplitPaneDivider.border", null, // AquaSplitPaneDividerUI draws it
+            "SplitPaneDivider.horizontalGradientVariant", new SwingLazyValue(PKG_PREFIX + "AquaSplitPaneDividerUI", "getHorizontalSplitDividerGradientVariant"),
+
+            // *** TabbedPane
+            "TabbedPane.font", controlFont,
+            "TabbedPane.smallFont", controlSmallFont,
+            "TabbedPane.useSmallLayout", Boolean.FALSE,//sSmallTabs ? Boolean.TRUE : Boolean.FALSE,
+            "TabbedPane.background", tabBackgroundColor, // for bug [3398277] use a background color so that
+            // tabs on a custom pane get erased when they are removed.
+            "TabbedPane.foreground", black, //ThemeTextColor.GetThemeTextColor(AppearanceConstants.kThemeTextColorTabFrontActive),
+            //"TabbedPane.lightHighlight", table.get("controlLtHighlight"),
+            //"TabbedPane.highlight", table.get("controlHighlight"),
+            //"TabbedPane.shadow", table.get("controlShadow"),
+            //"TabbedPane.darkShadow", table.get("controlDkShadow"),
+            //"TabbedPane.focus", table.get("controlText"),
+            "TabbedPane.opaque", useOpaqueComponents,
+            "TabbedPane.textIconGap", new Integer(4),
+            "TabbedPane.tabInsets", new InsetsUIResource(0, 10, 3, 10), // Label within tab (top, left, bottom, right)
+            //"TabbedPane.rightTabInsets", new InsetsUIResource(0, 10, 3, 10), // Label within tab (top, left, bottom, right)
+            "TabbedPane.leftTabInsets", new InsetsUIResource(0, 10, 3, 10), // Label within tab
+            "TabbedPane.rightTabInsets", new InsetsUIResource(0, 10, 3, 10), // Label within tab
+            //"TabbedPane.tabAreaInsets", new InsetsUIResource(3, 9, -1, 9), // Tabs relative to edge of pane (negative value for overlapping)
+            "TabbedPane.tabAreaInsets", new InsetsUIResource(3, 9, -1, 9), // Tabs relative to edge of pane (negative value for overlapping)
+            // (top = side opposite pane, left = edge || to pane, bottom = side adjacent to pane, right = left) - see rotateInsets
+            "TabbedPane.contentBorderInsets", new InsetsUIResource(8, 0, 0, 0), // width of border
+            //"TabbedPane.selectedTabPadInsets", new InsetsUIResource(0, 0, 1, 0), // Really outsets, this is where we allow for overlap
+            "TabbedPane.selectedTabPadInsets", new InsetsUIResource(0, 0, 0, 0), // Really outsets, this is where we allow for overlap
+            "TabbedPane.tabsOverlapBorder", Boolean.TRUE,
+            "TabbedPane.selectedTabTitlePressedColor", selectedTabTitlePressedColor,
+            "TabbedPane.selectedTabTitleDisabledColor", selectedTabTitleDisabledColor,
+            "TabbedPane.selectedTabTitleNormalColor", selectedTabTitleNormalColor,
+            "TabbedPane.selectedTabTitleShadowDisabledColor", selectedTabTitleShadowDisabledColor,
+            "TabbedPane.selectedTabTitleShadowNormalColor", selectedTabTitleShadowNormalColor,
+            "TabbedPane.nonSelectedTabTitleNormalColor", nonSelectedTabTitleNormalColor,
+
+            // *** Table
+            "Table.font", viewFont, // [3577901] Aqua HIG says "default font of text in lists and tables" should be 12 point (vm).
+            "Table.foreground", black, // cell text color
+            "Table.background", white, // cell background color
+            "Table.selectionForeground", selectionForeground,
+            "Table.selectionBackground", selectionBackground,
+            "Table.selectionInactiveBackground", selectionInactiveBackground,
+            "Table.selectionInactiveForeground", selectionInactiveForeground,
+            "Table.gridColor", white, // grid line color
+            "Table.focusCellBackground", textHighlightText,
+            "Table.focusCellForeground", textHighlight,
+            "Table.focusCellHighlightBorder", focusCellHighlightBorder,
+            "Table.scrollPaneBorder", scollListBorder,
+
+            "Table.ancestorInputMap", aquaKeyBindings.getTableInputMap(),
+            "Table.ancestorInputMap.RightToLeft", aquaKeyBindings.getTableRightToLeftInputMap(),
+
+            "TableHeader.font", controlSmallFont,
+            "TableHeader.foreground", black,
+            "TableHeader.background", white, // header background
+            "TableHeader.cellBorder", listHeaderBorder,
+
+            // *** Text
+            "TextArea.focusInputMap", aquaKeyBindings.getMultiLineTextInputMap(),
+            "TextArea.font", controlFont,
+            "TextArea.background", textBackground,
+            "TextArea.foreground", textForeground,
+            "TextArea.inactiveForeground", textInactiveText,
+            "TextArea.inactiveBackground", textInactiveBackground,
+            "TextArea.selectionBackground", textHighlight,
+            "TextArea.selectionForeground", textHighlightText,
+            "TextArea.caretForeground", textForeground,
+            "TextArea.caretBlinkRate", textCaretBlinkRate,
+            "TextArea.border", textAreaBorder,
+            "TextArea.margin", zeroInsets,
+
+            "TextComponent.selectionBackgroundInactive", textHighlightInactive,
+
+            "TextField.focusInputMap", aquaKeyBindings.getTextFieldInputMap(),
+            "TextField.font", controlFont,
+            "TextField.background", textBackground,
+            "TextField.foreground", textForeground,
+            "TextField.inactiveForeground", textInactiveText,
+            "TextField.inactiveBackground", textInactiveBackground,
+            "TextField.selectionBackground", textHighlight,
+            "TextField.selectionForeground", textHighlightText,
+            "TextField.caretForeground", textForeground,
+            "TextField.caretBlinkRate", textCaretBlinkRate,
+            "TextField.border", textFieldBorder,
+            "TextField.margin", zeroInsets,
+
+            "TextPane.focusInputMap", aquaKeyBindings.getMultiLineTextInputMap(),
+            "TextPane.font", controlFont,
+            "TextPane.background", textBackground,
+            "TextPane.foreground", textForeground,
+            "TextPane.selectionBackground", textHighlight,
+            "TextPane.selectionForeground", textHighlightText,
+            "TextPane.caretForeground", textForeground,
+            "TextPane.caretBlinkRate", textCaretBlinkRate,
+            "TextPane.inactiveForeground", textInactiveText,
+            "TextPane.inactiveBackground", textInactiveBackground,
+            "TextPane.border", textAreaBorder,
+            "TextPane.margin", editorMargin,
+
+            // *** ToggleButton
+            "ToggleButton.background", controlBackgroundColor,
+            "ToggleButton.foreground", black,
+            "ToggleButton.disabledText", disabled,
+            // we need to go through and find out if these are used, and if not what to set
+            // so that subclasses will get good aqua like colors.
+            //    "ToggleButton.select", getControlShadow(),
+            //    "ToggleButton.text", getControl(),
+            //    "ToggleButton.disabledSelectedText", getControlDarkShadow(),
+            //    "ToggleButton.disabledBackground", getControl(),
+            //    "ToggleButton.disabledSelectedBackground", getControlShadow(),
+            //"ToggleButton.focus", getFocusColor(),
+            "ToggleButton.border", new SwingLazyValue(PKG_PREFIX + "AquaButtonBorder", "getDynamicButtonBorder"), // sja make this lazy!
+            "ToggleButton.font", controlFont,
+            "ToggleButton.focusInputMap", controlFocusInputMap,
+            "ToggleButton.margin", new InsetsUIResource(2, 2, 2, 2),
+
+            // *** ToolBar
+            "ToolBar.font", controlFont,
+            "ToolBar.background", panelBackgroundColor,
+            "ToolBar.foreground", new ColorUIResource(Color.gray),
+            "ToolBar.dockingBackground", panelBackgroundColor,
+            "ToolBar.dockingForeground", selectionBackground,
+            "ToolBar.floatingBackground", panelBackgroundColor,
+            "ToolBar.floatingForeground", new ColorUIResource(Color.darkGray),
+            "ToolBar.border", new SwingLazyValue(PKG_PREFIX + "AquaToolBarUI", "getToolBarBorder"),
+            "ToolBar.borderHandleColor", toolbarDragHandleColor,
+            //"ToolBar.separatorSize", new DimensionUIResource( 10, 10 ),
+            "ToolBar.separatorSize", null,
+
+            // *** ToolBarButton
+            "ToolBarButton.margin", new InsetsUIResource(3, 3, 3, 3),
+            "ToolBarButton.insets", new InsetsUIResource(1, 1, 1, 1),
+
+            // *** ToolTips
+            "ToolTip.font", controlSmallFont,
+            //$ Tooltips - Same color as help balloons?
+            "ToolTip.background", toolTipBackground,
+            "ToolTip.foreground", black,
+            "ToolTip.border", toolTipBorder,
+
+            // *** Tree
+            "Tree.font", viewFont, // [3577901] Aqua HIG says "default font of text in lists and tables" should be 12 point (vm).
+            "Tree.background", white,
+            "Tree.foreground", black,
+            // for now no lines
+            "Tree.hash", white, //disabled, // Line color
+            "Tree.line", white, //disabled, // Line color
+            "Tree.textForeground", black,
+            "Tree.textBackground", white,
+            "Tree.selectionForeground", selectionForeground,
+            "Tree.selectionBackground", selectionBackground,
+            "Tree.selectionInactiveBackground", selectionInactiveBackground,
+            "Tree.selectionInactiveForeground", selectionInactiveForeground,
+            "Tree.selectionBorderColor", selectionBackground, // match the background so it looks like we don't draw anything
+            "Tree.editorBorderSelectionColor", null, // The EditTextFrame provides its own border
+            // "Tree.editorBorder", textFieldBorder, // If you still have Sun bug 4376328 in DefaultTreeCellEditor, it has to have the same insets as TextField.border
+            "Tree.leftChildIndent", new Integer(7),//$
+            "Tree.rightChildIndent", new Integer(13),//$
+            "Tree.rowHeight", new Integer(19),// iconHeight + 3, to match finder - a zero would have the renderer decide, except that leaves the icons touching
+            "Tree.scrollsOnExpand", Boolean.FALSE,
+            "Tree.openIcon", new SwingLazyValue(kAquaImageFactoryName, "getTreeOpenFolderIcon"), // Open folder icon
+            "Tree.closedIcon", new SwingLazyValue(kAquaImageFactoryName, "getTreeFolderIcon"), // Closed folder icon
+            "Tree.leafIcon", new SwingLazyValue(kAquaImageFactoryName, "getTreeDocumentIcon"), // Document icon
+            "Tree.expandedIcon", new SwingLazyValue(kAquaImageFactoryName, "getTreeExpandedIcon"),
+            "Tree.collapsedIcon", new SwingLazyValue(kAquaImageFactoryName, "getTreeCollapsedIcon"),
+            "Tree.rightToLeftCollapsedIcon", new SwingLazyValue(kAquaImageFactoryName, "getTreeRightToLeftCollapsedIcon"),
+            "Tree.changeSelectionWithFocus", Boolean.TRUE,
+            "Tree.drawsFocusBorderAroundIcon", Boolean.FALSE,
+
+            "Tree.focusInputMap", aquaKeyBindings.getTreeInputMap(),
+            "Tree.focusInputMap.RightToLeft", aquaKeyBindings.getTreeRightToLeftInputMap(),
+            "Tree.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[]{"ESCAPE", "cancel"}),};
+
+        table.putDefaults(defaults);
+
+        Object aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(true);
+        table.put(SwingUtilities2.AA_TEXT_PROPERTY_KEY, aaTextInfo);
+    }
+
+    protected void initSystemColorDefaults(final UIDefaults table) {
+//        String[] defaultSystemColors = {
+//                  "desktop", "#005C5C", /* Color of the desktop background */
+//          "activeCaption", "#000080", /* Color for captions (title bars) when they are active. */
+//          "activeCaptionText", "#FFFFFF", /* Text color for text in captions (title bars). */
+//        "activeCaptionBorder", "#C0C0C0", /* Border color for caption (title bar) window borders. */
+//            "inactiveCaption", "#808080", /* Color for captions (title bars) when not active. */
+//        "inactiveCaptionText", "#C0C0C0", /* Text color for text in inactive captions (title bars). */
+//      "inactiveCaptionBorder", "#C0C0C0", /* Border color for inactive caption (title bar) window borders. */
+//                 "window", "#FFFFFF", /* Default color for the interior of windows */
+//           "windowBorder", "#000000", /* ??? */
+//             "windowText", "#000000", /* ??? */
+//               "menu", "#C0C0C0", /* Background color for menus */
+//               "menuText", "#000000", /* Text color for menus  */
+//               "text", "#C0C0C0", /* Text background color */
+//               "textText", "#000000", /* Text foreground color */
+//          "textHighlight", "#000080", /* Text background color when selected */
+//          "textHighlightText", "#FFFFFF", /* Text color when selected */
+//           "textInactiveText", "#808080", /* Text color when disabled */
+//                "control", "#C0C0C0", /* Default color for controls (buttons, sliders, etc) */
+//            "controlText", "#000000", /* Default color for text in controls */
+//           "controlHighlight", "#C0C0C0", /* Specular highlight (opposite of the shadow) */
+//         "controlLtHighlight", "#FFFFFF", /* Highlight color for controls */
+//          "controlShadow", "#808080", /* Shadow color for controls */
+//            "controlDkShadow", "#000000", /* Dark shadow color for controls */
+//              "scrollbar", "#E0E0E0", /* Scrollbar background (usually the "track") */
+//               "info", "#FFFFE1", /* ??? */
+//               "infoText", "#000000"  /* ??? */
+//        };
+//
+//        loadSystemColors(table, defaultSystemColors, isNativeLookAndFeel());
+    }
+
+    /**
+     * Initialize the uiClassID to AquaComponentUI mapping.
+     * The JComponent classes define their own uiClassID constants
+     * (see AbstractComponent.getUIClassID).  This table must
+     * map those constants to a BasicComponentUI class of the
+     * appropriate type.
+     *
+     * @see #getDefaults
+     */
+    protected void initClassDefaults(final UIDefaults table) {
+        final String basicPackageName = "javax.swing.plaf.basic.";
+
+        final Object[] uiDefaults = {
+            "ButtonUI", PKG_PREFIX + "AquaButtonUI",
+            "CheckBoxUI", PKG_PREFIX + "AquaButtonCheckBoxUI",
+            "CheckBoxMenuItemUI", PKG_PREFIX + "AquaMenuItemUI",
+            "LabelUI", PKG_PREFIX + "AquaLabelUI",
+            "ListUI", PKG_PREFIX + "AquaListUI",
+            "MenuUI", PKG_PREFIX + "AquaMenuUI",
+            "MenuItemUI", PKG_PREFIX + "AquaMenuItemUI",
+            "OptionPaneUI", PKG_PREFIX + "AquaOptionPaneUI",
+            "PanelUI", PKG_PREFIX + "AquaPanelUI",
+            "RadioButtonMenuItemUI", PKG_PREFIX + "AquaMenuItemUI",
+            "RadioButtonUI", PKG_PREFIX + "AquaButtonRadioUI",
+            "ProgressBarUI", PKG_PREFIX + "AquaProgressBarUI",
+            "RootPaneUI", PKG_PREFIX + "AquaRootPaneUI",
+            "SliderUI", PKG_PREFIX + "AquaSliderUI",
+            "ScrollBarUI", PKG_PREFIX + "AquaScrollBarUI",
+            "TabbedPaneUI", PKG_PREFIX + (JRSUIUtils.TabbedPane.shouldUseTabbedPaneContrastUI() ? "AquaTabbedPaneContrastUI" : "AquaTabbedPaneUI"),
+            "TableUI", PKG_PREFIX + "AquaTableUI",
+            "ToggleButtonUI", PKG_PREFIX + "AquaButtonToggleUI",
+            "ToolBarUI", PKG_PREFIX + "AquaToolBarUI",
+            "ToolTipUI", PKG_PREFIX + "AquaToolTipUI",
+            "TreeUI", PKG_PREFIX + "AquaTreeUI",
+
+            "InternalFrameUI", PKG_PREFIX + "AquaInternalFrameUI",
+            "DesktopIconUI", PKG_PREFIX + "AquaInternalFrameDockIconUI",
+            "DesktopPaneUI", PKG_PREFIX + "AquaInternalFramePaneUI",
+            "EditorPaneUI", PKG_PREFIX + "AquaEditorPaneUI",
+            "TextFieldUI", PKG_PREFIX + "AquaTextFieldUI",
+            "TextPaneUI", PKG_PREFIX + "AquaTextPaneUI",
+            "ComboBoxUI", PKG_PREFIX + "AquaComboBoxUI",
+            "PopupMenuUI", PKG_PREFIX + "AquaPopupMenuUI",
+            "TextAreaUI", PKG_PREFIX + "AquaTextAreaUI",
+            "MenuBarUI", PKG_PREFIX + "AquaMenuBarUI",
+            "FileChooserUI", PKG_PREFIX + "AquaFileChooserUI",
+            "PasswordFieldUI", PKG_PREFIX + "AquaTextPasswordFieldUI",
+            "TableHeaderUI", PKG_PREFIX + "AquaTableHeaderUI",
+
+            "FormattedTextFieldUI", PKG_PREFIX + "AquaTextFieldFormattedUI",
+
+            "SpinnerUI", PKG_PREFIX + "AquaSpinnerUI",
+            "SplitPaneUI", PKG_PREFIX + "AquaSplitPaneUI",
+            "ScrollPaneUI", PKG_PREFIX + "AquaScrollPaneUI",
+
+            "PopupMenuSeparatorUI", PKG_PREFIX + "AquaPopupMenuSeparatorUI",
+            "SeparatorUI", PKG_PREFIX + "AquaPopupMenuSeparatorUI",
+            "ToolBarSeparatorUI", PKG_PREFIX + "AquaToolBarSeparatorUI",
+
+            // as we implement aqua versions of the swing elements
+            // we will aad the com.apple.laf.FooUI classes to this table.
+
+            "ColorChooserUI", basicPackageName + "BasicColorChooserUI",
+
+            // text UIs
+            "ViewportUI", basicPackageName + "BasicViewportUI",
+        };
+        table.putDefaults(uiDefaults);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaMenuBarBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaMenuBarBorder.java
new file mode 100644
index 0000000..f8baa79
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaMenuBarBorder.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.border.Border;
+
+public class AquaMenuBarBorder implements Border {
+    public AquaMenuBarBorder() {
+        super();
+    }
+
+    /**
+     * Paints the border for the specified component with the specified
+     * position and size.
+     * @param c the component for which this border is being painted
+     * @param g the paint graphics
+     * @param x the x position of the painted border
+     * @param y the y position of the painted border
+     * @param width the width of the painted border
+     * @param height the height of the painted border
+     */
+    public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+        // for now we don't paint a border. We let the button paint it since there
+        // needs to be a strict ordering for aqua components.
+        //paintButton(c, g, x, y, width, height);
+        g.setColor(Color.gray);
+        g.drawLine(x, y + height - 1, x + width, y + height - 1);
+    }
+
+    /**
+     * Returns the insets of the border.
+     * @param c the component for which this border insets value applies
+     */
+    public Insets getBorderInsets(final Component c) {
+        return new Insets(0, 0, 1, 0);
+    }
+
+    /**
+     * Returns whether or not the border is opaque.  If the border
+     * is opaque, it is responsible for filling in it's own
+     * background when painting.
+     */
+    public boolean isBorderOpaque() {
+        return false;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaMenuBarUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaMenuBarUI.java
new file mode 100644
index 0000000..da6a01e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaMenuBarUI.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicMenuBarUI;
+
+import sun.security.action.GetPropertyAction;
+
+// MenuBar implementation for Mac L&F
+public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvider {
+    // Utilities
+    public void uninstallUI(final JComponent c) {
+        if (fScreenMenuBar != null) {
+            final JFrame frame = (JFrame)(c.getTopLevelAncestor());
+            if (frame.getMenuBar() == fScreenMenuBar) {
+                frame.setMenuBar((MenuBar)null);
+            }
+            fScreenMenuBar = null;
+        }
+        super.uninstallUI(c);
+    }
+
+    // Create PLAF
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaMenuBarUI();
+    }
+
+    // [3320390] -- If the screen menu bar is in use, don't register keyboard actions that
+    // show the menus when F10 is pressed.
+    protected void installKeyboardActions() {
+        if (!useScreenMenuBar) {
+            super.installKeyboardActions();
+        }
+    }
+
+    protected void uninstallKeyboardActions() {
+        if (!useScreenMenuBar) {
+            super.uninstallKeyboardActions();
+        }
+    }
+
+    // Paint Methods
+    public void paint(final Graphics g, final JComponent c) {
+        AquaMenuPainter.instance().paintMenuBarBackground(g, c.getWidth(), c.getHeight(), c);
+    }
+
+    public Dimension getPreferredSize(final JComponent c) {
+        if (isScreenMenuBar((JMenuBar)c)) {
+            if (setScreenMenuBar((JFrame)(c.getTopLevelAncestor()))) ;
+            return new Dimension(0, 0);
+        }
+        return null;
+    }
+
+    void clearScreenMenuBar(final JFrame frame) {
+        if (useScreenMenuBar) {
+            frame.setMenuBar(null);
+        }
+    }
+
+    boolean setScreenMenuBar(final JFrame frame) {
+        if (useScreenMenuBar) {
+            try {
+                getScreenMenuBar();
+            } catch(final Throwable t) {
+                return false;
+            }
+
+            frame.setMenuBar(fScreenMenuBar);
+        }
+
+        return true;
+    }
+
+    public ScreenMenuBar getScreenMenuBar() {
+        // Lazy init of member variables means we should use a synchronized block.
+        synchronized(this) {
+            if (fScreenMenuBar == null) fScreenMenuBar = new ScreenMenuBar(this.menuBar);
+        }
+        return fScreenMenuBar;
+    }
+
+    // JMenuBars are in frame unless we're using ScreenMenuBars *and* it's
+    //   been set by JFrame.setJMenuBar
+    // unless the JFrame has a normal java.awt.MenuBar (it's possible!)
+    // Other JMenuBars appear where the programmer puts them - top of window or elsewhere
+    public static final boolean isScreenMenuBar(final JMenuBar c) {
+        final javax.swing.plaf.ComponentUI ui = c.getUI();
+        if (ui instanceof AquaMenuBarUI) {
+            if (!((AquaMenuBarUI)ui).useScreenMenuBar) return false;
+
+            final Component parent = c.getTopLevelAncestor();
+            if (parent instanceof JFrame) {
+                final MenuBar mb = ((JFrame)parent).getMenuBar();
+                final boolean thisIsTheJMenuBar = (((JFrame)parent).getJMenuBar() == c);
+                if (mb == null) return thisIsTheJMenuBar;
+                return (mb instanceof ScreenMenuBar && thisIsTheJMenuBar);
+            }
+        }
+        return false;
+    }
+
+    ScreenMenuBar fScreenMenuBar;
+    boolean useScreenMenuBar = getScreenMenuBarProperty();
+
+    private static String getPrivSysProp(final String propName) {
+        return java.security.AccessController.doPrivileged(new GetPropertyAction(propName));
+    }
+
+    static boolean getScreenMenuBarProperty() {
+        final String props[] = new String[]{""};
+
+        boolean useScreenMenuBar = false;
+        try {
+            props[0] = getPrivSysProp(AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar");
+
+            if (props[0] != null && props[0].equals("true")) useScreenMenuBar = true;
+            else {
+                props[0] = getPrivSysProp(AquaLookAndFeel.sOldPropertyPrefix + "useScreenMenuBar");
+
+                if (props[0] != null && props[0].equals("true")) {
+                    System.err.println(AquaLookAndFeel.sOldPropertyPrefix + "useScreenMenuBar has been deprecated. Please switch to " + AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar");
+                    useScreenMenuBar = true;
+                }
+            }
+        } catch(final Throwable t) { };
+
+        return useScreenMenuBar;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaMenuBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaMenuBorder.java
new file mode 100644
index 0000000..2e2d19b
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaMenuBorder.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.UIResource;
+
+public class AquaMenuBorder implements Border, UIResource {
+    public AquaMenuBorder() { }
+
+    /**
+     * Paints the border for the specified component with the specified
+     * position and size.
+     * @param c the component for which this border is being painted
+     * @param g the paint graphics
+     * @param x the x position of the painted border
+     * @param y the y position of the painted border
+     * @param width the width of the painted border
+     * @param height the height of the painted border
+     */
+    public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+        // for now we don't paint a border. We let the button paint it since there
+        // needs to be a strict ordering for aqua components.
+        //paintButton(c, g, x, y, width, height);
+        //if (c instanceof JPopupMenu) {
+            //g.setColor(Color.red);
+            //g.drawRect(x,y, width-1, height-1);
+        //}
+    }
+
+    /**
+     * Returns whether or not the border is opaque.  If the border
+     * is opaque, it is responsible for filling in it's own
+     * background when painting.
+     */
+    public boolean isBorderOpaque() {
+        return false;
+    }
+
+    protected static Insets getItemInsets() {
+        return new Insets(1, 5, 1, 5);
+    }
+
+    protected static Insets getEmptyInsets() {
+        return new Insets(0, 0, 0, 0);
+    }
+
+    protected static Insets getPopupInsets() {
+        return new Insets(4, 0, 4, 0);
+    }
+
+    /**
+     * Returns the insets of the border.
+     * @param c the component for which this border insets value applies
+     */
+    public Insets getBorderInsets(final Component c) {
+        if (!(c instanceof JPopupMenu)) {
+            return getItemInsets();
+        }
+
+        // for more info on this issue, see AquaComboBoxPopup.updateContents()
+        final JPopupMenu menu = (JPopupMenu)c;
+        final int nChildren = menu.getComponentCount();
+        if (nChildren > 0) {
+            final Component firstChild = menu.getComponent(0);
+            if (firstChild instanceof Box.Filler) return getEmptyInsets();
+            if (firstChild instanceof JScrollPane) return getEmptyInsets();
+        }
+
+        // just need top and bottom, and not right and left.
+        // but only for non-list popups.
+        return getPopupInsets();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaMenuItemUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaMenuItemUI.java
new file mode 100644
index 0000000..e9b8e00
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaMenuItemUI.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicMenuItemUI;
+
+import apple.laf.JRSUIConstants.Size;
+
+// TODO: no screen menu bar for now
+public class AquaMenuItemUI extends BasicMenuItemUI implements AquaMenuPainter.Client/*, ScreenMenuItemUI*/ {
+    static final int kPlain = 0, kCheckBox = 1, kRadioButton = 2;
+    static final String sPropertyPrefixes[] = { "MenuItem", "CheckBoxMenuItem", "RadioButtonMenuItem" };
+
+    boolean fIsScreenMenuItem = false;
+    boolean fIsIndeterminate = false;
+    int fType;
+
+    AquaMenuItemUI(final int type) {
+        super();
+        fType = type;
+    }
+
+    public static ComponentUI createUI(final JComponent c) {
+        int type = kPlain;
+        if (c instanceof JCheckBoxMenuItem) type = kCheckBox;
+        if (c instanceof JRadioButtonMenuItem) type = kRadioButton;
+        return new AquaMenuItemUI(type);
+    }
+
+    // The only real difference between the three is which property prefix it returns
+    // and therefore which icons!
+    protected String getPropertyPrefix() {
+        return sPropertyPrefixes[fType];
+    }
+
+    @Override
+    protected void installListeners() {
+        super.installListeners();
+        IndeterminateListener.install(menuItem);
+    }
+
+    @Override
+    protected void uninstallListeners() {
+        IndeterminateListener.uninstall(menuItem);
+        super.uninstallListeners();
+    }
+
+    public void updateListenersForScreenMenuItem() {
+        setIsScreenMenu(true);
+    }
+
+    // Users can dynamically change the kind of menu we're on by calling JPopupMenu.setInvoker
+    // so we need to be prepared to put the listeners back on
+    protected void setIsScreenMenu(final boolean isScreenMenuItem) {
+        if (fIsScreenMenuItem != isScreenMenuItem) {
+            fIsScreenMenuItem = isScreenMenuItem;
+            if (fIsScreenMenuItem) removeListeners();
+            else addListeners();
+        }
+    }
+
+    protected void removeListeners() {
+        menuItem.removeMouseListener(mouseInputListener);
+        menuItem.removeMouseMotionListener(mouseInputListener);
+        menuItem.removeMenuDragMouseListener(menuDragMouseListener);
+    }
+
+    protected void addListeners() {
+        menuItem.addMouseListener(mouseInputListener);
+        menuItem.addMouseMotionListener(mouseInputListener);
+        menuItem.addMenuDragMouseListener(menuDragMouseListener);
+    }
+
+    protected void paintMenuItem(final Graphics g, final JComponent c, final Icon localCheckIcon, final Icon localArrowIcon, final Color background, final Color foreground, final int localDefaultTextIconGap) {
+        AquaMenuPainter.instance().paintMenuItem(this, g, c, localCheckIcon, localArrowIcon, background, foreground, disabledForeground, selectionForeground, localDefaultTextIconGap, acceleratorFont);
+    }
+
+    protected Dimension getPreferredMenuItemSize(final JComponent c, final Icon localCheckIcon, final Icon localArrowIcon, final int localDefaultTextIconGap) {
+        return AquaMenuPainter.instance().getPreferredMenuItemSize(c, localCheckIcon, localArrowIcon, localDefaultTextIconGap, acceleratorFont);
+    }
+
+    public void update(final Graphics g, final JComponent c) {
+        if (c.isOpaque()) {
+            // sja fix ((PenGraphics)g).alphaClearRect(0,0,c.getWidth(),c.getHeight());
+            final Color oldColor = g.getColor();
+            g.setColor(c.getBackground());
+            g.fillRect(0, 0, c.getWidth(), c.getHeight());
+            g.setColor(oldColor);
+        }
+
+        paint(g, c);
+    }
+
+    public void paintBackground(final Graphics g, final JComponent c, final int menuWidth, final int menuHeight) {
+        if ((c.getParent() instanceof JMenuBar)) return;
+        final Color oldColor = g.getColor();
+
+        g.setColor(c.getBackground());
+        g.fillRect(0, 0, menuWidth, menuHeight);
+        if (((JMenuItem)c).isBorderPainted()) {
+            if (((JMenuItem)c).getModel().isArmed()) {
+                AquaMenuPainter.instance().paintSelectedMenuItemBackground(g, menuWidth, menuHeight);
+            }
+            //getTheme().drawMenuItem(c, g, 0, 0, menuWidth, menuHeight);
+        } else {
+            // If selected, use black (see AquaLookAndFeel "Menu.selectionBackground")
+            if (((JMenuItem)c).getModel().isArmed()) {
+                final Color holdc = g.getColor();
+                g.setColor(Color.black);
+                g.fillRect(0, 0, menuWidth, menuHeight);
+                g.setColor(holdc);
+            } else {
+                g.setColor(Color.green);
+                g.fillRect(0, 0, menuWidth, menuHeight);
+                //super.paintBackground(g,c,menuWidth, menuHeight); //getTheme().drawMenuBackground((Component)c, g, (short)1, 0, 0, menuWidth, menuHeight);
+            }
+        }
+        g.setColor(oldColor);
+    }
+
+    protected void doClick(final MenuSelectionManager msm) {
+        final Dimension size = menuItem.getSize();
+        AquaUtils.blinkMenu(new AquaUtils.Selectable() {
+            public void paintSelected(final boolean selected) {
+                menuItem.setArmed(selected);
+                menuItem.paintImmediately(0, 0, size.width, size.height);
+            }
+        });
+        super.doClick(msm);
+    }
+
+    static final IndeterminateListener INDETERMINATE_LISTENER = new IndeterminateListener();
+    static class IndeterminateListener implements PropertyChangeListener {
+        static final String CLIENT_PROPERTY_KEY = "JMenuItem.selectedState";
+
+        static void install(final JMenuItem menuItem) {
+            menuItem.addPropertyChangeListener(CLIENT_PROPERTY_KEY, INDETERMINATE_LISTENER);
+            apply(menuItem, menuItem.getClientProperty(CLIENT_PROPERTY_KEY));
+        }
+
+        static void uninstall(final JMenuItem menuItem) {
+            menuItem.removePropertyChangeListener(CLIENT_PROPERTY_KEY, INDETERMINATE_LISTENER);
+        }
+
+        public void propertyChange(final PropertyChangeEvent evt) {
+            final String key = evt.getPropertyName();
+            if (!CLIENT_PROPERTY_KEY.equalsIgnoreCase(key)) return;
+
+            final Object source = evt.getSource();
+            if (!(source instanceof JMenuItem)) return;
+
+            final JMenuItem c = (JMenuItem)source;
+            apply(c, evt.getNewValue());
+        }
+
+        static void apply(final JMenuItem menuItem, final Object value) {
+            final ButtonUI ui = menuItem.getUI();
+            if (!(ui instanceof AquaMenuItemUI)) return;
+
+            final AquaMenuItemUI aquaUI = (AquaMenuItemUI)ui;
+
+            if (aquaUI.fIsIndeterminate = "indeterminate".equals(value)) {
+                aquaUI.checkIcon = UIManager.getIcon(aquaUI.getPropertyPrefix() + ".dashIcon");
+            } else {
+                aquaUI.checkIcon = UIManager.getIcon(aquaUI.getPropertyPrefix() + ".checkIcon");
+            }
+        }
+
+        public static boolean isIndeterminate(final JMenuItem menuItem) {
+            return "indeterminate".equals(menuItem.getClientProperty(CLIENT_PROPERTY_KEY));
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaMenuPainter.java b/jdk/src/macosx/classes/com/apple/laf/AquaMenuPainter.java
new file mode 100644
index 0000000..a6b7de6
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaMenuPainter.java
@@ -0,0 +1,539 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.basic.BasicHTML;
+import javax.swing.text.View;
+
+import sun.swing.SwingUtilities2;
+
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaIcon.InvertableIcon;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+/**
+ * AquaMenuPainter, implements paintMenuItem to avoid code duplication
+ *
+ * BasicMenuItemUI didn't factor out the various parts of the Menu, and
+ * we subclass it and its subclasses BasicMenuUI
+ * Our classes need an implementation of paintMenuItem
+ * that allows them to paint their own backgrounds
+ */
+
+public class AquaMenuPainter {
+    // Glyph statics:
+    // ASCII character codes
+    static final byte
+        kShiftGlyph = 0x05,
+        kOptionGlyph = 0x07,
+        kControlGlyph = 0x06,
+        kPencilGlyph = 0x0F,
+        kCommandMark = 0x11;
+
+    // Unicode character codes
+    static final char
+        kUBlackDiamond = 0x25C6,
+        kUCheckMark = 0x2713,
+        kUControlGlyph = 0x2303,
+        kUOptionGlyph = 0x2325,
+        kUEnterGlyph = 0x2324,
+        kUCommandGlyph = 0x2318,
+        kULeftDeleteGlyph = 0x232B,
+        kURightDeleteGlyph = 0x2326,
+        kUShiftGlyph = 0x21E7,
+        kUCapsLockGlyph = 0x21EA;
+
+    static final int ALT_GRAPH_MASK = 1 << 5; // New to Java2
+    static final int sUnsupportedModifiersMask = ~(InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.SHIFT_MASK | InputEvent.META_MASK | ALT_GRAPH_MASK);
+
+    interface Client {
+        public void paintBackground(Graphics g, JComponent c, int menuWidth, int menuHeight);
+    }
+
+    // Return a string with the proper modifier glyphs
+    static String getKeyModifiersText(final int modifiers, final boolean isLeftToRight) {
+        return getKeyModifiersUnicode(modifiers, isLeftToRight);
+    }
+
+    // Return a string with the proper modifier glyphs
+    private static String getKeyModifiersUnicode(final int modifiers, final boolean isLeftToRight) {
+        final StringBuilder buf = new StringBuilder(2);
+        // Order (from StandardMenuDef.c): control, option(alt), shift, cmd
+        // reverse for right-to-left
+        //$ check for substitute key glyphs for localization
+        if (isLeftToRight) {
+            if ((modifiers & InputEvent.CTRL_MASK) != 0) {
+                buf.append(kUControlGlyph);
+            }
+            if ((modifiers & (InputEvent.ALT_MASK | ALT_GRAPH_MASK)) != 0) {
+                buf.append(kUOptionGlyph);
+            }
+            if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
+                buf.append(kUShiftGlyph);
+            }
+            if ((modifiers & InputEvent.META_MASK) != 0) {
+                buf.append(kUCommandGlyph);
+            }
+        } else {
+            if ((modifiers & InputEvent.META_MASK) != 0) {
+                buf.append(kUCommandGlyph);
+            }
+            if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
+                buf.append(kUShiftGlyph);
+            }
+            if ((modifiers & (InputEvent.ALT_MASK | ALT_GRAPH_MASK)) != 0) {
+                buf.append(kUOptionGlyph);
+            }
+            if ((modifiers & InputEvent.CTRL_MASK) != 0) {
+                buf.append(kUControlGlyph);
+            }
+        }
+        return buf.toString();
+    }
+
+    static final RecyclableSingleton<AquaMenuPainter> sPainter = new RecyclableSingletonFromDefaultConstructor<AquaMenuPainter>(AquaMenuPainter.class);
+    static AquaMenuPainter instance() {
+        return sPainter.get();
+    }
+
+    static final int defaultMenuItemGap = 2;
+    static final int kAcceleratorArrowSpace = 16; // Accel space doesn't overlap arrow space, even though items can't have both
+
+    static class RecyclableBorder extends RecyclableSingleton<Border> {
+        final String borderName;
+        RecyclableBorder(final String borderName) { this.borderName = borderName; }
+        protected Border getInstance() { return UIManager.getBorder(borderName); }
+    }
+
+    protected final RecyclableBorder menuBarPainter = new RecyclableBorder("MenuBar.backgroundPainter");
+    protected final RecyclableBorder selectedMenuBarItemPainter = new RecyclableBorder("MenuBar.selectedBackgroundPainter");
+    protected final RecyclableBorder selectedMenuItemPainter = new RecyclableBorder("MenuItem.selectedBackgroundPainter");
+
+    public void paintMenuBarBackground(final Graphics g, final int width, final int height, final JComponent c) {
+        g.setColor(c == null ? Color.white : c.getBackground());
+        g.fillRect(0, 0, width, height);
+        menuBarPainter.get().paintBorder(null, g, 0, 0, width, height);
+    }
+
+    public void paintSelectedMenuTitleBackground(final Graphics g, final int width, final int height) {
+        selectedMenuBarItemPainter.get().paintBorder(null, g, -1, 0, width + 2, height);
+    }
+
+    public void paintSelectedMenuItemBackground(final Graphics g, final int width, final int height) {
+        selectedMenuItemPainter.get().paintBorder(null, g, 0, 0, width, height);
+    }
+
+    protected void paintMenuItem(final Client client, final Graphics g, final JComponent c, final Icon checkIcon, final Icon arrowIcon, final Color background, final Color foreground, final Color disabledForeground, final Color selectionForeground, final int defaultTextIconGap, final Font acceleratorFont) {
+        final JMenuItem b = (JMenuItem)c;
+        final ButtonModel model = b.getModel();
+
+//        Dimension size = b.getSize();
+        final int menuWidth = b.getWidth();
+        final int menuHeight = b.getHeight();
+        final Insets i = c.getInsets();
+
+        Rectangle viewRect = new Rectangle(0, 0, menuWidth, menuHeight);
+
+        viewRect.x += i.left;
+        viewRect.y += i.top;
+        viewRect.width -= (i.right + viewRect.x);
+        viewRect.height -= (i.bottom + viewRect.y);
+
+        final Font holdf = g.getFont();
+        final Color holdc = g.getColor();
+        final Font f = c.getFont();
+        g.setFont(f);
+        final FontMetrics fm = g.getFontMetrics(f);
+
+        final FontMetrics fmAccel = g.getFontMetrics(acceleratorFont);
+
+        // Paint background (doesn't touch the Graphics object's color)
+        if (c.isOpaque()) {
+            client.paintBackground(g, c, menuWidth, menuHeight);
+        }
+
+        // get Accelerator text
+        final KeyStroke accelerator = b.getAccelerator();
+        String modifiersString = "", keyString = "";
+        final boolean leftToRight = AquaUtils.isLeftToRight(c);
+        if (accelerator != null) {
+            final int modifiers = accelerator.getModifiers();
+            if (modifiers > 0) {
+                modifiersString = getKeyModifiersText(modifiers, leftToRight);
+            }
+            final int keyCode = accelerator.getKeyCode();
+            if (keyCode != 0) {
+                keyString = KeyEvent.getKeyText(keyCode);
+            } else {
+                keyString += accelerator.getKeyChar();
+            }
+        }
+
+        Rectangle iconRect = new Rectangle();
+        Rectangle textRect = new Rectangle();
+        Rectangle acceleratorRect = new Rectangle();
+        Rectangle checkIconRect = new Rectangle();
+        Rectangle arrowIconRect = new Rectangle();
+
+        // layout the text and icon
+        final String text = layoutMenuItem(b, fm, b.getText(), fmAccel, keyString, modifiersString, b.getIcon(), checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, b.getText() == null ? 0 : defaultTextIconGap, defaultTextIconGap);
+
+        // if this is in a AquaScreenMenuBar that's attached to a DialogPeer
+        // the native menu will be disabled, though the awt Menu won't know about it
+        // so the JPopupMenu will not have visibility set and the items should draw disabled
+        // If it's not on a JPopupMenu then it should just use the model's enable state
+        final Container parent = b.getParent();
+        final boolean parentIsMenuBar = parent instanceof JMenuBar;
+
+        Container ancestor = parent;
+        while (ancestor != null && !(ancestor instanceof JPopupMenu)) ancestor = ancestor.getParent();
+
+        boolean isEnabled = model.isEnabled() && (ancestor == null || ancestor.isVisible());
+
+        // Set the accel/normal text color
+        boolean isSelected = false;
+        if (!isEnabled) {
+            // *** paint the text disabled
+            g.setColor(disabledForeground);
+        } else {
+            // *** paint the text normally
+            if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
+                g.setColor(selectionForeground);
+                isSelected = true;
+            } else {
+                g.setColor(parentIsMenuBar ? parent.getForeground() : b.getForeground()); // Which is either MenuItem.foreground or the user's choice
+            }
+        }
+
+        // We want to paint the icon after the text color is set since some icon painting depends on the correct
+        // graphics color being set
+        // See <rdar://problem/3792383> Menu icons missing in Java2D's Lines.Joins demo
+        // Paint the Icon
+        if (b.getIcon() != null) {
+            paintIcon(g, b, iconRect, isEnabled);
+        }
+
+        // Paint the Check using the current text color
+        if (checkIcon != null) {
+            paintCheck(g, b, checkIcon, checkIconRect);
+        }
+
+        // Draw the accelerator first in case the HTML renderer changes the color
+        if (keyString != null && !keyString.equals("")) {
+            final int yAccel = acceleratorRect.y + fm.getAscent();
+            if (modifiersString.equals("")) {
+                // just draw the keyString
+                SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x, yAccel);
+            } else {
+                final int modifiers = accelerator.getModifiers();
+                int underlinedChar = 0;
+                if ((modifiers & ALT_GRAPH_MASK) > 0) underlinedChar = kUOptionGlyph; // This is a Java2 thing, we won't be getting kOptionGlyph
+                // The keyStrings should all line up, so always adjust the width by the same amount
+                // (if they're multi-char, they won't line up but at least they won't be cut off)
+                final int emWidth = Math.max(fm.charWidth('M'), SwingUtilities.computeStringWidth(fm, keyString));
+
+                if (leftToRight) {
+                    g.setFont(acceleratorFont);
+                    drawString(g, c, modifiersString, underlinedChar, acceleratorRect.x, yAccel, isEnabled, isSelected);
+                    g.setFont(f);
+                    SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x + acceleratorRect.width - emWidth, yAccel);
+                } else {
+                    final int xAccel = acceleratorRect.x + emWidth;
+                    g.setFont(acceleratorFont);
+                    drawString(g, c, modifiersString, underlinedChar, xAccel, yAccel, isEnabled, isSelected);
+                    g.setFont(f);
+                    SwingUtilities2.drawString(c, g, keyString, xAccel - fm.stringWidth(keyString), yAccel);
+                }
+            }
+        }
+
+        // Draw the Text
+        if (text != null && !text.equals("")) {
+            final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
+            if (v != null) {
+                v.paint(g, textRect);
+            } else {
+                final int mnemonic = (AquaMnemonicHandler.isMnemonicHidden() ? -1 : model.getMnemonic());
+                drawString(g, c, text, mnemonic, textRect.x, textRect.y + fm.getAscent(), isEnabled, isSelected);
+            }
+        }
+
+        // Paint the Arrow
+        if (arrowIcon != null) {
+            paintArrow(g, b, model, arrowIcon, arrowIconRect);
+        }
+
+        g.setColor(holdc);
+        g.setFont(holdf);
+    }
+
+    // All this had to be copied from BasicMenuItemUI, just to get the right keyModifiersText fn
+    // and a few Mac tweaks
+    protected Dimension getPreferredMenuItemSize(final JComponent c, final Icon checkIcon, final Icon arrowIcon, final int defaultTextIconGap, final Font acceleratorFont) {
+        final JMenuItem b = (JMenuItem)c;
+        final Icon icon = b.getIcon();
+        final String text = b.getText();
+        final KeyStroke accelerator = b.getAccelerator();
+        String keyString = "", modifiersString = "";
+
+        if (accelerator != null) {
+            final int modifiers = accelerator.getModifiers();
+            if (modifiers > 0) {
+                modifiersString = getKeyModifiersText(modifiers, true); // doesn't matter, this is just for metrics
+            }
+            final int keyCode = accelerator.getKeyCode();
+            if (keyCode != 0) {
+                keyString = KeyEvent.getKeyText(keyCode);
+            } else {
+                keyString += accelerator.getKeyChar();
+            }
+        }
+
+        final Font font = b.getFont();
+        final FontMetrics fm = b.getFontMetrics(font);
+        final FontMetrics fmAccel = b.getFontMetrics(acceleratorFont);
+
+        Rectangle iconRect = new Rectangle();
+        Rectangle textRect = new Rectangle();
+        Rectangle acceleratorRect = new Rectangle();
+        Rectangle checkIconRect = new Rectangle();
+        Rectangle arrowIconRect = new Rectangle();
+        Rectangle viewRect = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);
+
+        layoutMenuItem(b, fm, text, fmAccel, keyString, modifiersString, icon, checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, text == null ? 0 : defaultTextIconGap, defaultTextIconGap);
+        // find the union of the icon and text rects
+        Rectangle r = new Rectangle();
+        r.setBounds(textRect);
+        r = SwingUtilities.computeUnion(iconRect.x, iconRect.y, iconRect.width, iconRect.height, r);
+        //   r = iconRect.union(textRect);
+
+        // Add in the accelerator
+        boolean acceleratorTextIsEmpty = (keyString == null) || keyString.equals("");
+
+        if (!acceleratorTextIsEmpty) {
+            r.width += acceleratorRect.width;
+        }
+
+        if (!isTopLevelMenu(b)) {
+            // Add in the checkIcon
+            r.width += checkIconRect.width;
+            r.width += defaultTextIconGap;
+
+            // Add in the arrowIcon space
+            r.width += defaultTextIconGap;
+            r.width += arrowIconRect.width;
+        }
+
+        final Insets insets = b.getInsets();
+        if (insets != null) {
+            r.width += insets.left + insets.right;
+            r.height += insets.top + insets.bottom;
+        }
+
+        // Tweak for Mac
+        r.width += 4 + defaultTextIconGap;
+        r.height = Math.max(r.height, 18);
+
+        return r.getSize();
+    }
+
+    protected void paintCheck(final Graphics g, final JMenuItem item, Icon checkIcon, Rectangle checkIconRect) {
+        if (isTopLevelMenu(item) || !item.isSelected()) return;
+
+        if (item.isArmed() && checkIcon instanceof InvertableIcon) {
+            ((InvertableIcon)checkIcon).getInvertedIcon().paintIcon(item, g, checkIconRect.x, checkIconRect.y);
+        } else {
+            checkIcon.paintIcon(item, g, checkIconRect.x, checkIconRect.y);
+        }
+    }
+
+    protected void paintIcon(final Graphics g, final JMenuItem c, final Rectangle localIconRect, boolean isEnabled) {
+        final ButtonModel model = c.getModel();
+        Icon icon;
+        if (!isEnabled) {
+            icon = c.getDisabledIcon();
+        } else if (model.isPressed() && model.isArmed()) {
+            icon = c.getPressedIcon();
+            if (icon == null) {
+                // Use default icon
+                icon = c.getIcon();
+            }
+        } else {
+            icon = c.getIcon();
+        }
+
+        if (icon != null) icon.paintIcon(c, g, localIconRect.x, localIconRect.y);
+    }
+
+    protected void paintArrow(Graphics g, JMenuItem c, ButtonModel model, Icon arrowIcon, Rectangle arrowIconRect) {
+        if (isTopLevelMenu(c)) return;
+
+        if (c instanceof JMenu && (model.isArmed() || model.isSelected()) && arrowIcon instanceof InvertableIcon) {
+            ((InvertableIcon)arrowIcon).getInvertedIcon().paintIcon(c, g, arrowIconRect.x, arrowIconRect.y);
+        } else {
+            arrowIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y);
+        }
+    }
+
+    /** Draw a string with the graphics g at location (x,y) just like g.drawString() would.
+     *  The first occurence of underlineChar in text will be underlined. The matching is
+     *  not case sensitive.
+     */
+    public void drawString(final Graphics g, final JComponent c, final String text, final int underlinedChar, final int x, final int y, final boolean isEnabled, final boolean isSelected) {
+        char lc, uc;
+        int index = -1, lci, uci;
+
+        if (underlinedChar != '\0') {
+            uc = Character.toUpperCase((char)underlinedChar);
+            lc = Character.toLowerCase((char)underlinedChar);
+
+            uci = text.indexOf(uc);
+            lci = text.indexOf(lc);
+
+            if (uci == -1) index = lci;
+            else if (lci == -1) index = uci;
+            else index = (lci < uci) ? lci : uci;
+        }
+
+        SwingUtilities2.drawStringUnderlineCharAt(c, g, text, index, x, y);
+    }
+
+    /*
+     * Returns false if the component is a JMenu and it is a top
+     * level menu (on the menubar).
+     */
+    private static boolean isTopLevelMenu(final JMenuItem menuItem) {
+        return (menuItem instanceof JMenu) && (((JMenu)menuItem).isTopLevelMenu());
+    }
+
+    private String layoutMenuItem(final JMenuItem menuItem, final FontMetrics fm, final String text, final FontMetrics fmAccel, String keyString, final String modifiersString, final Icon icon, final Icon checkIcon, final Icon arrowIcon, final int verticalAlignment, final int horizontalAlignment, final int verticalTextPosition, final int horizontalTextPosition, final Rectangle viewR, final Rectangle iconR, final Rectangle textR, final Rectangle acceleratorR, final Rectangle checkIconR, final Rectangle arrowIconR, final int textIconGap, final int menuItemGap) {
+        // Force it to do "LEFT", then flip the rects if we're right-to-left
+        SwingUtilities.layoutCompoundLabel(menuItem, fm, text, icon, verticalAlignment, SwingConstants.LEFT, verticalTextPosition, horizontalTextPosition, viewR, iconR, textR, textIconGap);
+
+        final boolean acceleratorTextIsEmpty = (keyString == null) || keyString.equals("");
+
+        if (acceleratorTextIsEmpty) {
+            acceleratorR.width = acceleratorR.height = 0;
+            keyString = "";
+        } else {
+            // Accel space doesn't overlap arrow space, even though items can't have both
+            acceleratorR.width = SwingUtilities.computeStringWidth(fmAccel, modifiersString);
+            // The keyStrings should all line up, so always adjust the width by the same amount
+            // (if they're multi-char, they won't line up but at least they won't be cut off)
+            acceleratorR.width += Math.max(fm.charWidth('M'), SwingUtilities.computeStringWidth(fm, keyString));
+            acceleratorR.height = fmAccel.getHeight();
+        }
+
+        /* Initialize the checkIcon bounds rectangle checkIconR.
+         */
+
+        final boolean isTopLevelMenu = isTopLevelMenu(menuItem);
+        if (!isTopLevelMenu) {
+            if (checkIcon != null) {
+                checkIconR.width = checkIcon.getIconWidth();
+                checkIconR.height = checkIcon.getIconHeight();
+            } else {
+                checkIconR.width = checkIconR.height = 16;
+            }
+
+            /* Initialize the arrowIcon bounds rectangle arrowIconR.
+             */
+
+            if (arrowIcon != null) {
+                arrowIconR.width = arrowIcon.getIconWidth();
+                arrowIconR.height = arrowIcon.getIconHeight();
+            } else {
+                arrowIconR.width = arrowIconR.height = 16;
+            }
+
+            textR.x += 12;
+            iconR.x += 12;
+        }
+
+        final Rectangle labelR = iconR.union(textR);
+
+        // Position the Accelerator text rect
+        // Menu shortcut text *ought* to have the letters left-justified - look at a menu with an "M" in it
+        acceleratorR.x += (viewR.width - arrowIconR.width - acceleratorR.width);
+        acceleratorR.y = viewR.y + (viewR.height / 2) - (acceleratorR.height / 2);
+
+        if (!isTopLevelMenu) {
+            //    if ( GetSysDirection() < 0 ) hierRect.right = hierRect.left + w + 4;
+            //    else hierRect.left = hierRect.right - w - 4;
+            arrowIconR.x = (viewR.width - arrowIconR.width) + 1;
+            arrowIconR.y = viewR.y + (labelR.height / 2) - (arrowIconR.height / 2) + 1;
+
+            checkIconR.y = viewR.y + (labelR.height / 2) - (checkIconR.height / 2);
+            checkIconR.x = 5;
+
+            textR.width += 8;
+        }
+
+        /*System.out.println("Layout: " +horizontalAlignment+ " v=" +viewR+"  c="+checkIconR+" i="+
+         iconR+" t="+textR+" acc="+acceleratorR+" a="+arrowIconR);*/
+
+        if (!AquaUtils.isLeftToRight(menuItem)) {
+            // Flip the rectangles so that instead of [check][icon][text][accel/arrow] it's [accel/arrow][text][icon][check]
+            final int w = viewR.width;
+            checkIconR.x = w - (checkIconR.x + checkIconR.width);
+            iconR.x = w - (iconR.x + iconR.width);
+            textR.x = w - (textR.x + textR.width);
+            acceleratorR.x = w - (acceleratorR.x + acceleratorR.width);
+            arrowIconR.x = w - (arrowIconR.x + arrowIconR.width);
+        }
+        textR.x += menuItemGap;
+        iconR.x += menuItemGap;
+
+        return text;
+    }
+
+    public static Border getMenuBarPainter() {
+        final AquaBorder border = new AquaBorder.Default();
+        border.painter.state.set(Widget.MENU_BAR);
+        return border;
+    }
+
+    public static Border getSelectedMenuBarItemPainter() {
+        final AquaBorder border = new AquaBorder.Default();
+        border.painter.state.set(Widget.MENU_TITLE);
+        border.painter.state.set(State.PRESSED);
+        return border;
+    }
+
+    public static Border getSelectedMenuItemPainter() {
+        final AquaBorder border = new AquaBorder.Default();
+        border.painter.state.set(Widget.MENU_ITEM);
+        border.painter.state.set(State.PRESSED);
+        return border;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaMenuUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaMenuUI.java
new file mode 100644
index 0000000..8ebaab6
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaMenuUI.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.MouseEvent;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicMenuUI;
+
+public class AquaMenuUI extends BasicMenuUI implements AquaMenuPainter.Client {
+    public static ComponentUI createUI(final JComponent x) {
+        return new AquaMenuUI();
+    }
+
+    protected ChangeListener createChangeListener(final JComponent c) {
+        return new ChangeHandler((JMenu)c, this);
+    }
+
+    protected void installDefaults() {
+        super.installDefaults();
+
+        // [3361625]
+        // In Aqua, the menu delay is 8 ticks, according to Eric Schlegel.
+        // That makes the millisecond delay 8 ticks * 1 second / 60 ticks * 1000 milliseconds/second
+        ((JMenu)menuItem).setDelay(8 * 1000 / 60);
+    }
+
+    protected void paintMenuItem(final Graphics g, final JComponent c, final Icon localCheckIcon, final Icon localArrowIcon, final Color background, final Color foreground, final int localDefaultTextIconGap) {
+        AquaMenuPainter.instance().paintMenuItem(this, g, c, localCheckIcon, localArrowIcon, background, foreground, disabledForeground, selectionForeground, localDefaultTextIconGap, acceleratorFont);
+    }
+
+    protected Dimension getPreferredMenuItemSize(final JComponent c, final Icon localCheckIcon, final Icon localArrowIcon, final int localDefaultTextIconGap) {
+        final Dimension d = AquaMenuPainter.instance().getPreferredMenuItemSize(c, localCheckIcon, localArrowIcon, localDefaultTextIconGap, acceleratorFont);
+        if (c.getParent() instanceof JMenuBar) d.height = Math.max(d.height, 21);
+        return d;
+    }
+
+    public void paintBackground(final Graphics g, final JComponent c, final int menuWidth, final int menuHeight) {
+        final Container parent = c.getParent();
+        final boolean parentIsMenuBar = parent instanceof JMenuBar;
+
+        final ButtonModel model = ((JMenuItem)c).getModel();
+        if (model.isArmed() || model.isSelected()) {
+            if (parentIsMenuBar) {
+                AquaMenuPainter.instance().paintSelectedMenuTitleBackground(g, menuWidth, menuHeight);
+            } else {
+                AquaMenuPainter.instance().paintSelectedMenuItemBackground(g, menuWidth, menuHeight);
+            }
+        } else {
+            if (parentIsMenuBar) {
+                AquaMenuPainter.instance().paintMenuBarBackground(g, menuWidth, menuHeight, c);
+            } else {
+                g.setColor(c.getBackground());
+                g.fillRect(0, 0, menuWidth, menuHeight);
+            }
+        }
+    }
+
+    protected MouseInputListener createMouseInputListener(final JComponent c) {
+        return new AquaMouseInputHandler();
+    }
+
+    protected MenuDragMouseListener createMenuDragMouseListener(final JComponent c) {
+        //return super.createMenuDragMouseListener(c);
+        return new MenuDragMouseHandler();
+    }
+
+    class MenuDragMouseHandler implements MenuDragMouseListener {
+        public void menuDragMouseDragged(final MenuDragMouseEvent e) {
+            if (menuItem.isEnabled() == false) return;
+
+            final MenuSelectionManager manager = e.getMenuSelectionManager();
+            final MenuElement path[] = e.getPath();
+
+            // In Aqua, we always respect the menu's delay, if one is set.
+            // Doesn't matter how the menu is clicked on or otherwise moused over.
+            final Point p = e.getPoint();
+            if (p.x >= 0 && p.x < menuItem.getWidth() && p.y >= 0 && p.y < menuItem.getHeight()) {
+                final JMenu menu = (JMenu)menuItem;
+                final MenuElement selectedPath[] = manager.getSelectedPath();
+                if (!(selectedPath.length > 0 && selectedPath[selectedPath.length - 1] == menu.getPopupMenu())) {
+                    if (menu.getDelay() == 0) {
+                        appendPath(path, menu.getPopupMenu());
+                    } else {
+                        manager.setSelectedPath(path);
+                        setupPostTimer(menu);
+                    }
+                }
+            } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
+                final Component comp = manager.componentForPoint(e.getComponent(), e.getPoint());
+                if (comp == null) manager.clearSelectedPath();
+            }
+        }
+
+        public void menuDragMouseEntered(final MenuDragMouseEvent e) { }
+        public void menuDragMouseExited(final MenuDragMouseEvent e) { }
+        public void menuDragMouseReleased(final MenuDragMouseEvent e) { }
+    }
+
+    static void appendPath(final MenuElement[] path, final MenuElement elem) {
+        final MenuElement newPath[] = new MenuElement[path.length + 1];
+        System.arraycopy(path, 0, newPath, 0, path.length);
+        newPath[path.length] = elem;
+        MenuSelectionManager.defaultManager().setSelectedPath(newPath);
+    }
+
+    protected class AquaMouseInputHandler extends MouseInputHandler {
+        /**
+         * Invoked when the cursor enters the menu. This method sets the selected
+         * path for the MenuSelectionManager and handles the case
+         * in which a menu item is used to pop up an additional menu, as in a
+         * hierarchical menu system.
+         *
+         * @param e the mouse event; not used
+         */
+        public void mouseEntered(final MouseEvent e) {
+            final JMenu menu = (JMenu)menuItem;
+            if (!menu.isEnabled()) return;
+
+            final MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+            final MenuElement selectedPath[] = manager.getSelectedPath();
+
+            // In Aqua, we always have a menu delay, regardless of where the menu is.
+            if (!(selectedPath.length > 0 && selectedPath[selectedPath.length - 1] == menu.getPopupMenu())) {
+                if (menu.getDelay() == 0) {
+                    appendPath(getPath(), menu.getPopupMenu());
+                } else {
+                    manager.setSelectedPath(getPath());
+                    setupPostTimer(menu);
+                }
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaMnemonicHandler.java b/jdk/src/macosx/classes/com/apple/laf/AquaMnemonicHandler.java
new file mode 100644
index 0000000..46b0417
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaMnemonicHandler.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.KeyEvent;
+
+import javax.swing.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaMnemonicHandler {
+    static final RecyclableSingleton<AltProcessor> altProcessor = new RecyclableSingletonFromDefaultConstructor<AltProcessor>(AltProcessor.class);
+    public static KeyEventPostProcessor getInstance() {
+        return altProcessor.get();
+    }
+
+    protected static boolean isMnemonicHidden = true; // true by default
+
+    public static void setMnemonicHidden(final boolean hide) {
+        if (UIManager.getBoolean("Button.showMnemonics")) {
+            // Do not hide mnemonics if the UI defaults do not support this
+            isMnemonicHidden = false;
+        } else {
+            isMnemonicHidden = hide;
+        }
+    }
+
+    /**
+     * Gets the state of the hide mnemonic flag. This only has meaning if this feature is supported by the underlying OS.
+     *
+     * @return true if mnemonics are hidden, otherwise, false
+     * @see #setMnemonicHidden
+     * @since 1.4
+     */
+    public static boolean isMnemonicHidden() {
+        if (UIManager.getBoolean("Button.showMnemonics")) {
+            // Do not hide mnemonics if the UI defaults do not support this
+            isMnemonicHidden = false;
+        }
+        return isMnemonicHidden;
+    }
+
+    static class AltProcessor implements KeyEventPostProcessor {
+        public boolean postProcessKeyEvent(final KeyEvent ev) {
+            if (ev.getKeyCode() != KeyEvent.VK_ALT) {
+                return false;
+            }
+
+            final JRootPane root = SwingUtilities.getRootPane(ev.getComponent());
+            final Window winAncestor = (root == null ? null : SwingUtilities.getWindowAncestor(root));
+
+            switch(ev.getID()) {
+                case KeyEvent.KEY_PRESSED:
+                    setMnemonicHidden(false);
+                    break;
+                case KeyEvent.KEY_RELEASED:
+                    setMnemonicHidden(true);
+                    break;
+            }
+
+            repaintMnemonicsInWindow(winAncestor);
+
+            return false;
+        }
+    }
+
+    /*
+     * Repaints all the components with the mnemonics in the given window and all its owned windows.
+     */
+    static void repaintMnemonicsInWindow(final Window w) {
+        if (w == null || !w.isShowing()) {
+            return;
+        }
+
+        final Window[] ownedWindows = w.getOwnedWindows();
+        for (final Window element : ownedWindows) {
+            repaintMnemonicsInWindow(element);
+        }
+
+        repaintMnemonicsInContainer(w);
+    }
+
+    /*
+     * Repaints all the components with the mnemonics in container.
+     * Recursively searches for all the subcomponents.
+     */
+    static void repaintMnemonicsInContainer(final Container cont) {
+        for (int i = 0; i < cont.getComponentCount(); i++) {
+            final Component c = cont.getComponent(i);
+            if (c == null || !c.isVisible()) {
+                continue;
+            }
+
+            if (c instanceof AbstractButton && ((AbstractButton)c).getMnemonic() != '\0') {
+                c.repaint();
+                continue;
+            }
+
+            if (c instanceof JLabel && ((JLabel)c).getDisplayedMnemonic() != '\0') {
+                c.repaint();
+                continue;
+            }
+
+            if (c instanceof Container) {
+                repaintMnemonicsInContainer((Container)c);
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaNativeResources.java b/jdk/src/macosx/classes/com/apple/laf/AquaNativeResources.java
new file mode 100644
index 0000000..5a227d9
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaNativeResources.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.security.PrivilegedAction;
+
+import javax.swing.plaf.UIResource;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaNativeResources {
+    static {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osxui"));
+    }
+
+    // TODO: removing CColorPaint for now
+    static class CColorPaintUIResource extends Color/*CColorPaint*/ implements UIResource {
+        // The color passed to this MUST be a retained NSColor, and the CColorPaintUIResource
+        //  takes ownership of that retain.
+        public CColorPaintUIResource(long color, int r, int g, int b, int a) {
+            super(r, g, b, a);
+            //super(color, r, g, b, a);
+        }
+    }
+
+    static final RecyclableSingleton<Color> sBackgroundColor = new RecyclableSingleton<Color>() {
+        @Override
+        protected Color getInstance() {
+            final long backgroundID = getWindowBackgroundColor();
+            return new CColorPaintUIResource(backgroundID, 0xEE, 0xEE, 0xEE, 0xFF);
+        }
+    };
+    private static native long getWindowBackgroundColor();
+    public static Color getWindowBackgroundColorUIResource() {
+        return sBackgroundColor.get();
+    }
+
+    static BufferedImage getRadioButtonSizerImage() {
+        final BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+
+        Graphics g = img.getGraphics();
+        g.setColor(Color.pink);
+        g.fillRect(0, 0, 20, 20);
+
+        return img;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaOptionPaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaOptionPaneUI.java
new file mode 100644
index 0000000..2ff885e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaOptionPaneUI.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicOptionPaneUI;
+
+public class AquaOptionPaneUI extends BasicOptionPaneUI {
+    private static final int kOKCancelButtonWidth = 79;
+    private static final int kButtonHeight = 23;
+
+    private static final int kDialogSmallPadding = 4;
+    private static final int kDialogLargePadding = 23;
+
+    /**
+     * Creates a new BasicOptionPaneUI instance.
+     */
+    public static ComponentUI createUI(final JComponent x) {
+        return new AquaOptionPaneUI();
+    }
+
+    /**
+     * Creates and returns a Container containin the buttons. The buttons
+     * are created by calling <code>getButtons</code>.
+     */
+    protected Container createButtonArea() {
+        final Container bottom = super.createButtonArea();
+        // Now replace the Layout
+        bottom.setLayout(new AquaButtonAreaLayout(true, kDialogSmallPadding));
+        return bottom;
+    }
+
+    /**
+     * Messaged from installComponents to create a Container containing the
+     * body of the message.
+     * The icon and body should be aligned on their top edges
+     */
+    protected Container createMessageArea() {
+        final JPanel top = new JPanel();
+        top.setBorder(UIManager.getBorder("OptionPane.messageAreaBorder"));
+        top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS));
+
+        /* Fill the body. */
+        final Container body = new JPanel();
+
+        final Icon sideIcon = getIcon();
+
+        if (sideIcon != null) {
+            final JLabel iconLabel = new JLabel(sideIcon);
+            iconLabel.setVerticalAlignment(SwingConstants.TOP);
+
+            final JPanel iconPanel = new JPanel();
+            iconPanel.add(iconLabel);
+            top.add(iconPanel);
+            top.add(Box.createHorizontalStrut(kDialogLargePadding));
+        }
+
+        body.setLayout(new GridBagLayout());
+        final GridBagConstraints cons = new GridBagConstraints();
+        cons.gridx = cons.gridy = 0;
+        cons.gridwidth = GridBagConstraints.REMAINDER;
+        cons.gridheight = 1;
+        cons.anchor = GridBagConstraints.WEST;
+        cons.insets = new Insets(0, 0, 3, 0);
+
+        addMessageComponents(body, cons, getMessage(), getMaxCharactersPerLineCount(), false);
+        top.add(body);
+
+        return top;
+    }
+
+    /**
+     * AquaButtonAreaLayout lays out all
+     *   components according to the HI Guidelines:
+     * The most important button is always on the far right
+     * The group of buttons is on the right for left-to-right,
+     *         left for right-to-left
+     * The widths of each component will be set to the largest preferred size width.
+     *
+     *
+     * This inner class is marked &quot;public&quot; due to a compiler bug.
+     * This class should be treated as a &quot;protected&quot; inner class.
+     * Instantiate it only within subclasses of BasicOptionPaneUI.
+     *
+     * BasicOptionPaneUI expects that its buttons are layed out with
+     * a subclass of ButtonAreaLayout
+     */
+    public static class AquaButtonAreaLayout extends ButtonAreaLayout {
+        public AquaButtonAreaLayout(final boolean syncAllWidths, final int padding) {
+            super(true, padding);
+        }
+
+        public void layoutContainer(final Container container) {
+            final Component[] children = container.getComponents();
+            if (children == null || 0 >= children.length) return;
+
+            final int numChildren = children.length;
+            final int yLocation = container.getInsets().top;
+
+            // Always syncAllWidths - and heights!
+            final Dimension maxSize = new Dimension(kOKCancelButtonWidth, kButtonHeight);
+            for (int i = 0; i < numChildren; i++) {
+                final Dimension sizes = children[i].getPreferredSize();
+                maxSize.width = Math.max(maxSize.width, sizes.width);
+                maxSize.height = Math.max(maxSize.height, sizes.height);
+            }
+
+            // ignore getCentersChildren, because we don't
+            int xLocation = container.getSize().width - (maxSize.width * numChildren + (numChildren - 1) * padding);
+            final int xOffset = maxSize.width + padding;
+
+            // most important button (button zero) on far right
+            for (int i = numChildren - 1; i >= 0; i--) {
+                children[i].setBounds(xLocation, yLocation, maxSize.width, maxSize.height);
+                xLocation += xOffset;
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaPainter.java b/jdk/src/macosx/classes/com/apple/laf/AquaPainter.java
new file mode 100644
index 0000000..cfafa43
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaPainter.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.image.*;
+import java.util.HashMap;
+
+import com.apple.laf.AquaImageFactory.RecyclableSlicedImageControl;
+import com.apple.laf.AquaImageFactory.NineSliceMetrics;
+import com.apple.laf.AquaImageFactory.SlicedImageControl;
+
+import sun.awt.image.*;
+import sun.java2d.*;
+import sun.print.*;
+import apple.laf.*;
+import apple.laf.JRSUIConstants.Widget;
+import apple.laf.JRSUIUtils.NineSliceMetricsProvider;
+
+abstract class AquaPainter <T extends JRSUIState> {
+    static <T extends JRSUIState> AquaPainter<T> create(final T state) {
+        return new AquaSingleImagePainter<T>(state);
+    }
+
+    static <T extends JRSUIState> AquaPainter<T> create(final T state, final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut) {
+        return AquaPainter.create(state, minWidth, minHeight, westCut, eastCut, northCut, southCut, true);
+    }
+
+    static <T extends JRSUIState> AquaPainter<T> create(final T state, final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean useMiddle) {
+        return AquaPainter.create(state, minWidth, minHeight, westCut, eastCut, northCut, southCut, useMiddle, true, true);
+    }
+
+    static <T extends JRSUIState> AquaPainter<T> create(final T state, final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean useMiddle, final boolean stretchHorizontally, final boolean stretchVertically) {
+        return create(state, new NineSliceMetricsProvider() {
+            @Override
+               public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state) {
+                return new NineSliceMetrics(minWidth, minHeight, westCut, eastCut, northCut, southCut, useMiddle, stretchHorizontally, stretchVertically);
+            }
+        });
+    }
+
+    static <T extends JRSUIState> AquaPainter<T> create(final T state, final NineSliceMetricsProvider metricsProvider) {
+        return new AquaNineSlicingImagePainter<T>(state, metricsProvider);
+    }
+
+    abstract void paint(final Graphics2D g, final T stateToPaint, final Component c);
+
+    final Rectangle boundsRect = new Rectangle();
+    final JRSUIControl control;
+    T state;
+    public AquaPainter(final JRSUIControl control, final T state) {
+        this.control = control;
+        this.state = state;
+    }
+
+    JRSUIControl getControl() {
+        control.set(state = (T)state.derive());
+        return control;
+    }
+
+    void paint(final Graphics g, final Component c, final int x, final int y, final int w, final int h) {
+        boundsRect.setBounds(x, y, w, h);
+
+        final T nextState = (T)state.derive();
+        final Graphics2D g2d = getGraphics2D(g);
+        if (g2d != null) paint(g2d, nextState, c);
+        state = nextState;
+    }
+
+    static class AquaNineSlicingImagePainter<T extends JRSUIState> extends AquaPainter<T> {
+        protected final HashMap<T, RecyclableJRSUISlicedImageControl> slicedControlImages;
+        protected final NineSliceMetricsProvider metricsProvider;
+
+        public AquaNineSlicingImagePainter(final T state) {
+            this(state, null);
+        }
+
+        public AquaNineSlicingImagePainter(final T state, final NineSliceMetricsProvider metricsProvider) {
+            super(new JRSUIControl(false), state);
+            this.metricsProvider = metricsProvider;
+            slicedControlImages = new HashMap<T, RecyclableJRSUISlicedImageControl>();
+        }
+
+        @Override
+        void paint(final Graphics2D g, final T stateToPaint, final Component c) {
+            if (metricsProvider == null) {
+                AquaSingleImagePainter.paintFromSingleCachedImage(g, control, stateToPaint, c, boundsRect);
+                return;
+            }
+
+            RecyclableJRSUISlicedImageControl slicesRef = slicedControlImages.get(stateToPaint);
+            if (slicesRef == null) {
+                final NineSliceMetrics metrics = metricsProvider.getNineSliceMetricsForState(stateToPaint);
+                if (metrics == null) {
+                    AquaSingleImagePainter.paintFromSingleCachedImage(g, control, stateToPaint, c, boundsRect);
+                    return;
+                }
+                slicesRef = new RecyclableJRSUISlicedImageControl(control, stateToPaint, metrics);
+                slicedControlImages.put(stateToPaint, slicesRef);
+            }
+            final SlicedImageControl slices = slicesRef.get();
+            slices.paint(g, boundsRect.x, boundsRect.y, boundsRect.width, boundsRect.height);
+        }
+    }
+
+    static class AquaSingleImagePainter<T extends JRSUIState> extends AquaPainter<T> {
+        public AquaSingleImagePainter(final T state) {
+            super(new JRSUIControl(false), state);
+        }
+
+        @Override
+        void paint(Graphics2D g, T stateToPaint, Component c) {
+            paintFromSingleCachedImage(g, control, stateToPaint, c, boundsRect);
+        }
+
+        static void paintFromSingleCachedImage(final Graphics2D g, final JRSUIControl control, final JRSUIState controlState, final Component c, final Rectangle boundsRect) {
+            Rectangle clipRect = g.getClipBounds();
+            Rectangle intersection = boundsRect.intersection(clipRect);
+            if (intersection.width <= 0 || intersection.height <= 0) return;
+
+            int imgX1 = intersection.x - boundsRect.x;
+            int imgY1 = intersection.y - boundsRect.y;
+
+            final GraphicsConfiguration config = g.getDeviceConfiguration();
+            final ImageCache cache = ImageCache.getInstance();
+            BufferedImage image = (BufferedImage)cache.getImage(config, boundsRect.width, boundsRect.height, controlState);
+            if (image == null) {
+                image = new BufferedImage(boundsRect.width, boundsRect.height, BufferedImage.TYPE_INT_ARGB_PRE);
+                cache.setImage(image, config, boundsRect.width, boundsRect.height, controlState);
+            } else {
+                g.drawImage(image, intersection.x, intersection.y, intersection.x + intersection.width, intersection.y + intersection.height,
+                        imgX1, imgY1, imgX1 + intersection.width, imgY1 + intersection.height, null);
+                return;
+            }
+
+            final WritableRaster raster = image.getRaster();
+            final DataBufferInt buffer = (DataBufferInt)raster.getDataBuffer();
+
+            control.set(controlState);
+            control.paint(SunWritableRaster.stealData(buffer, 0),
+                    image.getWidth(), image.getHeight(), 0, 0, boundsRect.width, boundsRect.height);
+            SunWritableRaster.markDirty(buffer);
+
+            g.drawImage(image, intersection.x, intersection.y, intersection.x + intersection.width, intersection.y + intersection.height,
+                    imgX1, imgY1, imgX1 + intersection.width, imgY1 + intersection.height, null);
+        }
+    }
+
+    static class RecyclableJRSUISlicedImageControl extends RecyclableSlicedImageControl {
+        final JRSUIControl control;
+        final JRSUIState state;
+
+        public RecyclableJRSUISlicedImageControl(final JRSUIControl control, final JRSUIState state, final NineSliceMetrics metrics) {
+            super(metrics);
+            this.control = control;
+            this.state = state;
+        }
+
+        @Override
+        protected Image createTemplateImage(int width, int height) {
+            BufferedImage image = new BufferedImage(metrics.minW, metrics.minH, BufferedImage.TYPE_INT_ARGB_PRE);
+
+            final WritableRaster raster = image.getRaster();
+            final DataBufferInt buffer = (DataBufferInt)raster.getDataBuffer();
+
+            control.set(state);
+            control.paint(SunWritableRaster.stealData(buffer, 0), metrics.minW, metrics.minH, 0, 0, metrics.minW, metrics.minH);
+
+            SunWritableRaster.markDirty(buffer);
+
+            return image;
+        }
+    }
+
+    protected Graphics2D getGraphics2D(final Graphics g) {
+        try {
+            return (SunGraphics2D)g; // doing a blind try is faster than checking instanceof
+        } catch (Exception e) {
+            if (g instanceof PeekGraphics) {
+                // if it is a peek just dirty the region
+                g.fillRect(boundsRect.x, boundsRect.y, boundsRect.width, boundsRect.height);
+            } else if (g instanceof ProxyGraphics2D) {
+                final ProxyGraphics2D pg = (ProxyGraphics2D)g;
+                final Graphics2D g2d = pg.getDelegate();
+                if (g2d instanceof SunGraphics2D) { return (SunGraphics2D)g2d; }
+            } else if (g instanceof Graphics2D) {
+                return (Graphics2D) g;
+            }
+        }
+
+        return null;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaPanelUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaPanelUI.java
new file mode 100644
index 0000000..07a758f
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaPanelUI.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import javax.swing.JComponent;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicPanelUI;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaPanelUI extends BasicPanelUI {
+    static RecyclableSingleton<AquaPanelUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaPanelUI>(AquaPanelUI.class);
+
+    public static ComponentUI createUI(final JComponent c) {
+        return instance.get();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaPopupMenuSeparatorUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaPopupMenuSeparatorUI.java
new file mode 100644
index 0000000..24fe678
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaPopupMenuSeparatorUI.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicSeparatorUI;
+
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaPopupMenuSeparatorUI extends BasicSeparatorUI {
+    protected static RecyclableSingletonFromDefaultConstructor<AquaPopupMenuSeparatorUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaPopupMenuSeparatorUI>(AquaPopupMenuSeparatorUI.class);
+
+    public static ComponentUI createUI(final JComponent c) {
+        return instance.get();
+    }
+
+    public void update(final Graphics g, final JComponent c) {
+        paint(g, c);
+    }
+
+    public void paint(final Graphics g, final JComponent c) {
+        final Dimension s = c.getSize();
+
+        if (((JSeparator)c).getOrientation() == SwingConstants.VERTICAL) {
+            g.setColor(c.getForeground());
+            g.drawLine(5, 1, 5, s.height - 2);
+
+            g.setColor(c.getBackground());
+            g.drawLine(6, 1, 6, s.height - 2);
+        } else {
+            g.setColor(c.getForeground());
+            g.drawLine(1, 5, s.width - 2, 5);
+
+            g.setColor(c.getBackground());
+            g.drawLine(1, 6, s.width - 2, 6);
+        }
+    }
+
+    public Dimension getPreferredSize(final JComponent c) {
+        if (((JSeparator)c).getOrientation() == SwingConstants.VERTICAL) {
+            return new Dimension(12, 0);
+        }
+
+        return new Dimension(0, 12);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaPopupMenuUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaPopupMenuUI.java
new file mode 100644
index 0000000..8d78040
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaPopupMenuUI.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.MouseEvent;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicPopupMenuUI;
+
+public class AquaPopupMenuUI extends BasicPopupMenuUI {
+    public static ComponentUI createUI(final JComponent x) {
+        return new AquaPopupMenuUI();
+    }
+
+    public boolean isPopupTrigger(final MouseEvent e) {
+        // Use the awt popup trigger code since this only runs on our OS!
+        return e.isPopupTrigger();
+    }
+
+    @Override
+    public void paint(final Graphics g, final JComponent c) {
+        if (!(g instanceof Graphics2D)) {
+            super.paint(g, c);
+            return;
+        }
+
+        if (!(PopupFactory.getSharedInstance() instanceof ScreenPopupFactory)) {
+            super.paint(g, c);
+            return;
+        }
+
+        // round off and put back edges in a new Graphics
+        final Graphics2D g2d = (Graphics2D)g.create();
+        final Rectangle popupBounds = popupMenu.getBounds(); // NB: origin is still at 0,0
+        paintRoundRect(g2d, popupBounds);
+        clipEdges(g2d, popupBounds);
+        g2d.dispose();
+
+        // if any subsequent drawing occurs over these corners, the window is square again
+        super.paint(g, c);
+    }
+
+    protected void paintRoundRect(final Graphics2D g2d, final Rectangle popupBounds) {
+        // setup the graphics context to blast alpha for every primitive we draw
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setComposite(AlphaComposite.Clear);
+
+        // draw the 3px round-rect line around the outer bounds of the window,
+        // this gives the appearance of rounded corners
+        g2d.setStroke(new BasicStroke(3.0f));
+        g2d.drawRoundRect(-2, -2, popupBounds.width + 3, popupBounds.height + 3, 12, 12);
+    }
+
+    static final int OVERLAP_SLACK = 10;
+    protected void clipEdges(final Graphics2D g2d, final Rectangle popupBounds) {
+        final Component invoker = popupMenu.getInvoker();
+        if (!(invoker instanceof JMenu)) return; // only point corners originating from menu items
+
+        final Rectangle invokerBounds = invoker.getBounds();
+
+        // only get location on screen when necessary
+        invokerBounds.setLocation(invoker.getLocationOnScreen());
+        popupBounds.setLocation(popupMenu.getLocationOnScreen());
+
+        final Point invokerCenter = new Point((int)invokerBounds.getCenterX(), (int)invokerBounds.getCenterY());
+        if (popupBounds.contains(invokerCenter)) {
+            // invoker is "behind" the popup, no corners should be pointed
+            return;
+        }
+
+        // blast opaque background over the corners we want to "put back"
+        g2d.setComposite(AlphaComposite.SrcOver);
+        g2d.setColor(popupMenu.getBackground());
+
+        final Point popupCenter = new Point((int)popupBounds.getCenterX(), (int)popupBounds.getCenterY());
+        final boolean invokerMidpointAbovePopupMidpoint = invokerCenter.y <= popupCenter.y;
+
+        if (invokerBounds.x + invokerBounds.width < popupBounds.x + OVERLAP_SLACK) {
+            // popup is far right of invoker
+            if (invokerMidpointAbovePopupMidpoint) {
+                // point upper left corner, most common case
+                g2d.fillRect(-2, -2, 8, 8);
+                return;
+            }
+            // point lower left corner
+            g2d.fillRect(-2, popupBounds.height - 6, 8, 8);
+            return;
+        }
+
+        if (popupBounds.x + popupBounds.width < invokerBounds.x + OVERLAP_SLACK) {
+            // popup is far left of invoker
+            if (invokerMidpointAbovePopupMidpoint) {
+                // point upper right corner
+                g2d.fillRect(popupBounds.width - 6, -2, 8, 8);
+                return;
+            }
+            // point lower right corner
+            g2d.fillRect(popupBounds.width - 6, popupBounds.height - 6, 8, 8);
+            return;
+        }
+
+        // popup is neither "far right" or "far left" of it's invoker
+        if (invokerBounds.y + invokerBounds.height < popupBounds.y + OVERLAP_SLACK) {
+            // popup is "middle" below it's invoker,
+            // this is probably the "connected" case where both upper corners should touch
+            g2d.fillRect(-2, -2, popupBounds.width + 4, 8);
+            return;
+        }
+
+        // if none of these cases match...don't make any corners pointed
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaProgressBarUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaProgressBarUI.java
new file mode 100644
index 0000000..ce70ee4
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaProgressBarUI.java
@@ -0,0 +1,491 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.AffineTransform;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+
+import sun.swing.SwingUtilities2;
+
+import apple.laf.JRSUIStateFactory;
+import apple.laf.JRSUIConstants.*;
+import apple.laf.JRSUIState.ValueState;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaProgressBarUI extends ProgressBarUI implements ChangeListener, PropertyChangeListener, AncestorListener, Sizeable {
+    private static final boolean ADJUSTTIMER = true;
+
+    protected static final RecyclableSingleton<SizeDescriptor> sizeDescriptor = new RecyclableSingleton<SizeDescriptor>() {
+        @Override
+        protected SizeDescriptor getInstance() {
+            return new SizeDescriptor(new SizeVariant(146, 20)) {
+                public SizeVariant deriveSmall(final SizeVariant v) { v.alterMinSize(0, -6); return super.deriveSmall(v); }
+            };
+        }
+    };
+    static SizeDescriptor getSizeDescriptor() {
+        return sizeDescriptor.get();
+    }
+
+    protected Size sizeVariant = Size.REGULAR;
+
+    protected Color selectionForeground;
+
+    private Animator animator;
+    protected boolean isAnimating;
+    protected boolean isCircular;
+
+    protected final AquaPainter<ValueState> painter = AquaPainter.create(JRSUIStateFactory.getProgressBar());
+
+    protected JProgressBar progressBar;
+
+    public static ComponentUI createUI(final JComponent x) {
+        return new AquaProgressBarUI();
+    }
+
+    protected AquaProgressBarUI() { }
+
+    public void installUI(final JComponent c) {
+        progressBar = (JProgressBar)c;
+        installDefaults();
+        installListeners();
+    }
+
+    public void uninstallUI(final JComponent c) {
+        uninstallDefaults();
+        uninstallListeners();
+        stopAnimationTimer();
+        progressBar = null;
+    }
+
+    protected void installDefaults() {
+        progressBar.setOpaque(false);
+        LookAndFeel.installBorder(progressBar, "ProgressBar.border");
+        LookAndFeel.installColorsAndFont(progressBar, "ProgressBar.background", "ProgressBar.foreground", "ProgressBar.font");
+        selectionForeground = UIManager.getColor("ProgressBar.selectionForeground");
+    }
+
+    protected void uninstallDefaults() {
+        LookAndFeel.uninstallBorder(progressBar);
+    }
+
+    protected void installListeners() {
+        progressBar.addChangeListener(this); // Listen for changes in the progress bar's data
+        progressBar.addPropertyChangeListener(this); // Listen for changes between determinate and indeterminate state
+        progressBar.addAncestorListener(this);
+        AquaUtilControlSize.addSizePropertyListener(progressBar);
+    }
+
+    protected void uninstallListeners() {
+        AquaUtilControlSize.removeSizePropertyListener(progressBar);
+        progressBar.removeAncestorListener(this);
+        progressBar.removePropertyChangeListener(this);
+        progressBar.removeChangeListener(this);
+    }
+
+    public void stateChanged(final ChangeEvent e) {
+        progressBar.repaint();
+    }
+
+    public void propertyChange(final PropertyChangeEvent e) {
+        final String prop = e.getPropertyName();
+        if ("indeterminate".equals(prop)) {
+            if (!progressBar.isIndeterminate()) return;
+            stopAnimationTimer();
+            // start the animation thread
+            startAnimationTimer();
+        }
+
+        if ("JProgressBar.style".equals(prop)) {
+            isCircular = "circular".equalsIgnoreCase(e.getNewValue() + "");
+            progressBar.repaint();
+        }
+    }
+
+    // listen for Ancestor events to stop our timer when we are no longer visible
+    // <rdar://problem/5405035> JProgressBar: UI in Aqua look and feel causes memory leaks
+    public void ancestorRemoved(final AncestorEvent e) {
+        stopAnimationTimer();
+    }
+
+    public void ancestorAdded(final AncestorEvent e) {
+        if (!progressBar.isIndeterminate()) return;
+        startAnimationTimer();
+    }
+
+    public void ancestorMoved(final AncestorEvent e) { }
+
+    public void paint(final Graphics g, final JComponent c) {
+        revalidateAnimationTimers(); // revalidate to turn on/off timers when values change
+
+        painter.state.set(getState(c));
+        painter.state.set(isHorizontal() ? Orientation.HORIZONTAL : Orientation.VERTICAL);
+        painter.state.set(isAnimating ? Animating.YES : Animating.NO);
+
+        if (progressBar.isIndeterminate()) {
+            if (isCircular) {
+                painter.state.set(Widget.PROGRESS_SPINNER);
+                painter.paint(g, c, 2, 2, 16, 16);
+                return;
+            }
+
+            painter.state.set(Widget.PROGRESS_INDETERMINATE_BAR);
+            paint(g);
+            return;
+        }
+
+        painter.state.set(Widget.PROGRESS_BAR);
+        painter.state.setValue(checkValue(progressBar.getPercentComplete()));
+        paint(g);
+    }
+
+    static double checkValue(final double value) {
+        return Double.isNaN(value) ? 0 : value;
+    }
+
+    protected void paint(final Graphics g) {
+        // this is questionable. We may want the insets to mean something different.
+        final Insets i = progressBar.getInsets();
+        final int width = progressBar.getWidth() - (i.right + i.left);
+        final int height = progressBar.getHeight() - (i.bottom + i.top);
+
+        painter.paint(g, progressBar, i.left, i.top, width, height);
+
+        if (progressBar.isStringPainted() && !progressBar.isIndeterminate()) {
+            paintString(g, i.left, i.top, width, height);
+        }
+    }
+
+    protected State getState(final JComponent c) {
+        if (!c.isEnabled()) return State.INACTIVE;
+        if (!AquaFocusHandler.isActive(c)) return State.INACTIVE;
+        return State.ACTIVE;
+    }
+
+    protected void paintString(final Graphics g, final int x, final int y, final int width, final int height) {
+        if (!(g instanceof Graphics2D)) return;
+
+        final Graphics2D g2 = (Graphics2D)g;
+        final String progressString = progressBar.getString();
+        g2.setFont(progressBar.getFont());
+        final Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
+        final Rectangle oldClip = g2.getClipBounds();
+
+        if (isHorizontal()) {
+            g2.setColor(selectionForeground);
+            SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y);
+        } else { // VERTICAL
+            // We rotate it -90 degrees, then translate it down since we are going to be bottom up.
+            final AffineTransform savedAT = g2.getTransform();
+            g2.transform(AffineTransform.getRotateInstance(0.0f - (Math.PI / 2.0f), 0, 0));
+            g2.translate(-progressBar.getHeight(), 0);
+
+            // 0,0 is now the bottom left of the viewable area, so we just draw our image at
+            // the render location since that calculation knows about rotation.
+            g2.setColor(selectionForeground);
+            SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y);
+
+            g2.setTransform(savedAT);
+        }
+
+        g2.setClip(oldClip);
+    }
+
+    /**
+     * Designate the place where the progress string will be painted. This implementation places it at the center of the
+     * progress bar (in both x and y). Override this if you want to right, left, top, or bottom align the progress
+     * string or if you need to nudge it around for any reason.
+     */
+    protected Point getStringPlacement(final Graphics g, final String progressString, int x, int y, int width, int height) {
+        final FontMetrics fontSizer = progressBar.getFontMetrics(progressBar.getFont());
+        final int stringWidth = fontSizer.stringWidth(progressString);
+
+        if (!isHorizontal()) {
+            // Calculate the location for the rotated text in real component coordinates.
+            // swapping x & y and width & height
+            final int oldH = height;
+            height = width;
+            width = oldH;
+
+            final int oldX = x;
+            x = y;
+            y = oldX;
+        }
+
+        return new Point(x + Math.round(width / 2 - stringWidth / 2), y + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2) - 1);
+    }
+
+    static Dimension getCircularPreferredSize() {
+        return new Dimension(20, 20);
+    }
+
+    public Dimension getPreferredSize(final JComponent c) {
+        if (isCircular) {
+            return getCircularPreferredSize();
+        }
+
+        final FontMetrics metrics = progressBar.getFontMetrics(progressBar.getFont());
+
+        final Dimension size = isHorizontal() ? getPreferredHorizontalSize(metrics) : getPreferredVerticalSize(metrics);
+        final Insets insets = progressBar.getInsets();
+
+        size.width += insets.left + insets.right;
+        size.height += insets.top + insets.bottom;
+        return size;
+    }
+
+    protected Dimension getPreferredHorizontalSize(final FontMetrics metrics) {
+        final SizeVariant variant = getSizeDescriptor().get(sizeVariant);
+        final Dimension size = new Dimension(variant.w, variant.h);
+        if (!progressBar.isStringPainted()) return size;
+
+        // Ensure that the progress string will fit
+        final String progString = progressBar.getString();
+        final int stringWidth = metrics.stringWidth(progString);
+        if (stringWidth > size.width) {
+            size.width = stringWidth;
+        }
+
+        // This uses both Height and Descent to be sure that
+        // there is more than enough room in the progress bar
+        // for everything.
+        // This does have a strange dependency on
+        // getStringPlacememnt() in a funny way.
+        final int stringHeight = metrics.getHeight() + metrics.getDescent();
+        if (stringHeight > size.height) {
+            size.height = stringHeight;
+        }
+        return size;
+    }
+
+    protected Dimension getPreferredVerticalSize(final FontMetrics metrics) {
+        final SizeVariant variant = getSizeDescriptor().get(sizeVariant);
+        final Dimension size = new Dimension(variant.h, variant.w);
+        if (!progressBar.isStringPainted()) return size;
+
+        // Ensure that the progress string will fit.
+        final String progString = progressBar.getString();
+        final int stringHeight = metrics.getHeight() + metrics.getDescent();
+        if (stringHeight > size.width) {
+            size.width = stringHeight;
+        }
+
+        // This is also for completeness.
+        final int stringWidth = metrics.stringWidth(progString);
+        if (stringWidth > size.height) {
+            size.height = stringWidth;
+        }
+        return size;
+    }
+
+    public Dimension getMinimumSize(final JComponent c) {
+        if (isCircular) {
+            return getCircularPreferredSize();
+        }
+
+        final Dimension pref = getPreferredSize(progressBar);
+
+        // The Minimum size for this component is 10.
+        // The rationale here is that there should be at least one pixel per 10 percent.
+        if (isHorizontal()) {
+            pref.width = 10;
+        } else {
+            pref.height = 10;
+        }
+
+        return pref;
+    }
+
+    public Dimension getMaximumSize(final JComponent c) {
+        if (isCircular) {
+            return getCircularPreferredSize();
+        }
+
+        final Dimension pref = getPreferredSize(progressBar);
+
+        if (isHorizontal()) {
+            pref.width = Short.MAX_VALUE;
+        } else {
+            pref.height = Short.MAX_VALUE;
+        }
+
+        return pref;
+    }
+
+    public void applySizeFor(final JComponent c, final Size size) {
+        painter.state.set(sizeVariant = size == Size.MINI ? Size.SMALL : sizeVariant); // CUI doesn't support mini progress bars right now
+    }
+
+    protected void startAnimationTimer() {
+        if (animator == null) animator = new Animator();
+        animator.start();
+        isAnimating = true;
+    }
+
+    protected void stopAnimationTimer() {
+        if (animator != null) animator.stop();
+        isAnimating = false;
+    }
+
+    private final Rectangle fUpdateArea = new Rectangle(0, 0, 0, 0);
+    private final Dimension fLastSize = new Dimension(0, 0);
+    protected Rectangle getRepaintRect() {
+        int height = progressBar.getHeight();
+        int width = progressBar.getWidth();
+
+        if (isCircular) {
+            return new Rectangle(20, 20);
+        }
+
+        if (fLastSize.height == height && fLastSize.width == width) {
+            return fUpdateArea;
+        }
+
+        int x = 0;
+        int y = 0;
+        fLastSize.height = height;
+        fLastSize.width = width;
+
+        final int maxHeight = getMaxProgressBarHeight();
+
+        if (isHorizontal()) {
+            final int excessHeight = height - maxHeight;
+            y += excessHeight / 2;
+            height = maxHeight;
+        } else {
+            final int excessHeight = width - maxHeight;
+            x += excessHeight / 2;
+            width = maxHeight;
+        }
+
+        fUpdateArea.setBounds(x, y, width, height);
+
+        return fUpdateArea;
+    }
+
+    protected int getMaxProgressBarHeight() {
+        return getSizeDescriptor().get(sizeVariant).h;
+    }
+
+    protected boolean isHorizontal() {
+        return progressBar.getOrientation() == SwingConstants.HORIZONTAL;
+    }
+
+    protected void revalidateAnimationTimers() {
+        if (progressBar.isIndeterminate()) return;
+
+        if (!isAnimating) {
+            startAnimationTimer(); // only starts if supposed to!
+            return;
+        }
+
+        final BoundedRangeModel model = progressBar.getModel();
+        final double currentValue = model.getValue();
+        if ((currentValue == model.getMaximum()) || (currentValue == model.getMinimum())) {
+            stopAnimationTimer();
+        }
+    }
+
+    protected void repaint() {
+        final Rectangle repaintRect = getRepaintRect();
+        if (repaintRect == null) {
+            progressBar.repaint();
+            return;
+        }
+
+        progressBar.repaint(repaintRect);
+    }
+
+    protected class Animator implements ActionListener {
+        private static final int MINIMUM_DELAY = 5;
+        private Timer timer;
+        private long previousDelay; // used to tune the repaint interval
+        private long lastCall; // the last time actionPerformed was called
+        private int repaintInterval;
+
+        public Animator() {
+            repaintInterval = UIManager.getInt("ProgressBar.repaintInterval");
+
+            // Make sure repaintInterval is reasonable.
+            if (repaintInterval <= 0) repaintInterval = 100;
+        }
+
+        protected void start() {
+            previousDelay = repaintInterval;
+            lastCall = 0;
+
+            if (timer == null) {
+                timer = new Timer(repaintInterval, this);
+            } else {
+                timer.setDelay(repaintInterval);
+            }
+
+            if (ADJUSTTIMER) {
+                timer.setRepeats(false);
+                timer.setCoalesce(false);
+            }
+
+            timer.start();
+        }
+
+        protected void stop() {
+            timer.stop();
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            if (!ADJUSTTIMER) {
+                repaint();
+                return;
+            }
+
+            final long time = System.currentTimeMillis();
+
+            if (lastCall > 0) {
+                // adjust nextDelay
+                int nextDelay = (int)(previousDelay - time + lastCall + repaintInterval);
+                if (nextDelay < MINIMUM_DELAY) {
+                    nextDelay = MINIMUM_DELAY;
+                }
+
+                timer.setInitialDelay(nextDelay);
+                previousDelay = nextDelay;
+            }
+
+            timer.start();
+            lastCall = time;
+
+            repaint();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaRootPaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaRootPaneUI.java
new file mode 100644
index 0000000..e727712
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaRootPaneUI.java
@@ -0,0 +1,322 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.PropertyChangeEvent;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicRootPaneUI;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+/**
+ * From AquaRootPaneUI.java
+ *
+ * The JRootPane manages the default button.  There can be only one active rootpane,
+ * and one default button, so we need only one timer
+ *
+ * AquaRootPaneUI is a singleton object
+ */
+public class AquaRootPaneUI extends BasicRootPaneUI implements AncestorListener, WindowListener, ContainerListener {
+    private static final RecyclableSingleton<AquaRootPaneUI> sRootPaneUI = new RecyclableSingletonFromDefaultConstructor<AquaRootPaneUI>(AquaRootPaneUI.class);
+
+    final static int kDefaultButtonPaintDelayBetweenFrames = 50;
+    JButton fCurrentDefaultButton = null;
+    Timer fTimer = null;
+    static final boolean sUseScreenMenuBar = AquaMenuBarUI.getScreenMenuBarProperty();
+
+    public static ComponentUI createUI(final JComponent c) {
+        return sRootPaneUI.get();
+    }
+
+    public void installUI(final JComponent c) {
+        super.installUI(c);
+        c.addAncestorListener(this);
+
+        if (c.isShowing() && c.isEnabled()) {
+            updateDefaultButton((JRootPane)c);
+        }
+
+        // for <rdar://problem/3689020> REGR: Realtime LAF updates no longer work
+        //
+        // because the JFrame parent has a LAF background set (why without a UI element I don't know!)
+        // we have to set it from the root pane so when we are coming from metal we will set it to
+        // the aqua color.
+        // This is because the aqua color is a magical color that gets the background of the window,
+        // so for most other LAFs the root pane changing is enough since it would be opaque, but for us
+        // it is not since we are going to grab the one that was set on the JFrame. :(
+        final Component parent = c.getParent();
+
+        if (parent != null && parent instanceof JFrame) {
+            final JFrame frameParent = (JFrame)parent;
+            final Color bg = frameParent.getBackground();
+            if (bg == null || bg instanceof UIResource) {
+                frameParent.setBackground(UIManager.getColor("Panel.background"));
+            }
+        }
+
+        // for <rdar://problem/3750909> OutOfMemoryError swapping menus.
+        // Listen for layered pane/JMenuBar updates if the screen menu bar is active.
+        if (sUseScreenMenuBar) {
+            final JRootPane root = (JRootPane)c;
+            root.addContainerListener(this);
+            root.getLayeredPane().addContainerListener(this);
+        }
+    }
+
+    public void uninstallUI(final JComponent c) {
+        stopTimer();
+        c.removeAncestorListener(this);
+
+        if (sUseScreenMenuBar) {
+            final JRootPane root = (JRootPane)c;
+            root.removeContainerListener(this);
+            root.getLayeredPane().removeContainerListener(this);
+        }
+
+        super.uninstallUI(c);
+    }
+
+    /**
+     * If the screen menu bar is active we need to listen to the layered pane of the root pane
+     * because it holds the JMenuBar.  So, if a new layered pane was added, listen to it.
+     * If a new JMenuBar was added, tell the menu bar UI, because it will need to update the menu bar.
+     */
+    public void componentAdded(final ContainerEvent e) {
+        if (e.getContainer() instanceof JRootPane) {
+            final JRootPane root = (JRootPane)e.getContainer();
+            if (e.getChild() == root.getLayeredPane()) {
+                final JLayeredPane layered = root.getLayeredPane();
+                layered.addContainerListener(this);
+            }
+        } else {
+            if (e.getChild() instanceof JMenuBar) {
+                final JMenuBar jmb = (JMenuBar)e.getChild();
+                final MenuBarUI mbui = jmb.getUI();
+
+                if (mbui instanceof AquaMenuBarUI) {
+                    final Window owningWindow = SwingUtilities.getWindowAncestor(jmb);
+
+                    // Could be a JDialog, and may have been added to a JRootPane not yet in a window.
+                    if (owningWindow != null && owningWindow instanceof JFrame) {
+                        ((AquaMenuBarUI)mbui).setScreenMenuBar((JFrame)owningWindow);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Likewise, when the layered pane is removed from the root pane, stop listening to it.
+     * If the JMenuBar is removed, tell the menu bar UI to clear the menu bar.
+     */
+    public void componentRemoved(final ContainerEvent e) {
+        if (e.getContainer() instanceof JRootPane) {
+            final JRootPane root = (JRootPane)e.getContainer();
+            if (e.getChild() == root.getLayeredPane()) {
+                final JLayeredPane layered = root.getLayeredPane();
+                layered.removeContainerListener(this);
+            }
+        } else {
+            if (e.getChild() instanceof JMenuBar) {
+                final JMenuBar jmb = (JMenuBar)e.getChild();
+                final MenuBarUI mbui = jmb.getUI();
+
+                if (mbui instanceof AquaMenuBarUI) {
+                    final Window owningWindow = SwingUtilities.getWindowAncestor(jmb);
+
+                    // Could be a JDialog, and may have been added to a JRootPane not yet in a window.
+                    if (owningWindow != null && owningWindow instanceof JFrame) {
+                        ((AquaMenuBarUI)mbui).clearScreenMenuBar((JFrame)owningWindow);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Invoked when a property changes on the root pane. If the event
+     * indicates the <code>defaultButton</code> has changed, this will
+     * update the animation.
+     * If the enabled state changed, it will start or stop the animation
+     */
+    public void propertyChange(final PropertyChangeEvent e) {
+        super.propertyChange(e);
+
+        final String prop = e.getPropertyName();
+        if ("defaultButton".equals(prop) || "temporaryDefaultButton".equals(prop)) {
+            // Change the animating button if this root is showing and enabled
+            // otherwise do nothing - someone else may be active
+            final JRootPane root = (JRootPane)e.getSource();
+
+            if (root.isShowing() && root.isEnabled()) {
+                updateDefaultButton(root);
+            }
+        } else if ("enabled".equals(prop) || AquaFocusHandler.FRAME_ACTIVE_PROPERTY.equals(prop)) {
+            final JRootPane root = (JRootPane)e.getSource();
+            if (root.isShowing()) {
+                if (((Boolean)e.getNewValue()).booleanValue()) {
+                    updateDefaultButton((JRootPane)e.getSource());
+                } else {
+                    stopTimer();
+                }
+            }
+        }
+    }
+
+    synchronized void stopTimer() {
+        if (fTimer != null) {
+            fTimer.stop();
+            fTimer = null;
+        }
+    }
+
+    synchronized void updateDefaultButton(final JRootPane root) {
+        final JButton button = root.getDefaultButton();
+        //System.err.println("in updateDefaultButton button = " + button);
+        fCurrentDefaultButton = button;
+        stopTimer();
+        if (button != null) {
+            fTimer = new Timer(kDefaultButtonPaintDelayBetweenFrames, new DefaultButtonPainter(root));
+            fTimer.start();
+        }
+    }
+
+    class DefaultButtonPainter implements ActionListener {
+        JRootPane root;
+
+        public DefaultButtonPainter(final JRootPane root) {
+            this.root = root;
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            final JButton defaultButton = root.getDefaultButton();
+            if ((defaultButton != null) && defaultButton.isShowing()) {
+                if (defaultButton.isEnabled()) {
+                    defaultButton.repaint();
+                }
+            } else {
+                stopTimer();
+            }
+        }
+    }
+
+    /**
+     * This is sort of like viewDidMoveToWindow:.  When the root pane is put into a window
+     * this method gets called for the notification.
+     * We need to set up the listener relationship so we can pick up activation events.
+     * And, if a JMenuBar was added before the root pane was added to the window, we now need
+     * to notify the menu bar UI.
+     */
+    public void ancestorAdded(final AncestorEvent event) {
+        // this is so we can handle window activated and deactivated events so
+        // our swing controls can color/enable/disable/focus draw correctly
+        final Container ancestor = event.getComponent();
+        final Window owningWindow = SwingUtilities.getWindowAncestor(ancestor);
+
+        if (owningWindow != null) {
+            // We get this message even when a dialog is opened and the owning window is a window
+            // that could already be listened to. We should only be a listener once.
+            // adding multiple listeners was the cause of <rdar://problem/3534047>
+            // but the incorrect removal of them caused <rdar://problem/3617848>
+            owningWindow.removeWindowListener(this);
+            owningWindow.addWindowListener(this);
+        }
+
+        // The root pane has been added to the hierarchy.  If it's enabled update the default
+        // button to start the throbbing.  Since the UI is a singleton make sure the root pane
+        // we are checking has a default button before calling update otherwise we will stop
+        // throbbing the current default button.
+        final JComponent comp = event.getComponent();
+        if (comp instanceof JRootPane) {
+            final JRootPane rp = (JRootPane)comp;
+            if (rp.isEnabled() && rp.getDefaultButton() != null) {
+                updateDefaultButton((JRootPane)comp);
+            }
+        }
+    }
+
+    /**
+     * If the JRootPane was removed from the window we should clear the screen menu bar.
+     * That's a non-trivial problem, because you need to know which window the JRootPane was in
+     * before it was removed.  By the time ancestorRemoved was called, the JRootPane has already been removed
+     */
+
+    public void ancestorRemoved(final AncestorEvent event) { }
+    public void ancestorMoved(final AncestorEvent event) { }
+
+    public void windowActivated(final WindowEvent e) {
+        updateComponentTreeUIActivation((Component)e.getSource(), Boolean.TRUE);
+    }
+
+    public void windowDeactivated(final WindowEvent e) {
+        updateComponentTreeUIActivation((Component)e.getSource(), Boolean.FALSE);
+    }
+
+    public void windowOpened(final WindowEvent e) { }
+    public void windowClosing(final WindowEvent e) { }
+
+    public void windowClosed(final WindowEvent e) {
+        // We know the window is closed so remove the listener.
+        final Window w = e.getWindow();
+        w.removeWindowListener(this);
+    }
+
+    public void windowIconified(final WindowEvent e) { }
+    public void windowDeiconified(final WindowEvent e) { }
+    public void windowStateChanged(final WindowEvent e) { }
+    public void windowGainedFocus(final WindowEvent e) { }
+    public void windowLostFocus(final WindowEvent e) { }
+
+    private static void updateComponentTreeUIActivation(final Component c, Object active) {
+        if (c instanceof javax.swing.JInternalFrame) {
+            active = (((JInternalFrame)c).isSelected() ? Boolean.TRUE : Boolean.FALSE);
+        }
+
+        if (c instanceof javax.swing.JComponent) {
+            ((javax.swing.JComponent)c).putClientProperty(AquaFocusHandler.FRAME_ACTIVE_PROPERTY, active);
+        }
+
+        Component[] children = null;
+
+        if (c instanceof javax.swing.JMenu) {
+            children = ((javax.swing.JMenu)c).getMenuComponents();
+        } else if (c instanceof Container) {
+            children = ((Container)c).getComponents();
+        }
+
+        if (children == null) return;
+
+        for (final Component element : children) {
+            updateComponentTreeUIActivation(element, active);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaScrollBarUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaScrollBarUI.java
new file mode 100644
index 0000000..f141bbc
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaScrollBarUI.java
@@ -0,0 +1,665 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.Timer;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+import apple.laf.JRSUIState.ScrollBarState;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaScrollBarUI extends ScrollBarUI {
+    private static final int kInitialDelay = 300;
+    private static final int kNormalDelay = 100;
+
+    // when we make small and mini scrollbars, this will no longer be a constant
+    static final int MIN_ARROW_COLLAPSE_SIZE = 64;
+
+    // tracking state
+    protected boolean fIsDragging;
+    protected Timer fScrollTimer;
+    protected ScrollListener fScrollListener;
+    protected TrackListener fTrackListener;
+    protected Hit fTrackHighlight = Hit.NONE;
+    protected Hit fMousePart = Hit.NONE; // Which arrow (if any) we moused pressed down in (used by arrow drag tracking)
+
+    protected JScrollBar fScrollBar;
+    protected ModelListener fModelListener;
+    protected PropertyChangeListener fPropertyChangeListener;
+
+    protected final AquaPainter<ScrollBarState> painter = AquaPainter.create(JRSUIStateFactory.getScrollBar());
+
+    // Create PLAF
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaScrollBarUI();
+    }
+
+    public AquaScrollBarUI() { }
+
+    public void installUI(final JComponent c) {
+        fScrollBar = (JScrollBar)c;
+        installListeners();
+        configureScrollBarColors();
+    }
+
+    public void uninstallUI(final JComponent c) {
+        uninstallListeners();
+        fScrollBar = null;
+    }
+
+    protected void configureScrollBarColors() {
+        LookAndFeel.installColors(fScrollBar, "ScrollBar.background", "ScrollBar.foreground");
+    }
+
+    protected TrackListener createTrackListener() {
+        return new TrackListener();
+    }
+
+    protected ScrollListener createScrollListener() {
+        return new ScrollListener();
+    }
+
+    protected void installListeners() {
+        fTrackListener = createTrackListener();
+        fModelListener = createModelListener();
+        fPropertyChangeListener = createPropertyChangeListener();
+        fScrollBar.addMouseListener(fTrackListener);
+        fScrollBar.addMouseMotionListener(fTrackListener);
+        fScrollBar.getModel().addChangeListener(fModelListener);
+        fScrollBar.addPropertyChangeListener(fPropertyChangeListener);
+        fScrollListener = createScrollListener();
+        fScrollTimer = new Timer(kNormalDelay, fScrollListener);
+        fScrollTimer.setInitialDelay(kInitialDelay); // default InitialDelay?
+    }
+
+    protected void uninstallListeners() {
+        fScrollTimer.stop();
+        fScrollTimer = null;
+        fScrollBar.getModel().removeChangeListener(fModelListener);
+        fScrollBar.removeMouseListener(fTrackListener);
+        fScrollBar.removeMouseMotionListener(fTrackListener);
+        fScrollBar.removePropertyChangeListener(fPropertyChangeListener);
+    }
+
+    protected PropertyChangeListener createPropertyChangeListener() {
+        return new PropertyChangeHandler();
+    }
+
+    protected ModelListener createModelListener() {
+        return new ModelListener();
+    }
+
+    protected void syncState(final JComponent c) {
+        final ScrollBarState scrollBarState = painter.state;
+        scrollBarState.set(isHorizontal() ? Orientation.HORIZONTAL : Orientation.VERTICAL);
+
+        final float trackExtent = fScrollBar.getMaximum() - fScrollBar.getMinimum() - fScrollBar.getModel().getExtent();
+        if (trackExtent <= 0.0f) {
+            scrollBarState.set(NothingToScroll.YES);
+            return;
+        }
+
+        final ScrollBarPart pressedPart = getPressedPart();
+        scrollBarState.set(pressedPart);
+        scrollBarState.set(getState(c, pressedPart));
+        scrollBarState.set(NothingToScroll.NO);
+        scrollBarState.setValue((fScrollBar.getValue() - fScrollBar.getMinimum()) / trackExtent);
+        scrollBarState.setThumbStart(getThumbStart());
+        scrollBarState.setThumbPercent(getThumbPercent());
+        scrollBarState.set(shouldShowArrows() ? ShowArrows.YES : ShowArrows.NO);
+    }
+
+    public void paint(final Graphics g, final JComponent c) {
+        syncState(c);
+        painter.paint(g, c, 0, 0, fScrollBar.getWidth(), fScrollBar.getHeight());
+    }
+
+    protected State getState(final JComponent c, final ScrollBarPart pressedPart) {
+        if (!AquaFocusHandler.isActive(c)) return State.INACTIVE;
+        if (!c.isEnabled()) return State.INACTIVE;
+        if (pressedPart != ScrollBarPart.NONE) return State.PRESSED;
+        return State.ACTIVE;
+    }
+
+    static final RecyclableSingleton<Map<Hit, ScrollBarPart>> hitToPressedPartMap = new RecyclableSingleton<Map<Hit,ScrollBarPart>>(){
+        @Override
+        protected Map<Hit, ScrollBarPart> getInstance() {
+            final Map<Hit, ScrollBarPart> map = new HashMap<Hit, ScrollBarPart>(7);
+            map.put(ScrollBarHit.ARROW_MAX, ScrollBarPart.ARROW_MAX);
+            map.put(ScrollBarHit.ARROW_MIN, ScrollBarPart.ARROW_MIN);
+            map.put(ScrollBarHit.ARROW_MAX_INSIDE, ScrollBarPart.ARROW_MAX_INSIDE);
+            map.put(ScrollBarHit.ARROW_MIN_INSIDE, ScrollBarPart.ARROW_MIN_INSIDE);
+            map.put(ScrollBarHit.TRACK_MAX, ScrollBarPart.TRACK_MAX);
+            map.put(ScrollBarHit.TRACK_MIN, ScrollBarPart.TRACK_MIN);
+            map.put(ScrollBarHit.THUMB, ScrollBarPart.THUMB);
+            return map;
+        }
+    };
+    protected ScrollBarPart getPressedPart() {
+        if (!fTrackListener.fInArrows || !fTrackListener.fStillInArrow) return ScrollBarPart.NONE;
+        final ScrollBarPart pressedPart = hitToPressedPartMap.get().get(fMousePart);
+        if (pressedPart == null) return ScrollBarPart.NONE;
+        return pressedPart;
+    }
+
+    protected boolean shouldShowArrows() {
+        return MIN_ARROW_COLLAPSE_SIZE < (isHorizontal() ? fScrollBar.getWidth() : fScrollBar.getHeight());
+    }
+
+    // Layout Methods
+    // Layout is controlled by the user in the Appearance Control Panel
+    // Theme will redraw correctly for the current layout
+    public void layoutContainer(final Container fScrollBarContainer) {
+        fScrollBar.repaint();
+        fScrollBar.revalidate();
+    }
+
+    protected Rectangle getTrackBounds() {
+        return new Rectangle(0, 0, fScrollBar.getWidth(), fScrollBar.getHeight());
+    }
+
+    protected Rectangle getDragBounds() {
+        return new Rectangle(0, 0, fScrollBar.getWidth(), fScrollBar.getHeight());
+    }
+
+    protected void startTimer(final boolean initial) {
+        fScrollTimer.setInitialDelay(initial ? kInitialDelay : kNormalDelay); // default InitialDelay?
+        fScrollTimer.start();
+    }
+
+    protected void scrollByBlock(final int direction) {
+        synchronized(fScrollBar) {
+            final int oldValue = fScrollBar.getValue();
+            final int blockIncrement = fScrollBar.getBlockIncrement(direction);
+            final int delta = blockIncrement * ((direction > 0) ? +1 : -1);
+
+            fScrollBar.setValue(oldValue + delta);
+            fTrackHighlight = direction > 0 ? ScrollBarHit.TRACK_MAX : ScrollBarHit.TRACK_MIN;
+            fScrollBar.repaint();
+            fScrollListener.setDirection(direction);
+            fScrollListener.setScrollByBlock(true);
+        }
+    }
+
+    protected void scrollByUnit(final int direction) {
+        synchronized(fScrollBar) {
+            int delta = fScrollBar.getUnitIncrement(direction);
+            if (direction <= 0) delta = -delta;
+
+            fScrollBar.setValue(delta + fScrollBar.getValue());
+            fScrollBar.repaint();
+            fScrollListener.setDirection(direction);
+            fScrollListener.setScrollByBlock(false);
+        }
+    }
+
+    protected Hit getPartHit(final int x, final int y) {
+        syncState(fScrollBar);
+        return JRSUIUtils.HitDetection.getHitForPoint(painter.getControl(), 0, 0, fScrollBar.getWidth(), fScrollBar.getHeight(), x, y);
+    }
+
+    protected class PropertyChangeHandler implements PropertyChangeListener {
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String propertyName = e.getPropertyName();
+
+            if ("model".equals(propertyName)) {
+                final BoundedRangeModel oldModel = (BoundedRangeModel)e.getOldValue();
+                final BoundedRangeModel newModel = (BoundedRangeModel)e.getNewValue();
+                oldModel.removeChangeListener(fModelListener);
+                newModel.addChangeListener(fModelListener);
+                fScrollBar.repaint();
+                fScrollBar.revalidate();
+            } else if (AquaFocusHandler.FRAME_ACTIVE_PROPERTY.equals(propertyName)) {
+                fScrollBar.repaint();
+            }
+        }
+    }
+
+    protected class ModelListener implements ChangeListener {
+        public void stateChanged(final ChangeEvent e) {
+            layoutContainer(fScrollBar);
+        }
+    }
+
+    // Track mouse drags.
+    protected class TrackListener extends MouseAdapter implements MouseMotionListener {
+        protected transient int fCurrentMouseX, fCurrentMouseY;
+        protected transient boolean fInArrows; // are we currently tracking arrows?
+        protected transient boolean fStillInArrow = false; // Whether mouse is in an arrow during arrow tracking
+        protected transient boolean fStillInTrack = false; // Whether mouse is in the track during pageup/down tracking
+        protected transient int fFirstMouseX, fFirstMouseY, fFirstValue; // Values for getValueFromOffset
+
+        public void mouseReleased(final MouseEvent e) {
+            if (!fScrollBar.isEnabled()) return;
+            if (fInArrows) {
+                mouseReleasedInArrows(e);
+            } else {
+                mouseReleasedInTrack(e);
+            }
+
+            fInArrows = false;
+            fStillInArrow = false;
+            fStillInTrack = false;
+
+            fScrollBar.repaint();
+            fScrollBar.revalidate();
+        }
+
+        public void mousePressed(final MouseEvent e) {
+            if (!fScrollBar.isEnabled()) return;
+
+            final Hit part = getPartHit(e.getX(), e.getY());
+            fInArrows = HitUtil.isArrow(part);
+            if (fInArrows) {
+                mousePressedInArrows(e, part);
+            } else {
+                if (part == Hit.NONE) {
+                    fTrackHighlight = Hit.NONE;
+                } else {
+                    mousePressedInTrack(e, part);
+                }
+            }
+        }
+
+        public void mouseDragged(final MouseEvent e) {
+            if (!fScrollBar.isEnabled()) return;
+
+            if (fInArrows) {
+                mouseDraggedInArrows(e);
+            } else if (fIsDragging) {
+                mouseDraggedInTrack(e);
+            } else {
+                // In pageup/down zones
+
+                // check that thumb has not been scrolled under the mouse cursor
+                final Hit previousPart = getPartHit(fCurrentMouseX, fCurrentMouseY);
+                if (!HitUtil.isTrack(previousPart)) {
+                    fStillInTrack = false;
+                }
+
+                fCurrentMouseX = e.getX();
+                fCurrentMouseY = e.getY();
+
+                final Hit part = getPartHit(e.getX(), e.getY());
+                final boolean temp = HitUtil.isTrack(part);
+                if (temp == fStillInTrack) return;
+
+                fStillInTrack = temp;
+                if (!fStillInTrack) {
+                    fScrollTimer.stop();
+                } else {
+                    fScrollListener.actionPerformed(new ActionEvent(fScrollTimer, 0, ""));
+                    startTimer(false);
+                }
+            }
+        }
+
+        int getValueFromOffset(final int xOffset, final int yOffset, final int firstValue) {
+            final boolean isHoriz = isHorizontal();
+
+            // find the amount of pixels we've moved x & y (we only care about one)
+            final int offsetWeCareAbout = isHoriz ? xOffset : yOffset;
+
+            // now based on that floating point percentage compute the real scroller value.
+            final int visibleAmt = fScrollBar.getVisibleAmount();
+            final int max = fScrollBar.getMaximum();
+            final int min = fScrollBar.getMinimum();
+            final int extent = max - min;
+
+            // ask native to tell us what the new float that is a ratio of how much scrollable area
+            // we have moved (not the thumb area, just the scrollable). If the
+            // scroller goes 0-100 with a visible area of 20 we are getting a ratio of the
+            // remaining 80.
+            syncState(fScrollBar);
+            final double offsetChange = JRSUIUtils.ScrollBar.getNativeOffsetChange(painter.getControl(), 0, 0, fScrollBar.getWidth(), fScrollBar.getHeight(), offsetWeCareAbout, visibleAmt, extent);
+
+            // the scrollable area is the extent - visible amount;
+            final int scrollableArea = extent - visibleAmt;
+
+            final int changeByValue = (int)(offsetChange * scrollableArea);
+            int newValue = firstValue + changeByValue;
+            newValue = Math.max(min, newValue);
+            newValue = Math.min((max - visibleAmt), newValue);
+            return newValue;
+        }
+
+        /**
+         * Arrow Listeners
+         */
+        // Because we are handling both mousePressed and Actions
+        // we need to make sure we don't fire under both conditions.
+        // (keyfocus on scrollbars causes action without mousePress
+        void mousePressedInArrows(final MouseEvent e, final Hit part) {
+            final int direction = HitUtil.isIncrement(part) ? 1 : -1;
+
+            fStillInArrow = true;
+            scrollByUnit(direction);
+            fScrollTimer.stop();
+            fScrollListener.setDirection(direction);
+            fScrollListener.setScrollByBlock(false);
+
+            fMousePart = part;
+            startTimer(true);
+        }
+
+        void mouseReleasedInArrows(final MouseEvent e) {
+            fScrollTimer.stop();
+            fMousePart = Hit.NONE;
+            fScrollBar.setValueIsAdjusting(false);
+        }
+
+        void mouseDraggedInArrows(final MouseEvent e) {
+            final Hit whichPart = getPartHit(e.getX(), e.getY());
+
+            if ((fMousePart == whichPart) && fStillInArrow) return; // Nothing has changed, so return
+
+            if (fMousePart != whichPart && !HitUtil.isArrow(whichPart)) {
+                // The mouse is not over the arrow we mouse pressed in, so stop the timer and mark as
+                // not being in the arrow
+                fScrollTimer.stop();
+                fStillInArrow = false;
+                fScrollBar.repaint();
+            } else {
+                // We are in the arrow we mouse pressed down in originally, but the timer was stopped so we need
+                // to start it up again.
+                fMousePart = whichPart;
+                fScrollListener.setDirection(HitUtil.isIncrement(whichPart) ? 1 : -1);
+                fStillInArrow = true;
+                fScrollListener.actionPerformed(new ActionEvent(fScrollTimer, 0, ""));
+                startTimer(false);
+            }
+
+            fScrollBar.repaint();
+        }
+
+        void mouseReleasedInTrack(final MouseEvent e) {
+            if (fTrackHighlight != Hit.NONE) {
+                fScrollBar.repaint();
+            }
+
+            fTrackHighlight = Hit.NONE;
+            fIsDragging = false;
+            fScrollTimer.stop();
+            fScrollBar.setValueIsAdjusting(false);
+        }
+
+        /**
+         * Adjust the fScrollBars value based on the result of hitTestTrack
+         */
+        void mousePressedInTrack(final MouseEvent e, final Hit part) {
+            fScrollBar.setValueIsAdjusting(true);
+
+            // If option-click, toggle scroll-to-here
+            boolean shouldScrollToHere = (part != ScrollBarHit.THUMB) && JRSUIUtils.ScrollBar.useScrollToClick();
+            if (e.isAltDown()) shouldScrollToHere = !shouldScrollToHere;
+
+            // pretend the mouse was dragged from a point in the current thumb to the current mouse point in one big jump
+            if (shouldScrollToHere) {
+                final Point p = getScrollToHereStartPoint(e.getX(), e.getY());
+                fFirstMouseX = p.x;
+                fFirstMouseY = p.y;
+                fFirstValue = fScrollBar.getValue();
+                moveToMouse(e);
+
+                // OK, now we're in the thumb - any subsequent dragging should move it
+                fTrackHighlight = ScrollBarHit.THUMB;
+                fIsDragging = true;
+                return;
+            }
+
+            fCurrentMouseX = e.getX();
+            fCurrentMouseY = e.getY();
+
+            int direction = 0;
+            if (part == ScrollBarHit.TRACK_MIN) {
+                fTrackHighlight = ScrollBarHit.TRACK_MIN;
+                direction = -1;
+            } else if (part == ScrollBarHit.TRACK_MAX) {
+                fTrackHighlight = ScrollBarHit.TRACK_MAX;
+                direction = 1;
+            } else {
+                fFirstValue = fScrollBar.getValue();
+                fFirstMouseX = fCurrentMouseX;
+                fFirstMouseY = fCurrentMouseY;
+                fTrackHighlight = ScrollBarHit.THUMB;
+                fIsDragging = true;
+                return;
+            }
+
+            fIsDragging = false;
+            fStillInTrack = true;
+
+            scrollByBlock(direction);
+            // Check the new location of the thumb
+            // stop scrolling if the thumb is under the mouse??
+
+            final Hit newPart = getPartHit(fCurrentMouseX, fCurrentMouseY);
+            if (newPart == ScrollBarHit.TRACK_MIN || newPart == ScrollBarHit.TRACK_MAX) {
+                fScrollTimer.stop();
+                fScrollListener.setDirection(((newPart == ScrollBarHit.TRACK_MAX) ? 1 : -1));
+                fScrollListener.setScrollByBlock(true);
+                startTimer(true);
+            }
+        }
+
+        /**
+         * Set the models value to the position of the top/left
+         * of the thumb relative to the origin of the track.
+         */
+        void mouseDraggedInTrack(final MouseEvent e) {
+            moveToMouse(e);
+        }
+
+        // For normal mouse dragging or click-to-here
+        // fCurrentMouseX, fCurrentMouseY, and fFirstValue must be set
+        void moveToMouse(final MouseEvent e) {
+            fCurrentMouseX = e.getX();
+            fCurrentMouseY = e.getY();
+
+            final int oldValue = fScrollBar.getValue();
+            final int newValue = getValueFromOffset(fCurrentMouseX - fFirstMouseX, fCurrentMouseY - fFirstMouseY, fFirstValue);
+            if (newValue == oldValue) return;
+
+            fScrollBar.setValue(newValue);
+            final Rectangle dirtyRect = getTrackBounds();
+            fScrollBar.repaint(dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height);
+        }
+    }
+
+    /**
+     * Listener for scrolling events initiated in the ScrollPane.
+     */
+    protected class ScrollListener implements ActionListener {
+        boolean fUseBlockIncrement;
+        int fDirection = 1;
+
+        void setDirection(final int direction) {
+            this.fDirection = direction;
+        }
+
+        void setScrollByBlock(final boolean block) {
+            this.fUseBlockIncrement = block;
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            if (fUseBlockIncrement) {
+                Hit newPart = getPartHit(fTrackListener.fCurrentMouseX, fTrackListener.fCurrentMouseY);
+
+                if (newPart == ScrollBarHit.TRACK_MIN || newPart == ScrollBarHit.TRACK_MAX) {
+                    final int newDirection = (newPart == ScrollBarHit.TRACK_MAX ? 1 : -1);
+                    if (fDirection != newDirection) {
+                        fDirection = newDirection;
+                    }
+                }
+
+                scrollByBlock(fDirection);
+                newPart = getPartHit(fTrackListener.fCurrentMouseX, fTrackListener.fCurrentMouseY);
+
+                if (newPart == ScrollBarHit.THUMB) {
+                    ((Timer)e.getSource()).stop();
+                }
+            } else {
+                scrollByUnit(fDirection);
+            }
+
+            if (fDirection > 0 && fScrollBar.getValue() + fScrollBar.getVisibleAmount() >= fScrollBar.getMaximum()) {
+                ((Timer)e.getSource()).stop();
+            } else if (fDirection < 0 && fScrollBar.getValue() <= fScrollBar.getMinimum()) {
+                ((Timer)e.getSource()).stop();
+            }
+        }
+    }
+
+    float getThumbStart() {
+        final int max = fScrollBar.getMaximum();
+        final int min = fScrollBar.getMinimum();
+        final int extent = max - min;
+        if (extent <= 0) return 0f;
+
+        return (float)(fScrollBar.getValue() - fScrollBar.getMinimum()) / (float)extent;
+    }
+
+    float getThumbPercent() {
+        final int visible = fScrollBar.getVisibleAmount();
+        final int max = fScrollBar.getMaximum();
+        final int min = fScrollBar.getMinimum();
+        final int extent = max - min;
+        if (extent <= 0) return 0f;
+
+        return (float)visible / (float)extent;
+    }
+
+    /**
+     * A scrollbar's preferred width is 16 by a reasonable size to hold
+     * the arrows
+     *
+     * @param c The JScrollBar that's delegating this method to us.
+     * @return The preferred size of a Basic JScrollBar.
+     * @see #getMaximumSize
+     * @see #getMinimumSize
+     */
+    public Dimension getPreferredSize(final JComponent c) {
+        return isHorizontal() ? new Dimension(96, 15) : new Dimension(15, 96);
+    }
+
+    public Dimension getMinimumSize(final JComponent c) {
+        return isHorizontal() ? new Dimension(54, 15) : new Dimension(15, 54);
+    }
+
+    public Dimension getMaximumSize(final JComponent c) {
+        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
+    }
+
+    boolean isHorizontal() {
+        return fScrollBar.getOrientation() == Adjustable.HORIZONTAL;
+    }
+
+    // only do scroll-to-here for page up and page down regions, when the option key is pressed
+    // This gets the point where the mouse would have been clicked in the current thumb
+    // so we can pretend the mouse was dragged to the current mouse point in one big jump
+    Point getScrollToHereStartPoint(final int clickPosX, final int clickPosY) {
+        // prepare the track rectangle and limit rectangle so we can do our calculations
+        final Rectangle limitRect = getDragBounds(); // GetThemeTrackDragRect
+
+        // determine the bounding rectangle for our thumb region
+        syncState(fScrollBar);
+        double[] rect = new double[4];
+        JRSUIUtils.ScrollBar.getPartBounds(rect, painter.getControl(), 0, 0, fScrollBar.getWidth(), fScrollBar.getHeight(), ScrollBarPart.THUMB);
+        final Rectangle r = new Rectangle((int)rect[0], (int)rect[1], (int)rect[2], (int)rect[3]);
+
+        // figure out the scroll-to-here start location based on our orientation, the
+        // click position, and where it must be in the thumb to travel to the endpoints
+        // properly.
+        final Point startPoint = new Point(clickPosX, clickPosY);
+
+        if (isHorizontal()) {
+            final int halfWidth = r.width / 2;
+            final int limitRectRight = limitRect.x + limitRect.width;
+
+            if (clickPosX + halfWidth > limitRectRight) {
+                // Up against right edge
+                startPoint.x = r.x + r.width - limitRectRight - clickPosX - 1;
+            } else if (clickPosX - halfWidth < limitRect.x) {
+                // Up against left edge
+                startPoint.x = r.x + clickPosX - limitRect.x;
+            } else {
+                // Center the thumb
+                startPoint.x = r.x + halfWidth;
+            }
+
+            // Pretend clicked in middle of indicator vertically
+            startPoint.y = (r.y + r.height) / 2;
+            return startPoint;
+        }
+
+        final int halfHeight = r.height / 2;
+        final int limitRectBottom = limitRect.y + limitRect.height;
+
+        if (clickPosY + halfHeight > limitRectBottom) {
+            // Up against bottom edge
+            startPoint.y = r.y + r.height - limitRectBottom - clickPosY - 1;
+        } else if (clickPosY - halfHeight < limitRect.y) {
+            // Up against top edge
+            startPoint.y = r.y + clickPosY - limitRect.y;
+        } else {
+            // Center the thumb
+            startPoint.y = r.y + halfHeight;
+        }
+
+        // Pretend clicked in middle of indicator horizontally
+        startPoint.x = (r.x + r.width) / 2;
+
+        return startPoint;
+    }
+
+    static class HitUtil {
+        static boolean isIncrement(final Hit hit) {
+            return (hit == ScrollBarHit.ARROW_MAX) || (hit == ScrollBarHit.ARROW_MAX_INSIDE);
+        }
+
+        static boolean isDecrement(final Hit hit) {
+            return (hit == ScrollBarHit.ARROW_MIN) || (hit == ScrollBarHit.ARROW_MIN_INSIDE);
+        }
+
+        static boolean isArrow(final Hit hit) {
+            return isIncrement(hit) || isDecrement(hit);
+        }
+
+        static boolean isTrack(final Hit hit) {
+            return (hit == ScrollBarHit.TRACK_MAX) || (hit == ScrollBarHit.TRACK_MIN);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaScrollPaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaScrollPaneUI.java
new file mode 100644
index 0000000..1035a3e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaScrollPaneUI.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.event.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+
+public class AquaScrollPaneUI extends javax.swing.plaf.basic.BasicScrollPaneUI {
+    public static ComponentUI createUI(final JComponent x) {
+        return new AquaScrollPaneUI();
+    }
+
+    protected MouseWheelListener createMouseWheelListener() {
+        return new XYMouseWheelHandler();
+    }
+
+    // This is a grody hack to trick BasicScrollPaneUI into scrolling horizontally
+    // when we notice that the shift key is down. This should be removed when AWT/Swing
+    // becomes aware of of multi-axis scroll wheels.
+    protected class XYMouseWheelHandler extends javax.swing.plaf.basic.BasicScrollPaneUI.MouseWheelHandler {
+        public void mouseWheelMoved(final MouseWheelEvent e) {
+            JScrollBar vScrollBar = null;
+            boolean wasVisible = false;
+
+            if (e.isShiftDown()) {
+                vScrollBar = scrollpane.getVerticalScrollBar();
+                if (vScrollBar != null) {
+                    wasVisible = vScrollBar.isVisible();
+                    vScrollBar.setVisible(false);
+                }
+            }
+
+            super.mouseWheelMoved(e);
+
+            if (wasVisible) {
+                vScrollBar.setVisible(true);
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaScrollRegionBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaScrollRegionBorder.java
new file mode 100644
index 0000000..fd2080e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaScrollRegionBorder.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.Component;
+import java.awt.Graphics;
+
+import javax.swing.JComponent;
+
+import apple.laf.JRSUIState;
+import apple.laf.JRSUIConstants.Focused;
+import apple.laf.JRSUIConstants.State;
+import apple.laf.JRSUIConstants.Widget;
+
+import com.apple.laf.AquaUtilControlSize.SizeDescriptor;
+import com.apple.laf.AquaUtilControlSize.SizeVariant;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaScrollRegionBorder extends AquaBorder {
+    static final RecyclableSingletonFromDefaultConstructor<AquaScrollRegionBorder> instance = new RecyclableSingletonFromDefaultConstructor<AquaScrollRegionBorder>(AquaScrollRegionBorder.class);
+
+    public static AquaScrollRegionBorder getScrollRegionBorder() {
+        return instance.get();
+    }
+
+    public AquaScrollRegionBorder() {
+        super(new SizeDescriptor(new SizeVariant().alterMargins(2, 2, 2, 2)));
+    }
+
+    @Override
+    protected AquaPainter<? extends JRSUIState> createPainter() {
+        JRSUIState state =  JRSUIState.getInstance();
+        state.set(Widget.FRAME_LIST_BOX);
+        return AquaPainter.<JRSUIState>create(state, 7, 7, 3, 3, 3, 3);
+    }
+
+    public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+        final State state = getState((JComponent)c);
+        painter.state.set(state);
+        painter.state.set(isFocused(c) && state == State.ACTIVE ? Focused.YES : Focused.NO);
+        painter.paint(g, c, x, y, width, height);
+    }
+
+    protected State getState(final JComponent c) {
+        if (!AquaFocusHandler.isActive(c)) return State.INACTIVE;
+        if (!c.isEnabled()) return State.DISABLED;
+        return State.ACTIVE;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaSliderUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaSliderUI.java
new file mode 100644
index 0000000..e2cfcf3
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaSliderUI.java
@@ -0,0 +1,501 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.MouseEvent;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicSliderUI;
+
+import apple.laf.*;
+import apple.laf.JRSUIUtils.NineSliceMetricsProvider;
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaImageFactory.NineSliceMetrics;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaSliderUI extends BasicSliderUI implements Sizeable {
+//    static final Dimension roundThumbSize = new Dimension(21 + 4, 21 + 4); // +2px on both sides for focus fuzz
+//    static final Dimension pointingThumbSize = new Dimension(19 + 4, 22 + 4);
+
+    protected static final RecyclableSingleton<SizeDescriptor> roundThumbDescriptor = new RecyclableSingleton<SizeDescriptor>() {
+        protected SizeDescriptor getInstance() {
+            return new SizeDescriptor(new SizeVariant(25, 25)) {
+                public SizeVariant deriveSmall(final SizeVariant v) {
+                    return super.deriveSmall(v.alterMinSize(-2, -2));
+                }
+                public SizeVariant deriveMini(final SizeVariant v) {
+                    return super.deriveMini(v.alterMinSize(-2, -2));
+                }
+            };
+        }
+    };
+    protected static final RecyclableSingleton<SizeDescriptor> pointingThumbDescriptor = new RecyclableSingleton<SizeDescriptor>() {
+        protected SizeDescriptor getInstance() {
+            return new SizeDescriptor(new SizeVariant(23, 26)) {
+                public SizeVariant deriveSmall(final SizeVariant v) {
+                    return super.deriveSmall(v.alterMinSize(-2, -2));
+                }
+                public SizeVariant deriveMini(final SizeVariant v) {
+                    return super.deriveMini(v.alterMinSize(-2, -2));
+                }
+            };
+        }
+    };
+
+    static final AquaPainter<JRSUIState> trackPainter = AquaPainter.create(JRSUIStateFactory.getSliderTrack(), new NineSliceMetricsProvider() {
+        @Override
+        public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state) {
+            if (state.is(Orientation.VERTICAL)) {
+                return new NineSliceMetrics(5, 7, 0, 0, 3, 3, true, false, true);
+            }
+            return new NineSliceMetrics(7, 5, 3, 3, 0, 0, true, true, false);
+        }
+    });
+    final AquaPainter<JRSUIState> thumbPainter = AquaPainter.create(JRSUIStateFactory.getSliderThumb());
+
+    protected Color tickColor;
+    protected Color disabledTickColor;
+
+    protected transient boolean fIsDragging = false;
+
+    // From AppearanceManager doc
+    static final int kTickWidth = 3;
+    static final int kTickLength = 8;
+
+    // Create PLAF
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaSliderUI((JSlider)c);
+    }
+
+    public AquaSliderUI(final JSlider b) {
+        super(b);
+    }
+
+    public void installUI(final JComponent c) {
+        super.installUI(c);
+
+        LookAndFeel.installProperty(slider, "opaque", Boolean.FALSE);
+        tickColor = UIManager.getColor("Slider.tickColor");
+    }
+
+    protected BasicSliderUI.TrackListener createTrackListener(final JSlider s) {
+        return new TrackListener();
+    }
+
+    protected void installListeners(final JSlider s) {
+        super.installListeners(s);
+        AquaFocusHandler.install(s);
+        AquaUtilControlSize.addSizePropertyListener(s);
+    }
+
+    protected void uninstallListeners(final JSlider s) {
+        AquaUtilControlSize.removeSizePropertyListener(s);
+        AquaFocusHandler.uninstall(s);
+        super.uninstallListeners(s);
+    }
+
+    public void applySizeFor(final JComponent c, final Size size) {
+        thumbPainter.state.set(size);
+        trackPainter.state.set(size);
+    }
+
+    // Paint Methods
+    public void paint(final Graphics g, final JComponent c) {
+        // We have to override paint of BasicSliderUI because we need slight differences.
+        // We don't paint focus the same way - it is part of the thumb.
+        // We also need to repaint the whole track when the thumb moves.
+        recalculateIfInsetsChanged();
+        final Rectangle clip = g.getClipBounds();
+
+        final Orientation orientation = slider.getOrientation() == SwingConstants.HORIZONTAL ? Orientation.HORIZONTAL : Orientation.VERTICAL;
+        final State state = getState();
+
+        if (slider.getPaintTrack()) {
+            // This is needed for when this is used as a renderer. It is the same as BasicSliderUI.java
+            // and is missing from our reimplementation.
+            //
+            // <rdar://problem/3721898> JSlider in TreeCellRenderer component not painted properly.
+            //
+            final boolean trackIntersectsClip = clip.intersects(trackRect);
+            if (!trackIntersectsClip) {
+                calculateGeometry();
+            }
+
+            if (trackIntersectsClip || clip.intersects(thumbRect)) paintTrack(g, c, orientation, state);
+        }
+
+        if (slider.getPaintTicks() && clip.intersects(tickRect)) {
+            paintTicks(g);
+        }
+
+        if (slider.getPaintLabels() && clip.intersects(labelRect)) {
+            paintLabels(g);
+        }
+
+        if (clip.intersects(thumbRect)) {
+            paintThumb(g, c, orientation, state);
+        }
+    }
+
+    // Paints track and thumb
+    public void paintTrack(final Graphics g, final JComponent c, final Orientation orientation, final State state) {
+        trackPainter.state.set(orientation);
+        trackPainter.state.set(state);
+
+        // for debugging
+        //g.setColor(Color.green);
+        //g.drawRect(trackRect.x, trackRect.y, trackRect.width - 1, trackRect.height - 1);
+        trackPainter.paint(g, c, trackRect.x, trackRect.y, trackRect.width, trackRect.height);
+    }
+
+    // Paints thumb only
+    public void paintThumb(final Graphics g, final JComponent c, final Orientation orientation, final State state) {
+        thumbPainter.state.set(orientation);
+        thumbPainter.state.set(state);
+        thumbPainter.state.set(slider.hasFocus() ? Focused.YES : Focused.NO);
+        thumbPainter.state.set(getDirection(orientation));
+
+        // for debugging
+        //g.setColor(Color.blue);
+        //g.drawRect(thumbRect.x, thumbRect.y, thumbRect.width - 1, thumbRect.height - 1);
+        thumbPainter.paint(g, c, thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height);
+    }
+
+    Direction getDirection(final Orientation orientation) {
+        if (shouldUseArrowThumb()) {
+            return orientation == Orientation.HORIZONTAL ? Direction.DOWN : Direction.RIGHT;
+        }
+
+        return Direction.NONE;
+    }
+
+    State getState() {
+        if (!slider.isEnabled()) {
+            return State.DISABLED;
+        }
+
+        if (fIsDragging) {
+            return State.PRESSED;
+        }
+
+        if (!AquaFocusHandler.isActive(slider)) {
+            return State.INACTIVE;
+        }
+
+        return State.ACTIVE;
+    }
+
+    public void paintTicks(final Graphics g) {
+        if (slider.isEnabled()) {
+            g.setColor(tickColor);
+        } else {
+            if (disabledTickColor == null) {
+                disabledTickColor = new Color(tickColor.getRed(), tickColor.getGreen(), tickColor.getBlue(), tickColor.getAlpha() / 2);
+            }
+            g.setColor(disabledTickColor);
+        }
+
+        super.paintTicks(g);
+    }
+
+    // Layout Methods
+
+    // Used lots
+    protected void calculateThumbLocation() {
+        super.calculateThumbLocation();
+
+        if (shouldUseArrowThumb()) {
+            final boolean isHorizonatal = slider.getOrientation() == SwingConstants.HORIZONTAL;
+            final Size size = AquaUtilControlSize.getUserSizeFrom(slider);
+
+            if (size == Size.REGULAR) {
+                if (isHorizonatal) thumbRect.y += 3; else thumbRect.x += 2; return;
+            }
+
+            if (size == Size.SMALL) {
+                if (isHorizonatal) thumbRect.y += 2; else thumbRect.x += 2; return;
+            }
+
+            if (size == Size.MINI) {
+                if (isHorizonatal) thumbRect.y += 1; return;
+            }
+        }
+    }
+
+    // Only called from calculateGeometry
+    protected void calculateThumbSize() {
+        final SizeDescriptor descriptor = shouldUseArrowThumb() ? pointingThumbDescriptor.get() : roundThumbDescriptor.get();
+        final SizeVariant variant = descriptor.get(slider);
+
+        if (slider.getOrientation() == SwingConstants.HORIZONTAL) {
+            thumbRect.setSize(variant.w, variant.h);
+        } else {
+            thumbRect.setSize(variant.h, variant.w);
+        }
+    }
+
+    protected boolean shouldUseArrowThumb() {
+        if (slider.getPaintTicks() || slider.getPaintLabels()) return true;
+
+        final Object shouldPaintArrowThumbProperty = slider.getClientProperty("Slider.paintThumbArrowShape");
+        if (shouldPaintArrowThumbProperty != null && shouldPaintArrowThumbProperty instanceof Boolean) {
+            return ((Boolean)shouldPaintArrowThumbProperty).booleanValue();
+        }
+
+        return false;
+    }
+
+    protected void calculateTickRect() {
+        // super assumes tickRect ends align with trackRect ends.
+        // Ours need to inset by trackBuffer
+        // Ours also needs to be *inside* trackRect
+        final int tickLength = slider.getPaintTicks() ? getTickLength() : 0;
+        if (slider.getOrientation() == SwingConstants.HORIZONTAL) {
+            tickRect.height = tickLength;
+            tickRect.x = trackRect.x + trackBuffer;
+            tickRect.y = trackRect.y + trackRect.height - (tickRect.height / 2);
+            tickRect.width = trackRect.width - (trackBuffer * 2);
+        } else {
+            tickRect.width = tickLength;
+            tickRect.x = trackRect.x + trackRect.width - (tickRect.width / 2);
+            tickRect.y = trackRect.y + trackBuffer;
+            tickRect.height = trackRect.height - (trackBuffer * 2);
+        }
+    }
+
+    // Basic's preferred size doesn't allow for our focus ring, throwing off things like SwingSet2
+    public Dimension getPreferredHorizontalSize() {
+        return new Dimension(190, 21);
+    }
+
+    public Dimension getPreferredVerticalSize() {
+        return new Dimension(21, 190);
+    }
+
+    protected ChangeListener createChangeListener(final JSlider s) {
+        return new ChangeListener() {
+            public void stateChanged(final ChangeEvent e) {
+                if (fIsDragging) return;
+                calculateThumbLocation();
+                slider.repaint();
+            }
+        };
+    }
+
+    // This is copied almost verbatim from superclass, except we changed things to use fIsDragging
+    // instead of isDragging since isDragging was a private member.
+    class TrackListener extends javax.swing.plaf.basic.BasicSliderUI.TrackListener {
+        protected transient int offset;
+        protected transient int currentMouseX = -1, currentMouseY = -1;
+
+        public void mouseReleased(final MouseEvent e) {
+            if (!slider.isEnabled()) return;
+
+            currentMouseX = -1;
+            currentMouseY = -1;
+
+            offset = 0;
+            scrollTimer.stop();
+
+            // This is the way we have to determine snap-to-ticks.  It's hard to explain
+            // but since ChangeEvents don't give us any idea what has changed we don't
+            // have a way to stop the thumb bounds from being recalculated.  Recalculating
+            // the thumb bounds moves the thumb over the current value (i.e., snapping
+            // to the ticks).
+            if (slider.getSnapToTicks() /*|| slider.getSnapToValue()*/) {
+                fIsDragging = false;
+                slider.setValueIsAdjusting(false);
+            } else {
+                slider.setValueIsAdjusting(false);
+                fIsDragging = false;
+            }
+
+            slider.repaint();
+        }
+
+        public void mousePressed(final MouseEvent e) {
+            if (!slider.isEnabled()) return;
+
+            final boolean firstClick = (currentMouseX == -1) && (currentMouseY == -1);
+
+            currentMouseX = e.getX();
+            currentMouseY = e.getY();
+
+            if (slider.isRequestFocusEnabled()) {
+                slider.requestFocus();
+            }
+
+            boolean isMouseEventInThumb = thumbRect.contains(currentMouseX, currentMouseY);
+
+            // we don't want to move the thumb if we just clicked on the edge of the thumb
+            if (!firstClick || !isMouseEventInThumb) {
+                slider.setValueIsAdjusting(true);
+
+                switch (slider.getOrientation()) {
+                    case SwingConstants.VERTICAL:
+                        slider.setValue(valueForYPosition(currentMouseY));
+                        break;
+                    case SwingConstants.HORIZONTAL:
+                        slider.setValue(valueForXPosition(currentMouseX));
+                        break;
+                }
+
+                slider.setValueIsAdjusting(false);
+
+                isMouseEventInThumb = true; // since we just moved it in there
+            }
+
+            // Clicked in the Thumb area?
+            if (isMouseEventInThumb) {
+                switch (slider.getOrientation()) {
+                    case SwingConstants.VERTICAL:
+                        offset = currentMouseY - thumbRect.y;
+                        break;
+                    case SwingConstants.HORIZONTAL:
+                        offset = currentMouseX - thumbRect.x;
+                        break;
+                }
+
+                fIsDragging = true;
+                return;
+            }
+
+            fIsDragging = false;
+        }
+
+        public boolean shouldScroll(final int direction) {
+            final Rectangle r = thumbRect;
+            if (slider.getOrientation() == SwingConstants.VERTICAL) {
+                if (drawInverted() ? direction < 0 : direction > 0) {
+                    if (r.y + r.height <= currentMouseY) return false;
+                } else {
+                    if (r.y >= currentMouseY) return false;
+                }
+            } else {
+                if (drawInverted() ? direction < 0 : direction > 0) {
+                    if (r.x + r.width >= currentMouseX) return false;
+                } else {
+                    if (r.x <= currentMouseX) return false;
+                }
+            }
+
+            if (direction > 0 && slider.getValue() + slider.getExtent() >= slider.getMaximum()) {
+                return false;
+            }
+
+            if (direction < 0 && slider.getValue() <= slider.getMinimum()) {
+                return false;
+            }
+
+            return true;
+        }
+
+        /**
+         * Set the models value to the position of the top/left
+         * of the thumb relative to the origin of the track.
+         */
+        public void mouseDragged(final MouseEvent e) {
+            int thumbMiddle = 0;
+
+            if (!slider.isEnabled()) return;
+
+            currentMouseX = e.getX();
+            currentMouseY = e.getY();
+
+            if (!fIsDragging) return;
+
+            slider.setValueIsAdjusting(true);
+
+            switch (slider.getOrientation()) {
+                case SwingConstants.VERTICAL:
+                    final int halfThumbHeight = thumbRect.height / 2;
+                    int thumbTop = e.getY() - offset;
+                    int trackTop = trackRect.y;
+                    int trackBottom = trackRect.y + (trackRect.height - 1);
+                    final int vMax = yPositionForValue(slider.getMaximum() - slider.getExtent());
+
+                    if (drawInverted()) {
+                        trackBottom = vMax;
+                    } else {
+                        trackTop = vMax;
+                    }
+                    thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
+                    thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
+
+                    setThumbLocation(thumbRect.x, thumbTop);
+
+                    thumbMiddle = thumbTop + halfThumbHeight;
+                    slider.setValue(valueForYPosition(thumbMiddle));
+                    break;
+                case SwingConstants.HORIZONTAL:
+                    final int halfThumbWidth = thumbRect.width / 2;
+                    int thumbLeft = e.getX() - offset;
+                    int trackLeft = trackRect.x;
+                    int trackRight = trackRect.x + (trackRect.width - 1);
+                    final int hMax = xPositionForValue(slider.getMaximum() - slider.getExtent());
+
+                    if (drawInverted()) {
+                        trackLeft = hMax;
+                    } else {
+                        trackRight = hMax;
+                    }
+                    thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
+                    thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
+
+                    setThumbLocation(thumbLeft, thumbRect.y);
+
+                    thumbMiddle = thumbLeft + halfThumbWidth;
+                    slider.setValue(valueForXPosition(thumbMiddle));
+                    break;
+                default:
+                    return;
+            }
+
+            // enable live snap-to-ticks <rdar://problem/3165310>
+            if (slider.getSnapToTicks()) {
+                calculateThumbLocation();
+                setThumbLocation(thumbRect.x, thumbRect.y); // need to call to refresh the repaint region
+            }
+        }
+
+        public void mouseMoved(final MouseEvent e) { }
+    }
+
+    // Super handles snap-to-ticks by recalculating the thumb rect in the TrackListener
+    // See setThumbLocation for why that doesn't work
+    int getScale() {
+        if (!slider.getSnapToTicks()) return 1;
+        int scale = slider.getMinorTickSpacing();
+            if (scale < 1) scale = slider.getMajorTickSpacing();
+        if (scale < 1) return 1;
+        return scale;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaSpinnerUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaSpinnerUI.java
new file mode 100644
index 0000000..191fb6e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaSpinnerUI.java
@@ -0,0 +1,648 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.text.*;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.text.Format.Field;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.JSpinner.DefaultEditor;
+import javax.swing.plaf.*;
+import javax.swing.text.InternationalFormatter;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+/**
+ * This is originally derived from BasicSpinnerUI, but they made everything private
+ * so we can't subclass!
+ */
+public class AquaSpinnerUI extends SpinnerUI {
+    private static final RecyclableSingleton<? extends PropertyChangeListener> propertyChangeListener = new RecyclableSingletonFromDefaultConstructor<PropertyChangeHandler>(PropertyChangeHandler.class);
+    static PropertyChangeListener getPropertyChangeListener() {
+        return propertyChangeListener.get();
+    }
+
+    private static final RecyclableSingleton<ArrowButtonHandler> nextButtonHandler = new RecyclableSingleton<ArrowButtonHandler>() {
+        @Override
+        protected ArrowButtonHandler getInstance() {
+            return new ArrowButtonHandler("increment", true);
+        }
+    };
+    static ArrowButtonHandler getNextButtonHandler() {
+        return nextButtonHandler.get();
+    }
+    private static final RecyclableSingleton<ArrowButtonHandler> previousButtonHandler = new RecyclableSingleton<ArrowButtonHandler>() {
+        @Override
+        protected ArrowButtonHandler getInstance() {
+            return new ArrowButtonHandler("decrement", false);
+        }
+    };
+    static ArrowButtonHandler getPreviousButtonHandler() {
+        return previousButtonHandler.get();
+    }
+
+    JSpinner spinner;
+    SpinPainter spinPainter;
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaSpinnerUI();
+    }
+
+    private void maybeAdd(final Component c, final String s) {
+        if (c != null) {
+            spinner.add(c, s);
+        }
+    }
+
+    boolean wasOpaque;
+    public void installUI(final JComponent c) {
+        this.spinner = (JSpinner)c;
+        installDefaults();
+        installListeners();
+        final TransparentButton next = createNextButton();
+        final TransparentButton prev = createPreviousButton();
+        spinPainter = new SpinPainter(next, prev);
+
+        maybeAdd(next, "Next");
+        maybeAdd(prev, "Previous");
+        maybeAdd(createEditor(), "Editor");
+        maybeAdd(spinPainter, "Painter");
+
+        updateEnabledState();
+        installKeyboardActions();
+
+        // this doesn't work because JSpinner calls setOpaque(true) directly in it's constructor
+    //    LookAndFeel.installProperty(spinner, "opaque", Boolean.FALSE);
+
+        // ...so we have to handle the is/was opaque ourselves
+        wasOpaque = spinner.isOpaque();
+        spinner.setOpaque(false);
+    }
+
+    public void uninstallUI(final JComponent c) {
+        uninstallDefaults();
+        uninstallListeners();
+        spinner.setOpaque(wasOpaque);
+        spinner = null;
+        c.removeAll();
+    }
+
+    protected void installListeners() {
+        spinner.addPropertyChangeListener(getPropertyChangeListener());
+    }
+
+    protected void uninstallListeners() {
+        spinner.removePropertyChangeListener(getPropertyChangeListener());
+    }
+
+    protected void installDefaults() {
+        spinner.setLayout(createLayout());
+        LookAndFeel.installBorder(spinner, "Spinner.border");
+        LookAndFeel.installColorsAndFont(spinner, "Spinner.background", "Spinner.foreground", "Spinner.font");
+    }
+
+    protected void uninstallDefaults() {
+        spinner.setLayout(null);
+    }
+
+    protected LayoutManager createLayout() {
+        return new SpinnerLayout();
+    }
+
+    protected PropertyChangeListener createPropertyChangeListener() {
+        return new PropertyChangeHandler();
+    }
+
+    protected TransparentButton createPreviousButton() {
+        final TransparentButton b = new TransparentButton();
+        b.addActionListener(getPreviousButtonHandler());
+        b.addMouseListener(getPreviousButtonHandler());
+        b.setInheritsPopupMenu(true);
+        return b;
+    }
+
+    protected TransparentButton createNextButton() {
+        final TransparentButton b = new TransparentButton();
+        b.addActionListener(getNextButtonHandler());
+        b.addMouseListener(getNextButtonHandler());
+        b.setInheritsPopupMenu(true);
+        return b;
+    }
+
+    class TransparentButton extends JButton implements SwingConstants {
+        boolean interceptRepaints = false;
+
+        public TransparentButton() {
+            super();
+            setFocusable(false);
+            // only intercept repaints if we are after this has been initialized
+            // otherwise we can't talk to our containing class
+            interceptRepaints = true;
+        }
+
+        public void paint(final Graphics g) {}
+
+        public void repaint() {
+            // only intercept repaints if we are after this has been initialized
+            // otherwise we can't talk to our containing class
+            if (interceptRepaints) {
+                if (spinPainter == null) return;
+                spinPainter.repaint();
+            }
+            super.repaint();
+        }
+    }
+
+    protected JComponent createEditor() {
+        final JComponent editor = spinner.getEditor();
+        fixupEditor(editor);
+        return editor;
+    }
+
+    protected void replaceEditor(final JComponent oldEditor, final JComponent newEditor) {
+        spinner.remove(oldEditor);
+        fixupEditor(newEditor);
+        spinner.add(newEditor, "Editor");
+    }
+
+    protected void fixupEditor(final JComponent editor) {
+        if (!(editor instanceof DefaultEditor)) return;
+
+        editor.setOpaque(false);
+        editor.setInheritsPopupMenu(true);
+
+        if (editor.getFont() instanceof UIResource) {
+            editor.setFont(spinner.getFont());
+        }
+
+        final JFormattedTextField editorTextField = ((DefaultEditor)editor).getTextField();
+        final InputMap spinnerInputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+        final InputMap editorInputMap = editorTextField.getInputMap();
+        final KeyStroke[] keys = spinnerInputMap.keys();
+        for (final KeyStroke k : keys) {
+            editorInputMap.put(k, spinnerInputMap.get(k));
+        }
+    }
+
+    void updateEnabledState() {
+        updateEnabledState(spinner, spinner.isEnabled());
+    }
+
+    private void updateEnabledState(final Container c, final boolean enabled) {
+        for (int counter = c.getComponentCount() - 1; counter >= 0; counter--) {
+            final Component child = c.getComponent(counter);
+
+            child.setEnabled(enabled);
+            if (child instanceof Container) {
+                updateEnabledState((Container)child, enabled);
+            }
+        }
+    }
+
+    private void installKeyboardActions() {
+        final InputMap iMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+        SwingUtilities.replaceUIInputMap(spinner, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, iMap);
+        SwingUtilities.replaceUIActionMap(spinner, getActionMap());
+    }
+
+    private InputMap getInputMap(final int condition) {
+        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
+            return (InputMap)UIManager.get("Spinner.ancestorInputMap");
+        }
+        return null;
+    }
+
+    private ActionMap getActionMap() {
+        ActionMap map = (ActionMap)UIManager.get("Spinner.actionMap");
+
+        if (map == null) {
+            map = createActionMap();
+            if (map != null) {
+                UIManager.getLookAndFeelDefaults().put("Spinner.actionMap", map);
+            }
+        }
+        return map;
+    }
+
+    private ActionMap createActionMap() {
+        final ActionMap map = new ActionMapUIResource();
+        map.put("increment", getNextButtonHandler());
+        map.put("decrement", getPreviousButtonHandler());
+        return map;
+    }
+
+    private static class ArrowButtonHandler extends AbstractAction implements MouseListener {
+        final javax.swing.Timer autoRepeatTimer;
+        final boolean isNext;
+        JSpinner spinner = null;
+
+        ArrowButtonHandler(final String name, final boolean isNext) {
+            super(name);
+            this.isNext = isNext;
+            autoRepeatTimer = new javax.swing.Timer(60, this);
+            autoRepeatTimer.setInitialDelay(300);
+        }
+
+        private JSpinner eventToSpinner(final AWTEvent e) {
+            Object src = e.getSource();
+            while ((src instanceof Component) && !(src instanceof JSpinner)) {
+                src = ((Component)src).getParent();
+            }
+            return (src instanceof JSpinner) ? (JSpinner)src : null;
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            if (!(e.getSource() instanceof javax.swing.Timer)) {
+                // Most likely resulting from being in ActionMap.
+                spinner = eventToSpinner(e);
+            }
+
+            if (spinner == null) return;
+
+            try {
+                final int calendarField = getCalendarField(spinner);
+                spinner.commitEdit();
+                if (calendarField != -1) {
+                    ((SpinnerDateModel)spinner.getModel()).setCalendarField(calendarField);
+                }
+                final Object value = (isNext) ? spinner.getNextValue() : spinner.getPreviousValue();
+                if (value != null) {
+                    spinner.setValue(value);
+                    select(spinner);
+                }
+            } catch (final IllegalArgumentException iae) {
+                UIManager.getLookAndFeel().provideErrorFeedback(spinner);
+            } catch (final ParseException pe) {
+                UIManager.getLookAndFeel().provideErrorFeedback(spinner);
+            }
+        }
+
+        /**
+         * If the spinner's editor is a DateEditor, this selects the field
+         * associated with the value that is being incremented.
+         */
+        private void select(final JSpinner spinnerComponent) {
+            final JComponent editor = spinnerComponent.getEditor();
+            if (!(editor instanceof JSpinner.DateEditor)) return;
+
+            final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
+            final JFormattedTextField ftf = dateEditor.getTextField();
+            final Format format = dateEditor.getFormat();
+            Object value;
+            if (format == null || (value = spinnerComponent.getValue()) == null) return;
+
+            final SpinnerDateModel model = dateEditor.getModel();
+            final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
+            if (field == null) return;
+
+            try {
+                final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
+                if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
+                    select(ftf, iterator, DateFormat.Field.HOUR1);
+                }
+            } catch (final IllegalArgumentException iae) {}
+        }
+
+        /**
+         * Selects the passed in field, returning true if it is found,
+         * false otherwise.
+         */
+        private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
+            final int max = ftf.getDocument().getLength();
+
+            iterator.first();
+            do {
+                final Map<Attribute,Object> attrs = iterator.getAttributes();
+                if (attrs == null || !attrs.containsKey(field)) continue;
+
+                final int start = iterator.getRunStart(field);
+                final int end = iterator.getRunLimit(field);
+                if (start != -1 && end != -1 && start <= max && end <= max) {
+                    ftf.select(start, end);
+                }
+
+                return true;
+            } while (iterator.next() != CharacterIterator.DONE);
+            return false;
+        }
+
+        /**
+         * Returns the calendarField under the start of the selection, or
+         * -1 if there is no valid calendar field under the selection (or
+         * the spinner isn't editing dates.
+         */
+        private int getCalendarField(final JSpinner spinnerComponent) {
+            final JComponent editor = spinnerComponent.getEditor();
+            if (!(editor instanceof JSpinner.DateEditor)) return -1;
+
+            final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
+            final JFormattedTextField ftf = dateEditor.getTextField();
+            final int start = ftf.getSelectionStart();
+            final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
+            if (!(formatter instanceof InternationalFormatter)) return -1;
+
+            final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
+            for (final Field element : fields) {
+                if (!(element instanceof DateFormat.Field)) continue;
+                int calendarField;
+
+                if (element == DateFormat.Field.HOUR1) {
+                    calendarField = Calendar.HOUR;
+                } else {
+                    calendarField = ((DateFormat.Field)element).getCalendarField();
+                }
+
+                if (calendarField != -1) {
+                    return calendarField;
+                }
+            }
+            return -1;
+        }
+
+        public void mousePressed(final MouseEvent e) {
+            if (!SwingUtilities.isLeftMouseButton(e) || !e.getComponent().isEnabled()) return;
+            spinner = eventToSpinner(e);
+            autoRepeatTimer.start();
+
+            focusSpinnerIfNecessary();
+        }
+
+        public void mouseReleased(final MouseEvent e) {
+            autoRepeatTimer.stop();
+            spinner = null;
+        }
+
+        public void mouseClicked(final MouseEvent e) {}
+        public void mouseEntered(final MouseEvent e) {}
+        public void mouseExited(final MouseEvent e) {}
+
+        /**
+         * Requests focus on a child of the spinner if the spinner doesn't
+         * have focus.
+         */
+        private void focusSpinnerIfNecessary() {
+            final Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+            if (!spinner.isRequestFocusEnabled() || (fo != null && (SwingUtilities.isDescendingFrom(fo, spinner)))) return;
+            Container root = spinner;
+
+            if (!root.isFocusCycleRoot()) {
+                root = root.getFocusCycleRootAncestor();
+            }
+
+            if (root == null) return;
+            final FocusTraversalPolicy ftp = root.getFocusTraversalPolicy();
+            final Component child = ftp.getComponentAfter(root, spinner);
+
+            if (child != null && SwingUtilities.isDescendingFrom(child, spinner)) {
+                child.requestFocus();
+            }
+        }
+    }
+
+    class SpinPainter extends JComponent {
+        final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIStateFactory.getSpinnerArrows());
+
+        ButtonModel fTopModel;
+        ButtonModel fBottomModel;
+
+        boolean fPressed = false;
+        boolean fTopPressed = false;
+
+        Dimension kPreferredSize = new Dimension(15, 24); // 19,27 before trimming
+
+        public SpinPainter(final AbstractButton top, final AbstractButton bottom) {
+            if (top != null) {
+                fTopModel = top.getModel();
+            }
+
+            if (bottom != null) {
+                fBottomModel = bottom.getModel();
+            }
+        }
+
+        public void paint(final Graphics g) {
+            if (spinner.isOpaque()) {
+                g.setColor(spinner.getBackground());
+                g.fillRect(0, 0, getWidth(), getHeight());
+            }
+
+            AquaUtilControlSize.applySizeForControl(spinner, painter);
+
+            if (isEnabled()) {
+                if (fTopModel != null && fTopModel.isPressed()) {
+                    painter.state.set(State.PRESSED);
+                    painter.state.set(BooleanValue.NO);
+                } else if (fBottomModel != null && fBottomModel.isPressed()) {
+                    painter.state.set(State.PRESSED);
+                    painter.state.set(BooleanValue.YES);
+                } else {
+                    painter.state.set(State.ACTIVE);
+                }
+            } else {
+                painter.state.set(State.DISABLED);
+            }
+
+            final Rectangle bounds = getBounds();
+            painter.paint(g, spinner, 0, 0, bounds.width, bounds.height);
+        }
+
+        public Dimension getPreferredSize() {
+            final Size size = AquaUtilControlSize.getUserSizeFrom(this);
+
+            if (size == Size.MINI) {
+                return new Dimension(kPreferredSize.width, kPreferredSize.height - 8);
+            }
+
+            return kPreferredSize;
+        }
+    }
+
+    /**
+     * A simple layout manager for the editor and the next/previous buttons.
+     * See the AquaSpinnerUI javadoc for more information about exactly
+     * how the components are arranged.
+     */
+    static class SpinnerLayout implements LayoutManager {
+        private Component nextButton = null;
+        private Component previousButton = null;
+        private Component editor = null;
+        private Component painter = null;
+
+        public void addLayoutComponent(final String name, final Component c) {
+            if ("Next".equals(name)) {
+                nextButton = c;
+            } else if ("Previous".equals(name)) {
+                previousButton = c;
+            } else if ("Editor".equals(name)) {
+                editor = c;
+            } else if ("Painter".equals(name)) {
+                painter = c;
+            }
+        }
+
+        public void removeLayoutComponent(Component c) {
+            if (c == nextButton) {
+                c = null;
+            } else if (c == previousButton) {
+                previousButton = null;
+            } else if (c == editor) {
+                editor = null;
+            } else if (c == painter) {
+                painter = null;
+            }
+        }
+
+        private Dimension preferredSize(final Component c) {
+            return (c == null) ? new Dimension(0, 0) : c.getPreferredSize();
+        }
+
+        public Dimension preferredLayoutSize(final Container parent) {
+//            Dimension nextD = preferredSize(nextButton);
+//            Dimension previousD = preferredSize(previousButton);
+            final Dimension editorD = preferredSize(editor);
+            final Dimension painterD = preferredSize(painter);
+
+            /* Force the editors height to be a multiple of 2
+             */
+            editorD.height = ((editorD.height + 1) / 2) * 2;
+
+            final Dimension size = new Dimension(editorD.width, Math.max(painterD.height, editorD.height));
+            size.width += painterD.width; //Math.max(nextD.width, previousD.width);
+            final Insets insets = parent.getInsets();
+            size.width += insets.left + insets.right;
+            size.height += insets.top + insets.bottom;
+            return size;
+        }
+
+        public Dimension minimumLayoutSize(final Container parent) {
+            return preferredLayoutSize(parent);
+        }
+
+        private void setBounds(final Component c, final int x, final int y, final int width, final int height) {
+            if (c != null) {
+                c.setBounds(x, y, width, height);
+            }
+        }
+
+        public void layoutContainer(final Container parent) {
+            final Insets insets = parent.getInsets();
+            final int availWidth = parent.getWidth() - (insets.left + insets.right);
+            final int availHeight = parent.getHeight() - (insets.top + insets.bottom);
+
+            final Dimension painterD = preferredSize(painter);
+//            Dimension nextD = preferredSize(nextButton);
+//            Dimension previousD = preferredSize(previousButton);
+            final int nextHeight = availHeight / 2;
+            final int previousHeight = availHeight - nextHeight;
+            final int buttonsWidth = painterD.width; //Math.max(nextD.width, previousD.width);
+            final int editorWidth = availWidth - buttonsWidth;
+
+            /* Deal with the spinners componentOrientation property.
+             */
+            int editorX, buttonsX;
+            if (parent.getComponentOrientation().isLeftToRight()) {
+                editorX = insets.left;
+                buttonsX = editorX + editorWidth;
+            } else {
+                buttonsX = insets.left;
+                editorX = buttonsX + buttonsWidth;
+            }
+
+            final int previousY = insets.top + nextHeight;
+            final int painterTop = previousY - (painterD.height / 2);
+            setBounds(editor, editorX, insets.top, editorWidth, availHeight);
+            setBounds(nextButton, buttonsX, insets.top, buttonsWidth, nextHeight);
+            setBounds(previousButton, buttonsX, previousY, buttonsWidth, previousHeight);
+            setBounds(painter, buttonsX, painterTop, buttonsWidth, painterD.height);
+        }
+    }
+
+    /**
+     * Detect JSpinner property changes we're interested in and delegate.  Subclasses
+     * shouldn't need to replace the default propertyChangeListener (although they
+     * can by overriding createPropertyChangeListener) since all of the interesting
+     * property changes are delegated to protected methods.
+     */
+    static class PropertyChangeHandler implements PropertyChangeListener {
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String propertyName = e.getPropertyName();
+            final JSpinner spinner = (JSpinner)(e.getSource());
+            final SpinnerUI spinnerUI = spinner.getUI();
+
+            if (spinnerUI instanceof AquaSpinnerUI) {
+                final AquaSpinnerUI ui = (AquaSpinnerUI)spinnerUI;
+
+                if ("editor".equals(propertyName)) {
+                    final JComponent oldEditor = (JComponent)e.getOldValue();
+                    final JComponent newEditor = (JComponent)e.getNewValue();
+                    ui.replaceEditor(oldEditor, newEditor);
+                    ui.updateEnabledState();
+                } else if ("enabled".equals(propertyName)) {
+                    ui.updateEnabledState();
+                } else if (JComponent.TOOL_TIP_TEXT_KEY.equals(propertyName)) {
+                    ui.updateToolTipTextForChildren(spinner);
+                } else if ("font".equals(propertyName)) {
+                    JComponent editor = spinner.getEditor();
+                    if (editor != null && editor instanceof JSpinner.DefaultEditor) {
+                        JTextField tf =
+                                ((JSpinner.DefaultEditor) editor).getTextField();
+                        if (tf != null) {
+                            if (tf.getFont() instanceof UIResource) {
+                                tf.setFont(spinner.getFont());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    // Syncronizes the ToolTip text for the components within the spinner
+    // to be the same value as the spinner ToolTip text.
+    void updateToolTipTextForChildren(final JComponent spinnerComponent) {
+        final String toolTipText = spinnerComponent.getToolTipText();
+        final Component[] children = spinnerComponent.getComponents();
+        for (final Component element : children) {
+            if (element instanceof JSpinner.DefaultEditor) {
+                final JTextField tf = ((JSpinner.DefaultEditor)element).getTextField();
+                if (tf != null) {
+                    tf.setToolTipText(toolTipText);
+                }
+            } else if (element instanceof JComponent) {
+                ((JComponent)element).setToolTipText(toolTipText);
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaSplitPaneDividerUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaSplitPaneDividerUI.java
new file mode 100644
index 0000000..ebedd36
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaSplitPaneDividerUI.java
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.beans.PropertyChangeEvent;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.State;
+
+import com.apple.laf.AquaUtils.LazyKeyedSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaSplitPaneDividerUI extends BasicSplitPaneDivider {
+    final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIStateFactory.getSplitPaneDivider());
+
+    public AquaSplitPaneDividerUI(final AquaSplitPaneUI ui) {
+        super(ui);
+        setLayout(new AquaSplitPaneDividerUI.DividerLayout());
+    }
+
+    /**
+     * Property change event, presumably from the JSplitPane, will message
+     * updateOrientation if necessary.
+     */
+    public void propertyChange(final PropertyChangeEvent e) {
+        if (e.getSource() == splitPane) {
+            final String propName = e.getPropertyName();
+            if ("enabled".equals(propName)) {
+                final boolean enabled = splitPane.isEnabled();
+                if (leftButton != null) leftButton.setEnabled(enabled);
+                if (rightButton != null) rightButton.setEnabled(enabled);
+            } else if (JSplitPane.ORIENTATION_PROPERTY.equals(propName)) {
+                // need to regenerate the buttons, since we bake the orientation into them
+                if (rightButton  != null) {
+                    remove(rightButton); rightButton = null;
+                }
+                if (leftButton != null) {
+                    remove(leftButton); leftButton = null;
+                }
+                oneTouchExpandableChanged();
+            }
+        }
+        super.propertyChange(e);
+    }
+
+    public int getMaxDividerSize() {
+        return 10;
+    }
+
+    /**
+     * Paints the divider.
+     */
+    public void paint(final Graphics g) {
+        final Dimension size = getSize();
+        int x = 0;
+        int y = 0;
+
+        final boolean horizontal = splitPane.getOrientation() == SwingConstants.HORIZONTAL;
+        //System.err.println("Size = " + size + " orientation horiz = " + horizontal);
+        // size determines orientation
+        final int maxSize = getMaxDividerSize();
+        boolean doPaint = true;
+        if (horizontal) {
+            if (size.height > maxSize) {
+                final int diff = size.height - maxSize;
+                y = diff / 2;
+                size.height = maxSize;
+            }
+            if (size.height < 4) doPaint = false;
+        } else {
+            if (size.width > maxSize) {
+                final int diff = size.width - maxSize;
+                x = diff / 2;
+                size.width = maxSize;
+            }
+            if (size.width < 4) doPaint = false;
+        }
+
+        if (doPaint) {
+            painter.state.set(getState());
+            painter.paint(g, splitPane, x, y, size.width, size.height);
+        }
+
+        super.paint(g); // Ends up at Container.paint, which paints our JButton children
+    }
+
+    protected State getState() {
+        return splitPane.isEnabled() ? State.ACTIVE : State.DISABLED;
+    }
+
+    protected JButton createLeftOneTouchButton() {
+        return createButtonForDirection(getDirection(true));
+    }
+
+    protected JButton createRightOneTouchButton() {
+        return createButtonForDirection(getDirection(false));
+    }
+
+    static final LazyKeyedSingleton<Integer, Image> directionArrows = new LazyKeyedSingleton<Integer, Image>() {
+        protected Image getInstance(final Integer direction) {
+            final Image arrowImage = AquaImageFactory.getArrowImageForDirection(direction);
+            final int h = (arrowImage.getHeight(null) * 5) / 7;
+            final int w = (arrowImage.getWidth(null) * 5) / 7;
+            return AquaUtils.generateLightenedImage(arrowImage.getScaledInstance(w, h, Image.SCALE_SMOOTH), 50);
+        }
+    };
+
+    // separate static, because the divider needs to be serializable
+    // see <rdar://problem/7590946> JSplitPane is not serializable when using Aqua look and feel
+    static JButton createButtonForDirection(final int direction) {
+        final JButton button = new JButton(new ImageIcon(directionArrows.get(Integer.valueOf(direction))));
+        button.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+        button.setFocusPainted(false);
+        button.setRequestFocusEnabled(false);
+        button.setFocusable(false);
+        button.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+        return button;
+    }
+
+    int getDirection(final boolean isLeft) {
+        if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
+            return isLeft ? SwingConstants.WEST : SwingConstants.EAST;
+        }
+
+        return isLeft ? SwingConstants.NORTH : SwingConstants.SOUTH;
+    }
+
+    static final int kMaxPopupArrowSize = 9;
+    protected class DividerLayout extends BasicSplitPaneDivider.DividerLayout {
+        public void layoutContainer(final Container c) {
+            final int maxSize = getMaxDividerSize();
+            final Dimension size = getSize();
+
+            if (leftButton == null || rightButton == null || c != AquaSplitPaneDividerUI.this) return;
+
+            if (!splitPane.isOneTouchExpandable()) {
+                leftButton.setBounds(-5, -5, 1, 1);
+                rightButton.setBounds(-5, -5, 1, 1);
+                return;
+            }
+
+            final int blockSize = Math.min(getDividerSize(), kMaxPopupArrowSize); // make it 1 less than divider, or kMaxPopupArrowSize
+
+            // put them at the right or the bottom
+            if (orientation == JSplitPane.VERTICAL_SPLIT) {
+                int yPosition = 0;
+                if (size.height > maxSize) {
+                    final int diff = size.height - maxSize;
+                    yPosition = diff / 2;
+                }
+                int xPosition = kMaxPopupArrowSize + ONE_TOUCH_OFFSET;
+
+                rightButton.setBounds(xPosition, yPosition, kMaxPopupArrowSize, blockSize);
+
+                xPosition -= (kMaxPopupArrowSize + ONE_TOUCH_OFFSET);
+                leftButton.setBounds(xPosition, yPosition, kMaxPopupArrowSize, blockSize);
+            } else {
+                int xPosition = 0;
+                if (size.width > maxSize) {
+                    final int diff = size.width - maxSize;
+                    xPosition = diff / 2;
+                }
+                int yPosition = kMaxPopupArrowSize + ONE_TOUCH_OFFSET;
+
+                rightButton.setBounds(xPosition, yPosition, blockSize, kMaxPopupArrowSize);
+
+                yPosition -= (kMaxPopupArrowSize + ONE_TOUCH_OFFSET);
+                leftButton.setBounds(xPosition, yPosition, blockSize, kMaxPopupArrowSize);
+            }
+        }
+    }
+
+    public static Border getHorizontalSplitDividerGradientVariant() {
+        return HorizontalSplitDividerGradientPainter.instance();
+    }
+
+    static class HorizontalSplitDividerGradientPainter implements Border {
+        private static final RecyclableSingleton<HorizontalSplitDividerGradientPainter> instance = new RecyclableSingletonFromDefaultConstructor<HorizontalSplitDividerGradientPainter>(HorizontalSplitDividerGradientPainter.class);
+        static HorizontalSplitDividerGradientPainter instance() {
+            return instance.get();
+        }
+
+        final Color startColor = Color.white;
+        final Color endColor = new Color(217, 217, 217);
+        final Color borderLines = Color.lightGray;
+
+        public Insets getBorderInsets(final Component c) {
+            return new Insets(0, 0, 0, 0);
+        }
+
+        public boolean isBorderOpaque() {
+            return true;
+        }
+
+        public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+            if (!(g instanceof Graphics2D)) return;
+
+            final Graphics2D g2d = (Graphics2D)g;
+            final Color oldColor = g2d.getColor();
+
+            g2d.setPaint(new GradientPaint(0, 0, startColor, 0, height, endColor));
+            g2d.fillRect(x, y, width, height);
+            g2d.setColor(borderLines);
+            g2d.drawLine(x, y, x + width, y);
+            g2d.drawLine(x, y + height - 1, x + width, y + height - 1);
+
+            g2d.setColor(oldColor);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaSplitPaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaSplitPaneUI.java
new file mode 100644
index 0000000..607563d
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaSplitPaneUI.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.event.*;
+import java.beans.*;
+
+import javax.swing.JComponent;
+import javax.swing.border.Border;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.*;
+
+public class AquaSplitPaneUI extends BasicSplitPaneUI implements MouseListener, PropertyChangeListener {
+    static final String DIVIDER_PAINTER_KEY = "JSplitPane.dividerPainter";
+
+    public AquaSplitPaneUI() {
+        super();
+    }
+
+    public static ComponentUI createUI(final JComponent x) {
+        return new AquaSplitPaneUI();
+    }
+
+    public BasicSplitPaneDivider createDefaultDivider() {
+        return new AquaSplitPaneDividerUI(this);
+    }
+
+    protected void installListeners() {
+        super.installListeners();
+        splitPane.addPropertyChangeListener(DIVIDER_PAINTER_KEY, this);
+        divider.addMouseListener(this);
+    }
+
+    protected void uninstallListeners() {
+        divider.removeMouseListener(this);
+        splitPane.removePropertyChangeListener(DIVIDER_PAINTER_KEY, this);
+        super.uninstallListeners();
+    }
+
+    public void mouseClicked(final MouseEvent e) {
+        if (e.getClickCount() < 2) return;
+        if (!splitPane.isOneTouchExpandable()) return;
+
+        final double resizeWeight = splitPane.getResizeWeight();
+        final int paneWidth = splitPane.getWidth();
+        final int divSize = splitPane.getDividerSize();
+        final int divLocation = splitPane.getDividerLocation();
+        final int lastDivLocation = splitPane.getLastDividerLocation();
+
+        // if we are at the far edge
+        if (paneWidth - divSize <= divLocation + 5) {
+            splitPane.setDividerLocation(lastDivLocation);
+            return;
+        }
+
+        // if we are at the starting edge
+        if (divSize >= divLocation - 5) {
+            splitPane.setDividerLocation(lastDivLocation);
+            return;
+        }
+
+        // otherwise, jump to the most "appropriate" end
+        if (resizeWeight > 0.5) {
+            splitPane.setDividerLocation(0);
+        } else {
+            splitPane.setDividerLocation(paneWidth);
+        }
+    }
+
+    public void mouseEntered(final MouseEvent e) { }
+    public void mouseExited(final MouseEvent e) { }
+    public void mousePressed(final MouseEvent e) { }
+    public void mouseReleased(final MouseEvent e) { }
+
+    public void propertyChange(final PropertyChangeEvent evt) {
+        if (!DIVIDER_PAINTER_KEY.equals(evt.getPropertyName())) return;
+
+        final Object value = evt.getNewValue();
+        if (value instanceof Border) {
+            divider.setBorder((Border)value);
+        } else {
+            divider.setBorder(null);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneContrastUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneContrastUI.java
new file mode 100644
index 0000000..46ab9cf
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneContrastUI.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import javax.swing.JComponent;
+import javax.swing.UIManager;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.UIResource;
+import javax.swing.text.View;
+
+import sun.swing.SwingUtilities2;
+
+import apple.laf.JRSUIConstants.*;
+
+public class AquaTabbedPaneContrastUI extends AquaTabbedPaneUI {
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTabbedPaneContrastUI();
+    }
+
+    public AquaTabbedPaneContrastUI() { }
+
+    protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
+        final View v = getTextViewForTab(tabIndex);
+        if (v != null) {
+            v.paint(g2d, textRect);
+            return;
+        }
+
+        if (title == null) return;
+
+        final Color color = tabPane.getForegroundAt(tabIndex);
+        if (color instanceof UIResource) {
+            g2d.setColor(getNonSelectedTabTitleColor());
+            if (tabPane.getSelectedIndex() == tabIndex) {
+                boolean pressed = isPressedAt(tabIndex);
+                boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
+                Color textColor = getSelectedTabTitleColor(enabled, pressed);
+                Color shadowColor = getSelectedTabTitleShadowColor(enabled);
+                AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
+                return;
+            }
+        } else {
+            g2d.setColor(color);
+        }
+        g2d.setFont(font);
+        SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
+    }
+
+    protected static Color getSelectedTabTitleColor(boolean enabled, boolean pressed) {
+        if (enabled && pressed) {
+            return UIManager.getColor("TabbedPane.selectedTabTitlePressedColor");
+        } else if (!enabled) {
+            return UIManager.getColor("TabbedPane.selectedTabTitleDisabledColor");
+        } else {
+            return UIManager.getColor("TabbedPane.selectedTabTitleNormalColor");
+        }
+    }
+
+    protected static Color getSelectedTabTitleShadowColor(boolean enabled) {
+        return enabled ? UIManager.getColor("TabbedPane.selectedTabTitleShadowNormalColor") : UIManager.getColor("TabbedPane.selectedTabTitleShadowDisabledColor");
+    }
+
+    protected static Color getNonSelectedTabTitleColor() {
+        return UIManager.getColor("TabbedPane.nonSelectedTabTitleNormalColor");
+    }
+
+    protected boolean isPressedAt(int index) {
+        return ((MouseHandler)mouseListener).trackingTab == index;
+    }
+
+    protected boolean shouldRepaintSelectedTabOnMouseDown() {
+        return true;
+    }
+
+    protected State getState(final int index, final boolean frameActive, final boolean isSelected) {
+        if (!frameActive) return State.INACTIVE;
+        if (!tabPane.isEnabled()) return State.DISABLED;
+        if (pressedTab == index) return State.PRESSED;
+        return State.ACTIVE;
+    }
+
+    protected SegmentTrailingSeparator getSegmentTrailingSeparator(final int index, final int selectedIndex, final boolean isLeftToRight) {
+        if (isTabBeforeSelectedTab(index, selectedIndex, isLeftToRight)) return SegmentTrailingSeparator.NO;
+        return SegmentTrailingSeparator.YES;
+    }
+
+    protected SegmentLeadingSeparator getSegmentLeadingSeparator(final int index, final int selectedIndex, final boolean isLeftToRight) {
+        if (index == selectedIndex) return SegmentLeadingSeparator.YES;
+        return SegmentLeadingSeparator.NO;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java
new file mode 100644
index 0000000..fdad818
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java
@@ -0,0 +1,3828 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Copy of javax.swing.plaf.basic.BasicTabbedPaneUI because the original
+ * does not have enough private methods marked as protected.
+ *
+ * This copy is from 1.6.0_04 as of 2008-02-02.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.*;
+import javax.swing.text.View;
+
+import sun.swing.*;
+
+public class AquaTabbedPaneCopyFromBasicUI extends TabbedPaneUI implements SwingConstants {
+// Instance variables initialized at installation
+
+    protected JTabbedPane tabPane;
+
+    protected Color highlight;
+    protected Color lightHighlight;
+    protected Color shadow;
+    protected Color darkShadow;
+    protected Color focus;
+    private Color selectedColor;
+
+    protected int textIconGap;
+
+    protected int tabRunOverlay;
+
+    protected Insets tabInsets;
+    protected Insets selectedTabPadInsets;
+    protected Insets tabAreaInsets;
+    protected Insets contentBorderInsets;
+    private boolean tabsOverlapBorder;
+    private boolean tabsOpaque = true;
+    private boolean contentOpaque = true;
+
+    /**
+     * As of Java 2 platform v1.3 this previously undocumented field is no
+     * longer used.
+     * Key bindings are now defined by the LookAndFeel, please refer to
+     * the key bindings specification for further details.
+     *
+     * @deprecated As of Java 2 platform v1.3.
+     */
+    @Deprecated
+    protected KeyStroke upKey;
+    /**
+     * As of Java 2 platform v1.3 this previously undocumented field is no
+     * longer used.
+     * Key bindings are now defined by the LookAndFeel, please refer to
+     * the key bindings specification for further details.
+     *
+     * @deprecated As of Java 2 platform v1.3.
+     */
+    @Deprecated
+    protected KeyStroke downKey;
+    /**
+     * As of Java 2 platform v1.3 this previously undocumented field is no
+     * longer used.
+     * Key bindings are now defined by the LookAndFeel, please refer to
+     * the key bindings specification for further details.
+     *
+     * @deprecated As of Java 2 platform v1.3.
+     */
+    @Deprecated
+    protected KeyStroke leftKey;
+    /**
+     * As of Java 2 platform v1.3 this previously undocumented field is no
+     * longer used.
+     * Key bindings are now defined by the LookAndFeel, please refer to
+     * the key bindings specification for further details.
+     *
+     * @deprecated As of Java 2 platform v1.3.
+     */
+    @Deprecated
+    protected KeyStroke rightKey;
+
+// Transient variables (recalculated each time TabbedPane is layed out)
+
+    protected int tabRuns[] = new int[10];
+    protected int runCount = 0;
+    protected int selectedRun = -1;
+    protected Rectangle rects[] = new Rectangle[0];
+    protected int maxTabHeight;
+    protected int maxTabWidth;
+
+// Listeners
+
+    protected ChangeListener tabChangeListener;
+    protected PropertyChangeListener propertyChangeListener;
+    protected MouseListener mouseListener;
+    protected FocusListener focusListener;
+
+// Private instance data
+
+    private final Insets currentPadInsets = new Insets(0, 0, 0, 0);
+    private final Insets currentTabAreaInsets = new Insets(0, 0, 0, 0);
+
+    private Component visibleComponent;
+    // PENDING(api): See comment for ContainerHandler
+    private Vector<View> htmlViews;
+
+    private Hashtable<Integer, Integer> mnemonicToIndexMap;
+
+    /**
+     * InputMap used for mnemonics. Only non-null if the JTabbedPane has
+     * mnemonics associated with it. Lazily created in initMnemonics.
+     */
+    private InputMap mnemonicInputMap;
+
+    // For use when tabLayoutPolicy = SCROLL_TAB_LAYOUT
+    private ScrollableTabSupport tabScroller;
+
+    private TabContainer tabContainer;
+
+    /**
+     * A rectangle used for general layout calculations in order
+     * to avoid constructing many new Rectangles on the fly.
+     */
+    protected transient Rectangle calcRect = new Rectangle(0, 0, 0, 0);
+
+    /**
+     * Tab that has focus.
+     */
+    private int focusIndex;
+
+    /**
+     * Combined listeners.
+     */
+    private Handler handler;
+
+    /**
+     * Index of the tab the mouse is over.
+     */
+    private int rolloverTabIndex;
+
+    /**
+     * This is set to true when a component is added/removed from the tab
+     * pane and set to false when layout happens.  If true it indicates that
+     * tabRuns is not valid and shouldn't be used.
+     */
+    private boolean isRunsDirty;
+
+    private boolean calculatedBaseline;
+    private int baseline;
+
+// UI creation
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTabbedPaneCopyFromBasicUI();
+    }
+
+    // MACOSX adding accessor for superclass
+    protected Component getTabComponentAt(final int i) {
+        return tabPane.getTabComponentAt(i);
+    }
+    // END MACOSX
+
+    static void loadActionMap(final LazyActionMap map) {
+        map.put(new Actions(Actions.NEXT));
+        map.put(new Actions(Actions.PREVIOUS));
+        map.put(new Actions(Actions.RIGHT));
+        map.put(new Actions(Actions.LEFT));
+        map.put(new Actions(Actions.UP));
+        map.put(new Actions(Actions.DOWN));
+        map.put(new Actions(Actions.PAGE_UP));
+        map.put(new Actions(Actions.PAGE_DOWN));
+        map.put(new Actions(Actions.REQUEST_FOCUS));
+        map.put(new Actions(Actions.REQUEST_FOCUS_FOR_VISIBLE));
+        map.put(new Actions(Actions.SET_SELECTED));
+        map.put(new Actions(Actions.SELECT_FOCUSED));
+        map.put(new Actions(Actions.SCROLL_FORWARD));
+        map.put(new Actions(Actions.SCROLL_BACKWARD));
+    }
+
+// UI Installation/De-installation
+
+    public void installUI(final JComponent c) {
+        this.tabPane = (JTabbedPane)c;
+
+        calculatedBaseline = false;
+        rolloverTabIndex = -1;
+        focusIndex = -1;
+        c.setLayout(createLayoutManager());
+        installComponents();
+        installDefaults();
+        installListeners();
+        installKeyboardActions();
+    }
+
+    public void uninstallUI(final JComponent c) {
+        uninstallKeyboardActions();
+        uninstallListeners();
+        uninstallDefaults();
+        uninstallComponents();
+        c.setLayout(null);
+
+        this.tabPane = null;
+    }
+
+    /**
+     * Invoked by <code>installUI</code> to create
+     * a layout manager object to manage
+     * the <code>JTabbedPane</code>.
+     *
+     * @return a layout manager object
+     *
+     * @see TabbedPaneLayout
+     * @see javax.swing.JTabbedPane#getTabLayoutPolicy
+     */
+    protected LayoutManager createLayoutManager() {
+        if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
+            return new TabbedPaneScrollLayout();
+        } else { /* WRAP_TAB_LAYOUT */
+            return new TabbedPaneLayout();
+        }
+    }
+
+    /* In an attempt to preserve backward compatibility for programs
+     * which have extended BasicTabbedPaneUI to do their own layout, the
+     * UI uses the installed layoutManager (and not tabLayoutPolicy) to
+     * determine if scrollTabLayout is enabled.
+     */
+    boolean scrollableTabLayoutEnabled() {
+        return (tabPane.getLayout() instanceof TabbedPaneScrollLayout);
+    }
+
+    /**
+     * Creates and installs any required subcomponents for the JTabbedPane.
+     * Invoked by installUI.
+     *
+     * @since 1.4
+     */
+    protected void installComponents() {
+        if (scrollableTabLayoutEnabled()) {
+            if (tabScroller == null) {
+                tabScroller = new ScrollableTabSupport(tabPane.getTabPlacement());
+                tabPane.add(tabScroller.viewport);
+            }
+        }
+        installTabContainer();
+    }
+
+    private void installTabContainer() {
+        for (int i = 0; i < tabPane.getTabCount(); i++) {
+            final Component tabComponent = tabPane.getTabComponentAt(i);
+            if (tabComponent != null) {
+                if (tabContainer == null) {
+                    tabContainer = new TabContainer();
+                }
+                tabContainer.add(tabComponent);
+            }
+        }
+        if (tabContainer == null) {
+            return;
+        }
+        if (scrollableTabLayoutEnabled()) {
+            tabScroller.tabPanel.add(tabContainer);
+        } else {
+            tabPane.add(tabContainer);
+        }
+    }
+
+    /**
+     * Creates and returns a JButton that will provide the user
+     * with a way to scroll the tabs in a particular direction. The
+     * returned JButton must be instance of UIResource.
+     *
+     * @param direction One of the SwingConstants constants:
+     * SOUTH, NORTH, EAST or WEST
+     * @return Widget for user to
+     * @see javax.swing.JTabbedPane#setTabPlacement
+     * @see javax.swing.SwingConstants
+     * @throws IllegalArgumentException if direction is not one of
+     *         NORTH, SOUTH, EAST or WEST
+     * @since 1.5
+     */
+    protected JButton createScrollButton(final int direction) {
+        if (direction != SOUTH && direction != NORTH && direction != EAST && direction != WEST) {
+            throw new IllegalArgumentException("Direction must be one of: " + "SOUTH, NORTH, EAST or WEST");
+        }
+        return new ScrollableTabButton(direction);
+    }
+
+    /**
+     * Removes any installed subcomponents from the JTabbedPane.
+     * Invoked by uninstallUI.
+     *
+     * @since 1.4
+     */
+    protected void uninstallComponents() {
+        uninstallTabContainer();
+        if (scrollableTabLayoutEnabled()) {
+            tabPane.remove(tabScroller.viewport);
+            tabPane.remove(tabScroller.scrollForwardButton);
+            tabPane.remove(tabScroller.scrollBackwardButton);
+            tabScroller = null;
+        }
+    }
+
+    private void uninstallTabContainer() {
+        if (tabContainer == null) {
+            return;
+        }
+        // Remove all the tabComponents, making sure not to notify
+        // the tabbedpane.
+        tabContainer.notifyTabbedPane = false;
+        tabContainer.removeAll();
+        if (scrollableTabLayoutEnabled()) {
+            tabContainer.remove(tabScroller.croppedEdge);
+            tabScroller.tabPanel.remove(tabContainer);
+        } else {
+            tabPane.remove(tabContainer);
+        }
+        tabContainer = null;
+    }
+
+    protected void installDefaults() {
+        LookAndFeel.installColorsAndFont(tabPane, "TabbedPane.background", "TabbedPane.foreground", "TabbedPane.font");
+        highlight = UIManager.getColor("TabbedPane.light");
+        lightHighlight = UIManager.getColor("TabbedPane.highlight");
+        shadow = UIManager.getColor("TabbedPane.shadow");
+        darkShadow = UIManager.getColor("TabbedPane.darkShadow");
+        focus = UIManager.getColor("TabbedPane.focus");
+        selectedColor = UIManager.getColor("TabbedPane.selected");
+
+        textIconGap = UIManager.getInt("TabbedPane.textIconGap");
+        tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
+        selectedTabPadInsets = UIManager.getInsets("TabbedPane.selectedTabPadInsets");
+        tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");
+        tabsOverlapBorder = UIManager.getBoolean("TabbedPane.tabsOverlapBorder");
+        contentBorderInsets = UIManager.getInsets("TabbedPane.contentBorderInsets");
+        tabRunOverlay = UIManager.getInt("TabbedPane.tabRunOverlay");
+        tabsOpaque = UIManager.getBoolean("TabbedPane.tabsOpaque");
+        contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque");
+        Object opaque = UIManager.get("TabbedPane.opaque");
+        if (opaque == null) {
+            opaque = Boolean.FALSE;
+        }
+        LookAndFeel.installProperty(tabPane, "opaque", opaque);
+    }
+
+    protected void uninstallDefaults() {
+        highlight = null;
+        lightHighlight = null;
+        shadow = null;
+        darkShadow = null;
+        focus = null;
+        tabInsets = null;
+        selectedTabPadInsets = null;
+        tabAreaInsets = null;
+        contentBorderInsets = null;
+    }
+
+    protected void installListeners() {
+        if ((propertyChangeListener = createPropertyChangeListener()) != null) {
+            tabPane.addPropertyChangeListener(propertyChangeListener);
+        }
+        if ((tabChangeListener = createChangeListener()) != null) {
+            tabPane.addChangeListener(tabChangeListener);
+        }
+        if ((mouseListener = createMouseListener()) != null) {
+            tabPane.addMouseListener(mouseListener);
+        }
+        tabPane.addMouseMotionListener(getHandler());
+        if ((focusListener = createFocusListener()) != null) {
+            tabPane.addFocusListener(focusListener);
+        }
+        tabPane.addContainerListener(getHandler());
+        if (tabPane.getTabCount() > 0) {
+            htmlViews = createHTMLVector();
+        }
+    }
+
+    protected void uninstallListeners() {
+        if (mouseListener != null) {
+            tabPane.removeMouseListener(mouseListener);
+            mouseListener = null;
+        }
+        tabPane.removeMouseMotionListener(getHandler());
+        if (focusListener != null) {
+            tabPane.removeFocusListener(focusListener);
+            focusListener = null;
+        }
+
+        tabPane.removeContainerListener(getHandler());
+        if (htmlViews != null) {
+            htmlViews.removeAllElements();
+            htmlViews = null;
+        }
+        if (tabChangeListener != null) {
+            tabPane.removeChangeListener(tabChangeListener);
+            tabChangeListener = null;
+        }
+        if (propertyChangeListener != null) {
+            tabPane.removePropertyChangeListener(propertyChangeListener);
+            propertyChangeListener = null;
+        }
+        handler = null;
+    }
+
+    protected MouseListener createMouseListener() {
+        return getHandler();
+    }
+
+    protected FocusListener createFocusListener() {
+        return getHandler();
+    }
+
+    protected ChangeListener createChangeListener() {
+        return getHandler();
+    }
+
+    protected PropertyChangeListener createPropertyChangeListener() {
+        return getHandler();
+    }
+
+    private Handler getHandler() {
+        if (handler == null) {
+            handler = new Handler();
+        }
+        return handler;
+    }
+
+    protected void installKeyboardActions() {
+        InputMap km = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+
+        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km);
+        km = getInputMap(JComponent.WHEN_FOCUSED);
+        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, km);
+
+        LazyActionMap.installLazyActionMap(tabPane, AquaTabbedPaneCopyFromBasicUI.class, "TabbedPane.actionMap");
+        updateMnemonics();
+    }
+
+    InputMap getInputMap(final int condition) {
+        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
+            return (InputMap)DefaultLookup.get(tabPane, this, "TabbedPane.ancestorInputMap");
+        } else if (condition == JComponent.WHEN_FOCUSED) {
+            return (InputMap)DefaultLookup.get(tabPane, this, "TabbedPane.focusInputMap");
+        }
+        return null;
+    }
+
+    protected void uninstallKeyboardActions() {
+        SwingUtilities.replaceUIActionMap(tabPane, null);
+        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
+        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, null);
+        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_IN_FOCUSED_WINDOW, null);
+        mnemonicToIndexMap = null;
+        mnemonicInputMap = null;
+    }
+
+    /**
+     * Reloads the mnemonics. This should be invoked when a memonic changes,
+     * when the title of a mnemonic changes, or when tabs are added/removed.
+     */
+    private void updateMnemonics() {
+        resetMnemonics();
+        for (int counter = tabPane.getTabCount() - 1; counter >= 0; counter--) {
+            final int mnemonic = tabPane.getMnemonicAt(counter);
+
+            if (mnemonic > 0) {
+                addMnemonic(counter, mnemonic);
+            }
+        }
+    }
+
+    /**
+     * Resets the mnemonics bindings to an empty state.
+     */
+    private void resetMnemonics() {
+        if (mnemonicToIndexMap != null) {
+            mnemonicToIndexMap.clear();
+            mnemonicInputMap.clear();
+        }
+    }
+
+    /**
+     * Adds the specified mnemonic at the specified index.
+     */
+    private void addMnemonic(final int index, final int mnemonic) {
+        if (mnemonicToIndexMap == null) {
+            initMnemonics();
+        }
+        // [2165820] Mac OS X change: mnemonics need to be triggered with ctrl-option, not just option.
+        mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, Event.ALT_MASK | Event.CTRL_MASK), "setSelectedIndex");
+        mnemonicToIndexMap.put(new Integer(mnemonic), new Integer(index));
+    }
+
+    /**
+     * Installs the state needed for mnemonics.
+     */
+    private void initMnemonics() {
+        mnemonicToIndexMap = new Hashtable<Integer, Integer>();
+        mnemonicInputMap = new ComponentInputMapUIResource(tabPane);
+        mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane, JComponent.WHEN_IN_FOCUSED_WINDOW));
+        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_IN_FOCUSED_WINDOW, mnemonicInputMap);
+    }
+
+    /**
+     * Sets the tab the mouse is over by location. This is a cover method
+     * for <code>setRolloverTab(tabForCoordinate(x, y, false))</code>.
+     */
+    private void setRolloverTab(final int x, final int y) {
+        // NOTE:
+        // This calls in with false otherwise it could trigger a validate,
+        // which should NOT happen if the user is only dragging the
+        // mouse around.
+        setRolloverTab(tabForCoordinate(tabPane, x, y, false));
+    }
+
+    /**
+     * Sets the tab the mouse is currently over to <code>index</code>.
+     * <code>index</code> will be -1 if the mouse is no longer over any
+     * tab. No checking is done to ensure the passed in index identifies a
+     * valid tab.
+     *
+     * @param index Index of the tab the mouse is over.
+     * @since 1.5
+     */
+    protected void setRolloverTab(final int index) {
+        rolloverTabIndex = index;
+    }
+
+    /**
+     * Returns the tab the mouse is currently over, or {@code -1} if the mouse is no
+     * longer over any tab.
+     *
+     * @return the tab the mouse is currently over, or {@code -1} if the mouse is no
+     * longer over any tab
+     * @since 1.5
+     */
+    protected int getRolloverTab() {
+        return rolloverTabIndex;
+    }
+
+    public Dimension getMinimumSize(final JComponent c) {
+        // Default to LayoutManager's minimumLayoutSize
+        return null;
+    }
+
+    public Dimension getMaximumSize(final JComponent c) {
+        // Default to LayoutManager's maximumLayoutSize
+        return null;
+    }
+
+    /**
+     * Returns the baseline.
+     *
+     * @throws NullPointerException {@inheritDoc}
+     * @throws IllegalArgumentException {@inheritDoc}
+     * @see javax.swing.JComponent#getBaseline(int, int)
+     * @since 1.6
+     */
+    public int getBaseline(final JComponent c, final int width, final int height) {
+        super.getBaseline(c, width, height);
+        int baseline = calculateBaselineIfNecessary();
+        if (baseline != -1) {
+            final int placement = tabPane.getTabPlacement();
+            final Insets insets = tabPane.getInsets();
+            final Insets tabAreaInsets = getTabAreaInsets(placement);
+            switch (placement) {
+                case SwingConstants.TOP:
+                    baseline += insets.top + tabAreaInsets.top;
+                    return baseline;
+                case SwingConstants.BOTTOM:
+                    baseline = height - insets.bottom - tabAreaInsets.bottom - maxTabHeight + baseline;
+                    return baseline;
+                case SwingConstants.LEFT:
+                case SwingConstants.RIGHT:
+                    baseline += insets.top + tabAreaInsets.top;
+                    return baseline;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Returns an enum indicating how the baseline of the component
+     * changes as the size changes.
+     *
+     * @throws NullPointerException {@inheritDoc}
+     * @see javax.swing.JComponent#getBaseline(int, int)
+     * @since 1.6
+     */
+    public Component.BaselineResizeBehavior getBaselineResizeBehavior(final JComponent c) {
+        super.getBaselineResizeBehavior(c);
+        switch (tabPane.getTabPlacement()) {
+            case SwingConstants.LEFT:
+            case SwingConstants.RIGHT:
+            case SwingConstants.TOP:
+                return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
+            case SwingConstants.BOTTOM:
+                return Component.BaselineResizeBehavior.CONSTANT_DESCENT;
+        }
+        return Component.BaselineResizeBehavior.OTHER;
+    }
+
+    /**
+     * Returns the baseline for the specified tab.
+     *
+     * @param tab index of tab to get baseline for
+     * @exception IndexOutOfBoundsException if index is out of range
+     *            (index < 0 || index >= tab count)
+     * @return baseline or a value &lt; 0 indicating there is no reasonable
+     *                  baseline
+     * @since 1.6
+     */
+    protected int getBaseline(final int tab) {
+        if (tabPane.getTabComponentAt(tab) != null) {
+            final int offset = getBaselineOffset();
+            if (offset != 0) {
+                // The offset is not applied to the tab component, and so
+                // in general we can't get good alignment like with components
+                // in the tab.
+                return -1;
+            }
+            final Component c = tabPane.getTabComponentAt(tab);
+            final Dimension pref = c.getPreferredSize();
+            final Insets tabInsets = getTabInsets(tabPane.getTabPlacement(), tab);
+            final int cellHeight = maxTabHeight - tabInsets.top - tabInsets.bottom;
+            return c.getBaseline(pref.width, pref.height) + (cellHeight - pref.height) / 2 + tabInsets.top;
+        } else {
+            final View view = getTextViewForTab(tab);
+            if (view != null) {
+                final int viewHeight = (int)view.getPreferredSpan(View.Y_AXIS);
+                final int baseline = BasicHTML.getHTMLBaseline(view, (int)view.getPreferredSpan(View.X_AXIS), viewHeight);
+                if (baseline >= 0) {
+                    return maxTabHeight / 2 - viewHeight / 2 + baseline + getBaselineOffset();
+                }
+                return -1;
+            }
+        }
+        final FontMetrics metrics = getFontMetrics();
+        final int fontHeight = metrics.getHeight();
+        final int fontBaseline = metrics.getAscent();
+        return maxTabHeight / 2 - fontHeight / 2 + fontBaseline + getBaselineOffset();
+    }
+
+    /**
+     * Returns the amount the baseline is offset by.  This is typically
+     * the same as <code>getTabLabelShiftY</code>.
+     *
+     * @return amount to offset the baseline by
+     * @since 1.6
+     */
+    protected int getBaselineOffset() {
+        switch (tabPane.getTabPlacement()) {
+            case SwingConstants.TOP:
+                if (tabPane.getTabCount() > 1) {
+                    return 1;
+                } else {
+                    return -1;
+                }
+            case SwingConstants.BOTTOM:
+                if (tabPane.getTabCount() > 1) {
+                    return -1;
+                } else {
+                    return 1;
+                }
+            default: // RIGHT|LEFT
+                return (maxTabHeight % 2);
+        }
+    }
+
+    private int calculateBaselineIfNecessary() {
+        if (!calculatedBaseline) {
+            calculatedBaseline = true;
+            baseline = -1;
+            if (tabPane.getTabCount() > 0) {
+                calculateBaseline();
+            }
+        }
+        return baseline;
+    }
+
+    private void calculateBaseline() {
+        final int tabCount = tabPane.getTabCount();
+        final int tabPlacement = tabPane.getTabPlacement();
+        maxTabHeight = calculateMaxTabHeight(tabPlacement);
+        baseline = getBaseline(0);
+        if (isHorizontalTabPlacement()) {
+            for (int i = 1; i < tabCount; i++) {
+                if (getBaseline(i) != baseline) {
+                    baseline = -1;
+                    break;
+                }
+            }
+        } else {
+            // left/right, tabs may be different sizes.
+            final FontMetrics fontMetrics = getFontMetrics();
+            final int fontHeight = fontMetrics.getHeight();
+            final int height = calculateTabHeight(tabPlacement, 0, fontHeight);
+            for (int i = 1; i < tabCount; i++) {
+                final int newHeight = calculateTabHeight(tabPlacement, i, fontHeight);
+                if (height != newHeight) {
+                    // assume different baseline
+                    baseline = -1;
+                    break;
+                }
+            }
+        }
+    }
+
+// UI Rendering
+
+    public void paint(final Graphics g, final JComponent c) {
+        final int selectedIndex = tabPane.getSelectedIndex();
+        final int tabPlacement = tabPane.getTabPlacement();
+
+        ensureCurrentLayout();
+
+        // Paint content border and tab area
+        if (tabsOverlapBorder) {
+            paintContentBorder(g, tabPlacement, selectedIndex);
+        }
+        // If scrollable tabs are enabled, the tab area will be
+        // painted by the scrollable tab panel instead.
+        //
+        if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT
+            paintTabArea(g, tabPlacement, selectedIndex);
+        }
+        if (!tabsOverlapBorder) {
+            paintContentBorder(g, tabPlacement, selectedIndex);
+        }
+    }
+
+    /**
+     * Paints the tabs in the tab area.
+     * Invoked by paint().
+     * The graphics parameter must be a valid <code>Graphics</code>
+     * object.  Tab placement may be either:
+     * <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
+     * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
+     * The selected index must be a valid tabbed pane tab index (0 to
+     * tab count - 1, inclusive) or -1 if no tab is currently selected.
+     * The handling of invalid parameters is unspecified.
+     *
+     * @param g the graphics object to use for rendering
+     * @param tabPlacement the placement for the tabs within the JTabbedPane
+     * @param selectedIndex the tab index of the selected component
+     *
+     * @since 1.4
+     */
+    protected void paintTabArea(final Graphics g, final int tabPlacement, final int selectedIndex) {
+        final int tabCount = tabPane.getTabCount();
+
+        final Rectangle iconRect = new Rectangle(), textRect = new Rectangle();
+        final Rectangle clipRect = g.getClipBounds();
+
+        // Paint tabRuns of tabs from back to front
+        for (int i = runCount - 1; i >= 0; i--) {
+            final int start = tabRuns[i];
+            final int next = tabRuns[(i == runCount - 1) ? 0 : i + 1];
+            final int end = (next != 0 ? next - 1 : tabCount - 1);
+            for (int j = start; j <= end; j++) {
+                if (j != selectedIndex && rects[j].intersects(clipRect)) {
+                    paintTab(g, tabPlacement, rects, j, iconRect, textRect);
+                }
+            }
+        }
+
+        // Paint selected tab if its in the front run
+        // since it may overlap other tabs
+        if (selectedIndex >= 0 && rects[selectedIndex].intersects(clipRect)) {
+            paintTab(g, tabPlacement, rects, selectedIndex, iconRect, textRect);
+        }
+    }
+
+    protected void paintTab(final Graphics g, final int tabPlacement, final Rectangle[] rects, final int tabIndex, final Rectangle iconRect, final Rectangle textRect) {
+        final Rectangle tabRect = rects[tabIndex];
+        final int selectedIndex = tabPane.getSelectedIndex();
+        final boolean isSelected = selectedIndex == tabIndex;
+
+        if (tabsOpaque || tabPane.isOpaque()) {
+            paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
+        }
+
+        paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
+
+        final String title = tabPane.getTitleAt(tabIndex);
+        final Font font = tabPane.getFont();
+        final FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
+        final Icon icon = getIconForTab(tabIndex);
+
+        layoutLabel(tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);
+
+        if (tabPane.getTabComponentAt(tabIndex) == null) {
+            String clippedTitle = title;
+
+            if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() && tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
+                final int availTextWidth = tabScroller.croppedEdge.getCropline() - (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
+                clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, availTextWidth);
+            }
+
+            paintText(g, tabPlacement, font, metrics, tabIndex, clippedTitle, textRect, isSelected);
+
+            paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
+        }
+        paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, isSelected);
+    }
+
+    private boolean isHorizontalTabPlacement() {
+        return tabPane.getTabPlacement() == TOP || tabPane.getTabPlacement() == BOTTOM;
+    }
+
+    /* This method will create and return a polygon shape for the given tab rectangle
+     * which has been cropped at the specified cropline with a torn edge visual.
+     * e.g. A "File" tab which has cropped been cropped just after the "i":
+     *             -------------
+     *             |  .....     |
+     *             |  .          |
+     *             |  ...  .    |
+     *             |  .    .   |
+     *             |  .    .    |
+     *             |  .    .     |
+     *             --------------
+     *
+     * The x, y arrays below define the pattern used to create a "torn" edge
+     * segment which is repeated to fill the edge of the tab.
+     * For tabs placed on TOP and BOTTOM, this righthand torn edge is created by
+     * line segments which are defined by coordinates obtained by
+     * subtracting xCropLen[i] from (tab.x + tab.width) and adding yCroplen[i]
+     * to (tab.y).
+     * For tabs placed on LEFT or RIGHT, the bottom torn edge is created by
+     * subtracting xCropLen[i] from (tab.y + tab.height) and adding yCropLen[i]
+     * to (tab.x).
+     */
+    private static int xCropLen[] = { 1, 1, 0, 0, 1, 1, 2, 2 };
+    private static int yCropLen[] = { 0, 3, 3, 6, 6, 9, 9, 12 };
+    private static final int CROP_SEGMENT = 12;
+
+    private static Polygon createCroppedTabShape(final int tabPlacement, final Rectangle tabRect, final int cropline) {
+        int rlen = 0;
+        int start = 0;
+        int end = 0;
+        int ostart = 0;
+
+        switch (tabPlacement) {
+            case LEFT:
+            case RIGHT:
+                rlen = tabRect.width;
+                start = tabRect.x;
+                end = tabRect.x + tabRect.width;
+                ostart = tabRect.y + tabRect.height;
+                break;
+            case TOP:
+            case BOTTOM:
+            default:
+                rlen = tabRect.height;
+                start = tabRect.y;
+                end = tabRect.y + tabRect.height;
+                ostart = tabRect.x + tabRect.width;
+        }
+        int rcnt = rlen / CROP_SEGMENT;
+        if (rlen % CROP_SEGMENT > 0) {
+            rcnt++;
+        }
+        final int npts = 2 + (rcnt * 8);
+        final int xp[] = new int[npts];
+        final int yp[] = new int[npts];
+        int pcnt = 0;
+
+        xp[pcnt] = ostart;
+        yp[pcnt++] = end;
+        xp[pcnt] = ostart;
+        yp[pcnt++] = start;
+        for (int i = 0; i < rcnt; i++) {
+            for (int j = 0; j < xCropLen.length; j++) {
+                xp[pcnt] = cropline - xCropLen[j];
+                yp[pcnt] = start + (i * CROP_SEGMENT) + yCropLen[j];
+                if (yp[pcnt] >= end) {
+                    yp[pcnt] = end;
+                    pcnt++;
+                    break;
+                }
+                pcnt++;
+            }
+        }
+        if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) {
+            return new Polygon(xp, yp, pcnt);
+
+        } else { // LEFT or RIGHT
+            return new Polygon(yp, xp, pcnt);
+        }
+    }
+
+    /* If tabLayoutPolicy == SCROLL_TAB_LAYOUT, this method will paint an edge
+     * indicating the tab is cropped in the viewport display
+     */
+    private void paintCroppedTabEdge(final Graphics g) {
+        final int tabIndex = tabScroller.croppedEdge.getTabIndex();
+        final int cropline = tabScroller.croppedEdge.getCropline();
+        int x, y;
+        switch (tabPane.getTabPlacement()) {
+            case LEFT:
+            case RIGHT:
+                x = rects[tabIndex].x;
+                y = cropline;
+                int xx = x;
+                g.setColor(shadow);
+                while (xx <= x + rects[tabIndex].width) {
+                    for (int i = 0; i < xCropLen.length; i += 2) {
+                        g.drawLine(xx + yCropLen[i], y - xCropLen[i], xx + yCropLen[i + 1] - 1, y - xCropLen[i + 1]);
+                    }
+                    xx += CROP_SEGMENT;
+                }
+                break;
+            case TOP:
+            case BOTTOM:
+            default:
+                x = cropline;
+                y = rects[tabIndex].y;
+                int yy = y;
+                g.setColor(shadow);
+                while (yy <= y + rects[tabIndex].height) {
+                    for (int i = 0; i < xCropLen.length; i += 2) {
+                        g.drawLine(x - xCropLen[i], yy + yCropLen[i], x - xCropLen[i + 1], yy + yCropLen[i + 1] - 1);
+                    }
+                    yy += CROP_SEGMENT;
+                }
+        }
+    }
+
+    protected void layoutLabel(final int tabPlacement, final FontMetrics metrics, final int tabIndex, final String title, final Icon icon, final Rectangle tabRect, final Rectangle iconRect, final Rectangle textRect, final boolean isSelected) {
+        textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
+
+        final View v = getTextViewForTab(tabIndex);
+        if (v != null) {
+            tabPane.putClientProperty("html", v);
+        }
+
+        SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.TRAILING, tabRect, iconRect, textRect, textIconGap);
+
+        tabPane.putClientProperty("html", null);
+
+        final int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
+        final int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
+        iconRect.x += xNudge;
+        iconRect.y += yNudge;
+        textRect.x += xNudge;
+        textRect.y += yNudge;
+    }
+
+    protected void paintIcon(final Graphics g, final int tabPlacement, final int tabIndex, final Icon icon, final Rectangle iconRect, final boolean isSelected) {
+        if (icon != null) {
+            icon.paintIcon(tabPane, g, iconRect.x, iconRect.y);
+        }
+    }
+
+    protected void paintText(final Graphics g, final int tabPlacement, final Font font, final FontMetrics metrics, final int tabIndex, final String title, final Rectangle textRect, final boolean isSelected) {
+
+        g.setFont(font);
+
+        final View v = getTextViewForTab(tabIndex);
+        if (v != null) {
+            // html
+            v.paint(g, textRect);
+        } else {
+            // plain text
+            final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
+
+            if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
+                Color fg = tabPane.getForegroundAt(tabIndex);
+                if (isSelected && (fg instanceof UIResource)) {
+                    final Color selectedFG = UIManager.getColor("TabbedPane.selectedForeground");
+                    if (selectedFG != null) {
+                        fg = selectedFG;
+                    }
+                }
+                g.setColor(fg);
+                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
+
+            } else { // tab disabled
+                g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
+                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
+                g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
+                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
+
+            }
+        }
+    }
+
+    protected int getTabLabelShiftX(final int tabPlacement, final int tabIndex, final boolean isSelected) {
+        final Rectangle tabRect = rects[tabIndex];
+        int nudge = 0;
+        switch (tabPlacement) {
+            case LEFT:
+                nudge = isSelected ? -1 : 1;
+                break;
+            case RIGHT:
+                nudge = isSelected ? 1 : -1;
+                break;
+            case BOTTOM:
+            case TOP:
+            default:
+                nudge = tabRect.width % 2;
+        }
+        return nudge;
+    }
+
+    protected int getTabLabelShiftY(final int tabPlacement, final int tabIndex, final boolean isSelected) {
+        final Rectangle tabRect = rects[tabIndex];
+        int nudge = 0;
+        switch (tabPlacement) {
+            case BOTTOM:
+                nudge = isSelected ? 1 : -1;
+                break;
+            case LEFT:
+            case RIGHT:
+                nudge = tabRect.height % 2;
+                break;
+            case TOP:
+            default:
+                nudge = isSelected ? -1 : 1;
+                ;
+        }
+        return nudge;
+    }
+
+    protected void paintFocusIndicator(final Graphics g, final int tabPlacement, final Rectangle[] rects, final int tabIndex, final Rectangle iconRect, final Rectangle textRect, final boolean isSelected) {
+        final Rectangle tabRect = rects[tabIndex];
+        if (tabPane.hasFocus() && isSelected) {
+            int x, y, w, h;
+            g.setColor(focus);
+            switch (tabPlacement) {
+                case LEFT:
+                    x = tabRect.x + 3;
+                    y = tabRect.y + 3;
+                    w = tabRect.width - 5;
+                    h = tabRect.height - 6;
+                    break;
+                case RIGHT:
+                    x = tabRect.x + 2;
+                    y = tabRect.y + 3;
+                    w = tabRect.width - 5;
+                    h = tabRect.height - 6;
+                    break;
+                case BOTTOM:
+                    x = tabRect.x + 3;
+                    y = tabRect.y + 2;
+                    w = tabRect.width - 6;
+                    h = tabRect.height - 5;
+                    break;
+                case TOP:
+                default:
+                    x = tabRect.x + 3;
+                    y = tabRect.y + 3;
+                    w = tabRect.width - 6;
+                    h = tabRect.height - 5;
+            }
+            BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
+        }
+    }
+
+    /**
+     * this function draws the border around each tab
+     * note that this function does now draw the background of the tab.
+     * that is done elsewhere
+     */
+    protected void paintTabBorder(final Graphics g, final int tabPlacement, final int tabIndex, final int x, final int y, final int w, final int h, final boolean isSelected) {
+        g.setColor(lightHighlight);
+
+        switch (tabPlacement) {
+            case LEFT:
+                g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); // bottom-left highlight
+                g.drawLine(x, y + 2, x, y + h - 3); // left highlight
+                g.drawLine(x + 1, y + 1, x + 1, y + 1); // top-left highlight
+                g.drawLine(x + 2, y, x + w - 1, y); // top highlight
+
+                g.setColor(shadow);
+                g.drawLine(x + 2, y + h - 2, x + w - 1, y + h - 2); // bottom shadow
+
+                g.setColor(darkShadow);
+                g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1); // bottom dark shadow
+                break;
+            case RIGHT:
+                g.drawLine(x, y, x + w - 3, y); // top highlight
+
+                g.setColor(shadow);
+                g.drawLine(x, y + h - 2, x + w - 3, y + h - 2); // bottom shadow
+                g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3); // right shadow
+
+                g.setColor(darkShadow);
+                g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); // top-right dark shadow
+                g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); // bottom-right dark shadow
+                g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3); // right dark shadow
+                g.drawLine(x, y + h - 1, x + w - 3, y + h - 1); // bottom dark shadow
+                break;
+            case BOTTOM:
+                g.drawLine(x, y, x, y + h - 3); // left highlight
+                g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); // bottom-left highlight
+
+                g.setColor(shadow);
+                g.drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2); // bottom shadow
+                g.drawLine(x + w - 2, y, x + w - 2, y + h - 3); // right shadow
+
+                g.setColor(darkShadow);
+                g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); // bottom dark shadow
+                g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); // bottom-right dark shadow
+                g.drawLine(x + w - 1, y, x + w - 1, y + h - 3); // right dark shadow
+                break;
+            case TOP:
+            default:
+                g.drawLine(x, y + 2, x, y + h - 1); // left highlight
+                g.drawLine(x + 1, y + 1, x + 1, y + 1); // top-left highlight
+                g.drawLine(x + 2, y, x + w - 3, y); // top highlight
+
+                g.setColor(shadow);
+                g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 1); // right shadow
+
+                g.setColor(darkShadow);
+                g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1); // right dark-shadow
+                g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); // top-right shadow
+        }
+    }
+
+    protected void paintTabBackground(final Graphics g, final int tabPlacement, final int tabIndex, final int x, final int y, final int w, final int h, boolean isSelected) {
+        g.setColor(!isSelected || selectedColor == null ? tabPane.getBackgroundAt(tabIndex) : selectedColor);
+        switch (tabPlacement) {
+            case LEFT:
+                g.fillRect(x + 1, y + 1, w - 1, h - 3);
+                break;
+            case RIGHT:
+                g.fillRect(x, y + 1, w - 2, h - 3);
+                break;
+            case BOTTOM:
+                g.fillRect(x + 1, y, w - 3, h - 1);
+                break;
+            case TOP:
+            default:
+                g.fillRect(x + 1, y + 1, w - 3, h - 1);
+        }
+    }
+
+    protected void paintContentBorder(final Graphics g, final int tabPlacement, final int selectedIndex) {
+        final int width = tabPane.getWidth();
+        final int height = tabPane.getHeight();
+        final Insets insets = tabPane.getInsets();
+        final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
+
+        int x = insets.left;
+        int y = insets.top;
+        int w = width - insets.right - insets.left;
+        int h = height - insets.top - insets.bottom;
+
+        switch (tabPlacement) {
+            case LEFT:
+                x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
+                if (tabsOverlapBorder) {
+                    x -= tabAreaInsets.right;
+                }
+                w -= (x - insets.left);
+                break;
+            case RIGHT:
+                w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
+                if (tabsOverlapBorder) {
+                    w += tabAreaInsets.left;
+                }
+                break;
+            case BOTTOM:
+                h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
+                if (tabsOverlapBorder) {
+                    h += tabAreaInsets.top;
+                }
+                break;
+            case TOP:
+            default:
+                y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
+                if (tabsOverlapBorder) {
+                    y -= tabAreaInsets.bottom;
+                }
+                h -= (y - insets.top);
+        }
+
+        if (tabPane.getTabCount() > 0 && (contentOpaque || tabPane.isOpaque())) {
+            // Fill region behind content area
+            final Color color = UIManager.getColor("TabbedPane.contentAreaColor");
+            if (color != null) {
+                g.setColor(color);
+            } else if (selectedColor == null || selectedIndex == -1) {
+                g.setColor(tabPane.getBackground());
+            } else {
+                g.setColor(selectedColor);
+            }
+            g.fillRect(x, y, w, h);
+        }
+
+        paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
+        paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
+        paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
+        paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
+
+    }
+
+    protected void paintContentBorderTopEdge(final Graphics g, final int tabPlacement, final int selectedIndex, final int x, final int y, final int w, final int h) {
+        final Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
+
+        g.setColor(lightHighlight);
+
+        // Draw unbroken line if tabs are not on TOP, OR
+        // selected tab is not in run adjacent to content, OR
+        // selected tab is not visible (SCROLL_TAB_LAYOUT)
+        //
+        if (tabPlacement != TOP || selectedIndex < 0 || (selRect.y + selRect.height + 1 < y) || (selRect.x < x || selRect.x > x + w)) {
+            g.drawLine(x, y, x + w - 2, y);
+        } else {
+            // Break line to show visual connection to selected tab
+            g.drawLine(x, y, selRect.x - 1, y);
+            if (selRect.x + selRect.width < x + w - 2) {
+                g.drawLine(selRect.x + selRect.width, y, x + w - 2, y);
+            } else {
+                g.setColor(shadow);
+                g.drawLine(x + w - 2, y, x + w - 2, y);
+            }
+        }
+    }
+
+    protected void paintContentBorderLeftEdge(final Graphics g, final int tabPlacement, final int selectedIndex, final int x, final int y, final int w, final int h) {
+        final Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
+
+        g.setColor(lightHighlight);
+
+        // Draw unbroken line if tabs are not on LEFT, OR
+        // selected tab is not in run adjacent to content, OR
+        // selected tab is not visible (SCROLL_TAB_LAYOUT)
+        //
+        if (tabPlacement != LEFT || selectedIndex < 0 || (selRect.x + selRect.width + 1 < x) || (selRect.y < y || selRect.y > y + h)) {
+            g.drawLine(x, y, x, y + h - 2);
+        } else {
+            // Break line to show visual connection to selected tab
+            g.drawLine(x, y, x, selRect.y - 1);
+            if (selRect.y + selRect.height < y + h - 2) {
+                g.drawLine(x, selRect.y + selRect.height, x, y + h - 2);
+            }
+        }
+    }
+
+    protected void paintContentBorderBottomEdge(final Graphics g, final int tabPlacement, final int selectedIndex, final int x, final int y, final int w, final int h) {
+        final Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
+
+        g.setColor(shadow);
+
+        // Draw unbroken line if tabs are not on BOTTOM, OR
+        // selected tab is not in run adjacent to content, OR
+        // selected tab is not visible (SCROLL_TAB_LAYOUT)
+        //
+        if (tabPlacement != BOTTOM || selectedIndex < 0 || (selRect.y - 1 > h) || (selRect.x < x || selRect.x > x + w)) {
+            g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
+            g.setColor(darkShadow);
+            g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
+        } else {
+            // Break line to show visual connection to selected tab
+            g.drawLine(x + 1, y + h - 2, selRect.x - 1, y + h - 2);
+            g.setColor(darkShadow);
+            g.drawLine(x, y + h - 1, selRect.x - 1, y + h - 1);
+            if (selRect.x + selRect.width < x + w - 2) {
+                g.setColor(shadow);
+                g.drawLine(selRect.x + selRect.width, y + h - 2, x + w - 2, y + h - 2);
+                g.setColor(darkShadow);
+                g.drawLine(selRect.x + selRect.width, y + h - 1, x + w - 1, y + h - 1);
+            }
+        }
+
+    }
+
+    protected void paintContentBorderRightEdge(final Graphics g, final int tabPlacement, final int selectedIndex, final int x, final int y, final int w, final int h) {
+        final Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
+
+        g.setColor(shadow);
+
+        // Draw unbroken line if tabs are not on RIGHT, OR
+        // selected tab is not in run adjacent to content, OR
+        // selected tab is not visible (SCROLL_TAB_LAYOUT)
+        //
+        if (tabPlacement != RIGHT || selectedIndex < 0 || (selRect.x - 1 > w) || (selRect.y < y || selRect.y > y + h)) {
+            g.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 3);
+            g.setColor(darkShadow);
+            g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
+        } else {
+            // Break line to show visual connection to selected tab
+            g.drawLine(x + w - 2, y + 1, x + w - 2, selRect.y - 1);
+            g.setColor(darkShadow);
+            g.drawLine(x + w - 1, y, x + w - 1, selRect.y - 1);
+
+            if (selRect.y + selRect.height < y + h - 2) {
+                g.setColor(shadow);
+                g.drawLine(x + w - 2, selRect.y + selRect.height, x + w - 2, y + h - 2);
+                g.setColor(darkShadow);
+                g.drawLine(x + w - 1, selRect.y + selRect.height, x + w - 1, y + h - 2);
+            }
+        }
+    }
+
+    protected void ensureCurrentLayout() {
+        if (!tabPane.isValid()) {
+            tabPane.validate();
+        }
+        /* If tabPane doesn't have a peer yet, the validate() call will
+         * silently fail.  We handle that by forcing a layout if tabPane
+         * is still invalid.  See bug 4237677.
+         */
+        if (!tabPane.isValid()) {
+            final TabbedPaneLayout layout = (TabbedPaneLayout)tabPane.getLayout();
+            layout.calculateLayoutInfo();
+        }
+    }
+
+// TabbedPaneUI methods
+
+    /**
+     * Returns the bounds of the specified tab index.  The bounds are
+     * with respect to the JTabbedPane's coordinate space.
+     */
+    public Rectangle getTabBounds(final JTabbedPane pane, final int i) {
+        ensureCurrentLayout();
+        final Rectangle tabRect = new Rectangle();
+        return getTabBounds(i, tabRect);
+    }
+
+    public int getTabRunCount(final JTabbedPane pane) {
+        ensureCurrentLayout();
+        return runCount;
+    }
+
+    /**
+     * Returns the tab index which intersects the specified point
+     * in the JTabbedPane's coordinate space.
+     */
+    public int tabForCoordinate(final JTabbedPane pane, final int x, final int y) {
+        return tabForCoordinate(pane, x, y, true);
+    }
+
+    private int tabForCoordinate(final JTabbedPane pane, final int x, final int y, final boolean validateIfNecessary) {
+        if (validateIfNecessary) {
+            ensureCurrentLayout();
+        }
+        if (isRunsDirty) {
+            // We didn't recalculate the layout, runs and tabCount may not
+            // line up, bail.
+            return -1;
+        }
+        final Point p = new Point(x, y);
+
+        if (scrollableTabLayoutEnabled()) {
+            translatePointToTabPanel(x, y, p);
+            final Rectangle viewRect = tabScroller.viewport.getViewRect();
+            if (!viewRect.contains(p)) {
+                return -1;
+            }
+        }
+        final int tabCount = tabPane.getTabCount();
+        for (int i = 0; i < tabCount; i++) {
+            if (rects[i].contains(p.x, p.y)) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Returns the bounds of the specified tab in the coordinate space
+     * of the JTabbedPane component.  This is required because the tab rects
+     * are by default defined in the coordinate space of the component where
+     * they are rendered, which could be the JTabbedPane
+     * (for WRAP_TAB_LAYOUT) or a ScrollableTabPanel (SCROLL_TAB_LAYOUT).
+     * This method should be used whenever the tab rectangle must be relative
+     * to the JTabbedPane itself and the result should be placed in a
+     * designated Rectangle object (rather than instantiating and returning
+     * a new Rectangle each time). The tab index parameter must be a valid
+     * tabbed pane tab index (0 to tab count - 1, inclusive).  The destination
+     * rectangle parameter must be a valid <code>Rectangle</code> instance.
+     * The handling of invalid parameters is unspecified.
+     *
+     * @param tabIndex the index of the tab
+     * @param dest the rectangle where the result should be placed
+     * @return the resulting rectangle
+     *
+     * @since 1.4
+     */
+    protected Rectangle getTabBounds(final int tabIndex, final Rectangle dest) {
+        dest.width = rects[tabIndex].width;
+        dest.height = rects[tabIndex].height;
+
+        if (scrollableTabLayoutEnabled()) { // SCROLL_TAB_LAYOUT
+            // Need to translate coordinates based on viewport location &
+            // view position
+            final Point vpp = tabScroller.viewport.getLocation();
+            final Point viewp = tabScroller.viewport.getViewPosition();
+            dest.x = rects[tabIndex].x + vpp.x - viewp.x;
+            dest.y = rects[tabIndex].y + vpp.y - viewp.y;
+
+        } else { // WRAP_TAB_LAYOUT
+            dest.x = rects[tabIndex].x;
+            dest.y = rects[tabIndex].y;
+        }
+        return dest;
+    }
+
+    /**
+     * Returns the index of the tab closest to the passed in location, note
+     * that the returned tab may not contain the location x,y.
+     */
+    private int getClosestTab(final int x, final int y) {
+        int min = 0;
+        final int tabCount = Math.min(rects.length, tabPane.getTabCount());
+        int max = tabCount;
+        final int tabPlacement = tabPane.getTabPlacement();
+        final boolean useX = (tabPlacement == TOP || tabPlacement == BOTTOM);
+        final int want = (useX) ? x : y;
+
+        while (min != max) {
+            final int current = (max + min) / 2;
+            int minLoc;
+            int maxLoc;
+
+            if (useX) {
+                minLoc = rects[current].x;
+                maxLoc = minLoc + rects[current].width;
+            } else {
+                minLoc = rects[current].y;
+                maxLoc = minLoc + rects[current].height;
+            }
+            if (want < minLoc) {
+                max = current;
+                if (min == max) {
+                    return Math.max(0, current - 1);
+                }
+            } else if (want >= maxLoc) {
+                min = current;
+                if (max - min <= 1) {
+                    return Math.max(current + 1, tabCount - 1);
+                }
+            } else {
+                return current;
+            }
+        }
+        return min;
+    }
+
+    /**
+     * Returns a point which is translated from the specified point in the
+     * JTabbedPane's coordinate space to the coordinate space of the
+     * ScrollableTabPanel.  This is used for SCROLL_TAB_LAYOUT ONLY.
+     */
+    private Point translatePointToTabPanel(final int srcx, final int srcy, final Point dest) {
+        final Point vpp = tabScroller.viewport.getLocation();
+        final Point viewp = tabScroller.viewport.getViewPosition();
+        dest.x = srcx - vpp.x + viewp.x;
+        dest.y = srcy - vpp.y + viewp.y;
+        return dest;
+    }
+
+// BasicTabbedPaneUI methods
+
+    protected Component getVisibleComponent() {
+        return visibleComponent;
+    }
+
+    protected void setVisibleComponent(final Component component) {
+        if (visibleComponent != null && visibleComponent != component && visibleComponent.getParent() == tabPane && visibleComponent.isVisible()) {
+
+            visibleComponent.setVisible(false);
+        }
+        if (component != null && !component.isVisible()) {
+            component.setVisible(true);
+        }
+        visibleComponent = component;
+    }
+
+    protected void assureRectsCreated(final int tabCount) {
+        final int rectArrayLen = rects.length;
+        if (tabCount != rectArrayLen) {
+            final Rectangle[] tempRectArray = new Rectangle[tabCount];
+            System.arraycopy(rects, 0, tempRectArray, 0, Math.min(rectArrayLen, tabCount));
+            rects = tempRectArray;
+            for (int rectIndex = rectArrayLen; rectIndex < tabCount; rectIndex++) {
+                rects[rectIndex] = new Rectangle();
+            }
+        }
+
+    }
+
+    protected void expandTabRunsArray() {
+        final int rectLen = tabRuns.length;
+        final int[] newArray = new int[rectLen + 10];
+        System.arraycopy(tabRuns, 0, newArray, 0, runCount);
+        tabRuns = newArray;
+    }
+
+    protected int getRunForTab(final int tabCount, final int tabIndex) {
+        for (int i = 0; i < runCount; i++) {
+            final int first = tabRuns[i];
+            final int last = lastTabInRun(tabCount, i);
+            if (tabIndex >= first && tabIndex <= last) {
+                return i;
+            }
+        }
+        return 0;
+    }
+
+    protected int lastTabInRun(final int tabCount, final int run) {
+        if (runCount == 1) {
+            return tabCount - 1;
+        }
+        final int nextRun = (run == runCount - 1 ? 0 : run + 1);
+        if (tabRuns[nextRun] == 0) {
+            return tabCount - 1;
+        }
+        return tabRuns[nextRun] - 1;
+    }
+
+    protected int getTabRunOverlay(final int tabPlacement) {
+        return tabRunOverlay;
+    }
+
+    protected int getTabRunIndent(final int tabPlacement, final int run) {
+        return 0;
+    }
+
+    protected boolean shouldPadTabRun(final int tabPlacement, final int run) {
+        return runCount > 1;
+    }
+
+    protected boolean shouldRotateTabRuns(final int tabPlacement) {
+        return true;
+    }
+
+    protected Icon getIconForTab(final int tabIndex) {
+        return (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex)) ? tabPane.getDisabledIconAt(tabIndex) : tabPane.getIconAt(tabIndex);
+    }
+
+    /**
+     * Returns the text View object required to render stylized text (HTML) for
+     * the specified tab or null if no specialized text rendering is needed
+     * for this tab. This is provided to support html rendering inside tabs.
+     *
+     * @param tabIndex the index of the tab
+     * @return the text view to render the tab's text or null if no
+     *         specialized rendering is required
+     *
+     * @since 1.4
+     */
+    protected View getTextViewForTab(final int tabIndex) {
+        if (htmlViews != null) {
+            return htmlViews.elementAt(tabIndex);
+        }
+        return null;
+    }
+
+    protected int calculateTabHeight(final int tabPlacement, final int tabIndex, final int fontHeight) {
+        int height = 0;
+        final Component c = tabPane.getTabComponentAt(tabIndex);
+        if (c != null) {
+            height = c.getPreferredSize().height;
+        } else {
+            final View v = getTextViewForTab(tabIndex);
+            if (v != null) {
+                // html
+                height += (int)v.getPreferredSpan(View.Y_AXIS);
+            } else {
+                // plain text
+                height += fontHeight;
+            }
+            final Icon icon = getIconForTab(tabIndex);
+
+            if (icon != null) {
+                height = Math.max(height, icon.getIconHeight());
+            }
+        }
+        final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
+        height += tabInsets.top + tabInsets.bottom + 2;
+        return height;
+    }
+
+    protected int calculateMaxTabHeight(final int tabPlacement) {
+        final FontMetrics metrics = getFontMetrics();
+        final int tabCount = tabPane.getTabCount();
+        int result = 0;
+        final int fontHeight = metrics.getHeight();
+        for (int i = 0; i < tabCount; i++) {
+            result = Math.max(calculateTabHeight(tabPlacement, i, fontHeight), result);
+        }
+        return result;
+    }
+
+    protected int calculateTabWidth(final int tabPlacement, final int tabIndex, final FontMetrics metrics) {
+        final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
+        int width = tabInsets.left + tabInsets.right + 3;
+        final Component tabComponent = tabPane.getTabComponentAt(tabIndex);
+        if (tabComponent != null) {
+            width += tabComponent.getPreferredSize().width;
+        } else {
+            final Icon icon = getIconForTab(tabIndex);
+            if (icon != null) {
+                width += icon.getIconWidth() + textIconGap;
+            }
+            final View v = getTextViewForTab(tabIndex);
+            if (v != null) {
+                // html
+                width += (int)v.getPreferredSpan(View.X_AXIS);
+            } else {
+                // plain text
+                final String title = tabPane.getTitleAt(tabIndex);
+                width += SwingUtilities2.stringWidth(tabPane, metrics, title);
+            }
+        }
+        return width;
+    }
+
+    protected int calculateMaxTabWidth(final int tabPlacement) {
+        final FontMetrics metrics = getFontMetrics();
+        final int tabCount = tabPane.getTabCount();
+        int result = 0;
+        for (int i = 0; i < tabCount; i++) {
+            result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
+        }
+        return result;
+    }
+
+    protected int calculateTabAreaHeight(final int tabPlacement, final int horizRunCount, final int maxTabHeight) {
+        final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
+        final int tabRunOverlay = getTabRunOverlay(tabPlacement);
+        return (horizRunCount > 0 ? horizRunCount * (maxTabHeight - tabRunOverlay) + tabRunOverlay + tabAreaInsets.top + tabAreaInsets.bottom : 0);
+    }
+
+    protected int calculateTabAreaWidth(final int tabPlacement, final int vertRunCount, final int maxTabWidth) {
+        final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
+        final int tabRunOverlay = getTabRunOverlay(tabPlacement);
+        return (vertRunCount > 0 ? vertRunCount * (maxTabWidth - tabRunOverlay) + tabRunOverlay + tabAreaInsets.left + tabAreaInsets.right : 0);
+    }
+
+    protected Insets getTabInsets(final int tabPlacement, final int tabIndex) {
+        return tabInsets;
+    }
+
+    protected Insets getSelectedTabPadInsets(final int tabPlacement) {
+        rotateInsets(selectedTabPadInsets, currentPadInsets, tabPlacement);
+        return currentPadInsets;
+    }
+
+    protected Insets getTabAreaInsets(final int tabPlacement) {
+        rotateInsets(tabAreaInsets, currentTabAreaInsets, tabPlacement);
+        return currentTabAreaInsets;
+    }
+
+    protected Insets getContentBorderInsets(final int tabPlacement) {
+        return contentBorderInsets;
+    }
+
+    protected FontMetrics getFontMetrics() {
+        final Font font = tabPane.getFont();
+        return tabPane.getFontMetrics(font);
+    }
+
+// Tab Navigation methods
+
+    protected void navigateSelectedTab(final int direction) {
+        final int tabPlacement = tabPane.getTabPlacement();
+        final int current = DefaultLookup.getBoolean(tabPane, this, "TabbedPane.selectionFollowsFocus", true) ? tabPane.getSelectedIndex() : getFocusIndex();
+        final int tabCount = tabPane.getTabCount();
+        final boolean leftToRight = AquaUtils.isLeftToRight(tabPane);
+
+        // If we have no tabs then don't navigate.
+        if (tabCount <= 0) {
+            return;
+        }
+
+        int offset;
+        switch (tabPlacement) {
+            case LEFT:
+            case RIGHT:
+                switch (direction) {
+                    case NEXT:
+                        selectNextTab(current);
+                        break;
+                    case PREVIOUS:
+                        selectPreviousTab(current);
+                        break;
+                    case NORTH:
+                        selectPreviousTabInRun(current);
+                        break;
+                    case SOUTH:
+                        selectNextTabInRun(current);
+                        break;
+                    case WEST:
+                        offset = getTabRunOffset(tabPlacement, tabCount, current, false);
+                        selectAdjacentRunTab(tabPlacement, current, offset);
+                        break;
+                    case EAST:
+                        offset = getTabRunOffset(tabPlacement, tabCount, current, true);
+                        selectAdjacentRunTab(tabPlacement, current, offset);
+                        break;
+                    default:
+                }
+                break;
+            case BOTTOM:
+            case TOP:
+            default:
+                switch (direction) {
+                    case NEXT:
+                        selectNextTab(current);
+                        break;
+                    case PREVIOUS:
+                        selectPreviousTab(current);
+                        break;
+                    case NORTH:
+                        offset = getTabRunOffset(tabPlacement, tabCount, current, false);
+                        selectAdjacentRunTab(tabPlacement, current, offset);
+                        break;
+                    case SOUTH:
+                        offset = getTabRunOffset(tabPlacement, tabCount, current, true);
+                        selectAdjacentRunTab(tabPlacement, current, offset);
+                        break;
+                    case EAST:
+                        if (leftToRight) {
+                            selectNextTabInRun(current);
+                        } else {
+                            selectPreviousTabInRun(current);
+                        }
+                        break;
+                    case WEST:
+                        if (leftToRight) {
+                            selectPreviousTabInRun(current);
+                        } else {
+                            selectNextTabInRun(current);
+                        }
+                        break;
+                    default:
+                }
+        }
+    }
+
+    protected void selectNextTabInRun(final int current) {
+        final int tabCount = tabPane.getTabCount();
+        int tabIndex = getNextTabIndexInRun(tabCount, current);
+
+        while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
+            tabIndex = getNextTabIndexInRun(tabCount, tabIndex);
+        }
+        navigateTo(tabIndex);
+    }
+
+    protected void selectPreviousTabInRun(final int current) {
+        final int tabCount = tabPane.getTabCount();
+        int tabIndex = getPreviousTabIndexInRun(tabCount, current);
+
+        while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
+            tabIndex = getPreviousTabIndexInRun(tabCount, tabIndex);
+        }
+        navigateTo(tabIndex);
+    }
+
+    protected void selectNextTab(final int current) {
+        int tabIndex = getNextTabIndex(current);
+
+        while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
+            tabIndex = getNextTabIndex(tabIndex);
+        }
+        navigateTo(tabIndex);
+    }
+
+    protected void selectPreviousTab(final int current) {
+        int tabIndex = getPreviousTabIndex(current);
+
+        while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
+            tabIndex = getPreviousTabIndex(tabIndex);
+        }
+        navigateTo(tabIndex);
+    }
+
+    protected void selectAdjacentRunTab(final int tabPlacement, final int tabIndex, final int offset) {
+        if (runCount < 2) {
+            return;
+        }
+        int newIndex;
+        final Rectangle r = rects[tabIndex];
+        switch (tabPlacement) {
+            case LEFT:
+            case RIGHT:
+                newIndex = tabForCoordinate(tabPane, r.x + r.width / 2 + offset, r.y + r.height / 2);
+                break;
+            case BOTTOM:
+            case TOP:
+            default:
+                newIndex = tabForCoordinate(tabPane, r.x + r.width / 2, r.y + r.height / 2 + offset);
+        }
+        if (newIndex != -1) {
+            while (!tabPane.isEnabledAt(newIndex) && newIndex != tabIndex) {
+                newIndex = getNextTabIndex(newIndex);
+            }
+            navigateTo(newIndex);
+        }
+    }
+
+    private void navigateTo(final int index) {
+        if (DefaultLookup.getBoolean(tabPane, this, "TabbedPane.selectionFollowsFocus", true)) {
+            tabPane.setSelectedIndex(index);
+        } else {
+            // Just move focus (not selection)
+            setFocusIndex(index, true);
+        }
+    }
+
+    void setFocusIndex(final int index, final boolean repaint) {
+        if (repaint && !isRunsDirty) {
+            repaintTab(focusIndex);
+            focusIndex = index;
+            repaintTab(focusIndex);
+        } else {
+            focusIndex = index;
+        }
+    }
+
+    /**
+     * Repaints the specified tab.
+     */
+    private void repaintTab(final int index) {
+        // If we're not valid that means we will shortly be validated and
+        // painted, which means we don't have to do anything here.
+        if (!isRunsDirty && index >= 0 && index < tabPane.getTabCount()) {
+            tabPane.repaint(getTabBounds(tabPane, index));
+        }
+    }
+
+    /**
+     * Makes sure the focusIndex is valid.
+     */
+    private void validateFocusIndex() {
+        if (focusIndex >= tabPane.getTabCount()) {
+            setFocusIndex(tabPane.getSelectedIndex(), false);
+        }
+    }
+
+    /**
+     * Returns the index of the tab that has focus.
+     *
+     * @return index of tab that has focus
+     * @since 1.5
+     */
+    protected int getFocusIndex() {
+        return focusIndex;
+    }
+
+    protected int getTabRunOffset(final int tabPlacement, final int tabCount, final int tabIndex, final boolean forward) {
+        final int run = getRunForTab(tabCount, tabIndex);
+        int offset;
+        switch (tabPlacement) {
+            case LEFT: {
+                if (run == 0) {
+                    offset = (forward ? -(calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth) - maxTabWidth) : -maxTabWidth);
+
+                } else if (run == runCount - 1) {
+                    offset = (forward ? maxTabWidth : calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth) - maxTabWidth);
+                } else {
+                    offset = (forward ? maxTabWidth : -maxTabWidth);
+                }
+                break;
+            }
+            case RIGHT: {
+                if (run == 0) {
+                    offset = (forward ? maxTabWidth : calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth) - maxTabWidth);
+                } else if (run == runCount - 1) {
+                    offset = (forward ? -(calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth) - maxTabWidth) : -maxTabWidth);
+                } else {
+                    offset = (forward ? maxTabWidth : -maxTabWidth);
+                }
+                break;
+            }
+            case BOTTOM: {
+                if (run == 0) {
+                    offset = (forward ? maxTabHeight : calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight) - maxTabHeight);
+                } else if (run == runCount - 1) {
+                    offset = (forward ? -(calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight) - maxTabHeight) : -maxTabHeight);
+                } else {
+                    offset = (forward ? maxTabHeight : -maxTabHeight);
+                }
+                break;
+            }
+            case TOP:
+            default: {
+                if (run == 0) {
+                    offset = (forward ? -(calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight) - maxTabHeight) : -maxTabHeight);
+                } else if (run == runCount - 1) {
+                    offset = (forward ? maxTabHeight : calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight) - maxTabHeight);
+                } else {
+                    offset = (forward ? maxTabHeight : -maxTabHeight);
+                }
+            }
+        }
+        return offset;
+    }
+
+    protected int getPreviousTabIndex(final int base) {
+        final int tabIndex = (base - 1 >= 0 ? base - 1 : tabPane.getTabCount() - 1);
+        return (tabIndex >= 0 ? tabIndex : 0);
+    }
+
+    protected int getNextTabIndex(final int base) {
+        return (base + 1) % tabPane.getTabCount();
+    }
+
+    protected int getNextTabIndexInRun(final int tabCount, final int base) {
+        if (runCount < 2) {
+            return getNextTabIndex(base);
+        }
+        final int currentRun = getRunForTab(tabCount, base);
+        final int next = getNextTabIndex(base);
+        if (next == tabRuns[getNextTabRun(currentRun)]) {
+            return tabRuns[currentRun];
+        }
+        return next;
+    }
+
+    protected int getPreviousTabIndexInRun(final int tabCount, final int base) {
+        if (runCount < 2) {
+            return getPreviousTabIndex(base);
+        }
+        final int currentRun = getRunForTab(tabCount, base);
+        if (base == tabRuns[currentRun]) {
+            final int previous = tabRuns[getNextTabRun(currentRun)] - 1;
+            return (previous != -1 ? previous : tabCount - 1);
+        }
+        return getPreviousTabIndex(base);
+    }
+
+    protected int getPreviousTabRun(final int baseRun) {
+        final int runIndex = (baseRun - 1 >= 0 ? baseRun - 1 : runCount - 1);
+        return (runIndex >= 0 ? runIndex : 0);
+    }
+
+    protected int getNextTabRun(final int baseRun) {
+        return (baseRun + 1) % runCount;
+    }
+
+    protected static void rotateInsets(final Insets topInsets, final Insets targetInsets, final int targetPlacement) {
+
+        switch (targetPlacement) {
+            case LEFT:
+                targetInsets.top = topInsets.left;
+                targetInsets.left = topInsets.top;
+                targetInsets.bottom = topInsets.right;
+                targetInsets.right = topInsets.bottom;
+                break;
+            case BOTTOM:
+                targetInsets.top = topInsets.bottom;
+                targetInsets.left = topInsets.left;
+                targetInsets.bottom = topInsets.top;
+                targetInsets.right = topInsets.right;
+                break;
+            case RIGHT:
+                targetInsets.top = topInsets.left;
+                targetInsets.left = topInsets.bottom;
+                targetInsets.bottom = topInsets.right;
+                targetInsets.right = topInsets.top;
+                break;
+            case TOP:
+            default:
+                targetInsets.top = topInsets.top;
+                targetInsets.left = topInsets.left;
+                targetInsets.bottom = topInsets.bottom;
+                targetInsets.right = topInsets.right;
+        }
+    }
+
+    // REMIND(aim,7/29/98): This method should be made
+    // protected in the next release where
+    // API changes are allowed
+    boolean requestFocusForVisibleComponent() {
+        return SwingUtilities2.tabbedPaneChangeFocusTo(getVisibleComponent());
+    }
+
+    private static class Actions extends UIAction {
+        final static String NEXT = "navigateNext";
+        final static String PREVIOUS = "navigatePrevious";
+        final static String RIGHT = "navigateRight";
+        final static String LEFT = "navigateLeft";
+        final static String UP = "navigateUp";
+        final static String DOWN = "navigateDown";
+        final static String PAGE_UP = "navigatePageUp";
+        final static String PAGE_DOWN = "navigatePageDown";
+        final static String REQUEST_FOCUS = "requestFocus";
+        final static String REQUEST_FOCUS_FOR_VISIBLE = "requestFocusForVisibleComponent";
+        final static String SET_SELECTED = "setSelectedIndex";
+        final static String SELECT_FOCUSED = "selectTabWithFocus";
+        final static String SCROLL_FORWARD = "scrollTabsForwardAction";
+        final static String SCROLL_BACKWARD = "scrollTabsBackwardAction";
+
+        Actions(final String key) {
+            super(key);
+        }
+
+        static Object getUIOfType(final ComponentUI ui, final Class<AquaTabbedPaneCopyFromBasicUI> klass) {
+            if (klass.isInstance(ui)) {
+                return ui;
+            }
+            return null;
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            final String key = getName();
+            final JTabbedPane pane = (JTabbedPane)e.getSource();
+            final AquaTabbedPaneCopyFromBasicUI ui = (AquaTabbedPaneCopyFromBasicUI)getUIOfType(pane.getUI(), AquaTabbedPaneCopyFromBasicUI.class);
+
+            if (ui == null) {
+                return;
+            }
+
+            if (key == NEXT) {
+                ui.navigateSelectedTab(SwingConstants.NEXT);
+            } else if (key == PREVIOUS) {
+                ui.navigateSelectedTab(SwingConstants.PREVIOUS);
+            } else if (key == RIGHT) {
+                ui.navigateSelectedTab(SwingConstants.EAST);
+            } else if (key == LEFT) {
+                ui.navigateSelectedTab(SwingConstants.WEST);
+            } else if (key == UP) {
+                ui.navigateSelectedTab(SwingConstants.NORTH);
+            } else if (key == DOWN) {
+                ui.navigateSelectedTab(SwingConstants.SOUTH);
+            } else if (key == PAGE_UP) {
+                final int tabPlacement = pane.getTabPlacement();
+                if (tabPlacement == TOP || tabPlacement == BOTTOM) {
+                    ui.navigateSelectedTab(SwingConstants.WEST);
+                } else {
+                    ui.navigateSelectedTab(SwingConstants.NORTH);
+                }
+            } else if (key == PAGE_DOWN) {
+                final int tabPlacement = pane.getTabPlacement();
+                if (tabPlacement == TOP || tabPlacement == BOTTOM) {
+                    ui.navigateSelectedTab(SwingConstants.EAST);
+                } else {
+                    ui.navigateSelectedTab(SwingConstants.SOUTH);
+                }
+            } else if (key == REQUEST_FOCUS) {
+                pane.requestFocus();
+            } else if (key == REQUEST_FOCUS_FOR_VISIBLE) {
+                ui.requestFocusForVisibleComponent();
+            } else if (key == SET_SELECTED) {
+                final String command = e.getActionCommand();
+
+                if (command != null && command.length() > 0) {
+                    int mnemonic = e.getActionCommand().charAt(0);
+                    if (mnemonic >= 'a' && mnemonic <= 'z') {
+                        mnemonic -= ('a' - 'A');
+                    }
+                    final Integer index = ui.mnemonicToIndexMap.get(new Integer(mnemonic));
+                    if (index != null && pane.isEnabledAt(index.intValue())) {
+                        pane.setSelectedIndex(index.intValue());
+                    }
+                }
+            } else if (key == SELECT_FOCUSED) {
+                final int focusIndex = ui.getFocusIndex();
+                if (focusIndex != -1) {
+                    pane.setSelectedIndex(focusIndex);
+                }
+            } else if (key == SCROLL_FORWARD) {
+                if (ui.scrollableTabLayoutEnabled()) {
+                    ui.tabScroller.scrollForward(pane.getTabPlacement());
+                }
+            } else if (key == SCROLL_BACKWARD) {
+                if (ui.scrollableTabLayoutEnabled()) {
+                    ui.tabScroller.scrollBackward(pane.getTabPlacement());
+                }
+            }
+        }
+    }
+
+    /**
+     * This class should be treated as a &quot;protected&quot; inner class.
+     * Instantiate it only within subclasses of BasicTabbedPaneUI.
+     */
+    public class TabbedPaneLayout implements LayoutManager {
+        // MACOSX adding accessor for superclass
+        protected Container getTabContainer() {
+            return tabContainer;
+        }
+        // END MACOSX
+
+        public void addLayoutComponent(final String name, final Component comp) {}
+
+        public void removeLayoutComponent(final Component comp) {}
+
+        public Dimension preferredLayoutSize(final Container parent) {
+            return calculateSize(false);
+        }
+
+        public Dimension minimumLayoutSize(final Container parent) {
+            return calculateSize(true);
+        }
+
+        protected Dimension calculateSize(final boolean minimum) {
+            final int tabPlacement = tabPane.getTabPlacement();
+            final Insets insets = tabPane.getInsets();
+            final Insets contentInsets = getContentBorderInsets(tabPlacement);
+            final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
+
+            final Dimension zeroSize = new Dimension(0, 0);
+            int height = 0;
+            int width = 0;
+            int cWidth = 0;
+            int cHeight = 0;
+
+            // Determine minimum size required to display largest
+            // child in each dimension
+            //
+            for (int i = 0; i < tabPane.getTabCount(); i++) {
+                final Component component = tabPane.getComponentAt(i);
+                if (component != null) {
+                    Dimension size = zeroSize;
+                    size = minimum ? component.getMinimumSize() : component.getPreferredSize();
+
+                    if (size != null) {
+                        cHeight = Math.max(size.height, cHeight);
+                        cWidth = Math.max(size.width, cWidth);
+                    }
+                }
+            }
+            // Add content border insets to minimum size
+            width += cWidth;
+            height += cHeight;
+            int tabExtent = 0;
+
+            // Calculate how much space the tabs will need, based on the
+            // minimum size required to display largest child + content border
+            //
+            switch (tabPlacement) {
+                case LEFT:
+                case RIGHT:
+                    height = Math.max(height, calculateMaxTabHeight(tabPlacement));
+                    tabExtent = preferredTabAreaWidth(tabPlacement, height - tabAreaInsets.top - tabAreaInsets.bottom);
+                    width += tabExtent;
+                    break;
+                case TOP:
+                case BOTTOM:
+                default:
+                    width = Math.max(width, calculateMaxTabWidth(tabPlacement));
+                    tabExtent = preferredTabAreaHeight(tabPlacement, width - tabAreaInsets.left - tabAreaInsets.right);
+                    height += tabExtent;
+            }
+            return new Dimension(width + insets.left + insets.right + contentInsets.left + contentInsets.right, height + insets.bottom + insets.top + contentInsets.top + contentInsets.bottom);
+
+        }
+
+        protected int preferredTabAreaHeight(final int tabPlacement, final int width) {
+            final FontMetrics metrics = getFontMetrics();
+            final int tabCount = tabPane.getTabCount();
+            int total = 0;
+            if (tabCount > 0) {
+                int rows = 1;
+                int x = 0;
+
+                final int maxTabHeight = calculateMaxTabHeight(tabPlacement);
+
+                for (int i = 0; i < tabCount; i++) {
+                    final int tabWidth = calculateTabWidth(tabPlacement, i, metrics);
+
+                    if (x != 0 && x + tabWidth > width) {
+                        rows++;
+                        x = 0;
+                    }
+                    x += tabWidth;
+                }
+                total = calculateTabAreaHeight(tabPlacement, rows, maxTabHeight);
+            }
+            return total;
+        }
+
+        protected int preferredTabAreaWidth(final int tabPlacement, final int height) {
+            final FontMetrics metrics = getFontMetrics();
+            final int tabCount = tabPane.getTabCount();
+            int total = 0;
+            if (tabCount > 0) {
+                int columns = 1;
+                int y = 0;
+                final int fontHeight = metrics.getHeight();
+
+                maxTabWidth = calculateMaxTabWidth(tabPlacement);
+
+                for (int i = 0; i < tabCount; i++) {
+                    final int tabHeight = calculateTabHeight(tabPlacement, i, fontHeight);
+
+                    if (y != 0 && y + tabHeight > height) {
+                        columns++;
+                        y = 0;
+                    }
+                    y += tabHeight;
+                }
+                total = calculateTabAreaWidth(tabPlacement, columns, maxTabWidth);
+            }
+            return total;
+        }
+
+        public void layoutContainer(final Container parent) {
+            /* Some of the code in this method deals with changing the
+             * visibility of components to hide and show the contents for the
+             * selected tab. This is older code that has since been duplicated
+             * in JTabbedPane.fireStateChanged(), so as to allow visibility
+             * changes to happen sooner (see the note there). This code remains
+             * for backward compatibility as there are some cases, such as
+             * subclasses that don't fireStateChanged() where it may be used.
+             * Any changes here need to be kept in synch with
+             * JTabbedPane.fireStateChanged().
+             */
+
+            setRolloverTab(-1);
+
+            final int tabPlacement = tabPane.getTabPlacement();
+            final Insets insets = tabPane.getInsets();
+            final int selectedIndex = tabPane.getSelectedIndex();
+            final Component visibleComponent = getVisibleComponent();
+
+            calculateLayoutInfo();
+
+            Component selectedComponent = null;
+            if (selectedIndex < 0) {
+                if (visibleComponent != null) {
+                    // The last tab was removed, so remove the component
+                    setVisibleComponent(null);
+                }
+            } else {
+                selectedComponent = tabPane.getComponentAt(selectedIndex);
+            }
+            int cx, cy, cw, ch;
+            int totalTabWidth = 0;
+            int totalTabHeight = 0;
+            final Insets contentInsets = getContentBorderInsets(tabPlacement);
+
+            boolean shouldChangeFocus = false;
+
+            // In order to allow programs to use a single component
+            // as the display for multiple tabs, we will not change
+            // the visible compnent if the currently selected tab
+            // has a null component.  This is a bit dicey, as we don't
+            // explicitly state we support this in the spec, but since
+            // programs are now depending on this, we're making it work.
+            //
+            if (selectedComponent != null) {
+                if (selectedComponent != visibleComponent && visibleComponent != null) {
+                    if (SwingUtilities.findFocusOwner(visibleComponent) != null) {
+                        shouldChangeFocus = true;
+                    }
+                }
+                setVisibleComponent(selectedComponent);
+            }
+
+            final Rectangle bounds = tabPane.getBounds();
+            final int numChildren = tabPane.getComponentCount();
+
+            if (numChildren > 0) {
+
+                switch (tabPlacement) {
+                    case LEFT:
+                        totalTabWidth = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
+                        cx = insets.left + totalTabWidth + contentInsets.left;
+                        cy = insets.top + contentInsets.top;
+                        break;
+                    case RIGHT:
+                        totalTabWidth = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
+                        cx = insets.left + contentInsets.left;
+                        cy = insets.top + contentInsets.top;
+                        break;
+                    case BOTTOM:
+                        totalTabHeight = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
+                        cx = insets.left + contentInsets.left;
+                        cy = insets.top + contentInsets.top;
+                        break;
+                    case TOP:
+                    default:
+                        totalTabHeight = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
+                        cx = insets.left + contentInsets.left;
+                        cy = insets.top + totalTabHeight + contentInsets.top;
+                }
+
+                cw = bounds.width - totalTabWidth - insets.left - insets.right - contentInsets.left - contentInsets.right;
+                ch = bounds.height - totalTabHeight - insets.top - insets.bottom - contentInsets.top - contentInsets.bottom;
+
+                for (int i = 0; i < numChildren; i++) {
+                    final Component child = tabPane.getComponent(i);
+                    if (child == tabContainer) {
+
+                        final int tabContainerWidth = totalTabWidth == 0 ? bounds.width : totalTabWidth + insets.left + insets.right + contentInsets.left + contentInsets.right;
+                        final int tabContainerHeight = totalTabHeight == 0 ? bounds.height : totalTabHeight + insets.top + insets.bottom + contentInsets.top + contentInsets.bottom;
+
+                        int tabContainerX = 0;
+                        int tabContainerY = 0;
+                        if (tabPlacement == BOTTOM) {
+                            tabContainerY = bounds.height - tabContainerHeight;
+                        } else if (tabPlacement == RIGHT) {
+                            tabContainerX = bounds.width - tabContainerWidth;
+                        }
+                        child.setBounds(tabContainerX, tabContainerY, tabContainerWidth, tabContainerHeight);
+                    } else {
+                        child.setBounds(cx, cy, cw, ch);
+                    }
+                }
+            }
+            layoutTabComponents();
+            if (shouldChangeFocus) {
+                if (!requestFocusForVisibleComponent()) {
+                    tabPane.requestFocus();
+                }
+            }
+        }
+
+        public void calculateLayoutInfo() {
+            final int tabCount = tabPane.getTabCount();
+            assureRectsCreated(tabCount);
+            calculateTabRects(tabPane.getTabPlacement(), tabCount);
+            isRunsDirty = false;
+        }
+
+        protected void layoutTabComponents() {
+            if (tabContainer == null) {
+                return;
+            }
+            final Rectangle rect = new Rectangle();
+            final Point delta = new Point(-tabContainer.getX(), -tabContainer.getY());
+            if (scrollableTabLayoutEnabled()) {
+                translatePointToTabPanel(0, 0, delta);
+            }
+            for (int i = 0; i < tabPane.getTabCount(); i++) {
+                final Component c = tabPane.getTabComponentAt(i);
+                if (c == null) {
+                    continue;
+                }
+                getTabBounds(i, rect);
+                final Dimension preferredSize = c.getPreferredSize();
+                final Insets insets = getTabInsets(tabPane.getTabPlacement(), i);
+                final int outerX = rect.x + insets.left + delta.x;
+                final int outerY = rect.y + insets.top + delta.y;
+                final int outerWidth = rect.width - insets.left - insets.right;
+                final int outerHeight = rect.height - insets.top - insets.bottom;
+                // centralize component
+                final int x = outerX + (outerWidth - preferredSize.width) / 2;
+                final int y = outerY + (outerHeight - preferredSize.height) / 2;
+                final int tabPlacement = tabPane.getTabPlacement();
+                final boolean isSeleceted = i == tabPane.getSelectedIndex();
+                c.setBounds(x + getTabLabelShiftX(tabPlacement, i, isSeleceted), y + getTabLabelShiftY(tabPlacement, i, isSeleceted), preferredSize.width, preferredSize.height);
+            }
+        }
+
+        protected void calculateTabRects(final int tabPlacement, final int tabCount) {
+            final FontMetrics metrics = getFontMetrics();
+            final Dimension size = tabPane.getSize();
+            final Insets insets = tabPane.getInsets();
+            final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
+            final int fontHeight = metrics.getHeight();
+            final int selectedIndex = tabPane.getSelectedIndex();
+            int tabRunOverlay;
+            int i, j;
+            int x, y;
+            int returnAt;
+            boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT);
+            boolean leftToRight = AquaUtils.isLeftToRight(tabPane);
+
+            //
+            // Calculate bounds within which a tab run must fit
+            //
+            switch (tabPlacement) {
+                case LEFT:
+                    maxTabWidth = calculateMaxTabWidth(tabPlacement);
+                    x = insets.left + tabAreaInsets.left;
+                    y = insets.top + tabAreaInsets.top;
+                    returnAt = size.height - (insets.bottom + tabAreaInsets.bottom);
+                    break;
+                case RIGHT:
+                    maxTabWidth = calculateMaxTabWidth(tabPlacement);
+                    x = size.width - insets.right - tabAreaInsets.right - maxTabWidth;
+                    y = insets.top + tabAreaInsets.top;
+                    returnAt = size.height - (insets.bottom + tabAreaInsets.bottom);
+                    break;
+                case BOTTOM:
+                    maxTabHeight = calculateMaxTabHeight(tabPlacement);
+                    x = insets.left + tabAreaInsets.left;
+                    y = size.height - insets.bottom - tabAreaInsets.bottom - maxTabHeight;
+                    returnAt = size.width - (insets.right + tabAreaInsets.right);
+                    break;
+                case TOP:
+                default:
+                    maxTabHeight = calculateMaxTabHeight(tabPlacement);
+                    x = insets.left + tabAreaInsets.left;
+                    y = insets.top + tabAreaInsets.top;
+                    returnAt = size.width - (insets.right + tabAreaInsets.right);
+                    break;
+            }
+
+            tabRunOverlay = getTabRunOverlay(tabPlacement);
+
+            runCount = 0;
+            selectedRun = -1;
+
+            if (tabCount == 0) {
+                return;
+            }
+
+            // Run through tabs and partition them into runs
+            Rectangle rect;
+            for (i = 0; i < tabCount; i++) {
+                rect = rects[i];
+
+                if (!verticalTabRuns) {
+                    // Tabs on TOP or BOTTOM....
+                    if (i > 0) {
+                        rect.x = rects[i - 1].x + rects[i - 1].width;
+                    } else {
+                        tabRuns[0] = 0;
+                        runCount = 1;
+                        maxTabWidth = 0;
+                        rect.x = x;
+                    }
+                    rect.width = calculateTabWidth(tabPlacement, i, metrics);
+                    maxTabWidth = Math.max(maxTabWidth, rect.width);
+
+                    // Never move a TAB down a run if it is in the first column.
+                    // Even if there isn't enough room, moving it to a fresh
+                    // line won't help.
+                    if (rect.x != 2 + insets.left && rect.x + rect.width > returnAt) {
+                        if (runCount > tabRuns.length - 1) {
+                            expandTabRunsArray();
+                        }
+                        tabRuns[runCount] = i;
+                        runCount++;
+                        rect.x = x;
+                    }
+                    // Initialize y position in case there's just one run
+                    rect.y = y;
+                    rect.height = maxTabHeight/* - 2*/;
+
+                } else {
+                    // Tabs on LEFT or RIGHT...
+                    if (i > 0) {
+                        rect.y = rects[i - 1].y + rects[i - 1].height;
+                    } else {
+                        tabRuns[0] = 0;
+                        runCount = 1;
+                        maxTabHeight = 0;
+                        rect.y = y;
+                    }
+                    rect.height = calculateTabHeight(tabPlacement, i, fontHeight);
+                    maxTabHeight = Math.max(maxTabHeight, rect.height);
+
+                    // Never move a TAB over a run if it is in the first run.
+                    // Even if there isn't enough room, moving it to a fresh
+                    // column won't help.
+                    if (rect.y != 2 + insets.top && rect.y + rect.height > returnAt) {
+                        if (runCount > tabRuns.length - 1) {
+                            expandTabRunsArray();
+                        }
+                        tabRuns[runCount] = i;
+                        runCount++;
+                        rect.y = y;
+                    }
+                    // Initialize x position in case there's just one column
+                    rect.x = x;
+                    rect.width = maxTabWidth/* - 2*/;
+
+                }
+                if (i == selectedIndex) {
+                    selectedRun = runCount - 1;
+                }
+            }
+
+            if (runCount > 1) {
+                // Re-distribute tabs in case last run has leftover space
+                normalizeTabRuns(tabPlacement, tabCount, verticalTabRuns ? y : x, returnAt);
+
+                selectedRun = getRunForTab(tabCount, selectedIndex);
+
+                // Rotate run array so that selected run is first
+                if (shouldRotateTabRuns(tabPlacement)) {
+                    rotateTabRuns(tabPlacement, selectedRun);
+                }
+            }
+
+            // Step through runs from back to front to calculate
+            // tab y locations and to pad runs appropriately
+            for (i = runCount - 1; i >= 0; i--) {
+                final int start = tabRuns[i];
+                final int next = tabRuns[i == (runCount - 1) ? 0 : i + 1];
+                final int end = (next != 0 ? next - 1 : tabCount - 1);
+                if (!verticalTabRuns) {
+                    for (j = start; j <= end; j++) {
+                        rect = rects[j];
+                        rect.y = y;
+                        rect.x += getTabRunIndent(tabPlacement, i);
+                    }
+                    if (shouldPadTabRun(tabPlacement, i)) {
+                        padTabRun(tabPlacement, start, end, returnAt);
+                    }
+                    if (tabPlacement == BOTTOM) {
+                        y -= (maxTabHeight - tabRunOverlay);
+                    } else {
+                        y += (maxTabHeight - tabRunOverlay);
+                    }
+                } else {
+                    for (j = start; j <= end; j++) {
+                        rect = rects[j];
+                        rect.x = x;
+                        rect.y += getTabRunIndent(tabPlacement, i);
+                    }
+                    if (shouldPadTabRun(tabPlacement, i)) {
+                        padTabRun(tabPlacement, start, end, returnAt);
+                    }
+                    if (tabPlacement == RIGHT) {
+                        x -= (maxTabWidth - tabRunOverlay);
+                    } else {
+                        x += (maxTabWidth - tabRunOverlay);
+                    }
+                }
+            }
+
+            // Pad the selected tab so that it appears raised in front
+            padSelectedTab(tabPlacement, selectedIndex);
+
+            // if right to left and tab placement on the top or
+            // the bottom, flip x positions and adjust by widths
+            if (!leftToRight && !verticalTabRuns) {
+                final int rightMargin = size.width - (insets.right + tabAreaInsets.right);
+                for (i = 0; i < tabCount; i++) {
+                    rects[i].x = rightMargin - rects[i].x - rects[i].width;
+                }
+            }
+        }
+
+        /*
+         * Rotates the run-index array so that the selected run is run[0]
+         */
+        protected void rotateTabRuns(final int tabPlacement, final int selectedRun) {
+            for (int i = 0; i < selectedRun; i++) {
+                final int save = tabRuns[0];
+                for (int j = 1; j < runCount; j++) {
+                    tabRuns[j - 1] = tabRuns[j];
+                }
+                tabRuns[runCount - 1] = save;
+            }
+        }
+
+        protected void normalizeTabRuns(final int tabPlacement, final int tabCount, final int start, final int max) {
+            boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT);
+            int run = runCount - 1;
+            boolean keepAdjusting = true;
+            double weight = 1.25;
+
+            // At this point the tab runs are packed to fit as many
+            // tabs as possible, which can leave the last run with a lot
+            // of extra space (resulting in very fat tabs on the last run).
+            // So we'll attempt to distribute this extra space more evenly
+            // across the runs in order to make the runs look more consistent.
+            //
+            // Starting with the last run, determine whether the last tab in
+            // the previous run would fit (generously) in this run; if so,
+            // move tab to current run and shift tabs accordingly.  Cycle
+            // through remaining runs using the same algorithm.
+            //
+            while (keepAdjusting) {
+                final int last = lastTabInRun(tabCount, run);
+                final int prevLast = lastTabInRun(tabCount, run - 1);
+                int end;
+                int prevLastLen;
+
+                if (!verticalTabRuns) {
+                    end = rects[last].x + rects[last].width;
+                    prevLastLen = (int)(maxTabWidth * weight);
+                } else {
+                    end = rects[last].y + rects[last].height;
+                    prevLastLen = (int)(maxTabHeight * weight * 2);
+                }
+
+                // Check if the run has enough extra space to fit the last tab
+                // from the previous row...
+                if (max - end > prevLastLen) {
+
+                    // Insert tab from previous row and shift rest over
+                    tabRuns[run] = prevLast;
+                    if (!verticalTabRuns) {
+                        rects[prevLast].x = start;
+                    } else {
+                        rects[prevLast].y = start;
+                    }
+                    for (int i = prevLast + 1; i <= last; i++) {
+                        if (!verticalTabRuns) {
+                            rects[i].x = rects[i - 1].x + rects[i - 1].width;
+                        } else {
+                            rects[i].y = rects[i - 1].y + rects[i - 1].height;
+                        }
+                    }
+
+                } else if (run == runCount - 1) {
+                    // no more room left in last run, so we're done!
+                    keepAdjusting = false;
+                }
+                if (run - 1 > 0) {
+                    // check previous run next...
+                    run -= 1;
+                } else {
+                    // check last run again...but require a higher ratio
+                    // of extraspace-to-tabsize because we don't want to
+                    // end up with too many tabs on the last run!
+                    run = runCount - 1;
+                    weight += .25;
+                }
+            }
+        }
+
+        protected void padTabRun(final int tabPlacement, final int start, final int end, final int max) {
+            final Rectangle lastRect = rects[end];
+            if (tabPlacement == TOP || tabPlacement == BOTTOM) {
+                final int runWidth = (lastRect.x + lastRect.width) - rects[start].x;
+                final int deltaWidth = max - (lastRect.x + lastRect.width);
+                final float factor = (float)deltaWidth / (float)runWidth;
+
+                for (int j = start; j <= end; j++) {
+                    final Rectangle pastRect = rects[j];
+                    if (j > start) {
+                        pastRect.x = rects[j - 1].x + rects[j - 1].width;
+                    }
+                    pastRect.width += Math.round(pastRect.width * factor);
+                }
+                lastRect.width = max - lastRect.x;
+            } else {
+                final int runHeight = (lastRect.y + lastRect.height) - rects[start].y;
+                final int deltaHeight = max - (lastRect.y + lastRect.height);
+                final float factor = (float)deltaHeight / (float)runHeight;
+
+                for (int j = start; j <= end; j++) {
+                    final Rectangle pastRect = rects[j];
+                    if (j > start) {
+                        pastRect.y = rects[j - 1].y + rects[j - 1].height;
+                    }
+                    pastRect.height += Math.round(pastRect.height * factor);
+                }
+                lastRect.height = max - lastRect.y;
+            }
+        }
+
+        protected void padSelectedTab(final int tabPlacement, final int selectedIndex) {
+
+            if (selectedIndex >= 0) {
+                final Rectangle selRect = rects[selectedIndex];
+                final Insets padInsets = getSelectedTabPadInsets(tabPlacement);
+                selRect.x -= padInsets.left;
+                selRect.width += (padInsets.left + padInsets.right);
+                selRect.y -= padInsets.top;
+                selRect.height += (padInsets.top + padInsets.bottom);
+
+                if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT
+                    // do not expand selected tab more then necessary
+                    final Dimension size = tabPane.getSize();
+                    final Insets insets = tabPane.getInsets();
+
+                    if ((tabPlacement == LEFT) || (tabPlacement == RIGHT)) {
+                        final int top = insets.top - selRect.y;
+                        if (top > 0) {
+                            selRect.y += top;
+                            selRect.height -= top;
+                        }
+                        final int bottom = (selRect.y + selRect.height) + insets.bottom - size.height;
+                        if (bottom > 0) {
+                            selRect.height -= bottom;
+                        }
+                    } else {
+                        final int left = insets.left - selRect.x;
+                        if (left > 0) {
+                            selRect.x += left;
+                            selRect.width -= left;
+                        }
+                        final int right = (selRect.x + selRect.width) + insets.right - size.width;
+                        if (right > 0) {
+                            selRect.width -= right;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    class TabbedPaneScrollLayout extends TabbedPaneLayout {
+
+        protected int preferredTabAreaHeight(final int tabPlacement, final int width) {
+            return calculateMaxTabHeight(tabPlacement);
+        }
+
+        protected int preferredTabAreaWidth(final int tabPlacement, final int height) {
+            return calculateMaxTabWidth(tabPlacement);
+        }
+
+        public void layoutContainer(final Container parent) {
+            /* Some of the code in this method deals with changing the
+             * visibility of components to hide and show the contents for the
+             * selected tab. This is older code that has since been duplicated
+             * in JTabbedPane.fireStateChanged(), so as to allow visibility
+             * changes to happen sooner (see the note there). This code remains
+             * for backward compatibility as there are some cases, such as
+             * subclasses that don't fireStateChanged() where it may be used.
+             * Any changes here need to be kept in synch with
+             * JTabbedPane.fireStateChanged().
+             */
+
+            setRolloverTab(-1);
+
+            final int tabPlacement = tabPane.getTabPlacement();
+            final int tabCount = tabPane.getTabCount();
+            final Insets insets = tabPane.getInsets();
+            final int selectedIndex = tabPane.getSelectedIndex();
+            final Component visibleComponent = getVisibleComponent();
+
+            calculateLayoutInfo();
+
+            Component selectedComponent = null;
+            if (selectedIndex < 0) {
+                if (visibleComponent != null) {
+                    // The last tab was removed, so remove the component
+                    setVisibleComponent(null);
+                }
+            } else {
+                selectedComponent = tabPane.getComponentAt(selectedIndex);
+            }
+
+            if (tabPane.getTabCount() == 0) {
+                tabScroller.croppedEdge.resetParams();
+                tabScroller.scrollForwardButton.setVisible(false);
+                tabScroller.scrollBackwardButton.setVisible(false);
+                return;
+            }
+
+            boolean shouldChangeFocus = false;
+
+            // In order to allow programs to use a single component
+            // as the display for multiple tabs, we will not change
+            // the visible compnent if the currently selected tab
+            // has a null component.  This is a bit dicey, as we don't
+            // explicitly state we support this in the spec, but since
+            // programs are now depending on this, we're making it work.
+            //
+            if (selectedComponent != null) {
+                if (selectedComponent != visibleComponent && visibleComponent != null) {
+                    if (SwingUtilities.findFocusOwner(visibleComponent) != null) {
+                        shouldChangeFocus = true;
+                    }
+                }
+                setVisibleComponent(selectedComponent);
+            }
+            int tx, ty, tw, th; // tab area bounds
+            int cx, cy, cw, ch; // content area bounds
+            final Insets contentInsets = getContentBorderInsets(tabPlacement);
+            final Rectangle bounds = tabPane.getBounds();
+            final int numChildren = tabPane.getComponentCount();
+
+            if (numChildren > 0) {
+                switch (tabPlacement) {
+                    case LEFT:
+                        // calculate tab area bounds
+                        tw = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
+                        th = bounds.height - insets.top - insets.bottom;
+                        tx = insets.left;
+                        ty = insets.top;
+
+                        // calculate content area bounds
+                        cx = tx + tw + contentInsets.left;
+                        cy = ty + contentInsets.top;
+                        cw = bounds.width - insets.left - insets.right - tw - contentInsets.left - contentInsets.right;
+                        ch = bounds.height - insets.top - insets.bottom - contentInsets.top - contentInsets.bottom;
+                        break;
+                    case RIGHT:
+                        // calculate tab area bounds
+                        tw = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
+                        th = bounds.height - insets.top - insets.bottom;
+                        tx = bounds.width - insets.right - tw;
+                        ty = insets.top;
+
+                        // calculate content area bounds
+                        cx = insets.left + contentInsets.left;
+                        cy = insets.top + contentInsets.top;
+                        cw = bounds.width - insets.left - insets.right - tw - contentInsets.left - contentInsets.right;
+                        ch = bounds.height - insets.top - insets.bottom - contentInsets.top - contentInsets.bottom;
+                        break;
+                    case BOTTOM:
+                        // calculate tab area bounds
+                        tw = bounds.width - insets.left - insets.right;
+                        th = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
+                        tx = insets.left;
+                        ty = bounds.height - insets.bottom - th;
+
+                        // calculate content area bounds
+                        cx = insets.left + contentInsets.left;
+                        cy = insets.top + contentInsets.top;
+                        cw = bounds.width - insets.left - insets.right - contentInsets.left - contentInsets.right;
+                        ch = bounds.height - insets.top - insets.bottom - th - contentInsets.top - contentInsets.bottom;
+                        break;
+                    case TOP:
+                    default:
+                        // calculate tab area bounds
+                        tw = bounds.width - insets.left - insets.right;
+                        th = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
+                        tx = insets.left;
+                        ty = insets.top;
+
+                        // calculate content area bounds
+                        cx = tx + contentInsets.left;
+                        cy = ty + th + contentInsets.top;
+                        cw = bounds.width - insets.left - insets.right - contentInsets.left - contentInsets.right;
+                        ch = bounds.height - insets.top - insets.bottom - th - contentInsets.top - contentInsets.bottom;
+                }
+
+                for (int i = 0; i < numChildren; i++) {
+                    final Component child = tabPane.getComponent(i);
+
+                    if (tabScroller != null && child == tabScroller.viewport) {
+                        final JViewport viewport = (JViewport)child;
+                        final Rectangle viewRect = viewport.getViewRect();
+                        int vw = tw;
+                        int vh = th;
+                        final Dimension butSize = tabScroller.scrollForwardButton.getPreferredSize();
+                        switch (tabPlacement) {
+                            case LEFT:
+                            case RIGHT:
+                                final int totalTabHeight = rects[tabCount - 1].y + rects[tabCount - 1].height;
+                                if (totalTabHeight > th) {
+                                    // Allow space for scrollbuttons
+                                    vh = (th > 2 * butSize.height) ? th - 2 * butSize.height : 0;
+                                    if (totalTabHeight - viewRect.y <= vh) {
+                                        // Scrolled to the end, so ensure the viewport size is
+                                        // such that the scroll offset aligns with a tab
+                                        vh = totalTabHeight - viewRect.y;
+                                    }
+                                }
+                                break;
+                            case BOTTOM:
+                            case TOP:
+                            default:
+                                final int totalTabWidth = rects[tabCount - 1].x + rects[tabCount - 1].width;
+                                if (totalTabWidth > tw) {
+                                    // Need to allow space for scrollbuttons
+                                    vw = (tw > 2 * butSize.width) ? tw - 2 * butSize.width : 0;
+                                    if (totalTabWidth - viewRect.x <= vw) {
+                                        // Scrolled to the end, so ensure the viewport size is
+                                        // such that the scroll offset aligns with a tab
+                                        vw = totalTabWidth - viewRect.x;
+                                    }
+                                }
+                        }
+                        child.setBounds(tx, ty, vw, vh);
+
+                    } else if (tabScroller != null && (child == tabScroller.scrollForwardButton || child == tabScroller.scrollBackwardButton)) {
+                        final Component scrollbutton = child;
+                        final Dimension bsize = scrollbutton.getPreferredSize();
+                        int bx = 0;
+                        int by = 0;
+                        final int bw = bsize.width;
+                        final int bh = bsize.height;
+                        boolean visible = false;
+
+                        switch (tabPlacement) {
+                            case LEFT:
+                            case RIGHT:
+                                final int totalTabHeight = rects[tabCount - 1].y + rects[tabCount - 1].height;
+                                if (totalTabHeight > th) {
+                                    visible = true;
+                                    bx = (tabPlacement == LEFT ? tx + tw - bsize.width : tx);
+                                    by = (child == tabScroller.scrollForwardButton) ? bounds.height - insets.bottom - bsize.height : bounds.height - insets.bottom - 2 * bsize.height;
+                                }
+                                break;
+
+                            case BOTTOM:
+                            case TOP:
+                            default:
+                                final int totalTabWidth = rects[tabCount - 1].x + rects[tabCount - 1].width;
+
+                                if (totalTabWidth > tw) {
+                                    visible = true;
+                                    bx = (child == tabScroller.scrollForwardButton) ? bounds.width - insets.left - bsize.width : bounds.width - insets.left - 2 * bsize.width;
+                                    by = (tabPlacement == TOP ? ty + th - bsize.height : ty);
+                                }
+                        }
+                        child.setVisible(visible);
+                        if (visible) {
+                            child.setBounds(bx, by, bw, bh);
+                        }
+
+                    } else {
+                        // All content children...
+                        child.setBounds(cx, cy, cw, ch);
+                    }
+                }
+                super.layoutTabComponents();
+                layoutCroppedEdge();
+                if (shouldChangeFocus) {
+                    if (!requestFocusForVisibleComponent()) {
+                        tabPane.requestFocus();
+                    }
+                }
+            }
+        }
+
+        private void layoutCroppedEdge() {
+            tabScroller.croppedEdge.resetParams();
+            final Rectangle viewRect = tabScroller.viewport.getViewRect();
+            int cropline;
+            for (int i = 0; i < rects.length; i++) {
+                final Rectangle tabRect = rects[i];
+                switch (tabPane.getTabPlacement()) {
+                    case LEFT:
+                    case RIGHT:
+                        cropline = viewRect.y + viewRect.height;
+                        if ((tabRect.y < cropline) && (tabRect.y + tabRect.height > cropline)) {
+                            tabScroller.croppedEdge.setParams(i, cropline - tabRect.y - 1, -currentTabAreaInsets.left, 0);
+                        }
+                        break;
+                    case TOP:
+                    case BOTTOM:
+                    default:
+                        cropline = viewRect.x + viewRect.width;
+                        if ((tabRect.x < cropline - 1) && (tabRect.x + tabRect.width > cropline)) {
+                            tabScroller.croppedEdge.setParams(i, cropline - tabRect.x - 1, 0, -currentTabAreaInsets.top);
+                        }
+                }
+            }
+        }
+
+        protected void calculateTabRects(final int tabPlacement, final int tabCount) {
+            final FontMetrics metrics = getFontMetrics();
+            final Dimension size = tabPane.getSize();
+            final Insets insets = tabPane.getInsets();
+            final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
+            final int fontHeight = metrics.getHeight();
+            final int selectedIndex = tabPane.getSelectedIndex();
+            int i;
+            boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT);
+            boolean leftToRight = AquaUtils.isLeftToRight(tabPane);
+            final int x = tabAreaInsets.left;
+            final int y = tabAreaInsets.top;
+            int totalWidth = 0;
+            int totalHeight = 0;
+
+            //
+            // Calculate bounds within which a tab run must fit
+            //
+            switch (tabPlacement) {
+                case LEFT:
+                case RIGHT:
+                    maxTabWidth = calculateMaxTabWidth(tabPlacement);
+                    break;
+                case BOTTOM:
+                case TOP:
+                default:
+                    maxTabHeight = calculateMaxTabHeight(tabPlacement);
+            }
+
+            runCount = 0;
+            selectedRun = -1;
+
+            if (tabCount == 0) {
+                return;
+            }
+
+            selectedRun = 0;
+            runCount = 1;
+
+            // Run through tabs and lay them out in a single run
+            Rectangle rect;
+            for (i = 0; i < tabCount; i++) {
+                rect = rects[i];
+
+                if (!verticalTabRuns) {
+                    // Tabs on TOP or BOTTOM....
+                    if (i > 0) {
+                        rect.x = rects[i - 1].x + rects[i - 1].width;
+                    } else {
+                        tabRuns[0] = 0;
+                        maxTabWidth = 0;
+                        totalHeight += maxTabHeight;
+                        rect.x = x;
+                    }
+                    rect.width = calculateTabWidth(tabPlacement, i, metrics);
+                    totalWidth = rect.x + rect.width;
+                    maxTabWidth = Math.max(maxTabWidth, rect.width);
+
+                    rect.y = y;
+                    rect.height = maxTabHeight/* - 2*/;
+
+                } else {
+                    // Tabs on LEFT or RIGHT...
+                    if (i > 0) {
+                        rect.y = rects[i - 1].y + rects[i - 1].height;
+                    } else {
+                        tabRuns[0] = 0;
+                        maxTabHeight = 0;
+                        totalWidth = maxTabWidth;
+                        rect.y = y;
+                    }
+                    rect.height = calculateTabHeight(tabPlacement, i, fontHeight);
+                    totalHeight = rect.y + rect.height;
+                    maxTabHeight = Math.max(maxTabHeight, rect.height);
+
+                    rect.x = x;
+                    rect.width = maxTabWidth/* - 2*/;
+
+                }
+            }
+
+            if (tabsOverlapBorder) {
+                // Pad the selected tab so that it appears raised in front
+                padSelectedTab(tabPlacement, selectedIndex);
+            }
+
+            // if right to left and tab placement on the top or
+            // the bottom, flip x positions and adjust by widths
+            if (!leftToRight && !verticalTabRuns) {
+                final int rightMargin = size.width - (insets.right + tabAreaInsets.right);
+                for (i = 0; i < tabCount; i++) {
+                    rects[i].x = rightMargin - rects[i].x - rects[i].width;
+                }
+            }
+            tabScroller.tabPanel.setPreferredSize(new Dimension(totalWidth, totalHeight));
+        }
+    }
+
+    private class ScrollableTabSupport implements ActionListener, ChangeListener {
+        public ScrollableTabViewport viewport;
+        public ScrollableTabPanel tabPanel;
+        public JButton scrollForwardButton;
+        public JButton scrollBackwardButton;
+        public CroppedEdge croppedEdge;
+        public int leadingTabIndex;
+
+        private final Point tabViewPosition = new Point(0, 0);
+
+        ScrollableTabSupport(final int tabPlacement) {
+            viewport = new ScrollableTabViewport();
+            tabPanel = new ScrollableTabPanel();
+            viewport.setView(tabPanel);
+            viewport.addChangeListener(this);
+            croppedEdge = new CroppedEdge();
+            createButtons();
+        }
+
+        /**
+         * Recreates the scroll buttons and adds them to the TabbedPane.
+         */
+        void createButtons() {
+            if (scrollForwardButton != null) {
+                tabPane.remove(scrollForwardButton);
+                scrollForwardButton.removeActionListener(this);
+                tabPane.remove(scrollBackwardButton);
+                scrollBackwardButton.removeActionListener(this);
+            }
+            final int tabPlacement = tabPane.getTabPlacement();
+            if (tabPlacement == TOP || tabPlacement == BOTTOM) {
+                scrollForwardButton = createScrollButton(EAST);
+                scrollBackwardButton = createScrollButton(WEST);
+
+            } else { // tabPlacement = LEFT || RIGHT
+                scrollForwardButton = createScrollButton(SOUTH);
+                scrollBackwardButton = createScrollButton(NORTH);
+            }
+            scrollForwardButton.addActionListener(this);
+            scrollBackwardButton.addActionListener(this);
+            tabPane.add(scrollForwardButton);
+            tabPane.add(scrollBackwardButton);
+        }
+
+        public void scrollForward(final int tabPlacement) {
+            final Dimension viewSize = viewport.getViewSize();
+            final Rectangle viewRect = viewport.getViewRect();
+
+            if (tabPlacement == TOP || tabPlacement == BOTTOM) {
+                if (viewRect.width >= viewSize.width - viewRect.x) {
+                    return; // no room left to scroll
+                }
+            } else { // tabPlacement == LEFT || tabPlacement == RIGHT
+                if (viewRect.height >= viewSize.height - viewRect.y) {
+                    return;
+                }
+            }
+            setLeadingTabIndex(tabPlacement, leadingTabIndex + 1);
+        }
+
+        public void scrollBackward(final int tabPlacement) {
+            if (leadingTabIndex == 0) {
+                return; // no room left to scroll
+            }
+            setLeadingTabIndex(tabPlacement, leadingTabIndex - 1);
+        }
+
+        public void setLeadingTabIndex(final int tabPlacement, final int index) {
+            leadingTabIndex = index;
+            final Dimension viewSize = viewport.getViewSize();
+            final Rectangle viewRect = viewport.getViewRect();
+
+            switch (tabPlacement) {
+                case TOP:
+                case BOTTOM:
+                    tabViewPosition.x = leadingTabIndex == 0 ? 0 : rects[leadingTabIndex].x;
+
+                    if ((viewSize.width - tabViewPosition.x) < viewRect.width) {
+                        // We've scrolled to the end, so adjust the viewport size
+                        // to ensure the view position remains aligned on a tab boundary
+                        final Dimension extentSize = new Dimension(viewSize.width - tabViewPosition.x, viewRect.height);
+                        viewport.setExtentSize(extentSize);
+                    }
+                    break;
+                case LEFT:
+                case RIGHT:
+                    tabViewPosition.y = leadingTabIndex == 0 ? 0 : rects[leadingTabIndex].y;
+
+                    if ((viewSize.height - tabViewPosition.y) < viewRect.height) {
+                        // We've scrolled to the end, so adjust the viewport size
+                        // to ensure the view position remains aligned on a tab boundary
+                        final Dimension extentSize = new Dimension(viewRect.width, viewSize.height - tabViewPosition.y);
+                        viewport.setExtentSize(extentSize);
+                    }
+            }
+            viewport.setViewPosition(tabViewPosition);
+        }
+
+        public void stateChanged(final ChangeEvent e) {
+            updateView();
+        }
+
+        private void updateView() {
+            final int tabPlacement = tabPane.getTabPlacement();
+            final int tabCount = tabPane.getTabCount();
+            final Rectangle vpRect = viewport.getBounds();
+            final Dimension viewSize = viewport.getViewSize();
+            final Rectangle viewRect = viewport.getViewRect();
+
+            leadingTabIndex = getClosestTab(viewRect.x, viewRect.y);
+
+            // If the tab isn't right aligned, adjust it.
+            if (leadingTabIndex + 1 < tabCount) {
+                switch (tabPlacement) {
+                    case TOP:
+                    case BOTTOM:
+                        if (rects[leadingTabIndex].x < viewRect.x) {
+                            leadingTabIndex++;
+                        }
+                        break;
+                    case LEFT:
+                    case RIGHT:
+                        if (rects[leadingTabIndex].y < viewRect.y) {
+                            leadingTabIndex++;
+                        }
+                        break;
+                }
+            }
+            final Insets contentInsets = getContentBorderInsets(tabPlacement);
+            switch (tabPlacement) {
+                case LEFT:
+                    tabPane.repaint(vpRect.x + vpRect.width, vpRect.y, contentInsets.left, vpRect.height);
+                    scrollBackwardButton.setEnabled(viewRect.y > 0 && leadingTabIndex > 0);
+                    scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.height - viewRect.y > viewRect.height);
+                    break;
+                case RIGHT:
+                    tabPane.repaint(vpRect.x - contentInsets.right, vpRect.y, contentInsets.right, vpRect.height);
+                    scrollBackwardButton.setEnabled(viewRect.y > 0 && leadingTabIndex > 0);
+                    scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.height - viewRect.y > viewRect.height);
+                    break;
+                case BOTTOM:
+                    tabPane.repaint(vpRect.x, vpRect.y - contentInsets.bottom, vpRect.width, contentInsets.bottom);
+                    scrollBackwardButton.setEnabled(viewRect.x > 0 && leadingTabIndex > 0);
+                    scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.width - viewRect.x > viewRect.width);
+                    break;
+                case TOP:
+                default:
+                    tabPane.repaint(vpRect.x, vpRect.y + vpRect.height, vpRect.width, contentInsets.top);
+                    scrollBackwardButton.setEnabled(viewRect.x > 0 && leadingTabIndex > 0);
+                    scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.width - viewRect.x > viewRect.width);
+            }
+        }
+
+        /**
+         * ActionListener for the scroll buttons.
+         */
+        public void actionPerformed(final ActionEvent e) {
+            final ActionMap map = tabPane.getActionMap();
+
+            if (map != null) {
+                String actionKey;
+
+                if (e.getSource() == scrollForwardButton) {
+                    actionKey = "scrollTabsForwardAction";
+                } else {
+                    actionKey = "scrollTabsBackwardAction";
+                }
+                final Action action = map.get(actionKey);
+
+                if (action != null && action.isEnabled()) {
+                    action.actionPerformed(new ActionEvent(tabPane, ActionEvent.ACTION_PERFORMED, null, e.getWhen(), e.getModifiers()));
+                }
+            }
+        }
+
+        public String toString() {
+            return new String("viewport.viewSize=" + viewport.getViewSize() + "\n" + "viewport.viewRectangle=" + viewport.getViewRect() + "\n" + "leadingTabIndex=" + leadingTabIndex + "\n" + "tabViewPosition=" + tabViewPosition);
+        }
+
+    }
+
+    private class ScrollableTabViewport extends JViewport implements UIResource {
+        public ScrollableTabViewport() {
+            super();
+            setName("TabbedPane.scrollableViewport");
+            setScrollMode(SIMPLE_SCROLL_MODE);
+            setOpaque(tabPane.isOpaque());
+            Color bgColor = UIManager.getColor("TabbedPane.tabAreaBackground");
+            if (bgColor == null) {
+                bgColor = tabPane.getBackground();
+            }
+            setBackground(bgColor);
+        }
+    }
+
+    private class ScrollableTabPanel extends JPanel implements UIResource {
+        public ScrollableTabPanel() {
+            super(null);
+            setOpaque(tabPane.isOpaque());
+            Color bgColor = UIManager.getColor("TabbedPane.tabAreaBackground");
+            if (bgColor == null) {
+                bgColor = tabPane.getBackground();
+            }
+            setBackground(bgColor);
+        }
+
+        public void paintComponent(final Graphics g) {
+            super.paintComponent(g);
+            AquaTabbedPaneCopyFromBasicUI.this.paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex());
+            if (tabScroller.croppedEdge.isParamsSet() && tabContainer == null) {
+                final Rectangle croppedRect = rects[tabScroller.croppedEdge.getTabIndex()];
+                g.translate(croppedRect.x, croppedRect.y);
+                tabScroller.croppedEdge.paintComponent(g);
+                g.translate(-croppedRect.x, -croppedRect.y);
+            }
+        }
+
+        public void doLayout() {
+            if (getComponentCount() > 0) {
+                final Component child = getComponent(0);
+                child.setBounds(0, 0, getWidth(), getHeight());
+            }
+        }
+    }
+
+    private class ScrollableTabButton extends javax.swing.plaf.basic.BasicArrowButton implements UIResource, SwingConstants {
+        public ScrollableTabButton(final int direction) {
+            super(direction, UIManager.getColor("TabbedPane.selected"), UIManager.getColor("TabbedPane.shadow"), UIManager.getColor("TabbedPane.darkShadow"), UIManager.getColor("TabbedPane.highlight"));
+        }
+    }
+
+// Controller: event listeners
+
+    private class Handler implements ChangeListener, ContainerListener, FocusListener, MouseListener, MouseMotionListener, PropertyChangeListener {
+        //
+        // PropertyChangeListener
+        //
+        public void propertyChange(final PropertyChangeEvent e) {
+            final JTabbedPane pane = (JTabbedPane)e.getSource();
+            final String name = e.getPropertyName();
+            final boolean isScrollLayout = scrollableTabLayoutEnabled();
+            if (name == "mnemonicAt") {
+                updateMnemonics();
+                pane.repaint();
+            } else if (name == "displayedMnemonicIndexAt") {
+                pane.repaint();
+            } else if (name == "indexForTitle") {
+                calculatedBaseline = false;
+                updateHtmlViews((Integer) e.getNewValue());
+            } else if (name == "tabLayoutPolicy") {
+                AquaTabbedPaneCopyFromBasicUI.this.uninstallUI(pane);
+                AquaTabbedPaneCopyFromBasicUI.this.installUI(pane);
+                calculatedBaseline = false;
+            } else if (name == "tabPlacement") {
+                if (scrollableTabLayoutEnabled()) {
+                    tabScroller.createButtons();
+                }
+                calculatedBaseline = false;
+            } else if (name == "opaque" && isScrollLayout) {
+                final boolean newVal = ((Boolean)e.getNewValue()).booleanValue();
+                tabScroller.tabPanel.setOpaque(newVal);
+                tabScroller.viewport.setOpaque(newVal);
+            } else if (name == "background" && isScrollLayout) {
+                final Color newVal = (Color)e.getNewValue();
+                tabScroller.tabPanel.setBackground(newVal);
+                tabScroller.viewport.setBackground(newVal);
+                final Color newColor = selectedColor == null ? newVal : selectedColor;
+                tabScroller.scrollForwardButton.setBackground(newColor);
+                tabScroller.scrollBackwardButton.setBackground(newColor);
+            } else if (name == "indexForTabComponent") {
+                if (tabContainer != null) {
+                    tabContainer.removeUnusedTabComponents();
+                }
+                final Component c = tabPane.getTabComponentAt((Integer)e.getNewValue());
+                if (c != null) {
+                    if (tabContainer == null) {
+                        installTabContainer();
+                    } else {
+                        tabContainer.add(c);
+                    }
+                }
+                tabPane.revalidate();
+                tabPane.repaint();
+                calculatedBaseline = false;
+            } else if (name == "indexForNullComponent") {
+                isRunsDirty = true;
+                updateHtmlViews((Integer) e.getNewValue());
+            } else if (name == "font") {
+                calculatedBaseline = false;
+            }
+        }
+
+        //
+        // ChangeListener
+        //
+        public void stateChanged(final ChangeEvent e) {
+            final JTabbedPane tabPane = (JTabbedPane)e.getSource();
+            tabPane.revalidate();
+            tabPane.repaint();
+
+            setFocusIndex(tabPane.getSelectedIndex(), false);
+
+            if (scrollableTabLayoutEnabled()) {
+                final int index = tabPane.getSelectedIndex();
+                if (index < rects.length && index != -1) {
+                    tabScroller.tabPanel.scrollRectToVisible((Rectangle)rects[index].clone());
+                }
+            }
+        }
+
+        //
+        // MouseListener
+        //
+        public void mouseClicked(final MouseEvent e) {}
+
+        public void mouseReleased(final MouseEvent e) {}
+
+        public void mouseEntered(final MouseEvent e) {
+            setRolloverTab(e.getX(), e.getY());
+        }
+
+        public void mouseExited(final MouseEvent e) {
+            setRolloverTab(-1);
+        }
+
+        public void mousePressed(final MouseEvent e) {
+            if (!tabPane.isEnabled()) {
+                return;
+            }
+            final int tabIndex = tabForCoordinate(tabPane, e.getX(), e.getY());
+            if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
+                if (tabIndex != tabPane.getSelectedIndex()) {
+                    // Clicking on unselected tab, change selection, do NOT
+                    // request focus.
+                    // This will trigger the focusIndex to change by way
+                    // of stateChanged.
+                    tabPane.setSelectedIndex(tabIndex);
+                } else if (tabPane.isRequestFocusEnabled()) {
+                    // Clicking on selected tab, try and give the tabbedpane
+                    // focus.  Repaint will occur in focusGained.
+                    tabPane.requestFocus();
+                }
+            }
+        }
+
+        //
+        // MouseMotionListener
+        //
+        public void mouseDragged(final MouseEvent e) {}
+
+        public void mouseMoved(final MouseEvent e) {
+            setRolloverTab(e.getX(), e.getY());
+        }
+
+        //
+        // FocusListener
+        //
+        public void focusGained(final FocusEvent e) {
+            setFocusIndex(tabPane.getSelectedIndex(), true);
+        }
+
+        public void focusLost(final FocusEvent e) {
+            repaintTab(focusIndex);
+        }
+
+        //
+        // ContainerListener
+        //
+        /* GES 2/3/99:
+           The container listener code was added to support HTML
+           rendering of tab titles.
+
+           Ideally, we would be able to listen for property changes
+           when a tab is added or its text modified.  At the moment
+           there are no such events because the Beans spec doesn't
+           allow 'indexed' property changes (i.e. tab 2's text changed
+           from A to B).
+
+           In order to get around this, we listen for tabs to be added
+           or removed by listening for the container events.  we then
+           queue up a runnable (so the component has a chance to complete
+           the add) which checks the tab title of the new component to see
+           if it requires HTML rendering.
+
+           The Views (one per tab title requiring HTML rendering) are
+           stored in the htmlViews Vector, which is only allocated after
+           the first time we run into an HTML tab.  Note that this vector
+           is kept in step with the number of pages, and nulls are added
+           for those pages whose tab title do not require HTML rendering.
+
+           This makes it easy for the paint and layout code to tell
+           whether to invoke the HTML engine without having to check
+           the string during time-sensitive operations.
+
+           When we have added a way to listen for tab additions and
+           changes to tab text, this code should be removed and
+           replaced by something which uses that.  */
+
+        public void componentAdded(final ContainerEvent e) {
+            final JTabbedPane tp = (JTabbedPane)e.getContainer();
+            final Component child = e.getChild();
+            if (child instanceof UIResource) {
+                return;
+            }
+            isRunsDirty = true;
+            updateHtmlViews(tp.indexOfComponent(child));
+        }
+
+        private void updateHtmlViews(int index) {
+            final String title = tabPane.getTitleAt(index);
+            final boolean isHTML = BasicHTML.isHTMLString(title);
+            if (isHTML) {
+                if (htmlViews == null) { // Initialize vector
+                    htmlViews = createHTMLVector();
+                } else { // Vector already exists
+                    final View v = BasicHTML.createHTMLView(tabPane, title);
+                    htmlViews.insertElementAt(v, index);
+                }
+            } else { // Not HTML
+                if (htmlViews != null) { // Add placeholder
+                    htmlViews.insertElementAt(null, index);
+                } // else nada!
+            }
+            updateMnemonics();
+        }
+
+        public void componentRemoved(final ContainerEvent e) {
+            final JTabbedPane tp = (JTabbedPane)e.getContainer();
+            final Component child = e.getChild();
+            if (child instanceof UIResource) {
+                return;
+            }
+
+            // NOTE 4/15/2002 (joutwate):
+            // This fix is implemented using client properties since there is
+            // currently no IndexPropertyChangeEvent.  Once
+            // IndexPropertyChangeEvents have been added this code should be
+            // modified to use it.
+            final Integer indexObj = (Integer)tp.getClientProperty("__index_to_remove__");
+            if (indexObj != null) {
+                final int index = indexObj.intValue();
+                if (htmlViews != null && htmlViews.size() > index) {
+                    htmlViews.removeElementAt(index);
+                }
+                tp.putClientProperty("__index_to_remove__", null);
+            }
+            isRunsDirty = true;
+            updateMnemonics();
+
+            validateFocusIndex();
+        }
+    }
+
+    /**
+     * This class should be treated as a &quot;protected&quot; inner class.
+     * Instantiate it only within subclasses of BasicTabbedPaneUI.
+     */
+    public class PropertyChangeHandler implements PropertyChangeListener {
+        // NOTE: This class exists only for backward compatability. All
+        // its functionality has been moved into Handler. If you need to add
+        // new functionality add it to the Handler, but make sure this
+        // class calls into the Handler.
+        public void propertyChange(final PropertyChangeEvent e) {
+            getHandler().propertyChange(e);
+        }
+    }
+
+    /**
+     * This class should be treated as a &quot;protected&quot; inner class.
+     * Instantiate it only within subclasses of BasicTabbedPaneUI.
+     */
+    public class TabSelectionHandler implements ChangeListener {
+        // NOTE: This class exists only for backward compatability. All
+        // its functionality has been moved into Handler. If you need to add
+        // new functionality add it to the Handler, but make sure this
+        // class calls into the Handler.
+        public void stateChanged(final ChangeEvent e) {
+            getHandler().stateChanged(e);
+        }
+    }
+
+    /**
+     * This class should be treated as a &quot;protected&quot; inner class.
+     * Instantiate it only within subclasses of BasicTabbedPaneUI.
+     */
+    public class MouseHandler extends MouseAdapter {
+        // NOTE: This class exists only for backward compatability. All
+        // its functionality has been moved into Handler. If you need to add
+        // new functionality add it to the Handler, but make sure this
+        // class calls into the Handler.
+        public void mousePressed(final MouseEvent e) {
+            getHandler().mousePressed(e);
+        }
+    }
+
+    /**
+     * This class should be treated as a &quot;protected&quot; inner class.
+     * Instantiate it only within subclasses of BasicTabbedPaneUI.
+     */
+    public class FocusHandler extends FocusAdapter {
+        // NOTE: This class exists only for backward compatability. All
+        // its functionality has been moved into Handler. If you need to add
+        // new functionality add it to the Handler, but make sure this
+        // class calls into the Handler.
+        public void focusGained(final FocusEvent e) {
+            getHandler().focusGained(e);
+        }
+
+        public void focusLost(final FocusEvent e) {
+            getHandler().focusLost(e);
+        }
+    }
+
+    private Vector<View> createHTMLVector() {
+        final Vector<View> htmlViews = new Vector<View>();
+        final int count = tabPane.getTabCount();
+        if (count > 0) {
+            for (int i = 0; i < count; i++) {
+                final String title = tabPane.getTitleAt(i);
+                if (BasicHTML.isHTMLString(title)) {
+                    htmlViews.addElement(BasicHTML.createHTMLView(tabPane, title));
+                } else {
+                    htmlViews.addElement(null);
+                }
+            }
+        }
+        return htmlViews;
+    }
+
+    private class TabContainer extends JPanel implements UIResource {
+        private boolean notifyTabbedPane = true;
+
+        public TabContainer() {
+            super(null);
+            setOpaque(false);
+        }
+
+        public void remove(final Component comp) {
+            final int index = tabPane.indexOfTabComponent(comp);
+            super.remove(comp);
+            if (notifyTabbedPane && index != -1) {
+                tabPane.setTabComponentAt(index, null);
+            }
+        }
+
+        private void removeUnusedTabComponents() {
+            for (final Component c : getComponents()) {
+                if (!(c instanceof UIResource)) {
+                    final int index = tabPane.indexOfTabComponent(c);
+                    if (index == -1) {
+                        super.remove(c);
+                    }
+                }
+            }
+        }
+
+        public boolean isOptimizedDrawingEnabled() {
+            return tabScroller != null && !tabScroller.croppedEdge.isParamsSet();
+        }
+
+        public void doLayout() {
+            // We layout tabComponents in JTabbedPane's layout manager
+            // and use this method as a hook for repainting tabs
+            // to update tabs area e.g. when the size of tabComponent was changed
+            if (scrollableTabLayoutEnabled()) {
+                tabScroller.tabPanel.repaint();
+                tabScroller.updateView();
+            } else {
+                tabPane.repaint(getBounds());
+            }
+        }
+    }
+
+    private class CroppedEdge extends JPanel implements UIResource {
+        private Shape shape;
+        private int tabIndex;
+        private int cropline;
+        private int cropx, cropy;
+
+        public CroppedEdge() {
+            setOpaque(false);
+        }
+
+        public void setParams(final int tabIndex, final int cropline, final int cropx, final int cropy) {
+            this.tabIndex = tabIndex;
+            this.cropline = cropline;
+            this.cropx = cropx;
+            this.cropy = cropy;
+            final Rectangle tabRect = rects[tabIndex];
+            setBounds(tabRect);
+            shape = createCroppedTabShape(tabPane.getTabPlacement(), tabRect, cropline);
+            if (getParent() == null && tabContainer != null) {
+                tabContainer.add(this, 0);
+            }
+        }
+
+        public void resetParams() {
+            shape = null;
+            if (getParent() == tabContainer && tabContainer != null) {
+                tabContainer.remove(this);
+            }
+        }
+
+        public boolean isParamsSet() {
+            return shape != null;
+        }
+
+        public int getTabIndex() {
+            return tabIndex;
+        }
+
+        public int getCropline() {
+            return cropline;
+        }
+
+        public int getCroppedSideWidth() {
+            return 3;
+        }
+
+        private Color getBgColor() {
+            final Component parent = tabPane.getParent();
+            if (parent != null) {
+                final Color bg = parent.getBackground();
+                if (bg != null) {
+                    return bg;
+                }
+            }
+            return UIManager.getColor("control");
+        }
+
+        protected void paintComponent(final Graphics g) {
+            super.paintComponent(g);
+            if (isParamsSet() && g instanceof Graphics2D) {
+                final Graphics2D g2 = (Graphics2D)g;
+                g2.clipRect(0, 0, getWidth(), getHeight());
+                g2.setColor(getBgColor());
+                g2.translate(cropx, cropy);
+                g2.fill(shape);
+                paintCroppedTabEdge(g);
+                g2.translate(-cropx, -cropy);
+            }
+        }
+    }
+
+    /**
+     * An ActionMap that populates its contents as necessary. The
+     * contents are populated by invoking the <code>loadActionMap</code>
+     * method on the passed in Object.
+     *
+     * @version 1.6, 11/17/05
+     * @author Scott Violet
+     */
+    static class LazyActionMap extends ActionMapUIResource {
+        /**
+         * Object to invoke <code>loadActionMap</code> on. This may be
+         * a Class object.
+         */
+        private transient Object _loader;
+
+        /**
+         * Installs an ActionMap that will be populated by invoking the
+         * <code>loadActionMap</code> method on the specified Class
+         * when necessary.
+         * <p>
+         * This should be used if the ActionMap can be shared.
+         *
+         * @param c JComponent to install the ActionMap on.
+         * @param loaderClass Class object that gets loadActionMap invoked
+         *                    on.
+         * @param defaultsKey Key to use to defaults table to check for
+         *        existing map and what resulting Map will be registered on.
+         */
+        static void installLazyActionMap(final JComponent c, final Class<AquaTabbedPaneCopyFromBasicUI> loaderClass, final String defaultsKey) {
+            ActionMap map = (ActionMap)UIManager.get(defaultsKey);
+            if (map == null) {
+                map = new LazyActionMap(loaderClass);
+                UIManager.getLookAndFeelDefaults().put(defaultsKey, map);
+            }
+            SwingUtilities.replaceUIActionMap(c, map);
+        }
+
+        /**
+         * Returns an ActionMap that will be populated by invoking the
+         * <code>loadActionMap</code> method on the specified Class
+         * when necessary.
+         * <p>
+         * This should be used if the ActionMap can be shared.
+         *
+         * @param c JComponent to install the ActionMap on.
+         * @param loaderClass Class object that gets loadActionMap invoked
+         *                    on.
+         * @param defaultsKey Key to use to defaults table to check for
+         *        existing map and what resulting Map will be registered on.
+         */
+        static ActionMap getActionMap(final Class<AquaTabbedPaneCopyFromBasicUI> loaderClass, final String defaultsKey) {
+            ActionMap map = (ActionMap)UIManager.get(defaultsKey);
+            if (map == null) {
+                map = new LazyActionMap(loaderClass);
+                UIManager.getLookAndFeelDefaults().put(defaultsKey, map);
+            }
+            return map;
+        }
+
+        private LazyActionMap(final Class<AquaTabbedPaneCopyFromBasicUI> loader) {
+            _loader = loader;
+        }
+
+        public void put(final Action action) {
+            put(action.getValue(Action.NAME), action);
+        }
+
+        public void put(final Object key, final Action action) {
+            loadIfNecessary();
+            super.put(key, action);
+        }
+
+        public Action get(final Object key) {
+            loadIfNecessary();
+            return super.get(key);
+        }
+
+        public void remove(final Object key) {
+            loadIfNecessary();
+            super.remove(key);
+        }
+
+        public void clear() {
+            loadIfNecessary();
+            super.clear();
+        }
+
+        public Object[] keys() {
+            loadIfNecessary();
+            return super.keys();
+        }
+
+        public int size() {
+            loadIfNecessary();
+            return super.size();
+        }
+
+        public Object[] allKeys() {
+            loadIfNecessary();
+            return super.allKeys();
+        }
+
+        public void setParent(final ActionMap map) {
+            loadIfNecessary();
+            super.setParent(map);
+        }
+
+        private void loadIfNecessary() {
+            if (_loader != null) {
+                final Object loader = _loader;
+
+                _loader = null;
+                final Class<?> klass = (Class<?>)loader;
+                try {
+                    final java.lang.reflect.Method method = klass.getDeclaredMethod("loadActionMap", new Class[] { LazyActionMap.class });
+                    method.invoke(klass, new Object[] { this });
+                } catch (final NoSuchMethodException nsme) {
+                    assert false : "LazyActionMap unable to load actions " + klass;
+                } catch (final IllegalAccessException iae) {
+                    assert false : "LazyActionMap unable to load actions " + iae;
+                } catch (final InvocationTargetException ite) {
+                    assert false : "LazyActionMap unable to load actions " + ite;
+                } catch (final IllegalArgumentException iae) {
+                    assert false : "LazyActionMap unable to load actions " + iae;
+                }
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneTabState.java b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneTabState.java
new file mode 100644
index 0000000..52140bc
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneTabState.java
@@ -0,0 +1,433 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.SwingConstants;
+
+class AquaTabbedPaneTabState {
+    static final int FIXED_SCROLL_TAB_LENGTH = 27;
+
+    protected final Rectangle leftScrollTabRect = new Rectangle();
+    protected final Rectangle rightScrollTabRect = new Rectangle();
+
+    protected int numberOfVisibleTabs = 0;
+    protected int visibleTabList[] = new int[10];
+    protected int lastLeftmostTab;
+    protected int lastReturnAt;
+
+    private boolean needsScrollers;
+    private boolean hasMoreLeftTabs;
+    private boolean hasMoreRightTabs;
+
+    private final AquaTabbedPaneUI pane;
+
+    protected AquaTabbedPaneTabState(final AquaTabbedPaneUI pane) {
+        this.pane = pane;
+    }
+
+    protected int getIndex(final int i) {
+        if (i >= visibleTabList.length) return Integer.MIN_VALUE;
+        return visibleTabList[i];
+    }
+
+    protected void init(final int tabCount) {
+        if (tabCount < 1) needsScrollers = false;
+        if (tabCount == visibleTabList.length) return;
+        final int[] tempVisibleTabs = new int[tabCount];
+        System.arraycopy(visibleTabList, 0, tempVisibleTabs, 0, Math.min(visibleTabList.length, tabCount));
+        visibleTabList = tempVisibleTabs;
+    }
+
+    int getTotal() {
+        return numberOfVisibleTabs;
+    }
+
+    boolean needsScrollTabs() {
+        return needsScrollers;
+    }
+
+    void setNeedsScrollers(final boolean needsScrollers) {
+        this.needsScrollers = needsScrollers;
+    }
+
+    boolean needsLeftScrollTab() {
+        return hasMoreLeftTabs;
+    }
+
+    boolean needsRightScrollTab() {
+        return hasMoreRightTabs;
+    }
+
+    Rectangle getLeftScrollTabRect() {
+        return leftScrollTabRect;
+    }
+
+    Rectangle getRightScrollTabRect() {
+        return rightScrollTabRect;
+    }
+
+    boolean isBefore(final int i) {
+        if (numberOfVisibleTabs == 0) return true;
+        if (i < visibleTabList[0]) return true;
+        return false;
+    }
+
+    boolean isAfter(final int i) {
+        if (i > visibleTabList[numberOfVisibleTabs - 1]) return true;
+        return false;
+    }
+
+    private void addToEnd(final int idToAdd, final int length) {
+        visibleTabList[length] = idToAdd;
+    }
+
+    private void addToBeginning(final int idToAdd, final int length) {
+        System.arraycopy(visibleTabList, 0, visibleTabList, 1, length);
+        visibleTabList[0] = idToAdd;
+    }
+
+
+    void relayoutForScrolling(final Rectangle[] rects, final int startX, final int startY, final int returnAt, final int selectedIndex, final boolean verticalTabRuns, final int tabCount, final boolean isLeftToRight) {
+        if (!needsScrollers) {
+            hasMoreLeftTabs = false;
+            hasMoreRightTabs = false;
+            return;
+        }
+
+        // we don't fit, so we need to figure the space based on the size of the popup
+        // tab, then add the tabs, centering the selected tab as much as possible.
+
+        // Tabs on TOP or BOTTOM or LEFT or RIGHT
+        // if top or bottom, width is hardocoded
+        // if left or right height should be hardcoded.
+        if (verticalTabRuns) {
+            rightScrollTabRect.height = FIXED_SCROLL_TAB_LENGTH;
+            leftScrollTabRect.height = FIXED_SCROLL_TAB_LENGTH;
+        } else {
+            rightScrollTabRect.width = FIXED_SCROLL_TAB_LENGTH;
+            leftScrollTabRect.width = FIXED_SCROLL_TAB_LENGTH;
+        }
+
+        // we have all the tab rects, we just need to adjust the x coordinates
+        // and populate the visible list
+
+        // sja fix what do we do if remaining width is <0??
+
+        // we could try to center it based on width of tabs, but for now
+        // we try to center based on number of tabs on each side, putting the extra
+        // on the left (since the first right is the selected tab).
+        // if we have 0 selected we will just go right, and if we have
+
+        // the logic here is start with the selected tab, and then fit
+        // in as many tabs as possible on each side until we don't fit any more.
+        // but if all we did was change selection then we need to try to keep the same
+        // tabs on screen so we don't get a jarring tab moving out from under the mouse
+        // effect.
+
+        final boolean sizeChanged = returnAt != lastReturnAt;
+        // so if we stay the same, make right the first tab and say left done = true
+        if (pane.popupSelectionChanged || sizeChanged) {
+            pane.popupSelectionChanged = false;
+            lastLeftmostTab = -1;
+        }
+
+        int right = selectedIndex;
+        int left = selectedIndex - 1;
+
+        // if we had a good last leftmost tab then we set left to unused and
+        // start at that tab.
+        if (lastLeftmostTab >= 0) {
+            right = lastLeftmostTab;
+            left = -1;
+        } else if (selectedIndex < 0) {
+            // this is if there is none selected see radar 3138137
+            right = 0;
+            left = -1;
+        }
+
+        int remainingSpace = returnAt - pane.tabAreaInsets.right - pane.tabAreaInsets.left - FIXED_SCROLL_TAB_LENGTH * 2;
+        int visibleCount = 0;
+
+        final Rectangle firstRect = rects[right];
+        if ((verticalTabRuns ? firstRect.height : firstRect.width) > remainingSpace) {
+            // always show at least the selected one!
+            addToEnd(right, visibleCount);
+            if (verticalTabRuns) {
+                firstRect.height = remainingSpace; // force it to fit!
+            } else {
+                firstRect.width = remainingSpace; // force it to fit!
+            }
+            visibleCount++;
+        } else {
+            boolean rightDone = false;
+            boolean leftDone = false;
+
+            // at least one if not more will fit
+            while ((visibleCount < tabCount) && !(rightDone && leftDone)) {
+                if (!rightDone && right >= 0 && right < tabCount) {
+                    final Rectangle rightRect = rects[right];
+                    if ((verticalTabRuns ? rightRect.height : rightRect.width) > remainingSpace) {
+                        rightDone = true;
+                    } else {
+                        addToEnd(right, visibleCount);
+                        visibleCount++;
+                        remainingSpace -= (verticalTabRuns ? rightRect.height : rightRect.width);
+                        right++;
+                        continue; // this gives a bias to "paging forward", and "inching backward"
+                    }
+                } else {
+                    rightDone = true;
+                }
+
+                if (!leftDone && left >= 0 && left < tabCount) {
+                    final Rectangle leftRect = rects[left];
+                    if ((verticalTabRuns ? leftRect.height : leftRect.width) > remainingSpace) {
+                        leftDone = true;
+                    } else {
+                        addToBeginning(left, visibleCount);
+                        visibleCount++;
+                        remainingSpace -= (verticalTabRuns ? leftRect.height : leftRect.width);
+                        left--;
+                    }
+                } else {
+                    leftDone = true;
+                }
+            }
+        }
+
+        if (visibleCount > visibleTabList.length) visibleCount = visibleTabList.length;
+
+        hasMoreLeftTabs = visibleTabList[0] > 0;
+        hasMoreRightTabs = visibleTabList[visibleCount - 1] < visibleTabList.length - 1;
+
+        numberOfVisibleTabs = visibleCount;
+        // add the scroll tab at the end;
+        lastLeftmostTab = getIndex(0);
+        lastReturnAt = returnAt;
+
+        final int firstTabIndex = getIndex(0);
+        final int lastTabIndex = getIndex(visibleCount - 1);
+
+        // move all "invisible" tabs beyond the edge of known space...
+        for (int i = 0; i < tabCount; i++) {
+            if (i < firstTabIndex || i > lastTabIndex) {
+                final Rectangle rect = rects[i];
+                rect.x = Short.MAX_VALUE;
+                rect.y = Short.MAX_VALUE;
+            }
+        }
+    }
+
+    protected void alignRectsRunFor(final Rectangle[] rects, final Dimension tabPaneSize, final int tabPlacement, final boolean isRightToLeft) {
+        final boolean isVertical = tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT;
+
+        if (isVertical) {
+            if (needsScrollers) {
+                stretchScrollingVerticalRun(rects, tabPaneSize);
+            } else {
+                centerVerticalRun(rects, tabPaneSize);
+            }
+        } else {
+            if (needsScrollers) {
+                stretchScrollingHorizontalRun(rects, tabPaneSize, isRightToLeft);
+            } else {
+                centerHorizontalRun(rects, tabPaneSize, isRightToLeft);
+            }
+        }
+    }
+
+    private void centerHorizontalRun(final Rectangle[] rects, final Dimension size, final boolean isRightToLeft) {
+        int totalLength = 0;
+        for (final Rectangle element : rects) {
+            totalLength += element.width;
+        }
+
+        int x = size.width / 2 - totalLength / 2;
+
+        if (isRightToLeft) {
+            for (final Rectangle rect : rects) {
+                rect.x = x;
+                x += rect.width;
+            }
+        } else {
+            for (int i = rects.length - 1; i >= 0; i--) {
+                final Rectangle rect = rects[i];
+                rect.x = x;
+                x += rect.width;
+            }
+        }
+    }
+
+    private void centerVerticalRun(final Rectangle[] rects, final Dimension size) {
+        int totalLength = 0;
+        for (final Rectangle element : rects) {
+            totalLength += element.height;
+        }
+
+        int y = size.height / 2 - totalLength / 2;
+
+        if (true) {
+            for (final Rectangle rect : rects) {
+                rect.y = y;
+                y += rect.height;
+            }
+        } else {
+            for (int i = rects.length - 1; i >= 0; i--) {
+                final Rectangle rect = rects[i];
+                rect.y = y;
+                y += rect.height;
+            }
+        }
+    }
+
+    private void stretchScrollingHorizontalRun(final Rectangle[] rects, final Dimension size, final boolean isRightToLeft) {
+        final int totalTabs = getTotal();
+        final int firstTabIndex = getIndex(0);
+        final int lastTabIndex = getIndex(totalTabs - 1);
+
+        int totalRunLength = 0;
+        for (int i = firstTabIndex; i <= lastTabIndex; i++) {
+            totalRunLength += rects[i].width;
+        }
+
+        int slack = size.width - totalRunLength - pane.tabAreaInsets.left - pane.tabAreaInsets.right;
+        if (needsLeftScrollTab()) {
+            slack -= FIXED_SCROLL_TAB_LENGTH;
+        }
+        if (needsRightScrollTab()) {
+            slack -= FIXED_SCROLL_TAB_LENGTH;
+        }
+
+        final int minSlack = (int)((float)(slack) / (float)(totalTabs));
+        int extraSlack = slack - (minSlack * totalTabs);
+        int runningLength = 0;
+        final int xOffset = pane.tabAreaInsets.left + (needsLeftScrollTab() ? FIXED_SCROLL_TAB_LENGTH : 0);
+
+        if (isRightToLeft) {
+            for (int i = firstTabIndex; i <= lastTabIndex; i++) {
+                final Rectangle rect = rects[i];
+                int slackToAdd = minSlack;
+                if (extraSlack > 0) {
+                    slackToAdd++;
+                    extraSlack--;
+                }
+                rect.x = runningLength + xOffset;
+                rect.width += slackToAdd;
+                runningLength += rect.width;
+            }
+        } else {
+            for (int i = lastTabIndex; i >= firstTabIndex; i--) {
+                final Rectangle rect = rects[i];
+                int slackToAdd = minSlack;
+                if (extraSlack > 0) {
+                    slackToAdd++;
+                    extraSlack--;
+                }
+                rect.x = runningLength + xOffset;
+                rect.width += slackToAdd;
+                runningLength += rect.width;
+            }
+        }
+
+        if (isRightToLeft) {
+            leftScrollTabRect.x = pane.tabAreaInsets.left;
+            leftScrollTabRect.y = rects[firstTabIndex].y;
+            leftScrollTabRect.height = rects[firstTabIndex].height;
+
+            rightScrollTabRect.x = size.width - pane.tabAreaInsets.right - rightScrollTabRect.width;
+            rightScrollTabRect.y = rects[lastTabIndex].y;
+            rightScrollTabRect.height = rects[lastTabIndex].height;
+        } else {
+            rightScrollTabRect.x = pane.tabAreaInsets.left;
+            rightScrollTabRect.y = rects[firstTabIndex].y;
+            rightScrollTabRect.height = rects[firstTabIndex].height;
+
+            leftScrollTabRect.x = size.width - pane.tabAreaInsets.right - rightScrollTabRect.width;
+            leftScrollTabRect.y = rects[lastTabIndex].y;
+            leftScrollTabRect.height = rects[lastTabIndex].height;
+
+            if (needsLeftScrollTab()) {
+                for (int i = lastTabIndex; i >= firstTabIndex; i--) {
+                    final Rectangle rect = rects[i];
+                    rect.x -= FIXED_SCROLL_TAB_LENGTH;
+                }
+            }
+
+            if (needsRightScrollTab()) {
+                for (int i = lastTabIndex; i >= firstTabIndex; i--) {
+                    final Rectangle rect = rects[i];
+                    rect.x += FIXED_SCROLL_TAB_LENGTH;
+                }
+            }
+        }
+    }
+
+    private void stretchScrollingVerticalRun(final Rectangle[] rects, final Dimension size) {
+        final int totalTabs = getTotal();
+        final int firstTabIndex = getIndex(0);
+        final int lastTabIndex = getIndex(totalTabs - 1);
+
+        int totalRunLength = 0;
+        for (int i = firstTabIndex; i <= lastTabIndex; i++) {
+            totalRunLength += rects[i].height;
+        }
+
+        int slack = size.height - totalRunLength - pane.tabAreaInsets.top - pane.tabAreaInsets.bottom;
+        if (needsLeftScrollTab()) {
+            slack -= FIXED_SCROLL_TAB_LENGTH;
+        }
+        if (needsRightScrollTab()) {
+            slack -= FIXED_SCROLL_TAB_LENGTH;
+        }
+
+        final int minSlack = (int)((float)(slack) / (float)(totalTabs));
+        int extraSlack = slack - (minSlack * totalTabs);
+        int runningLength = 0;
+        final int yOffset = pane.tabAreaInsets.top + (needsLeftScrollTab() ? FIXED_SCROLL_TAB_LENGTH : 0);
+
+        for (int i = firstTabIndex; i <= lastTabIndex; i++) {
+            final Rectangle rect = rects[i];
+            int slackToAdd = minSlack;
+            if (extraSlack > 0) {
+                slackToAdd++;
+                extraSlack--;
+            }
+            rect.y = runningLength + yOffset;
+            rect.height += slackToAdd;
+            runningLength += rect.height;
+        }
+
+        leftScrollTabRect.x = rects[firstTabIndex].x;
+        leftScrollTabRect.y = pane.tabAreaInsets.top;
+        leftScrollTabRect.width = rects[firstTabIndex].width;
+
+        rightScrollTabRect.x = rects[lastTabIndex].x;
+        rightScrollTabRect.y = size.height - pane.tabAreaInsets.bottom - rightScrollTabRect.height;
+        rightScrollTabRect.width = rects[lastTabIndex].width;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java
new file mode 100644
index 0000000..f463d64
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java
@@ -0,0 +1,1234 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.AffineTransform;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+import javax.swing.text.View;
+
+import sun.swing.SwingUtilities2;
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+
+public class AquaTabbedPaneUI extends AquaTabbedPaneCopyFromBasicUI {
+    private static final int kSmallTabHeight = 20; // height of a small tab
+    private static final int kLargeTabHeight = 23; // height of a large tab
+    private static final int kMaxIconSize = kLargeTabHeight - 7;
+
+    private static final double kNinetyDegrees = (Math.PI / 2.0); // used for rotation
+
+    protected final Insets currentContentDrawingInsets = new Insets(0, 0, 0, 0);
+    protected final Insets currentContentBorderInsets = new Insets(0, 0, 0, 0);
+    protected final Insets contentDrawingInsets = new Insets(0, 0, 0, 0);
+
+    protected int pressedTab = -3; // -2 is right scroller, -1 is left scroller
+    protected boolean popupSelectionChanged;
+
+    protected Boolean isDefaultFocusReceiver = null;
+    protected boolean hasAvoidedFirstFocus = false;
+
+    // Create PLAF
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTabbedPaneUI();
+    }
+
+    protected final AquaTabbedPaneTabState visibleTabState = new AquaTabbedPaneTabState(this);
+    protected final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIStateFactory.getTab());
+
+    public AquaTabbedPaneUI() { }
+
+    protected void installListeners() {
+        super.installListeners();
+
+        // We're not just a mouseListener, we're a mouseMotionListener
+        if (mouseListener != null) {
+            tabPane.addMouseMotionListener((MouseMotionListener)mouseListener);
+        }
+    }
+
+    protected void installDefaults() {
+        super.installDefaults();
+
+        if (tabPane.getFont() instanceof UIResource) {
+            final Boolean b = (Boolean)UIManager.get("TabbedPane.useSmallLayout");
+            if (b != null && b == Boolean.TRUE) {
+                tabPane.setFont(UIManager.getFont("TabbedPane.smallFont"));
+                painter.state.set(Size.SMALL);
+            }
+        }
+
+        contentDrawingInsets.set(0, 11, 13, 10);
+        tabPane.setOpaque(false);
+    }
+
+    protected void assureRectsCreated(final int tabCount) {
+        visibleTabState.init(tabCount);
+        super.assureRectsCreated(tabCount);
+    }
+
+    protected void uninstallDefaults() {
+        contentDrawingInsets.set(0, 0, 0, 0);
+    }
+
+    protected MouseListener createMouseListener() {
+        return new MouseHandler();
+    }
+
+    protected FocusListener createFocusListener() {
+        return new FocusHandler();
+    }
+
+    protected PropertyChangeListener createPropertyChangeListener() {
+        return new TabbedPanePropertyChangeHandler();
+    }
+
+    protected LayoutManager createLayoutManager() {
+        return new AquaTruncatingTabbedPaneLayout();
+    }
+
+    protected boolean shouldRepaintSelectedTabOnMouseDown() {
+        return false;
+    }
+
+    // Paint Methods
+    // Cache for performance
+    final Rectangle fContentRect = new Rectangle();
+    final Rectangle fIconRect = new Rectangle();
+    final Rectangle fTextRect = new Rectangle();
+
+    // UI Rendering
+    public void paint(final Graphics g, final JComponent c) {
+        painter.state.set(getDirection());
+
+        final int tabPlacement = tabPane.getTabPlacement();
+        final int selectedIndex = tabPane.getSelectedIndex();
+        paintContentBorder(g, tabPlacement, selectedIndex);
+
+        // we want to call ensureCurrentLayout, but it's private
+        ensureCurrentLayout();
+        final Rectangle clipRect = g.getClipBounds();
+
+        final boolean active = tabPane.isEnabled();
+        final boolean frameActive = AquaFocusHandler.isActive(tabPane);
+        final boolean isLeftToRight = tabPane.getComponentOrientation().isLeftToRight() || tabPlacement == LEFT || tabPlacement == RIGHT;
+
+        // Paint tabRuns of tabs from back to front
+        if (visibleTabState.needsScrollTabs()) {
+            paintScrollingTabs(g, clipRect, tabPlacement, selectedIndex, active, frameActive, isLeftToRight);
+            return;
+        }
+
+        // old way
+        paintAllTabs(g, clipRect, tabPlacement, selectedIndex, active, frameActive, isLeftToRight);
+    }
+
+    protected void paintAllTabs(final Graphics g, final Rectangle clipRect, final int tabPlacement, final int selectedIndex, final boolean active, final boolean frameActive, final boolean isLeftToRight) {
+        boolean drawSelectedLast = false;
+        for (int i = 0; i < rects.length; i++) {
+            if (i == selectedIndex) {
+                drawSelectedLast = true;
+            } else {
+                if (rects[i].intersects(clipRect)) {
+                    paintTabNormal(g, tabPlacement, i, active, frameActive, isLeftToRight);
+                }
+            }
+        }
+
+        // paint the selected tab last.
+        if (drawSelectedLast && rects[selectedIndex].intersects(clipRect)) {
+            paintTabNormal(g, tabPlacement, selectedIndex, active, frameActive, isLeftToRight);
+        }
+    }
+
+    protected void paintScrollingTabs(final Graphics g, final Rectangle clipRect, final int tabPlacement, final int selectedIndex, final boolean active, final boolean frameActive, final boolean isLeftToRight) {
+//        final Graphics g2 = g.create();
+//        g2.setColor(Color.cyan);
+//        Rectangle r = new Rectangle();
+//        for (int i = 0; i < visibleTabState.getTotal(); i++) {
+//            r.add(rects[visibleTabState.getIndex(i)]);
+//        }
+//        g2.fillRect(r.x, r.y, r.width, r.height);
+//        g2.dispose();
+//        System.out.println(r);
+
+        // for each visible tab, except the selected one
+        for (int i = 0; i < visibleTabState.getTotal(); i++) {
+            final int realIndex = visibleTabState.getIndex(i);
+            if (realIndex != selectedIndex) {
+                if (rects[realIndex].intersects(clipRect)) {
+                    paintTabNormal(g, tabPlacement, realIndex, active, frameActive, isLeftToRight);
+                }
+            }
+        }
+
+        final Rectangle leftScrollTabRect = visibleTabState.getLeftScrollTabRect();
+        if (visibleTabState.needsLeftScrollTab() && leftScrollTabRect.intersects(clipRect)) {
+            paintTabNormalFromRect(g, tabPlacement, leftScrollTabRect, -2, fIconRect, fTextRect, visibleTabState.needsLeftScrollTab(), frameActive, isLeftToRight);
+        }
+
+        final Rectangle rightScrollTabRect = visibleTabState.getRightScrollTabRect();
+        if (visibleTabState.needsRightScrollTab() && rightScrollTabRect.intersects(clipRect)) {
+            paintTabNormalFromRect(g, tabPlacement, rightScrollTabRect, -1, fIconRect, fTextRect, visibleTabState.needsRightScrollTab(), frameActive, isLeftToRight);
+        }
+
+        if (selectedIndex >= 0) { // && rects[selectedIndex].intersects(clipRect)) {
+            paintTabNormal(g, tabPlacement, selectedIndex, active, frameActive, isLeftToRight);
+        }
+    }
+
+    private static boolean isScrollTabIndex(final int index) {
+        return index == -1 || index == -2;
+    }
+
+    protected static void transposeRect(final Rectangle r) {
+        int temp = r.y;
+        r.y = r.x;
+        r.x = temp;
+        temp = r.width;
+        r.width = r.height;
+        r.height = temp;
+    }
+
+    protected int getTabLabelShiftX(final int tabPlacement, final int tabIndex, final boolean isSelected) {
+        final Rectangle tabRect = (tabIndex >= 0 ? rects[tabIndex] : visibleTabState.getRightScrollTabRect());
+        int nudge = 0;
+        switch (tabPlacement) {
+            case LEFT:
+            case RIGHT:
+                nudge = tabRect.height % 2;
+                break;
+            case BOTTOM:
+            case TOP:
+            default:
+                nudge = tabRect.width % 2;
+        }
+        return nudge;
+    }
+
+    protected int getTabLabelShiftY(final int tabPlacement, final int tabIndex, final boolean isSelected) {
+        switch (tabPlacement) {
+            case RIGHT:
+            case LEFT:
+            case BOTTOM:
+                return -1;
+            case TOP:
+            default:
+                return 0;
+        }
+    }
+
+    protected Icon getIconForScrollTab(final int tabPlacement, final int tabIndex, final boolean enabled) {
+        boolean shouldFlip = !AquaUtils.isLeftToRight(tabPane);
+        if (tabPlacement == RIGHT) shouldFlip = false;
+        if (tabPlacement == LEFT) shouldFlip = true;
+
+        int direction = tabIndex == -1 ? EAST : WEST;
+        if (shouldFlip) {
+            if (direction == EAST) {
+                direction = WEST;
+            } else if (direction == WEST) {
+                direction = EAST;
+            }
+        }
+
+        if (enabled) return AquaImageFactory.getArrowIconForDirection(direction);
+
+        final Image icon = AquaImageFactory.getArrowImageForDirection(direction);
+        return new ImageIcon(AquaUtils.generateDisabledImage(icon));
+    }
+
+    protected void paintContents(final Graphics g, final int tabPlacement, final int tabIndex, final Rectangle tabRect, final Rectangle iconRect, final Rectangle textRect, final boolean isSelected) {
+        final Shape temp = g.getClip();
+        g.clipRect(fContentRect.x, fContentRect.y, fContentRect.width, fContentRect.height);
+
+        final Component component;
+        final String title;
+        final Icon icon;
+        if (isScrollTabIndex(tabIndex)) {
+            component = null;
+            title = null;
+            icon = getIconForScrollTab(tabPlacement, tabIndex, true);
+        } else {
+            component = getTabComponentAt(tabIndex);
+            if (component == null) {
+                title = tabPane.getTitleAt(tabIndex);
+                icon = getIconForTab(tabIndex);
+            } else {
+                title = null;
+                icon = null;
+            }
+        }
+
+        final boolean isVertical = tabPlacement == RIGHT || tabPlacement == LEFT;
+        if (isVertical) {
+            transposeRect(fContentRect);
+        }
+
+        final Font font = tabPane.getFont();
+        final FontMetrics metrics = g.getFontMetrics(font);
+
+        // our scrolling tabs
+        layoutLabel(tabPlacement, metrics, tabIndex < 0 ? 0 : tabIndex, title, icon, fContentRect, iconRect, textRect, false); // Never give it "isSelected" - ApprMgr handles this
+        if (isVertical) {
+            transposeRect(fContentRect);
+            transposeRect(iconRect);
+            transposeRect(textRect);
+        }
+
+        // from super.paintText - its normal text painting is totally wrong for the Mac
+        if (!(g instanceof Graphics2D)) {
+            g.setClip(temp);
+            return;
+        }
+        final Graphics2D g2d = (Graphics2D) g;
+
+        AffineTransform savedAT = null;
+        if (isVertical) {
+            savedAT = g2d.getTransform();
+            rotateGraphics(g2d, tabRect, textRect, iconRect, tabPlacement);
+        }
+
+        // not for the scrolling tabs
+        if (tabIndex >= 0) {
+            paintTitle(g2d, font, metrics, textRect, tabIndex, title);
+        }
+
+        if (icon != null) {
+            paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
+        }
+
+        if (savedAT != null) {
+            g2d.setTransform(savedAT);
+        }
+
+        g.setClip(temp);
+    }
+
+    protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
+        final View v = getTextViewForTab(tabIndex);
+        if (v != null) {
+            v.paint(g2d, textRect);
+            return;
+        }
+
+        if (title == null) return;
+
+        final Color color = tabPane.getForegroundAt(tabIndex);
+        if (color instanceof UIResource) {
+            // sja fix getTheme().setThemeTextColor(g, isSelected, isPressed && tracking, tabPane.isEnabledAt(tabIndex));
+            if (tabPane.isEnabledAt(tabIndex)) {
+                g2d.setColor(Color.black);
+            } else {
+                g2d.setColor(Color.gray);
+            }
+        } else {
+            g2d.setColor(color);
+        }
+
+        g2d.setFont(font);
+        SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
+    }
+
+    protected void rotateGraphics(final Graphics2D g2d, final Rectangle tabRect, final Rectangle textRect, final Rectangle iconRect, final int tabPlacement) {
+        int yDiff = 0; // textRect.y - tabRect.y;
+        int xDiff = 0; // (tabRect.x+tabRect.width) - (textRect.x+textRect.width);
+        int yIconDiff = 0; // iconRect.y - tabRect.y;
+        int xIconDiff = 0; // (tabRect.x+tabRect.width) - (iconRect.x + iconRect.width);
+
+        final double rotateAmount = (tabPlacement == LEFT ? -kNinetyDegrees : kNinetyDegrees);
+        g2d.transform(AffineTransform.getRotateInstance(rotateAmount, tabRect.x, tabRect.y));
+
+        // x and y diffs are named weirdly.
+        // I will rename them, but what they mean now is
+        // original x offset which will be used to adjust the y coordinate for the
+        // rotated context
+        if (tabPlacement == LEFT) {
+            g2d.translate(-tabRect.height - 1, 1);
+            xDiff = textRect.x - tabRect.x;
+            yDiff = tabRect.height + tabRect.y - (textRect.y + textRect.height);
+            xIconDiff = iconRect.x - tabRect.x;
+            yIconDiff = tabRect.height + tabRect.y - (iconRect.y + iconRect.height);
+        } else {
+            g2d.translate(0, -tabRect.width - 1);
+            yDiff = textRect.y - tabRect.y;
+            xDiff = (tabRect.x + tabRect.width) - (textRect.x + textRect.width);
+            yIconDiff = iconRect.y - tabRect.y;
+            xIconDiff = (tabRect.x + tabRect.width) - (iconRect.x + iconRect.width);
+        }
+
+        // rotation changes needed for the rendering
+        // we are rotating so we can't just use the rects wholesale.
+        textRect.x = tabRect.x + yDiff;
+        textRect.y = tabRect.y + xDiff;
+
+        int tempVal = textRect.height;
+        textRect.height = textRect.width;
+        textRect.width = tempVal;
+    // g.setColor(Color.red);
+    // g.drawLine(textRect.x, textRect.y, textRect.x+textRect.height, textRect.y+textRect.width);
+    // g.drawLine(textRect.x+textRect.height, textRect.y, textRect.x, textRect.y+textRect.width);
+
+        iconRect.x = tabRect.x + yIconDiff;
+        iconRect.y = tabRect.y + xIconDiff;
+
+        tempVal = iconRect.height;
+        iconRect.height = iconRect.width;
+        iconRect.width = tempVal;
+    }
+
+    protected void paintTabNormal(final Graphics g, final int tabPlacement, final int tabIndex, final boolean active, final boolean frameActive, final boolean isLeftToRight) {
+        paintTabNormalFromRect(g, tabPlacement, rects[tabIndex], tabIndex, fIconRect, fTextRect, active, frameActive, isLeftToRight);
+    }
+
+    protected void paintTabNormalFromRect(final Graphics g, final int tabPlacement, final Rectangle tabRect, final int nonRectIndex, final Rectangle iconRect, final Rectangle textRect, final boolean active, final boolean frameActive, final boolean isLeftToRight) {
+        final int selectedIndex = tabPane.getSelectedIndex();
+        final boolean isSelected = selectedIndex == nonRectIndex;
+
+        paintCUITab(g, tabPlacement, tabRect, isSelected, frameActive, isLeftToRight, nonRectIndex);
+
+        textRect.setBounds(tabRect);
+        fContentRect.setBounds(tabRect);
+        paintContents(g, tabPlacement, nonRectIndex, tabRect, iconRect, textRect, isSelected);
+    }
+
+    protected void paintCUITab(final Graphics g, final int tabPlacement, final Rectangle tabRect, final boolean isSelected, final boolean frameActive, final boolean isLeftToRight, final int nonRectIndex) {
+        final int tabCount = tabPane.getTabCount();
+
+        final boolean needsLeftScrollTab = visibleTabState.needsLeftScrollTab();
+        final boolean needsRightScrollTab = visibleTabState.needsRightScrollTab();
+
+        // first or last
+        boolean first = nonRectIndex == 0;
+        boolean last = nonRectIndex == tabCount - 1;
+        if (needsLeftScrollTab || needsRightScrollTab) {
+            if (nonRectIndex == -1) {
+                first = false;
+                last = true;
+            } else if (nonRectIndex == -2) {
+                first = true;
+                last = false;
+            } else {
+                if (needsLeftScrollTab) first = false;
+                if (needsRightScrollTab) last = false;
+            }
+        }
+
+        if (tabPlacement == LEFT || tabPlacement == RIGHT) {
+            final boolean tempSwap = last;
+            last = first;
+            first = tempSwap;
+        }
+
+        final State state = getState(nonRectIndex, frameActive, isSelected);
+        painter.state.set(state);
+        painter.state.set(isSelected || (state == State.INACTIVE && frameActive) ? BooleanValue.YES : BooleanValue.NO);
+        painter.state.set(getSegmentPosition(first, last, isLeftToRight));
+        final int selectedIndex = tabPane.getSelectedIndex();
+        painter.state.set(getSegmentTrailingSeparator(nonRectIndex, selectedIndex, isLeftToRight));
+        painter.state.set(getSegmentLeadingSeparator(nonRectIndex, selectedIndex, isLeftToRight));
+        painter.state.set(tabPane.hasFocus() && isSelected ? Focused.YES : Focused.NO);
+        painter.paint(g, tabPane, tabRect.x, tabRect.y, tabRect.width, tabRect.height);
+
+        if (isScrollTabIndex(nonRectIndex)) return;
+
+        final Color color = tabPane.getBackgroundAt(nonRectIndex);
+        if (color == null || (color instanceof UIResource)) return;
+
+        if (!isLeftToRight && (tabPlacement == TOP || tabPlacement == BOTTOM)) {
+            final boolean tempSwap = last;
+            last = first;
+            first = tempSwap;
+        }
+
+        fillTabWithBackground(g, tabRect, tabPlacement, first, last, color);
+    }
+
+    protected Direction getDirection() {
+        switch (tabPane.getTabPlacement()) {
+            case SwingConstants.BOTTOM: return Direction.SOUTH;
+            case SwingConstants.LEFT: return Direction.WEST;
+            case SwingConstants.RIGHT: return Direction.EAST;
+        }
+        return Direction.NORTH;
+    }
+
+    protected static SegmentPosition getSegmentPosition(final boolean first, final boolean last, final boolean isLeftToRight) {
+        if (first && last) return SegmentPosition.ONLY;
+        if (first) return isLeftToRight ? SegmentPosition.FIRST : SegmentPosition.LAST;
+        if (last) return isLeftToRight ? SegmentPosition.LAST : SegmentPosition.FIRST;
+        return SegmentPosition.MIDDLE;
+    }
+
+    protected SegmentTrailingSeparator getSegmentTrailingSeparator(final int index, final int selectedIndex, final boolean isLeftToRight) {
+        return SegmentTrailingSeparator.YES;
+    }
+
+    protected SegmentLeadingSeparator getSegmentLeadingSeparator(final int index, final int selectedIndex, final boolean isLeftToRight) {
+        return SegmentLeadingSeparator.NO;
+    }
+
+    protected boolean isTabBeforeSelectedTab(final int index, final int selectedIndex, final boolean isLeftToRight) {
+        if (index == -2 && visibleTabState.getIndex(0) == selectedIndex) return true;
+        int indexBeforeSelectedIndex = isLeftToRight ? selectedIndex - 1 : selectedIndex + 1;
+        return index == indexBeforeSelectedIndex ? true : false;
+    }
+
+    protected State getState(final int index, final boolean frameActive, final boolean isSelected) {
+        if (!frameActive) return State.INACTIVE;
+        if (!tabPane.isEnabled()) return State.DISABLED;
+        if (JRSUIUtils.TabbedPane.useLegacyTabs()) {
+            if (isSelected) return State.PRESSED;
+            if (pressedTab == index) return State.INACTIVE;
+        } else {
+            if (isSelected) return State.ACTIVE;
+            if (pressedTab == index) return State.PRESSED;
+        }
+        return State.ACTIVE;
+    }
+
+    /**
+     * This routine adjusts the background fill rect so it just fits inside a tab, allowing for
+     * whether we're talking about a first tab or last tab.  NOTE that this code is very much
+     * Aqua 2 dependent!
+     */
+    static class AlterRects {
+        Rectangle standard, first, last;
+        AlterRects(final int x, final int y, final int w, final int h) { standard = new Rectangle(x, y, w, h); }
+        AlterRects start(final int x, final int y, final int w, final int h) { first = new Rectangle(x, y, w, h); return this; }
+        AlterRects end(final int x, final int y, final int w, final int h) { last = new Rectangle(x, y, w, h); return this; }
+
+        static Rectangle alter(final Rectangle r, final Rectangle o) {
+            // r = new Rectangle(r);
+            r.x += o.x;
+            r.y += o.y;
+            r.width += o.width;
+            r.height += o.height;
+            return r;
+        }
+    }
+
+    static AlterRects[] alterRects = new AlterRects[5];
+
+    protected static AlterRects getAlterationFor(final int tabPlacement) {
+        if (alterRects[tabPlacement] != null) return alterRects[tabPlacement];
+
+        switch (tabPlacement) {
+            case LEFT: return alterRects[LEFT] = new AlterRects(2, 0, -4, 1).start(0, 0, 0, -4).end(0, 3, 0, -3);
+            case RIGHT: return alterRects[RIGHT] = new AlterRects(1, 0, -4, 1).start(0, 0, 0, -4).end(0, 3, 0, -3);
+            case BOTTOM: return alterRects[BOTTOM] = new AlterRects(0, 1, 0, -4).start(3, 0, -3, 0).end(0, 0, -3, 0);
+            case TOP:
+            default: return alterRects[TOP] = new AlterRects(0, 2, 0, -4).start(3, 0, -3, 0).end(0, 0, -3, 0);
+        }
+    }
+
+    protected void fillTabWithBackground(final Graphics g, final Rectangle rect, final int tabPlacement, final boolean first, final boolean last, final Color color) {
+        final Rectangle fillRect = new Rectangle(rect);
+
+        final AlterRects alteration = getAlterationFor(tabPlacement);
+        AlterRects.alter(fillRect, alteration.standard);
+        if (first) AlterRects.alter(fillRect, alteration.first);
+        if (last) AlterRects.alter(fillRect, alteration.last);
+
+        g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)(color.getAlpha() * 0.25)));
+        g.fillRoundRect(fillRect.x, fillRect.y, fillRect.width, fillRect.height, 3, 1);
+    }
+
+    protected Insets getContentBorderInsets(final int tabPlacement) {
+        final Insets draw = getContentDrawingInsets(tabPlacement); // will be rotated
+
+        rotateInsets(contentBorderInsets, currentContentBorderInsets, tabPlacement);
+
+        currentContentBorderInsets.left += draw.left;
+        currentContentBorderInsets.right += draw.right;
+        currentContentBorderInsets.top += draw.top;
+        currentContentBorderInsets.bottom += draw.bottom;
+
+        return currentContentBorderInsets;
+    }
+
+    protected static void rotateInsets(final Insets topInsets, final Insets targetInsets, final int targetPlacement) {
+        switch (targetPlacement) {
+            case LEFT:
+                targetInsets.top = topInsets.left;
+                targetInsets.left = topInsets.top;
+                targetInsets.bottom = topInsets.right;
+                targetInsets.right = topInsets.bottom;
+                break;
+            case BOTTOM:
+                targetInsets.top = topInsets.bottom;
+                targetInsets.left = topInsets.left;
+                targetInsets.bottom = topInsets.top;
+                targetInsets.right = topInsets.right;
+                break;
+            case RIGHT:
+                targetInsets.top = topInsets.right;
+                targetInsets.left = topInsets.bottom;
+                targetInsets.bottom = topInsets.left;
+                targetInsets.right = topInsets.top;
+                break;
+            case TOP:
+            default:
+                targetInsets.top = topInsets.top;
+                targetInsets.left = topInsets.left;
+                targetInsets.bottom = topInsets.bottom;
+                targetInsets.right = topInsets.right;
+        }
+    }
+
+    protected Insets getContentDrawingInsets(final int tabPlacement) {
+        rotateInsets(contentDrawingInsets, currentContentDrawingInsets, tabPlacement);
+        return currentContentDrawingInsets;
+    }
+
+    protected Icon getIconForTab(final int tabIndex) {
+        final Icon mainIcon = super.getIconForTab(tabIndex);
+        if (mainIcon == null) return null;
+
+        final int iconHeight = mainIcon.getIconHeight();
+        if (iconHeight <= kMaxIconSize) return mainIcon;
+        final float ratio = (float)kMaxIconSize / (float)iconHeight;
+
+        final int iconWidth = mainIcon.getIconWidth();
+        return new AquaIcon.CachingScalingIcon((int)(iconWidth * ratio), kMaxIconSize) {
+            Image createImage() {
+                return AquaIcon.getImageForIcon(mainIcon);
+            }
+        };
+    }
+
+    private static final int TAB_BORDER_INSET = 9;
+    protected void paintContentBorder(final Graphics g, final int tabPlacement, final int selectedIndex) {
+        final int width = tabPane.getWidth();
+        final int height = tabPane.getHeight();
+        final Insets insets = tabPane.getInsets();
+
+        int x = insets.left;
+        int y = insets.top;
+        int w = width - insets.right - insets.left;
+        int h = height - insets.top - insets.bottom;
+
+        switch (tabPlacement) {
+            case TOP:
+                y += TAB_BORDER_INSET;
+                h -= TAB_BORDER_INSET;
+                break;
+            case BOTTOM:
+                h -= TAB_BORDER_INSET;// - 2;
+                break;
+            case LEFT:
+                x += TAB_BORDER_INSET;// - 5;
+                w -= TAB_BORDER_INSET;// + 1;
+                break;
+            case RIGHT:
+                w -= TAB_BORDER_INSET;// + 1;
+                break;
+        }
+
+        if (tabPane.isOpaque()) {
+            g.setColor(tabPane.getBackground());
+            g.fillRect(0, 0, width, height);
+        }
+
+        AquaGroupBorder.getTabbedPaneGroupBorder().paintBorder(tabPane, g, x, y, w, h);
+    }
+
+    // see paintContentBorder
+    protected void repaintContentBorderEdge() {
+        final int width = tabPane.getWidth();
+        final int height = tabPane.getHeight();
+        final Insets insets = tabPane.getInsets();
+        final int tabPlacement = tabPane.getTabPlacement();
+        final Insets localContentBorderInsets = getContentBorderInsets(tabPlacement);
+
+        int x = insets.left;
+        int y = insets.top;
+        int w = width - insets.right - insets.left;
+        int h = height - insets.top - insets.bottom;
+
+        switch (tabPlacement) {
+            case LEFT:
+                x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
+                w = localContentBorderInsets.left;
+                break;
+            case RIGHT:
+                w = localContentBorderInsets.right;
+                break;
+            case BOTTOM:
+                h = localContentBorderInsets.bottom;
+                break;
+            case TOP:
+            default:
+                y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
+                h = localContentBorderInsets.top;
+        }
+        tabPane.repaint(x, y, w, h);
+    }
+
+    public boolean isTabVisible(final int index) {
+        if (index == -1 || index == -2) return true;
+        for (int i = 0; i < visibleTabState.getTotal(); i++) {
+            if (visibleTabState.getIndex(i) == index) return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns the tab index which intersects the specified point
+     * in the JTabbedPane's coordinate space.
+     */
+    public int tabForCoordinate(final JTabbedPane pane, final int x, final int y) {
+        ensureCurrentLayout();
+        final Point p = new Point(x, y);
+        if (visibleTabState.needsScrollTabs()) {
+            for (int i = 0; i < visibleTabState.getTotal(); i++) {
+                final int realOffset = visibleTabState.getIndex(i);
+                if (rects[realOffset].contains(p.x, p.y)) return realOffset;
+            }
+            if (visibleTabState.getRightScrollTabRect().contains(p.x, p.y)) return -1; //tabPane.getTabCount();
+        } else {
+            //old way
+            final int tabCount = tabPane.getTabCount();
+            for (int i = 0; i < tabCount; i++) {
+                if (rects[i].contains(p.x, p.y)) return i;
+            }
+        }
+        return -1;
+    }
+
+    protected Insets getTabInsets(final int tabPlacement, final int tabIndex) {
+        switch (tabPlacement) {
+            case LEFT: return UIManager.getInsets("TabbedPane.leftTabInsets");
+            case RIGHT: return UIManager.getInsets("TabbedPane.rightTabInsets");
+        }
+        return tabInsets;
+    }
+
+    // This is the preferred size - the layout manager will ignore if it has to
+    protected int calculateTabHeight(final int tabPlacement, final int tabIndex, final int fontHeight) {
+        // Constrain to what the Mac allows
+        final int result = super.calculateTabHeight(tabPlacement, tabIndex, fontHeight);
+
+        // force tabs to have a max height for aqua
+        if (result <= kSmallTabHeight) return kSmallTabHeight;
+        return kLargeTabHeight;
+    }
+
+    // JBuilder requested this - it's against HI, but then so are multiple rows
+    protected boolean shouldRotateTabRuns(final int tabPlacement) {
+        return false;
+    }
+
+    protected class TabbedPanePropertyChangeHandler extends PropertyChangeHandler {
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String prop = e.getPropertyName();
+
+            if (!AquaFocusHandler.FRAME_ACTIVE_PROPERTY.equals(prop)) {
+                super.propertyChange(e);
+                return;
+            }
+
+            final JTabbedPane comp = (JTabbedPane)e.getSource();
+            comp.repaint();
+
+            // Repaint the "front" tab and the border
+            final int selected = tabPane.getSelectedIndex();
+            final Rectangle[] theRects = rects;
+            if (selected >= 0 && selected < theRects.length) comp.repaint(theRects[selected]);
+            repaintContentBorderEdge();
+        }
+    }
+
+    protected ChangeListener createChangeListener() {
+        return new ChangeListener() {
+            public void stateChanged(final ChangeEvent e) {
+                if (!isTabVisible(tabPane.getSelectedIndex())) popupSelectionChanged = true;
+                tabPane.revalidate();
+                tabPane.repaint();
+            }
+        };
+    }
+
+    protected class FocusHandler extends FocusAdapter {
+        Rectangle sWorkingRect = new Rectangle();
+
+        public void focusGained(final FocusEvent e) {
+            if (isDefaultFocusReceiver(tabPane) && !hasAvoidedFirstFocus) {
+                KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();
+                hasAvoidedFirstFocus = true;
+            }
+            adjustPaintingRectForFocusRing(e);
+        }
+
+        public void focusLost(final FocusEvent e) {
+            adjustPaintingRectForFocusRing(e);
+        }
+
+        void adjustPaintingRectForFocusRing(final FocusEvent e) {
+            final JTabbedPane pane = (JTabbedPane)e.getSource();
+            final int tabCount = pane.getTabCount();
+            final int selectedIndex = pane.getSelectedIndex();
+
+            if (selectedIndex != -1 && tabCount > 0 && tabCount == rects.length) {
+                sWorkingRect.setBounds(rects[selectedIndex]);
+                sWorkingRect.grow(4, 4);
+                pane.repaint(sWorkingRect);
+            }
+        }
+
+        boolean isDefaultFocusReceiver(final JComponent component) {
+            if (isDefaultFocusReceiver == null) {
+                Component defaultFocusReceiver = KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy().getDefaultComponent(getTopLevelFocusCycleRootAncestor(component));
+                isDefaultFocusReceiver = new Boolean(defaultFocusReceiver != null && defaultFocusReceiver.equals(component));
+            }
+            return isDefaultFocusReceiver.booleanValue();
+        }
+
+        Container getTopLevelFocusCycleRootAncestor(Container container) {
+            Container ancestor;
+            while ((ancestor = container.getFocusCycleRootAncestor()) != null) {
+                container = ancestor;
+            }
+            return container;
+        }
+    }
+
+    public class MouseHandler extends MouseInputAdapter implements ActionListener {
+        protected int trackingTab = -3;
+        protected Timer popupTimer = new Timer(500, this);
+
+        public MouseHandler() {
+            popupTimer.setRepeats(false);
+        }
+
+        public void mousePressed(final MouseEvent e) {
+            final JTabbedPane pane = (JTabbedPane)e.getSource();
+            if (!pane.isEnabled()) {
+                trackingTab = -3;
+                return;
+            }
+
+            final Point p = e.getPoint();
+            trackingTab = getCurrentTab(pane, p);
+            if (trackingTab == -3 || (!shouldRepaintSelectedTabOnMouseDown() && trackingTab == pane.getSelectedIndex())) {
+                trackingTab = -3;
+                return;
+            }
+
+            if (trackingTab < 0 && trackingTab > -3) {
+                popupTimer.start();
+            }
+
+            pressedTab = trackingTab;
+            repaint(pane, pressedTab);
+        }
+
+        public void mouseDragged(final MouseEvent e) {
+            if (trackingTab < -2) return;
+
+            final JTabbedPane pane = (JTabbedPane)e.getSource();
+            final int currentTab = getCurrentTab(pane, e.getPoint());
+
+            if (currentTab != trackingTab) {
+                pressedTab = -3;
+            } else {
+                pressedTab = trackingTab;
+            }
+
+            if (trackingTab < 0 && trackingTab > -3) {
+                popupTimer.start();
+            }
+
+            repaint(pane, trackingTab);
+        }
+
+        public void mouseReleased(final MouseEvent e) {
+            if (trackingTab < -2) return;
+
+            popupTimer.stop();
+
+            final JTabbedPane pane = (JTabbedPane)e.getSource();
+            final Point p = e.getPoint();
+            final int currentTab = getCurrentTab(pane, p);
+
+            if (trackingTab == -1 && currentTab == -1) {
+                pane.setSelectedIndex(pane.getSelectedIndex() + 1);
+            }
+
+            if (trackingTab == -2 && currentTab == -2) {
+                pane.setSelectedIndex(pane.getSelectedIndex() - 1);
+            }
+
+            if (trackingTab >= 0 && currentTab == trackingTab) {
+                pane.setSelectedIndex(trackingTab);
+            }
+
+            repaint(pane, trackingTab);
+
+            pressedTab = -3;
+            trackingTab = -3;
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            if (trackingTab != pressedTab) {
+                return;
+            }
+
+            if (trackingTab == -1) {
+                showFullPopup(false);
+                trackingTab = -3;
+            }
+
+            if (trackingTab == -2) {
+                showFullPopup(true);
+                trackingTab = -3;
+            }
+        }
+
+        int getCurrentTab(final JTabbedPane pane, final Point p) {
+            final int tabIndex = tabForCoordinate(pane, p.x, p.y);
+            if (tabIndex >= 0 && pane.isEnabledAt(tabIndex)) return tabIndex;
+
+            if (visibleTabState.needsLeftScrollTab() && visibleTabState.getLeftScrollTabRect().contains(p)) return -2;
+            if (visibleTabState.needsRightScrollTab() && visibleTabState.getRightScrollTabRect().contains(p)) return -1;
+
+            return -3;
+        }
+
+        void repaint(final JTabbedPane pane, final int tab) {
+            switch (tab) {
+                case -1:
+                    pane.repaint(visibleTabState.getRightScrollTabRect());
+                    return;
+                case -2:
+                    pane.repaint(visibleTabState.getLeftScrollTabRect());
+                    return;
+                default:
+                    if (trackingTab >= 0) pane.repaint(rects[trackingTab]);
+                    return;
+            }
+        }
+
+        void showFullPopup(final boolean firstTab) {
+            final JPopupMenu popup = new JPopupMenu();
+
+            for (int i = 0; i < tabPane.getTabCount(); i++) {
+                if (firstTab ? visibleTabState.isBefore(i) : visibleTabState.isAfter(i)) {
+                    popup.add(createMenuItem(i));
+                }
+            }
+
+            if (firstTab) {
+                final Rectangle leftScrollTabRect = visibleTabState.getLeftScrollTabRect();
+                final Dimension popupRect = popup.getPreferredSize();
+                popup.show(tabPane, leftScrollTabRect.x - popupRect.width, leftScrollTabRect.y + 7);
+            } else {
+                final Rectangle rightScrollTabRect = visibleTabState.getRightScrollTabRect();
+                popup.show(tabPane, rightScrollTabRect.x + rightScrollTabRect.width, rightScrollTabRect.y + 7);
+            }
+
+            popup.addPopupMenuListener(new PopupMenuListener() {
+                public void popupMenuCanceled(final PopupMenuEvent e) { }
+                public void popupMenuWillBecomeVisible(final PopupMenuEvent e) { }
+
+                public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
+                    pressedTab = -3;
+                    tabPane.repaint(visibleTabState.getLeftScrollTabRect());
+                    tabPane.repaint(visibleTabState.getRightScrollTabRect());
+                }
+            });
+        }
+
+        JMenuItem createMenuItem(final int i) {
+            final Component component = getTabComponentAt(i);
+            final JMenuItem menuItem;
+            if (component == null) {
+                menuItem = new JMenuItem(tabPane.getTitleAt(i), tabPane.getIconAt(i));
+            } else {
+                menuItem = new JMenuItem() {
+                    public void paintComponent(final Graphics g) {
+                        super.paintComponent(g);
+                        final Dimension size = component.getSize();
+                        component.setSize(getSize());
+                        component.validate();
+                        component.paint(g);
+                        component.setSize(size);
+                    }
+
+                    public Dimension getPreferredSize() {
+                        return component.getPreferredSize();
+                    }
+                };
+            }
+
+            final Color background = tabPane.getBackgroundAt(i);
+            if (!(background instanceof UIResource)) {
+                menuItem.setBackground(background);
+            }
+
+            menuItem.setForeground(tabPane.getForegroundAt(i));
+            // for <rdar://problem/3520267> make sure to disable items that are disabled in the tab.
+            if (!tabPane.isEnabledAt(i)) menuItem.setEnabled(false);
+
+            final int fOffset = i;
+            menuItem.addActionListener(new ActionListener() {
+                public void actionPerformed(final ActionEvent ae) {
+                    boolean visible = isTabVisible(fOffset);
+                    tabPane.setSelectedIndex(fOffset);
+                    if (!visible) {
+                        popupSelectionChanged = true;
+                        tabPane.invalidate();
+                        tabPane.repaint();
+                    }
+                }
+            });
+
+            return menuItem;
+        }
+    }
+
+    protected class AquaTruncatingTabbedPaneLayout extends AquaTabbedPaneCopyFromBasicUI.TabbedPaneLayout {
+        // fix for Radar #3346131
+        protected int preferredTabAreaWidth(final int tabPlacement, final int height) {
+            // Our superclass wants to stack tabs, but we rotate them,
+            // so when tabs are on the left or right we know that
+            // our width is actually the "height" of a tab which is then
+            // rotated.
+            if (tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT) {
+                return super.preferredTabAreaHeight(tabPlacement, height);
+            }
+
+            return super.preferredTabAreaWidth(tabPlacement, height);
+        }
+
+        protected int preferredTabAreaHeight(final int tabPlacement, final int width) {
+            if (tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT) {
+                return super.preferredTabAreaWidth(tabPlacement, width);
+            }
+
+            return super.preferredTabAreaHeight(tabPlacement, width);
+        }
+
+        protected void calculateTabRects(final int tabPlacement, final int tabCount) {
+            if (tabCount <= 0) return;
+
+            superCalculateTabRects(tabPlacement, tabCount); // does most of the hard work
+
+            // If they haven't been padded (which they only do when there are multiple rows) we should center them
+            if (rects.length <= 0) return;
+
+            visibleTabState.alignRectsRunFor(rects, tabPane.getSize(), tabPlacement, AquaUtils.isLeftToRight(tabPane));
+        }
+
+        protected void padTabRun(final int tabPlacement, final int start, final int end, final int max) {
+            if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) {
+                super.padTabRun(tabPlacement, start, end, max);
+                return;
+            }
+
+            final Rectangle lastRect = rects[end];
+            final int runHeight = (lastRect.y + lastRect.height) - rects[start].y;
+            final int deltaHeight = max - (lastRect.y + lastRect.height);
+            final float factor = (float)deltaHeight / (float)runHeight;
+            for (int i = start; i <= end; i++) {
+                final Rectangle pastRect = rects[i];
+                if (i > start) {
+                    pastRect.y = rects[i - 1].y + rects[i - 1].height;
+                }
+                pastRect.height += Math.round(pastRect.height * factor);
+            }
+            lastRect.height = max - lastRect.y;
+        }
+
+        /**
+         * This is a massive routine and I left it like this because the bulk of the code comes
+         * from the BasicTabbedPaneUI class. Here is what it does:
+         * 1. Calculate rects for the tabs - we have to play tricks here because our right and left tabs
+         *    should get widths calculated the same way as top and bottom, but they will be rotated so the
+         *    calculated width is stored as the rect height.
+         * 2. Decide if we can fit all the tabs.
+         * 3. When we cannot fit all the tabs we create a tab popup, and then layout the new tabs until
+         *    we can't fit them anymore. Laying them out is a matter of adding them into the visible list
+         *    and shifting them horizontally to the correct location.
+         */
+        protected synchronized void superCalculateTabRects(final int tabPlacement, final int tabCount) {
+            final Dimension size = tabPane.getSize();
+            final Insets insets = tabPane.getInsets();
+            final Insets localTabAreaInsets = getTabAreaInsets(tabPlacement);
+
+            // Calculate bounds within which a tab run must fit
+            final int returnAt;
+            final int x, y;
+            switch (tabPlacement) {
+                case SwingConstants.LEFT:
+                    maxTabWidth = calculateMaxTabHeight(tabPlacement);
+                    x = insets.left + localTabAreaInsets.left;
+                    y = insets.top + localTabAreaInsets.top;
+                    returnAt = size.height - (insets.bottom + localTabAreaInsets.bottom);
+                    break;
+                case SwingConstants.RIGHT:
+                    maxTabWidth = calculateMaxTabHeight(tabPlacement);
+                    x = size.width - insets.right - localTabAreaInsets.right - maxTabWidth - 1;
+                    y = insets.top + localTabAreaInsets.top;
+                    returnAt = size.height - (insets.bottom + localTabAreaInsets.bottom);
+                    break;
+                case SwingConstants.BOTTOM:
+                    maxTabHeight = calculateMaxTabHeight(tabPlacement);
+                    x = insets.left + localTabAreaInsets.left;
+                    y = size.height - insets.bottom - localTabAreaInsets.bottom - maxTabHeight;
+                    returnAt = size.width - (insets.right + localTabAreaInsets.right);
+                    break;
+                case SwingConstants.TOP:
+                default:
+                    maxTabHeight = calculateMaxTabHeight(tabPlacement);
+                    x = insets.left + localTabAreaInsets.left;
+                    y = insets.top + localTabAreaInsets.top;
+                    returnAt = size.width - (insets.right + localTabAreaInsets.right);
+                    break;
+            }
+
+            tabRunOverlay = getTabRunOverlay(tabPlacement);
+
+            runCount = 0;
+            selectedRun = 0;
+
+            if (tabCount == 0) return;
+
+            final FontMetrics metrics = getFontMetrics();
+            final boolean verticalTabRuns = (tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT);
+            final int selectedIndex = tabPane.getSelectedIndex();
+
+            // calculate all the widths
+            // if they all fit we are done, if not
+            // we have to do the dance of figuring out which ones to show.
+            visibleTabState.setNeedsScrollers(false);
+            for (int i = 0; i < tabCount; i++) {
+                final Rectangle rect = rects[i];
+
+                if (verticalTabRuns) {
+                    calculateVerticalTabRunRect(rect, metrics, tabPlacement, returnAt, i, x, y);
+
+                    // test if we need to scroll!
+                    if (rect.y + rect.height > returnAt) {
+                        visibleTabState.setNeedsScrollers(true);
+                    }
+                } else {
+                    calculateHorizontalTabRunRect(rect, metrics, tabPlacement, returnAt, i, x, y);
+
+                    // test if we need to scroll!
+                    if (rect.x + rect.width > returnAt) {
+                        visibleTabState.setNeedsScrollers(true);
+                    }
+                }
+            }
+
+            visibleTabState.relayoutForScrolling(rects, x, y, returnAt, selectedIndex, verticalTabRuns, tabCount, AquaUtils.isLeftToRight(tabPane));
+            // Pad the selected tab so that it appears raised in front
+
+            // if right to left and tab placement on the top or
+            // the bottom, flip x positions and adjust by widths
+            if (!AquaUtils.isLeftToRight(tabPane) && !verticalTabRuns) {
+                final int rightMargin = size.width - (insets.right + localTabAreaInsets.right);
+                for (int i = 0; i < tabCount; i++) {
+                    rects[i].x = rightMargin - rects[i].x - rects[i].width;
+                }
+            }
+        }
+
+        private void calculateHorizontalTabRunRect(final Rectangle rect, final FontMetrics metrics, final int tabPlacement, final int returnAt, final int i, final int x, final int y) {
+            // Tabs on TOP or BOTTOM....
+            if (i > 0) {
+                rect.x = rects[i - 1].x + rects[i - 1].width;
+            } else {
+                tabRuns[0] = 0;
+                runCount = 1;
+                maxTabWidth = 0;
+                rect.x = x;
+            }
+
+            rect.width = calculateTabWidth(tabPlacement, i, metrics);
+            maxTabWidth = Math.max(maxTabWidth, rect.width);
+
+            rect.y = y;
+            rect.height = maxTabHeight;
+        }
+
+        private void calculateVerticalTabRunRect(final Rectangle rect, final FontMetrics metrics, final int tabPlacement, final int returnAt, final int i, final int x, final int y) {
+            // Tabs on LEFT or RIGHT...
+            if (i > 0) {
+                rect.y = rects[i - 1].y + rects[i - 1].height;
+            } else {
+                tabRuns[0] = 0;
+                runCount = 1;
+                maxTabHeight = 0;
+                rect.y = y;
+            }
+
+            rect.height = calculateTabWidth(tabPlacement, i, metrics);
+            maxTabHeight = Math.max(maxTabHeight, rect.height);
+
+            rect.x = x;
+            rect.width = maxTabWidth;
+        }
+
+        protected void layoutTabComponents() {
+            final Container tabContainer = getTabContainer();
+            if (tabContainer == null) return;
+
+            final int placement = tabPane.getTabPlacement();
+            final Rectangle rect = new Rectangle();
+            final Point delta = new Point(-tabContainer.getX(), -tabContainer.getY());
+
+            for (int i = 0; i < tabPane.getTabCount(); i++) {
+                final Component c = getTabComponentAt(i);
+                if (c == null) continue;
+
+                getTabBounds(i, rect);
+                final Insets insets = getTabInsets(tabPane.getTabPlacement(), i);
+                final boolean isSeleceted = i == tabPane.getSelectedIndex();
+
+                if (placement == SwingConstants.TOP || placement == SwingConstants.BOTTOM) {
+                    rect.x += insets.left + delta.x + getTabLabelShiftX(placement, i, isSeleceted);
+                    rect.y += insets.top + delta.y + getTabLabelShiftY(placement, i, isSeleceted) + 1;
+                    rect.width -= insets.left + insets.right;
+                    rect.height -= insets.top + insets.bottom - 1;
+                } else {
+                    rect.x += insets.top + delta.x + getTabLabelShiftY(placement, i, isSeleceted) + (placement == SwingConstants.LEFT ? 2 : 1);
+                    rect.y += insets.left + delta.y + getTabLabelShiftX(placement, i, isSeleceted);
+                    rect.width -= insets.top + insets.bottom - 1;
+                    rect.height -= insets.left + insets.right;
+                }
+
+                c.setBounds(rect);
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTableHeaderBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaTableHeaderBorder.java
new file mode 100644
index 0000000..d8f1dbb
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTableHeaderBorder.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.plaf.UIResource;
+
+import apple.laf.JRSUIState;
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaTableHeaderBorder extends AbstractBorder {
+    protected static final int SORT_NONE = 0;
+    protected static final int SORT_ASCENDING = 1;
+    protected static final int SORT_DECENDING = -1;
+
+    protected final Insets editorBorderInsets = new Insets(1, 3, 1, 3);
+    protected final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIState.getInstance());
+
+    protected static AquaTableHeaderBorder getListHeaderBorder() {
+        // we don't want to share this, because the .setSelected() state
+        // would persist to all other JTable instances
+        return new AquaTableHeaderBorder();
+    }
+
+    protected AquaTableHeaderBorder() {
+        painter.state.set(AlignmentHorizontal.LEFT);
+        painter.state.set(AlignmentVertical.TOP);
+    }
+
+    /**
+     * Paints the border for the specified component with the specified
+     * position and size.
+     * @param c the component for which this border is being painted
+     * @param g the paint graphics
+     * @param x the x position of the painted border
+     * @param y the y position of the painted border
+     * @param width the width of the painted border
+     * @param height the height of the painted border
+     */
+    protected boolean doPaint = true;
+    public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+        if (!doPaint) return;
+        final JComponent jc = (JComponent)c;
+
+        // if the developer wants to set their own color, we should
+        // interpret this as "get out of the way", and don't draw aqua.
+        final Color componentBackground = jc.getBackground();
+        if (!(componentBackground instanceof UIResource)) {
+            doPaint = false;
+            jc.paint(g);
+            getAlternateBorder().paintBorder(jc, g, x, y, width, height);
+            doPaint = true;
+            return;
+        }
+
+        final State state = getState(jc);
+        painter.state.set(state);
+        painter.state.set(jc.hasFocus() ? Focused.YES : Focused.NO);
+        painter.state.set(height > 16 ? Widget.BUTTON_BEVEL : Widget.BUTTON_LIST_HEADER);
+        painter.state.set(selected ? BooleanValue.YES : BooleanValue.NO);
+
+        switch (sortOrder) {
+            case SORT_ASCENDING:
+                painter.state.set(Direction.UP);
+                break;
+            case SORT_DECENDING:
+                painter.state.set(Direction.DOWN);
+                break;
+            default:
+                painter.state.set(Direction.NONE);
+                break;
+        }
+
+        final int newX = x;
+        final int newY = y;
+        final int newWidth = width;
+        final int newHeight = height;
+
+        painter.paint(g, c, newX - 1, newY - 1, newWidth + 1, newHeight);
+
+        // Draw the header
+        g.clipRect(newX, y, newWidth, height);
+        g.translate(fHorizontalShift, -1);
+        doPaint = false;
+        jc.paint(g);
+        doPaint = true;
+    }
+
+    protected State getState(final JComponent jc) {
+        if (!jc.isEnabled()) return State.DISABLED;
+
+        final JRootPane rootPane = jc.getRootPane();
+        if (rootPane == null) return State.ACTIVE;
+
+        if (!AquaFocusHandler.isActive(rootPane)) return State.INACTIVE;
+
+        return State.ACTIVE;
+    }
+
+    static final RecyclableSingleton<Border> alternateBorder = new RecyclableSingleton<Border>() {
+        @Override
+        protected Border getInstance() {
+            return BorderFactory.createRaisedBevelBorder();
+        }
+    };
+    protected static Border getAlternateBorder() {
+        return alternateBorder.get();
+    }
+
+    /**
+     * Returns the insets of the border.
+     * @param c the component for which this border insets value applies
+     */
+    public Insets getBorderInsets(final Component c) {
+        // bad to create new one each time. For debugging only.
+        return editorBorderInsets;
+    }
+
+    public Insets getBorderInsets(final Component c, final Insets insets) {
+        insets.left = editorBorderInsets.left;
+        insets.top = editorBorderInsets.top;
+        insets.right = editorBorderInsets.right;
+        insets.bottom = editorBorderInsets.bottom;
+        return insets;
+    }
+
+    /**
+     * Returns whether or not the border is opaque.  If the border
+     * is opaque, it is responsible for filling in it's own
+     * background when painting.
+     */
+    public boolean isBorderOpaque() {
+        return false;
+    }
+
+    /**
+     * Sets whether or not this instance of Border draws selected or not.  Used by AquaFileChooserUI
+     */
+    private boolean selected = false;
+    protected void setSelected(final boolean inSelected) {
+        selected = inSelected;
+    }
+
+    /**
+     * Sets an amount to shift the position of the labels.  Used by AquaFileChooserUI
+     */
+    private int fHorizontalShift = 0;
+    protected void setHorizontalShift(final int inShift) {
+        fHorizontalShift = inShift;
+    }
+
+    private int sortOrder = SORT_NONE;
+    protected void setSortOrder(final int inSortOrder) {
+        if (inSortOrder < SORT_DECENDING || inSortOrder > SORT_ASCENDING) {
+            throw new IllegalArgumentException("Invalid sort order constant: " + inSortOrder);
+        }
+
+        sortOrder = inSortOrder;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTableHeaderUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTableHeaderUI.java
new file mode 100644
index 0000000..99414f3
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTableHeaderUI.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.util.Enumeration;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicTableHeaderUI;
+import javax.swing.table.*;
+import com.apple.laf.ClientPropertyApplicator;
+import com.apple.laf.ClientPropertyApplicator.Property;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+public class AquaTableHeaderUI extends BasicTableHeaderUI {
+    private int originalHeaderAlignment;
+    protected int sortColumn;
+    protected int sortOrder;
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTableHeaderUI();
+    }
+
+    public void installDefaults() {
+        super.installDefaults();
+
+        final TableCellRenderer renderer = header.getDefaultRenderer();
+        if (renderer instanceof UIResource && renderer instanceof DefaultTableCellRenderer) {
+            final DefaultTableCellRenderer defaultRenderer = (DefaultTableCellRenderer)renderer;
+            originalHeaderAlignment = defaultRenderer.getHorizontalAlignment();
+            defaultRenderer.setHorizontalAlignment(SwingConstants.LEADING);
+        }
+    }
+
+    public void uninstallDefaults() {
+        final TableCellRenderer renderer = header.getDefaultRenderer();
+        if (renderer instanceof UIResource && renderer instanceof DefaultTableCellRenderer) {
+            final DefaultTableCellRenderer defaultRenderer = (DefaultTableCellRenderer)renderer;
+            defaultRenderer.setHorizontalAlignment(originalHeaderAlignment);
+        }
+
+        super.uninstallDefaults();
+    }
+
+    final static RecyclableSingleton<ClientPropertyApplicator<JTableHeader, JTableHeader>> TABLE_HEADER_APPLICATORS = new RecyclableSingleton<ClientPropertyApplicator<JTableHeader, JTableHeader>>() {
+        @Override
+        protected ClientPropertyApplicator<JTableHeader, JTableHeader> getInstance() {
+            return new ClientPropertyApplicator<JTableHeader, JTableHeader>(
+                    new Property<JTableHeader>("JTableHeader.selectedColumn") {
+                        public void applyProperty(final JTableHeader target, final Object value) {
+                            tickle(target, value, target.getClientProperty("JTableHeader.sortDirection"));
+                        }
+                    },
+                    new Property<JTableHeader>("JTableHeader.sortDirection") {
+                        public void applyProperty(final JTableHeader target, final Object value) {
+                            tickle(target, target.getClientProperty("JTableHeader.selectedColumn"), value);
+                        }
+                    }
+            );
+        }
+    };
+    static ClientPropertyApplicator<JTableHeader, JTableHeader> getTableHeaderApplicators() {
+        return TABLE_HEADER_APPLICATORS.get();
+    }
+
+    static void tickle(final JTableHeader target, final Object selectedColumn, final Object direction) {
+        final TableColumn tableColumn = getTableColumn(target, selectedColumn);
+        if (tableColumn == null) return;
+
+        int sortDirection = 0;
+        if ("ascending".equalsIgnoreCase(direction+"")) {
+            sortDirection = 1;
+        } else if ("descending".equalsIgnoreCase(direction+"")) {
+            sortDirection = -1;
+        } else if ("decending".equalsIgnoreCase(direction+"")) {
+            sortDirection = -1; // stupid misspelling that GM'ed in 10.5.0
+        }
+
+        final TableHeaderUI headerUI = target.getUI();
+        if (headerUI == null || !(headerUI instanceof AquaTableHeaderUI)) return;
+
+        final AquaTableHeaderUI aquaHeaderUI = (AquaTableHeaderUI)headerUI;
+        aquaHeaderUI.sortColumn = tableColumn.getModelIndex();
+        aquaHeaderUI.sortOrder = sortDirection;
+        final AquaTableCellRenderer renderer = aquaHeaderUI.new AquaTableCellRenderer();
+        tableColumn.setHeaderRenderer(renderer);
+    }
+
+    class AquaTableCellRenderer extends DefaultTableCellRenderer implements UIResource {
+        public Component getTableCellRendererComponent(final JTable localTable, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
+            if (localTable != null) {
+                if (header != null) {
+                    setForeground(header.getForeground());
+                    setBackground(header.getBackground());
+                    setFont(UIManager.getFont("TableHeader.font"));
+                }
+            }
+
+            setText((value == null) ? "" : value.toString());
+
+            // Modify the table "border" to draw smaller, and with the titles in the right position
+            // and sort indicators, just like an NSSave/Open panel.
+            final AquaTableHeaderBorder cellBorder = AquaTableHeaderBorder.getListHeaderBorder();
+            final boolean thisColumnSelected = localTable.getColumnModel().getColumn(column).getModelIndex() == sortColumn;
+
+            cellBorder.setSelected(thisColumnSelected);
+            if (thisColumnSelected) {
+                cellBorder.setSortOrder(sortOrder);
+            } else {
+                cellBorder.setSortOrder(AquaTableHeaderBorder.SORT_NONE);
+            }
+            setBorder(cellBorder);
+            return this;
+        }
+    }
+
+    protected static TableColumn getTableColumn(final JTableHeader target, final Object value) {
+        if (value == null || !(value instanceof Integer)) return null;
+        final int columnIndex = ((Integer)value).intValue();
+
+        final TableColumnModel columnModel = target.getColumnModel();
+        if (columnIndex < 0 || columnIndex >= columnModel.getColumnCount()) return null;
+
+        return columnModel.getColumn(columnIndex);
+    }
+
+    protected static AquaTableHeaderBorder getAquaBorderFrom(final JTableHeader header, final TableColumn column) {
+        final TableCellRenderer renderer = column.getHeaderRenderer();
+        if (renderer == null) return null;
+
+        final Component c = renderer.getTableCellRendererComponent(header.getTable(), column.getHeaderValue(), false, false, -1, column.getModelIndex());
+        if (!(c instanceof JComponent)) return null;
+
+        final Border border = ((JComponent)c).getBorder();
+        if (!(border instanceof AquaTableHeaderBorder)) return null;
+
+        return (AquaTableHeaderBorder)border;
+    }
+
+    protected void installListeners() {
+        super.installListeners();
+        getTableHeaderApplicators().attachAndApplyClientProperties(header);
+    }
+
+    protected void uninstallListeners() {
+        getTableHeaderApplicators().removeFrom(header);
+        super.uninstallListeners();
+    }
+
+    private int getHeaderHeightAqua() {
+        int height = 0;
+        boolean accomodatedDefault = false;
+
+        final TableColumnModel columnModel = header.getColumnModel();
+        for (int column = 0; column < columnModel.getColumnCount(); column++) {
+            final TableColumn aColumn = columnModel.getColumn(column);
+            // Configuring the header renderer to calculate its preferred size is expensive.
+            // Optimise this by assuming the default renderer always has the same height.
+            if (aColumn.getHeaderRenderer() != null || !accomodatedDefault) {
+                final Component comp = getHeaderRendererAqua(column);
+                final int rendererHeight = comp.getPreferredSize().height;
+                height = Math.max(height, rendererHeight);
+                // If the header value is empty (== "") in the
+                // first column (and this column is set up
+                // to use the default renderer) we will
+                // return zero from this routine and the header
+                // will disappear altogether. Avoiding the calculation
+                // of the preferred size is such a performance win for
+                // most applications that we will continue to
+                // use this cheaper calculation, handling these
+                // issues as `edge cases'.
+
+                // Mac OS X Change - since we have a border on our renderers
+                // it is possible the height of an empty header could be > 0,
+                // so we chose the relatively safe number of 4 to handle this case.
+                // Now if we get a size of 4 or less we assume it is empty and measure
+                // a different header.
+                if (rendererHeight > 4) {
+                    accomodatedDefault = true;
+                }
+            }
+        }
+        return height;
+    }
+
+    private Component getHeaderRendererAqua(final int columnIndex) {
+        final TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
+        TableCellRenderer renderer = aColumn.getHeaderRenderer();
+        if (renderer == null) {
+            renderer = header.getDefaultRenderer();
+        }
+        return renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, columnIndex);
+    }
+
+    private Dimension createHeaderSizeAqua(long width) {
+        // None of the callers include the intercell spacing, do it here.
+        if (width > Integer.MAX_VALUE) {
+            width = Integer.MAX_VALUE;
+        }
+        return new Dimension((int)width, getHeaderHeightAqua());
+    }
+
+    /**
+     * Return the minimum size of the header. The minimum width is the sum of the minimum widths of each column (plus
+     * inter-cell spacing).
+     */
+    public Dimension getMinimumSize(final JComponent c) {
+        long width = 0;
+        final Enumeration<TableColumn> enumeration = header.getColumnModel().getColumns();
+        while (enumeration.hasMoreElements()) {
+            final TableColumn aColumn = enumeration.nextElement();
+            width = width + aColumn.getMinWidth();
+        }
+        return createHeaderSizeAqua(width);
+    }
+
+    /**
+     * Return the preferred size of the header. The preferred height is the maximum of the preferred heights of all of
+     * the components provided by the header renderers. The preferred width is the sum of the preferred widths of each
+     * column (plus inter-cell spacing).
+     */
+    public Dimension getPreferredSize(final JComponent c) {
+        long width = 0;
+        final Enumeration<TableColumn> enumeration = header.getColumnModel().getColumns();
+        while (enumeration.hasMoreElements()) {
+            final TableColumn aColumn = enumeration.nextElement();
+            width = width + aColumn.getPreferredWidth();
+        }
+        return createHeaderSizeAqua(width);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTableUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTableUI.java
new file mode 100644
index 0000000..6dd909d
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTableUI.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.event.*;
+import java.beans.PropertyChangeEvent;
+
+import javax.swing.*;
+import javax.swing.event.MouseInputListener;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicTableUI;
+
+/**
+ * A Mac L&F implementation of JTable
+ *
+ * All this does is look for a ThemeBorder and invalidate it when the focus changes
+ */
+public class AquaTableUI extends BasicTableUI {
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTableUI();
+    }
+
+    /**
+     * Creates the focus listener to repaint the focus ring
+     */
+    protected FocusListener createFocusListener() {
+        return new AquaTableUI.FocusHandler();
+    }
+
+    /**
+     * Creates the mouse listener for the JTable.
+     */
+    protected MouseInputListener createMouseInputListener() {
+        return new AquaTableUI.MouseInputHandler();
+    }
+
+    /**
+     * This inner class is marked &quot;public&quot; due to a compiler bug.
+     * This class should be treated as a &quot;protected&quot; inner class.
+     * Instantiate it only within subclasses of BasicTableUI.
+     */
+    public class FocusHandler extends BasicTableUI.FocusHandler {
+        public void focusGained(final FocusEvent e) {
+            super.focusGained(e);
+            AquaBorder.repaintBorder(getComponent());
+        }
+
+        public void focusLost(final FocusEvent e) {
+            super.focusLost(e);
+            AquaBorder.repaintBorder(getComponent());
+        }
+    }
+
+    protected AquaFocusHandler focusHandler = new AquaFocusHandler() {
+        public void propertyChange(final PropertyChangeEvent ev) {
+            super.propertyChange(ev);
+            if (!FRAME_ACTIVE_PROPERTY.equals(ev.getPropertyName())) return;
+            AquaFocusHandler.swapSelectionColors("Table", getComponent(), ev.getNewValue());
+        }
+    };
+    protected void installListeners() {
+        super.installListeners();
+        table.addFocusListener(focusHandler);
+        table.addPropertyChangeListener(focusHandler);
+    }
+
+    protected void uninstallListeners() {
+        table.removePropertyChangeListener(focusHandler);
+        table.removeFocusListener(focusHandler);
+        super.uninstallListeners();
+    }
+
+    // TODO: Using default handler for now, need to handle cmd-key
+
+    // Replace the mouse event with one that returns the cmd-key state when asked
+    // for the control-key state, which super assumes is what everyone does to discontiguously extend selections
+    public class MouseInputHandler extends BasicTableUI.MouseInputHandler {
+        /*public void mousePressed(final MouseEvent e) {
+            super.mousePressed(new SelectionMouseEvent(e));
+        }
+        public void mouseDragged(final MouseEvent e) {
+            super.mouseDragged(new SelectionMouseEvent(e));
+        }*/
+    }
+
+    JTable getComponent() {
+        return table;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTextAreaUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTextAreaUI.java
new file mode 100644
index 0000000..eea400f
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTextAreaUI.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicTextAreaUI;
+import javax.swing.text.*;
+
+public class AquaTextAreaUI extends BasicTextAreaUI {
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTextAreaUI();
+    }
+
+    public AquaTextAreaUI() {
+        super();
+    }
+
+    AquaFocusHandler handler;
+    protected void installListeners() {
+        super.installListeners();
+
+        final JTextComponent c = getComponent();
+        handler = new AquaFocusHandler();
+        c.addFocusListener(handler);
+        c.addPropertyChangeListener(handler);
+
+        AquaUtilControlSize.addSizePropertyListener(c);
+    }
+
+    protected void uninstallListeners() {
+        final JTextComponent c = getComponent();
+
+        AquaUtilControlSize.removeSizePropertyListener(c);
+
+        c.removeFocusListener(handler);
+        c.removePropertyChangeListener(handler);
+        handler = null;
+
+        super.uninstallListeners();
+    }
+
+    boolean oldDragState = false;
+    protected void installDefaults() {
+        if (!GraphicsEnvironment.isHeadless()) {
+            oldDragState = getComponent().getDragEnabled();
+            getComponent().setDragEnabled(true);
+        }
+        super.installDefaults();
+    }
+
+    protected void uninstallDefaults() {
+        if (!GraphicsEnvironment.isHeadless()) {
+            getComponent().setDragEnabled(oldDragState);
+        }
+        super.uninstallDefaults();
+    }
+
+    // Install a default keypress action which handles Cmd and Option keys properly
+    protected void installKeyboardActions() {
+        super.installKeyboardActions();
+        AquaKeyBindings bindings = AquaKeyBindings.instance();
+        bindings.setDefaultAction(getKeymapName());
+        final JTextComponent c = getComponent();
+        bindings.installAquaUpDownActions(c);
+    }
+
+    protected Caret createCaret() {
+        final JTextComponent c = getComponent();
+        final Window owningWindow = SwingUtilities.getWindowAncestor(c);
+        final AquaCaret returnValue = new AquaCaret(owningWindow, c);
+        return returnValue;
+    }
+
+    protected Highlighter createHighlighter() {
+        return new AquaHighlighter();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldBorder.java b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldBorder.java
new file mode 100644
index 0000000..c0ee26a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldBorder.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.plaf.*;
+import javax.swing.text.JTextComponent;
+
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.*;
+
+public class AquaTextFieldBorder extends AquaBorder {
+    protected static final RecyclableSingleton<AquaTextFieldBorder> instance = new RecyclableSingletonFromDefaultConstructor<AquaTextFieldBorder>(AquaTextFieldBorder.class);
+    public static AquaTextFieldBorder getTextFieldBorder() {
+        return instance.get();
+    }
+
+    public AquaTextFieldBorder() {
+        this(new SizeDescriptor(new SizeVariant().alterMargins(6, 7, 6, 7).alterInsets(3, 3, 3, 3)));
+        painter.state.set(Widget.FRAME_TEXT_FIELD);
+        painter.state.set(FrameOnly.YES);
+        painter.state.set(Size.LARGE);
+    }
+
+    public AquaTextFieldBorder(final SizeDescriptor sizeDescriptor) {
+        super(sizeDescriptor);
+    }
+
+    public AquaTextFieldBorder(final AquaTextFieldBorder other) {
+        super(other);
+    }
+
+    protected void setSize(final Size size) {
+        super.setSize(size);
+        painter.state.set(Size.LARGE);
+    }
+
+    public void paintBorder(final Component c, final Graphics g, int x, int y, int width, int height) {
+//        g.setColor(Color.MAGENTA);
+//        g.drawRect(x, y, width - 1, height - 1);
+
+        if (!(c instanceof JTextComponent)) {
+            painter.state.set(State.ACTIVE);
+            painter.state.set(Focused.NO);
+            painter.paint(g, c, x, y, width, height);
+            return;
+        }
+
+        final JTextComponent jc = (JTextComponent)c;
+        final State state = getStateFor(jc);
+        painter.state.set(state);
+        painter.state.set(State.ACTIVE == state && jc.hasFocus() ? Focused.YES : Focused.NO);
+
+        if (jc.isOpaque()) {
+            painter.paint(g, c, x, y, width, height);
+            return;
+        }
+
+        final int shrinkage = getShrinkageFor(jc, height);
+        final Insets subInsets = getSubInsets(shrinkage);
+        x += subInsets.left;
+        y += subInsets.top;
+        width -= (subInsets.left + subInsets.right);
+        height -= (subInsets.top + subInsets.bottom);
+
+        if (shrinkage > 0) {
+            final Rectangle clipBounds = g.getClipBounds();
+            clipBounds.x += shrinkage;
+            clipBounds.width -= shrinkage * 2;
+            g.setClip(clipBounds);
+        }
+
+        painter.paint(g, c, x, y, width, height);
+//        g.setColor(Color.ORANGE);
+//        g.drawRect(x, y, width - 1, height - 1);
+    }
+
+    static int getShrinkageFor(final JTextComponent jc, final int height) {
+        if (jc == null) return 0;
+        final TextUI ui = jc.getUI();
+        if (ui == null) return 0;
+        final Dimension size = ui.getPreferredSize(jc);
+        if (size == null) return 0;
+        final int shrinkage = size.height - height;
+        return (shrinkage < 0) ? 0 : (shrinkage > 3) ? 3 : shrinkage;
+    }
+
+    // this determines the rect that we should draw inset to our existing bounds
+    protected Insets getSubInsets(final int shrinkage) {
+        final Insets insets = sizeVariant.insets;
+
+        if (shrinkage > 0) {
+            return new InsetsUIResource(insets.top - shrinkage, insets.left, insets.bottom - shrinkage, insets.right);
+        }
+
+        return insets;
+    }
+
+    public Insets getBorderInsets(final Component c) {
+        if (!(c instanceof JTextComponent) || c.isOpaque()) return new InsetsUIResource(3, 7, 3, 7);
+        return new InsetsUIResource(6, 7, 6, 7);
+    }
+
+    protected static State getStateFor(final JTextComponent jc) {
+        if (!AquaFocusHandler.isActive(jc)) {
+            return State.INACTIVE;
+        }
+
+        if (!jc.isEnabled()) {
+            return State.DISABLED;
+        }
+
+        if (!jc.isEditable()) {
+            return State.DISABLED;
+        }
+
+        return State.ACTIVE;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldFormattedUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldFormattedUI.java
new file mode 100644
index 0000000..d532c6a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldFormattedUI.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.event.*;
+
+import javax.swing.JComponent;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.text.JTextComponent;
+
+/**
+ * This class exists only as a hack to work around a Sun bug which parks the
+ * insertion caret at the begining of a text field when it gets clicked on.
+ */
+public class AquaTextFieldFormattedUI extends AquaTextFieldUI implements MouseListener {
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTextFieldFormattedUI();
+    }
+
+    @Override
+    protected String getPropertyPrefix() {
+        return "FormattedTextField";
+    }
+
+    protected void installListeners() {
+        super.installListeners();
+        getComponent().addMouseListener(this);
+    }
+
+    protected void uninstallListeners() {
+        getComponent().removeMouseListener(this);
+        super.uninstallListeners();
+    }
+
+    public void mouseClicked(final MouseEvent e) {
+        if (e.getClickCount() != 1) return;
+
+        final JTextComponent c = getComponent();
+        // apparently, focus has already been granted by the time this mouse listener fires
+    //    if (c.hasFocus()) return;
+
+        c.setCaretPosition(viewToModel(c, e.getPoint()));
+    }
+
+    public void mouseEntered(final MouseEvent e) { }
+    public void mouseExited(final MouseEvent e) { }
+    public void mousePressed(final MouseEvent e) { }
+    public void mouseReleased(final MouseEvent e) { }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldSearch.java b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldSearch.java
new file mode 100644
index 0000000..68d6255
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldSearch.java
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.TextUI;
+import javax.swing.text.JTextComponent;
+
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaIcon.DynamicallySizingJRSUIIcon;
+import com.apple.laf.AquaUtilControlSize.*;
+import com.apple.laf.AquaUtils.*;
+
+public class AquaTextFieldSearch {
+    private static final String VARIANT_KEY = "JTextField.variant";
+    private static final String SEARCH_VARIANT_VALUE = "search";
+
+    private static final String FIND_POPUP_KEY = "JTextField.Search.FindPopup";
+    private static final String FIND_ACTION_KEY = "JTextField.Search.FindAction";
+    private static final String CANCEL_ACTION_KEY = "JTextField.Search.CancelAction";
+    private static final String PROMPT_KEY = "JTextField.Search.Prompt";
+
+    private static final SearchFieldPropertyListener SEARCH_FIELD_PROPERTY_LISTENER = new SearchFieldPropertyListener();
+    protected static void installSearchFieldListener(final JTextComponent c) {
+        c.addPropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
+    }
+
+    protected static void uninstallSearchFieldListener(final JTextComponent c) {
+        c.removePropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
+    }
+
+    static class SearchFieldPropertyListener implements PropertyChangeListener {
+        public void propertyChange(final PropertyChangeEvent evt) {
+            final Object source = evt.getSource();
+            if (!(source instanceof JTextComponent)) return;
+
+            final String propertyName = evt.getPropertyName();
+            if (!VARIANT_KEY.equals(propertyName) &&
+                !FIND_POPUP_KEY.equals(propertyName) &&
+                !FIND_ACTION_KEY.equals(propertyName) &&
+                !CANCEL_ACTION_KEY.equals(propertyName) &&
+                !PROMPT_KEY.equals(propertyName)) {
+                return;
+            }
+
+            final JTextComponent c = (JTextComponent)source;
+            if (wantsToBeASearchField(c)) {
+                uninstallSearchField(c);
+                installSearchField(c);
+            } else {
+                uninstallSearchField(c);
+            }
+        }
+    }
+
+    protected static boolean wantsToBeASearchField(final JTextComponent c) {
+        return SEARCH_VARIANT_VALUE.equals(c.getClientProperty(VARIANT_KEY));
+    }
+
+    protected static boolean hasPopupMenu(final JTextComponent c) {
+        return (c.getClientProperty(FIND_POPUP_KEY) instanceof JPopupMenu);
+    }
+
+    protected static final RecyclableSingleton<SearchFieldBorder> instance = new RecyclableSingletonFromDefaultConstructor<SearchFieldBorder>(SearchFieldBorder.class);
+    public static SearchFieldBorder getSearchTextFieldBorder() {
+        return instance.get();
+    }
+
+    protected static void installSearchField(final JTextComponent c) {
+        final SearchFieldBorder border = getSearchTextFieldBorder();
+        c.setBorder(border);
+        c.setLayout(border.getCustomLayout());
+        c.add(getFindButton(c), BorderLayout.WEST);
+        c.add(getCancelButton(c), BorderLayout.EAST);
+        c.add(getPromptLabel(c), BorderLayout.CENTER);
+
+        final TextUI ui = c.getUI();
+        if (ui instanceof AquaTextFieldUI) {
+            ((AquaTextFieldUI)ui).setPaintingDelegate(border);
+        }
+    }
+
+    protected static void uninstallSearchField(final JTextComponent c) {
+        c.setBorder(UIManager.getBorder("TextField.border"));
+        c.removeAll();
+
+        final TextUI ui = c.getUI();
+        if (ui instanceof AquaTextFieldUI) {
+            ((AquaTextFieldUI)ui).setPaintingDelegate(null);
+        }
+    }
+
+    // The "magnifying glass" icon that sometimes has a downward pointing triangle next to it
+    // if a popup has been assigned to it. It does not appear to have a pressed state.
+    protected static DynamicallySizingJRSUIIcon getFindIcon(final JTextComponent text) {
+        return (text.getClientProperty(FIND_POPUP_KEY) == null) ?
+            new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, -5))) {
+                public void initJRSUIState() {
+                    painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
+                }
+            }
+        :
+            new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, 2))) {
+                public void initJRSUIState() {
+                    painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
+                }
+            }
+        ;
+    }
+
+    // The "X in a circle" that only shows up when there is text in the search field.
+    protected static DynamicallySizingJRSUIIcon getCancelIcon() {
+        return new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(22, 22).alterMargins(0, 0, 0, 4))) {
+            public void initJRSUIState() {
+                painter.state.set(Widget.BUTTON_SEARCH_FIELD_CANCEL);
+            }
+        };
+    }
+
+    protected static State getState(final JButton b) {
+        if (!AquaFocusHandler.isActive(b)) return State.INACTIVE;
+        if (b.getModel().isPressed()) return State.PRESSED;
+        return State.ACTIVE;
+    }
+
+    protected static JButton createButton(final JTextComponent c, final DynamicallySizingJRSUIIcon icon) {
+        final JButton b = new JButton()
+//        {
+//            public void paint(Graphics g) {
+//                super.paint(g);
+//
+//                g.setColor(Color.green);
+//                g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
+//            }
+//        }
+        ;
+
+        final Insets i = icon.sizeVariant.margins;
+        b.setBorder(BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right));
+
+        b.setIcon(icon);
+        b.setBorderPainted(false);
+        b.setFocusable(false);
+        b.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+        b.addChangeListener(new ChangeListener() {
+            public void stateChanged(final ChangeEvent e) {
+                icon.painter.state.set(getState(b));
+            }
+        });
+        b.addMouseListener(new MouseAdapter() {
+            public void mousePressed(final MouseEvent e) {
+                c.requestFocusInWindow();
+            }
+        });
+
+        return b;
+    }
+
+    protected static JButton getFindButton(final JTextComponent c) {
+        final DynamicallySizingJRSUIIcon findIcon = getFindIcon(c);
+        final JButton b = createButton(c, findIcon);
+        b.setName("find");
+
+        final Object findPopup = c.getClientProperty(FIND_POPUP_KEY);
+        if (findPopup instanceof JPopupMenu) {
+            // if we have a popup, indicate that in the icon
+            findIcon.painter.state.set(Variant.MENU_GLYPH);
+
+            b.addMouseListener(new MouseAdapter() {
+                public void mousePressed(final MouseEvent e) {
+                    ((JPopupMenu)findPopup).show(b, 8, b.getHeight() - 2);
+                    c.requestFocusInWindow();
+                    c.repaint();
+                }
+            });
+        }
+
+        final Object findAction = c.getClientProperty(FIND_ACTION_KEY);
+        if (findAction instanceof ActionListener) {
+            b.addActionListener((ActionListener)findAction);
+        }
+
+        return b;
+    }
+
+    private static Component getPromptLabel(final JTextComponent c) {
+        final JLabel label = new JLabel();
+        label.setForeground(UIManager.getColor("TextField.inactiveForeground"));
+
+        c.getDocument().addDocumentListener(new DocumentListener() {
+            public void changedUpdate(final DocumentEvent e) { updatePromptLabel(label, c); }
+            public void insertUpdate(final DocumentEvent e) { updatePromptLabel(label, c); }
+            public void removeUpdate(final DocumentEvent e) { updatePromptLabel(label, c); }
+        });
+        c.addFocusListener(new FocusAdapter() {
+            public void focusGained(final FocusEvent e) { updatePromptLabel(label, c); }
+            public void focusLost(final FocusEvent e) { updatePromptLabel(label, c); }
+        });
+        updatePromptLabel(label, c);
+
+        return label;
+    }
+
+    static void updatePromptLabel(final JLabel label, final JTextComponent text) {
+        if (SwingUtilities.isEventDispatchThread()) {
+            updatePromptLabelOnEDT(label, text);
+        } else {
+            SwingUtilities.invokeLater(new Runnable() {
+                public void run() { updatePromptLabelOnEDT(label, text); }
+            });
+        }
+    }
+
+    static void updatePromptLabelOnEDT(final JLabel label, final JTextComponent text) {
+        String promptText = " ";
+        if (!text.hasFocus() && "".equals(text.getText())) {
+            final Object prompt = text.getClientProperty(PROMPT_KEY);
+            if (prompt != null) promptText = prompt.toString();
+        }
+        label.setText(promptText);
+    }
+
+    protected static JButton getCancelButton(final JTextComponent c) {
+        final JButton b = createButton(c, getCancelIcon());
+        b.setName("cancel");
+
+        final Object cancelAction = c.getClientProperty(CANCEL_ACTION_KEY);
+        if (cancelAction instanceof ActionListener) {
+            b.addActionListener((ActionListener)cancelAction);
+        }
+
+        b.addActionListener(new AbstractAction("cancel") {
+            public void actionPerformed(final ActionEvent e) {
+                c.setText("");
+            }
+        });
+
+        c.getDocument().addDocumentListener(new DocumentListener() {
+            public void changedUpdate(final DocumentEvent e) { updateCancelIcon(b, c); }
+            public void insertUpdate(final DocumentEvent e) { updateCancelIcon(b, c); }
+            public void removeUpdate(final DocumentEvent e) { updateCancelIcon(b, c); }
+        });
+
+        updateCancelIcon(b, c);
+        return b;
+    }
+
+    // <rdar://problem/6444328> JTextField.variant=search: not thread-safe
+    static void updateCancelIcon(final JButton button, final JTextComponent text) {
+        if (SwingUtilities.isEventDispatchThread()) {
+            updateCancelIconOnEDT(button, text);
+        } else {
+            SwingUtilities.invokeLater(new Runnable() {
+                public void run() { updateCancelIconOnEDT(button, text); }
+            });
+        }
+    }
+
+    static void updateCancelIconOnEDT(final JButton button, final JTextComponent text) {
+        button.setVisible(!"".equals(text.getText()));
+    }
+
+    // subclass of normal text border, because we still want all the normal text field behaviors
+    static class SearchFieldBorder extends AquaTextFieldBorder implements JComponentPainter {
+        protected boolean reallyPaintBorder;
+
+        public SearchFieldBorder() {
+            super(new SizeDescriptor(new SizeVariant().alterMargins(6, 31, 6, 24).alterInsets(3, 3, 3, 3)));
+            painter.state.set(Widget.FRAME_TEXT_FIELD_ROUND);
+        }
+
+        public SearchFieldBorder(final SearchFieldBorder other) {
+            super(other);
+        }
+
+        public void paint(final JComponent c, final Graphics g, final int x, final int y, final int w, final int h) {
+            reallyPaintBorder = true;
+            paintBorder(c, g, x, y, w, h);
+            reallyPaintBorder = false;
+        }
+
+        // apparently without adjusting for odd height pixels, the search field "wobbles" relative to it's contents
+        public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+            if (!reallyPaintBorder) return;
+            super.paintBorder(c, g, x, y - (height % 2), width, height);
+        }
+
+        public Insets getBorderInsets(final Component c) {
+            if (doingLayout) return new Insets(0, 0, 0, 0);
+
+            if (!hasPopupMenu((JTextComponent)c)) {
+                return new Insets(sizeVariant.margins.top, sizeVariant.margins.left - 7, sizeVariant.margins.bottom, sizeVariant.margins.right);
+            }
+
+            return sizeVariant.margins;
+        }
+
+        protected boolean doingLayout;
+        protected LayoutManager getCustomLayout() {
+            // unfortunately, the default behavior of BorderLayout, which accommodates for margins
+            // is not what we want, so we "turn off margins" for layout for layout out our buttons
+            return new BorderLayout(0, 0) {
+                public void layoutContainer(final Container target) {
+                    doingLayout = true;
+                    super.layoutContainer(target);
+                    doingLayout = false;
+                }
+            };
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldUI.java
new file mode 100644
index 0000000..075f641
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTextFieldUI.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicTextFieldUI;
+import javax.swing.text.*;
+
+import com.apple.laf.AquaUtils.JComponentPainter;
+
+public class AquaTextFieldUI extends BasicTextFieldUI {
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTextFieldUI();
+    }
+
+    protected JComponentPainter delegate;
+    protected AquaFocusHandler handler;
+
+    protected void installListeners() {
+        super.installListeners();
+
+        handler = new AquaFocusHandler();
+        final JTextComponent c = getComponent();
+        c.addFocusListener(handler);
+        c.addPropertyChangeListener(handler);
+
+        LookAndFeel.installProperty(c, "opaque", UIManager.getBoolean(getPropertyPrefix() + "opaque"));
+        AquaUtilControlSize.addSizePropertyListener(c);
+        AquaTextFieldSearch.installSearchFieldListener(c);
+    }
+
+    protected void uninstallListeners() {
+        final JTextComponent c = getComponent();
+        AquaTextFieldSearch.uninstallSearchFieldListener(c);
+        AquaUtilControlSize.removeSizePropertyListener(c);
+        c.removeFocusListener(handler);
+        c.removePropertyChangeListener(handler);
+        handler = null;
+
+        super.uninstallListeners();
+    }
+
+    boolean oldDragState = false;
+    protected void installDefaults() {
+        if (!GraphicsEnvironment.isHeadless()) {
+            oldDragState = getComponent().getDragEnabled();
+            getComponent().setDragEnabled(true);
+        }
+
+        super.installDefaults();
+    }
+
+    protected void uninstallDefaults() {
+        super.uninstallDefaults();
+
+        if (!GraphicsEnvironment.isHeadless()) {
+            getComponent().setDragEnabled(oldDragState);
+        }
+    }
+
+    // Install a default keypress action which handles Cmd and Option keys properly
+    protected void installKeyboardActions() {
+        super.installKeyboardActions();
+        AquaKeyBindings.instance().setDefaultAction(getKeymapName());
+    }
+
+    protected Rectangle getVisibleEditorRect() {
+        final Rectangle rect = super.getVisibleEditorRect();
+        if (rect == null) return null;
+
+        if (!getComponent().isOpaque()) {
+            rect.y -= 3;
+            rect.height += 6;
+        }
+
+        return rect;
+    }
+
+    protected void paintSafely(final Graphics g) {
+        paintBackgroundSafely(g);
+        super.paintSafely(g);
+    }
+
+    protected void paintBackgroundSafely(final Graphics g) {
+        final JTextComponent c = getComponent();
+        final int width = c.getWidth();
+        final int height = c.getHeight();
+
+        // a delegate takes precedence
+        if (delegate != null) {
+            delegate.paint(c, g, 0, 0, width, height);
+            return;
+        }
+
+        final boolean isOpaque = c.isOpaque();
+        if (!(c.getBorder() instanceof AquaTextFieldBorder)) {
+            // developer must have set a custom border
+            if (!isOpaque && AquaUtils.hasOpaqueBeenExplicitlySet(c)) return;
+
+            // must fill whole region with background color if opaque
+            g.setColor(c.getBackground());
+            g.fillRect(0, 0, width, height);
+            return;
+        }
+
+        // using our own border
+        g.setColor(c.getBackground());
+        if (isOpaque) {
+            g.fillRect(0, 0, width, height);
+            return;
+        }
+
+        final Insets margin = c.getMargin();
+        Insets insets = c.getInsets();
+
+        if (insets == null) insets = new Insets(0, 0, 0, 0);
+        if (margin != null) {
+            insets.top -= margin.top;
+            insets.left -= margin.left;
+            insets.bottom -= margin.bottom;
+            insets.right -= margin.right;
+        }
+
+        // the common case
+        final int shrinkage = AquaTextFieldBorder.getShrinkageFor(c, height);
+        g.fillRect(insets.left - 2, insets.top - shrinkage - 1, width - insets.right - insets.left + 4, height - insets.bottom - insets.top + shrinkage * 2 + 2);
+    }
+
+    protected void paintBackground(final Graphics g) {
+        // we have already ensured that the background is painted to our liking
+        // by paintBackgroundSafely(), called from paintSafely().
+    }
+
+    protected Caret createCaret() {
+        final JTextComponent c = getComponent();
+        final Window owningWindow = SwingUtilities.getWindowAncestor(c);
+        return new AquaCaret(owningWindow, c);
+    }
+
+    protected Highlighter createHighlighter() {
+        return new AquaHighlighter();
+    }
+
+    protected void setPaintingDelegate(final JComponentPainter delegate) {
+        this.delegate = delegate;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTextPaneUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTextPaneUI.java
new file mode 100644
index 0000000..dbec2e5
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTextPaneUI.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicTextPaneUI;
+import javax.swing.text.*;
+
+//[3663467] moved it to sublcass from BasicEditorPaneUI to BasicTextPaneUI. (vm)
+public class AquaTextPaneUI extends BasicTextPaneUI {
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTextPaneUI();
+    }
+
+    public AquaTextPaneUI() {
+        super();
+    }
+
+    AquaFocusHandler handler;
+    protected void installListeners() {
+        super.installListeners();
+        final JComponent c = getComponent();
+        handler = new AquaFocusHandler();
+        c.addFocusListener(handler);
+        c.addPropertyChangeListener(handler);
+        AquaUtilControlSize.addSizePropertyListener(c);
+    }
+
+    protected void uninstallListeners() {
+        final JComponent c = getComponent();
+        AquaUtilControlSize.removeSizePropertyListener(c);
+        c.removeFocusListener(handler);
+        c.removePropertyChangeListener(handler);
+        handler = null;
+        super.uninstallListeners();
+    }
+
+    boolean oldDragState = false;
+    protected void installDefaults() {
+        final JTextComponent c = getComponent();
+        if (!GraphicsEnvironment.isHeadless()) {
+            oldDragState = c.getDragEnabled();
+            c.setDragEnabled(true);
+        }
+        super.installDefaults();
+    }
+
+    protected void uninstallDefaults() {
+        if (!GraphicsEnvironment.isHeadless()) {
+            getComponent().setDragEnabled(oldDragState);
+        }
+        super.uninstallDefaults();
+    }
+
+    // Install a default keypress action which handles Cmd and Option keys properly
+    protected void installKeyboardActions() {
+        super.installKeyboardActions();
+        AquaKeyBindings bindings = AquaKeyBindings.instance();
+        bindings.setDefaultAction(getKeymapName());
+
+        final JTextComponent c = getComponent();
+        bindings.installAquaUpDownActions(c);
+    }
+
+    protected Caret createCaret() {
+        final JTextComponent c = getComponent();
+        final Window owningWindow = SwingUtilities.getWindowAncestor(c);
+        return new AquaCaret(owningWindow, c);
+    }
+
+    protected Highlighter createHighlighter() {
+        return new AquaHighlighter();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTextPasswordFieldUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTextPasswordFieldUI.java
new file mode 100644
index 0000000..157f6f5e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTextPasswordFieldUI.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.*;
+import javax.swing.text.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaTextPasswordFieldUI extends AquaTextFieldUI {
+    static final RecyclableSingleton<CapsLockSymbolPainter> capsLockPainter = new RecyclableSingletonFromDefaultConstructor<CapsLockSymbolPainter>(CapsLockSymbolPainter.class);
+    static CapsLockSymbolPainter getCapsLockPainter() {
+        return capsLockPainter.get();
+    }
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTextPasswordFieldUI();
+    }
+
+    @Override
+    protected String getPropertyPrefix() {
+        return "PasswordField";
+    }
+
+    @Override
+    public View create(final Element elem) {
+        return new AquaPasswordView(elem);
+    }
+
+    @Override
+    protected void installListeners() {
+        super.installListeners();
+        getComponent().addKeyListener(getCapsLockPainter());
+    }
+
+    @Override
+    protected void uninstallListeners() {
+        getComponent().removeKeyListener(getCapsLockPainter());
+        super.uninstallListeners();
+    }
+
+    @Override
+    protected void paintBackgroundSafely(final Graphics g) {
+        super.paintBackgroundSafely(g);
+
+        final JTextComponent component = getComponent();
+        if (component == null) return;
+        if (!component.isFocusOwner()) return;
+
+        final boolean capsLockDown = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
+        if (!capsLockDown) return;
+
+        final Rectangle bounds = component.getBounds();
+        getCapsLockPainter().paintBorder(component, g, bounds.x, bounds.y, bounds.width, bounds.height);
+    }
+
+    protected class AquaPasswordView extends PasswordView {
+        public AquaPasswordView(final Element elem) {
+            super(elem);
+            setupDefaultEchoCharacter();
+        }
+
+        protected void setupDefaultEchoCharacter() {
+            // this allows us to change the echo character in CoreAquaLookAndFeel.java
+            final Character echoChar = (Character)UIManager.getDefaults().get(getPropertyPrefix() + ".echoChar");
+            if (echoChar != null) {
+                LookAndFeel.installProperty(getComponent(), "echoChar", echoChar);
+            }
+        }
+    }
+
+    static class CapsLockSymbolPainter extends KeyAdapter implements Border, UIResource {
+        protected Shape capsLockShape;
+        protected Shape getCapsLockShape() {
+            if (capsLockShape != null) return capsLockShape;
+
+            final RoundRectangle2D rect = new RoundRectangle2D.Double(0.5, 0.5, 16, 16, 8, 8);
+            final GeneralPath shape = new GeneralPath(rect);
+            shape.setWindingRule(Path2D.WIND_EVEN_ODD);
+
+            // arrow
+            shape.moveTo( 8.50,  2.00);
+            shape.lineTo( 4.00,  7.00);
+            shape.lineTo( 6.25,  7.00);
+            shape.lineTo( 6.25, 10.25);
+            shape.lineTo(10.75, 10.25);
+            shape.lineTo(10.75,  7.00);
+            shape.lineTo(13.00,  7.00);
+            shape.lineTo( 8.50,  2.00);
+
+            // base line
+            shape.moveTo(10.75, 12.00);
+            shape.lineTo( 6.25, 12.00);
+            shape.lineTo( 6.25, 14.25);
+            shape.lineTo(10.75, 14.25);
+            shape.lineTo(10.75, 12.00);
+
+            return capsLockShape = shape;
+        }
+
+        @Override
+        public Insets getBorderInsets(final Component c) {
+            return new Insets(0, 0, 0, 0);
+        }
+
+        @Override
+        public boolean isBorderOpaque() {
+            return false;
+        }
+
+        @Override
+        public void paintBorder(final Component c, Graphics g, final int x, final int y, final int width, final int height) {
+            g = g.create(width - 23, height / 2 - 8, 18, 18);
+
+            g.setColor(UIManager.getColor("PasswordField.capsLockIconColor"));
+            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            ((Graphics2D)g).fill(getCapsLockShape());
+            g.dispose();
+        }
+
+        @Override
+        public void keyPressed(final KeyEvent e) {
+            update(e);
+        }
+
+        @Override
+        public void keyReleased(final KeyEvent e) {
+            update(e);
+        }
+
+        void update(final KeyEvent e) {
+            if (KeyEvent.VK_CAPS_LOCK != e.getKeyCode()) return;
+            e.getComponent().repaint();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaToolBarSeparatorUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaToolBarSeparatorUI.java
new file mode 100644
index 0000000..9c1d180
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaToolBarSeparatorUI.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicToolBarSeparatorUI;
+
+import com.apple.laf.AquaUtils.*;
+
+public class AquaToolBarSeparatorUI extends BasicToolBarSeparatorUI {
+    protected static RecyclableSingleton<AquaToolBarSeparatorUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaToolBarSeparatorUI>(AquaToolBarSeparatorUI.class);
+
+    public static ComponentUI createUI(final JComponent c) {
+        return instance.get();
+    }
+
+    public AquaToolBarSeparatorUI() {
+        super();
+    }
+
+    BasicStroke dashedStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 1.0f, 2.0f }, 0.0f);
+
+    public void paint(final Graphics g, final JComponent c) {
+        g.setColor(c.getForeground());
+        ((Graphics2D)g).setStroke(dashedStroke);
+
+        final int width = c.getWidth();
+        final int height = c.getHeight();
+        if (((JToolBar.Separator)c).getOrientation() == SwingConstants.HORIZONTAL) {
+            g.drawLine(2, height / 2, width - 3, height / 2);
+        } else {
+            g.drawLine(width / 2, 2, width / 2, height - 3);
+        }
+    }
+
+    public Dimension getMinimumSize(final JComponent c) {
+        final JToolBar.Separator sep = (JToolBar.Separator)c;
+        if (sep.getOrientation() == SwingConstants.HORIZONTAL) {
+            return new Dimension(1, 11);
+        }
+        return new Dimension(11, 1);
+    }
+
+    public Dimension getPreferredSize(final JComponent c) {
+        final JToolBar.Separator sep = (JToolBar.Separator)c;
+        if (sep.getOrientation() == SwingConstants.HORIZONTAL) {
+            return new Dimension(1, 11);
+        }
+        return new Dimension(11, 1);
+    }
+
+    public Dimension getMaximumSize(final JComponent c) {
+        final JToolBar.Separator sep = (JToolBar.Separator)c;
+        if (sep.getOrientation() == SwingConstants.HORIZONTAL) {
+            return new Dimension(Integer.MAX_VALUE, 11);
+        }
+        return new Dimension(11, Integer.MAX_VALUE);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaToolBarUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaToolBarUI.java
new file mode 100644
index 0000000..660cff3
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaToolBarUI.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicToolBarUI;
+
+import com.apple.laf.AquaUtils.*;
+
+public class AquaToolBarUI extends BasicToolBarUI implements SwingConstants {
+    private static RecyclableSingleton<ToolBarBorder> toolBarBorder = new RecyclableSingletonFromDefaultConstructor<ToolBarBorder>(ToolBarBorder.class);
+    public static Border getToolBarBorder() {
+        return toolBarBorder.get();
+    }
+
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaToolBarUI();
+    }
+
+    protected void setBorderToNonRollover(final Component c) { }
+    protected void setBorderToNormal(final Component c) { }
+    protected void setBorderToRollover(final Component c) { }
+
+    protected RootPaneContainer createFloatingWindow(final JToolBar toolbar) {
+        final RootPaneContainer window = super.createFloatingWindow(toolbar);
+        window.getRootPane().putClientProperty("Window.style", "small");
+        return window;
+    }
+
+    /* ToolBarBorder and drag-off handle, based loosly on MetalBumps */
+    static class ToolBarBorder extends AbstractBorder implements UIResource, javax.swing.SwingConstants {
+        protected void fillHandle(final Graphics g, final int x1, final int y1, final int x2, final int y2, final boolean horizontal) {
+            g.setColor(UIManager.getColor("ToolBar.borderHandleColor"));
+            if (horizontal) {
+                final int h = y2 - y1 - 2;
+                g.fillRect(x1 + 2, y1 + 1, 1, h);
+                g.fillRect(x1 + 5, y1 + 1, 1, h);
+            } else {
+                final int w = x2 - x1 - 2;
+                g.fillRect(x1 + 1, y1 + 2, w, 1);
+                g.fillRect(x1 + 1, y1 + 5, w, 1);
+            }
+        }
+
+        public void paintBorder(final java.awt.Component c, final Graphics g, int x, int y, final int w, final int h) {
+            g.translate(x, y);
+
+            if (c.isOpaque()) {
+                final Color background = c.getBackground();
+                g.setColor(background);
+                g.fillRect(0, 0, w - 1, h - 1);
+            }
+
+            final Color oldColor = g.getColor();
+
+            final JToolBar jtb = (JToolBar)c;
+            final ComponentOrientation orient = jtb.getComponentOrientation();
+            final boolean horizontal = jtb.getOrientation() == SwingConstants.HORIZONTAL;
+
+            if (jtb.isFloatable()) {
+                if (horizontal) {
+                    if (orient.isLeftToRight()) {
+                        fillHandle(g, 2, 2, 10, h - 2, true);
+                    } else {
+                        fillHandle(g, w - 10, 2, w - 2, h - 2, true);
+                    }
+                } else {
+                    fillHandle(g, 2, 2, w - 2, 10, false);
+                }
+            }
+
+            g.setColor(oldColor);
+
+            g.translate(-x, -y);
+        }
+
+        public Insets getBorderInsets(final java.awt.Component c) {
+            final Insets borderInsets = new Insets(5, 5, 5, 5);
+            return getBorderInsets(c, borderInsets);
+        }
+
+        public Insets getBorderInsets(final java.awt.Component c, final Insets borderInsets) {
+            borderInsets.left = 4;
+            borderInsets.right = 4;
+            borderInsets.top = 2;
+            borderInsets.bottom = 2;
+
+            if (((JToolBar)c).isFloatable()) {
+                if (((JToolBar)c).getOrientation() == HORIZONTAL) {
+                    borderInsets.left = 12;
+                    // We don't have to adjust for right-to-left
+                } else { // vertical
+                    borderInsets.top = 12;
+                }
+            }
+
+            final Insets margin = ((JToolBar)c).getMargin();
+
+            if (margin != null) {
+                borderInsets.left += margin.left;
+                borderInsets.top += margin.top;
+                borderInsets.right += margin.right;
+                borderInsets.bottom += margin.bottom;
+            }
+
+            return borderInsets;
+        }
+
+        public boolean isBorderOpaque() {
+            return true;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaToolTipUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaToolTipUI.java
new file mode 100644
index 0000000..a3fbbec
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaToolTipUI.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+
+import javax.swing.JComponent;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicToolTipUI;
+
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaToolTipUI extends BasicToolTipUI {
+    static final RecyclableSingletonFromDefaultConstructor<AquaToolTipUI> sharedAquaInstance = new RecyclableSingletonFromDefaultConstructor<AquaToolTipUI>(AquaToolTipUI.class);
+
+    public static ComponentUI createUI(final JComponent c) {
+        return sharedAquaInstance.get();
+    }
+
+    public AquaToolTipUI() {
+        super();
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaTreeUI.java b/jdk/src/macosx/classes/com/apple/laf/AquaTreeUI.java
new file mode 100644
index 0000000..93bcf7a
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaTreeUI.java
@@ -0,0 +1,593 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+
+import javax.swing.*;
+import javax.swing.event.MouseInputAdapter;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.BasicTreeUI;
+import javax.swing.tree.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+import apple.laf.JRSUIState.AnimationFrameState;
+
+/**
+ * AquaTreeUI supports the client property "value-add" system of customization See MetalTreeUI
+ * This is heavily based on the 1.3.1 AquaTreeUI implementation.
+ */
+public class AquaTreeUI extends BasicTreeUI {
+
+    // Create PLAF
+    public static ComponentUI createUI(final JComponent c) {
+        return new AquaTreeUI();
+    }
+
+    // Begin Line Stuff from Metal
+
+    private static final String LINE_STYLE = "JTree.lineStyle";
+
+    private static final String LEG_LINE_STYLE_STRING = "Angled";
+    private static final String HORIZ_STYLE_STRING = "Horizontal";
+    private static final String NO_STYLE_STRING = "None";
+
+    private static final int LEG_LINE_STYLE = 2;
+    private static final int HORIZ_LINE_STYLE = 1;
+    private static final int NO_LINE_STYLE = 0;
+
+    private int lineStyle = HORIZ_LINE_STYLE;
+    private final PropertyChangeListener lineStyleListener = new LineListener();
+
+    // mouse tracking state
+    protected TreePath fTrackingPath;
+    protected boolean fIsPressed = false;
+    protected boolean fIsInBounds = false;
+    protected int fAnimationFrame = -1;
+    protected TreeArrowMouseInputHandler fMouseHandler;
+
+    protected final AquaPainter<AnimationFrameState> painter = AquaPainter.create(JRSUIStateFactory.getDisclosureTriangle());
+
+    public AquaTreeUI() {
+
+    }
+
+    public void installUI(final JComponent c) {
+        super.installUI(c);
+
+        final Object lineStyleFlag = c.getClientProperty(LINE_STYLE);
+        decodeLineStyle(lineStyleFlag);
+        c.addPropertyChangeListener(lineStyleListener);
+    }
+
+    public void uninstallUI(final JComponent c) {
+        c.removePropertyChangeListener(lineStyleListener);
+        super.uninstallUI(c);
+    }
+
+    /**
+     * Creates the focus listener to repaint the focus ring
+     */
+    protected FocusListener createFocusListener() {
+        return new AquaTreeUI.FocusHandler();
+    }
+
+    /**
+     * this function converts between the string passed into the client property and the internal representation
+     * (currently an int)
+     */
+    protected void decodeLineStyle(final Object lineStyleFlag) {
+        if (lineStyleFlag == null || NO_STYLE_STRING.equals(lineStyleFlag)) {
+            lineStyle = NO_LINE_STYLE; // default case
+            return;
+        }
+
+        if (LEG_LINE_STYLE_STRING.equals(lineStyleFlag)) {
+            lineStyle = LEG_LINE_STYLE;
+        } else if (HORIZ_STYLE_STRING.equals(lineStyleFlag)) {
+            lineStyle = HORIZ_LINE_STYLE;
+        }
+    }
+
+    public TreePath getClosestPathForLocation(final JTree treeLocal, final int x, final int y) {
+        if (treeLocal == null || treeState == null) return null;
+
+        Insets i = treeLocal.getInsets();
+        if (i == null) i = new Insets(0, 0, 0, 0);
+        return treeState.getPathClosestTo(x - i.left, y - i.top);
+    }
+
+    public void paint(final Graphics g, final JComponent c) {
+        super.paint(g, c);
+
+        // Paint the lines
+        if (lineStyle == HORIZ_LINE_STYLE && !largeModel) {
+            paintHorizontalSeparators(g, c);
+        }
+    }
+
+    protected void paintHorizontalSeparators(final Graphics g, final JComponent c) {
+        g.setColor(UIManager.getColor("Tree.line"));
+
+        final Rectangle clipBounds = g.getClipBounds();
+
+        final int beginRow = getRowForPath(tree, getClosestPathForLocation(tree, 0, clipBounds.y));
+        final int endRow = getRowForPath(tree, getClosestPathForLocation(tree, 0, clipBounds.y + clipBounds.height - 1));
+
+        if (beginRow <= -1 || endRow <= -1) { return; }
+
+        for (int i = beginRow; i <= endRow; ++i) {
+            final TreePath path = getPathForRow(tree, i);
+
+            if (path != null && path.getPathCount() == 2) {
+                final Rectangle rowBounds = getPathBounds(tree, getPathForRow(tree, i));
+
+                // Draw a line at the top
+                if (rowBounds != null) g.drawLine(clipBounds.x, rowBounds.y, clipBounds.x + clipBounds.width, rowBounds.y);
+            }
+        }
+    }
+
+    protected void paintVerticalPartOfLeg(final Graphics g, final Rectangle clipBounds, final Insets insets, final TreePath path) {
+        if (lineStyle == LEG_LINE_STYLE) {
+            super.paintVerticalPartOfLeg(g, clipBounds, insets, path);
+        }
+    }
+
+    protected void paintHorizontalPartOfLeg(final Graphics g, final Rectangle clipBounds, final Insets insets, final Rectangle bounds, final TreePath path, final int row, final boolean isExpanded, final boolean hasBeenExpanded, final boolean isLeaf) {
+        if (lineStyle == LEG_LINE_STYLE) {
+            super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
+        }
+    }
+
+    /** This class listens for changes in line style */
+    class LineListener implements PropertyChangeListener {
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String name = e.getPropertyName();
+            if (name.equals(LINE_STYLE)) {
+                decodeLineStyle(e.getNewValue());
+            }
+        }
+    }
+
+    /**
+     * Paints the expand (toggle) part of a row. The reciever should NOT modify <code>clipBounds</code>, or
+     * <code>insets</code>.
+     */
+    protected void paintExpandControl(final Graphics g, final Rectangle clipBounds, final Insets insets, final Rectangle bounds, final TreePath path, final int row, final boolean isExpanded, final boolean hasBeenExpanded, final boolean isLeaf) {
+        final Object value = path.getLastPathComponent();
+
+        // Draw icons if not a leaf and either hasn't been loaded,
+        // or the model child count is > 0.
+        if (isLeaf || (hasBeenExpanded && treeModel.getChildCount(value) <= 0)) return;
+
+        final boolean isLeftToRight = AquaUtils.isLeftToRight(tree); // Basic knows, but keeps it private
+
+        final State state = getState(path);
+
+        // if we are not animating, do the expected thing, and use the icon
+        // also, if there is a custom (non-LaF defined) icon - just use that instead
+        if (fAnimationFrame == -1 && state != State.PRESSED) {
+            super.paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
+            return;
+        }
+
+        // Both icons are the same size
+        final Icon icon = isExpanded ? getExpandedIcon() : getCollapsedIcon();
+        if (!(icon instanceof UIResource)) {
+            super.paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
+            return;
+        }
+
+        // if painting a right-to-left knob, we ensure that we are only painting when
+        // the clipbounds rect is set to the exact size of the knob, and positioned correctly
+        // (this code is not the same as metal)
+        int middleXOfKnob;
+        if (isLeftToRight) {
+            middleXOfKnob = bounds.x - (getRightChildIndent() - 1);
+        } else {
+            middleXOfKnob = clipBounds.x + clipBounds.width / 2;
+        }
+
+        // Center vertically
+        final int middleYOfKnob = bounds.y + (bounds.height / 2);
+
+        final int x = middleXOfKnob - icon.getIconWidth() / 2;
+        final int y = middleYOfKnob - icon.getIconHeight() / 2;
+        final int height = icon.getIconHeight(); // use the icon height so we don't get drift  we modify the bounds (by changing row height)
+        final int width = 20; // this is a hardcoded value from our default icon (since we are only at this point for animation)
+
+        setupPainter(state, isExpanded, isLeftToRight);
+        painter.paint(g, tree, x, y, width, height);
+    }
+
+    @Override
+    public Icon getCollapsedIcon() {
+        final Icon icon = super.getCollapsedIcon();
+        if (AquaUtils.isLeftToRight(tree)) return icon;
+        if (!(icon instanceof UIResource)) return icon;
+        return UIManager.getIcon("Tree.rightToLeftCollapsedIcon");
+    }
+
+    protected void setupPainter(State state, final boolean isExpanded, final boolean leftToRight) {
+        if (!fIsInBounds && state == State.PRESSED) state = State.ACTIVE;
+
+        painter.state.set(state);
+        if (JRSUIUtils.Tree.useLegacyTreeKnobs()) {
+            if (fAnimationFrame == -1) {
+                painter.state.set(isExpanded ? Direction.DOWN : Direction.RIGHT);
+            } else {
+                painter.state.set(Direction.NONE);
+                painter.state.setAnimationFrame(fAnimationFrame - 1);
+            }
+        } else {
+            painter.state.set(getDirection(isExpanded, leftToRight));
+            painter.state.setAnimationFrame(fAnimationFrame);
+        }
+    }
+
+    protected Direction getDirection(final boolean isExpanded, final boolean isLeftToRight) {
+        if (isExpanded && (fAnimationFrame == -1)) return Direction.DOWN;
+        return isLeftToRight ? Direction.RIGHT : Direction.LEFT;
+    }
+
+    protected State getState(final TreePath path) {
+        if (!tree.isEnabled()) return State.DISABLED;
+        if (fIsPressed) {
+            if (fTrackingPath.equals(path)) return State.PRESSED;
+        }
+        return State.ACTIVE;
+    }
+
+    /**
+     * Misnamed - this is called on mousePressed Macs shouldn't react till mouseReleased
+     * We install a motion handler that gets removed after.
+     * See super.MouseInputHandler & super.startEditing for why
+     */
+    protected void handleExpandControlClick(final TreePath path, final int mouseX, final int mouseY) {
+        fMouseHandler = new TreeArrowMouseInputHandler(path);
+    }
+
+    /**
+     * Returning true signifies a mouse event on the node should toggle the selection of only the row under mouse.
+     */
+    protected boolean isToggleSelectionEvent(final MouseEvent event) {
+        return SwingUtilities.isLeftMouseButton(event) && event.isMetaDown();
+    }
+
+    class FocusHandler extends BasicTreeUI.FocusHandler {
+        public void focusGained(final FocusEvent e) {
+            super.focusGained(e);
+            AquaBorder.repaintBorder(tree);
+        }
+
+        public void focusLost(final FocusEvent e) {
+            super.focusLost(e);
+            AquaBorder.repaintBorder(tree);
+        }
+    }
+
+    protected PropertyChangeListener createPropertyChangeListener() {
+        return new MacPropertyChangeHandler();
+    }
+
+    public class MacPropertyChangeHandler extends PropertyChangeHandler {
+        public void propertyChange(final PropertyChangeEvent e) {
+            final String prop = e.getPropertyName();
+            if (prop.equals(AquaFocusHandler.FRAME_ACTIVE_PROPERTY)) {
+                AquaBorder.repaintBorder(tree);
+                AquaFocusHandler.swapSelectionColors("Tree", tree, e.getNewValue());
+            } else {
+                super.propertyChange(e);
+            }
+        }
+    }
+
+    /**
+     * TreeArrowMouseInputHandler handles passing all mouse events the way a Mac should - hilite/dehilite on enter/exit,
+     * only perform the action if released in arrow.
+     *
+     * Just like super.MouseInputHandler, this is removed once it's not needed, so they won't clash with each other
+     */
+    // The Adapters take care of defining all the empties
+    class TreeArrowMouseInputHandler extends MouseInputAdapter {
+        protected Rectangle fPathBounds = new Rectangle();
+
+        // Values needed for paintOneControl
+        protected boolean fIsLeaf, fIsExpanded, fHasBeenExpanded;
+        protected Rectangle fBounds, fVisibleRect;
+        int fTrackingRow;
+        Insets fInsets;
+        Color fBackground;
+
+        TreeArrowMouseInputHandler(final TreePath path) {
+            fTrackingPath = path;
+            fIsPressed = true;
+            fIsInBounds = true;
+            this.fPathBounds = getPathArrowBounds(path);
+            tree.addMouseListener(this);
+            tree.addMouseMotionListener(this);
+            fBackground = tree.getBackground();
+            if (!tree.isOpaque()) {
+                final Component p = tree.getParent();
+                if (p != null) fBackground = p.getBackground();
+            }
+
+            // Set up values needed to paint the triangle - see
+            // BasicTreeUI.paint
+            fVisibleRect = tree.getVisibleRect();
+            fInsets = tree.getInsets();
+
+            if (fInsets == null) fInsets = new Insets(0, 0, 0, 0);
+            fIsLeaf = treeModel.isLeaf(path.getLastPathComponent());
+            if (fIsLeaf) fIsExpanded = fHasBeenExpanded = false;
+            else {
+                fIsExpanded = treeState.getExpandedState(path);
+                fHasBeenExpanded = tree.hasBeenExpanded(path);
+            }
+            final Rectangle boundsBuffer = new Rectangle();
+            fBounds = treeState.getBounds(fTrackingPath, boundsBuffer);
+            fBounds.x += fInsets.left;
+            fBounds.y += fInsets.top;
+            fTrackingRow = getRowForPath(fTrackingPath);
+
+            paintOneControl();
+        }
+
+        public void mouseDragged(final MouseEvent e) {
+            fIsInBounds = fPathBounds.contains(e.getX(), e.getY());
+                paintOneControl();
+            }
+
+        @Override
+        public void mouseExited(MouseEvent e) {
+            fIsInBounds = fPathBounds.contains(e.getX(), e.getY());
+            paintOneControl();
+        }
+
+        public void mouseReleased(final MouseEvent e) {
+            if (tree == null) return;
+
+            if (fIsPressed) {
+                final boolean wasInBounds = fIsInBounds;
+
+                fIsPressed = false;
+                fIsInBounds = false;
+
+                if (wasInBounds) {
+                    fIsExpanded = !fIsExpanded;
+                    paintAnimation(fIsExpanded);
+                    if (e.isAltDown()) {
+                        if (fIsExpanded) {
+                            expandNode(fTrackingRow, true);
+                        } else {
+                            collapseNode(fTrackingRow, true);
+                        }
+                    } else {
+                        toggleExpandState(fTrackingPath);
+                    }
+                }
+            }
+            fTrackingPath = null;
+            removeFromSource();
+        }
+
+        protected void paintAnimation(final boolean expanding) {
+            if (expanding) {
+                paintAnimationFrame(1);
+                paintAnimationFrame(2);
+                paintAnimationFrame(3);
+            } else {
+                paintAnimationFrame(3);
+                paintAnimationFrame(2);
+                paintAnimationFrame(1);
+            }
+            fAnimationFrame = -1;
+        }
+
+        protected void paintAnimationFrame(final int frame) {
+            fAnimationFrame = frame;
+            paintOneControl();
+            try { Thread.sleep(20); } catch (final InterruptedException e) { }
+        }
+
+        // Utility to paint just one widget while it's being tracked
+        // Just doing "repaint" runs into problems if someone does "translate" on the graphics
+        // (ie, Sun's JTreeTable example, which is used by Moneydance - see Radar 2697837)
+        void paintOneControl() {
+            if (tree == null) return;
+            final Graphics g = tree.getGraphics();
+            if (g == null) {
+                // i.e. source is not displayable
+                return;
+            }
+
+            try {
+                g.setClip(fVisibleRect);
+                // If we ever wanted a callback for drawing the arrow between
+                // transition stages
+                // the code between here and paintExpandControl would be it
+                g.setColor(fBackground);
+                g.fillRect(fPathBounds.x, fPathBounds.y, fPathBounds.width, fPathBounds.height);
+
+                // if there is no tracking path, we don't need to paint anything
+                if (fTrackingPath == null) return;
+
+                // draw the vertical line to the parent
+                final TreePath parentPath = fTrackingPath.getParentPath();
+                if (parentPath != null) {
+                    paintVerticalPartOfLeg(g, fPathBounds, fInsets, parentPath);
+                    paintHorizontalPartOfLeg(g, fPathBounds, fInsets, fBounds, fTrackingPath, fTrackingRow, fIsExpanded, fHasBeenExpanded, fIsLeaf);
+                } else if (isRootVisible() && fTrackingRow == 0) {
+                    paintHorizontalPartOfLeg(g, fPathBounds, fInsets, fBounds, fTrackingPath, fTrackingRow, fIsExpanded, fHasBeenExpanded, fIsLeaf);
+                }
+                paintExpandControl(g, fPathBounds, fInsets, fBounds, fTrackingPath, fTrackingRow, fIsExpanded, fHasBeenExpanded, fIsLeaf);
+            } finally {
+                g.dispose();
+            }
+        }
+
+        protected void removeFromSource() {
+            tree.removeMouseListener(this);
+            tree.removeMouseMotionListener(this);
+            }
+        }
+
+    protected int getRowForPath(final TreePath path) {
+        return treeState.getRowForPath(path);
+    }
+
+    /**
+     * see isLocationInExpandControl for bounds calc
+     */
+    protected Rectangle getPathArrowBounds(final TreePath path) {
+        final Rectangle bounds = getPathBounds(tree, path); // Gives us the y values, but x is adjusted for the contents
+        final Insets i = tree.getInsets();
+
+        if (getExpandedIcon() != null) bounds.width = getExpandedIcon().getIconWidth();
+        else bounds.width = 8;
+
+        int boxLeftX = (i != null) ? i.left : 0;
+        if (AquaUtils.isLeftToRight(tree)) {
+            boxLeftX += (((path.getPathCount() + depthOffset - 2) * totalChildIndent) + getLeftChildIndent()) - bounds.width / 2;
+        } else {
+            boxLeftX += tree.getWidth() - 1 - ((path.getPathCount() - 2 + depthOffset) * totalChildIndent) - getLeftChildIndent() - bounds.width / 2;
+        }
+        bounds.x = boxLeftX;
+        return bounds;
+    }
+
+    protected void installKeyboardActions() {
+        super.installKeyboardActions();
+        tree.getActionMap().put("aquaExpandNode", new KeyboardExpandCollapseAction(true, false));
+        tree.getActionMap().put("aquaCollapseNode", new KeyboardExpandCollapseAction(false, false));
+        tree.getActionMap().put("aquaFullyExpandNode", new KeyboardExpandCollapseAction(true, true));
+        tree.getActionMap().put("aquaFullyCollapseNode", new KeyboardExpandCollapseAction(false, true));
+    }
+
+    class KeyboardExpandCollapseAction extends AbstractAction {
+        /**
+         * Determines direction to traverse, 1 means expand, -1 means collapse.
+         */
+        final boolean expand;
+        final boolean recursive;
+
+        /**
+         * True if the selection is reset, false means only the lead path changes.
+         */
+        public KeyboardExpandCollapseAction(final boolean expand, final boolean recursive) {
+            this.expand = expand;
+            this.recursive = recursive;
+        }
+
+        public void actionPerformed(final ActionEvent e) {
+            if (tree == null || 0 > getRowCount(tree)) return;
+
+            final TreePath[] selectionPaths = tree.getSelectionPaths();
+            if (selectionPaths == null) return;
+
+            for (int i = selectionPaths.length - 1; i >= 0; i--) {
+                final TreePath path = selectionPaths[i];
+
+                /*
+                 * Try and expand the node, otherwise go to next node.
+                 */
+                if (expand) {
+                    expandNode(tree.getRowForPath(path), recursive);
+                    continue;
+                }
+                // else collapse
+
+                // in the special case where there is only one row selected,
+                // we want to do what the Cocoa does, and select the parent
+                if (selectionPaths.length == 1 && tree.isCollapsed(path)) {
+                    final TreePath parentPath = path.getParentPath();
+                    if (parentPath != null && (!(parentPath.getParentPath() == null) || tree.isRootVisible())) {
+                        tree.scrollPathToVisible(parentPath);
+                        tree.setSelectionPath(parentPath);
+                    }
+                    continue;
+                }
+
+                collapseNode(tree.getRowForPath(path), recursive);
+            }
+        }
+
+        public boolean isEnabled() {
+            return (tree != null && tree.isEnabled());
+        }
+    }
+
+    void expandNode(final int row, final boolean recursive) {
+        final TreePath path = getPathForRow(tree, row);
+        if (path == null) return;
+
+        tree.expandPath(path);
+        if (!recursive) return;
+
+        expandAllNodes(path, row + 1);
+    }
+
+    void expandAllNodes(final TreePath parent, final int initialRow) {
+        for (int i = initialRow; true; i++) {
+            final TreePath path = getPathForRow(tree, i);
+            if (!parent.isDescendant(path)) return;
+
+            tree.expandPath(path);
+        }
+    }
+
+    void collapseNode(final int row, final boolean recursive) {
+        final TreePath path = getPathForRow(tree, row);
+        if (path == null) return;
+
+        if (recursive) {
+            collapseAllNodes(path, row + 1);
+        }
+
+        tree.collapsePath(path);
+    }
+
+    void collapseAllNodes(final TreePath parent, final int initialRow) {
+        int lastRow = -1;
+        for (int i = initialRow; lastRow == -1; i++) {
+            final TreePath path = getPathForRow(tree, i);
+            if (!parent.isDescendant(path)) {
+                lastRow = i - 1;
+            }
+        }
+
+        for (int i = lastRow; i >= initialRow; i--) {
+            final TreePath path = getPathForRow(tree, i);
+            tree.collapsePath(path);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaUtilControlSize.java b/jdk/src/macosx/classes/com/apple/laf/AquaUtilControlSize.java
new file mode 100644
index 0000000..61ab08b
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaUtilControlSize.java
@@ -0,0 +1,289 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.beans.*;
+import java.lang.reflect.Method;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.*;
+
+import apple.laf.*;
+import apple.laf.JRSUIConstants.*;
+
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
+
+public class AquaUtilControlSize {
+    protected final static String CLIENT_PROPERTY_KEY = "JComponent.sizeVariant";
+    protected final static String SYSTEM_PROPERTY_KEY = "swing.component.sizevariant";
+
+    interface Sizeable {
+        void applySizeFor(final JComponent c, final Size size);
+    }
+
+    protected static final RecyclableSingleton<PropertySizeListener> sizeListener = new RecyclableSingletonFromDefaultConstructor<PropertySizeListener>(PropertySizeListener.class);
+    protected static PropertySizeListener getSizeListener() {
+        return sizeListener.get();
+    }
+
+    protected static void addSizePropertyListener(final JComponent c) {
+        c.addPropertyChangeListener(CLIENT_PROPERTY_KEY, getSizeListener());
+        PropertySizeListener.applyComponentSize(c, c.getClientProperty(CLIENT_PROPERTY_KEY));
+    }
+
+    protected static void removeSizePropertyListener(final JComponent c) {
+        c.removePropertyChangeListener(CLIENT_PROPERTY_KEY, getSizeListener());
+    }
+
+    private static JRSUIConstants.Size getSizeFromString(final String name) {
+        if ("regular".equalsIgnoreCase(name)) return Size.REGULAR;
+        if ("small".equalsIgnoreCase(name)) return Size.SMALL;
+        if ("mini".equalsIgnoreCase(name)) return Size.MINI;
+        if ("large".equalsIgnoreCase(name)) return Size.LARGE;
+        return null;
+    }
+
+    private static Size getDefaultSize() {
+        final String sizeProperty = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction(SYSTEM_PROPERTY_KEY));
+        final JRSUIConstants.Size size = getSizeFromString(sizeProperty);
+        if (size != null) return size;
+        return JRSUIConstants.Size.REGULAR;
+    }
+
+    protected final static JRSUIConstants.Size defaultSize = getDefaultSize();
+    protected static JRSUIConstants.Size getUserSizeFrom(final JComponent c) {
+        final Object sizeProp = c.getClientProperty(CLIENT_PROPERTY_KEY);
+        if (sizeProp == null) return defaultSize;
+        final Size size = getSizeFromString(sizeProp.toString());
+        if (size == null) return Size.REGULAR;
+        return size;
+    }
+
+    protected static JRSUIConstants.Size applySizeForControl(final JComponent c, final AquaPainter<? extends JRSUIState> painter) {
+        final JRSUIConstants.Size sizeFromUser = getUserSizeFrom(c);
+        final JRSUIConstants.Size size = sizeFromUser == null ? JRSUIConstants.Size.REGULAR : sizeFromUser;
+        painter.state.set(size);
+        return size;
+    }
+
+    protected static Font getFontForSize(final Component c, final JRSUIConstants.Size size) {
+        final Font initialFont = c.getFont();
+
+        if (size == null || !(initialFont instanceof UIResource)) return initialFont;
+
+        if (size == JRSUIConstants.Size.MINI) return initialFont.deriveFont(AquaFonts.getMiniControlTextFont().getSize2D());
+        if (size == JRSUIConstants.Size.SMALL) return initialFont.deriveFont(AquaFonts.getSmallControlTextFont().getSize2D());
+
+        return initialFont.deriveFont(AquaFonts.getControlTextFont().getSize2D());
+    }
+
+    private static void applyBorderForSize(final JComponent c, final Size size) {
+        final Border border = c.getBorder();
+        if (!(border instanceof AquaBorder)) return;
+        final AquaBorder aquaBorder = (AquaBorder)border;
+
+        if (aquaBorder.sizeVariant.size == size) return;
+        final AquaBorder derivedBorder = aquaBorder.deriveBorderForSize(size);
+        if (derivedBorder == null) return;
+
+        c.setBorder(derivedBorder);
+    }
+
+    // call JComponent.getUI() if it exists, then call Sizeable.applySizeFor() if the UI is "Sizeable"
+    // next best thing to -respondsToSelector: :-P
+    private static void applyUISizing(final JComponent c, final Size size) {
+        try {
+            // see if this component has a "getUI" method
+            final Class<? extends JComponent> clazz = c.getClass();
+            final Method getUIMethod = clazz.getMethod("getUI", new Class[0]);
+
+            // see if that UI is one of ours that understands sizing
+            final Object ui = getUIMethod.invoke(c, new Object[0]);
+            if (!(ui instanceof Sizeable)) return;
+
+            // size it!
+            final Sizeable sizeable = (Sizeable)ui;
+            sizeable.applySizeFor(c, size);
+        } catch (final Throwable e) { return; }
+    }
+
+    protected static class PropertySizeListener implements PropertyChangeListener {
+        public void propertyChange(final PropertyChangeEvent evt) {
+            final String key = evt.getPropertyName();
+            if (!CLIENT_PROPERTY_KEY.equalsIgnoreCase(key)) return;
+
+            final Object source = evt.getSource();
+            if (!(source instanceof JComponent)) return;
+
+            final JComponent c = (JComponent)source;
+            applyComponentSize(c, evt.getNewValue());
+        }
+
+        protected static void applyComponentSize(final JComponent c, final Object value) {
+            Size size = getSizeFromString(value == null ? null : value.toString());
+            if (size == null) {
+                size = getUserSizeFrom(c);
+                if (size == Size.REGULAR) return;
+            }
+
+            applyBorderForSize(c, size);
+
+            applyUISizing(c, size);
+
+            final Font priorFont = c.getFont();
+            if (!(priorFont instanceof FontUIResource)) return;
+            c.setFont(getFontForSize(c, size));
+        }
+    }
+
+    public static class SizeDescriptor {
+        SizeVariant regular;
+        SizeVariant small;
+        SizeVariant mini;
+
+        public SizeDescriptor(final SizeVariant variant) {
+            regular = deriveRegular(variant);
+            small = deriveSmall(new SizeVariant(regular));
+            mini = deriveMini(new SizeVariant(small));
+        }
+
+        public SizeVariant deriveRegular(final SizeVariant v) {
+            v.size = Size.REGULAR;
+            return v;
+        }
+
+        public SizeVariant deriveSmall(final SizeVariant v) {
+            v.size = Size.SMALL;
+            return v;
+        }
+
+        public SizeVariant deriveMini(final SizeVariant v) {
+            v.size = Size.MINI;
+            return v;
+        }
+
+        public SizeVariant get(final JComponent c) {
+            if (c == null) return regular;
+            return get(getUserSizeFrom(c));
+        }
+
+        public SizeVariant get(final Size size) {
+            if (size == Size.REGULAR) return regular;
+            if (size == Size.SMALL) return small;
+            if (size == Size.MINI) return mini;
+            return regular;
+        }
+
+        public String toString() {
+            return "regular[" + regular + "] small[" + small + "] mini[" + mini + "]";
+        }
+    }
+
+    public static class SizeVariant {
+        Size size = Size.REGULAR;
+        Insets insets = new InsetsUIResource(0, 0, 0, 0);
+        Insets margins = new InsetsUIResource(0, 0, 0, 0);
+        Float fontSize;
+        int w = 0;
+        int h = 0;
+    //    Integer textBaseline;
+
+        public SizeVariant() { }
+
+        public SizeVariant(final int minWidth, final int minHeight) {
+            this.w = minWidth;
+            this.h = minHeight;
+        }
+
+        public SizeVariant(final SizeVariant desc){
+            this.size = desc.size;
+            this.insets = new InsetsUIResource(desc.insets.top, desc.insets.left, desc.insets.bottom, desc.insets.right);
+            this.margins = new InsetsUIResource(desc.margins.top, desc.margins.left, desc.margins.bottom, desc.margins.right);
+            this.fontSize = desc.fontSize;
+            this.w = desc.w;
+            this.h = desc.h;
+    //        this.textBaseline = desc.textBaseline;
+        }
+
+        public SizeVariant replaceInsets(final String insetName) {
+            this.insets = UIManager.getInsets(insetName);
+            return this;
+        }
+
+        public SizeVariant replaceInsets(final Insets i) {
+            this.insets = new InsetsUIResource(i.top, i.left, i.bottom, i.right);
+            return this;
+        }
+
+        public SizeVariant alterInsets(final int top, final int left, final int bottom, final int right) {
+            insets = generateInsets(insets, top, left, bottom, right);
+            return this;
+        }
+
+        public SizeVariant replaceMargins(final String marginName) {
+            this.margins = UIManager.getInsets(marginName);
+            return this;
+        }
+
+        public SizeVariant alterMargins(final int top, final int left, final int bottom, final int right) {
+            margins = generateInsets(margins, top, left, bottom, right);
+            return this;
+        }
+
+        public SizeVariant alterFontSize(final float newSize) {
+            final float oldSize = fontSize == null ? 0.0f : fontSize.floatValue();
+            fontSize = new Float(newSize + oldSize);
+            return this;
+        }
+
+        public SizeVariant alterMinSize(final int width, final int height) {
+            this.w += width; this.h += height;
+            return this;
+        }
+
+//        public SizeVariant alterTextBaseline(final int baseline) {
+//            final int oldSize = textBaseline == null ? 0 : textBaseline.intValue();
+//            textBaseline = new Integer(baseline + oldSize);
+//            return this;
+//        }
+
+        static Insets generateInsets(final Insets i, final int top, final int left, final int bottom, final int right) {
+            if (i == null) return new InsetsUIResource(top, left, bottom, right);
+            i.top += top;
+            i.left += left;
+            i.bottom += bottom;
+            i.right += right;
+            return i;
+        }
+
+        public String toString() {
+            return "insets:" + insets + ", margins:" + margins + ", fontSize:" + fontSize;// + ", textBaseline:" + textBaseline;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/AquaUtils.java b/jdk/src/macosx/classes/com/apple/laf/AquaUtils.java
new file mode 100644
index 0000000..58b0d1e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaUtils.java
@@ -0,0 +1,392 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.image.*;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+import java.util.*;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+
+import sun.awt.AppContext;
+
+import sun.lwawt.macosx.CImage;
+import sun.lwawt.macosx.CImage.Creator;
+import sun.swing.SwingUtilities2;
+
+import com.apple.laf.AquaImageFactory.SlicedImageControl;
+
+public class AquaUtils {
+    final static String ANIMATIONS_SYSTEM_PROPERTY = "swing.enableAnimations";
+
+    /*
+     * Convenience function for determining ComponentOrientation.  Helps us
+     * avoid having Munge directives throughout the code.
+     */
+    public static boolean isLeftToRight(final Component c) {
+        return c.getComponentOrientation().isLeftToRight();
+    }
+
+    public static void enforceComponentOrientation(Component c, ComponentOrientation orientation) {
+        c.setComponentOrientation(orientation);
+        if (c instanceof Container) {
+            for (Component child : ((Container)c).getComponents()) {
+                enforceComponentOrientation(child, orientation);
+            }
+        }
+    }
+
+    private static CImage.Creator getCImageCreatorInternal() {
+        return java.security.AccessController.doPrivileged(new PrivilegedAction<CImage.Creator>() {
+            public Creator run() {
+                try {
+                    final Method getCreatorMethod = CImage.class.getDeclaredMethod("getCreator", new Class[] {});
+                    getCreatorMethod.setAccessible(true);
+                    return (CImage.Creator)getCreatorMethod.invoke(null, new Object[] {});
+                } catch (final Exception e) {
+                    return null;
+                }
+            }
+        });
+    }
+
+    private static final RecyclableSingleton<CImage.Creator> cImageCreator = new RecyclableSingleton<CImage.Creator>() {
+        @Override
+        protected Creator getInstance() {
+            return getCImageCreatorInternal();
+        }
+    };
+    static CImage.Creator getCImageCreator() {
+        return cImageCreator.get();
+    }
+
+    protected static Image generateSelectedDarkImage(final Image image) {
+        final ImageProducer prod = new FilteredImageSource(image.getSource(), new IconImageFilter() {
+            int getGreyFor(final int gray) {
+                return gray * 75 / 100;
+            }
+        });
+        return Toolkit.getDefaultToolkit().createImage(prod);
+    }
+
+    protected static Image generateDisabledImage(final Image image) {
+        final ImageProducer prod = new FilteredImageSource(image.getSource(), new IconImageFilter() {
+            int getGreyFor(final int gray) {
+                return 255 - ((255 - gray) * 65 / 100);
+            }
+        });
+        return Toolkit.getDefaultToolkit().createImage(prod);
+    }
+
+    protected static Image generateLightenedImage(final Image image, final int percent) {
+        final GrayFilter filter = new GrayFilter(true, percent);
+        final ImageProducer prod = new FilteredImageSource(image.getSource(), filter);
+        return Toolkit.getDefaultToolkit().createImage(prod);
+    }
+
+    static abstract class IconImageFilter extends RGBImageFilter {
+        public IconImageFilter() {
+            super();
+            canFilterIndexColorModel = true;
+        }
+
+        public int filterRGB(final int x, final int y, final int rgb) {
+            final int red = (rgb >> 16) & 0xff;
+            final int green = (rgb >> 8) & 0xff;
+            final int blue = rgb & 0xff;
+            final int gray = getGreyFor((int)((0.30 * red + 0.59 * green + 0.11 * blue) / 3));
+
+            return (rgb & 0xff000000) | (grayTransform(red, gray) << 16) | (grayTransform(green, gray) << 8) | (grayTransform(blue, gray) << 0);
+        }
+
+        private static int grayTransform(final int color, final int gray) {
+            int result = color - gray;
+            if (result < 0) result = 0;
+            if (result > 255) result = 255;
+            return result;
+        }
+
+        abstract int getGreyFor(final int gray);
+    }
+
+    public abstract static class RecyclableObject<T> {
+        protected SoftReference<T> objectRef = null;
+
+        public T get() {
+            T referent = null;
+            if (objectRef != null && (referent = objectRef.get()) != null) return referent;
+            referent = create();
+            objectRef = new SoftReference<T>(referent);
+            return referent;
+        }
+
+        protected abstract T create();
+    }
+
+    public abstract static class RecyclableSingleton<T> {
+        public T get() {
+            final AppContext appContext = AppContext.getAppContext();
+            SoftReference<T> ref = (SoftReference<T>) appContext.get(this);
+            if (ref != null) {
+                final T object = ref.get();
+                if (object != null) return object;
+            }
+            final T object = getInstance();
+            ref = new SoftReference<T>(object);
+            appContext.put(this, ref);
+            return object;
+        }
+
+        public void reset() {
+            AppContext appContext = AppContext.getAppContext();
+            appContext.remove(this);
+        }
+
+        protected abstract T getInstance();
+    }
+
+    public static class RecyclableSingletonFromDefaultConstructor<T> extends RecyclableSingleton<T> {
+        protected final Class<T> clazz;
+
+        public RecyclableSingletonFromDefaultConstructor(final Class<T> clazz) {
+            this.clazz = clazz;
+        }
+
+        protected T getInstance() {
+            try {
+                return clazz.newInstance();
+            } catch (final InstantiationException e) {
+                e.printStackTrace();
+            } catch (final IllegalAccessException e) {
+                e.printStackTrace();
+            }
+            return null;
+        }
+    }
+
+    public abstract static class LazyKeyedSingleton<K, V> {
+        protected Map<K, V> refs;
+
+        public V get(final K key) {
+            if (refs == null) refs = new HashMap<K, V>();
+
+            final V cachedValue = refs.get(key);
+            if (cachedValue != null) return cachedValue;
+
+            final V value = getInstance(key);
+            refs.put(key, value);
+            return value;
+        }
+
+        protected abstract V getInstance(final K key);
+    }
+
+    static final RecyclableSingleton<Boolean> enableAnimations = new RecyclableSingleton<Boolean>() {
+        @Override
+        protected Boolean getInstance() {
+            final String sizeProperty = (String)java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.GetPropertyAction(ANIMATIONS_SYSTEM_PROPERTY));
+            return new Boolean(!"false".equals(sizeProperty)); // should be true by default
+        }
+    };
+    static boolean animationsEnabled() {
+        return enableAnimations.get();
+    }
+
+    static final int MENU_BLINK_DELAY = 50; // 50ms == 3/60 sec, according to the spec
+    protected static void blinkMenu(final Selectable selectable) {
+        if (!animationsEnabled()) return;
+        try {
+            selectable.paintSelected(false);
+            Thread.sleep(MENU_BLINK_DELAY);
+            selectable.paintSelected(true);
+            Thread.sleep(MENU_BLINK_DELAY);
+        } catch (final InterruptedException e) { }
+    }
+
+    interface Selectable {
+        void paintSelected(final boolean selected);
+    }
+
+    interface JComponentPainter {
+        public void paint(JComponent c, Graphics g, int x, int y, int w, int h);
+    }
+
+    interface Painter {
+        public void paint(final Graphics g, int x, int y, int w, int h);
+    }
+
+    public static void paintDropShadowText(final Graphics g, final JComponent c, final Font font, final FontMetrics metrics, final int x, final int y, final int offsetX, final int offsetY, final Color textColor, final Color shadowColor, final String text) {
+        g.setFont(font);
+        g.setColor(shadowColor);
+        SwingUtilities2.drawString(c, g, text, x + offsetX, y + offsetY + metrics.getAscent());
+        g.setColor(textColor);
+        SwingUtilities2.drawString(c, g, text, x, y + metrics.getAscent());
+    }
+
+    public static class ShadowBorder implements Border {
+        final Painter prePainter;
+        final Painter postPainter;
+
+        final int offsetX;
+        final int offsetY;
+        final float distance;
+        final int blur;
+        final Insets insets;
+        final ConvolveOp blurOp;
+
+        public ShadowBorder(final Painter prePainter, final Painter postPainter, final int offsetX, final int offsetY, final float distance, final float intensity, final int blur) {
+            this.prePainter = prePainter; this.postPainter = postPainter;
+            this.offsetX = offsetX; this.offsetY = offsetY; this.distance = distance; this.blur = blur;
+            final int halfBlur = blur / 2;
+            this.insets = new Insets(halfBlur - offsetY, halfBlur - offsetX, halfBlur + offsetY, halfBlur + offsetX);
+
+            final float blurry = intensity / (blur * blur);
+            final float[] blurKernel = new float[blur * blur];
+            for (int i = 0; i < blurKernel.length; i++) blurKernel[i] = blurry;
+            blurOp = new ConvolveOp(new Kernel(blur, blur, blurKernel));
+        }
+
+        public boolean isBorderOpaque() {
+            return false;
+        }
+
+        public Insets getBorderInsets(final Component c) {
+            return insets;
+        }
+
+        public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+            final BufferedImage img = new BufferedImage(width + blur * 2, height + blur * 2, BufferedImage.TYPE_INT_ARGB_PRE);
+            paintToImage(img, x, y, width, height);
+//            debugFrame("border", img);
+            g.drawImage(img, -blur, -blur, null);
+        }
+
+        protected void paintToImage(final BufferedImage img, final int x, final int y, final int width, final int height) {
+            // clear the prior image
+            Graphics2D imgG = (Graphics2D)img.getGraphics();
+            imgG.setComposite(AlphaComposite.Clear);
+            imgG.setColor(Color.black);
+            imgG.fillRect(0, 0, width + blur * 2, height + blur * 2);
+
+            final int adjX = (int)(x + blur + offsetX + (insets.left * distance));
+            final int adjY = (int)(y + blur + offsetY + (insets.top * distance));
+            final int adjW = (int)(width - (insets.left + insets.right) * distance);
+            final int adjH = (int)(height - (insets.top + insets.bottom) * distance);
+
+            // let the delegate paint whatever they want to be blurred
+            imgG.setComposite(AlphaComposite.DstAtop);
+            if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH);
+            imgG.dispose();
+
+            // blur the prior image back into the same pixels
+            imgG = (Graphics2D)img.getGraphics();
+            imgG.setComposite(AlphaComposite.DstAtop);
+            imgG.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+            imgG.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+            imgG.drawImage(img, blurOp, 0, 0);
+
+            if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH);
+            imgG.dispose();
+        }
+    }
+
+    public static class SlicedShadowBorder extends ShadowBorder {
+        final SlicedImageControl slices;
+
+        public SlicedShadowBorder(final Painter prePainter, final Painter postPainter, final int offsetX, final int offsetY, final float distance, final float intensity, final int blur, final int templateWidth, final int templateHeight, final int leftCut, final int topCut, final int rightCut, final int bottomCut) {
+            super(prePainter, postPainter, offsetX, offsetY, distance, intensity, blur);
+
+            final BufferedImage i = new BufferedImage(templateWidth, templateHeight, BufferedImage.TYPE_INT_ARGB_PRE);
+            super.paintBorder(null, i.getGraphics(), 0, 0, templateWidth, templateHeight);
+//            debugFrame("slices", i);
+            slices = new SlicedImageControl(i, leftCut, topCut, rightCut, bottomCut, false);
+        }
+
+        public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
+            slices.paint(g, x, y, width, height);
+        }
+    }
+
+    public interface NineSliceMetricsProvider {
+
+    }
+
+//    static void debugFrame(String name, Image image) {
+//        JFrame f = new JFrame(name);
+//        f.setContentPane(new JLabel(new ImageIcon(image)));
+//        f.pack();
+//        f.setVisible(true);
+//    }
+
+    // special casing naughty applications, like InstallAnywhere
+    // <rdar://problem/4851533> REGR: JButton: Myst IV: the buttons of 1.0.3 updater have redraw issue
+    static boolean shouldUseOpaqueButtons() {
+        final ClassLoader launcherClassLoader = sun.misc.Launcher.getLauncher().getClassLoader();
+        if (classExists(launcherClassLoader, "com.installshield.wizard.platform.macosx.MacOSXUtils")) return true;
+        return false;
+    }
+
+    static boolean classExists(final ClassLoader classLoader, final String clazzName) {
+        try {
+            return Class.forName(clazzName, false, classLoader) != null;
+        } catch (final Throwable e) { }
+        return false;
+    }
+
+    private static RecyclableSingleton<Method> getJComponentGetFlagMethod = new RecyclableSingleton<Method>() {
+        protected Method getInstance() {
+            return java.security.AccessController.doPrivileged(
+                new PrivilegedAction<Method>() {
+                    public Method run() {
+                        try {
+                            final Method method = JComponent.class.getDeclaredMethod("getFlag", new Class[] { int.class });
+                            method.setAccessible(true);
+                            return method;
+                        } catch (final Throwable e) {
+                            return null;
+                        }
+                    }
+                }
+            );
+        }
+    };
+
+    private static final Integer OPAQUE_SET_FLAG = new Integer(24); // private int JComponent.OPAQUE_SET
+    protected static boolean hasOpaqueBeenExplicitlySet(final JComponent c) {
+        final Method method = getJComponentGetFlagMethod.get();
+        if (method == null) return false;
+        try {
+            return Boolean.TRUE.equals(method.invoke(c, OPAQUE_SET_FLAG));
+        } catch (final Throwable e) {
+            return false;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ClientPropertyApplicator.java b/jdk/src/macosx/classes/com/apple/laf/ClientPropertyApplicator.java
new file mode 100644
index 0000000..bf40515
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ClientPropertyApplicator.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.beans.*;
+import java.util.*;
+
+import javax.swing.JComponent;
+
+public class ClientPropertyApplicator<T extends JComponent, N> implements PropertyChangeListener {
+    private final Map<String, Property<N>> properties = new HashMap<String, Property<N>>();
+
+    public ClientPropertyApplicator(final Property<N>... propertyList) {
+        for (final Property<N> p : propertyList) {
+            properties.put(p.name, p);
+        }
+    }
+
+    void applyProperty(final N target, final String propName, final Object value) {
+        final Property<N> property = properties.get(propName);
+        if (property != null) {
+            property.applyProperty(target, value);
+        }
+    }
+
+    public void attachAndApplyClientProperties(final T target) {
+        target.addPropertyChangeListener(this);
+        final N obj = convertJComponentToTarget(target);
+        if (obj == null) {
+            return;
+        }
+
+        final Set<String> propNames = properties.keySet();
+        for (final String propName : propNames) {
+            final Object value = target.getClientProperty(propName);
+            if (value == null) {
+                continue;
+            }
+            applyProperty(obj, propName, value);
+        }
+    }
+
+    public void removeFrom(final T target) {
+        target.removePropertyChangeListener(this);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void propertyChange(final PropertyChangeEvent evt) {
+        final N obj = convertJComponentToTarget((T)evt.getSource());
+        if (obj == null) return;
+        applyProperty(obj, evt.getPropertyName(), evt.getNewValue());
+    }
+
+    @SuppressWarnings("unchecked")
+    public N convertJComponentToTarget(final T component) {
+        return (N)component; // naive implementation
+    }
+
+    public abstract static class Property<X> {
+        final String name;
+
+        public Property(final String name) {
+            this.name = name;
+        }
+
+        public abstract void applyProperty(final X target, final Object value);
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ImageCache.java b/jdk/src/macosx/classes/com/apple/laf/ImageCache.java
new file mode 100644
index 0000000..7ed83ae
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ImageCache.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.lang.ref.*;
+import java.util.*;
+import java.util.concurrent.locks.*;
+
+import apple.laf.JRSUIState;
+import com.apple.laf.AquaUtils.RecyclableSingleton;
+
+/**
+ * ImageCache - A fixed pixel count sized cache of Images keyed by arbitrary set of arguments. All images are held with
+ * SoftReferences so they will be dropped by the GC if heap memory gets tight. When our size hits max pixel count least
+ * recently requested images are removed first.
+ */
+class ImageCache {
+    // Ordered Map keyed by args hash, ordered by most recent accessed entry.
+    private final LinkedHashMap<Integer, PixelCountSoftReference> map = new LinkedHashMap<Integer, PixelCountSoftReference>(16, 0.75f, true);
+
+    // Maximum number of pixels to cache, this is used if maxCount
+    private final int maxPixelCount;
+    // The current number of pixels stored in the cache
+    private int currentPixelCount = 0;
+
+    // Lock for concurrent access to map
+    private final ReadWriteLock lock = new ReentrantReadWriteLock();
+    // Reference queue for tracking lost softreferences to images in the cache
+    private final ReferenceQueue<Image> referenceQueue = new ReferenceQueue<Image>();
+
+    // Singleton Instance
+    private static final RecyclableSingleton<ImageCache> instance = new RecyclableSingleton<ImageCache>() {
+        @Override
+        protected ImageCache getInstance() {
+            return new ImageCache();
+        }
+    };
+    static ImageCache getInstance() {
+        return instance.get();
+    }
+
+    public ImageCache(final int maxPixelCount) {
+        this.maxPixelCount = maxPixelCount;
+    }
+
+    public ImageCache() {
+        this((8 * 1024 * 1024) / 4); // 8Mb of pixels
+    }
+
+    public void flush() {
+        lock.writeLock().lock();
+        try {
+            map.clear();
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    public Image getImage(final GraphicsConfiguration config, final int w, final int h, final JRSUIState state) {
+        lock.readLock().lock();
+        try {
+            final PixelCountSoftReference ref = map.get(hash(config, w, h, state));
+            // check reference has not been lost and the key truly matches, in case of false positive hash match
+            if (ref != null && ref.equals(config, w, h, state)) return ref.get();
+            return null;
+        } finally {
+            lock.readLock().unlock();
+        }
+    }
+
+    /**
+     * Sets the cached image for the specified constraints.
+     *
+     * @param image  The image to store in cache
+     * @param config The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
+     * @param w      The image width, used as part of cache key
+     * @param h      The image height, used as part of cache key
+     * @param args   Other arguments to use as part of the cache key
+     * @return true if the image could be cached or false if the image is too big
+     */
+    public boolean setImage(final Image image, final GraphicsConfiguration config, final int w, final int h, final JRSUIState state) {
+        final int hash = hash(config, w, h, state);
+
+        lock.writeLock().lock();
+        try {
+            PixelCountSoftReference ref = map.get(hash);
+            // check if currently in map
+            if (ref != null && ref.get() == image) return true;
+
+            // clear out old
+            if (ref != null) {
+                currentPixelCount -= ref.pixelCount;
+                map.remove(hash);
+            }
+
+            // add new image to pixel count
+            final int newPixelCount = image.getWidth(null) * image.getHeight(null);
+            currentPixelCount += newPixelCount;
+            // clean out lost references if not enough space
+            if (currentPixelCount > maxPixelCount) {
+                while ((ref = (PixelCountSoftReference)referenceQueue.poll()) != null) {
+                    //reference lost
+                    map.remove(ref.hash);
+                    currentPixelCount -= ref.pixelCount;
+                }
+            }
+
+            // remove old items till there is enough free space
+            if (currentPixelCount > maxPixelCount) {
+                final Iterator<Map.Entry<Integer, PixelCountSoftReference>> mapIter = map.entrySet().iterator();
+                while ((currentPixelCount > maxPixelCount) && mapIter.hasNext()) {
+                    final Map.Entry<Integer, PixelCountSoftReference> entry = mapIter.next();
+                    mapIter.remove();
+                    final Image img = entry.getValue().get();
+                    if (img != null) img.flush();
+                    currentPixelCount -= entry.getValue().pixelCount;
+                }
+            }
+            // finally put new in map
+            map.put(hash, new PixelCountSoftReference(image, referenceQueue, newPixelCount, hash, config, w, h, state));
+            return true;
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    private int hash(final GraphicsConfiguration config, final int w, final int h, final JRSUIState state) {
+        int hash = (config != null ? config.hashCode() : 0);
+        hash = 31 * hash + w;
+        hash = 31 * hash + h;
+        hash = 31 * hash + state.hashCode();
+        return hash;
+    }
+
+    /** Extended SoftReference that stores the pixel count even after the image is lost */
+    private static class PixelCountSoftReference extends SoftReference<Image> {
+        private final int pixelCount;
+        private final int hash;
+
+        // key parts
+        private final GraphicsConfiguration config;
+        private final int w;
+        private final int h;
+        private final JRSUIState state;
+
+        public PixelCountSoftReference(final Image referent, final ReferenceQueue<? super Image> q, final int pixelCount, final int hash, final GraphicsConfiguration config, final int w, final int h, final JRSUIState state) {
+            super(referent, q);
+            this.pixelCount = pixelCount;
+            this.hash = hash;
+            this.config = config;
+            this.w = w;
+            this.h = h;
+            this.state = state;
+        }
+
+        public boolean equals(final GraphicsConfiguration config, final int w, final int h, final JRSUIState state) {
+            return config == this.config && w == this.w && h == this.h && state.equals(this.state);
+        }
+    }
+
+//    /** Gets the rendered image for this painter at the requested size, either from cache or create a new one */
+//    private VolatileImage getImage(GraphicsConfiguration config, JComponent c, int w, int h, Object[] extendedCacheKeys) {
+//        VolatileImage buffer = (VolatileImage)getImage(config, w, h, this, extendedCacheKeys);
+//
+//        int renderCounter = 0; // to avoid any potential, though unlikely, infinite loop
+//        do {
+//            //validate the buffer so we can check for surface loss
+//            int bufferStatus = VolatileImage.IMAGE_INCOMPATIBLE;
+//            if (buffer != null) {
+//                bufferStatus = buffer.validate(config);
+//            }
+//
+//            //If the buffer status is incompatible or restored, then we need to re-render to the volatile image
+//            if (bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE || bufferStatus == VolatileImage.IMAGE_RESTORED) {
+//                // if the buffer isn't the right size, or has lost its contents, then recreate
+//                if (buffer != null) {
+//                    if (buffer.getWidth() != w || buffer.getHeight() != h || bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE) {
+//                        // clear any resources related to the old back buffer
+//                        buffer.flush();
+//                        buffer = null;
+//                    }
+//                }
+//
+//                if (buffer == null) {
+//                    // recreate the buffer
+//                    buffer = config.createCompatibleVolatileImage(w, h, Transparency.TRANSLUCENT);
+//                    // put in cache for future
+//                    setImage(buffer, config, w, h, this, extendedCacheKeys);
+//                }
+//
+//                //create the graphics context with which to paint to the buffer
+//                Graphics2D bg = buffer.createGraphics();
+//
+//                //clear the background before configuring the graphics
+//                bg.setComposite(AlphaComposite.Clear);
+//                bg.fillRect(0, 0, w, h);
+//                bg.setComposite(AlphaComposite.SrcOver);
+//                bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+//
+//                // paint the painter into buffer
+//                paint0(bg, c, w, h, extendedCacheKeys);
+//                //close buffer graphics
+//                bg.dispose();
+//            }
+//        } while (buffer.contentsLost() && renderCounter++ < 3);
+//
+//        // check if we failed
+//        if (renderCounter >= 3) return null;
+//
+//        return buffer;
+//    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenu.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenu.java
new file mode 100644
index 0000000..ec4c3f7
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenu.java
@@ -0,0 +1,432 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.peer.MenuComponentPeer;
+import java.security.PrivilegedAction;
+import java.util.Hashtable;
+
+import javax.swing.*;
+
+import sun.lwawt.LWToolkit;
+import sun.lwawt.macosx.*;
+
+class ScreenMenu extends Menu implements ContainerListener, ComponentListener, ScreenMenuPropertyHandler {
+    static {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("awt"));
+    }
+
+    // screen menu stuff
+    public static native long addMenuListeners(ScreenMenu listener, long nativeMenu);
+    public static native void removeMenuListeners(long modelPtr);
+
+    long fModelPtr = 0;
+
+    Hashtable<Component, MenuItem> fItems;
+    JMenu fInvoker;
+
+    Component fLastMouseEventTarget;
+    Rectangle fLastTargetRect;
+    private volatile Rectangle[] fItemBounds;
+
+    // Array of child hashes used to see if we need to recreate the Menu.
+    int childHashArray[];
+
+    ScreenMenu(final JMenu invoker) {
+        super(invoker.getText());
+        fInvoker = invoker;
+
+        int count = fInvoker.getMenuComponentCount();
+        if (count < 5) count = 5;
+        fItems = new Hashtable<Component, MenuItem>(count);
+        setEnabled(fInvoker.isEnabled());
+        updateItems();
+    }
+
+    // I'm always 'visible', but never on screen
+    static class ScreenMenuComponent extends Container {
+        public boolean isVisible() { return true; }
+        public boolean isShowing() { return true; }
+        public void setVisible(final boolean b) {}
+        public void show() {}
+    }
+
+    ScreenMenuComponent makeScreenMenuComponent() {
+        return new ScreenMenuComponent();
+    }
+
+
+    /**
+     * Determine if we need to tear down the Menu and re-create it, since the contents may have changed in the Menu opened listener and
+     * we do not get notified of it, because EDT is busy in our code. We only need to update if the menu contents have changed in some
+     * way, such as the number of menu items, the text of the menuitems, icon, shortcut etc.
+     */
+    static boolean needsUpdate(final Component items[], final int childHashArray[]) {
+      if (items == null || childHashArray == null) {
+        return true;
+      }
+      if (childHashArray.length != items.length) {
+       return true;
+      }
+      for (int i = 0; i < items.length; i++) {
+          final int hashCode = getHashCode(items[i]);
+          if (hashCode != childHashArray[i]) {
+            return true;
+          }
+      }
+      return false;
+    }
+
+    /**
+     * Used to recreate the AWT based Menu structure that implements the Screen Menu.
+     * Also computes hashcode and stores them so that we can compare them later in needsUpdate.
+     */
+    void updateItems() {
+        final int count = fInvoker.getMenuComponentCount();
+        final Component[] items = fInvoker.getMenuComponents();
+        if (needsUpdate(items, childHashArray)) {
+            removeAll();
+            if (count <= 0) return;
+
+            childHashArray = new int[count];
+            for (int i = 0; i < count; i++) {
+                addItem(items[i]);
+                childHashArray[i] = getHashCode(items[i]);
+            }
+        }
+    }
+
+    /**
+     * Callback from JavaMenuUpdater.m -- called when menu first opens
+     */
+    public void invokeOpenLater() {
+        final JMenu invoker = fInvoker;
+        if (invoker == null) {
+            System.err.println("invoker is null!");
+            return;
+        }
+
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public void run() {
+                    invoker.setSelected(true);
+                    invoker.validate();
+                    updateItems();
+                    fItemBounds = new Rectangle[invoker.getMenuComponentCount()];
+                }
+            }, null);
+        } catch (final Exception e) {
+            System.err.println(e);
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Callback from JavaMenuUpdater.m -- called when menu closes.
+     */
+    public void invokeMenuClosing() {
+        final JMenu invoker = fInvoker;
+        if (invoker == null) return;
+
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public void run() {
+                    invoker.setSelected(false);
+
+            // Null out the tracking rectangles and the array.
+                    if (fItemBounds != null) {
+            for (int i = 0; i < fItemBounds.length; i++) {
+                fItemBounds[i] = null;
+            }
+                    }
+
+            fItemBounds = null;
+    }
+            }, null);
+        } catch (final Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Callback from JavaMenuUpdater.m -- called when menu item is hilighted.
+     *
+     * @param inWhichItem The menu item selected by the user. -1 if mouse moves off the menu.
+     * @param itemRectTop
+     * @param itemRectLeft
+     * @param itemRectBottom
+     * @param itemRectRight Tracking rectangle coordinates.
+     */
+    public void handleItemTargeted(final int inWhichItem, final int itemRectTop, final int itemRectLeft, final int itemRectBottom, final int itemRectRight) {
+        if (fItemBounds == null || inWhichItem < 0 || inWhichItem > (fItemBounds.length - 1)) return;
+        final Rectangle itemRect = new Rectangle(itemRectLeft, itemRectTop, itemRectRight - itemRectLeft, itemRectBottom - itemRectTop);
+        fItemBounds[inWhichItem] = itemRect;
+    }
+
+    /**
+     * Callback from JavaMenuUpdater.m -- called when mouse event happens on the menu.
+     */
+    public void handleMouseEvent(final int kind, final int x, final int y, final int modifiers, final long when) {
+        if (kind == 0) return;
+        if (fItemBounds == null) return;
+
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                Component target = null;
+                Rectangle targetRect = null;
+                for (int i = 0; i < fItemBounds.length; i++) {
+                    final Rectangle testRect = fItemBounds[i];
+                    if (testRect != null) {
+                        if (testRect.contains(x, y)) {
+                            target = fInvoker.getMenuComponent(i);
+                            targetRect = testRect;
+                            break;
+                        }
+                    }
+                }
+                if (target == null && fLastMouseEventTarget == null) return;
+
+                // Send a mouseExited to the previously hilited item, if it wasn't 0.
+                if (target != fLastMouseEventTarget) {
+                    if (fLastMouseEventTarget != null) {
+                        LWToolkit.postEvent(new MouseEvent(fLastMouseEventTarget, MouseEvent.MOUSE_EXITED, when, modifiers, x - fLastTargetRect.x, y - fLastTargetRect.y, 0, false));
+                    }
+                    // Send a mouseEntered to the current hilited item, if it wasn't 0.
+                    if (target != null) {
+                        LWToolkit.postEvent(new MouseEvent(target, MouseEvent.MOUSE_ENTERED, when, modifiers, x - targetRect.x, y - targetRect.y, 0, false));
+                    }
+                    fLastMouseEventTarget = target;
+                    fLastTargetRect = targetRect;
+                }
+                // Post a mouse event to the current item.
+                if (target == null) return;
+                LWToolkit.postEvent(new MouseEvent(target, kind, when, modifiers, x - targetRect.x, y - targetRect.y, 0, false));
+            }
+        });
+    }
+
+    ScreenMenuPropertyListener fPropertyListener;
+    public void addNotify() {
+        super.addNotify();
+        if (fModelPtr == 0) {
+        fInvoker.addContainerListener(this);
+        fInvoker.addComponentListener(this);
+        fPropertyListener = new ScreenMenuPropertyListener(this);
+        fInvoker.addPropertyChangeListener(fPropertyListener);
+
+        final Icon icon = fInvoker.getIcon();
+        if (icon != null) {
+            this.setIcon(icon);
+        }
+
+        final String tooltipText = fInvoker.getToolTipText();
+        if (tooltipText != null) {
+            this.setToolTipText(tooltipText);
+        }
+        final MenuComponentPeer peer = getPeer();
+        if (peer instanceof CMenu) {
+            final CMenu menu = (CMenu)peer;
+            final long nativeMenu = menu.getNativeMenu();
+            fModelPtr = addMenuListeners(this, nativeMenu);
+            }
+        }
+    }
+
+    public void removeNotify() {
+        // Call super so that the NSMenu has been removed, before we release the delegate in removeMenuListeners
+        super.removeNotify();
+        fItems.clear();
+        if (fModelPtr != 0) {
+            removeMenuListeners(fModelPtr);
+            fModelPtr = 0;
+            fInvoker.removeContainerListener(this);
+            fInvoker.removeComponentListener(this);
+            fInvoker.removePropertyChangeListener(fPropertyListener);
+        }
+    }
+
+    /**
+     * Invoked when a component has been added to the container.
+     */
+    public void componentAdded(final ContainerEvent e) {
+        addItem(e.getChild());
+    }
+
+    /**
+     * Invoked when a component has been removed from the container.
+     */
+    public void componentRemoved(final ContainerEvent e) {
+        final Component child = e.getChild();
+        final MenuItem sm = fItems.get(child);
+        if (sm == null) return;
+
+            remove(sm);
+            fItems.remove(sm);
+        }
+
+    /**
+     * Invoked when the component's size changes.
+     */
+    public void componentResized(final ComponentEvent e) {}
+
+    /**
+     * Invoked when the component's position changes.
+     */
+    public void componentMoved(final ComponentEvent e) {}
+
+    /**
+     * Invoked when the component has been made visible.
+     * See componentHidden - we should still have a MenuItem
+     * it just isn't inserted
+     */
+    public void componentShown(final ComponentEvent e) {
+        setVisible(true);
+    }
+
+    /**
+     * Invoked when the component has been made invisible.
+     * MenuComponent.setVisible does nothing,
+     * so we remove the ScreenMenuItem from the ScreenMenu
+     * but leave it in fItems
+     */
+    public void componentHidden(final ComponentEvent e) {
+        setVisible(false);
+    }
+
+    public void setVisible(final boolean b) {
+        // Tell our parent to add/remove us
+        final MenuContainer parent = getParent();
+
+        if (parent != null) {
+            if (parent instanceof ScreenMenu) {
+                final ScreenMenu sm = (ScreenMenu)parent;
+                sm.setChildVisible(fInvoker, b);
+    }
+        }
+    }
+
+    public void setChildVisible(final JMenuItem child, final boolean b) {
+        fItems.remove(child);
+        updateItems();
+    }
+
+    public void setAccelerator(final KeyStroke ks) {}
+
+    // only check and radio items can be indeterminate
+    public void setIndeterminate(boolean indeterminate) { }
+
+    public void setToolTipText(final String text) {
+        final MenuComponentPeer peer = getPeer();
+        if (!(peer instanceof CMenuItem)) return;
+
+        final CMenuItem cmi = (CMenuItem)peer;
+        cmi.setToolTipText(text);
+    }
+
+    public void setIcon(final Icon i) {
+        final MenuComponentPeer peer = getPeer();
+        if (!(peer instanceof CMenuItem)) return;
+
+        final CMenuItem cmi = (CMenuItem)peer;
+        Image img = null;
+
+        if (i != null) {
+            if (i.getIconWidth() > 0 && i.getIconHeight() > 0) {
+                img = AquaIcon.getImageForIcon(i);
+            }
+        }
+        cmi.setImage(img);
+    }
+
+
+    /**
+     * Gets a hashCode for a JMenu or JMenuItem or subclass so that we can compare for
+     * changes in the Menu.
+     *
+     */
+    static int getHashCode(final Component m) {
+        int hashCode = m.hashCode();
+
+        if (m instanceof JMenuItem) {
+            final JMenuItem mi = (JMenuItem) m;
+
+            final String text = mi.getText();
+            if (text != null) hashCode ^= text.hashCode();
+
+            final Icon icon = mi.getIcon();
+            if (icon != null) hashCode ^= icon.hashCode();
+
+            final Icon disabledIcon = mi.getDisabledIcon();
+            if (disabledIcon != null) hashCode ^= disabledIcon.hashCode();
+
+            final Action action = mi.getAction();
+            if (action != null) hashCode ^= action.hashCode();
+
+            final KeyStroke ks = mi.getAccelerator();
+            if (ks != null) hashCode ^= ks.hashCode();
+
+            hashCode ^= Boolean.valueOf(mi.isVisible()).hashCode();
+            hashCode ^= Boolean.valueOf(mi.isEnabled()).hashCode();
+            hashCode ^= Boolean.valueOf(mi.isSelected()).hashCode();
+
+        } else if (m instanceof JSeparator) {
+            hashCode ^= "-".hashCode();
+        }
+
+        return hashCode;
+    }
+
+    void addItem(final Component m) {
+        if (!m.isVisible()) return;
+        MenuItem sm = fItems.get(m);
+
+        if (sm == null) {
+            if (m instanceof JMenu) {
+                sm = new ScreenMenu((JMenu)m);
+            } else if (m instanceof JCheckBoxMenuItem) {
+                sm = new ScreenMenuItemCheckbox((JCheckBoxMenuItem)m);
+            } else if (m instanceof JRadioButtonMenuItem) {
+                sm = new ScreenMenuItemCheckbox((JRadioButtonMenuItem)m);
+            } else if (m instanceof JMenuItem) {
+                sm = new ScreenMenuItem((JMenuItem)m);
+            } else if (m instanceof JPopupMenu.Separator || m instanceof JSeparator) {
+                sm = new MenuItem("-"); // This is what java.awt.Menu.addSeparator does
+            }
+
+            // Only place the menu item in the hashtable if we just created it.
+            if (sm != null) {
+                fItems.put(m, sm);
+            }
+        }
+
+        if (sm != null) {
+            add(sm);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuBar.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuBar.java
new file mode 100644
index 0000000..c0d515d
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuBar.java
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.reflect.*;
+import java.security.*;
+import java.util.*;
+
+import javax.swing.*;
+
+public class ScreenMenuBar extends MenuBar implements ContainerListener, ScreenMenuPropertyHandler, ComponentListener {
+    static boolean sJMenuBarHasHelpMenus = false; //$ could check by calling getHelpMenu in a try block
+
+    JMenuBar fSwingBar;
+    Hashtable<JMenu, ScreenMenu> fSubmenus;
+
+    ScreenMenuPropertyListener fPropertyListener;
+    ScreenMenuPropertyListener fAccessibleListener;
+
+    public ScreenMenuBar(final JMenuBar swingBar) {
+        fSwingBar = swingBar;
+        fSubmenus = new Hashtable<JMenu, ScreenMenu>(fSwingBar.getMenuCount());
+    }
+
+    public void addNotify() {
+        super.addNotify();
+
+        fSwingBar.addContainerListener(this);
+        fPropertyListener = new ScreenMenuPropertyListener(this);
+        fSwingBar.addPropertyChangeListener(fPropertyListener);
+        fAccessibleListener = new ScreenMenuPropertyListener(this);
+        fSwingBar.getAccessibleContext().addPropertyChangeListener(fAccessibleListener);
+
+        // We disable component events when the menu bar is not parented.  So now we need to
+        // sync back up with the current state of the JMenuBar.  We first add the menus we
+        // don't have and then remove the items that are no longer on the JMenuBar.
+        final int count = fSwingBar.getMenuCount();
+        for(int i = 0; i < count ; i++) {
+            final JMenu m = fSwingBar.getMenu(i);
+            if (m != null) {
+                addSubmenu(m);
+            }
+        }
+
+        final Enumeration<JMenu> e = fSubmenus.keys();
+        while (e.hasMoreElements()) {
+            final JMenu m = e.nextElement();
+            if (fSwingBar.getComponentIndex(m) == -1) {
+                removeSubmenu(m);
+            }
+        }
+    }
+
+    public void removeNotify() {
+        // KCH - 3974930 - We do null checks for fSwingBar and fSubmenus because some people are using
+        // reflection to muck about with our ivars
+        if (fSwingBar != null) {
+            fSwingBar.removePropertyChangeListener(fPropertyListener);
+            fSwingBar.getAccessibleContext().removePropertyChangeListener(fAccessibleListener);
+            fSwingBar.removeContainerListener(this);
+        }
+
+        fPropertyListener = null;
+        fAccessibleListener = null;
+
+        if (fSubmenus != null) {
+            // We don't listen to events when the menu bar is not parented.
+            // Remove all the component listeners.
+            final Enumeration<JMenu> e = fSubmenus.keys();
+            while (e.hasMoreElements()) {
+                final JMenu m = e.nextElement();
+                m.removeComponentListener(this);
+            }
+        }
+
+        super.removeNotify();
+    }
+
+    /**
+     * Invoked when a component has been added to the container.
+     */
+    public void componentAdded(final ContainerEvent e) {
+        final Component child = e.getChild();
+        if (!(child instanceof JMenu)) return;
+            addSubmenu((JMenu)child);
+     }
+
+    /**
+     * Invoked when a component has been removed from the container.
+     */
+    public void componentRemoved(final ContainerEvent e) {
+          final Component child = e.getChild();
+          if (!(child instanceof JMenu)) return;
+            removeSubmenu((JMenu)child);
+        }
+
+    /**
+        * Invoked when the component's size changes.
+     */
+    public void componentResized(final ComponentEvent e)  {}
+
+    /**
+        * Invoked when the component's position changes.
+     */
+    public void componentMoved(final ComponentEvent e)  {}
+
+    /**
+        * Invoked when the component has been made visible.
+     * See componentHidden - we should still have a MenuItem
+     * it just isn't inserted
+     */
+    public void componentShown(final ComponentEvent e) {
+        final Object source = e.getSource();
+        if (!(source instanceof JMenuItem)) return;
+        setChildVisible((JMenuItem)source, true);
+    }
+
+    /**
+        * Invoked when the component has been made invisible.
+     * MenuComponent.setVisible does nothing,
+     * so we remove the ScreenMenuItem from the ScreenMenu
+     * but leave it in fItems
+     */
+    public void componentHidden(final ComponentEvent e)  {
+        final Object source = e.getSource();
+        if (!(source instanceof JMenuItem)) return;
+        setChildVisible((JMenuItem)source, false);
+    }
+
+    /*
+     * MenuComponent.setVisible does nothing,
+     * so we just add or remove the child from the ScreenMenuBar
+     * but leave it in the list
+     */
+    public void setChildVisible(final JMenuItem child, final boolean b) {
+        if (child instanceof JMenu) {
+            if (b) {
+                addSubmenu((JMenu)child);
+            } else {
+                final ScreenMenu sm = fSubmenus.get(child);
+                if (sm != null)
+                    remove(sm);
+            }
+        }
+    }
+
+    public void removeAll() {
+        synchronized (getTreeLock()) {
+            final int nitems = getMenuCount();
+            for (int i = nitems-1 ; i >= 0 ; i--) {
+                remove(i);
+            }
+        }
+    }
+
+    public void setIcon(final Icon i) {}
+    public void setLabel(final String s) {}
+
+    public void setEnabled(final boolean b) {
+        final int count = fSwingBar.getMenuCount();
+        for (int i = 0; i < count; i++) {
+            fSwingBar.getMenu(i).setEnabled(b);
+        }
+    }
+
+    public void setAccelerator(final KeyStroke ks) {}
+    public void setToolTipText(final String tooltip) {}
+
+    // only check and radio items can be indeterminate
+    public void setIndeterminate(boolean indeterminate) { }
+
+    ScreenMenu addSubmenu(final JMenu m) {
+        ScreenMenu sm = fSubmenus.get(m);
+
+        if (sm == null) {
+            sm = new ScreenMenu(m);
+            m.addComponentListener(this);
+            fSubmenus.put(m, sm);
+        }
+
+        sm.setEnabled(m.isEnabled());
+
+        // MenuComponents don't support setVisible, so we just don't add it to the menubar
+        if (m.isVisible() && sm.getParent() == null) {
+            int newIndex = 0, currVisibleIndex = 0;
+            JMenu menu = null;
+            final int menuCount = fSwingBar.getMenuCount();
+            for (int i = 0; i < menuCount; i++) {
+                menu = fSwingBar.getMenu(i);
+                if (menu == m) {
+                    newIndex = currVisibleIndex;
+                    break;
+                }
+                if (menu != null && menu.isVisible()) {
+                    currVisibleIndex++;
+                }
+            }
+            add(sm, newIndex);
+        }
+
+        return sm;
+    }
+
+    /**
+     * Remove the screen menu associated with the specifiec menu.  This
+     * also removes any associated component listener on the screen menu
+     * and removes the key/value (menu/screen menu) from the fSubmenus cache.
+     *
+     * @param menu The swing menu we want to remove the screen menu for.
+     */
+    private void removeSubmenu(final JMenu menu) {
+        final ScreenMenu screenMenu = fSubmenus.get(menu);
+        if (screenMenu == null) return;
+
+            menu.removeComponentListener(this);
+            remove(screenMenu);
+            fSubmenus.remove(menu);
+    }
+
+    private static Field[] stolenFields = null;
+
+    static {
+        stolenFields = AccessController.doPrivileged(new PrivilegedAction<Field[]>() {
+            public Field[] run() {
+                try {
+                    final Field[] localFields = new Field[2];
+                    localFields[0] = MenuBar.class.getDeclaredField("menus");
+                    localFields[1] = MenuComponent.class.getDeclaredField("parent");
+                    AccessibleObject.setAccessible(localFields, true);
+                    return localFields;
+                } catch (final NoSuchFieldException nsf) {
+                    // If this happens, Sun changed the definition of MenuBar and MenuComponent!
+                    nsf.printStackTrace(System.err);
+                    return null;
+                }
+            }
+        });
+    };
+
+    public Menu add(final Menu m, final int index) {
+        synchronized (getTreeLock()) {
+            if (m.getParent() != null) {
+                m.getParent().remove(m);
+            }
+
+            // Use nasty reflection to get at the menus array and parent fields.
+            try {
+                if (stolenFields == null) return m;
+
+                final Vector<Menu> menus = (Vector<Menu>)stolenFields[0].get(this);
+                    menus.insertElementAt(m, index);
+
+                    stolenFields[1].set(m, this);
+
+                    final sun.lwawt.macosx.CMenuBar peer = (sun.lwawt.macosx.CMenuBar)getPeer();
+                if (peer == null) return m;
+
+                        peer.setNextInsertionIndex(index);
+                        if (m.getPeer() == null) {
+                            m.addNotify();
+                        }
+
+                        peer.setNextInsertionIndex(-1);
+            } catch (final IllegalAccessException iae) {
+                iae.printStackTrace(System.err);
+            }
+
+            return m;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuBarProvider.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuBarProvider.java
new file mode 100644
index 0000000..4e59591
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuBarProvider.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+public interface ScreenMenuBarProvider {
+    ScreenMenuBar getScreenMenuBar();
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItem.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItem.java
new file mode 100644
index 0000000..49e4997
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItem.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.peer.MenuComponentPeer;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+
+import sun.lwawt.macosx.CMenuItem;
+
+class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler {
+    ScreenMenuPropertyListener fListener;
+    JMenuItem fMenuItem;
+
+    ScreenMenuItem(final JMenuItem mi) {
+        super(mi.getText());
+        fMenuItem = mi;
+        setEnabled(fMenuItem.isEnabled());
+        final ComponentUI ui = fMenuItem.getUI();
+
+        if (ui instanceof ScreenMenuItemUI) {
+            ((ScreenMenuItemUI)ui).updateListenersForScreenMenuItem();
+            // SAK:  Not calling this means that mouse and mouse motion listeners don't get
+            // installed.  Not a problem because the menu manager handles tracking for us.
+    }
+    }
+
+    public void addNotify() {
+        super.addNotify();
+
+        fMenuItem.addComponentListener(this);
+        fListener = new ScreenMenuPropertyListener(this);
+        fMenuItem.addPropertyChangeListener(fListener);
+        addActionListener(this);
+
+        setEnabled(fMenuItem.isEnabled());
+
+        // can't setState or setAccelerator or setIcon till we have a peer
+        setAccelerator(fMenuItem.getAccelerator());
+
+        final String label = fMenuItem.getText();
+        if (label != null) {
+            setLabel(label);
+        }
+
+        final Icon icon = fMenuItem.getIcon();
+        if (icon != null) {
+            this.setIcon(icon);
+        }
+
+        final String tooltipText = fMenuItem.getToolTipText();
+        if (tooltipText != null) {
+            this.setToolTipText(tooltipText);
+        }
+
+        if (fMenuItem instanceof JRadioButtonMenuItem) {
+            final ComponentUI ui = fMenuItem.getUI();
+
+            if (ui instanceof ScreenMenuItemUI) {
+                ((ScreenMenuItemUI)ui).updateListenersForScreenMenuItem();
+            }
+        }
+    }
+
+    public void removeNotify() {
+        super.removeNotify();
+        removeActionListener(this);
+        fMenuItem.removePropertyChangeListener(fListener);
+        fListener = null;
+        fMenuItem.removeComponentListener(this);
+    }
+
+    public void setAccelerator(final KeyStroke ks) {
+        if (ks == null) {
+            setShortcut(null);
+            return;
+        }
+
+        final MenuComponentPeer peer = getPeer();
+        if (peer instanceof CMenuItem) {
+            final CMenuItem ourPeer = (CMenuItem)peer;
+            ourPeer.setLabel(fMenuItem.getText(), ks.getKeyChar(), ks.getKeyCode(), ks.getModifiers());
+        } else {
+            setShortcut(new MenuShortcut(ks.getKeyCode(), (ks.getModifiers() & InputEvent.SHIFT_MASK) != 0));
+        }
+    }
+
+    public void actionPerformed(final ActionEvent e) {
+        fMenuItem.doClick(0); // This takes care of all the different events
+    }
+
+    /**
+     * Invoked when the component's size changes.
+     */
+    public void componentResized(final ComponentEvent e) {}
+
+    /**
+     * Invoked when the component's position changes.
+     */
+    public void componentMoved(final ComponentEvent e) {}
+
+    /**
+     * Invoked when the component has been made visible.
+     * See componentHidden - we should still have a MenuItem
+     * it just isn't inserted
+     */
+    public void componentShown(final ComponentEvent e) {
+        setVisible(true);
+    }
+
+    /**
+     * Invoked when the component has been made invisible.
+     * MenuComponent.setVisible does nothing,
+     * so we remove the ScreenMenuItem from the ScreenMenu
+     * but leave it in fItems
+     */
+    public void componentHidden(final ComponentEvent e) {
+        setVisible(false);
+    }
+
+    public void setVisible(final boolean b) {
+        // Tell our parent to add/remove us -- parent may be nil if we aren't set up yet.
+        // Hang on to our parent
+        final MenuContainer parent = getParent();
+
+        if (parent != null) {
+            ((ScreenMenuPropertyHandler)parent).setChildVisible(fMenuItem, b);
+        }
+    }
+
+    public void setToolTipText(final String text) {
+        final MenuComponentPeer peer = getPeer();
+        if (!(peer instanceof CMenuItem)) return;
+
+        final CMenuItem cmi = (CMenuItem)peer;
+        cmi.setToolTipText(text);
+    }
+
+    public void setIcon(final Icon i) {
+        final MenuComponentPeer peer = getPeer();
+        if (!(peer instanceof CMenuItem)) return;
+
+        final CMenuItem cmi = (CMenuItem)peer;
+            Image img = null;
+
+        if (i != null) {
+            if (i.getIconWidth() > 0 && i.getIconHeight() > 0) {
+                    img = AquaIcon.getImageForIcon(i);
+                }
+        }
+            cmi.setImage(img);
+        }
+
+    // we have no children
+    public void setChildVisible(final JMenuItem child, final boolean b) {}
+
+    // only check and radio items can be indeterminate
+    public void setIndeterminate(boolean indeterminate) { }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java
new file mode 100644
index 0000000..15f314e
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.peer.MenuComponentPeer;
+
+import javax.swing.*;
+import javax.swing.plaf.ButtonUI;
+
+import com.apple.laf.AquaMenuItemUI.IndeterminateListener;
+
+import sun.lwawt.macosx.*;
+
+class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler, ItemListener {
+    JMenuItem fMenuItem;
+    MenuContainer fParent;
+
+    ScreenMenuItemCheckbox(final JCheckBoxMenuItem mi) {
+        super(mi.getText(), mi.getState());
+        init(mi);
+    }
+
+    ScreenMenuItemCheckbox(final JRadioButtonMenuItem mi) {
+        super(mi.getText(), mi.getModel().isSelected());
+        init(mi);
+    }
+
+    public void init(final JMenuItem mi) {
+        fMenuItem = mi;
+        setEnabled(fMenuItem.isEnabled());
+    }
+
+    ScreenMenuPropertyListener fPropertyListener;
+    public void addNotify() {
+        super.addNotify();
+
+        // Avoid the Auto toggle behavior of AWT CheckBoxMenuItem
+        CCheckboxMenuItem ccb = (CCheckboxMenuItem) getPeer();
+        ccb.setAutoToggle(false);
+
+        fMenuItem.addComponentListener(this);
+        fPropertyListener = new ScreenMenuPropertyListener(this);
+        fMenuItem.addPropertyChangeListener(fPropertyListener);
+        addActionListener(this);
+        addItemListener(this);
+        fMenuItem.addItemListener(this);
+        setIndeterminate(IndeterminateListener.isIndeterminate(fMenuItem));
+
+        // can't setState or setAccelerator or setIcon till we have a peer
+        setAccelerator(fMenuItem.getAccelerator());
+
+        final Icon icon = fMenuItem.getIcon();
+        if (icon != null) {
+            this.setIcon(icon);
+        }
+
+        final String tooltipText = fMenuItem.getToolTipText();
+        if (tooltipText != null) {
+            this.setToolTipText(tooltipText);
+        }
+
+        // sja fix is this needed?
+        fMenuItem.addItemListener(this);
+
+        final ButtonUI ui = fMenuItem.getUI();
+        if (ui instanceof ScreenMenuItemUI) {
+            ((ScreenMenuItemUI)ui).updateListenersForScreenMenuItem();
+        }
+
+        if (fMenuItem instanceof JCheckBoxMenuItem) {
+            setState(((JCheckBoxMenuItem)fMenuItem).isSelected());
+        } else {
+            setState(fMenuItem.getModel().isSelected());
+        }
+    }
+
+    public void removeNotify() {
+        fMenuItem.removeComponentListener(this);
+        fMenuItem.removePropertyChangeListener(fPropertyListener);
+        fPropertyListener = null;
+        removeActionListener(this);
+        removeItemListener(this);
+        fMenuItem.removeItemListener(this);
+
+        super.removeNotify();
+    }
+
+    public void setAccelerator(final KeyStroke ks) {
+        if (ks == null) {
+            setShortcut(null);
+            return;
+        }
+
+        final MenuComponentPeer peer = getPeer();
+        if (peer instanceof CMenuItem) {
+            final CMenuItem ourPeer = (CMenuItem)peer;
+            ourPeer.setLabel(fMenuItem.getText(), ks.getKeyChar(), ks.getKeyCode(), ks.getModifiers());
+        } else {
+            setShortcut(new MenuShortcut(ks.getKeyCode(), (ks.getModifiers() & InputEvent.SHIFT_MASK) != 0));
+        }
+    }
+
+    public void actionPerformed(final ActionEvent e) {
+        fMenuItem.doClick(0); // This takes care of all the different events
+    }
+
+    /**
+     * Invoked when the component's size changes.
+     */
+    public void componentResized(final ComponentEvent e) {}
+
+    /**
+     * Invoked when the component's position changes.
+     */
+    public void componentMoved(final ComponentEvent e) {}
+
+    /**
+     * Invoked when the component has been made visible.
+     * See componentHidden - we should still have a MenuItem
+     * it just isn't inserted
+     */
+    public void componentShown(final ComponentEvent e) {
+        setVisible(true);
+    }
+
+    /**
+     * Invoked when the component has been made invisible.
+     * MenuComponent.setVisible does nothing,
+     * so we remove the ScreenMenuItem from the ScreenMenu
+     * but leave it in fItems
+     */
+    public void componentHidden(final ComponentEvent e) {
+        setVisible(false);
+    }
+
+    public void setToolTipText(final String text) {
+        final MenuComponentPeer peer = getPeer();
+        if (!(peer instanceof CMenuItem)) return;
+
+        ((CMenuItem)peer).setToolTipText(text);
+    }
+
+    public void setIcon(final Icon i) {
+        final MenuComponentPeer peer = getPeer();
+        if (!(peer instanceof CMenuItem)) return;
+
+        final CMenuItem cmi = (CMenuItem)peer;
+        Image img = null;
+
+        if (i != null) {
+            if (i.getIconWidth() > 0 && i.getIconHeight() > 0) {
+                img = AquaIcon.getImageForIcon(i);
+            }
+        }
+        cmi.setImage(img);
+    }
+
+    public void setVisible(final boolean b) {
+        // Tell our parent to add/remove us
+        // Hang on to our parent
+        if (fParent == null) fParent = getParent();
+        ((ScreenMenuPropertyHandler)fParent).setChildVisible(fMenuItem, b);
+    }
+
+    // we have no children
+    public void setChildVisible(final JMenuItem child, final boolean b) {}
+
+    /**
+     * Invoked when an item's state has been changed.
+     */
+    public void itemStateChanged(final ItemEvent e) {
+        if (e.getSource() == this) {
+            fMenuItem.doClick(0);
+            return;
+        }
+
+            switch (e.getStateChange()) {
+                case ItemEvent.SELECTED:
+                    setState(true);
+                    break;
+                case ItemEvent.DESELECTED:
+                    setState(false);
+                    break;
+            }
+        }
+
+    public void setIndeterminate(final boolean indeterminate) {
+        final MenuComponentPeer peer = getPeer();
+        if (peer instanceof CCheckboxMenuItem) {
+            ((CCheckboxMenuItem)peer).setIsIndeterminate(indeterminate);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemUI.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemUI.java
new file mode 100644
index 0000000..d3754bd
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemUI.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+public interface ScreenMenuItemUI {
+    void updateListenersForScreenMenuItem();
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuPropertyHandler.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuPropertyHandler.java
new file mode 100644
index 0000000..1f9d2e3
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuPropertyHandler.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.Font;
+
+import javax.swing.*;
+
+// interface to let the Screen Menu classes share a JComponent PropertyChangeListener
+interface ScreenMenuPropertyHandler {
+    public void setEnabled(boolean b);
+    public void setFont(Font f);
+    public void setLabel(String f);
+    public void setIcon(Icon icon);
+    public void setAccelerator(KeyStroke ks);
+    public void setToolTipText(String tooltip);
+    public void setChildVisible(javax.swing.JMenuItem child, boolean b);
+    public void setIndeterminate(boolean indeterminate);
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuPropertyListener.java b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuPropertyListener.java
new file mode 100644
index 0000000..7d2f970
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuPropertyListener.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.beans.*;
+
+import javax.accessibility.*;
+import javax.swing.*;
+
+class ScreenMenuPropertyListener implements PropertyChangeListener {
+    ScreenMenuPropertyHandler fMenu;
+
+    ScreenMenuPropertyListener(final ScreenMenuPropertyHandler mc) {
+        fMenu = mc;
+    }
+
+    /**
+     * This method gets called when a bound property is changed.
+     * @param evt A PropertyChangeEvent object describing the event source
+     *       and the property that has changed.
+     */
+    public void propertyChange(final PropertyChangeEvent e) {
+        final String propertyName = e.getPropertyName();
+
+        if ("enabled".equals(propertyName)) {
+            fMenu.setEnabled(((Boolean)e.getNewValue()).booleanValue());
+            return;
+        }
+
+        if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(propertyName)) {
+            // rdar://Problem/3553843
+            // When an ACCESSIBLE_STATE_PROPERTY changes, it's always newValue == null and oldValue == state turned off
+            // or newValue == state turned on and oldValue == null.  We only care about changes in the ENABLED
+            // state, so only change the menu's enabled state when the value is AccessibleState.ENABLED
+            if (e.getNewValue() == AccessibleState.ENABLED || e.getOldValue() == AccessibleState.ENABLED) {
+                final Object newValue = e.getNewValue();
+                fMenu.setEnabled(newValue == AccessibleState.ENABLED);
+            }
+            return;
+    }
+
+        if ("accelerator".equals(propertyName)) {
+            fMenu.setAccelerator((KeyStroke)e.getNewValue());
+            return;
+        }
+
+        if (AbstractButton.TEXT_CHANGED_PROPERTY.equals(propertyName)) {
+            fMenu.setLabel((String)e.getNewValue());
+            return;
+        }
+
+        if (AbstractButton.ICON_CHANGED_PROPERTY.equals(propertyName)) {
+            fMenu.setIcon((Icon)e.getNewValue());
+            return;
+        }
+
+        if (JComponent.TOOL_TIP_TEXT_KEY.equals(propertyName)) {
+            fMenu.setToolTipText((String)e.getNewValue());
+            return;
+        }
+
+        if (AquaMenuItemUI.IndeterminateListener.CLIENT_PROPERTY_KEY.equals(propertyName)) {
+            fMenu.setIndeterminate(AquaMenuItemUI.IndeterminateListener.isIndeterminate((JMenuItem)e.getSource()));
+            return;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/ScreenPopupFactory.java b/jdk/src/macosx/classes/com/apple/laf/ScreenPopupFactory.java
new file mode 100644
index 0000000..6993d4f
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenPopupFactory.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.laf;
+
+import java.awt.*;
+import java.security.PrivilegedAction;
+
+import javax.swing.*;
+
+import sun.lwawt.macosx.CPlatformWindow;
+
+class ScreenPopupFactory extends PopupFactory {
+    static {
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osxui"));
+    }
+
+    static final Float TRANSLUCENT = new Float(248f/255f);
+    static final Float OPAQUE = new Float(1.0f);
+
+    boolean fIsActive = true;
+
+    // Only popups generated with the Aqua LaF turned on will be translucent with shadows
+    void setActive(final boolean b) {
+        fIsActive = b;
+    }
+
+    private static Window getWindow(final Component c) {
+        Component w = c;
+        while(!(w instanceof Window) && (w!=null)) {
+            w = w.getParent();
+        }
+        return (Window)w;
+    }
+
+    /*
+     * Since we can't change the signature of PopupFactory, we have to call the
+     * private method getPopup(Component, Component, int, int, int) through JNI
+     * (see AquaLookAndFeel.m)
+     */
+    native Popup _getHeavyWeightPopup(Component comp, Component invoker, int x, int y);
+
+    public Popup getPopup(final Component comp, final Component invoker, final int x, final int y) {
+        if (invoker == null) throw new IllegalArgumentException("Popup.getPopup must be passed non-null contents");
+
+        final Popup popup;
+        if (fIsActive) {
+            popup = _getHeavyWeightPopup(comp, invoker, x, y);
+        } else {
+            popup = super.getPopup(comp, invoker, x, y);
+        }
+
+        // Make the popup semi-translucent if it is a heavy weight
+        // see <rdar://problem/3547670> JPopupMenus have incorrect background
+        final Window w = getWindow(invoker);
+        if (w == null) return popup;
+
+        if (!(w instanceof RootPaneContainer)) return popup;
+        final JRootPane popupRootPane = ((RootPaneContainer)w).getRootPane();
+
+        // we need to set every time, because PopupFactory caches the heavy weight
+        // TODO: CPlatformWindow constants?
+        if (fIsActive) {
+            popupRootPane.putClientProperty(CPlatformWindow.WINDOW_ALPHA, TRANSLUCENT);
+            popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW, Boolean.TRUE);
+            popupRootPane.putClientProperty(CPlatformWindow.WINDOW_FADE_DELEGATE, invoker);
+
+            w.setBackground(UIManager.getColor("PopupMenu.translucentBackground"));
+            popupRootPane.putClientProperty(CPlatformWindow.WINDOW_DRAGGABLE_BACKGROUND, Boolean.FALSE);
+            SwingUtilities.invokeLater(new Runnable() {
+                public void run() {
+                    popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW_REVALIDATE_NOW, Double.valueOf(Math.random()));
+                }
+            });
+        } else {
+            popupRootPane.putClientProperty(CPlatformWindow.WINDOW_ALPHA, OPAQUE);
+            popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW, Boolean.FALSE);
+        }
+
+        return popup;
+    }
+}
diff --git a/jdk/src/macosx/classes/com/apple/laf/resources/aqua.properties b/jdk/src/macosx/classes/com/apple/laf/resources/aqua.properties
new file mode 100644
index 0000000..30a840d
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/resources/aqua.properties
@@ -0,0 +1,205 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used in Swing
+# Currently, it contains the additional strings needed for the Aqua versions of these components:
+#
+#    FileChooser
+#
+# When this file is read in, the strings are put into the
+# defaults table.  This is an implementation detail of the current
+# workings of Swing.  DO NOT DEPEND ON THIS.
+# This may change in future versions of Swing as we improve localization
+# support.
+
+############ FILE CHOOSER STRINGS #############
+FileChooser.fileDescriptionText=Generic File
+FileChooser.directoryDescriptionText=Directory
+FileChooser.newFolderErrorText=Error occured during folder creation
+FileChooser.newFolderErrorSeparator= :
+FileChooser.acceptAllFileFilterText=All Files
+FileChooser.cancelButtonText=Cancel
+FileChooser.saveButtonText=Save
+FileChooser.openButtonText=Open
+FileChooser.saveDialogTitleText=Save
+FileChooser.openDialogTitleText=Open
+FileChooser.updateButtonText=Update
+FileChooser.helpButtonText=Help
+FileChooser.directoryOpenButtonText=Open
+
+# File Size Units
+FileChooser.fileSizeKiloBytes={0} KB
+FileChooser.fileSizeMegaBytes={0} MB
+FileChooser.fileSizeGigaBytes={0} GB
+
+// Mac-specific strings
+FileChooser.saveTitleText=Save
+FileChooser.openTitleText=Open
+FileChooser.newFolderExistsErrorText=That name is already taken
+FileChooser.chooseButtonText=Choose
+
+FileChooser.newFolderButtonText=New Folder
+FileChooser.newFolderTitleText=New Folder
+FileChooser.fileNameLabelText=File:
+FileChooser.saveDialogFileNameLabelText=Save As:
+FileChooser.filesOfTypeLabelText=File Format:
+
+FileChooser.desktopName=Desktop
+FileChooser.newFolderPromptText=Name of new folder:
+FileChooser.untitledFolderName=untitled folder
+FileChooser.untitledFileName=untitled
+FileChooser.createButtonText=Create
+
+FileChooser.byDateText=Date Modified
+FileChooser.byNameText=Name
+FileChooser.newFolderAccessibleName=New Folder
+
+FileChooser.mac.newFolder=untitled folder
+FileChooser.mac.newFolder.subsequent=untitled folder {0}
+
+
+############ COLOR CHOOSER STRINGS #############
+ColorChooser.previewText=Preview
+ColorChooser.okText=OK
+ColorChooser.cancelText=Cancel
+ColorChooser.resetText=Reset
+# VK_XXX constant for 'ColorChooser.resetText' button to make mnemonic
+ColorChooser.resetMnemonic=82
+ColorChooser.sampleText=Sample Text  Sample Text
+ColorChooser.swatchesNameText=Swatches
+ColorChooser.swatchesMnemonic=83
+ColorChooser.swatchesDisplayedMnemonicIndex=0
+ColorChooser.swatchesRecentText=Recent:
+ColorChooser.hsbNameText=HSB
+# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
+# constant, and an index into the text to render the mnemonic as. The
+# mnemonic is xxxMnemonic and the index of the character to underline is
+# xxxDisplayedMnemonicIndex.
+ColorChooser.hsbMnemonic=72
+ColorChooser.hsbDisplayedMnemonicIndex=0
+ColorChooser.hsbHueText=H
+ColorChooser.hsbSaturationText=S
+ColorChooser.hsbBrightnessText=B
+ColorChooser.hsbRedText=R
+ColorChooser.hsbGreenText=G
+ColorChooser.hsbBlueText=B
+ColorChooser.rgbNameText=RGB
+ColorChooser.rgbMnemonic=71
+ColorChooser.rgbDisplayedMnemonicIndex=1
+ColorChooser.rgbRedText=Red
+ColorChooser.rgbRedMnemonic=68
+ColorChooser.rgbGreenText=Green
+ColorChooser.rgbGreenMnemonic=78
+ColorChooser.rgbBlueText=Blue
+ColorChooser.rgbBlueMnemonic=66
+
+############ OPTION PANE STRINGS #############
+# Mnemonic keys correspond to KeyEvent.VK_XXX constant
+# We only define mnemonics for YES/NO, but for completeness you can
+# define mnemonics for any of the buttons.
+OptionPane.yesButtonText=Yes
+OptionPane.yesButtonMnemonic=89
+OptionPane.noButtonText=No
+OptionPane.noButtonMnemonic=78
+OptionPane.okButtonText=OK
+OptionPane.okButtonMnemonic=0
+OptionPane.cancelButtonText=Cancel
+OptionPane.cancelButtonMnemonic=0
+OptionPane.titleText=Select an Option
+# Title for the dialog for the showInputDialog methods. Only used if
+# the developer uses one of the variants that doesn't take a title.
+OptionPane.inputDialogTitle=Input
+# Title for the dialog for the showMessageDialog methods. Only used if
+# the developer uses one of the variants that doesn't take a title.
+OptionPane.messageDialogTitle=Message
+
+############ Printing Dialog Strings ############
+PrintingDialog.titleProgressText=Printing
+PrintingDialog.titleAbortingText=Printing (Aborting)
+
+PrintingDialog.contentInitialText=Printing in progress...
+
+# The following string will be formatted by a MessageFormat
+# and {0} will be replaced by page number being printed
+PrintingDialog.contentProgressText=Printed page {0}...
+
+PrintingDialog.contentAbortingText=Printing aborting...
+
+PrintingDialog.abortButtonText=Abort
+PrintingDialog.abortButtonMnemonic=65
+PrintingDialog.abortButtonDisplayedMnemonicIndex=0
+PrintingDialog.abortButtonToolTipText=Abort Printing
+
+############ Internal Frame Strings ############
+InternalFrame.iconButtonToolTip=Minimize
+InternalFrame.maxButtonToolTip=Maximize
+InternalFrame.restoreButtonToolTip=Restore
+InternalFrame.closeButtonToolTip=Close
+
+############ Internal Frame Title Pane Strings ############
+InternalFrameTitlePane.restoreButtonText=Restore
+InternalFrameTitlePane.moveButtonText=Move
+InternalFrameTitlePane.sizeButtonText=Size
+InternalFrameTitlePane.minimizeButtonText=Minimize
+InternalFrameTitlePane.maximizeButtonText=Maximize
+InternalFrameTitlePane.closeButtonText=Close
+
+############ Text strings #############
+# Used for html forms
+FormView.submitButtonText=Submit Query
+FormView.resetButtonText=Reset
+FormView.browseFileButtonText=Browse...
+
+############ Abstract Document Strings ############
+AbstractDocument.styleChangeText=style change
+AbstractDocument.additionText=addition
+AbstractDocument.deletionText=deletion
+AbstractDocument.undoText=Undo
+AbstractDocument.redoText=Redo
+
+############ Abstract Button Strings ############
+AbstractButton.clickText=click
+
+############ Abstract Undoable Edit Strings ############
+AbstractUndoableEdit.undoText=Undo
+AbstractUndoableEdit.redoText=Redo
+
+############ Combo Box Strings ############
+ComboBox.togglePopupText=togglePopup
+
+############ Progress Monitor Strings ############
+ProgressMonitor.progressText=Progress...
+
+############ Split Pane Strings ############
+SplitPane.leftButtonText=left button
+SplitPane.rightButtonText=right button
+# Used for Isindex
+IsindexView.prompt=This is a searchable index.  Enter search keywords:
+
+############ InternalFrameTitlePane Strings ############
+InternalFrameTitlePane.iconifyButtonAccessibleName=Iconify
+InternalFrameTitlePane.maximizeButtonAccessibleName=Maximize
+InternalFrameTitlePane.closeButtonAccessibleName=Close
diff --git a/jdk/src/macosx/classes/com/apple/resources/MacOSXResourceBundle.java b/jdk/src/macosx/classes/com/apple/resources/MacOSXResourceBundle.java
new file mode 100644
index 0000000..eaf93c2
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/resources/MacOSXResourceBundle.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.resources;
+
+import java.security.*;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+import java.io.*;
+
+public class MacOSXResourceBundle extends PropertyResourceBundle {
+    MacOSXResourceBundle(InputStream stream) throws IOException {
+        super(stream);
+    }
+
+    void setItsParent(ResourceBundle rb) {
+        setParent(rb);
+    }
+
+    public static ResourceBundle getMacResourceBundle(String baseJavaBundle) throws Exception {
+        return getMacResourceBundle(baseJavaBundle, null);
+    }
+
+    public static ResourceBundle getMacResourceBundle(String baseJavaBundle, String filename) throws Exception {
+        LoadNativeBundleAction lnba = new LoadNativeBundleAction(baseJavaBundle, filename);
+        return (ResourceBundle)java.security.AccessController.doPrivileged(lnba);
+    }
+}
+
+class LoadNativeBundleAction implements PrivilegedExceptionAction {
+    String mBaseJavaBundle;
+    String mFilenameOverride;
+
+    LoadNativeBundleAction(String baseJavaBundle, String filenameOverride) {
+        mBaseJavaBundle = baseJavaBundle;
+        mFilenameOverride = filenameOverride;
+    }
+
+    public Object run() {
+        java.util.ResourceBundle returnValue = null;
+        MacOSXResourceBundle macOSrb = null;
+
+        // Load the Mac OS X resources.
+        // Use a base filename if we were given one. Otherwise, we will look for the last piece of the bundle path
+        // with '.properties' appended. Either way, the native method will take care of the extension.
+        String filename = mFilenameOverride;
+
+        if (filename == null) {
+            filename = mBaseJavaBundle.substring(mBaseJavaBundle.lastIndexOf('.') + 1);
+        }
+
+        File propsFile = null;
+        String propertyFileName = getPathToBundleFile(filename);
+        InputStream stream = null;
+
+        try {
+            propsFile = new File(propertyFileName);
+            stream = new FileInputStream(propsFile);
+            stream = new java.io.BufferedInputStream(stream);
+            macOSrb = new MacOSXResourceBundle(stream);
+        } catch (Exception e) {
+            //e.printStackTrace();
+            //System.out.println("Failed to create resources from application bundle.  Using Java-based resources.");
+        } finally {
+            try {
+                if (stream != null) stream.close();
+                stream = null;
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+        returnValue = ResourceBundle.getBundle(mBaseJavaBundle);
+
+        // If we have a platform-specific bundle, make it the parent of the generic bundle, so failures propagate up to the parent.
+        if (returnValue != null) {
+            if (macOSrb != null) {
+                macOSrb.setItsParent(returnValue);
+                returnValue = macOSrb;
+            }
+        }
+
+        return returnValue;
+    }
+
+    private static native String getPathToBundleFile(String filename);
+}
+
diff --git a/jdk/src/macosx/classes/java/net/DefaultInterface.java b/jdk/src/macosx/classes/java/net/DefaultInterface.java
new file mode 100644
index 0000000..b393516
--- /dev/null
+++ b/jdk/src/macosx/classes/java/net/DefaultInterface.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.net;
+
+/**
+ * Choose a network inteface to be the default for
+ * outgoing IPv6 traffic that does not specify a scope_id (and which needs one).
+ * We choose the first interface that is up and is (in order of preference):
+ * 1. neither loopback nor point to point
+ * 2. point to point
+ * 3. loopback
+ * 4. none.
+ * Platforms that do not require a default interface implement a dummy
+ * that returns null.
+ */
+
+import java.util.Enumeration;
+import java.io.IOException;
+
+class DefaultInterface {
+
+    private final static NetworkInterface defaultInterface =
+        chooseDefaultInterface();
+
+    static NetworkInterface getDefault() {
+        return defaultInterface;
+    }
+
+    /**
+     * Choose a default interface. This method returns an interface that is
+     * both "up" and supports multicast. This method choses an interface in
+     * order of preference:
+     * 1. neither loopback nor point to point
+     * 2. point to point
+     * 3. loopback
+     *
+     * @return  the chosen interface or {@code null} if there isn't a suitable
+     *          default
+     */
+    private static NetworkInterface chooseDefaultInterface() {
+        Enumeration<NetworkInterface> nifs;
+
+        try {
+           nifs = NetworkInterface.getNetworkInterfaces();
+        } catch (IOException ignore) {
+            // unable to enumate network interfaces
+            return null;
+        }
+
+        NetworkInterface ppp = null;
+        NetworkInterface loopback = null;
+
+        while (nifs.hasMoreElements()) {
+            NetworkInterface ni = nifs.nextElement();
+            try {
+                if (ni.isUp() && ni.supportsMulticast()) {
+                    boolean isLoopback = ni.isLoopback();
+                    boolean isPPP = ni.isPointToPoint();
+                    if (!isLoopback && !isPPP) {
+                        // found an interface that is not the loopback or a
+                        // point-to-point interface
+                        return ni;
+                    }
+                    if (ppp == null && isPPP)
+                        ppp = ni;
+                    if (loopback == null && isLoopback)
+                        loopback = ni;
+                }
+            } catch (IOException skip) { }
+        }
+
+        return (ppp != null) ? ppp : loopback;
+    }
+}
diff --git a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java
new file mode 100644
index 0000000..8f3f461
--- /dev/null
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.prefs;
+
+class MacOSXPreferences extends AbstractPreferences {
+    // fixme need security checks?
+
+    // CF preferences file name for Java nodes with short names
+    // This value is also in MacOSXPreferencesFile.c
+    private static final String defaultAppName = "com.apple.java.util.prefs";
+
+    // true if this node is a child of userRoot or is userRoot
+    private boolean isUser;
+
+    // true if this node is userRoot or systemRoot
+    private boolean isRoot;
+
+    // CF's storage location for this node and its keys
+    private MacOSXPreferencesFile file;
+
+    // absolutePath() + "/"
+    private String path;
+
+    // User root and system root nodes
+    private static MacOSXPreferences userRoot = null;
+    private static MacOSXPreferences systemRoot = null;
+
+
+    // Returns user root node, creating it if necessary.
+    // Called by MacOSXPreferencesFactory
+    static synchronized Preferences getUserRoot() {
+        if (userRoot == null) {
+            userRoot = new MacOSXPreferences(true);
+        }
+        return userRoot;
+    }
+
+
+    // Returns system root node, creating it if necessary.
+    // Called by MacOSXPreferencesFactory
+    static synchronized Preferences getSystemRoot() {
+        if (systemRoot == null) {
+            systemRoot = new MacOSXPreferences(false);
+        }
+        return systemRoot;
+    }
+
+
+    // Create a new root node. Called by getUserRoot() and getSystemRoot()
+    // Synchronization is provided by the caller.
+    private MacOSXPreferences(boolean newIsUser)
+    {
+        super(null, "");
+        isUser = newIsUser;
+        isRoot = true;
+
+        initFields();
+    }
+
+
+    // Create a new non-root node with the given parent.
+    // Called by childSpi().
+    private MacOSXPreferences(MacOSXPreferences parent, String name)
+    {
+        super(parent, name);
+        isUser = isUserNode();
+        isRoot = false;
+
+        initFields();
+    }
+
+
+    private void initFields()
+    {
+        path = isRoot ? absolutePath() : absolutePath() + "/";
+        file = cfFileForNode(isUser);
+        newNode = file.addNode(path);
+    }
+
+
+    // Create and return the MacOSXPreferencesFile for this node.
+    // Does not write anything to the file.
+    private MacOSXPreferencesFile cfFileForNode(boolean isUser)
+    {
+        String name = path;
+        // /one/two/three/four/five/
+        // The fourth slash is the end of the first three components.
+        // If there is no fourth slash, the name has fewer than 3 components
+        int componentCount = 0;
+        int pos = -1;
+        for (int i = 0; i < 4; i++) {
+            pos = name.indexOf('/', pos+1);
+            if (pos == -1) break;
+        }
+
+        if (pos == -1) {
+            // fewer than three components - use default name
+            name = defaultAppName;
+        } else {
+            // truncate to three components, no leading or trailing '/'
+            // replace '/' with '.' to make filesystem happy
+            // convert to all lowercase to survive on HFS+
+            name = name.substring(1, pos);
+            name = name.replace('/', '.');
+            name = name.toLowerCase();
+        }
+
+        return MacOSXPreferencesFile.getFile(name, isUser);
+    }
+
+
+    // AbstractPreferences implementation
+    protected void putSpi(String key, String value)
+    {
+        file.addKeyToNode(path, key, value);
+    }
+
+    // AbstractPreferences implementation
+    protected String getSpi(String key)
+    {
+        return file.getKeyFromNode(path, key);
+    }
+
+    // AbstractPreferences implementation
+    protected void removeSpi(String key)
+    {
+        file.removeKeyFromNode(path, key);
+    }
+
+
+    // AbstractPreferences implementation
+    protected void removeNodeSpi()
+        throws BackingStoreException
+    {
+        // Disallow flush or sync between these two operations
+        // (they may be manipulating two different files)
+        synchronized(MacOSXPreferencesFile.class) {
+            ((MacOSXPreferences)parent()).removeChild(name());
+            file.removeNode(path);
+        }
+    }
+
+    // Erase knowledge about a child of this node. Called by removeNodeSpi.
+    private void removeChild(String child)
+    {
+        file.removeChildFromNode(path, child);
+    }
+
+
+    // AbstractPreferences implementation
+    protected String[] childrenNamesSpi()
+        throws BackingStoreException
+    {
+        String[] result = file.getChildrenForNode(path);
+        if (result == null) throw new BackingStoreException("Couldn't get list of children for node '" + path + "'");
+        return result;
+    }
+
+    // AbstractPreferences implementation
+    protected String[] keysSpi()
+        throws BackingStoreException
+    {
+        String[] result = file.getKeysForNode(path);
+        if (result == null) throw new BackingStoreException("Couldn't get list of keys for node '" + path + "'");
+        return result;
+    }
+
+    // AbstractPreferences implementation
+    protected AbstractPreferences childSpi(String name)
+    {
+        // Add to parent's child list here and disallow sync
+        // because parent and child might be in different files.
+        synchronized(MacOSXPreferencesFile.class) {
+            file.addChildToNode(path, name);
+            return new MacOSXPreferences(this, name);
+        }
+    }
+
+    // AbstractPreferences override
+    public void flush()
+        throws BackingStoreException
+    {
+        // Flush should *not* check for removal, unlike sync, but should
+        // prevent simultaneous removal.
+        synchronized(lock) {
+            // fixme! overkill
+            if (!MacOSXPreferencesFile.flushWorld()) {
+                throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+            }
+        }
+    }
+
+    // AbstractPreferences implementation
+    protected void flushSpi()
+        throws BackingStoreException
+    {
+        // nothing here - overridden flush() doesn't call this
+    }
+
+    // AbstractPreferences override
+    public void sync()
+        throws BackingStoreException
+    {
+        synchronized(lock) {
+            if (isRemoved())
+                throw new IllegalStateException("Node has been removed");
+            // fixme! overkill
+            if (!MacOSXPreferencesFile.syncWorld()) {
+                throw new BackingStoreException("Synchronization failed for node '" + path + "'");
+            }
+        }
+    }
+
+    // AbstractPreferences implementation
+    protected void syncSpi()
+        throws BackingStoreException
+    {
+        // nothing here - overridden sync() doesn't call this
+    }
+}
+
diff --git a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java
new file mode 100644
index 0000000..05ef30c
--- /dev/null
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.prefs;
+
+class MacOSXPreferencesFactory implements PreferencesFactory {
+    public Preferences userRoot() {
+        return MacOSXPreferences.getUserRoot();
+    }
+
+    public Preferences systemRoot() {
+        return MacOSXPreferences.getSystemRoot();
+    }
+}
diff --git a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java
new file mode 100644
index 0000000..a5d6293
--- /dev/null
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java
@@ -0,0 +1,425 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.prefs;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.lang.ref.WeakReference;
+
+
+/*
+  MacOSXPreferencesFile synchronization:
+
+  Everything is synchronized on MacOSXPreferencesFile.class. This prevents:
+  * simultaneous updates to cachedFiles or changedFiles
+  * simultaneous creation of two objects for the same name+user+host triplet
+  * simultaneous modifications to the same file
+  * modifications during syncWorld/flushWorld
+  * (in MacOSXPreferences.removeNodeSpi()) modification or sync during
+    multi-step node removal process
+  ... among other things.
+*/
+/*
+  Timers. There are two timers that control synchronization of prefs data to
+  and from disk.
+
+  * Sync timer periodically calls syncWorld() to force external disk changes
+      (e.g. from another VM) into the memory cache. The sync timer runs even
+      if there are no outstanding local changes. The sync timer syncs all live
+      MacOSXPreferencesFile objects (the cachedFiles list).
+    The sync timer period is controlled by the java.util.prefs.syncInterval
+      property (same as FileSystemPreferences). By default there is *no*
+      sync timer (unlike FileSystemPreferences); it is only enabled if the
+      syncInterval property is set. The minimum interval is 5 seconds.
+
+  * Flush timer calls flushWorld() to force local changes to disk.
+      The flush timer is scheduled to fire some time after each pref change,
+      unless it's already scheduled to fire before that. syncWorld and
+      flushWorld will cancel any outstanding flush timer as unnecessary.
+      The flush timer flushes all changed files (the changedFiles list).
+    The time between pref write and flush timer call is controlled by the
+      java.util.prefs.flushDelay property (unlike FileSystemPreferences).
+      The default is 60 seconds and the minimum is 5 seconds.
+
+  The flush timer's behavior is required by the Java Preferences spec
+  ("changes will eventually propagate to the persistent backing store with
+  an implementation-dependent delay"). The sync timer is not required by
+  the spec (multiple VMs are only required to not corrupt the prefs), but
+  the periodic sync is implemented by FileSystemPreferences and may be
+  useful to some programs. The sync timer is disabled by default because
+  it's expensive and is usually not necessary.
+*/
+
+class MacOSXPreferencesFile {
+
+    static {
+        java.security.AccessController.doPrivileged(new sun.security.action.LoadLibraryAction("osx"));
+    }
+
+    private class FlushTask extends TimerTask {
+        public void run() {
+            MacOSXPreferencesFile.flushWorld();
+        }
+    }
+
+    private class SyncTask extends TimerTask {
+        public void run() {
+            MacOSXPreferencesFile.syncWorld();
+        }
+    }
+
+    // Maps string -> weak reference to MacOSXPreferencesFile
+    private static HashMap cachedFiles = null;
+    // Files that may have unflushed changes
+    private static HashSet changedFiles = null;
+
+
+    // Timer and pending sync and flush tasks (which are both scheduled
+    // on the same timer)
+    private static Timer timer = null;
+    private static FlushTask flushTimerTask = null;
+    private static long flushDelay = -1; // in seconds (min 5, default 60)
+    private static long syncInterval = -1; // (min 5, default negative == off)
+
+    private String appName;
+    private long user;
+    private long host;
+
+    String name() { return appName; }
+    long user() { return user; }
+    long host() { return host; }
+
+    // private contructor - use factory method getFile() instead
+    private MacOSXPreferencesFile(String newName, long newUser, long newHost)
+    {
+        appName = newName;
+        user = newUser;
+        host = newHost;
+    }
+
+    // Factory method
+    // Always returns the same object for the given name+user+host
+    static synchronized MacOSXPreferencesFile
+        getFile(String newName, boolean isUser)
+    {
+        MacOSXPreferencesFile result = null;
+
+        if (cachedFiles == null) cachedFiles = new HashMap();
+
+        String hashkey =
+            newName + String.valueOf(isUser);
+        WeakReference hashvalue = (WeakReference)cachedFiles.get(hashkey);
+        if (hashvalue != null) {
+            result = (MacOSXPreferencesFile)hashvalue.get();
+        }
+        if (result == null) {
+            // Java user node == CF current user, any host
+            // Java system node == CF any user, current host
+            result = new MacOSXPreferencesFile(newName,
+                                         isUser ? cfCurrentUser : cfAnyUser,
+                                         isUser ? cfAnyHost : cfCurrentHost);
+            cachedFiles.put(hashkey, new WeakReference(result));
+        }
+
+        // Don't schedule this file for flushing until some nodes or
+        // keys are added to it.
+
+        // Do set up the sync timer if requested; sync timer affects reads
+        // as well as writes.
+        initSyncTimerIfNeeded();
+
+        return result;
+    }
+
+
+    // Write all prefs changes to disk and clear all cached prefs values
+    // (so the next read will read from disk).
+    static synchronized boolean syncWorld()
+    {
+        boolean ok = true;
+
+        if (cachedFiles != null  &&  !cachedFiles.isEmpty()) {
+            Iterator iter = cachedFiles.values().iterator();
+            while (iter.hasNext()) {
+                WeakReference ref = (WeakReference)iter.next();
+                MacOSXPreferencesFile f = (MacOSXPreferencesFile)ref.get();
+                if (f != null) {
+                    if (!f.synchronize()) ok = false;
+                } else {
+                    iter.remove();
+                }
+            }
+        }
+
+        // Kill any pending flush
+        if (flushTimerTask != null) {
+            flushTimerTask.cancel();
+            flushTimerTask = null;
+        }
+
+        // Clear changed file list. The changed files were guaranteed to
+        // have been in the cached file list (because there was a strong
+        // reference from changedFiles.
+        if (changedFiles != null) changedFiles.clear();
+
+        return ok;
+    }
+
+
+    // Write all prefs changes to disk, but do not clear all cached prefs
+    // values. Also kills any scheduled flush task.
+    // There's no CFPreferencesFlush() (<rdar://problem/3049129>), so lots of cached prefs
+    // are cleared anyway.
+    static synchronized boolean flushWorld()
+    {
+        boolean ok = true;
+
+        if (changedFiles != null  &&  !changedFiles.isEmpty()) {
+            Iterator iter = changedFiles.iterator();
+            while (iter.hasNext()) {
+                MacOSXPreferencesFile f = (MacOSXPreferencesFile)iter.next();
+                if (!f.synchronize()) ok = false;
+            }
+
+            changedFiles.clear();
+        }
+
+        if (flushTimerTask != null) {
+            flushTimerTask.cancel();
+            flushTimerTask = null;
+        }
+
+        return ok;
+    }
+
+    // Mark this prefs file as changed. The changes will be flushed in
+    // at most flushDelay() seconds.
+    // Must be called when synchronized on MacOSXPreferencesFile.class
+    private void markChanged()
+    {
+        // Add this file to the changed file list
+        if (changedFiles == null) changedFiles = new HashSet();
+        changedFiles.add(this);
+
+        // Schedule a new flush and a shutdown hook, if necessary
+        if (flushTimerTask == null) {
+            flushTimerTask = new FlushTask();
+            timer().schedule(flushTimerTask, flushDelay() * 1000);
+        }
+    }
+
+    // Return the flush delay, initializing from a property if necessary.
+    private static synchronized long flushDelay()
+    {
+        if (flushDelay == -1) {
+            try {
+                // flush delay >= 5, default 60
+                flushDelay = Math.max(5, Integer.parseInt(System.getProperty("java.util.prefs.flushDelay", "60")));
+            } catch (NumberFormatException e) {
+                flushDelay = 60;
+            }
+        }
+        return flushDelay;
+    }
+
+    // Initialize and run the sync timer, if the sync timer property is set
+    // and the sync timer hasn't already been started.
+    private static synchronized void initSyncTimerIfNeeded()
+    {
+        // syncInterval: -1 is uninitialized, other negative is off,
+        // positive is seconds between syncs (min 5).
+
+        if (syncInterval == -1) {
+            try {
+                syncInterval = Integer.parseInt(System.getProperty("java.util.prefs.syncInterval", "-2"));
+                if (syncInterval >= 0) {
+                    // minimum of 5 seconds
+                    syncInterval = Math.max(5, syncInterval);
+                } else {
+                    syncInterval = -2; // default off
+                }
+            } catch (NumberFormatException e) {
+                syncInterval = -2; // bad property value - default off
+            }
+
+            if (syncInterval > 0) {
+                timer().schedule(new TimerTask() {
+                        public void run() { MacOSXPreferencesFile.syncWorld();}
+                    }, syncInterval * 1000, syncInterval * 1000);
+            } else {
+                // syncInterval property not set. No sync timer ever.
+            }
+        }
+    }
+
+    // Return the timer used for flush and sync, creating it if necessary.
+    private static synchronized Timer timer()
+    {
+        if (timer == null) {
+            timer = new Timer(true); // daemon
+            Thread flushThread = new Thread() {
+                public void run() {
+                    flushWorld();
+                }
+            };
+            /* Set context class loader to null in order to avoid
+             * keeping a strong reference to an application classloader.
+             */
+            flushThread.setContextClassLoader(null);
+            Runtime.getRuntime().addShutdownHook(flushThread);
+        }
+        return timer;
+    }
+
+
+    // Node manipulation
+    boolean addNode(String path)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            markChanged();
+            return addNode(path, appName, user, host);
+        }
+    }
+
+    void removeNode(String path)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            markChanged();
+            removeNode(path, appName, user, host);
+        }
+    }
+
+    void addChildToNode(String path, String child)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            markChanged();
+            addChildToNode(path, child+"/", appName, user, host);
+        }
+    }
+
+    void removeChildFromNode(String path, String child)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            markChanged();
+            removeChildFromNode(path, child+"/", appName, user, host);
+        }
+    }
+
+
+    // Key manipulation
+    void addKeyToNode(String path, String key, String value)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            markChanged();
+            addKeyToNode(path, key, value, appName, user, host);
+        }
+    }
+
+    void removeKeyFromNode(String path, String key)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            markChanged();
+            removeKeyFromNode(path, key, appName, user, host);
+        }
+    }
+
+    String getKeyFromNode(String path, String key)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            return getKeyFromNode(path, key, appName, user, host);
+        }
+    }
+
+
+    // Enumerators
+    String[] getChildrenForNode(String path)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            return getChildrenForNode(path, appName, user, host);
+        }
+    }
+
+    String[] getKeysForNode(String path)
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            return getKeysForNode(path, appName, user, host);
+        }
+    }
+
+
+    // Synchronization
+    boolean synchronize()
+    {
+        synchronized(MacOSXPreferencesFile.class) {
+            return synchronize(appName, user, host);
+        }
+    }
+
+
+    // CF functions
+    // Must be called when synchronized on MacOSXPreferencesFile.class
+    private static final native boolean
+        addNode(String path, String name, long user, long host);
+    private static final native void
+        removeNode(String path, String name, long user, long host);
+    private static final native void
+        addChildToNode(String path, String child,
+                       String name, long user, long host);
+    private static final native void
+        removeChildFromNode(String path, String child,
+                            String name, long user, long host);
+    private static final native void
+        addKeyToNode(String path, String key, String value,
+                     String name, long user, long host);
+    private static final native void
+        removeKeyFromNode(String path, String key,
+                          String name, long user, long host);
+    private static final native String
+        getKeyFromNode(String path, String key,
+                       String name, long user, long host);
+    private static final native String[]
+        getChildrenForNode(String path, String name, long user, long host);
+    private static final native String[]
+        getKeysForNode(String path, String name, long user, long host);
+    private static final native boolean
+        synchronize(String name, long user, long host);
+
+    // CFPreferences host and user values (CFStringRefs)
+    private static long cfCurrentUser = currentUser();
+    private static long cfAnyUser = anyUser();
+    private static long cfCurrentHost = currentHost();
+    private static long cfAnyHost = anyHost();
+
+    // CFPreferences constant accessors
+    private static final native long currentUser();
+    private static final native long anyUser();
+    private static final native long currentHost();
+    private static final native long anyHost();
+}
+
diff --git a/jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java b/jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java
new file mode 100644
index 0000000..01409a5
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.awt;
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.image.*;
+
+import sun.java2d.SurfaceData;
+import sun.java2d.opengl.CGLLayer;
+import sun.lwawt.macosx.CPlatformView;
+
+public class CGraphicsConfig extends GraphicsConfiguration {
+    private final CGraphicsDevice device;
+    private ColorModel colorModel;
+
+    public CGraphicsConfig(CGraphicsDevice device) {
+        this.device = device;
+    }
+
+    @Override
+    public BufferedImage createCompatibleImage(int width, int height) {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    private static native Rectangle2D nativeGetBounds(int screen);
+
+    @Override
+    public Rectangle getBounds() {
+        final Rectangle2D nativeBounds = nativeGetBounds(device.getCoreGraphicsScreen());
+        return nativeBounds.getBounds(); // does integer rounding
+    }
+
+    @Override
+    public ColorModel getColorModel() {
+        if (colorModel == null) {
+            colorModel = getColorModel(Transparency.OPAQUE);
+        }
+        return colorModel;
+    }
+
+    @Override
+    public ColorModel getColorModel(int transparency) {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    @Override
+    public AffineTransform getDefaultTransform() {
+        return new AffineTransform();
+    }
+
+    @Override
+    public CGraphicsDevice getDevice() {
+        return device;
+    }
+
+    @Override
+    public AffineTransform getNormalizingTransform() {
+        double xscale = device.getXResolution() / 72.0;
+        double yscale = device.getYResolution() / 72.0;
+        return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
+    }
+
+
+    /**
+     * The following methods are invoked from CToolkit.java and
+     * LWWindowPeer.java rather than having the native
+     * implementations hardcoded in those classes.  This way the appropriate
+     * actions are taken based on the peer's GraphicsConfig, whether it is
+     * an CGLGraphicsConfig or something else.
+     */
+
+    /**
+     * Creates a new SurfaceData that will be associated with the given
+     * LWWindowPeer.
+     */
+    public SurfaceData createSurfaceData(CPlatformView pView) {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    /**
+     * Creates a new SurfaceData that will be associated with the given
+     * CGLLayer.
+     */
+    public SurfaceData createSurfaceData(CGLLayer layer) {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    /**
+     * Creates a new hidden-acceleration image of the given width and height
+     * that is associated with the target Component.
+     */
+    public Image createAcceleratedImage(Component target,
+                                        int width, int height)
+    {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    /**
+     * The following methods correspond to the multibuffering methods in
+     * LWWindowPeer.java...
+     */
+
+    /**
+     * Attempts to create a native backbuffer for the given peer.  If
+     * the requested configuration is not natively supported, an AWTException
+     * is thrown.  Otherwise, if the backbuffer creation is successful, a
+     * handle to the native backbuffer is returned.
+     */
+    public long createBackBuffer(CPlatformView pView,
+                                 int numBuffers, BufferCapabilities caps)
+        throws AWTException
+    {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    public void destroyBackBuffer(long backBuffer)
+        throws AWTException
+    {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    /**
+     * Creates a VolatileImage that essentially wraps the target Component's
+     * backbuffer, using the provided backbuffer handle.
+     */
+    public VolatileImage createBackBufferImage(Component target,
+                                               long backBuffer)
+    {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    /**
+     * Performs the native flip operation for the given target Component.
+     */
+    public void flip(CPlatformView delegate,
+                     Component target, VolatileImage xBackBuffer,
+                     int x1, int y1, int x2, int y2,
+                     BufferCapabilities.FlipContents flipAction)
+    {
+        throw new UnsupportedOperationException("not implemented");
+    }
+
+    @Override
+    public boolean isTranslucencyCapable() {
+        //we know for sure we have capable config :)
+        return true;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java b/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java
new file mode 100644
index 0000000..1fda340
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.awt;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.Window;
+import java.awt.AWTPermission;
+
+import sun.java2d.opengl.CGLGraphicsConfig;
+
+import sun.awt.FullScreenCapable;
+
+public class CGraphicsDevice extends GraphicsDevice {
+
+    // CoreGraphics display ID
+    private final int displayID;
+
+    // Array of all GraphicsConfig instances for this device
+    private final CGraphicsConfig[] configs;
+
+    // Default config (temporarily hard coded)
+    private final int DEFAULT_CONFIG = 0;
+
+    private static AWTPermission fullScreenExclusivePermission;
+
+    public CGraphicsDevice(int displayID) {
+        this.displayID = displayID;
+        configs = new CGraphicsConfig[] {
+            CGLGraphicsConfig.getConfig(this, 0)
+        };
+    }
+
+    /**
+     * @return CoreGraphics display id.
+     */
+    public int getCoreGraphicsScreen() {
+        return displayID;
+    }
+
+    /**
+     * Return a list of all configurations.
+     */
+    @Override
+    public GraphicsConfiguration[] getConfigurations() {
+        return configs;
+    }
+
+    /**
+     * Return the default configuration.
+     */
+    @Override
+    public GraphicsConfiguration getDefaultConfiguration() {
+        return configs[DEFAULT_CONFIG];
+    }
+
+    /**
+     * Return a human-readable screen description.
+     */
+    @Override
+    public String getIDstring() {
+        return "Display " + this.displayID;
+    }
+
+    /**
+     * Returns the type of the graphics device.
+     * @see #TYPE_RASTER_SCREEN
+     * @see #TYPE_PRINTER
+     * @see #TYPE_IMAGE_BUFFER
+     */
+    @Override
+    public int getType() {
+        return TYPE_RASTER_SCREEN;
+    }
+
+    public double getXResolution() {
+        return nativeGetXResolution(displayID);
+    }
+
+    public double getYResolution() {
+        return nativeGetYResolution(displayID);
+    }
+
+    public int getScreenResolution() {
+        // TODO: report non-72 value when HiDPI is turned on
+        return 72;
+    }
+
+    private static native double nativeGetXResolution(int displayID);
+    private static native double nativeGetYResolution(int displayID);
+
+    /**
+     * Enters full-screen mode, or returns to windowed mode.
+     */
+    @Override
+    public synchronized void setFullScreenWindow(Window w) {
+        Window old = getFullScreenWindow();
+        if (w == old) {
+            return;
+        }
+
+        boolean fsSupported = isFullScreenSupported();
+        if (fsSupported && old != null) {
+            // enter windowed mode (and restore original display mode)
+            exitFullScreenExclusive(old);
+
+            // TODO: restore display mode
+        }
+
+        super.setFullScreenWindow(w);
+
+        if (fsSupported && w != null) {
+            // TODO: save current display mode
+
+            // enter fullscreen mode
+            enterFullScreenExclusive(w);
+        }
+    }
+
+    /**
+     * Returns true if this GraphicsDevice supports
+     * full-screen exclusive mode and false otherwise.
+     */
+    @Override
+    public boolean isFullScreenSupported() {
+        return isFSExclusiveModeAllowed();
+    }
+
+    private static boolean isFSExclusiveModeAllowed() {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            if (fullScreenExclusivePermission == null) {
+                fullScreenExclusivePermission =
+                    new AWTPermission("fullScreenExclusive");
+            }
+            try {
+                security.checkPermission(fullScreenExclusivePermission);
+            } catch (SecurityException e) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private static void enterFullScreenExclusive(Window w) {
+        FullScreenCapable peer = (FullScreenCapable)w.getPeer();
+        if (peer != null) {
+            peer.enterFullScreenMode();
+        }
+    }
+
+    private static void exitFullScreenExclusive(Window w) {
+        FullScreenCapable peer = (FullScreenCapable)w.getPeer();
+        if (peer != null) {
+            peer.exitFullScreenMode();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java b/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java
new file mode 100644
index 0000000..b8c244b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.awt;
+
+import java.awt.*;
+import java.awt.print.*;
+import java.util.*;
+
+import sun.java2d.*;
+
+/**
+ * This is an implementation of a GraphicsEnvironment object for the default local GraphicsEnvironment used by the Java
+ * Runtime Environment for Mac OS X GUI environments.
+ *
+ * @see GraphicsDevice
+ * @see GraphicsConfiguration
+ */
+public class CGraphicsEnvironment extends SunGraphicsEnvironment {
+    // Global initialization of the Cocoa runtime.
+    private static native void initCocoa();
+
+    /**
+     * Fetch an array of all valid CoreGraphics display identifiers.
+     */
+    private static native int[] getDisplayIDs();
+
+    /**
+     * Fetch the CoreGraphics display ID for the 'main' display.
+     */
+    private static native int getMainDisplayID();
+
+    /**
+     * Noop function that just acts as an entry point for someone to force a static initialization of this class.
+     */
+    public static void init() { }
+
+    static {
+        java.security.AccessController.doPrivileged(new sun.security.action.LoadLibraryAction("awt"));
+        java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() {
+            public Object run() {
+                if (isHeadless()) return null;
+                initCocoa();
+                return null;
+            }
+        });
+
+        // Install the correct surface manager factory.
+        SurfaceManagerFactory.setInstance(new MacosxSurfaceManagerFactory());
+    }
+
+    /**
+     * Register the instance with CGDisplayRegisterReconfigurationCallback()
+     * The registration uses a weak global reference -- if our instance is garbage collected, the reference will be dropped.
+     *
+     * @return Return the registration context (a pointer).
+     */
+    private native long registerDisplayReconfiguration();
+
+    /**
+     * Remove the instance's registration with CGDisplayRemoveReconfigurationCallback()
+     */
+    private native void deregisterDisplayReconfiguration(long context);
+
+    /** Available CoreGraphics displays. */
+    private final Map<Integer, CGraphicsDevice> devices = new HashMap<Integer, CGraphicsDevice>();
+
+    /** Reference to the display reconfiguration callback context. */
+    private final long displayReconfigContext;
+
+    /**
+     * Construct a new instance.
+     */
+    public CGraphicsEnvironment() {
+        if (isHeadless()) {
+            displayReconfigContext = 0L;
+            return;
+        }
+
+        /* Populate the device table */
+        initDevices();
+
+        /* Register our display reconfiguration listener */
+        displayReconfigContext = registerDisplayReconfiguration();
+        if (displayReconfigContext == 0L) {
+            throw new RuntimeException("Could not register CoreGraphics display reconfiguration callback");
+        }
+    }
+
+    /**
+     * Called by the CoreGraphics Display Reconfiguration Callback.
+     *
+     * @param displayId
+     *            CoreGraphics displayId
+     */
+    void _displayReconfiguration(long displayId) {
+        displayChanged();
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            super.finalize();
+        } finally {
+            deregisterDisplayReconfiguration(displayReconfigContext);
+        }
+    }
+
+    /**
+     * (Re)create all CGraphicsDevices
+     *
+     * @return
+     */
+    private synchronized void initDevices() {
+        devices.clear();
+
+        int mainID = getMainDisplayID();
+
+        // initialization of the graphics device may change
+        // list of displays on hybrid systems via an activation
+        // of discrete video.
+        // So, we initialize the main display first, and then
+        // retrieve actual list of displays.
+        CGraphicsDevice mainDevice = new CGraphicsDevice(mainID);
+
+        final int[] displayIDs = getDisplayIDs();
+
+        for (int displayID : displayIDs) {
+            if (displayID != mainID) {
+                devices.put(displayID, new CGraphicsDevice(displayID));
+            } else {
+                devices.put(mainID, mainDevice);
+            }
+        }
+    }
+
+    @Override
+    public synchronized GraphicsDevice getDefaultScreenDevice() throws HeadlessException {
+        final int mainDisplayID = getMainDisplayID();
+        CGraphicsDevice d = devices.get(mainDisplayID);
+        if (d == null) {
+            // we do not exepct that this may happen, the only responce
+            // is to re-initialize the list of devices
+            initDevices();
+
+            d = devices.get(mainDisplayID);
+        }
+        return d;
+    }
+
+    @Override
+    public synchronized GraphicsDevice[] getScreenDevices() throws HeadlessException {
+        return devices.values().toArray(new CGraphicsDevice[devices.values().size()]);
+    }
+
+    @Override
+    protected synchronized int getNumScreens() {
+        return devices.size();
+    }
+
+    @Override
+    protected GraphicsDevice makeScreenDevice(int screennum) {
+        throw new UnsupportedOperationException("This method is unused and should not be called in this implementation");
+    }
+
+    @Override
+    public boolean isDisplayLocal() {
+       return true;
+    }
+
+    private Font[] allFontsWithLogical;
+    static String[] sLogicalFonts = { "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput" };
+
+    @Override
+    public Font[] getAllFonts() {
+        if (allFontsWithLogical == null)
+        {
+            Font[] newFonts;
+            Font[] superFonts = super.getAllFonts();
+
+            int numLogical = sLogicalFonts.length;
+            int numOtherFonts = superFonts.length;
+
+            newFonts = new Font[numOtherFonts + numLogical];
+            System.arraycopy(superFonts,0,newFonts,numLogical,numOtherFonts);
+
+            for (int i = 0; i < numLogical; i++)
+            {
+                newFonts[i] = new Font(sLogicalFonts[i], Font.PLAIN, 1);
+            }
+            allFontsWithLogical = newFonts;
+        }
+        return java.util.Arrays.copyOf(allFontsWithLogical, allFontsWithLogical.length);
+    }
+
+}
diff --git a/jdk/src/macosx/classes/sun/awt/FullScreenCapable.java b/jdk/src/macosx/classes/sun/awt/FullScreenCapable.java
new file mode 100644
index 0000000..23e84ee
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/awt/FullScreenCapable.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.awt;
+
+/**
+ * A class implements the FullScreenCapable interface to
+ * indicate that it's capable to enter the full-screen mode.
+ */
+public interface FullScreenCapable {
+
+    /**
+     * Enters full-screen mode.
+     */
+    public void enterFullScreenMode();
+
+    /**
+     * Returns to windowed mode.
+     */
+    public void exitFullScreenMode();
+
+}
diff --git a/jdk/src/macosx/classes/sun/awt/SunToolkitSubclass.java b/jdk/src/macosx/classes/sun/awt/SunToolkitSubclass.java
new file mode 100644
index 0000000..5669b5b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/awt/SunToolkitSubclass.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.awt;
+
+// This class exists only so we can flush the PostEventQueue for the right AppContext
+// The default flushPendingEvents only flushes the thread-local context, which is wrong.
+// c.f. 3746956
+public abstract class SunToolkitSubclass extends SunToolkit {
+    public static void flushPendingEvents(AppContext appContext) {
+        flushLock.lock();
+        PostEventQueue postEventQueue = (PostEventQueue)appContext.get("PostEventQueue");
+        if (postEventQueue != null) {
+            postEventQueue.flush();
+        }
+        flushLock.unlock();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/awt/fontconfigs/macosx.fontconfig.properties b/jdk/src/macosx/classes/sun/awt/fontconfigs/macosx.fontconfig.properties
new file mode 100644
index 0000000..353a133
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/awt/fontconfigs/macosx.fontconfig.properties
@@ -0,0 +1,262 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# Version
+
+version=1
+
+# Component Font Mappings
+
+allfonts.chinese-ms936=SimSun
+allfonts.chinese-gb18030=SimSun-18030
+allfonts.chinese-hkscs=MingLiU_HKSCS
+allfonts.devanagari=Mangal
+allfonts.dingbats=Wingdings
+allfonts.lucida=Lucida Sans Regular
+allfonts.symbol=Symbol
+allfonts.thai=Lucida Sans Regular
+
+serif.plain.alphabetic=Times New Roman
+serif.plain.chinese-ms950=MingLiU
+serif.plain.hebrew=David
+serif.plain.japanese=MS Mincho
+serif.plain.korean=Batang
+
+serif.bold.alphabetic=Times New Roman Bold
+serif.bold.chinese-ms950=PMingLiU
+serif.bold.hebrew=David Bold
+serif.bold.japanese=MS Mincho
+serif.bold.korean=Batang
+
+serif.italic.alphabetic=Times New Roman Italic
+serif.italic.chinese-ms950=PMingLiU
+serif.italic.hebrew=David
+serif.italic.japanese=MS Mincho
+serif.italic.korean=Batang
+
+serif.bolditalic.alphabetic=Times New Roman Bold Italic
+serif.bolditalic.chinese-ms950=PMingLiU
+serif.bolditalic.hebrew=David Bold
+serif.bolditalic.japanese=MS Mincho
+serif.bolditalic.korean=Batang
+
+sansserif.plain.alphabetic=Arial
+sansserif.plain.chinese-ms950=MingLiU
+sansserif.plain.hebrew=David
+sansserif.plain.japanese=MS Gothic
+sansserif.plain.korean=Gulim
+
+sansserif.bold.alphabetic=Arial Bold
+sansserif.bold.chinese-ms950=PMingLiU
+sansserif.bold.hebrew=David Bold
+sansserif.bold.japanese=MS Gothic
+sansserif.bold.korean=Gulim
+
+sansserif.italic.alphabetic=Arial Italic
+sansserif.italic.chinese-ms950=PMingLiU
+sansserif.italic.hebrew=David
+sansserif.italic.japanese=MS Gothic
+sansserif.italic.korean=Gulim
+
+sansserif.bolditalic.alphabetic=Arial Bold Italic
+sansserif.bolditalic.chinese-ms950=PMingLiU
+sansserif.bolditalic.hebrew=David Bold
+sansserif.bolditalic.japanese=MS Gothic
+sansserif.bolditalic.korean=Gulim
+
+monospaced.plain.alphabetic=Courier New
+monospaced.plain.chinese-ms950=MingLiU
+monospaced.plain.hebrew=David
+monospaced.plain.japanese=MS Gothic
+monospaced.plain.korean=GulimChe
+
+monospaced.bold.alphabetic=Courier New Bold
+monospaced.bold.chinese-ms950=PMingLiU
+monospaced.bold.hebrew=David Bold
+monospaced.bold.japanese=MS Gothic
+monospaced.bold.korean=GulimChe
+
+monospaced.italic.alphabetic=Courier New Italic
+monospaced.italic.chinese-ms950=PMingLiU
+monospaced.italic.hebrew=David
+monospaced.italic.japanese=MS Gothic
+monospaced.italic.korean=GulimChe
+
+monospaced.bolditalic.alphabetic=Courier New Bold Italic
+monospaced.bolditalic.chinese-ms950=PMingLiU
+monospaced.bolditalic.hebrew=David Bold
+monospaced.bolditalic.japanese=MS Gothic
+monospaced.bolditalic.korean=GulimChe
+
+dialog.plain.alphabetic=Arial
+dialog.plain.chinese-ms950=MingLiU
+dialog.plain.hebrew=David
+dialog.plain.japanese=MS Gothic
+dialog.plain.korean=Gulim
+
+dialog.bold.alphabetic=Arial Bold
+dialog.bold.chinese-ms950=PMingLiU
+dialog.bold.hebrew=David Bold
+dialog.bold.japanese=MS Gothic
+dialog.bold.korean=Gulim
+
+dialog.italic.alphabetic=Arial Italic
+dialog.italic.chinese-ms950=PMingLiU
+dialog.italic.hebrew=David
+dialog.italic.japanese=MS Gothic
+dialog.italic.korean=Gulim
+
+dialog.bolditalic.alphabetic=Arial Bold Italic
+dialog.bolditalic.chinese-ms950=PMingLiU
+dialog.bolditalic.hebrew=David Bold
+dialog.bolditalic.japanese=MS Gothic
+dialog.bolditalic.korean=Gulim
+
+dialoginput.plain.alphabetic=Courier New
+dialoginput.plain.chinese-ms950=MingLiU
+dialoginput.plain.hebrew=David
+dialoginput.plain.japanese=MS Gothic
+dialoginput.plain.korean=Gulim
+
+dialoginput.bold.alphabetic=Courier New Bold
+dialoginput.bold.chinese-ms950=PMingLiU
+dialoginput.bold.hebrew=David Bold
+dialoginput.bold.japanese=MS Gothic
+dialoginput.bold.korean=Gulim
+
+dialoginput.italic.alphabetic=Courier New Italic
+dialoginput.italic.chinese-ms950=PMingLiU
+dialoginput.italic.hebrew=David
+dialoginput.italic.japanese=MS Gothic
+dialoginput.italic.korean=Gulim
+
+dialoginput.bolditalic.alphabetic=Courier New Bold Italic
+dialoginput.bolditalic.chinese-ms950=PMingLiU
+dialoginput.bolditalic.hebrew=David Bold
+dialoginput.bolditalic.japanese=MS Gothic
+dialoginput.bolditalic.korean=Gulim
+
+# Search Sequences
+
+sequence.allfonts=alphabetic/default,dingbats,symbol
+
+sequence.serif.GBK=alphabetic,chinese-ms936,dingbats,symbol
+sequence.sansserif.GBK=alphabetic,chinese-ms936,dingbats,symbol
+sequence.monospaced.GBK=chinese-ms936,alphabetic,dingbats,symbol
+sequence.dialog.GBK=alphabetic,chinese-ms936,dingbats,symbol
+sequence.dialoginput.GBK=alphabetic,chinese-ms936,dingbats,symbol
+
+sequence.serif.GB18030=alphabetic,chinese-gb18030,dingbats,symbol
+sequence.sansserif.GB18030=alphabetic,chinese-gb18030,dingbats,symbol
+sequence.monospaced.GB18030=chinese-gb18030,alphabetic,dingbats,symbol
+sequence.dialog.GB18030=alphabetic,chinese-gb18030,dingbats,symbol
+sequence.dialoginput.GB18030=alphabetic,chinese-gb18030,dingbats,symbol
+
+sequence.serif.x-windows-950=alphabetic,chinese-ms950,dingbats,symbol
+sequence.sansserif.x-windows-950=alphabetic,chinese-ms950,dingbats,symbol
+sequence.monospaced.x-windows-950=chinese-ms950,alphabetic,dingbats,symbol
+sequence.dialog.x-windows-950=alphabetic,chinese-ms950,dingbats,symbol
+sequence.dialoginput.x-windows-950=alphabetic,chinese-ms950,dingbats,symbol
+
+sequence.serif.x-MS950-HKSCS=alphabetic,chinese-ms950,chinese-hkscs,dingbats,symbol
+sequence.sansserif.x-MS950-HKSCS=alphabetic,chinese-ms950,chinese-hkscs,dingbats,symbol
+sequence.monospaced.x-MS950-HKSCS=chinese-ms950,alphabetic,chinese-hkscs,dingbats,symbol
+sequence.dialog.x-MS950-HKSCS=alphabetic,chinese-ms950,chinese-hkscs,dingbats,symbol
+sequence.dialoginput.x-MS950-HKSCS=alphabetic,chinese-ms950,chinese-hkscs,dingbats,symbol
+
+sequence.allfonts.UTF-8.hi=alphabetic/1252,devanagari,dingbats,symbol
+
+sequence.allfonts.windows-1255=hebrew,alphabetic/1252,dingbats,symbol
+
+sequence.serif.windows-31j=alphabetic,japanese,dingbats,symbol
+sequence.sansserif.windows-31j=alphabetic,japanese,dingbats,symbol
+sequence.monospaced.windows-31j=japanese,alphabetic,dingbats,symbol
+sequence.dialog.windows-31j=alphabetic,japanese,dingbats,symbol
+sequence.dialoginput.windows-31j=alphabetic,japanese,dingbats,symbol
+
+sequence.serif.x-windows-949=alphabetic,korean,dingbats,symbol
+sequence.sansserif.x-windows-949=alphabetic,korean,dingbats,symbol
+sequence.monospaced.x-windows-949=korean,alphabetic,dingbats,symbol
+sequence.dialog.x-windows-949=alphabetic,korean,dingbats,symbol
+sequence.dialoginput.x-windows-949=alphabetic,korean,dingbats,symbol
+
+sequence.allfonts.x-windows-874=alphabetic,thai,dingbats,symbol
+
+sequence.fallback=lucida,\
+                  chinese-ms950,chinese-hkscs,chinese-ms936,chinese-gb18030,\
+                  japanese,korean
+
+# Exclusion Ranges
+
+exclusion.alphabetic=0700-1e9f,1f00-20ab,20ad-f8ff
+exclusion.chinese-gb18030=0390-03d6,2200-22ef,2701-27be
+exclusion.hebrew=0041-005a,0060-007a,007f-00ff,20ac-20ac
+
+# Monospaced to Proportional width variant mapping
+# (Experimental private syntax)
+proportional.MS_Gothic=MS PGothic
+proportional.MS_Mincho=MS PMincho
+proportional.MingLiU=PMingLiU
+
+# Font File Names
+
+filename.Arial=ARIAL.TTF
+filename.Arial_Bold=ARIALBD.TTF
+filename.Arial_Italic=ARIALI.TTF
+filename.Arial_Bold_Italic=ARIALBI.TTF
+
+filename.Courier_New=COUR.TTF
+filename.Courier_New_Bold=COURBD.TTF
+filename.Courier_New_Italic=COURI.TTF
+filename.Courier_New_Bold_Italic=COURBI.TTF
+
+filename.Times_New_Roman=TIMES.TTF
+filename.Times_New_Roman_Bold=TIMESBD.TTF
+filename.Times_New_Roman_Italic=TIMESI.TTF
+filename.Times_New_Roman_Bold_Italic=TIMESBI.TTF
+
+filename.SimSun=SIMSUN.TTC
+filename.SimSun-18030=SIMSUN18030.TTC
+
+filename.MingLiU=MINGLIU.TTC
+filename.PMingLiU=MINGLIU.TTC
+filename.MingLiU_HKSCS=hkscsm3u.ttf
+
+filename.David=DAVID.TTF
+filename.David_Bold=DAVIDBD.TTF
+
+filename.MS_Mincho=MSMINCHO.TTC
+filename.MS_PMincho=MSMINCHO.TTC
+filename.MS_Gothic=MSGOTHIC.TTC
+filename.MS_PGothic=MSGOTHIC.TTC
+
+filename.Gulim=gulim.TTC
+filename.Batang=batang.TTC
+filename.GulimChe=gulim.TTC
+
+filename.Lucida_Sans_Regular=LucidaSansRegular.ttf
+filename.Mangal=MANGAL.TTF
+filename.Symbol=SYMBOL.TTF
+filename.Wingdings=WINGDING.TTF
diff --git a/jdk/src/macosx/classes/sun/font/CCharToGlyphMapper.java b/jdk/src/macosx/classes/sun/font/CCharToGlyphMapper.java
new file mode 100644
index 0000000..70fad4d
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/font/CCharToGlyphMapper.java
@@ -0,0 +1,314 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.font;
+
+import java.util.HashMap;
+
+public class CCharToGlyphMapper extends CharToGlyphMapper {
+    private static native int countGlyphs(final long nativeFontPtr);
+
+    private Cache cache = new Cache();
+    CFont fFont;
+    int numGlyphs = -1;
+
+    public CCharToGlyphMapper(CFont font) {
+        fFont = font;
+        missingGlyph = 0; // for getMissingGlyphCode()
+    }
+
+    public int getNumGlyphs() {
+        if (numGlyphs == -1) {
+            numGlyphs = countGlyphs(fFont.getNativeFontPtr());
+        }
+        return numGlyphs;
+    }
+
+    public boolean canDisplay(char ch) {
+        int glyph = charToGlyph(ch);
+        return glyph != missingGlyph;
+    }
+
+    public boolean canDisplay(int cp) {
+        int glyph = charToGlyph(cp);
+        return glyph != missingGlyph;
+    }
+
+    public synchronized boolean charsToGlyphsNS(int count,
+                                                char[] unicodes, int[] glyphs)
+    {
+        charsToGlyphs(count, unicodes, glyphs);
+
+        // The following shaping checks are from either
+        // TrueTypeGlyphMapper or Type1GlyphMapper
+        for (int i = 0; i < count; i++) {
+            int code = unicodes[i];
+
+            if (code >= HI_SURROGATE_START && code <= HI_SURROGATE_END && i < count - 1) {
+                char low = unicodes[i + 1];
+
+                if (low >= LO_SURROGATE_START && low <= LO_SURROGATE_END) {
+                    code = (code - HI_SURROGATE_START) * 0x400 + low - LO_SURROGATE_START + 0x10000;
+                    glyphs[i + 1] = INVISIBLE_GLYPH_ID;
+                }
+            }
+
+            if (code < 0x0590) {
+                continue;
+            } else if (code <= 0x05ff) {
+                // Hebrew 0x0590->0x05ff
+                return true;
+            } else if (code >= 0x0600 && code <= 0x06ff) {
+                // Arabic
+                return true;
+            } else if (code >= 0x0900 && code <= 0x0d7f) {
+                // if Indic, assume shaping for conjuncts, reordering:
+                // 0900 - 097F Devanagari
+                // 0980 - 09FF Bengali
+                // 0A00 - 0A7F Gurmukhi
+                // 0A80 - 0AFF Gujarati
+                // 0B00 - 0B7F Oriya
+                // 0B80 - 0BFF Tamil
+                // 0C00 - 0C7F Telugu
+                // 0C80 - 0CFF Kannada
+                // 0D00 - 0D7F Malayalam
+                return true;
+            } else if (code >= 0x0e00 && code <= 0x0e7f) {
+                // if Thai, assume shaping for vowel, tone marks
+                return true;
+            } else if (code >= 0x200c && code <= 0x200d) {
+                // zwj or zwnj
+                return true;
+            } else if (code >= 0x202a && code <= 0x202e) {
+                // directional control
+                return true;
+            } else if (code >= 0x206a && code <= 0x206f) {
+                // directional control
+                return true;
+            } else if (code >= 0x10000) {
+                i += 1; // Empty glyph slot after surrogate
+                continue;
+            }
+        }
+
+        return false;
+    }
+
+    public synchronized int charToGlyph(char unicode) {
+        final int glyph = cache.get(unicode);
+        if (glyph != 0) return glyph;
+
+        final char[] unicodeArray = new char[] { unicode };
+        final int[] glyphArray = new int[1];
+
+        nativeCharsToGlyphs(fFont.getNativeFontPtr(), 1, unicodeArray, glyphArray);
+        cache.put(unicode, glyphArray[0]);
+
+        return glyphArray[0];
+    }
+
+    public synchronized int charToGlyph(int unicode) {
+        return charToGlyph((char)unicode);
+    }
+
+    public synchronized void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {
+        cache.get(count, unicodes, glyphs);
+    }
+
+    public synchronized void charsToGlyphs(int count, int[] unicodes, int[] glyphs) {
+        final char[] unicodeChars = new char[count];
+        for (int i = 0; i < count; i++) unicodeChars[i] = (char)unicodes[i];
+        cache.get(count, unicodeChars, glyphs);
+    }
+
+    // This mapper returns either the glyph code, or if the character can be
+    // replaced on-the-fly using CoreText substitution; the negative unicode
+    // value. If this "glyph code int" is treated as an opaque code, it will
+    // strike and measure exactly as a real glyph code - whether the character
+    // is present or not. Missing characters for any font on the system will
+    // be returned as 0, as the getMissingGlyphCode() function above indicates.
+    private static native void nativeCharsToGlyphs(final long nativeFontPtr,
+                                                   int count, char[] unicodes,
+                                                   int[] glyphs);
+
+    private class Cache {
+        private static final int FIRST_LAYER_SIZE = 256;
+        private static final int SECOND_LAYER_SIZE = 16384; // 16384 = 128x128
+
+        private final int[] firstLayerCache = new int[FIRST_LAYER_SIZE];
+        private SparseBitShiftingTwoLayerArray secondLayerCache;
+        private HashMap<Integer, Integer> generalCache;
+
+        Cache() {
+            // <rdar://problem/5331678> need to prevent getting '-1' stuck in the cache
+            firstLayerCache[1] = 1;
+        }
+
+        public int get(final char index) {
+            if (index < FIRST_LAYER_SIZE) {
+                // catch common glyphcodes
+                return firstLayerCache[index];
+            }
+
+            if (index < SECOND_LAYER_SIZE) {
+                // catch common unicodes
+                if (secondLayerCache == null) return 0;
+                return secondLayerCache.get(index);
+            }
+
+            if (generalCache == null) return 0;
+            final Integer value = generalCache.get(new Integer(index));
+            if (value == null) return 0;
+            return value.intValue();
+        }
+
+        public void put(final char index, final int value) {
+            if (index < FIRST_LAYER_SIZE) {
+                // catch common glyphcodes
+                firstLayerCache[index] = value;
+                return;
+            }
+
+            if (index < SECOND_LAYER_SIZE) {
+                // catch common unicodes
+                if (secondLayerCache == null) {
+                    secondLayerCache = new SparseBitShiftingTwoLayerArray(SECOND_LAYER_SIZE, 7); // 128x128
+                }
+                secondLayerCache.put(index, value);
+                return;
+            }
+
+            if (generalCache == null) {
+                generalCache = new HashMap<Integer, Integer>();
+            }
+
+            generalCache.put(new Integer(index), new Integer(value));
+        }
+
+        private class SparseBitShiftingTwoLayerArray {
+            final int[][] cache;
+            final int shift;
+            final int secondLayerLength;
+
+            public SparseBitShiftingTwoLayerArray(final int size,
+                                                  final int shift)
+            {
+                this.shift = shift;
+                this.cache = new int[1 << shift][];
+                this.secondLayerLength = size >> shift;
+            }
+
+            public int get(final char index) {
+                final int firstIndex = index >> shift;
+                final int[] firstLayerRow = cache[firstIndex];
+                if (firstLayerRow == null) return 0;
+                return firstLayerRow[index - (firstIndex * (1 << shift))];
+            }
+
+            public void put(final char index, final int value) {
+                final int firstIndex = index >> shift;
+                int[] firstLayerRow = cache[firstIndex];
+                if (firstLayerRow == null) {
+                    cache[firstIndex] = firstLayerRow = new int[secondLayerLength];
+                }
+                firstLayerRow[index - (firstIndex * (1 << shift))] = value;
+            }
+        }
+
+        public void get(int count, char[] indicies, int[] values){
+            int missed = 0;
+            for(int i = 0; i < count; i++){
+                char code = indicies[i];
+
+                final int value = get(code);
+                if(value != 0){
+                    values[i] = value;
+                }else{
+                    // zero this element out, because the caller does not
+                    // promise to keep it clean
+                    values[i] = 0;
+                    missed++;
+                }
+            }
+
+            if (missed == 0) return; // horray! everything is already cached!
+
+            final char[] filteredCodes = new char[missed]; // all index codes requested (partially filled)
+            final int[] filteredIndicies = new int[missed]; // local indicies into filteredCodes array (totally filled)
+
+            // scan, mark, and store the index codes again to send into native
+            int j = 0;
+            int dupes = 0;
+            for (int i = 0; i < count; i++){
+                if (values[i] != 0L) continue; // already filled
+
+                final char code = indicies[i];
+
+                // we have already promised to fill this code - this is a dupe
+                if (get(code) == -1){
+                    filteredIndicies[j] = -1;
+                    dupes++;
+                    j++;
+                    continue;
+                }
+
+                // this is a code we have not obtained before
+                // mark this one as "promise to get" in the global cache with a -1
+                final int k = j - dupes;
+                filteredCodes[k] = code;
+                put(code, -1);
+                filteredIndicies[j] = k;
+                j++;
+            }
+
+            final int filteredRunLen = j - dupes;
+            final int[] filteredValues = new int[filteredRunLen];
+
+            // bulk call to fill in the distinct values
+            nativeCharsToGlyphs(fFont.getNativeFontPtr(), filteredRunLen, filteredCodes, filteredValues);
+
+            // scan the requested list, and fill in values from our
+            // distinct code list which has been filled from "getDistinct"
+            j = 0;
+            for (int i = 0; i < count; i++){
+                if (values[i] != 0L && values[i] != -1L) continue; // already placed
+
+                final int k = filteredIndicies[j]; // index into filteredImages array
+                final char code = indicies[i];
+                if(k == -1L){
+                    // we should have already filled the cache with this value
+                    values[i] = get(code);
+                }else{
+                    // fill the particular code request, and store in the cache
+                    final int ptr = filteredValues[k];
+                    values[i] = ptr;
+                    put(code, ptr);
+                }
+
+                j++;
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/font/CFont.java b/jdk/src/macosx/classes/sun/font/CFont.java
new file mode 100644
index 0000000..a787c77
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/font/CFont.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.font;
+
+import java.awt.Font;
+import java.awt.font.FontRenderContext;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+// Right now this class is final to avoid a problem with native code.
+// For some reason the JNI IsInstanceOf was not working correctly
+// so we are checking the class specifically. If we subclass this
+// we need to modify the native code in CFontWrapper.m
+public final class CFont extends PhysicalFont {
+
+    /* CFontStrike doesn't call these methods so they are unimplemented.
+     * They are here to meet the requirements of PhysicalFont, needed
+     * because a CFont can sometimes be returned where a PhysicalFont
+     * is expected.
+     */
+    StrikeMetrics getFontMetrics(long pScalerContext) {
+       throw new InternalError("Not implemented");
+    }
+
+    float getGlyphAdvance(long pScalerContext, int glyphCode) {
+       throw new InternalError("Not implemented");
+    }
+
+    void getGlyphMetrics(long pScalerContext, int glyphCode,
+                                  Point2D.Float metrics) {
+       throw new InternalError("Not implemented");
+    }
+
+    long getGlyphImage(long pScalerContext, int glyphCode) {
+       throw new InternalError("Not implemented");
+    }
+
+    Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext,
+                                                     int glyphCode) {
+       throw new InternalError("Not implemented");
+    }
+
+    GeneralPath getGlyphOutline(long pScalerContext, int glyphCode,
+                                         float x, float y) {
+       throw new InternalError("Not implemented");
+    }
+
+    GeneralPath getGlyphVectorOutline(long pScalerContext,
+                                               int[] glyphs, int numGlyphs,
+                                               float x, float y) {
+       throw new InternalError("Not implemented");
+    }
+
+    private static native long createNativeFont(final String nativeFontName,
+                                                final int style,
+                                                final boolean isFakeItalic);
+    private static native void disposeNativeFont(final long nativeFontPtr);
+
+    private boolean isFakeItalic;
+    private String nativeFontName;
+    private long nativeFontPtr;
+
+    // this constructor is called from CFontWrapper.m
+    public CFont(String name) {
+        this(name, name);
+    }
+
+    public CFont(String name, String inFamilyName) {
+        handle = new Font2DHandle(this);
+        fullName = name;
+        familyName = inFamilyName;
+        nativeFontName = inFamilyName;
+        setStyle();
+    }
+
+    public CFont(CFont other, String logicalFamilyName) {
+        handle = new Font2DHandle(this);
+        fullName = logicalFamilyName;
+        familyName = logicalFamilyName;
+        nativeFontName = other.nativeFontName;
+        style = other.style;
+        isFakeItalic = other.isFakeItalic;
+    }
+
+    public CFont createItalicVariant() {
+        CFont font = new CFont(this, familyName);
+        font.fullName =
+            fullName + (style == Font.BOLD ? "" : "-") + "Italic-Derived";
+        font.style |= Font.ITALIC;
+        font.isFakeItalic = true;
+        return font;
+    }
+
+    protected synchronized long getNativeFontPtr() {
+        if (nativeFontPtr == 0L) {
+            nativeFontPtr = createNativeFont(nativeFontName, style, isFakeItalic);
+}
+        return nativeFontPtr;
+    }
+
+    protected synchronized void finalize() {
+        if (nativeFontPtr != 0) {
+            disposeNativeFont(nativeFontPtr);
+        }
+        nativeFontPtr = 0;
+    }
+
+    protected CharToGlyphMapper getMapper() {
+        if (mapper == null) {
+            mapper = new CCharToGlyphMapper(this);
+        }
+        return mapper;
+    }
+
+    protected FontStrike createStrike(FontStrikeDesc desc) {
+        if (isFakeItalic) {
+            desc = new FontStrikeDesc(desc);
+            desc.glyphTx.concatenate(AffineTransform.getShearInstance(-0.2, 0));
+        }
+        return new CStrike(this, desc);
+    }
+
+    // <rdar://problem/5321707> sun.font.Font2D caches the last used strike,
+    // but does not check if the properties of the strike match the properties
+    // of the incoming java.awt.Font object (size, style, etc).
+    // Simple answer: don't cache.
+    private static FontRenderContext DEFAULT_FRC =
+        new FontRenderContext(null, false, false);
+    public FontStrike getStrike(final Font font) {
+        return getStrike(font, DEFAULT_FRC);
+    }
+
+    public String toString() {
+        return "CFont { fullName: " + fullName +
+            ",  familyName: " + familyName + ", style: " + style +
+            " } aka: " + super.toString();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/font/CFontConfiguration.java b/jdk/src/macosx/classes/sun/font/CFontConfiguration.java
new file mode 100644
index 0000000..ee70fc5
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/font/CFontConfiguration.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.font;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import sun.awt.FontConfiguration;
+import sun.font.CompositeFontDescriptor;
+import sun.font.SunFontManager;
+
+class CFontConfiguration extends FontConfiguration {
+
+    private static CompositeFontDescriptor[] emptyDescriptors =
+        new CompositeFontDescriptor[0];
+    private static String[] emptyStrings = new String[0];
+
+    public CFontConfiguration(SunFontManager fm) {
+        super(fm);
+    }
+
+    public CFontConfiguration(SunFontManager fm,
+                              boolean preferLocaleFonts,
+                              boolean preferPropFonts)
+    {
+        super(fm, preferLocaleFonts, preferPropFonts);
+    }
+
+    /*
+     * On Mac OS X we essentially ignore the font.properties file, and do
+     * it all programatically.  The intention is end users will use things
+     * like the Font Book to manage fonts. Plus our fonts automatically do
+     * unicode substitution, so a localized font is not required.
+     *
+     * The following methods therefore act like stubs and return empty values.
+     */
+
+    @Override
+    public int getNumberCoreFonts() {
+        return 0;
+    }
+
+    @Override
+    public String[] getPlatformFontNames() {
+        return emptyStrings;
+    }
+
+    @Override
+    public CompositeFontDescriptor[] get2DCompositeFontInfo() {
+        return emptyDescriptors;
+    }
+
+    @Override
+    protected String mapFileName(String fileName) {
+        return "";
+    }
+
+    @Override
+    protected Charset getDefaultFontCharset(String fontName) {
+        return Charset.forName("ISO8859_1");
+    }
+
+    @Override
+    protected String getEncoding(String awtFontName, String charSubsetName) {
+        return "default";
+    }
+
+    @Override
+    protected String getFaceNameFromComponentFontName(String compFontName) {
+        return compFontName;
+    }
+
+    @Override
+    protected String getFileNameFromComponentFontName(String compFontName) {
+        return compFontName;
+    }
+
+    @Override
+    public String getFallbackFamilyName(String fontName,
+                                        String defaultFallback)
+    {
+        return defaultFallback;
+    }
+
+    @Override
+    protected void initReorderMap() {
+        reorderMap = new HashMap();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/font/CFontManager.java b/jdk/src/macosx/classes/sun/font/CFontManager.java
new file mode 100644
index 0000000..5caca1e
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/font/CFontManager.java
@@ -0,0 +1,367 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.font;
+
+import java.awt.*;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import javax.swing.plaf.FontUIResource;
+
+import sun.awt.FontConfiguration;
+import sun.lwawt.macosx.*;
+
+public class CFontManager extends SunFontManager {
+    private FontConfigManager fcManager = null;
+    private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
+
+    @Override
+    protected FontConfiguration createFontConfiguration() {
+        FontConfiguration fc = new CFontConfiguration(this);
+        fc.init();
+        return fc;
+    }
+
+    @Override
+    public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
+                                                     boolean preferPropFonts)
+    {
+        return new CFontConfiguration(this, preferLocaleFonts, preferPropFonts);
+    }
+
+    private static String[] defaultPlatformFont = null;
+
+    /*
+     * Returns an array of two strings. The first element is the
+     * name of the font. The second element is the file name.
+     */
+    @Override
+    public synchronized String[] getDefaultPlatformFont() {
+        if (defaultPlatformFont == null) {
+            defaultPlatformFont = new String[2];
+            defaultPlatformFont[0] = "Lucida Grande";
+            defaultPlatformFont[1] = "/System/Library/Fonts/LucidaGrande.ttc";
+        }
+        return defaultPlatformFont;
+    }
+
+    // This is a way to register any kind of Font2D, not just files and composites.
+    public static Font2D[] getGenericFonts() {
+        return (Font2D[])genericFonts.values().toArray(new Font2D[0]);
+    }
+
+    public Font2D registerGenericFont(Font2D f)
+    {
+        return registerGenericFont(f, false);
+    }
+    public Font2D registerGenericFont(Font2D f, boolean logicalFont)
+    {
+        int rank = 4;
+
+        String fontName = f.fullName;
+        String familyName = f.familyName;
+
+        if (fontName == null || "".equals(fontName)) {
+            return null;
+        }
+
+        // logical fonts always need to be added to the family
+        // plus they never need to be added to the generic font list
+        // or the fullNameToFont table since they are covers for
+        // already existing fonts in this list
+        if (logicalFont || !genericFonts.containsKey(fontName)) {
+            if (FontUtilities.debugFonts()) {
+                FontUtilities.getLogger().info("Add to Family "+familyName +
+                    ", Font " + fontName + " rank="+rank);
+            }
+            FontFamily family = FontFamily.getFamily(familyName);
+            if (family == null) {
+                family = new FontFamily(familyName, false, rank);
+                family.setFont(f, f.style);
+            } else if (family.getRank() >= rank) {
+                family.setFont(f, f.style);
+            }
+            if (!logicalFont)
+            {
+                genericFonts.put(fontName, f);
+                fullNameToFont.put(fontName.toLowerCase(Locale.ENGLISH), f);
+            }
+            return f;
+        } else {
+            return (Font2D)genericFonts.get(fontName);
+        }
+    }
+
+    @Override
+    public Font2D[] getRegisteredFonts() {
+        Font2D[] regFonts = super.getRegisteredFonts();
+
+        // Add in the Mac OS X native fonts
+        Font2D[] genericFonts = getGenericFonts();
+        Font2D[] allFonts = new Font2D[regFonts.length+genericFonts.length];
+        System.arraycopy(regFonts, 0, allFonts, 0, regFonts.length);
+        System.arraycopy(genericFonts, 0, allFonts, regFonts.length, genericFonts.length);
+
+        return allFonts;
+    }
+
+    @Override
+    protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) {
+        Font2D[] genericfonts = getGenericFonts();
+        for (int i=0; i < genericfonts.length; i++) {
+            if (!(genericfonts[i] instanceof NativeFont)) {
+                String name = genericfonts[i].getFamilyName(requestedLocale);
+                familyNames.put(name.toLowerCase(requestedLocale), name);
+            }
+        }
+    }
+
+    @Override
+    public Font2D createFont2D(File fontFile, int fontFormat, boolean isCopy, CreatedFontTracker tracker) throws FontFormatException {
+
+    String fontFilePath = fontFile.getPath();
+    Font2D font2D = null;
+    final File fFile = fontFile;
+    final CreatedFontTracker _tracker = tracker;
+    try {
+        switch (fontFormat) {
+            case Font.TRUETYPE_FONT:
+                        font2D = new TrueTypeFont(fontFilePath, null, 0, true);
+                break;
+            case Font.TYPE1_FONT:
+                        font2D = new Type1Font(fontFilePath, null, isCopy);
+                break;
+            default:
+                throw new FontFormatException("Unrecognised Font Format");
+        }
+    } catch (FontFormatException e) {
+        if (isCopy) {
+            java.security.AccessController.doPrivileged(
+                    new java.security.PrivilegedAction<Object>() {
+                        public Object run() {
+                            if (_tracker != null) {
+                                _tracker.subBytes((int)fFile.length());
+                            }
+                            fFile.delete();
+                            return null;
+                        }
+                    });
+        }
+        throw(e);
+    }
+    if (isCopy) {
+        FileFont.setFileToRemove(font2D, fontFile, tracker);
+        synchronized (FontManager.class) {
+
+            if (tmpFontFiles == null) {
+                tmpFontFiles = new Vector<File>();
+            }
+            tmpFontFiles.add(fontFile);
+
+            if (fileCloser == null) {
+                final Runnable fileCloserRunnable = new Runnable() {
+                    public void run() {
+                        java.security.AccessController.doPrivileged(
+                                new java.security.PrivilegedAction<Object>() {
+                                    public Object run() {
+
+                                        for (int i=0;i<CHANNELPOOLSIZE;i++) {
+                                            if (fontFileCache[i] != null) {
+                                                try {
+                                                    fontFileCache[i].close();
+                                                } catch (Exception e) {}
+                                            }
+                                        }
+                                        if (tmpFontFiles != null) {
+                                            File[] files = new File[tmpFontFiles.size()];
+                                            files = tmpFontFiles.toArray(files);
+                                            for (int f=0; f<files.length;f++) {
+                                                try {
+                                                    files[f].delete();
+                                                } catch (Exception e) {}
+                                            }
+                                        }
+                                        return null;
+                                    }
+                                });
+                    }
+                };
+                java.security.AccessController.doPrivileged(
+                        new java.security.PrivilegedAction<Object>() {
+                            public Object run() {
+                                /* The thread must be a member of a thread group
+                                 * which will not get GCed before VM exit.
+                                 * Make its parent the top-level thread group.
+                                 */
+                                ThreadGroup tg =
+                                    Thread.currentThread().getThreadGroup();
+                                for (ThreadGroup tgn = tg;
+                                tgn != null;
+                                tg = tgn, tgn = tg.getParent());
+                                fileCloser = new Thread(tg, fileCloserRunnable);
+                                fileCloser.setContextClassLoader(null);
+                                Runtime.getRuntime().addShutdownHook(fileCloser);
+                                return null;
+                            }
+                        });
+                }
+            }
+        }
+        return font2D;
+    }
+
+    /*
+    public synchronized FontConfigManager getFontConfigManager() {
+        if (fcManager  == null) {
+            fcManager = new FontConfigManager();
+        }
+        return fcManager;
+    }
+    */
+
+    protected void registerFontsInDir(String dirName, boolean useJavaRasterizer, int fontRank, boolean defer, boolean resolveSymLinks) {
+        loadNativeDirFonts(dirName);
+        super.registerFontsInDir(dirName, useJavaRasterizer, fontRank, defer, resolveSymLinks);
+    }
+
+    private native void loadNativeDirFonts(String dirName);
+    private native void loadNativeFonts();
+
+    void registerFont(String fontName, String fontFamilyName) {
+        final CFont font = new CFont(fontName, fontFamilyName);
+
+        registerGenericFont(font);
+
+        if ((font.getStyle() & Font.ITALIC) == 0) {
+            registerGenericFont(font.createItalicVariant(), true);
+        }
+    }
+
+    Object waitForFontsToBeLoaded  = new Object();
+    public void loadFonts()
+    {
+        synchronized(waitForFontsToBeLoaded)
+        {
+            super.loadFonts();
+            java.security.AccessController.doPrivileged(
+                new java.security.PrivilegedAction<Object>() {
+                    public Object run() {
+                        loadNativeFonts();
+                        return null;
+                    }
+                }
+            );
+
+            String defaultFont = "Lucida Grande";
+            String defaultFallback = "Lucida Sans";
+
+            setupLogicalFonts("Dialog", defaultFont, defaultFallback);
+            setupLogicalFonts("Serif", "Times", "Lucida Bright");
+            setupLogicalFonts("SansSerif", defaultFont, defaultFallback);
+            setupLogicalFonts("Monospaced", "Menlo", "Lucida Sans Typewriter");
+            setupLogicalFonts("DialogInput", defaultFont, defaultFallback);
+        }
+    }
+
+    protected void setupLogicalFonts(String logicalName, String realName, String fallbackName) {
+        FontFamily realFamily = getFontFamilyWithExtraTry(logicalName, realName, fallbackName);
+
+        cloneStyledFont(realFamily, logicalName, Font.PLAIN);
+        cloneStyledFont(realFamily, logicalName, Font.BOLD);
+        cloneStyledFont(realFamily, logicalName, Font.ITALIC);
+        cloneStyledFont(realFamily, logicalName, Font.BOLD | Font.ITALIC);
+    }
+
+    protected FontFamily getFontFamilyWithExtraTry(String logicalName, String realName, String fallbackName){
+        FontFamily family = getFontFamily(realName, fallbackName);
+        if (family != null) return family;
+
+        // at this point, we recognize that we probably needed a fallback font
+        super.loadFonts();
+
+        family = getFontFamily(realName, fallbackName);
+        if (family != null) return family;
+
+        System.err.println("Warning: the fonts \"" + realName + "\" and \"" + fallbackName + "\" are not available for the Java logical font \"" + logicalName + "\", which may have unexpected appearance or behavior. Re-enable the \""+ realName +"\" font to remove this warning.");
+        return null;
+    }
+
+    protected FontFamily getFontFamily(String realName, String fallbackName){
+        FontFamily family = FontFamily.getFamily(realName);
+        if (family != null) return family;
+
+        family = FontFamily.getFamily(fallbackName);
+        if (family != null){
+            System.err.println("Warning: the font \"" + realName + "\" is not available, so \"" + fallbackName + "\" has been substituted, but may have unexpected appearance or behavor. Re-enable the \""+ realName +"\" font to remove this warning.");
+            return family;
+        }
+
+        return null;
+    }
+
+    protected boolean cloneStyledFont(FontFamily realFamily, String logicalFamilyName, int style) {
+        if (realFamily == null) return false;
+
+        Font2D realFont = realFamily.getFontWithExactStyleMatch(style);
+        if (realFont == null || !(realFont instanceof CFont)) return false;
+
+        CFont newFont = new CFont((CFont)realFont, logicalFamilyName);
+        registerGenericFont(newFont, true);
+
+        return true;
+    }
+
+    @Override
+    public String getFontPath(boolean noType1Fonts) {
+        // In the case of the Cocoa toolkit, since we go through NSFont, we dont need to register /Library/Fonts
+        if (Toolkit.getDefaultToolkit() instanceof LWCToolkit) {
+            return "";
+        }
+        // X11 case
+        return "/Library/Fonts";
+    }
+
+    @Override
+    protected FontUIResource getFontConfigFUIR(
+            String family, int style, int size)
+    {
+        String mappedName = FontUtilities.mapFcName(family);
+        if (mappedName == null) {
+            mappedName = "sansserif";
+        }
+        return new FontUIResource(mappedName, style, size);
+    }
+
+    // Only implemented on Windows
+    @Override
+    protected void populateFontFileNameMap(HashMap<String, String> fontToFileMap, HashMap<String, String> fontToFamilyNameMap,
+            HashMap<String, ArrayList<String>> familyToFontListMap, Locale locale) {}
+}
diff --git a/jdk/src/macosx/classes/sun/font/CStrike.java b/jdk/src/macosx/classes/sun/font/CStrike.java
new file mode 100644
index 0000000..61fe234
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/font/CStrike.java
@@ -0,0 +1,632 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.font;
+
+import java.awt.Rectangle;
+import java.awt.geom.*;
+import java.util.*;
+
+import sun.awt.SunHints;
+
+public class CStrike extends FontStrike {
+
+    // Creates the native strike
+    private static native long createNativeStrikePtr(long nativeFontPtr,
+                                                     double[] glyphTx,
+                                                     double[] invDevTxMatrix,
+                                                     int aaHint,
+                                                     int fmHint);
+
+    // Disposes the native strike
+    private static native void disposeNativeStrikePtr(long nativeStrikePtr);
+
+    // Creates a StrikeMetrics from the underlying native system fonts
+    private static native StrikeMetrics getFontMetrics(long nativeStrikePtr);
+
+    // Returns native struct pointers used by the Sun 2D Renderer
+    private static native void getGlyphImagePtrsNative(long nativeStrikePtr,
+                                                       long[] glyphInfos,
+                                                       int[] uniCodes, int len);
+
+    // Returns the advance give a glyph code. It should be used only
+    // when the glyph code belongs to the CFont passed in.
+    private static native float getNativeGlyphAdvance(long nativeStrikePtr,
+                                                      int glyphCode);
+
+    // Returns the outline shape of a glyph
+    private static native GeneralPath getNativeGlyphOutline(long nativeStrikePtr,
+                                                            int glyphCode,
+                                                            double x,
+                                                            double y);
+
+    // returns the bounding rect for a glyph
+    private static native void getNativeGlyphImageBounds(long nativeStrikePtr,
+                                                         int glyphCode,
+                                                         Rectangle2D.Float result,
+                                                         double x, double y);
+
+    private CFont nativeFont;
+    private AffineTransform invDevTx;
+    private GlyphInfoCache glyphInfoCache;
+    private GlyphAdvanceCache glyphAdvanceCache;
+    private long nativeStrikePtr;
+
+    CStrike(final CFont font, final FontStrikeDesc inDesc) {
+        nativeFont = font;
+        desc = inDesc;
+        glyphInfoCache = new GlyphInfoCache(font, desc);
+        glyphAdvanceCache = new GlyphAdvanceCache();
+        disposer = glyphInfoCache;
+
+        // Normally the device transform should be the identity transform
+        // for screen operations.  The device transform only becomes
+        // interesting when we are outputting between different dpi surfaces,
+        // like when we are printing to postscript.
+        if (inDesc.devTx != null && !inDesc.devTx.isIdentity()) {
+            try {
+                invDevTx = inDesc.devTx.createInverse();
+            } catch (NoninvertibleTransformException e) {
+                // ignored, since device transforms should not be that
+                // complicated, and if they are - there is nothing we can do,
+                // so we won't worry about it.
+            }
+        }
+    }
+
+    public long getNativeStrikePtr() {
+        if (nativeStrikePtr != 0) {
+            return nativeStrikePtr;
+        }
+
+        final double[] glyphTx = new double[6];
+        desc.glyphTx.getMatrix(glyphTx);
+
+        final double[] invDevTxMatrix = new double[6];
+        if (invDevTx == null) {
+            invDevTxMatrix[0] = 1;
+            invDevTxMatrix[3] = 1;
+        } else {
+            invDevTx.getMatrix(invDevTxMatrix);
+        }
+
+        final int aaHint = desc.aaHint;
+        final int fmHint = desc.fmHint;
+
+        synchronized (this) {
+            if (nativeStrikePtr != 0) {
+                return nativeStrikePtr;
+            }
+            nativeStrikePtr =
+                createNativeStrikePtr(nativeFont.getNativeFontPtr(),
+                                      glyphTx, invDevTxMatrix, aaHint, fmHint);
+        }
+
+        return nativeStrikePtr;
+    }
+
+    protected synchronized void finalize() throws Throwable {
+        if (nativeStrikePtr != 0) {
+            disposeNativeStrikePtr(nativeStrikePtr);
+        }
+        nativeStrikePtr = 0;
+    }
+
+    // the fractional metrics default on our platform is OFF
+    private boolean useFractionalMetrics() {
+        return desc.fmHint == SunHints.INTVAL_FRACTIONALMETRICS_ON;
+    }
+
+    public int getNumGlyphs() {
+        return nativeFont.getNumGlyphs();
+    }
+
+    StrikeMetrics getFontMetrics() {
+        if (strikeMetrics == null) {
+            StrikeMetrics metrics = getFontMetrics(getNativeStrikePtr());
+            if (invDevTx != null) {
+                metrics.convertToUserSpace(invDevTx);
+            }
+            metrics.convertToUserSpace(desc.glyphTx);
+            strikeMetrics = metrics;
+        }
+        return strikeMetrics;
+    }
+
+    float getGlyphAdvance(int glyphCode) {
+        return getScaledAdvanceForAdvance(getCachedNativeGlyphAdvance(glyphCode));
+    }
+
+    float getCodePointAdvance(int cp) {
+        float advance = getCachedNativeGlyphAdvance(nativeFont.getMapper().charToGlyph(cp));
+
+        double glyphScaleX = desc.glyphTx.getScaleX();
+        double devScaleX = desc.devTx.getScaleX();
+
+        if (devScaleX == 0) {
+            glyphScaleX = Math.sqrt(desc.glyphTx.getDeterminant());
+            devScaleX = Math.sqrt(desc.devTx.getDeterminant());
+        }
+
+        if (devScaleX == 0) {
+            devScaleX = Double.NaN; // this an undefined graphics state
+        }
+        advance = (float) (advance * glyphScaleX / devScaleX);
+        return useFractionalMetrics() ? advance : Math.round(advance);
+    }
+
+    // calculate an advance, and round if not using fractional metrics
+    private float getScaledAdvanceForAdvance(float advance) {
+        if (invDevTx != null) {
+            advance *= invDevTx.getScaleX();
+        }
+        advance *= desc.glyphTx.getScaleX();
+        return useFractionalMetrics() ? advance : Math.round(advance);
+    }
+
+    Point2D.Float getCharMetrics(char ch) {
+        return getScaledPointForAdvance(getCachedNativeGlyphAdvance(nativeFont.getMapper().charToGlyph(ch)));
+    }
+
+    Point2D.Float getGlyphMetrics(int glyphCode) {
+        return getScaledPointForAdvance(getCachedNativeGlyphAdvance(glyphCode));
+    }
+
+    // calculate an advance point, and round if not using fractional metrics
+    private Point2D.Float getScaledPointForAdvance(float advance) {
+        Point2D.Float pt = new Point2D.Float(advance, 0);
+
+        if (!desc.glyphTx.isIdentity()) {
+            return scalePoint(pt);
+        }
+
+        if (!useFractionalMetrics()) {
+            pt.x = Math.round(pt.x);
+        }
+        return pt;
+    }
+
+    private Point2D.Float scalePoint(Point2D.Float pt) {
+        if (invDevTx != null) {
+            // transform the point out of the device space first
+            invDevTx.transform(pt, pt);
+        }
+        desc.glyphTx.transform(pt, pt);
+        pt.x -= desc.glyphTx.getTranslateX();
+        pt.y -= desc.glyphTx.getTranslateY();
+
+        if (!useFractionalMetrics()) {
+            pt.x = Math.round(pt.x);
+            pt.y = Math.round(pt.y);
+        }
+
+        return pt;
+    }
+
+    Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) {
+        GeneralPath gp = getGlyphOutline(glyphCode, 0f, 0f);
+        Rectangle2D r2d = gp.getBounds2D();
+        Rectangle2D.Float r2df;
+        if (r2d instanceof Rectangle2D.Float) {
+            r2df = (Rectangle2D.Float)r2d;
+        } else {
+            float x = (float)r2d.getX();
+            float y = (float)r2d.getY();
+            float w = (float)r2d.getWidth();
+            float h = (float)r2d.getHeight();
+            r2df = new Rectangle2D.Float(x, y, w, h);
+        }
+        return r2df;
+    }
+
+    // pt, result in device space
+    void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
+        Rectangle2D.Float floatRect = new Rectangle2D.Float();
+
+        if (invDevTx != null) {
+            invDevTx.transform(pt, pt);
+        }
+
+        getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);
+
+        if (floatRect.width == 0 && floatRect.height == 0) {
+            result.setRect(0, 0, -1, -1);
+            return;
+        }
+
+        result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
+    }
+
+    private void getGlyphImageBounds(int glyphCode, float x, float y, Rectangle2D.Float floatRect) {
+        getNativeGlyphImageBounds(getNativeStrikePtr(), glyphCode, floatRect, x, y);
+    }
+
+    GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
+        return getNativeGlyphOutline(getNativeStrikePtr(), glyphCode, x, y);
+    }
+
+    // should implement, however not called though any path that is publicly exposed
+    GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) {
+        throw new Error("not implemented yet");
+    }
+
+    // called from the Sun2D renderer
+    long getGlyphImagePtr(int glyphCode) {
+        synchronized (glyphInfoCache) {
+            long ptr = glyphInfoCache.get(glyphCode);
+            if (ptr != 0L) return ptr;
+
+            long[] ptrs = new long[1];
+            int[] codes = new int[1];
+            codes[0] = glyphCode;
+
+            getGlyphImagePtrs(codes, ptrs, 1);
+
+            ptr = ptrs[0];
+            glyphInfoCache.put(glyphCode, ptr);
+
+            return ptr;
+        }
+    }
+
+    // called from the Sun2D renderer
+    void getGlyphImagePtrs(int[] glyphCodes, long[] images, int len) {
+        synchronized (glyphInfoCache) {
+            // fill the image pointer array with existing pointers
+            // from the cache
+            int missed = 0;
+            for (int i = 0; i < len; i++) {
+                int code = glyphCodes[i];
+
+                final long ptr = glyphInfoCache.get(code);
+                if (ptr != 0L) {
+                    images[i] = ptr;
+                } else {
+                    // zero this element out, because the caller does not
+                    // promise to keep it clean
+                    images[i] = 0L;
+                    missed++;
+                }
+            }
+
+            if (missed == 0) {
+                return; // horray! we got away without touching native!
+            }
+
+            // all distinct glyph codes requested (partially filled)
+            final int[] filteredCodes = new int[missed];
+            // indices into filteredCodes array (totally filled)
+            final int[] filteredIndicies = new int[missed];
+
+            // scan, mark, and store the requested glyph codes again to
+            // send into native
+            int j = 0;
+            int dupes = 0;
+            for (int i = 0; i < len; i++) {
+                if (images[i] != 0L) continue; // already filled
+
+                final int code = glyphCodes[i];
+
+                // we have already promised to strike this glyph - this is
+                // a dupe
+                if (glyphInfoCache.get(code) == -1L) {
+                    filteredIndicies[j] = -1;
+                    dupes++;
+                    j++;
+                    continue;
+                }
+
+                // this is a distinct glyph we have not struck before, or
+                // promised to strike mark this one as "promise to strike"
+                // in the global cache with a -1L
+                final int k = j - dupes;
+                filteredCodes[k] = code;
+                glyphInfoCache.put(code, -1L);
+                filteredIndicies[j] = k;
+                j++;
+            }
+
+            final int filteredRunLen = j - dupes;
+            final long[] filteredImages = new long[filteredRunLen];
+
+            // bulk call to fill in the distinct glyph pointers from native
+            getFilteredGlyphImagePtrs(filteredImages, filteredCodes, filteredRunLen);
+
+            // scan the requested glyph list, and fill in pointers from our
+            // distinct glyph list which has been filled from native
+            j = 0;
+            for (int i = 0; i < len; i++) {
+                if (images[i] != 0L && images[i] != -1L) {
+                    continue; // already placed
+                }
+
+                // index into filteredImages array
+                final int k = filteredIndicies[j];
+                final int code = glyphCodes[i];
+                if (k == -1L) {
+                    // we should have already filled the cache with this pointer
+                    images[i] = glyphInfoCache.get(code);
+                } else {
+                    // fill the particular glyph code request, and store
+                    // in the cache
+                    final long ptr = filteredImages[k];
+                    images[i] = ptr;
+                    glyphInfoCache.put(code, ptr);
+                }
+
+                j++;
+            }
+        }
+    }
+
+    private void getFilteredGlyphImagePtrs(long[] glyphInfos,
+                                           int[] uniCodes, int len)
+    {
+        getGlyphImagePtrsNative(getNativeStrikePtr(), glyphInfos, uniCodes, len);
+    }
+
+    private float getCachedNativeGlyphAdvance(int glyphCode) {
+        synchronized(glyphAdvanceCache) {
+            float advance = glyphAdvanceCache.get(glyphCode);
+            if (advance != 0) {
+                return advance;
+            }
+
+            advance = getNativeGlyphAdvance(getNativeStrikePtr(), glyphCode);
+            glyphAdvanceCache.put(glyphCode, advance);
+            return advance;
+        }
+    }
+
+    // This class stores glyph pointers, and is indexed based on glyph codes,
+    // and negative unicode values.  See the comments in
+    // CCharToGlyphMapper for more details on our glyph code strategy.
+    private static class GlyphInfoCache extends CStrikeDisposer {
+        private static final int FIRST_LAYER_SIZE = 256;
+        private static final int SECOND_LAYER_SIZE = 16384; // 16384 = 128x128
+
+        // rdar://problem/5204197
+        private boolean disposed = false;
+
+        private final long[] firstLayerCache;
+        private SparseBitShiftingTwoLayerArray secondLayerCache;
+        private HashMap<Integer, Long> generalCache;
+
+        public GlyphInfoCache(final Font2D nativeFont,
+                              final FontStrikeDesc desc)
+        {
+            super(nativeFont, desc);
+            firstLayerCache = new long[FIRST_LAYER_SIZE];
+        }
+
+        public synchronized long get(final int index) {
+            if (index < 0) {
+                if (-index < SECOND_LAYER_SIZE) {
+                    // catch common unicodes
+                    if (secondLayerCache == null) {
+                        return 0L;
+                    }
+                    return secondLayerCache.get(-index);
+                }
+            } else {
+                if (index < FIRST_LAYER_SIZE) {
+                    // catch common glyphcodes
+                    return firstLayerCache[index];
+                }
+            }
+
+            if (generalCache == null) {
+                return 0L;
+            }
+            final Long value = generalCache.get(new Integer(index));
+            if (value == null) {
+                return 0L;
+            }
+            return value.longValue();
+        }
+
+        public synchronized void put(final int index, final long value) {
+            if (index < 0) {
+                if (-index < SECOND_LAYER_SIZE) {
+                    // catch common unicodes
+                    if (secondLayerCache == null) {
+                        secondLayerCache = new SparseBitShiftingTwoLayerArray(SECOND_LAYER_SIZE, 7); // 128x128
+                    }
+                    secondLayerCache.put(-index, value);
+                    return;
+                }
+            } else {
+                if (index < FIRST_LAYER_SIZE) {
+                    // catch common glyphcodes
+                    firstLayerCache[index] = value;
+                    return;
+                }
+            }
+
+            if (generalCache == null) {
+                generalCache = new HashMap<Integer, Long>();
+            }
+
+            generalCache.put(new Integer(index), new Long(value));
+        }
+
+        public synchronized void dispose() {
+            // rdar://problem/5204197
+            // Note that sun.font.Font2D.getStrike() actively disposes
+            // cleared strikeRef.  We need to check the disposed flag to
+            // prevent double frees of native resources.
+            if (disposed) {
+                return;
+            }
+
+            super.dispose();
+
+            // clean out the first array
+            disposeLongArray(firstLayerCache);
+
+            // clean out the two layer arrays
+            if (secondLayerCache != null) {
+                final long[][] secondLayerLongArrayArray = secondLayerCache.cache;
+                for (int i = 0; i < secondLayerLongArrayArray.length; i++) {
+                    final long[] longArray = secondLayerLongArrayArray[i];
+                    if (longArray != null) disposeLongArray(longArray);
+                }
+            }
+
+            // clean up everyone else
+            if (generalCache != null) {
+                final Iterator<Long> i = generalCache.values().iterator();
+                while (i.hasNext()) {
+                    final long longValue = i.next().longValue();
+                    if (longValue != -1 && longValue != 0) StrikeCache.freeLongPointer(longValue);
+                }
+            }
+
+            // rdar://problem/5204197
+            // Finally, set the flag.
+            disposed = true;
+        }
+
+        private static void disposeLongArray(final long[] longArray) {
+            for (int i = 0; i < longArray.length; i++) {
+                final long ptr = longArray[i];
+                if (ptr != 0 && ptr != -1) StrikeCache.freeLongPointer(ptr); // free's the native struct pointer
+            }
+        }
+
+        private static class SparseBitShiftingTwoLayerArray {
+            final long[][] cache;
+            final int shift;
+            final int secondLayerLength;
+
+            public SparseBitShiftingTwoLayerArray(final int size, final int shift) {
+                this.shift = shift;
+                this.cache = new long[1 << shift][];
+                this.secondLayerLength = size >> shift;
+            }
+
+            public long get(final int index) {
+                final int firstIndex = index >> shift;
+                final long[] firstLayerRow = cache[firstIndex];
+                if (firstLayerRow == null) return 0L;
+                return firstLayerRow[index - (firstIndex * (1 << shift))];
+            }
+
+            public void put(final int index, final long value) {
+                final int firstIndex = index >> shift;
+                long[] firstLayerRow = cache[firstIndex];
+                if (firstLayerRow == null) {
+                    cache[firstIndex] = firstLayerRow = new long[secondLayerLength];
+                }
+                firstLayerRow[index - (firstIndex * (1 << shift))] = value;
+            }
+        }
+    }
+
+    private static class GlyphAdvanceCache {
+        private static final int FIRST_LAYER_SIZE = 256;
+        private static final int SECOND_LAYER_SIZE = 16384; // 16384 = 128x128
+
+        private final float[] firstLayerCache = new float[FIRST_LAYER_SIZE];
+        private SparseBitShiftingTwoLayerArray secondLayerCache;
+        private HashMap<Integer, Float> generalCache;
+
+        public synchronized float get(final int index) {
+            if (index < 0) {
+                if (-index < SECOND_LAYER_SIZE) {
+                    // catch common unicodes
+                    if (secondLayerCache == null) return 0;
+                    return secondLayerCache.get(-index);
+                }
+            } else {
+                if (index < FIRST_LAYER_SIZE) {
+                    // catch common glyphcodes
+                    return firstLayerCache[index];
+                }
+            }
+
+            if (generalCache == null) return 0;
+            final Float value = generalCache.get(new Integer(index));
+            if (value == null) return 0;
+            return value.floatValue();
+        }
+
+        public synchronized void put(final int index, final float value) {
+            if (index < 0) {
+                if (-index < SECOND_LAYER_SIZE) {
+                    // catch common unicodes
+                    if (secondLayerCache == null) {
+                        secondLayerCache = new SparseBitShiftingTwoLayerArray(SECOND_LAYER_SIZE, 7); // 128x128
+                    }
+                    secondLayerCache.put(-index, value);
+                    return;
+                }
+            } else {
+                if (index < FIRST_LAYER_SIZE) {
+                    // catch common glyphcodes
+                    firstLayerCache[index] = value;
+                    return;
+                }
+            }
+
+            if (generalCache == null) {
+                generalCache = new HashMap<Integer, Float>();
+            }
+
+            generalCache.put(new Integer(index), new Float(value));
+        }
+
+        private static class SparseBitShiftingTwoLayerArray {
+            final float[][] cache;
+            final int shift;
+            final int secondLayerLength;
+
+            public SparseBitShiftingTwoLayerArray(final int size,
+                                                  final int shift)
+            {
+                this.shift = shift;
+                this.cache = new float[1 << shift][];
+                this.secondLayerLength = size >> shift;
+            }
+
+            public float get(final int index) {
+                final int firstIndex = index >> shift;
+                final float[] firstLayerRow = cache[firstIndex];
+                if (firstLayerRow == null) return 0L;
+                return firstLayerRow[index - (firstIndex * (1 << shift))];
+            }
+
+            public void put(final int index, final float value) {
+                final int firstIndex = index >> shift;
+                float[] firstLayerRow = cache[firstIndex];
+                if (firstLayerRow == null) {
+                    cache[firstIndex] = firstLayerRow =
+                        new float[secondLayerLength];
+                }
+                firstLayerRow[index - (firstIndex * (1 << shift))] = value;
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/font/CStrikeDisposer.java b/jdk/src/macosx/classes/sun/font/CStrikeDisposer.java
new file mode 100644
index 0000000..7357ea6
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/font/CStrikeDisposer.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.font;
+
+/*
+ * This keeps track of data that needs to be cleaned up once a
+ * strike is freed.
+ * a) The native memory that is the glyph image cache.
+ * b) removing the "desc" key from the strike's map.
+ * This is safe to do because this disposer is invoked only when the
+ * reference object has been cleared, which means the value indexed by
+ * this key is just an empty reference object.
+ * It is possible that a new FontStrike has been created that would
+ * be referenced by the same (equals) key. If it is placed in the map
+ * before this disposer is executed, then we do not want to remove that
+ * object. We should only remove an object where the value is null.
+ * So we first verify that the key still points to a cleared reference.
+ * Updates to the map thus need to be synchronized.
+ *
+ * A WeakHashmap will automatically clean up, but we might maintain a
+ * reference to the "desc" key in the FontStrike (value) which would
+ * prevent the keys from being discarded. And since the strike is the only
+ * place is likely we would maintain such a strong reference, then the map
+ * entries would be removed much more promptly than we need.
+ */
+class CStrikeDisposer extends FontStrikeDisposer {
+
+    long pNativeScalerContext;
+
+    public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc,
+                               long pContext, int[] images)
+    {
+        super(font2D, desc, 0L, images);
+        pNativeScalerContext = pContext;
+    }
+
+    public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc,
+                               long pContext, long[] images)
+    {
+        super(font2D, desc, 0L, images);
+        pNativeScalerContext = pContext;
+    }
+
+    public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc,
+                               long pContext)
+    {
+        super(font2D, desc, 0L);
+        pNativeScalerContext = pContext;
+    }
+
+    public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc) {
+        super(font2D, desc);
+    }
+
+    public synchronized void dispose() {
+        if (!disposed) {
+            if (pNativeScalerContext != 0L) {
+                freeNativeScalerContext(pNativeScalerContext);
+            }
+            super.dispose();
+        }
+    }
+
+    private native void freeNativeScalerContext(long pContext);
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/BackBufferCapsProvider.java b/jdk/src/macosx/classes/sun/java2d/BackBufferCapsProvider.java
new file mode 100644
index 0000000..155550f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/BackBufferCapsProvider.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import java.awt.BufferCapabilities;
+
+/**
+ * Provides access to back-buffer's BufferCapabilities.
+ */
+public interface BackBufferCapsProvider {
+    public BufferCapabilities getBackBufferCaps();
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/CRenderer.java b/jdk/src/macosx/classes/sun/java2d/CRenderer.java
new file mode 100644
index 0000000..e26cdce
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/CRenderer.java
@@ -0,0 +1,646 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.image.*;
+import java.nio.*;
+
+import sun.awt.image.*;
+import sun.java2d.loops.*;
+import sun.java2d.pipe.*;
+import sun.lwawt.macosx.*;
+
+public class CRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe, DrawImagePipe {
+    native static void init();
+
+    // cache of the runtime options
+    static {
+        init(); // initialize coordinate tables for shapes
+    }
+
+    native void doLine(SurfaceData sData, float x1, float y1, float x2, float y2);
+
+    public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
+        drawLine(sg2d, (float) x1, (float) y1, (float) x2, (float) y2);
+    }
+
+    Line2D lineToShape;
+
+    public void drawLine(SunGraphics2D sg2d, float x1, float y1, float x2, float y2) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            surfaceData.doLine(this, sg2d, x1, y1, x2, y2);
+        } else {
+            if (lineToShape == null) {
+                synchronized (this) {
+                    if (lineToShape == null) {
+                        lineToShape = new Line2D.Float();
+                    }
+                }
+            }
+            synchronized (lineToShape) {
+                lineToShape.setLine(x1, y1, x2, y2);
+                drawfillShape(sg2d, sg2d.stroke.createStrokedShape(lineToShape), true, true);
+            }
+        }
+    }
+
+    native void doRect(SurfaceData sData, float x, float y, float width, float height, boolean isfill);
+
+    public void drawRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        drawRect(sg2d, (float) x, (float) y, (float) width, (float) height);
+    }
+
+    Rectangle2D rectToShape;
+
+    public void drawRect(SunGraphics2D sg2d, float x, float y, float width, float height) {
+        if ((width < 0) || (height < 0)) return;
+
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            surfaceData.doRect(this, sg2d, x, y, width, height, false);
+        } else {
+            if (rectToShape == null) {
+                synchronized (this) {
+                    if (rectToShape == null) {
+                        rectToShape = new Rectangle2D.Float();
+                    }
+                }
+            }
+            synchronized (rectToShape) {
+                rectToShape.setRect(x, y, width, height);
+                drawfillShape(sg2d, sg2d.stroke.createStrokedShape(rectToShape), true, true);
+            }
+        }
+    }
+
+    public void fillRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        fillRect(sg2d, (float) x, (float) y, (float) width, (float) height);
+    }
+
+    public void fillRect(SunGraphics2D sg2d, float x, float y, float width, float height) {
+        if ((width >= 0) && (height >= 0)) {
+            OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+            surfaceData.doRect(this, sg2d, x, y, width, height, true);
+        }
+    }
+
+    native void doRoundRect(SurfaceData sData, float x, float y, float width, float height, float arcW, float arcH, boolean isfill);
+
+    public void drawRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
+        drawRoundRect(sg2d, (float) x, (float) y, (float) width, (float) height, (float) arcWidth, (float) arcHeight);
+    }
+
+    RoundRectangle2D roundrectToShape;
+
+    public void drawRoundRect(SunGraphics2D sg2d, float x, float y, float width, float height, float arcWidth, float arcHeight) {
+        if ((width < 0) || (height < 0)) return;
+
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            surfaceData.doRoundRect(this, sg2d, x, y, width, height, arcWidth, arcHeight, false);
+        } else {
+            if (roundrectToShape == null) {
+                synchronized (this) {
+                    if (roundrectToShape == null) {
+                        roundrectToShape = new RoundRectangle2D.Float();
+                    }
+                }
+            }
+            synchronized (roundrectToShape) {
+                roundrectToShape.setRoundRect(x, y, width, height, arcWidth, arcHeight);
+                drawfillShape(sg2d, sg2d.stroke.createStrokedShape(roundrectToShape), true, true);
+            }
+        }
+    }
+
+    public void fillRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
+        fillRoundRect(sg2d, (float) x, (float) y, (float) width, (float) height, (float) arcWidth, (float) arcHeight);
+    }
+
+    public void fillRoundRect(SunGraphics2D sg2d, float x, float y, float width, float height, float arcWidth, float arcHeight) {
+        if ((width < 0) || (height < 0)) return;
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        surfaceData.doRoundRect(this, sg2d, x, y, width, height, arcWidth, arcHeight, true);
+    }
+
+    native void doOval(SurfaceData sData, float x, float y, float width, float height, boolean isfill);
+
+    public void drawOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        drawOval(sg2d, (float) x, (float) y, (float) width, (float) height);
+    }
+
+    Ellipse2D ovalToShape;
+
+    public void drawOval(SunGraphics2D sg2d, float x, float y, float width, float height) {
+        if ((width < 0) || (height < 0)) return;
+
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            surfaceData.doOval(this, sg2d, x, y, width, height, false);
+        } else {
+            if (ovalToShape == null) {
+                synchronized (this) {
+                    if (ovalToShape == null) {
+                        ovalToShape = new Ellipse2D.Float();
+                    }
+                }
+            }
+            synchronized (ovalToShape) {
+                ovalToShape.setFrame(x, y, width, height);
+                drawfillShape(sg2d, sg2d.stroke.createStrokedShape(ovalToShape), true, true);
+            }
+        }
+    }
+
+    public void fillOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        fillOval(sg2d, (float) x, (float) y, (float) width, (float) height);
+    }
+
+    public void fillOval(SunGraphics2D sg2d, float x, float y, float width, float height) {
+        if ((width < 0) || (height < 0)) return;
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        surfaceData.doOval(this, sg2d, x, y, width, height, true);
+    }
+
+    native void doArc(SurfaceData sData, float x, float y, float width, float height, float angleStart, float angleExtent, int type, boolean isfill);
+
+    public void drawArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
+        drawArc(sg2d, x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
+    }
+
+    Arc2D arcToShape;
+
+    public void drawArc(SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type) {
+        if ((width < 0) || (height < 0)) return;
+
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            surfaceData.doArc(this, sg2d, x, y, width, height, startAngle, arcAngle, type, false);
+        } else {
+            if (arcToShape == null) {
+                synchronized (this) {
+                    if (arcToShape == null) {
+                        arcToShape = new Arc2D.Float();
+                    }
+                }
+            }
+            synchronized (arcToShape) {
+                arcToShape.setArc(x, y, width, height, startAngle, arcAngle, type);
+                drawfillShape(sg2d, sg2d.stroke.createStrokedShape(arcToShape), true, true);
+            }
+        }
+    }
+
+    public void fillArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
+        fillArc(sg2d, x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
+    }
+
+    public void fillArc(SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type) {
+        if ((width < 0) || (height < 0)) return;
+
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        surfaceData.doArc(this, sg2d, x, y, width, height, startAngle, arcAngle, type, true);
+    }
+
+    native void doPoly(SurfaceData sData, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill);
+
+    public void drawPolyline(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, false, false);
+        } else {
+            GeneralPath polyToShape = new GeneralPath();
+            polyToShape.moveTo(xpoints[0], ypoints[0]);
+            for (int i = 1; i < npoints; i++) {
+                polyToShape.lineTo(xpoints[i], ypoints[i]);
+            }
+            drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
+        }
+    }
+
+    public void drawPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, false);
+        } else {
+            GeneralPath polyToShape = new GeneralPath();
+            polyToShape.moveTo(xpoints[0], ypoints[0]);
+            for (int i = 1; i < npoints; i++) {
+                polyToShape.lineTo(xpoints[i], ypoints[i]);
+            }
+            polyToShape.lineTo(xpoints[0], ypoints[0]);
+            drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
+        }
+    }
+
+    public void fillPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, true);
+    }
+
+    native void doShape(SurfaceData sData, int length, FloatBuffer coordinates, IntBuffer types, int windingRule, boolean isfill, boolean shouldApplyOffset);
+
+    void drawfillShape(SunGraphics2D sg2d, Shape s, boolean isfill, boolean shouldApplyOffset) {
+        if (s == null) { throw new NullPointerException(); }
+
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        // TODO:
+        boolean sOptimizeShapes = true;
+        if (sOptimizeShapes && OSXSurfaceData.IsSimpleColor(sg2d.paint)) {
+            if (s instanceof Rectangle2D) {
+                Rectangle2D rectangle = (Rectangle2D) s;
+
+                float x = (float) rectangle.getX();
+                float y = (float) rectangle.getY();
+                float w = (float) rectangle.getWidth();
+                float h = (float) rectangle.getHeight();
+                if (isfill) {
+                    fillRect(sg2d, x, y, w, h);
+                } else {
+                    drawRect(sg2d, x, y, w, h);
+                }
+            } else if (s instanceof Ellipse2D) {
+                Ellipse2D ellipse = (Ellipse2D) s;
+
+                float x = (float) ellipse.getX();
+                float y = (float) ellipse.getY();
+                float w = (float) ellipse.getWidth();
+                float h = (float) ellipse.getHeight();
+
+                if (isfill) {
+                    fillOval(sg2d, x, y, w, h);
+                } else {
+                    drawOval(sg2d, x, y, w, h);
+                }
+            } else if (s instanceof Arc2D) {
+                Arc2D arc = (Arc2D) s;
+
+                float x = (float) arc.getX();
+                float y = (float) arc.getY();
+                float w = (float) arc.getWidth();
+                float h = (float) arc.getHeight();
+                float as = (float) arc.getAngleStart();
+                float ae = (float) arc.getAngleExtent();
+
+                if (isfill) {
+                    fillArc(sg2d, x, y, w, h, as, ae, arc.getArcType());
+                } else {
+                    drawArc(sg2d, x, y, w, h, as, ae, arc.getArcType());
+                }
+            } else if (s instanceof RoundRectangle2D) {
+                RoundRectangle2D roundrect = (RoundRectangle2D) s;
+
+                float x = (float) roundrect.getX();
+                float y = (float) roundrect.getY();
+                float w = (float) roundrect.getWidth();
+                float h = (float) roundrect.getHeight();
+                float aw = (float) roundrect.getArcWidth();
+                float ah = (float) roundrect.getArcHeight();
+
+                if (isfill) {
+                    fillRoundRect(sg2d, x, y, w, h, aw, ah);
+                } else {
+                    drawRoundRect(sg2d, x, y, w, h, aw, ah);
+                }
+            } else if (s instanceof Line2D) {
+                Line2D line = (Line2D) s;
+
+                float x1 = (float) line.getX1();
+                float y1 = (float) line.getY1();
+                float x2 = (float) line.getX2();
+                float y2 = (float) line.getY2();
+
+                drawLine(sg2d, x1, y1, x2, y2);
+            } else if (s instanceof Point2D) {
+                Point2D point = (Point2D) s;
+
+                float x = (float) point.getX();
+                float y = (float) point.getY();
+
+                drawLine(sg2d, x, y, x, y);
+            } else {
+                GeneralPath gp;
+
+                if (s instanceof GeneralPath) {
+                    gp = (GeneralPath) s;
+                } else {
+                    gp = new GeneralPath(s);
+                }
+
+                PathIterator pi = gp.getPathIterator(null);
+                if (pi.isDone() == false) {
+                    surfaceData.drawfillShape(this, sg2d, gp, isfill, shouldApplyOffset);
+                }
+            }
+        } else {
+            GeneralPath gp;
+
+            if (s instanceof GeneralPath) {
+                gp = (GeneralPath) s;
+            } else {
+                gp = new GeneralPath(s);
+            }
+
+            PathIterator pi = gp.getPathIterator(null);
+            if (pi.isDone() == false) {
+                surfaceData.drawfillShape(this, sg2d, gp, isfill, shouldApplyOffset);
+            }
+        }
+    }
+
+    public void draw(SunGraphics2D sg2d, Shape s) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+        if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
+            drawfillShape(sg2d, s, false, true);
+        } else {
+            drawfillShape(sg2d, sg2d.stroke.createStrokedShape(s), true, true);
+        }
+    }
+
+    public void fill(SunGraphics2D sg2d, Shape s) {
+        drawfillShape(sg2d, s, true, false);
+    }
+
+    native void doImage(SurfaceData sData, SurfaceData img, boolean fliph, boolean flipv, int w, int h, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh);
+
+    // Copy img to scaled sg2d @ x,y with width height
+    public boolean scaleImage(SunGraphics2D sg2d, Image img, int x, int y, int width, int height, Color bgColor) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+
+        int sx = 0;
+        int sy = 0;
+        int iw = img.getWidth(null);
+        int ih = img.getHeight(null);
+
+        return scaleImage(sg2d, img, x, y, x + width, y + height, sx, sy, sx + iw, sy + ih, bgColor);
+    }
+
+    // Copy img, clipped to sx1, sy1 by sx2, sy2 to dx1, dy2 by dx2, dy2
+    public boolean scaleImage(SunGraphics2D sg2d, Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor) {
+
+        // System.err.println("scaleImage");
+        // System.err.println("    sx1="+sx1+", sy1="+sy1+", sx2="+sx2+", sy2="+sy2);
+        // System.err.println("    dx1="+dx1+", dy1="+dy1+", dx2="+dx2+", dy2="+dy2);
+
+        int srcW, srcH, dstW, dstH;
+        int srcX, srcY, dstX, dstY;
+        boolean srcWidthFlip = false;
+        boolean srcHeightFlip = false;
+        boolean dstWidthFlip = false;
+        boolean dstHeightFlip = false;
+
+        if (sx2 > sx1) {
+            srcW = sx2 - sx1;
+            srcX = sx1;
+        } else {
+            srcWidthFlip = true;
+            srcW = sx1 - sx2;
+            srcX = sx2;
+        }
+        if (sy2 > sy1) {
+            srcH = sy2 - sy1;
+            srcY = sy1;
+        } else {
+            srcHeightFlip = true;
+            srcH = sy1 - sy2;
+            srcY = sy2;
+        }
+        if (dx2 > dx1) {
+            dstW = dx2 - dx1;
+            dstX = dx1;
+        } else {
+            dstW = dx1 - dx2;
+            dstWidthFlip = true;
+            dstX = dx2;
+        }
+        if (dy2 > dy1) {
+            dstH = dy2 - dy1;
+            dstY = dy1;
+        } else {
+            dstH = dy1 - dy2;
+            dstHeightFlip = true;
+            dstY = dy2;
+        }
+        if (srcW <= 0 || srcH <= 0) { return true; }
+
+        boolean flipv = (srcHeightFlip != dstHeightFlip);
+        boolean fliph = (srcWidthFlip != dstWidthFlip);
+
+        return blitImage(sg2d, img, fliph, flipv, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH, bgColor);
+    }
+
+    protected boolean blitImage(SunGraphics2D sg2d, Image img, boolean fliph, boolean flipv, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, Color bgColor) {
+        CPrinterSurfaceData surfaceData = (CPrinterSurfaceData)sg2d.getSurfaceData();
+        OSXOffScreenSurfaceData imgSurfaceData = (OSXOffScreenSurfaceData) OSXOffScreenSurfaceData.createNewSurface((BufferedImage)img);
+        surfaceData.blitImage(this, sg2d, imgSurfaceData, fliph, flipv, sx, sy, sw, sh, dx, dy, dw, dh, bgColor);
+        return true;
+    }
+
+    // Copy img to sg2d @ x, y
+    protected boolean copyImage(SunGraphics2D sg2d, Image img, int dx, int dy, Color bgColor) {
+        if (img == null) { return true; }
+
+        int sx = 0;
+        int sy = 0;
+        int width = img.getWidth(null);
+        int height = img.getHeight(null);
+
+        return blitImage(sg2d, img, false, false, sx, sy, width, height, dx, dy, width, height, bgColor);
+    }
+
+    // Copy img, clipped to sx, sy with width, height to sg2d @ dx, dy
+    protected boolean copyImage(SunGraphics2D sg2d, Image img, int dx, int dy, int sx, int sy, int width, int height, Color bgColor) {
+        return blitImage(sg2d, img, false, false, sx, sy, width, height, dx, dy, width, height, bgColor);
+    }
+
+    protected void transformImage(SunGraphics2D sg2d, Image img, int x, int y, BufferedImageOp op, AffineTransform xf, Color bgColor) {
+        if (img != null) {
+            int iw = img.getWidth(null);
+            int ih = img.getHeight(null);
+
+            if ((op != null) && (img instanceof BufferedImage)) {
+                if (((BufferedImage) img).getType() == BufferedImage.TYPE_CUSTOM) {
+                    // BufferedImageOp can not handle custom images
+                    BufferedImage dest = null;
+                    dest = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB_PRE);
+                    Graphics g = dest.createGraphics();
+                    g.drawImage(img, 0, 0, null);
+                    g.dispose();
+                    img = op.filter(dest, null);
+                } else {
+                    // sun.awt.image.BufImgSurfaceData.createData((BufferedImage)img).finishLazyDrawing();
+                    img = op.filter((BufferedImage) img, null);
+                }
+
+                iw = img.getWidth(null);
+                ih = img.getHeight(null);
+            }
+
+            if (xf != null) {
+                AffineTransform reset = sg2d.getTransform();
+                sg2d.transform(xf);
+                scaleImage(sg2d, img, x, y, x + iw, y + ih, 0, 0, iw, ih, bgColor);
+                sg2d.setTransform(reset);
+            } else {
+                scaleImage(sg2d, img, x, y, x + iw, y + ih, 0, 0, iw, ih, bgColor);
+            }
+        } else {
+            throw new NullPointerException();
+        }
+    }
+
+    // copied from DrawImage.java
+    protected boolean imageReady(sun.awt.image.ToolkitImage sunimg, ImageObserver observer) {
+        if (sunimg.hasError()) {
+            if (observer != null) {
+                observer.imageUpdate(sunimg, ImageObserver.ERROR | ImageObserver.ABORT, -1, -1, -1, -1);
+            }
+            return false;
+        }
+        return true;
+    }
+
+    // copied from DrawImage.java
+    public boolean copyImage(SunGraphics2D sg2d, Image img, int x, int y, Color bgColor, ImageObserver observer) {
+        if (img == null) { throw new NullPointerException(); }
+
+        if (!(img instanceof sun.awt.image.ToolkitImage)) { return copyImage(sg2d, img, x, y, bgColor); }
+
+        sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
+        if (!imageReady(sunimg, observer)) { return false; }
+        ImageRepresentation ir = sunimg.getImageRep();
+        return ir.drawToBufImage(sg2d, sunimg, x, y, bgColor, observer);
+    }
+
+    // copied from DrawImage.java
+    public boolean copyImage(SunGraphics2D sg2d, Image img, int dx, int dy, int sx, int sy, int width, int height, Color bgColor, ImageObserver observer) {
+        if (img == null) { throw new NullPointerException(); }
+
+        if (!(img instanceof sun.awt.image.ToolkitImage)) { return copyImage(sg2d, img, dx, dy, sx, sy, width, height, bgColor); }
+
+        sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
+        if (!imageReady(sunimg, observer)) { return false; }
+        ImageRepresentation ir = sunimg.getImageRep();
+        return ir.drawToBufImage(sg2d, sunimg, dx, dy, (dx + width), (dy + height), sx, sy, (sx + width), (sy + height), null, observer);
+    }
+
+    // copied from DrawImage.java
+    public boolean scaleImage(SunGraphics2D sg2d, Image img, int x, int y, int width, int height, Color bgColor, ImageObserver observer) {
+        if (img == null) { throw new NullPointerException(); }
+
+        if (!(img instanceof sun.awt.image.ToolkitImage)) { return scaleImage(sg2d, img, x, y, width, height, bgColor); }
+
+        sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
+        if (!imageReady(sunimg, observer)) { return false; }
+        ImageRepresentation ir = sunimg.getImageRep();
+        return ir.drawToBufImage(sg2d, sunimg, x, y, width, height, bgColor, observer);
+    }
+
+    // copied from DrawImage.java
+    public boolean scaleImage(SunGraphics2D sg2d, Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver observer) {
+        if (img == null) { throw new NullPointerException(); }
+
+        if (!(img instanceof sun.awt.image.ToolkitImage)) { return scaleImage(sg2d, img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgColor); }
+
+        sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
+        if (!imageReady(sunimg, observer)) { return false; }
+        ImageRepresentation ir = sunimg.getImageRep();
+        return ir.drawToBufImage(sg2d, sunimg, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgColor, observer);
+    }
+
+    // copied from DrawImage.java
+    public boolean transformImage(SunGraphics2D sg2d, Image img, AffineTransform atfm, ImageObserver observer) {
+        if (img == null) { throw new NullPointerException(); }
+
+        if (!(img instanceof sun.awt.image.ToolkitImage)) {
+            transformImage(sg2d, img, 0, 0, null, atfm, null);
+            return true;
+        }
+
+        sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
+        if (!imageReady(sunimg, observer)) { return false; }
+        ImageRepresentation ir = sunimg.getImageRep();
+        return ir.drawToBufImage(sg2d, sunimg, atfm, observer);
+    }
+
+    // copied from DrawImage.java
+    public void transformImage(SunGraphics2D sg2d, BufferedImage img, BufferedImageOp op, int x, int y) {
+        if (img != null) {
+            transformImage(sg2d, img, x, y, op, null, null);
+        } else {
+            throw new NullPointerException();
+        }
+    }
+
+    public CRenderer traceWrap() {
+        return new Tracer();
+    }
+
+    public static class Tracer extends CRenderer {
+        void doLine(SurfaceData sData, float x1, float y1, float x2, float y2) {
+            GraphicsPrimitive.tracePrimitive("QuartzLine");
+            super.doLine(sData, x1, y1, x2, y2);
+        }
+
+        void doRect(SurfaceData sData, float x, float y, float width, float height, boolean isfill) {
+            GraphicsPrimitive.tracePrimitive("QuartzRect");
+            super.doRect(sData, x, y, width, height, isfill);
+        }
+
+        void doRoundRect(SurfaceData sData, float x, float y, float width, float height, float arcW, float arcH, boolean isfill) {
+            GraphicsPrimitive.tracePrimitive("QuartzRoundRect");
+            super.doRoundRect(sData, x, y, width, height, arcW, arcH, isfill);
+        }
+
+        void doOval(SurfaceData sData, float x, float y, float width, float height, boolean isfill) {
+            GraphicsPrimitive.tracePrimitive("QuartzOval");
+            super.doOval(sData, x, y, width, height, isfill);
+        }
+
+        void doArc(SurfaceData sData, float x, float y, float width, float height, float angleStart, float angleExtent, int type, boolean isfill) {
+            GraphicsPrimitive.tracePrimitive("QuartzArc");
+            super.doArc(sData, x, y, width, height, angleStart, angleExtent, type, isfill);
+        }
+
+        void doPoly(SurfaceData sData, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill) {
+            GraphicsPrimitive.tracePrimitive("QuartzDoPoly");
+            super.doPoly(sData, xpoints, ypoints, npoints, ispolygon, isfill);
+        }
+
+        void doShape(SurfaceData sData, int length, FloatBuffer coordinates, IntBuffer types, int windingRule, boolean isfill, boolean shouldApplyOffset) {
+            GraphicsPrimitive.tracePrimitive("QuartzFillOrDrawShape");
+            super.doShape(sData, length, coordinates, types, windingRule, isfill, shouldApplyOffset);
+        }
+
+        void doImage(SurfaceData sData, SurfaceData img, boolean fliph, boolean flipv, int w, int h, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) {
+            GraphicsPrimitive.tracePrimitive("QuartzDrawImage");
+            super.doImage(sData, img, fliph, flipv, w, h, sx, sy, sw, sh, dx, dy, dw, dh);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/CompositeCRenderer.java b/jdk/src/macosx/classes/sun/java2d/CompositeCRenderer.java
new file mode 100644
index 0000000..f7d6ab4
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/CompositeCRenderer.java
@@ -0,0 +1,437 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import java.awt.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.image.*;
+
+import sun.awt.image.*;
+import sun.java2d.loops.*;
+import sun.java2d.pipe.*;
+
+public class CompositeCRenderer extends CRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe, DrawImagePipe, TextPipe {
+    final static int fPadding = 4;
+    final static int fPaddingHalf = fPadding / 2;
+
+    private static AffineTransform sIdentityMatrix = new AffineTransform();
+
+    AffineTransform ShapeTM = new AffineTransform();
+    Rectangle2D ShapeBounds = new Rectangle2D.Float();
+
+    Line2D line = new Line2D.Float();
+    Rectangle2D rectangle = new Rectangle2D.Float();
+    RoundRectangle2D roundrectangle = new RoundRectangle2D.Float();
+    Ellipse2D ellipse = new Ellipse2D.Float();
+    Arc2D arc = new Arc2D.Float();
+
+    public synchronized void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
+        // create shape corresponding to this primitive
+        line.setLine(x1, y1, x2, y2);
+
+        draw(sg2d, line);
+    }
+
+    public synchronized void drawRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        // create shape corresponding to this primitive
+        rectangle.setRect(x, y, width, height);
+
+        draw(sg2d, rectangle);
+    }
+
+    public synchronized void drawRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
+        // create shape corresponding to this primitive
+        roundrectangle.setRoundRect(x, y, width, height, arcWidth, arcHeight);
+
+        draw(sg2d, roundrectangle);
+    }
+
+    public synchronized void drawOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        // create shape corresponding to this primitive
+        ellipse.setFrame(x, y, width, height);
+
+        draw(sg2d, ellipse);
+    }
+
+    public synchronized void drawArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
+        // create shape corresponding to this primitive
+        arc.setArc(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
+
+        draw(sg2d, arc);
+    }
+
+    public synchronized void drawPolyline(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
+        doPolygon(sg2d, xpoints, ypoints, npoints, false, false);
+    }
+
+    public synchronized void drawPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
+        doPolygon(sg2d, xpoints, ypoints, npoints, true, false);
+    }
+
+    public synchronized void fillRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        // create shape corresponding to this primitive
+        rectangle.setRect(x, y, width, height);
+
+        fill(sg2d, rectangle);
+    }
+
+    public synchronized void fillRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
+        // create shape corresponding to this primitive
+        roundrectangle.setRoundRect(x, y, width, height, arcWidth, arcHeight);
+
+        fill(sg2d, roundrectangle);
+    }
+
+    public synchronized void fillOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        // create shape corresponding to this primitive
+        ellipse.setFrame(x, y, width, height);
+
+        fill(sg2d, ellipse);
+    }
+
+    public synchronized void fillArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
+        // create shape corresponding to this primitive
+        arc.setArc(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
+
+        fill(sg2d, arc);
+    }
+
+    public synchronized void fillPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
+        doPolygon(sg2d, xpoints, ypoints, npoints, true, true);
+    }
+
+    public synchronized void doPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints, boolean ispolygon, boolean isfill) {
+        GeneralPath gp = new GeneralPath(Path2D.WIND_NON_ZERO, npoints);
+        gp.moveTo(xpoints[0], ypoints[0]);
+        for (int i = 1; i < npoints; i++) {
+            gp.lineTo(xpoints[i], ypoints[i]);
+        }
+        if (ispolygon) {
+            // according to the specs (only applies to polygons, not polylines)
+            if ((xpoints[0] != xpoints[npoints - 1]) || (ypoints[0] != ypoints[npoints - 1])) {
+                gp.lineTo(xpoints[0], ypoints[0]);
+            }
+        }
+
+        doShape(sg2d, (OSXSurfaceData) sg2d.getSurfaceData(), (Shape) gp, isfill);
+    }
+
+    public synchronized void draw(SunGraphics2D sg2d, Shape shape) {
+        doShape(sg2d, (OSXSurfaceData) sg2d.getSurfaceData(), shape, false);
+    }
+
+    public synchronized void fill(SunGraphics2D sg2d, Shape shape) {
+        doShape(sg2d, (OSXSurfaceData) sg2d.getSurfaceData(), shape, true);
+    }
+
+    void doShape(SunGraphics2D sg2d, OSXSurfaceData surfaceData, Shape shape, boolean isfill) {
+        Rectangle2D shapeBounds = shape.getBounds2D();
+
+        // We don't want to draw with negative width and height (CRender doesn't do it and Windows doesn't do it either)
+        // Drawing with negative w and h, can cause CG problems down the line <rdar://3960579> (vm)
+        if ((shapeBounds.getWidth() < 0) || (shapeBounds.getHeight() < 0)) { return; }
+
+        // get final destination compositing bounds (after all transformations if needed)
+        Rectangle2D compositingBounds = padBounds(sg2d, shape);
+
+        // constrain the bounds to be within surface bounds
+        clipBounds(sg2d, compositingBounds);
+
+        // if the compositing region is empty we skip all remaining compositing work:
+        if (compositingBounds.isEmpty() == false) {
+            BufferedImage srcPixels;
+            // create a matching surface into which we'll render the primitive to be composited
+            // with the desired dimension
+            srcPixels = surfaceData.getCompositingSrcImage((int) (compositingBounds.getWidth()),
+                    (int) (compositingBounds.getHeight()));
+
+            Graphics2D g = srcPixels.createGraphics();
+
+            // sync up graphics state
+            ShapeTM.setToTranslation(-compositingBounds.getX(), -compositingBounds.getY());
+            ShapeTM.concatenate(sg2d.transform);
+            g.setTransform(ShapeTM);
+            g.setRenderingHints(sg2d.getRenderingHints());
+            g.setPaint(sg2d.getPaint());
+            g.setStroke(sg2d.getStroke());
+
+            // render the primitive to be composited
+            if (isfill) {
+                g.fill(shape);
+            } else {
+                g.draw(shape);
+            }
+
+            g.dispose();
+
+            composite(sg2d, surfaceData, srcPixels, compositingBounds);
+        }
+    }
+
+    public synchronized void drawString(SunGraphics2D sg2d, String str, double x, double y) {
+        drawGlyphVector(sg2d, sg2d.getFont().createGlyphVector(sg2d.getFontRenderContext(), str), x, y);
+    }
+
+    public synchronized void drawChars(SunGraphics2D sg2d, char data[], int offset, int length, int x, int y) {
+        drawString(sg2d, new String(data, offset, length), x, y);
+    }
+
+    public synchronized void drawGlyphVector(SunGraphics2D sg2d, GlyphVector glyphVector, double x, double y) {
+        drawGlyphVector(sg2d, glyphVector, (float) x, (float) y);
+    }
+
+    public synchronized void drawGlyphVector(SunGraphics2D sg2d, GlyphVector glyphVector, float x, float y) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+
+        Shape shape = glyphVector.getOutline(x, y);
+
+        // get final destination compositing bounds (after all transformations if needed)
+        Rectangle2D compositingBounds = padBounds(sg2d, shape);
+
+        // constrain the bounds to be within surface bounds
+        clipBounds(sg2d, compositingBounds);
+
+        // if the compositing region is empty we skip all remaining compositing work:
+        if (compositingBounds.isEmpty() == false) {
+            BufferedImage srcPixels;
+            {
+                // create matching image into which we'll render the primitive to be composited
+                srcPixels = surfaceData.getCompositingSrcImage((int) compositingBounds.getWidth(), (int) compositingBounds.getHeight());
+
+                Graphics2D g = srcPixels.createGraphics();
+
+                // sync up graphics state
+                ShapeTM.setToTranslation(-compositingBounds.getX(), -compositingBounds.getY());
+                ShapeTM.concatenate(sg2d.transform);
+                g.setTransform(ShapeTM);
+                g.setPaint(sg2d.getPaint());
+                g.setStroke(sg2d.getStroke());
+                g.setFont(sg2d.getFont());
+                g.setRenderingHints(sg2d.getRenderingHints());
+
+                // render the primitive to be composited
+                g.drawGlyphVector(glyphVector, x, y);
+                g.dispose();
+            }
+
+            composite(sg2d, surfaceData, srcPixels, compositingBounds);
+        }
+    }
+
+    protected boolean blitImage(SunGraphics2D sg2d, Image img, boolean fliph, boolean flipv, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, Color bgColor) {
+        OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
+
+        // get final destination compositing bounds (after all transformations if needed)
+        dx = (flipv == false) ? dx : dx - dw;
+        dy = (fliph == false) ? dy : dy - dh;
+        ShapeBounds.setFrame(dx, dy, dw, dh);
+        Rectangle2D compositingBounds = ShapeBounds;
+        boolean complexTransform = (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE);
+        if (complexTransform == false) {
+            double newX = Math.floor(compositingBounds.getX() + sg2d.transX);
+            double newY = Math.floor(compositingBounds.getY() + sg2d.transY);
+            double newW = Math.ceil(compositingBounds.getWidth()) + (newX < compositingBounds.getX() ? 1 : 0);
+            double newH = Math.ceil(compositingBounds.getHeight()) + (newY < compositingBounds.getY() ? 1 : 0);
+            compositingBounds.setRect(newX, newY, newW, newH);
+        } else {
+            Shape transformedShape = sg2d.transform.createTransformedShape(compositingBounds);
+            compositingBounds = transformedShape.getBounds2D();
+            double newX = Math.floor(compositingBounds.getX());
+            double newY = Math.floor(compositingBounds.getY());
+            double newW = Math.ceil(compositingBounds.getWidth()) + (newX < compositingBounds.getX() ? 1 : 0);
+            double newH = Math.ceil(compositingBounds.getHeight()) + (newY < compositingBounds.getY() ? 1 : 0);
+            compositingBounds.setRect(newX, newY, newW, newH);
+        }
+
+        // constrain the bounds to be within surface bounds
+        clipBounds(sg2d, compositingBounds);
+
+        // if the compositing region is empty we skip all remaining compositing work:
+        if (compositingBounds.isEmpty() == false) {
+            BufferedImage srcPixels;
+            {
+                // create matching image into which we'll render the primitive to be composited
+                srcPixels = surfaceData.getCompositingSrcImage((int) compositingBounds.getWidth(), (int) compositingBounds.getHeight());
+
+                Graphics2D g = srcPixels.createGraphics();
+
+                // sync up graphics state
+                ShapeTM.setToTranslation(-compositingBounds.getX(), -compositingBounds.getY());
+                ShapeTM.concatenate(sg2d.transform);
+                g.setTransform(ShapeTM);
+                g.setRenderingHints(sg2d.getRenderingHints());
+                g.setComposite(AlphaComposite.Src);
+
+                int sx2 = (flipv == false) ? sx + sw : sx - sw;
+                int sy2 = (fliph == false) ? sy + sh : sy - sh;
+                g.drawImage(img, dx, dy, dx + dw, dy + dh, sx, sy, sx2, sy2, null);
+
+                g.dispose();
+            }
+
+            composite(sg2d, surfaceData, srcPixels, compositingBounds);
+        }
+
+        return true;
+    }
+
+    Rectangle2D padBounds(SunGraphics2D sg2d, Shape shape) {
+        shape = sg2d.transformShape(shape);
+
+        int paddingHalf = fPaddingHalf;
+        int padding = fPadding;
+        if (sg2d.stroke != null) {
+            if (sg2d.stroke instanceof BasicStroke) {
+                int width = (int) (((BasicStroke) sg2d.stroke).getLineWidth() + 0.5f);
+                int widthHalf = width / 2 + 1;
+                paddingHalf += widthHalf;
+                padding += 2 * widthHalf;
+            } else {
+                shape = sg2d.stroke.createStrokedShape(shape);
+            }
+        }
+        Rectangle2D bounds = shape.getBounds2D();
+        bounds.setRect(bounds.getX() - paddingHalf, bounds.getY() - paddingHalf, bounds.getWidth() + padding, bounds.getHeight() + padding);
+
+        double newX = Math.floor(bounds.getX());
+        double newY = Math.floor(bounds.getY());
+        double newW = Math.ceil(bounds.getWidth()) + (newX < bounds.getX() ? 1 : 0);
+        double newH = Math.ceil(bounds.getHeight()) + (newY < bounds.getY() ? 1 : 0);
+        bounds.setRect(newX, newY, newW, newH);
+
+        return bounds;
+    }
+
+    void clipBounds(SunGraphics2D sg2d, Rectangle2D bounds) {
+        /*
+         * System.err.println("clipBounds"); System.err.println("    transform="+sg2d.transform);
+         * System.err.println("    getTransform()="+sg2d.getTransform());
+         * System.err.println("    complexTransform="+(sg2d.transformState > SunGraphics2D.TRANSFORM_TRANSLATESCALE));
+         * System.err.println("    transX="+sg2d.transX+" transY="+sg2d.transX);
+         * System.err.println("    sg2d.constrainClip="+sg2d.constrainClip); if (sg2d.constrainClip != null) {
+         * System.err
+         * .println("    constrainClip: x="+sg2d.constrainClip.getLoX()+" y="+sg2d.constrainClip.getLoY()+" w="
+         * +sg2d.constrainClip.getWidth()+" h="+sg2d.constrainClip.getHeight());}
+         * System.err.println("    constrainX="+sg2d.constrainX+" constrainY="+sg2d.constrainY);
+         * System.err.println("    usrClip="+sg2d.usrClip);
+         * System.err.println("    devClip: x="+sg2d.devClip.getLoX()+" y="
+         * +sg2d.devClip.getLoY()+" w="+sg2d.devClip.getWidth()+" h="+sg2d.devClip.getHeight());
+         */
+        Region intersection = sg2d.clipRegion.getIntersectionXYWH((int) bounds.getX(), (int) bounds.getY(), (int) bounds.getWidth(), (int) bounds.getHeight());
+        bounds.setRect(intersection.getLoX(), intersection.getLoY(), intersection.getWidth(), intersection.getHeight());
+    }
+
+    BufferedImage getSurfacePixels(SunGraphics2D sg2d, OSXSurfaceData surfaceData, int x, int y, int w, int h) {
+        // create an image to copy the surface pixels into
+        BufferedImage dstInPixels = surfaceData.getCompositingDstInImage(w, h);
+
+        // get the pixels from the dst surface
+        return surfaceData.copyArea(sg2d, x, y, w, h, dstInPixels);
+    }
+
+    void composite(SunGraphics2D sg2d, OSXSurfaceData surfaceData, BufferedImage srcPixels, Rectangle2D compositingBounds) {
+        // Thread.dumpStack();
+        // System.err.println("composite");
+        // System.err.println("    compositingBounds="+compositingBounds);
+        int x = (int) compositingBounds.getX();
+        int y = (int) compositingBounds.getY();
+        int w = (int) compositingBounds.getWidth();
+        int h = (int) compositingBounds.getHeight();
+
+        boolean succeded = false;
+
+        Composite composite = sg2d.getComposite();
+        if (composite instanceof XORComposite) {
+            // 1st native XOR try
+            // we try to perform XOR using surface pixels directly
+            try {
+                succeded = surfaceData.xorSurfacePixels(sg2d, srcPixels, x, y, w, h, ((XORComposite) composite).getXorColor().getRGB());
+            } catch (Exception e) {
+                succeded = false;
+            }
+        }
+
+        if (succeded == false) {
+            // create image with the original pixels of surface
+            BufferedImage dstInPixels = getSurfacePixels(sg2d, surfaceData, x, y, w, h);
+            BufferedImage dstOutPixels = null;
+
+            if (composite instanceof XORComposite) {
+                // 2nd native XOR try
+                // we try to perform XOR on image's pixels (which were copied from surface first)
+                try {
+                    OSXSurfaceData osxsd = (OSXSurfaceData) (BufImgSurfaceData.createData(dstInPixels));
+                    succeded = osxsd.xorSurfacePixels(sg2d, srcPixels, 0, 0, w, h, ((XORComposite) composite).getXorColor().getRGB());
+                    dstOutPixels = dstInPixels;
+                } catch (Exception e) {
+                    succeded = false;
+                }
+            }
+
+            // either 2nd native XOR failed OR we have a case of custom compositing
+            if (succeded == false) {
+                // create an image into which we'll composite result: we MUST use a different destination (compositing
+                // is NOT "in place" operation)
+                dstOutPixels = surfaceData.getCompositingDstOutImage(w, h);
+
+                // prepare rasters for compositing
+                WritableRaster srcRaster = srcPixels.getRaster();
+                WritableRaster dstInRaster = dstInPixels.getRaster();
+                WritableRaster dstOutRaster = dstOutPixels.getRaster();
+
+                CompositeContext compositeContext = composite.createContext(srcPixels.getColorModel(), dstOutPixels.getColorModel(), sg2d.getRenderingHints());
+                compositeContext.compose(srcRaster, dstInRaster, dstOutRaster);
+                compositeContext.dispose();
+
+                // gznote: radar bug number
+                // "cut out" the shape we're interested in
+                // applyMask(BufImgSurfaceData.createData(dstOutPixels), BufImgSurfaceData.createData(srcPixels), w, h);
+            }
+
+            // blit the results back to the dst surface
+            Composite savedComposite = sg2d.getComposite();
+            AffineTransform savedTM = sg2d.getTransform();
+            int savedCX = sg2d.constrainX;
+            int savedCY = sg2d.constrainY;
+            {
+                sg2d.setComposite(AlphaComposite.SrcOver);
+                // all the compositing is done in the coordinate space of the component. the x and the y are the
+                // position of that component in the surface
+                // so we need to set the sg2d.transform to identity and we must set the contrainX/Y to 0 for the
+                // setTransform() to not be constrained
+                sg2d.constrainX = 0;
+                sg2d.constrainY = 0;
+                sg2d.setTransform(sIdentityMatrix);
+                sg2d.drawImage(dstOutPixels, x, y, x + w, y + h, 0, 0, w, h, null);
+            }
+            sg2d.constrainX = savedCX;
+            sg2d.constrainY = savedCY;
+            sg2d.setTransform(savedTM);
+            sg2d.setComposite(savedComposite);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/DataBufferNIOInt.java b/jdk/src/macosx/classes/sun/java2d/DataBufferNIOInt.java
new file mode 100644
index 0000000..e1c6039
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/DataBufferNIOInt.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import java.awt.image.DataBuffer;
+import java.nio.*;
+
+public final class DataBufferNIOInt extends DataBuffer {
+
+    /** The default data bank. */
+    IntBuffer data;
+
+    /** All data banks */
+    IntBuffer bankdata[];
+
+    /**
+     * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank
+     * and the specified size.
+     *
+     * @param size The size of the <CODE>DataBuffer</CODE>.
+     */
+    public DataBufferNIOInt(int size) {
+        super(TYPE_INT,size);
+        //+++gdb how to get sizeof(int) in java? Using 4 for now.
+        data = getBufferOfSize(size * 4).asIntBuffer();
+        bankdata = new IntBuffer[1];
+        bankdata[0] = data;
+    }
+
+    /**
+     * Returns the default (first) IntBuffer in <CODE>DataBuffer</CODE>.
+     *
+     * @return The first IntBuffer.
+     */
+    public IntBuffer getBuffer() {
+        return data;
+    }
+
+    /**
+     * Returns the Buffer for the specified bank.
+     *
+     * @param bank The bank whose Buffer you want to get.
+     * @return The Buffer for the specified bank.
+     */
+    public IntBuffer getBuffer(int bank) {
+        return bankdata[bank];
+    }
+
+    /**
+     * Returns the default (first) int data array in <CODE>DataBuffer</CODE>.
+     *
+     * @return The first integer data array.
+     */
+    public int[] getData() {
+        return data.array();
+    }
+
+    /**
+     * Returns the data array for the specified bank.
+     *
+     * @param bank The bank whose data array you want to get.
+     * @return The data array for the specified bank.
+     */
+    public int[] getData(int bank) {
+        return bankdata[bank].array();
+    }
+
+    /**
+     * Returns the data arrays for all banks.
+     * @return All of the data arrays.
+     */
+    public int[][] getBankData() {
+        // Unsupported.
+        return null;
+    }
+
+    /**
+     * Returns the requested data array element from the first (default) bank.
+     *
+     * @param i The data array element you want to get.
+     * @return The requested data array element as an integer.
+     * @see #setElem(int, int)
+     * @see #setElem(int, int, int)
+     */
+    public int getElem(int i) {
+        return data.get(i+offset);
+    }
+
+    /**
+     * Returns the requested data array element from the specified bank.
+     *
+     * @param bank The bank from which you want to get a data array element.
+     * @param i The data array element you want to get.
+     * @return The requested data array element as an integer.
+     * @see #setElem(int, int)
+     * @see #setElem(int, int, int)
+     */
+    public int getElem(int bank, int i) {
+        return bankdata[bank].get(i+offsets[bank]);
+    }
+
+    /**
+     * Sets the requested data array element in the first (default) bank
+     * to the specified value.
+     *
+     * @param i The data array element you want to set.
+     * @param val The integer value to which you want to set the data array element.
+     * @see #getElem(int)
+     * @see #getElem(int, int)
+     */
+    public void setElem(int i, int val) {
+        data.put(i+offset, val);
+    }
+
+    /**
+     * Sets the requested data array element in the specified bank
+     * to the integer value <CODE>i</CODE>.
+     * @param bank The bank in which you want to set the data array element.
+     * @param i The data array element you want to set.
+     * @param val The integer value to which you want to set the specified data array element.
+     * @see #getElem(int)
+     * @see #getElem(int, int)
+     */
+    public void setElem(int bank, int i, int val) {
+        bankdata[bank].put(i+offsets[bank], val);
+    }
+
+    ByteBuffer getBufferOfSize(int size)
+    {
+        ByteBuffer buffer = ByteBuffer.allocateDirect(size);
+        buffer.order(ByteOrder.nativeOrder());
+        return buffer;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/IntegerNIORaster.java b/jdk/src/macosx/classes/sun/java2d/IntegerNIORaster.java
new file mode 100644
index 0000000..3a7eb16
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/IntegerNIORaster.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import java.awt.*;
+import java.awt.image.*;
+import java.nio.IntBuffer;
+import sun.awt.image.SunWritableRaster;
+
+public class IntegerNIORaster extends SunWritableRaster {
+
+    protected IntBuffer data;
+
+    public static WritableRaster createNIORaster(int w, int h, int bandMasks[], Point location) {
+        if ((w <= 0) || (h <= 0)) {
+            throw new IllegalArgumentException("Width (" + w + ") and height (" + h +
+                                               ") cannot be <= 0");
+        }
+        // This is cribbed from java.awt.image.Raster.
+        DataBuffer db = new DataBufferNIOInt(w * h);
+        if (location == null) {
+            location = new Point(0, 0);
+        }
+        SinglePixelPackedSampleModel sppsm =  new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, w, bandMasks);
+        return new IntegerNIORaster(sppsm, db, location);
+    }
+
+    public IntegerNIORaster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin) {
+        // This is all cribbed from sun.awt.image.IntegerInterleavedRaster & sun.awt.image.IntegerComponentRaster
+        super(sampleModel, dataBuffer, new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null);
+        if (!(dataBuffer instanceof DataBufferNIOInt)) {
+           throw new RasterFormatException("IntegerNIORasters must have DataBufferNIOInt DataBuffers");
+        }
+        this.data = ((DataBufferNIOInt)dataBuffer).getBuffer();
+    }
+
+    public WritableRaster createCompatibleWritableRaster() {
+        return new IntegerNIORaster(sampleModel, new DataBufferNIOInt(sampleModel.getWidth() * sampleModel.getHeight()), new Point(0,0));
+    }
+
+    public WritableRaster createCompatibleWritableRaster(int w, int h) {
+        if (w <= 0 || h <=0) {
+            throw new RasterFormatException("negative " + ((w <= 0) ? "width" : "height"));
+        }
+
+        SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);
+
+        return new IntegerNIORaster(sm, new DataBufferNIOInt(w * h), new Point(0,0));
+    }
+
+    public WritableRaster createCompatibleWritableRaster(Rectangle rect) {
+        if (rect == null) {
+            throw new NullPointerException("Rect cannot be null");
+        }
+        return createCompatibleWritableRaster(rect.x, rect.y, rect.width, rect.height);
+    }
+
+    public WritableRaster createCompatibleWritableRaster(int x, int y, int w, int h) {
+        WritableRaster ret = createCompatibleWritableRaster(w, h);
+        return ret.createWritableChild(0,0,w,h,x,y,null);
+    }
+
+
+    public IntBuffer getBuffer() {
+        return data;
+    }
+
+    public String toString() {
+        return new String ("IntegerNIORaster: width = "+width
+                           +" height = " + height
+                           +" #Bands = " + numBands
+                           +" xOff = "+sampleModelTranslateX
+                           +" yOff = "+sampleModelTranslateY);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java b/jdk/src/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java
new file mode 100644
index 0000000..1cfbde9
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import sun.awt.image.SunVolatileImage;
+import sun.awt.image.VolatileSurfaceManager;
+import sun.java2d.opengl.CGLVolatileSurfaceManager;
+
+/**
+ * This is a factory class with static methods for creating a
+ * platform-specific instance of a particular SurfaceManager.  Each platform
+ * (Windows, Unix, etc.) has its own specialized SurfaceManagerFactory.
+ */
+public class MacosxSurfaceManagerFactory extends SurfaceManagerFactory {
+
+    /**
+     * Creates a new instance of a VolatileSurfaceManager given any
+     * arbitrary SunVolatileImage.  An optional context Object can be supplied
+     * as a way for the caller to pass pipeline-specific context data to
+     * the VolatileSurfaceManager (such as a backbuffer handle, for example).
+     *
+     * For Mac OS X, this method returns either an CGL-specific
+     * VolatileSurfaceManager based on the GraphicsConfiguration
+     * under which the SunVolatileImage was created.
+     */
+    public VolatileSurfaceManager createVolatileManager(SunVolatileImage vImg,
+                                                        Object context)
+    {
+        return new CGLVolatileSurfaceManager(vImg, context);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/OSXOffScreenSurfaceData.java b/jdk/src/macosx/classes/sun/java2d/OSXOffScreenSurfaceData.java
new file mode 100644
index 0000000..ad854a8
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/OSXOffScreenSurfaceData.java
@@ -0,0 +1,654 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import java.awt.*;
+import java.awt.color.*;
+import java.awt.image.*;
+import java.nio.*;
+
+import sun.awt.image.*;
+import sun.java2d.loops.*;
+
+public class OSXOffScreenSurfaceData extends OSXSurfaceData // implements RasterListener
+{
+    private static native void initIDs();
+
+    static {
+        initIDs();
+    }
+
+    // the image associated with this surface
+    BufferedImage bim;
+    // the image associated with this custom surface
+    BufferedImage bimBackup;
+    // <rdar://problem/4177639> nio based images use ARGB_PRE
+    static DirectColorModel dcmBackup = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, true, DataBuffer.TYPE_INT);
+
+    Object lock;
+
+    // cached rasters for easy access
+    WritableRaster bufImgRaster;
+    SunWritableRaster bufImgSunRaster;
+
+    // these are extra image types we can handle
+    private static final int TYPE_3BYTE_RGB = BufferedImage.TYPE_BYTE_INDEXED + 1;
+
+    // these are for callbacks when pixes have been touched
+    protected ByteBuffer fImageInfo;
+    IntBuffer fImageInfoInt;
+    private static final int kNeedToSyncFromJavaPixelsIndex = 0;
+    private static final int kNativePixelsChangedIndex = 1;
+    private static final int kImageStolenIndex = 2;
+    private static final int kSizeOfParameters = kImageStolenIndex + 1;
+
+    public static native SurfaceData getSurfaceData(BufferedImage bufImg);
+
+    protected static native void setSurfaceData(BufferedImage bufImg, SurfaceData sData);
+
+    public static SurfaceData createData(BufferedImage bufImg) {
+        /*
+         * if ((bufImg.getWidth() == 32) && (bufImg.getHeight() == 32)) { Thread.dumpStack(); }
+         */
+        // This could be called from multiple threads. We need to synchronized on the image so that
+        // we can ensure that only one surface data is created per image. (<rdar://4564873>)
+        // Note: Eventually, we should switch to using the same mechanism (CachingSurfaceManager) that Sun uses
+        // <rdar://4563741>
+        synchronized (bufImg) {
+            SurfaceData sData = getSurfaceData(bufImg);
+            if (sData != null) { return sData; }
+
+            OSXOffScreenSurfaceData osData = OSXOffScreenSurfaceData.createNewSurface(bufImg);
+
+            OSXOffScreenSurfaceData.setSurfaceData(bufImg, osData);
+            osData.cacheRasters(bufImg);
+//            osData.setRasterListener();
+
+            return osData;
+        }
+    }
+
+    public static SurfaceData createData(Raster ras, ColorModel cm) {
+        throw new InternalError("SurfaceData not implemented for Raster/CM");
+    }
+
+    static OSXOffScreenSurfaceData createNewSurface(BufferedImage bufImg) {
+        SurfaceData sData = null;
+
+        ColorModel cm = bufImg.getColorModel();
+        int type = bufImg.getType();
+        // REMIND: Check the image type and pick an appropriate subclass
+        switch (type) {
+            case BufferedImage.TYPE_INT_BGR:
+                sData = createDataIC(bufImg, SurfaceType.IntBgr);
+                break;
+            case BufferedImage.TYPE_INT_RGB:
+                sData = createDataIC(bufImg, SurfaceType.IntRgb);
+                break;
+            case BufferedImage.TYPE_INT_ARGB:
+                sData = createDataIC(bufImg, SurfaceType.IntArgb);
+                break;
+            case BufferedImage.TYPE_INT_ARGB_PRE:
+                sData = createDataIC(bufImg, SurfaceType.IntArgbPre);
+                break;
+            case BufferedImage.TYPE_3BYTE_BGR:
+                sData = createDataBC(bufImg, SurfaceType.ThreeByteBgr, 2);
+                break;
+            case BufferedImage.TYPE_4BYTE_ABGR:
+                sData = createDataBC(bufImg, SurfaceType.FourByteAbgr, 3);
+                break;
+            case BufferedImage.TYPE_4BYTE_ABGR_PRE:
+                sData = createDataBC(bufImg, SurfaceType.FourByteAbgrPre, 3);
+                break;
+            case BufferedImage.TYPE_USHORT_565_RGB:
+                sData = createDataSC(bufImg, SurfaceType.Ushort565Rgb, null);
+                break;
+            case BufferedImage.TYPE_USHORT_555_RGB:
+                sData = createDataSC(bufImg, SurfaceType.Ushort555Rgb, null);
+                break;
+            case BufferedImage.TYPE_BYTE_INDEXED: {
+                SurfaceType sType;
+                switch (cm.getTransparency()) {
+                    case OPAQUE:
+                        if (isOpaqueGray((IndexColorModel) cm)) {
+                            sType = SurfaceType.Index8Gray;
+                        } else {
+                            sType = SurfaceType.ByteIndexedOpaque;
+                        }
+                        break;
+                    case BITMASK:
+                        sType = SurfaceType.ByteIndexedBm;
+                        break;
+                    case TRANSLUCENT:
+                        sType = SurfaceType.ByteIndexed;
+                        break;
+                    default:
+                        throw new InternalError("Unrecognized transparency");
+                }
+                sData = createDataBC(bufImg, sType, 0);
+            }
+                break;
+            case BufferedImage.TYPE_BYTE_GRAY:
+                sData = createDataBC(bufImg, SurfaceType.ByteGray, 0);
+                break;
+            case BufferedImage.TYPE_USHORT_GRAY:
+                sData = createDataSC(bufImg, SurfaceType.UshortGray, null);
+                break;
+            case BufferedImage.TYPE_BYTE_BINARY:
+            case BufferedImage.TYPE_CUSTOM:
+            default: {
+                Raster raster = bufImg.getRaster();
+
+                // we try to fit a custom image into one of the predefined BufferedImages (BufferedImage does that
+                // first, we further refine it here)
+                // we can do that because a pointer in C is a pointer (pixel pointer not dependent on DataBuffer type)
+                SampleModel sm = bufImg.getSampleModel();
+                SurfaceType sType = SurfaceType.Custom;
+                int transferType = cm.getTransferType();
+                int pixelSize = cm.getPixelSize();
+                int numOfComponents = cm.getNumColorComponents();
+                if ((numOfComponents == 3) && (cm instanceof ComponentColorModel) && (sm instanceof PixelInterleavedSampleModel)) {
+                    int sizes[] = cm.getComponentSize();
+                    boolean validsizes = (sizes[0] == 8) && (sizes[1] == 8) && (sizes[2] == 8);
+                    int[] offs = ((ComponentSampleModel) sm).getBandOffsets();
+                    int numBands = raster.getNumBands();
+                    boolean bigendian = (offs[0] == numBands - 3) && (offs[1] == numBands - 2) && (offs[2] == numBands - 1);
+                    boolean littleendian = (offs[0] == numBands - 1) && (offs[1] == numBands - 2) && (offs[2] == numBands - 3);
+
+                    if ((pixelSize == 32) && (transferType == DataBuffer.TYPE_INT)) {
+                        if (validsizes && bigendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {
+                            try {
+                                sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB_PRE);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && bigendian && cm.hasAlpha() && sizes[3] == 8) {
+                            try {
+                                sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && littleendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {
+                            try {
+                                sData = createDataIC(bufImg, sType, BufferedImage.TYPE_4BYTE_ABGR_PRE);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && littleendian && cm.hasAlpha() && sizes[3] == 8) {
+                            try {
+                                sData = createDataIC(bufImg, sType, BufferedImage.TYPE_4BYTE_ABGR);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && bigendian) {
+                            try {
+                                sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    } else if ((pixelSize == 32) && (transferType == DataBuffer.TYPE_BYTE)) {
+                        if (validsizes && bigendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_ARGB_PRE);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                        if (validsizes && bigendian && cm.hasAlpha() && sizes[3] == 8) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_ARGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && littleendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_4BYTE_ABGR_PRE);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && littleendian && cm.hasAlpha() && sizes[3] == 8) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_4BYTE_ABGR);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && littleendian) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_BGR);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && bigendian) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    } else if ((pixelSize == 24) && (transferType == DataBuffer.TYPE_INT)) {
+                        if (validsizes && bigendian) {
+                            try {
+                                sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && littleendian) {
+                            try {
+                                sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_BGR);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    } else if ((pixelSize == 24) && (transferType == DataBuffer.TYPE_BYTE)) {
+                        if (validsizes && bigendian) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 0, TYPE_3BYTE_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        } else if (validsizes && littleendian) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 0, BufferedImage.TYPE_3BYTE_BGR);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    } else if ((pixelSize == 16) && (transferType == DataBuffer.TYPE_USHORT)) {
+                        validsizes = (sizes[0] == 5) && (sizes[1] == 6) && (sizes[2] == 5);
+                        if (validsizes && bigendian) {
+                            try {
+                                sData = createDataSC(bufImg, sType, null, BufferedImage.TYPE_USHORT_565_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    } else if ((pixelSize == 16) && (transferType == DataBuffer.TYPE_BYTE)) {
+                        validsizes = (sizes[0] == 5) && (sizes[1] == 6) && (sizes[2] == 5);
+                        if (validsizes && bigendian) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 1, BufferedImage.TYPE_USHORT_565_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    } else if ((pixelSize == 15) && (transferType == DataBuffer.TYPE_USHORT)) {
+                        validsizes = (sizes[0] == 5) && (sizes[1] == 5) && (sizes[2] == 5);
+                        if (validsizes && bigendian) {
+                            try {
+                                sData = createDataSC(bufImg, sType, null, BufferedImage.TYPE_USHORT_555_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    } else if ((pixelSize == 15) && (transferType == DataBuffer.TYPE_BYTE)) {
+                        validsizes = (sizes[0] == 5) && (sizes[1] == 5) && (sizes[2] == 5);
+                        if (validsizes && bigendian) {
+                            try {
+                                sData = createDataBC(bufImg, sType, 1, BufferedImage.TYPE_USHORT_555_RGB);
+                            } catch (ClassCastException e) {
+                                sData = null;
+                            }
+                        }
+                    }
+                }
+            }
+                break;
+        }
+
+        // we failed to match
+        if (sData == null) {
+            sData = new OSXOffScreenSurfaceData(bufImg, SurfaceType.Custom);
+            OSXOffScreenSurfaceData offsd = (OSXOffScreenSurfaceData) sData;
+
+            // 2004_03_26 cmc: We used to use createCompatibleImage here. Now that createCompatibleImage returns
+            // an INT_ARGB_PRE instead of an NIO-based image, we need to explicitly create an NIO-based image.
+            IntegerNIORaster backupRaster = (IntegerNIORaster) IntegerNIORaster.createNIORaster(bufImg.getWidth(), bufImg.getHeight(), dcmBackup.getMasks(), null);
+            offsd.bimBackup = new BufferedImage(dcmBackup, backupRaster, dcmBackup.isAlphaPremultiplied(), null);
+
+            // the trick that makes it work - assign the raster from backup to the surface data of the original image
+            offsd.initCustomRaster(backupRaster.getBuffer(),
+                                    backupRaster.getWidth(),
+                                    backupRaster.getHeight(),
+                                    offsd.fGraphicsStates,
+                                    offsd.fGraphicsStatesObject,
+                                    offsd.fImageInfo);
+
+            //offsd.checkIfLazyPixelConversionDisabled();
+            offsd.fImageInfoInt.put(kImageStolenIndex, 1);
+        }
+
+        return (OSXOffScreenSurfaceData) sData;
+    }
+
+    private static SurfaceData createDataIC(BufferedImage bImg, SurfaceType sType, int iType) {
+        OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);
+
+        IntegerComponentRaster icRaster = (IntegerComponentRaster) bImg.getRaster();
+        offsd.initRaster(icRaster.getDataStorage(),
+                            icRaster.getDataOffset(0) * 4,
+                            icRaster.getWidth(),
+                            icRaster.getHeight(),
+                            icRaster.getPixelStride() * 4,
+                            icRaster.getScanlineStride() * 4,
+                            null,
+                            iType,
+                            offsd.fGraphicsStates,
+                            offsd.fGraphicsStatesObject,
+                            offsd.fImageInfo);
+
+       // offsd.checkIfLazyPixelConversionDisabled();
+        offsd.fImageInfoInt.put(kImageStolenIndex, 1);
+        return offsd;
+    }
+
+    public static SurfaceData createDataIC(BufferedImage bImg, SurfaceType sType) {
+        return createDataIC(bImg, sType, bImg.getType());
+    }
+
+    private static SurfaceData createDataSC(BufferedImage bImg, SurfaceType sType, IndexColorModel icm, int iType) {
+        OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);
+
+        ShortComponentRaster scRaster = (ShortComponentRaster) bImg.getRaster();
+        offsd.initRaster(scRaster.getDataStorage(),
+                            scRaster.getDataOffset(0) * 2,
+                            scRaster.getWidth(),
+                            scRaster.getHeight(),
+                            scRaster.getPixelStride() * 2,
+                            scRaster.getScanlineStride() * 2,
+                            icm,
+                            iType,
+                            offsd.fGraphicsStates,
+                            offsd.fGraphicsStatesObject,
+                            offsd.fImageInfo);
+
+        //offsd.checkIfLazyPixelConversionDisabled();
+        offsd.fImageInfoInt.put(kImageStolenIndex, 1);
+        return offsd;
+    }
+
+    public static SurfaceData createDataSC(BufferedImage bImg, SurfaceType sType, IndexColorModel icm) {
+        return createDataSC(bImg, sType, icm, bImg.getType());
+    }
+
+    private static SurfaceData createDataBC(BufferedImage bImg, SurfaceType sType, int primaryBank, int iType) {
+        OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);
+
+        ByteComponentRaster bcRaster = (ByteComponentRaster) bImg.getRaster();
+        ColorModel cm = bImg.getColorModel();
+        IndexColorModel icm = ((cm instanceof IndexColorModel) ? (IndexColorModel) cm : null);
+        offsd.initRaster(bcRaster.getDataStorage(),
+                            bcRaster.getDataOffset(primaryBank),
+                            bcRaster.getWidth(),
+                            bcRaster.getHeight(),
+                            bcRaster.getPixelStride(),
+                            bcRaster.getScanlineStride(),
+                            icm,
+                            iType,
+                            offsd.fGraphicsStates,
+                            offsd.fGraphicsStatesObject,
+                            offsd.fImageInfo);
+
+        offsd.fImageInfoInt.put(kImageStolenIndex, 1);
+
+        return offsd;
+    }
+
+    public static SurfaceData createDataBC(BufferedImage bImg, SurfaceType sType, int primaryBank) {
+        return createDataBC(bImg, sType, primaryBank, bImg.getType());
+    }
+
+    private static SurfaceData createDataBP(BufferedImage bImg, SurfaceType sType, int iType) {
+        OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);
+
+        BytePackedRaster bpRaster = (BytePackedRaster) bImg.getRaster();
+        ColorModel cm = bImg.getColorModel();
+        IndexColorModel icm = ((cm instanceof IndexColorModel) ? (IndexColorModel) cm : null);
+        offsd.initRaster(bpRaster.getDataStorage(),
+                            bpRaster.getDataBitOffset(), // in bits, NOT bytes! (needs special attention in native
+                                                         // code!)
+                bpRaster.getWidth(),
+                            bpRaster.getHeight(),
+                            bpRaster.getPixelBitStride(),
+                            bpRaster.getScanlineStride() * 8,
+                            icm,
+                            iType,
+                            offsd.fGraphicsStates,
+                            offsd.fGraphicsStatesObject,
+                            offsd.fImageInfo);
+
+        //offsd.checkIfLazyPixelConversionDisabled();
+        offsd.fImageInfoInt.put(kImageStolenIndex, 1);
+        return offsd;
+    }
+
+    protected native void initRaster(Object theArray, int offset, int width, int height, int pixStr, int scanStr, IndexColorModel icm, int type, ByteBuffer graphicsStates, Object graphicsStatesObjects, ByteBuffer imageInfo);
+
+    protected native void initCustomRaster(IntBuffer buffer, int width, int height, ByteBuffer graphicsStates, Object graphicsStatesObjects, ByteBuffer imageInfo);
+
+    public Object getLockObject() {
+        return this.lock;
+    }
+
+    // Makes the constructor package private instead of public.
+    OSXOffScreenSurfaceData(BufferedImage bufImg, SurfaceType sType) {
+        super(sType, bufImg.getColorModel());
+        setBounds(0, 0, bufImg.getWidth(), bufImg.getHeight());
+
+        this.bim = bufImg;
+
+        this.fImageInfo = ByteBuffer.allocateDirect(4 * kSizeOfParameters);
+        this.fImageInfo.order(ByteOrder.nativeOrder());
+        this.fImageInfoInt = this.fImageInfo.asIntBuffer();
+
+        this.fImageInfoInt.put(kNeedToSyncFromJavaPixelsIndex, 1); // need to sync from Java the very first time
+        this.fImageInfoInt.put(kNativePixelsChangedIndex, 0);
+        this.fImageInfoInt.put(kImageStolenIndex, 0);
+
+        this.lock = new Object();
+    }
+
+    /**
+     * Performs a copyArea within this surface.
+     */
+    public boolean copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy) {
+        // <rdar://problem/4488745> For the Sun2D renderer we should rely on the implementation of the super class.
+        // BufImageSurfaceData.java doesn't have an implementation of copyArea() and relies on the super class.
+
+        int offsetX = 0;
+        int offsetY = 0;
+        if (sg2d.transformState == SunGraphics2D.TRANSFORM_ANY_TRANSLATE ||
+                    sg2d.transformState == SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
+            offsetX = (int) sg2d.transform.getTranslateX();
+            offsetY = (int) sg2d.transform.getTranslateY();
+        } else if (sg2d.transformState != SunGraphics2D.TRANSFORM_ISIDENT) { return false; }
+
+        // reset the clip (this is how it works on windows)
+        // we actually can handle a case with any clips but windows ignores the light clip
+        Shape clip = sg2d.getClip();
+        sg2d.setClip(getBounds());
+
+        // clip copyArea
+        Rectangle clippedCopyAreaRect = clipCopyArea(sg2d, x, y, w, h, dx, dy);
+        if (clippedCopyAreaRect == null) {
+            // clipped out
+            return true;
+        }
+
+        // the rectangle returned from clipCopyArea() is in the coordinate space of the surface (image)
+        // we need to substract the offsetX and offsetY to move it to the coordinate space of the graphics2d.
+        // sg2d.drawImage expects the destination rect to be in the coord space of the graphics2d. <rdar://3746194>
+        // (vm)
+        x = clippedCopyAreaRect.x - offsetX;
+        y = clippedCopyAreaRect.y - offsetY;
+        w = clippedCopyAreaRect.width;
+        h = clippedCopyAreaRect.height;
+
+        // copy (dst coordinates are in the coord space of the graphics2d, and src coordinates are
+        // in the coordinate space of the image)
+        sg2d.drawImage(this.bim, x + dx, y + dy, x + dx + w, y + dy + h, x + offsetX, y + offsetY, x + w + offsetX, y + h + offsetY, null);
+
+        // restore the clip
+        sg2d.setClip(clip);
+
+        return true;
+    }
+
+    /**
+     * Performs a copyarea from this surface to a buffered image. If null is passed in for the image a new image will be
+     * created.
+     *
+     * Only used by compositor code (private API)
+     */
+    public BufferedImage copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, BufferedImage dstImage) {
+        // create the destination image if needed
+        if (dstImage == null) {
+            dstImage = getDeviceConfiguration().createCompatibleImage(w, h);
+        }
+
+        // copy
+        Graphics g = dstImage.createGraphics();
+        g.drawImage(this.bim, 0, 0, w, h, x, y, x + w, y + h, null);
+        g.dispose();
+
+        return dstImage;
+    }
+
+    public boolean xorSurfacePixels(SunGraphics2D sg2d, BufferedImage srcPixels, int x, int y, int w, int h, int colorXOR) {
+
+        int type = this.bim.getType();
+
+        if ((type == BufferedImage.TYPE_INT_ARGB_PRE) || (type == BufferedImage.TYPE_INT_ARGB) || (type == BufferedImage.TYPE_INT_RGB)) { return xorSurfacePixels(createData(srcPixels), colorXOR, x, y, w, h); }
+
+        return false;
+    }
+
+    native boolean xorSurfacePixels(SurfaceData src, int colorXOR, int x, int y, int w, int h);
+
+    public void clearRect(BufferedImage bim, int w, int h) {
+        OSXOffScreenSurfaceData offsd = (OSXOffScreenSurfaceData) (OSXOffScreenSurfaceData.createData(bim));
+        // offsd.clear();
+        if (offsd.clearSurfacePixels(w, h) == false) {
+            Graphics2D g = bim.createGraphics();
+            g.setComposite(AlphaComposite.Clear);
+            g.fillRect(0, 0, w, h);
+            g.dispose();
+        }
+    }
+
+    native boolean clearSurfacePixels(int w, int h);
+
+    // 04/06/04 cmc: radr://3612381 Graphics.drawImage ignores bgcolor parameter.
+    // getCopyWithBgColor returns a new version of an image, drawn with a background
+    // color. Called by blitImage in OSXSurfaceData.java.
+    BufferedImage copyWithBgColor_cache = null;
+
+    public SurfaceData getCopyWithBgColor(Color bgColor) {
+        int bimW = this.bim.getWidth();
+        int bimH = this.bim.getHeight();
+
+        if ((this.copyWithBgColor_cache == null)
+                || (this.copyWithBgColor_cache.getWidth() < bimW) || (this.copyWithBgColor_cache.getHeight() < bimH)) {
+            GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
+            this.copyWithBgColor_cache = gc.createCompatibleImage(bimW, bimH);
+        }
+
+        Graphics g2 = this.copyWithBgColor_cache.createGraphics();
+        g2.setColor(bgColor);
+        g2.fillRect(0, 0, bimW, bimH);
+        g2.drawImage(this.bim, 0, 0, bimW, bimH, null);
+        g2.dispose();
+
+        return getSurfaceData(this.copyWithBgColor_cache);
+    }
+
+    /**
+     * Invoked before the raster's contents are to be read (via one of the modifier methods in Raster such as
+     * getPixel())
+     */
+    public void rasterRead() {
+        if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {
+            syncToJavaPixels();
+        }
+    }
+
+    /**
+     * Invoked before the raster's contents are to be written to (via one of the modifier methods in Raster such as
+     * setPixel())
+     */
+    public void rasterWrite() {
+        if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {
+            syncToJavaPixels();
+        }
+
+        fImageInfoInt.put(kNeedToSyncFromJavaPixelsIndex, 1); // the pixels will change
+    }
+
+//    /**
+//     * Invoked when the raster's contents will be taken (via the Raster.getDataBuffer() method)
+//     */
+//    public void rasterStolen() {
+//        fImageInfoInt.put(kImageStolenIndex, 1); // this means we must convert between Java and native pixels every
+//                                                 // single primitive! (very expensive)
+//        if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {
+//            syncToJavaPixels();
+//        }
+//
+//        // we know the pixels have been stolen, no need to listen for changes any more
+////        if (this.bufImgSunRaster != null) {
+////            this.bufImgSunRaster.setRasterListener(null);
+////        }
+//    }
+
+    private native void syncToJavaPixels();
+
+    // we need to refer to rasters often, so cache them
+    void cacheRasters(BufferedImage bim) {
+        this.bufImgRaster = bim.getRaster();
+        if (this.bufImgRaster instanceof SunWritableRaster) {
+            this.bufImgSunRaster = (SunWritableRaster) this.bufImgRaster;
+        }
+    }
+
+//    void setRasterListener() {
+//        if (this.bufImgSunRaster != null) {
+//            this.bufImgSunRaster.setRasterListener(this);
+//
+//            Raster parentRaster = this.bufImgSunRaster.getParent();
+//            if (parentRaster != null) {
+//                if (parentRaster instanceof SunWritableRaster) {
+//                    // mark subimages stolen to turn off lazy pixel conversion (gznote: can we do better here?)
+//                    ((SunWritableRaster) parentRaster).notifyStolen();
+//                }
+//                rasterStolen();
+//            }
+//        } else {
+//            // it's a custom image (non-natively supported) and we can not set a raster listener
+//            // so mark the image as stolen - this will turn off LazyPixelConversion optimization (slow, but correct)
+//            rasterStolen();
+//        }
+//    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/OSXSurfaceData.java b/jdk/src/macosx/classes/sun/java2d/OSXSurfaceData.java
new file mode 100644
index 0000000..a91cf5f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/OSXSurfaceData.java
@@ -0,0 +1,1166 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d;
+
+import java.awt.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.image.*;
+import java.nio.*;
+
+import sun.awt.*;
+import sun.awt.image.*;
+import sun.java2d.loops.*;
+import sun.java2d.pipe.*;
+import sun.lwawt.macosx.*;
+
+/*
+ * This is the SurfaceData for a CGContextRef.
+ */
+public abstract class OSXSurfaceData extends BufImgSurfaceData {
+    final static float UPPER_BND = Float.MAX_VALUE / 2.0f;
+    final static float LOWER_BND = -UPPER_BND;
+
+    protected static CRenderer sQuartzPipe = null;
+    protected static CTextPipe sCocoaTextPipe = null;
+    protected static CompositeCRenderer sQuartzCompositePipe = null;
+
+    private GraphicsConfiguration fConfig;
+    private Rectangle fBounds; // bounds in user coordinates
+
+    static {
+        sQuartzPipe = new CRenderer(); // Creates the singleton quartz pipe.
+    }
+
+    // NOTE: Any subclasses must eventually call QuartzSurfaceData_InitOps in OSXSurfaceData.h
+    // This sets up the native side for the SurfaceData, and is required.
+    public OSXSurfaceData(SurfaceType sType, ColorModel cm) {
+        this(sType, cm, null, new Rectangle());
+    }
+
+    public OSXSurfaceData(SurfaceType sType, ColorModel cm, GraphicsConfiguration config, Rectangle bounds) {
+        super(sType, cm);
+
+        this.fConfig = config;
+
+        this.fBounds = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.y + bounds.height);
+
+        this.fGraphicsStates = getBufferOfSize(kSizeOfParameters);
+        this.fGraphicsStatesInt = this.fGraphicsStates.asIntBuffer();
+        this.fGraphicsStatesFloat = this.fGraphicsStates.asFloatBuffer();
+        this.fGraphicsStatesLong = this.fGraphicsStates.asLongBuffer();
+        this.fGraphicsStatesObject = new Object[6]; // clip coordinates + clip types + texture paint image + stroke dash
+                                                    // array + font + font paint
+
+        // NOTE: All access to the DrawingQueue comes through this OSXSurfaceData instance. Therefore
+        // every instance method of OSXSurfaceData that accesses the fDrawingQueue is synchronized.
+
+        // Thread.dumpStack();
+    }
+
+    public void validatePipe(SunGraphics2D sg2d) {
+
+        if (sg2d.compositeState <= SunGraphics2D.COMP_ALPHA) {
+            if (sCocoaTextPipe == null) {
+                sCocoaTextPipe = new CTextPipe();
+            }
+
+            sg2d.imagepipe = sQuartzPipe;
+            sg2d.drawpipe = sQuartzPipe;
+            sg2d.fillpipe = sQuartzPipe;
+            sg2d.shapepipe = sQuartzPipe;
+            sg2d.textpipe = sCocoaTextPipe;
+        } else {
+            setPipesToQuartzComposite(sg2d);
+        }
+    }
+
+    protected void setPipesToQuartzComposite(SunGraphics2D sg2d) {
+        if (sQuartzCompositePipe == null) {
+            sQuartzCompositePipe = new CompositeCRenderer();
+        }
+
+        if (sCocoaTextPipe == null) {
+            sCocoaTextPipe = new CTextPipe();
+        }
+
+        sg2d.imagepipe = sQuartzCompositePipe;
+        sg2d.drawpipe = sQuartzCompositePipe;
+        sg2d.fillpipe = sQuartzCompositePipe;
+        sg2d.shapepipe = sQuartzCompositePipe;
+        sg2d.textpipe = sCocoaTextPipe;
+    }
+
+    public Rectangle getBounds() {
+        // gznote: always return a copy, not the rect itself and translate into device space
+        return new Rectangle(fBounds.x, fBounds.y, fBounds.width, fBounds.height - fBounds.y);
+    }
+
+    public GraphicsConfiguration getDeviceConfiguration() {
+        return fConfig;
+    }
+
+    protected void setBounds(int x, int y, int w, int h) {
+        fBounds.reshape(x, y, w, y + h);
+    }
+
+    // START compositing support API
+    public abstract BufferedImage copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, BufferedImage image);
+
+    public abstract boolean xorSurfacePixels(SunGraphics2D sg2d, BufferedImage srcPixels, int x, int y, int w, int h, int colorXOR);
+
+    GraphicsConfiguration sDefaultGraphicsConfiguration = null;
+
+    protected BufferedImage getCompositingImage(int w, int h) {
+        if (sDefaultGraphicsConfiguration == null) {
+            sDefaultGraphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
+        }
+
+        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
+        // clear the image.
+        clearRect(img, w, h);
+        return img;
+    }
+
+    protected BufferedImage getCompositingImageSame(BufferedImage img, int w, int h) {
+        if ((img == null) || (img.getWidth() != w) || (img.getHeight() != h)) {
+            img = getCompositingImage(w, h);
+        }
+        return img;
+    }
+
+    BufferedImage sSrcComposite = null;
+
+    public BufferedImage getCompositingSrcImage(int w, int h) {
+        // <rdar://problem/3720263>. Changed from getCompositingImageBiggerOrSame() to
+        // getCompositingImageSame(). (vm)
+        BufferedImage bim = getCompositingImageSame(sSrcComposite, w, h);
+        sSrcComposite = bim;
+        return bim;
+    }
+
+    BufferedImage sDstInComposite = null;
+
+    public BufferedImage getCompositingDstInImage(int w, int h) {
+        BufferedImage bim = getCompositingImageSame(sDstInComposite, w, h);
+        sDstInComposite = bim;
+        return bim;
+    }
+
+    BufferedImage sDstOutComposite = null;
+
+    public BufferedImage getCompositingDstOutImage(int w, int h) {
+        BufferedImage bim = getCompositingImageSame(sDstOutComposite, w, h);
+        sDstOutComposite = bim;
+        return bim;
+    }
+
+    public void clearRect(BufferedImage bim, int w, int h) {
+        Graphics2D g = bim.createGraphics();
+        g.setComposite(AlphaComposite.Clear);
+        g.fillRect(0, 0, w, h);
+        g.dispose();
+    }
+
+    // END compositing support API
+
+    public void invalidate() {
+        // always valid
+    }
+
+     // graphics primitives drawing implementation:
+
+    // certain primitives don't care about all the states (ex. drawing an image needs not involve setting current paint)
+    static final int kPrimitive = 0;
+    static final int kImage = 1;
+    static final int kText = 2;
+    static final int kCopyArea = 3;
+    static final int kExternal = 4;
+
+    static final int kLine = 5; // belongs to kPrimitive
+    static final int kRect = 6; // belongs to kPrimitive
+    static final int kRoundRect = 7; // belongs to kPrimitive
+    static final int kOval = 8; // belongs to kPrimitive
+    static final int kArc = 9; // belongs to kPrimitive
+    static final int kPolygon = 10; // belongs to kPrimitive
+    static final int kShape = 11; // belongs to kPrimitive
+    // static final int kImage = 12; // belongs to kImage
+    static final int kString = 13; // belongs to kText
+    static final int kGlyphs = 14; // belongs to kText
+    static final int kUnicodes = 15; // belongs to kText
+    // static final int kCopyArea = 16; // belongs to kCopyArea
+    // static final int kExternal = 17; // belongs to kExternal
+
+    static final int kCommonParameterCount = 1 + 1 + 4 + 4; // type + change flags + color info (type(1) align(1) and
+                                                            // value(2)) + parameters ((x1, y1, x2, y2) OR (x, y, w, h))
+    static final int kLineParametersCount = kCommonParameterCount; // kCommonParameterCount
+    static final int kRectParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill
+    static final int kRoundRectParametersCount = kCommonParameterCount + 2 + 1; // kCommonParameterCount + arcW + arcH +
+                                                                                // isfill
+    static final int kOvalParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill
+    static final int kArcParametersCount = kCommonParameterCount + 2 + 1 + 1;// kCommonParameterCount + startAngle +
+                                                                             // arcAngle + isfill + type
+    static final int kPolygonParametersCount = 0; // not supported
+    static final int kShapeParametersCount = 0; // not supported
+    static final int kImageParametersCount = kCommonParameterCount + 2 + 2 + 4 + 4; // flip horz vert + w&h + src + dst
+    static final int kStringParametersCount = 0; // not supported
+    static final int kGlyphsParametersCount = 0; // not supported
+    static final int kUnicodesParametersCount = 0; // not supported
+    static final int kPixelParametersCount = 0; // not supported
+    static final int kExternalParametersCount = 0; // not supported
+
+    // for intParameters
+    // states info
+    static final int kChangeFlagIndex = 0; // kBoundsChangedBit | .. | kFontChangedBit
+    // bounds info
+    static final int kBoundsXIndex = 1;
+    static final int kBoundsYIndex = 2;
+    static final int kBoundsWidthIndex = 3;
+    static final int kBoundsHeightIndex = 4;
+    // clip info
+    static final int kClipStateIndex = 5;
+    static final int kClipNumTypesIndex = 6;
+    static final int kClipNumCoordsIndex = 7;
+    static final int kClipWindingRuleIndex = 8;
+    static final int kClipXIndex = 9;
+    static final int kClipYIndex = 10;
+    static final int kClipWidthIndex = 11;
+    static final int kClipHeightIndex = 12;
+    // ctm info
+    static final int kCTMaIndex = 13;
+    static final int kCTMbIndex = 14;
+    static final int kCTMcIndex = 15;
+    static final int kCTMdIndex = 16;
+    static final int kCTMtxIndex = 17;
+    static final int kCTMtyIndex = 18;
+    // color info
+    static final int kColorStateIndex = 19; // kColorSimple or kColorGradient or kColorTexture
+    static final int kColorRGBValueIndex = 20; // if kColorSimple
+    static final int kColorIndexValueIndex = 21; // if kColorSystem
+    static final int kColorPointerIndex = 22; //
+    static final int kColorPointerIndex2 = 23; //
+    static final int kColorRGBValue1Index = 24; // if kColorGradient
+    static final int kColorWidthIndex = 25; // if kColorTexture
+    static final int kColorRGBValue2Index = 26; // if kColorGradient
+    static final int kColorHeightIndex = 27; // if kColorTexture
+    static final int kColorIsCyclicIndex = 28; // if kColorGradient (kColorNonCyclic or kColorCyclic)
+    static final int kColorx1Index = 29;
+    static final int kColortxIndex = 30;
+    static final int kColory1Index = 31;
+    static final int kColortyIndex = 32;
+    static final int kColorx2Index = 33;
+    static final int kColorsxIndex = 34;
+    static final int kColory2Index = 35;
+    static final int kColorsyIndex = 36;
+    // composite info
+    static final int kCompositeRuleIndex = 37; // kCGCompositeClear or ... or kCGCompositeXor
+    static final int kCompositeValueIndex = 38;
+    // stroke info
+    static final int kStrokeJoinIndex = 39; // see BasicStroke.java
+    static final int kStrokeCapIndex = 40; // see BasicStroke.java
+    static final int kStrokeWidthIndex = 41;
+    static final int kStrokeDashPhaseIndex = 42;
+    static final int kStrokeLimitIndex = 43;
+    // hints info
+    static final int kHintsAntialiasIndex = 44;
+    static final int kHintsTextAntialiasIndex = 45;
+    static final int kHintsFractionalMetricsIndex = 46;
+    static final int kHintsRenderingIndex = 47;
+    static final int kHintsInterpolationIndex = 48;
+    // live resizing info
+    static final int kCanDrawDuringLiveResizeIndex = 49;
+
+    static final int kSizeOfParameters = kCanDrawDuringLiveResizeIndex + 1;
+
+    // for objectParameters
+    static final int kClipCoordinatesIndex = 0;
+    static final int kClipTypesIndex = 1;
+    static final int kTextureImageIndex = 2;
+    static final int kStrokeDashArrayIndex = 3;
+    static final int kFontIndex = 4;
+    static final int kFontPaintIndex = 5;
+
+    // possible state changes
+    static final int kBoundsChangedBit = 1 << 0;
+    static final int kBoundsNotChangedBit = ~kBoundsChangedBit;
+    static final int kClipChangedBit = 1 << 1;
+    static final int kClipNotChangedBit = ~kClipChangedBit;
+    static final int kCTMChangedBit = 1 << 2;
+    static final int kCTMNotChangedBit = ~kCTMChangedBit;
+    static final int kColorChangedBit = 1 << 3;
+    static final int kColorNotChangedBit = ~kColorChangedBit;
+    static final int kCompositeChangedBit = 1 << 4;
+    static final int kCompositeNotChangedBit = ~kCompositeChangedBit;
+    static final int kStrokeChangedBit = 1 << 5;
+    static final int kStrokeNotChangedBit = ~kStrokeChangedBit;
+    static final int kHintsChangedBit = 1 << 6;
+    static final int kHintsNotChangedBit = ~kHintsChangedBit;
+    static final int kFontChangedBit = 1 << 7;
+    static final int kFontNotChangedBit = ~kFontChangedBit;
+    static final int kEverythingChangedFlag = 0xffffffff;
+
+    // possible color states
+    static final int kColorSimple = 0;
+    static final int kColorSystem = 1;
+    static final int kColorGradient = 2;
+    static final int kColorTexture = 3;
+
+    // possible gradient color states
+    static final int kColorNonCyclic = 0;
+    static final int kColorCyclic = 1;
+
+    // possible clip states
+    static final int kClipRect = 0;
+    static final int kClipShape = 1;
+
+    static int getRendererTypeForPrimitive(int primitiveType) {
+        switch (primitiveType) {
+            case kImage:
+                return kImage;
+            case kCopyArea:
+                return kCopyArea;
+            case kExternal:
+                return kExternal;
+            case kString:
+            case kGlyphs:
+            case kUnicodes:
+                return kText;
+            default:
+                return kPrimitive;
+        }
+    }
+
+    int fChangeFlag;
+    protected ByteBuffer fGraphicsStates = null;
+    IntBuffer fGraphicsStatesInt = null;
+    FloatBuffer fGraphicsStatesFloat = null;
+    LongBuffer fGraphicsStatesLong = null;
+    protected Object[] fGraphicsStatesObject = null;
+
+    Rectangle userBounds = new Rectangle();
+    float lastUserX = 0;
+    float lastUserY = 0;
+    float lastUserW = 0;
+    float lastUserH = 0;
+
+    void setUserBounds(SunGraphics2D sg2d, int x, int y, int width, int height) {
+        if ((lastUserX != x) || (lastUserY != y) || (lastUserW != width) || (lastUserH != height)) {
+            lastUserX = x;
+            lastUserY = y;
+            lastUserW = width;
+            lastUserH = height;
+
+            this.fGraphicsStatesInt.put(kBoundsXIndex, x);
+            this.fGraphicsStatesInt.put(kBoundsYIndex, y);
+            this.fGraphicsStatesInt.put(kBoundsWidthIndex, width);
+            this.fGraphicsStatesInt.put(kBoundsHeightIndex, height);
+
+            userBounds.setBounds(x, y, width, height);
+
+            this.fChangeFlag = (this.fChangeFlag | kBoundsChangedBit);
+        } else {
+            this.fChangeFlag = (this.fChangeFlag & kBoundsNotChangedBit);
+        }
+    }
+
+    static ByteBuffer getBufferOfSize(int size) {
+        ByteBuffer buffer = ByteBuffer.allocateDirect(size * 4);
+        buffer.order(ByteOrder.nativeOrder());
+        return buffer;
+    }
+
+    FloatBuffer clipCoordinatesArray = null;
+    IntBuffer clipTypesArray = null;
+    Shape lastClipShape = null;
+    float lastClipX = 0;
+    float lastClipY = 0;
+    float lastClipW = 0;
+    float lastClipH = 0;
+
+    void setupClip(SunGraphics2D sg2d) {
+        switch (sg2d.clipState) {
+            case SunGraphics2D.CLIP_DEVICE:
+            case SunGraphics2D.CLIP_RECTANGULAR: {
+                Region clip = sg2d.getCompClip();
+                float x = clip.getLoX();
+                float y = clip.getLoY();
+                float w = clip.getWidth();
+                float h = clip.getHeight();
+                if ((this.fGraphicsStatesInt.get(kClipStateIndex) != kClipRect) ||
+                        (x != lastClipX) ||
+                            (y != lastClipY) ||
+                                (w != lastClipW) ||
+                                    (h != lastClipH)) {
+                    this.fGraphicsStatesFloat.put(kClipXIndex, x);
+                    this.fGraphicsStatesFloat.put(kClipYIndex, y);
+                    this.fGraphicsStatesFloat.put(kClipWidthIndex, w);
+                    this.fGraphicsStatesFloat.put(kClipHeightIndex, h);
+
+                    lastClipX = x;
+                    lastClipY = y;
+                    lastClipW = w;
+                    lastClipH = h;
+
+                    this.fChangeFlag = (this.fChangeFlag | kClipChangedBit);
+                } else {
+                    this.fChangeFlag = (this.fChangeFlag & kClipNotChangedBit);
+                }
+                this.fGraphicsStatesInt.put(kClipStateIndex, kClipRect);
+                break;
+            }
+            case SunGraphics2D.CLIP_SHAPE: {
+                // if (lastClipShape != sg2d.usrClip) shapes are mutable!, and doing "equals" traverses all
+                // the coordinates, so we might as well do all of it anyhow
+                lastClipShape = sg2d.usrClip;
+
+                GeneralPath gp = null;
+
+                if (sg2d.usrClip instanceof GeneralPath) {
+                    gp = (GeneralPath) sg2d.usrClip;
+                } else {
+                    gp = new GeneralPath(sg2d.usrClip);
+                }
+
+                int shapeLength = getPathLength(gp);
+
+                if ((clipCoordinatesArray == null) || (clipCoordinatesArray.capacity() < (shapeLength * 6))) {
+                    clipCoordinatesArray = getBufferOfSize(shapeLength * 6).asFloatBuffer(); // segment can have a
+                                                                                             // max of 6 coordinates
+                }
+                if ((clipTypesArray == null) || (clipTypesArray.capacity() < shapeLength)) {
+                    clipTypesArray = getBufferOfSize(shapeLength).asIntBuffer();
+                }
+
+                int windingRule = getPathCoordinates(gp, clipCoordinatesArray, clipTypesArray);
+
+                this.fGraphicsStatesInt.put(kClipNumTypesIndex, clipTypesArray.position());
+                this.fGraphicsStatesInt.put(kClipNumCoordsIndex, clipCoordinatesArray.position());
+                this.fGraphicsStatesInt.put(kClipWindingRuleIndex, windingRule);
+                this.fGraphicsStatesObject[kClipTypesIndex] = clipTypesArray;
+                this.fGraphicsStatesObject[kClipCoordinatesIndex] = clipCoordinatesArray;
+
+                this.fChangeFlag = (this.fChangeFlag | kClipChangedBit);
+                this.fGraphicsStatesInt.put(kClipStateIndex, kClipShape);
+                break;
+            }
+        }
+
+    }
+
+    final double[] lastCTM = new double[6];
+    float lastCTMa = 0;
+    float lastCTMb = 0;
+    float lastCTMc = 0;
+    float lastCTMd = 0;
+    float lastCTMtx = 0;
+    float lastCTMty = 0;
+
+    void setupTransform(SunGraphics2D sg2d) {
+        sg2d.transform.getMatrix(lastCTM);
+
+        float a = (float) lastCTM[0];
+        float b = (float) lastCTM[1];
+        float c = (float) lastCTM[2];
+        float d = (float) lastCTM[3];
+        float tx = (float) lastCTM[4];
+        float ty = (float) lastCTM[5];
+        if (tx != lastCTMtx ||
+                ty != lastCTMty ||
+                    a != lastCTMa ||
+                        b != lastCTMb ||
+                            c != lastCTMc ||
+                                d != lastCTMd) {
+            this.fGraphicsStatesFloat.put(kCTMaIndex, a);
+            this.fGraphicsStatesFloat.put(kCTMbIndex, b);
+            this.fGraphicsStatesFloat.put(kCTMcIndex, c);
+            this.fGraphicsStatesFloat.put(kCTMdIndex, d);
+            this.fGraphicsStatesFloat.put(kCTMtxIndex, tx);
+            this.fGraphicsStatesFloat.put(kCTMtyIndex, ty);
+
+            lastCTMa = a;
+            lastCTMb = b;
+            lastCTMc = c;
+            lastCTMd = d;
+            lastCTMtx = tx;
+            lastCTMty = ty;
+
+            this.fChangeFlag = (this.fChangeFlag | kCTMChangedBit);
+        } else {
+            this.fChangeFlag = (this.fChangeFlag & kCTMNotChangedBit);
+        }
+    }
+
+    static AffineTransform sIdentityMatrix = new AffineTransform();
+    Paint lastPaint = null;
+    long lastPaintPtr = 0;
+    int lastPaintRGB = 0;
+    int lastPaintIndex = 0;
+    BufferedImage texturePaintImage = null;
+
+    void setupPaint(SunGraphics2D sg2d, int x, int y, int w, int h) {
+        if (sg2d.paint instanceof SystemColor) {
+            SystemColor color = (SystemColor) sg2d.paint;
+            int index = color.hashCode(); // depends on Color.java hashCode implementation! (returns "value" of color)
+            if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorSystem) || (index != this.lastPaintIndex)) {
+                this.lastPaintIndex = index;
+
+                this.fGraphicsStatesInt.put(kColorStateIndex, kColorSystem);
+                this.fGraphicsStatesInt.put(kColorIndexValueIndex, index);
+
+                this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
+            } else {
+                this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
+            }
+        } else if (sg2d.paint instanceof Color) {
+            Color color = (Color) sg2d.paint;
+            int rgb = color.getRGB();
+            if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorSimple) || (rgb != this.lastPaintRGB)) {
+                this.lastPaintRGB = rgb;
+
+                this.fGraphicsStatesInt.put(kColorStateIndex, kColorSimple);
+                this.fGraphicsStatesInt.put(kColorRGBValueIndex, rgb);
+
+                this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
+            } else {
+                this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
+            }
+        } else if (sg2d.paint instanceof GradientPaint) {
+            if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorGradient) || (lastPaint != sg2d.paint)) {
+                GradientPaint color = (GradientPaint) sg2d.paint;
+                this.fGraphicsStatesInt.put(kColorStateIndex, kColorGradient);
+                this.fGraphicsStatesInt.put(kColorRGBValue1Index, color.getColor1().getRGB());
+                this.fGraphicsStatesInt.put(kColorRGBValue2Index, color.getColor2().getRGB());
+                this.fGraphicsStatesInt.put(kColorIsCyclicIndex, (color.isCyclic()) ? kColorCyclic : kColorNonCyclic);
+                Point2D p = color.getPoint1();
+                this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());
+                this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());
+                p = color.getPoint2();
+                this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());
+                this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());
+
+                this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
+            } else {
+                this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
+            }
+        } else if (sg2d.paint instanceof TexturePaint) {
+            if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorTexture) || (lastPaint != sg2d.paint)) {
+                TexturePaint color = (TexturePaint) sg2d.paint;
+                this.fGraphicsStatesInt.put(kColorStateIndex, kColorTexture);
+                texturePaintImage = color.getImage();
+                SurfaceData textureSurfaceData = BufImgSurfaceData.createData(texturePaintImage);
+                this.fGraphicsStatesInt.put(kColorWidthIndex, texturePaintImage.getWidth());
+                this.fGraphicsStatesInt.put(kColorHeightIndex, texturePaintImage.getHeight());
+                Rectangle2D anchor = color.getAnchorRect();
+                this.fGraphicsStatesFloat.put(kColortxIndex, (float) anchor.getX());
+                this.fGraphicsStatesFloat.put(kColortyIndex, (float) anchor.getY());
+                this.fGraphicsStatesFloat.put(kColorsxIndex, (float) (anchor.getWidth() / texturePaintImage.getWidth()));
+                this.fGraphicsStatesFloat.put(kColorsyIndex, (float) (anchor.getHeight() / texturePaintImage.getHeight()));
+                this.fGraphicsStatesObject[kTextureImageIndex] = textureSurfaceData;
+
+                this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
+            } else {
+                this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
+            }
+        } else {
+            if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorTexture) || (lastPaint != sg2d.paint) || ((this.fChangeFlag & kBoundsChangedBit) != 0)) {
+                PaintContext context = sg2d.paint.createContext(sg2d.getDeviceColorModel(), userBounds, userBounds, sIdentityMatrix, sg2d.getRenderingHints());
+                WritableRaster raster = (WritableRaster) (context.getRaster(userBounds.x, userBounds.y, userBounds.width, userBounds.height));
+                ColorModel cm = context.getColorModel();
+                texturePaintImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
+
+                this.fGraphicsStatesInt.put(kColorStateIndex, kColorTexture);
+                this.fGraphicsStatesInt.put(kColorWidthIndex, texturePaintImage.getWidth());
+                this.fGraphicsStatesInt.put(kColorHeightIndex, texturePaintImage.getHeight());
+                this.fGraphicsStatesFloat.put(kColortxIndex, (float) userBounds.getX());
+                this.fGraphicsStatesFloat.put(kColortyIndex, (float) userBounds.getY());
+                this.fGraphicsStatesFloat.put(kColorsxIndex, 1.0f);
+                this.fGraphicsStatesFloat.put(kColorsyIndex, 1.0f);
+                this.fGraphicsStatesObject[kTextureImageIndex] = sun.awt.image.BufImgSurfaceData.createData(texturePaintImage);
+
+                context.dispose();
+
+                this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
+            } else {
+                this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
+            }
+        }
+        lastPaint = sg2d.paint;
+    }
+
+    Composite lastComposite;
+    int lastCompositeAlphaRule = 0;
+    float lastCompositeAlphaValue = 0;
+
+    void setupComposite(SunGraphics2D sg2d) {
+        Composite composite = sg2d.composite;
+
+        if (lastComposite != composite) {
+            lastComposite = composite;
+
+            // For composite state COMP_ISCOPY, COMP_XOR or COMP_CUSTOM set alpha compositor to COPY:
+            int alphaRule = AlphaComposite.SRC_OVER;
+            float alphaValue = 1.0f;
+
+            // For composite state COMP_ISCOPY composite could be null. If it's not (or composite state == COMP_ALPHA)
+            // get alpha compositor's values:
+            if ((sg2d.compositeState <= SunGraphics2D.COMP_ALPHA) && (composite != null)) {
+                AlphaComposite alphaComposite = (AlphaComposite) composite;
+                alphaRule = alphaComposite.getRule();
+                alphaValue = alphaComposite.getAlpha();
+            }
+
+            // 2-17-03 VL: [Radar 3174922]
+            // For COMP_XOR and COMP_CUSTOM compositing modes we should be setting alphaRule = AlphaComposite.SRC
+            // which should map to kCGCompositeCopy.
+
+            if ((lastCompositeAlphaRule != alphaRule) || (lastCompositeAlphaValue != alphaValue)) {
+                this.fGraphicsStatesInt.put(kCompositeRuleIndex, alphaRule);
+                this.fGraphicsStatesFloat.put(kCompositeValueIndex, alphaValue);
+
+                lastCompositeAlphaRule = alphaRule;
+                lastCompositeAlphaValue = alphaValue;
+
+                this.fChangeFlag = (this.fChangeFlag | kCompositeChangedBit);
+            } else {
+                this.fChangeFlag = (this.fChangeFlag & kCompositeNotChangedBit);
+            }
+        } else {
+            this.fChangeFlag = (this.fChangeFlag & kCompositeNotChangedBit);
+        }
+    }
+
+    BasicStroke lastStroke = null;
+    static BasicStroke defaultBasicStroke = new BasicStroke();
+
+    void setupStroke(SunGraphics2D sg2d) {
+        BasicStroke stroke = defaultBasicStroke;
+
+        if (sg2d.stroke instanceof BasicStroke) {
+            stroke = (BasicStroke) sg2d.stroke;
+        }
+
+        if (lastStroke != stroke) {
+            this.fGraphicsStatesObject[kStrokeDashArrayIndex] = stroke.getDashArray();
+            this.fGraphicsStatesFloat.put(kStrokeDashPhaseIndex, stroke.getDashPhase());
+            this.fGraphicsStatesInt.put(kStrokeCapIndex, stroke.getEndCap());
+            this.fGraphicsStatesInt.put(kStrokeJoinIndex, stroke.getLineJoin());
+            this.fGraphicsStatesFloat.put(kStrokeWidthIndex, stroke.getLineWidth());
+            this.fGraphicsStatesFloat.put(kStrokeLimitIndex, stroke.getMiterLimit());
+
+            this.fChangeFlag = (this.fChangeFlag | kStrokeChangedBit);
+
+            lastStroke = stroke;
+        } else {
+            this.fChangeFlag = (this.fChangeFlag & kStrokeNotChangedBit);
+        }
+    }
+
+    Font lastFont;
+
+    void setupFont(Font font, Paint paint) {
+        if (font == null) { return; }
+
+        // We have to setup the kFontPaintIndex if we have changed the color so we added the last
+        // test to see if the color has changed - needed for complex strings
+        // see Radar 3368674
+        if ((font != lastFont) || ((this.fChangeFlag & kColorChangedBit) != 0)) {
+            this.fGraphicsStatesObject[kFontIndex] = font;
+            this.fGraphicsStatesObject[kFontPaintIndex] = paint;
+
+            this.fChangeFlag = (this.fChangeFlag | kFontChangedBit);
+
+            lastFont = font;
+        } else {
+            this.fChangeFlag = (this.fChangeFlag & kFontNotChangedBit);
+        }
+    }
+
+    void setupRenderingHints(SunGraphics2D sg2d) {
+        boolean hintsChanged = false;
+
+        // Significant for draw, fill, text, and image ops:
+        int antialiasHint = sg2d.antialiasHint;
+        if (this.fGraphicsStatesInt.get(kHintsAntialiasIndex) != antialiasHint) {
+            this.fGraphicsStatesInt.put(kHintsAntialiasIndex, antialiasHint);
+            hintsChanged = true;
+        }
+
+        // Significant only for text ops:
+        int textAntialiasHint = sg2d.textAntialiasHint;
+        if (this.fGraphicsStatesInt.get(kHintsTextAntialiasIndex) != textAntialiasHint) {
+            this.fGraphicsStatesInt.put(kHintsTextAntialiasIndex, textAntialiasHint);
+            hintsChanged = true;
+        }
+
+        // Significant only for text ops:
+        int fractionalMetricsHint = sg2d.fractionalMetricsHint;
+        if (this.fGraphicsStatesInt.get(kHintsFractionalMetricsIndex) != fractionalMetricsHint) {
+            this.fGraphicsStatesInt.put(kHintsFractionalMetricsIndex, fractionalMetricsHint);
+            hintsChanged = true;
+        }
+
+        // Significant only for image ops:
+        int renderHint = sg2d.renderHint;
+        if (this.fGraphicsStatesInt.get(kHintsRenderingIndex) != renderHint) {
+            this.fGraphicsStatesInt.put(kHintsRenderingIndex, renderHint);
+            hintsChanged = true;
+        }
+
+        // Significant only for image ops:
+        Object hintValue = sg2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
+        int interpolationHint = (hintValue != null ? ((SunHints.Value) hintValue).getIndex() : -1);
+        if (this.fGraphicsStatesInt.get(kHintsInterpolationIndex) != interpolationHint) {
+            this.fGraphicsStatesInt.put(kHintsInterpolationIndex, interpolationHint);
+            hintsChanged = true;
+        }
+
+        if (hintsChanged) {
+            this.fChangeFlag = (this.fChangeFlag | kHintsChangedBit);
+        } else {
+            this.fChangeFlag = (this.fChangeFlag & kHintsNotChangedBit);
+        }
+    }
+
+    SunGraphics2D sg2dCurrent = null;
+    Thread threadCurrent = null;
+
+    void setupGraphicsState(SunGraphics2D sg2d, int primitiveType) {
+        setupGraphicsState(sg2d, primitiveType, sg2d.font, 0, 0, fBounds.width, fBounds.height); // deviceBounds into userBounds
+    }
+
+    void setupGraphicsState(SunGraphics2D sg2d, int primitiveType, int x, int y, int w, int h) {
+        setupGraphicsState(sg2d, primitiveType, sg2d.font, x, y, w, h);
+    }
+
+    // the method below is overriden by CPeerSurface to check the last peer used to draw
+    // if the peer changed we finish lazy drawing
+    void setupGraphicsState(SunGraphics2D sg2d, int primitiveType, Font font, int x, int y, int w, int h) {
+        this.fChangeFlag = 0;
+
+        setUserBounds(sg2d, x, y, w, h);
+
+        Thread thread = Thread.currentThread();
+        if ((this.sg2dCurrent != sg2d) || (this.threadCurrent != thread)) {
+            this.sg2dCurrent = sg2d;
+            this.threadCurrent = thread;
+
+            setupClip(sg2d);
+            setupTransform(sg2d);
+            setupPaint(sg2d, x, y, w, h);
+            setupComposite(sg2d);
+            setupStroke(sg2d);
+            setupFont(font, sg2d.paint);
+            setupRenderingHints(sg2d);
+
+            this.fChangeFlag = kEverythingChangedFlag;
+        } else {
+            int rendererType = getRendererTypeForPrimitive(primitiveType);
+
+            setupClip(sg2d);
+            setupTransform(sg2d);
+
+            if (rendererType != kCopyArea) {
+                setupComposite(sg2d);
+                setupRenderingHints(sg2d);
+
+                if ((rendererType != kImage)) {
+                    setupPaint(sg2d, x, y, w, h);
+                    setupStroke(sg2d);
+                }
+                if (rendererType != kPrimitive) {
+                    setupFont(font, sg2d.paint);
+                }
+
+            }
+        }
+
+        this.fGraphicsStatesInt.put(kChangeFlagIndex, this.fChangeFlag);
+    }
+
+    boolean isCustomPaint(SunGraphics2D sg2d) {
+        if ((sg2d.paint instanceof Color) || (sg2d.paint instanceof SystemColor) || (sg2d.paint instanceof GradientPaint) || (sg2d.paint instanceof TexturePaint)) { return false; }
+
+        return true;
+    }
+
+    final float[] segmentCoordinatesArray = new float[6];
+
+    int getPathLength(GeneralPath gp) {
+        int length = 0;
+
+        PathIterator pi = gp.getPathIterator(null);
+        while (pi.isDone() == false) {
+            pi.next();
+            length++;
+        }
+
+        return length;
+    }
+
+    int getPathCoordinates(GeneralPath gp, FloatBuffer coordinates, IntBuffer types) {
+        // System.err.println("getPathCoordinates");
+        boolean skip = false;
+
+        coordinates.clear();
+        types.clear();
+
+        int type;
+
+        PathIterator pi = gp.getPathIterator(null);
+        while (pi.isDone() == false) {
+            skip = false;
+            type = pi.currentSegment(segmentCoordinatesArray);
+
+            switch (type) {
+                case PathIterator.SEG_MOVETO:
+                    // System.err.println(" SEG_MOVETO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+")");
+                    if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&
+                            segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND) {
+                        coordinates.put(segmentCoordinatesArray[0]);
+                        coordinates.put(segmentCoordinatesArray[1]);
+                    } else {
+                        skip = true;
+                    }
+                    break;
+                case PathIterator.SEG_LINETO:
+                    // System.err.println(" SEG_LINETO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+")");
+                    if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&
+                            segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND) {
+                        coordinates.put(segmentCoordinatesArray[0]);
+                        coordinates.put(segmentCoordinatesArray[1]);
+                    } else {
+                        skip = true;
+                    }
+                    break;
+                case PathIterator.SEG_QUADTO:
+                    // System.err.println(" SEG_QUADTO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+"), ("+segmentCoordinatesArray[2]+", "+segmentCoordinatesArray[3]+")");
+                    if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&
+                            segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND &&
+                            segmentCoordinatesArray[2] < UPPER_BND && segmentCoordinatesArray[2] > LOWER_BND &&
+                            segmentCoordinatesArray[3] < UPPER_BND && segmentCoordinatesArray[3] > LOWER_BND) {
+                        coordinates.put(segmentCoordinatesArray[0]);
+                        coordinates.put(segmentCoordinatesArray[1]);
+                        coordinates.put(segmentCoordinatesArray[2]);
+                        coordinates.put(segmentCoordinatesArray[3]);
+                    } else {
+                        skip = true;
+                    }
+                    break;
+                case PathIterator.SEG_CUBICTO:
+                    // System.err.println(" SEG_QUADTO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+"), ("+segmentCoordinatesArray[2]+", "+segmentCoordinatesArray[3]+"), ("+segmentCoordinatesArray[4]+", "+segmentCoordinatesArray[5]+")");
+                    if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&
+                            segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND &&
+                            segmentCoordinatesArray[2] < UPPER_BND && segmentCoordinatesArray[2] > LOWER_BND &&
+                            segmentCoordinatesArray[3] < UPPER_BND && segmentCoordinatesArray[3] > LOWER_BND &&
+                            segmentCoordinatesArray[4] < UPPER_BND && segmentCoordinatesArray[4] > LOWER_BND &&
+                            segmentCoordinatesArray[5] < UPPER_BND && segmentCoordinatesArray[5] > LOWER_BND) {
+                        coordinates.put(segmentCoordinatesArray[0]);
+                        coordinates.put(segmentCoordinatesArray[1]);
+                        coordinates.put(segmentCoordinatesArray[2]);
+                        coordinates.put(segmentCoordinatesArray[3]);
+                        coordinates.put(segmentCoordinatesArray[4]);
+                        coordinates.put(segmentCoordinatesArray[5]);
+                    } else {
+                        skip = true;
+                    }
+                    break;
+                case PathIterator.SEG_CLOSE:
+                    // System.err.println(" SEG_CLOSE");
+                    break;
+            }
+
+            if (!skip) {
+                types.put(type);
+            }
+
+            pi.next();
+        }
+
+        return pi.getWindingRule();
+    }
+
+    public void doLine(CRenderer renderer, SunGraphics2D sg2d, float x1, float y1, float x2, float y2) {
+        // System.err.println("-- doLine x1="+x1+" y1="+y1+" x2="+x2+" y2="+y2+" paint="+sg2d.paint);
+        setupGraphicsState(sg2d, kLine, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        renderer.doLine(this, x1, y1, x2, y2);
+    }
+
+    public void doRect(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, boolean isfill) {
+        // System.err.println("-- doRect x="+x+" y="+y+" w="+width+" h="+height+" isfill="+isfill+" paint="+sg2d.paint);
+        if ((isfill) && (isCustomPaint(sg2d))) {
+            setupGraphicsState(sg2d, kRect, (int) x, (int) y, (int) width, (int) height);
+        } else {
+            setupGraphicsState(sg2d, kRect, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        }
+        renderer.doRect(this, x, y, width, height, isfill);
+    }
+
+    public void doRoundRect(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, float arcW, float arcH, boolean isfill) {
+        // System.err.println("--- doRoundRect");
+        if ((isfill) && (isCustomPaint(sg2d))) {
+            setupGraphicsState(sg2d, kRoundRect, (int) x, (int) y, (int) width, (int) height);
+        } else {
+            setupGraphicsState(sg2d, kRoundRect, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        }
+        renderer.doRoundRect(this, x, y, width, height, arcW, arcH, isfill);
+    }
+
+    public void doOval(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, boolean isfill) {
+        // System.err.println("--- doOval");
+        if ((isfill) && (isCustomPaint(sg2d))) {
+            setupGraphicsState(sg2d, kOval, (int) x, (int) y, (int) width, (int) height);
+        } else {
+            setupGraphicsState(sg2d, kOval, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        }
+        renderer.doOval(this, x, y, width, height, isfill);
+    }
+
+    public void doArc(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type, boolean isfill) {
+        // System.err.println("--- doArc");
+        if ((isfill) && (isCustomPaint(sg2d))) {
+            setupGraphicsState(sg2d, kArc, (int) x, (int) y, (int) width, (int) height);
+        } else {
+            setupGraphicsState(sg2d, kArc, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        }
+
+        renderer.doArc(this, x, y, width, height, startAngle, arcAngle, type, isfill);
+    }
+
+    public void doPolygon(CRenderer renderer, SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints, boolean ispolygon, boolean isfill) {
+        // System.err.println("--- doPolygon");
+
+        if ((isfill) && (isCustomPaint(sg2d))) {
+            int minx = xpoints[0];
+            int miny = ypoints[0];
+            int maxx = minx;
+            int maxy = miny;
+            for (int i = 1; i < npoints; i++) {
+                int x = xpoints[i];
+                if (x < minx) {
+                    minx = x;
+                } else if (x > maxx) {
+                    maxx = x;
+                }
+
+                int y = ypoints[i];
+                if (y < miny) {
+                    miny = y;
+                } else if (y > maxy) {
+                    maxy = y;
+                }
+            }
+            setupGraphicsState(sg2d, kPolygon, minx, miny, maxx - minx, maxy - miny);
+        } else {
+            setupGraphicsState(sg2d, kPolygon, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        }
+        renderer.doPoly(this, xpoints, ypoints, npoints, ispolygon, isfill);
+    }
+
+    FloatBuffer shapeCoordinatesArray = null;
+    IntBuffer shapeTypesArray = null;
+
+    public void drawfillShape(CRenderer renderer, SunGraphics2D sg2d, GeneralPath gp, boolean isfill, boolean shouldApplyOffset) {
+        // System.err.println("--- drawfillShape");
+
+        if ((isfill) && (isCustomPaint(sg2d))) {
+            Rectangle bounds = gp.getBounds();
+            setupGraphicsState(sg2d, kShape, bounds.x, bounds.y, bounds.width, bounds.height);
+        } else {
+            setupGraphicsState(sg2d, kShape, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        }
+
+        int shapeLength = getPathLength(gp);
+
+        if ((shapeCoordinatesArray == null) || (shapeCoordinatesArray.capacity() < (shapeLength * 6))) {
+            shapeCoordinatesArray = getBufferOfSize(shapeLength * 6).asFloatBuffer(); // segment can have a max of 6
+                                                                                      // coordinates
+        }
+        if ((shapeTypesArray == null) || (shapeTypesArray.capacity() < shapeLength)) {
+            shapeTypesArray = getBufferOfSize(shapeLength).asIntBuffer();
+        }
+
+        int windingRule = getPathCoordinates(gp, shapeCoordinatesArray, shapeTypesArray);
+
+        renderer.doShape(this, shapeLength, shapeCoordinatesArray, shapeTypesArray, windingRule, isfill, shouldApplyOffset);
+    }
+
+    public void blitImage(CRenderer renderer, SunGraphics2D sg2d, SurfaceData img, boolean fliph, boolean flipv, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, Color bgColor) {
+        // System.err.println("--- blitImage sx="+sx+", sy="+sy+", sw="+sw+", sh="+sh+", img="+img);
+        OSXOffScreenSurfaceData osxsd = (OSXOffScreenSurfaceData) img;
+        synchronized (osxsd.getLockObject()) {
+            int w = osxsd.bim.getWidth();
+            int h = osxsd.bim.getHeight();
+
+            // the image itself can have outstanding graphics primitives that might need to be flushed
+            setupGraphicsState(sg2d, kImage, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+
+            // 04/06/04 cmc: radr://3612381 Graphics.drawImage ignores bgcolor parameter
+            if (bgColor != null) {
+                img = osxsd.getCopyWithBgColor(bgColor);
+            }
+
+            renderer.doImage(this, img, fliph, flipv, w, h, sx, sy, sw, sh, dx, dy, dw, dh);
+        }
+    }
+
+    public interface CGContextDrawable {
+        public void drawIntoCGContext(final long cgContext);
+    }
+
+    public void drawString(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, String str, double x, double y) {
+        // System.err.println("--- drawString str=\""+str+"\"");
+        // see <rdar://problem/3825795>. We don't want to call anything if the string is empty!
+        if (str.length() == 0) { return; }
+
+        setupGraphicsState(sg2d, kString, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        renderer.doDrawString(this, nativeStrikePtr, str, x, y);
+    }
+
+    public void drawGlyphs(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, GlyphVector gv, float x, float y) {
+        // System.err.println("--- drawGlyphs");
+        setupGraphicsState(sg2d, kGlyphs, gv.getFont(), 0, 0, fBounds.width, fBounds.height);
+        renderer.doDrawGlyphs(this, nativeStrikePtr, gv, x, y);
+    }
+
+    public void drawUnicodes(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, char unicodes[], int offset, int length, float x, float y) {
+        // System.err.println("--- drawUnicodes "+(new String(unicodes, offset, length)));
+        setupGraphicsState(sg2d, kUnicodes, sg2d.font, 0, 0, fBounds.width, fBounds.height);
+        if (length == 1) {
+            renderer.doOneUnicode(this, nativeStrikePtr, unicodes[offset], x, y);
+        } else {
+            renderer.doUnicodes(this, nativeStrikePtr, unicodes, offset, length, x, y);
+        }
+    }
+
+    // used by copyArea:
+
+    Rectangle srcCopyAreaRect = new Rectangle();
+    Rectangle dstCopyAreaRect = new Rectangle();
+    Rectangle finalCopyAreaRect = new Rectangle();
+    Rectangle copyAreaBounds = new Rectangle();
+
+    void intersection(Rectangle r1, Rectangle r2, Rectangle r3) {
+        // this code is taken from Rectangle.java (modified to put results in r3)
+        int tx1 = r1.x;
+        int ty1 = r1.y;
+        long tx2 = tx1 + r1.width;
+        long ty2 = ty1 + r1.height;
+
+        int rx1 = r2.x;
+        int ry1 = r2.y;
+        long rx2 = rx1 + r2.width;
+        long ry2 = ry1 + r2.height;
+
+        if (tx1 < rx1) tx1 = rx1;
+        if (ty1 < ry1) ty1 = ry1;
+        if (tx2 > rx2) tx2 = rx2;
+        if (ty2 > ry2) ty2 = ry2;
+
+        tx2 -= tx1;
+        ty2 -= ty1;
+
+        // tx2,ty2 will never overflow (they will never be
+        // larger than the smallest of the two source w,h)
+        // they might underflow, though...
+        if (tx2 < Integer.MIN_VALUE) tx2 = Integer.MIN_VALUE;
+        if (ty2 < Integer.MIN_VALUE) ty2 = Integer.MIN_VALUE;
+
+        r3.setBounds(tx1, ty1, (int) tx2, (int) ty2);
+    }
+
+    /**
+     * Clips the copy area to the heavywieght bounds and returns the cliped rectangle. The tricky part here is the the
+     * passed arguments x, y are in the coordinate space of the sg2d/lightweight comp. In order to do the clipping we
+     * translate them to the coordinate space of the surface, and the returned clipped rectangle is in the coordinate
+     * space of the surface.
+     */
+    protected Rectangle clipCopyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy) {
+        // we need to clip against the heavyweight bounds
+        copyAreaBounds.setBounds(sg2d.devClip.getLoX(), sg2d.devClip.getLoY(), sg2d.devClip.getWidth(), sg2d.devClip.getHeight());
+
+        // put src rect into surface coordinate space
+        x += sg2d.transX;
+        y += sg2d.transY;
+
+        // clip src rect
+        srcCopyAreaRect.setBounds(x, y, w, h);
+        intersection(srcCopyAreaRect, copyAreaBounds, srcCopyAreaRect);
+        if ((srcCopyAreaRect.width <= 0) || (srcCopyAreaRect.height <= 0)) {
+            // src rect outside bounds
+            return null;
+        }
+
+        // clip dst rect
+        dstCopyAreaRect.setBounds(srcCopyAreaRect.x + dx, srcCopyAreaRect.y + dy, srcCopyAreaRect.width, srcCopyAreaRect.height);
+        intersection(dstCopyAreaRect, copyAreaBounds, dstCopyAreaRect);
+        if ((dstCopyAreaRect.width <= 0) || (dstCopyAreaRect.height <= 0)) {
+            // dst rect outside clip
+            return null;
+        }
+
+        x = dstCopyAreaRect.x - dx;
+        y = dstCopyAreaRect.y - dy;
+        w = dstCopyAreaRect.width;
+        h = dstCopyAreaRect.height;
+
+        finalCopyAreaRect.setBounds(x, y, w, h);
+
+        return finalCopyAreaRect;
+    }
+
+    // <rdar://3785539> We only need to mark dirty on screen surfaces. This method is
+    // marked as protected and it is intended for subclasses to override if they need to
+    // be notified when the surface is dirtied. See CPeerSurfaceData.markDirty() for implementation.
+    // We don't do anything for buffered images.
+    protected void markDirty(boolean markAsDirty) {
+        // do nothing by default
+    }
+
+    // LazyDrawing optimization implementation:
+
+    @Override
+    public boolean canRenderLCDText(SunGraphics2D sg2d) {
+        if (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&
+                sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
+                sg2d.clipState <= SunGraphics2D.CLIP_RECTANGULAR &&
+                // sg2d.surfaceData.getTransparency() == Transparency.OPAQUE &&
+                // This last test is a workaround until we fix loop selection
+                // in the pipe validation
+                sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { return true; }
+        return false; /* for now - in the future we may want to search */
+    }
+
+    public static boolean IsSimpleColor(Object c) {
+        return ((c instanceof Color) || (c instanceof SystemColor) || (c instanceof javax.swing.plaf.ColorUIResource));
+    }
+
+    static {
+        if ((kColorPointerIndex % 2) != 0) {
+            System.err.println("kColorPointerIndex=" + kColorPointerIndex + " is NOT aligned for 64 bit");
+            System.exit(0);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java b/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
new file mode 100644
index 0000000..ba0b16f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
@@ -0,0 +1,501 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d.opengl;
+
+import java.awt.AWTException;
+import java.awt.BufferCapabilities;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.ImageCapabilities;
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DirectColorModel;
+import java.awt.image.VolatileImage;
+import java.awt.image.WritableRaster;
+
+import sun.awt.CGraphicsConfig;
+import sun.awt.CGraphicsDevice;
+import sun.awt.image.OffScreenImage;
+import sun.awt.image.SunVolatileImage;
+import sun.awt.image.SurfaceManager;
+import sun.java2d.Disposer;
+import sun.java2d.DisposerRecord;
+import sun.java2d.SunGraphics2D;
+import sun.java2d.Surface;
+import sun.java2d.SurfaceData;
+import sun.java2d.opengl.OGLContext.OGLContextCaps;
+import sun.java2d.pipe.hw.AccelSurface;
+import sun.java2d.pipe.hw.AccelTypedVolatileImage;
+import sun.java2d.pipe.hw.ContextCapabilities;
+import static sun.java2d.opengl.OGLSurfaceData.*;
+import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
+import sun.java2d.opengl.CGLSurfaceData.CGLVSyncOffScreenSurfaceData;
+import sun.java2d.pipe.hw.AccelDeviceEventListener;
+import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
+
+import sun.lwawt.macosx.CPlatformView;
+
+public class CGLGraphicsConfig extends CGraphicsConfig
+    implements OGLGraphicsConfig
+{
+    //private static final int kOpenGLSwapInterval = RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
+    private static final int kOpenGLSwapInterval = 0; // TODO
+    protected static boolean cglAvailable;
+    private static ImageCapabilities imageCaps = new CGLImageCaps();
+
+    private int pixfmt;
+    private BufferCapabilities bufferCaps;
+    private long pConfigInfo;
+    private ContextCapabilities oglCaps;
+    private OGLContext context;
+    private Object disposerReferent = new Object();
+
+    public static native int getDefaultPixFmt(int screennum);
+    private static native boolean initCGL();
+    private static native long getCGLConfigInfo(int screennum, int visualnum,
+                                                int swapInterval);
+    private static native int getOGLCapabilities(long configInfo);
+
+    static {
+        cglAvailable = initCGL();
+    }
+
+    protected CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
+                                long configInfo, ContextCapabilities oglCaps)
+    {
+        super(device);
+
+        this.pixfmt = pixfmt;
+        this.pConfigInfo = configInfo;
+        this.oglCaps = oglCaps;
+        context = new OGLContext(OGLRenderQueue.getInstance(), this);
+
+        // add a record to the Disposer so that we destroy the native
+        // CGLGraphicsConfigInfo data when this object goes away
+        Disposer.addRecord(disposerReferent,
+                           new CGLGCDisposerRecord(pConfigInfo));
+    }
+
+    @Override
+    public Object getProxyKey() {
+        return this;
+    }
+
+    @Override
+    public SurfaceData createManagedSurface(int w, int h, int transparency) {
+        return CGLSurfaceData.createData(this, w, h,
+                                         getColorModel(transparency),
+                                         null,
+                                         OGLSurfaceData.TEXTURE);
+    }
+
+    public static CGLGraphicsConfig getConfig(CGraphicsDevice device,
+                                              int pixfmt)
+    {
+        if (!cglAvailable) {
+            return null;
+        }
+
+        long cfginfo = 0;
+        final String ids[] = new String[1];
+        OGLRenderQueue rq = OGLRenderQueue.getInstance();
+        rq.lock();
+        try {
+            // getCGLConfigInfo() creates and destroys temporary
+            // surfaces/contexts, so we should first invalidate the current
+            // Java-level context and flush the queue...
+            OGLContext.invalidateCurrentContext();
+            CGLGetConfigInfo action =
+                new CGLGetConfigInfo(device.getCoreGraphicsScreen(), pixfmt);
+            rq.flushAndInvokeNow(action);
+            cfginfo = action.getConfigInfo();
+            OGLContext.setScratchSurface(cfginfo);
+            rq.flushAndInvokeNow(new Runnable() {
+                public void run() {
+                    ids[0] = OGLContext.getOGLIdString();
+                }
+            });
+        } finally {
+            rq.unlock();
+        }
+        if (cfginfo == 0) {
+            return null;
+        }
+
+        int oglCaps = getOGLCapabilities(cfginfo);
+        ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]);
+
+        return new CGLGraphicsConfig(device, pixfmt, cfginfo, caps);
+    }
+
+    /**
+     * This is a small helper class that allows us to execute
+     * getCGLConfigInfo() on the queue flushing thread.
+     */
+    private static class CGLGetConfigInfo implements Runnable {
+        private int screen;
+        private int pixfmt;
+        private long cfginfo;
+        private CGLGetConfigInfo(int screen, int pixfmt) {
+            this.screen = screen;
+            this.pixfmt = pixfmt;
+        }
+        public void run() {
+            cfginfo = getCGLConfigInfo(screen, pixfmt, kOpenGLSwapInterval);
+        }
+        public long getConfigInfo() {
+            return cfginfo;
+        }
+    }
+
+    public static boolean isCGLAvailable() {
+        return cglAvailable;
+    }
+
+    /**
+     * Returns true if the provided capability bit is present for this config.
+     * See OGLContext.java for a list of supported capabilities.
+     */
+    public final boolean isCapPresent(int cap) {
+        return ((oglCaps.getCaps() & cap) != 0);
+    }
+
+    public final long getNativeConfigInfo() {
+        return pConfigInfo;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
+     */
+    public final OGLContext getContext() {
+        return context;
+    }
+
+    @Override
+    public BufferedImage createCompatibleImage(int width, int height) {
+        ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
+        WritableRaster
+            raster = model.createCompatibleWritableRaster(width, height);
+        return new BufferedImage(model, raster, model.isAlphaPremultiplied(),
+                                 null);
+    }
+
+    @Override
+    public ColorModel getColorModel(int transparency) {
+        switch (transparency) {
+        case Transparency.OPAQUE:
+            // REMIND: once the ColorModel spec is changed, this should be
+            //         an opaque premultiplied DCM...
+            return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
+        case Transparency.BITMASK:
+            return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
+        case Transparency.TRANSLUCENT:
+            ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+            return new DirectColorModel(cs, 32,
+                                        0xff0000, 0xff00, 0xff, 0xff000000,
+                                        true, DataBuffer.TYPE_INT);
+        default:
+            return null;
+        }
+    }
+
+    public boolean isDoubleBuffered() {
+        return isCapPresent(CAPS_DOUBLEBUFFERED);
+    }
+
+    private static class CGLGCDisposerRecord implements DisposerRecord {
+        private long pCfgInfo;
+        public CGLGCDisposerRecord(long pCfgInfo) {
+            this.pCfgInfo = pCfgInfo;
+        }
+        public void dispose() {
+            if (pCfgInfo != 0) {
+                OGLRenderQueue.disposeGraphicsConfig(pCfgInfo);
+                pCfgInfo = 0;
+            }
+        }
+    }
+
+    // TODO: CGraphicsConfig doesn't implement displayChanged() yet
+    //@Override
+    public synchronized void displayChanged() {
+        //super.displayChanged();
+
+        // the context could hold a reference to a CGLSurfaceData, which in
+        // turn has a reference back to this CGLGraphicsConfig, so in order
+        // for this instance to be disposed we need to break the connection
+        OGLRenderQueue rq = OGLRenderQueue.getInstance();
+        rq.lock();
+        try {
+            OGLContext.invalidateCurrentContext();
+        } finally {
+            rq.unlock();
+        }
+    }
+
+    @Override
+    public String toString() {
+        int screen = getDevice().getCoreGraphicsScreen();
+        return ("CGLGraphicsConfig[dev="+screen+",pixfmt="+pixfmt+"]");
+    }
+
+
+    /**
+     * The following methods are invoked from ComponentModel.java rather
+     * than having the Mac OS X-dependent implementations hardcoded in that
+     * class.  This way the appropriate actions are taken based on the peer's
+     * GraphicsConfig, whether it is a CGraphicsConfig or a
+     * CGLGraphicsConfig.
+     */
+
+    /**
+     * Creates a new SurfaceData that will be associated with the given
+     * LWWindowPeer.
+     */
+    @Override
+    public SurfaceData createSurfaceData(CPlatformView pView) {
+        return CGLSurfaceData.createData(pView);
+    }
+
+    /**
+     * Creates a new SurfaceData that will be associated with the given
+     * CGLLayer.
+     */
+    @Override
+    public SurfaceData createSurfaceData(CGLLayer layer) {
+        return CGLSurfaceData.createData(layer);
+    }
+
+    /**
+     * Creates a new hidden-acceleration image of the given width and height
+     * that is associated with the target Component.
+     */
+    @Override
+    public Image createAcceleratedImage(Component target,
+                                        int width, int height)
+    {
+        ColorModel model = getColorModel(Transparency.OPAQUE);
+        WritableRaster wr =
+            model.createCompatibleWritableRaster(width, height);
+        return new OffScreenImage(target, model, wr,
+                                  model.isAlphaPremultiplied());
+    }
+
+    /**
+     * The following methods correspond to the multibuffering methods in
+     * CWindowPeer.java...
+     */
+
+    /**
+     * Attempts to create a OGL-based backbuffer for the given peer.  If
+     * the requested configuration is not natively supported, an AWTException
+     * is thrown.  Otherwise, if the backbuffer creation is successful, a
+     * value of 1 is returned.
+     */
+    @Override
+    public long createBackBuffer(CPlatformView pView,
+                                 int numBuffers, BufferCapabilities caps)
+        throws AWTException
+    {
+        if (numBuffers > 2) {
+            throw new AWTException(
+                "Only double or single buffering is supported");
+        }
+        BufferCapabilities configCaps = getBufferCapabilities();
+        if (!configCaps.isPageFlipping()) {
+            throw new AWTException("Page flipping is not supported");
+        }
+        if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) {
+            throw new AWTException("FlipContents.PRIOR is not supported");
+        }
+
+        // non-zero return value means backbuffer creation was successful
+        // (checked in CPlatformWindow.flip(), etc.)
+        return 1;
+    }
+
+    /**
+     * Destroys the backbuffer object represented by the given handle value.
+     */
+    @Override
+    public void destroyBackBuffer(long backBuffer) {
+    }
+
+    /**
+     * Creates a VolatileImage that essentially wraps the target Component's
+     * backbuffer (the provided backbuffer handle is essentially ignored).
+     */
+    @Override
+    public VolatileImage createBackBufferImage(Component target,
+                                               long backBuffer)
+    {
+        return new SunVolatileImage(target,
+                                    target.getWidth(), target.getHeight(),
+                                    Boolean.TRUE);
+    }
+
+    /**
+     * Performs the native OGL flip operation for the given target Component.
+     */
+    @Override
+    public void flip(CPlatformView pView,
+                     Component target, VolatileImage xBackBuffer,
+                     int x1, int y1, int x2, int y2,
+                     BufferCapabilities.FlipContents flipAction)
+    {
+        if (flipAction == BufferCapabilities.FlipContents.COPIED) {
+            SurfaceManager vsm = SurfaceManager.getManager(xBackBuffer);
+            SurfaceData sd = vsm.getPrimarySurfaceData();
+
+            if (sd instanceof CGLVSyncOffScreenSurfaceData) {
+                CGLVSyncOffScreenSurfaceData vsd =
+                    (CGLVSyncOffScreenSurfaceData)sd;
+                SurfaceData bbsd = vsd.getFlipSurface();
+                Graphics2D bbg =
+                    new SunGraphics2D(bbsd, Color.black, Color.white, null);
+                try {
+                    bbg.drawImage(xBackBuffer, 0, 0, null);
+                } finally {
+                    bbg.dispose();
+                }
+            } else {
+                pView.drawImageOnPeer(xBackBuffer, x1, y1, x2, y2);
+                return;
+            }
+        } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
+            // not supported by CGL...
+            return;
+        }
+
+        OGLSurfaceData.swapBuffers(pView.getAWTView());
+
+        if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
+            Graphics g = xBackBuffer.getGraphics();
+            try {
+                g.setColor(target.getBackground());
+                g.fillRect(0, 0,
+                           xBackBuffer.getWidth(),
+                           xBackBuffer.getHeight());
+            } finally {
+                g.dispose();
+            }
+        }
+    }
+
+    private static class CGLBufferCaps extends BufferCapabilities {
+        public CGLBufferCaps(boolean dblBuf) {
+            super(imageCaps, imageCaps,
+                  dblBuf ? FlipContents.UNDEFINED : null);
+        }
+    }
+
+    @Override
+    public BufferCapabilities getBufferCapabilities() {
+        if (bufferCaps == null) {
+            bufferCaps = new CGLBufferCaps(isDoubleBuffered());
+        }
+        return bufferCaps;
+    }
+
+    private static class CGLImageCaps extends ImageCapabilities {
+        private CGLImageCaps() {
+            super(true);
+        }
+        public boolean isTrueVolatile() {
+            return true;
+        }
+    }
+
+    @Override
+    public ImageCapabilities getImageCapabilities() {
+        return imageCaps;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
+     */
+    public VolatileImage
+        createCompatibleVolatileImage(int width, int height,
+                                      int transparency, int type)
+    {
+        if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
+            transparency == Transparency.BITMASK)
+        {
+            return null;
+        }
+
+        if (type == FBOBJECT) {
+            if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
+                return null;
+            }
+        } else if (type == PBUFFER) {
+            boolean isOpaque = transparency == Transparency.OPAQUE;
+            if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
+                return null;
+            }
+        }
+
+        SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
+                                                          transparency, type);
+        Surface sd = vi.getDestSurface();
+        if (!(sd instanceof AccelSurface) ||
+            ((AccelSurface)sd).getType() != type)
+        {
+            vi.flush();
+            vi = null;
+        }
+
+        return vi;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
+     */
+    public ContextCapabilities getContextCapabilities() {
+        return oglCaps;
+    }
+
+    public void addDeviceEventListener(AccelDeviceEventListener l) {
+        int screen = getDevice().getCoreGraphicsScreen();
+        AccelDeviceEventNotifier.addListener(l, screen);
+    }
+
+    public void removeDeviceEventListener(AccelDeviceEventListener l) {
+        AccelDeviceEventNotifier.removeListener(l);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/opengl/CGLLayer.java b/jdk/src/macosx/classes/sun/java2d/opengl/CGLLayer.java
new file mode 100644
index 0000000..219c84c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLLayer.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d.opengl;
+
+import sun.lwawt.macosx.CFRetainedResource;
+import sun.lwawt.LWWindowPeer;
+
+import sun.java2d.SurfaceData;
+import sun.java2d.NullSurfaceData;
+
+import sun.awt.CGraphicsConfig;
+
+import java.awt.Rectangle;
+import java.awt.GraphicsConfiguration;
+import java.awt.Transparency;
+
+public class CGLLayer extends CFRetainedResource {
+
+    private native long nativeCreateLayer();
+
+    private static native void validate(long layerPtr, CGLSurfaceData cglsd);
+    private static native void blitTexture(long layerPtr);
+
+    private LWWindowPeer peer;
+
+    private SurfaceData surfaceData; // represents intermediate buffer (texture)
+
+    public CGLLayer(LWWindowPeer peer) {
+        super(0, true);
+
+        setPtr(nativeCreateLayer());
+        this.peer = peer;
+    }
+
+    public long getPointer() {
+        return ptr;
+    }
+
+    public Rectangle getBounds() {
+        return peer.getBounds();
+    }
+
+    public GraphicsConfiguration getGraphicsConfiguration() {
+        return peer.getGraphicsConfiguration();
+    }
+
+    public boolean isOpaque() {
+        return peer.isOpaque();
+    }
+
+    public int getTransparency() {
+        return (peer.isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT);
+    }
+
+    public Object getDestination() {
+        return peer;
+    }
+
+    public SurfaceData replaceSurfaceData() {
+        if (peer.getBounds().isEmpty()) {
+            surfaceData = NullSurfaceData.theInstance;
+            return surfaceData;
+        }
+
+        // the layer redirects all painting to the buffer's graphics
+        // and blits the buffer to the layer surface (in drawInCGLContext callback)
+        CGraphicsConfig gc = (CGraphicsConfig)peer.getGraphicsConfiguration();
+        surfaceData = gc.createSurfaceData(this);
+
+        // the layer holds a reference to the buffer, which in
+        // turn has a reference back to this layer
+        if (surfaceData instanceof CGLSurfaceData) {
+            validate((CGLSurfaceData)surfaceData);
+        }
+
+        return surfaceData;
+    }
+
+    public SurfaceData getSurfaceData() {
+        return surfaceData;
+    }
+
+    public void validate(final CGLSurfaceData cglsd) {
+        OGLRenderQueue rq = OGLRenderQueue.getInstance();
+        rq.lock();
+        try {
+            validate(getPointer(), cglsd);
+        } finally {
+            rq.unlock();
+        }
+    }
+
+    @Override
+    public void dispose() {
+        // break the connection between the layer and the buffer
+        validate(null);
+        super.dispose();
+    }
+
+    // ----------------------------------------------------------------------
+    // NATIVE CALLBACKS
+    // ----------------------------------------------------------------------
+
+    private void drawInCGLContext() {
+        // tell the flusher thread not to update the intermediate buffer
+        // until we are done blitting from it
+        OGLRenderQueue rq = OGLRenderQueue.getInstance();
+        rq.lock();
+        try {
+            blitTexture(getPointer());
+        } finally {
+            rq.unlock();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/opengl/CGLSurfaceData.java b/jdk/src/macosx/classes/sun/java2d/opengl/CGLSurfaceData.java
new file mode 100644
index 0000000..98ec47b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLSurfaceData.java
@@ -0,0 +1,375 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d.opengl;
+
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import java.awt.image.ColorModel;
+
+import sun.java2d.SunGraphics2D;
+import sun.java2d.SurfaceData;
+
+import sun.lwawt.macosx.CPlatformView;
+
+public abstract class CGLSurfaceData extends OGLSurfaceData {
+
+    protected CPlatformView pView;
+    private CGLGraphicsConfig graphicsConfig;
+
+    native void validate(int xoff, int yoff, int width, int height, boolean isOpaque);
+
+    private native void initOps(long pConfigInfo, long pPeerData, long layerPtr,
+                                int xoff, int yoff, boolean isOpaque);
+
+    protected native boolean initPbuffer(long pData, long pConfigInfo,
+            boolean isOpaque, int width, int height);
+
+    protected CGLSurfaceData(CPlatformView pView, CGLGraphicsConfig gc,
+                             ColorModel cm, int type)
+    {
+        super(gc, cm, type);
+        this.pView = pView;
+        this.graphicsConfig = gc;
+
+        long pConfigInfo = gc.getNativeConfigInfo();
+        long pPeerData = 0L;
+        boolean isOpaque = true;
+        if (pView != null) {
+            pPeerData = pView.getAWTView();
+            isOpaque = pView.isOpaque();
+        }
+        initOps(pConfigInfo, pPeerData, 0, 0, 0, isOpaque);
+    }
+
+    protected CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
+                             ColorModel cm, int type)
+    {
+        super(gc, cm, type);
+        this.graphicsConfig = gc;
+
+        long pConfigInfo = gc.getNativeConfigInfo();
+        long layerPtr = 0L;
+        boolean isOpaque = true;
+        if (layer != null) {
+            layerPtr = layer.getPointer();
+            isOpaque = layer.isOpaque();
+        }
+        initOps(pConfigInfo, 0, layerPtr, 0, 0, isOpaque);
+    }
+
+    @Override //SurfaceData
+    public GraphicsConfiguration getDeviceConfiguration() {
+        return graphicsConfig;
+    }
+
+    /**
+     * Creates a SurfaceData object representing the primary (front) buffer of
+     * an on-screen Window.
+     */
+    public static CGLWindowSurfaceData createData(CPlatformView pView) {
+        CGLGraphicsConfig gc = getGC(pView);
+        return new CGLWindowSurfaceData(pView, gc);
+    }
+
+    /**
+     * Creates a SurfaceData object representing the intermediate buffer
+     * between the Java2D flusher thread and the AppKit thread.
+     */
+    public static CGLLayerSurfaceData createData(CGLLayer layer) {
+        CGLGraphicsConfig gc = getGC(layer);
+        Rectangle r = layer.getBounds();
+        return new CGLLayerSurfaceData(layer, gc, r.width, r.height);
+    }
+
+    /**
+     * Creates a SurfaceData object representing the back buffer of a
+     * double-buffered on-screen Window.
+     */
+    public static CGLOffScreenSurfaceData createData(CPlatformView pView,
+            Image image, int type) {
+        CGLGraphicsConfig gc = getGC(pView);
+        Rectangle r = pView.getBounds();
+        if (type == FLIP_BACKBUFFER) {
+            return new CGLOffScreenSurfaceData(pView, gc, r.width, r.height,
+                    image, gc.getColorModel(), FLIP_BACKBUFFER);
+        } else {
+            return new CGLVSyncOffScreenSurfaceData(pView, gc, r.width,
+                    r.height, image, gc.getColorModel(), type);
+        }
+    }
+
+    /**
+     * Creates a SurfaceData object representing an off-screen buffer (either a
+     * Pbuffer or Texture).
+     */
+    public static CGLOffScreenSurfaceData createData(CGLGraphicsConfig gc,
+            int width, int height, ColorModel cm, Image image, int type) {
+        return new CGLOffScreenSurfaceData(null, gc, width, height, image, cm,
+                type);
+    }
+
+    public static CGLGraphicsConfig getGC(CPlatformView pView) {
+        if (pView != null) {
+            return (CGLGraphicsConfig)pView.getGraphicsConfiguration();
+        } else {
+            // REMIND: this should rarely (never?) happen, but what if
+            // default config is not CGL?
+            GraphicsEnvironment env = GraphicsEnvironment
+                .getLocalGraphicsEnvironment();
+            GraphicsDevice gd = env.getDefaultScreenDevice();
+            return (CGLGraphicsConfig) gd.getDefaultConfiguration();
+        }
+    }
+
+    public static CGLGraphicsConfig getGC(CGLLayer layer) {
+        return (CGLGraphicsConfig)layer.getGraphicsConfiguration();
+    }
+
+    public void validate() {
+        // Overridden in CGLWindowSurfaceData below
+    }
+
+    protected native void clearWindow();
+
+    public static class CGLWindowSurfaceData extends CGLSurfaceData {
+
+        public CGLWindowSurfaceData(CPlatformView pView,
+                CGLGraphicsConfig gc) {
+            super(pView, gc, gc.getColorModel(), WINDOW);
+        }
+
+        @Override
+        public SurfaceData getReplacement() {
+            return pView.getSurfaceData();
+        }
+
+        @Override
+        public Rectangle getBounds() {
+            Rectangle r = pView.getBounds();
+            return new Rectangle(0, 0, r.width, r.height);
+        }
+
+        /**
+         * Returns destination Component associated with this SurfaceData.
+         */
+        @Override
+        public Object getDestination() {
+            return pView.getDestination();
+        }
+
+        public void validate() {
+            OGLRenderQueue rq = OGLRenderQueue.getInstance();
+            rq.lock();
+            try {
+                rq.flushAndInvokeNow(new Runnable() {
+                    public void run() {
+                        Rectangle peerBounds = pView.getBounds();
+                        validate(0, 0, peerBounds.width, peerBounds.height, pView.isOpaque());
+                    }
+                });
+            } finally {
+                rq.unlock();
+            }
+        }
+
+        @Override
+        public void invalidate() {
+            super.invalidate();
+            clearWindow();
+        }
+    }
+
+    /**
+     * A surface which implements an intermediate buffer between
+     * the Java2D flusher thread and the AppKit thread.
+     *
+     * This surface serves as a buffer attached to a CGLLayer and
+     * the layer redirects all painting to the buffer's graphics.
+     */
+    public static class CGLLayerSurfaceData extends CGLSurfaceData {
+
+        private CGLLayer layer;
+        private int width, height;
+
+        public CGLLayerSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
+                                   int width, int height) {
+            super(layer, gc, gc.getColorModel(), FBOBJECT);
+
+            this.width = width;
+            this.height = height;
+            this.layer = layer;
+
+            initSurface(width, height);
+        }
+
+        @Override
+        public SurfaceData getReplacement() {
+            return layer.getSurfaceData();
+        }
+
+        @Override
+        boolean isOnScreen() {
+            return true;
+        }
+
+        @Override
+        public Rectangle getBounds() {
+            return new Rectangle(width, height);
+        }
+
+        @Override
+        public Object getDestination() {
+            return layer.getDestination();
+        }
+
+        @Override
+        public int getTransparency() {
+            return layer.getTransparency();
+        }
+
+        @Override
+        public void invalidate() {
+            super.invalidate();
+            clearWindow();
+        }
+    }
+
+    /**
+     * A surface which implements a v-synced flip back-buffer with COPIED
+     * FlipContents.
+     *
+     * This surface serves as a back-buffer to the outside world, while it is
+     * actually an offscreen surface. When the BufferStrategy this surface
+     * belongs to is showed, it is first copied to the real private
+     * FLIP_BACKBUFFER, which is then flipped.
+     */
+    public static class CGLVSyncOffScreenSurfaceData extends
+            CGLOffScreenSurfaceData {
+        private CGLOffScreenSurfaceData flipSurface;
+
+        public CGLVSyncOffScreenSurfaceData(CPlatformView pView,
+                CGLGraphicsConfig gc, int width, int height, Image image,
+                ColorModel cm, int type) {
+            super(pView, gc, width, height, image, cm, type);
+            flipSurface = CGLSurfaceData.createData(pView, image,
+                    FLIP_BACKBUFFER);
+        }
+
+        public SurfaceData getFlipSurface() {
+            return flipSurface;
+        }
+
+        @Override
+        public void flush() {
+            flipSurface.flush();
+            super.flush();
+        }
+    }
+
+    public static class CGLOffScreenSurfaceData extends CGLSurfaceData {
+        private Image offscreenImage;
+        private int width, height;
+
+        public CGLOffScreenSurfaceData(CPlatformView pView,
+                                       CGLGraphicsConfig gc, int width, int height, Image image,
+                                       ColorModel cm, int type) {
+            super(pView, gc, cm, type);
+
+            this.width = width;
+            this.height = height;
+            offscreenImage = image;
+
+            initSurface(width, height);
+        }
+
+        @Override
+        public SurfaceData getReplacement() {
+            return restoreContents(offscreenImage);
+        }
+
+        @Override
+        public Rectangle getBounds() {
+            if (type == FLIP_BACKBUFFER) {
+                Rectangle r = pView.getBounds();
+                return new Rectangle(0, 0, r.width, r.height);
+            } else {
+                return new Rectangle(width, height);
+            }
+        }
+
+        /**
+         * Returns destination Image associated with this SurfaceData.
+         */
+        @Override
+        public Object getDestination() {
+            return offscreenImage;
+        }
+    }
+
+    // Mac OS X specific APIs for JOGL/Java2D bridge...
+
+    // given a surface create and attach GL context, then return it
+    private native static long createCGLContextOnSurface(CGLSurfaceData sd,
+            long sharedContext);
+
+    public static long createOGLContextOnSurface(Graphics g, long sharedContext) {
+        SurfaceData sd = ((SunGraphics2D) g).surfaceData;
+        if ((sd instanceof CGLSurfaceData) == true) {
+            CGLSurfaceData cglsd = (CGLSurfaceData) sd;
+            return createCGLContextOnSurface(cglsd, sharedContext);
+        } else {
+            return 0L;
+        }
+    }
+
+    // returns whether or not the makeCurrent operation succeeded
+    native static boolean makeCGLContextCurrentOnSurface(CGLSurfaceData sd,
+            long ctx);
+
+    public static boolean makeOGLContextCurrentOnSurface(Graphics g, long ctx) {
+        SurfaceData sd = ((SunGraphics2D) g).surfaceData;
+        if ((ctx != 0L) && ((sd instanceof CGLSurfaceData) == true)) {
+            CGLSurfaceData cglsd = (CGLSurfaceData) sd;
+            return makeCGLContextCurrentOnSurface(cglsd, ctx);
+        } else {
+            return false;
+        }
+    }
+
+    // additional cleanup
+    private native static void destroyCGLContext(long ctx);
+
+    public static void destroyOGLContext(long ctx) {
+        if (ctx != 0L) {
+            destroyCGLContext(ctx);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.java b/jdk/src/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.java
new file mode 100644
index 0000000..4f6d8e9
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.java2d.opengl;
+
+import java.awt.BufferCapabilities;
+import static java.awt.BufferCapabilities.FlipContents.*;
+import java.awt.Component;
+import java.awt.GraphicsConfiguration;
+import java.awt.Transparency;
+import java.awt.image.ColorModel;
+import java.awt.peer.ComponentPeer;
+
+import sun.awt.image.SunVolatileImage;
+import sun.awt.image.VolatileSurfaceManager;
+import sun.java2d.BackBufferCapsProvider;
+import sun.java2d.SurfaceData;
+import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
+import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
+import static sun.java2d.pipe.hw.AccelSurface.*;
+import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
+
+public class CGLVolatileSurfaceManager extends VolatileSurfaceManager {
+
+    private boolean accelerationEnabled;
+
+    public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
+        super(vImg, context);
+
+        /*
+         * We will attempt to accelerate this image only under the
+         * following conditions:
+         *   - the image is opaque OR
+         *   - the image is translucent AND
+         *       - the GraphicsConfig supports the FBO extension OR
+         *       - the GraphicsConfig has a stored alpha channel
+         */
+        int transparency = vImg.getTransparency();
+        CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
+        accelerationEnabled =
+            (transparency == Transparency.OPAQUE) ||
+            ((transparency == Transparency.TRANSLUCENT) &&
+             (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
+              gc.isCapPresent(CAPS_STORED_ALPHA)));
+    }
+
+    protected boolean isAccelerationEnabled() {
+        return accelerationEnabled;
+    }
+
+    /**
+     * Create a pbuffer-based SurfaceData object (or init the backbuffer
+     * of an existing window if this is a double buffered GraphicsConfig)
+     */
+    protected SurfaceData initAcceleratedSurface() {
+        SurfaceData sData = null;
+        Component comp = vImg.getComponent();
+        final ComponentPeer peer = (comp != null) ? comp.getPeer() : null;
+
+        try {
+            boolean createVSynced = false;
+            boolean forceback = false;
+            if (context instanceof Boolean) {
+                forceback = ((Boolean)context).booleanValue();
+                if (forceback && peer instanceof BackBufferCapsProvider) {
+                    BackBufferCapsProvider provider =
+                        (BackBufferCapsProvider)peer;
+                    BufferCapabilities caps = provider.getBackBufferCaps();
+                    if (caps instanceof ExtendedBufferCapabilities) {
+                        ExtendedBufferCapabilities ebc =
+                            (ExtendedBufferCapabilities)caps;
+                        if (ebc.getVSync() == VSYNC_ON &&
+                            ebc.getFlipContents() == COPIED)
+                        {
+                            createVSynced = true;
+                            forceback = false;
+                        }
+                    }
+                }
+            }
+
+            if (forceback) {
+                // peer must be non-null in this case
+                // TODO: modify parameter to delegate
+                //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
+            } else {
+                CGLGraphicsConfig gc =
+                    (CGLGraphicsConfig)vImg.getGraphicsConfig();
+                ColorModel cm = gc.getColorModel(vImg.getTransparency());
+                int type = vImg.getForcedAccelSurfaceType();
+                // if acceleration type is forced (type != UNDEFINED) then
+                // use the forced type, otherwise choose one based on caps
+                if (type == OGLSurfaceData.UNDEFINED) {
+                    type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
+                        OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
+                }
+                if (createVSynced) {
+                    // TODO: modify parameter to delegate
+//                  sData = CGLSurfaceData.createData(peer, vImg, type);
+                } else {
+                    sData = CGLSurfaceData.createData(gc,
+                                                      vImg.getWidth(),
+                                                      vImg.getHeight(),
+                                                      cm, vImg, type);
+                }
+            }
+        } catch (NullPointerException ex) {
+            sData = null;
+        } catch (OutOfMemoryError er) {
+            sData = null;
+        }
+
+        return sData;
+    }
+
+    @Override
+    protected boolean isConfigValid(GraphicsConfiguration gc) {
+        return ((gc == null) || (gc == vImg.getGraphicsConfig()));
+    }
+
+    @Override
+    public void initContents() {
+        if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {
+            super.initContents();
+        }
+    }
+}
+
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWButtonPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWButtonPeer.java
new file mode 100644
index 0000000..f0cd54d
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWButtonPeer.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Button;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.peer.ButtonPeer;
+
+import javax.swing.JButton;
+
+final class LWButtonPeer extends LWComponentPeer<Button, JButton>
+        implements ButtonPeer, ActionListener {
+
+    LWButtonPeer(final Button target,
+                 final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected JButton createDelegate() {
+        return new JButtonDelegate();
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        setLabel(getTarget().getLabel());
+        synchronized (getDelegateLock()) {
+            getDelegate().addActionListener(this);
+        }
+    }
+
+    @Override
+    public void actionPerformed(final ActionEvent e) {
+        postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
+                                  getTarget().getActionCommand(), e.getWhen(),
+                                  e.getModifiers()));
+    }
+
+    @Override
+    public void setLabel(final String label) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setText(label);
+        }
+    }
+
+    @Override
+    public boolean isFocusable() {
+        return true;
+    }
+
+    private final class JButtonDelegate extends JButton {
+
+        // Empty non private constructor was added because access to this
+        // class shouldn't be emulated by a synthetic accessor method.
+        JButtonDelegate() {
+            super();
+        }
+
+        @Override
+        public boolean hasFocus() {
+            return getTarget().hasFocus();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWCanvasPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWCanvasPeer.java
new file mode 100644
index 0000000..5651dcd
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWCanvasPeer.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.BufferCapabilities;
+import java.awt.Canvas;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.peer.CanvasPeer;
+
+import javax.swing.JComponent;
+
+final class LWCanvasPeer
+    extends LWComponentPeer<Component, JComponent>
+    implements CanvasPeer
+{
+    LWCanvasPeer(final Canvas target, PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    public JComponent createDelegate() {
+        return new JCanvasDelegate();
+    }
+
+    // ---- PEER METHODS ---- //
+
+    @Override
+    public void createBuffers(int numBuffers, BufferCapabilities caps) {
+        // TODO
+    }
+
+    @Override
+    public Image getBackBuffer() {
+        // TODO
+        return null;
+    }
+
+    @Override
+    public void flip(int x1, int y1, int x2, int y2,
+                     BufferCapabilities.FlipContents flipAction)
+    {
+        // TODO
+    }
+
+    @Override
+    public void destroyBuffers() {
+        // TODO
+    }
+
+    @Override
+    public GraphicsConfiguration getAppropriateGraphicsConfiguration(
+            GraphicsConfiguration gc)
+    {
+        // TODO
+        return gc;
+    }
+
+    class JCanvasDelegate
+        extends JComponent
+    {
+
+        @Override
+        public Dimension getMinimumSize() {
+            return getTarget().getSize();
+        }
+
+        @Override
+        public Dimension getPreferredSize() {
+            return getTarget().getSize();
+        }
+
+        @Override
+        protected void paintComponent(final Graphics g) {
+            if (isOpaque()) {
+                g.setColor(getBackground());
+                g.fillRect(0, 0, getWidth(), getHeight());
+                g.setColor(getForeground());
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWCheckboxPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWCheckboxPeer.java
new file mode 100644
index 0000000..b639e6c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWCheckboxPeer.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Checkbox;
+import java.awt.CheckboxGroup;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.peer.CheckboxPeer;
+import java.beans.Transient;
+
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JRadioButton;
+import javax.swing.JToggleButton;
+import javax.swing.SwingUtilities;
+
+final class LWCheckboxPeer
+        extends LWComponentPeer<Checkbox, LWCheckboxPeer.CheckboxDelegate>
+        implements CheckboxPeer, ItemListener {
+
+    LWCheckboxPeer(final Checkbox target,
+                   final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected CheckboxDelegate createDelegate() {
+        return new CheckboxDelegate();
+    }
+
+    @Override
+    protected Component getDelegateFocusOwner() {
+        return getDelegate().getCurrentButton();
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        setLabel(getTarget().getLabel());
+        setState(getTarget().getState());
+        setCheckboxGroup(getTarget().getCheckboxGroup());
+    }
+
+    @Override
+    public void itemStateChanged(final ItemEvent e) {
+        // group.setSelectedCheckbox() will repaint the component
+        // to let LWCheckboxPeer correctly handle it we should call it
+        // after the current event is processed
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                boolean postEvent = true;
+                final CheckboxGroup group = getTarget().getCheckboxGroup();
+                if (group != null) {
+                    if (e.getStateChange() == ItemEvent.SELECTED) {
+                        if (group.getSelectedCheckbox() != getTarget()) {
+                            group.setSelectedCheckbox(getTarget());
+                        } else {
+                            postEvent = false;
+                        }
+                    } else {
+                        postEvent = false;
+                        if (group.getSelectedCheckbox() == getTarget()) {
+                            // Don't want to leave the group with no selected
+                            // checkbox.
+                            getTarget().setState(true);
+                        }
+                    }
+                } else {
+                    getTarget().setState(e.getStateChange()
+                                         == ItemEvent.SELECTED);
+                }
+                if (postEvent) {
+                    postEvent(new ItemEvent(getTarget(),
+                                            ItemEvent.ITEM_STATE_CHANGED,
+                                            getTarget().getLabel(),
+                                            e.getStateChange()));
+                }
+            }
+        });
+    }
+
+    @Override
+    public void setCheckboxGroup(final CheckboxGroup g) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getCurrentButton().removeItemListener(this);
+            getDelegate().setRadioButton(g != null);
+            getDelegate().getCurrentButton().addItemListener(this);
+        }
+        repaintPeer();
+    }
+
+    @Override
+    public void setLabel(final String label) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setText(label);
+        }
+    }
+
+    @Override
+    public void setState(final boolean state) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setSelected(state);
+        }
+        repaintPeer();
+    }
+
+    @Override
+    public boolean isFocusable() {
+        return true;
+    }
+
+    final class CheckboxDelegate extends JComponent {
+
+        private final JCheckBox cb;
+        private final JRadioButton rb;
+
+        CheckboxDelegate() {
+            super();
+            cb = new JCheckBox() {
+                @Override
+                public boolean hasFocus() {
+                    return getTarget().hasFocus();
+                }
+            };
+            rb = new JRadioButton() {
+                @Override
+                public boolean hasFocus() {
+                    return getTarget().hasFocus();
+                }
+            };
+            setLayout(null);
+            setRadioButton(false);
+            add(rb);
+            add(cb);
+        }
+
+        @Override
+        public void setEnabled(final boolean enabled) {
+            super.setEnabled(enabled);
+            rb.setEnabled(enabled);
+            cb.setEnabled(enabled);
+        }
+
+        @Override
+        public void setOpaque(final boolean isOpaque) {
+            super.setOpaque(isOpaque);
+            rb.setOpaque(isOpaque);
+            cb.setOpaque(isOpaque);
+        }
+
+        @Override
+        @Deprecated
+        public void reshape(final int x, final int y, final int w,
+                            final int h) {
+            super.reshape(x, y, w, h);
+            cb.setBounds(0, 0, w, h);
+            rb.setBounds(0, 0, w, h);
+        }
+
+        @Override
+        @Transient
+        public Dimension getMinimumSize() {
+            return getCurrentButton().getMinimumSize();
+        }
+
+        void setRadioButton(final boolean showRadioButton) {
+            rb.setVisible(showRadioButton);
+            cb.setVisible(!showRadioButton);
+        }
+
+        @Transient
+        JToggleButton getCurrentButton() {
+            return cb.isVisible() ? cb : rb;
+        }
+
+        void setText(final String label) {
+            cb.setText(label);
+            rb.setText(label);
+        }
+
+        void setSelected(final boolean state) {
+            cb.setSelected(state);
+            rb.setSelected(state);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWChoicePeer.java b/jdk/src/macosx/classes/sun/lwawt/LWChoicePeer.java
new file mode 100644
index 0000000..b0ab9d0
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWChoicePeer.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Choice;
+import java.awt.Point;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.peer.ChoicePeer;
+
+import javax.swing.JComboBox;
+
+final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
+        implements ChoicePeer, ItemListener {
+
+    /**
+     * According to Choice specification item events are sent in response to
+     * user input, but not in response to calls to select(). But JComboBox are
+     * sent item events in both cases. Should be used under delegateLock.
+     */
+    private boolean skipPostMessage;
+
+    LWChoicePeer(final Choice target,
+                 final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected JComboBox<String> createDelegate() {
+        return new JComboBoxDelegate();
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        final Choice choice = getTarget();
+        final JComboBox<String> combo = getDelegate();
+        synchronized (getDelegateLock()) {
+            final int count = choice.getItemCount();
+            for (int i = 0; i < count; ++i) {
+                combo.addItem(choice.getItem(i));
+            }
+            select(choice.getSelectedIndex());
+
+            // NOTE: the listener must be added at the very end, otherwise it
+            // fires events upon initialization of the combo box.
+            combo.addItemListener(this);
+        }
+    }
+
+    @Override
+    public void itemStateChanged(final ItemEvent e) {
+        // AWT Choice sends SELECTED event only whereas JComboBox
+        // sends both SELECTED and DESELECTED.
+        if (e.getStateChange() == ItemEvent.SELECTED) {
+            synchronized (getDelegateLock()) {
+                if (skipPostMessage) {
+                    return;
+                }
+                getTarget().select(getDelegate().getSelectedIndex());
+            }
+            postEvent(new ItemEvent(getTarget(), ItemEvent.ITEM_STATE_CHANGED,
+                                    e.getItem(), ItemEvent.SELECTED));
+        }
+    }
+
+    @Override
+    public void add(final String item, final int index) {
+        synchronized (getDelegateLock()) {
+            getDelegate().insertItemAt(item, index);
+        }
+    }
+
+    @Override
+    public void remove(final int index) {
+        synchronized (getDelegateLock()) {
+            // We shouldn't post event, if selected item was removed.
+            skipPostMessage = true;
+            getDelegate().removeItemAt(index);
+            skipPostMessage = false;
+        }
+    }
+
+    @Override
+    public void removeAll() {
+        synchronized (getDelegateLock()) {
+            getDelegate().removeAllItems();
+        }
+    }
+
+    @Override
+    public void select(final int index) {
+        synchronized (getDelegateLock()) {
+            if (index != getDelegate().getSelectedIndex()) {
+                skipPostMessage = true;
+                getDelegate().setSelectedIndex(index);
+                skipPostMessage = false;
+            }
+        }
+    }
+
+    @Override
+    public boolean isFocusable() {
+        return true;
+    }
+
+    private final class JComboBoxDelegate extends JComboBox<String> {
+
+        // Empty non private constructor was added because access to this
+        // class shouldn't be emulated by a synthetic accessor method.
+        JComboBoxDelegate() {
+            super();
+        }
+
+        @Override
+        public boolean hasFocus() {
+            return getTarget().hasFocus();
+        }
+
+        //Needed for proper popup menu location
+        @Override
+        public Point getLocationOnScreen() {
+            return LWChoicePeer.this.getLocationOnScreen();
+        }
+
+        /**
+         * We should post ITEM_STATE_CHANGED event when the same element is
+         * reselected.
+         */
+        @Override
+        public void setSelectedItem(final Object anObject) {
+            final Object oldSelection = selectedItemReminder;
+            if (oldSelection != null && oldSelection.equals(anObject)) {
+                selectedItemChanged();
+            }
+            super.setSelectedItem(anObject);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
new file mode 100644
index 0000000..a7b3f54
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
@@ -0,0 +1,1394 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.*;
+
+import java.awt.dnd.DropTarget;
+import java.awt.dnd.peer.DropTargetPeer;
+import java.awt.event.*;
+
+import java.awt.image.ColorModel;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.awt.image.VolatileImage;
+
+import java.awt.peer.ComponentPeer;
+import java.awt.peer.ContainerPeer;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.beans.Transient;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import sun.awt.*;
+
+import sun.awt.event.IgnorePaintEvent;
+
+import sun.awt.image.SunVolatileImage;
+import sun.awt.image.ToolkitImage;
+
+import sun.java2d.SunGraphics2D;
+import sun.java2d.opengl.OGLRenderQueue;
+import sun.java2d.pipe.Region;
+
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+import javax.swing.RepaintManager;
+
+import sun.lwawt.macosx.CDropTarget;
+
+import com.sun.java.swing.SwingUtilities3;
+
+public abstract class LWComponentPeer<T extends Component, D extends JComponent>
+        implements ComponentPeer, DropTargetPeer {
+    // State lock is to be used for modifications to this
+    // peer's fields (e.g. bounds, background, font, etc.)
+    // It should be the last lock in the lock chain
+    private final Object stateLock =
+            new StringBuilder("LWComponentPeer.stateLock");
+
+    // The lock to operate with the peers hierarchy. AWT tree
+    // lock is not used as there are many peers related ops
+    // to be done on the toolkit thread, and we don't want to
+    // depend on a public lock on this thread
+    private final static Object peerTreeLock =
+            new StringBuilder("LWComponentPeer.peerTreeLock");
+
+    /**
+     * A custom tree-lock used for the hierarchy of the delegate Swing
+     * components.
+     * The lock synchronizes access to the delegate
+     * internal state. Think of it as a 'virtual EDT'.
+     */
+//    private final Object delegateTreeLock =
+//        new StringBuilder("LWComponentPeer.delegateTreeLock");
+
+    private T target;
+
+    // Container peer. It may not be the peer of the target's direct
+    // parent, for example, in the case of hw/lw mixing. However,
+    // let's skip this scenario for the time being. We also assume
+    // the container peer is not null, which might also be false if
+    // addNotify() is called for a component outside of the hierarchy.
+    // The exception is LWWindowPeers: their parents are always null
+    private LWContainerPeer containerPeer;
+
+    // Handy reference to the top-level window peer. Window peer is
+    // borrowed from the containerPeer in constructor, and should also
+    // be updated when the component is reparented to another container
+    private LWWindowPeer windowPeer;
+
+    private AtomicBoolean disposed = new AtomicBoolean(false);
+
+    // Bounds are relative to parent peer
+    private Rectangle bounds = new Rectangle();
+    private Region region;
+
+    // Component state. Should be accessed under the state lock
+    private boolean visible = false;
+    private boolean enabled = true;
+
+    // Paint area to coalesce all the paint events and store
+    // the target dirty area
+    private RepaintArea targetPaintArea;
+
+    //   private volatile boolean paintPending;
+    private volatile boolean isLayouting;
+
+    private D delegate = null;
+    private Container delegateContainer;
+    private Component delegateDropTarget;
+
+    private int fNumDropTargets = 0;
+    private CDropTarget fDropTarget = null;
+
+    private PlatformComponent platformComponent;
+
+    private final class DelegateContainer extends Container {
+        {
+            enableEvents(0xFFFFFFFF);
+        }
+
+        DelegateContainer() {
+            super();
+        }
+
+        @Override
+        public boolean isLightweight() {
+            return false;
+        }
+
+        @Override
+        public Point getLocation() {
+            return getLocationOnScreen();
+        }
+
+        @Override
+        public Point getLocationOnScreen() {
+            return LWComponentPeer.this.getLocationOnScreen();
+        }
+
+        @Override
+        public int getX() {
+            return getLocation().x;
+        }
+
+        @Override
+        public int getY() {
+            return getLocation().y;
+        }
+
+        @Override
+        @Transient
+        public Color getBackground() {
+            return getTarget().getBackground();
+        }
+
+        @Override
+        @Transient
+        public Color getForeground() {
+            return getTarget().getForeground();
+        }
+
+        @Override
+        @Transient
+        public Font getFont() {
+            return getTarget().getFont();
+        }
+    }
+
+    public LWComponentPeer(T target, PlatformComponent platformComponent) {
+        this.target = target;
+        this.platformComponent = platformComponent;
+
+        initializeContainerPeer();
+        // Container peer is always null for LWWindowPeers, so
+        // windowPeer is always null for them as well. On the other
+        // hand, LWWindowPeer shouldn't use windowPeer at all
+        if (containerPeer != null) {
+            windowPeer = containerPeer.getWindowPeerOrSelf();
+        }
+        // don't bother about z-order here as updateZOrder()
+        // will be called from addNotify() later anyway
+        if (containerPeer != null) {
+            containerPeer.addChildPeer(this);
+        }
+
+        // the delegate must be created after the target is set
+        AWTEventListener toolkitListener = null;
+        synchronized (Toolkit.getDefaultToolkit()) {
+            try {
+                toolkitListener = getToolkitAWTEventListener();
+                setToolkitAWTEventListener(null);
+
+                synchronized (getDelegateLock()) {
+                    delegate = createDelegate();
+                    if (delegate != null) {
+                        delegateContainer = new DelegateContainer();
+                        delegateContainer.add(delegate);
+                        delegateContainer.addNotify();
+                        delegate.addNotify();
+                    } else {
+                        return;
+                    }
+                }
+
+            } finally {
+                setToolkitAWTEventListener(toolkitListener);
+            }
+
+            // todo swing: later on we will probably have one global RM
+            SwingUtilities3.setDelegateRepaintManager(delegate, new RepaintManager() {
+                @Override
+                public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) {
+                    // Repainting in Swing is asynchronous, so it is emulated here by using invokeLater()
+                    // to extract the painting call from the event's processing routine
+                    //TODO: so why exactly do we have to emulate this in lwawt? We use a back-buffer anyway,
+                    //why not paint the components synchronously into the buffer?
+                    Rectangle res = SwingUtilities.convertRectangle(
+                            c, new Rectangle(x, y, w, h), getDelegate());
+                    repaintPeer(res);
+                }
+            });
+        }
+    }
+
+    /**
+     * This method must be called under Toolkit.getDefaultToolkit() lock
+     * and followed by setToolkitAWTEventListener()
+     */
+    protected final AWTEventListener getToolkitAWTEventListener() {
+        return AccessController.doPrivileged(new PrivilegedAction<AWTEventListener>() {
+            public AWTEventListener run() {
+                Toolkit toolkit = Toolkit.getDefaultToolkit();
+                try {
+                    Field field = Toolkit.class.getDeclaredField("eventListener");
+                    field.setAccessible(true);
+                    return (AWTEventListener) field.get(toolkit);
+                } catch (Exception e) {
+                    throw new InternalError(e.toString());
+                }
+            }
+        });
+    }
+
+    protected final void setToolkitAWTEventListener(final AWTEventListener listener) {
+        AccessController.doPrivileged(new PrivilegedAction<Void>() {
+            public Void run() {
+                Toolkit toolkit = Toolkit.getDefaultToolkit();
+                try {
+                    Field field = Toolkit.class.getDeclaredField("eventListener");
+                    field.setAccessible(true);
+                    field.set(toolkit, listener);
+                } catch (Exception e) {
+                    throw new InternalError(e.toString());
+                }
+                return null;
+            }
+        });
+    }
+
+    /**
+     * This method is called under getDelegateLock().
+     * Overridden in subclasses.
+     */
+    protected D createDelegate() {
+        return null;
+    }
+
+    protected final D getDelegate() {
+        synchronized (getStateLock()) {
+            return delegate;
+        }
+    }
+
+    protected Component getDelegateFocusOwner() {
+        return getDelegate();
+    }
+
+    /*
+     * Initializes this peer by fetching all the properties from the target.
+     * The call to initialize() is not placed to LWComponentPeer ctor to
+     * let the subclass ctor to finish completely first. Instead, it's the
+     * LWToolkit object who is responsible for initialization.
+     */
+    public void initialize() {
+        platformComponent.initialize(target, this, getPlatformWindow());
+        targetPaintArea = new LWRepaintArea();
+        synchronized (getDelegateLock()) {
+            if (getDelegate() != null) {
+                getDelegate().setOpaque(true);
+                resetColorsAndFont(delegate);
+                // we must explicitly set the font here
+                // see Component.getFont_NoClientCode() for details
+                delegateContainer.setFont(target.getFont());
+            }
+        }
+        if (target.isBackgroundSet()) {
+            setBackground(target.getBackground());
+        }
+        if (target.isForegroundSet()) {
+            setForeground(target.getForeground());
+        }
+        if (target.isFontSet()) {
+            setFont(target.getFont());
+        }
+        setBounds(target.getBounds());
+        setEnabled(target.isEnabled());
+        setVisible(target.isVisible());
+    }
+
+    private static void resetColorsAndFont(final Container c) {
+        c.setBackground(null);
+        c.setForeground(null);
+        c.setFont(null);
+        for (int i = 0; i < c.getComponentCount(); i++) {
+            resetColorsAndFont((Container) c.getComponent(i));
+        }
+    }
+
+    final Object getStateLock() {
+        return stateLock;
+    }
+
+    // Synchronize all operations with the Swing delegates under
+    // AWT tree lock, using a new separate lock to synchronize
+    // access to delegates may lead deadlocks
+    final Object getDelegateLock() {
+        //return delegateTreeLock;
+        return getTarget().getTreeLock();
+    }
+
+    protected final static Object getPeerTreeLock() {
+        return peerTreeLock;
+    }
+
+    final T getTarget() {
+        return target;
+    }
+
+    // Just a helper method
+    // Returns the window peer or null if this is a window peer
+    protected final LWWindowPeer getWindowPeer() {
+        return windowPeer;
+    }
+
+    // Returns the window peer or 'this' if this is a window peer
+    protected LWWindowPeer getWindowPeerOrSelf() {
+        return getWindowPeer();
+    }
+
+    // Just a helper method
+    protected final LWContainerPeer getContainerPeer() {
+        return containerPeer;
+    }
+
+    // Just a helper method
+    // Overridden in LWWindowPeer to skip containerPeer initialization
+    protected void initializeContainerPeer() {
+        Container parent = LWToolkit.getNativeContainer(target);
+        if (parent != null) {
+            containerPeer = (LWContainerPeer) LWToolkit.targetToPeer(parent);
+        }
+    }
+
+    public PlatformWindow getPlatformWindow() {
+        LWWindowPeer windowPeer = getWindowPeer();
+        return windowPeer.getPlatformWindow();
+    }
+
+    protected AppContext getAppContext() {
+        return SunToolkit.targetToAppContext(getTarget());
+    }
+
+    // ---- PEER METHODS ---- //
+
+    @Override
+    public Toolkit getToolkit() {
+        return LWToolkit.getLWToolkit();
+    }
+
+    // Just a helper method
+    public LWToolkit getLWToolkit() {
+        return LWToolkit.getLWToolkit();
+    }
+
+    @Override
+    public void dispose() {
+        if (disposed.compareAndSet(false, true)) {
+            disposeImpl();
+        }
+    }
+
+    protected void disposeImpl() {
+        LWContainerPeer cp = getContainerPeer();
+        if (cp != null) {
+            cp.removeChildPeer(this);
+        }
+        platformComponent.dispose();
+        LWToolkit.targetDisposedPeer(getTarget(), this);
+    }
+
+    public final boolean isDisposed() {
+        return disposed.get();
+    }
+
+    /*
+     * GraphicsConfiguration is borrowed from the parent peer. The
+     * return value must not be null.
+     *
+     * Overridden in LWWindowPeer.
+     */
+    @Override
+    public GraphicsConfiguration getGraphicsConfiguration() {
+        // Don't check windowPeer for null as it can only happen
+        // for windows, but this method is overridden in
+        // LWWindowPeer and doesn't call super()
+        return getWindowPeer().getGraphicsConfiguration();
+    }
+
+    /*
+     * Overridden in LWWindowPeer to replace its surface
+     * data and back buffer.
+     */
+    @Override
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        // TODO: not implemented
+//        throw new RuntimeException("Has not been implemented yet.");
+        return false;
+    }
+
+    @Override
+    public final synchronized Graphics getGraphics() {
+        Graphics g = getWindowPeerOrSelf().isOpaque() ? getOnscreenGraphics()
+                                                      : getOffscreenGraphics();
+        if (g != null) {
+            synchronized (getPeerTreeLock()){
+                applyConstrain(g);
+            }
+        }
+        return g;
+    }
+
+    /*
+     * Peer Graphics is borrowed from the parent peer, while
+     * foreground and background colors and font are specific to
+     * this peer.
+     */
+    public final Graphics getOnscreenGraphics() {
+        final LWWindowPeer wp = getWindowPeerOrSelf();
+        return wp.getOnscreenGraphics(getForeground(), getBackground(),
+                                      getFont());
+    }
+
+    public final Graphics getOffscreenGraphics() {
+        final LWWindowPeer wp = getWindowPeerOrSelf();
+
+        return wp.getOffscreenGraphics(getForeground(), getBackground(),
+                                       getFont());
+    }
+
+    private void applyConstrain(final Graphics g) {
+        final SunGraphics2D sg2d = (SunGraphics2D) g;
+        final Rectangle constr = localToWindow(getSize());
+        // translate and set rectangle constrain.
+        sg2d.constrain(constr.x, constr.y, constr.width, constr.height);
+        // set region constrain.
+        //sg2d.constrain(getVisibleRegion());
+        SG2DConstraint(sg2d, getVisibleRegion());
+    }
+
+    //TODO Move this method to SG2D?
+    private void SG2DConstraint(final SunGraphics2D sg2d, Region r) {
+        sg2d.constrainX = sg2d.transX;
+        sg2d.constrainY = sg2d.transY;
+
+        Region c = sg2d.constrainClip;
+        if ((sg2d.constrainX | sg2d.constrainY) != 0) {
+            r = r.getTranslatedRegion(sg2d.constrainX, sg2d.constrainY);
+        }
+        if (c == null) {
+            c = r;
+        } else {
+            c = c.getIntersection(r);
+            if (c == sg2d.constrainClip) {
+                // Common case to ignore
+                return;
+            }
+        }
+        sg2d.constrainClip = c;
+        //validateCompClip() forced call.
+        sg2d.setDevClip(r.getLoX(), r.getLoY(), r.getWidth(), r.getHeight());
+    }
+
+    public Region getVisibleRegion() {
+        return computeVisibleRect(this, getRegion());
+    }
+
+    static final Region computeVisibleRect(LWComponentPeer c, Region region) {
+        final LWContainerPeer p = c.getContainerPeer();
+        if (p != null) {
+            final Rectangle r = c.getBounds();
+            region = region.getTranslatedRegion(r.x, r.y);
+            region = region.getIntersection(p.getRegion());
+            region = region.getIntersection(p.getContentSize());
+            region = p.cutChildren(region, c);
+            region = computeVisibleRect(p, region);
+            region = region.getTranslatedRegion(-r.x, -r.y);
+        }
+        return region;
+    }
+
+    @Override
+    public ColorModel getColorModel() {
+        // Is it a correct implementation?
+        return getGraphicsConfiguration().getColorModel();
+    }
+
+    @Override
+    public void createBuffers(int numBuffers, BufferCapabilities caps)
+            throws AWTException {
+        throw new AWTException("Back buffers are only supported for " +
+                "Window or Canvas components.");
+    }
+
+    /*
+     * To be overridden in LWWindowPeer and LWCanvasPeer.
+     */
+    @Override
+    public Image getBackBuffer() {
+        // Return null or throw AWTException?
+        return null;
+    }
+
+    @Override
+    public void flip(int x1, int y1, int x2, int y2,
+                     BufferCapabilities.FlipContents flipAction) {
+        // Skip silently or throw AWTException?
+    }
+
+    @Override
+    public void destroyBuffers() {
+        // Do nothing
+    }
+
+    // Helper method
+    public void setBounds(Rectangle r) {
+        setBounds(r.x, r.y, r.width, r.height, SET_BOUNDS);
+    }
+
+    /**
+     * This method could be called on the toolkit thread.
+     */
+    @Override
+    public void setBounds(int x, int y, int w, int h, int op) {
+        setBounds(x, y, w, h, op, true, false);
+    }
+
+    protected void setBounds(int x, int y, int w, int h, int op, boolean notify,
+                             final boolean updateTarget) {
+        Rectangle oldBounds;
+        synchronized (getStateLock()) {
+            oldBounds = new Rectangle(bounds);
+            if ((op & (SET_LOCATION | SET_BOUNDS)) != 0) {
+                bounds.x = x;
+                bounds.y = y;
+            }
+            if ((op & (SET_SIZE | SET_BOUNDS)) != 0) {
+                bounds.width = w;
+                bounds.height = h;
+            }
+        }
+        boolean moved = (oldBounds.x != x) || (oldBounds.y != y);
+        boolean resized = (oldBounds.width != w) || (oldBounds.height != h);
+        if (!moved && !resized) {
+            return;
+        }
+        final D delegate = getDelegate();
+        if (delegate != null) {
+            synchronized (getDelegateLock()) {
+                delegateContainer.setBounds(0, 0, w, h);
+                delegate.setBounds(delegateContainer.getBounds());
+                // TODO: the following means that the delegateContainer NEVER gets validated. That's WRONG!
+                delegate.validate();
+            }
+        }
+
+        final Point locationInWindow = localToWindow(0, 0);
+        platformComponent.setBounds(locationInWindow.x, locationInWindow.y, w,
+                                    h);
+        if (notify) {
+            repaintOldNewBounds(oldBounds);
+            if (resized) {
+                handleResize(w, h, updateTarget);
+            }
+            if (moved) {
+                handleMove(x, y, updateTarget);
+            }
+        }
+    }
+
+    public final Rectangle getBounds() {
+        synchronized (getStateLock()) {
+            // Return a copy to prevent subsequent modifications
+            return bounds.getBounds();
+        }
+    }
+
+    public final Rectangle getSize() {
+        synchronized (getStateLock()) {
+            // Return a copy to prevent subsequent modifications
+            return new Rectangle(bounds.width, bounds.height);
+        }
+    }
+
+    @Override
+    public Point getLocationOnScreen() {
+        Point windowLocation = getWindowPeer().getLocationOnScreen();
+        Point locationInWindow = localToWindow(0, 0);
+        return new Point(windowLocation.x + locationInWindow.x,
+                windowLocation.y + locationInWindow.y);
+    }
+
+    @Override
+    public void setBackground(Color c) {
+        synchronized (getDelegateLock()) {
+            D delegate = getDelegate();
+            if (delegate != null) {
+                // delegate will repaint the target
+                delegate.setBackground(c);
+            }
+        }
+    }
+
+    protected Color getBackground() {
+        synchronized (getDelegateLock()) {
+            D delegate = getDelegate();
+            if (delegate != null) {
+                return delegate.getBackground();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public void setForeground(Color c) {
+        synchronized (getDelegateLock()) {
+            D delegate = getDelegate();
+            if (delegate != null) {
+                // delegate will repaint the target
+                delegate.setForeground(c);
+            }
+        }
+    }
+
+    protected Color getForeground() {
+        synchronized (getDelegateLock()) {
+            D delegate = getDelegate();
+            if (delegate != null) {
+                return delegate.getForeground();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public void setFont(Font f) {
+        synchronized (getDelegateLock()) {
+            D delegate = getDelegate();
+            if (delegate != null) {
+                // delegate will repaint the target
+                delegate.setFont(f);
+                if (f == null) {
+                    // we must explicitly set the font here
+                    // see Component.getFont_NoClientCode() for details
+                    delegateContainer.setFont(getTarget().getFont());
+                }
+            }
+        }
+    }
+
+    protected Font getFont() {
+        synchronized (getDelegateLock()) {
+            D delegate = getDelegate();
+            if (delegate != null) {
+                return delegate.getFont();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public FontMetrics getFontMetrics(Font f) {
+        // Borrow the metrics from the top-level window
+//        return getWindowPeer().getFontMetrics(f);
+        // Obtain the metrics from the offscreen window where this peer is
+        // mostly drawn to.
+        // TODO: check for "use platform metrics" settings
+        Graphics g = getWindowPeer().getOffscreenGraphics();
+        try {
+            if (g != null) {
+                return g.getFontMetrics(f);
+            } else {
+                synchronized (getDelegateLock()) {
+                    return delegateContainer.getFontMetrics(f);
+                }
+            }
+        } finally {
+            if (g != null) {
+                g.dispose();
+            }
+        }
+    }
+
+    @Override
+    public void setEnabled(final boolean e) {
+        boolean status = e;
+        final LWComponentPeer cp = getContainerPeer();
+        if (cp != null) {
+            status &= cp.isEnabled();
+        }
+        synchronized (getStateLock()) {
+            if (enabled == status) {
+                return;
+            }
+            enabled = status;
+        }
+
+        final D delegate = getDelegate();
+
+        if (delegate != null) {
+            synchronized (getDelegateLock()) {
+                delegate.setEnabled(status);
+            }
+        } else {
+            repaintPeer();
+        }
+    }
+
+    // Helper method
+    public boolean isEnabled() {
+        synchronized (getStateLock()) {
+            return enabled;
+        }
+    }
+
+    @Override
+    public void setVisible(boolean v) {
+        synchronized (getStateLock()) {
+            if (visible == v) {
+                return;
+            }
+            visible = v;
+        }
+
+        final D delegate = getDelegate();
+
+        if (delegate != null) {
+            synchronized (getDelegateLock()) {
+                delegate.setVisible(v);
+            }
+        }
+        if (visible) {
+            repaintPeer();
+        } else {
+            repaintParent(getBounds());
+        }
+    }
+
+    // Helper method
+    public boolean isVisible() {
+        synchronized (getStateLock()) {
+            return visible;
+        }
+    }
+
+    @Override
+    public void paint(final Graphics g) {
+        getTarget().paint(g);
+    }
+
+    @Override
+    public void print(final Graphics g) {
+        getTarget().print(g);
+    }
+
+    @Override
+    public void reparent(ContainerPeer newContainer) {
+        // TODO: not implemented
+        throw new UnsupportedOperationException("ComponentPeer.reparent()");
+    }
+
+    @Override
+    public boolean isReparentSupported() {
+        // TODO: not implemented
+        return false;
+    }
+
+    @Override
+    public void setZOrder(ComponentPeer above) {
+        LWContainerPeer cp = getContainerPeer();
+        // Don't check containerPeer for null as it can only happen
+        // for windows, but this method is overridden in
+        // LWWindowPeer and doesn't call super()
+        cp.setChildPeerZOrder(this, (LWComponentPeer) above);
+    }
+
+    @Override
+    public void coalescePaintEvent(PaintEvent e) {
+        if (!(e instanceof IgnorePaintEvent)) {
+            Rectangle r = e.getUpdateRect();
+            if ((r != null) && !r.isEmpty()) {
+                targetPaintArea.add(r, e.getID());
+            }
+        }
+    }
+
+    /*
+     * Should be overridden in subclasses which use complex Swing components.
+     */
+    @Override
+    public void layout() {
+        // TODO: not implemented
+    }
+
+    @Override
+    public boolean isObscured() {
+        // TODO: not implemented
+        return false;
+    }
+
+    @Override
+    public boolean canDetermineObscurity() {
+        // TODO: not implemented
+        return false;
+    }
+
+    /**
+     * Should be overridden in subclasses to forward the request
+     * to the Swing helper component, if required.
+     */
+    @Override
+    public Dimension getPreferredSize() {
+        // It looks like a default implementation for all toolkits
+        return getMinimumSize();
+    }
+
+    /*
+     * Should be overridden in subclasses to forward the request
+     * to the Swing helper component.
+     */
+    @Override
+    public Dimension getMinimumSize() {
+        D delegate = getDelegate();
+
+        if (delegate == null) {
+            // Is it a correct default value?
+            return getBounds().getSize();
+        } else {
+            synchronized (getDelegateLock()) {
+                return delegate.getMinimumSize();
+            }
+        }
+    }
+
+    @Override
+    public void updateCursorImmediately() {
+        getLWToolkit().getCursorManager().updateCursor();
+    }
+
+    @Override
+    public boolean isFocusable() {
+        // Overridden in focusable subclasses like buttons
+        return false;
+    }
+
+    @Override
+    public boolean requestFocus(Component lightweightChild, boolean temporary,
+                                boolean focusedWindowChangeAllowed, long time,
+                                CausedFocusEvent.Cause cause) {
+        if (LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
+                processSynchronousLightweightTransfer(getTarget(), lightweightChild, temporary,
+                        focusedWindowChangeAllowed, time)) {
+            return true;
+        }
+
+        int result = LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
+                shouldNativelyFocusHeavyweight(getTarget(), lightweightChild, temporary,
+                        focusedWindowChangeAllowed, time, cause);
+        switch (result) {
+            case LWKeyboardFocusManagerPeer.SNFH_FAILURE:
+                return false;
+            case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
+                Window parentWindow = SunToolkit.getContainingWindow(getTarget());
+                if (parentWindow == null) {
+                    LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
+                    return false;
+                }
+                LWWindowPeer parentPeer = (LWWindowPeer) parentWindow.getPeer();
+                if (parentPeer == null) {
+                    LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
+                    return false;
+                }
+
+                boolean res = parentPeer.requestWindowFocus(cause);
+                // If parent window can be made focused and has been made focused (synchronously)
+                // then we can proceed with children, otherwise we retreat
+                if (!res || !parentWindow.isFocused()) {
+                    LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
+                    return false;
+                }
+
+                LWComponentPeer focusOwnerPeer =
+                    LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
+                        getFocusOwner();
+                Component focusOwner = (focusOwnerPeer != null) ? focusOwnerPeer.getTarget() : null;
+                return LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
+                        getTarget(), temporary,
+                        focusedWindowChangeAllowed,
+                        time, cause, focusOwner);
+            case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
+                return true;
+        }
+
+        return false;
+    }
+
+    @Override
+    public Image createImage(ImageProducer producer) {
+        return new ToolkitImage(producer);
+    }
+
+    @Override
+    public Image createImage(int w, int h) {
+        // TODO: accelerated image
+        return getGraphicsConfiguration().createCompatibleImage(w, h);
+    }
+
+    @Override
+    public VolatileImage createVolatileImage(int w, int h) {
+        // TODO: is it a right/complete implementation?
+        return new SunVolatileImage(getTarget(), w, h);
+    }
+
+    @Override
+    public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
+        // TODO: is it a right/complete implementation?
+        return getToolkit().prepareImage(img, w, h, o);
+    }
+
+    @Override
+    public int checkImage(Image img, int w, int h, ImageObserver o) {
+        // TODO: is it a right/complete implementation?
+        return getToolkit().checkImage(img, w, h, o);
+    }
+
+    @Override
+    public boolean handlesWheelScrolling() {
+        // TODO: not implemented
+        return false;
+    }
+
+    @Override
+    public final void applyShape(final Region shape) {
+        synchronized (getStateLock()) {
+            region = shape;
+        }
+        repaintParent(getBounds());
+    }
+
+    protected final Region getRegion() {
+        synchronized (getStateLock()) {
+            return region == null ? Region.getInstance(getSize()) : region;
+        }
+    }
+
+    // DropTargetPeer Method
+    public synchronized void addDropTarget(DropTarget dt) {
+        // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
+        // if it's the first (or last) one for the component. Otherwise this call is a no-op.
+        if (++fNumDropTargets == 1) {
+            // Having a non-null drop target would be an error but let's check just in case:
+            if (fDropTarget != null)
+                System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
+
+            // Create a new drop target:
+            fDropTarget = CDropTarget.createDropTarget(dt, target, this);
+        }
+    }
+
+    // DropTargetPeer Method
+    public synchronized void removeDropTarget(DropTarget dt) {
+        // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
+        // if it's the first (or last) one for the component. Otherwise this call is a no-op.
+        if (--fNumDropTargets == 0) {
+            // Having a null drop target would be an error but let's check just in case:
+            if (fDropTarget != null) {
+                // Dispose of the drop target:
+                fDropTarget.dispose();
+                fDropTarget = null;
+            } else
+                System.err.println("CComponent.removeDropTarget(): current drop target is null.");
+        }
+    }
+
+    // ---- PEER NOTIFICATIONS ---- //
+
+    /**
+     * Called when this peer's location has been changed either as a result
+     * of target.setLocation() or as a result of user actions (window is
+     * dragged with mouse).
+     *
+     * To be overridden in LWWindowPeer to update its GraphicsConfig.
+     *
+     * This method could be called on the toolkit thread.
+     */
+    protected final void handleMove(final int x, final int y,
+                                    final boolean updateTarget) {
+        if (updateTarget) {
+            AWTAccessor.getComponentAccessor().setLocation(getTarget(), x, y);
+        }
+        postEvent(new ComponentEvent(getTarget(),
+                                     ComponentEvent.COMPONENT_MOVED));
+    }
+
+    /**
+     * Called when this peer's size has been changed either as a result of
+     * target.setSize() or as a result of user actions (window is resized).
+     *
+     * To be overridden in LWWindowPeer to update its SurfaceData and
+     * GraphicsConfig.
+     *
+     * This method could be called on the toolkit thread.
+     */
+    protected final void handleResize(final int w, final int h,
+                                      final boolean updateTarget) {
+        if (updateTarget) {
+            AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h);
+        }
+        postEvent(new ComponentEvent(getTarget(),
+                                     ComponentEvent.COMPONENT_RESIZED));
+    }
+
+    protected final void repaintOldNewBounds(final Rectangle oldB) {
+        repaintParent(oldB);
+        repaintPeer(getSize());
+    }
+
+    protected final void repaintParent(final Rectangle oldB) {
+        final LWContainerPeer cp = getContainerPeer();
+        if (cp != null) {
+            // Repaint unobscured part of the parent
+            cp.repaintPeer(cp.getContentSize().intersection(oldB));
+        }
+    }
+
+    // ---- EVENTS ---- //
+
+    /**
+     * Post an event to the proper Java EDT.
+     */
+    public void postEvent(AWTEvent event) {
+        SunToolkit.postEvent(getAppContext(), event);
+    }
+
+    protected void postPaintEvent(int x, int y, int w, int h) {
+        // TODO: call getIgnoreRepaint() directly with the right ACC
+        if (AWTAccessor.getComponentAccessor().getIgnoreRepaint(target)) {
+            return;
+        }
+        PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
+                createPaintEvent(getTarget(), x, y, w, h);
+        if (event != null) {
+            postEvent(event);
+        }
+    }
+
+    /*
+     * Gives a chance for the peer to handle the event after it's been
+     * processed by the target.
+     */
+    @Override
+    public void handleEvent(AWTEvent e) {
+        if ((e instanceof InputEvent) && ((InputEvent) e).isConsumed()) {
+            return;
+        }
+        switch (e.getID()) {
+            case FocusEvent.FOCUS_GAINED:
+            case FocusEvent.FOCUS_LOST:
+                handleJavaFocusEvent((FocusEvent) e);
+                break;
+            case PaintEvent.PAINT:
+                // Got a native paint event
+//                paintPending = false;
+                // fall through to the next statement
+            case PaintEvent.UPDATE:
+                handleJavaPaintEvent();
+                break;
+            case MouseEvent.MOUSE_PRESSED:
+                Component target = getTarget();
+                if ((e.getSource() == target) && !target.isFocusOwner() &&
+                        LWKeyboardFocusManagerPeer.shouldFocusOnClick(target)) {
+                    LWKeyboardFocusManagerPeer.requestFocusFor(target,
+                            CausedFocusEvent.Cause.MOUSE_EVENT);
+                }
+                break;
+        }
+
+        sendEventToDelegate(e);
+    }
+
+    private void sendEventToDelegate(final AWTEvent e) {
+        synchronized (getDelegateLock()) {
+            if (getDelegate() == null || !isShowing() || !isEnabled()) {
+                return;
+            }
+            AWTEvent delegateEvent = createDelegateEvent(e);
+            if (delegateEvent != null) {
+                AWTAccessor.getComponentAccessor()
+                        .processEvent((Component) delegateEvent.getSource(),
+                                delegateEvent);
+                if (delegateEvent instanceof KeyEvent) {
+                    KeyEvent ke = (KeyEvent) delegateEvent;
+                    SwingUtilities.processKeyBindings(ke);
+                }
+            }
+        }
+    }
+
+    protected AWTEvent createDelegateEvent(AWTEvent e) {
+        AWTEvent delegateEvent = null;
+        if (e instanceof MouseWheelEvent) {
+            MouseWheelEvent me = (MouseWheelEvent) e;
+            delegateEvent = new MouseWheelEvent(
+                    delegate, me.getID(), me.getWhen(),
+                    me.getModifiers(),
+                    me.getX(), me.getY(),
+                    me.getClickCount(),
+                    false,                       // popupTrigger
+                    MouseWheelEvent.WHEEL_UNIT_SCROLL,
+                    3, // TODO: wheel scroll amount
+                    me.getWheelRotation());
+        } else if (e instanceof MouseEvent) {
+            MouseEvent me = (MouseEvent) e;
+
+            Component eventTarget = SwingUtilities.getDeepestComponentAt(delegate, me.getX(), me.getY());
+
+            if (me.getID() == MouseEvent.MOUSE_DRAGGED) {
+                if (delegateDropTarget == null) {
+                    delegateDropTarget = eventTarget;
+                } else {
+                    eventTarget = delegateDropTarget;
+                }
+            }
+            if (me.getID() == MouseEvent.MOUSE_RELEASED && delegateDropTarget != null) {
+                eventTarget = delegateDropTarget;
+                delegateDropTarget = null;
+            }
+            if (eventTarget == null) {
+                eventTarget = delegate;
+            }
+            delegateEvent = SwingUtilities.convertMouseEvent(getTarget(), me, eventTarget);
+        } else if (e instanceof KeyEvent) {
+            KeyEvent ke = (KeyEvent) e;
+            delegateEvent = new KeyEvent(getDelegateFocusOwner(), ke.getID(), ke.getWhen(),
+                    ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation());
+        } else if (e instanceof FocusEvent) {
+            FocusEvent fe = (FocusEvent) e;
+            delegateEvent = new FocusEvent(getDelegateFocusOwner(), fe.getID(), fe.isTemporary());
+        }
+        return delegateEvent;
+    }
+
+    /**
+     * Handler for FocusEvents.
+     */
+    protected void handleJavaFocusEvent(FocusEvent e) {
+        // Note that the peer receives all the FocusEvents from
+        // its lightweight children as well
+        LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
+                setFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? this : null);
+    }
+
+    /**
+     * Peers with null delegates should clear background before paint.
+     *
+     * @return false on components that DO NOT require a clearRect() before
+     *         painting.
+     */
+    protected final boolean shouldClearRectBeforePaint() {
+        // By default, just fill the entire bounds with a bg color
+        // TODO: sun.awt.noerasebackground
+        return getDelegate() == null;
+    }
+
+    /**
+     * Handler for PAINT and UPDATE PaintEvents.
+     */
+    private void handleJavaPaintEvent() {
+        // Skip all painting while layouting and all UPDATEs
+        // while waiting for native paint
+//        if (!isLayouting && !paintPending) {
+        if (!isLayouting()) {
+            targetPaintArea.paint(getTarget(), shouldClearRectBeforePaint());
+        }
+    }
+
+    // ---- UTILITY METHODS ---- //
+
+    /**
+     * Finds a top-most visible component for the given point. The location is
+     * specified relative to the peer's parent.
+     */
+    public LWComponentPeer findPeerAt(final int x, final int y) {
+        final Rectangle r = getBounds();
+        final Region sh = getRegion();
+        final boolean found = isVisible() && sh.contains(x - r.x, y - r.y);
+        return found ? this : null;
+    }
+
+    /*
+     * Translated the given point in Window coordinates to the point in
+     * coordinates local to this component. The given window peer must be
+     * the window where this component is in.
+     */
+    public Point windowToLocal(int x, int y, LWWindowPeer wp) {
+        return windowToLocal(new Point(x, y), wp);
+    }
+
+    public Point windowToLocal(Point p, LWWindowPeer wp) {
+        LWComponentPeer cp = this;
+        while (cp != wp) {
+            Rectangle cpb = cp.getBounds();
+            p.x -= cpb.x;
+            p.y -= cpb.y;
+            cp = cp.getContainerPeer();
+        }
+        // Return a copy to prevent subsequent modifications
+        return new Point(p);
+    }
+
+    public Rectangle windowToLocal(Rectangle r, LWWindowPeer wp) {
+        Point p = windowToLocal(r.getLocation(), wp);
+        return new Rectangle(p, r.getSize());
+    }
+
+    public Point localToWindow(int x, int y) {
+        return localToWindow(new Point(x, y));
+    }
+
+    public Point localToWindow(Point p) {
+        LWComponentPeer cp = getContainerPeer();
+        Rectangle r = getBounds();
+        while (cp != null) {
+            p.x += r.x;
+            p.y += r.y;
+            r = cp.getBounds();
+            cp = cp.getContainerPeer();
+        }
+        // Return a copy to prevent subsequent modifications
+        return new Point(p);
+    }
+
+    public Rectangle localToWindow(Rectangle r) {
+        Point p = localToWindow(r.getLocation());
+        return new Rectangle(p, r.getSize());
+    }
+
+    public final void repaintPeer() {
+        repaintPeer(getSize());
+    }
+
+    public void repaintPeer(final Rectangle r) {
+        final Rectangle toPaint = getSize().intersection(r);
+        if (!isShowing() || toPaint.isEmpty()) {
+            return;
+        }
+
+        postPaintEvent(toPaint.x, toPaint.y, toPaint.width, toPaint.height);
+    }
+
+    /**
+     * Determines whether this peer is showing on screen. This means that the
+     * peer must be visible, and it must be in a container that is visible and
+     * showing.
+     *
+     * @see #isVisible()
+     */
+    protected boolean isShowing() {
+        synchronized (getPeerTreeLock()) {
+            if (isVisible()) {
+                final LWContainerPeer container = getContainerPeer();
+                return (container == null) || container.isShowing();
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Paints the peer. Overridden in subclasses to delegate the actual painting
+     * to Swing components.
+     */
+    protected void paintPeer(final Graphics g) {
+        final D delegate = getDelegate();
+        if (delegate != null) {
+            if (!SwingUtilities.isEventDispatchThread()) {
+                throw new InternalError("Painting must be done on EDT");
+            }
+            synchronized (getDelegateLock()) {
+                // JComponent.print() is guaranteed to not affect the double buffer
+                getDelegate().print(g);
+            }
+        }
+    }
+
+    // Just a helper method, thus final
+    protected final void flushOffscreenGraphics() {
+        flushOffscreenGraphics(getSize());
+    }
+
+    protected static final void flushOnscreenGraphics(){
+        final OGLRenderQueue rq = OGLRenderQueue.getInstance();
+        rq.lock();
+        try {
+            rq.flushNow();
+        } finally {
+            rq.unlock();
+        }
+    }
+
+    /*
+     * Flushes the given rectangle from the back buffer to the screen.
+     */
+    protected void flushOffscreenGraphics(Rectangle r) {
+        flushOffscreenGraphics(r.x, r.y, r.width, r.height);
+    }
+
+    private void flushOffscreenGraphics(int x, int y, int width, int height) {
+        Image bb = getWindowPeerOrSelf().getBackBuffer();
+        if (bb != null) {
+            // g is a screen Graphics from the delegate
+            final Graphics g = getOnscreenGraphics();
+
+            if (g != null && g instanceof Graphics2D) {
+                try {
+                    Graphics2D g2d = (Graphics2D)g;
+                    Point p = localToWindow(new Point(0, 0));
+                    Composite composite = g2d.getComposite();
+                    g2d.setComposite(AlphaComposite.Src);
+                    g.drawImage(bb, x, y, x + width, y + height, p.x + x,
+                            p.y + y, p.x + x + width, p.y + y + height,
+                            null);
+                    g2d.setComposite(composite);
+                } finally {
+                    g.dispose();
+                }
+            }
+        }
+    }
+
+    /**
+     * Used by ContainerPeer to skip all the paint events during layout.
+     *
+     * @param isLayouting layouting state.
+     */
+    protected final void setLayouting(final boolean isLayouting) {
+        this.isLayouting = isLayouting;
+    }
+
+    /**
+     * Returns layouting state. Used by ComponentPeer to skip all the paint
+     * events during layout.
+     *
+     * @return true during layout, false otherwise.
+     */
+    private final boolean isLayouting() {
+        return isLayouting;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWContainerPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWContainerPeer.java
new file mode 100644
index 0000000..563b743
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWContainerPeer.java
@@ -0,0 +1,253 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import sun.awt.SunGraphicsCallback;
+import sun.java2d.pipe.Region;
+
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import java.awt.peer.ContainerPeer;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.swing.JComponent;
+
+abstract class LWContainerPeer<T extends Container, D extends JComponent>
+    extends LWComponentPeer<T, D>
+    implements ContainerPeer
+{
+    // List of child peers sorted by z-order from bottom-most
+    // to top-most
+    private List<LWComponentPeer> childPeers =
+        new LinkedList<LWComponentPeer>();
+
+    LWContainerPeer(T target, PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    void addChildPeer(LWComponentPeer child) {
+        synchronized (getPeerTreeLock()) {
+            addChildPeer(child, childPeers.size());
+        }
+    }
+
+    void addChildPeer(LWComponentPeer child, int index) {
+        synchronized (getPeerTreeLock()) {
+            childPeers.add(index, child);
+        }
+        // TODO: repaint
+    }
+
+    void removeChildPeer(LWComponentPeer child) {
+        synchronized (getPeerTreeLock()) {
+            childPeers.remove(child);
+        }
+        // TODO: repaint
+    }
+
+    // Used by LWComponentPeer.setZOrder()
+    void setChildPeerZOrder(LWComponentPeer peer, LWComponentPeer above) {
+        synchronized (getPeerTreeLock()) {
+            childPeers.remove(peer);
+            int index = (above != null) ? childPeers.indexOf(above) : childPeers.size();
+            if (index >= 0) {
+                childPeers.add(index, peer);
+            } else {
+                // TODO: log
+            }
+        }
+        // TODO: repaint
+    }
+
+    // ---- PEER METHODS ---- //
+
+    /*
+     * Overridden in LWWindowPeer.
+     */
+    @Override
+    public Insets getInsets() {
+        return new Insets(0, 0, 0, 0);
+    }
+
+    @Override
+    public void beginValidate() {
+        // TODO: it seems that begin/endValidate() is only useful
+        // for heavyweight windows, when a batch movement for
+        // child windows  occurs. That's why no-op
+    }
+    @Override
+    public void endValidate() {
+        // TODO: it seems that begin/endValidate() is only useful
+        // for heavyweight windows, when a batch movement for
+        // child windows  occurs. That's why no-op
+    }
+
+    @Override
+    public void beginLayout() {
+        // Skip all painting till endLayout()
+        setLayouting(true);
+    }
+    @Override
+    public void endLayout() {
+        setLayouting(false);
+
+        // Post an empty event to flush all the pending target paints
+        postPaintEvent(0, 0, 0, 0);
+    }
+
+    // ---- PEER NOTIFICATIONS ---- //
+
+    /*
+     * Returns a copy of the childPeer collection.
+     */
+    protected List<LWComponentPeer> getChildren() {
+        synchronized (getPeerTreeLock()) {
+            Object copy = ((LinkedList)childPeers).clone();
+            return (List<LWComponentPeer>)copy;
+        }
+    }
+
+    @Override
+    public final Region getVisibleRegion() {
+        return cutChildren(super.getVisibleRegion(), null);
+    }
+
+    /**
+     * Removes bounds of children above specific child from the region. If above
+     * is null removes all bounds of children.
+     */
+    protected final Region cutChildren(Region r, final LWComponentPeer above) {
+        boolean aboveFound = above == null;
+        for (final LWComponentPeer child : getChildren()) {
+            if (!aboveFound && child == above) {
+                aboveFound = true;
+                continue;
+            }
+            if (aboveFound) {
+                if(child.isVisible()){
+                    final Rectangle cb = child.getBounds();
+                    final Region cr = child.getRegion();
+                    final Region tr = cr.getTranslatedRegion(cb.x, cb.y);
+                    r = r.getDifference(tr.getIntersection(getContentSize()));
+                }
+            }
+        }
+        return r;
+    }
+
+    // ---- UTILITY METHODS ---- //
+
+    /**
+     * Finds a top-most visible component for the given point. The location is
+     * specified relative to the peer's parent.
+     */
+    @Override
+    public final LWComponentPeer findPeerAt(int x, int y) {
+        LWComponentPeer peer = super.findPeerAt(x, y);
+        final Rectangle r = getBounds();
+        // Translate to this container's coordinates to pass to children
+        x -= r.x;
+        y -= r.y;
+        if (peer != null && getContentSize().contains(x, y)) {
+            synchronized (getPeerTreeLock()) {
+                for (int i = childPeers.size() - 1; i >= 0; --i) {
+                    LWComponentPeer p = childPeers.get(i).findPeerAt(x, y);
+                    if (p != null) {
+                        peer = p;
+                        break;
+                    }
+                }
+            }
+        }
+        return peer;
+    }
+
+    /*
+    * Called by the container when any part of this peer or child
+    * peers should be repainted
+    */
+    @Override
+    public final void repaintPeer(final Rectangle r) {
+        final Rectangle toPaint = getSize().intersection(r);
+        if (!isShowing() || toPaint.isEmpty()) {
+            return;
+        }
+        // First, post the PaintEvent for this peer
+        super.repaintPeer(toPaint);
+        // Second, handle all the children
+        // Use the straight order of children, so the bottom
+        // ones are painted first
+        repaintChildren(toPaint);
+    }
+
+    /*
+    * Paints all the child peers in the straight z-order, so the
+    * bottom-most ones are painted first.
+    */
+    private void repaintChildren(final Rectangle r) {
+        final Rectangle content = getContentSize();
+        for (final LWComponentPeer child : getChildren()) {
+            final Rectangle childBounds = child.getBounds();
+            Rectangle toPaint = r.intersection(childBounds);
+            toPaint = toPaint.intersection(content);
+            toPaint.translate(-childBounds.x, -childBounds.y);
+            child.repaintPeer(toPaint);
+        }
+    }
+
+    protected Rectangle getContentSize() {
+        return getSize();
+    }
+
+    @Override
+    public void setEnabled(final boolean e) {
+        super.setEnabled(e);
+        for (final LWComponentPeer child : getChildren()) {
+            child.setEnabled(e && child.getTarget().isEnabled());
+        }
+    }
+
+    @Override
+    public final void paint(final Graphics g) {
+        super.paint(g);
+        SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
+            runComponents(getTarget().getComponents(), g,
+                          SunGraphicsCallback.LIGHTWEIGHTS
+                          | SunGraphicsCallback.HEAVYWEIGHTS);
+    }
+
+    @Override
+    public final void print(final Graphics g) {
+        super.print(g);
+        SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
+            runComponents(getTarget().getComponents(), g,
+                          SunGraphicsCallback.LIGHTWEIGHTS
+                          | SunGraphicsCallback.HEAVYWEIGHTS);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java b/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java
new file mode 100644
index 0000000..62de104
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Cursor;
+import java.awt.Point;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import sun.awt.SunToolkit;
+
+public abstract class LWCursorManager {
+
+    // A flag to indicate if the update is scheduled, so we don't
+    // process it twice
+    private AtomicBoolean updatePending = new AtomicBoolean(false);
+
+    protected LWCursorManager() {
+    }
+
+    /*
+     * Sets the cursor to correspond the component currently under mouse.
+     *
+     * This method should not be executed on the toolkit thread as it
+     * calls to user code (e.g. Container.findComponentAt).
+     */
+    public void updateCursor() {
+        updatePending.set(false);
+        updateCursorImpl();
+    }
+
+    /*
+     * Schedules updating the cursor on the corresponding event dispatch
+     * thread for the given window.
+     *
+     * This method is called on the toolkit thread as a result of a
+     * native update cursor request (e.g. WM_SETCURSOR on Windows).
+     */
+    public void updateCursorLater(LWWindowPeer window) {
+        if (updatePending.compareAndSet(false, true)) {
+            Runnable r = new Runnable() {
+                @Override
+                public void run() {
+                    updateCursor();
+                }
+            };
+            SunToolkit.executeOnEventHandlerThread(window.getTarget(), r);
+        }
+    }
+
+    private void updateCursorImpl() {
+        LWWindowPeer windowUnderCursor = LWWindowPeer.getWindowUnderCursor();
+        Point cursorPos = getCursorPosition();
+        LWComponentPeer<?, ?> componentUnderCursor = null;
+        // TODO: it's possible to get the component under cursor directly as
+        // it's stored in LWWindowPee anyway (lastMouseEventPeer)
+        if (windowUnderCursor != null) {
+            componentUnderCursor = windowUnderCursor.findPeerAt(cursorPos.x, cursorPos.y);
+        }
+        Cursor cursor = null;
+        if (componentUnderCursor != null) {
+            Component c = componentUnderCursor.getTarget();
+            if (c instanceof Container) {
+                Point p = componentUnderCursor.getLocationOnScreen();
+                c = ((Container)c).findComponentAt(cursorPos.x - p.x, cursorPos.y - p.y);
+            }
+            // Traverse up to the first visible, enabled and showing component
+            while (c != null) {
+                if (c.isVisible() && c.isEnabled() && (c.getPeer() != null)) {
+                    break;
+                }
+                c = c.getParent();
+            }
+            if (c != null) {
+                cursor = c.getCursor();
+            }
+        }
+        // TODO: default cursor for modal blocked windows
+        setCursor(windowUnderCursor, cursor);
+    }
+
+    /*
+     * Returns the current cursor position.
+     */
+    // TODO: make it public to reuse for MouseInfo
+    protected abstract Point getCursorPosition();
+
+    /*
+     * Sets a cursor. The cursor can be null if the mouse is not over a Java window.
+     */
+    protected abstract void setCursor(LWWindowPeer windowUnderCursor, Cursor cursor);
+
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWKeyboardFocusManagerPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWKeyboardFocusManagerPeer.java
new file mode 100644
index 0000000..c230d7e
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWKeyboardFocusManagerPeer.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.Component;
+import java.awt.KeyboardFocusManager;
+import java.awt.Window;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import sun.awt.AWTAccessor;
+import sun.awt.AppContext;
+import sun.awt.KeyboardFocusManagerPeerImpl;
+
+public class LWKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
+
+    private Object lock = new Object();
+    private LWWindowPeer focusedWindow;
+    private LWComponentPeer focusOwner;
+
+    private static Map<KeyboardFocusManager, LWKeyboardFocusManagerPeer> instances =
+        new HashMap<KeyboardFocusManager, LWKeyboardFocusManagerPeer>();
+
+    public static synchronized LWKeyboardFocusManagerPeer getInstance(AppContext ctx) {
+        return getInstance(AWTAccessor.getKeyboardFocusManagerAccessor().
+                           getCurrentKeyboardFocusManager(ctx));
+    }
+
+    public static synchronized LWKeyboardFocusManagerPeer getInstance(KeyboardFocusManager manager) {
+        LWKeyboardFocusManagerPeer instance = instances.get(manager);
+        if (instance == null) {
+            instance = new LWKeyboardFocusManagerPeer(manager);
+            instances.put(manager, instance);
+        }
+        return instance;
+    }
+
+    public LWKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
+        super(manager);
+    }
+
+    @Override
+    public Window getCurrentFocusedWindow() {
+        synchronized (lock) {
+            return (focusedWindow != null) ? (Window)focusedWindow.getTarget() : null;
+        }
+    }
+
+    @Override
+    public Component getCurrentFocusOwner() {
+        synchronized (lock) {
+            return (focusOwner != null) ? focusOwner.getTarget() : null;
+        }
+    }
+
+    @Override
+    public void setCurrentFocusOwner(Component comp) {
+        synchronized (lock) {
+            focusOwner = (comp != null) ? (LWComponentPeer)comp.getPeer() : null;
+        }
+    }
+
+    void setFocusedWindow(LWWindowPeer peer) {
+        synchronized (lock) {
+            focusedWindow = peer;
+        }
+    }
+
+    void setFocusOwner(LWComponentPeer peer) {
+        synchronized (lock) {
+            focusOwner = peer;
+        }
+    }
+
+    LWComponentPeer getFocusOwner() {
+        synchronized (lock) {
+            return focusOwner;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWLabelPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWLabelPeer.java
new file mode 100644
index 0000000..5481e26
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWLabelPeer.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Label;
+import java.awt.peer.LabelPeer;
+
+import javax.swing.JLabel;
+import javax.swing.SwingConstants;
+
+/**
+ * Lightweight implementation of {@link LabelPeer}. Delegates most of the work
+ * to the {@link JLabel}.
+ */
+final class LWLabelPeer extends LWComponentPeer<Label, JLabel>
+        implements LabelPeer {
+
+    LWLabelPeer(final Label target, final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected JLabel createDelegate() {
+        final JLabel label = new JLabel();
+        label.setVerticalAlignment(SwingConstants.TOP);
+        return label;
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        setText(getTarget().getText());
+        setAlignment(getTarget().getAlignment());
+    }
+
+    @Override
+    public void setText(final String label) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setText(label);
+        }
+    }
+
+    @Override
+    public void setAlignment(final int alignment) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setHorizontalAlignment(convertAlignment(alignment));
+        }
+    }
+
+    /**
+     * Converts {@code Label} alignment constant to the {@code JLabel} constant.
+     * If wrong Label alignment provided returns default alignment.
+     *
+     * @param alignment {@code Label} constant.
+     *
+     * @return {@code JLabel} constant.
+     */
+    private static int convertAlignment(final int alignment) {
+        switch (alignment) {
+            case Label.CENTER:
+                return SwingConstants.CENTER;
+            case Label.RIGHT:
+                return SwingConstants.RIGHT;
+            default:
+                return SwingConstants.LEFT;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWListPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWListPeer.java
new file mode 100644
index 0000000..16740ab
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWListPeer.java
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.peer.ListPeer;
+import java.util.Arrays;
+
+final class LWListPeer
+        extends LWComponentPeer<List, LWListPeer.ScrollableJList>
+        implements ListPeer {
+
+    LWListPeer(final List target, final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected ScrollableJList createDelegate() {
+        return new ScrollableJList();
+    }
+
+    public void initialize() {
+        super.initialize();
+        setMultipleMode(getTarget().isMultipleMode());
+        final int[] selectedIndices = getTarget().getSelectedIndexes();
+        synchronized (getDelegateLock()) {
+            getDelegate().getView().setSelectedIndices(selectedIndices);
+        }
+    }
+
+    public boolean isFocusable() {
+        return true;
+    }
+
+    @Override
+    protected Component getDelegateFocusOwner() {
+        return getDelegate().getView();
+    }
+
+    @Override
+    public int[] getSelectedIndexes() {
+        synchronized (getDelegateLock()) {
+            return getDelegate().getView().getSelectedIndices();
+        }
+    }
+
+    @Override
+    public void add(final String item, final int index) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getModel().add(index, item);
+        }
+    }
+
+    @Override
+    public void delItems(final int start, final int end) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getModel().removeRange(start, end);
+        }
+    }
+
+    @Override
+    public void removeAll() {
+        synchronized (getDelegateLock()) {
+            getDelegate().getModel().removeAllElements();
+        }
+    }
+
+    @Override
+    public void select(final int index) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getView().setSelectedIndex(index);
+        }
+    }
+
+    @Override
+    public void deselect(final int index) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getView().getSelectionModel().
+                    removeSelectionInterval(index, index);
+        }
+    }
+
+    @Override
+    public void makeVisible(final int index) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getView().ensureIndexIsVisible(index);
+        }
+    }
+
+    @Override
+    public void setMultipleMode(final boolean m) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getView().setSelectionMode(m ?
+                    ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
+                    : ListSelectionModel.SINGLE_SELECTION);
+        }
+    }
+
+    @Override
+    public Dimension getPreferredSize(final int rows) {
+        return getMinimumSize(rows);
+    }
+
+    @Override
+    public Dimension getMinimumSize(final int rows) {
+        synchronized (getDelegateLock()) {
+            final int margin = 2;
+            final int space = 1;
+
+            // TODO: count ScrollPane's scrolling elements if any.
+            final FontMetrics fm = getFontMetrics(getFont());
+            final int itemHeight = (fm.getHeight() - fm.getLeading()) + (2 * space);
+
+            return new Dimension(20 + (fm == null ? 10 * 15 : fm.stringWidth("0123456789abcde")),
+                    (fm == null ? 10 : itemHeight) * rows + (2 * margin));
+        }
+    }
+
+
+    final class ScrollableJList extends JScrollPane implements ListSelectionListener {
+
+        private DefaultListModel<Object> model =
+                new DefaultListModel<Object>() {
+                    @Override
+                    public void add(final int index, final Object element) {
+                        if (index == -1) {
+                            addElement(element);
+                        } else {
+                            super.add(index, element);
+                        }
+                    }
+                };
+
+        private int[] oldSelectedIndices = new int[0];
+
+        ScrollableJList() {
+            getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
+            final JList<Object> list = new JListDelegate();
+            list.addListSelectionListener(this);
+
+            getViewport().setView(list);
+
+            // Pull the items from the target.
+            final String[] items = getTarget().getItems();
+            for (int i = 0; i < items.length; i++) {
+                model.add(i, items[i]);
+            }
+        }
+
+        @Override
+        public void valueChanged(final ListSelectionEvent e) {
+            if (!e.getValueIsAdjusting()) {
+                final JList source = (JList) e.getSource();
+                for(int i = 0 ; i < source.getModel().getSize(); i++) {
+
+                    final boolean wasSelected = Arrays.binarySearch(oldSelectedIndices, i) >= 0;
+                    final boolean isSelected = source.isSelectedIndex(i);
+
+                    if (wasSelected == isSelected) {
+                        continue;
+                    }
+
+                    final int state = !wasSelected && isSelected ? ItemEvent.SELECTED: ItemEvent.DESELECTED;
+
+                    LWListPeer.this.postEvent(new ItemEvent(getTarget(), ItemEvent.ITEM_STATE_CHANGED,
+                            i, state));
+                }
+                oldSelectedIndices = source.getSelectedIndices();
+            }
+        }
+
+        public JList getView() {
+            return (JList) getViewport().getView();
+        }
+
+        public DefaultListModel<Object> getModel() {
+            return model;
+        }
+
+        @Override
+        public void setEnabled(final boolean enabled) {
+            getView().setEnabled(enabled);
+            super.setEnabled(enabled);
+        }
+
+        @Override
+        public void setBackground(final Color bg) {
+            super.setBackground(bg);
+            if (getView() != null) {
+                getView().setBackground(bg);
+            }
+        }
+
+        @Override
+        public void setForeground(final Color fg) {
+            super.setForeground(fg);
+            if (getView() != null) {
+                getView().setForeground(fg);
+            }
+        }
+
+        @Override
+        public void setFont(final Font font) {
+            super.setFont(font);
+            if (getView() != null) {
+                getView().setFont(font);
+            }
+        }
+
+        @Override
+        public void setOpaque(final boolean isOpaque) {
+            super.setOpaque(isOpaque);
+            if (getView() != null) {
+                getView().setOpaque(isOpaque);
+            }
+        }
+
+        private final class JListDelegate extends JList<Object> {
+
+            JListDelegate() {
+                super(ScrollableJList.this.model);
+            }
+
+            @Override
+            public boolean hasFocus() {
+                return getTarget().hasFocus();
+            }
+
+            @Override
+            protected void processMouseEvent(final MouseEvent e) {
+                super.processMouseEvent(e);
+                if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2) {
+                    final int index = locationToIndex(e.getPoint());
+                    LWListPeer.this.postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
+                            getModel().getElementAt(index).toString(), e.getWhen(), e.getModifiers()));
+                }
+            }
+
+            @Override
+            protected void processKeyEvent(final KeyEvent e) {
+                super.processKeyEvent(e);
+                if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ENTER) {
+                    final int index = getSelectedIndex();
+                    LWListPeer.this.postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
+                            getModel().getElementAt(index).toString(), e.getWhen(), e.getModifiers()));
+                }
+            }
+
+            //Needed for Autoscroller.
+            @Override
+            public Point getLocationOnScreen() {
+                return LWListPeer.this.getLocationOnScreen();
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWMouseInfoPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWMouseInfoPeer.java
new file mode 100644
index 0000000..2cce1b1
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWMouseInfoPeer.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.Point;
+import java.awt.Window;
+
+import java.awt.peer.MouseInfoPeer;
+
+public class LWMouseInfoPeer implements MouseInfoPeer {
+
+    public LWMouseInfoPeer() {
+    }
+
+    @Override
+    public int fillPointWithCoords(Point point) {
+        LWCursorManager cursorManager =
+            LWToolkit.getLWToolkit().getCursorManager();
+        Point cursorPos = cursorManager.getCursorPosition();
+        point.x = cursorPos.x;
+        point.y = cursorPos.y;
+        // TODO: multiscreen
+        return 0;
+    }
+
+    @Override
+    public boolean isWindowUnderMouse(Window w) {
+        if (w == null) {
+            return false;
+        }
+
+        LWWindowPeer windowPeer = (LWWindowPeer)w.getPeer();
+        return LWWindowPeer.getWindowUnderCursor() == windowPeer;
+    }
+
+}
+
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWPanelPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWPanelPeer.java
new file mode 100644
index 0000000..c38c608
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWPanelPeer.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Dimension;
+import java.awt.Panel;
+import java.awt.peer.PanelPeer;
+
+import javax.swing.JPanel;
+
+final class LWPanelPeer extends LWContainerPeer<Panel, JPanel>
+        implements PanelPeer {
+
+    LWPanelPeer(final Panel target, final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    public JPanel createDelegate() {
+        return new JPanel();
+    }
+
+    @Override
+    public Dimension getMinimumSize() {
+        return getTarget().getSize();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWRepaintArea.java b/jdk/src/macosx/classes/sun/lwawt/LWRepaintArea.java
new file mode 100644
index 0000000..e29009d
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWRepaintArea.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import sun.awt.RepaintArea;
+
+import java.awt.Component;
+import java.awt.Graphics;
+
+/**
+ * @author Sergey Bylokhov
+ */
+final class LWRepaintArea extends RepaintArea {
+
+    @Override
+    protected void updateComponent(final Component comp, final Graphics g) {
+        if (comp != null) {
+            final LWComponentPeer peer = (LWComponentPeer) comp.getPeer();
+            if (peer != null) {
+                peer.paintPeer(g);
+            }
+            super.updateComponent(comp, g);
+            flushBuffers(peer);
+        }
+    }
+
+    @Override
+    protected void paintComponent(final Component comp, final Graphics g) {
+        if (comp != null) {
+            final LWComponentPeer peer = (LWComponentPeer) comp.getPeer();
+            if (peer != null) {
+                peer.paintPeer(g);
+            }
+            super.paintComponent(comp, g);
+            flushBuffers(peer);
+        }
+    }
+
+    private static void flushBuffers(final LWComponentPeer peer) {
+        if (peer != null) {
+            if (!peer.getWindowPeerOrSelf().isOpaque()) {
+                peer.flushOffscreenGraphics();
+            }
+            peer.flushOnscreenGraphics();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWScrollBarPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWScrollBarPeer.java
new file mode 100644
index 0000000..acf4226
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWScrollBarPeer.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Adjustable;
+import java.awt.Dimension;
+import java.awt.Scrollbar;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
+import java.awt.peer.ScrollbarPeer;
+
+import javax.swing.JScrollBar;
+
+final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar>
+        implements ScrollbarPeer, AdjustmentListener {
+
+    //JScrollBar fires two changes with firePropertyChange (one for old value
+    // and one for new one.
+    // We save the last value and don't fire event if not changed.
+    private int currentValue;
+
+    LWScrollBarPeer(final Scrollbar target,
+                    final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected JScrollBar createDelegate() {
+        return new JScrollBar();
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        final Scrollbar target = getTarget();
+        setValues(target.getValue(), target.getVisibleAmount(),
+                  target.getMinimum(), target.getMaximum());
+
+        final int orientation = target.getOrientation();
+        final JScrollBar delegate = getDelegate();
+        synchronized (getDelegateLock()) {
+            delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
+                                    ? Adjustable.HORIZONTAL
+                                    : Adjustable.VERTICAL);
+            delegate.addAdjustmentListener(this);
+        }
+    }
+
+    @Override
+    public void setValues(final int value, final int visible, final int minimum,
+                          final int maximum) {
+        synchronized (getDelegateLock()) {
+            currentValue = value;
+            getDelegate().setValue(value);
+            getDelegate().setVisibleAmount(visible);
+            getDelegate().setMinimum(minimum);
+            getDelegate().setMaximum(maximum);
+        }
+    }
+
+    @Override
+    public void setLineIncrement(final int l) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setUnitIncrement(l);
+        }
+    }
+
+    @Override
+    public void setPageIncrement(final int l) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setBlockIncrement(l);
+        }
+    }
+
+    @Override
+    public Dimension getPreferredSize() {
+        synchronized (getDelegateLock()) {
+            return getDelegate().getPreferredSize();
+        }
+    }
+
+    // Peer also registered as a listener for ComponentDelegate component
+    @Override
+    public void adjustmentValueChanged(final AdjustmentEvent e) {
+        synchronized (getDelegateLock()) {
+            if (currentValue == e.getValue()) {
+                return;
+            }
+            currentValue = e.getValue();
+        }
+
+        // TODO: we always get event with the TRACK adj. type.
+        // Could we check if we are over the ArrowButton and send event there?
+        postEvent(new AdjustmentEvent(getTarget(), e.getID(),
+                                      e.getAdjustmentType(), e.getValue(),
+                                      e.getValueIsAdjusting()));
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWScrollPanePeer.java b/jdk/src/macosx/classes/sun/lwawt/LWScrollPanePeer.java
new file mode 100644
index 0000000..1b1bdf5
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWScrollPanePeer.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import javax.swing.*;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ChangeEvent;
+import java.awt.*;
+import java.awt.peer.ScrollPanePeer;
+import java.util.List;
+
+final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane>
+        implements ScrollPanePeer, ChangeListener {
+
+    LWScrollPanePeer(final ScrollPane target,
+                     final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    protected JScrollPane createDelegate() {
+        final JScrollPane sp = new JScrollPane();
+        final JPanel panel = new JPanel();
+        panel.setOpaque(false);
+        panel.setVisible(false);
+        sp.getViewport().setView(panel);
+        sp.setBorder(BorderFactory.createEmptyBorder());
+        sp.getViewport().addChangeListener(this);
+        return sp;
+    }
+
+    @Override
+    public void stateChanged(final ChangeEvent e) {
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                final LWComponentPeer viewPeer = getViewPeer();
+                if (viewPeer != null) {
+                    final Rectangle r;
+                    synchronized (getDelegateLock()) {
+                        r = getDelegate().getViewport().getView().getBounds();
+                    }
+                    viewPeer.setBounds(r.x, r.y, r.width, r.height, SET_BOUNDS,
+                                       true, true);
+                }
+            }
+        });
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        final int policy = getTarget().getScrollbarDisplayPolicy();
+        synchronized (getDelegateLock()) {
+            getDelegate().getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
+            getDelegate().setVerticalScrollBarPolicy(convertVPolicy(policy));
+            getDelegate().setHorizontalScrollBarPolicy(convertHPolicy(policy));
+        }
+    }
+
+    LWComponentPeer getViewPeer() {
+        List<LWComponentPeer> peerList = getChildren();
+        return peerList.isEmpty() ? null : peerList.get(0);
+    }
+
+
+    @Override
+    protected Rectangle getContentSize() {
+        Rectangle viewRect = getDelegate().getViewport().getViewRect();
+        return new Rectangle(viewRect.width, viewRect.height);
+    }
+
+    @Override
+    public void layout() {
+        super.layout();
+        synchronized (getDelegateLock()) {
+            LWComponentPeer viewPeer = getViewPeer();
+            if (viewPeer != null) {
+                Component view = getDelegate().getViewport().getView();
+                view.setBounds(viewPeer.getBounds());
+                view.setPreferredSize(viewPeer.getPreferredSize());
+                view.setMinimumSize(viewPeer.getMinimumSize());
+                getDelegate().invalidate();
+                getDelegate().validate();
+                viewPeer.setBounds(view.getBounds());
+            }
+        }
+    }
+
+    @Override
+    public void setScrollPosition(int x, int y) {
+    }
+
+    @Override
+    public int getHScrollbarHeight() {
+        synchronized (getDelegateLock()) {
+            return getDelegate().getHorizontalScrollBar().getHeight();
+        }
+    }
+
+    @Override
+    public int getVScrollbarWidth() {
+        synchronized (getDelegateLock()) {
+            return getDelegate().getVerticalScrollBar().getWidth();
+        }
+    }
+
+    @Override
+    public void childResized(int w, int h) {
+        synchronized (getDelegateLock()) {
+            getDelegate().invalidate();
+            getDelegate().validate();
+        }
+    }
+
+    @Override
+    public void setUnitIncrement(Adjustable adj, int u) {
+    }
+
+    @Override
+    public void setValue(Adjustable adj, int v) {
+    }
+
+    private static int convertHPolicy(final int policy) {
+        switch (policy) {
+            case ScrollPane.SCROLLBARS_NEVER:
+                return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
+            case ScrollPane.SCROLLBARS_ALWAYS:
+                return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
+            default:
+                return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
+        }
+    }
+
+    private static int convertVPolicy(final int policy) {
+        switch (policy) {
+            case ScrollPane.SCROLLBARS_NEVER:
+                return ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER;
+            case ScrollPane.SCROLLBARS_ALWAYS:
+                return ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
+            default:
+                return ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java
new file mode 100644
index 0000000..1d93c4c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.TextArea;
+import java.awt.event.TextEvent;
+import java.awt.peer.TextAreaPeer;
+
+import javax.swing.JScrollBar;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+
+final class LWTextAreaPeer
+        extends LWTextComponentPeer<TextArea, LWTextAreaPeer.ScrollableJTextArea>
+        implements TextAreaPeer {
+
+    private static final int DEFAULT_COLUMNS = 60;
+    private static final int DEFAULT_ROWS = 10;
+
+    LWTextAreaPeer(final TextArea target,
+                   final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected ScrollableJTextArea createDelegate() {
+        return new ScrollableJTextArea();
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        final int visibility = getTarget().getScrollbarVisibility();
+        synchronized (getDelegateLock()) {
+            setScrollBarVisibility(visibility);
+        }
+    }
+
+    @Override
+    JTextComponent getTextComponent() {
+        return getDelegate().getView();
+    }
+
+    @Override
+    protected Component getDelegateFocusOwner() {
+        return getTextComponent();
+    }
+
+    @Override
+    public Dimension getMinimumSize() {
+        return getMinimumSize(DEFAULT_ROWS, DEFAULT_COLUMNS);
+    }
+
+    @Override
+    public Dimension getMinimumSize(final int rows, final int columns) {
+        return getPreferredSize(rows, columns);
+    }
+
+    @Override
+    public Dimension getPreferredSize(final int rows, final int columns) {
+        final Dimension size = super.getPreferredSize(rows, columns);
+        synchronized (getDelegateLock()) {
+            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
+            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
+            final int scrollbarW = vbar != null ? vbar.getWidth() : 0;
+            final int scrollbarH = hbar != null ? hbar.getHeight() : 0;
+            return new Dimension(size.width + scrollbarW,
+                                 size.height + scrollbarH);
+        }
+    }
+
+    @Override
+    public void insert(final String text, final int pos) {
+        final ScrollableJTextArea pane = getDelegate();
+        synchronized (getDelegateLock()) {
+            final JTextArea area = pane.getView();
+            final boolean doScroll = pos >= area.getDocument().getLength()
+                                     && area.getDocument().getLength() != 0;
+            area.insert(text, pos);
+            pane.validate();
+            if (doScroll) {
+                final JScrollBar vbar = pane.getVerticalScrollBar();
+                if (vbar != null) {
+                    vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
+                }
+            }
+        }
+        repaintPeer();
+    }
+
+    @Override
+    public void setText(final String l) {
+        // Please note that we do not want to post an event
+        // if TextArea.setText() replaces an empty text by an empty text,
+        // that is, if component's text remains unchanged.
+        if (!l.isEmpty() || getTextComponent().getDocument().getLength() != 0) {
+            super.setText(l);
+        }
+    }
+
+    @Override
+    public void replaceRange(final String text, final int start,
+                             final int end) {
+        synchronized (getDelegateLock()) {
+            // JTextArea.replaceRange() posts two different events.
+            // Since we make no differences between text events,
+            // the document listener has to be disabled while
+            // JTextArea.replaceRange() is called.
+            final Document document = getTextComponent().getDocument();
+            document.removeDocumentListener(this);
+            getDelegate().getView().replaceRange(text, start, end);
+            postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
+            document.addDocumentListener(this);
+        }
+        repaintPeer();
+    }
+
+    private void setScrollBarVisibility(final int visibility) {
+        final ScrollableJTextArea pane = getDelegate();
+        final JTextArea view = pane.getView();
+        view.setLineWrap(false);
+
+        switch (visibility) {
+            case TextArea.SCROLLBARS_NONE:
+                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+                view.setLineWrap(true);
+                break;
+            case TextArea.SCROLLBARS_VERTICAL_ONLY:
+                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
+                view.setLineWrap(true);
+                break;
+            case TextArea.SCROLLBARS_HORIZONTAL_ONLY:
+                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
+                break;
+            default:
+                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
+                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
+                break;
+        }
+    }
+
+    @SuppressWarnings("serial")
+    final class ScrollableJTextArea extends JScrollPane {
+
+        ScrollableJTextArea() {
+            super();
+            getViewport().setView(new JTextAreaDelegate());
+        }
+
+        public JTextArea getView() {
+            return (JTextArea) getViewport().getView();
+        }
+
+        @Override
+        public void setEnabled(final boolean enabled) {
+            getViewport().getView().setEnabled(enabled);
+            super.setEnabled(enabled);
+        }
+
+        @SuppressWarnings("serial")
+        private final class JTextAreaDelegate extends JTextArea {
+
+            // Empty non private constructor was added because access to this
+            // class shouldn't be emulated by a synthetic accessor method.
+            JTextAreaDelegate() {
+                super();
+            }
+
+            @Override
+            public boolean hasFocus() {
+                return getTarget().hasFocus();
+            }
+
+            @Override
+            public Point getLocationOnScreen() {
+                return LWTextAreaPeer.this.getLocationOnScreen();
+            }
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java
new file mode 100644
index 0000000..311a44f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.SystemColor;
+import java.awt.TextComponent;
+import java.awt.event.TextEvent;
+import java.awt.im.InputMethodRequests;
+import java.awt.peer.TextComponentPeer;
+
+import javax.swing.JComponent;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+
+abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent>
+        extends LWComponentPeer<T, D>
+        implements DocumentListener, TextComponentPeer {
+
+    /**
+     * Character with reasonable value between the minimum width and maximum.
+     */
+    protected static final char WIDE_CHAR = 'w';
+    private volatile boolean firstChangeSkipped;
+
+    LWTextComponentPeer(final T target,
+                        final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        if (!getTarget().isBackgroundSet()) {
+            getTarget().setBackground(SystemColor.text);
+        }
+        synchronized (getDelegateLock()) {
+            // This listener should be added before setText().
+            getTextComponent().getDocument().addDocumentListener(this);
+        }
+        setEditable(getTarget().isEditable());
+        setText(getTarget().getText());
+        final int start = getTarget().getSelectionStart();
+        final int end = getTarget().getSelectionEnd();
+        if (end > start) {
+            select(start, end);
+        }
+        setCaretPosition(getTarget().getCaretPosition());
+        firstChangeSkipped = true;
+    }
+
+    abstract JTextComponent getTextComponent();
+
+    public Dimension getPreferredSize(final int rows, final int columns) {
+        final Insets insets;
+        synchronized (getDelegateLock()) {
+            insets = getDelegate().getInsets();
+        }
+        final int borderHeight = insets.top + insets.bottom;
+        final int borderWidth = insets.left + insets.right;
+        final FontMetrics fm = getFontMetrics(getFont());
+        final int charWidth = (fm != null) ? fm.charWidth(WIDE_CHAR) : 10;
+        final int itemHeight = (fm != null) ? fm.getHeight() : 10;
+        return new Dimension(columns * charWidth + borderWidth,
+                             rows * itemHeight + borderHeight);
+    }
+
+    @Override
+    public final void setEditable(final boolean editable) {
+        synchronized (getDelegateLock()) {
+            getTextComponent().setEditable(editable);
+        }
+    }
+
+    @Override
+    public final String getText() {
+        synchronized (getDelegateLock()) {
+            return getTextComponent().getText();
+        }
+    }
+
+    @Override
+    public void setText(final String l) {
+        synchronized (getDelegateLock()) {
+            // JTextArea.setText() posts two different events (remove & insert).
+            // Since we make no differences between text events,
+            // the document listener has to be disabled while
+            // JTextArea.setText() is called.
+            final Document document = getTextComponent().getDocument();
+            document.removeDocumentListener(this);
+            getTextComponent().setText(l);
+            if (firstChangeSkipped) {
+                postEvent(new TextEvent(getTarget(),
+                                        TextEvent.TEXT_VALUE_CHANGED));
+            }
+            document.addDocumentListener(this);
+        }
+        repaintPeer();
+    }
+
+    @Override
+    public final int getSelectionStart() {
+        synchronized (getDelegateLock()) {
+            return getTextComponent().getSelectionStart();
+        }
+    }
+
+    @Override
+    public final int getSelectionEnd() {
+        synchronized (getDelegateLock()) {
+            return getTextComponent().getSelectionEnd();
+        }
+    }
+
+    @Override
+    public final void select(final int selStart, final int selEnd) {
+        synchronized (getDelegateLock()) {
+            getTextComponent().select(selStart, selEnd);
+        }
+        repaintPeer();
+    }
+
+    @Override
+    public final void setCaretPosition(final int pos) {
+        synchronized (getDelegateLock()) {
+            getTextComponent().setCaretPosition(pos);
+        }
+        repaintPeer();
+    }
+
+    @Override
+    public final int getCaretPosition() {
+        synchronized (getDelegateLock()) {
+            return getTextComponent().getCaretPosition();
+        }
+    }
+
+    @Override
+    public final InputMethodRequests getInputMethodRequests() {
+        return null;
+    }
+
+    @Override
+    public final boolean isFocusable() {
+        return getTarget().isFocusable();
+    }
+
+    private void sendTextEvent(final DocumentEvent e) {
+        postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
+        synchronized (getDelegateLock()) {
+            getDelegate().invalidate();
+            getDelegate().validate();
+        }
+    }
+
+    @Override
+    public final void changedUpdate(final DocumentEvent e) {
+        sendTextEvent(e);
+    }
+
+    @Override
+    public final void insertUpdate(final DocumentEvent e) {
+        sendTextEvent(e);
+    }
+
+    @Override
+    public final void removeUpdate(final DocumentEvent e) {
+        sendTextEvent(e);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
new file mode 100644
index 0000000..fb94d0b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt;
+
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.peer.TextFieldPeer;
+
+import javax.swing.JPasswordField;
+import javax.swing.text.JTextComponent;
+
+final class LWTextFieldPeer
+        extends LWTextComponentPeer<TextField, JPasswordField>
+        implements TextFieldPeer, ActionListener {
+
+    private static final int DEFAULT_COLUMNS = 1;
+
+    LWTextFieldPeer(final TextField target,
+                    final PlatformComponent platformComponent) {
+        super(target, platformComponent);
+    }
+
+    @Override
+    protected JPasswordField createDelegate() {
+        return new JTextAreaDelegate();
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        setEchoChar(getTarget().getEchoChar());
+        synchronized (getDelegateLock()) {
+            getDelegate().addActionListener(this);
+        }
+    }
+
+    @Override
+    public JTextComponent getTextComponent() {
+        return getDelegate();
+    }
+
+    @Override
+    public void setEchoChar(final char echoChar) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setEchoChar(echoChar);
+            getDelegate().putClientProperty("JPasswordField.cutCopyAllowed",
+                                            getDelegate().echoCharIsSet()
+                                            ? Boolean.FALSE : Boolean.TRUE);
+        }
+    }
+
+    @Override
+    public Dimension getPreferredSize(final int columns) {
+        return getPreferredSize(1, columns);
+    }
+
+    @Override
+    public Dimension getMinimumSize(final int columns) {
+        return getPreferredSize(columns);
+    }
+
+    @Override
+    public Dimension getMinimumSize() {
+        return getMinimumSize(DEFAULT_COLUMNS);
+    }
+
+    @Override
+    public void actionPerformed(final ActionEvent e) {
+        postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
+                                  getText(), e.getWhen(), e.getModifiers()));
+    }
+
+    private final class JTextAreaDelegate extends JPasswordField {
+
+        // Empty non private constructor was added because access to this
+        // class shouldn't be emulated by a synthetic accessor method.
+        JTextAreaDelegate() {
+            super();
+        }
+
+        @Override
+        public boolean hasFocus() {
+            return getTarget().hasFocus();
+        }
+
+        @Override
+        public Point getLocationOnScreen() {
+            return LWTextFieldPeer.this.getLocationOnScreen();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java b/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java
new file mode 100644
index 0000000..37d8a89
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java
@@ -0,0 +1,537 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.*;
+import java.awt.List;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.awt.dnd.peer.*;
+import java.awt.image.*;
+import java.awt.peer.*;
+import java.security.*;
+import java.util.*;
+
+import sun.awt.*;
+import sun.lwawt.macosx.*;
+import sun.print.*;
+
+public abstract class LWToolkit extends SunToolkit implements Runnable {
+
+    private final static int STATE_NONE = 0;
+    private final static int STATE_INIT = 1;
+    private final static int STATE_MESSAGELOOP = 2;
+    private final static int STATE_SHUTDOWN = 3;
+    private final static int STATE_CLEANUP = 4;
+    private final static int STATE_DONE = 5;
+
+    private int runState = STATE_NONE;
+
+    private Clipboard clipboard;
+    private MouseInfoPeer mouseInfoPeer;
+
+    private static Map<PlatformWindow, LWWindowPeer> delegateMap =
+        new HashMap<PlatformWindow, LWWindowPeer>();
+
+    public LWToolkit() {
+    }
+
+    /*
+     * This method is called by subclasses to start this toolkit
+     * by launching the message loop.
+     *
+     * This method waits for the toolkit to be completely initialized
+     * and returns before the message pump is started.
+     */
+    protected final void init() {
+        AWTAutoShutdown.notifyToolkitThreadBusy();
+
+        ThreadGroup mainTG = AccessController.doPrivileged(
+            new PrivilegedAction<ThreadGroup>() {
+                public ThreadGroup run() {
+                    ThreadGroup currentTG = Thread.currentThread().getThreadGroup();
+                    ThreadGroup parentTG = currentTG.getParent();
+                    while (parentTG != null) {
+                        currentTG = parentTG;
+                        parentTG = currentTG.getParent();
+                    }
+                    return currentTG;
+                }
+            }
+        );
+
+        Runtime.getRuntime().addShutdownHook(
+            new Thread(mainTG, new Runnable() {
+                public void run() {
+                    shutdown();
+                    waitForRunState(STATE_CLEANUP);
+                }
+            })
+        );
+
+        Thread toolkitThread = new Thread(mainTG, this, "AWT-LW");
+        toolkitThread.setDaemon(true);
+        toolkitThread.setPriority(Thread.NORM_PRIORITY + 1);
+        toolkitThread.start();
+
+        waitForRunState(STATE_MESSAGELOOP);
+    }
+
+    /*
+     * Implemented in subclasses to initialize platform-dependent
+     * part of the toolkit (open X display connection, create
+     * toolkit HWND, etc.)
+     *
+     * This method is called on the toolkit thread.
+     */
+    protected abstract void platformInit();
+
+    /*
+     * Sends a request to stop the message pump.
+     */
+    public void shutdown() {
+        setRunState(STATE_SHUTDOWN);
+        platformShutdown();
+    }
+
+    /*
+     * Implemented in subclasses to release all the platform-
+     * dependent resources. Called after the message loop is
+     * terminated.
+     *
+     * Could be called (always called?) on a non-toolkit thread.
+     */
+    protected abstract void platformShutdown();
+
+    /*
+     * Implemented in subclasses to release all the platform
+     * resources before the application is terminated.
+     *
+     * This method is called on the toolkit thread.
+     */
+    protected abstract void platformCleanup();
+
+    private synchronized int getRunState() {
+        return runState;
+    }
+
+    private synchronized void setRunState(int state) {
+        runState = state;
+        notifyAll();
+    }
+
+    public boolean isTerminating() {
+        return getRunState() >= STATE_SHUTDOWN;
+    }
+
+    private void waitForRunState(int state) {
+        while (getRunState() < state) {
+            try {
+                synchronized (this) {
+                    wait();
+                }
+            } catch (InterruptedException z) {
+                // TODO: log
+                break;
+            }
+        }
+    }
+
+    public void run() {
+        setRunState(STATE_INIT);
+        platformInit();
+        AWTAutoShutdown.notifyToolkitThreadFree();
+        setRunState(STATE_MESSAGELOOP);
+        while (getRunState() < STATE_SHUTDOWN) {
+            try {
+                platformRunMessage();
+                if (Thread.currentThread().isInterrupted()) {
+                    if (AppContext.getAppContext().isDisposed()) {
+                        break;
+                    }
+                }
+            } catch (ThreadDeath td) {
+                //XXX: if there isn't native code on the stack, the VM just
+                //kills the thread right away. Do we expect to catch it
+                //nevertheless?
+                break;
+            } catch (Throwable t) {
+                // TODO: log
+                System.err.println("Exception on the toolkit thread");
+                t.printStackTrace(System.err);
+            }
+        }
+        //XXX: if that's a secondary loop, jump back to the STATE_MESSAGELOOP
+        setRunState(STATE_CLEANUP);
+        AWTAutoShutdown.notifyToolkitThreadFree();
+        platformCleanup();
+        setRunState(STATE_DONE);
+    }
+
+    /*
+     * Process the next message(s) from the native event queue.
+     *
+     * Initially, all the LWToolkit implementations were supposed
+     * to have the similar message loop sequence: check if any events
+     * available, peek events, wait. However, the later analysis shown
+     * that X11 and Windows implementations are really different, so
+     * let the subclasses do whatever they require.
+     */
+    protected abstract void platformRunMessage();
+
+    public static LWToolkit getLWToolkit() {
+        return (LWToolkit)Toolkit.getDefaultToolkit();
+    }
+
+    // ---- TOPLEVEL PEERS ---- //
+
+    /*
+     * Note that LWWindowPeer implements WindowPeer, FramePeer
+     * and DialogPeer interfaces.
+     */
+    private LWWindowPeer createDelegatedPeer(Window target, PlatformComponent platformComponent,
+                                             PlatformWindow platformWindow)
+    {
+        LWWindowPeer peer = new LWWindowPeer(target, platformComponent, platformWindow);
+        targetCreatedPeer(target, peer);
+        targetDelegate(platformWindow, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public WindowPeer createWindow(Window target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.SIMPLEWINDOW);
+        return createDelegatedPeer(target, platformComponent, platformWindow);
+    }
+
+    @Override
+    public FramePeer createFrame(Frame target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.FRAME);
+        return createDelegatedPeer(target, platformComponent, platformWindow);
+    }
+
+
+    CPrinterDialogPeer createCPrinterDialog(CPrinterDialog target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.DIALOG);
+        CPrinterDialogPeer peer = new CPrinterDialogPeer(target, platformComponent, platformWindow);
+        targetCreatedPeer(target, peer);
+        return peer;
+    }
+
+    @Override
+    public DialogPeer createDialog(Dialog target) {
+        if (target instanceof CPrinterDialog) {
+            return createCPrinterDialog((CPrinterDialog)target);
+        }
+
+        PlatformComponent platformComponent = createPlatformComponent();
+        PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.DIALOG);
+        return createDelegatedPeer(target, platformComponent, platformWindow);
+    }
+
+    @Override
+    public FileDialogPeer createFileDialog(FileDialog target) {
+        FileDialogPeer peer = createFileDialogPeer(target);
+        targetCreatedPeer(target, peer);
+        return peer;
+    }
+
+    // ---- LIGHTWEIGHT COMPONENT PEERS ---- //
+
+    @Override
+    public ButtonPeer createButton(Button target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWButtonPeer peer = new LWButtonPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public CheckboxPeer createCheckbox(Checkbox target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWCheckboxPeer peer = new LWCheckboxPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public ChoicePeer createChoice(Choice target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWChoicePeer peer = new LWChoicePeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public LabelPeer createLabel(Label target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWLabelPeer peer = new LWLabelPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public CanvasPeer createCanvas(Canvas target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWCanvasPeer peer = new LWCanvasPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public ListPeer createList(List target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWListPeer peer = new LWListPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public MenuPeer createMenu(Menu target) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public MenuBarPeer createMenuBar(MenuBar target) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public MenuItemPeer createMenuItem(MenuItem target) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public PanelPeer createPanel(Panel target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWPanelPeer peer = new LWPanelPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public PopupMenuPeer createPopupMenu(PopupMenu target) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public ScrollPanePeer createScrollPane(ScrollPane target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWScrollPanePeer peer = new LWScrollPanePeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public ScrollbarPeer createScrollbar(Scrollbar target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWScrollBarPeer peer = new LWScrollBarPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public TextAreaPeer createTextArea(TextArea target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWTextAreaPeer peer = new LWTextAreaPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    @Override
+    public TextFieldPeer createTextField(TextField target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        LWTextFieldPeer peer = new LWTextFieldPeer(target, platformComponent);
+        targetCreatedPeer(target, peer);
+        peer.initialize();
+        return peer;
+    }
+
+    // ---- NON-COMPONENT PEERS ---- //
+
+    @Override
+    public ColorModel getColorModel() throws HeadlessException {
+        return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getColorModel();
+    }
+
+    @Override
+    public boolean isDesktopSupported() {
+        return true;
+    }
+
+    @Override
+    protected DesktopPeer createDesktopPeer(Desktop target) {
+       return new CDesktopPeer();
+    }
+
+    @Override
+    public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) {
+        DragSourceContextPeer dscp = CDragSourceContextPeer.createDragSourceContextPeer(dge);
+
+        return dscp;
+    }
+
+    @Override
+    public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
+        return LWKeyboardFocusManagerPeer.getInstance(manager);
+    }
+
+    @Override
+    public synchronized MouseInfoPeer getMouseInfoPeer() {
+        if (mouseInfoPeer == null) {
+            mouseInfoPeer = createMouseInfoPeerImpl();
+        }
+        return mouseInfoPeer;
+    }
+
+    protected MouseInfoPeer createMouseInfoPeerImpl() {
+        return new LWMouseInfoPeer();
+    }
+
+    public PrintJob getPrintJob(Frame frame, String doctitle, Properties props) {
+        return getPrintJob(frame, doctitle, null, null);
+    }
+
+    public PrintJob getPrintJob(Frame frame, String doctitle, JobAttributes jobAttributes, PageAttributes pageAttributes) {
+        if (GraphicsEnvironment.isHeadless()) {
+            throw new IllegalArgumentException();
+        }
+
+        PrintJob2D printJob = new PrintJob2D(frame, doctitle, jobAttributes, pageAttributes);
+
+        if (printJob.printDialog() == false) {
+            printJob = null;
+        }
+
+        return printJob;
+    }
+
+    @Override
+    public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public boolean isTraySupported() {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public SystemTrayPeer createSystemTray(SystemTray target) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public TrayIconPeer createTrayIcon(TrayIcon target) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public Clipboard getSystemClipboard() {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkSystemClipboardAccess();
+        }
+
+        synchronized (this) {
+            if (clipboard == null) {
+                clipboard = createPlatformClipboard();
+            }
+        }
+        return clipboard;
+    }
+
+    // ---- DELEGATES ---- //
+
+    public abstract Clipboard createPlatformClipboard();
+
+    /*
+     * Creates a delegate for the given peer type (window, frame, dialog, etc.)
+     */
+    protected abstract PlatformWindow createPlatformWindow(LWWindowPeer.PeerType peerType);
+
+    protected abstract PlatformComponent createPlatformComponent();
+
+    protected abstract FileDialogPeer createFileDialogPeer(FileDialog target);
+
+    public static void targetDelegate(PlatformWindow delegate, LWWindowPeer peer) {
+        delegateMap.put(delegate, peer);
+    }
+
+    public static LWWindowPeer delegateToPeer(PlatformWindow delegate) {
+        return delegateMap.get(delegate);
+    }
+
+    // ---- UTILITY METHODS ---- //
+
+    /*
+     * Expose non-public targetToPeer() method.
+     */
+    public final static Object targetToPeer(Object target) {
+        return SunToolkit.targetToPeer(target);
+    }
+
+    /*
+     * Expose non-public targetDisposedPeer() method.
+     */
+    public final static void targetDisposedPeer(Object target, Object peer) {
+        SunToolkit.targetDisposedPeer(target, peer);
+    }
+
+    /*
+     * Returns the current cursor manager.
+     */
+    public abstract LWCursorManager getCursorManager();
+
+    public static void postEvent(AWTEvent event) {
+        postEvent(targetToAppContext(event.getSource()), event);
+    }
+
+    // use peer's back buffer to implement non-opaque windows.
+    @Override
+    public boolean needUpdateWindow() {
+        return true;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
new file mode 100644
index 0000000..db44b2c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
@@ -0,0 +1,1125 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.BufferedImage;
+import java.awt.peer.*;
+import java.util.List;
+
+import javax.swing.*;
+
+import sun.awt.*;
+import sun.java2d.*;
+import sun.java2d.loops.Blit;
+import sun.java2d.loops.CompositeType;
+
+public class LWWindowPeer
+    extends LWContainerPeer<Window, JComponent>
+    implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
+{
+    public static enum PeerType {
+        SIMPLEWINDOW,
+        FRAME,
+        DIALOG,
+        EMBEDDEDFRAME
+    }
+
+    private PlatformWindow platformWindow;
+
+    // Window bounds reported by the native system (as opposed to
+    // regular bounds inherited from LWComponentPeer which are
+    // requested by user and may haven't been applied yet because
+    // of asynchronous requests to the windowing system)
+    private int sysX;
+    private int sysY;
+    private int sysW;
+    private int sysH;
+
+    private static final int MINIMUM_WIDTH = 1;
+    private static final int MINIMUM_HEIGHT = 1;
+
+    private Insets insets = new Insets(0, 0, 0, 0);
+
+    private int screenOn = -1;
+    private GraphicsConfiguration graphicsConfig;
+
+    private SurfaceData surfaceData;
+
+    private int backBufferCount;
+    private BufferCapabilities backBufferCaps;
+
+    // The back buffer is used for two purposes:
+    // 1. To render all the lightweight peers
+    // 2. To provide user with a BufferStrategy
+    // Need to check if a single back buffer can be used for both
+// TODO: VolatileImage
+//    private VolatileImage backBuffer;
+    private volatile BufferedImage backBuffer;
+
+    private volatile int windowState = Frame.NORMAL;
+
+    // A peer where the last mouse event came to. Used to generate
+    // MOUSE_ENTERED/EXITED notifications and by cursor manager to
+    // find the component under cursor
+    private static volatile LWComponentPeer lastMouseEventPeer = null;
+
+    // Peers where all dragged/released events should come to,
+    // depending on what mouse button is being dragged according to Cocoa
+    private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
+
+    private static final int ButtonsDownMask = InputEvent.BUTTON1_DOWN_MASK |
+                                               InputEvent.BUTTON2_DOWN_MASK |
+                                               InputEvent.BUTTON3_DOWN_MASK;
+
+
+    // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
+    // on MOUSE_RELEASE. Click events are only generated if there were no drag
+    // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
+    private static int mouseClickButtons = 0;
+
+    private volatile boolean cachedFocusableWindow;
+
+    private static final Font DEFAULT_FONT = new Font(Font.DIALOG, Font.PLAIN, 12);
+
+    private Color background;
+    private Color foreground;
+    private Font font;
+
+    private volatile boolean isOpaque = true;
+
+    /**
+     * Current modal blocker or null.
+     *
+     * Synchronization: peerTreeLock.
+     */
+    private LWWindowPeer blocker;
+
+    public LWWindowPeer(Window target, PlatformComponent platformComponent,
+                        PlatformWindow platformWindow)
+    {
+        super(target, platformComponent);
+        this.platformWindow = platformWindow;
+
+        Window owner = target.getOwner();
+        LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
+        PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
+
+        // The delegate.initialize() needs a non-null GC on X11.
+        GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
+        synchronized (getStateLock()) {
+            // graphicsConfig should be updated according to the real window
+            // bounds when the window is shown, see 4868278
+            this.graphicsConfig = gc;
+        }
+
+        platformWindow.initialize(target, this, ownerDelegate);
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+
+        updateInsets(platformWindow.getInsets());
+
+        if (getTarget() instanceof Frame) {
+            setTitle(((Frame)getTarget()).getTitle());
+            setState(((Frame)getTarget()).getExtendedState());
+        } else if (getTarget() instanceof Dialog) {
+            setTitle(((Dialog)getTarget()).getTitle());
+        }
+
+        setAlwaysOnTop(getTarget().isAlwaysOnTop());
+        updateMinimumSize();
+
+        cachedFocusableWindow = getTarget().isFocusableWindow();
+
+        setOpacity(getTarget().getOpacity());
+        setOpaque(getTarget().isOpaque());
+
+        // Create surface data and back buffer
+        replaceSurfaceData(1, null);
+    }
+
+    public void setBackground(Color c) {
+        final boolean changed;
+        synchronized (getStateLock()) {
+            changed = ((background != null) ? !background.equals(c) :
+                    ((c != null) && !c.equals(background)));
+                background = c;
+        }
+        if (changed) {
+            repaintPeer();
+        }
+    }
+
+    protected Color getBackground() {
+        synchronized (getStateLock()) {
+            return background;
+        }
+    }
+
+    public void setForeground(Color c) {
+        final boolean changed;
+        synchronized (getStateLock()) {
+            changed = ((foreground != null) ? !foreground.equals(c) :
+                    ((c != null) && !c.equals(foreground)));
+            foreground = c;
+        }
+        if (changed) {
+            repaintPeer();
+        }
+    }
+
+    protected Color getForeground() {
+        synchronized (getStateLock()) {
+            return foreground;
+        }
+    }
+
+    public void setFont(Font f) {
+        final boolean changed;
+        synchronized (getStateLock()) {
+            changed = ((font != null) ? !font.equals(f) :
+                    ((f != null) && !f.equals(font)));
+            font = f;
+        }
+        if (changed) {
+            repaintPeer();
+        }
+    }
+
+    protected Font getFont() {
+        synchronized (getStateLock()) {
+            return font == null ? DEFAULT_FONT : font;
+        }
+    }
+
+    // Just a helper method
+    public PlatformWindow getPlatformWindow() {
+        return platformWindow;
+    }
+
+    @Override
+    protected LWWindowPeer getWindowPeerOrSelf() {
+        return this;
+    }
+
+    @Override
+    protected void initializeContainerPeer() {
+        // No-op as LWWindowPeer doesn't have any containerPeer
+    }
+
+    // ---- PEER METHODS ---- //
+
+    @Override
+    protected void disposeImpl() {
+        SurfaceData oldData = getSurfaceData();
+        surfaceData = null;
+        if (oldData != null) {
+            oldData.invalidate();
+        }
+        platformWindow.dispose();
+        super.disposeImpl();
+    }
+
+    @Override
+    public void setVisible(final boolean v) {
+        if (getSurfaceData() == null) {
+            replaceSurfaceData();
+        }
+
+        if (isVisible() == v) {
+            return;
+        }
+        super.setVisible(v);
+
+        // TODO: update graphicsConfig, see 4868278
+        // TODO: don't notify the delegate if our visibility is unchanged
+
+        // it is important to call this method on EDT
+        // to prevent the deadlocks during the painting of the lightweight delegates
+        //TODO: WHY? This is a native-system related call. Perhaps NOT calling
+        // the painting procedure right from the setVisible(), but rather relying
+        // on the native Expose event (or, scheduling the repainting asynchronously)
+        // is better?
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                platformWindow.setVisible(v);
+                if (isSimpleWindow()) {
+                    updateFocusableWindowState();
+                    changeFocusedWindow(v, v);
+                }
+            }
+        });
+    }
+
+    @Override
+    public GraphicsConfiguration getGraphicsConfiguration() {
+        return graphicsConfig;
+    }
+
+    @Override
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        setGraphicsConfig(gc);
+        return false;
+    }
+
+    protected final synchronized Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
+        if (getSurfaceData() == null) {
+            return null;
+        }
+        if (fg == null) {
+            fg = SystemColor.windowText;
+        }
+        if (bg == null) {
+            bg = SystemColor.window;
+        }
+        if (f == null) {
+            f = DEFAULT_FONT;
+        }
+        return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
+    }
+
+    @Override
+    public void createBuffers(int numBuffers, BufferCapabilities caps)
+        throws AWTException
+    {
+        try {
+            // Assume this method is never called with numBuffers <= 1, as 0 is
+            // unsupported, and 1 corresponds to a SingleBufferStrategy which
+            // doesn't depend on the peer. Screen is considered as a separate
+            // "buffer", that's why numBuffers - 1
+            assert numBuffers > 1;
+
+            replaceSurfaceData(numBuffers - 1, caps);
+        } catch (InvalidPipeException z) {
+            throw new AWTException(z.toString());
+        }
+    }
+
+    @Override
+    public Image getBackBuffer() {
+        return backBuffer;
+    }
+
+    @Override
+    public void flip(int x1, int y1, int x2, int y2,
+                     BufferCapabilities.FlipContents flipAction)
+    {
+        platformWindow.flip(x1, y1, x2, y2, flipAction);
+    }
+
+    @Override
+    public void destroyBuffers() {
+        replaceSurfaceData(1, null);
+    }
+
+    @Override
+    public void setBounds(int x, int y, int w, int h, int op) {
+        if ((op & SET_CLIENT_SIZE) != 0) {
+            // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
+            // instead of pulling 'insets' field up to LWComponentPeer
+            // no need to add insets since Window's notion of width and height includes insets.
+            op &= ~SET_CLIENT_SIZE;
+            op |= SET_SIZE;
+        }
+
+        if (w < MINIMUM_WIDTH) {
+            w = MINIMUM_WIDTH;
+        }
+        if (h < MINIMUM_HEIGHT) {
+            h = MINIMUM_HEIGHT;
+        }
+
+        // Don't post ComponentMoved/Resized and Paint events
+        // until we've got a notification from the delegate
+        setBounds(x, y, w, h, op, false, false);
+        // Get updated bounds, so we don't have to handle 'op' here manually
+        Rectangle r = getBounds();
+        platformWindow.setBounds(r.x, r.y, r.width, r.height);
+    }
+
+    @Override
+    public Point getLocationOnScreen() {
+        return platformWindow.getLocationOnScreen();
+    }
+
+    /**
+     * Overridden from LWContainerPeer to return the correct insets.
+     * Insets are queried from the delegate and are kept up to date by
+     * requiering when needed (i.e. when the window geometry is changed).
+     */
+    @Override
+    public Insets getInsets() {
+        synchronized (getStateLock()) {
+            return insets;
+        }
+    }
+
+    @Override
+    public FontMetrics getFontMetrics(Font f) {
+        // TODO: check for "use platform metrics" settings
+        return platformWindow.getFontMetrics(f);
+    }
+
+    @Override
+    public void toFront() {
+        platformWindow.toFront();
+    }
+
+    @Override
+    public void toBack() {
+        platformWindow.toBack();
+    }
+
+    @Override
+    public void setZOrder(ComponentPeer above) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public void setAlwaysOnTop(boolean value) {
+        platformWindow.setAlwaysOnTop(value);
+    }
+
+    @Override
+    public void updateFocusableWindowState() {
+        cachedFocusableWindow = getTarget().isFocusableWindow();
+        platformWindow.updateFocusableWindowState();
+    }
+
+    @Override
+    public void setModalBlocked(Dialog blocker, boolean blocked) {
+        synchronized (getPeerTreeLock()) {
+            this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
+        }
+    }
+
+    @Override
+    public void updateMinimumSize() {
+        Dimension d = null;
+        if (getTarget().isMinimumSizeSet()) {
+            d = getTarget().getMinimumSize();
+        }
+        if (d == null) {
+            d = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
+        }
+        platformWindow.setMinimumSize(d.width, d.height);
+    }
+
+    @Override
+    public void updateIconImages() {
+        getPlatformWindow().updateIconImages();
+    }
+
+    @Override
+    public void setOpacity(float opacity) {
+        getPlatformWindow().setOpacity(opacity);
+    }
+
+    @Override
+    public void setOpaque(boolean isOpaque) {
+        if (this.isOpaque != isOpaque) {
+            this.isOpaque = isOpaque;
+            getPlatformWindow().setOpaque(isOpaque);
+            replaceSurfaceData();
+        }
+    }
+
+    public boolean isOpaque() {
+        return isOpaque;
+    }
+
+    @Override
+    public void updateWindow() {
+        flushOffscreenGraphics();
+    }
+
+    @Override
+    public void repositionSecurityWarning() {
+        throw new RuntimeException("not implemented");
+    }
+
+    // ---- FRAME PEER METHODS ---- //
+
+    @Override // FramePeer and DialogPeer
+    public void setTitle(String title) {
+        platformWindow.setTitle(title == null ? "" : title);
+    }
+
+    @Override
+    public void setMenuBar(MenuBar mb) {
+         platformWindow.setMenuBar(mb);
+    }
+
+    @Override // FramePeer and DialogPeer
+    public void setResizable(boolean resizable) {
+        platformWindow.setResizable(resizable);
+    }
+
+    @Override
+    public void setState(int state) {
+        platformWindow.setWindowState(state);
+    }
+
+    @Override
+    public int getState() {
+        return windowState;
+    }
+
+    @Override
+    public void setMaximizedBounds(Rectangle bounds) {
+        // TODO: not implemented
+    }
+
+    @Override
+    public void setBoundsPrivate(int x, int y, int width, int height) {
+        throw new RuntimeException("not implemented");
+    }
+
+    @Override
+    public Rectangle getBoundsPrivate() {
+        throw new RuntimeException("not implemented");
+    }
+
+    // ---- DIALOG PEER METHODS ---- //
+
+    @Override
+    public void blockWindows(List<Window> windows) {
+        //TODO: LWX will probably need some collectJavaToplevels to speed this up
+        for (Window w : windows) {
+            WindowPeer wp = (WindowPeer)w.getPeer();
+            if (wp != null) {
+                wp.setModalBlocked((Dialog)getTarget(), true);
+            }
+        }
+    }
+
+    // ---- PEER NOTIFICATIONS ---- //
+
+    public void notifyIconify(boolean iconify) {
+        //The toplevel target is Frame and states are applicable to it.
+        //Otherwise, the target is Window and it don't have state property.
+        //Hopefully, no such events are posted in the queue so consider the
+        //target as Frame in all cases.
+
+        // REMIND: should we send it anyway if the state not changed since last
+        // time?
+        WindowEvent iconifyEvent = new WindowEvent(getTarget(),
+                iconify ? WindowEvent.WINDOW_ICONIFIED
+                        : WindowEvent.WINDOW_DEICONIFIED);
+        postEvent(iconifyEvent);
+
+        int newWindowState = iconify ? Frame.ICONIFIED : Frame.NORMAL;
+        postWindowStateChangedEvent(newWindowState);
+
+        // REMIND: RepaintManager doesn't repaint iconified windows and
+        // hence ignores any repaint request during deiconification.
+        // So, we need to repaint window explicitly when it becomes normal.
+        if (!iconify) {
+            repaintPeer();
+        }
+    }
+
+    public void notifyZoom(boolean isZoomed) {
+        int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL;
+        postWindowStateChangedEvent(newWindowState);
+    }
+
+    /**
+     * Called by the delegate when any part of the window should be repainted.
+     */
+    public void notifyExpose(final int x, final int y, final int w, final int h) {
+        // TODO: there's a serious problem with Swing here: it handles
+        // the exposition internally, so SwingPaintEventDispatcher always
+        // return null from createPaintEvent(). However, we flush the
+        // back buffer here unconditionally, so some flickering may appear.
+        // A possible solution is to split postPaintEvent() into two parts,
+        // and override that part which is only called after if
+        // createPaintEvent() returned non-null value and flush the buffer
+        // from the overridden method
+        flushOnscreenGraphics();
+        repaintPeer(new Rectangle(x, y, w, h));
+    }
+
+    /**
+     * Called by the delegate when this window is moved/resized by user.
+     * There's no notifyReshape() in LWComponentPeer as the only
+     * components which could be resized by user are top-level windows.
+     */
+    public final void notifyReshape(int x, int y, int w, int h) {
+        boolean moved = false;
+        boolean resized = false;
+        synchronized (getStateLock()) {
+            moved = (x != sysX) || (y != sysY);
+            resized = (w != sysW) || (h != sysH);
+            sysX = x;
+            sysY = y;
+            sysW = w;
+            sysH = h;
+        }
+
+        // Check if anything changed
+        if (!moved && !resized) {
+            return;
+        }
+        // First, update peer's bounds
+        setBounds(x, y, w, h, SET_BOUNDS, false, false);
+
+        // Second, update the graphics config and surface data
+        checkIfOnNewScreen();
+        if (resized) {
+            replaceSurfaceData();
+            flushOnscreenGraphics();
+        }
+
+        // Third, COMPONENT_MOVED/COMPONENT_RESIZED events
+        if (moved) {
+            handleMove(x, y, true);
+        }
+        if (resized) {
+            handleResize(w, h,true);
+        }
+    }
+
+    private void clearBackground(final int w, final int h) {
+        final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
+                                               getFont());
+        if (g != null) {
+            try {
+                g.clearRect(0, 0, w, h);
+            } finally {
+                g.dispose();
+            }
+        }
+    }
+
+    public void notifyUpdateCursor() {
+        getLWToolkit().getCursorManager().updateCursorLater(this);
+    }
+
+    public void notifyActivation(boolean activation) {
+        changeFocusedWindow(activation, false);
+    }
+
+    // ---- EVENTS ---- //
+
+    /*
+     * Called by the delegate to dispatch the event to Java. Event
+     * coordinates are relative to non-client window are, i.e. the top-left
+     * point of the client area is (insets.top, insets.left).
+     */
+    public void dispatchMouseEvent(int id, long when, int button,
+                                   int x, int y, int screenX, int screenY,
+                                   int modifiers, int clickCount, boolean popupTrigger,
+                                   byte[] bdata)
+    {
+        // TODO: fill "bdata" member of AWTEvent
+        Rectangle r = getBounds();
+        // findPeerAt() expects parent coordinates
+        LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
+        LWWindowPeer lastWindowPeer =
+            (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
+        LWWindowPeer curWindowPeer =
+            (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null;
+
+        if (id == MouseEvent.MOUSE_EXITED) {
+            // Sometimes we may get MOUSE_EXITED after lastMouseEventPeer is switched
+            // to a peer from another window. So we must first check if this peer is
+            // the same as lastWindowPeer
+            if (lastWindowPeer == this) {
+                if (isEnabled()) {
+                    Point lp = lastMouseEventPeer.windowToLocal(x, y,
+                                                                lastWindowPeer);
+                    postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
+                                             MouseEvent.MOUSE_EXITED, when,
+                                             modifiers, lp.x, lp.y, screenX,
+                                             screenY, clickCount, popupTrigger,
+                                             button));
+                }
+                lastMouseEventPeer = null;
+            }
+        } else {
+            if (targetPeer != lastMouseEventPeer) {
+                // lastMouseEventPeer may be null if mouse was out of Java windows
+                if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
+                    // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
+                    // later), in which case lastWindowPeer is another window
+                    if (lastWindowPeer != this) {
+                        Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
+                        // Additionally translate from this to lastWindowPeer coordinates
+                        Rectangle lr = lastWindowPeer.getBounds();
+                        oldp.x += r.x - lr.x;
+                        oldp.y += r.y - lr.y;
+                        postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
+                                                 MouseEvent.MOUSE_EXITED,
+                                                 when, modifiers,
+                                                 oldp.x, oldp.y, screenX, screenY,
+                                                 clickCount, popupTrigger, button));
+                    } else {
+                        Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
+                        postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
+                                                 MouseEvent.MOUSE_EXITED,
+                                                 when, modifiers,
+                                                 oldp.x, oldp.y, screenX, screenY,
+                                                 clickCount, popupTrigger, button));
+                    }
+                }
+                lastMouseEventPeer = targetPeer;
+                if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
+                    Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);
+                    postEvent(new MouseEvent(targetPeer.getTarget(),
+                                             MouseEvent.MOUSE_ENTERED,
+                                             when, modifiers,
+                                             newp.x, newp.y, screenX, screenY,
+                                             clickCount, popupTrigger, button));
+                }
+            }
+            // TODO: fill "bdata" member of AWTEvent
+
+            // For pressed/dragged/released events JDK 1.6 treats other
+            // mouse buttons as if they were BUTTON2, so we do the same
+            int eventButtonMask = (button == 0) ? MouseEvent.BUTTON2_DOWN_MASK :
+                                                  MouseEvent.getMaskForButton(button);
+            int mouseButtonsPressed = modifiers & ButtonsDownMask;
+            int otherButtonsPressed = mouseButtonsPressed & ~eventButtonMask;
+            int targetIdx = (button == 0) ? MouseEvent.BUTTON2 - 1 : button - 1;
+
+            // MOUSE_ENTERED/EXITED are generated for the components strictly under
+            // mouse even when dragging. That's why we first update lastMouseEventPeer
+            // based on initial targetPeer value and only then recalculate targetPeer
+            // for MOUSE_DRAGGED/RELEASED events
+            if (id == MouseEvent.MOUSE_PRESSED) {
+                changeFocusedWindow(true, false);
+
+                if (otherButtonsPressed == 0) {
+                    mouseClickButtons = eventButtonMask;
+                } else {
+                    mouseClickButtons |= eventButtonMask;
+                }
+
+                mouseDownTarget[targetIdx] = targetPeer;
+            } else if (id == MouseEvent.MOUSE_DRAGGED) {
+                // Cocoa dragged event has the information about which mouse
+                // button is being dragged. Use it to determine the peer that
+                // should receive the dragged event.
+                targetPeer = mouseDownTarget[targetIdx];
+                mouseClickButtons &= ~mouseButtonsPressed;
+            } else if (id == MouseEvent.MOUSE_RELEASED) {
+                // TODO: currently, mouse released event goes to the same component
+                // that received corresponding mouse pressed event. For most cases,
+                // it's OK, however, we need to make sure that our behavior is consistent
+                // with 1.6 for cases where component in question have been
+                // hidden/removed in between of mouse pressed/released events.
+                targetPeer = mouseDownTarget[targetIdx];
+
+                if ((mouseButtonsPressed & eventButtonMask) == 0) {
+                    mouseDownTarget[targetIdx] = null;
+                }
+
+                // mouseClickButtons is updated below, after MOUSE_CLICK is sent
+            }
+
+            // check if we receive mouseEvent from outside the window's bounds
+            // it can be either mouseDragged or mouseReleased
+            if (curWindowPeer == null) {
+                //TODO This can happen if this window is invisible. this is correct behavior in this case?
+                curWindowPeer = this;
+            }
+            if (targetPeer == null) {
+                //TODO This can happen if this window is invisible. this is correct behavior in this case?
+                targetPeer = this;
+            }
+
+
+            Point lp = targetPeer.windowToLocal(x, y, curWindowPeer);
+            if (targetPeer.isEnabled()) {
+                MouseEvent event = new MouseEvent(targetPeer.getTarget(), id,
+                                                  when, modifiers, lp.x, lp.y,
+                                                  screenX, screenY, clickCount,
+                                                  popupTrigger, button);
+                postEvent(event);
+            }
+
+            if (id == MouseEvent.MOUSE_RELEASED) {
+                if ((mouseClickButtons & eventButtonMask) != 0
+                    && targetPeer.isEnabled()) {
+                    postEvent(new MouseEvent(targetPeer.getTarget(),
+                                             MouseEvent.MOUSE_CLICKED,
+                                             when, modifiers,
+                                             lp.x, lp.y, screenX, screenY,
+                                             clickCount, popupTrigger, button));
+                }
+                mouseClickButtons &= ~eventButtonMask;
+            }
+
+            notifyUpdateCursor();
+        }
+    }
+
+    public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
+                                        int scrollType, int scrollAmount,
+                                        int wheelRotation, double preciseWheelRotation,
+                                        byte[] bdata)
+    {
+        // TODO: could we just use the last mouse event target here?
+        Rectangle r = getBounds();
+        // findPeerAt() expects parent coordinates
+        final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
+        if (targetPeer == null || !targetPeer.isEnabled()) {
+            return;
+        }
+
+        Point lp = targetPeer.windowToLocal(x, y, this);
+        // TODO: fill "bdata" member of AWTEvent
+        // TODO: screenX/screenY
+        postEvent(new MouseWheelEvent(targetPeer.getTarget(),
+                                      MouseEvent.MOUSE_WHEEL,
+                                      when, modifiers,
+                                      lp.x, lp.y,
+                                      0, 0, /* screenX, Y */
+                                      0 /* clickCount */, false /* popupTrigger */,
+                                      scrollType, scrollAmount,
+                                      wheelRotation, preciseWheelRotation));
+    }
+
+    /*
+     * Called by the delegate when a key is pressed.
+     */
+    public void dispatchKeyEvent(int id, long when, int modifiers,
+                                 int keyCode, char keyChar, int keyLocation)
+    {
+        LWComponentPeer focusOwner =
+            LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
+                getFocusOwner();
+
+        // Null focus owner may receive key event when
+        // application hides the focused window upon ESC press
+        // (AWT transfers/clears the focus owner) and pending ESC release
+        // may come to already hidden window. This check eliminates NPE.
+        if (focusOwner != null) {
+            KeyEvent event =
+                new KeyEvent(focusOwner.getTarget(), id, when, modifiers,
+                             keyCode, keyChar, keyLocation);
+            focusOwner.postEvent(event);
+        }
+    }
+
+
+    // ---- UTILITY METHODS ---- //
+
+    private void postWindowStateChangedEvent(int newWindowState) {
+        if (getTarget() instanceof Frame) {
+            AWTAccessor.getFrameAccessor().setExtendedState(
+                    (Frame)getTarget(), newWindowState);
+        }
+        WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
+                WindowEvent.WINDOW_STATE_CHANGED,
+                windowState, newWindowState);
+        postEvent(stateChangedEvent);
+        windowState = newWindowState;
+    }
+
+    private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
+        // TODO: this method can be implemented in a more
+        // efficient way by forwarding to the delegate
+        GraphicsDevice gd = gc.getDevice();
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        GraphicsDevice[] gds = ge.getScreenDevices();
+        for (int i = 0; i < gds.length; i++) {
+            if (gds[i] == gd) {
+                return i;
+            }
+        }
+        // Should never happen if gc is a screen device config
+        return 0;
+    }
+
+    private static GraphicsConfiguration getScreenGraphicsConfig(int screen) {
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        GraphicsDevice[] gds = ge.getScreenDevices();
+        if (screen >= gds.length) {
+            // This could happen during device addition/removal. Use
+            // the default screen device in this case
+            return ge.getDefaultScreenDevice().getDefaultConfiguration();
+        }
+        return gds[screen].getDefaultConfiguration();
+    }
+
+    /*
+     * This method is called when window's graphics config is changed from
+     * the app code (e.g. when the window is made non-opaque) or when
+     * the window is moved to another screen by user.
+     *
+     * Returns true if the graphics config has been changed, false otherwise.
+     */
+    private boolean setGraphicsConfig(GraphicsConfiguration gc) {
+        synchronized (getStateLock()) {
+            if (graphicsConfig == gc) {
+                return false;
+            }
+            // If window's graphics config is changed from the app code, the
+            // config correspond to the same device as before; when the window
+            // is moved by user, screenOn is updated in checkIfOnNewScreen().
+            // In either case, there's nothing to do with screenOn here
+            graphicsConfig = gc;
+        }
+        // SurfaceData is replaced later in updateGraphicsData()
+        return true;
+    }
+
+    private void checkIfOnNewScreen() {
+        int windowScreen = platformWindow.getScreenImOn();
+        synchronized (getStateLock()) {
+            if (windowScreen == screenOn) {
+                return;
+            }
+            screenOn = windowScreen;
+        }
+
+        // TODO: DisplayChangedListener stuff
+        final GraphicsConfiguration newGC = getScreenGraphicsConfig(windowScreen);
+        if (!setGraphicsConfig(newGC)) return;
+
+        SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
+            public void run() {
+                AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
+            }
+        });
+    }
+
+    /**
+     * This method returns a back buffer Graphics to render all the
+     * peers to. After the peer is painted, the back buffer contents
+     * should be flushed to the screen. All the target painting
+     * (Component.paint() method) should be done directly to the screen.
+     */
+    protected final Graphics getOffscreenGraphics(Color fg, Color bg, Font f) {
+        final Image bb = getBackBuffer();
+        if (bb == null) {
+            return null;
+        }
+        if (fg == null) {
+            fg = SystemColor.windowText;
+        }
+        if (bg == null) {
+            bg = SystemColor.window;
+        }
+        if (f == null) {
+            f = DEFAULT_FONT;
+        }
+        final Graphics2D g = (Graphics2D) bb.getGraphics();
+        if (g != null) {
+            g.setColor(fg);
+            g.setBackground(bg);
+            g.setFont(f);
+        }
+        return g;
+    }
+
+    /*
+     * May be called by delegate to provide SD to Java2D code.
+     */
+    public synchronized SurfaceData getSurfaceData() {
+        //TODO: synchronize access to the surfaceData.
+        return surfaceData;
+    }
+
+    private void replaceSurfaceData() {
+        replaceSurfaceData(backBufferCount, backBufferCaps);
+    }
+
+    private synchronized void replaceSurfaceData(int newBackBufferCount,
+                                                 BufferCapabilities newBackBufferCaps) {
+        // TODO: need some kind of synchronization here?
+        final SurfaceData oldData = getSurfaceData();
+        surfaceData = platformWindow.replaceSurfaceData();
+        // TODO: volatile image
+//        VolatileImage oldBB = backBuffer;
+        BufferedImage oldBB = backBuffer;
+        backBufferCount = newBackBufferCount;
+        backBufferCaps = newBackBufferCaps;
+        final Rectangle size = getSize();
+        if (getSurfaceData() != null && oldData != getSurfaceData()) {
+            clearBackground(size.width, size.height);
+        }
+        blitSurfaceData(oldData, getSurfaceData());
+
+        if (oldData != null && oldData != getSurfaceData()) {
+            // TODO: drop oldData for D3D/WGL pipelines
+            // This can only happen when this peer is being created
+            oldData.flush();
+        }
+
+        // TODO: volatile image
+//        backBuffer = (VolatileImage)delegate.createBackBuffer();
+        backBuffer = (BufferedImage) platformWindow.createBackBuffer();
+        if (backBuffer != null) {
+            Graphics g = backBuffer.getGraphics();
+            try {
+                Rectangle r = getBounds();
+                g.setColor(getBackground());
+                g.fillRect(0, 0, r.width, r.height);
+                if (oldBB != null) {
+                    // Draw the old back buffer to the new one
+                    g.drawImage(oldBB, 0, 0, null);
+                    oldBB.flush();
+                }
+            } finally {
+                g.dispose();
+            }
+        }
+    }
+
+    private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
+        //TODO blit. proof-of-concept
+        if (src != dst && src != null && dst != null
+            && !(dst instanceof NullSurfaceData)
+            && !(src instanceof NullSurfaceData)
+            && src.getSurfaceType().equals(dst.getSurfaceType())) {
+            final Rectangle size = getSize();
+            final Blit blit = Blit.locate(src.getSurfaceType(),
+                                          CompositeType.Src,
+                                          dst.getSurfaceType());
+            if (blit != null) {
+                blit.Blit(src, dst, ((Graphics2D) getGraphics()).getComposite(),
+                          getRegion(), 0, 0, 0, 0, size.width, size.height);
+            }
+        }
+    }
+
+    public int getBackBufferCount() {
+        return backBufferCount;
+    }
+
+    public BufferCapabilities getBackBufferCaps() {
+        return backBufferCaps;
+    }
+
+    /*
+     * Request the window insets from the delegate and compares it
+     * with the current one. This method is mostly called by the
+     * delegate, e.g. when the window state is changed and insets
+     * should be recalculated.
+     *
+     * This method may be called on the toolkit thread.
+     */
+    public boolean updateInsets(Insets newInsets) {
+        boolean changed = false;
+        synchronized (getStateLock()) {
+            changed = (insets.equals(newInsets));
+            insets = newInsets;
+        }
+
+        if (changed) {
+            replaceSurfaceData();
+        }
+
+        return changed;
+    }
+
+    public static LWWindowPeer getWindowUnderCursor() {
+        return lastMouseEventPeer != null ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
+    }
+
+    public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
+        if (!focusAllowedFor()) {
+            return false;
+        }
+        return platformWindow.requestWindowFocus(cause == CausedFocusEvent.Cause.MOUSE_EVENT);
+    }
+
+    private boolean focusAllowedFor() {
+        Window window = getTarget();
+        // TODO: check if modal blocked
+        return window.isVisible() && window.isEnabled() && window.isFocusableWindow();
+    }
+
+    public boolean isSimpleWindow() {
+        Window window = getTarget();
+        return !(window instanceof Dialog || window instanceof Frame);
+    }
+
+    /*
+     * "Delegates" the responsibility of managing focus to keyboard focus manager.
+     */
+    private void changeFocusedWindow(boolean becomesFocused, boolean isShowing) {
+        if (isShowing && !getTarget().isAutoRequestFocus()) {
+            return;
+        }
+
+        if (!cachedFocusableWindow) {
+            return;
+        }
+        if (becomesFocused) {
+            synchronized (getPeerTreeLock()) {
+                if (blocker != null) {
+                    return;
+                }
+            }
+        }
+
+        LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
+            getInstance(getAppContext());
+
+        Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
+        // TODO: ungrab
+        manager.setFocusedWindow(becomesFocused ? LWWindowPeer.this : null);
+
+        int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
+        WindowEvent windowEvent = new WindowEvent(getTarget(), eventID, oppositeWindow);
+
+        // TODO: wrap in SequencedEvent
+        postEvent(windowEvent);
+    }
+
+    /**
+     * Returns the foremost modal blocker of this window, or null.
+     */
+    public LWWindowPeer getBlocker() {
+        synchronized (getPeerTreeLock()) {
+            LWWindowPeer blocker = this.blocker;
+            if (blocker == null) {
+                return null;
+            }
+            while (blocker.blocker != null) {
+                blocker = blocker.blocker;
+            }
+            return blocker;
+        }
+    }
+
+    public void enterFullScreenMode() {
+        platformWindow.enterFullScreenMode();
+    }
+
+    public void exitFullScreenMode() {
+        platformWindow.exitFullScreenMode();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/PlatformComponent.java b/jdk/src/macosx/classes/sun/lwawt/PlatformComponent.java
new file mode 100644
index 0000000..e791e0d
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformComponent.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.Component;
+
+public interface PlatformComponent {
+
+    public void initialize(Component target, LWComponentPeer peer, PlatformWindow platformWindow);
+
+    public void setBounds(int x, int y, int w, int h);
+
+    public void dispose();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java
new file mode 100644
index 0000000..4f8f951
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+import java.awt.*;
+
+import sun.java2d.SurfaceData;
+
+// TODO Is it worth to generify this interface, like that:
+//
+// public interface PlatformWindow<WindowType extends Window>
+//
+// ?
+
+public interface PlatformWindow {
+
+    /*
+     * Delegate initialization (create native window and all the
+     * related resources).
+     */
+    public void initialize(Window target, LWWindowPeer peer, PlatformWindow owner);
+
+    /*
+     * Delegate shutdown (dispose native window and all the
+     * related resources).
+     */
+    public void dispose();
+
+    /*
+     * Shows or hides the window.
+     */
+    public void setVisible(boolean visible);
+
+    /*
+     * Sets the window title
+     */
+    public void setTitle(String title);
+
+    /*
+     * Sets the window bounds. Called when user changes window bounds
+     * with setSize/setLocation/setBounds/reshape methods.
+     */
+    public void setBounds(int x, int y, int w, int h);
+
+    /*
+     * Returns the screen number where the window is.
+     */
+    public int getScreenImOn();
+
+    /*
+     * Returns the location of the window.
+     */
+    public Point getLocationOnScreen();
+
+    /*
+     * Returns the window insets.
+     */
+    public Insets getInsets();
+
+    /*
+     * Returns the metrics for a given font.
+     */
+    public FontMetrics getFontMetrics(Font f);
+
+    /*
+     * Get the SurfaceData for the window.
+     */
+    public SurfaceData getScreenSurface();
+
+    /*
+     * Revalidates the window's current SurfaceData and returns
+     * the newly created one.
+     */
+    public SurfaceData replaceSurfaceData();
+
+    /*
+     * Creates a new image to serve as a back buffer.
+     */
+    public Image createBackBuffer();
+
+    /*
+     * Move the given part of the back buffer to the front buffer.
+     */
+    public void flip(int x1, int y1, int x2, int y2,
+                     BufferCapabilities.FlipContents flipAction);
+
+    public void toFront();
+
+    public void toBack();
+
+    public void setMenuBar(MenuBar mb);
+
+    public void setAlwaysOnTop(boolean value);
+
+    public void updateFocusableWindowState();
+
+    public boolean requestWindowFocus(boolean isMouseEventCause);
+
+    public void setResizable(boolean resizable);
+
+    public void setMinimumSize(int width, int height);
+
+    /**
+     * Transforms the given Graphics object according to the native
+     * implementation traits (insets, etc.).
+     */
+    public Graphics transformGraphics(Graphics g);
+
+    /*
+     * Installs the images for particular window.
+     */
+    public void updateIconImages();
+
+    public void setOpacity(float opacity);
+
+    public void setOpaque(boolean isOpaque);
+
+    public void enterFullScreenMode();
+
+    public void exitFullScreenMode();
+
+    public void setWindowState(int windowState);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/SelectionClearListener.java b/jdk/src/macosx/classes/sun/lwawt/SelectionClearListener.java
new file mode 100644
index 0000000..4b37848
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/SelectionClearListener.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+/*
+ * Every time the TextField (or TextArea) change selection, every other text components
+ * must immediately clear their selections.
+ */
+interface SelectionClearListener {
+   void clearSelection();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessibility.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessibility.java
new file mode 100644
index 0000000..a1d535e
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessibility.java
@@ -0,0 +1,665 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.beans.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedAction;
+import java.util.*;
+import java.util.concurrent.Callable;
+
+import javax.accessibility.*;
+import javax.swing.*;
+
+class CAccessibility implements PropertyChangeListener {
+    private static Set<String> ignoredRoles;
+
+    static {
+        // Need to load the native library for this code.
+        java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("awt"));
+    }
+
+    static CAccessibility sAccessibility;
+    static synchronized CAccessibility getAccessibility(final String[] roles) {
+        if (sAccessibility != null) return sAccessibility;
+        sAccessibility = new CAccessibility();
+
+        if (roles != null) {
+            ignoredRoles = new HashSet<String>(roles.length);
+            for (final String role : roles) ignoredRoles.add(role);
+        } else {
+            ignoredRoles = new HashSet<String>();
+        }
+
+        return sAccessibility;
+    }
+
+    private CAccessibility() {
+        KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", this);
+    }
+
+    public void propertyChange(final PropertyChangeEvent evt) {
+        if (evt.getNewValue() == null) return;
+        focusChanged();
+    }
+
+    private native void focusChanged();
+
+    static <T> T invokeAndWait(final Callable<T> callable, final Component c) {
+        try {
+            return LWCToolkit.invokeAndWait(callable, c);
+        } catch (final Exception e) { e.printStackTrace(); }
+        return null;
+    }
+
+    static void invokeLater(final Runnable runnable, final Component c) {
+        try {
+            LWCToolkit.invokeLater(runnable, c);
+        } catch (InvocationTargetException e) { e.printStackTrace(); }
+    }
+
+    public static String getAccessibleActionDescription(final AccessibleAction aa, final int index, final Component c) {
+        if (aa == null) return null;
+
+        return invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                return aa.getAccessibleActionDescription(index);
+            }
+        }, c);
+    }
+
+    public static void doAccessibleAction(final AccessibleAction aa, final int index, final Component c) {
+        // We make this an invokeLater because we don't need a reply.
+        if (aa == null) return;
+
+        invokeLater(new Runnable() {
+            public void run() {
+                aa.doAccessibleAction(index);
+            }
+        }, c);
+    }
+
+    public static Dimension getSize(final AccessibleComponent ac, final Component c) {
+        if (ac == null) return null;
+
+        return invokeAndWait(new Callable<Dimension>() {
+            public Dimension call() throws Exception {
+                return ac.getSize();
+            }
+        }, c);
+    }
+
+    public static AccessibleSelection getAccessibleSelection(final AccessibleContext ac, final Component c) {
+        if (ac == null) return null;
+
+        return invokeAndWait(new Callable<AccessibleSelection>() {
+            public AccessibleSelection call() throws Exception {
+                return ac.getAccessibleSelection();
+            }
+        }, c);
+    }
+
+    public static Accessible ax_getAccessibleSelection(final AccessibleContext ac, final int index, final Component c) {
+        if (ac == null) return null;
+
+        return invokeAndWait(new Callable<Accessible>() {
+            public Accessible call() throws Exception {
+                final AccessibleSelection as = ac.getAccessibleSelection();
+                if (as == null) return null;
+                return as.getAccessibleSelection(index);
+            }
+        }, c);
+    }
+
+    // KCH - can we make this a postEvent?
+    public static void addAccessibleSelection(final AccessibleContext ac, final int index, final Component c) {
+        if (ac == null) return;
+
+        invokeLater(new Runnable() {
+            public void run() {
+                final AccessibleSelection as = ac.getAccessibleSelection();
+                if (as == null) return;
+                as.addAccessibleSelection(index);
+            }
+        }, c);
+    }
+
+    public static AccessibleContext getAccessibleContext(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<AccessibleContext>() {
+            public AccessibleContext call() throws Exception {
+                return a.getAccessibleContext();
+            }
+        }, c);
+    }
+
+    public static boolean isAccessibleChildSelected(final Accessible a, final int index, final Component c) {
+        if (a == null) return false;
+
+        return invokeAndWait(new Callable<Boolean>() {
+            public Boolean call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return Boolean.FALSE;
+
+                final AccessibleSelection as = ac.getAccessibleSelection();
+                if (as == null) return Boolean.FALSE;
+
+                return new Boolean(as.isAccessibleChildSelected(index));
+            }
+        }, c);
+    }
+
+    public static AccessibleStateSet getAccessibleStateSet(final AccessibleContext ac, final Component c) {
+        if (ac == null) return null;
+
+        return invokeAndWait(new Callable<AccessibleStateSet>() {
+            public AccessibleStateSet call() throws Exception {
+                return ac.getAccessibleStateSet();
+            }
+        }, c);
+    }
+
+    public static boolean contains(final AccessibleContext ac, final AccessibleState as, final Component c) {
+        if (ac == null || as == null) return false;
+
+        return invokeAndWait(new Callable<Boolean>() {
+            public Boolean call() throws Exception {
+                final AccessibleStateSet ass = ac.getAccessibleStateSet();
+                if (ass == null) return null;
+                return ass.contains(as);
+            }
+        }, c);
+    }
+
+    static Field getAccessibleBundleKeyFieldWithReflection() {
+        try {
+            final Field fieldKey = AccessibleBundle.class.getDeclaredField("key");
+            fieldKey.setAccessible(true);
+            return fieldKey;
+        } catch (final SecurityException e) {
+            e.printStackTrace();
+        } catch (final NoSuchFieldException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+    private static final Field FIELD_KEY = getAccessibleBundleKeyFieldWithReflection();
+
+    static String getAccessibleRoleFor(final Accessible a) {
+        final AccessibleContext ac = a.getAccessibleContext();
+        if (ac == null) return null;
+
+        final AccessibleRole role = ac.getAccessibleRole();
+        try {
+            return (String)FIELD_KEY.get(role);
+        } catch (final IllegalArgumentException e) {
+            e.printStackTrace();
+        } catch (final IllegalAccessException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public static String getAccessibleRole(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                final Accessible sa = CAccessible.getSwingAccessible(a);
+                final String role = getAccessibleRoleFor(a);
+
+                if (!"text".equals(role)) return role;
+                if (sa instanceof JTextArea || sa instanceof JEditorPane) {
+                    return "textarea";
+                }
+                return role;
+            }
+        }, c);
+    }
+
+    public static Point getLocationOnScreen(final AccessibleComponent ac, final Component c) {
+        if (ac == null) return null;
+
+        return invokeAndWait(new Callable<Point>() {
+            public Point call() throws Exception {
+                return ac.getLocationOnScreen();
+            }
+        }, c);
+    }
+
+    public static int getCharCount(final AccessibleText at, final Component c) {
+        if (at == null) return 0;
+
+        return invokeAndWait(new Callable<Integer>() {
+            public Integer call() throws Exception {
+                return at.getCharCount();
+            }
+        }, c);
+    }
+
+    // Accessibility Threadsafety for JavaComponentAccessibility.m
+    public static Accessible getAccessibleParent(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<Accessible>() {
+            public Accessible call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+                return ac.getAccessibleParent();
+            }
+        }, c);
+    }
+
+    public static int getAccessibleIndexInParent(final Accessible a, final Component c) {
+        if (a == null) return 0;
+
+        return invokeAndWait(new Callable<Integer>() {
+            public Integer call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+                return ac.getAccessibleIndexInParent();
+            }
+        }, c);
+    }
+
+    public static AccessibleComponent getAccessibleComponent(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<AccessibleComponent>() {
+            public AccessibleComponent call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+                return ac.getAccessibleComponent();
+            }
+        }, c);
+    }
+
+    public static AccessibleValue getAccessibleValue(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<AccessibleValue>() {
+            public AccessibleValue call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                AccessibleValue accessibleValue = ac.getAccessibleValue();
+                return accessibleValue;
+            }
+        }, c);
+    }
+
+    public static String getAccessibleName(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final String accessibleName = ac.getAccessibleName();
+                if (accessibleName == null) {
+                    return ac.getAccessibleDescription();
+                }
+                return accessibleName;
+            }
+        }, c);
+    }
+
+    public static AccessibleText getAccessibleText(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<AccessibleText>() {
+            public AccessibleText call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                AccessibleText accessibleText = ac.getAccessibleText();
+                return accessibleText;
+            }
+        }, c);
+    }
+
+    public static String getAccessibleDescription(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final String accessibleDescription = ac.getAccessibleDescription();
+                if (accessibleDescription == null) {
+                    if (c instanceof JComponent) {
+                        String toolTipText = ((JComponent)c).getToolTipText();
+                        if (toolTipText != null) {
+                            return toolTipText;
+                        }
+                    }
+                }
+
+                return accessibleDescription;
+            }
+        }, c);
+    }
+
+    public static boolean isFocusTraversable(final Accessible a, final Component c) {
+        if (a == null) return false;
+
+        return invokeAndWait(new Callable<Boolean>() {
+            public Boolean call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final AccessibleComponent aComp = ac.getAccessibleComponent();
+                if (aComp == null) return null;
+
+                return aComp.isFocusTraversable();
+            }
+        }, c);
+    }
+
+    public static Accessible accessibilityHitTest(final Container parent, final float hitPointX, final float hitPointY) {
+        return invokeAndWait(new Callable<Accessible>() {
+            public Accessible call() throws Exception {
+                final Point p = parent.getLocationOnScreen();
+
+                // Make it into local coords
+                final Point localPoint = new Point((int)(hitPointX - p.getX()), (int)(hitPointY - p.getY()));
+
+                final Component component = parent.findComponentAt(localPoint);
+                if (component == null) return null;
+
+                final AccessibleContext axContext = component.getAccessibleContext();
+                if (axContext == null) return null;
+
+                final AccessibleComponent axComponent = axContext.getAccessibleComponent();
+                if (axComponent == null) return null;
+
+                final int numChildren = axContext.getAccessibleChildrenCount();
+                if (numChildren > 0) {
+                    // It has children, check to see which one is hit.
+                    final Point p2 = axComponent.getLocationOnScreen();
+                    final Point localP2 = new Point((int)(hitPointX - p2.getX()), (int)(hitPointY - p2.getY()));
+                    return CAccessible.getCAccessible(axComponent.getAccessibleAt(localP2));
+                }
+
+                if (!(component instanceof Accessible)) return null;
+                return CAccessible.getCAccessible((Accessible)component);
+            }
+        }, parent);
+    }
+
+    public static AccessibleAction getAccessibleAction(final Accessible a, final Component c) {
+        return invokeAndWait(new Callable<AccessibleAction>() {
+            public AccessibleAction call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+                return ac.getAccessibleAction();
+            }
+        }, c);
+    }
+
+    public static boolean isEnabled(final Accessible a, final Component c) {
+        if (a == null) return false;
+
+        return invokeAndWait(new Callable<Boolean>() {
+            public Boolean call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final AccessibleComponent aComp = ac.getAccessibleComponent();
+                if (aComp == null) return null;
+
+                return aComp.isEnabled();
+            }
+        }, c);
+    }
+
+    // KCH - can we make this a postEvent instead?
+    public static void requestFocus(final Accessible a, final Component c) {
+        if (a == null) return;
+
+        invokeLater(new Runnable() {
+            public void run() {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return;
+
+                final AccessibleComponent aComp = ac.getAccessibleComponent();
+                if (aComp == null) return;
+
+                aComp.requestFocus();
+            }
+        }, c);
+    }
+
+    public static Number getMaximumAccessibleValue(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<Number>() {
+            public Number call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final AccessibleValue av = ac.getAccessibleValue();
+                if (av == null) return null;
+
+                return av.getMaximumAccessibleValue();
+            }
+        }, c);
+    }
+
+    public static Number getMinimumAccessibleValue(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<Number>() {
+            public Number call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final AccessibleValue av = ac.getAccessibleValue();
+                if (av == null) return null;
+
+                return av.getMinimumAccessibleValue();
+            }
+        }, c);
+    }
+
+    public static String getAccessibleRoleDisplayString(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final AccessibleRole ar = ac.getAccessibleRole();
+                if (ar == null) return null;
+
+                return ar.toDisplayString();
+            }
+        }, c);
+    }
+
+    public static Number getCurrentAccessibleValue(final AccessibleValue av, final Component c) {
+        if (av == null) return null;
+
+        return invokeAndWait(new Callable<Number>() {
+            public Number call() throws Exception {
+                Number currentAccessibleValue = av.getCurrentAccessibleValue();
+                return currentAccessibleValue;
+            }
+        }, c);
+    }
+
+    public static Accessible getFocusOwner(final Component c) {
+        return invokeAndWait(new Callable<Accessible>() {
+            public Accessible call() throws Exception {
+                Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+                if (c == null || !(c instanceof Accessible)) return null;
+                return CAccessible.getCAccessible((Accessible)c);
+            }
+        }, c);
+    }
+
+    public static boolean[] getInitialAttributeStates(final Accessible a, final Component c) {
+        final boolean[] ret = new boolean[7];
+        if (a == null) return ret;
+
+        return invokeAndWait(new Callable<boolean[]>() {
+            public boolean[] call() throws Exception {
+                final AccessibleContext aContext = a.getAccessibleContext();
+                if (aContext == null) return ret;
+
+                final AccessibleComponent aComponent = aContext.getAccessibleComponent();
+                ret[0] = (aComponent != null);
+                ret[1] = ((aComponent != null) && (aComponent.isFocusTraversable()));
+                ret[2] = (aContext.getAccessibleValue() != null);
+                ret[3] = (aContext.getAccessibleText() != null);
+
+                final AccessibleStateSet aStateSet = aContext.getAccessibleStateSet();
+                ret[4] = (aStateSet.contains(AccessibleState.HORIZONTAL) || aStateSet.contains(AccessibleState.VERTICAL));
+                ret[5] = (aContext.getAccessibleName() != null);
+                ret[6] = (aContext.getAccessibleChildrenCount() > 0);
+                return ret;
+            }
+        }, c);
+    }
+
+    // Duplicated from JavaComponentAccessibility
+    // Note that values >=0 are indexes into the child array
+    final static int JAVA_AX_ALL_CHILDREN = -1;
+    final static int JAVA_AX_SELECTED_CHILDREN = -2;
+    final static int JAVA_AX_VISIBLE_CHILDREN = -3;
+
+    // Each child takes up two entries in the array: one for itself and one for its role
+    public static Object[] getChildrenAndRoles(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored) {
+        if (a == null) return null;
+        return invokeAndWait(new Callable<Object[]>() {
+            public Object[] call() throws Exception {
+                final ArrayList<Object> childrenAndRoles = new ArrayList<Object>();
+                _addChildren(a, whichChildren, allowIgnored, childrenAndRoles);
+
+                if ((whichChildren < 0) || (whichChildren * 2 >= childrenAndRoles.size())) {
+                    return childrenAndRoles.toArray();
+                }
+
+                return new Object[] { childrenAndRoles.get(whichChildren * 2), childrenAndRoles.get((whichChildren * 2) + 1) };
+            }
+        }, c);
+    }
+
+    private static AccessibleRole getAccessibleRoleForLabel(JLabel l, AccessibleRole fallback) {
+        String text = l.getText();
+        if (text != null && text.length() > 0) {
+            return fallback;
+        }
+        Icon icon = l.getIcon();
+        if (icon != null) {
+            return AccessibleRole.ICON;
+        }
+        return fallback;
+    }
+
+    private static AccessibleRole getAccessibleRole(Accessible a) {
+        AccessibleContext ac = a.getAccessibleContext();
+        AccessibleRole role = ac.getAccessibleRole();
+        Object component = CAccessible.getSwingAccessible(a);
+        if (role == null) return null;
+        String roleString = role.toString();
+        if ("label".equals(roleString) && component instanceof JLabel) {
+            return getAccessibleRoleForLabel((JLabel) component, role);
+        }
+        return role;
+    }
+
+
+    // Either gets the immediate children of a, or recursively gets all unignored children of a
+    private static void _addChildren(final Accessible a, final int whichChildren, final boolean allowIgnored, final ArrayList<Object> childrenAndRoles) {
+        if (a == null) return;
+
+        final AccessibleContext ac = a.getAccessibleContext();
+        if (ac == null) return;
+
+        final int numChildren = ac.getAccessibleChildrenCount();
+
+        // each child takes up two entries in the array: itself, and its role
+        // so the array holds alternating Accessible and AccessibleRole objects
+        for (int i = 0; i < numChildren; i++) {
+            final Accessible child = ac.getAccessibleChild(i);
+            if (child == null) continue;
+
+            final AccessibleContext context = child.getAccessibleContext();
+            if (context == null) continue;
+
+            if (whichChildren == JAVA_AX_VISIBLE_CHILDREN) {
+                if (!context.getAccessibleComponent().isVisible()) continue;
+            } else if (whichChildren == JAVA_AX_SELECTED_CHILDREN) {
+                if (!ac.getAccessibleSelection().isAccessibleChildSelected(i)) continue;
+            }
+
+            if (!allowIgnored) {
+                final AccessibleRole role = context.getAccessibleRole();
+                if (role != null && ignoredRoles.contains(roleKey(role))) {
+                    // Get the child's unignored children.
+                    _addChildren(child, whichChildren, false, childrenAndRoles);
+                } else {
+                    childrenAndRoles.add(child);
+                    childrenAndRoles.add(getAccessibleRole(child));
+                }
+            } else {
+                childrenAndRoles.add(child);
+                childrenAndRoles.add(getAccessibleRole(child));
+            }
+
+            // If there is an index, and we are beyond it, time to finish up
+            if ((whichChildren >= 0) && (childrenAndRoles.size() / 2) >= (whichChildren + 1)) {
+                return;
+            }
+        }
+    }
+
+    private static native String roleKey(AccessibleRole aRole);
+
+    public static Object[] getChildren(final Accessible a, final Component c) {
+        if (a == null) return null;
+        return invokeAndWait(new Callable<Object[]>() {
+            public Object[] call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final int numChildren = ac.getAccessibleChildrenCount();
+                final Object[] children = new Object[numChildren];
+                for (int i = 0; i < numChildren; i++) {
+                    children[i] = ac.getAccessibleChild(i);
+                }
+                return children;
+            }
+        }, c);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessible.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessible.java
new file mode 100644
index 0000000..54bc1b1
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessible.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Component;
+import java.lang.reflect.Field;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.swing.JProgressBar;
+import javax.swing.JSlider;
+import javax.swing.event.CaretEvent;
+import javax.swing.event.CaretListener;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.JTextComponent;
+
+
+class CAccessible extends CFRetainedResource implements Accessible {
+    static Field getNativeAXResourceField() {
+        try {
+            final Field field = AccessibleContext.class.getDeclaredField("nativeAXResource");
+            field.setAccessible(true);
+            return field;
+        } catch (final Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    private static Field nativeAXResourceField = getNativeAXResourceField();
+
+    public static CAccessible getCAccessible(final Accessible a) {
+        if (a == null) return null;
+        AccessibleContext context = a.getAccessibleContext();
+        try {
+            final CAccessible cachedCAX = (CAccessible) nativeAXResourceField.get(context);
+            if (cachedCAX != null) return cachedCAX;
+
+            final CAccessible newCAX = new CAccessible(a);
+            nativeAXResourceField.set(context, newCAX);
+            return newCAX;
+        }  catch (final Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    private static native void unregisterFromCocoaAXSystem(long ptr);
+    private static native void valueChanged(long ptr);
+    private static native void selectionChanged(long ptr);
+
+    private Accessible accessible;
+
+    private CAccessible(final Accessible accessible) {
+        super(0L, true); // real pointer will be poked in by native
+
+        if (accessible == null) throw new NullPointerException();
+        this.accessible = accessible;
+
+        if (accessible instanceof Component) {
+            addNotificationListeners((Component)accessible);
+        }
+    }
+
+    @Override
+    protected synchronized void dispose() {
+        if (ptr != 0) unregisterFromCocoaAXSystem(ptr);
+        super.dispose();
+    }
+
+    @Override
+    public AccessibleContext getAccessibleContext() {
+        return accessible.getAccessibleContext();
+    }
+
+    // currently only supports text components
+    public void addNotificationListeners(Component c) {
+        if (c instanceof JTextComponent) {
+            JTextComponent tc = (JTextComponent) c;
+            AXTextChangeNotifier listener = new AXTextChangeNotifier();
+            tc.getDocument().addDocumentListener(listener);
+            tc.addCaretListener(listener);
+        }
+        if (c instanceof JProgressBar) {
+            JProgressBar pb = (JProgressBar) c;
+            pb.addChangeListener(new AXProgressChangeNotifier());
+        } else if (c instanceof JSlider) {
+            JSlider slider = (JSlider) c;
+            slider.addChangeListener(new AXProgressChangeNotifier());
+        }
+    }
+
+
+    private class AXTextChangeNotifier implements DocumentListener, CaretListener {
+        @Override
+        public void changedUpdate(DocumentEvent e) {
+            if (ptr != 0) valueChanged(ptr);
+        }
+
+        @Override
+        public void insertUpdate(DocumentEvent e) {
+            if (ptr != 0) valueChanged(ptr);
+        }
+
+        @Override
+        public void removeUpdate(DocumentEvent e) {
+            if (ptr != 0) valueChanged(ptr);
+        }
+
+        @Override
+        public void caretUpdate(CaretEvent e) {
+            if (ptr != 0) selectionChanged(ptr);
+        }
+    }
+
+    private class AXProgressChangeNotifier implements ChangeListener {
+        public void stateChanged(ChangeEvent e) {
+            if (ptr != 0) valueChanged(ptr);
+        }
+    }
+
+    static Accessible getSwingAccessible(final Accessible a) {
+        return (a instanceof CAccessible) ? ((CAccessible)a).accessible : a;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessibleText.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessibleText.java
new file mode 100644
index 0000000..8bbca33
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CAccessibleText.java
@@ -0,0 +1,341 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Component;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
+import java.util.concurrent.Callable;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleEditableText;
+import javax.accessibility.AccessibleText;
+import javax.swing.text.Element;
+import javax.swing.text.JTextComponent;
+
+class CAccessibleText {
+    static AccessibleEditableText getAccessibleEditableText(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return CAccessibility.invokeAndWait(new Callable<AccessibleEditableText>() {
+            public AccessibleEditableText call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+                return ac.getAccessibleEditableText();
+            }
+        }, c);
+    }
+
+    static String getSelectedText(final Accessible a, final Component c) {
+        if (a == null) return null;
+
+        return CAccessibility.invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final AccessibleText at = ac.getAccessibleText();
+                if (at == null) return null;
+
+                return at.getSelectedText();
+            }
+        }, c);
+    }
+
+    // replace the currently selected text with newText
+    static void setSelectedText(final Accessible a, final Component c, final String newText) {
+        if (a == null) return;
+
+        CAccessibility.invokeLater(new Runnable() {
+            public void run() {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return;
+
+                final AccessibleEditableText aet = ac.getAccessibleEditableText();
+                if (aet == null) return;
+
+                final int selectionStart = aet.getSelectionStart();
+                final int selectionEnd = aet.getSelectionEnd();
+                aet.replaceText(selectionStart, selectionEnd, newText);
+            }
+        }, c);
+    }
+
+    static void setSelectedTextRange(final Accessible a, final Component c, final int startIndex, final int endIndex) {
+        if (a == null) return;
+
+        CAccessibility.invokeLater(new Runnable() {
+            public void run() {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return;
+
+                final AccessibleEditableText aet = ac.getAccessibleEditableText();
+                if (aet == null) return;
+
+                final boolean validRange = (startIndex >= 0) && (endIndex >= startIndex) && (endIndex <= aet.getCharCount());
+                if (!validRange) return;
+
+                aet.selectText(startIndex, endIndex);
+            }
+        }, c);
+    }
+
+    static String getTextRange(final AccessibleEditableText aet, final int start, final int stop, final Component c) {
+        if (aet == null) return null;
+
+        return CAccessibility.invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                return aet.getTextRange(start, stop);
+            }
+        }, c);
+    }
+
+    static int getCharacterIndexAtPosition(final Accessible a, final Component c, final int x, final int y) {
+        if (a == null) return 0;
+
+        return CAccessibility.invokeAndWait(new Callable<Integer>() {
+            public Integer call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+                final AccessibleText at = ac.getAccessibleText();
+                if (at == null) return null;
+                // (x, y) passed in as java screen coords - (0, 0) at upper-left corner of screen.
+                // Convert to java component-local coords
+                final Point componentLocation = ac.getAccessibleComponent().getLocationOnScreen();
+                final int localX = x - (int)componentLocation.getX();
+                final int localY = y - (int)componentLocation.getY();
+
+                return at.getIndexAtPoint(new Point(localX, localY));
+            }
+        }, c);
+    }
+
+    static int[] getSelectedTextRange(final Accessible a, final Component c) {
+        if (a == null) return new int[2];
+
+        return CAccessibility.invokeAndWait(new Callable<int[]>() {
+            public int[] call() {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return new int[2];
+
+                final AccessibleText at = ac.getAccessibleText();
+                if (at == null) return new int[2];
+
+                final int[] ret = new int[2];
+                ret[0] = at.getSelectionStart();
+                ret[1] = at.getSelectionEnd();
+                return ret;
+            }
+        }, c);
+    }
+
+
+    static int[] getVisibleCharacterRange(final Accessible a, final Component c) {
+        if (a == null) return null;
+        return CAccessibility.invokeAndWait(new Callable<int[]>() {
+            public int[] call() {
+                return getVisibleCharacterRange(a);
+            }
+        }, c);
+    }
+
+    static int getLineNumberForIndex(final Accessible a, final Component c, final int index) {
+        if (a == null) return 0;
+        return CAccessibility.invokeAndWait(new Callable<Integer>() {
+            public Integer call() {
+                return Integer.valueOf(getLineNumberForIndex(a, index));
+            }
+        }, c);
+    }
+
+    static int getLineNumberForInsertionPoint(final Accessible a, final Component c) {
+        if (a == null) return 0;
+        return CAccessibility.invokeAndWait(new Callable<Integer>() {
+            public Integer call() {
+                return Integer.valueOf(getLineNumberForInsertionPoint(a));
+            }
+        }, c);
+    }
+
+    static int[] getRangeForLine(final Accessible a, final Component c, final int line) {
+        if (a == null) return null;
+        return CAccessibility.invokeAndWait(new Callable<int[]>() {
+            public int[] call() {
+                return getRangeForLine(a, line);
+            }
+        }, c);
+    }
+
+    static int[] getRangeForIndex(final Accessible a, final Component c, final int index) {
+        if (a == null) return new int[2];
+
+        return CAccessibility.invokeAndWait(new Callable<int[]>() {
+            public int[] call() {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return new int[2];
+
+                final AccessibleEditableText aet = ac.getAccessibleEditableText();
+                if (aet == null) return new int[2];
+
+                final int charCount = aet.getCharCount();
+                if (index >= charCount) return new int[2];
+
+                final String foundWord = aet.getAtIndex(AccessibleText.WORD, index);
+                final int foundWordLength = foundWord.length();
+                final String wholeString = aet.getTextRange(0, charCount - 1);
+
+                // now we need to find the index of the foundWord in wholeString. It's somewhere pretty close to the passed-in index,
+                // but we don't know if it's before or after the passed-in index. So, look behind and ahead of the passed-in index
+                int foundWordIndex = -1;
+                int offset = 0;
+                while ((foundWordIndex == -1) && (offset < foundWordLength)) {
+                    if (wholeString.regionMatches(true, index - offset, foundWord, 0, foundWordLength)) {
+                        // is the index of foundWord to the left of the passed-in index?
+                        foundWordIndex = index - offset;
+                    }
+                    if (wholeString.regionMatches(true, index + offset, foundWord, 0, foundWordLength)) {
+                        // is the index of the foundWord to the right of the passed-in index?
+                        foundWordIndex = index + offset;
+                    }
+                    offset++;
+                }
+
+                final int[] ret = new int[2];
+                ret[0] = foundWordIndex;
+                ret[1] = foundWordIndex + foundWordLength;
+                return ret;
+            }
+        }, c);
+    }
+
+    // cmcnote: this method does not currently work for JLabels. JLabels, for some reason unbeknownst to me, do not
+    // return a value from getAccessibleText. According to the javadocs, AccessibleJLabels implement AccessibleText,
+    // so this doesn't really make sense. Perhaps a sun bug? Investigate. We currently get the text value out of labels
+    // via "getAccessibleName". This just returns a String - so we don't know it's position, etc, as we do for
+    // AccessibleText.
+    static double[] getBoundsForRange(final Accessible a, final Component c, final int location, final int length) {
+        final double[] ret = new double[4];
+        if (a == null) return ret;
+
+        return CAccessibility.invokeAndWait(new Callable<double[]>() {
+            public double[] call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return ret;
+
+                final AccessibleText at = ac.getAccessibleText();
+                if (at == null) {
+                    ac.getAccessibleName();
+                    ac.getAccessibleEditableText();
+                    return ret;
+                }
+
+                final Rectangle2D boundsStart = at.getCharacterBounds(location);
+                final Rectangle2D boundsEnd = at.getCharacterBounds(location + length - 1);
+                if (boundsEnd == null || boundsStart == null) return ret;
+                final Rectangle2D boundsUnion = boundsStart.createUnion(boundsEnd);
+                if (boundsUnion.isEmpty()) return ret;
+
+                final double localX = boundsUnion.getX();
+                final double localY = boundsUnion.getY();
+
+                final Point componentLocation = ac.getAccessibleComponent().getLocationOnScreen();
+                final double screenX = componentLocation.getX() + localX;
+                final double screenY = componentLocation.getY() + localY;
+
+                ret[0] = screenX;
+                ret[1] = screenY; // in java screen coords (from top-left corner of screen)
+                ret[2] = boundsUnion.getWidth();
+                ret[3] = boundsUnion.getHeight();
+                return ret;
+            }
+        }, c);
+    }
+
+    static String getStringForRange(final Accessible a, final Component c, final int location, final int length) {
+        if (a == null) return null;
+        return CAccessibility.invokeAndWait(new Callable<String>() {
+            public String call() throws Exception {
+                final AccessibleContext ac = a.getAccessibleContext();
+                if (ac == null) return null;
+
+                final AccessibleEditableText aet = ac.getAccessibleEditableText();
+                if (aet == null) return null;
+
+                return aet.getTextRange(location, location + length);
+            }
+        }, c);
+    }
+
+    static int[] getVisibleCharacterRange(final Accessible a) {
+        final Accessible sa = CAccessible.getSwingAccessible(a);
+        if (!(sa instanceof JTextComponent)) return null;
+
+        final JTextComponent jc = (JTextComponent) sa;
+        final Rectangle rect = jc.getVisibleRect();
+        final Point topLeft = new Point(rect.x, rect.y);
+        final Point topRight = new Point(rect.x + rect.width, rect.y);
+        final Point bottomLeft = new Point(rect.x, rect.y + rect.height);
+        final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height);
+
+        int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight));
+        int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight));
+        if (start < 0) start = 0;
+        if (end < 0) end = 0;
+        return new int[] { start, end };
+    }
+
+    static int getLineNumberForIndex(final Accessible a, int index) {
+        final Accessible sa = CAccessible.getSwingAccessible(a);
+        if (!(sa instanceof JTextComponent)) return -1;
+
+        final JTextComponent jc = (JTextComponent) sa;
+        final Element root = jc.getDocument().getDefaultRootElement();
+
+        // treat -1 special, returns the current caret position
+        if (index == -1) index = jc.getCaretPosition();
+
+        // Determine line number (can be -1)
+        return root.getElementIndex(index);
+    }
+
+    static int getLineNumberForInsertionPoint(final Accessible a) {
+        return getLineNumberForIndex(a, -1); // uses special -1 for above
+    }
+
+    static int[] getRangeForLine(final Accessible a, final int lineIndex) {
+        Accessible sa = CAccessible.getSwingAccessible(a);
+        if (!(sa instanceof JTextComponent)) return null;
+
+        final JTextComponent jc = (JTextComponent) sa;
+        final Element root = jc.getDocument().getDefaultRootElement();
+        final Element line = root.getElement(lineIndex);
+        if (line == null) return null;
+
+        return new int[] { line.getStartOffset(), line.getEndOffset() };
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CCheckboxMenuItem.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CCheckboxMenuItem.java
new file mode 100644
index 0000000..9b59cea
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CCheckboxMenuItem.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.CheckboxMenuItem;
+import java.awt.EventQueue;
+import java.awt.event.ItemEvent;
+import java.awt.peer.CheckboxMenuItemPeer;
+
+import sun.awt.SunToolkit;
+
+public class CCheckboxMenuItem extends CMenuItem implements CheckboxMenuItemPeer {
+    boolean fAutoToggle = true;
+    boolean fIsIndeterminate = false;
+
+    private native void nativeSetState(long modelPtr, boolean state);
+    private native void nativeSetIsCheckbox(long modelPtr);
+
+    CCheckboxMenuItem(CheckboxMenuItem target) {
+        super(target);
+        nativeSetIsCheckbox(getModel());
+        setState(target.getState());
+    }
+
+    // MenuItemPeer implementation
+    @Override
+    public void setState(boolean state) {
+        nativeSetState(getModel(), state);
+    }
+
+    public void handleAction(final boolean state) {
+        final CheckboxMenuItem target = (CheckboxMenuItem)getTarget();
+        EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                target.setState(state);
+            }
+        });
+        ItemEvent event = new ItemEvent(target, ItemEvent.ITEM_STATE_CHANGED, target.getLabel(), state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
+        SunToolkit.postEvent(SunToolkit.targetToAppContext(getTarget()), event);
+    }
+
+    public void setIsIndeterminate(final boolean indeterminate) {
+        fIsIndeterminate = indeterminate;
+    }
+
+    private boolean isAutoToggle() {
+        return fAutoToggle;
+    }
+
+    public void setAutoToggle(boolean b) {
+        fAutoToggle = b;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CClipboard.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CClipboard.java
new file mode 100644
index 0000000..882fe55
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CClipboard.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.datatransfer.*;
+import java.io.IOException;
+import java.util.*;
+
+import sun.awt.datatransfer.*;
+
+
+/**
+* A class which interfaces with Cocoa's pasteboard in order to support
+ * data transfer via Clipboard operations. Most of the work is provided by
+ * sun.awt.datatransfer.DataTransferer.
+ */
+
+public class CClipboard extends SunClipboard {
+
+    public CClipboard(String name) {
+        super(name);
+    }
+
+    public long getID() {
+        return 0;
+    }
+
+    protected void clearNativeContext() {
+        // Leaving Empty, as WClipboard.clearNativeContext is empty as well.
+    }
+
+    protected void setContentsNative(Transferable contents) {
+
+        // Don't use delayed Clipboard rendering for the Transferable's data.
+        // If we did that, we would call Transferable.getTransferData on
+        // the Toolkit thread, which is a security hole.
+        //
+        // Get all of the target formats into which the Transferable can be
+        // translated. Then, for each format, translate the data and post
+        // it to the Clipboard.
+        DataTransferer dataTransferer = DataTransferer.getInstance();
+        long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap);
+        declareTypes(formatArray, this);
+
+        Map<Long, DataFlavor> formatMap = DataTransferer.getInstance().getFormatsForTransferable(contents, flavorMap);
+
+        for (Iterator<Long> iter = formatMap.keySet().iterator(); iter.hasNext(); ) {
+            Long lFormat = iter.next();
+            long format = lFormat.longValue();
+            DataFlavor flavor = formatMap.get(lFormat);
+
+            try {
+                byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format);
+                setData(bytes, format);
+            } catch (IOException e) {
+                // Fix 4696186: don't print exception if data with
+                // javaJVMLocalObjectMimeType failed to serialize.
+                // May remove this if-check when 5078787 is fixed.
+                if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
+                      e instanceof java.io.NotSerializableException)) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    private void lostSelectionOwnershipImpl() {
+        lostOwnershipImpl();
+    }
+
+    protected native long[] getClipboardFormats();
+    protected native byte[] getClipboardData(long format) throws IOException;
+
+    // 1.5 peer method
+    protected void unregisterClipboardViewerChecked() {
+        // no-op because we lack OS support. This requires 4048791, which requires 4048792
+    }
+
+    // 1.5 peer method
+    protected void registerClipboardViewerChecked()    {
+        // no-op because we lack OS support. This requires 4048791, which requires 4048792
+    }
+
+    // 1.5 peer method
+    // no-op. This appears to be win32 specific. Filed 4048790 for investigation
+    //protected Transferable createLocaleTransferable(long[] formats) throws IOException;
+
+    public native void declareTypes(long[] formats, SunClipboard newOwner);
+    public native void setData(byte[] data, long format);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CCursorManager.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CCursorManager.java
new file mode 100644
index 0000000..cc4cd35
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CCursorManager.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.geom.Point2D;
+
+import sun.lwawt.*;
+
+public class CCursorManager extends LWCursorManager {
+    private static native Point2D nativeGetCursorPosition();
+    private static native void nativeSetBuiltInCursor(final int type, final String name);
+    private static native void nativeSetCustomCursor(final long imgPtr, final double x, final double y);
+
+    private static final int NAMED_CURSOR = -1;
+
+    private final static CCursorManager theInstance = new CCursorManager();
+    public static CCursorManager getInstance() {
+        return theInstance;
+    }
+
+    Cursor currentCursor;
+
+    private CCursorManager() { }
+
+    @Override
+    protected Point getCursorPosition() {
+        synchronized(this) {
+            if (isDragging) {
+                // during the drag operation, the appkit thread is blocked,
+                // so nativeGetCursorPosition invocation may cause a deadlock.
+                // In order to avoid this, we returns last know cursor position.
+                return new Point(dragPos);
+            }
+        }
+
+        final Point2D nativePosition = nativeGetCursorPosition();
+        return new Point((int)nativePosition.getX(), (int)nativePosition.getY());
+    }
+
+    @Override
+    protected void setCursor(final LWWindowPeer windowUnderCursor, final Cursor cursor) {
+        if (cursor == currentCursor) return;
+
+        if (cursor == null) {
+            nativeSetBuiltInCursor(Cursor.DEFAULT_CURSOR, null);
+            return;
+        }
+
+        if (cursor instanceof CCustomCursor) {
+            final CCustomCursor customCursor = ((CCustomCursor)cursor);
+            final long imagePtr = customCursor.getImageData();
+            final Point hotSpot = customCursor.getHotSpot();
+            if(imagePtr != 0L) nativeSetCustomCursor(imagePtr, hotSpot.x, hotSpot.y);
+            return;
+        }
+
+        final int type = cursor.getType();
+        if (type != Cursor.CUSTOM_CURSOR) {
+            nativeSetBuiltInCursor(type, null);
+            return;
+        }
+
+        final String name = cursor.getName();
+        if (name != null) {
+            nativeSetBuiltInCursor(NAMED_CURSOR, name);
+            return;
+        }
+
+        // do something special
+        throw new RuntimeException("Unimplemented");
+    }
+
+    static long getNativeWindow(final LWWindowPeer window) {
+        if (window == null) return 0;
+        final CPlatformWindow platformWindow = (CPlatformWindow)window.getPlatformWindow();
+        if (platformWindow == null) return 0;
+        return platformWindow.getNSWindowPtr();
+    }
+
+    // package private methods to handle cursor change during drag-and-drop
+    private boolean isDragging = false;
+    private Point dragPos = null;
+
+    synchronized void startDrag(int x, int y) {
+        if (isDragging) {
+            throw new RuntimeException("Invalid Drag state in CCursorManager!");
+        }
+
+        isDragging = true;
+
+        dragPos = new Point(x, y);
+    }
+
+    synchronized void updateDragPosition(int x, int y) {
+        if (!isDragging) {
+            throw new RuntimeException("Invalid Drag state in CCursorManager!");
+        }
+        dragPos.move(x, y);
+    }
+
+    synchronized void stopDrag() {
+        if (!isDragging) {
+            throw new RuntimeException("Invalid Drag state in CCursorManager!");
+        }
+        isDragging = false;
+        dragPos = null;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java
new file mode 100644
index 0000000..371f7f8
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+
+public class CCustomCursor extends Cursor {
+    static Dimension sMaxCursorSize;
+    static Dimension getMaxCursorSize() {
+        if (sMaxCursorSize != null) return sMaxCursorSize;
+        final Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
+        return sMaxCursorSize = new Dimension(bounds.width / 2, bounds.height / 2);
+    }
+
+    Image fImage;
+    Point fHotspot;
+
+    public CCustomCursor(final Image cursor, final Point hotSpot, final String name) throws IndexOutOfBoundsException, HeadlessException {
+        super(name);
+        fImage = cursor;
+        fHotspot = hotSpot;
+
+        // This chunk of code is copied from sun.awt.CustomCursor
+        final Toolkit toolkit = Toolkit.getDefaultToolkit();
+
+        // Make sure image is fully loaded.
+        final Component c = new Canvas(); // for its imageUpdate method
+        final MediaTracker tracker = new MediaTracker(c);
+        tracker.addImage(fImage, 0);
+        try {
+            tracker.waitForAll();
+        } catch (final InterruptedException e) {}
+
+        int width = fImage.getWidth(c);
+        int height = fImage.getHeight(c);
+
+        // Fix for bug 4212593 The Toolkit.createCustomCursor does not
+        // check absence of the image of cursor
+        // If the image is invalid, the cursor will be hidden (made completely
+        // transparent). In this case, getBestCursorSize() will adjust negative w and h,
+        // but we need to set the hotspot inside the image here.
+        if (tracker.isErrorAny() || width < 0 || height < 0) {
+            fHotspot.x = fHotspot.y = 0;
+        }
+
+        // Scale image to nearest supported size
+        final Dimension nativeSize = toolkit.getBestCursorSize(width, height);
+        if (nativeSize.width != width || nativeSize.height != height) {
+            fImage = fImage.getScaledInstance(nativeSize.width, nativeSize.height, Image.SCALE_DEFAULT);
+            width = nativeSize.width;
+            height = nativeSize.height;
+        }
+
+        // NOTE: this was removed for 3169146, but in 1.5 the JCK tests for an exception and fails if one isn't thrown.
+        // See what JBuilder does.
+        // Verify that the hotspot is within cursor bounds.
+        if (fHotspot.x >= width || fHotspot.y >= height || fHotspot.x < 0 || fHotspot.y < 0) {
+            throw new IndexOutOfBoundsException("invalid hotSpot");
+        }
+
+        // Must normalize the hotspot
+        if (fHotspot.x >= width) {
+            fHotspot.x = width - 1; // it is zero based.
+        } else if (fHotspot.x < 0) {
+            fHotspot.x = 0;
+        }
+        if (fHotspot.y >= height) {
+            fHotspot.y = height - 1; // it is zero based.
+        } else if (fHotspot.y < 0) {
+            fHotspot.y = 0;
+        }
+    }
+
+    public static Dimension getBestCursorSize(final int preferredWidth, final int preferredHeight) {
+        // With Panther, cursors have no limit on their size. So give the client their
+        // preferred size, but no larger than half the dimensions of the main screen
+        // This will allow large cursors, but not cursors so large that they cover the
+        // screen. Since solaris nor windows allow cursors this big, this shouldn't be
+        // a limitation.
+        // JCK triggers an overflow in the int -- if we get a bizarre value normalize it.
+        final Dimension maxCursorSize = getMaxCursorSize();
+        final Dimension d = new Dimension(Math.max(1, Math.abs(preferredWidth)), Math.max(1, Math.abs(preferredHeight)));
+        return new Dimension(Math.min(d.width, maxCursorSize.width), Math.min(d.height, maxCursorSize.height));
+    }
+
+    // Called from native when the cursor is set
+    // Returns long array of [NSImage ptr, x hotspot, y hotspot]
+    CImage fCImage;
+    long getImageData() {
+        if (fCImage == null) {
+            try {
+                fCImage = CImage.getCreator().createFromImage(fImage);
+            } catch (IllegalArgumentException iae) {
+                // Silently return null - we want to hide cursor by providing an empty
+                // ByteArray or just null
+                return 0L;
+            }
+        }
+
+        return fCImage.ptr;
+    }
+
+    Point getHotSpot() {
+        return fHotspot;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java
new file mode 100644
index 0000000..4598955
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java
@@ -0,0 +1,524 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.image.*;
+import sun.awt.image.ImageRepresentation;
+
+import java.io.*;
+import java.net.URL;
+import java.text.Normalizer;
+import java.text.Normalizer.Form;
+import java.util.*;
+
+import java.awt.datatransfer.*;
+import sun.awt.datatransfer.*;
+
+public class CDataTransferer extends DataTransferer {
+    private static final Map<String, Long> predefinedClipboardNameMap;
+    private static final Map<Long, String> predefinedClipboardFormatMap;
+
+    // See SystemFlavorMap, or the flavormap.properties file:
+    // We should define a few more types in flavormap.properties, it's rather slim now.
+    private static final String[] predefinedClipboardNames = {
+        "",
+        "STRING",
+        "FILE_NAME",
+        "TIFF",
+        "RICH_TEXT",
+        "HTML",
+        "PDF",
+        "URL"
+    };
+
+    static {
+        Map<String, Long> nameMap = new HashMap<String, Long>(predefinedClipboardNames.length, 1.0f);
+        Map<Long, String> formatMap = new HashMap<Long, String>(predefinedClipboardNames.length, 1.0f);
+        for (int i = 1; i < predefinedClipboardNames.length; i++) {
+            nameMap.put(predefinedClipboardNames[i], new Long(i));
+            formatMap.put(new Long(i), predefinedClipboardNames[i]);
+        }
+        predefinedClipboardNameMap = Collections.synchronizedMap(nameMap);
+        predefinedClipboardFormatMap = Collections.synchronizedMap(formatMap);
+    }
+
+    public static final int CF_UNSUPPORTED = 0;
+    public static final int CF_STRING      = 1;
+    public static final int CF_FILE        = 2;
+    public static final int CF_TIFF        = 3;
+    public static final int CF_RICH_TEXT   = 4;
+    public static final int CF_HTML        = 5;
+    public static final int CF_PDF         = 6;
+    public static final int CF_URL         = 7;
+    public static final int CF_PNG         = 10;
+    public static final int CF_JPEG        = 11;
+
+    public static final Long L_CF_TIFF = predefinedClipboardNameMap.get(predefinedClipboardNames[CF_TIFF]);
+
+    // Image file formats with java.awt.Image representation:
+    private static final Long[] imageFormats = new Long[] {
+        L_CF_TIFF
+    };
+
+
+    private CDataTransferer() {}
+
+    private static CDataTransferer fTransferer;
+
+    public static synchronized CDataTransferer getInstanceImpl() {
+        if (fTransferer == null) {
+            fTransferer = new CDataTransferer();
+        }
+
+        return fTransferer;
+    }
+
+    public String getDefaultUnicodeEncoding() {
+        return "utf-16le";
+    }
+
+    public boolean isLocaleDependentTextFormat(long format) {
+        return format == CF_STRING;
+    }
+
+    public boolean isFileFormat(long format) {
+        return format == CF_FILE;
+    }
+
+    public boolean isImageFormat(long format) {
+        int ifmt = (int)format;
+        switch(ifmt) {
+            case CF_TIFF:
+            case CF_PDF:
+            case CF_PNG:
+            case CF_JPEG:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    protected Long[] getImageFormatsAsLongArray() {
+        return imageFormats;
+    }
+
+    public byte[] translateTransferable(Transferable contents, DataFlavor flavor, long format) throws IOException
+        {
+            byte[] bytes = super.translateTransferable(contents, flavor, format);
+
+            // 9-12-02 VL: we may need to do something like Windows here.
+            //if (format == CF_HTML) {
+            //    bytes = HTMLSupport.convertToHTMLFormat(bytes);
+            //}
+
+            return bytes;
+        }
+
+    protected Object translateBytesOrStream(InputStream stream, byte[] bytes, DataFlavor flavor, long format,
+                                            Transferable transferable) throws IOException
+        {
+            // 5-28-03 VL: [Radar 3266030]
+            // We need to do like Windows does here.
+            if (format == CF_HTML && flavor.isFlavorTextType()) {
+                if (stream == null) {
+                    stream = new ByteArrayInputStream(bytes);
+                    bytes = null;
+                }
+
+                stream = new HTMLDecodingInputStream(stream);
+            }
+
+            if (format == CF_URL && URL.class.equals(flavor.getRepresentationClass()))
+            {
+                if (bytes == null) {
+                    bytes = inputStreamToByteArray(stream);
+                    stream = null;
+                }
+
+                String charset = getDefaultTextCharset();
+                if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
+                    try {
+                        charset = new String((byte[])transferable.getTransferData(javaTextEncodingFlavor), "UTF-8");
+                    } catch (UnsupportedFlavorException cannotHappen) {
+                    }
+                }
+
+                return new URL(new String(bytes, charset));
+            }
+
+            if (format == CF_STRING) {
+                bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8");
+            }
+
+            return super.translateBytesOrStream(stream, bytes, flavor, format, transferable);
+        }
+
+
+    synchronized protected Long getFormatForNativeAsLong(String str) {
+        Long format = predefinedClipboardNameMap.get(str);
+
+        if (format == null) {
+            format = new Long(registerFormatWithPasteboard(str));
+            predefinedClipboardNameMap.put(str, format);
+            predefinedClipboardFormatMap.put(format, str);
+        }
+
+        return format;
+    }
+
+    /*
+     * Adds type to native mapping NSDictionary.
+     */
+    private native long registerFormatWithPasteboard(String type);
+
+    // Get registered native format string for an index, return null if unknown:
+    private native String formatForIndex(long index);
+
+    protected String getNativeForFormat(long format) {
+        String returnValue = null;
+
+        // The most common case - just index the array of predefined names:
+        if (format >= 0 && format < predefinedClipboardNames.length) {
+            returnValue = predefinedClipboardNames[(int) format];
+        } else {
+            Long formatObj = new Long(format);
+            returnValue = predefinedClipboardFormatMap.get(formatObj);
+
+            // predefinedClipboardFormatMap may not know this format:
+            if (returnValue == null) {
+                returnValue = formatForIndex(format);
+
+                // Native clipboard may not know this format either:
+                if (returnValue != null) {
+                    predefinedClipboardNameMap.put(returnValue, formatObj);
+                    predefinedClipboardFormatMap.put(formatObj, returnValue);
+                }
+            }
+        }
+
+        if (returnValue == null) {
+            returnValue = predefinedClipboardNames[CF_UNSUPPORTED];
+        }
+
+        return returnValue;
+    }
+
+    private final ToolkitThreadBlockedHandler handler = new CToolkitThreadBlockedHandler();
+
+    public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {
+        return handler;
+    }
+
+    protected byte[] imageToPlatformBytes(Image image, long format) {
+        int w = image.getWidth(null);
+        int h = image.getHeight(null);
+        BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
+        Graphics g = bimage.getGraphics();
+        g.drawImage(image, 0, 0, w, h, null);
+        g.dispose();
+        Raster raster = bimage.getRaster();
+        DataBuffer buffer = raster.getDataBuffer();
+        return imageDataToPlatformImageBytes(((DataBufferInt)buffer).getData(),
+                                             raster.getWidth(),
+                                             raster.getHeight());
+    }
+
+    private static native String[] nativeDragQueryFile(final byte[] bytes);
+    protected String[] dragQueryFile(final byte[] bytes) {
+        if (bytes == null) return null;
+        if (new String(bytes).startsWith("Unsupported type")) return null;
+        return nativeDragQueryFile(bytes);
+    }
+
+    private native byte[] imageDataToPlatformImageBytes(int[] rData, int nW, int nH);
+
+    /**
+        * Translates either a byte array or an input stream which contain
+     * platform-specific image data in the given format into an Image.
+     */
+    protected Image platformImageBytesOrStreamToImage(InputStream stream, byte[] bytes, long format) throws IOException {
+        byte[] imageData = bytes;
+
+        if (imageData == null)
+            imageData = inputStreamToByteArray(stream);
+
+        return getImageForByteStream(imageData);
+    }
+
+    private native Image getImageForByteStream(byte[] bytes);
+
+    @Override
+    protected ByteArrayOutputStream convertFileListToBytes(ArrayList<String> fileList) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}
+
+
+// ---- Code borrowed from WDataTransferer: ----
+// This will come handy for supporting HTML data.
+
+final class HTMLSupport {
+    public static final String ENCODING = "UTF-8";
+
+    public static final String VERSION = "Version:";
+    public static final String START_HTML = "StartHTML:";
+    public static final String END_HTML = "EndHTML:";
+    public static final String START_FRAGMENT = "StartFragment:";
+    public static final String END_FRAGMENT = "EndFragment:";
+    public static final String START_FRAGMENT_CMT = "<!--StartFragment-->";
+    public static final String END_FRAGMENT_CMT = "<!--EndFragment-->";
+    public static final String EOLN = "\r\n";
+
+    private static final String VERSION_NUM = "0.9";
+    private static final String HTML_START_END = "-1";
+
+    private static final int PADDED_WIDTH = 10;
+
+    private static final int HEADER_LEN =
+        VERSION.length() + VERSION_NUM.length() + EOLN.length() +
+        START_HTML.length() + HTML_START_END.length() + EOLN.length() +
+        END_HTML.length() + HTML_START_END.length() + EOLN.length() +
+        START_FRAGMENT.length() + PADDED_WIDTH + EOLN.length() +
+        END_FRAGMENT.length() + PADDED_WIDTH + EOLN.length() +
+        START_FRAGMENT_CMT.length() + EOLN.length();
+    private static final String HEADER_LEN_STR =
+        toPaddedString(HEADER_LEN, PADDED_WIDTH);
+
+    private static final String TRAILER = END_FRAGMENT_CMT + EOLN + '\0';
+
+    private static String toPaddedString(int n, int width) {
+        String string = "" + n;
+        int len = string.length();
+        if (n >= 0 && len < width) {
+            char[] array = new char[width - len];
+            Arrays.fill(array, '0');
+            StringBuffer buffer = new StringBuffer();
+            buffer.append(array);
+            buffer.append(string);
+            string = buffer.toString();
+        }
+        return string;
+    }
+
+    public static byte[] convertToHTMLFormat(byte[] bytes) {
+        StringBuffer header = new StringBuffer(HEADER_LEN);
+        header.append(VERSION);
+        header.append(VERSION_NUM);
+        header.append(EOLN);
+        header.append(START_HTML);
+        header.append(HTML_START_END);
+        header.append(EOLN);
+        header.append(END_HTML);
+        header.append(HTML_START_END);
+        header.append(EOLN);
+        header.append(START_FRAGMENT);
+        header.append(HEADER_LEN_STR);
+        header.append(EOLN);
+        header.append(END_FRAGMENT);
+        // Strip terminating NUL byte from array
+        header.append(toPaddedString(HEADER_LEN + bytes.length - 1,
+                                     PADDED_WIDTH));
+        header.append(EOLN);
+        header.append(START_FRAGMENT_CMT);
+        header.append(EOLN);
+
+        byte[] headerBytes = null, trailerBytes = null;
+
+        try {
+            headerBytes = new String(header).getBytes(ENCODING);
+            trailerBytes = TRAILER.getBytes(ENCODING);
+        } catch (UnsupportedEncodingException cannotHappen) {
+        }
+
+        byte[] retval = new byte[headerBytes.length + bytes.length - 1 +
+            trailerBytes.length];
+
+        System.arraycopy(headerBytes, 0, retval, 0, headerBytes.length);
+        System.arraycopy(bytes, 0, retval, headerBytes.length,
+                         bytes.length - 1);
+        System.arraycopy(trailerBytes, 0, retval,
+                         headerBytes.length + bytes.length - 1,
+                         trailerBytes.length);
+
+        return retval;
+    }
+}
+
+/**
+* This stream takes an InputStream which provides data in CF_HTML format,
+ * strips off the description and context to extract the original HTML data.
+ */
+class HTMLDecodingInputStream extends InputStream {
+
+    private final BufferedInputStream bufferedStream;
+    private boolean descriptionParsed = false;
+    private boolean closed = false;
+    private int index;
+    private int end;
+
+    // InputStreamReader uses an 8K buffer. The size is not customizable.
+    public static final int BYTE_BUFFER_LEN = 8192;
+
+    // CharToByteUTF8.getMaxBytesPerChar returns 3, so we should not buffer
+    // more chars than 3 times the number of bytes we can buffer.
+    public static final int CHAR_BUFFER_LEN = BYTE_BUFFER_LEN / 3;
+
+    private static final String FAILURE_MSG =
+        "Unable to parse HTML description: ";
+    private static final String INVALID_MSG = " invalid";
+
+    public HTMLDecodingInputStream(InputStream bytestream) throws IOException {
+        bufferedStream = new BufferedInputStream(bytestream, BYTE_BUFFER_LEN);
+    }
+
+    private void parseDescription() throws IOException {
+        bufferedStream.mark(BYTE_BUFFER_LEN);
+
+        BufferedReader bufferedReader = new BufferedReader
+            (new InputStreamReader(bufferedStream, HTMLSupport.ENCODING),
+             CHAR_BUFFER_LEN);
+        String version = bufferedReader.readLine().trim();
+        if (version == null || !version.startsWith(HTMLSupport.VERSION)) {
+            // Not MS-compliant HTML text. Return raw text from read().
+            index = 0;
+            end = -1;
+            bufferedStream.reset();
+            return;
+        }
+
+        String input;
+        boolean startHTML, endHTML, startFragment, endFragment;
+        startHTML = endHTML = startFragment = endFragment = false;
+
+        try {
+            do {
+                input = bufferedReader.readLine().trim();
+                if (input == null) {
+                    close();
+                    throw new IOException(FAILURE_MSG);
+                } else if (input.startsWith(HTMLSupport.START_HTML)) {
+                    int val = Integer.parseInt
+                    (input.substring(HTMLSupport.START_HTML.length(),
+                                     input.length()).trim());
+                    if (val >= 0) {
+                        index = val;
+                        startHTML = true;
+                    } else if (val != -1) {
+                        close();
+                        throw new IOException(FAILURE_MSG +
+                                              HTMLSupport.START_HTML +
+                                              INVALID_MSG);
+                    }
+                } else if (input.startsWith(HTMLSupport.END_HTML)) {
+                    int val = Integer.parseInt
+                    (input.substring(HTMLSupport.END_HTML.length(),
+                                     input.length()).trim());
+                    if (val >= 0) {
+                        end = val;
+                        endHTML = true;
+                    } else if (val != -1) {
+                        close();
+                        throw new IOException(FAILURE_MSG +
+                                              HTMLSupport.END_HTML +
+                                              INVALID_MSG);
+                    }
+                } else if (!startHTML && !endHTML &&
+                           input.startsWith(HTMLSupport.START_FRAGMENT)) {
+                    index = Integer.parseInt
+                    (input.substring(HTMLSupport.START_FRAGMENT.length(),
+                                     input.length()).trim());
+                    if (index < 0) {
+                        close();
+                        throw new IOException(FAILURE_MSG +
+                                              HTMLSupport.START_FRAGMENT +
+                                              INVALID_MSG);
+                    }
+                    startFragment = true;
+                } else if (!startHTML && !endHTML &&
+                           input.startsWith(HTMLSupport.END_FRAGMENT)) {
+                    end = Integer.parseInt
+                    (input.substring(HTMLSupport.END_FRAGMENT.length(),
+                                     input.length()).trim());
+                    if (end < 0) {
+                        close();
+                        throw new IOException(FAILURE_MSG +
+                                              HTMLSupport.END_FRAGMENT +
+                                              INVALID_MSG);
+                    }
+                    endFragment = true;
+                }
+            } while (!((startHTML && endHTML) ||
+                       (startFragment && endFragment)));
+        } catch (NumberFormatException e) {
+            close();
+            throw new IOException(FAILURE_MSG + e);
+        }
+
+        bufferedStream.reset();
+
+        for (int i = 0; i < index; i++) {
+            if (bufferedStream.read() == -1) {
+                close();
+                throw new IOException(FAILURE_MSG +
+                                      "Byte stream ends in description.");
+            }
+        }
+    }
+
+    public int read() throws IOException {
+        if (closed) {
+            throw new IOException("Stream closed");
+        }
+
+        if (!descriptionParsed) {
+            parseDescription(); // initializes 'index' and 'end'
+            descriptionParsed = true;
+        }
+
+        if (end != -1 && index >= end) {
+            return -1;
+        }
+
+        int retval = bufferedStream.read();
+        if (retval == -1) {
+            index = end = 0; // so future read() calls will fail quickly
+            return -1;
+        }
+
+        index++;
+    //    System.out.print((char)retval);
+        return retval;
+    }
+
+    public void close() throws IOException {
+        if (!closed) {
+            closed = true;
+            bufferedStream.close();
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CDesktopPeer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CDesktopPeer.java
new file mode 100644
index 0000000..142d9a5
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDesktopPeer.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Desktop.Action;
+import java.awt.peer.DesktopPeer;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+
+
+/**
+ * Concrete implementation of the interface <code>DesktopPeer</code> for MacOS X
+ *
+ * @see DesktopPeer
+ */
+public class CDesktopPeer implements DesktopPeer {
+
+    public boolean isSupported(Action action) {
+        // OPEN, EDIT, PRINT, MAIL, BROWSE all supported.
+        // Though we don't really differentiate between OPEN / EDIT
+        return true;
+    }
+
+    public void open(File file) throws IOException {
+        this.lsOpenFile(file, false);
+    }
+
+    public void edit(File file) throws IOException {
+        this.lsOpenFile(file, false);
+    }
+
+    public void print(File file) throws IOException {
+        this.lsOpenFile(file, true);
+    }
+
+    public void mail(URI uri) throws IOException {
+        this.lsOpen(uri);
+    }
+
+    public void browse(URI uri) throws IOException {
+        this.lsOpen(uri);
+    }
+
+    private void lsOpen(URI uri) throws IOException {
+        int status = _lsOpenURI(uri.toString());
+
+        if (status != 0 /* noErr */) {
+            throw new IOException("Failed to mail or browse " + uri + ". Error code: " + status);
+        }
+    }
+
+    private void lsOpenFile(File file, boolean print) throws IOException {
+        int status = _lsOpenFile(file.getCanonicalPath(), print);
+
+        if (status != 0 /* noErr */) {
+            throw new IOException("Failed to open, edit or print " + file + ". Error code: " + status);
+        }
+    }
+
+    private static native int _lsOpenURI(String uri);
+
+    private static native int _lsOpenFile(String path, boolean print);
+
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java
new file mode 100644
index 0000000..e1e7c9c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java
@@ -0,0 +1,504 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.awt.peer.*;
+
+import javax.swing.*;
+import javax.swing.text.*;
+import javax.accessibility.*;
+
+import java.util.Map;
+import sun.awt.dnd.*;
+import sun.lwawt.LWComponentPeer;
+
+
+public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
+
+    private static final CDragSourceContextPeer fInstance = new CDragSourceContextPeer(null);
+
+    private Image  fDragImage;
+    private CImage fDragCImage;
+    private Point  fDragImageOffset;
+
+    private static Component hoveringComponent = null;
+
+    private static double fMaxImageSize = 128.0;
+
+    static {
+        String propValue = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("apple.awt.dnd.defaultDragImageSize"));
+        if (propValue != null) {
+            try {
+                double value = Double.parseDouble(propValue);
+                if (value > 0) {
+                    fMaxImageSize = value;
+                }
+            } catch(NumberFormatException e) {}
+        }
+    }
+
+    private CDragSourceContextPeer(DragGestureEvent dge) {
+        super(dge);
+    }
+
+    public static CDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
+        fInstance.setTrigger(dge);
+
+        return fInstance;
+    }
+
+    // We have to overload this method just to be able to grab the drag image and its offset as shared code doesn't store it:
+    public void startDrag(DragSourceContext dsc, Cursor cursor, Image dragImage, Point dragImageOffset) throws InvalidDnDOperationException {
+        fDragImage = dragImage;
+        fDragImageOffset = dragImageOffset;
+
+        super.startDrag(dsc, cursor, dragImage, dragImageOffset);
+    }
+
+    protected void startDrag(Transferable transferable, long[] formats, Map formatMap) {
+        DragGestureEvent trigger = getTrigger();
+        InputEvent         triggerEvent = trigger.getTriggerEvent();
+
+        Point dragOrigin = trigger.getDragOrigin();
+        int extModifiers = (triggerEvent.getModifiers() | triggerEvent.getModifiersEx());
+        long timestamp   = triggerEvent.getWhen();
+        int clickCount   = ((triggerEvent instanceof MouseEvent) ? (((MouseEvent) triggerEvent).getClickCount()) : 1);
+
+        // Get drag source component and its peer:
+        Component component = trigger.getComponent();
+        Point componentOffset = new Point();
+        ComponentPeer peer = component.getPeer();
+
+        // For a lightweight component traverse up the hierarchy to the first heavyweight
+        // which will be used as the ComponentModel for the native drag source.
+        if (component.isLightweight()) {
+            Point loc = component.getLocation();
+            componentOffset.translate(loc.x, loc.y);
+
+            for (Component parent = component.getParent(); parent != null; parent = parent.getParent()) {
+                if (parent.isLightweight() == false) {
+                    peer = parent.getPeer();
+                    break;
+                }
+
+                loc = parent.getLocation();
+                componentOffset.translate(loc.x, loc.y);
+            }
+        }
+
+        // Make sure the drop target is a ComponentModel:
+        if (!(peer instanceof LWComponentPeer))
+            throw new IllegalArgumentException("DragSource's peer must be a ComponentModel.");
+
+        // Get model pointer (CButton.m and such) and its native peer:
+        LWComponentPeer model = (LWComponentPeer) peer;
+        CPlatformWindow platformWindow = (CPlatformWindow) model.getPlatformWindow();
+        long nativeWindowPtr = platformWindow.getNSWindowPtr();
+
+        // Get drag cursor:
+        Cursor cursor = this.getCursor();
+
+        // If there isn't any drag image make one of default appearance:
+        if (fDragImage == null)
+            this.setDefaultDragImage(component);
+
+        // Get drag image (if any) as BufferedImage and convert that to CImage:
+        long  dragImage;
+        Point dragImageOffset;
+
+        if (fDragImage != null) {
+            BufferedImage bi = (fDragImage instanceof BufferedImage ? (BufferedImage) fDragImage : null);
+
+            if (bi == null) {
+                // Create a new buffered image:
+                int width  = fDragImage.getWidth(null);
+                int height = fDragImage.getHeight(null);
+                bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
+
+                // Draw drag image into the buffered image:
+                Graphics g = bi.getGraphics();
+                g.drawImage(fDragImage, 0, 0, null);
+                g.dispose();
+            }
+            /*   TODO:BG
+            fDragCImage = CImage.getCreator().createImage(bi);
+            dragImage = fDragCImage.getNSImage(); */
+            fDragCImage = null;
+            dragImage = 0L;
+            dragImageOffset = fDragImageOffset;
+        } else {
+
+            fDragCImage = null;
+            dragImage = 0L;
+            dragImageOffset = new Point(0, 0);
+        }
+
+        // Get NS drag image instance if we have a drag image:
+        long nsDragImage = 0L; //TODO:BG (fDragCImage != null ? fDragCImage.getNSImage() : 0L);
+
+        try {
+            // Create native dragging source:
+            final long nativeDragSource = createNativeDragSource(component, peer, nativeWindowPtr, transferable, triggerEvent,
+                (int) (dragOrigin.getX() + componentOffset.x), (int) (dragOrigin.getY() + componentOffset.y), extModifiers,
+                clickCount, timestamp, cursor, dragImage, dragImageOffset.x, dragImageOffset.y,
+                getDragSourceContext().getSourceActions(), formats, formatMap);
+
+            if (nativeDragSource == 0)
+                throw new InvalidDnDOperationException("");
+
+            setNativeContext(nativeDragSource);
+
+            CCursorManager.getInstance().startDrag(
+                    (int) (dragOrigin.getX() + componentOffset.x),
+                    (int) (dragOrigin.getY() + componentOffset.y));
+        }
+
+        catch (Exception e) {
+            throw new InvalidDnDOperationException("failed to create native peer: " + e);
+        }
+
+        SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
+
+        // Create a new thread to run the dragging operation since it's synchronous, only coming back
+        // after dragging is finished. This leaves the AWT event thread free to handle AWT events which
+        // are posted during dragging by native event handlers.
+
+        try {
+            Thread dragThread = new Thread() {
+                public void run() {
+                    final long nativeDragSource = getNativeContext();
+                    try {
+                        doDragging(nativeDragSource);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                        CCursorManager.getInstance().stopDrag();
+
+                        releaseNativeDragSource(nativeDragSource);
+                        fDragImage = null;
+                        if (fDragCImage != null) {
+                            fDragCImage.dispose();
+                            fDragCImage = null;
+                        }
+                    }
+                }
+            };
+
+            dragThread.start();
+        }
+
+        catch (Exception e) {
+            CCursorManager.getInstance().stopDrag();
+
+            final long nativeDragSource = getNativeContext();
+            setNativeContext(0);
+            releaseNativeDragSource(nativeDragSource);
+            SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(null);
+            throw new InvalidDnDOperationException("failed to start dragging thread: " + e);
+        }
+    }
+
+    private void setDefaultDragImage(Component component) {
+        boolean handled = false;
+
+        // Special-case default drag image, depending on the drag source type:
+        if (component.isLightweight()) {
+            if (component instanceof JTextComponent) {
+                this.setDefaultDragImage((JTextComponent) component);
+                handled = true;
+            } else if (component instanceof JTree) {
+                            this.setDefaultDragImage((JTree) component);
+                            handled = true;
+                        } else if (component instanceof JTable) {
+                            this.setDefaultDragImage((JTable) component);
+                            handled = true;
+                        } else if (component instanceof JList) {
+                            this.setDefaultDragImage((JList) component);
+                            handled = true;
+                        }
+        }
+
+        if (handled == false)
+            this.setDefaultDragImage();
+    }
+
+    private void setDefaultDragImage(JTextComponent component) {
+        DragGestureEvent trigger = getTrigger();
+        int selectionStart = component.getSelectionStart();
+        int selectionEnd = component.getSelectionEnd();
+        boolean handled = false;
+
+        // Make sure we're dragging current selection:
+        int index = component.viewToModel(trigger.getDragOrigin());
+        if ((selectionStart < selectionEnd) && (index >= selectionStart) && (index <= selectionEnd)) {
+            try {
+                Rectangle selectionStartBounds = component.modelToView(selectionStart);
+                Rectangle selectionEndBounds = component.modelToView(selectionEnd);
+
+                Rectangle selectionBounds = null;
+
+                // Single-line selection:
+                if (selectionStartBounds.y == selectionEndBounds.y) {
+                    selectionBounds = new Rectangle(selectionStartBounds.x, selectionStartBounds.y,
+                        selectionEndBounds.x - selectionStartBounds.x + selectionEndBounds.width,
+                        selectionEndBounds.y - selectionStartBounds.y + selectionEndBounds.height);
+                }
+
+                // Multi-line selection:
+                else {
+                    AccessibleContext ctx = component.getAccessibleContext();
+                    AccessibleText at = (AccessibleText) ctx;
+
+                    selectionBounds = component.modelToView(selectionStart);
+                    for (int i = selectionStart + 1; i <= selectionEnd; i++) {
+                                            Rectangle charBounds = at.getCharacterBounds(i);
+                                            // Invalid index returns null Rectangle
+                                            // Note that this goes against jdk doc - should be empty, but is null instead
+                                            if (charBounds != null) {
+                                                selectionBounds.add(charBounds);
+                                            }
+                    }
+                }
+
+                this.setOutlineDragImage(selectionBounds);
+                handled = true;
+            }
+
+            catch (BadLocationException exc) {
+                // Default the drag image to component bounds.
+            }
+        }
+
+        if (handled == false)
+            this.setDefaultDragImage();
+    }
+
+
+    private void setDefaultDragImage(JTree component) {
+        Rectangle selectedOutline = null;
+
+        int[] selectedRows = component.getSelectionRows();
+        for (int i=0; i<selectedRows.length; i++) {
+            Rectangle r = component.getRowBounds(selectedRows[i]);
+            if (selectedOutline == null)
+                selectedOutline = r;
+            else
+                selectedOutline.add(r);
+        }
+
+        if (selectedOutline != null) {
+            this.setOutlineDragImage(selectedOutline);
+        } else {
+            this.setDefaultDragImage();
+        }
+    }
+
+    private void setDefaultDragImage(JTable component) {
+        Rectangle selectedOutline = null;
+
+        // This code will likely break once multiple selections works (3645873)
+        int[] selectedRows = component.getSelectedRows();
+        int[] selectedColumns = component.getSelectedColumns();
+        for (int row=0; row<selectedRows.length; row++) {
+            for (int col=0; col<selectedColumns.length; col++) {
+                Rectangle r = component.getCellRect(selectedRows[row], selectedColumns[col], true);
+                if (selectedOutline == null)
+                    selectedOutline = r;
+                else
+                    selectedOutline.add(r);
+            }
+        }
+
+        if (selectedOutline != null) {
+            this.setOutlineDragImage(selectedOutline);
+        } else {
+            this.setDefaultDragImage();
+        }
+    }
+
+    private void setDefaultDragImage(JList component) {
+        Rectangle selectedOutline = null;
+
+        // This code actually works, even under the (non-existant) multiple-selections, because we only draw a union outline
+        int[] selectedIndices = component.getSelectedIndices();
+        if (selectedIndices.length > 0)
+            selectedOutline = component.getCellBounds(selectedIndices[0], selectedIndices[selectedIndices.length-1]);
+
+        if (selectedOutline != null) {
+            this.setOutlineDragImage(selectedOutline);
+        } else {
+            this.setDefaultDragImage();
+        }
+    }
+
+
+    private void setDefaultDragImage() {
+        DragGestureEvent trigger = this.getTrigger();
+        Component comp = trigger.getComponent();
+
+        setOutlineDragImage(new Rectangle(0, 0, comp.getWidth(), comp.getHeight()), true);
+    }
+
+    private void setOutlineDragImage(Rectangle outline) {
+        setOutlineDragImage(outline, false);
+    }
+
+    private void setOutlineDragImage(Rectangle outline, Boolean shouldScale) {
+        int width = (int)outline.getWidth();
+        int height = (int)outline.getHeight();
+
+        double scale = 1.0;
+        if (shouldScale) {
+            final int area = width * height;
+            final int maxArea = (int)(fMaxImageSize * fMaxImageSize);
+
+            if (area > maxArea) {
+                scale = (double)area / (double)maxArea;
+                width /= scale;
+                height /= scale;
+            }
+        }
+
+        if (width <=0) width = 1;
+        if (height <=0) height = 1;
+
+        DragGestureEvent trigger = this.getTrigger();
+        Component comp = trigger.getComponent();
+        Point compOffset = comp.getLocation();
+
+        // For lightweight components add some special treatment:
+        if (comp instanceof JComponent) {
+            // Intersect requested bounds with visible bounds:
+            Rectangle visibleBounds = ((JComponent) comp).getVisibleRect();
+            Rectangle clipedOutline = outline.intersection(visibleBounds);
+            if (clipedOutline.isEmpty() == false)
+                outline = clipedOutline;
+
+            // Compensate for the component offset (e.g. when contained in a JScrollPane):
+            outline.translate(compOffset.x, compOffset.y);
+        }
+
+        GraphicsConfiguration config = comp.getGraphicsConfiguration();
+        BufferedImage dragImage = config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
+
+        Color paint = Color.gray;
+        BasicStroke stroke = new BasicStroke(2.0f);
+        int halfLineWidth = (int) (stroke.getLineWidth() + 1) / 2; // Rounded up.
+
+        Graphics2D g2 = (Graphics2D) dragImage.getGraphics();
+        g2.setPaint(paint);
+        g2.setStroke(stroke);
+        g2.drawRect(halfLineWidth, halfLineWidth, width - 2 * halfLineWidth - 1, height - 2 * halfLineWidth - 1);
+        g2.dispose();
+
+        fDragImage = dragImage;
+
+
+        Point dragOrigin = trigger.getDragOrigin();
+        Point dragImageOffset = new Point(outline.x - dragOrigin.x, outline.y - dragOrigin.y);
+        if (comp instanceof JComponent) {
+            dragImageOffset.translate(-compOffset.x, -compOffset.y);
+        }
+
+        if (shouldScale) {
+            dragImageOffset.x /= scale;
+            dragImageOffset.y /= scale;
+        }
+
+        fDragImageOffset = dragImageOffset;
+    }
+
+    /**
+     * upcall from native code
+     */
+    private void dragMouseMoved(final int targetActions,
+                                final int modifiers,
+                                final int x, final int y) {
+
+        CCursorManager.getInstance().updateDragPosition(x, y);
+
+        Component rootComponent = SwingUtilities.getRoot(getComponent());
+        if(rootComponent != null) {
+            Point componentPoint = new Point(x, y);
+            SwingUtilities.convertPointFromScreen(componentPoint, rootComponent);
+            Component componentAt = SwingUtilities.getDeepestComponentAt(rootComponent, componentPoint.x, componentPoint.y);
+            if(componentAt != hoveringComponent) {
+                if(hoveringComponent != null) {
+                    dragExit(x, y);
+                }
+                if(componentAt != null) {
+                    dragEnter(targetActions, modifiers, x, y);
+                }
+                hoveringComponent = componentAt;
+            }
+        }
+        postDragSourceDragEvent(targetActions, modifiers, x, y,
+                                DISPATCH_MOUSE_MOVED);
+    }
+
+    /**
+     * upcall from native code
+     */
+    private void dragEnter(final int targetActions,
+                           final int modifiers,
+                           final int x, final int y) {
+        CCursorManager.getInstance().updateDragPosition(x, y);
+
+        postDragSourceDragEvent(targetActions, modifiers, x, y, DISPATCH_ENTER);
+    }
+
+    /**
+     * upcall from native code - reset hovering component
+     */
+    private void resetHovering() {
+        hoveringComponent = null;
+    }
+
+    public void setCursor(Cursor c) throws InvalidDnDOperationException {
+        // TODO : BG
+        //AWTLockAccess.awtLock();
+        super.setCursor(c);
+        //AWTLockAccess.awtUnlock();
+    }
+
+    protected native void setNativeCursor(long nativeCtxt, Cursor c, int cType);
+
+    // Native support:
+    private native long createNativeDragSource(Component component, ComponentPeer peer, long nativePeer, Transferable transferable,
+        InputEvent triggerEvent, int dragPosX, int dragPosY, int extModifiers, int clickCount, long timestamp,
+        Cursor cursor, long nsDragImage, int dragImageOffsetX, int dragImageOffsetY,
+        int sourceActions, long[] formats, Map formatMap);
+
+    private native void doDragging(long nativeDragSource);
+
+    private native void releaseNativeDragSource(long nativeDragSource);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTarget.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTarget.java
new file mode 100644
index 0000000..23c8c9f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTarget.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Component;
+import java.awt.peer.ComponentPeer;
+import java.awt.dnd.DropTarget;
+
+import sun.lwawt.LWComponentPeer;
+
+
+public final class CDropTarget {
+
+    Component        fComponent;
+    ComponentPeer    fPeer;
+    DropTarget        fDropTarget;
+    private long    fNativeDropTarget;
+
+    public static CDropTarget createDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer) {
+        return new CDropTarget(dropTarget, component, peer);
+    }
+
+    private CDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer) {
+        super();
+
+        fDropTarget = dropTarget;
+        fComponent = component;
+        fPeer = peer;
+
+        // Make sure the drop target is a ComponentModel:
+        if (!(peer instanceof LWComponentPeer))
+            throw new IllegalArgumentException("CDropTarget's peer must be a LWComponentPeer.");
+
+        // Get model pointer (CButton.m and such) and its native peer:
+        LWComponentPeer model = (LWComponentPeer) peer;
+        CPlatformWindow platformWindow = (CPlatformWindow) model.getPlatformWindow();
+        long nativePeer = platformWindow.getNSWindowPtr();
+
+        // Create native dragging destination:
+        fNativeDropTarget = this.createNativeDropTarget(dropTarget, component, peer, nativePeer);
+        if (fNativeDropTarget == 0)
+            throw new IllegalStateException("CDropTarget.createNativeDropTarget() failed.");
+    }
+
+    public DropTarget getDropTarget() {
+        return fDropTarget;
+    }
+
+    public void dispose() {
+        // Release native dragging destination, if any:
+        if (fNativeDropTarget != 0) {
+            this.releaseNativeDropTarget(fNativeDropTarget);
+            fNativeDropTarget = 0;
+        }
+    }
+
+    protected native long createNativeDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer, long nativePeer);
+    protected native void releaseNativeDropTarget(long nativeDropTarget);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTargetContextPeer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTargetContextPeer.java
new file mode 100644
index 0000000..7f36a79
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTargetContextPeer.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+
+import sun.awt.dnd.SunDropTargetContextPeer;
+import sun.awt.dnd.SunDropTargetEvent;
+
+import javax.swing.*;
+
+
+final class CDropTargetContextPeer extends SunDropTargetContextPeer {
+
+    private long    fNativeDropTransfer = 0;
+    private long    fNativeDataAvailable = 0;
+    private Object  fNativeData    = null;
+    private boolean insideTarget = false;
+
+    Object awtLockAccess = new Object();
+
+    static CDropTargetContextPeer getDropTargetContextPeer() {
+        return new CDropTargetContextPeer();
+    }
+
+    private CDropTargetContextPeer() {
+        super();
+    }
+
+    // We block, waiting for an empty event to get posted (CToolkit.invokeAndWait)
+    // This is so we finish dispatching DropTarget events before we dispatch the dragDropFinished event (which is a higher priority).
+    private void flushEvents(Component c) {
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public synchronized void run() {
+                }
+            }, c);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    protected Object getNativeData(long format) {
+        long nativeDropTarget = this.getNativeDragContext();
+
+        synchronized (awtLockAccess) {
+            fNativeDataAvailable = 0;
+
+            if (fNativeDropTransfer == 0) {
+                fNativeDropTransfer = startTransfer(nativeDropTarget, format);
+            } else {
+                addTransfer(nativeDropTarget, fNativeDropTransfer, format);
+            }
+
+            while (format != fNativeDataAvailable) {
+                try {
+                    awtLockAccess.wait();
+                } catch (Throwable e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        return fNativeData;
+    }
+
+    // We need to take care of dragExit message because for some reason it is not being
+    // generated for lightweight components
+    @Override
+    protected void processMotionMessage(SunDropTargetEvent event, boolean operationChanged) {
+        Component eventSource = (Component)event.getComponent();
+        Component rootComponent = SwingUtilities.getRoot(eventSource);
+        Point screenPoint = event.getPoint();
+        SwingUtilities.convertPointToScreen(screenPoint, rootComponent);
+        Rectangle screenBounds = new Rectangle(eventSource.getLocationOnScreen().x,
+                eventSource.getLocationOnScreen().y,
+                eventSource.getWidth(), eventSource.getHeight());
+        if(insideTarget) {
+            if(!screenBounds.contains(screenPoint)) {
+                processExitMessage(event);
+                insideTarget = false;
+                return;
+            }
+            super.processMotionMessage(event, operationChanged);
+        }
+        insideTarget = screenBounds.contains(screenPoint);
+    }
+
+    @Override
+    protected void processDropMessage(SunDropTargetEvent event) {
+        Component eventSource = (Component)event.getComponent();
+        Component rootComponent = SwingUtilities.getRoot(eventSource);
+        Point screenPoint = event.getPoint();
+        SwingUtilities.convertPointToScreen(screenPoint, rootComponent);
+        Rectangle screenBounds = new Rectangle(eventSource.getLocationOnScreen().x,
+                eventSource.getLocationOnScreen().y,
+                eventSource.getWidth(), eventSource.getHeight());
+        if(!screenBounds.contains(screenPoint)) {
+            super.processDropMessage(event);
+        }
+    }
+
+    // Signal drop complete:
+    protected void doDropDone(boolean success, int dropAction, boolean isLocal) {
+        long nativeDropTarget = this.getNativeDragContext();
+
+        dropDone(nativeDropTarget, fNativeDropTransfer, isLocal, success, dropAction);
+    }
+
+    // Notify transfer complete - this is an upcall from getNativeData's native calls:
+    private void newData(long format, byte[] data) {
+        fNativeDataAvailable = format;
+        fNativeData          = data;
+
+        awtLockAccess.notifyAll();
+    }
+
+    // Notify transfer failed - this is an upcall from getNativeData's native calls:
+    private void transferFailed(long format) {
+        fNativeDataAvailable = format;
+        fNativeData          = null;
+
+        awtLockAccess.notifyAll();
+    }
+
+    // Schedule a native dnd transfer:
+    private native long startTransfer(long nativeDropTarget, long format);
+
+    // Schedule a native dnd data transfer:
+    private native void addTransfer(long nativeDropTarget, long nativeDropTransfer, long format);
+
+    // Notify drop completed:
+    private native void dropDone(long nativeDropTarget, long nativeDropTransfer, boolean isLocal, boolean success, int dropAction);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java
new file mode 100644
index 0000000..5ff47d6
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package sun.lwawt.macosx;
+
+/**
+ * Safely holds and disposes of native AppKit resources, using the
+ * correct AppKit threading and Objective-C GC semantics.
+ */
+public class CFRetainedResource {
+    private static native void nativeCFRelease(final long ptr, final boolean disposeOnAppKitThread);
+
+    final boolean disposeOnAppKitThread;
+    protected long ptr;
+
+    /**
+     * @param ptr CFRetained native object pointer
+     * @param disposeOnAppKitThread is the object needs to be CFReleased on the main thread
+     */
+    protected CFRetainedResource(final long ptr, final boolean disposeOnAppKitThread) {
+        this.disposeOnAppKitThread = disposeOnAppKitThread;
+        this.ptr = ptr;
+    }
+
+    /**
+     * CFReleases previous resource and assigns new pre-retained resource.
+     * @param ptr CFRetained native object pointer
+     */
+    protected void setPtr(final long ptr) {
+        synchronized (this) {
+            if (this.ptr != 0) dispose();
+            this.ptr = ptr;
+        }
+    }
+
+    /**
+     * Manually CFReleases the native resource
+     */
+    protected void dispose() {
+        long oldPtr = 0L;
+        synchronized (this) {
+            if (ptr == 0) return;
+            oldPtr = ptr;
+            ptr = 0;
+        }
+
+        nativeCFRelease(oldPtr, disposeOnAppKitThread); // perform outside of the synchronized block
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        dispose();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java
new file mode 100644
index 0000000..2c55692
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.peer.*;
+import java.awt.BufferCapabilities.FlipContents;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.util.List;
+import java.io.*;
+
+import sun.awt.CausedFocusEvent.Cause;
+import sun.java2d.pipe.Region;
+
+class CFileDialog implements FileDialogPeer {
+
+    private class Task implements Runnable {
+
+        @Override
+        public void run() {
+            try {
+                boolean navigateApps = false;
+                int dialogMode = target.getMode();
+
+                navigateApps = true;
+
+                String title = target.getTitle();
+                if (title == null) {
+                    title = " ";
+                }
+
+                String userFileName = nativeRunFileDialog(title,
+                        dialogMode, navigateApps,
+                        target.getFilenameFilter() != null,
+                        target.getDirectory(),
+                        target.getFile());
+
+                File file = null;
+                if (userFileName != null) {
+                    // the dialog wasn't cancelled
+                    file = new File(userFileName);
+                }
+
+                if (file != null) {
+                    // make sure directory always ends in '/'
+                    String parent = file.getParent();
+                    if (!parent.endsWith(File.separator)) {
+                        parent = parent + File.separator;
+                    }
+
+                    // store results back in component
+                    target.setDirectory(parent);
+                    target.setFile(file.getName());
+                } else {
+                    // setting file name to null is how we tell
+                    // java client that user hit the cancel button
+                    target.setFile(null);
+                }
+            } finally {
+                // Java2 Dialog waits for hide to let show() return
+                target.dispose();
+            }
+        }
+    }
+
+    // The target FileDialog
+    private final FileDialog target;
+
+    CFileDialog(FileDialog target) {
+        this.target = target;
+    }
+
+    @Override
+    public void dispose() {
+        LWCToolkit.targetDisposedPeer(target, this);
+        // Unlike other peers, we do not have a native model pointer to
+        // dispose of because the save and open panels are never released by
+        // an application.
+    }
+
+    @Override
+    public void setVisible(boolean visible) {
+        if (visible) {
+            // Java2 Dialog class requires peer to run code in a separate thread
+            // and handles keeping the call modal
+            new Thread(new Task()).start(); // invokes my 'run' method, below...
+        }
+        // We hide ourself before "show" returns - setVisible(false)
+        // doesn't apply
+    }
+
+    /**
+     * A callback method.
+     * If the file dialog has a file filter, ask it if inFilename is acceptable.
+     * If the dialog doesn't have a file filter return true.
+     */
+    private boolean queryFilenameFilter(final String inFilename) {
+        boolean ret = false;
+
+        final FilenameFilter ff = target.getFilenameFilter();
+        File fileObj = new File(inFilename);
+
+        // Directories are never filtered by the FileDialog.
+        if (!fileObj.isDirectory()) {
+            File directoryObj = new File(fileObj.getParent());
+            String nameOnly = fileObj.getName();
+            ret = ff.accept(directoryObj, nameOnly);
+        }
+        return ret;
+    }
+
+    private native String nativeRunFileDialog(String title, int mode,
+            boolean shouldNavigateApps, boolean hasFilenameFilter,
+            String directory, String file);
+
+    @Override
+    public void setDirectory(String dir) {
+    }
+
+    @Override
+    public void setFile(String file) {
+    }
+
+    @Override
+    public void setFilenameFilter(FilenameFilter filter) {
+    }
+
+    @Override
+    public void blockWindows(List<Window> windows) {
+    }
+
+    @Override
+    public void setResizable(boolean resizeable) {
+    }
+
+    @Override
+    public void setTitle(String title) {
+    }
+
+    @Override
+    public void repositionSecurityWarning() {
+    }
+
+    @Override
+    public void setAlwaysOnTop(boolean alwaysOnTop) {
+    }
+
+    @Override
+    public void setModalBlocked(Dialog blocker, boolean blocked) {
+    }
+
+    @Override
+    public void setOpacity(float opacity) {
+    }
+
+    @Override
+    public void setOpaque(boolean isOpaque) {
+    }
+
+    @Override
+    public void toBack() {
+    }
+
+    @Override
+    public void toFront() {
+    }
+
+    @Override
+    public void updateFocusableWindowState() {
+    }
+
+    @Override
+    public void updateIconImages() {
+    }
+
+    @Override
+    public void updateMinimumSize() {
+    }
+
+    @Override
+    public void updateWindow() {
+    }
+
+    @Override
+    public void beginLayout() {
+    }
+
+    @Override
+    public void beginValidate() {
+    }
+
+    @Override
+    public void endLayout() {
+    }
+
+    @Override
+    public void endValidate() {
+    }
+
+    @Override
+    public Insets getInsets() {
+        return new Insets(0, 0, 0, 0);
+    }
+
+    @Override
+    public void applyShape(Region shape) {
+    }
+
+    @Override
+    public boolean canDetermineObscurity() {
+        return false;
+    }
+
+    @Override
+    public int checkImage(Image img, int w, int h, ImageObserver o) {
+        return 0;
+    }
+
+    @Override
+    public void coalescePaintEvent(PaintEvent e) {
+    }
+
+    @Override
+    public void createBuffers(int numBuffers, BufferCapabilities caps)
+            throws AWTException {
+    }
+
+    @Override
+    public Image createImage(ImageProducer producer) {
+        return null;
+    }
+
+    @Override
+    public Image createImage(int width, int height) {
+        return null;
+    }
+
+    @Override
+    public VolatileImage createVolatileImage(int width, int height) {
+        return null;
+    }
+
+    @Override
+    public void destroyBuffers() {
+    }
+
+    @Override
+    public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) {
+    }
+
+    @Override
+    public Image getBackBuffer() {
+        return null;
+    }
+
+    @Override
+    public ColorModel getColorModel() {
+        return null;
+    }
+
+    @Override
+    public FontMetrics getFontMetrics(Font font) {
+        return null;
+    }
+
+    @Override
+    public Graphics getGraphics() {
+        return null;
+    }
+
+    @Override
+    public GraphicsConfiguration getGraphicsConfiguration() {
+        return null;
+    }
+
+    @Override
+    public Point getLocationOnScreen() {
+        return null;
+    }
+
+    @Override
+    public Dimension getMinimumSize() {
+        return target.getSize();
+    }
+
+    @Override
+    public Dimension getPreferredSize() {
+        return getMinimumSize();
+    }
+
+    @Override
+    public Toolkit getToolkit() {
+        return Toolkit.getDefaultToolkit();
+    }
+
+    @Override
+    public void handleEvent(AWTEvent e) {
+    }
+
+    @Override
+    public boolean handlesWheelScrolling() {
+        return false;
+    }
+
+    @Override
+    public boolean isFocusable() {
+        return false;
+    }
+
+    @Override
+    public boolean isObscured() {
+        return false;
+    }
+
+    @Override
+    public boolean isReparentSupported() {
+        return false;
+    }
+
+    @Override
+    public void layout() {
+    }
+
+    @Override
+    public void paint(Graphics g) {
+    }
+
+    @Override
+    public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
+        return false;
+    }
+
+    @Override
+    public void print(Graphics g) {
+    }
+
+    @Override
+    public void reparent(ContainerPeer newContainer) {
+    }
+
+    @Override
+    public boolean requestFocus(Component lightweightChild, boolean temporary,
+            boolean focusedWindowChangeAllowed, long time, Cause cause) {
+        return false;
+    }
+
+    @Override
+    public void setBackground(Color c) {
+    }
+
+    @Override
+    public void setForeground(Color c) {
+    }
+
+    @Override
+    public void setBounds(int x, int y, int width, int height, int op) {
+    }
+
+    @Override
+    public void setEnabled(boolean e) {
+    }
+
+    @Override
+    public void setFont(Font f) {
+    }
+
+    @Override
+    public void setZOrder(ComponentPeer above) {
+    }
+
+    @Override
+    public void updateCursorImmediately() {
+    }
+
+    @Override
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        return false;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CImage.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CImage.java
new file mode 100644
index 0000000..dea7082
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CImage.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.geom.Dimension2D;
+import java.awt.image.*;
+
+import sun.awt.image.SunWritableRaster;
+
+public class CImage extends CFRetainedResource {
+    private static native long nativeCreateNSImageFromArray(int[] buffer, int w, int h);
+    private static native long nativeCreateNSImageFromFileContents(String file);
+    private static native long nativeCreateNSImageOfFileFromLaunchServices(String file);
+    private static native long nativeCreateNSImageFromImageName(String name);
+    private static native long nativeCreateNSImageFromIconSelector(int selector);
+    private static native void nativeCopyNSImageIntoArray(long image, int[] buffer, int w, int h);
+    private static native Dimension2D nativeGetNSImageSize(long image);
+    private static native void nativeSetNSImageSize(long image, double w, double h);
+
+    static Creator creator = new Creator();
+    static Creator getCreator() {
+        return creator;
+    }
+
+    public static class Creator {
+        Creator() { }
+
+        // This is used to create a CImage with an NSImage pointer. It MUST be a CFRetained
+        // NSImage, and the CImage takes ownership of the non-GC retain. If callers need the
+        // NSImage themselves, they MUST call retain on the NSImage themselves.
+        public BufferedImage createImageUsingNativeSize(final long image) {
+            if (image == 0) return null;
+            final Dimension2D size = nativeGetNSImageSize(image);
+            return createBufferedImage(image, size.getWidth(), size.getHeight());
+        }
+
+        // the width and height passed in as a parameter could differ than the width and the height of the NSImage (image), in that case, the image will be scaled
+        BufferedImage createBufferedImage(long image, double width, double height) {
+            if (image == 0) throw new Error("Unable to instantiate CImage with null native image reference.");
+            return createImageWithSize(image, width, height);
+        }
+
+        public BufferedImage createImageWithSize(final long image, final double width, final double height) {
+            final CImage img = new CImage(image);
+            img.resize(width, height);
+            return img.toImage();
+        }
+
+        // This is used to create a CImage that represents the icon of the given file.
+        public BufferedImage createImageOfFile(final String file, final int width, final int height) {
+            return createBufferedImage(nativeCreateNSImageOfFileFromLaunchServices(file), width, height);
+        }
+
+        public BufferedImage createImageFromFile(final String file, final double width, final double height) {
+            final long image = nativeCreateNSImageFromFileContents(file);
+            nativeSetNSImageSize(image, width, height);
+            return createBufferedImage(image, width, height);
+        }
+
+        public BufferedImage createSystemImageFromSelector(final String iconSelector, final int width, final int height) {
+            return createBufferedImage(nativeCreateNSImageFromIconSelector(getSelectorAsInt(iconSelector)), width, height);
+        }
+
+        public Image createImageFromName(final String name, final int width, final int height) {
+            return createBufferedImage(nativeCreateNSImageFromImageName(name), width, height);
+        }
+
+        public Image createImageFromName(final String name) {
+            return createImageUsingNativeSize(nativeCreateNSImageFromImageName(name));
+        }
+
+        // This is used to create a CImage from a Image
+        public CImage createFromImage(final Image image) {
+            if (image == null) return null;
+
+            MediaTracker mt = new MediaTracker(new Label());
+            final int id = 0;
+            mt.addImage(image, id);
+
+            try {
+                mt.waitForID(id);
+            } catch (InterruptedException e) {
+            }
+
+            if (mt.isErrorID(id)) {
+                return null;
+            }
+
+            int w = image.getWidth(null);
+            int h = image.getHeight(null);
+            BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
+            Graphics2D g2 = bimg.createGraphics();
+            g2.setComposite(AlphaComposite.Src);
+            g2.drawImage(image, 0, 0, null);
+            g2.dispose();
+            int[] buffer = ((DataBufferInt)bimg.getRaster().getDataBuffer()).getData();
+            return new CImage(nativeCreateNSImageFromArray(buffer, w, h));
+        }
+
+        static int getSelectorAsInt(final String fromString) {
+            final byte[] b = fromString.getBytes();
+            final int len = Math.min(b.length, 4);
+            int result = 0;
+            for (int i = 0; i < len; i++) {
+                if (i > 0) result <<= 8;
+                result |= (b[i] & 0xff);
+            }
+            return result;
+        }
+    }
+
+    CImage(long nsImagePtr) {
+        super(nsImagePtr, true);
+    }
+
+    /** @return A BufferedImage created from nsImagePtr, or null. */
+    public BufferedImage toImage() {
+        if (ptr == 0) return null;
+
+        final Dimension2D size = nativeGetNSImageSize(ptr);
+        final int w = (int)size.getWidth();
+        final int h = (int)size.getHeight();
+
+        final BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
+        final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
+        final int[] buffer = SunWritableRaster.stealData(dbi, 0);
+        nativeCopyNSImageIntoArray(ptr, buffer, w, h);
+        SunWritableRaster.markDirty(dbi);
+        return bimg;
+    }
+
+    /** If nsImagePtr != 0 then scale this NSImage. @return *this* */
+    CImage resize(final double w, final double h) {
+        if (ptr != 0) nativeSetNSImageSize(ptr, w, h);
+        return this;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
new file mode 100644
index 0000000..b4bebba
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
@@ -0,0 +1,813 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.im.spi.*;
+import java.util.*;
+import java.awt.*;
+import java.awt.peer.*;
+import java.awt.event.*;
+import java.awt.im.*;
+import java.awt.font.*;
+import java.lang.Character.Subset;
+import java.lang.reflect.InvocationTargetException;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.text.*;
+import javax.swing.text.JTextComponent;
+
+import sun.awt.im.InputMethodAdapter;
+import sun.lwawt.*;
+
+public class CInputMethod extends InputMethodAdapter {
+    private InputMethodContext fIMContext;
+    private Component fAwtFocussedComponent;
+    private LWComponentPeer fAwtFocussedComponentPeer;
+    private boolean isActive;
+
+    private static Map<TextAttribute, Integer>[] sHighlightStyles;
+
+    // Intitalize highlight mapping table and its mapper.
+    static {
+        Map<TextAttribute, Integer> styles[] = new Map[4];
+        HashMap<TextAttribute, Integer> map;
+
+        // UNSELECTED_RAW_TEXT_HIGHLIGHT
+        map = new HashMap<TextAttribute, Integer>(1);
+        map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
+                TextAttribute.UNDERLINE_LOW_GRAY);
+        styles[0] = Collections.unmodifiableMap(map);
+
+        // SELECTED_RAW_TEXT_HIGHLIGHT
+        map = new HashMap<TextAttribute, Integer>(1);
+        map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
+                TextAttribute.UNDERLINE_LOW_GRAY);
+        styles[1] = Collections.unmodifiableMap(map);
+
+        // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
+        map = new HashMap<TextAttribute, Integer>(1);
+        map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
+                TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
+        styles[2] = Collections.unmodifiableMap(map);
+
+        // SELECTED_CONVERTED_TEXT_HIGHLIGHT
+        map = new HashMap<TextAttribute, Integer>(1);
+        map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
+                TextAttribute.UNDERLINE_LOW_TWO_PIXEL);
+        styles[3] = Collections.unmodifiableMap(map);
+
+        sHighlightStyles = styles;
+
+        nativeInit();
+
+    }
+
+    public CInputMethod() {
+    }
+
+
+    /**
+        * Sets the input method context, which is used to dispatch input method
+     * events to the client component and to request information from
+     * the client component.
+     * <p>
+     * This method is called once immediately after instantiating this input
+     * method.
+     *
+     * @param context the input method context for this input method
+     * @exception NullPointerException if <code>context</code> is null
+     */
+    public void setInputMethodContext(InputMethodContext context) {
+        fIMContext = context;
+    }
+
+    /**
+        * Attempts to set the input locale. If the input method supports the
+     * desired locale, it changes its behavior to support input for the locale
+     * and returns true.
+     * Otherwise, it returns false and does not change its behavior.
+     * <p>
+     * This method is called
+     * <ul>
+     * <li>by {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
+     * <li>when switching to this input method through the user interface if the user
+     *     specified a locale or if the previously selected input method's
+     *     {@link java.awt.im.spi.InputMethod#getLocale getLocale} method
+     *     returns a non-null value.
+     * </ul>
+     *
+     * @param lang locale to input
+     * @return whether the specified locale is supported
+     * @exception NullPointerException if <code>locale</code> is null
+     */
+    public boolean setLocale(Locale lang) {
+        return setLocale(lang, false);
+    }
+
+    private boolean setLocale(Locale lang, boolean onActivate) {
+        Object[] available = CInputMethodDescriptor.getAvailableLocalesInternal();
+        for (int i = 0; i < available.length; i++) {
+            Locale locale = (Locale)available[i];
+            if (lang.equals(locale) ||
+                // special compatibility rule for Japanese and Korean
+                locale.equals(Locale.JAPAN) && lang.equals(Locale.JAPANESE) ||
+                locale.equals(Locale.KOREA) && lang.equals(Locale.KOREAN)) {
+                if (isActive) {
+                    setNativeLocale(locale.toString(), onActivate);
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+        * Returns the current input locale. Might return null in exceptional cases.
+     * <p>
+     * This method is called
+     * <ul>
+     * <li>by {@link java.awt.im.InputContext#getLocale InputContext.getLocale} and
+     * <li>when switching from this input method to a different one through the
+     *     user interface.
+     * </ul>
+     *
+     * @return the current input locale, or null
+     */
+    public Locale getLocale() {
+        // On Mac OS X we'll ask the currently active input method what its locale is.
+        Locale returnValue = getNativeLocale();
+        if (returnValue == null) {
+            returnValue = Locale.getDefault();
+        }
+
+        return returnValue;
+    }
+
+    /**
+        * Sets the subsets of the Unicode character set that this input method
+     * is allowed to input. Null may be passed in to indicate that all
+     * characters are allowed.
+     * <p>
+     * This method is called
+     * <ul>
+     * <li>immediately after instantiating this input method,
+     * <li>when switching to this input method from a different one, and
+     * <li>by {@link java.awt.im.InputContext#setCharacterSubsets InputContext.setCharacterSubsets}.
+     * </ul>
+     *
+     * @param subsets the subsets of the Unicode character set from which
+     * characters may be input
+     */
+    public void setCharacterSubsets(Subset[] subsets) {
+        // -- SAK: Does mac OS X support this?
+    }
+
+    /**
+        * Composition cannot be set on Mac OS X -- the input method remembers this
+     */
+    public void setCompositionEnabled(boolean enable) {
+        throw new UnsupportedOperationException("Can't adjust composition mode on Mac OS X.");
+    }
+
+    public boolean isCompositionEnabled() {
+        throw new UnsupportedOperationException("Can't adjust composition mode on Mac OS X.");
+    }
+
+    /**
+     * Dispatches the event to the input method. If input method support is
+     * enabled for the focussed component, incoming events of certain types
+     * are dispatched to the current input method for this component before
+     * they are dispatched to the component's methods or event listeners.
+     * The input method decides whether it needs to handle the event. If it
+     * does, it also calls the event's <code>consume</code> method; this
+     * causes the event to not get dispatched to the component's event
+     * processing methods or event listeners.
+     * <p>
+     * Events are dispatched if they are instances of InputEvent or its
+     * subclasses.
+     * This includes instances of the AWT classes KeyEvent and MouseEvent.
+     * <p>
+     * This method is called by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}.
+     *
+     * @param event the event being dispatched to the input method
+     * @exception NullPointerException if <code>event</code> is null
+     */
+    public void dispatchEvent(final AWTEvent event) {
+        // No-op for Mac OS X.
+    }
+
+
+    /**
+     * Activate and deactivate are no-ops on Mac OS X.
+     * A non-US keyboard layout is an 'input method' in that it generates events the same way as
+     * a CJK input method. A component that doesn't want input method events still wants the dead-key
+     * events.
+     *
+     *
+     */
+    public void activate() {
+        isActive = true;
+    }
+
+    public void deactivate(boolean isTemporary) {
+        isActive = false;
+    }
+
+    /**
+     * Closes or hides all windows opened by this input method instance or
+     * its class.  Deactivate hides windows for us on Mac OS X.
+     */
+    public void hideWindows() {
+    }
+
+    long getNativeViewPtr(LWComponentPeer peer) {
+        CPlatformWindow platformWindow = (CPlatformWindow) peer.getPlatformWindow();
+        CPlatformView platformView = platformWindow.getContentView();
+        return platformView.getAWTView();
+    }
+
+    /**
+        * Notifies the input method that a client component has been
+     * removed from its containment hierarchy, or that input method
+     * support has been disabled for the component.
+     */
+    public void removeNotify() {
+        if (fAwtFocussedComponentPeer != null) {
+            nativeEndComposition(getNativeViewPtr(fAwtFocussedComponentPeer));
+        }
+
+        fAwtFocussedComponentPeer = null;
+    }
+
+    /**
+     * Informs the input method adapter about the component that has the AWT
+     * focus if it's using the input context owning this adapter instance.
+     * We also take the opportunity to tell the native side that we are the input method
+     * to talk to when responding to key events.
+     */
+    protected void setAWTFocussedComponent(Component component) {
+        LWComponentPeer peer = null;
+        long modelPtr = 0;
+        CInputMethod imInstance = this;
+
+        // component will be null when we are told there's no focused component.
+        // When that happens we need to notify the native architecture to stop generating IMEs
+        if (component == null) {
+            peer = fAwtFocussedComponentPeer;
+            imInstance = null;
+        } else {
+            peer = getNearestNativePeer(component);
+
+            // If we have a passive client, don't pass input method events to it.
+            if (component.getInputMethodRequests() == null) {
+                imInstance = null;
+            }
+        }
+
+        if (peer != null) {
+            modelPtr = getNativeViewPtr(peer);
+
+            // modelPtr refers to the ControlModel that either got or lost focus.
+            nativeNotifyPeer(modelPtr, imInstance);
+        }
+
+        // Track the focused component and its nearest peer.
+        fAwtFocussedComponent = component;
+        fAwtFocussedComponentPeer = getNearestNativePeer(component);
+    }
+
+    /**
+        * @see java.awt.Toolkit#mapInputMethodHighlight
+     */
+    public static Map mapInputMethodHighlight(InputMethodHighlight highlight) {
+        int index;
+        int state = highlight.getState();
+        if (state == InputMethodHighlight.RAW_TEXT) {
+            index = 0;
+        } else if (state == InputMethodHighlight.CONVERTED_TEXT) {
+            index = 2;
+        } else {
+            return null;
+        }
+        if (highlight.isSelected()) {
+            index += 1;
+        }
+        return sHighlightStyles[index];
+    }
+
+    /**
+        * Ends any input composition that may currently be going on in this
+     * context. Depending on the platform and possibly user preferences,
+     * this may commit or delete uncommitted text. Any changes to the text
+     * are communicated to the active component using an input method event.
+     *
+     * <p>
+     * A text editing component may call this in a variety of situations,
+     * for example, when the user moves the insertion point within the text
+     * (but outside the composed text), or when the component's text is
+     * saved to a file or copied to the clipboard.
+     * <p>
+     * This method is called
+     * <ul>
+     * <li>by {@link java.awt.im.InputContext#endComposition InputContext.endComposition},
+     * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
+     *     when switching to a different client component
+     * <li>when switching from this input method to a different one using the
+     *     user interface or
+     *     {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
+     * </ul>
+     */
+    public void endComposition() {
+        if (fAwtFocussedComponentPeer != null)
+            nativeEndComposition(getNativeViewPtr(fAwtFocussedComponentPeer));
+    }
+
+    /**
+        * Disposes of the input method and releases the resources used by it.
+     * In particular, the input method should dispose windows and close files that are no
+     * longer needed.
+     * <p>
+     * This method is called by {@link java.awt.im.InputContext#dispose InputContext.dispose}.
+     * <p>
+     * The method is only called when the input method is inactive.
+     * No method of this interface is called on this instance after dispose.
+     */
+    public void dispose() {
+        fIMContext = null;
+        fAwtFocussedComponent = null;
+        fAwtFocussedComponentPeer = null;
+    }
+
+    /**
+        * Returns a control object from this input method, or null. A
+     * control object provides methods that control the behavior of the
+     * input method or obtain information from the input method. The type
+     * of the object is an input method specific class. Clients have to
+     * compare the result against known input method control object
+     * classes and cast to the appropriate class to invoke the methods
+     * provided.
+     * <p>
+     * This method is called by
+     * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}.
+     *
+     * @return a control object from this input method, or null
+     */
+    public Object getControlObject() {
+        return null;
+    }
+
+    // java.awt.Toolkit#getNativeContainer() is not available
+    //    from this package
+    private LWComponentPeer getNearestNativePeer(Component comp) {
+        if (comp==null)
+            return null;
+
+        ComponentPeer peer = comp.getPeer();
+        if (peer==null)
+            return null;
+
+        while (peer instanceof java.awt.peer.LightweightPeer) {
+            comp = comp.getParent();
+            if (comp==null)
+                return null;
+            peer = comp.getPeer();
+            if (peer==null)
+                return null;
+        }
+
+        if (peer instanceof LWComponentPeer)
+            return (LWComponentPeer)peer;
+
+        return null;
+    }
+
+    // =========================== NSTextInput callbacks ===========================
+    // The 'marked text' that we get from Cocoa.  We need to track this separately, since
+    // Java doesn't let us ask the IM context for it.
+    private AttributedString fCurrentText = null;
+    private String fCurrentTextAsString = null;
+    private int fCurrentTextLength = 0;
+
+    /**
+     * Tell the component to commit all of the characters in the string to the current
+     * text view. This effectively wipes out any text in progress.
+     */
+    synchronized private void insertText(String aString) {
+        AttributedString attribString = new AttributedString(aString);
+
+        // Set locale information on the new string.
+        attribString.addAttribute(Attribute.LANGUAGE, getLocale(), 0, aString.length());
+
+        TextHitInfo theCaret = TextHitInfo.afterOffset(aString.length() - 1);
+        InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
+                                                      InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
+                                                      attribString.getIterator(),
+                                                      aString.length(),
+                                                      theCaret,
+                                                      theCaret);
+        LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
+        fCurrentText = null;
+        fCurrentTextAsString = null;
+        fCurrentTextLength = 0;
+    }
+
+    private void startIMUpdate (String rawText) {
+        fCurrentTextAsString = new String(rawText);
+        fCurrentText = new AttributedString(fCurrentTextAsString);
+        fCurrentTextLength = rawText.length();
+    }
+
+    static private final int kCaretPosition = 0;
+    static private final int kRawText = 1;
+    static private final int kSelectedRawText = 2;
+    static private final int kConvertedText = 3;
+    static private final int kSelectedConvertedText = 4;
+
+    /**
+     * Convert Cocoa text highlight attributes into Java input method highlighting.
+     */
+    private void addAttribute (boolean isThickUnderline, boolean isGray, int start, int length) {
+        int begin = start;
+        int end = start + length;
+        int markupType = kRawText;
+
+        if (isThickUnderline && isGray) {
+            markupType = kRawText;
+        } else if (!isThickUnderline && isGray) {
+            markupType = kRawText;
+        } else if (isThickUnderline && !isGray) {
+            markupType = kSelectedConvertedText;
+        } else if (!isThickUnderline && !isGray) {
+            markupType = kConvertedText;
+        }
+
+        InputMethodHighlight theHighlight;
+
+        switch (markupType) {
+            case kSelectedRawText:
+                theHighlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
+                break;
+            case kConvertedText:
+                theHighlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
+                break;
+            case kSelectedConvertedText:
+                theHighlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
+                break;
+            case kRawText:
+            default:
+                theHighlight = InputMethodHighlight.UNSELECTED_RAW_TEXT_HIGHLIGHT;
+                break;
+        }
+
+        fCurrentText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, theHighlight, begin, end);
+    }
+
+   /* Called from JNI to select the previously typed glyph during press and hold */
+    private void selectPreviousGlyph() {
+        if (fIMContext == null) return; // ???
+        try {
+            LWCToolkit.invokeLater(new Runnable() {
+                public void run() {
+                    final int offset = fIMContext.getInsertPositionOffset();
+                    if (offset < 1) return; // ???
+
+                    if (fAwtFocussedComponent instanceof JTextComponent) {
+                        ((JTextComponent) fAwtFocussedComponent).select(offset - 1, offset);
+                        return;
+                    }
+
+                    if (fAwtFocussedComponent instanceof TextComponent) {
+                        ((TextComponent) fAwtFocussedComponent).select(offset - 1, offset);
+                        return;
+                    }
+                    // TODO: Ideally we want to disable press-and-hold in this case
+                }
+            }, fAwtFocussedComponent);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void selectNextGlyph() {
+        if (fIMContext == null || !(fAwtFocussedComponent instanceof JTextComponent)) return;
+        try {
+            LWCToolkit.invokeLater(new Runnable() {
+                public void run() {
+                    final int offset = fIMContext.getInsertPositionOffset();
+                    if (offset < 0) return;
+                    ((JTextComponent) fAwtFocussedComponent).select(offset, offset + 1);
+                    return;
+                }
+            }, fAwtFocussedComponent);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void dispatchText(int selectStart, int selectLength, boolean pressAndHold) {
+        // Nothing to do if we have no text.
+        if (fCurrentText == null)
+            return;
+
+        TextHitInfo theCaret = (selectLength == 0 ? TextHitInfo.beforeOffset(selectStart) : null);
+        TextHitInfo visiblePosition = TextHitInfo.beforeOffset(0);
+
+        InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
+                                                      InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
+                                                      fCurrentText.getIterator(),
+                                                      0,
+                                                      theCaret,
+                                                      visiblePosition);
+        LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
+
+        if (pressAndHold) selectNextGlyph();
+    }
+
+    /**
+     * Frequent callbacks from NSTextInput.  I think we're supposed to commit it here?
+     */
+    synchronized private void unmarkText() {
+        if (fCurrentText == null)
+            return;
+
+        TextHitInfo theCaret = TextHitInfo.afterOffset(fCurrentTextLength);
+        TextHitInfo visiblePosition = theCaret;
+        InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
+                                                      InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
+                                                      fCurrentText.getIterator(),
+                                                      fCurrentTextLength,
+                                                      theCaret,
+                                                      visiblePosition);
+        LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
+        fCurrentText = null;
+        fCurrentTextAsString = null;
+        fCurrentTextLength = 0;
+    }
+
+    synchronized private boolean hasMarkedText() {
+        return fCurrentText != null;
+    }
+
+    /**
+        * Cocoa assumes the marked text and committed text is all stored in the same storage, but
+     * Java does not.  So, we have to see where the request is and based on that return the right
+     * substring.
+     */
+    synchronized private String attributedSubstringFromRange(final int locationIn, final int lengthIn) {
+        final String[] retString = new String[1];
+
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public void run() { synchronized(retString) {
+                    int location = locationIn;
+                    int length = lengthIn;
+
+                    if ((location + length) > (fIMContext.getCommittedTextLength() + fCurrentTextLength)) {
+                        length = fIMContext.getCommittedTextLength() - location;
+                    }
+
+                    AttributedCharacterIterator theIterator = null;
+
+                    if (fCurrentText == null) {
+                        theIterator = fIMContext.getCommittedText(location, location + length, null);
+                    } else {
+                        int insertSpot = fIMContext.getInsertPositionOffset();
+
+                        if (location < insertSpot) {
+                            theIterator = fIMContext.getCommittedText(location, location + length, null);
+                        } else if (location >= insertSpot && location < insertSpot + fCurrentTextLength) {
+                            theIterator = fCurrentText.getIterator(null, location - insertSpot, location - insertSpot +length);
+                        } else  {
+                            theIterator = fIMContext.getCommittedText(location - fCurrentTextLength, location - fCurrentTextLength + length, null);
+                        }
+                    }
+
+                    // Get the characters from the iterator
+                    char selectedText[] = new char[theIterator.getEndIndex() - theIterator.getBeginIndex()];
+                    char current = theIterator.first();
+                    int index = 0;
+                    while (current != CharacterIterator.DONE) {
+                        selectedText[index++] = current;
+                        current = theIterator.next();
+                    }
+
+                    retString[0] = new String(selectedText);
+                }}
+            }, fAwtFocussedComponent);
+        } catch (InterruptedException ie) { ie.printStackTrace(); }
+        catch (InvocationTargetException ite) { ite.printStackTrace(); }
+
+        synchronized(retString) { return retString[0]; }
+    }
+
+    /**
+     * Cocoa wants the range of characters that are currently selected.  We have to synthesize this
+     * by getting the insert location and the length of the selected text. NB:  This does NOT allow
+     * for the fact that the insert point in Swing can come AFTER the selected text, making this
+     * potentially incorrect.
+     */
+    synchronized private int[] selectedRange() {
+        final int[] returnValue = new int[2];
+
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public void run() { synchronized(returnValue) {
+                    AttributedCharacterIterator theIterator = fIMContext.getSelectedText(null);
+                    if (theIterator == null) {
+                        returnValue[0] = fIMContext.getInsertPositionOffset();
+                        returnValue[1] = 0;
+                        return;
+                    }
+
+                    int startLocation;
+
+                    if (fAwtFocussedComponent instanceof JTextComponent) {
+                        JTextComponent theComponent = (JTextComponent)fAwtFocussedComponent;
+                        startLocation = theComponent.getSelectionStart();
+                    } else if (fAwtFocussedComponent instanceof TextComponent) {
+                        TextComponent theComponent = (TextComponent)fAwtFocussedComponent;
+                        startLocation = theComponent.getSelectionStart();
+                    } else {
+                        // If we don't have a Swing or AWT component, we have to guess whether the selection is before or after the input spot.
+                        startLocation = fIMContext.getInsertPositionOffset() - (theIterator.getEndIndex() - theIterator.getBeginIndex());
+
+                        // If the calculated spot is negative the insert spot must be at the beginning of
+                        // the selection.
+                        if (startLocation <  0) {
+                            startLocation = fIMContext.getInsertPositionOffset() + (theIterator.getEndIndex() - theIterator.getBeginIndex());
+                        }
+                    }
+
+                    returnValue[0] = startLocation;
+                    returnValue[1] = theIterator.getEndIndex() - theIterator.getBeginIndex();
+
+                }}
+            }, fAwtFocussedComponent);
+        } catch (InterruptedException ie) { ie.printStackTrace(); }
+        catch (InvocationTargetException ite) { ite.printStackTrace(); }
+
+        synchronized(returnValue) { return returnValue; }
+    }
+
+    /**
+     * Cocoa wants the range of characters that are currently marked.  Since Java doesn't store committed and
+     * text in progress (composed text) together, we have to synthesize it.  We know where the text will be
+     * inserted, so we can return that position, and the length of the text in progress.  If there is no marked text
+     * return null.
+     */
+    synchronized private int[] markedRange() {
+        if (fCurrentText == null)
+            return null;
+
+        final int[] returnValue = new int[2];
+
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public void run() { synchronized(returnValue) {
+                    // The insert position is always after the composed text, so the range start is the
+                    // insert spot less the length of the composed text.
+                    returnValue[0] = fIMContext.getInsertPositionOffset();
+                }}
+            }, fAwtFocussedComponent);
+        } catch (InterruptedException ie) { ie.printStackTrace(); }
+        catch (InvocationTargetException ite) { ite.printStackTrace(); }
+
+        returnValue[1] = fCurrentTextLength;
+        synchronized(returnValue) { return returnValue; }
+    }
+
+    /**
+     * Cocoa wants a rectangle that describes where a particular range is on screen, but only cares about the
+     * location of that rectangle.  We are given the index of the character for which we want the location on
+     * screen, which will be a character in the in-progress text.  By subtracting the current insert position,
+     * which is always in front of the in-progress text, we get the offset into the composed text, and we get
+     * that location from the input method context.
+     */
+    synchronized private int[] firstRectForCharacterRange(final int absoluteTextOffset) {
+        final int[] rect = new int[4];
+
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public void run() { synchronized(rect) {
+                    int insertOffset = fIMContext.getInsertPositionOffset();
+                    int composedTextOffset = absoluteTextOffset - insertOffset;
+                    if (composedTextOffset < 0) composedTextOffset = 0;
+                    Rectangle r = fIMContext.getTextLocation(TextHitInfo.beforeOffset(composedTextOffset));
+                    rect[0] = r.x;
+                    rect[1] = r.y;
+                    rect[2] = r.width;
+                    rect[3] = r.height;
+
+                    // This next if-block is a hack to work around a bug in JTextComponent. getTextLocation ignores
+                    // the TextHitInfo passed to it and always returns the location of the insertion point, which is
+                    // at the start of the composed text.  We'll do some calculation so the candidate window for Kotoeri
+                    // follows the requested offset into the composed text.
+                    if (composedTextOffset > 0 && (fAwtFocussedComponent instanceof JTextComponent)) {
+                        Rectangle r2 = fIMContext.getTextLocation(TextHitInfo.beforeOffset(0));
+
+                        if (r.equals(r2)) {
+                            // FIXME: (SAK) If the candidate text wraps over two lines, this calculation pushes the candidate
+                            // window off the right edge of the component.
+                            String inProgressSubstring = fCurrentTextAsString.substring(0, composedTextOffset);
+                            Graphics g = fAwtFocussedComponent.getGraphics();
+                            int xOffset = g.getFontMetrics().stringWidth(inProgressSubstring);
+                            rect[0] += xOffset;
+                            g.dispose();
+                        }
+                    }
+                }}
+            }, fAwtFocussedComponent);
+        } catch (InterruptedException ie) { ie.printStackTrace(); }
+        catch (InvocationTargetException ite) { ite.printStackTrace(); }
+
+        synchronized(rect) { return rect; }
+    }
+
+    /* This method returns the index for the character that is nearest to the point described by screenX and screenY.
+     * The coordinates are in Java screen coordinates.  If no character in the composed text was hit, we return -1, indicating
+     * not found.
+     */
+    synchronized private int characterIndexForPoint(final int screenX, final int screenY) {
+        final TextHitInfo[] offsetInfo = new TextHitInfo[1];
+        final int[] insertPositionOffset = new int[1];
+
+        try {
+            LWCToolkit.invokeAndWait(new Runnable() {
+                public void run() { synchronized(offsetInfo) {
+                    offsetInfo[0] = fIMContext.getLocationOffset(screenX, screenY);
+                    insertPositionOffset[0] = fIMContext.getInsertPositionOffset();
+                }}
+            }, fAwtFocussedComponent);
+        } catch (InterruptedException ie) { ie.printStackTrace(); }
+        catch (InvocationTargetException ite) { ite.printStackTrace(); }
+
+        // This bit of gymnastics ensures that the returned location is within the composed text.
+        // If it falls outside that region, the input method will commit the text, which is inconsistent with native
+        // Cocoa apps (see TextEdit, for example.)  Clicking to the left of or above the selected text moves the
+        // cursor to the start of the composed text, and to the right or below moves it to one character before the end.
+        if (offsetInfo[0] == null) {
+            return insertPositionOffset[0];
+        }
+
+        int returnValue = offsetInfo[0].getCharIndex() + insertPositionOffset[0];
+
+        if (offsetInfo[0].getCharIndex() == fCurrentTextLength)
+            returnValue --;
+
+        return returnValue;
+    }
+
+    // On Mac OS X we effectively disabled the input method when focus was lost, so
+    // this call can be ignored.
+    public void disableInputMethod()
+    {
+        // Deliberately ignored. See setAWTFocussedComponent above.
+    }
+
+    public String getNativeInputMethodInfo()
+    {
+        return nativeGetCurrentInputMethodInfo();
+    }
+
+
+    // =========================== Native methods ===========================
+    // Note that if nativePeer isn't something that normally accepts keystrokes (i.e., a CPanel)
+    // these calls will be ignored.
+    private native void nativeNotifyPeer(long nativePeer, CInputMethod imInstance);
+    private native void nativeEndComposition(long nativePeer);
+    private native void nativeHandleEvent(LWComponentPeer peer, AWTEvent event);
+
+    // Returns the locale of the active input method.
+    static native Locale getNativeLocale();
+
+    // Switches to the input method with language indicated in localeName
+    static native boolean setNativeLocale(String localeName, boolean onActivate);
+
+    // Returns information about the currently selected input method.
+    static native String nativeGetCurrentInputMethodInfo();
+
+    // Initialize toolbox routines
+    static native void nativeInit();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CInputMethodDescriptor.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CInputMethodDescriptor.java
new file mode 100644
index 0000000..d25d508
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CInputMethodDescriptor.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.im.spi.*;
+import java.util.*;
+import java.util.List;
+
+/**
+* Provides sufficient information about an input method
+ * to enable selection and loading of that input method.
+ * The input method itself is only loaded when it is actually used.
+ */
+
+public class CInputMethodDescriptor implements InputMethodDescriptor {
+
+    static {
+        nativeInit();
+    }
+
+    public CInputMethodDescriptor() {
+    }
+
+    /**
+     * @see java.awt.im.spi.InputMethodDescriptor#getAvailableLocales
+     */
+    public Locale[] getAvailableLocales() {
+        // returns a copy of internal list for public API
+        Object[] locales = getAvailableLocalesInternal();
+        Locale[] tmp = new Locale[locales.length];
+        System.arraycopy(locales, 0, tmp, 0, locales.length);
+        return tmp;
+    }
+
+    static Object[] getAvailableLocalesInternal() {
+        List workList = nativeGetAvailableLocales();
+
+        if (workList != null) {
+            return workList.toArray();
+        }
+
+        return new Object[] {
+            Locale.getDefault()
+        };
+    }
+
+    /**
+        * @see java.awt.im.spi.InputMethodDescriptor#hasDynamicLocaleList
+     */
+    public boolean hasDynamicLocaleList() {
+        return false;
+    }
+
+    /**
+        * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodDisplayName
+     */
+    public synchronized String getInputMethodDisplayName(Locale inputLocale, Locale displayLanguage) {
+        String name = "System Input Methods";
+        if (Locale.getDefault().equals(displayLanguage)) {
+            name = Toolkit.getProperty("AWT.HostInputMethodDisplayName", name);
+        }
+        return name;
+    }
+
+    /**
+        * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodIcon
+     */
+    public Image getInputMethodIcon(Locale inputLocale) {
+        // This should return the flag icon corresponding to the input Locale.
+        return null;
+    }
+
+    /**
+        * @see java.awt.im.spi.InputMethodDescriptor#createInputMethod
+     */
+    public InputMethod createInputMethod() throws Exception {
+        return new CInputMethod();
+    }
+
+    public String toString() {
+        Locale loc[] = getAvailableLocales();
+        String locnames = null;
+
+        for (int i = 0; i < loc.length; i++) {
+            if (locnames == null) {
+                locnames = loc[i].toString();
+            } else {
+                locnames += "," + loc[i];
+            }
+        }
+        return getClass().getName() + "[" +
+            "locales=" + locnames +
+            ",localelist=" + (hasDynamicLocaleList() ? "dynamic" : "static") +
+            "]";
+    }
+
+    private static native void nativeInit();
+    private static native List nativeGetAvailableLocales();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CMenu.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenu.java
new file mode 100644
index 0000000..56a7061
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenu.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.peer.MenuPeer;
+
+public class CMenu extends CMenuItem implements MenuPeer {
+    public CMenu(Menu target) {
+        super(target);
+    }
+
+    // This way we avoiding invocation of the setters twice
+    @Override
+    protected void initialize(MenuItem target) {
+        setLabel(target.getLabel());
+        setEnabled(target.isEnabled());
+    }
+
+    @Override
+    protected long createModel() {
+        CMenuComponent parent = (CMenuComponent)
+            LWCToolkit.targetToPeer(getTarget().getParent());
+
+        if (parent instanceof CMenu ||
+            parent instanceof CPopupMenu)
+        {
+            return nativeCreateSubMenu(parent.getModel());
+        } else if (parent instanceof CMenuBar) {
+            MenuBar parentContainer = (MenuBar)getTarget().getParent();
+            boolean isHelpMenu = parentContainer.getHelpMenu() == getTarget();
+            int insertionLocation = ((CMenuBar)parent).getNextInsertionIndex();
+            return nativeCreateMenu(parent.getModel(),
+                                    isHelpMenu, insertionLocation);
+        } else {
+            throw new InternalError("Parent must be CMenu or CMenuBar");
+        }
+    }
+
+    @Override
+    public void addItem(MenuItem item) {
+        // Nothing to do here -- we added it when we created the
+        // menu item's peer.
+    }
+
+    @Override
+    public void delItem(int index) {
+        nativeDeleteItem(getModel(), index);
+    }
+
+    @Override
+    public void setLabel(String label) {
+        nativeSetMenuTitle(getModel(), label);
+        super.setLabel(label);
+    }
+
+    // Note that addSeparator is never called directly from java.awt.Menu,
+    // though it is required in the MenuPeer interface.
+    @Override
+    public void addSeparator() {
+        nativeAddSeparator(getModel());
+    }
+
+    // Used by ScreenMenuBar to get to the native menu for event handling.
+    public long getNativeMenu() {
+        return nativeGetNSMenu(getModel());
+    }
+
+    private native long nativeCreateMenu(long parentMenuPtr,
+                                         boolean isHelpMenu,
+                                         int insertionLocation);
+    private native long nativeCreateSubMenu(long parentMenuPtr);
+    private native void nativeSetMenuTitle(long menuPtr, String title);
+    private native void nativeAddSeparator(long menuPtr);
+    private native void nativeDeleteItem(long menuPtr, int index);
+
+    // Returns a retained NSMenu object! We have to explicitly
+    // release at some point!
+    private native long nativeGetNSMenu(long menuPtr);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuBar.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuBar.java
new file mode 100644
index 0000000..8f7e7a3
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuBar.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.peer.MenuBarPeer;
+
+public class CMenuBar extends CMenuComponent implements MenuBarPeer {
+
+    private int nextInsertionIndex = -1;
+
+    public CMenuBar(MenuBar target) {
+        super(target);
+    }
+
+    @Override
+    protected long createModel() {
+        return nativeCreateMenuBar();
+    }
+
+    @Override
+    public void addHelpMenu(Menu m) {
+        CMenu cMenu = (CMenu)m.getPeer();
+        nativeSetHelpMenu(getModel(), cMenu.getModel());
+    }
+
+    public int getNextInsertionIndex() {
+        return nextInsertionIndex;
+    }
+
+    // Used by ScreenMenuBar to add newly visible menus in the right spot.
+    public void setNextInsertionIndex(int index) {
+        nextInsertionIndex = index;
+    }
+
+    @Override
+    public void addMenu(Menu m) {
+        // Nothing to do here -- we added it when the menu was created.
+    }
+
+    @Override
+    public void delMenu(int index) {
+        nativeDelMenu(getModel(), index);
+    }
+
+    private native long nativeCreateMenuBar();
+    private native void nativeSetHelpMenu(long menuBarPtr, long menuPtr);
+    private native void nativeDelMenu(long menuBarPtr, int index);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuComponent.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuComponent.java
new file mode 100644
index 0000000..0ac7c0c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuComponent.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Font;
+import java.awt.MenuComponent;
+import java.awt.peer.MenuComponentPeer;
+
+public abstract class CMenuComponent implements MenuComponentPeer {
+
+    private MenuComponent target;
+    private long modelPtr;
+
+    CMenuComponent(MenuComponent target) {
+        this.target = target;
+        this.modelPtr = createModel();
+    }
+
+    MenuComponent getTarget() {
+        return target;
+    }
+
+    long getModel() {
+        return modelPtr;
+    }
+
+    protected abstract long createModel();
+
+    public void dispose() {
+        LWCToolkit.targetDisposedPeer(target, this);
+        nativeDispose(modelPtr);
+        target = null;
+    }
+
+    private native void nativeDispose(long modelPtr);
+
+    // 1.5 peer method
+    public void setFont(Font f) {
+        // no-op, as we don't currently support menu fonts
+        // c.f. radar 4032912
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java
new file mode 100644
index 0000000..ac3bea3
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import sun.awt.SunToolkit;
+import sun.lwawt.LWToolkit;
+
+import java.awt.MenuItem;
+import java.awt.MenuShortcut;
+import java.awt.event.*;
+import java.awt.peer.MenuItemPeer;
+
+public class CMenuItem extends CMenuComponent implements MenuItemPeer {
+
+    public CMenuItem(MenuItem target) {
+        super(target);
+        initialize(target);
+
+    }
+
+    // This way we avoiding invocation of the setters twice
+    protected void initialize(MenuItem target) {
+        if (!isSeparator()) {
+            setLabel(target.getLabel());
+            setEnabled(target.isEnabled());
+        }
+    }
+
+    private boolean isSeparator() {
+        String label = ((MenuItem)getTarget()).getLabel();
+        return (label != null && label.equals("-"));
+    }
+
+    @Override
+    protected long createModel() {
+        CMenuComponent parent = (CMenuComponent)LWToolkit.targetToPeer(getTarget().getParent());
+        return nativeCreate(parent.getModel(), isSeparator());
+    }
+
+    public void setLabel(String label, char keyChar, int keyCode, int modifiers) {
+        int keyMask = modifiers;
+        if (keyCode == KeyEvent.VK_UNDEFINED) {
+            MenuShortcut shortcut = ((MenuItem)getTarget()).getShortcut();
+
+            if (shortcut != null) {
+                keyCode = shortcut.getKey();
+                keyMask |= InputEvent.META_MASK;
+
+                if (shortcut.usesShiftModifier()) {
+                    keyMask |= InputEvent.SHIFT_MASK;
+                }
+            }
+        }
+
+        if (label == null) {
+            label = "";
+        }
+
+        // <rdar://problem/3654824>
+        // Native code uses a keyChar of 0 to indicate that the
+        // keyCode should be used to generate the shortcut.  Translate
+        // CHAR_UNDEFINED into 0.
+        if (keyChar == KeyEvent.CHAR_UNDEFINED) {
+            keyChar = 0;
+        }
+
+        nativeSetLabel(getModel(), label, keyChar, keyCode, keyMask);
+    }
+
+    @Override
+    public void setLabel(String label) {
+        setLabel(label, (char)0, KeyEvent.VK_UNDEFINED, 0);
+    }
+
+    /**
+     * This is new API that we've added to AWT menu items
+     * because AWT menu items are used for Swing screen menu bars
+     * and we want to support the NSMenuItem image apis.
+     * There isn't a need to expose this except in a instanceof because
+     * it isn't defined in the peer api.
+     */
+    public void setImage(java.awt.Image img) {
+        CImage cimg = CImage.getCreator().createFromImage(img);
+        nativeSetImage(getModel(), cimg == null ? 0L : cimg.ptr);
+    }
+
+    /**
+     * New API for tooltips
+     */
+    public void setToolTipText(String text) {
+        nativeSetTooltip(getModel(), text);
+    }
+
+//    @Override
+    public void enable() {
+        setEnabled(true);
+    }
+
+//    @Override
+    public void disable() {
+        setEnabled(false);
+    }
+
+    @Override
+    public void setEnabled(boolean b) {
+        nativeSetEnabled(getModel(), b);
+    }
+
+    private native long nativeCreate(long parentMenu, boolean isSeparator);
+    private native void nativeSetLabel(long modelPtr, String label, char keyChar, int keyCode, int modifiers);
+    private native void nativeSetImage(long modelPtr, long image);
+    private native void nativeSetTooltip(long modelPtr, String text);
+    private native void nativeSetEnabled(long modelPtr, boolean b);
+
+    // native callbacks
+    void handleAction(final long when, final int modifiers) {
+        assert CThreading.assertAppKit();
+
+        SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
+            public void run() {
+                final String cmd = ((MenuItem)getTarget()).getActionCommand();
+                final ActionEvent event = new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED, cmd, when, modifiers);
+                SunToolkit.postEvent(SunToolkit.targetToAppContext(getTarget()), event);
+            }
+        });
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CMouseDragGestureRecognizer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CMouseDragGestureRecognizer.java
new file mode 100644
index 0000000..c089a78
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMouseDragGestureRecognizer.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+
+import java.awt.*;
+import java.awt.dnd.*;
+import java.awt.event.*;
+
+import sun.awt.dnd.SunDragSourceContextPeer;
+
+
+class CMouseDragGestureRecognizer extends MouseDragGestureRecognizer {
+
+      // Number of pixels before drag is determined to have started:
+    private static final int fMotionThreshold = getMotionThreshold();
+
+    // Default is the Aqua-approved value:
+    private static final int kDefaultMotionThreshold = 3;
+
+    private static int getMotionThreshold() {
+        try {
+            return ((Integer)Toolkit.getDefaultToolkit().getDesktopProperty("DnD.gestureMotionThreshold")).intValue();
+        } catch (Exception e) {
+            return kDefaultMotionThreshold;
+        }
+    }
+
+    protected static final int ButtonMask = InputEvent.BUTTON1_DOWN_MASK |
+                                            InputEvent.BUTTON2_DOWN_MASK |
+                                            InputEvent.BUTTON3_DOWN_MASK;
+
+    protected CMouseDragGestureRecognizer(DragSource ds, Component c, int act, DragGestureListener dgl) {
+        super(ds, c, act, dgl);
+    }
+
+    protected CMouseDragGestureRecognizer(DragSource ds, Component c, int act) {
+        this(ds, c, act, null);
+    }
+
+    protected CMouseDragGestureRecognizer(DragSource ds, Component c) {
+        this(ds, c, DnDConstants.ACTION_NONE);
+    }
+
+    protected CMouseDragGestureRecognizer(DragSource ds) {
+        this(ds, null);
+    }
+
+    // Determine the drop action from the event:
+    protected int mapDragOperationFromModifiers(MouseEvent e) {
+        int mods = e.getModifiersEx();
+        int btns = mods & ButtonMask;
+
+        // 8-29-02 VL: this shouldn't apply to OS X but let's leave this commented out until verified:
+        // Do not allow right mouse button drag since Motif DnD does not terminate drag operation on right mouse button release.
+        //if (!(btns == InputEvent.BUTTON1_DOWN_MASK || btns == InputEvent.BUTTON2_DOWN_MASK)) {
+        //    return DnDConstants.ACTION_NONE;
+        //}
+
+        return SunDragSourceContextPeer.convertModifiersToDropAction(mods, getSourceActions());
+    }
+
+    // Invoked when the mouse has been clicked on a component:
+    public void mouseClicked(MouseEvent e) {
+        // do nothing
+    }
+
+    // Invoked when a mouse button has been pressed on a component:
+    public void mousePressed(MouseEvent e) {
+        events.clear();
+
+        if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
+            appendEvent(e);
+        }
+    }
+
+    // Invoked when a mouse button has been released over a component:
+    public void mouseReleased(MouseEvent e) {
+        events.clear();
+    }
+
+    // Invoked when the mouse enters a component:
+    public void mouseEntered(MouseEvent e) {
+        events.clear();
+    }
+
+    // Invoked when the mouse exits a component:
+    public void mouseExited(MouseEvent e) {
+        if (!events.isEmpty()) { // gesture pending
+            int dragAction = mapDragOperationFromModifiers(e);
+
+            if (dragAction == DnDConstants.ACTION_NONE) {
+                events.clear();
+            }
+        }
+    }
+
+    // Invoked when a mouse button is pressed on a component:
+    public void mouseDragged(MouseEvent e) {
+        if (!events.isEmpty()) { // gesture pending
+            int dop = mapDragOperationFromModifiers(e);
+
+            if (dop == DnDConstants.ACTION_NONE) {
+                return;
+            }
+
+            MouseEvent trigger = (MouseEvent) events.get(0);
+
+            Point      origin  = trigger.getPoint();
+            Point      current = e.getPoint();
+
+            int        dx      = Math.abs(origin.x - current.x);
+            int        dy      = Math.abs(origin.y - current.y);
+
+            if (dx >= fMotionThreshold || dy >= fMotionThreshold) {
+                fireDragGestureRecognized(dop, ((MouseEvent)getTriggerEvent()).getPoint());
+            } else {
+                appendEvent(e);
+            }
+        }
+    }
+
+    // Invoked when the mouse button has been moved on a component (with no buttons no down):
+    public void mouseMoved(MouseEvent e) {
+        // do nothing
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CMouseInfoPeer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CMouseInfoPeer.java
new file mode 100644
index 0000000..8651aa3
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMouseInfoPeer.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Window;
+
+import sun.lwawt.LWMouseInfoPeer;
+import sun.lwawt.LWWindowPeer;
+
+public class CMouseInfoPeer extends LWMouseInfoPeer
+{
+    //If a new window is to appear under the cursor,
+    //we get wrong window.
+    //This is a workaround for macosx.
+    @Override
+    public boolean isWindowUnderMouse(Window w) {
+        if (w == null) {
+            return false;
+        }
+
+        LWWindowPeer peer = (LWWindowPeer)w.getPeer();
+        CPlatformWindow platformWindow = (CPlatformWindow)peer.getPlatformWindow();
+        return nativeIsWindowUnderMouse(platformWindow.getNSWindowPtr());
+    }
+
+    private static native boolean nativeIsWindowUnderMouse(long ptr);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java
new file mode 100644
index 0000000..f3d06e7
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Component;
+import java.awt.Insets;
+
+import sun.lwawt.PlatformComponent;
+import sun.lwawt.PlatformWindow;
+import sun.lwawt.LWComponentPeer;
+
+import sun.lwawt.macosx.CFRetainedResource;
+
+public class CPlatformComponent extends CFRetainedResource implements PlatformComponent {
+
+    Component target;
+    LWComponentPeer peer;
+    CPlatformWindow platformWindow;
+
+    private native long nativeCreateComponent(long windowLayer);
+    private native long nativeSetBounds(long ptr, int x, int y, int width, int height);
+
+    public CPlatformComponent() {
+        super(0, true);
+    }
+
+    public long getPointer() {
+        return ptr;
+    }
+
+    public void initialize(Component target, LWComponentPeer peer, PlatformWindow platformWindow) {
+        this.target = target;
+        this.peer = peer;
+        this.platformWindow = (CPlatformWindow)platformWindow;
+
+        long windowLayerPtr = this.platformWindow.getContentView().getWindowLayerPtr();
+        setPtr(nativeCreateComponent(windowLayerPtr));
+    }
+
+    // TODO: visibility, z-order
+
+    @Override
+    public void setBounds(int x, int y, int width, int height) {
+        // translates values from the coordinate system of the top-level window
+        // to the coordinate system of the content view
+        Insets insets = platformWindow.getPeer().getInsets();
+        nativeSetBounds(getPointer(), x - insets.left, y - insets.top, width, height);
+    }
+
+    @Override
+    public void dispose() {
+        super.dispose();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java
new file mode 100644
index 0000000..399f7d1
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.VolatileImage;
+
+import sun.awt.CGraphicsConfig;
+import sun.lwawt.LWWindowPeer;
+import sun.lwawt.macosx.event.NSEvent;
+
+import sun.java2d.SurfaceData;
+import sun.java2d.opengl.CGLLayer;
+import sun.java2d.opengl.CGLSurfaceData;
+
+public class CPlatformView extends CFRetainedResource {
+    private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
+
+    private LWWindowPeer peer;
+    private SurfaceData surfaceData;
+    private CGLLayer windowLayer;
+
+    public CPlatformView() {
+        super(0, true);
+    }
+
+    public void initialize(LWWindowPeer peer) {
+        this.peer = peer;
+
+        if (!LWCToolkit.getSunAwtDisableCALayers()) {
+            this.windowLayer = new CGLLayer(peer);
+        }
+        setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr()));
+    }
+
+    public long getAWTView() {
+        return ptr;
+    }
+
+    public boolean isOpaque() {
+        return peer.isOpaque();
+    }
+
+    /*
+     * All coordinates passed to the method should be based on the origin being in the bottom-left corner (standard
+     * Cocoa coordinates).
+     */
+    public void setBounds(int x, int y, int width, int height) {
+        CWrapper.NSView.setFrame(ptr, x, y, width, height);
+    }
+
+    // REMIND: CGLSurfaceData expects top-level's size
+    public Rectangle getBounds() {
+        return peer.getBounds();
+    }
+
+    public Object getDestination() {
+        return peer;
+    }
+
+    public void enterFullScreenMode(final long nsWindowPtr) {
+        CWrapper.NSView.enterFullScreenMode(ptr);
+
+        // REMIND: CGLSurfaceData expects top-level's size
+        // and therefore we need to account insets before
+        // recreating the surface data
+        Insets insets = peer.getInsets();
+
+        Rectangle screenBounds;
+        final long screenPtr = CWrapper.NSWindow.screen(nsWindowPtr);
+        try {
+            screenBounds = CWrapper.NSScreen.frame(screenPtr).getBounds();
+        } finally {
+            CWrapper.NSObject.release(screenPtr);
+        }
+
+        // the move/size notification from the underlying system comes
+        // but it contains a bounds smaller than the whole screen
+        // and therefore we need to create the synthetic notifications
+        peer.notifyReshape(screenBounds.x - insets.left,
+                           screenBounds.y - insets.bottom,
+                           screenBounds.width + insets.left + insets.right,
+                           screenBounds.height + insets.top + insets.bottom);
+    }
+
+    public void exitFullScreenMode() {
+        CWrapper.NSView.exitFullScreenMode(ptr);
+    }
+
+    // ----------------------------------------------------------------------
+    // PAINTING METHODS
+    // ----------------------------------------------------------------------
+
+    public void drawImageOnPeer(VolatileImage xBackBuffer, int x1, int y1, int x2, int y2) {
+        Graphics g = peer.getGraphics();
+        try {
+            g.drawImage(xBackBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
+        } finally {
+            g.dispose();
+        }
+    }
+
+    public Image createBackBuffer() {
+        Rectangle r = peer.getBounds();
+        Image im = null;
+        if (!r.isEmpty()) {
+            int transparency = (isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT);
+            im = peer.getGraphicsConfiguration().createCompatibleImage(r.width, r.height, transparency);
+        }
+        return im;
+    }
+
+    public SurfaceData replaceSurfaceData() {
+        if (!LWCToolkit.getSunAwtDisableCALayers()) {
+            surfaceData = windowLayer.replaceSurfaceData();
+        } else {
+            if (surfaceData == null) {
+                CGraphicsConfig graphicsConfig = (CGraphicsConfig)peer.getGraphicsConfiguration();
+                surfaceData = graphicsConfig.createSurfaceData(this);
+            } else {
+                validateSurface();
+            }
+        }
+        return surfaceData;
+    }
+
+    private void validateSurface() {
+        if (surfaceData != null) {
+            ((CGLSurfaceData)surfaceData).validate();
+        }
+    }
+
+    public GraphicsConfiguration getGraphicsConfiguration() {
+        return peer.getGraphicsConfiguration();
+    }
+
+    public SurfaceData getSurfaceData() {
+        return surfaceData;
+    }
+
+    @Override
+    public void dispose() {
+        if (!LWCToolkit.getSunAwtDisableCALayers()) {
+            windowLayer.dispose();
+        }
+        super.dispose();
+    }
+
+    public long getWindowLayerPtr() {
+        if (!LWCToolkit.getSunAwtDisableCALayers()) {
+            return windowLayer.getPointer();
+        } else {
+            return 0;
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // NATIVE CALLBACKS
+    // ----------------------------------------------------------------------
+
+    // This code uses peer's API which is a no-no on the AppKit thread.
+    // TODO: post onto the EDT.
+    private void deliverMouseEvent(NSEvent event) {
+        int jModifiers = event.getModifiers();
+        int jX = event.getX();
+        // a difference in coordinate systems
+        int jY = getBounds().height - event.getY();
+        int jAbsX = event.getAbsX();
+        int jAbsY = event.getAbsY();
+        int jButton = NSEvent.nsButtonToJavaButton(event);
+        int jClickCount = event.getClickCount();
+        double wheelDeltaY = event.getScrollDeltaY();
+        double wheelDeltaX = event.getScrollDeltaX();
+        boolean isPopupTrigger = event.isPopupTrigger();
+
+        int jEventType;
+        switch (event.getType()) {
+            case CocoaConstants.NSLeftMouseDown:
+            case CocoaConstants.NSRightMouseDown:
+            case CocoaConstants.NSOtherMouseDown:
+                jEventType = MouseEvent.MOUSE_PRESSED;
+                break;
+            case CocoaConstants.NSLeftMouseUp:
+            case CocoaConstants.NSRightMouseUp:
+            case CocoaConstants.NSOtherMouseUp:
+                jEventType = MouseEvent.MOUSE_RELEASED;
+                break;
+            case CocoaConstants.NSMouseMoved:
+                jEventType = MouseEvent.MOUSE_MOVED;
+                break;
+
+            case CocoaConstants.NSLeftMouseDragged:
+            case CocoaConstants.NSRightMouseDragged:
+            case CocoaConstants.NSOtherMouseDragged:
+                jEventType = MouseEvent.MOUSE_DRAGGED;
+                break;
+            case CocoaConstants.NSMouseEntered:
+                jEventType = MouseEvent.MOUSE_ENTERED;
+                break;
+            case CocoaConstants.NSMouseExited:
+                jEventType = MouseEvent.MOUSE_EXITED;
+                break;
+            case CocoaConstants.NSScrollWheel:
+                jEventType = MouseEvent.MOUSE_WHEEL;
+                double wheelDelta = wheelDeltaY;
+
+                // shift+vertical wheel scroll produces horizontal scroll
+                // we convert it to vertical
+                if ((jModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
+                    wheelDelta = wheelDeltaX;
+                }
+
+                // Wheel amount "oriented" inside out
+                wheelDelta = -wheelDelta;
+                peer.dispatchMouseWheelEvent(System.currentTimeMillis(), jX, jY, jModifiers, MouseWheelEvent.WHEEL_UNIT_SCROLL, 3, // WHEEL_SCROLL_AMOUNT
+                        (int)wheelDelta, wheelDelta, null);
+                return;
+            default:
+                return;
+        }
+        peer.dispatchMouseEvent(jEventType, System.currentTimeMillis(), jButton, jX, jY, jAbsX, jAbsY, jModifiers, jClickCount, isPopupTrigger, null);
+    }
+
+    private void deliverKeyEvent(final int javaKeyType, final int javaModifiers, final char testChar, final int javaKeyCode, final int javaKeyLocation) {
+        // TODO: there is no focus owner installed now, get back to this once we assign it properly.
+        java.awt.EventQueue.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                peer.dispatchKeyEvent(javaKeyType, System.currentTimeMillis(), javaModifiers, javaKeyCode, testChar, javaKeyLocation);
+
+                // That's the reaction on the PRESSED (not RELEASED) event as it comes to
+                // appear in MacOSX.
+                // Modifier keys (shift, etc) don't want to send TYPED events.
+                // On the other hand we don't want to generate keyTyped events
+                // for clipboard related shortcuts like Meta + [CVX]
+                boolean isMetaDown = (javaModifiers & KeyEvent.META_DOWN_MASK) != 0;
+                if (!isMetaDown && javaKeyType == KeyEvent.KEY_PRESSED && testChar != KeyEvent.CHAR_UNDEFINED) {
+                    boolean isCtrlDown = (javaModifiers & KeyEvent.CTRL_DOWN_MASK) != 0;
+                    boolean isShiftDown = (javaModifiers & KeyEvent.SHIFT_DOWN_MASK) != 0;
+                    // emulating the codes from the ASCII table
+                    int shift = isCtrlDown ? isShiftDown ? 64 : 96 : 0;
+                    peer.dispatchKeyEvent(KeyEvent.KEY_TYPED, System.currentTimeMillis(), javaModifiers,
+                            KeyEvent.VK_UNDEFINED, (char) (testChar - shift), KeyEvent.KEY_LOCATION_UNKNOWN);
+                }
+            }
+        });
+    }
+
+    private void deliverWindowDidExposeEvent() {
+        Rectangle r = peer.getBounds();
+        peer.notifyExpose(0, 0, r.width, r.height);
+    }
+
+    private void deliverWindowDidExposeEvent(float x, float y, float w, float h) {
+        peer.notifyExpose((int)x, (int)y, (int)w, (int)h);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
new file mode 100644
index 0000000..df7072b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
@@ -0,0 +1,876 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.BufferCapabilities.FlipContents;
+import java.awt.*;
+import java.awt.Dialog.ModalityType;
+import java.awt.event.*;
+import java.beans.*;
+import java.util.List;
+
+import javax.swing.*;
+
+import sun.awt.*;
+import sun.java2d.SurfaceData;
+import sun.java2d.opengl.CGLSurfaceData;
+import sun.lwawt.*;
+import sun.lwawt.LWWindowPeer.PeerType;
+import sun.util.logging.PlatformLogger;
+
+import com.apple.laf.*;
+import com.apple.laf.ClientPropertyApplicator.Property;
+import com.sun.awt.AWTUtilities;
+
+public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
+    private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
+    private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
+    private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
+    private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
+    private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
+    private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
+    private static native void nativePushNSWindowToBack(long nsWindowPtr);
+    private static native void nativePushNSWindowToFront(long nsWindowPtr);
+    private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
+    private static native void nativeSetNSWindowAlpha(long nsWindowPtr, float alpha);
+    private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
+    private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
+    private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
+    private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
+
+    private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr);
+
+    private static native boolean nativeIsApplicationActive();
+
+    // Loger to report issues happened during execution but that do not affect functionality
+    private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
+    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
+
+    // for client properties
+    public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
+    public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
+
+    public static final String WINDOW_ALPHA = "Window.alpha";
+    public static final String WINDOW_SHADOW = "Window.shadow";
+
+    public static final String WINDOW_STYLE = "Window.style";
+    public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
+
+    public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
+    public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
+
+    public static final String WINDOW_CLOSEABLE = "Window.closeable";
+    public static final String WINDOW_MINIMIZABLE = "Window.minimizable";
+    public static final String WINDOW_ZOOMABLE = "Window.zoomable";
+    public static final String WINDOW_HIDES_ON_DEACTIVATE="Window.hidesOnDeactivate";
+
+    public static final String WINDOW_DOC_MODAL_SHEET = "apple.awt.documentModalSheet";
+    public static final String WINDOW_FADE_DELEGATE = "apple.awt._windowFadeDelegate";
+    public static final String WINDOW_FADE_IN = "apple.awt._windowFadeIn";
+    public static final String WINDOW_FADE_OUT = "apple.awt._windowFadeOut";
+    public static final String WINDOW_FULLSCREENABLE = "apple.awt.fullscreenable";
+
+
+    // Yeah, I know. But it's easier to deal with ints from JNI
+    static final int MODELESS = 0;
+    static final int DOCUMENT_MODAL = 1;
+    static final int APPLICATION_MODAL = 2;
+    static final int TOOLKIT_MODAL = 3;
+
+    // window style bits
+    static final int _RESERVED_FOR_DATA = 1 << 0;
+
+    // corresponds to native style mask bits
+    static final int DECORATED = 1 << 1;
+    static final int TEXTURED = 1 << 2;
+    static final int UNIFIED = 1 << 3;
+    static final int UTILITY = 1 << 4;
+    static final int HUD = 1 << 5;
+    static final int SHEET = 1 << 6;
+
+    static final int CLOSEABLE = 1 << 7;
+    static final int MINIMIZABLE = 1 << 8;
+
+    static final int RESIZABLE = 1 << 9; // both a style bit and prop bit
+
+    static final int _STYLE_PROP_BITMASK = DECORATED | TEXTURED | UNIFIED | UTILITY | HUD | SHEET | CLOSEABLE | MINIMIZABLE | RESIZABLE;
+
+    // corresponds to method-based properties
+    static final int HAS_SHADOW = 1 << 10;
+    static final int ZOOMABLE = 1 << 11;
+
+    static final int ALWAYS_ON_TOP = 1 << 15;
+    static final int HIDES_ON_DEACTIVATE = 1 << 17;
+    static final int DRAGGABLE_BACKGROUND = 1 << 19;
+    static final int DOCUMENT_MODIFIED = 1 << 21;
+    static final int FULLSCREENABLE = 1 << 23;
+
+    static final int _METHOD_PROP_BITMASK = RESIZABLE | HAS_SHADOW | ZOOMABLE | ALWAYS_ON_TOP | HIDES_ON_DEACTIVATE | DRAGGABLE_BACKGROUND | DOCUMENT_MODIFIED | FULLSCREENABLE;
+
+    // not sure
+    static final int POPUP = 1 << 14;
+
+    // corresponds to callback-based properties
+    static final int SHOULD_BECOME_KEY = 1 << 12;
+    static final int SHOULD_BECOME_MAIN = 1 << 13;
+    static final int MODAL_EXCLUDED = 1 << 16;
+
+    static final int _CALLBACK_PROP_BITMASK = SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | MODAL_EXCLUDED;
+
+    static int SET(final int bits, final int mask, final boolean value) {
+        if (value) return (bits | mask);
+        return bits & ~mask;
+    }
+
+    static boolean IS(final int bits, final int mask) {
+        return (bits & mask) != 0;
+    }
+
+    @SuppressWarnings("unchecked")
+    static ClientPropertyApplicator<JRootPane, CPlatformWindow> CLIENT_PROPERTY_APPLICATOR = new ClientPropertyApplicator<JRootPane, CPlatformWindow>(new Property[] {
+        new Property<CPlatformWindow>(WINDOW_DOCUMENT_MODIFIED) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            c.setStyleBits(DOCUMENT_MODIFIED, value == null ? false : Boolean.parseBoolean(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_BRUSH_METAL_LOOK) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_ALPHA) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            AWTUtilities.setWindowOpacity(c.target, value == null ? 1.0f : Float.parseFloat(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_SHADOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_MINIMIZABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            c.setStyleBits(MINIMIZABLE, Boolean.parseBoolean(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_CLOSEABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            c.setStyleBits(CLOSEABLE, Boolean.parseBoolean(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_ZOOMABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            c.setStyleBits(ZOOMABLE, Boolean.parseBoolean(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_FULLSCREENABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            c.setStyleBits(FULLSCREENABLE, Boolean.parseBoolean(value.toString()));
+        }},
+        new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            nativeRevalidateNSWindowShadow(c.getNSWindowPtr());
+        }},
+        new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
+            if (value == null || !(value instanceof java.io.File)) {
+                nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
+                return;
+            }
+
+            final String filename = ((java.io.File)value).getAbsolutePath();
+            nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
+        }}
+    }) {
+        public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
+            Component root = SwingUtilities.getRoot(p);
+            if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
+            return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
+        }
+    };
+
+    private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
+
+    // Bounds of the native widget but in the Java coordinate system.
+    // In order to keep it up-to-date we will update them on
+    // 1) setting native bounds via nativeSetBounds() call
+    // 2) getting notification from the native level via deliverMoveResizeEvent()
+    private Rectangle nativeBounds;
+    private volatile boolean isFullScreenMode = false;
+
+    private Window target;
+    private LWWindowPeer peer;
+    private CPlatformView contentView;
+    private CPlatformWindow owner;
+
+    public CPlatformWindow(final PeerType peerType) {
+        super(0, true);
+        assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
+    }
+
+    /*
+     * Delegate initialization (create native window and all the
+     * related resources).
+     */
+    @Override // PlatformWindow
+    public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
+        this.peer = _peer;
+        this.target = _target;
+        this.owner = (CPlatformWindow)_owner;
+
+        final Font font = target.getFont();
+        if (font == null) {
+            target.setFont(DEFAULT_FONT);
+        }
+
+        final Color background = target.getBackground();
+        if (background == null) {
+            target.setBackground(SystemColor.window);
+        } else {
+            // first we check if user provided alpha for background. This is
+            // similar to what Apple's Java do.
+            // Since JDK7 we should rely on setOpacity() only.
+            // this.opacity = c.getAlpha();
+            // System.out.println("Delegate assigns alpha (we ignore setOpacity()):"
+            // +this.opacity);
+        }
+
+        Color foreground = target.getForeground();
+        if (foreground == null) {
+            target.setForeground(SystemColor.windowText);
+            // we should not call setForeground because it will call a repaint
+            // which the peer may not be ready to do yet.
+        }
+
+        final int styleBits = getInitialStyleBits();
+
+        // TODO: handle these misc properties
+        final long parentNSWindowPtr = (owner != null ? owner.getNSWindowPtr() : 0);
+        String warningString = target.getWarningString();
+
+        contentView = new CPlatformView();
+        contentView.initialize(peer);
+
+        final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(), styleBits, 0, 0, 0, 0);
+        setPtr(nativeWindowPtr);
+
+        // TODO: implement on top of JObjC bridged class
+    //    NSWindow window = JObjC.getInstance().AppKit().NSWindow().getInstance(nativeWindowPtr, JObjCRuntime.getInstance());
+
+        // Since JDK7 we have standard way to set opacity, so we should not pick
+        // background's alpha.
+        // TODO: set appropriate opacity value
+        //        this.opacity = target.getOpacity();
+        //        this.setOpacity(this.opacity);
+
+        final float windowAlpha = target.getOpacity();
+        if (windowAlpha != 1.0f) {
+            nativeSetNSWindowAlpha(nativeWindowPtr, windowAlpha);
+        }
+
+        if (target instanceof javax.swing.RootPaneContainer) {
+            final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
+            if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
+                public void propertyChange(final PropertyChangeEvent evt) {
+                    CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
+                    rootpane.removePropertyChangeListener("ancestor", this);
+                }
+            });
+        }
+
+        validateSurface();
+    }
+
+    protected int getInitialStyleBits() {
+        // defaults style bits
+        int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE;
+
+        if (target.getName() == "###overrideRedirect###") {
+            styleBits = SET(styleBits, POPUP, true);
+        }
+
+        if (isNativelyFocusableWindow()) {
+            styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
+            styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
+        }
+
+        final boolean isFrame = (target instanceof Frame);
+        final boolean isDialog = (target instanceof Dialog);
+        if (isDialog) {
+            styleBits = SET(styleBits, MINIMIZABLE, false);
+        }
+
+        // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
+        {
+            final boolean undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
+            if (undecorated) styleBits = SET(styleBits, DECORATED, false);
+        }
+
+        // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
+        {
+            final boolean resizable = isFrame ? ((Frame)target).isResizable() : (isDialog ? ((Dialog)target).isResizable() : false);
+            styleBits = SET(styleBits, RESIZABLE, resizable);
+            if (!resizable) {
+                styleBits = SET(styleBits, RESIZABLE, false);
+                styleBits = SET(styleBits, ZOOMABLE, false);
+            }
+        }
+
+        if (target.isAlwaysOnTop()) {
+            styleBits = SET(styleBits, ALWAYS_ON_TOP, true);
+        }
+
+        if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
+            styleBits = SET(styleBits, MODAL_EXCLUDED, true);
+        }
+
+        // If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
+        if (!isDialog && IS(styleBits, POPUP)) {
+            styleBits = SET(styleBits, TEXTURED, true);
+        }
+
+        if (target instanceof javax.swing.RootPaneContainer) {
+            javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
+            Object prop = null;
+
+            prop = rootpane.getClientProperty(WINDOW_BRUSH_METAL_LOOK);
+            if (prop != null) {
+                styleBits = SET(styleBits, TEXTURED, Boolean.parseBoolean(prop.toString()));
+            }
+
+            if (isDialog && ((Dialog)target).getModalityType() == ModalityType.DOCUMENT_MODAL) {
+                prop = rootpane.getClientProperty(WINDOW_DOC_MODAL_SHEET);
+                if (prop != null) {
+                    styleBits = SET(styleBits, SHEET, Boolean.parseBoolean(prop.toString()));
+                }
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_STYLE);
+            if (prop != null) {
+                if ("small".equals(prop))  {
+                    styleBits = SET(styleBits, UTILITY, true);
+                    if (target.isAlwaysOnTop() && rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE) == null) {
+                        styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, true);
+                    }
+                }
+                if ("textured".equals(prop)) styleBits = SET(styleBits, TEXTURED, true);
+                if ("unified".equals(prop)) styleBits = SET(styleBits, UNIFIED, true);
+                if ("hud".equals(prop)) styleBits = SET(styleBits, HUD, true);
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE);
+            if (prop != null) {
+                styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, Boolean.parseBoolean(prop.toString()));
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_CLOSEABLE);
+            if (prop != null) {
+                styleBits = SET(styleBits, CLOSEABLE, Boolean.parseBoolean(prop.toString()));
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_MINIMIZABLE);
+            if (prop != null) {
+                styleBits = SET(styleBits, MINIMIZABLE, Boolean.parseBoolean(prop.toString()));
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_ZOOMABLE);
+            if (prop != null) {
+                styleBits = SET(styleBits, ZOOMABLE, Boolean.parseBoolean(prop.toString()));
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_FULLSCREENABLE);
+            if (prop != null) {
+                styleBits = SET(styleBits, FULLSCREENABLE, Boolean.parseBoolean(prop.toString()));
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_SHADOW);
+            if (prop != null) {
+                styleBits = SET(styleBits, HAS_SHADOW, Boolean.parseBoolean(prop.toString()));
+            }
+
+            prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND);
+            if (prop != null) {
+                styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString()));
+            }
+        }
+
+        return styleBits;
+    }
+
+    // this is the counter-point to -[CWindow _nativeSetStyleBit:]
+    protected void setStyleBits(final int mask, final boolean value) {
+        nativeSetNSWindowStyleBits(getNSWindowPtr(), mask, value ? mask : 0);
+    }
+
+    private native void _toggleFullScreenMode(final long model);
+
+    public void toggleFullScreen() {
+        _toggleFullScreenMode(getNSWindowPtr());
+    }
+
+    @Override // PlatformWindow
+    public void setMenuBar(MenuBar mb) {
+        final long nsWindowPtr = getNSWindowPtr();
+        CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
+        if (mbPeer != null) {
+            nativeSetNSWindowMenuBar(nsWindowPtr, mbPeer.getModel());
+        } else {
+            nativeSetNSWindowMenuBar(nsWindowPtr, 0);
+        }
+    }
+
+    @Override // PlatformWindow
+    public Image createBackBuffer() {
+        return contentView.createBackBuffer();
+    }
+
+    @Override // PlatformWindow
+    public void dispose() {
+        if (owner != null) {
+            CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr());
+        }
+        // Make sure window is ordered out before it is disposed, we could order it out right here or
+        // we could postpone the disposal, I think postponing is probably better.
+        EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                contentView.dispose();
+                CPlatformWindow.super.dispose();
+            }
+        });
+    }
+
+    @Override // PlatformWindow
+    public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) {
+        // TODO: not implemented
+        (new RuntimeException("unimplemented")).printStackTrace();
+    }
+
+    @Override // PlatformWindow
+    public FontMetrics getFontMetrics(Font f) {
+        // TODO: not implemented
+        (new RuntimeException("unimplemented")).printStackTrace();
+        return null;
+    }
+
+    @Override // PlatformWindow
+    public Insets getInsets() {
+        final Insets insets = nativeGetNSWindowInsets(getNSWindowPtr());
+        return insets;
+    }
+
+    @Override // PlatformWindow
+    public Point getLocationOnScreen() {
+        return new Point(nativeBounds.x, nativeBounds.y);
+    }
+
+    @Override // PlatformWindow
+    public int getScreenImOn() {
+    // REMIND: we could also acquire screenID from the
+    // graphicsConfig.getDevice().getCoreGraphicsScreen()
+    // which might look a bit less natural but don't
+    // require new native accessor.
+        return nativeGetScreenNSWindowIsOn_AppKitThread(getNSWindowPtr());
+    }
+
+    @Override // PlatformWindow
+    public SurfaceData getScreenSurface() {
+        // TODO: not implemented
+        return null;
+    }
+
+    @Override // PlatformWindow
+    public SurfaceData replaceSurfaceData() {
+        return contentView.replaceSurfaceData();
+    }
+
+    @Override // PlatformWindow
+    public void setBounds(int x, int y, int w, int h) {
+//        assert CThreading.assertEventQueue();
+        nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
+    }
+
+    @Override // PlatformWindow
+    public void setVisible(boolean visible) {
+        if (owner != null) {
+            if (!visible) {
+                CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr());
+            }
+        }
+
+        updateIconImages();
+        updateFocusabilityForAutoRequestFocus(false);
+
+        LWWindowPeer blocker = peer.getBlocker();
+        if (blocker == null || !visible) {
+            // If it ain't blocked, or is being hidden, go regular way
+            setVisibleHelper(visible);
+        } else {
+            // otherwise, put it in a proper z-order
+            CWrapper.NSWindow.orderWindow(getNSWindowPtr(), CWrapper.NSWindow.NSWindowBelow,
+                    ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
+        }
+        updateFocusabilityForAutoRequestFocus(true);
+
+        if (owner != null) {
+            if (visible) {
+                CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);
+            }
+        }
+
+        if (blocker != null && visible) {
+            // Make sure the blocker is above its siblings
+            ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings();
+        }
+    }
+
+    @Override // PlatformWindow
+    public void setTitle(String title) {
+        nativeSetNSWindowTitle(getNSWindowPtr(), title);
+    }
+
+    // Should be called on every window key property change.
+    @Override // PlatformWindow
+    public void updateIconImages() {
+        final long nsWindowPtr = getNSWindowPtr();
+        final CImage cImage = getImageForTarget();
+        nativeSetNSWindowMinimizedIcon(nsWindowPtr, cImage == null ? 0L : cImage.ptr);
+    }
+
+    public long getNSWindowPtr() {
+        final long nsWindowPtr = ptr;
+        if (nsWindowPtr == 0L) {
+            if(logger.isLoggable(PlatformLogger.FINE)) {
+                logger.fine("NSWindow already disposed?", new Exception("Pointer to native NSWindow is invalid."));
+            }
+        }
+        return nsWindowPtr;
+    }
+
+    public SurfaceData getSurfaceData() {
+        return contentView.getSurfaceData();
+    }
+
+    @Override  // PlatformWindow
+    public void toBack() {
+        final long nsWindowPtr = getNSWindowPtr();
+        nativePushNSWindowToBack(nsWindowPtr);
+    }
+
+    @Override  // PlatformWindow
+    public void toFront() {
+        final long nsWindowPtr = getNSWindowPtr();
+        updateFocusabilityForAutoRequestFocus(false);
+        nativePushNSWindowToFront(nsWindowPtr);
+        updateFocusabilityForAutoRequestFocus(true);
+    }
+
+    @Override
+    public void setResizable(boolean resizable) {
+        setStyleBits(RESIZABLE, resizable);
+    }
+
+    @Override
+    public void setMinimumSize(int width, int height) {
+        //TODO width, height should be used
+        final long nsWindowPtr = getNSWindowPtr();
+        final Dimension min = target.getMinimumSize();
+        final Dimension max = target.getMaximumSize();
+        nativeSetNSWindowMinMax(nsWindowPtr, min.getWidth(), min.getHeight(), max.getWidth(), max.getHeight());
+    }
+
+    @Override
+    public boolean requestWindowFocus(boolean isMouseEventCause) {
+        if (!isMouseEventCause && !nativeIsApplicationActive()) {
+            focusLog.fine("the app is inactive, so the window activation is rejected");
+            // Cross-app activation requests are not allowed.
+            return false;
+        }
+        long ptr = getNSWindowPtr();
+        if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
+            CWrapper.NSWindow.makeMainWindow(ptr);
+        }
+        CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
+        return true;
+    }
+
+    @Override
+    public void updateFocusableWindowState() {
+        final boolean isFocusable = isNativelyFocusableWindow();
+        setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
+    }
+
+    @Override
+    public Graphics transformGraphics(Graphics g) {
+        // is this where we can inject a transform for HiDPI?
+        return g;
+    }
+
+    @Override
+    public void setAlwaysOnTop(boolean isAlwaysOnTop) {
+        setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
+    }
+
+    @Override
+    public void setOpacity(float opacity) {
+        CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
+    }
+
+    @Override
+    public void setOpaque(boolean isOpaque) {
+        CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
+        if (!isOpaque) {
+            long clearColor = CWrapper.NSColor.clearColor();
+            CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
+        }
+    }
+
+    @Override
+    public void enterFullScreenMode() {
+        isFullScreenMode = true;
+        contentView.enterFullScreenMode(getNSWindowPtr());
+    }
+
+    @Override
+    public void exitFullScreenMode() {
+        contentView.exitFullScreenMode();
+        isFullScreenMode = false;
+    }
+
+    @Override
+    public void setWindowState(int windowState) {
+        int prevWindowState = peer.getState();
+        if (prevWindowState == windowState) return;
+
+        final long nsWindowPtr = getNSWindowPtr();
+        switch (windowState) {
+            case Frame.ICONIFIED:
+                if (!peer.isVisible()) {
+                    // later on the setVisible will minimize itself
+                    // otherwise, orderFront will deminiaturize window
+                   return;
+                }
+                if (prevWindowState == Frame.MAXIMIZED_BOTH) {
+                    // let's return into the normal states first
+                    // the zoom call toggles between the normal and the max states
+                    CWrapper.NSWindow.zoom(nsWindowPtr);
+                }
+                CWrapper.NSWindow.miniaturize(nsWindowPtr);
+                break;
+            case Frame.MAXIMIZED_BOTH:
+                if (prevWindowState == Frame.ICONIFIED) {
+                    // let's return into the normal states first
+                    CWrapper.NSWindow.deminiaturize(nsWindowPtr);
+                }
+                CWrapper.NSWindow.zoom(nsWindowPtr);
+                break;
+            case Frame.NORMAL:
+                if (prevWindowState == Frame.ICONIFIED) {
+                    CWrapper.NSWindow.deminiaturize(nsWindowPtr);
+                } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
+                    // the zoom call toggles between the normal and the max states
+                    CWrapper.NSWindow.zoom(nsWindowPtr);
+                }
+                break;
+            default:
+                throw new RuntimeException("Unknown window state: " + windowState);
+        }
+
+        // NOTE: the SWP.windowState field gets updated to the newWindowState
+        //       value when the native notification comes to us
+    }
+
+    // ----------------------------------------------------------------------
+    //                          UTILITY METHODS
+    // ----------------------------------------------------------------------
+
+    private void setVisibleHelper(boolean visible) {
+        final long nsWindowPtr = getNSWindowPtr();
+        if (visible) {
+            CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
+            boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
+            if (!isKeyWindow) {
+                CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
+            } else {
+                CWrapper.NSWindow.orderFront(nsWindowPtr);
+            }
+            if (target instanceof Frame) {
+                if (((Frame)target).getExtendedState() == Frame.ICONIFIED) {
+                    CWrapper.NSWindow.miniaturize(nsWindowPtr);
+                }
+            }
+            return;
+        }
+
+        if (target instanceof Frame) {
+            if (((Frame)target).getExtendedState() == Frame.ICONIFIED) {
+                CWrapper.NSWindow.deminiaturize(nsWindowPtr);
+            }
+        }
+
+        CWrapper.NSWindow.orderOut(nsWindowPtr);
+    }
+
+    /*
+     * Find image to install into Title or into Application icon.
+     * First try icons installed for toplevel. If there is no icon
+     * use default Duke image.
+     * This method shouldn't return null.
+     */
+    private CImage getImageForTarget() {
+        List<Image> icons = target.getIconImages();
+        if (icons == null || icons.size() == 0) {
+            return null;
+        }
+
+        // TODO: need a walk-through to find the best image.
+        // The best mean with higher resolution. Otherwise an icon looks bad.
+        final Image image = icons.get(0);
+        return CImage.getCreator().createFromImage(image);
+    }
+
+    /*
+     * Returns LWWindowPeer associated with this delegate.
+     */
+    public LWWindowPeer getPeer() {
+        return peer;
+    }
+
+    public CPlatformView getContentView() {
+        return contentView;
+    }
+
+    private void validateSurface() {
+        SurfaceData surfaceData = getSurfaceData();
+        if (surfaceData instanceof CGLSurfaceData) {
+            ((CGLSurfaceData)surfaceData).validate();
+        }
+    }
+
+    /*************************************************************
+     * Callbacks from the AWTWindow and AWTView objc classes.
+     *************************************************************/
+    private void deliverWindowFocusEvent(boolean gained){
+        peer.notifyActivation(gained);
+    }
+
+    private void deliverMoveResizeEvent(int x, int y, int width, int height) {
+        // when the content view enters the full-screen mode, the native
+        // move/resize notifications contain a bounds smaller than
+        // the whole screen and therefore we ignore the native notifications
+        // and the content view itself creates correct synthetic notifications
+        if (isFullScreenMode) return;
+
+        nativeBounds = new Rectangle(x, y, width, height);
+        peer.notifyReshape(x, y, width, height);
+        //TODO validateSurface already called from notifyReshape
+        validateSurface();
+    }
+
+    private void deliverWindowClosingEvent() {
+        if (peer.getBlocker() == null)  {
+            peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
+        }
+    }
+
+    private void deliverIconify(final boolean iconify) {
+        peer.notifyIconify(iconify);
+    }
+
+    private void deliverZoom(final boolean isZoomed) {
+        peer.notifyZoom(isZoomed);
+    }
+
+    /*
+     * Our focus model is synthetic and only non-simple window
+     * may become natively focusable window.
+     */
+    private boolean isNativelyFocusableWindow() {
+        return !peer.isSimpleWindow() && target.getFocusableWindowState();
+    }
+
+    /*
+     * An utility method for the support of the auto request focus.
+     * Updates the focusable state of the window under certain
+     * circumstances.
+     */
+    private void updateFocusabilityForAutoRequestFocus(boolean isFocusable) {
+        if (target.isAutoRequestFocus() || !isNativelyFocusableWindow()) return;
+        setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
+    }
+
+    private boolean checkBlocking() {
+        LWWindowPeer blocker = peer.getBlocker();
+        if (blocker == null) {
+            return false;
+        }
+
+        CPlatformWindow pWindow = (CPlatformWindow)blocker.getPlatformWindow();
+
+        pWindow.orderAboveSiblings();
+
+        final long nsWindowPtr = pWindow.getNSWindowPtr();
+        CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
+        CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
+        CWrapper.NSWindow.makeMainWindow(nsWindowPtr);
+
+        return true;
+    }
+
+    private void orderAboveSiblings() {
+        if (owner == null) {
+            return;
+        }
+
+        // Recursively pop up the windows from the very bottom so that only
+        // the very top-most one becomes the main window
+        owner.orderAboveSiblings();
+
+        // Order the window to front of the stack of child windows
+        final long nsWindowSelfPtr = getNSWindowPtr();
+        final long nsWindowOwnerPtr = owner.getNSWindowPtr();
+        CWrapper.NSWindow.removeChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr);
+        CWrapper.NSWindow.addChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove);
+    }
+
+    // ----------------------------------------------------------------------
+    //                          NATIVE CALLBACKS
+    // ----------------------------------------------------------------------
+
+    private void windowDidBecomeMain() {
+        assert CThreading.assertAppKit();
+
+        if (checkBlocking()) return;
+        // If it's not blocked, make sure it's above its siblings
+        orderAboveSiblings();
+    }
+
+    private void updateDisplay() {
+        EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                validateSurface();
+            }
+        });
+    }
+
+    private void updateWindowContent() {
+        ComponentEvent resizeEvent = new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED);
+        SunToolkit.postEvent(SunToolkit.targetToAppContext(target), resizeEvent);
+    }
+
+    private void windowWillEnterFullScreen() {
+        updateWindowContent();
+    }
+    private void windowDidEnterFullScreen() {
+        updateDisplay();
+    }
+    private void windowWillExitFullScreen() {
+        updateWindowContent();
+    }
+    private void windowDidExitFullScreen() {}
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPopupMenu.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPopupMenu.java
new file mode 100644
index 0000000..44dac0d
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPopupMenu.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.peer.PopupMenuPeer;
+
+import sun.lwawt.LWWindowPeer;
+
+public class CPopupMenu extends CMenu implements PopupMenuPeer {
+    CPopupMenu(PopupMenu target) {
+        super(target);
+    }
+
+    @Override
+    protected long createModel() {
+        return nativeCreatePopupMenu();
+    }
+
+    private native long nativeCreatePopupMenu();
+    private native long nativeShowPopupMenu(long modelPtr, int x, int y);
+
+    @Override
+    public void show(Event e) {
+        Component origin = (Component)e.target;
+        if (origin != null) {
+            Point loc = origin.getLocationOnScreen();
+            e.x += loc.x;
+            e.y += loc.y;
+            nativeShowPopupMenu(getModel(), e.x, e.y);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDevice.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDevice.java
new file mode 100644
index 0000000..d9fb787
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDevice.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+
+public class CPrinterDevice extends GraphicsDevice {
+    GraphicsConfiguration gc;
+
+    public CPrinterDevice(CPrinterGraphicsConfig gc) {
+        this.gc = gc;
+    }
+
+    /**
+     * Returns the type of this <code>GraphicsDevice</code>.
+     * @return the type of this <code>GraphicsDevice</code>, which can
+     * either be TYPE_RASTER_SCREEN, TYPE_PRINTER or TYPE_IMAGE_BUFFER.
+     * @see #TYPE_RASTER_SCREEN
+     * @see #TYPE_PRINTER
+     * @see #TYPE_IMAGE_BUFFER
+     */
+    public int getType() {
+        return GraphicsDevice.TYPE_PRINTER;
+    }
+
+    /**
+     * Returns the identification string associated with this
+     * <code>GraphicsDevice</code>.
+     * @return a <code>String</code> that is the identification
+     * of this <code>GraphicsDevice</code>.
+     */
+    public String getIDstring() {
+        return ("Printer");
+    }
+
+    /**
+     * Returns all of the <code>GraphicsConfiguration</code>
+     * objects associated with this <code>GraphicsDevice</code>.
+     * @return an array of <code>GraphicsConfiguration</code>
+     * objects that are associated with this
+     * <code>GraphicsDevice</code>.
+     */
+    public GraphicsConfiguration[] getConfigurations() {
+        return new GraphicsConfiguration[] { gc };
+    }
+
+    /**
+     * Returns the default <code>GraphicsConfiguration</code>
+     * associated with this <code>GraphicsDevice</code>.
+     * @return the default <code>GraphicsConfiguration</code>
+     * of this <code>GraphicsDevice</code>.
+     */
+    public GraphicsConfiguration getDefaultConfiguration() {
+        return gc;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDialog.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDialog.java
new file mode 100644
index 0000000..c44ea31
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDialog.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+
+public abstract class CPrinterDialog extends Dialog {
+    private final CPrinterJob fPrinterJob; // used from native
+
+    CPrinterDialog(Frame parent, CPrinterJob printerJob) {
+        super(parent, true);
+        fPrinterJob = printerJob;
+        setLayout(null);
+    }
+
+    private boolean retval = false;
+
+    public void setRetVal(boolean ret) {
+        retval = ret;
+    }
+
+    public boolean getRetVal() {
+        return retval;
+    }
+
+    protected abstract boolean showDialog();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDialogPeer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDialogPeer.java
new file mode 100644
index 0000000..f50f286
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterDialogPeer.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.dnd.*;
+
+import sun.lwawt.*;
+
+public class CPrinterDialogPeer extends LWWindowPeer {
+    static {
+        // AWT has to be initialized for the native code to function correctly.
+        Toolkit.getDefaultToolkit();
+    }
+
+    Component fTarget;
+
+    public CPrinterDialogPeer(CPrinterDialog target, PlatformComponent platformComponent,
+                              PlatformWindow platformWindow)
+    {
+        super(target, platformComponent, platformWindow);
+        //super(target);
+        fTarget = target;
+        super.initialize();
+    }
+
+    protected void disposeImpl() {
+        LWCToolkit.targetDisposedPeer(fTarget, this);
+    }
+
+    public void setVisible(boolean visible) {
+        if (visible) {
+            new Thread(new Runnable() {
+                public void run() {
+                    CPrinterDialog printerDialog = (CPrinterDialog)fTarget;
+                    printerDialog.setRetVal(printerDialog.showDialog());
+                    printerDialog.setVisible(false);
+                }
+            }).start();
+        }
+    }
+
+    // unused methods.
+    public void toFront() {}
+    public void toBack() {}
+    public void setResizable(boolean resizable) {}
+    public void setEnabled(boolean enable) {}
+    public void setBounds(int x, int y, int width, int height) {}
+    public boolean handleEvent(Event e) { return false; }
+    public void setForeground(Color c) {}
+    public void setBackground(Color c) {}
+    public void setFont(Font f) {}
+    public boolean requestFocus(boolean temporary, boolean focusedWindowChangeAllowed) {
+        return false;
+    }
+    void start() {}
+    void invalidate(int x, int y, int width, int height) {}
+    public void addDropTarget(DropTarget dt) {}
+    public void removeDropTarget(DropTarget dt) {}
+
+    // 1.5 peer method
+    public boolean isRestackSupported() {
+        return false;
+    }
+
+    // 1.6 peer method
+    public void setAlwaysOnTop(boolean value) {
+        // no-op, since we just show the native print dialog
+    }
+
+    // 1.6 peer method
+    public void updateMinimumSize() {}
+
+    // 1.6 peer method
+    public void setModalBlocked(Dialog blocker, boolean blocked) {
+        // I don't think we care since this is a native dialog
+    }
+
+    // 1.6 peer method
+    public void updateFocusableWindowState() {}
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterGraphics.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterGraphics.java
new file mode 100644
index 0000000..145af39
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterGraphics.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.image.*;
+import java.awt.print.*;
+import sun.print.*;
+
+public class CPrinterGraphics extends ProxyGraphics2D {
+    // NOTE: This is a ProxyGraphics2D, and not a PathGraphics. However
+    // the RasterPrinterJob, upon which CPrinterJob is based, refers to
+    // PathGraphics. However, this is not a code path that will be
+    // encountered by CPrinterJob/CPrinterGraphics. This is because
+    // CPrinterGraphics wraps a SunGraphics2D that has a OSXSurfaceData
+    // based CPrinterSurfaceData. It can do "path graphics" because it
+    // is based upon CoreGraphics. See WPathGraphics and PSPathGraphics.
+
+    public CPrinterGraphics(Graphics2D graphics, PrinterJob printerJob) {
+        super(graphics, printerJob);
+    }
+
+    public boolean drawImage(Image img, int x, int y,
+                 Color bgcolor,
+                 ImageObserver observer) {
+        // ProxyGraphics2D works around a problem that shouldn't be
+        // a problem with CPrinterSurfaceData (and the decision method,
+        // needToCopyBgColorImage, is private instead of protected!)
+        return getDelegate().drawImage(img, x, y, bgcolor, observer);
+    }
+
+    public boolean drawImage(Image img, int x, int y,
+                 int width, int height,
+                 Color bgcolor,
+                 ImageObserver observer) {
+        // ProxyGraphics2D works around a problem that shouldn't be
+        // a problem with CPrinterSurfaceData (and the decision method,
+        // needToCopyBgColorImage, is private instead of protected!)
+        return getDelegate().drawImage(img, x, y, width, height, bgcolor, observer);
+    }
+
+    public boolean drawImage(Image img,
+                 int dx1, int dy1, int dx2, int dy2,
+                 int sx1, int sy1, int sx2, int sy2,
+                 Color bgcolor,
+                 ImageObserver observer) {
+        // ProxyGraphics2D works around a problem that shouldn't be
+        // a problem with CPrinterSurfaceData (and the decision method,
+        // needToCopyBgColorImage, is private instead of protected!)
+        return getDelegate().drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterGraphicsConfig.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterGraphicsConfig.java
new file mode 100644
index 0000000..18b16b3
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterGraphicsConfig.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.image.*;
+import java.awt.print.*;
+
+public class CPrinterGraphicsConfig extends GraphicsConfiguration {
+    public static CPrinterGraphicsConfig getConfig(PageFormat pf) {
+        return new CPrinterGraphicsConfig(pf);
+    }
+
+    GraphicsDevice gd;
+    PageFormat pf;
+
+    public CPrinterGraphicsConfig(PageFormat pf) {
+        this.gd = new CPrinterDevice(this);
+        this.pf = pf;
+    }
+
+    public PageFormat getPageFormat() {
+        return pf;
+    }
+
+    /**
+     * Returns the {@link GraphicsDevice} associated with this
+     * <code>GraphicsConfiguration</code>.
+     * @return a <code>GraphicsDevice</code> object that is
+     * associated with this <code>GraphicsConfiguration</code>.
+     */
+    public GraphicsDevice getDevice() {
+        return gd;
+    }
+
+    /**
+     * Returns a {@link BufferedImage} with a data layout and color model
+     * compatible with this <code>GraphicsConfiguration</code>.  This
+     * method has nothing to do with memory-mapping
+     * a device.  The returned <code>BufferedImage</code> has
+     * a layout and color model that is closest to this native device
+     * configuration and can therefore be optimally blitted to this
+     * device.
+     * @param width the width of the returned <code>BufferedImage</code>
+     * @param height the height of the returned <code>BufferedImage</code>
+     * @return a <code>BufferedImage</code> whose data layout and color
+     * model is compatible with this <code>GraphicsConfiguration</code>.
+     */
+    public BufferedImage createCompatibleImage(int width, int height) {
+        return createCompatibleImage(width, height, Transparency.OPAQUE);
+    }
+
+    /**
+     * Returns a {@link VolatileImage} with a data layout and color model
+     * compatible with this <code>GraphicsConfiguration</code>.
+     * The returned <code>VolatileImage</code>
+     * may have data that is stored optimally for the underlying graphics
+     * device and may therefore benefit from platform-specific rendering
+     * acceleration.
+     * @param width the width of the returned <code>VolatileImage</code>
+     * @param height the height of the returned <code>VolatileImage</code>
+     * @return a <code>VolatileImage</code> whose data layout and color
+     * model is compatible with this <code>GraphicsConfiguration</code>.
+     * @see Component#createVolatileImage(int, int)
+     */
+    public VolatileImage createCompatibleVolatileImage(int width, int height) {
+        return createCompatibleVolatileImage(width, height, Transparency.OPAQUE);
+    }
+
+    // empty implementation (this should not be called)
+    public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency) {
+        return null;
+    }
+
+    /**
+     * Returns a <code>BufferedImage</code> that supports the specified
+     * transparency and has a data layout and color model
+     * compatible with this <code>GraphicsConfiguration</code>.  This
+     * method has nothing to do with memory-mapping
+     * a device. The returned <code>BufferedImage</code> has a layout and
+     * color model that can be optimally blitted to a device
+     * with this <code>GraphicsConfiguration</code>.
+     * @param width the width of the returned <code>BufferedImage</code>
+     * @param height the height of the returned <code>BufferedImage</code>
+     * @param transparency the specified transparency mode
+     * @return a <code>BufferedImage</code> whose data layout and color
+     * model is compatible with this <code>GraphicsConfiguration</code>
+     * and also supports the specified transparency.
+     * @see Transparency#OPAQUE
+     * @see Transparency#BITMASK
+     * @see Transparency#TRANSLUCENT
+     */
+    public BufferedImage createCompatibleImage(int width, int height, int transparency) {
+        //+++gdb what to do?
+        return null;
+    }
+
+    /**
+     * Returns the {@link ColorModel} associated with this
+     * <code>GraphicsConfiguration</code>.
+     * @return a <code>ColorModel</code> object that is associated with
+     * this <code>GraphicsConfiguration</code>.
+     */
+    public ColorModel getColorModel() {
+        return getColorModel(Transparency.OPAQUE);
+    }
+
+    /**
+     * Returns the <code>ColorModel</code> associated with this
+     * <code>GraphicsConfiguration</code> that supports the specified
+     * transparency.
+     * @param transparency the specified transparency mode
+     * @return a <code>ColorModel</code> object that is associated with
+     * this <code>GraphicsConfiguration</code> and supports the
+     * specified transparency.
+     */
+    public ColorModel getColorModel(int transparency) {
+        return ColorModel.getRGBdefault();
+    }
+
+    /**
+     * Returns the default {@link AffineTransform} for this
+     * <code>GraphicsConfiguration</code>. This
+     * <code>AffineTransform</code> is typically the Identity transform
+     * for most normal screens.  The default <code>AffineTransform</code>
+     * maps coordinates onto the device such that 72 user space
+     * coordinate units measure approximately 1 inch in device
+     * space.  The normalizing transform can be used to make
+     * this mapping more exact.  Coordinates in the coordinate space
+     * defined by the default <code>AffineTransform</code> for screen and
+     * printer devices have the origin in the upper left-hand corner of
+     * the target region of the device, with X coordinates
+     * increasing to the right and Y coordinates increasing downwards.
+     * For image buffers not associated with a device, such as those not
+     * created by <code>createCompatibleImage</code>,
+     * this <code>AffineTransform</code> is the Identity transform.
+     * @return the default <code>AffineTransform</code> for this
+     * <code>GraphicsConfiguration</code>.
+     */
+    public AffineTransform getDefaultTransform() {
+        return new AffineTransform();
+    }
+
+    /**
+     *
+     * Returns a <code>AffineTransform</code> that can be concatenated
+     * with the default <code>AffineTransform</code>
+     * of a <code>GraphicsConfiguration</code> so that 72 units in user
+     * space equals 1 inch in device space.
+     * <p>
+     * For a particular {@link Graphics2D}, g, one
+     * can reset the transformation to create
+     * such a mapping by using the following pseudocode:
+     * <pre>
+     *      GraphicsConfiguration gc = g.getGraphicsConfiguration();
+     *
+     *      g.setTransform(gc.getDefaultTransform());
+     *      g.transform(gc.getNormalizingTransform());
+     * </pre>
+     * Note that sometimes this <code>AffineTransform</code> is identity,
+     * such as for printers or metafile output, and that this
+     * <code>AffineTransform</code> is only as accurate as the information
+     * supplied by the underlying system.  For image buffers not
+     * associated with a device, such as those not created by
+     * <code>createCompatibleImage</code>, this
+     * <code>AffineTransform</code> is the Identity transform
+     * since there is no valid distance measurement.
+     * @return an <code>AffineTransform</code> to concatenate to the
+     * default <code>AffineTransform</code> so that 72 units in user
+     * space is mapped to 1 inch in device space.
+     */
+    public AffineTransform getNormalizingTransform() {
+        return new AffineTransform();
+    }
+
+    /**
+     * Returns the bounds of the <code>GraphicsConfiguration</code>
+     * in the device coordinates. In a multi-screen environment
+     * with a virtual device, the bounds can have negative X
+     * or Y origins.
+     * @return the bounds of the area covered by this
+     * <code>GraphicsConfiguration</code>.
+     * @since 1.3
+     */
+    public Rectangle getBounds() {
+        return new Rectangle(0, 0, (int)pf.getWidth(), (int)pf.getHeight());
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
new file mode 100644
index 0000000..56f5ac7
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
@@ -0,0 +1,662 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.print.*;
+
+import javax.print.*;
+import javax.print.attribute.PrintRequestAttributeSet;
+
+import sun.java2d.*;
+import sun.print.*;
+
+public class CPrinterJob extends RasterPrinterJob {
+    // NOTE: This uses RasterPrinterJob as a base, but it doesn't use
+    // all of the RasterPrinterJob functions. RasterPrinterJob will
+    // break down printing to pieces that aren't necessary under MacOSX
+    // printing, such as controlling the # of copies and collating. These
+    // are handled by the native printing. RasterPrinterJob is kept for
+    // future compatibility and the state keeping that it handles.
+
+    private static String sShouldNotReachHere = "Should not reach here.";
+
+    private boolean noDefaultPrinter = false;
+
+    private static Font defaultFont;
+
+    // This is the NSPrintInfo for this PrinterJob. Protect multi thread
+    //  access to it. It is used by the pageDialog, jobDialog, and printLoop.
+    //  This way the state of these items is shared across these calls.
+    //  PageFormat data is passed in and set on the fNSPrintInfo on a per call
+    //  basis.
+    private long fNSPrintInfo = -1;
+    private Object fNSPrintInfoLock = new Object();
+
+    static {
+        // AWT has to be initialized for the native code to function correctly.
+        Toolkit.getDefaultToolkit();
+    }
+
+    /**
+     * Presents a dialog to the user for changing the properties of
+     * the print job.
+     * This method will display a native dialog if a native print
+     * service is selected, and user choice of printers will be restricted
+     * to these native print services.
+     * To present the cross platform print dialog for all services,
+     * including native ones instead use
+     * <code>printDialog(PrintRequestAttributeSet)</code>.
+     * <p>
+     * PrinterJob implementations which can use PrintService's will update
+     * the PrintService for this PrinterJob to reflect the new service
+     * selected by the user.
+     * @return <code>true</code> if the user does not cancel the dialog;
+     * <code>false</code> otherwise.
+     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
+     * returns true.
+     * @see java.awt.GraphicsEnvironment#isHeadless
+     */
+    public boolean printDialog() throws HeadlessException {
+        if (GraphicsEnvironment.isHeadless()) {
+            throw new HeadlessException();
+        }
+
+        if (noDefaultPrinter) {
+            return false;
+        }
+
+        return jobSetup(getPageable(), checkAllowedToPrintToFile());
+    }
+
+    /**
+     * Displays a dialog that allows modification of a
+     * <code>PageFormat</code> instance.
+     * The <code>page</code> argument is used to initialize controls
+     * in the page setup dialog.
+     * If the user cancels the dialog then this method returns the
+     * original <code>page</code> object unmodified.
+     * If the user okays the dialog then this method returns a new
+     * <code>PageFormat</code> object with the indicated changes.
+     * In either case, the original <code>page</code> object is
+     * not modified.
+     * @param page the default <code>PageFormat</code> presented to the
+     *            user for modification
+     * @return    the original <code>page</code> object if the dialog
+     *            is cancelled; a new <code>PageFormat</code> object
+     *          containing the format indicated by the user if the
+     *          dialog is acknowledged.
+     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
+     * returns true.
+     * @see java.awt.GraphicsEnvironment#isHeadless
+     * @since     1.2
+     */
+    public PageFormat pageDialog(PageFormat page) throws HeadlessException {
+        if (GraphicsEnvironment.isHeadless()) {
+            throw new HeadlessException();
+        }
+
+        if (noDefaultPrinter) {
+            return page;
+        }
+
+        PageFormat pageClone = (PageFormat) page.clone();
+        boolean doIt = pageSetup(pageClone, null);
+        return doIt ? pageClone : page;
+    }
+
+    /**
+     * Clones the <code>PageFormat</code> argument and alters the
+     * clone to describe a default page size and orientation.
+     * @param page the <code>PageFormat</code> to be cloned and altered
+     * @return clone of <code>page</code>, altered to describe a default
+     *                      <code>PageFormat</code>.
+     */
+    public PageFormat defaultPage(PageFormat page) {
+        PageFormat newPage = (PageFormat)page.clone();
+        getDefaultPage(newPage);
+        return newPage;
+    }
+
+    protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
+        super.setAttributes(attributes);
+
+        if (attributes == null) {
+            return;
+        }
+
+        // See if this has an NSPrintInfo in it.
+        NSPrintInfo nsPrintInfo = (NSPrintInfo)attributes.get(NSPrintInfo.class);
+        if (nsPrintInfo != null) {
+            fNSPrintInfo = nsPrintInfo.getValue();
+        }
+    }
+
+    volatile boolean onEventThread;
+
+    private void completePrintLoop() {
+        Runnable r = new Runnable() { public void run() {
+            synchronized(this) {
+                performingPrinting = false;
+            }
+        }};
+
+        if (onEventThread) {
+            try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
+        } else {
+            r.run();
+        }
+    }
+
+
+    public void print(PrintRequestAttributeSet attributes) throws PrinterException {
+        // NOTE: Some of this code is copied from RasterPrinterJob.
+
+
+        // this code uses javax.print APIs
+        // this will make it print directly to the printer
+        // this will not work if the user clicks on the "Preview" button
+        // However if the printer is a StreamPrintService, its the right path.
+        PrintService psvc = getPrintService();
+        if (psvc instanceof StreamPrintService) {
+            spoolToService(psvc, attributes);
+            return;
+        }
+
+
+        setAttributes(attributes);
+
+        /* Get the range of pages we are to print. If the
+         * last page to print is unknown, then we print to
+         * the end of the document. Note that firstPage
+         * and lastPage are 0 based page indices.
+         */
+        int numPages = mDocument.getNumberOfPages();
+
+        int firstPage = getFirstPage();
+        int lastPage = getLastPage();
+        if(lastPage == Pageable.UNKNOWN_NUMBER_OF_PAGES) {
+            int totalPages = mDocument.getNumberOfPages();
+            if (totalPages != Pageable.UNKNOWN_NUMBER_OF_PAGES) {
+                lastPage = mDocument.getNumberOfPages() - 1;
+            }
+        }
+
+        try {
+            synchronized (this) {
+                performingPrinting = true;
+                userCancelled = false;
+            }
+
+            if (EventQueue.isDispatchThread()) {
+                // This is an AWT EventQueue, and this print rendering loop needs to block it.
+
+                onEventThread = true;
+
+                try {
+                    // Fire off the print rendering loop on the AppKit thread, and don't have
+                    //  it wait and block this thread.
+                    if (printLoop(false, firstPage, lastPage)) {
+                        // Fire off the EventConditional that will what until the condition is met,
+                        //  but will still process AWTEvent's as they occur.
+                        new EventDispatchAccess() {
+                            public boolean evaluate() {
+                                return performingPrinting;
+                            }
+                        }.pumpEventsAndWait();
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            } else {
+                // Fire off the print rendering loop on the AppKit, and block this thread
+                //  until it is done.
+                // But don't actually block... we need to come back here!
+                onEventThread = false;
+
+                try {
+                    printLoop(true, firstPage, lastPage);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        } finally {
+            synchronized (this) {
+                // NOTE: Native code shouldn't allow exceptions out while
+                // printing. They should cancel the print loop.
+                performingPrinting = false;
+                notify();
+            }
+        }
+
+        // Normalize the collated, # copies, numPages, first/last pages. Need to
+        //  make note of pageRangesAttr.
+
+        // Set up NSPrintInfo with the java settings (PageFormat & Paper).
+
+        // Create an NSView for printing. Have knowsPageRange return YES, and give the correct
+        //  range, or MAX? if unknown. Have rectForPage do a peekGraphics check before returning
+        //  the rectangle. Have drawRect do the real render of the page. Have printJobTitle do
+        //  the right thing.
+
+        // Call NSPrintOperation, it will call NSView.drawRect: for each page.
+
+        // NSView.drawRect: will create a CPrinterGraphics with the current CGContextRef, and then
+        //  pass this Graphics onto the Printable with the appropriate PageFormat and index.
+
+        // Need to be able to cancel the NSPrintOperation (using code from RasterPrinterJob, be
+        //  sure to initialize userCancelled and performingPrinting member variables).
+
+        // Extensions available from AppKit: Print to PDF or EPS file!
+    }
+
+    /**
+     * Returns the resolution in dots per inch across the width
+     * of the page.
+     */
+    protected double getXRes() {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Returns the resolution in dots per inch down the height
+     * of the page.
+     */
+    protected double getYRes() {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Must be obtained from the current printer.
+     * Value is in device pixels.
+     * Not adjusted for orientation of the paper.
+     */
+    protected double getPhysicalPrintableX(Paper p) {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Must be obtained from the current printer.
+     * Value is in device pixels.
+     * Not adjusted for orientation of the paper.
+     */
+    protected double getPhysicalPrintableY(Paper p) {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Must be obtained from the current printer.
+     * Value is in device pixels.
+     * Not adjusted for orientation of the paper.
+     */
+    protected double getPhysicalPrintableWidth(Paper p) {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Must be obtained from the current printer.
+     * Value is in device pixels.
+     * Not adjusted for orientation of the paper.
+     */
+    protected double getPhysicalPrintableHeight(Paper p) {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Must be obtained from the current printer.
+     * Value is in device pixels.
+     * Not adjusted for orientation of the paper.
+     */
+    protected double getPhysicalPageWidth(Paper p) {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Must be obtained from the current printer.
+     * Value is in device pixels.
+     * Not adjusted for orientation of the paper.
+     */
+    protected double getPhysicalPageHeight(Paper p) {
+        // NOTE: This is not used in the CPrinterJob code path.
+        return 0;
+    }
+
+    /**
+     * Begin a new page. This call's Window's
+     * StartPage routine.
+     */
+    protected void startPage(PageFormat format, Printable painter, int index) throws PrinterException {
+        // NOTE: This is not used in the CPrinterJob code path.
+        throw new PrinterException(sShouldNotReachHere);
+    }
+
+    /**
+     * End a page.
+     */
+    protected void endPage(PageFormat format, Printable painter, int index) throws PrinterException {
+        // NOTE: This is not used in the CPrinterJob code path.
+        throw new PrinterException(sShouldNotReachHere);
+    }
+
+    /**
+     * Prints the contents of the array of ints, 'data'
+     * to the current page. The band is placed at the
+     * location (x, y) in device coordinates on the
+     * page. The width and height of the band is
+     * specified by the caller.
+     */
+    protected void printBand(byte[] data, int x, int y, int width, int height) throws PrinterException {
+        // NOTE: This is not used in the CPrinterJob code path.
+        throw new PrinterException(sShouldNotReachHere);
+    }
+
+    /**
+     * Called by the print() method at the start of
+     * a print job.
+     */
+    protected void startDoc() throws PrinterException {
+        // NOTE: This is not used in the CPrinterJob code path.
+        throw new PrinterException(sShouldNotReachHere);
+    }
+
+    /**
+     * Called by the print() method at the end of
+     * a print job.
+     */
+    protected void endDoc() throws PrinterException {
+        // NOTE: This is not used in the CPrinterJob code path.
+        throw new PrinterException(sShouldNotReachHere);
+    }
+
+    /* Called by cancelDoc */
+    protected native void abortDoc();
+
+    /**
+     * Displays the page setup dialog placing the user's
+     * settings into 'page'.
+     */
+    public boolean pageSetup(PageFormat page, Printable painter) {
+        CPrinterDialog printerDialog = new CPrinterPageDialog(null, this, page, painter);
+        printerDialog.setVisible(true);
+        boolean result = printerDialog.getRetVal();
+        printerDialog.dispose();
+        return result;
+    }
+
+    /**
+     * Displays the print dialog and records the user's settings
+     * into this object. Return false if the user cancels the
+     * dialog.
+     * If the dialog is to use a set of attributes, useAttributes is true.
+     */
+    private boolean jobSetup(Pageable doc, boolean allowPrintToFile) {
+        CPrinterDialog printerDialog = new CPrinterJobDialog(null, this, doc, allowPrintToFile);
+        printerDialog.setVisible(true);
+        boolean result = printerDialog.getRetVal();
+        printerDialog.dispose();
+        return result;
+    }
+
+    /**
+     * Alters the orientation and Paper to match defaults obtained
+     * from a printer.
+     */
+    private native void getDefaultPage(PageFormat page);
+
+    /**
+     * validate the paper size against the current printer.
+     */
+    protected native void validatePaper(Paper origPaper, Paper newPaper );
+
+    // The following methods are CPrinterJob specific.
+
+    protected void finalize() {
+        if (fNSPrintInfo != -1) {
+            dispose(fNSPrintInfo);
+        }
+    }
+
+    private native long createNSPrintInfo();
+    private native void dispose(long printInfo);
+
+    private long getNSPrintInfo() {
+        // This is called from the native side.
+        synchronized (fNSPrintInfoLock) {
+            if (fNSPrintInfo == -1) {
+                fNSPrintInfo = createNSPrintInfo();
+            }
+            return fNSPrintInfo;
+        }
+    }
+
+    private native boolean printLoop(boolean waitUntilDone, int firstPage, int lastPage) throws PrinterException;
+
+    private PageFormat getPageFormat(int pageIndex) {
+        // This is called from the native side.
+        PageFormat page;
+        try {
+            page = getPageable().getPageFormat(pageIndex);
+        } catch (Exception e) {
+            return null;
+        }
+        return page;
+    }
+
+    private Printable getPrintable(int pageIndex) {
+        // This is called from the native side.
+        Printable painter;
+        try {
+            painter = getPageable().getPrintable(pageIndex);
+        } catch (Exception e) {
+            return null;
+        }
+        return painter;
+    }
+
+    private String getPrinterName(){
+        // This is called from the native side.
+        PrintService service = getPrintService();
+        if (service == null) return null;
+        return service.getName();
+    }
+
+    private void setPrinterServiceFromNative(String printerName) {
+        // This is called from the native side.
+        PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
+
+        for (int i = 0; i < services.length; i++) {
+            PrintService service = services[i];
+
+            if (printerName.equals(service.getName())) {
+                try {
+                    setPrintService(service);
+                } catch (PrinterException e) {
+                    // ignored
+                }
+                return;
+            }
+        }
+    }
+
+    private Rectangle2D getPageFormatArea(PageFormat page) {
+        Rectangle2D.Double pageFormatArea =
+            new Rectangle2D.Double(page.getImageableX(),
+                    page.getImageableY(),
+                    page.getImageableWidth(),
+                    page.getImageableHeight());
+        return pageFormatArea;
+    }
+
+    private boolean cancelCheck() {
+        // This is called from the native side.
+
+        // This is used to avoid deadlock
+        // We would like to just call if isCancelled(),
+        // but that will block the AppKit thread against whomever is holding the synchronized lock
+        boolean cancelled = (performingPrinting && userCancelled);
+        if (cancelled) {
+            try {
+                LWCToolkit.invokeLater(new Runnable() { public void run() {
+                    try {
+                    cancelDoc();
+                    } catch (PrinterAbortException pae) {
+                        // no-op, let the native side handle it
+                    }
+                }}, null);
+            } catch (java.lang.reflect.InvocationTargetException ite) {}
+        }
+        return cancelled;
+    }
+
+    private PeekGraphics createFirstPassGraphics(PrinterJob printerJob, PageFormat page) {
+        // This is called from the native side.
+        BufferedImage bimg = new BufferedImage((int)Math.round(page.getWidth()), (int)Math.round(page.getHeight()), BufferedImage.TYPE_INT_ARGB_PRE);
+        PeekGraphics peekGraphics = createPeekGraphics(bimg.createGraphics(), printerJob);
+        Rectangle2D pageFormatArea = getPageFormatArea(page);
+        initPrinterGraphics(peekGraphics, pageFormatArea);
+        return peekGraphics;
+    }
+
+    private void printToPathGraphics(    final PeekGraphics graphics, // Always an actual PeekGraphics
+                                        final PrinterJob printerJob, // Always an actual CPrinterJob
+                                        final Printable painter, // Client class
+                                        final PageFormat page, // Client class
+                                        final int pageIndex,
+                                        final long context) throws PrinterException {
+        // This is called from the native side.
+        Runnable r = new Runnable() { public void run() {
+            try {
+                SurfaceData sd = CPrinterSurfaceData.createData(page, context); // Just stores page into an ivar
+                if (defaultFont == null) {
+                    defaultFont = new Font("Dialog", Font.PLAIN, 12);
+                }
+                Graphics2D delegate = new SunGraphics2D(sd, Color.black, Color.white, defaultFont);
+
+                Graphics2D pathGraphics = new CPrinterGraphics(delegate, printerJob); // Just stores delegate into an ivar
+                Rectangle2D pageFormatArea = getPageFormatArea(page);
+                initPrinterGraphics(pathGraphics, pageFormatArea);
+                painter.print(pathGraphics, page, pageIndex);
+                delegate.dispose();
+                delegate = null;
+        } catch (PrinterException pe) { throw new java.lang.reflect.UndeclaredThrowableException(pe); }
+        }};
+
+        if (onEventThread) {
+            try { EventQueue.invokeAndWait(r);
+            } catch (java.lang.reflect.InvocationTargetException ite) {
+                Throwable te = (Throwable)ite.getTargetException();
+                if (te instanceof PrinterException) throw (PrinterException)te;
+                else te.printStackTrace();
+            } catch (Exception e) { e.printStackTrace(); }
+        } else {
+            r.run();
+        }
+
+    }
+
+    // Returns either 1. an array of 3 object (PageFormat, Printable, PeekGraphics) or 2. null
+    private Object[] getPageformatPrintablePeekgraphics(final int pageIndex) {
+        final Object[] ret = new Object[3];
+        final PrinterJob printerJob = this;
+
+        Runnable r = new Runnable() { public void run() { synchronized(ret) {
+            try {
+                Pageable pageable = getPageable();
+                PageFormat pageFormat = pageable.getPageFormat(pageIndex);
+                if (pageFormat != null) {
+                    Printable printable = pageable.getPrintable(pageIndex);
+                    if (printable != null) {
+                        BufferedImage bimg = new BufferedImage((int)Math.round(pageFormat.getWidth()), (int)Math.round(pageFormat.getHeight()), BufferedImage.TYPE_INT_ARGB_PRE);
+                        PeekGraphics peekGraphics = createPeekGraphics(bimg.createGraphics(), printerJob);
+                        Rectangle2D pageFormatArea = getPageFormatArea(pageFormat);
+                        initPrinterGraphics(peekGraphics, pageFormatArea);
+
+                        // Do the assignment here!
+                        ret[0] = pageFormat;
+                        ret[1] = printable;
+                        ret[2] = peekGraphics;
+                    }
+                }
+            } catch (Exception e) {} // Original code bailed on any exception
+        }}};
+
+        if (onEventThread) {
+            try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
+        } else {
+            r.run();
+        }
+
+        synchronized(ret) {
+            if (ret[2] != null)
+                return ret;
+            return null;
+        }
+    }
+
+    private Rectangle2D printAndGetPageFormatArea(final Printable printable, final Graphics graphics, final PageFormat pageFormat, final int pageIndex) {
+        final Rectangle2D[] ret = new Rectangle2D[1];
+
+        Runnable r = new Runnable() { public void run() { synchronized(ret) {
+            try {
+                int pageResult = printable.print(graphics, pageFormat, pageIndex);
+                if (pageResult != Printable.NO_SUCH_PAGE) {
+                    ret[0] = getPageFormatArea(pageFormat);
+                }
+            } catch (Exception e) {} // Original code bailed on any exception
+        }}};
+
+        if (onEventThread) {
+            try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
+        } else {
+            r.run();
+        }
+
+        synchronized(ret) { return ret[0]; }
+    }
+
+    // upcall from native
+    private static void detachPrintLoop(final long target, final long arg) {
+        new Thread() { public void run() {
+            _safePrintLoop(target, arg);
+        }}.start();
+    }
+    private static native void _safePrintLoop(long target, long arg);
+
+    @Override
+    protected void startPage(PageFormat arg0, Printable arg1, int arg2, boolean arg3) throws PrinterException {
+        // TODO Auto-generated method stub
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJobDialog.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJobDialog.java
new file mode 100644
index 0000000..a97b15a
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJobDialog.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+
+import java.awt.*;
+import java.awt.print.*;
+
+public class CPrinterJobDialog extends CPrinterDialog {
+    private Pageable fPageable;
+    private boolean fAllowPrintToFile;
+
+    CPrinterJobDialog(Frame parent, CPrinterJob printerJob, Pageable doc, boolean allowPrintToFile) {
+        super(parent, printerJob);
+        fPageable = doc;
+        fAllowPrintToFile = allowPrintToFile;
+    }
+
+    protected native boolean showDialog();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterPageDialog.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterPageDialog.java
new file mode 100644
index 0000000..0776d26
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterPageDialog.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+
+import java.awt.*;
+import java.awt.print.*;
+
+public class CPrinterPageDialog extends CPrinterDialog {
+    private PageFormat fPage;
+    private Printable fPainter;
+
+    CPrinterPageDialog(Frame parent, CPrinterJob printerJob, PageFormat page, Printable painter) {
+        super(parent, printerJob);
+        fPage = page;
+        fPainter = painter;
+    }
+
+    protected native boolean showDialog();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterSurfaceData.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterSurfaceData.java
new file mode 100644
index 0000000..665417b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterSurfaceData.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.image.*;
+import java.awt.print.PageFormat;
+import java.nio.ByteBuffer;
+
+import sun.java2d.*;
+import sun.java2d.loops.SurfaceType;
+
+public class CPrinterSurfaceData extends OSXSurfaceData{
+    public static final String DESC_INT_RGB_PQ = "Integer RGB Printer Quartz";
+//    public static final String DESC_INT_ARGB_PQ = "Integer ARGB Printer Quartz";
+
+//    public static final SurfaceType IntArgbPQ = SurfaceType.IntArgb.deriveSubType(DESC_INT_ARGB_PQ);
+    public static final SurfaceType IntRgbPQ = SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_PQ);
+
+    public static SurfaceData createData(PageFormat pf, long context) {
+        return new CPrinterSurfaceData(CPrinterGraphicsConfig.getConfig(pf), context);
+    }
+
+    public CPrinterSurfaceData(GraphicsConfiguration gc, long context) {
+        super(IntRgbPQ, gc.getColorModel(), gc, gc.getBounds());
+        initOps(context, this.fGraphicsStates, this.fGraphicsStatesObject, gc.getBounds().width, gc.getBounds().height);
+    }
+
+    public SurfaceData getReplacement() {
+        return this;
+    }
+
+    private native void initOps(long context, ByteBuffer byteParameters, Object[] objectParameters, int width, int height);
+
+    public void enableFlushing() {
+        _flush();
+    }
+    native void _flush();
+
+    public Object getDestination() {
+        // this should never get called for the printer surface (see BufferStrategyPaintManager for one case of usage)
+        return null;
+    }
+
+    public Raster getRaster(int x, int y, int w, int h) {
+        BufferedImage dstImage = new BufferedImage(x + w, y + h, BufferedImage.TYPE_INT_ARGB_PRE);
+        return dstImage.getRaster();
+    }
+
+    public BufferedImage copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, BufferedImage dstImage) {
+        // create the destination image if needed
+        if (dstImage == null) {
+            dstImage = getDeviceConfiguration().createCompatibleImage(w, h);
+        }
+
+        // copy
+        Graphics g = dstImage.createGraphics();
+        BufferedImage thisImage = getCompositingImage(w, h);
+        g.drawImage(thisImage, 0, 0, w, h, x, y, x+w, y+h, null);
+        g.dispose();
+
+        return dstImage;
+    }
+
+    public boolean xorSurfacePixels(SunGraphics2D sg2d, BufferedImage srcPixels, int x, int y, int w, int h, int colorXOR) {
+        throw new InternalError("not implemented yet");
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CRobot.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CRobot.java
new file mode 100644
index 0000000..e436b8b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CRobot.java
@@ -0,0 +1,253 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.peer.*;
+
+import sun.awt.CGraphicsDevice;
+
+class CRobot implements RobotPeer {
+
+    private static final int MOUSE_LOCATION_UNKNOWN      = -1;
+    private static final int BUTTON_STATE_UNKNOWN        = 0;
+    private static final int BUTTON_STATE_DOWN           = 1;
+    private static final int BUTTON_STATE_UP             = 2;
+    private static final int MODIFIER_PREVIOUSLY_UNKNOWN = 0;
+    private static final int MODIFIER_PREVIOUSLY_UP      = 1;
+    private static final int MODIFIER_PREVIOUSLY_DOWN    = 2;
+
+    private final CGraphicsDevice fDevice;
+    private int fMouseLastX             = MOUSE_LOCATION_UNKNOWN;
+    private int fMouseLastY             = MOUSE_LOCATION_UNKNOWN;
+    private int fMouse1DesiredState     = BUTTON_STATE_UNKNOWN;
+    private int fMouse2DesiredState     = BUTTON_STATE_UNKNOWN;
+    private int fMouse3DesiredState     = BUTTON_STATE_UNKNOWN;
+    private int fMouse2KeyModifierState = MODIFIER_PREVIOUSLY_UNKNOWN;
+    private int fMouse3KeyModifierState = MODIFIER_PREVIOUSLY_UNKNOWN;
+    private boolean fMouseMoveAction;
+
+    /**
+     * Uses the given GraphicsDevice as the coordinate system for subsequent
+     * coordinate calls.
+     */
+    public CRobot(Robot r, CGraphicsDevice d) {
+        fDevice = d;
+        initRobot();
+    }
+
+    @Override
+    public void dispose() {
+    }
+
+    /**
+     * Moves mouse pointer to given screen coordinates.
+     * @param x X position
+     * @param y Y position
+     */
+    @Override
+    public void mouseMove(int x, int y) {
+        fMouseLastX = x;
+        fMouseLastY = y;
+        fMouseMoveAction = true;
+        mouseEvent(fDevice.getCoreGraphicsScreen(), fMouseLastX, fMouseLastY,
+                   fMouse1DesiredState, fMouse2DesiredState,
+                   fMouse3DesiredState, fMouseMoveAction);
+    }
+
+    /**
+     * Presses one or more mouse buttons.
+     *
+     * @param buttons the button mask (combination of
+     * <code>InputEvent.BUTTON1/2/3_MASK</code>)
+     */
+    @Override
+    public void mousePress(int buttons) {
+        if ((buttons & InputEvent.BUTTON1_MASK) != 0 ||
+                (buttons & InputEvent.BUTTON1_DOWN_MASK) != 0) {
+            fMouse1DesiredState = BUTTON_STATE_DOWN;
+        } else {
+            fMouse1DesiredState = BUTTON_STATE_UNKNOWN;
+        }
+
+        if ((buttons & InputEvent.BUTTON2_MASK) != 0 ||
+                (buttons & InputEvent.BUTTON2_DOWN_MASK) != 0) {
+            fMouse2DesiredState = BUTTON_STATE_DOWN;
+        } else {
+            fMouse2DesiredState = BUTTON_STATE_UNKNOWN;
+        }
+
+        if ((buttons & InputEvent.BUTTON3_MASK) != 0 ||
+                (buttons & InputEvent.BUTTON3_DOWN_MASK) != 0) {
+            fMouse3DesiredState = BUTTON_STATE_DOWN;
+        } else {
+            fMouse3DesiredState = BUTTON_STATE_UNKNOWN;
+        }
+
+        fMouseMoveAction = false;
+
+        mouseEvent(fDevice.getCoreGraphicsScreen(), fMouseLastX, fMouseLastY,
+                   fMouse1DesiredState, fMouse2DesiredState,
+                   fMouse3DesiredState, fMouseMoveAction);
+    }
+
+    /**
+     * Releases one or more mouse buttons.
+     *
+     * @param buttons the button mask (combination of
+     * <code>InputEvent.BUTTON1/2/3_MASK</code>)
+     */
+    @Override
+    public void mouseRelease(int buttons) {
+        if ((buttons & InputEvent.BUTTON1_MASK) != 0 ||
+                (buttons & InputEvent.BUTTON1_DOWN_MASK) != 0) {
+            fMouse1DesiredState = BUTTON_STATE_UP;
+        } else {
+            fMouse1DesiredState = BUTTON_STATE_UNKNOWN;
+        }
+
+        if ((buttons & InputEvent.BUTTON2_MASK) != 0 ||
+                (buttons & InputEvent.BUTTON2_DOWN_MASK) != 0) {
+            fMouse2DesiredState = BUTTON_STATE_UP;
+        } else {
+            fMouse2DesiredState = BUTTON_STATE_UNKNOWN;
+        }
+
+        if ((buttons & InputEvent.BUTTON3_MASK) != 0 ||
+                (buttons & InputEvent.BUTTON3_DOWN_MASK) != 0) {
+            fMouse3DesiredState = BUTTON_STATE_UP;
+        } else {
+            fMouse3DesiredState = BUTTON_STATE_UNKNOWN;
+        }
+
+        fMouseMoveAction = false;
+
+        mouseEvent(fDevice.getCoreGraphicsScreen(), fMouseLastX, fMouseLastY,
+                   fMouse1DesiredState, fMouse2DesiredState,
+                   fMouse3DesiredState, fMouseMoveAction);
+    }
+
+    @Override
+    public native void mouseWheel(int wheelAmt);
+
+    /**
+     * Presses a given key.
+     * <p>
+     * Key codes that have more than one physical key associated with them
+     * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
+     * left or right shift key) will map to the left key.
+     * <p>
+     * Assumes that the
+     * peer implementations will throw an exception for other bogus
+     * values e.g. -1, 999999
+     *
+     * @param keycode the key to press (e.g. <code>KeyEvent.VK_A</code>)
+     */
+    @Override
+    public void keyPress(final int keycode) {
+        keyEvent(keycode, true);
+    }
+
+    /**
+     * Releases a given key.
+     * <p>
+     * Key codes that have more than one physical key associated with them
+     * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
+     * left or right shift key) will map to the left key.
+     * <p>
+     * Assumes that the
+     * peer implementations will throw an exception for other bogus
+     * values e.g. -1, 999999
+     *
+     * @param keycode the key to release (e.g. <code>KeyEvent.VK_A</code>)
+     */
+    @Override
+    public void keyRelease(final int keycode) {
+        keyEvent(keycode, false);
+    }
+
+    /**
+     * Returns the color of a pixel at the given screen coordinates.
+     * @param x X position of pixel
+     * @param y Y position of pixel
+     * @return color of the pixel
+     */
+    @Override
+    public int getRGBPixel(int x, int y) {
+        int c[] = new int[1];
+        getScreenPixels(new Rectangle(x, y, 1, 1), c);
+        return c[0];
+    }
+
+    /**
+     * Creates an image containing pixels read from the screen.
+     * @param bounds the rect to capture in screen coordinates
+     * @return the array of pixels
+     */
+    @Override
+    public int [] getRGBPixels(final Rectangle bounds) {
+        Rectangle screenBounds = fDevice.getDefaultConfiguration().getBounds();
+        // screenBounds is in the coordinates of the primary device
+        // but bounds is in the coordinates of fDevice
+        // so we fix screenbounds at 0,0 origin
+        screenBounds.x = screenBounds.y = 0;
+        Rectangle intersection = screenBounds.intersection(bounds);
+
+        int c[] = new int[intersection.width * intersection.height];
+        getScreenPixels(intersection, c);
+
+        if (!intersection.equals(bounds)) {
+            // Since we are returning a smaller array than the code expects,
+            // we have to copy our existing array into an array of the
+            // "correct" size
+            int c2[] = new int[bounds.width * bounds.height];
+            for (int h=0; h<bounds.height; h++) {
+                int boundsRow = h+bounds.y;
+                if (boundsRow>=intersection.y && boundsRow<intersection.height) {
+                    int srcPos = (boundsRow-intersection.y)*intersection.width;
+                    int destPos = (h*bounds.width) + (intersection.x-bounds.x);
+                    System.arraycopy(c, srcPos, c2, destPos, intersection.width);
+                }
+            }
+            c = c2;
+        }
+
+        return c;
+    }
+
+    private native void initRobot();
+    private native void mouseEvent(int screen, int lastX, int lastY,
+                                   int button1DesiredState,
+                                   int button2DesiredState,
+                                   int button3DesiredState,
+                                   boolean moveAction);
+    private native void keyEvent(int javaKeyCode, boolean keydown);
+    private void getScreenPixels(Rectangle r, int[] pixels){
+        nativeGetScreenPixels(r.x, r.y, r.width, r.height, pixels);
+    }
+    private native void nativeGetScreenPixels(int x, int y, int width, int height, int[] pixels);
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CSystemTray.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CSystemTray.java
new file mode 100644
index 0000000..8b453ef
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CSystemTray.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.Dimension;
+import java.awt.peer.SystemTrayPeer;
+
+public class CSystemTray implements SystemTrayPeer {
+
+    CSystemTray(){
+    }
+
+    @Override
+    public Dimension getTrayIconSize() {
+        // TODO: ask the native system.
+        return new Dimension(20, 20);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CTextPipe.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CTextPipe.java
new file mode 100644
index 0000000..00b859a
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CTextPipe.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+
+import java.awt.*;
+import java.awt.font.*;
+
+import sun.awt.*;
+import sun.font.*;
+import sun.java2d.*;
+import sun.java2d.loops.*;
+import sun.java2d.pipe.*;
+
+public class CTextPipe implements TextPipe {
+    public native void doDrawString(SurfaceData sData, long nativeStrikePtr, String s, double x, double y);
+    public native void doDrawGlyphs(SurfaceData sData, long nativeStrikePtr, GlyphVector gV, float x, float y);
+    public native void doUnicodes(SurfaceData sData, long nativeStrikePtr, char unicodes[], int offset, int length, float x, float y);
+    public native void doOneUnicode(SurfaceData sData, long nativeStrikePtr, char aUnicode, float x, float y);
+
+    long getNativeStrikePtr(final SunGraphics2D sg2d) {
+        final FontStrike fontStrike = sg2d.getFontInfo().fontStrike;
+        if (!(fontStrike instanceof CStrike)) return 0;
+        return ((CStrike)fontStrike).getNativeStrikePtr();
+    }
+
+    void drawGlyphVectorAsShape(final SunGraphics2D sg2d, final GlyphVector gv, final float x, final float y) {
+        final int length = gv.getNumGlyphs();
+        for (int i = 0; i < length; i++) {
+            final Shape glyph = gv.getGlyphOutline(i, x, y);
+            sg2d.fill(glyph);
+        }
+    }
+
+    void drawTextAsShape(final SunGraphics2D sg2d, final String s, final double x, final double y) {
+        final Object oldAliasingHint = sg2d.getRenderingHint(SunHints.KEY_ANTIALIASING);
+        final FontRenderContext frc = sg2d.getFontRenderContext();
+        sg2d.setRenderingHint(SunHints.KEY_ANTIALIASING, (frc.isAntiAliased() ? SunHints.VALUE_ANTIALIAS_ON : SunHints.VALUE_ANTIALIAS_OFF));
+
+        final Font font = sg2d.getFont();
+        final GlyphVector gv = font.createGlyphVector(frc, s);
+        final int length = gv.getNumGlyphs();
+        for (int i = 0; i < length; i++) {
+            final Shape glyph = gv.getGlyphOutline(i, (float)x, (float)y);
+            sg2d.fill(glyph);
+        }
+
+        sg2d.setRenderingHint(SunHints.KEY_ANTIALIASING, oldAliasingHint);
+    }
+
+    public void drawString(final SunGraphics2D sg2d, final String s, final double x, final double y) {
+        final long nativeStrikePtr = getNativeStrikePtr(sg2d);
+        if (OSXSurfaceData.IsSimpleColor(sg2d.paint) && nativeStrikePtr != 0) {
+            final OSXSurfaceData surfaceData = (OSXSurfaceData)sg2d.getSurfaceData();
+            surfaceData.drawString(this, sg2d, nativeStrikePtr, s, x, y);
+        } else {
+            drawTextAsShape(sg2d, s, x, y);
+        }
+    }
+
+    public void drawGlyphVector(final SunGraphics2D sg2d, final GlyphVector gV, final float x, final float y) {
+        final Font prevFont = sg2d.getFont();
+        sg2d.setFont(gV.getFont());
+
+        final long nativeStrikePtr = getNativeStrikePtr(sg2d);
+        if (OSXSurfaceData.IsSimpleColor(sg2d.paint) && nativeStrikePtr != 0) {
+            final OSXSurfaceData surfaceData = (OSXSurfaceData)sg2d.getSurfaceData();
+            surfaceData.drawGlyphs(this, sg2d, nativeStrikePtr, gV, x, y);
+        } else {
+            drawGlyphVectorAsShape(sg2d, gV, x, y);
+        }
+        sg2d.setFont(prevFont);
+    }
+
+    public void drawChars(final SunGraphics2D sg2d, final char data[], final int offset, final int length, final int x, final int y) {
+        final long nativeStrikePtr = getNativeStrikePtr(sg2d);
+        if (OSXSurfaceData.IsSimpleColor(sg2d.paint) && nativeStrikePtr != 0) {
+            final OSXSurfaceData surfaceData = (OSXSurfaceData)sg2d.getSurfaceData();
+            surfaceData.drawUnicodes(this, sg2d, nativeStrikePtr, data, offset, length, x, y);
+        } else {
+            drawTextAsShape(sg2d, new String(data, offset, length), x, y);
+        }
+    }
+
+    public CTextPipe traceWrap() {
+        return new Tracer();
+    }
+
+    public static class Tracer extends CTextPipe {
+        void doDrawString(final SurfaceData sData, final long nativeStrikePtr, final String s, final float x, final float y) {
+            GraphicsPrimitive.tracePrimitive("QuartzDrawString");
+            super.doDrawString(sData, nativeStrikePtr, s, x, y);
+        }
+
+        public void doDrawGlyphs(final SurfaceData sData, final long nativeStrikePtr, final GlyphVector gV, final float x, final float y) {
+            GraphicsPrimitive.tracePrimitive("QuartzDrawGlyphs");
+            super.doDrawGlyphs(sData, nativeStrikePtr, gV, x, y);
+        }
+
+        public void doUnicodes(final SurfaceData sData, final long nativeStrikePtr, final char unicodes[], final int offset, final int length, final float x, final float y) {
+            GraphicsPrimitive.tracePrimitive("QuartzDrawUnicodes");
+            super.doUnicodes(sData, nativeStrikePtr, unicodes, offset, length, x, y);
+        }
+
+        public void doOneUnicode(final SurfaceData sData, final long nativeStrikePtr, final char aUnicode, final float x, final float y) {
+            GraphicsPrimitive.tracePrimitive("QuartzDrawUnicode");
+            super.doOneUnicode(sData, nativeStrikePtr, aUnicode, x, y);
+        }
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CThreading.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CThreading.java
new file mode 100644
index 0000000..c533c67
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CThreading.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package sun.lwawt.macosx;
+
+import java.awt.EventQueue;
+
+
+public class CThreading {
+    static String APPKIT_THREAD_NAME = "AppKit Thread";
+
+    static boolean isEventQueue() {
+        return EventQueue.isDispatchThread();
+    }
+
+    static boolean isAppKit() {
+        return APPKIT_THREAD_NAME.equals(Thread.currentThread().getName());
+    }
+
+    static boolean assertEventQueue() {
+        final boolean isEventQueue = isEventQueue();
+        assert isEventQueue : "Threading violation: not EventQueue thread";
+        return isEventQueue;
+    }
+
+    static boolean assertNotEventQueue() {
+        final boolean isNotEventQueue = isEventQueue();
+        assert isNotEventQueue : "Threading violation: EventQueue thread";
+        return isNotEventQueue;
+    }
+
+    static boolean assertAppKit() {
+        final boolean isAppKitThread = isAppKit();
+        assert isAppKitThread : "Threading violation: not AppKit thread";
+        return isAppKitThread;
+    }
+
+    static boolean assertNotAppKit() {
+        final boolean isNotAppKitThread = !isAppKit();
+        assert isNotAppKitThread : "Threading violation: AppKit thread";
+        return isNotAppKitThread;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
new file mode 100644
index 0000000..2d36a91
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
+
+// TODO:BG this class is really a NOOP right now, but should be filled in if needed.
+
+final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler {
+    public void lock() {
+    }
+
+    public void unlock() {
+    }
+
+    protected boolean isOwned() {
+       return false;
+    }
+
+    public void enter() {
+    }
+
+    public void exit() {
+    }
+
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java
new file mode 100644
index 0000000..fac844e
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java
@@ -0,0 +1,418 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import sun.awt.SunToolkit;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.Point2D;
+import java.awt.image.BufferedImage;
+import java.awt.peer.TrayIconPeer;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
+    private TrayIcon target;
+    private PopupMenu popup;
+    private JDialog messageDialog;
+    private DialogEventHandler handler;
+
+    CTrayIcon(TrayIcon target) {
+        super(0, true);
+
+        this.messageDialog = null;
+        this.handler = null;
+        this.target = target;
+        this.popup = target.getPopupMenu();
+        setPtr(createModel());
+
+        //if no one else is creating the peer.
+        checkAndCreatePopupPeer();
+        updateImage();
+    }
+
+    private CPopupMenu checkAndCreatePopupPeer() {
+        CPopupMenu menuPeer = null;
+        if (popup != null) {
+            try {
+                menuPeer = (CPopupMenu)popup.getPeer();
+                if (menuPeer == null) {
+                    popup.addNotify();
+                }
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        }
+        return menuPeer;
+    }
+
+    private long createModel() {
+        return nativeCreate();
+    }
+
+    private long getModel() {
+        return ptr;
+    }
+
+    private native long nativeCreate();
+
+    //invocation from the AWTTrayIcon.m
+    public long getPopupMenuModel(){
+        if(popup == null) {
+            return 0L;
+        }
+        return checkAndCreatePopupPeer().getModel();
+    }
+
+    /**
+     * We display tray icon message as a small dialog with OK button.
+     * This is lame, but JDK 1.6 does basically the same. There is a new
+     * kind of window in Lion, NSPopover, so perhaps it could be used it
+     * to implement better looking notifications.
+     */
+    public void displayMessage(final String caption, final String text,
+                               final String messageType) {
+
+        if (SwingUtilities.isEventDispatchThread()) {
+            displayMessageOnEDT(caption, text, messageType);
+        } else {
+            try {
+                SwingUtilities.invokeAndWait(new Runnable() {
+                    public void run() {
+                        displayMessageOnEDT(caption, text, messageType);
+                    }
+                });
+            } catch (Exception e) {
+                throw new AssertionError(e);
+            }
+        }
+    }
+
+    @Override
+    public void dispose() {
+        if (messageDialog != null) {
+            disposeMessageDialog();
+        }
+
+        LWCToolkit.targetDisposedPeer(target, this);
+        target = null;
+
+        super.dispose();
+    }
+
+    @Override
+    public void setToolTip(String tooltip) {
+        nativeSetToolTip(getModel(), tooltip);
+    }
+
+    //adds tooltip to the NSStatusBar's NSButton.
+    private native void nativeSetToolTip(long trayIconModel, String tooltip);
+
+    @Override
+    public void showPopupMenu(int x, int y) {
+        //Not used. The popupmenu is shown from the native code.
+    }
+
+    @Override
+    public void updateImage() {
+        Image image = target.getImage();
+        if (image == null) return;
+
+        MediaTracker tracker = new MediaTracker(new Button(""));
+        tracker.addImage(image, 0);
+        try {
+            tracker.waitForAll();
+        } catch (InterruptedException ignore) { }
+
+        if (image.getWidth(null) <= 0 ||
+            image.getHeight(null) <= 0)
+        {
+            return;
+        }
+
+        CImage cimage = CImage.getCreator().createFromImage(image);
+        setNativeImage(getModel(), cimage.ptr, target.isImageAutoSize());
+    }
+
+    private native void setNativeImage(final long model, final long nsimage, final boolean autosize);
+
+    //invocation from the AWTTrayIcon.m
+    public void performAction() {
+        SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
+            public void run() {
+                final String cmd = target.getActionCommand();
+                final ActionEvent event = new ActionEvent(target, ActionEvent.ACTION_PERFORMED, cmd);
+                SunToolkit.postEvent(SunToolkit.targetToAppContext(target), event);
+            }
+        });
+    }
+
+    private native Point2D nativeGetIconLocation(long trayIconModel);
+
+    public void displayMessageOnEDT(String caption, String text,
+                                    String messageType) {
+        if (messageDialog != null) {
+            disposeMessageDialog();
+        }
+
+        // obtain icon to show along the message
+        Icon icon = getIconForMessageType(messageType);
+        if (icon != null) {
+            icon = new ImageIcon(scaleIcon(icon, 0.75));
+        }
+
+        // We want the message dialog text area to be about 1/8 of the screen
+        // size. There is nothing special about this value, it's just makes the
+        // message dialog to look nice
+        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
+        int textWidth = screenSize.width / 8;
+
+        // create dialog to show
+        messageDialog = createMessageDialog(caption, text, textWidth, icon);
+
+        // finally, show the dialog to user
+        showMessageDialog();
+    }
+
+    /**
+     * Creates dialog window used to display the message
+     */
+    private JDialog createMessageDialog(String caption, String text,
+                                     int textWidth, Icon icon) {
+        JDialog dialog;
+        handler = new DialogEventHandler();
+
+        JTextArea captionArea = null;
+        if (caption != null) {
+            captionArea = createTextArea(caption, textWidth, false, true);
+        }
+
+        JTextArea textArea = null;
+        if (text != null){
+            textArea = createTextArea(text, textWidth, true, false);
+        }
+
+        Object[] panels = null;
+        if (captionArea != null) {
+            if (textArea != null) {
+                panels = new Object[] {captionArea, new JLabel(), textArea};
+            } else {
+                panels = new Object[] {captionArea};
+            }
+        } else {
+           if (textArea != null) {
+                panels = new Object[] {textArea};
+            }
+        }
+
+        // We want message dialog with small title bar. There is a client
+        // property property that does it, however, it must be set before
+        // dialog's native window is created. This is why we create option
+        // pane and dialog separately
+        final JOptionPane op = new JOptionPane(panels);
+        op.setIcon(icon);
+        op.addPropertyChangeListener(handler);
+
+        // Make Ok button small. Most likely won't work for L&F other then Aqua
+        try {
+            JPanel buttonPanel = (JPanel)op.getComponent(1);
+            JButton ok = (JButton)buttonPanel.getComponent(0);
+            ok.putClientProperty("JComponent.sizeVariant", "small");
+        } catch (Throwable t) {
+            // do nothing, we tried and failed, no big deal
+        }
+
+        dialog = new JDialog((Dialog) null);
+        JRootPane rp = dialog.getRootPane();
+
+        // gives us dialog window with small title bar and not zoomable
+        rp.putClientProperty(CPlatformWindow.WINDOW_STYLE, "small");
+        rp.putClientProperty(CPlatformWindow.WINDOW_ZOOMABLE, "false");
+
+        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
+        dialog.setModal(false);
+        dialog.setResizable(false);
+        dialog.setContentPane(op);
+
+        dialog.addWindowListener(handler);
+
+        dialog.pack();
+
+        return dialog;
+    }
+
+    private void showMessageDialog() {
+
+        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
+        Point2D iconLoc = nativeGetIconLocation(getModel());
+
+        int dialogY = (int)iconLoc.getY();
+        int dialogX = (int)iconLoc.getX();
+        if (dialogX + messageDialog.getWidth() > screenSize.width) {
+            dialogX = screenSize.width - messageDialog.getWidth();
+        }
+
+        messageDialog.setLocation(dialogX, dialogY);
+        messageDialog.setVisible(true);
+    }
+
+   private void disposeMessageDialog() {
+        if (SwingUtilities.isEventDispatchThread()) {
+            disposeMessageDialogOnEDT();
+        } else {
+            try {
+                SwingUtilities.invokeAndWait(new Runnable() {
+                    public void run() {
+                        disposeMessageDialogOnEDT();
+                    }
+                });
+            } catch (Exception e) {
+                throw new AssertionError(e);
+            }
+        }
+   }
+
+    private void disposeMessageDialogOnEDT() {
+        if (messageDialog != null) {
+            messageDialog.removeWindowListener(handler);
+            messageDialog.removePropertyChangeListener(handler);
+            messageDialog.dispose();
+
+            messageDialog = null;
+            handler = null;
+        }
+    }
+
+    /**
+     * Scales an icon using specified scale factor
+     *
+     * @param icon        icon to scale
+     * @param scaleFactor scale factor to use
+     * @return scaled icon as BuffedredImage
+     */
+    private static BufferedImage scaleIcon(Icon icon, double scaleFactor) {
+        if (icon == null) {
+            return null;
+        }
+
+        int w = icon.getIconWidth();
+        int h = icon.getIconHeight();
+
+        GraphicsEnvironment ge =
+                GraphicsEnvironment.getLocalGraphicsEnvironment();
+        GraphicsDevice gd = ge.getDefaultScreenDevice();
+        GraphicsConfiguration gc = gd.getDefaultConfiguration();
+
+        // convert icon into image
+        BufferedImage iconImage = gc.createCompatibleImage(w, h,
+                Transparency.TRANSLUCENT);
+        Graphics2D g = iconImage.createGraphics();
+        icon.paintIcon(null, g, 0, 0);
+        g.dispose();
+
+        // and scale it nicely
+        int scaledW = (int) (w * scaleFactor);
+        int scaledH = (int) (h * scaleFactor);
+        BufferedImage scaledImage = gc.createCompatibleImage(scaledW, scaledH,
+                Transparency.TRANSLUCENT);
+        g = scaledImage.createGraphics();
+        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+        g.drawImage(iconImage, 0, 0, scaledW, scaledH, null);
+        g.dispose();
+
+        return scaledImage;
+    }
+
+
+    /**
+     * Gets Aqua icon used in message dialog.
+     */
+    private static Icon getIconForMessageType(String messageType) {
+        if (messageType.equals("ERROR")) {
+            return UIManager.getIcon("OptionPane.errorIcon");
+        } else if (messageType.equals("WARNING")) {
+            return UIManager.getIcon("OptionPane.warningIcon");
+        } else {
+            // this is just an application icon
+            return UIManager.getIcon("OptionPane.informationIcon");
+        }
+    }
+
+    private static JTextArea createTextArea(String text, int width,
+                                            boolean isSmall, boolean isBold) {
+        JTextArea textArea = new JTextArea(text);
+
+        textArea.setLineWrap(true);
+        textArea.setWrapStyleWord(true);
+        textArea.setEditable(false);
+        textArea.setFocusable(false);
+        textArea.setBorder(null);
+        textArea.setBackground(new JLabel().getBackground());
+
+        if (isSmall) {
+            textArea.putClientProperty("JComponent.sizeVariant", "small");
+        }
+
+        if (isBold) {
+            Font font = textArea.getFont();
+            Font boldFont = new Font(font.getName(), Font.BOLD, font.getSize());
+            textArea.setFont(boldFont);
+        }
+
+        textArea.setSize(width, 1);
+
+        return textArea;
+    }
+
+    /**
+     * Implements all the Listeners needed by message dialog
+     */
+    private final class DialogEventHandler extends WindowAdapter
+            implements PropertyChangeListener {
+
+        public void windowClosing(WindowEvent we) {
+                disposeMessageDialog();
+        }
+
+        public void propertyChange(PropertyChangeEvent e) {
+            if (messageDialog == null) {
+                return;
+            }
+
+            String prop = e.getPropertyName();
+            Container cp = messageDialog.getContentPane();
+
+            if (messageDialog.isVisible() && e.getSource() == cp &&
+                    (prop.equals(JOptionPane.VALUE_PROPERTY))) {
+                disposeMessageDialog();
+            }
+        }
+    }
+}
+
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CWrapper.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CWrapper.java
new file mode 100644
index 0000000..05c3b1f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CWrapper.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.geom.Rectangle2D;
+
+public final class CWrapper {
+    private CWrapper() { }
+
+    public static final class NSWindow {
+        // NSWindowOrderingMode
+        public static final int NSWindowAbove = 1;
+        public static final int NSWindowBelow = -1;
+        public static final int NSWindowOut = 0;
+
+        public static native void makeKeyAndOrderFront(long window);
+        public static native void makeMainWindow(long window);
+        public static native boolean canBecomeMainWindow(long window);
+        public static native boolean isKeyWindow(long window);
+
+        public static native void orderFront(long window);
+        public static native void orderFrontRegardless(long window);
+        public static native void orderWindow(long window, int ordered, long relativeTo);
+        public static native void orderOut(long window);
+
+        public static native void addChildWindow(long parent, long child, int ordered);
+        public static native void removeChildWindow(long parent, long child);
+
+        public static native void setFrame(long window, int x, int y, int w, int h, boolean display);
+
+        public static native void setAlphaValue(long window, float alpha);
+        public static native void setOpaque(long window, boolean opaque);
+        public static native void setBackgroundColor(long window, long color);
+
+        public static native void miniaturize(long window);
+        public static native void deminiaturize(long window);
+        public static native void zoom(long window);
+
+        public static native void makeFirstResponder(long window, long responder);
+
+        public static native long screen(long window);
+    }
+
+    public static final class NSView {
+        public static native void addSubview(long view, long subview);
+        public static native void removeFromSuperview(long view);
+
+        public static native void setFrame(long view, int x, int y, int w, int h);
+        public static native Rectangle2D frame(long view);
+        public static native long window(long view);
+
+        public static native void enterFullScreenMode(long view);
+        public static native void exitFullScreenMode(long view);
+    }
+
+    public static final class NSObject {
+        public static native void release(long object);
+    }
+
+    public static final class NSScreen {
+        public static native Rectangle2D frame(long screen);
+        public static native Rectangle2D visibleFrame(long screen);
+        public static native long screenByDisplayId(int displayID);
+    }
+
+    public static final class NSColor {
+        public static native long clearColor();
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CocoaConstants.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CocoaConstants.java
new file mode 100644
index 0000000..c86779c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CocoaConstants.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+public final class CocoaConstants {
+    private CocoaConstants(){}
+
+    //from the NSEvent class reference:
+    public final static int NSLeftMouseDown      = 1;
+    public final static int NSLeftMouseUp        = 2;
+    public final static int NSRightMouseDown     = 3;
+    public final static int NSRightMouseUp       = 4;
+    public final static int NSMouseMoved         = 5;
+    public final static int NSLeftMouseDragged   = 6;
+    public final static int NSRightMouseDragged  = 7;
+    public final static int NSMouseEntered       = 8;
+    public final static int NSMouseExited        = 9;
+    public final static int NSKeyDown            = 10;
+    public final static int NSKeyUp              = 11;
+    public final static int NSFlagsChanged       = 12;
+
+    public final static int NSScrollWheel        = 22;
+    public final static int NSOtherMouseDown     = 25;
+    public final static int NSOtherMouseUp       = 26;
+    public final static int NSOtherMouseDragged  = 27;
+
+    public final static int AllLeftMouseEventsMask =
+        1 << NSLeftMouseDown |
+        1 << NSLeftMouseUp |
+        1 << NSLeftMouseDragged;
+
+    public final static int AllRightMouseEventsMask =
+        1 << NSRightMouseDown |
+        1 << NSRightMouseUp |
+        1 << NSRightMouseDragged;
+
+    public final static int AllOtherMouseEventsMask =
+        1 << NSOtherMouseDown |
+        1 << NSOtherMouseUp |
+        1 << NSOtherMouseDragged;
+
+    /*
+    NSAppKitDefined      = 13,
+    NSSystemDefined      = 14,
+    NSApplicationDefined = 15,
+    NSPeriodic           = 16,
+    NSCursorUpdate       = 17,
+    NSScrollWheel        = 22,
+    NSTabletPoint        = 23,
+    NSTabletProximity    = 24,
+    NSEventTypeGesture   = 29,
+    NSEventTypeMagnify   = 30,
+    NSEventTypeSwipe     = 31,
+    NSEventTypeRotate    = 18,
+    NSEventTypeBeginGesture = 19,
+    NSEventTypeEndGesture   = 20
+    */
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java b/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java
new file mode 100644
index 0000000..1124d12
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+// This exists strictly to work around the fact that java.awt.Conditional isn't a public class.
+// It uses java reflection to get the EventDispatchThread class and call a MacOSX only
+// method on it.
+//
+// NOTE: This uses reflection in its implementation, so it is not for performance critical code.
+//
+// See java.awt.EventDispatchThread and apple.awt.CPrintJob for more.
+//
+public abstract class EventDispatchAccess {
+    public native void pumpEventsAndWait();
+    public abstract boolean evaluate();
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
new file mode 100644
index 0000000..3124c0f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
@@ -0,0 +1,715 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.datatransfer.Clipboard;
+import java.awt.dnd.*;
+import java.awt.dnd.peer.DragSourceContextPeer;
+import java.awt.event.InputEvent;
+import java.awt.event.InvocationEvent;
+import java.awt.im.InputMethodHighlight;
+import java.awt.peer.*;
+import java.lang.reflect.*;
+import java.security.*;
+import java.util.*;
+import java.util.concurrent.Callable;
+
+import sun.awt.*;
+import sun.lwawt.*;
+import sun.lwawt.LWWindowPeer.PeerType;
+
+
+class NamedCursor extends Cursor {
+    NamedCursor(String name) {
+        super(name);
+    }
+}
+
+/**
+ * Mac OS X Cocoa-based AWT Toolkit.
+ */
+public class LWCToolkit extends LWToolkit {
+    private static final Integer BUTTONS = 3; // number of available mouse buttons
+
+    private static native void initIDs();
+
+    private static CInputMethodDescriptor sInputMethodDescriptor;
+
+    static {
+        System.err.flush();
+        java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() {
+            public Object run() {
+                System.loadLibrary("awt");
+                System.loadLibrary("fontmanager");
+                return null;
+            }
+        });
+        if (!GraphicsEnvironment.isHeadless()) {
+            initIDs();
+        }
+    }
+
+    static String getSystemProperty(final String name, final String deflt) {
+        return AccessController.doPrivileged (new PrivilegedAction<String>() {
+            public String run() {
+                return System.getProperty(name, deflt);
+            }
+        });
+    }
+
+    public LWCToolkit() {
+        SunToolkit.setDataTransfererClassName("sun.lwawt.macosx.CDataTransferer");
+    }
+
+    /*
+     * System colors with default initial values, overwritten by toolkit if system values differ and are available.
+     */
+    private final static int NUM_APPLE_COLORS = 3;
+    public final static int KEYBOARD_FOCUS_COLOR = 0;
+    public final static int INACTIVE_SELECTION_BACKGROUND_COLOR = 1;
+    public final static int INACTIVE_SELECTION_FOREGROUND_COLOR = 2;
+    private static int[] appleColors = {
+        0xFF808080, // keyboardFocusColor = Color.gray;
+        0xFFC0C0C0, // secondarySelectedControlColor
+        0xFF303030, // controlDarkShadowColor
+    };
+
+    private native void loadNativeColors(final int[] systemColors, final int[] appleColors);
+
+    protected void loadSystemColors(final int[] systemColors) {
+        if (systemColors == null) return;
+        loadNativeColors(systemColors, appleColors);
+    }
+
+    private static class AppleSpecificColor extends Color {
+        int index;
+        public AppleSpecificColor(int index) {
+            super(appleColors[index]);
+            this.index = index;
+        }
+
+        public int getRGB() {
+            return appleColors[index];
+        }
+    }
+
+    /**
+     * Returns Apple specific colors that we may expose going forward.
+     *
+     */
+    public static Color getAppleColor(int color) {
+        return new AppleSpecificColor(color);
+    }
+
+    static void systemColorsChanged() {
+        // This is only called from native code.
+        EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                AccessController.doPrivileged (new PrivilegedAction<Object>() {
+                    public Object run() {
+                        try {
+                            final Method updateColorsMethod = SystemColor.class.getDeclaredMethod("updateSystemColors", new Class[0]);
+                            updateColorsMethod.setAccessible(true);
+                            updateColorsMethod.invoke(null, new Object[0]);
+                        } catch (final Throwable e) {
+                            e.printStackTrace();
+                            // swallow this if something goes horribly wrong
+                        }
+                        return null;
+                    }
+                });
+            }
+           });
+    }
+
+    @Override
+    protected PlatformWindow createPlatformWindow(PeerType peerType) {
+        // TODO: window type
+        return new CPlatformWindow(peerType);
+    }
+
+    @Override
+    protected PlatformComponent createPlatformComponent() {
+        return new CPlatformComponent();
+    }
+
+    @Override
+    protected FileDialogPeer createFileDialogPeer(FileDialog target) {
+        return new CFileDialog(target);
+    }
+
+    @Override
+    public MenuPeer createMenu(Menu target) {
+        MenuPeer peer = new CMenu(target);
+        targetCreatedPeer(target, peer);
+        return peer;
+    }
+
+    @Override
+    public MenuBarPeer createMenuBar(MenuBar target) {
+         MenuBarPeer peer = new CMenuBar(target);
+         targetCreatedPeer(target, peer);
+             return peer;
+    }
+
+    @Override
+    public MenuItemPeer createMenuItem(MenuItem target) {
+        MenuItemPeer peer = new CMenuItem(target);
+        targetCreatedPeer(target, peer);
+        return peer;
+    }
+
+    @Override
+    public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
+        CheckboxMenuItemPeer peer = new CCheckboxMenuItem(target);
+        targetCreatedPeer(target, peer);
+        return peer;
+    }
+
+    @Override
+    public PopupMenuPeer createPopupMenu(PopupMenu target) {
+        PopupMenuPeer peer = new CPopupMenu(target);
+        targetCreatedPeer(target, peer);
+        return peer;
+
+    }
+
+    @Override
+    public SystemTrayPeer createSystemTray(SystemTray target) {
+        SystemTrayPeer peer = new CSystemTray();
+        targetCreatedPeer(target, peer);
+        return peer;
+    }
+
+    @Override
+    public TrayIconPeer createTrayIcon(TrayIcon target) {
+        TrayIconPeer peer = new CTrayIcon(target);
+        targetCreatedPeer(target, peer);
+        return peer;
+    }
+
+    @Override
+    public LWCursorManager getCursorManager() {
+        return CCursorManager.getInstance();
+    }
+
+    @Override
+    public Cursor createCustomCursor(final Image cursor, final Point hotSpot, final String name) throws IndexOutOfBoundsException, HeadlessException {
+        return new CCustomCursor(cursor, hotSpot, name);
+    }
+
+    @Override
+    public Dimension getBestCursorSize(final int preferredWidth, final int preferredHeight) throws HeadlessException {
+        return CCustomCursor.getBestCursorSize(preferredWidth, preferredHeight);
+    }
+
+    @Override
+    protected void platformCleanup() {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    protected void platformInit() {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    protected void platformRunMessage() {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    protected void platformShutdown() {
+        // TODO Auto-generated method stub
+
+    }
+
+    class OSXPlatformFont extends sun.awt.PlatformFont
+    {
+        public OSXPlatformFont(String name, int style)
+        {
+            super(name, style);
+        }
+        protected char getMissingGlyphCharacter()
+        {
+            // Follow up for real implementation
+            return (char)0xfff8; // see http://developer.apple.com/fonts/LastResortFont/
+        }
+    }
+    public FontPeer getFontPeer(String name, int style) {
+        return new OSXPlatformFont(name, style);
+    }
+
+    @Override
+    protected MouseInfoPeer createMouseInfoPeerImpl() {
+        return new CMouseInfoPeer();
+    }
+
+
+    @Override
+    protected int getScreenHeight() {
+        return GraphicsEnvironment.getLocalGraphicsEnvironment()
+                .getDefaultScreenDevice().getDefaultConfiguration().getBounds().height;
+    }
+
+    @Override
+    protected int getScreenWidth() {
+        return GraphicsEnvironment.getLocalGraphicsEnvironment()
+                .getDefaultScreenDevice().getDefaultConfiguration().getBounds().width;
+    }
+
+    @Override
+    protected void initializeDesktopProperties() {
+        super.initializeDesktopProperties();
+        Map <Object, Object> fontHints = new HashMap<Object, Object>();
+        fontHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        fontHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+        desktopProperties.put(SunToolkit.DESKTOPFONTHINTS, fontHints);
+        desktopProperties.put("awt.mouse.numButtons", BUTTONS);
+
+        // These DnD properties must be set, otherwise Swing ends up spewing NPEs
+        // all over the place. The values came straight off of MToolkit.
+        desktopProperties.put("DnD.Autoscroll.initialDelay", new Integer(50));
+        desktopProperties.put("DnD.Autoscroll.interval", new Integer(50));
+        desktopProperties.put("DnD.Autoscroll.cursorHysteresis", new Integer(5));
+
+        desktopProperties.put("DnD.isDragImageSupported", new Boolean(true));
+
+        // Register DnD cursors
+        desktopProperties.put("DnD.Cursor.CopyDrop", new NamedCursor("DnD.Cursor.CopyDrop"));
+        desktopProperties.put("DnD.Cursor.MoveDrop", new NamedCursor("DnD.Cursor.MoveDrop"));
+        desktopProperties.put("DnD.Cursor.LinkDrop", new NamedCursor("DnD.Cursor.LinkDrop"));
+        desktopProperties.put("DnD.Cursor.CopyNoDrop", new NamedCursor("DnD.Cursor.CopyNoDrop"));
+        desktopProperties.put("DnD.Cursor.MoveNoDrop", new NamedCursor("DnD.Cursor.MoveNoDrop"));
+        desktopProperties.put("DnD.Cursor.LinkNoDrop", new NamedCursor("DnD.Cursor.LinkNoDrop"));
+
+    }
+
+
+/*
+ * The method returns true if some events were processed during that timeout.
+ * @see sun.awt.SunToolkit#syncNativeQueue(long)
+ */
+    @Override
+    protected boolean syncNativeQueue(long timeout) {
+        return nativeSyncQueue(timeout);
+    }
+
+    @Override
+    public native void beep();
+
+    @Override
+    public int getScreenResolution() throws HeadlessException {
+        return ((CGraphicsDevice) GraphicsEnvironment
+                .getLocalGraphicsEnvironment().getDefaultScreenDevice()).getScreenResolution();
+    }
+
+    @Override
+    public Insets getScreenInsets(final GraphicsConfiguration gc) {
+        final CGraphicsConfig cgc = (CGraphicsConfig) gc;
+        final int displayId = cgc.getDevice().getCoreGraphicsScreen();
+        Rectangle fullScreen, workArea;
+        final long screen = CWrapper.NSScreen.screenByDisplayId(displayId);
+        try {
+            fullScreen = CWrapper.NSScreen.frame(screen).getBounds();
+            workArea = CWrapper.NSScreen.visibleFrame(screen).getBounds();
+        } finally {
+            CWrapper.NSObject.release(screen);
+        }
+        // Convert between Cocoa's coordinate system and Java.
+        return new Insets(fullScreen.height - workArea.height - workArea.y,
+                          workArea.x, workArea.y,
+                          fullScreen.width - workArea.width - workArea.x);
+    }
+
+    @Override
+    public void sync() {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void grab(Window w) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void ungrab(Window w) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
+        return new CRobot(target, (CGraphicsDevice)screen);
+    }
+
+    /*
+     * TODO: take a look at the Cocoa API for this method, return false for now.
+     */
+    public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException {
+        return false;
+    }
+
+    /*
+     * TODO: take a look on pointer API for Cocoa. For now, suppress extra-button
+     * mouse events.
+     */
+    public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
+        return false;
+    }
+
+    @Override
+    public boolean isTraySupported() {
+        return true;
+    }
+
+    @Override
+    public boolean isAlwaysOnTopSupported() {
+        return true;
+    }
+
+    // Intended to be called from the LWCToolkit.m only.
+    private static void installToolkitThreadNameInJava() {
+        Thread.currentThread().setName(CThreading.APPKIT_THREAD_NAME);
+    }
+
+    @Override
+    public boolean isWindowOpacitySupported() {
+        return true;
+    }
+
+    @Override
+    public boolean isFrameStateSupported(int state) throws HeadlessException {
+        switch (state) {
+            case Frame.NORMAL:
+            case Frame.ICONIFIED:
+            case Frame.MAXIMIZED_BOTH:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    /**
+     * Determines which modifier key is the appropriate accelerator
+     * key for menu shortcuts.
+     * <p>
+     * Menu shortcuts, which are embodied in the
+     * <code>MenuShortcut</code> class, are handled by the
+     * <code>MenuBar</code> class.
+     * <p>
+     * By default, this method returns <code>Event.CTRL_MASK</code>.
+     * Toolkit implementations should override this method if the
+     * <b>Control</b> key isn't the correct key for accelerators.
+     * @return    the modifier mask on the <code>Event</code> class
+     *                 that is used for menu shortcuts on this toolkit.
+     * @see       java.awt.MenuBar
+     * @see       java.awt.MenuShortcut
+     * @since     JDK1.1
+     */
+    public int getMenuShortcutKeyMask() {
+        return Event.META_MASK;
+    }
+
+    @Override
+    public Image getImage(final String filename) {
+        final Image nsImage = checkForNSImage(filename);
+        if (nsImage != null) return nsImage;
+
+        return super.getImage(filename);
+    }
+
+    static final String nsImagePrefix = "NSImage://";
+    protected Image checkForNSImage(final String imageName) {
+        if (imageName == null) return null;
+        if (!imageName.startsWith(nsImagePrefix)) return null;
+        return CImage.getCreator().createImageFromName(imageName.substring(nsImagePrefix.length()));
+    }
+
+    // Thread-safe Object.equals() called from native
+    public static boolean doEquals(final Object a, final Object b, Component c) {
+        if (a == b) return true;
+
+        final boolean[] ret = new boolean[1];
+
+        try {  invokeAndWait(new Runnable() { public void run() { synchronized(ret) {
+            ret[0] = a.equals(b);
+        }}}, c); } catch (Exception e) { e.printStackTrace(); }
+
+        synchronized(ret) { return ret[0]; }
+    }
+
+    // Kicks an event over to the appropriate eventqueue and waits for it to finish
+    // To avoid deadlocking, we manually run the NSRunLoop while waiting
+    // Any selector invoked using ThreadUtilities performOnMainThread will be processed in doAWTRunLoop
+    // The CInvocationEvent will call LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual runloop
+    public static void invokeAndWait(Runnable event, Component component) throws InterruptedException, InvocationTargetException {
+        invokeAndWait(event, component, true);
+    }
+
+    public static <T> T invokeAndWait(final Callable<T> callable, Component component) throws Exception {
+        final CallableWrapper<T> wrapper = new CallableWrapper<T>(callable);
+        invokeAndWait(wrapper, component);
+        return wrapper.getResult();
+    }
+
+    static final class CallableWrapper<T> implements Runnable {
+        final Callable<T> callable;
+        T object;
+        Exception e;
+
+        public CallableWrapper(final Callable<T> callable) {
+            this.callable = callable;
+        }
+
+        public void run() {
+            try {
+                object = callable.call();
+            } catch (final Exception e) {
+                this.e = e;
+            }
+        }
+
+        public T getResult() throws Exception {
+            if (e != null) throw e;
+            return object;
+        }
+    }
+
+    public static void invokeAndWait(Runnable event, Component component, boolean detectDeadlocks) throws InterruptedException, InvocationTargetException {
+        long mediator = createAWTRunLoopMediator();
+
+        InvocationEvent invocationEvent = new CPeerEvent(event, mediator);
+
+        if (component != null) {
+            AppContext appContext = SunToolkit.targetToAppContext(component);
+            SunToolkit.postEvent(appContext, invocationEvent);
+
+            // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
+            sun.awt.SunToolkitSubclass.flushPendingEvents(appContext);
+        } else {
+            // This should be the equivalent to EventQueue.invokeAndWait
+            ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
+        }
+
+        doAWTRunLoop(mediator, true, detectDeadlocks);
+
+        Throwable eventException = invocationEvent.getException();
+        if (eventException != null) {
+            if (eventException instanceof UndeclaredThrowableException) {
+                eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
+            }
+            throw new InvocationTargetException(eventException);
+        }
+    }
+
+    public static void invokeLater(Runnable event, Component component) throws InvocationTargetException {
+        final InvocationEvent invocationEvent = new CPeerEvent(event, 0);
+
+        if (component != null) {
+            final AppContext appContext = SunToolkit.targetToAppContext(component);
+            SunToolkit.postEvent(appContext, invocationEvent);
+
+            // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
+            sun.awt.SunToolkitSubclass.flushPendingEvents(appContext);
+        } else {
+            // This should be the equivalent to EventQueue.invokeAndWait
+            ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
+        }
+
+        final Throwable eventException = invocationEvent.getException();
+        if (eventException == null) return;
+
+        if (eventException instanceof UndeclaredThrowableException) {
+            throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
+        }
+        throw new InvocationTargetException(eventException);
+    }
+
+    // This exists purely to get around permissions issues with getSystemEventQueueImpl
+    EventQueue getSystemEventQueueForInvokeAndWait() {
+        return getSystemEventQueueImpl();
+    }
+
+
+// DnD support
+
+    public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
+        DragSourceContextPeer dscp = CDragSourceContextPeer.createDragSourceContextPeer(dge);
+
+        return dscp;
+    }
+
+    public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) {
+        DragGestureRecognizer dgr = null;
+
+        // Create a new mouse drag gesture recognizer if we have a class match:
+        if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
+            dgr = new CMouseDragGestureRecognizer(ds, c, srcActions, dgl);
+
+        return (T)dgr;
+    }
+
+// InputMethodSupport Method
+    /**
+     * Returns the default keyboard locale of the underlying operating system
+     */
+    public Locale getDefaultKeyboardLocale() {
+        Locale locale = CInputMethod.getNativeLocale();
+
+        if (locale == null) {
+            return super.getDefaultKeyboardLocale();
+        }
+
+        return locale;
+    }
+
+    public java.awt.im.spi.InputMethodDescriptor getInputMethodAdapterDescriptor() {
+        if (sInputMethodDescriptor == null)
+            sInputMethodDescriptor = new CInputMethodDescriptor();
+
+        return sInputMethodDescriptor;
+    }
+
+    /**
+     * Returns a map of visual attributes for thelevel description
+     * of the given input method highlight, or null if no mapping is found.
+     * The style field of the input method highlight is ignored. The map
+     * returned is unmodifiable.
+     * @param highlight input method highlight
+     * @return style attribute map, or null
+     * @since 1.3
+     */
+    public Map mapInputMethodHighlight(InputMethodHighlight highlight) {
+        return CInputMethod.mapInputMethodHighlight(highlight);
+    }
+
+    /**
+     * Returns key modifiers used by Swing to set up a focus accelerator key stroke.
+     */
+    @Override
+    public int getFocusAcceleratorKeyMask() {
+        return InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
+    }
+
+    // Extends PeerEvent because we want to pass long an ObjC mediator object and because we want these events to be posted early
+    // Typically, rather than relying on the notifier to call notifyAll(), we use the mediator to stop the runloop
+    public static class CPeerEvent extends PeerEvent {
+        private long _mediator = 0;
+
+        public CPeerEvent(Runnable runnable, long mediator) {
+            super(Toolkit.getDefaultToolkit(), runnable, null, true, 0);
+            _mediator = mediator;
+        }
+
+        public void dispatch() {
+            try {
+                super.dispatch();
+            } finally {
+                if (_mediator != 0) {
+                    LWCToolkit.stopAWTRunLoop(_mediator);
+                }
+            }
+        }
+    }
+
+    // Call through to native methods
+    public static void doAWTRunLoop(long mediator, boolean awtMode) { doAWTRunLoop(mediator, awtMode, true); }
+    public static void doAWTRunLoop(long mediator) { doAWTRunLoop(mediator, true); }
+
+    private static Boolean sunAwtDisableCALayers = null;
+
+    /**
+     * Returns the value of "sun.awt.disableCALayers" property. Default
+     * value is {@code false}.
+     */
+    public synchronized static boolean getSunAwtDisableCALayers() {
+        if (sunAwtDisableCALayers == null) {
+            sunAwtDisableCALayers =
+            getBooleanSystemProperty("sun.awt.disableCALayers");
+        }
+        return sunAwtDisableCALayers.booleanValue();
+    }
+
+    /************************
+     * Native methods section
+     ************************/
+
+    // These are public because they are accessed from WebKitPluginObject in JavaDeploy
+    // Basic usage:
+    // createAWTRunLoopMediator. Start client code on another thread. doAWTRunLoop. When client code is finished, stopAWTRunLoop.
+    public static native long createAWTRunLoopMediator();
+    public static native void doAWTRunLoop(long mediator, boolean awtMode, boolean detectDeadlocks);
+    public static native void stopAWTRunLoop(long mediator);
+
+    private native boolean nativeSyncQueue(long timeout);
+
+    @Override
+    public Clipboard createPlatformClipboard() {
+        return new CClipboard("System");
+    }
+
+    @Override
+    public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
+        return (exclusionType == null) ||
+            (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) ||
+            (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) ||
+            (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
+    }
+
+    @Override
+    public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
+        //TODO: FileDialog blocks excluded windows...
+        //TODO: Test: 2 file dialogs, separate AppContexts: a) Dialog 1 blocked, shouldn't be. Frame 4 blocked (shouldn't be).
+        return (modalityType == null) ||
+            (modalityType == Dialog.ModalityType.MODELESS) ||
+            (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
+            (modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
+            (modalityType == Dialog.ModalityType.TOOLKIT_MODAL);
+    }
+
+    @Override
+    public boolean isWindowTranslucencySupported() {
+        return true;
+    }
+
+    @Override
+    public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
+        return true;
+    }
+
+    @Override
+    public boolean enableInputMethodsForTextComponent() {
+        return true;
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/NSPrintInfo.java b/jdk/src/macosx/classes/sun/lwawt/macosx/NSPrintInfo.java
new file mode 100644
index 0000000..4e278a8
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/NSPrintInfo.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx;
+
+
+import java.io.*;
+import javax.print.attribute.*;
+
+public final class NSPrintInfo implements PrintJobAttribute, PrintRequestAttribute, Serializable, Cloneable {
+
+    private long fNSPrintInfo;
+
+    public NSPrintInfo(long nsPrintInfo) {
+        fNSPrintInfo = nsPrintInfo;
+    }
+
+    public long getValue() {
+        return fNSPrintInfo;
+    }
+
+    public boolean equals(Object object) {
+        return (object != null && object instanceof NSPrintInfo && fNSPrintInfo == ((NSPrintInfo)object).fNSPrintInfo);
+    }
+
+    public int hashCode() {
+        return (int)fNSPrintInfo;
+    }
+
+    public String toString() {
+        return "" + fNSPrintInfo;
+    }
+
+    public final Class<? extends Attribute> getCategory() {
+        return NSPrintInfo.class;
+    }
+
+    public final String getName() {
+        return "nsPrintInfo";
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/event/NSEvent.java b/jdk/src/macosx/classes/sun/lwawt/macosx/event/NSEvent.java
new file mode 100644
index 0000000..d4b43ba
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/event/NSEvent.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt.macosx.event;
+
+import sun.lwawt.macosx.CocoaConstants;
+
+import java.awt.event.*;
+
+/*
+ * A class representing Cocoa NSEvent class with
+ * the fields only necessary for JDK functionality.
+ */
+
+public final class NSEvent {
+    private int type;
+
+    /*
+     * Java-level modifiers
+     */
+    private int modifiers;
+    private int clickCount;
+    private int button;
+    private int x;
+    private int y;
+    private double scrollDeltaY;
+    private double scrollDeltaX;
+    private int absX;
+    private int absY;
+
+    public NSEvent(int type, int modifiers, int clickCount, int button,
+            int x, int y,
+            int absX, int absY,
+            double scrollDeltaY, double scrollDeltaX) {
+        this.type = type;
+        this.modifiers = modifiers;
+        this.clickCount = clickCount;
+        this.button = button;
+        this.x = x;
+        this.y = y;
+        this.absX = absX;
+        this.absY = absY;
+        this.scrollDeltaY = scrollDeltaY;
+        this.scrollDeltaX = scrollDeltaX;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public int getModifiers() {
+        return modifiers;
+    }
+
+    public int getClickCount() {
+        return clickCount;
+    }
+
+    public int getButton() {
+        return button;
+    }
+
+    public int getX() {
+        return x;
+    }
+
+    public int getY() {
+        return y;
+    }
+
+    public double getScrollDeltaY() {
+        return scrollDeltaY;
+    }
+
+    public double getScrollDeltaX() {
+        return scrollDeltaX;
+    }
+
+    public int getAbsX() {
+        return absX;
+    }
+
+    public int getAbsY() {
+        return absY;
+    }
+
+    @Override
+    public String toString() {
+        return "NSEvent[" + getType() + " ," + getModifiers() + " ,"
+                + getClickCount() + " ," + getButton() + " ," + getX() + " ,"
+                + getY() + " ," + absX + " ," + absY+ "]";
+    }
+
+    /*
+     * Converts an NSEvent button number to a MouseEvent constant.
+     */
+    public static int nsButtonToJavaButton(NSEvent event) {
+        int nsButtonNumber = event.getButton();
+        int jbutton = MouseEvent.NOBUTTON;
+
+        if (event.getType() != CocoaConstants.NSMouseMoved) {
+            if (nsButtonNumber == 0) { // left
+                jbutton = MouseEvent.BUTTON1;
+            } else if (nsButtonNumber == 1) { // right
+                jbutton = MouseEvent.BUTTON3;
+            } else if (nsButtonNumber == 2) { // middle
+                jbutton = MouseEvent.BUTTON2;
+            }
+        }
+
+        return jbutton;
+    }
+
+    // utility methods
+
+    public boolean isPopupTrigger() {
+        final int mods = getModifiers();
+        final boolean isRightButtonDown = ((mods & InputEvent.BUTTON3_DOWN_MASK) != 0);
+        final boolean isLeftButtonDown = ((mods & InputEvent.BUTTON1_DOWN_MASK) != 0);
+        final boolean isControlDown = ((mods & InputEvent.CTRL_DOWN_MASK) != 0);
+        return isRightButtonDown || (isControlDown && isLeftButtonDown);
+    }
+}
diff --git a/jdk/src/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java b/jdk/src/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java
new file mode 100644
index 0000000..12ffd1b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.nio.ch;
+
+import java.nio.channels.spi.SelectorProvider;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import sun.security.action.GetPropertyAction;
+
+/**
+ * Creates this platform's default SelectorProvider
+ */
+
+public class DefaultSelectorProvider {
+
+    /**
+     * Prevent instantiation.
+     */
+    private DefaultSelectorProvider() { }
+
+    /**
+     * Returns the default SelectorProvider.
+     */
+    public static SelectorProvider create() {
+        // Mac OS X supports selectors implemented with select() and kqueue().
+        // Prefer kqueue() unless otherwise requested.
+        boolean preferSelect = ((Boolean)java.security.AccessController.doPrivileged(new sun.security.action.GetBooleanAction("java.nio.preferSelect"))).booleanValue();
+        if (!preferSelect) {
+            return new sun.nio.ch.KQueueSelectorProvider();
+        } else {
+            return new sun.nio.ch.PollSelectorProvider();
+        }
+    }
+
+}
diff --git a/jdk/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java b/jdk/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java
new file mode 100644
index 0000000..388a42b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * KQueueArrayWrapper.java
+ * Implementation of Selector using FreeBSD / Mac OS X kqueues
+ * Derived from Sun's DevPollArrayWrapper
+ */
+
+package sun.nio.ch;
+
+import sun.misc.*;
+import java.io.IOException;
+import java.io.FileDescriptor;
+
+
+/*
+ * struct kevent {           // 32-bit    64-bit
+ *     uintptr_t ident;      //   4         8
+ *     short     filter;     //   2         2
+ *     u_short   flags;      //   2         2
+ *     u_int     fflags;     //   4         4
+ *     intptr_t  data;       //   4         8
+ *     void      *udata;     //   4         8
+ * }                  // Total:  20        32
+ *
+ * The implementation works in 32-bit and 64-bit world. We do this by calling a
+ * native function that actually sets the sizes and offsets of the fields based
+ * on which mode we're in.
+ */
+
+class KQueueArrayWrapper {
+    // Event masks
+    static final short POLLIN       = AbstractPollArrayWrapper.POLLIN;
+    static final short POLLOUT      = AbstractPollArrayWrapper.POLLOUT;
+
+    // kevent filters
+    static short EVFILT_READ;
+    static short EVFILT_WRITE;
+
+    // kevent struct
+    // These fields are now set by initStructSizes in the static initializer.
+    static short SIZEOF_KEVENT;
+    static short FD_OFFSET;
+    static short FILTER_OFFSET;
+
+    // kevent array size (just under 1K bytes)
+    static final int NUM_KEVENTS = 50;
+
+    // Are we in a 64-bit VM?
+    static boolean is64bit = false;
+
+    // The kevent array (used for outcoming events only)
+    private AllocatedNativeObject keventArray = null;
+    private long keventArrayAddress;
+
+    // The kqueue fd
+    private int kq = -1;
+
+    // The fd of the interrupt line going out
+    private int outgoingInterruptFD;
+
+    // The fd of the interrupt line coming in
+    private int incomingInterruptFD;
+
+    static {
+        initStructSizes();
+        String datamodel = (String) java.security.AccessController.doPrivileged(
+        new sun.security.action.GetPropertyAction("sun.arch.data.model"));
+        is64bit = datamodel.equals("64");
+    }
+
+    KQueueArrayWrapper() {
+        int allocationSize = SIZEOF_KEVENT * NUM_KEVENTS;
+        keventArray = new AllocatedNativeObject(allocationSize, true);
+        keventArrayAddress = keventArray.address();
+        kq = init();
+    }
+
+    void initInterrupt(int fd0, int fd1) {
+        outgoingInterruptFD = fd1;
+        incomingInterruptFD = fd0;
+        register0(kq, fd0, 1, 0);
+    }
+
+    int getReventOps(int index) {
+        int result = 0;
+        int offset = SIZEOF_KEVENT*index + FILTER_OFFSET;
+        short filter = keventArray.getShort(offset);
+
+        // This is all that's necessary based on inspection of usage:
+        //   SinkChannelImpl, SourceChannelImpl, DatagramChannelImpl,
+        //   ServerSocketChannelImpl, SocketChannelImpl
+        if (filter == EVFILT_READ) {
+            result |= POLLIN;
+        } else if (filter == EVFILT_WRITE) {
+            result |= POLLOUT;
+        }
+
+        return result;
+    }
+
+    int getDescriptor(int index) {
+        int offset = SIZEOF_KEVENT*index + FD_OFFSET;
+        /* The ident field is 8 bytes in 64-bit world, however the API wants us
+         * to return an int. Hence read the 8 bytes but return as an int.
+         */
+        if (is64bit) {
+          long fd = keventArray.getLong(offset);
+          assert fd <= Integer.MAX_VALUE;
+          return (int) fd;
+        } else {
+          return keventArray.getInt(offset);
+        }
+    }
+
+    void setInterest(int fd, int events) {
+        register0(kq, fd, events & POLLIN, events & POLLOUT);
+    }
+
+    void release(int fd) {
+        register0(kq, fd, 0, 0);
+    }
+
+    void close() throws IOException {
+        if (keventArray != null) {
+            keventArray.free();
+            keventArray = null;
+        }
+        if (kq >= 0) {
+            FileDispatcherImpl.closeIntFD(kq);
+            kq = -1;
+        }
+    }
+
+    int poll(long timeout) {
+        int updated = kevent0(kq, keventArrayAddress, NUM_KEVENTS, timeout);
+        return updated;
+    }
+
+    void interrupt() {
+        interrupt(outgoingInterruptFD);
+    }
+
+    private native int init();
+    private static native void initStructSizes();
+
+    private native void register0(int kq, int fd, int read, int write);
+    private native int kevent0(int kq, long keventAddress, int keventCount,
+                               long timeout);
+    private static native void interrupt(int fd);
+}
+
diff --git a/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java b/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java
new file mode 100644
index 0000000..ff12fff
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * KQueueSelectorImpl.java
+ * Implementation of Selector using FreeBSD / Mac OS X kqueues
+ * Derived from Sun's DevPollSelectorImpl
+ */
+
+package sun.nio.ch;
+
+import java.io.IOException;
+import java.io.FileDescriptor;
+import java.nio.channels.*;
+import java.nio.channels.spi.*;
+import java.util.*;
+import sun.misc.*;
+
+class KQueueSelectorImpl
+    extends SelectorImpl
+{
+    // File descriptors used for interrupt
+    protected int fd0;
+    protected int fd1;
+
+    // The kqueue manipulator
+    KQueueArrayWrapper kqueueWrapper;
+
+    // Count of registered descriptors (including interrupt)
+    private int totalChannels;
+
+    // Map from file descriptors to selection keys
+    private HashMap fdToKey;
+
+    // True if this Selector has been closed
+    private boolean closed = false;
+
+    // Lock for interrupt triggering and clearing
+    private Object interruptLock = new Object();
+    private boolean interruptTriggered = false;
+
+    /**
+     * Package private constructor called by factory method in
+     * the abstract superclass Selector.
+     */
+    KQueueSelectorImpl(SelectorProvider sp) {
+        super(sp);
+        long fds = IOUtil.makePipe(false);
+        fd0 = (int)(fds >>> 32);
+        fd1 = (int)fds;
+        kqueueWrapper = new KQueueArrayWrapper();
+        kqueueWrapper.initInterrupt(fd0, fd1);
+        fdToKey = new HashMap();
+        totalChannels = 1;
+    }
+
+
+    protected int doSelect(long timeout)
+        throws IOException
+    {
+        int entries = 0;
+        if (closed)
+            throw new ClosedSelectorException();
+        processDeregisterQueue();
+        if (timeout == 0  &&  totalChannels == 1)
+            return 0;
+        try {
+            begin();
+            entries = kqueueWrapper.poll(timeout);
+        } finally {
+            end();
+        }
+        processDeregisterQueue();
+        return updateSelectedKeys(entries);
+    }
+
+
+    /**
+     * Update the keys whose fd's have been selected by the devpoll
+     * driver. Add the ready keys to the ready queue.
+     * If the interrupt fd has been selected, drain it and clear the interrupt.
+     */
+    private int updateSelectedKeys(int entries)
+        throws IOException
+    {
+        int numKeysUpdated = 0;
+        boolean interrupted = false;
+
+        for (int i = 0; i < entries; i++) {
+            int nextFD = kqueueWrapper.getDescriptor(i);
+            if (nextFD == fd0) {
+                interrupted = true;
+            } else {
+                SelectionKeyImpl ski =
+                    (SelectionKeyImpl) fdToKey.get(new Integer(nextFD));
+                // ski is null in the case of an interrupt
+                if (ski != null) {
+                    int rOps = kqueueWrapper.getReventOps(i);
+                    if (selectedKeys.contains(ski)) {
+                        if (ski.channel.translateAndSetReadyOps(rOps, ski)) {
+                            numKeysUpdated++;
+                        }
+                    } else {
+                        ski.channel.translateAndSetReadyOps(rOps, ski);
+                        if ((ski.readyOps() & ski.interestOps()) != 0) {
+                            selectedKeys.add(ski);
+                            numKeysUpdated++;
+                        }
+                    }
+                }
+            }
+        }
+
+        if (interrupted) {
+            // Clear the wakeup pipe
+            synchronized (interruptLock) {
+                IOUtil.drain(fd0);
+                interruptTriggered = false;
+            }
+        }
+
+        return numKeysUpdated;
+    }
+
+
+    protected void implClose() throws IOException {
+        if (!closed) {
+            closed = true;
+            FileDispatcherImpl.closeIntFD(fd0);
+            FileDispatcherImpl.closeIntFD(fd1);
+            if (kqueueWrapper != null) {
+                kqueueWrapper.release(fd0);
+                kqueueWrapper.close();
+                kqueueWrapper = null;
+                selectedKeys = null;
+
+                // Deregister channels
+                Iterator i = keys.iterator();
+                while (i.hasNext()) {
+                    SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
+                    deregister(ski);
+                    SelectableChannel selch = ski.channel();
+                    if (!selch.isOpen() && !selch.isRegistered())
+                        ((SelChImpl)selch).kill();
+                    i.remove();
+                }
+                totalChannels = 0;
+            }
+            fd0 = -1;
+            fd1 = -1;
+        }
+    }
+
+
+    protected void implRegister(SelectionKeyImpl ski) {
+        int fd = IOUtil.fdVal(ski.channel.getFD());
+        fdToKey.put(new Integer(fd), ski);
+        totalChannels++;
+        keys.add(ski);
+    }
+
+
+    protected void implDereg(SelectionKeyImpl ski) throws IOException {
+        int fd = ski.channel.getFDVal();
+        fdToKey.remove(new Integer(fd));
+        kqueueWrapper.release(fd);
+        totalChannels--;
+        keys.remove(ski);
+        selectedKeys.remove(ski);
+        deregister((AbstractSelectionKey)ski);
+        SelectableChannel selch = ski.channel();
+        if (!selch.isOpen() && !selch.isRegistered())
+            ((SelChImpl)selch).kill();
+    }
+
+
+    void putEventOps(SelectionKeyImpl ski, int ops) {
+        int fd = IOUtil.fdVal(ski.channel.getFD());
+        kqueueWrapper.setInterest(fd, ops);
+    }
+
+
+    public Selector wakeup() {
+        synchronized (interruptLock) {
+            if (!interruptTriggered) {
+                kqueueWrapper.interrupt();
+                interruptTriggered = true;
+            }
+        }
+        return this;
+    }
+
+
+    static {
+        Util.load();
+    }
+}
+
diff --git a/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorProvider.java b/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorProvider.java
new file mode 100644
index 0000000..6e7b7cf
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorProvider.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * KQueueSelectorProvider.java
+ * Implementation of Selector using FreeBSD / Mac OS X kqueues
+ * Derived from Sun's DevPollSelectorProvider
+ */
+
+package sun.nio.ch;
+
+import java.io.IOException;
+import java.nio.channels.*;
+import java.nio.channels.spi.*;
+
+public class KQueueSelectorProvider
+extends SelectorProviderImpl
+{
+    public AbstractSelector openSelector() throws IOException {
+        return new KQueueSelectorImpl(this);
+    }
+}
diff --git a/jdk/src/macosx/native/apple/applescript/AS_NS_ConversionUtils.h b/jdk/src/macosx/native/apple/applescript/AS_NS_ConversionUtils.h
new file mode 100644
index 0000000..e9fbf51
--- /dev/null
+++ b/jdk/src/macosx/native/apple/applescript/AS_NS_ConversionUtils.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Foundation/Foundation.h>
+
+
+// A 'collection' (responds to -objectEnumerator) is translated to an AS list.
+// For any other object obj, this returns [[obj description] aeDescriptorValue], mainly
+// intended for debugging purposes.
+@interface NSObject (JavaAppleScriptEngineAdditions)
+- (NSAppleEventDescriptor *) aeDescriptorValue;
+@end
+
+@interface NSAppleEventDescriptor (JavaAppleScriptEngineAdditions)
+- (id) objCObjectValue;
+@end
diff --git a/jdk/src/macosx/native/apple/applescript/AS_NS_ConversionUtils.m b/jdk/src/macosx/native/apple/applescript/AS_NS_ConversionUtils.m
new file mode 100644
index 0000000..568891d
--- /dev/null
+++ b/jdk/src/macosx/native/apple/applescript/AS_NS_ConversionUtils.m
@@ -0,0 +1,793 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//
+//    Most of this is adapted from Ken Ferry's KFAppleScript Additions, contributed with permission
+//    http://homepage.mac.com/kenferry/software.html
+//
+
+#import "AS_NS_ConversionUtils.h"
+
+#import <Cocoa/Cocoa.h>
+#import <Carbon/Carbon.h>
+
+
+@interface NSAppleEventDescriptor (JavaAppleScriptEngineAdditionsPrivate)
+
+// just returns self.  This means that you can pass custom descriptors
+// to -[NSAppleScript executeHandler:error:withParameters:].
+- (NSAppleEventDescriptor *)aeDescriptorValue;
+
+// working with primitive descriptor types
++ (id)descriptorWithInt16:(SInt16)val;
+- (SInt16)int16Value;
++ (id)descriptorWithUnsignedInt32:(UInt32)val;
+- (UInt32)unsignedInt32Value;
++ (id)descriptorWithFloat32:(Float32)val;
+- (Float32)float32Value;
++ (id)descriptorWithFloat64:(Float64)val;
+- (Float64)float64Value;
++ (id)descriptorWithLongDateTime:(LongDateTime)val;
+- (LongDateTime)longDateTimeValue;
+
+
+// These are the methods for converting AS objects to objective-C objects.
+// -[NSAppleEventDescriptor objCObjectValue] is the general method for converting
+// AS objects to ObjC objects, and is called by -[NSAppleScript executeHandler:error:withParameters:].
+// It does no work itself.  It finds a handler based on the type of the descriptor and lets that
+// handler object do the work.  If there is no handler type registered for a the type of a descriptor,
+// the raw descriptor is returned.
+//
+// You can designate a handlers for descriptor types with
+// +[NSAppleEventDescriptor registerConversionHandler:selector:forDescriptorTypes:].  Please note
+// that this method does _not_ retain the handler object (for now anyway).  The selector should
+// take a single argument, a descriptor to translate, and should return an object.  An example such
+// selector is @selector(dictionaryWithAEDesc:), for which the handler object would be [NSDictionary class].
+//
+// A number of handlers are designated by default.  The methods and objects can be easily inferred (or check
+// the implementation), but the automatically handled types are
+//    typeUnicodeText,
+//    typeText,
+//    typeUTF8Text,
+//    typeCString,
+//    typeChar,
+//    typeBoolean,
+//    typeTrue,
+//    typeFalse,
+//    typeSInt16,
+//    typeSInt32,
+//    typeUInt32,
+//    typeSInt64,
+//    typeIEEE32BitFloatingPoint,
+//    typeIEEE64BitFloatingPoint,
+//    type128BitFloatingPoint,
+//    typeAEList,
+//    typeAERecord,
+//    typeLongDateTime,
+//    typeNull.
++ (void)registerConversionHandler:(id)anObject selector:(SEL)aSelector forDescriptorTypes:(DescType)firstType, ...;
++ (void) jaseSetUpHandlerDict;
+@end
+
+// wrap the NSAppleEventDescriptor string methods
+@interface NSString (JavaAppleScriptEngineAdditions)
+- (NSAppleEventDescriptor *)aeDescriptorValue;
++ (NSString *)stringWithAEDesc:(NSAppleEventDescriptor *)desc;
+@end
+
+// wrap the NSAppleEventDescriptor longDateTime methods
+@interface NSDate (JavaAppleScriptEngineAdditions)
+- (NSAppleEventDescriptor *)aeDescriptorValue;
++ (NSDate *)dateWithAEDesc:(NSAppleEventDescriptor *)desc;
+@end
+
+// these are fairly complicated methods, due to having to try to match up the various
+// AS number types (see NSAppleEventDescriptor for the primitive number methods)
+// with NSNumber variants.  For complete behavior it's best to look at the implementation.
+// Some notes:
+//    NSNumbers created with numberWithBool should be correctly translated to AS booleans and vice versa.
+//    NSNumbers created with large integer types may have to be translated to AS doubles,
+//      so be careful if checking equality (you may have to check equality within epsilon).
+//    Since NSNumbers can't remember if they were created with an unsigned value,
+//      [[NSNumber numberWithUnsignedChar:255] aeDescriptorValue] is going to get you an AS integer
+//      with value -1.  If you really need a descriptor with an unsigned value, you'll need to do it
+//      manually using the primitive methods on NSAppleEventDescriptor.  The resulting descriptor
+//      can still be passed to AS with -[NSAppleScript executeHandler:error:withParameters:].
+@interface NSNumber (JavaAppleScriptEngineAdditions)
+- (NSAppleEventDescriptor *)aeDescriptorValue;
++ (id)numberWithAEDesc:(NSAppleEventDescriptor *)desc;
+@end
+
+// Here we're following the behavior described in the CocoaScripting release note.
+//
+// NSPoint -> list of two numbers: {x, y}
+// NSRange -> list of two numbers: {begin offset, end offset}
+// NSRect  -> list of four numbers: {left, bottom, right, top}
+// NSSize  -> list of two numbers: {width, height}
+@interface NSValue (JavaAppleScriptEngineAdditions)
+- (NSAppleEventDescriptor *)aeDescriptorValue;
+@end
+
+// No need for ObjC -> AS conversion here, we fall through to NSObject as a collection.
+// For AS -> ObjC conversion, we build an array using the primitive list methods on
+// NSAppleEventDescriptor.
+@interface NSArray (JavaAppleScriptEngineAdditions)
++ (NSArray *)arrayWithAEDesc:(NSAppleEventDescriptor *)desc;
+@end
+
+
+// Please see the CocoaScripting release note for behavior.  It's kind of complicated.
+//
+// methods wrap the primitive record methods on NSAppleEventDescriptor.
+@interface NSDictionary (JavaAppleScriptEngineAdditions)
+- (NSAppleEventDescriptor *)aeDescriptorValue;
++ (NSDictionary *)dictionaryWithAEDesc:(NSAppleEventDescriptor *)desc;
+@end
+
+// be aware that a null descriptor does not correspond to the 'null' keyword in
+// AppleScript - it's more like nothing at all.  For example, the return
+// from an empty handler.
+@interface NSNull (JavaAppleScriptEngineAdditions)
+- (NSAppleEventDescriptor *)aeDescriptorValue;
++ (NSNull *)nullWithAEDesc:(NSAppleEventDescriptor *)desc;
+@end
+
+
+@interface NSNumber (JavaAppleScriptEngineAdditionsPrivate)
++ (id) jaseNumberWithSignedIntP:(void *)int_p byteCount:(int)bytes;
++ (id) jaseNumberWithUnsignedIntP:(void *)int_p byteCount:(int)bytes;
++ (id) jaseNumberWithFloatP:(void *)float_p byteCount:(int)bytes;
+@end
+
+
+@implementation NSObject (JavaAppleScriptEngineAdditions)
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    // collections go to lists
+    if (![self respondsToSelector:@selector(objectEnumerator)]) {
+        // encode the description as a fallback - this is pretty useless, only helpful for debugging
+        return [[self description] aeDescriptorValue];
+    }
+
+    NSAppleEventDescriptor *resultDesc = [NSAppleEventDescriptor listDescriptor];
+    NSEnumerator *objectEnumerator = [(id)self objectEnumerator];
+
+    unsigned int i = 1; // apple event descriptors are 1-indexed
+    id currentObject;
+    while((currentObject = [objectEnumerator nextObject]) != nil) {
+        [resultDesc insertDescriptor:[currentObject aeDescriptorValue] atIndex:i++];
+    }
+
+    return resultDesc;
+}
+
+@end
+
+
+@implementation NSArray (JavaAppleScriptEngineAdditions)
+
+// don't need to override aeDescriptorValue, the NSObject will treat the array as a collection
++ (NSArray *)arrayWithAEDesc:(NSAppleEventDescriptor *)desc {
+    NSAppleEventDescriptor *listDesc = [desc coerceToDescriptorType:typeAEList];
+    NSMutableArray *resultArray = [NSMutableArray array];
+
+    // apple event descriptors are 1-indexed
+    unsigned int listCount = [listDesc numberOfItems];
+    unsigned int i;
+    for (i = 1; i <= listCount; i++) {
+        [resultArray addObject:[[listDesc descriptorAtIndex:i] objCObjectValue]];
+    }
+
+    return resultArray;
+}
+
+@end
+
+
+@implementation NSDictionary (JavaAppleScriptEngineAdditions)
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    NSAppleEventDescriptor *resultDesc = [NSAppleEventDescriptor recordDescriptor];
+    NSMutableArray *userFields = [NSMutableArray array];
+    NSArray *keys = [self allKeys];
+
+    unsigned int keyCount = [keys count];
+    unsigned int i;
+    for (i = 0; i < keyCount; i++) {
+        id key = [keys objectAtIndex:i];
+
+        if ([key isKindOfClass:[NSNumber class]]) {
+            [resultDesc setDescriptor:[[self objectForKey:key] aeDescriptorValue] forKeyword:[(NSNumber *)key intValue]];
+        } else if ([key isKindOfClass:[NSString class]]) {
+            [userFields addObject:key];
+            [userFields addObject:[self objectForKey:key]];
+        }
+    }
+
+    if ([userFields count] > 0) {
+        [resultDesc setDescriptor:[userFields aeDescriptorValue] forKeyword:keyASUserRecordFields];
+    }
+
+    return resultDesc;
+}
+
++ (NSDictionary *)dictionaryWithAEDesc:(NSAppleEventDescriptor *)desc {
+    NSAppleEventDescriptor *recDescriptor = [desc coerceToDescriptorType:typeAERecord];
+    NSMutableDictionary *resultDict = [NSMutableDictionary dictionary];
+
+    // NSAppleEventDescriptor uses 1 indexing
+    unsigned int recordCount = [recDescriptor numberOfItems];
+    unsigned int recordIndex;
+    for (recordIndex = 1; recordIndex <= recordCount; recordIndex++) {
+        AEKeyword keyword = [recDescriptor keywordForDescriptorAtIndex:recordIndex];
+
+        if(keyword == keyASUserRecordFields) {
+            NSAppleEventDescriptor *listDescriptor = [recDescriptor descriptorAtIndex:recordIndex];
+
+            // NSAppleEventDescriptor uses 1 indexing
+            unsigned int listCount = [listDescriptor numberOfItems];
+            unsigned int listIndex;
+            for (listIndex = 1; listIndex <= listCount; listIndex += 2) {
+                id keyObj = [[listDescriptor descriptorAtIndex:listIndex] objCObjectValue];
+                id valObj = [[listDescriptor descriptorAtIndex:listIndex+1] objCObjectValue];
+
+                [resultDict setObject:valObj forKey:keyObj];
+            }
+        } else {
+            id keyObj = [NSNumber numberWithInt:keyword];
+            id valObj = [[recDescriptor descriptorAtIndex:recordIndex] objCObjectValue];
+
+            [resultDict setObject:valObj forKey:keyObj];
+        }
+    }
+
+    return resultDict;
+}
+
+@end
+
+
+@implementation NSString (JavaAppleScriptEngineAdditions)
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    return [NSAppleEventDescriptor descriptorWithString:self];
+}
+
++ (NSString *)stringWithAEDesc:(NSAppleEventDescriptor *)desc {
+    return [desc stringValue];
+}
+
++ (NSString *)versionWithAEDesc:(NSAppleEventDescriptor *)desc {
+    const AEDesc *aeDesc = [desc aeDesc];
+    VersRec v;
+    AEGetDescData(aeDesc, &v, sizeof(v));
+    return [[[NSString alloc] initWithBytes:&v.shortVersion[1] length:StrLength(v.shortVersion) encoding:NSUTF8StringEncoding] autorelease];
+}
+
+@end
+
+
+@implementation NSNull (JavaAppleScriptEngineAdditions)
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    return [NSAppleEventDescriptor nullDescriptor];
+}
+
++ (NSNull *)nullWithAEDesc:(NSAppleEventDescriptor *)desc {
+    return [NSNull null];
+}
+
+@end
+
+
+@implementation NSDate (JavaAppleScriptEngineAdditions)
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    LongDateTime ldt;
+    UCConvertCFAbsoluteTimeToLongDateTime(CFDateGetAbsoluteTime((CFDateRef)self), &ldt);
+    return [NSAppleEventDescriptor descriptorWithLongDateTime:ldt];
+}
+
++ (NSDate *)dateWithAEDesc:(NSAppleEventDescriptor *)desc {
+    CFAbsoluteTime absTime;
+    UCConvertLongDateTimeToCFAbsoluteTime([desc longDateTimeValue], &absTime);
+    NSDate *resultDate = (NSDate *)CFDateCreate(NULL, absTime);
+    return [resultDate autorelease];
+}
+
+@end
+
+
+
+static inline int areEqualEncodings(const char *enc1, const char *enc2) {
+    return (strcmp(enc1, enc2) == 0);
+}
+
+@implementation NSNumber (JavaAppleScriptEngineAdditions)
+
+-(id)jaseDescriptorValueWithFloatP:(void *)float_p byteCount:(int)bytes {
+    float floatVal;
+    if (bytes < sizeof(Float32)) {
+        floatVal = [self floatValue];
+        float_p = &floatVal;
+        bytes = sizeof(floatVal);
+    }
+
+    double doubleVal;
+    if (bytes > sizeof(Float64)) {
+        doubleVal = [self doubleValue];
+        float_p = &doubleVal;
+        bytes = sizeof(doubleVal);
+    }
+
+    if (bytes == sizeof(Float32)) {
+        return [NSAppleEventDescriptor descriptorWithFloat32:*(Float32 *)float_p];
+    }
+
+    if (bytes == sizeof(Float64)) {
+        return [NSAppleEventDescriptor descriptorWithFloat64:*(Float64 *)float_p];
+    }
+
+    [NSException raise:NSInvalidArgumentException
+                format:@"Cannot create an NSAppleEventDescriptor for float with %d bytes of data.",  bytes];
+
+    return nil;
+}
+
+-(id)jaseDescriptorValueWithSignedIntP:(void *)int_p byteCount:(int)bytes {
+    int intVal;
+
+    if (bytes < sizeof(SInt16)) {
+        intVal = [self intValue];
+        int_p = &intVal;
+        bytes = sizeof(intVal);
+    }
+
+    if (bytes == sizeof(SInt16)) {
+        return [NSAppleEventDescriptor descriptorWithInt16:*(SInt16 *)int_p];
+    }
+
+    if (bytes == sizeof(SInt32)) {
+        return [NSAppleEventDescriptor descriptorWithInt32:*(SInt32 *)int_p];
+    }
+
+    double val = [self doubleValue];
+    return [self jaseDescriptorValueWithFloatP:&val byteCount:sizeof(val)];
+}
+
+-(id)jaseDescriptorValueWithUnsignedIntP:(void *)int_p byteCount:(int)bytes {
+    unsigned int uIntVal;
+
+    if (bytes < sizeof(UInt32)) {
+        uIntVal = [self unsignedIntValue];
+        int_p = &uIntVal;
+        bytes = sizeof(uIntVal);
+    }
+
+    if (bytes == sizeof(UInt32)) {
+        return [NSAppleEventDescriptor descriptorWithUnsignedInt32:*(UInt32 *)int_p];
+    }
+
+    double val = (double)[self unsignedLongLongValue];
+    return [self jaseDescriptorValueWithFloatP:&val byteCount:sizeof(val)];
+}
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    // NSNumber is unfortunately complicated, because the applescript
+    // type we should use depends on the c type that our NSNumber corresponds to
+
+    const char *type = [self objCType];
+
+    // convert
+    if (areEqualEncodings(type, @encode(BOOL))) {
+        return [NSAppleEventDescriptor descriptorWithBoolean:[self boolValue]];
+    }
+
+    if (areEqualEncodings(type, @encode(char))) {
+        char val = [self charValue];
+        return [self jaseDescriptorValueWithSignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(short))) {
+        short val = [self shortValue];
+        return [self jaseDescriptorValueWithSignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(int))) {
+        int val = [self intValue];
+        return [self jaseDescriptorValueWithSignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(long))) {
+        long val = [self longValue];
+        return [self jaseDescriptorValueWithSignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(long long))) {
+        long long val = [self longLongValue];
+        return [self jaseDescriptorValueWithSignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(unsigned char))) {
+        unsigned char val = [self unsignedCharValue];
+        return [self jaseDescriptorValueWithUnsignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(unsigned short))) {
+        unsigned short val = [self unsignedShortValue];
+        return [self jaseDescriptorValueWithUnsignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(unsigned int))) {
+        unsigned int val = [self unsignedIntValue];
+        return [self jaseDescriptorValueWithUnsignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(unsigned long))) {
+        unsigned long val = [self unsignedLongValue];
+        return [self jaseDescriptorValueWithUnsignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(unsigned long long))) {
+        unsigned long long val = [self unsignedLongLongValue];
+        return [self jaseDescriptorValueWithUnsignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(float))) {
+        float val = [self floatValue];
+        return [self jaseDescriptorValueWithFloatP:&val byteCount:sizeof(val)];
+    }
+
+    if (areEqualEncodings(type, @encode(double))) {
+        double val = [self doubleValue];
+        return [self jaseDescriptorValueWithFloatP:&val byteCount:sizeof(val)];
+    }
+
+    [NSException raise:@"jaseUnsupportedAEDescriptorConversion"
+                format:@"JavaAppleScriptEngineAdditions: conversion of an NSNumber with objCType '%s' to an aeDescriptor is not supported.", type];
+
+    return nil;
+}
+
++ (id)numberWithAEDesc:(NSAppleEventDescriptor *)desc {
+    DescType type = [desc descriptorType];
+
+    if ((type == typeTrue) || (type == typeFalse) || (type == typeBoolean)) {
+        return [NSNumber numberWithBool:[desc booleanValue]];
+    }
+
+    if (type == typeSInt16) {
+        SInt16 val = [desc int16Value];
+        return [NSNumber jaseNumberWithSignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (type == typeSInt32) {
+        SInt32 val = [desc int32Value];
+        return [NSNumber jaseNumberWithSignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (type == typeUInt32) {
+        UInt32 val = [desc unsignedInt32Value];
+        return [NSNumber jaseNumberWithUnsignedIntP:&val byteCount:sizeof(val)];
+    }
+
+    if (type == typeIEEE32BitFloatingPoint) {
+        Float32 val = [desc float32Value];
+        return [NSNumber jaseNumberWithFloatP:&val byteCount:sizeof(val)];
+    }
+
+    if (type == typeIEEE64BitFloatingPoint) {
+        Float64 val = [desc float64Value];
+        return [NSNumber jaseNumberWithFloatP:&val byteCount:sizeof(val)];
+    }
+
+    // try to coerce to 64bit floating point
+    desc = [desc coerceToDescriptorType:typeIEEE64BitFloatingPoint];
+    if (desc != nil) {
+        Float64 val = [desc float64Value];
+        return [NSNumber jaseNumberWithFloatP:&val byteCount:sizeof(val)];
+    }
+
+    [NSException raise:@"jaseUnsupportedAEDescriptorConversion"
+                format:@"JavaAppleScriptEngineAdditions: conversion of an NSAppleEventDescriptor with objCType '%s' to an aeDescriptor is not supported.", type];
+
+    return nil;
+}
+
++ (id) jaseNumberWithSignedIntP:(void *)int_p byteCount:(int)bytes {
+    if (bytes == sizeof(char)) {
+        return [NSNumber numberWithChar:*(char *)int_p];
+    }
+
+    if (bytes == sizeof(short)) {
+        return [NSNumber numberWithShort:*(short *)int_p];
+    }
+
+    if (bytes == sizeof(int)) {
+        return [NSNumber numberWithInt:*(int *)int_p];
+    }
+
+    if (bytes == sizeof(long)) {
+        return [NSNumber numberWithLong:*(long *)int_p];
+    }
+
+    if (bytes == sizeof(long long)) {
+        return [NSNumber numberWithLongLong:*(long long *)int_p];
+    }
+
+    [NSException raise:NSInvalidArgumentException
+                format:@"NSNumber jaseNumberWithSignedIntP:byteCount: number with %i bytes not supported.", bytes];
+
+    return nil;
+}
+
++ (id) jaseNumberWithUnsignedIntP:(void *)int_p byteCount:(int)bytes {
+    if (bytes == sizeof(unsigned char)) {
+        return [NSNumber numberWithUnsignedChar:*(unsigned char *)int_p];
+    }
+
+    if (bytes == sizeof(unsigned short)) {
+        return [NSNumber numberWithUnsignedShort:*(unsigned short *)int_p];
+    }
+
+    if (bytes == sizeof(unsigned int)) {
+        return [NSNumber numberWithUnsignedInt:*(unsigned int *)int_p];
+    }
+
+    if (bytes == sizeof(unsigned long)) {
+        return [NSNumber numberWithUnsignedLong:*(unsigned long *)int_p];
+    }
+
+    if (bytes == sizeof(unsigned long long)) {
+        return [NSNumber numberWithUnsignedLongLong:*(unsigned long long *)int_p];
+    }
+
+    [NSException raise:NSInvalidArgumentException
+                format:@"NSNumber numberWithUnsignedInt:byteCount: number with %i bytes not supported.", bytes];
+
+    return nil;
+}
+
++ (id) jaseNumberWithFloatP:(void *)float_p byteCount:(int)bytes {
+    if (bytes == sizeof(float)) {
+        return [NSNumber numberWithFloat:*(float *)float_p];
+    }
+
+    if (bytes == sizeof(double)) {
+        return [NSNumber numberWithFloat:*(double *)float_p];
+    }
+
+    [NSException raise:NSInvalidArgumentException
+                format:@"NSNumber numberWithFloat:byteCount: floating point number with %i bytes not supported.", bytes];
+
+    return nil;
+}
+
+@end
+
+@implementation NSValue (JavaAppleScriptEngineAdditions)
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    const char *type = [self objCType];
+
+    if (areEqualEncodings(type, @encode(NSSize))) {
+        NSSize size = [self sizeValue];
+        return [[NSArray arrayWithObjects:
+                 [NSNumber numberWithFloat:size.width],
+                 [NSNumber numberWithFloat:size.height], nil] aeDescriptorValue];
+    }
+
+    if (areEqualEncodings(type, @encode(NSPoint))) {
+        NSPoint point = [self pointValue];
+        return [[NSArray arrayWithObjects:
+                 [NSNumber numberWithFloat:point.x],
+                 [NSNumber numberWithFloat:point.y], nil] aeDescriptorValue];
+    }
+
+    if (areEqualEncodings(type, @encode(NSRange))) {
+        NSRange range = [self rangeValue];
+        return [[NSArray arrayWithObjects:
+                 [NSNumber numberWithUnsignedInt:range.location],
+                 [NSNumber numberWithUnsignedInt:range.location + range.length], nil] aeDescriptorValue];
+    }
+
+    if (areEqualEncodings(type, @encode(NSRect))) {
+        NSRect rect = [self rectValue];
+        return [[NSArray arrayWithObjects:
+                 [NSNumber numberWithFloat:rect.origin.x],
+                 [NSNumber numberWithFloat:rect.origin.y],
+                 [NSNumber numberWithFloat:rect.origin.x + rect.size.width],
+                 [NSNumber numberWithFloat:rect.origin.y + rect.size.height], nil] aeDescriptorValue];
+    }
+
+    [NSException raise:@"jaseUnsupportedAEDescriptorConversion"
+                format:@"JavaAppleScriptEngineAdditions: conversion of an NSNumber with objCType '%s' to an aeDescriptor is not supported.", type];
+
+    return nil;
+}
+
+@end
+
+
+@implementation NSImage (JavaAppleScriptEngineAdditions)
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    NSData *data = [self TIFFRepresentation];
+    return [NSAppleEventDescriptor descriptorWithDescriptorType:typeTIFF data:data];
+}
+
++ (NSImage *)imageWithAEDesc:(NSAppleEventDescriptor *)desc {
+    const AEDesc *d = [desc aeDesc];
+    NSMutableData *data = [NSMutableData dataWithLength:AEGetDescDataSize(d)];
+    AEGetDescData(d, [data mutableBytes], [data length]);
+    return [[[NSImage alloc] initWithData:data] autorelease];
+}
+
+@end
+
+
+
+@implementation NSAppleEventDescriptor (JavaAppleScriptEngineAdditions)
+
+// we're going to leak this.  It doesn't matter much for running apps, but
+// for developers it might be nice to try to dispose of it (so it would not clutter the
+// output when testing for leaks)
+static NSMutableDictionary *handlerDict = nil;
+
+- (id)objCObjectValue {
+    if (handlerDict == nil) [NSAppleEventDescriptor jaseSetUpHandlerDict];
+
+    id returnObj;
+    DescType type = [self descriptorType];
+    NSInvocation *handlerInvocation = [handlerDict objectForKey:[NSValue valueWithBytes:&type objCType:@encode(DescType)]];
+    if (handlerInvocation == nil) {
+        if (type == typeType) {
+            DescType subType;
+            AEGetDescData([self aeDesc], &subType, sizeof(subType));
+            if (subType == typeNull) return [NSNull null];
+        }
+        // return raw apple event descriptor if no handler is registered
+        returnObj = self;
+    } else {
+        [handlerInvocation setArgument:&self atIndex:2];
+        [handlerInvocation invoke];
+        [handlerInvocation getReturnValue:&returnObj];
+    }
+
+    return returnObj;
+}
+
+// FIXME - error checking, non nil handler
++ (void)registerConversionHandler:(id)anObject selector:(SEL)aSelector forDescriptorTypes:(DescType)firstType, ... {
+    if (handlerDict == nil) [NSAppleEventDescriptor jaseSetUpHandlerDict];
+
+    NSInvocation *handlerInvocation = [NSInvocation invocationWithMethodSignature:[anObject methodSignatureForSelector:aSelector]];
+    [handlerInvocation setTarget:anObject];
+    [handlerInvocation setSelector:aSelector];
+
+    DescType aType = firstType;
+    va_list typesList;
+    va_start(typesList, firstType);
+    do {
+        NSValue *type = [NSValue valueWithBytes:&aType objCType:@encode(DescType)];
+        [handlerDict setObject:handlerInvocation forKey:type];
+    } while((aType = va_arg(typesList, DescType)) != 0);
+    va_end(typesList);
+}
+
+
+- (NSAppleEventDescriptor *)aeDescriptorValue {
+    return self;
+}
+
++ (id)descriptorWithInt16:(SInt16)val {
+    return [NSAppleEventDescriptor descriptorWithDescriptorType:typeSInt16 bytes:&val length:sizeof(val)];
+}
+
+- (SInt16)int16Value {
+    SInt16 retValue;
+    [[[self coerceToDescriptorType:typeSInt16] data] getBytes:&retValue];
+    return retValue;
+}
+
++ (id)descriptorWithUnsignedInt32:(UInt32)val {
+    return [NSAppleEventDescriptor descriptorWithDescriptorType:typeUInt32 bytes:&val length:sizeof(val)];
+}
+
+- (UInt32)unsignedInt32Value {
+    UInt32 retValue;
+    [[[self coerceToDescriptorType:typeUInt32] data] getBytes:&retValue];
+    return retValue;
+}
+
+
++ (id)descriptorWithFloat32:(Float32)val {
+    return [NSAppleEventDescriptor descriptorWithDescriptorType:typeIEEE32BitFloatingPoint bytes:&val length:sizeof(val)];
+}
+
+- (Float32)float32Value {
+    Float32 retValue;
+    [[[self coerceToDescriptorType:typeIEEE32BitFloatingPoint] data] getBytes:&retValue];
+    return retValue;
+}
+
+
++ (id)descriptorWithFloat64:(Float64)val {
+    return [NSAppleEventDescriptor descriptorWithDescriptorType:typeIEEE64BitFloatingPoint bytes:&val length:sizeof(val)];
+}
+
+- (Float64)float64Value {
+    Float64 retValue;
+    [[[self coerceToDescriptorType:typeIEEE64BitFloatingPoint] data] getBytes:&retValue];
+    return retValue;
+}
+
++ (id)descriptorWithLongDateTime:(LongDateTime)val {
+    return [NSAppleEventDescriptor descriptorWithDescriptorType:typeLongDateTime bytes:&val length:sizeof(val)];
+}
+
+- (LongDateTime)longDateTimeValue {
+    LongDateTime retValue;
+    [[[self coerceToDescriptorType:typeLongDateTime] data] getBytes:&retValue];
+    return retValue;
+}
+
++ (void)jaseSetUpHandlerDict {
+    handlerDict = [[NSMutableDictionary alloc] init];
+
+    // register default handlers
+    // types are culled from AEDataModel.h and AERegistry.h
+
+    // string -> NSStrings
+    [NSAppleEventDescriptor registerConversionHandler:[NSString class] selector:@selector(stringWithAEDesc:) forDescriptorTypes:
+     typeUnicodeText, typeText, typeUTF8Text, typeCString, typeChar, nil];
+
+    // number/bool -> NSNumber
+    [NSAppleEventDescriptor registerConversionHandler:[NSNumber class] selector:@selector(numberWithAEDesc:) forDescriptorTypes:
+     typeBoolean, typeTrue, typeFalse,
+     typeSInt16, typeSInt32, typeUInt32, typeSInt64,
+     typeIEEE32BitFloatingPoint, typeIEEE64BitFloatingPoint, type128BitFloatingPoint, nil];
+
+    // list -> NSArray
+    [NSAppleEventDescriptor registerConversionHandler:[NSArray class] selector:@selector(arrayWithAEDesc:) forDescriptorTypes:typeAEList, nil];
+
+    // record -> NSDictionary
+    [NSAppleEventDescriptor registerConversionHandler:[NSDictionary class] selector:@selector(dictionaryWithAEDesc:) forDescriptorTypes:typeAERecord, nil];
+
+    // date -> NSDate
+    [NSAppleEventDescriptor registerConversionHandler:[NSDate class] selector:@selector(dateWithAEDesc:) forDescriptorTypes:typeLongDateTime, nil];
+
+    // images -> NSImage
+    [NSAppleEventDescriptor registerConversionHandler:[NSImage class] selector:@selector(imageWithAEDesc:) forDescriptorTypes:
+     typeTIFF, typeJPEG, typeGIF, typePict, typeIconFamily, typeIconAndMask, nil];
+
+    // vers -> NSString
+    [NSAppleEventDescriptor registerConversionHandler:[NSString class] selector:@selector(versionWithAEDesc:) forDescriptorTypes:typeVersion, nil];
+
+    // null -> NSNull
+    [NSAppleEventDescriptor registerConversionHandler:[NSNull class] selector:@selector(nullWithAEDesc:) forDescriptorTypes:typeNull, nil];
+}
+
+@end
diff --git a/jdk/src/macosx/native/apple/applescript/AppleScriptEngine.m b/jdk/src/macosx/native/apple/applescript/AppleScriptEngine.m
new file mode 100644
index 0000000..5c1ab06
--- /dev/null
+++ b/jdk/src/macosx/native/apple/applescript/AppleScriptEngine.m
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "apple_applescript_AppleScriptEngine.h"
+#import "apple_applescript_AppleScriptEngineFactory.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "NS_Java_ConversionUtils.h"
+#import "AppleScriptExecutionContext.h"
+
+//#define DEBUG 1
+
+
+/*
+ * Class:     apple_applescript_AppleScriptEngineFactory
+ * Method:    initNative
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_apple_applescript_AppleScriptEngineFactory_initNative
+(JNIEnv *env, jclass clazz)
+{
+    return;
+}
+
+
+/*
+ * Class:     apple_applescript_AppleScriptEngine
+ * Method:    initNative
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_apple_applescript_AppleScriptEngine_initNative
+(JNIEnv *env, jclass clazz)
+{
+    return;
+}
+
+
+/*
+ * Class:     apple_applescript_AppleScriptEngine
+ * Method:    createContextFrom
+ * Signature: (Ljava/lang/Object;)J
+ */
+JNIEXPORT jlong JNICALL Java_apple_applescript_AppleScriptEngine_createContextFrom
+(JNIEnv *env, jclass clazz, jobject javaContext)
+{
+    NSObject *obj = nil;
+
+JNF_COCOA_ENTER(env);
+
+    obj = [[JavaAppleScriptEngineCoercion coercer] coerceJavaObject:javaContext withEnv:env];
+
+#ifdef DEBUG
+    NSLog(@"converted context: %@", obj);
+#endif
+
+    CFRetain(obj);
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(obj);
+}
+
+
+/*
+ * Class:     apple_applescript_AppleScriptEngine
+ * Method:    createObjectFrom
+ * Signature: (J)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_apple_applescript_AppleScriptEngine_createObjectFrom
+(JNIEnv *env, jclass clazz, jlong nativeContext)
+{
+    jobject obj = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    obj = [[JavaAppleScriptEngineCoercion coercer] coerceNSObject:(id)jlong_to_ptr(nativeContext) withEnv:env];
+
+JNF_COCOA_EXIT(env);
+
+    return obj;
+}
+
+
+/*
+ * Class:     apple_applescript_AppleScriptEngine
+ * Method:    disposeContext
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_apple_applescript_AppleScriptEngine_disposeContext
+(JNIEnv *env, jclass clazz, jlong nativeContext)
+{
+
+JNF_COCOA_ENTER(env);
+
+    id obj = (id)jlong_to_ptr(nativeContext);
+    if (obj != nil) CFRelease(obj);
+
+JNF_COCOA_EXIT(env);
+
+}
+
+
+/*
+ * Class:     apple_applescript_AppleScriptEngine
+ * Method:    evalScript
+ * Signature: (Ljava/lang/String;J)J
+ */
+JNIEXPORT jlong JNICALL Java_apple_applescript_AppleScriptEngine_evalScript
+(JNIEnv *env, jclass clazz, jstring ascript, jlong contextptr)
+{
+    id retval = nil;
+
+JNF_COCOA_ENTER(env);
+
+    NSDictionary *ncontext = jlong_to_ptr(contextptr);
+    NSString *source = JNFJavaToNSString(env, ascript);
+
+#ifdef DEBUG
+    NSLog(@"evalScript(source:\"%@\" context: %@)", source, ncontext);
+#endif
+
+    AppleScriptExecutionContext *scriptInvocationCtx = [[[AppleScriptExecutionContext alloc] initWithSource:source context:ncontext] autorelease];
+    retval = [scriptInvocationCtx invokeWithEnv:env];
+
+#ifdef DEBUG
+    NSLog(@"returning: %@", retval);
+#endif
+
+    if (retval) CFRetain(retval);
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(retval);
+}
+
+
+/*
+ * Class:     apple_applescript_AppleScriptEngine
+ * Method:    evalScriptFromURL
+ * Signature: (Ljava/lang/String;J)J
+ */
+JNIEXPORT jlong JNICALL Java_apple_applescript_AppleScriptEngine_evalScriptFromURL
+(JNIEnv *env, jclass clazz, jstring afilename, jlong contextptr)
+{
+    id retval = nil;
+
+JNF_COCOA_ENTER(env);
+
+    NSDictionary *ncontext = jlong_to_ptr(contextptr);
+    NSString *filename = JNFJavaToNSString(env, afilename);
+
+#ifdef DEBUG
+    NSLog(@"evalScript(filename:\"%@\" context: %@)", filename, ncontext);
+#endif
+
+    AppleScriptExecutionContext *scriptInvocationCtx = [[[AppleScriptExecutionContext alloc] initWithFile:filename context:ncontext] autorelease];
+    retval = [scriptInvocationCtx invokeWithEnv:env];
+
+#ifdef DEBUG
+    NSLog(@"returning: %@", retval);
+#endif
+
+    if (retval) CFRetain(retval);
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(retval);
+}
diff --git a/jdk/src/macosx/native/apple/applescript/AppleScriptExecutionContext.h b/jdk/src/macosx/native/apple/applescript/AppleScriptExecutionContext.h
new file mode 100644
index 0000000..8c2bba6
--- /dev/null
+++ b/jdk/src/macosx/native/apple/applescript/AppleScriptExecutionContext.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+@interface AppleScriptExecutionContext : NSObject {
+    NSString *source;
+    BOOL isFile;
+    NSDictionary *context;
+    NSDictionary *error;
+    id returnValue;
+}
+
+@property (nonatomic, retain) NSString *source;
+@property (nonatomic, retain) NSDictionary *context;
+@property (nonatomic, retain) NSDictionary *error;
+@property (nonatomic, retain) id returnValue;
+
+- (id) initWithSource:(NSString *)source context:(NSDictionary *)context;
+- (id) initWithFile:(NSString *)filename context:(NSDictionary *)context;
+- (id) invokeWithEnv:(JNIEnv *)env;
+
+@end
diff --git a/jdk/src/macosx/native/apple/applescript/AppleScriptExecutionContext.m b/jdk/src/macosx/native/apple/applescript/AppleScriptExecutionContext.m
new file mode 100644
index 0000000..f26edc2
--- /dev/null
+++ b/jdk/src/macosx/native/apple/applescript/AppleScriptExecutionContext.m
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "AppleScriptExecutionContext.h"
+
+#import <Carbon/Carbon.h>
+
+#import "AS_NS_ConversionUtils.h"
+
+
+@implementation AppleScriptExecutionContext
+
+@synthesize source;
+@synthesize context;
+@synthesize error;
+@synthesize returnValue;
+
+- (id) init:(NSString *)sourceIn context:(id)contextIn {
+    self = [super init];
+    if (!self) return self;
+
+    self.source = sourceIn;
+    self.context = contextIn;
+    self.returnValue = nil;
+    self.error = nil;
+
+    return self;
+}
+
+- (id) initWithSource:(NSString *)sourceIn context:(NSDictionary *)contextIn {
+    self = [self init:sourceIn context:contextIn];
+    isFile = NO;
+    return self;
+}
+
+- (id) initWithFile:(NSString *)filenameIn context:(NSDictionary *)contextIn {
+    self = [self init:filenameIn context:contextIn];
+    isFile = YES;
+    return self;
+}
+
+- (void) dealloc {
+    self.source = nil;
+    self.context = nil;
+    self.returnValue = nil;
+    self.error = nil;
+
+    [super dealloc];
+}
+
+- (NSAppleScript *) scriptFromURL {
+    NSURL *url = [NSURL URLWithString:source];
+    NSDictionary *err = nil;
+    NSAppleScript *script = [[[NSAppleScript alloc] initWithContentsOfURL:url error:(&err)] autorelease];
+    if (err != nil) self.error = err;
+    return script;
+}
+
+- (NSAppleScript *) scriptFromSource {
+    return [[[NSAppleScript alloc] initWithSource:source] autorelease];
+}
+
+- (NSAppleEventDescriptor *) functionInvocationEvent {
+    NSString *function = [[context objectForKey:@"javax_script_function"] description];
+    if (function == nil) return nil;
+
+    // wrap the arg in an array if it is not already a list
+    id args = [context objectForKey:@"javax_script_argv"];
+    if (![args isKindOfClass:[NSArray class]]) {
+        args = [NSArray arrayWithObjects:args, nil];
+    }
+
+    // triangulate our target
+    int pid = [[NSProcessInfo processInfo] processIdentifier];
+    NSAppleEventDescriptor* targetAddress = [NSAppleEventDescriptor descriptorWithDescriptorType:typeKernelProcessID
+                                                                                           bytes:&pid
+                                                                                          length:sizeof(pid)];
+
+    // create the event to call a subroutine in the script
+    NSAppleEventDescriptor* event = [[NSAppleEventDescriptor alloc] initWithEventClass:kASAppleScriptSuite
+                                                                               eventID:kASSubroutineEvent
+                                                                      targetDescriptor:targetAddress
+                                                                              returnID:kAutoGenerateReturnID
+                                                                         transactionID:kAnyTransactionID];
+
+    // set up the handler
+    NSAppleEventDescriptor* subroutineDescriptor = [NSAppleEventDescriptor descriptorWithString:[function lowercaseString]];
+    [event setParamDescriptor:subroutineDescriptor forKeyword:keyASSubroutineName];
+
+    // set up the arguments
+    [event setParamDescriptor:[args aeDescriptorValue] forKeyword:keyDirectObject];
+
+    return [event autorelease];
+}
+
+- (void) invoke {
+    // create our script
+    NSAppleScript *script = isFile ? [self scriptFromURL] : [self scriptFromSource];
+    if (self.error != nil) return;
+
+    // find out if we have a subroutine to call
+    NSAppleEventDescriptor *fxnInvkEvt = [self functionInvocationEvent];
+
+    // exec!
+    NSAppleEventDescriptor *desc = nil;
+    NSDictionary *err = nil;
+    if (fxnInvkEvt == nil) {
+        desc = [script executeAndReturnError:(&err)];
+    } else {
+        desc = [script executeAppleEvent:fxnInvkEvt error:(&err)];
+    }
+
+    // if we encountered an exception, stash and bail
+    if (err != nil) {
+        self.error = err;
+        return;
+    }
+
+    // convert to NSObjects, and return in ivar
+    self.returnValue = [desc objCObjectValue];
+}
+
+- (id) invokeWithEnv:(JNIEnv *)env {
+    BOOL useAnyThread = [@"any-thread" isEqual:[context valueForKey:@"javax_script_threading"]];
+
+    // check if we are already on the AppKit thread, if desired
+    if(pthread_main_np() || useAnyThread) {
+        [self invoke];
+    } else {
+        [JNFRunLoop performOnMainThread:@selector(invoke) on:self withObject:nil waitUntilDone:YES];
+    }
+
+    // if we have an exception parked in our ivar, snarf the message (if there is one), and toss a ScriptException
+    if (self.error != nil) {
+        NSString *asErrString = [self.error objectForKey:NSAppleScriptErrorMessage];
+        if (!asErrString) asErrString = @"AppleScriptEngine failed to execute script."; // usually when we fail to load a file
+        [JNFException raise:env as:"javax/script/ScriptException" reason:[asErrString UTF8String]];
+    }
+
+    return self.returnValue;
+}
+
+@end
diff --git a/jdk/src/macosx/native/apple/applescript/NS_Java_ConversionUtils.h b/jdk/src/macosx/native/apple/applescript/NS_Java_ConversionUtils.h
new file mode 100644
index 0000000..d4dfb9f
--- /dev/null
+++ b/jdk/src/macosx/native/apple/applescript/NS_Java_ConversionUtils.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+@interface JavaAppleScriptEngineCoercion : NSObject
+
++ (JNFTypeCoercer *) coercer;
+
+@end
diff --git a/jdk/src/macosx/native/apple/applescript/NS_Java_ConversionUtils.m b/jdk/src/macosx/native/apple/applescript/NS_Java_ConversionUtils.m
new file mode 100644
index 0000000..771c6fc
--- /dev/null
+++ b/jdk/src/macosx/native/apple/applescript/NS_Java_ConversionUtils.m
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "NS_Java_ConversionUtils.h"
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface JavaAppleScriptBaseConverter : NSObject <JNFTypeCoercion>
+@end
+
+@interface JavaAppleScriptImageConverter : NSObject <JNFTypeCoercion>
+@end
+
+@interface JavaAppleScriptVersionConverter : NSObject <JNFTypeCoercion>
+@end
+
+@interface JavaAppleScriptNullConverter : NSObject <JNFTypeCoercion>
+@end
+
+
+@implementation JavaAppleScriptEngineCoercion
+
+static JNFTypeCoercer *appleScriptCoercer = nil;
+
++ (JNFTypeCoercer *) coercer {
+    if (appleScriptCoercer) return appleScriptCoercer;
+
+    id asSpecificCoercions = [[JNFDefaultCoercions defaultCoercer] deriveCoercer];
+    [asSpecificCoercions addCoercion:[[[JavaAppleScriptImageConverter alloc] init] autorelease] forNSClass:[NSImage class] javaClass:@"java/awt/Image"];
+    [asSpecificCoercions addCoercion:[[[JavaAppleScriptVersionConverter alloc] init] autorelease] forNSClass:[NSAppleEventDescriptor class] javaClass:nil];
+    [asSpecificCoercions addCoercion:[[[JavaAppleScriptNullConverter alloc] init] autorelease] forNSClass:[NSNull class] javaClass:nil];
+
+    return appleScriptCoercer = [asSpecificCoercions retain];
+}
+
+@end
+
+
+// [NSObject description] <-> java.lang.Object.toString()
+@implementation JavaAppleScriptBaseConverter
+
+// by default, bizzare NSObjects will have -description called on them, and passed back to Java like that
+- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    return JNFNSToJavaString(env, [obj description]);
+}
+
+// by default, bizzare Java objects will be toString()'d and passed to AppleScript like that
+- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    return JNFObjectToString(env, obj);
+}
+
+@end
+
+
+// NSImage <-> apple.awt.CImage
+@implementation JavaAppleScriptImageConverter
+
+static JNF_CLASS_CACHE(jc_CImage, "apple/awt/CImage");
+static JNF_STATIC_MEMBER_CACHE(jm_CImage_getCreator, jc_CImage, "getCreator", "()Lapple/awt/CImage$Creator;");
+static JNF_MEMBER_CACHE(jm_CImage_getNSImage, jc_CImage, "getNSImage", "()J");
+
+static JNF_CLASS_CACHE(jc_CImage_Generator, "apple/awt/CImage$Creator");
+static JNF_MEMBER_CACHE(jm_CImage_Generator_createImageFromPtr, jc_CImage_Generator, "createImage", "(J)Ljava/awt/image/BufferedImage;");
+static JNF_MEMBER_CACHE(jm_CImage_Generator_createImageFromImg, jc_CImage_Generator, "createImage", "(Ljava/awt/Image;)Lapple/awt/CImage;");
+
+- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    NSImage *img = (NSImage *)obj;
+    CFRetain(img);
+    jobject creator = JNFCallStaticObjectMethod(env, jm_CImage_getCreator);
+    jobject jobj = JNFCallObjectMethod(env, creator, jm_CImage_Generator_createImageFromPtr, ptr_to_jlong(img));
+    return jobj;
+}
+
+- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    jobject cimage = obj;
+    if (!JNFIsInstanceOf(env, obj, &jc_CImage)) {
+        jobject creator = JNFCallStaticObjectMethod(env, jm_CImage_getCreator);
+        cimage = JNFCallObjectMethod(env, creator, jm_CImage_Generator_createImageFromImg, obj);
+    }
+
+    jlong nsImagePtr = JNFCallLongMethod(env, cimage, jm_CImage_getNSImage);
+
+    NSImage *img = (NSImage *)jlong_to_ptr(nsImagePtr);
+    return [[img retain] autorelease];
+}
+
+@end
+
+
+// NSAppleEventDescriptor('vers') -> java.lang.String
+@implementation JavaAppleScriptVersionConverter
+
+- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    NSAppleEventDescriptor *desc = (NSAppleEventDescriptor *)obj;
+
+    const AEDesc *aeDesc = [desc aeDesc];
+    if (aeDesc->descriptorType == typeNull) {
+        return NULL;
+    }
+
+    return JNFNSToJavaString(env, [obj description]);
+}
+
+- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    return nil; // there is no Java object that represents a "version"
+}
+
+@end
+
+
+// NSNull <-> null
+@implementation JavaAppleScriptNullConverter
+
+- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    return NULL;
+}
+
+- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    return nil;
+}
+
+@end
diff --git a/jdk/src/macosx/native/apple/launcher/JavaAppLauncher.m b/jdk/src/macosx/native/apple/launcher/JavaAppLauncher.m
new file mode 100644
index 0000000..9dccdc5
--- /dev/null
+++ b/jdk/src/macosx/native/apple/launcher/JavaAppLauncher.m
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "apple_launcher_JavaAppLauncher.h"
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+/*
+ * Class:     apple_launcher_JavaAppLauncher
+ * Method:    nativeConvertAndRelease
+ * Signature: (J)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_apple_launcher_JavaAppLauncher_nativeConvertAndRelease
+(JNIEnv *env, jclass clazz, jlong nsObjectPtr) {
+
+    jobject value = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    id obj = jlong_to_ptr(nsObjectPtr);
+    value = [[JNFDefaultCoercions defaultCoercer] coerceNSObject:obj withEnv:env];
+    CFRelease(obj);
+
+JNF_COCOA_EXIT(env);
+
+    return value;
+}
+
+/*
+ * Class:     apple_launcher_JavaAppLauncher
+ * Method:    nativeInvokeNonPublic
+ * Signature: (Ljava/lang/Class;Ljava/lang/reflect/Method;[Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_apple_launcher_JavaAppLauncher_nativeInvokeNonPublic
+(JNIEnv *env, jclass clazz, jclass targetClass, jobject targetMethod, jobjectArray args) {
+    jmethodID mainMethodID = (*env)->FromReflectedMethod(env, targetMethod);
+    if ((*env)->ExceptionOccurred(env)) return;
+    (*env)->CallStaticVoidMethod(env, targetClass, mainMethodID, args);
+}
diff --git a/jdk/src/macosx/native/apple/security/KeystoreImpl.m b/jdk/src/macosx/native/apple/security/KeystoreImpl.m
new file mode 100644
index 0000000..d8dfff3
--- /dev/null
+++ b/jdk/src/macosx/native/apple/security/KeystoreImpl.m
@@ -0,0 +1,553 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "apple_security_KeychainStore.h"
+
+#import <Security/Security.h>
+#import <Security/SecImportExport.h>
+#import <CoreServices/CoreServices.h>  // (for require() macros)
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+static JNF_CLASS_CACHE(jc_KeychainStore, "apple/security/KeychainStore");
+static JNF_MEMBER_CACHE(jm_createTrustedCertEntry, jc_KeychainStore, "createTrustedCertEntry", "(Ljava/lang/String;JJ[B)V");
+static JNF_MEMBER_CACHE(jm_createKeyEntry, jc_KeychainStore, "createKeyEntry", "(Ljava/lang/String;JJ[J[[B)V");
+
+static jstring getLabelFromItem(JNIEnv *env, SecKeychainItemRef inItem)
+{
+    OSStatus status;
+    jstring returnValue = NULL;
+    char *attribCString = NULL;
+
+    SecKeychainAttribute itemAttrs[] = { { kSecLabelItemAttr, 0, NULL } };
+    SecKeychainAttributeList attrList = { sizeof(itemAttrs) / sizeof(itemAttrs[0]), itemAttrs };
+
+    status = SecKeychainItemCopyContent(inItem, NULL, &attrList, NULL, NULL);
+
+    if(status) {
+        cssmPerror("getLabelFromItem: SecKeychainItemCopyContent", status);
+        goto errOut;
+    }
+
+    attribCString = malloc(itemAttrs[0].length + 1);
+    strncpy(attribCString, itemAttrs[0].data, itemAttrs[0].length);
+    attribCString[itemAttrs[0].length] = '\0';
+    returnValue = (*env)->NewStringUTF(env, attribCString);
+
+errOut:
+    SecKeychainItemFreeContent(&attrList, NULL);
+    if (attribCString) free(attribCString);
+    return returnValue;
+}
+
+static jlong getModDateFromItem(JNIEnv *env, SecKeychainItemRef inItem)
+{
+    OSStatus status;
+    SecKeychainAttribute itemAttrs[] = { { kSecModDateItemAttr, 0, NULL } };
+    SecKeychainAttributeList attrList = { sizeof(itemAttrs) / sizeof(itemAttrs[0]), itemAttrs };
+    jlong returnValue = 0;
+
+    status = SecKeychainItemCopyContent(inItem, NULL, &attrList, NULL, NULL);
+
+    if(status) {
+        // This is almost always missing, so don't dump an error.
+        // cssmPerror("getModDateFromItem: SecKeychainItemCopyContent", status);
+        goto errOut;
+    }
+
+    memcpy(&returnValue, itemAttrs[0].data, itemAttrs[0].length);
+
+errOut:
+    SecKeychainItemFreeContent(&attrList, NULL);
+    return returnValue;
+}
+
+static void setLabelForItem(NSString *inLabel, SecKeychainItemRef inItem)
+{
+    OSStatus status;
+    const char *labelCString = [inLabel UTF8String];
+
+    // Set up attribute vector (each attribute consists of {tag, length, pointer}):
+    SecKeychainAttribute attrs[] = {
+        { kSecLabelItemAttr, strlen(labelCString), (void *)labelCString }
+    };
+
+    const SecKeychainAttributeList attributes = { sizeof(attrs) / sizeof(attrs[0]), attrs };
+
+    // Not changing data here, just attributes.
+    status = SecKeychainItemModifyContent(inItem, &attributes, 0, NULL);
+
+    if(status) {
+        cssmPerror("setLabelForItem: SecKeychainItemModifyContent", status);
+    }
+}
+
+/*
+ * Given a SecIdentityRef, do our best to construct a complete, ordered, and
+ * verified cert chain, returning the result in a CFArrayRef. The result is
+ * can be passed back to Java as a chain for a private key.
+ */
+static OSStatus completeCertChain(
+                                     SecIdentityRef         identity,
+                                     SecCertificateRef    trustedAnchor,    // optional additional trusted anchor
+                                     bool                 includeRoot,     // include the root in outArray
+                                     CFArrayRef            *outArray)        // created and RETURNED
+{
+    SecTrustRef                    secTrust = NULL;
+    SecPolicyRef                policy = NULL;
+    SecPolicySearchRef            policySearch = NULL;
+    SecTrustResultType            secTrustResult;
+    CSSM_TP_APPLE_EVIDENCE_INFO *dummyEv;            // not used
+    CFArrayRef                    certChain = NULL;   // constructed chain, CERTS ONLY
+    CFMutableArrayRef             subjCerts;            // passed to SecTrust
+    CFMutableArrayRef             certArray;            // returned array starting with
+                                                    //   identity
+    CFIndex                     numResCerts;
+    CFIndex                     dex;
+    OSStatus                     ortn;
+      SecCertificateRef             certRef;
+
+    /* First element in out array is the SecIdentity */
+    certArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+    CFArrayAppendValue(certArray, identity);
+
+    /* the single element in certs-to-be-evaluated comes from the identity */
+       ortn = SecIdentityCopyCertificate(identity, &certRef);
+    if(ortn) {
+        /* should never happen */
+        cssmPerror("SecIdentityCopyCertificate", ortn);
+        return ortn;
+    }
+
+    /*
+     * Now use SecTrust to get a complete cert chain, using all of the
+     * user's keychains to look for intermediate certs.
+     * NOTE this does NOT handle root certs which are not in the system
+     * root cert DB.
+     */
+    subjCerts = CFArrayCreateMutable(NULL, 1, &kCFTypeArrayCallBacks);
+    CFArraySetValueAtIndex(subjCerts, 0, certRef);
+
+    /* the array owns the subject cert ref now */
+    CFRelease(certRef);
+
+    /* Get a SecPolicyRef for generic X509 cert chain verification */
+    ortn = SecPolicySearchCreate(CSSM_CERT_X_509v3,
+                                 &CSSMOID_APPLE_X509_BASIC,
+                                 NULL,                // value
+                                 &policySearch);
+    if(ortn) {
+        /* should never happen */
+        cssmPerror("SecPolicySearchCreate", ortn);
+        goto errOut;
+    }
+    ortn = SecPolicySearchCopyNext(policySearch, &policy);
+    if(ortn) {
+        /* should never happen */
+        cssmPerror("SecPolicySearchCopyNext", ortn);
+        goto errOut;
+    }
+
+    /* build a SecTrustRef for specified policy and certs */
+    ortn = SecTrustCreateWithCertificates(subjCerts,
+                                          policy, &secTrust);
+    if(ortn) {
+        cssmPerror("SecTrustCreateWithCertificates", ortn);
+        goto errOut;
+    }
+
+    if(trustedAnchor) {
+        /*
+        * Tell SecTrust to trust this one in addition to the current
+         * trusted system-wide anchors.
+         */
+        CFMutableArrayRef newAnchors;
+        CFArrayRef currAnchors;
+
+        ortn = SecTrustCopyAnchorCertificates(&currAnchors);
+        if(ortn) {
+            /* should never happen */
+            cssmPerror("SecTrustCopyAnchorCertificates", ortn);
+            goto errOut;
+        }
+        newAnchors = CFArrayCreateMutableCopy(NULL,
+                                              CFArrayGetCount(currAnchors) + 1,
+                                              currAnchors);
+        CFRelease(currAnchors);
+        CFArrayAppendValue(newAnchors, trustedAnchor);
+        ortn = SecTrustSetAnchorCertificates(secTrust, newAnchors);
+        CFRelease(newAnchors);
+        if(ortn) {
+            cssmPerror("SecTrustSetAnchorCertificates", ortn);
+            goto errOut;
+        }
+    }
+
+    /* evaluate: GO */
+    ortn = SecTrustEvaluate(secTrust, &secTrustResult);
+    if(ortn) {
+        cssmPerror("SecTrustEvaluate", ortn);
+        goto errOut;
+    }
+    switch(secTrustResult) {
+        case kSecTrustResultUnspecified:
+            /* cert chain valid, no special UserTrust assignments; drop thru */
+        case kSecTrustResultProceed:
+            /* cert chain valid AND user explicitly trusts this */
+            break;
+        default:
+            /*
+             * Cert chain construction failed.
+             * Just go with the single subject cert we were given; maybe the
+             * peer can complete the chain.
+             */
+            ortn = noErr;
+            goto errOut;
+    }
+
+    /* get resulting constructed cert chain */
+    ortn = SecTrustGetResult(secTrust, &secTrustResult, &certChain, &dummyEv);
+    if(ortn) {
+        cssmPerror("SecTrustEvaluate", ortn);
+        goto errOut;
+    }
+
+    /*
+     * Copy certs from constructed chain to our result array, skipping
+     * the leaf (which is already there, as a SecIdentityRef) and possibly
+     * a root.
+     */
+    numResCerts = CFArrayGetCount(certChain);
+    if(numResCerts < 1) {
+        /*
+         * Can't happen: If chain doesn't verify to a root, we'd
+         * have bailed after SecTrustEvaluate().
+         */
+        ortn = noErr;
+        goto errOut;
+    }
+    if(!includeRoot) {
+        /* skip the last (root) cert) */
+        numResCerts--;
+    }
+    for(dex=1; dex<numResCerts; dex++) {
+        certRef = (SecCertificateRef)CFArrayGetValueAtIndex(certChain, dex);
+        CFArrayAppendValue(certArray, certRef);
+    }
+errOut:
+        /* clean up */
+        if(secTrust) {
+            CFRelease(secTrust);
+        }
+    if(subjCerts) {
+        CFRelease(subjCerts);
+    }
+    if(policy) {
+        CFRelease(policy);
+    }
+    if(policySearch) {
+        CFRelease(policySearch);
+    }
+    *outArray = certArray;
+    return ortn;
+}
+
+static void addIdentitiesToKeystore(JNIEnv *env, jobject keyStore)
+{
+    // Search the user keychain list for all identities. Identities are a certificate/private key association that
+    // can be chosen for a purpose such as signing or an SSL connection.
+    SecIdentitySearchRef identitySearch = NULL;
+    OSStatus err = SecIdentitySearchCreate(NULL, CSSM_KEYUSE_ANY, &identitySearch);
+    SecIdentityRef theIdentity = NULL;
+    OSErr searchResult = noErr;
+
+    do {
+        searchResult = SecIdentitySearchCopyNext(identitySearch, &theIdentity);
+
+        if (searchResult == noErr) {
+            // Get the cert from the identity, then generate a chain.
+            SecCertificateRef certificate;
+            SecIdentityCopyCertificate(theIdentity, &certificate);
+            CFArrayRef certChain = NULL;
+
+            // *** Should do something with this error...
+            err = completeCertChain(theIdentity, NULL, TRUE, &certChain);
+
+            CFIndex i, certCount = CFArrayGetCount(certChain);
+
+            // Make a java array of certificate data from the chain.
+            jclass byteArrayClass = (*env)->FindClass(env, "[B");
+            jobjectArray javaCertArray = (*env)->NewObjectArray(env, certCount, byteArrayClass, NULL);
+            (*env)->DeleteLocalRef(env, byteArrayClass);
+
+            // And, make an array of the certificate refs.
+            jlongArray certRefArray = (*env)->NewLongArray(env, certCount);
+
+            SecCertificateRef currCertRef = NULL;
+
+            for (i = 0; i < certCount; i++) {
+                CSSM_DATA currCertData;
+
+                if (i == 0)
+                    currCertRef = certificate;
+                else
+                    currCertRef = (SecCertificateRef)CFArrayGetValueAtIndex(certChain, i);
+
+                bzero(&currCertData, sizeof(CSSM_DATA));
+                err = SecCertificateGetData(currCertRef, &currCertData);
+                jbyteArray encodedCertData = (*env)->NewByteArray(env, currCertData.Length);
+                (*env)->SetByteArrayRegion(env, encodedCertData, 0, currCertData.Length, (jbyte *)currCertData.Data);
+                (*env)->SetObjectArrayElement(env, javaCertArray, i, encodedCertData);
+                jlong certRefElement = ptr_to_jlong(currCertRef);
+                (*env)->SetLongArrayRegion(env, certRefArray, i, 1, &certRefElement);
+            }
+
+            // Get the private key.  When needed we'll export the data from it later.
+            SecKeyRef privateKeyRef;
+            err = SecIdentityCopyPrivateKey(theIdentity, &privateKeyRef);
+
+            // Find the label.  It's a 'blob', but we interpret as characters.
+            jstring alias = getLabelFromItem(env, (SecKeychainItemRef)certificate);
+
+            // Find the creation date.
+            jlong creationDate = getModDateFromItem(env, (SecKeychainItemRef)certificate);
+
+            // Call back to the Java object to create Java objects corresponding to this security object.
+            jlong nativeKeyRef = ptr_to_jlong(privateKeyRef);
+            JNFCallVoidMethod(env, keyStore, jm_createKeyEntry, alias, creationDate, nativeKeyRef, certRefArray, javaCertArray);
+            break;
+        }
+    } while (searchResult == noErr);
+
+    if (identitySearch != NULL) {
+        CFRelease(identitySearch);
+    }
+}
+
+static void addCertificatesToKeystore(JNIEnv *env, jobject keyStore)
+{
+    // Search the user keychain list for all X509 certificates.
+    SecKeychainSearchRef keychainItemSearch = NULL;
+    OSStatus err = SecKeychainSearchCreateFromAttributes(NULL, kSecCertificateItemClass, NULL, &keychainItemSearch);
+    SecKeychainItemRef theItem = NULL;
+    OSErr searchResult = noErr;
+
+    do {
+        searchResult = SecKeychainSearchCopyNext(keychainItemSearch, &theItem);
+
+        if (searchResult == noErr) {
+            // Make a byte array with the DER-encoded contents of the certificate.
+            SecCertificateRef certRef = (SecCertificateRef)theItem;
+            CSSM_DATA currCertificate;
+            err = SecCertificateGetData(certRef, &currCertificate);
+            jbyteArray certData = (*env)->NewByteArray(env, currCertificate.Length);
+            (*env)->SetByteArrayRegion(env, certData, 0, currCertificate.Length, (jbyte *)currCertificate.Data);
+
+            // Find the label.  It's a 'blob', but we interpret as characters.
+            jstring alias = getLabelFromItem(env, theItem);
+
+            // Find the creation date.
+            jlong creationDate = getModDateFromItem(env, theItem);
+
+            // Call back to the Java object to create Java objects corresponding to this security object.
+            jlong nativeRef = ptr_to_jlong(certRef);
+            JNFCallVoidMethod(env, keyStore, jm_createTrustedCertEntry, alias, nativeRef, creationDate, certData);
+        }
+    } while (searchResult == noErr);
+
+    if (keychainItemSearch != NULL) {
+        CFRelease(keychainItemSearch);
+    }
+}
+
+/*
+ * Class:     apple_security_KeychainStore
+ * Method:    _getEncodedKeyData
+ * Signature: (J)[B
+     */
+JNIEXPORT jbyteArray JNICALL Java_apple_security_KeychainStore__1getEncodedKeyData
+(JNIEnv *env, jobject this, jlong keyRefLong, jcharArray passwordObj)
+{
+    SecKeyRef keyRef = (SecKeyRef)jlong_to_ptr(keyRefLong);
+    SecKeyImportExportParameters paramBlock;
+    OSStatus err = noErr;
+    CFDataRef exportedData = NULL;
+    jbyteArray returnValue = NULL;
+    CFStringRef passwordStrRef = NULL;
+
+    jsize passwordLen = 0;
+    jchar *passwordChars = NULL;
+
+    if (passwordObj) {
+        passwordLen = (*env)->GetArrayLength(env, passwordObj);
+
+        if (passwordLen > 0) {
+            passwordChars = (*env)->GetCharArrayElements(env, passwordObj, NULL);
+            passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
+        }
+    }
+
+    paramBlock.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
+    // Note that setting the flags field **requires** you to pass in a password of some kind.  The keychain will not prompt you.
+    paramBlock.flags = 0;
+    paramBlock.passphrase = passwordStrRef;
+    paramBlock.alertTitle = NULL;
+    paramBlock.alertPrompt = NULL;
+    paramBlock.accessRef = NULL;
+    paramBlock.keyUsage = CSSM_KEYUSE_ANY;
+    paramBlock.keyAttributes = CSSM_KEYATTR_RETURN_DEFAULT;
+
+    err = SecKeychainItemExport(keyRef, kSecFormatPKCS12, 0, &paramBlock, &exportedData);
+
+    if (err == noErr) {
+        CFIndex size = CFDataGetLength(exportedData);
+        returnValue = (*env)->NewByteArray(env, size);
+        (*env)->SetByteArrayRegion(env, returnValue, 0, size, (jbyte *)CFDataGetBytePtr(exportedData));
+    }
+
+    if (exportedData) CFRelease(exportedData);
+    if (passwordStrRef) CFRelease(passwordStrRef);
+
+    return returnValue;
+}
+
+
+/*
+ * Class:     apple_security_KeychainStore
+ * Method:    _scanKeychain
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_apple_security_KeychainStore__1scanKeychain
+(JNIEnv *env, jobject this)
+{
+    // Look for 'identities' -- private key and certificate chain pairs -- and add those.
+    // Search for these first, because a certificate that's found here as part of an identity will show up
+    // again later as a certificate.
+    addIdentitiesToKeystore(env, this);
+
+    // Scan current keychain for trusted certificates.
+    addCertificatesToKeystore(env, this);
+
+}
+
+/*
+ * Class:     apple_security_KeychainStore
+ * Method:    _addItemToKeychain
+ * Signature: (Ljava/lang/String;[B)I
+*/
+JNIEXPORT jlong JNICALL Java_apple_security_KeychainStore__1addItemToKeychain
+(JNIEnv *env, jobject this, jstring alias, jboolean isCertificate, jbyteArray rawDataObj, jcharArray passwordObj)
+{
+    OSStatus err;
+    jlong returnValue = 0;
+
+JNF_COCOA_ENTER(env);
+
+    jsize dataSize = (*env)->GetArrayLength(env, rawDataObj);
+    jbyte *rawData = (*env)->GetByteArrayElements(env, rawDataObj, NULL);
+
+    CFDataRef cfDataToImport = CFDataCreate(kCFAllocatorDefault, (UInt8 *)rawData, dataSize);
+    CFArrayRef createdItems = NULL;
+
+    SecKeychainRef defaultKeychain = NULL;
+    SecKeychainCopyDefault(&defaultKeychain);
+
+    SecExternalItemType dataType = (isCertificate == JNI_TRUE ? kSecFormatX509Cert : kSecFormatWrappedPKCS8);
+
+    // Convert the password obj into a CFStringRef that the keychain importer can use for encryption.
+    SecKeyImportExportParameters paramBlock;
+    CFStringRef passwordStrRef = NULL;
+
+    jsize passwordLen = 0;
+    jchar *passwordChars = NULL;
+
+    if (passwordObj) {
+        passwordLen = (*env)->GetArrayLength(env, passwordObj);
+        passwordChars = (*env)->GetCharArrayElements(env, passwordObj, NULL);
+        passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
+    }
+
+    paramBlock.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
+    // Note that setting the flags field **requires** you to pass in a password of some kind.  The keychain will not prompt you.
+    paramBlock.flags = 0;
+    paramBlock.passphrase = passwordStrRef;
+    paramBlock.alertTitle = NULL;
+    paramBlock.alertPrompt = NULL;
+    paramBlock.accessRef = NULL;
+    paramBlock.keyUsage = CSSM_KEYUSE_ANY;
+    paramBlock.keyAttributes = CSSM_KEYATTR_RETURN_DEFAULT;
+
+    err = SecKeychainItemImport(cfDataToImport, NULL, &dataType, NULL,
+                                0, &paramBlock, defaultKeychain, &createdItems);
+
+    if (err == noErr) {
+        SecKeychainItemRef anItem = (SecKeychainItemRef)CFArrayGetValueAtIndex(createdItems, 0);
+
+        // Don't bother labeling keys. They become part of an identity, and are not an accessible part of the keychain.
+        if (CFGetTypeID(anItem) == SecCertificateGetTypeID()) {
+            setLabelForItem(JNFJavaToNSString(env, alias), anItem);
+        }
+
+        // Retain the item, since it will be released once when the array holding it gets released.
+        CFRetain(anItem);
+        returnValue = ptr_to_jlong(anItem);
+    } else {
+        cssmPerror("_addItemToKeychain: SecKeychainItemImport", err);
+    }
+
+    (*env)->ReleaseByteArrayElements(env, rawDataObj, rawData, JNI_ABORT);
+
+    if (createdItems != NULL) {
+        CFRelease(createdItems);
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return returnValue;
+}
+
+/*
+ * Class:     apple_security_KeychainStore
+ * Method:    _removeItemFromKeychain
+ * Signature: (J)I
+*/
+JNIEXPORT jint JNICALL Java_apple_security_KeychainStore__1removeItemFromKeychain
+(JNIEnv *env, jobject this, jlong keychainItem)
+{
+    SecKeychainItemRef itemToRemove = jlong_to_ptr(keychainItem);
+    return SecKeychainItemDelete(itemToRemove);
+}
+
+/*
+ * Class:     apple_security_KeychainStore
+ * Method:    _releaseKeychainItemRef
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_apple_security_KeychainStore__1releaseKeychainItemRef
+(JNIEnv *env, jobject this, jlong keychainItem)
+{
+    SecKeychainItemRef itemToFree = jlong_to_ptr(keychainItem);
+    CFRelease(itemToFree);
+}
diff --git a/jdk/src/macosx/native/com/apple/concurrent/Dispatch.m b/jdk/src/macosx/native/com/apple/concurrent/Dispatch.m
new file mode 100644
index 0000000..d26cc0d
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/concurrent/Dispatch.m
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "com_apple_concurrent_LibDispatchNative.h"
+
+#import <dispatch/dispatch.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+/*
+ * Class:     com_apple_concurrent_LibDispatchNative
+ * Method:    nativeIsDispatchSupported
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeIsDispatchSupported
+(JNIEnv *env, jclass clazz)
+{
+        return JNI_TRUE;
+}
+
+
+/*
+ * Class:     com_apple_concurrent_LibDispatchNative
+ * Method:    nativeGetMainQueue
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeGetMainQueue
+(JNIEnv *env, jclass clazz)
+{
+        dispatch_queue_t queue = dispatch_get_main_queue();
+        return ptr_to_jlong(queue);
+}
+
+
+/*
+ * Class:     com_apple_concurrent_LibDispatchNative
+ * Method:    nativeCreateConcurrentQueue
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeCreateConcurrentQueue
+(JNIEnv *env, jclass clazz, jint priority)
+{
+        dispatch_queue_t queue = dispatch_get_global_queue((long)priority, 0);
+        return ptr_to_jlong(queue);
+}
+
+
+/*
+ * Class:     com_apple_concurrent_LibDispatchNative
+ * Method:    nativeCreateSerialQueue
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeCreateSerialQueue
+(JNIEnv *env, jclass clazz, jstring name)
+{
+        if (name == NULL) return 0L;
+
+        jboolean isCopy;
+        const char *queue_name = (*env)->GetStringUTFChars(env, name, &isCopy);
+        dispatch_queue_t queue = dispatch_queue_create(queue_name, NULL);
+        (*env)->ReleaseStringUTFChars(env, name, queue_name);
+
+        return ptr_to_jlong(queue);
+}
+
+
+/*
+ * Class:     com_apple_concurrent_LibDispatchNative
+ * Method:    nativeReleaseQueue
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeReleaseQueue
+(JNIEnv *env, jclass clazz, jlong nativeQueue)
+{
+        if (nativeQueue == 0L) return;
+        dispatch_release((dispatch_queue_t)jlong_to_ptr(nativeQueue));
+}
+
+
+static JNF_CLASS_CACHE(jc_Runnable, "java/lang/Runnable");
+static JNF_MEMBER_CACHE(jm_run, jc_Runnable, "run", "()V");
+
+static void perform_dispatch(JNIEnv *env, jlong nativeQueue, jobject runnable, void (*dispatch_fxn)(dispatch_queue_t, dispatch_block_t))
+{
+JNF_COCOA_ENTER(env);
+        dispatch_queue_t queue = (dispatch_queue_t)jlong_to_ptr(nativeQueue);
+        if (queue == NULL) return; // shouldn't happen
+
+        // create a global-ref around the Runnable, so it can be safely passed to the dispatch thread
+        JNFJObjectWrapper *wrappedRunnable = [[JNFJObjectWrapper alloc] initWithJObject:runnable withEnv:env];
+
+        dispatch_fxn(queue, ^{
+                // attach the dispatch thread to the JVM if necessary, and get an env
+                JNFThreadContext ctx = JNFThreadDetachOnThreadDeath | JNFThreadSetSystemClassLoaderOnAttach | JNFThreadAttachAsDaemon;
+                JNIEnv *blockEnv = JNFObtainEnv(&ctx);
+
+        JNF_COCOA_ENTER(blockEnv);
+
+                // call the user's runnable
+                JNFCallObjectMethod(blockEnv, [wrappedRunnable jObject], jm_run);
+
+                // explicitly clear object while we have an env (it's cheaper that way)
+                [wrappedRunnable setJObject:NULL withEnv:blockEnv];
+
+        JNF_COCOA_EXIT(blockEnv);
+
+                // let the env go, but leave the thread attached as a daemon
+                JNFReleaseEnv(blockEnv, &ctx);
+        });
+
+        // release this thread's interest in the Runnable, the block
+        // will have retained the it's own interest above
+        [wrappedRunnable release];
+
+JNF_COCOA_EXIT(env);
+}
+
+
+/*
+ * Class:     com_apple_concurrent_LibDispatchNative
+ * Method:    nativeExecuteAsync
+ * Signature: (JLjava/lang/Runnable;)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeExecuteAsync
+(JNIEnv *env, jclass clazz, jlong nativeQueue, jobject runnable)
+{
+        // enqueues and returns
+        perform_dispatch(env, nativeQueue, runnable, dispatch_async);
+}
+
+
+/*
+ * Class:     com_apple_concurrent_LibDispatchNative
+ * Method:    nativeExecuteSync
+ * Signature: (JLjava/lang/Runnable;)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeExecuteSync
+(JNIEnv *env, jclass clazz, jlong nativeQueue, jobject runnable)
+{
+        // blocks until the Runnable completes
+        perform_dispatch(env, nativeQueue, runnable, dispatch_sync);
+}
diff --git a/jdk/src/macosx/native/com/apple/eio/CFileManager.m b/jdk/src/macosx/native/com/apple/eio/CFileManager.m
new file mode 100644
index 0000000..f28840d
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/eio/CFileManager.m
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "com_apple_eio_FileManager.h"
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "ThreadUtilities.h"
+
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    _setFileTypeAndCreator
+ * Signature: (Ljava/lang/String;II)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1setFileTypeAndCreator
+(JNIEnv *env, jclass clz, jstring javaFilename, jint type, jint creator)
+{
+JNF_COCOA_ENTER(env);
+        NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename);
+        NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys:
+                                                        [NSNumber numberWithInt:type], NSFileHFSTypeCode,
+                                                        [NSNumber numberWithInt:creator], NSFileHFSCreatorCode, nil];
+    [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    _setFileType
+ * Signature: (Ljava/lang/String;I)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1setFileType
+(JNIEnv *env, jclass ckz, jstring javaFilename, jint type)
+{
+JNF_COCOA_ENTER(env);
+        NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename);
+        NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:type] forKey:NSFileHFSTypeCode];
+    [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    _setFileCreator
+ * Signature: (Ljava/lang/String;I)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1setFileCreator
+(JNIEnv *env, jclass clz, jstring javaFilename, jint creator)
+{
+JNF_COCOA_ENTER(env);
+        NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename);
+        NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:creator] forKey:NSFileHFSCreatorCode];
+    [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    _getFileType
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_com_apple_eio_FileManager__1getFileType
+(JNIEnv *env, jclass clz, jstring javaFilename)
+{
+    jint type = 0;
+JNF_COCOA_ENTER(env);
+        NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename);
+    NSDictionary *attributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES];
+    NSNumber *val = [attributes objectForKey:NSFileHFSTypeCode];
+    type = [val intValue];
+JNF_COCOA_EXIT(env);
+    return type;
+}
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    _getFileCreator
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_com_apple_eio_FileManager__1getFileCreator
+  (JNIEnv *env, jclass clz, jstring javaFilename)
+{
+    jint creator = 0;
+JNF_COCOA_ENTER(env);
+        NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename);
+    NSDictionary *attributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES];
+    NSNumber *val = [attributes objectForKey:NSFileHFSCreatorCode];
+    creator = [val intValue];
+JNF_COCOA_EXIT(env);
+    return creator;
+}
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    _findFolder
+ * Signature: (SIZ)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_eio_FileManager__1findFolder__SIZ
+(JNIEnv *env, jclass clz, jshort domain, jint folderType, jboolean createIfNeeded)
+{
+    jstring filename = nil;
+JNF_COCOA_ENTER(env);
+
+    FSRef foundRef;
+    createIfNeeded = createIfNeeded || (folderType == kTemporaryFolderType) || (folderType == kChewableItemsFolderType);
+    if (FSFindFolder((SInt16)domain, (OSType)folderType, (Boolean)createIfNeeded, &foundRef) == noErr) {
+        char path[PATH_MAX];
+        if (FSRefMakePath(&foundRef, (UInt8 *)path, sizeof(path)) == noErr) {
+            NSString *filenameString = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path length:strlen(path)];
+            filename = JNFNormalizedJavaStringForPath(env, filenameString);
+        }
+    }
+
+JNF_COCOA_EXIT(env);
+    return filename;
+}
+
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    _openURL
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1openURL
+(JNIEnv *env, jclass clz, jstring urlString)
+{
+JNF_COCOA_ENTER(env);
+
+    NSURL *url = [NSURL URLWithString:JNFNormalizedNSStringForPath(env, urlString)];
+
+        // Radar 3208005: Run this on the main thread; file:// style URLs will hang otherwise.
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [[NSWorkspace sharedWorkspace] openURL:url];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    getNativeResourceFromBundle
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_eio_FileManager_getNativeResourceFromBundle
+(JNIEnv *env, jclass clz, jstring javaResourceName, jstring javaSubDirName, jstring javaTypeName)
+{
+    jstring filename = NULL;
+JNF_COCOA_ENTER(env);
+
+    NSString *resourceName = JNFNormalizedNSStringForPath(env, javaResourceName);
+        NSString *subDirectory = JNFNormalizedNSStringForPath(env, javaSubDirName);
+        NSString *typeName = JNFNormalizedNSStringForPath(env, javaTypeName);
+
+    NSString *path = [[NSBundle mainBundle] pathForResource:resourceName
+                                                     ofType:typeName
+                                                inDirectory:subDirectory];
+
+    filename = JNFNormalizedJavaStringForPath(env, path);
+
+JNF_COCOA_EXIT(env);
+    return filename;
+}
+
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    getNativePathToApplicationBundle
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_eio_FileManager_getNativePathToApplicationBundle
+(JNIEnv *env, jclass clazz)
+{
+        jstring filename = nil;
+JNF_COCOA_ENTER(env);
+
+        NSBundle *mainBundle = [NSBundle mainBundle];
+        filename = JNFNormalizedJavaStringForPath(env, [mainBundle bundlePath]);
+
+JNF_COCOA_EXIT(env);
+        return filename;
+}
+
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    __moveToTrash
+ * Signature: (Ljava/lang/String;)V
+ */
+
+JNIEXPORT jboolean JNICALL Java_com_apple_eio_FileManager__1moveToTrash
+(JNIEnv *env, jclass clz, jstring url)
+{
+        __block jboolean returnValue = JNI_FALSE;
+JNF_COCOA_ENTER(env);
+
+    NSString *path = JNFNormalizedNSStringForPath(env, url);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        NSInteger res = 0;
+        [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation
+                                                     source:[path stringByDeletingLastPathComponent]
+                                                destination:nil
+                                                      files:[NSArray arrayWithObject:[path lastPathComponent]]
+                                                        tag:&res];
+        returnValue = (res == 0);
+    }];
+
+JNF_COCOA_EXIT(env);
+
+        return returnValue;
+}
+
+/*
+ * Class:     com_apple_eio_FileManager
+ * Method:    __revealInFinder
+ * Signature: (Ljava/lang/String;)V
+ */
+
+JNIEXPORT jboolean JNICALL Java_com_apple_eio_FileManager__1revealInFinder
+(JNIEnv *env, jclass clz, jstring url)
+{
+        __block jboolean returnValue = JNI_FALSE;
+JNF_COCOA_ENTER(env);
+
+    NSString *path = JNFNormalizedNSStringForPath(env, url);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        returnValue = [[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:@""];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+        return returnValue;
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/AquaFileView.m b/jdk/src/macosx/native/com/apple/laf/AquaFileView.m
new file mode 100644
index 0000000..8f33cc5
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/AquaFileView.m
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "com_apple_laf_AquaFileView.h"
+
+#import <sys/param.h> // for MAXPATHLEN
+#import <CoreFoundation/CoreFoundation.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ * Class:     com_apple_laf_AquaFileView
+ * Method:    getNativePathToRunningJDKBundle
+ * Signature: ()Ljava/lang/String;
+ */
+// TODO: Un-comment this out
+/*JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToRunningJDKBundle
+(JNIEnv *env, jclass clazz)
+{
+    jstring returnValue = NULL;
+JNF_COCOA_ENTER(env);
+
+    returnValue = JNFNSToJavaString(env, getRunningJavaBundle());
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}*/
+
+/*
+ * Class:     com_apple_laf_AquaFileView
+ * Method:    getNativePathToSharedJDKBundle
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToSharedJDKBundle
+(JNIEnv *env, jclass clazz)
+{
+    jstring returnValue = NULL;
+JNF_COCOA_ENTER(env);
+
+    returnValue = JNFNSToJavaString(env, [[NSBundle bundleWithIdentifier:@"com.apple.JavaVM"] bundlePath]);
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     com_apple_laf_AquaFileView
+ * Method:    getNativeMachineName
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeMachineName
+(JNIEnv *env, jclass clazz)
+{
+    jstring returnValue = NULL;
+JNF_COCOA_ENTER(env);
+
+    CFStringRef machineName = CSCopyMachineName();
+    returnValue = JNFNSToJavaString(env, (NSString*)machineName);
+
+    if (machineName != NULL) {
+        CFRelease(machineName);
+    }
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     com_apple_laf_AquaFileView
+ * Method:    getNativeLSInfo
+ * Signature: ([BZ)I
+ */
+JNIEXPORT jint JNICALL Java_com_apple_laf_AquaFileView_getNativeLSInfo
+(JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)
+{
+    jint returnValue = com_apple_laf_AquaFileView_UNINITALIZED_LS_INFO;
+JNF_COCOA_ENTER(env);
+
+    jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);
+    jsize length = (*env)->GetArrayLength(env, absolutePath);
+
+    // Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't
+    // let us specify a length.
+    UInt8 arrayCopy[length + 1];
+    jsize i;
+    for (i = 0; i < length; i++) {
+        arrayCopy[i] = (UInt8)byteArray[i];
+    }
+    arrayCopy[length] = '\0';
+    (*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);
+
+    Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
+    FSRef ref;
+    OSErr err = FSPathMakeRef((const UInt8 *)&arrayCopy, &ref, &isDirectory);
+    if (err == noErr) {
+        LSItemInfoRecord itemInfo;
+        err = LSCopyItemInfoForRef(&ref, kLSRequestBasicFlagsOnly, &itemInfo);
+
+        if (err == noErr) {
+            returnValue = itemInfo.flags;
+        }
+    }
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     com_apple_laf_AquaFileView
+ * Method:    getNativeDisplayName
+ * Signature: ([BZ)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeDisplayName
+(JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)
+{
+    jstring returnValue = NULL;
+JNF_COCOA_ENTER(env);
+
+    jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);
+    jsize length = (*env)->GetArrayLength(env, absolutePath);
+
+    // Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't
+    // let us specify a length.
+    UInt8 arrayCopy[length + 1];
+    jsize i;
+    for (i = 0; i < length; i++) {
+        arrayCopy[i] = (UInt8)byteArray[i];
+    }
+    arrayCopy[length] = '\0';
+    (*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);
+
+    Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
+    FSRef ref;
+
+    OSErr theErr = FSPathMakeRefWithOptions((const UInt8 *)&arrayCopy, kFSPathMakeRefDoNotFollowLeafSymlink, &ref, &isDirectory);
+    if (theErr == noErr) {
+        CFStringRef displayName = NULL;
+
+        theErr = LSCopyDisplayNameForRef(&ref, &displayName);
+
+        if (theErr == noErr) {
+            CFMutableStringRef mutableDisplayName = CFStringCreateMutableCopy(NULL, 0, displayName);
+            CFStringNormalize(mutableDisplayName, kCFStringNormalizationFormC);
+            returnValue = JNFNSToJavaString(env, (NSString *)mutableDisplayName);
+            CFRelease(mutableDisplayName);
+        }
+
+        if (displayName != NULL) {
+            CFRelease(displayName);
+        }
+    }
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     com_apple_laf_AquaFileView
+ * Method:    getNativePathForResolvedAlias
+ * Signature: ([BZ)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathForResolvedAlias
+(JNIEnv *env, jclass clazz, jbyteArray pathToAlias, jboolean isDir)
+{
+    jstring returnValue = NULL;
+JNF_COCOA_ENTER(env);
+
+    UInt8 pathCString[MAXPATHLEN + 1];
+    size_t pathSize = sizeof(pathCString);
+
+    jbyte *byteArray = (*env)->GetByteArrayElements(env, pathToAlias, NULL);
+    jsize length = (*env)->GetArrayLength(env, pathToAlias);
+
+    if (length > pathSize) {
+        length = pathSize;
+    }
+    strncpy((char *)pathCString, (char *)byteArray, length);
+    // make sure it's null terminated
+    pathCString[length] = '\0';
+    (*env)->ReleaseByteArrayElements(env, pathToAlias, byteArray, JNI_ABORT);
+
+    Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
+    FSRef fileRef;
+    OSErr theErr = FSPathMakeRef(pathCString, &fileRef, &isDirectory);
+
+    Boolean ignored;
+    theErr = FSResolveAliasFileWithMountFlags(&fileRef, false, &ignored, &ignored, kResolveAliasFileNoUI);
+    if (theErr == noErr) {
+        UInt8 resolvedPath[MAXPATHLEN];
+        theErr = FSRefMakePath(&fileRef, resolvedPath, MAXPATHLEN);
+
+        if (theErr == noErr) {
+            returnValue = (*env)->NewStringUTF(env, (char *)resolvedPath);
+        }
+    }
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/AquaLookAndFeel.m b/jdk/src/macosx/native/com/apple/laf/AquaLookAndFeel.m
new file mode 100644
index 0000000..83abf77
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/AquaLookAndFeel.m
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ *    Empty JNI_OnLoad - needed to prevent:
+ *    <rdar://4984599> AWT's JNI_OnLoad called multiple times
+ *    Please remove when <rdar://5121166> has been resolved.
+ */
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
+    return JNI_VERSION_1_4;
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/AquaNativeResources.m b/jdk/src/macosx/native/com/apple/laf/AquaNativeResources.m
new file mode 100644
index 0000000..cddd6df
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/AquaNativeResources.m
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "com_apple_laf_AquaNativeResources.h"
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ * Class:     com_apple_laf_AquaNativeResources
+ * Method:    getWindowBackgroundColor
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_laf_AquaNativeResources_getWindowBackgroundColor
+    (JNIEnv *env, jclass clz)
+{
+    // TODO(cpc): this code is currently disabled at the Java level
+#if 0
+    NSColor* color = nil;
+JNF_COCOA_ENTER(env);
+    color = [NSColor lightGrayColor];//[AWTColor getMagicBackgroundColor];
+    if (color) CFRetain(color); // GC
+JNF_COCOA_EXIT(env);
+    return ptr_to_jlong(color);
+#else
+    return 0L;
+#endif
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/JRSUIConstantSync.h b/jdk/src/macosx/native/com/apple/laf/JRSUIConstantSync.h
new file mode 100644
index 0000000..d2fdd5c
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/JRSUIConstantSync.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+BOOL _InitializeJRSProperties();
+jint _SyncEncodedProperties(JRSUIControlRef control, jlong oldProperties, jlong newProperties);
diff --git a/jdk/src/macosx/native/com/apple/laf/JRSUIConstantSync.m b/jdk/src/macosx/native/com/apple/laf/JRSUIConstantSync.m
new file mode 100644
index 0000000..8c6567d
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/JRSUIConstantSync.m
@@ -0,0 +1,386 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "apple_laf_JRSUIConstants.h"
+#import "apple_laf_JRSUIConstants_Key.h"
+#import "apple_laf_JRSUIConstants_AlignmentVertical.h"
+#import "apple_laf_JRSUIConstants_AlignmentHorizontal.h"
+#import "apple_laf_JRSUIConstants_Animating.h"
+#import "apple_laf_JRSUIConstants_ArrowsOnly.h"
+#import "apple_laf_JRSUIConstants_BooleanValue.h"
+#import "apple_laf_JRSUIConstants_Direction.h"
+#import "apple_laf_JRSUIConstants_Focused.h"
+#import "apple_laf_JRSUIConstants_FrameOnly.h"
+#import "apple_laf_JRSUIConstants_IndicatorOnly.h"
+#import "apple_laf_JRSUIConstants_NoIndicator.h"
+#import "apple_laf_JRSUIConstants_NothingToScroll.h"
+#import "apple_laf_JRSUIConstants_Orientation.h"
+#import "apple_laf_JRSUIConstants_ScrollBarPart.h"
+#import "apple_laf_JRSUIConstants_SegmentPosition.h"
+#import "apple_laf_JRSUIConstants_SegmentTrailingSeparator.h"
+#import "apple_laf_JRSUIConstants_SegmentLeadingSeparator.h"
+#import "apple_laf_JRSUIConstants_ShowArrows.h"
+#import "apple_laf_JRSUIConstants_Size.h"
+#import "apple_laf_JRSUIConstants_State.h"
+#import "apple_laf_JRSUIConstants_Variant.h"
+#import "apple_laf_JRSUIConstants_Widget.h"
+#import "apple_laf_JRSUIConstants_WindowType.h"
+#import "apple_laf_JRSUIConstants_WindowTitleBarSeparator.h"
+#import "apple_laf_JRSUIConstants_WindowClipCorners.h"
+
+#import "JRSUIConstantSync.h"
+
+
+static CFTypeRef widgetKey = NULL;
+static CFTypeRef stateKey = NULL;
+static CFTypeRef sizeKey = NULL;
+static CFTypeRef directionKey = NULL;
+static CFTypeRef orientationKey = NULL;
+static CFTypeRef verticalAlignmentKey = NULL;
+static CFTypeRef horizontalAlignmentKey = NULL;
+static CFTypeRef positionKey = NULL;
+static CFTypeRef pressedPartKey = NULL;
+static CFTypeRef variantKey = NULL;
+static CFTypeRef windowTypeKey = NULL;
+static CFTypeRef focusedKey = NULL;
+static CFTypeRef indicatorOnlyKey = NULL;
+static CFTypeRef noIndicatorKey = NULL;
+static CFTypeRef nothingToScrollKey = NULL;
+static CFTypeRef arrowsOnlyKey = NULL;
+static CFTypeRef frameOnlyKey = NULL;
+static CFTypeRef segmentTrailingSeparatorKey = NULL;
+static CFTypeRef segmentLeadingSeparatorKey = NULL;
+static CFTypeRef windowFrameDrawClippedKey = NULL;
+static CFTypeRef windowFrameDrawTitleSeparatorKey = NULL;
+static CFTypeRef maximumValueKey = NULL;
+static CFTypeRef valueKey = NULL;
+static CFTypeRef animationStartTimeKey = NULL;
+static CFTypeRef animationTimeKey = NULL;
+
+
+#define JRS_CONSTANT(clazz, constant)                                \
+    kJRSUI_ ## clazz ## _ ## constant
+
+#define JNI_CONSTANT(clazz, constant)                                \
+    apple_laf_JRSUIConstants_ ## clazz ## __ ## constant
+
+#define CONSTANT_CHECK(clazz, constant)                                \
+    JRS_CONSTANT(clazz, constant) == JNI_CONSTANT(clazz, constant)
+
+#define CONSISTENCY_CHECK(clazz, constant)                            \
+    if ( !CONSTANT_CHECK(clazz, constant) ) return NO;
+
+#define ASSIGN_KEY(key)                                                \
+    key ## Key = JRSUIGetKey(JRS_CONSTANT(Key, key));                \
+    if (key ## Key == NULL) return NO;
+
+#define ASSIGN_KEY_IF_EXISTS(key, constant)                          \
+    key ## Key = JRSUIGetKey(constant);
+
+static BOOL init_and_check_constant_coherency() {
+    ASSIGN_KEY(widget);
+    ASSIGN_KEY(state);
+    ASSIGN_KEY(size);
+    ASSIGN_KEY(direction);
+    ASSIGN_KEY(orientation);
+    ASSIGN_KEY(verticalAlignment);
+    ASSIGN_KEY(horizontalAlignment);
+    ASSIGN_KEY(position);
+    ASSIGN_KEY(pressedPart);
+    ASSIGN_KEY(variant);
+    ASSIGN_KEY(windowType);
+    ASSIGN_KEY(focused);
+    ASSIGN_KEY(indicatorOnly);
+    ASSIGN_KEY(noIndicator);
+    ASSIGN_KEY(nothingToScroll);
+    ASSIGN_KEY(arrowsOnly);
+    ASSIGN_KEY(frameOnly);
+    ASSIGN_KEY(segmentTrailingSeparator);
+    ASSIGN_KEY_IF_EXISTS(segmentLeadingSeparator, 29); // kJRSUI_Key_segmentLeadingSeparator = 29
+    ASSIGN_KEY(windowFrameDrawClipped);
+    ASSIGN_KEY(windowFrameDrawTitleSeparator);
+    ASSIGN_KEY(maximumValue);
+    ASSIGN_KEY(value);
+    ASSIGN_KEY(animationStartTime);
+    ASSIGN_KEY(animationTime);
+
+    CONSISTENCY_CHECK(Key, value);
+    CONSISTENCY_CHECK(Key, thumbProportion);
+    CONSISTENCY_CHECK(Key, thumbStart);
+    CONSISTENCY_CHECK(Key, animationFrame);
+    CONSISTENCY_CHECK(Key, windowTitleBarHeight);
+
+    CONSISTENCY_CHECK(Widget, background);
+    CONSISTENCY_CHECK(Widget, buttonBevel);
+    CONSISTENCY_CHECK(Widget, buttonBevelInset);
+    CONSISTENCY_CHECK(Widget, buttonBevelRound);
+    CONSISTENCY_CHECK(Widget, buttonCheckBox);
+    CONSISTENCY_CHECK(Widget, buttonComboBox);
+    CONSISTENCY_CHECK(Widget, buttonComboBoxInset);
+    CONSISTENCY_CHECK(Widget, buttonDisclosure);
+    CONSISTENCY_CHECK(Widget, buttonListHeader);
+    CONSISTENCY_CHECK(Widget, buttonLittleArrows);
+    CONSISTENCY_CHECK(Widget, buttonPopDown);
+    CONSISTENCY_CHECK(Widget, buttonPopDownInset);
+    CONSISTENCY_CHECK(Widget, buttonPopDownSquare);
+    CONSISTENCY_CHECK(Widget, buttonPopUp);
+    CONSISTENCY_CHECK(Widget, buttonPopUpInset);
+    CONSISTENCY_CHECK(Widget, buttonPopUpSquare);
+    CONSISTENCY_CHECK(Widget, buttonPush);
+    CONSISTENCY_CHECK(Widget, buttonPushScope);
+    CONSISTENCY_CHECK(Widget, buttonPushScope2);
+    CONSISTENCY_CHECK(Widget, buttonPushTextured);
+    CONSISTENCY_CHECK(Widget, buttonPushInset);
+    CONSISTENCY_CHECK(Widget, buttonPushInset2);
+    CONSISTENCY_CHECK(Widget, buttonRadio);
+    CONSISTENCY_CHECK(Widget, buttonRound);
+    CONSISTENCY_CHECK(Widget, buttonRoundHelp);
+    CONSISTENCY_CHECK(Widget, buttonRoundInset);
+    CONSISTENCY_CHECK(Widget, buttonRoundInset2);
+    CONSISTENCY_CHECK(Widget, buttonSearchFieldCancel);
+    CONSISTENCY_CHECK(Widget, buttonSearchFieldFind);
+    CONSISTENCY_CHECK(Widget, buttonSegmented);
+    CONSISTENCY_CHECK(Widget, buttonSegmentedInset);
+    CONSISTENCY_CHECK(Widget, buttonSegmentedInset2);
+    CONSISTENCY_CHECK(Widget, buttonSegmentedSCurve);
+    CONSISTENCY_CHECK(Widget, buttonSegmentedTextured);
+    CONSISTENCY_CHECK(Widget, buttonSegmentedToolbar);
+    CONSISTENCY_CHECK(Widget, dial);
+    CONSISTENCY_CHECK(Widget, disclosureTriangle);
+    CONSISTENCY_CHECK(Widget, dividerGrabber);
+    CONSISTENCY_CHECK(Widget, dividerSeparatorBar);
+    CONSISTENCY_CHECK(Widget, dividerSplitter);
+    CONSISTENCY_CHECK(Widget, focus);
+    CONSISTENCY_CHECK(Widget, frameGroupBox);
+    CONSISTENCY_CHECK(Widget, frameGroupBoxSecondary);
+    CONSISTENCY_CHECK(Widget, frameListBox);
+    CONSISTENCY_CHECK(Widget, framePlacard);
+    CONSISTENCY_CHECK(Widget, frameTextField);
+    CONSISTENCY_CHECK(Widget, frameTextFieldRound);
+    CONSISTENCY_CHECK(Widget, frameWell);
+    CONSISTENCY_CHECK(Widget, growBox);
+    CONSISTENCY_CHECK(Widget, growBoxTextured);
+    CONSISTENCY_CHECK(Widget, gradient);
+    CONSISTENCY_CHECK(Widget, menu);
+    CONSISTENCY_CHECK(Widget, menuItem);
+    CONSISTENCY_CHECK(Widget, menuBar);
+    CONSISTENCY_CHECK(Widget, menuTitle);
+    CONSISTENCY_CHECK(Widget, progressBar);
+    CONSISTENCY_CHECK(Widget, progressIndeterminateBar);
+    CONSISTENCY_CHECK(Widget, progressRelevance);
+    CONSISTENCY_CHECK(Widget, progressSpinner);
+    CONSISTENCY_CHECK(Widget, scrollBar);
+    CONSISTENCY_CHECK(Widget, scrollColumnSizer);
+    CONSISTENCY_CHECK(Widget, slider);
+    CONSISTENCY_CHECK(Widget, sliderThumb);
+    CONSISTENCY_CHECK(Widget, synchronization);
+    CONSISTENCY_CHECK(Widget, tab);
+    CONSISTENCY_CHECK(Widget, titleBarCloseBox);
+    CONSISTENCY_CHECK(Widget, titleBarCollapseBox);
+    CONSISTENCY_CHECK(Widget, titleBarZoomBox);
+    CONSISTENCY_CHECK(Widget, titleBarToolbarButton);
+    CONSISTENCY_CHECK(Widget, toolbarItemWell);
+    CONSISTENCY_CHECK(Widget, windowFrame);
+
+    CONSISTENCY_CHECK(State, active);
+    CONSISTENCY_CHECK(State, inactive);
+    CONSISTENCY_CHECK(State, disabled);
+    CONSISTENCY_CHECK(State, pressed);
+    CONSISTENCY_CHECK(State, pulsed);
+    CONSISTENCY_CHECK(State, rollover);
+    CONSISTENCY_CHECK(State, drag);
+
+    CONSISTENCY_CHECK(Size, mini);
+    CONSISTENCY_CHECK(Size, small);
+    CONSISTENCY_CHECK(Size, regular);
+    CONSISTENCY_CHECK(Size, large);
+
+    CONSISTENCY_CHECK(Direction, none);
+    CONSISTENCY_CHECK(Direction, up);
+    CONSISTENCY_CHECK(Direction, down);
+    CONSISTENCY_CHECK(Direction, left);
+    CONSISTENCY_CHECK(Direction, right);
+    CONSISTENCY_CHECK(Direction, north);
+    CONSISTENCY_CHECK(Direction, south);
+    CONSISTENCY_CHECK(Direction, east);
+    CONSISTENCY_CHECK(Direction, west);
+
+    CONSISTENCY_CHECK(Orientation, horizontal);
+    CONSISTENCY_CHECK(Orientation, vertical);
+
+    CONSISTENCY_CHECK(AlignmentHorizontal, left);
+    CONSISTENCY_CHECK(AlignmentHorizontal, center);
+    CONSISTENCY_CHECK(AlignmentHorizontal, right);
+
+    CONSISTENCY_CHECK(AlignmentVertical, top);
+    CONSISTENCY_CHECK(AlignmentVertical, center);
+    CONSISTENCY_CHECK(AlignmentVertical, bottom);
+
+    CONSISTENCY_CHECK(SegmentPosition, first);
+    CONSISTENCY_CHECK(SegmentPosition, middle);
+    CONSISTENCY_CHECK(SegmentPosition, last);
+    CONSISTENCY_CHECK(SegmentPosition, only);
+
+    CONSISTENCY_CHECK(ScrollBarPart, none);
+    CONSISTENCY_CHECK(ScrollBarPart, thumb);
+    CONSISTENCY_CHECK(ScrollBarPart, arrowMin);
+    CONSISTENCY_CHECK(ScrollBarPart, arrowMax);
+    CONSISTENCY_CHECK(ScrollBarPart, arrowMaxInside);
+    CONSISTENCY_CHECK(ScrollBarPart, arrowMinInside);
+    CONSISTENCY_CHECK(ScrollBarPart, trackMin);
+    CONSISTENCY_CHECK(ScrollBarPart, trackMax);
+
+    CONSISTENCY_CHECK(Variant, menuGlyph);
+    CONSISTENCY_CHECK(Variant, menuPopup);
+    CONSISTENCY_CHECK(Variant, menuPulldown);
+    CONSISTENCY_CHECK(Variant, menuHierarchical);
+    CONSISTENCY_CHECK(Variant, gradientListBackgroundEven);
+    CONSISTENCY_CHECK(Variant, gradientListBackgroundOdd);
+    CONSISTENCY_CHECK(Variant, gradientSideBar);
+    CONSISTENCY_CHECK(Variant, gradientSideBarSelection);
+    CONSISTENCY_CHECK(Variant, gradientSideBarFocusedSelection);
+
+    CONSISTENCY_CHECK(WindowType, document);
+    CONSISTENCY_CHECK(WindowType, utility);
+    CONSISTENCY_CHECK(WindowType, titlelessUtility);
+
+    return YES;
+}
+
+static CFBooleanRef get_boolean_value_for(jbyte value) {
+    return (value != 0) ? kCFBooleanTrue : kCFBooleanFalse;
+}
+
+static CFNumberRef get_boolean_number_value_for(jbyte value) {
+    static CFNumberRef zero = NULL;
+    static CFNumberRef one = NULL;
+
+    if (!zero) {
+        double zeroVal = 0.0;
+        zero = CFNumberCreate(NULL, kCFNumberDoubleType, &zeroVal);
+        double oneVal = 1.0;
+        one = CFNumberCreate(NULL, kCFNumberDoubleType, &oneVal);
+    }
+
+    return (value != 0) ? one : zero;
+}
+
+BOOL _InitializeJRSProperties() {
+    static BOOL initialized = NO;
+    static BOOL coherent = NO;
+
+    if (!initialized) {
+        coherent = init_and_check_constant_coherency();
+        initialized = YES;
+    }
+
+    return coherent;
+}
+
+#define MASK(property) \
+    apple_laf_JRSUIConstants_ ## property ## _MASK
+
+#define SHIFT(property) \
+    apple_laf_JRSUIConstants_ ## property ## _SHIFT
+
+#define IF_CHANGED_SET_USING(property, setter)                        \
+{                                                                    \
+    jlong value = (newProperties & MASK(property));                    \
+    if ((value - (oldProperties & MASK(property))) != 0L) {            \
+        setter(control, value >> SHIFT(property));                    \
+    }                                                                \
+}
+
+#define IF_CHANGED_SET_KEYED_BOOLEAN(property, key, getter)            \
+{                                                                    \
+    jlong value = (newProperties & MASK(property));                    \
+    if ((value - (oldProperties & MASK(property))) != 0L) {            \
+        CFTypeRef cfValue = getter(value >> SHIFT(property));        \
+        if (cfValue) {                                                \
+            JRSUIControlSetValueByKey(control, key, cfValue);        \
+        }                                                            \
+    }                                                                \
+}
+
+#define IF_KEY_EXISTS_DO(key, operation)                             \
+{                                                                    \
+    if (key != NULL) {                                               \
+        operation;                                                   \
+    }                                                                \
+}
+
+jint _SyncEncodedProperties(JRSUIControlRef control, jlong oldProperties, jlong newProperties) {
+    if (!_InitializeJRSProperties()) abort();
+
+    IF_CHANGED_SET_USING(Widget, JRSUIControlSetWidget);
+    IF_CHANGED_SET_USING(State, JRSUIControlSetState);
+    IF_CHANGED_SET_USING(Size, JRSUIControlSetSize);
+    IF_CHANGED_SET_USING(Direction, JRSUIControlSetDirection);
+    IF_CHANGED_SET_USING(Orientation, JRSUIControlSetOrientation);
+    IF_CHANGED_SET_USING(AlignmentVertical, JRSUIControlSetAlignmentVertical);
+    IF_CHANGED_SET_USING(AlignmentHorizontal, JRSUIControlSetAlignmentHorizontal);
+    IF_CHANGED_SET_USING(SegmentPosition, JRSUIControlSetSegmentPosition);
+    IF_CHANGED_SET_USING(ScrollBarPart, JRSUIControlSetScrollBarPart);
+    IF_CHANGED_SET_USING(Variant, JRSUIControlSetVariant);
+    IF_CHANGED_SET_USING(WindowType, JRSUIControlSetWindowType);
+    IF_CHANGED_SET_USING(ShowArrows, JRSUIControlSetShowArrows);
+
+    IF_CHANGED_SET_KEYED_BOOLEAN(Focused, focusedKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(IndicatorOnly, indicatorOnlyKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(NoIndicator, noIndicatorKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(ArrowsOnly, arrowsOnlyKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(FrameOnly, frameOnlyKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(SegmentTrailingSeparator, segmentTrailingSeparatorKey, get_boolean_value_for);
+    IF_KEY_EXISTS_DO(segmentLeadingSeparatorKey, IF_CHANGED_SET_KEYED_BOOLEAN(SegmentLeadingSeparator, segmentLeadingSeparatorKey, get_boolean_value_for));
+    IF_CHANGED_SET_KEYED_BOOLEAN(NothingToScroll, nothingToScrollKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(WindowTitleBarSeparator, windowFrameDrawTitleSeparatorKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(WindowClipCorners, windowFrameDrawClippedKey, get_boolean_value_for);
+    IF_CHANGED_SET_KEYED_BOOLEAN(BooleanValue, valueKey, get_boolean_number_value_for);
+
+    { // animation is special: keep setting while true
+        jlong value = (newProperties & MASK(Animating));
+        Boolean animating = value != 0L;
+        Boolean changed = ((oldProperties & MASK(Animating)) - value) != 0L;
+        if (animating || changed) {
+            JRSUIControlSetAnimating(control, animating);
+        }
+    }
+
+    return 0;
+}
+
+
+/*
+ * Class:     apple_laf_JRSUIConstants
+ * Method:    getPtrForConstant
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_apple_laf_JRSUIConstants_getPtrForConstant
+(JNIEnv *env, jclass clazz, jint constant){
+    return ptr_to_jlong(JRSUIGetKey(constant));
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/JRSUIController.m b/jdk/src/macosx/native/com/apple/laf/JRSUIController.m
new file mode 100644
index 0000000..c2128d8
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/JRSUIController.m
@@ -0,0 +1,299 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "apple_laf_JRSUIControl.h"
+#import "apple_laf_JRSUIConstants_DoubleValue.h"
+#import "apple_laf_JRSUIConstants_Hit.h"
+
+#import "JRSUIConstantSync.h"
+
+
+static JRSUIRendererRef gRenderer;
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    initNativeJRSUI
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_initNativeJRSUI
+(JNIEnv *env, jclass clazz)
+{
+    BOOL coherent = _InitializeJRSProperties();
+    if (!coherent) return apple_laf_JRSUIControl_INCOHERENT;
+
+    gRenderer = JRSUIRendererCreate();
+    if (gRenderer == NULL) return apple_laf_JRSUIControl_NULL_PTR;
+
+    return apple_laf_JRSUIControl_SUCCESS;
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    getPtrOfBuffer
+ * Signature: (Ljava/nio/ByteBuffer;)J
+ */
+JNIEXPORT jlong JNICALL Java_apple_laf_JRSUIControl_getPtrOfBuffer
+(JNIEnv *env, jclass clazz, jobject byteBuffer)
+{
+    char *byteBufferPtr = (*env)->GetDirectBufferAddress(env, byteBuffer);
+    if (byteBufferPtr == NULL) return 0L;
+    return ptr_to_jlong(byteBufferPtr); // GC
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    getCFDictionary
+ * Signature: (Z)J
+ */
+JNIEXPORT jlong JNICALL Java_apple_laf_JRSUIControl_getCFDictionary
+(JNIEnv *env, jclass clazz, jboolean isFlipped)
+{
+    return ptr_to_jlong(JRSUIControlCreate(isFlipped));
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    disposeCFDictionary
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_apple_laf_JRSUIControl_disposeCFDictionary
+(JNIEnv *env, jclass clazz, jlong controlPtr)
+{
+    void *ptr = jlong_to_ptr(controlPtr);
+    if (!ptr) return;
+    JRSUIControlRelease((JRSUIControlRef)ptr);
+}
+
+
+static inline void *getValueFor
+(jbyte code, UInt8 *changeBuffer, size_t *dataSizePtr)
+{
+    switch (code)
+    {
+        case apple_laf_JRSUIConstants_DoubleValue_TYPE_CODE:
+            *dataSizePtr = sizeof(jdouble);
+            jdouble doubleValue = (*(jdouble *)changeBuffer);
+            return (void *)CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &doubleValue);
+    }
+
+    return NULL;
+}
+
+static inline jint syncChangesToControl
+(JRSUIControlRef control, UInt8 *changeBuffer)
+{
+    UInt8 *endOfBuffer = changeBuffer + apple_laf_JRSUIControl_NIO_BUFFER_SIZE;
+
+    while (changeBuffer < endOfBuffer)
+    {
+        // dereference the pointer to the constant that was stored as a jlong in the byte buffer
+        CFStringRef key = (CFStringRef)jlong_to_ptr(*((jlong *)changeBuffer));
+        if (key == NULL) return apple_laf_JRSUIControl_SUCCESS;
+        changeBuffer += sizeof(jlong);
+
+        jbyte code = *((jbyte *)changeBuffer);
+        changeBuffer += sizeof(jbyte);
+
+        size_t dataSize;
+        void *value = (void *)getValueFor(code, changeBuffer, &dataSize);
+        if (value == NULL) {
+            NSLog(@"null pointer for %@ for value %d", key, (int)code);
+
+            return apple_laf_JRSUIControl_NULL_PTR;
+        }
+
+        changeBuffer += dataSize;
+        JRSUIControlSetValueByKey(control, key, value);
+        CFRelease(value);
+    }
+
+    return apple_laf_JRSUIControl_SUCCESS;
+}
+
+static inline jint doSyncChanges
+(JNIEnv *env, jlong controlPtr, jlong byteBufferPtr)
+{
+    JRSUIControlRef control = (JRSUIControlRef)jlong_to_ptr(controlPtr);
+    UInt8 *changeBuffer = (UInt8 *)jlong_to_ptr(byteBufferPtr);
+
+    return syncChangesToControl(control, changeBuffer);
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    syncChanges
+ * Signature: (JJ)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_syncChanges
+(JNIEnv *env, jclass clazz, jlong controlPtr, jlong byteBufferPtr)
+{
+    return doSyncChanges(env, controlPtr, byteBufferPtr);
+}
+
+static inline jint doPaintCGContext(CGContextRef cgRef, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h)
+{
+    JRSUIControlRef control = (JRSUIControlRef)jlong_to_ptr(controlPtr);
+    _SyncEncodedProperties(control, oldProperties, newProperties);
+    CGRect bounds = CGRectMake(x, y, w, h);
+    JRSUIControlDraw(gRenderer, control, cgRef, bounds);
+    return 0;
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    paintToCGContext
+ * Signature: (JJJJDDDD)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintToCGContext
+(JNIEnv *env, jclass clazz, jlong cgContextPtr, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h)
+{
+    return doPaintCGContext((CGContextRef)jlong_to_ptr(cgContextPtr), controlPtr, oldProperties, newProperties, x, y, w, h);
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    paintChangesToCGContext
+ * Signature: (JJJJDDDDJ)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintChangesToCGContext
+(JNIEnv *env, jclass clazz, jlong cgContextPtr, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h, jlong changes)
+{
+    int syncStatus = doSyncChanges(env, controlPtr, changes);
+    if (syncStatus != apple_laf_JRSUIControl_SUCCESS) return syncStatus;
+
+    return doPaintCGContext((CGContextRef)jlong_to_ptr(cgContextPtr), controlPtr, oldProperties, newProperties, x, y, w, h);
+}
+
+static inline jint doPaintImage
+(JNIEnv *env, jlong controlPtr, jlong oldProperties, jlong newProperties, jintArray data, jint imgW, jint imgH, jdouble x, jdouble y, jdouble w, jdouble h)
+{
+    jboolean isCopy = JNI_FALSE;
+    void *rawPixelData = (*env)->GetPrimitiveArrayCritical(env, data, &isCopy);
+    if (!rawPixelData) return apple_laf_JRSUIControl_NULL_PTR;
+
+    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
+    CGContextRef cgRef = CGBitmapContextCreate(rawPixelData, imgW, imgH, 8, imgW * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
+    CGColorSpaceRelease(colorspace);
+
+    jint status = doPaintCGContext(cgRef, controlPtr, oldProperties, newProperties, x, y, w, h);
+    CGContextRelease(cgRef);
+
+    (*env)->ReleasePrimitiveArrayCritical(env, data, rawPixelData, 0);
+
+    return status == noErr ? apple_laf_JRSUIControl_SUCCESS : status;
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    paintImage
+ * Signature: ([IIIJJJDDDD)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintImage
+(JNIEnv *env, jclass clazz, jintArray data, jint imgW, jint imgH, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h)
+{
+    return doPaintImage(env, controlPtr, oldProperties, newProperties, data, imgW, imgH, x, y, w, h);
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    paintChangesImage
+ * Signature: ([IIIJJJDDDDJ)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintChangesImage
+(JNIEnv *env, jclass clazz, jintArray data, jint imgW, jint imgH, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h, jlong changes)
+{
+    int syncStatus = doSyncChanges(env, controlPtr, changes);
+    if (syncStatus != apple_laf_JRSUIControl_SUCCESS) return syncStatus;
+
+    return doPaintImage(env, controlPtr, oldProperties, newProperties, data, imgW, imgH, x, y, w, h);
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    getNativeHitPart
+ * Signature: (JJJDDDDDD)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_getNativeHitPart
+(JNIEnv *env, jclass clazz, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h, jdouble pointX, jdouble pointY)
+{
+    JRSUIControlRef control = (JRSUIControlRef)jlong_to_ptr(controlPtr);
+    _SyncEncodedProperties(control, oldProperties, newProperties);
+
+    CGRect bounds = CGRectMake(x, y, w, h);
+    CGPoint point = CGPointMake(pointX, pointY);
+
+    return JRSUIControlGetHitPart(gRenderer, control, bounds, point);
+}
+
+/*
+ * Class:     apple_laf_JRSUIUtils_ScrollBar
+ * Method:    shouldUseScrollToClick
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_apple_laf_JRSUIUtils_00024ScrollBar_shouldUseScrollToClick
+(JNIEnv *env, jclass clazz)
+{
+    return JRSUIControlShouldScrollToClick();
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    getNativePartBounds
+ * Signature: ([DJJJDDDDI)V
+ */
+JNIEXPORT void JNICALL Java_apple_laf_JRSUIControl_getNativePartBounds
+(JNIEnv *env, jclass clazz, jdoubleArray rectArray, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h, jint part)
+{
+    JRSUIControlRef control = (JRSUIControlRef)jlong_to_ptr(controlPtr);
+    _SyncEncodedProperties(control, oldProperties, newProperties);
+
+    CGRect frame = CGRectMake(x, y, w, h);
+    CGRect partBounds = JRSUIControlGetScrollBarPartBounds(control, frame, part);
+
+    jdouble *rect = (*env)->GetPrimitiveArrayCritical(env, rectArray, NULL);
+    rect[0] = partBounds.origin.x;
+    rect[1] = partBounds.origin.y;
+    rect[2] = partBounds.size.width;
+    rect[3] = partBounds.size.height;
+    (*env)->ReleasePrimitiveArrayCritical(env, rectArray, rect, 0);
+}
+
+/*
+ * Class:     apple_laf_JRSUIControl
+ * Method:    getNativeScrollBarOffsetChange
+ * Signature: (JJJDDDDIII)D
+ */
+JNIEXPORT jdouble JNICALL Java_apple_laf_JRSUIControl_getNativeScrollBarOffsetChange
+(JNIEnv *env, jclass clazz, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h, jint offset, jint visibleAmount, jint extent)
+{
+    JRSUIControlRef control = (JRSUIControlRef)jlong_to_ptr(controlPtr);
+    _SyncEncodedProperties(control, oldProperties, newProperties);
+
+    CGRect frame = CGRectMake(x, y, w, h);
+    return (jdouble)JRSUIControlGetScrollBarOffsetFor(control, frame, offset, visibleAmount, extent);
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/JRSUIFocus.m b/jdk/src/macosx/native/com/apple/laf/JRSUIFocus.m
new file mode 100644
index 0000000..96cab1b
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/JRSUIFocus.m
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "apple_laf_JRSUIFocus.h"
+#import "apple_laf_JRSUIControl.h"
+
+#include <Carbon/Carbon.h>
+
+
+/*
+ * Class:     apple_laf_JRSUIFocus
+ * Method:    beginNativeFocus
+ * Signature: (JI)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIFocus_beginNativeFocus
+(JNIEnv *env, jclass clazz, jlong cgContext, jint ringStyle)
+{
+    if (cgContext == 0L) return apple_laf_JRSUIFocus_NULL_CG_REF;
+    CGContextRef cgRef = (CGContextRef)jlong_to_ptr(cgContext);
+
+    OSStatus status = HIThemeBeginFocus(cgRef, ringStyle, NULL);
+    return status == noErr ? apple_laf_JRSUIFocus_SUCCESS : status;
+}
+
+/*
+ * Class:     apple_laf_JRSUIFocus
+ * Method:    endNativeFocus
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_apple_laf_JRSUIFocus_endNativeFocus
+(JNIEnv *env, jclass clazz, jlong cgContext)
+{
+    if (cgContext == 0L) return apple_laf_JRSUIFocus_NULL_CG_REF;
+    CGContextRef cgRef = (CGContextRef)jlong_to_ptr(cgContext);
+
+    OSStatus status = HIThemeEndFocus(cgRef);
+    return status == noErr ? apple_laf_JRSUIFocus_SUCCESS : status;
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/ScreenMenu.h b/jdk/src/macosx/native/com/apple/laf/ScreenMenu.h
new file mode 100644
index 0000000..aa2cb39
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/ScreenMenu.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <Carbon/Carbon.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
diff --git a/jdk/src/macosx/native/com/apple/laf/ScreenMenu.m b/jdk/src/macosx/native/com/apple/laf/ScreenMenu.m
new file mode 100644
index 0000000..8dab11c
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/ScreenMenu.m
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "ScreenMenu.h"
+
+#import "com_apple_laf_ScreenMenu.h"
+#import "java_awt_Event.h"
+#import "java_awt_event_KeyEvent.h"
+#import "java_awt_event_InputEvent.h"
+#import "java_awt_event_MouseEvent.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "ThreadUtilities.h"
+#import "CMenuBar.h"
+
+
+static JNF_CLASS_CACHE(sjc_ScreenMenu, "com/apple/laf/ScreenMenu");
+
+static jint ns2awtModifiers(NSUInteger keyMods) {
+    jint result = 0;
+    if (keyMods & NSShiftKeyMask)        result |= java_awt_Event_SHIFT_MASK;
+    if (keyMods & NSControlKeyMask)        result |= java_awt_Event_CTRL_MASK;
+    if (keyMods & NSAlternateKeyMask)    result |= java_awt_Event_ALT_MASK;
+    if (keyMods & NSCommandKeyMask)        result |= java_awt_Event_META_MASK;
+    return result;
+}
+
+static jint ns2awtMouseButton(NSInteger mouseButton) {
+    switch (mouseButton) {
+        case 1: return java_awt_event_InputEvent_BUTTON1_MASK;
+        case 2: return java_awt_event_InputEvent_BUTTON2_MASK;
+        case 3: return java_awt_event_InputEvent_BUTTON3_MASK;
+    }
+    return 0;
+}
+
+
+@interface NativeToJavaDelegate : NSObject <JRSMenuDelegate, NSMenuDelegate>
+{
+@public
+    NSMenu *nsmenu;
+    JNFJObjectWrapper *javaObjectWrapper;
+}
+
+@property (nonatomic, retain) NSMenu *nsmenu;
+@property (nonatomic, retain) JNFJObjectWrapper *javaObjectWrapper;
+
+- (id)initFromMenu:(NSMenu *)menu javaObj:(JNFJObjectWrapper *)obj;
+- (NSMenu*)menu;
+@end
+
+
+@implementation NativeToJavaDelegate
+
+@synthesize nsmenu;
+@synthesize javaObjectWrapper;
+
+- (id)initFromMenu:(NSMenu *)aMenu javaObj:(JNFJObjectWrapper *)obj
+{
+    self = [super init];
+    if (self) {
+        self.nsmenu = aMenu;
+        self.javaObjectWrapper = obj;
+    }
+    return self;
+}
+
+- (NSMenu *)menu {
+    return self.nsmenu;
+}
+
+- (void)menuWillOpen:(NSMenu *)menu
+{
+    if (self.javaObjectWrapper == nil) {
+#ifdef DEBUG
+        NSLog(@"_javaObject is NULL: (%s - %s : %d)", __FILE__, __FUNCTION__, __LINE__);
+#endif
+        return;
+    }
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+JNF_COCOA_ENTER(env);
+    //NSLog(@"menuWillOpen %@", [menu title]);
+    static JNF_MEMBER_CACHE(jm_ScreenMenu_invokeOpenLater, sjc_ScreenMenu, "invokeOpenLater", "()V");
+    JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_invokeOpenLater); // AWT_THREADING Safe (AWTRunLoopMode)
+JNF_COCOA_EXIT(env);
+
+}
+
+- (void)menuDidClose:(NSMenu *)menu
+{
+    if (self.javaObjectWrapper == nil) {
+#ifdef DEBUG
+        NSLog(@"_javaObject is NULL: (%s - %s : %d)", __FILE__, __FUNCTION__, __LINE__);
+#endif
+        return;
+    }
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+JNF_COCOA_ENTER(env);
+    //NSLog(@"menuDidClose %@", [menu title]);
+    static JNF_MEMBER_CACHE(jm_ScreenMenu_invokeMenuClosing, sjc_ScreenMenu, "invokeMenuClosing", "()V");
+    JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_invokeMenuClosing); // AWT_THREADING Safe (AWTRunLoopMode)
+JNF_COCOA_EXIT(env);
+}
+
+
+- (void)handleJavaMenuItemTargetedAtIndex:(NSUInteger)menuIndex rect:(NSRect)rect
+{
+    if (self.javaObjectWrapper == nil) {
+#ifdef DEBUG
+        NSLog(@"_javaObject is NULL: (%s - %s : %d)", __FILE__, __FUNCTION__, __LINE__);
+#endif
+        return;
+    }
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+JNF_COCOA_ENTER(env);
+    // Send that to Java so we can test which item was hit.
+    static JNF_MEMBER_CACHE(jm_ScreenMenu_updateSelectedItem, sjc_ScreenMenu, "handleItemTargeted", "(IIIII)V");
+    JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_updateSelectedItem, menuIndex,
+                    NSMinY(rect), NSMinX(rect), NSMaxY(rect), NSMaxX(rect)); // AWT_THREADING Safe (AWTRunLoopMode)
+
+JNF_COCOA_EXIT(env);
+}
+
+
+// Called from event handler callback
+- (void)handleJavaMouseEvent:(NSEvent *)event
+{
+    NSInteger kind = [event type];
+    jint javaKind = 0;
+
+    switch (kind) {
+        case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
+            javaKind = java_awt_event_MouseEvent_MOUSE_RELEASED;
+            break;
+        case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
+            javaKind = java_awt_event_MouseEvent_MOUSE_PRESSED;
+            break;
+        case NSMouseMoved:
+            javaKind = java_awt_event_MouseEvent_MOUSE_MOVED;
+            break;
+        case NSLeftMouseDragged: case NSRightMouseDragged: case NSOtherMouseDragged:
+            javaKind = java_awt_event_MouseEvent_MOUSE_DRAGGED;
+            break;
+    }
+
+    // Get the coordinates of the mouse in global coordinates (must be global, since our tracking rects are global.)
+    NSPoint globalPoint = [event locationInWindow];
+    jint javaX = globalPoint.x;
+    jint javaY = globalPoint.y;
+
+    // Convert the event modifiers into Java modifiers
+    jint javaModifiers = ns2awtModifiers([event modifierFlags]) | ns2awtMouseButton([event buttonNumber]);
+
+    // Get the event time
+    jlong javaWhen = JNFNSTimeIntervalToJavaMillis([event timestamp]);
+
+    // Call the mouse event handler, which will generate Java mouse events.
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+JNF_COCOA_ENTER(env);
+    static JNF_MEMBER_CACHE(jm_ScreenMenu_handleMouseEvent, sjc_ScreenMenu, "handleMouseEvent", "(IIIIJ)V");
+    JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_handleMouseEvent, javaKind, javaX, javaY, javaModifiers, javaWhen); // AWT_THREADING Safe (AWTRunLoopMode)
+JNF_COCOA_EXIT(env);
+}
+
+@end
+
+
+/*
+ * Class:     com_apple_laf_ScreenMenu
+ * Method:    addMenuListeners
+ * Signature: (Lcom/apple/laf/ScreenMenu;J[J)V
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_laf_ScreenMenu_addMenuListeners
+(JNIEnv *env, jclass clz, jobject listener, jlong nativeMenu)
+{
+    NativeToJavaDelegate *delegate = nil;
+
+JNF_COCOA_ENTER(env);
+
+    JNFJObjectWrapper *wrapper = [JNFJObjectWrapper wrapperWithJObject:listener withEnv:env];
+    NSMenu *menu = jlong_to_ptr(nativeMenu);
+
+    delegate = [[[NativeToJavaDelegate alloc] initFromMenu:menu javaObj:wrapper] autorelease];
+    CFRetain(delegate); // GC
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{
+        NSMenu *menu = delegate.nsmenu;
+        if ([menu isJavaMenu]) {
+            [menu setDelegate:delegate];
+            [menu setJavaMenuDelegate:delegate];
+        }
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(delegate);
+}
+
+/*
+ * Class:     com_apple_laf_ScreenMenu
+ * Method:    removeMenuListeners
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_laf_ScreenMenu_removeMenuListeners
+(JNIEnv *env, jclass clz, jlong fModelPtr)
+{
+    if (fModelPtr == 0L) return;
+
+JNF_COCOA_ENTER(env);
+
+    NativeToJavaDelegate *delegate = (NativeToJavaDelegate *)jlong_to_ptr(fModelPtr);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{
+        NSMenu *menu = delegate.nsmenu;
+        [menu setJavaMenuDelegate:nil];
+        [menu setDelegate:nil];
+        delegate.nsmenu = nil;
+        delegate.javaObjectWrapper = nil;
+    }];
+
+    CFRelease(delegate); // GC
+
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/com/apple/laf/ScreenPopupFactory.m b/jdk/src/macosx/native/com/apple/laf/ScreenPopupFactory.m
new file mode 100644
index 0000000..53cc5c3
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/laf/ScreenPopupFactory.m
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "com_apple_laf_ScreenPopupFactory.h"
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+static JNF_CLASS_CACHE(sjc_PopupFactory, "javax/swing/PopupFactory");
+static JNF_MEMBER_CACHE(jm_getPopup, sjc_PopupFactory, "getPopup", "(Ljava/awt/Component;Ljava/awt/Component;III)Ljavax/swing/Popup;");
+
+/*
+ * Class:     com_apple_laf_ScreenPopupFactory
+ * Method:    _getHeavyWeightPopup
+ * Signature: (Ljava/awt/Component;Ljava/awt/Component;II)Ljavax/swing/Popup;
+ */
+JNIEXPORT jobject /* javax.swing.Popup */ JNICALL Java_com_apple_laf_ScreenPopupFactory__1getHeavyWeightPopup
+(JNIEnv *env, jobject screenPopupFactory, jobject comp, jobject invoker, jint x, jint y) {
+    jobject popup;
+JNF_COCOA_ENTER(env);
+    popup = JNFCallObjectMethod(env, screenPopupFactory, jm_getPopup, comp, invoker, x, y, 2);
+JNF_COCOA_EXIT(env);
+    return popup;
+}
diff --git a/jdk/src/macosx/native/com/apple/resources/MacOSXResourceBundle.m b/jdk/src/macosx/native/com/apple/resources/MacOSXResourceBundle.m
new file mode 100644
index 0000000..783d747
--- /dev/null
+++ b/jdk/src/macosx/native/com/apple/resources/MacOSXResourceBundle.m
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <dlfcn.h>
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#ifndef MAXPATHLEN
+#define MAXPATHLEN PATH_MAX
+#endif
+
+static jboolean
+GetPathFromCurrentBinary(char *buf, jint bufsize)
+{
+    Dl_info dlinfo;
+    dladdr((void *)GetPathFromCurrentBinary, &dlinfo);
+    if (realpath(dlinfo.dli_fname, buf) == NULL) {
+//      fprintf(stderr, "Error: realpath(`%s') failed.\n", dlinfo.dli_fname);
+        return JNI_FALSE;
+    }
+
+    const char *libawt = "lib/libawt.dylib";
+    int strLen, libawtLen;
+
+    strLen = strlen(buf);
+    libawtLen = strlen(libawt);
+
+    if (strLen < libawtLen ||
+        strcmp(buf + strLen - libawtLen, libawt) != 0) {
+        return JNI_FALSE;
+    }
+
+    buf[strLen - libawtLen] = '\0';
+
+    return JNI_TRUE;
+}
+
+#define JAVA_DLL "libjava.dylib"
+
+static jboolean
+GetJREPath(char *buf, jint bufsize)
+{
+    /* try to get the path from the current binary, if not, bail to the framework */
+    if (GetPathFromCurrentBinary(buf, bufsize) == JNI_TRUE) {
+        /* does the rest of the JRE exist? */
+        char libjava[MAXPATHLEN];
+        snprintf(libjava, MAXPATHLEN, "%s/lib/" JAVA_DLL, buf);
+        if (access(libjava, F_OK) == 0) {
+            return JNI_TRUE;
+        }
+    }
+
+    return JNI_FALSE;
+}
+
+static NSString *getRunningJavaBundle()
+{
+    char path[MAXPATHLEN];
+    GetJREPath(path, MAXPATHLEN);
+    return [[NSString alloc] initWithFormat:@"%@/bundle", [NSString stringWithUTF8String:path]];
+}
+
+/*
+ * Class:     com_apple_resources_LoadNativeBundleAction
+ * Method:    getPathToBundleFile
+ * Signature: (Ljava/lang/String)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_com_apple_resources_LoadNativeBundleAction_getPathToBundleFile
+    (JNIEnv *env, jclass klass, jstring filename)
+{
+    jstring returnVal = NULL;
+    if (filename == NULL) {
+        return NULL;
+    }
+
+JNF_COCOA_ENTER(env);
+    NSBundle *javaBundle = [NSBundle bundleWithPath:getRunningJavaBundle()];
+    NSString *baseFilename = JNFJavaToNSString(env, filename);
+    NSString *propertyFilePath = [javaBundle pathForResource:baseFilename ofType:@"properties"];
+
+    if (propertyFilePath != nil) {
+        returnVal = JNFNSToJavaString(env, propertyFilePath);
+    }
+JNF_COCOA_EXIT(env);
+
+    return returnVal;
+}
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiIn.c b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiIn.c
new file mode 100644
index 0000000..a09f6ae
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiIn.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_ERROR
+//#define USE_TRACE
+
+#if USE_PLATFORM_MIDI_IN == TRUE
+
+#include "PLATFORM_API_MacOSX_MidiUtils.h"
+
+char* MIDI_IN_GetErrorStr(INT32 err) {
+    return (char *) MIDI_Utils_GetErrorMsg((int) err);
+}
+
+
+INT32 MIDI_IN_GetNumDevices() {
+    return MIDI_Utils_GetNumDevices(MIDI_IN);
+}
+
+
+INT32 MIDI_IN_GetDeviceName(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceName(MIDI_IN, deviceID, name, nameLength);
+}
+
+
+INT32 MIDI_IN_GetDeviceVendor(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceVendor(MIDI_IN, deviceID, name, nameLength);
+}
+
+
+INT32 MIDI_IN_GetDeviceDescription(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceDescription(MIDI_IN, deviceID, name, nameLength);
+}
+
+
+INT32 MIDI_IN_GetDeviceVersion(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceVersion(MIDI_IN, deviceID, name, nameLength);
+}
+
+
+INT32 MIDI_IN_OpenDevice(INT32 deviceID, MidiDeviceHandle** handle) {
+    TRACE0("MIDI_IN_OpenDevice\n");
+    return
+        MIDI_Utils_OpenDevice(MIDI_IN, deviceID, (MacMidiDeviceHandle**) handle,
+                              MIDI_IN_MESSAGE_QUEUE_SIZE,
+                              MIDI_IN_LONG_QUEUE_SIZE,
+                              MIDI_IN_LONG_MESSAGE_SIZE);
+}
+
+
+INT32 MIDI_IN_CloseDevice(MidiDeviceHandle* handle) {
+    TRACE0("MIDI_IN_CloseDevice\n");
+    return MIDI_Utils_CloseDevice((MacMidiDeviceHandle*) handle);
+}
+
+
+INT32 MIDI_IN_StartDevice(MidiDeviceHandle* handle) {
+    TRACE0("MIDI_IN_StartDevice\n");
+    return MIDI_Utils_StartDevice((MacMidiDeviceHandle*) handle);
+}
+
+
+INT32 MIDI_IN_StopDevice(MidiDeviceHandle* handle) {
+    TRACE0("MIDI_IN_StopDevice\n");
+    return MIDI_Utils_StopDevice((MacMidiDeviceHandle*) handle);
+}
+
+INT64 MIDI_IN_GetTimeStamp(MidiDeviceHandle* handle) {
+    return MIDI_Utils_GetTimeStamp((MacMidiDeviceHandle*) handle);
+}
+
+
+/* read the next message from the queue */
+MidiMessage* MIDI_IN_GetMessage(MidiDeviceHandle* handle) {
+    if (handle == NULL) {
+        return NULL;
+    }
+    while (handle->queue != NULL && handle->platformData != NULL) {
+        MidiMessage* msg = MIDI_QueueRead(handle->queue);
+        if (msg != NULL) {
+            //fprintf(stdout, "GetMessage returns index %d\n", msg->data.l.index); fflush(stdout);
+            return msg;
+        }
+        TRACE0("MIDI_IN_GetMessage: before waiting\n");
+        handle->isWaiting = TRUE;
+        MIDI_WaitOnConditionVariable(handle->platformData, handle->queue->lock);
+        handle->isWaiting = FALSE;
+        TRACE0("MIDI_IN_GetMessage: waiting finished\n");
+    }
+    return NULL;
+}
+
+
+void MIDI_IN_ReleaseMessage(MidiDeviceHandle* handle, MidiMessage* msg) {
+    if (handle == NULL || handle->queue == NULL) {
+        return;
+    }
+    MIDI_QueueRemove(handle->queue, TRUE /*onlyLocked*/);
+}
+
+#endif /* USE_PLATFORM_MIDI_IN */
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiOut.c b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiOut.c
new file mode 100644
index 0000000..e981415
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiOut.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_ERROR
+//#define USE_TRACE
+
+#if USE_PLATFORM_MIDI_OUT == TRUE
+
+#include "PLATFORM_API_MacOSX_MidiUtils.h"
+
+char* MIDI_OUT_GetErrorStr(INT32 err) {
+    return (char *) MIDI_Utils_GetErrorMsg((int) err);
+}
+
+
+INT32 MIDI_OUT_GetNumDevices() {
+    return MIDI_Utils_GetNumDevices(MIDI_OUT);
+}
+
+
+INT32 MIDI_OUT_GetDeviceName(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceName(MIDI_OUT, deviceID, name, nameLength);
+}
+
+
+INT32 MIDI_OUT_GetDeviceVendor(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceVendor(MIDI_OUT, deviceID, name, nameLength);
+}
+
+
+INT32 MIDI_OUT_GetDeviceDescription(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceDescription(MIDI_OUT, deviceID, name, nameLength);
+}
+
+
+INT32 MIDI_OUT_GetDeviceVersion(INT32 deviceID, char *name, UINT32 nameLength) {
+    return MIDI_Utils_GetDeviceVersion(MIDI_OUT, deviceID, name, nameLength);
+}
+
+
+/* *************************** MidiOutDevice implementation ***************************************** */
+
+INT32 MIDI_OUT_OpenDevice(INT32 deviceID, MidiDeviceHandle** handle) {
+    TRACE1("MIDI_OUT_OpenDevice: deviceID: %d\n", (int) deviceID);
+    /* queue sizes are ignored for MIDI_OUT only (uses STREAMS) */
+    return MIDI_Utils_OpenDevice(MIDI_OUT, deviceID, (MacMidiDeviceHandle**) handle, 0, 0, 0);
+}
+
+INT32 MIDI_OUT_CloseDevice(MidiDeviceHandle* handle) {
+    TRACE0("MIDI_OUT_CloseDevice\n");
+
+    // issue a "SUSTAIN OFF" message to each MIDI channel, 0 to 15.
+    // "CONTROL CHANGE" is 176, "SUSTAIN CONTROLLER" is 64, and the value is 0.
+    // $$fb 2002-04-04: It is responsability of the application developer to
+    // leave the device in a consistent state. So I put this in comments
+    /*
+      for (channel = 0; channel < 16; channel++)
+      MIDI_OUT_SendShortMessage(deviceHandle, (unsigned char)(176 + channel),
+      (unsigned char)64, (unsigned char)0, (UINT32)-1);
+    */
+    return MIDI_Utils_CloseDevice((MacMidiDeviceHandle*) handle);
+}
+
+
+INT64 MIDI_OUT_GetTimeStamp(MidiDeviceHandle* handle) {
+    return MIDI_Utils_GetTimeStamp((MacMidiDeviceHandle*) handle);
+}
+
+
+INT32 MIDI_OUT_SendShortMessage(MidiDeviceHandle* handle, UINT32 packedMsg, UINT32 timestamp) {
+    OSStatus err = noErr;
+
+    TRACE2("> MIDI_OUT_SendShortMessage %x, time: %d\n", (uint) packedMsg, (int) timestamp);
+    if (!handle) {
+        ERROR0("< ERROR: MIDI_OUT_SendShortMessage: handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+
+    MacMidiDeviceHandle* macHandle = (MacMidiDeviceHandle*) handle;
+    UInt8 mBuffers[100];
+    MIDIPacketList* packetList = (MIDIPacketList*) mBuffers;
+    MIDIPacket* packet;
+    UINT32 nData;
+    Byte data[3] = {packedMsg & 0xFF, (packedMsg >> 8) & 0xFF, (packedMsg >> 16) & 0xFF};
+    bool byteIsInvalid = FALSE;
+
+    packet = MIDIPacketListInit(packetList);
+    switch (data[0] & 0xF0) {
+        case 0x80:    // Note off
+        case 0x90:    // Note on
+        case 0xA0:    // Aftertouch
+        case 0xB0:    // Controller
+        case 0xE0:    // Pitch wheel
+            nData = 3;
+            break;
+
+        case 0xC0:    // Program change
+        case 0xD0:    // Channel pressure
+            nData = 2;
+            break;
+
+        case 0xF0: {
+            // System common message
+            switch (data[0]) {
+                case 0xF0:
+                case 0xF7:
+                    // System exclusive
+                    fprintf(stderr, "%s: %d->internal error: sysex message status=0x%X while sending short message\n",
+                            __FILE__, __LINE__, data[0]);
+                    byteIsInvalid = TRUE;
+                    break;
+
+                case 0xF1:    // MTC quarter frame message
+                    //fprintf(stderr, ">>>MIDI_OUT_SendShortMessage: MTC quarter frame message....\n");
+                    nData = 2;
+                    break;
+                case 0xF3:    // Song select
+                    //fprintf(stderr, ">>>MIDI_OUT_SendShortMessage: Song select....\n");
+                    nData = 2;
+                    break;
+
+                case 0xF2:    // Song position pointer
+                    //fprintf(stderr, ">>>MIDI_OUT_SendShortMessage: Song position pointer....\n");
+                    nData = 3;
+                    break;
+
+                case 0xF6:    // Tune request
+                    //fprintf(stderr, ">>>MIDI_OUT_SendShortMessage: Tune request....\n");
+                    nData = 1;
+                    break;
+
+                default:
+                    // Invalid message
+                    fprintf(stderr, "%s: %d->Invalid message: message status=0x%X while sending short message\n",
+                            __FILE__, __LINE__, data[0]);
+                    byteIsInvalid = TRUE;
+                    break;
+            }
+            break;
+        }
+
+        default:
+            // This can't happen, but handle it anyway.
+            fprintf(stderr, "%s: %d->Invalid message: message status=0x%X while sending short message\n",
+                    __FILE__, __LINE__, data[0]);
+            byteIsInvalid = TRUE;
+            break;
+    }
+
+    if (byteIsInvalid) return -1;
+
+    MIDIPacketListAdd(packetList, sizeof(mBuffers), packet, 0, nData, data);
+    err = MIDISend(macHandle->port, (MIDIEndpointRef) (intptr_t) handle->deviceHandle, packetList);
+
+    MIDI_CHECK_ERROR;
+    TRACE0("< MIDI_OUT_SendShortMessage\n");
+    return (err == noErr ? MIDI_SUCCESS : -1);
+}
+
+
+INT32 MIDI_OUT_SendLongMessage(MidiDeviceHandle* handle, UBYTE* data, UINT32 size, UINT32 timestamp) {
+    OSStatus err = noErr;
+
+    TRACE2("> MIDI_OUT_SendLongMessage size %d, time: %d\n", (int) size, (int) timestamp);
+    if (!handle || !data) {
+        ERROR0("< ERROR: MIDI_OUT_SendLongMessage: handle, or data is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    if (size == 0) {
+        return MIDI_SUCCESS;
+    }
+
+    MacMidiDeviceHandle* macHandle = (MacMidiDeviceHandle*) handle;
+    UInt8 mBuffers[8196];
+    MIDIPacketList* packetList = (MIDIPacketList*) mBuffers;
+    MIDIPacket* packet = NULL;
+    UINT32 remaining = size;
+    UINT32 increment = 512;
+    UINT32 nData;
+
+    handle->isWaiting = TRUE;
+
+    while (remaining > 0) {
+
+        if (packet == NULL) {
+            packet = MIDIPacketListInit(packetList);
+        }
+
+        if (remaining > increment) {
+            nData = increment;
+        } else {
+            nData = remaining;
+        }
+
+        // Copies the bytes to our current packet.
+        if ((packet = MIDIPacketListAdd(packetList, sizeof(mBuffers), packet, 0, nData, (const Byte*) data)) == NULL) {
+            // Packet list is full, send it.
+            err = MIDISend(macHandle->port, (MIDIEndpointRef) (intptr_t) handle->deviceHandle, packetList);
+            if (err != noErr) {
+                break;
+            }
+        } else {
+            // Moves the data pointer to the next segment.
+            data += nData;
+            remaining -= nData;
+            packet = MIDIPacketNext(packet);
+        }
+    }
+
+    MIDI_CHECK_ERROR;
+    handle->isWaiting = FALSE;
+    TRACE0("< MIDI_OUT_SendLongMessage\n");
+    return (err == noErr ? MIDI_SUCCESS : -1);
+}
+
+#endif /* USE_PLATFORM_MIDI_OUT */
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiUtils.c b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiUtils.c
new file mode 100644
index 0000000..b044dac
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiUtils.c
@@ -0,0 +1,702 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+**
+**    Overview:
+**      Implementation of the functions used for both MIDI in and MIDI out.
+**
+**      Java package com.sun.media.sound defines the AbstractMidiDevice class
+**      which encapsulates functionalities shared by both MidiInDevice and
+**      MidiOutDevice classes in the same package.
+**
+**      The Java layer classes MidiInDevice and MidiOutDevice in turn map to
+**      the MIDIEndpointRef data type in the CoreMIDI framework, which
+**      represents a source or destination for a standard 16-channel MIDI data
+**      stream.
+*/
+/*****************************************************************************/
+
+//#define USE_ERROR
+//#define USE_TRACE
+
+#if (USE_PLATFORM_MIDI_IN == TRUE) || (USE_PLATFORM_MIDI_OUT == TRUE)
+
+#include "PLATFORM_API_MacOSX_MidiUtils.h"
+#include <pthread.h>
+#include <assert.h>
+
+// Constant character string definitions of CoreMIDI's corresponding error codes.
+
+static const char* strMIDIInvalidClient =
+                        "An invalid MIDIClientRef was passed.";
+static const char* strMIDIInvalidPort =
+                        "An invalid MIDIPortRef was passed.";
+static const char* strMIDIWrongEndpointType =
+                        "A source endpoint was passed to a function expecting a destination, or vice versa.";
+static const char* strMIDINoConnection =
+                        "Attempt to close a non-existant connection.";
+static const char* strMIDIUnknownEndpoint =
+                        "An invalid MIDIEndpointRef was passed.";
+static const char* strMIDIUnknownProperty =
+                        "Attempt to query a property not set on the object.";
+static const char* strMIDIWrongPropertyType =
+                        "Attempt to set a property with a value not of the correct type.";
+static const char* strMIDINoCurrentSetup =
+                        "Internal error; there is no current MIDI setup object.";
+static const char* strMIDIMessageSendErr =
+                        "Communication with MIDIServer failed.";
+static const char* strMIDIServerStartErr =
+                        "Unable to start MIDIServer.";
+static const char* strMIDISetupFormatErr =
+                        "Unable to read the saved state.";
+static const char* strMIDIWrongThread =
+                        "A driver is calling a non-I/O function in the server from a thread other than"
+                        "the server's main thread.";
+static const char* strMIDIObjectNotFound =
+                        "The requested object does not exist.";
+static const char* strMIDIIDNotUnique =
+                        "Attempt to set a non-unique kMIDIPropertyUniqueID on an object.";
+
+static const char* midi_strerror(int err) {
+/*
+    @enum           Error Constants
+    @abstract       The error constants unique to Core MIDI.
+    @discussion     These are the error constants that are unique to Core MIDI. Note that Core MIDI
+                    functions may return other codes that are not listed here.
+*/
+    const char* strerr;
+
+    switch (err) {
+    case kMIDIInvalidClient:
+        strerr = strMIDIInvalidClient;
+        break;
+    case kMIDIInvalidPort:
+        strerr = strMIDIInvalidPort;
+        break;
+    case kMIDIWrongEndpointType:
+        strerr = strMIDIWrongEndpointType;
+        break;
+    case kMIDINoConnection:
+        strerr = strMIDINoConnection;
+        break;
+    case kMIDIUnknownEndpoint:
+        strerr = strMIDIUnknownEndpoint;
+        break;
+    case kMIDIUnknownProperty:
+        strerr = strMIDIUnknownProperty;
+        break;
+    case kMIDIWrongPropertyType:
+        strerr = strMIDIWrongPropertyType;
+        break;
+    case kMIDINoCurrentSetup:
+        strerr = strMIDINoCurrentSetup;
+        break;
+    case kMIDIMessageSendErr:
+        strerr = strMIDIMessageSendErr;
+        break;
+    case kMIDIServerStartErr:
+        strerr = strMIDIServerStartErr;
+        break;
+    case kMIDISetupFormatErr:
+        strerr = strMIDISetupFormatErr;
+        break;
+    case kMIDIWrongThread:
+        strerr = strMIDIWrongThread;
+        break;
+    case kMIDIObjectNotFound:
+        strerr = strMIDIObjectNotFound;
+        break;
+    case kMIDIIDNotUnique:
+        strerr = strMIDIIDNotUnique;
+        break;
+    default:
+        strerr = "Unknown error.";
+        break;
+    }
+    return strerr;
+}
+
+const char* MIDI_Utils_GetErrorMsg(int err) {
+    return midi_strerror(err);
+}
+
+
+void MIDI_Utils_PrintError(int err) {
+#ifdef USE_ERROR
+    const char* s = MIDI_Utils_GetErrorMsg(err);
+    if (s != NULL) {
+        fprintf(stderr, "%s\n", s);
+    }
+#endif
+}
+
+
+// Note direction is either MIDI_IN or MIDI_OUT.
+INT32 MIDI_Utils_GetNumDevices(int direction) {
+    int num_endpoints;
+    if (direction == MIDI_IN) {
+        num_endpoints = MIDIGetNumberOfSources();
+    //fprintf(stdout, "MIDIGetNumberOfSources() returns %d\n", num_endpoints);
+    } else if (direction == MIDI_OUT) {
+        num_endpoints = MIDIGetNumberOfDestinations();
+        //printf(stdout, "MIDIGetNumberOfDestinations() returns %d\n", num_endpoints);
+    } else {
+        assert((direction == MIDI_IN || direction == MIDI_OUT));
+        num_endpoints = 0;
+    }
+    return (INT32) num_endpoints;
+}
+
+// Wraps calls to CFStringGetCStringPtr and CFStringGetCString to make sure
+// we extract the c characters into the buffer and null-terminate it.
+static void CFStringExtractCString(CFStringRef cfs, char* buffer, UINT32 bufferSize, CFStringEncoding encoding) {
+    const char* ptr = CFStringGetCStringPtr(cfs, encoding);
+    if (ptr) {
+        strlcpy(buffer, ptr, bufferSize);
+    } else {
+        if (! CFStringGetCString(cfs, buffer, bufferSize, encoding)) {
+            // There's an error in conversion, make sure we null-terminate the buffer.
+            buffer[bufferSize - 1] = '\0';
+        }
+    }
+}
+
+//
+// @see com.sun.media.sound.AbstractMidiDeviceProvider.getDeviceInfo().
+static int getEndpointProperty(int direction, INT32 deviceID, char *buffer, int bufferLength, CFStringRef propertyID) {
+
+    if (deviceID < 0) {
+        return MIDI_INVALID_DEVICEID;
+    }
+
+    MIDIEndpointRef endpoint;
+
+    if (direction == MIDI_IN) {
+        endpoint = MIDIGetSource(deviceID);
+    } else if (direction == MIDI_OUT) {
+        endpoint = MIDIGetDestination(deviceID);
+    } else {
+        return MIDI_INVALID_ARGUMENT;
+    }
+
+    if (!endpoint) {
+        return MIDI_INVALID_DEVICEID;
+    }
+
+    int status = MIDI_SUCCESS;
+    if (propertyID == kMIDIPropertyDriverVersion) {
+        SInt32 driverVersion;
+        status = MIDIObjectGetIntegerProperty(endpoint, kMIDIPropertyDriverVersion, &driverVersion);
+        if (status != MIDI_SUCCESS) return status;
+        snprintf(buffer,
+                 bufferLength,
+                 "%d",
+                 (int) driverVersion);
+    }
+    else {
+        CFStringRef pname;
+        status = MIDIObjectGetStringProperty(endpoint, propertyID, &pname);
+        if (status != MIDI_SUCCESS) return status;
+        CFStringExtractCString(pname, buffer, bufferLength, 0);
+    }
+    return MIDI_ERROR_NONE;
+}
+
+// A simple utility which encapsulates CoreAudio's HostTime APIs.
+// It returns the current host time in nanoseconds which when subtracted from
+// a previous getCurrentTimeInNanos() result produces the delta in nanos.
+static UInt64 getCurrentTimeInNanos() {
+    UInt64 hostTime = AudioGetCurrentHostTime();
+    UInt64 nanos = AudioConvertHostTimeToNanos(hostTime);
+    return nanos;
+}
+
+
+INT32 MIDI_Utils_GetDeviceName(int direction, INT32 deviceID, char *name, UINT32 bufferLength) {
+    return getEndpointProperty(direction, deviceID, name, bufferLength, kMIDIPropertyName);
+}
+
+
+INT32 MIDI_Utils_GetDeviceVendor(int direction, INT32 deviceID, char *name, UINT32 bufferLength) {
+    return getEndpointProperty(direction, deviceID, name, bufferLength, kMIDIPropertyManufacturer);
+}
+
+
+INT32 MIDI_Utils_GetDeviceDescription(int direction, INT32 deviceID, char *name, UINT32 bufferLength) {
+    return getEndpointProperty(direction, deviceID, name, bufferLength, kMIDIPropertyDisplayName);
+}
+
+
+INT32 MIDI_Utils_GetDeviceVersion(int direction, INT32 deviceID, char *name, UINT32 bufferLength) {
+    return getEndpointProperty(direction, deviceID, name, bufferLength, kMIDIPropertyDriverVersion);
+}
+
+
+static MIDIClientRef client = (MIDIClientRef) NULL;
+static MIDIPortRef inPort = (MIDIPortRef) NULL;
+static MIDIPortRef outPort = (MIDIPortRef) NULL;
+
+// Each MIDIPacket can contain more than one midi messages.
+// This function processes the packet and adds the messages to the specified message queue.
+// @see also src/share/native/com/sun/media/sound/PlatformMidi.h.
+static void processMessagesForPacket(const MIDIPacket* packet, MacMidiDeviceHandle* handle) {
+    const UInt8* data;
+    UInt16 length;
+    UInt8 byte;
+    UInt8 pendingMessageStatus;
+    UInt8 pendingData[2];
+    UInt16 pendingDataIndex, pendingDataLength;
+    UINT32 packedMsg;
+    MIDITimeStamp ts = packet->timeStamp;
+
+    pendingMessageStatus = 0;
+    pendingDataIndex = pendingDataLength = 0;
+
+    data = packet->data;
+    length = packet->length;
+    while (length--) {
+        bool byteIsInvalid = FALSE;
+
+        byte = *data++;
+        packedMsg = byte;
+
+        if (byte >= 0xF8) {
+            // Each RealTime Category message (ie, Status of 0xF8 to 0xFF) consists of only 1 byte, the Status.
+            // Except that 0xFD is an invalid status code.
+            //
+            // 0xF8 -> Midi clock
+            // 0xF9 -> Midi tick
+            // 0xFA -> Midi start
+            // 0xFB -> Midi continue
+            // 0xFC -> Midi stop
+            // 0xFE -> Active sense
+            // 0xFF -> Reset
+            if (byte == 0xFD) {
+                byteIsInvalid = TRUE;
+            } else {
+                pendingDataLength = 0;
+            }
+        } else {
+            if (byte < 0x80) {
+                // Not a status byte -- check our history.
+                if (handle->readingSysExData) {
+                    CFDataAppendBytes(handle->readingSysExData, &byte, 1);
+
+                } else if (pendingDataIndex < pendingDataLength) {
+                    pendingData[pendingDataIndex] = byte;
+                    pendingDataIndex++;
+
+                    if (pendingDataIndex == pendingDataLength) {
+                        // This message is now done -- do the final processing.
+                        if (pendingDataLength == 2) {
+                            packedMsg = pendingMessageStatus | pendingData[0] << 8 | pendingData[1] << 16;
+                        } else if (pendingDataLength == 1) {
+                            packedMsg = pendingMessageStatus | pendingData[0] << 8;
+                        } else {
+                            fprintf(stderr, "%s: %d->internal error: pendingMessageStatus=0x%X, pendingDataLength=%d\n",
+                                    __FILE__, __LINE__, pendingMessageStatus, pendingDataLength);
+                            byteIsInvalid = TRUE;
+                        }
+                        pendingDataLength = 0;
+                    }
+                } else {
+                    // Skip this byte -- it is invalid.
+                    byteIsInvalid = TRUE;
+                }
+            } else {
+                if (handle->readingSysExData /* && (byte == 0xF7) */) {
+                    // We have reached the end of system exclusive message -- send it finally.
+                    const UInt8* bytes = CFDataGetBytePtr(handle->readingSysExData);
+                    CFIndex size = CFDataGetLength(handle->readingSysExData);
+                    MIDI_QueueAddLong(handle->h.queue,
+                                      (UBYTE*) bytes,
+                                      (UINT32) size,
+                                      0, // Don't care, windowish porting only.
+                                      (INT64) (AudioConvertHostTimeToNanos(ts) + 500) / 1000,
+                                      TRUE);
+                    CFRelease(handle->readingSysExData);
+                    handle->readingSysExData = NULL;
+                }
+
+                pendingMessageStatus = byte;
+                pendingDataLength = 0;
+                pendingDataIndex = 0;
+
+                switch (byte & 0xF0) {
+                    case 0x80:    // Note off
+                    case 0x90:    // Note on
+                    case 0xA0:    // Aftertouch
+                    case 0xB0:    // Controller
+                    case 0xE0:    // Pitch wheel
+                        pendingDataLength = 2;
+                        break;
+
+                    case 0xC0:    // Program change
+                    case 0xD0:    // Channel pressure
+                        pendingDataLength = 1;
+                        break;
+
+                    case 0xF0: {
+                        // System common message
+                        switch (byte) {
+                        case 0xF0:
+                            // System exclusive
+                            // Allocates a CFMutableData reference to accumulate the SysEx data until EOX (0xF7) is reached.
+                            handle->readingSysExData = CFDataCreateMutable(NULL, 0);
+                            break;
+
+                        case 0xF7:
+                            // System exclusive ends--already handled above.
+                            // But if this is showing up outside of sysex, it's invalid.
+                            byteIsInvalid = TRUE;
+                            break;
+
+                        case 0xF1:    // MTC quarter frame message
+                        case 0xF3:    // Song select
+                            pendingDataLength = 1;
+                            break;
+
+                        case 0xF2:    // Song position pointer
+                            pendingDataLength = 2;
+                            break;
+
+                        case 0xF6:    // Tune request
+                            pendingDataLength = 0;
+                            break;
+
+                        default:
+                            // Invalid message
+                            byteIsInvalid = TRUE;
+                            break;
+                        }
+                        break;
+                    }
+
+                    default:
+                        // This can't happen, but handle it anyway.
+                        byteIsInvalid = TRUE;
+                        break;
+                }
+            }
+        }
+        if (byteIsInvalid) continue;
+
+        // If the byte is valid and pendingDataLength is 0, we are ready to send the message.
+        if (pendingDataLength == 0) {
+            MIDI_QueueAddShort(handle->h.queue, packedMsg, (INT64) (AudioConvertHostTimeToNanos(ts) + 500) / 1000, TRUE);
+        }
+    }
+}
+
+static void midiReadProc(const MIDIPacketList* packetList, void* refCon, void* connRefCon) {
+    unsigned int i;
+    const MIDIPacket* packet;
+    MacMidiDeviceHandle* handle = (MacMidiDeviceHandle*) connRefCon;
+
+    packet = packetList->packet;
+    for (i = 0; i < packetList->numPackets; ++i) {
+        processMessagesForPacket(packet, handle);
+        packet = MIDIPacketNext(packet);
+    }
+
+    // Notify the waiting thread that there's data available.
+    if (handle) {
+        MIDI_SignalConditionVariable(handle->h.platformData);
+    }
+}
+
+static void midiInit() {
+    if (client) {
+        return;
+    }
+
+    OSStatus err = noErr;
+
+    err = MIDIClientCreate(CFSTR("MIDI Client"), NULL, NULL, &client);
+    if (err != noErr) { goto Exit; }
+
+    // This just creates an input port through which the client may receive
+    // incoming MIDI messages from any MIDI source.
+    err = MIDIInputPortCreate(client, CFSTR("MIDI Input Port"), midiReadProc, NULL, &inPort);
+    if (err != noErr) { goto Exit; }
+
+    err = MIDIOutputPortCreate(client, CFSTR("MIDI Output Port"), &outPort);
+    if (err != noErr) { goto Exit; }
+
+Exit:
+    if (err != noErr) {
+        const char* s = MIDI_Utils_GetErrorMsg(err);
+        if (s != NULL) {
+            printf("%s\n", s);
+        }
+    }
+}
+
+
+INT32 MIDI_Utils_OpenDevice(int direction, INT32 deviceID, MacMidiDeviceHandle** handle,
+                            int num_msgs, int num_long_msgs,
+                            size_t lm_size)
+{
+    midiInit();
+
+    int err = MIDI_ERROR_NONE;
+    MIDIEndpointRef endpoint = (MIDIEndpointRef) NULL;
+
+    TRACE0("MIDI_Utils_OpenDevice\n");
+
+    (*handle) = (MacMidiDeviceHandle*) malloc(sizeof(MacMidiDeviceHandle));
+    if (!(*handle)) {
+        ERROR0("ERROR: MIDI_Utils_OpenDevice: out of memory\n");
+        return MIDI_OUT_OF_MEMORY;
+    }
+    memset(*handle, 0, sizeof(MacMidiDeviceHandle));
+
+    // Create the infrastructure for MIDI in/out, and after that,
+    // get the device's endpoint.
+    if (direction == MIDI_IN) {
+        // Create queue and the pthread condition variable.
+        (*handle)->h.queue = MIDI_CreateQueue(num_msgs);
+        (*handle)->h.platformData = MIDI_CreateConditionVariable();
+        if (!(*handle)->h.queue || !(*handle)->h.platformData) {
+            ERROR0("< ERROR: MIDI_IN_OpenDevice: could not create queue or condition variable\n");
+            free(*handle);
+            (*handle) = NULL;
+            return MIDI_OUT_OF_MEMORY;
+        }
+        endpoint = MIDIGetSource(deviceID);
+        (*handle)->port = inPort;
+    } else if (direction == MIDI_OUT) {
+        endpoint = MIDIGetDestination(deviceID);
+        (*handle)->port = outPort;
+    }
+
+    if (!endpoint) {
+        // An error occurred.
+        free(*handle);
+        return MIDI_INVALID_DEVICEID;
+    }
+    (*handle)->h.deviceHandle = (void*) (intptr_t) endpoint;
+    (*handle)->h.startTime = getCurrentTimeInNanos();
+    (*handle)->direction = direction;
+    (*handle)->deviceID = deviceID;
+
+    TRACE0("MIDI_Utils_OpenDevice: succeeded\n");
+    return err;
+}
+
+
+INT32 MIDI_Utils_CloseDevice(MacMidiDeviceHandle* handle) {
+    int err = MIDI_ERROR_NONE;
+    bool midiIn = (handle->direction == MIDI_IN);
+
+    TRACE0("> MIDI_Utils_CloseDevice\n");
+    if (!handle) {
+        ERROR0("< ERROR: MIDI_Utils_CloseDevice: handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    if (!handle->h.deviceHandle) {
+        ERROR0("< ERROR: MIDI_Utils_CloseDevice: native handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    handle->isStarted = FALSE;
+    handle->h.deviceHandle = NULL;
+
+    if (midiIn) {
+        if (handle->h.queue != NULL) {
+            MidiMessageQueue* queue = handle->h.queue;
+            handle->h.queue = NULL;
+            MIDI_DestroyQueue(queue);
+        }
+        if (handle->h.platformData) {
+            MIDI_DestroyConditionVariable(handle->h.platformData);
+        }
+    }
+    free(handle);
+
+    TRACE0("< MIDI_Utils_CloseDevice: succeeded\n");
+    return err;
+}
+
+
+INT32 MIDI_Utils_StartDevice(MacMidiDeviceHandle* handle) {
+    OSStatus err = noErr;
+
+    if (!handle || !handle->h.deviceHandle) {
+        ERROR0("ERROR: MIDI_Utils_StartDevice: handle or native is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+
+    // Clears all the events from the queue.
+    MIDI_QueueClear(handle->h.queue);
+
+    if (!handle->isStarted) {
+        /* set the flag that we can now receive messages */
+        handle->isStarted = TRUE;
+
+        if (handle->direction == MIDI_IN) {
+            // The handle->h.platformData field contains the (pthread_cond_t*)
+            // associated with the source of the MIDI input stream, and is
+            // used in the CoreMIDI's callback to signal the arrival of new
+            // data.
+            //
+            // Similarly, handle->h.queue is used in the CoreMDID's callback
+            // to dispatch the incoming messages to the appropriate queue.
+            //
+            err = MIDIPortConnectSource(inPort, (MIDIEndpointRef) (intptr_t) (handle->h.deviceHandle), (void*) handle);
+        } else if (handle->direction == MIDI_OUT) {
+            // Unschedules previous-sent packets.
+            err = MIDIFlushOutput((MIDIEndpointRef) (intptr_t) handle->h.deviceHandle);
+        }
+
+        MIDI_CHECK_ERROR;
+    }
+    return MIDI_SUCCESS; /* don't fail */
+}
+
+
+INT32 MIDI_Utils_StopDevice(MacMidiDeviceHandle* handle) {
+    OSStatus err = noErr;
+
+    if (!handle || !handle->h.deviceHandle) {
+        ERROR0("ERROR: MIDI_Utils_StopDevice: handle or native handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+
+    if (handle->isStarted) {
+        /* set the flag that we don't want to receive messages anymore */
+        handle->isStarted = FALSE;
+
+        if (handle->direction == MIDI_IN) {
+            err = MIDIPortDisconnectSource(inPort, (MIDIEndpointRef) (intptr_t) (handle->h.deviceHandle));
+        } else if (handle->direction == MIDI_OUT) {
+            // Unschedules previously-sent packets.
+            err = MIDIFlushOutput((MIDIEndpointRef) (intptr_t) handle->h.deviceHandle);
+        }
+
+        MIDI_CHECK_ERROR;
+    }
+    return MIDI_SUCCESS;
+}
+
+
+INT64 MIDI_Utils_GetTimeStamp(MacMidiDeviceHandle* handle) {
+
+    if (!handle || !handle->h.deviceHandle) {
+        ERROR0("ERROR: MIDI_Utils_GetTimeStamp: handle or native handle is NULL\n");
+        return (INT64) -1; /* failure */
+    }
+
+    UInt64 delta = getCurrentTimeInNanos() - handle->h.startTime;
+    return (INT64) ((delta + 500) / 1000);
+}
+
+
+/***************************************************************************/
+/*            Condition Variable Support for Mac OS X Port                 */
+/*                                                                         */
+/* This works with the Native Locking Support defined below.  We are using */
+/* POSIX pthread_cond_t/pthread_mutex_t to do locking and synchronization. */
+/*                                                                         */
+/* For MidiDeviceHandle* handle, the mutex reference is stored as handle-> */
+/* queue->lock while the condition variabale reference is stored as handle */
+/* ->platformData.                                                         */
+/***************************************************************************/
+
+// Called from Midi_Utils_Opendevice(...) to create a condition variable
+// used to synchronize between the receive thread created by the CoreMIDI
+// and the Java-initiated MidiInDevice run loop.
+void* MIDI_CreateConditionVariable() {
+    pthread_cond_t* cond = (pthread_cond_t*) malloc(sizeof(pthread_cond_t));
+    pthread_cond_init(cond, NULL);
+    return (void*) cond;
+}
+
+void MIDI_DestroyConditionVariable(void* cond) {
+    while (pthread_cond_destroy((pthread_cond_t*) cond) == EBUSY) {
+        pthread_cond_broadcast((pthread_cond_t*) cond);
+        sched_yield();
+    }
+    return;
+}
+
+// Called from MIDI_IN_GetMessage(...) to wait for MIDI messages to become
+// available via delivery from the CoreMIDI receive thread
+void MIDI_WaitOnConditionVariable(void* cond, void* lock) {
+    if (cond && lock) {
+        pthread_mutex_lock(lock);
+        pthread_cond_wait((pthread_cond_t*) cond, (pthread_mutex_t*) lock);
+        pthread_mutex_unlock(lock);
+    }
+    return;
+}
+
+// Called from midiReadProc(...) to notify the waiting thread to unblock on
+// the condition variable.
+void MIDI_SignalConditionVariable(void* cond) {
+    if (cond) {
+        pthread_cond_signal((pthread_cond_t*) cond);
+    }
+    return;
+}
+
+
+/**************************************************************************/
+/*                     Native Locking Support                             */
+/*                                                                        */
+/* @see src/share/natve/com/sun/media/sound/PlatformMidi.c which contains */
+/* utility functions for platform midi support where the section of code  */
+/* for MessageQueue implementation calls out to these functions.          */
+/**************************************************************************/
+
+void* MIDI_CreateLock() {
+    pthread_mutex_t* lock = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
+    pthread_mutex_init(lock, NULL);
+    TRACE0("MIDI_CreateLock\n");
+    return (void *)lock;
+}
+
+void MIDI_DestroyLock(void* lock) {
+    if (lock) {
+        pthread_mutex_destroy((pthread_mutex_t*) lock);
+        free(lock);
+        TRACE0("MIDI_DestroyLock\n");
+    }
+}
+
+void MIDI_Lock(void* lock) {
+    if (lock) {
+        pthread_mutex_lock((pthread_mutex_t*) lock);
+    }
+}
+
+void MIDI_Unlock(void* lock) {
+    if (lock) {
+        pthread_mutex_unlock((pthread_mutex_t*) lock);
+    }
+}
+
+
+#endif // USE_PLATFORM_MIDI_IN || USE_PLATFORM_MIDI_OUT
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiUtils.h b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiUtils.h
new file mode 100644
index 0000000..7276616
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_MidiUtils.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#if (USE_PLATFORM_MIDI_IN == TRUE) || (USE_PLATFORM_MIDI_OUT == TRUE)
+
+#include "PlatformMidi.h"                  // JavaSound header for platform midi support.
+#include <CoreMIDI/CoreMIDI.h>             // Umbrella header for the CoreMIDI framework.
+#include <CoreAudio/CoreAudio.h>           // This provides access to the host's time base and translations to nanoseconds.
+#include <CoreFoundation/CoreFoundation.h> // CFDataRef.
+
+/* for memcpy */
+#include <string.h>
+/* for malloc */
+#include <stdlib.h>
+/* for usleep */
+#include <unistd.h>
+
+#ifdef USE_ERROR
+#include <stdio.h>
+#endif
+
+#define MIDI_ERROR_NONE MIDI_SUCCESS
+
+#ifdef USE_ERROR
+#define MIDI_CHECK_ERROR  { if (err != MIDI_ERROR_NONE) MIDI_Utils_PrintError(err); }
+#else
+#define MIDI_CHECK_ERROR
+#endif
+
+typedef struct {
+    MidiDeviceHandle h;                  /* the real handle (must be the first field!) */
+    int direction;                       /* direction of the endpoint */
+    int deviceID;                        /* logical index (0 .. numEndpoints-1) */
+    int isStarted;                       /* whether device is "started" */
+    MIDIPortRef port;                    /* input or output port associated with the endpoint */
+    CFMutableDataRef readingSysExData;   /* Non-Null: in the middle of reading SysEx data; Null: otherwise */
+} MacMidiDeviceHandle;
+
+extern const char* MIDI_Utils_GetErrorMsg(int err);
+extern void MIDI_Utils_PrintError(int err);
+
+// A MIDI endpoint represents a source or a destination for a standard 16-channel MIDI data stream.
+enum {
+    MIDI_IN = 0, // source
+    MIDI_OUT = 1 // destination
+};
+
+// The parameter "direction" is either MIDI_IN or MIDI_OUT.
+// Declarations of functions required by the JavaSound MIDI Porting layer.
+
+extern INT32 MIDI_Utils_GetNumDevices(int direction);
+extern INT32 MIDI_Utils_GetDeviceName(int direction, INT32 deviceID, char *name, UINT32 nameLength);
+extern INT32 MIDI_Utils_GetDeviceVendor(int direction, INT32 deviceID, char *name, UINT32 nameLength);
+extern INT32 MIDI_Utils_GetDeviceDescription(int direction, INT32 deviceID, char *name, UINT32 nameLength);
+extern INT32 MIDI_Utils_GetDeviceVersion(int direction, INT32 deviceID, char *name, UINT32 nameLength);
+extern INT32 MIDI_Utils_OpenDevice(int direction, INT32 deviceID, MacMidiDeviceHandle** handle,
+                   int num_msgs, int num_long_msgs,
+                   size_t lm_size);
+extern INT32 MIDI_Utils_CloseDevice(MacMidiDeviceHandle* handle);
+extern INT32 MIDI_Utils_StartDevice(MacMidiDeviceHandle* handle);
+extern INT32 MIDI_Utils_StopDevice(MacMidiDeviceHandle* handle);
+extern INT64 MIDI_Utils_GetTimeStamp(MacMidiDeviceHandle* handle);
+
+// Mac OS X port for locking and synchronization.
+
+extern void* MIDI_CreateConditionVariable();
+extern void  MIDI_DestroyConditionVariable(void* cond);
+extern void  MIDI_WaitOnConditionVariable(void* cond, void* lock);
+extern void  MIDI_SignalConditionVariable(void* cond);
+
+#endif // USE_PLATFORM_MIDI_IN || USE_PLATFORM_MIDI_OUT
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp
new file mode 100644
index 0000000..5aa09102
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp
@@ -0,0 +1,776 @@
+/*
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_ERROR
+//#define USE_TRACE
+//#define USE_VERBOSE_TRACE
+
+#include <AudioUnit/AudioUnit.h>
+#include <CoreServices/CoreServices.h>
+#include <pthread.h>
+/*
+#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
+#include <CoreAudio/CoreAudioTypes.h>
+#else
+#include <CoreAudioTypes.h>
+#endif
+*/
+
+#include "PLATFORM_API_MacOSX_Utils.h"
+
+extern "C" {
+#include "Utilities.h"
+#include "DirectAudio.h"
+}
+
+#if USE_DAUDIO == TRUE
+
+
+#ifdef USE_TRACE
+static void PrintStreamDesc(AudioStreamBasicDescription *inDesc) {
+    TRACE4("ID='%c%c%c%c'", (char)(inDesc->mFormatID >> 24), (char)(inDesc->mFormatID >> 16), (char)(inDesc->mFormatID >> 8), (char)(inDesc->mFormatID));
+    TRACE2(", %f Hz, flags=0x%lX", (float)inDesc->mSampleRate, (long unsigned)inDesc->mFormatFlags);
+    TRACE2(", %ld channels, %ld bits", (long)inDesc->mChannelsPerFrame, (long)inDesc->mBitsPerChannel);
+    TRACE1(", %ld bytes per frame\n", (long)inDesc->mBytesPerFrame);
+}
+#else
+static inline void PrintStreamDesc(AudioStreamBasicDescription *inDesc) { }
+#endif
+
+
+#define MAX(x, y)   ((x) >= (y) ? (x) : (y))
+#define MIN(x, y)   ((x) <= (y) ? (x) : (y))
+
+
+// =======================================
+// MixerProvider functions implementation
+
+static DeviceList deviceCache;
+
+INT32 DAUDIO_GetDirectAudioDeviceCount() {
+    deviceCache.Refresh();
+    int count = deviceCache.GetCount();
+    if (count > 0) {
+        // add "default" device
+        count++;
+        TRACE1("DAUDIO_GetDirectAudioDeviceCount: returns %d devices\n", count);
+    } else {
+        TRACE0("DAUDIO_GetDirectAudioDeviceCount: no devices found\n");
+    }
+    return count;
+}
+
+INT32 DAUDIO_GetDirectAudioDeviceDescription(INT32 mixerIndex, DirectAudioDeviceDescription *desc) {
+    bool result = true;
+    desc->deviceID = 0;
+    if (mixerIndex == 0) {
+        // default device
+        strncpy(desc->name, "Default Audio Device", DAUDIO_STRING_LENGTH);
+        strncpy(desc->description, "Default Audio Device", DAUDIO_STRING_LENGTH);
+        desc->maxSimulLines = -1;
+    } else {
+        AudioDeviceID deviceID;
+        result = deviceCache.GetDeviceInfo(mixerIndex-1, &deviceID, DAUDIO_STRING_LENGTH,
+            desc->name, desc->vendor, desc->description, desc->version);
+        if (result) {
+            desc->deviceID = (INT32)deviceID;
+            desc->maxSimulLines = -1;
+        }
+    }
+    return result ? TRUE : FALSE;
+}
+
+
+void DAUDIO_GetFormats(INT32 mixerIndex, INT32 deviceID, int isSource, void* creator) {
+    TRACE3(">>DAUDIO_GetFormats mixerIndex=%d deviceID=0x%x isSource=%d\n", (int)mixerIndex, (int)deviceID, isSource);
+
+    AudioDeviceID audioDeviceID = deviceID == 0 ? GetDefaultDevice(isSource) : (AudioDeviceID)deviceID;
+
+    if (audioDeviceID == 0) {
+        return;
+    }
+
+    int totalChannels = GetChannelCount(audioDeviceID, isSource);
+
+    if (totalChannels == 0) {
+        TRACE0("<<DAUDIO_GetFormats, no streams!\n");
+        return;
+    }
+
+    if (isSource && totalChannels < 2) {
+        // report 2 channels even if only mono is supported
+        totalChannels = 2;
+    }
+
+    int channels[] = {1, 2, totalChannels};
+    int channelsCount = MIN(totalChannels, 3);
+
+    float hardwareSampleRate = GetSampleRate(audioDeviceID, isSource);
+    TRACE2("  DAUDIO_GetFormats: got %d channels, sampleRate == %f\n", totalChannels, hardwareSampleRate);
+
+    // target lines support only current sample rate!
+    float sampleRate = isSource ? -1 : hardwareSampleRate;
+
+    static int sampleBits[] = {8, 16, 24};
+    static int sampleBitsCount = sizeof(sampleBits)/sizeof(sampleBits[0]);
+
+    // the last audio format is the default one (used by DataLine.open() if format is not specified)
+    // consider as default 16bit PCM stereo (mono is stereo is not supported) with the current sample rate
+    int defBits = 16;
+    int defChannels = MIN(2, channelsCount);
+    float defSampleRate = hardwareSampleRate;
+    // don't add default format is sample rate is not specified
+    bool addDefault = defSampleRate > 0;
+
+    // TODO: CoreAudio can handle signed/unsigned, little-endian/big-endian
+    // TODO: register the formats (to prevent DirectAudio software conversion) - need to fix DirectAudioDevice.createDataLineInfo
+    // to avoid software conversions if both signed/unsigned or big-/little-endian are supported
+    for (int channelIndex = 0; channelIndex < channelsCount; channelIndex++) {
+        for (int bitIndex = 0; bitIndex < sampleBitsCount; bitIndex++) {
+            int bits = sampleBits[bitIndex];
+            if (addDefault && bits == defBits && channels[channelIndex] != defChannels && sampleRate == defSampleRate) {
+                // the format is the default one, don't add it now
+                continue;
+            }
+            DAUDIO_AddAudioFormat(creator,
+                bits,                       // sample size in bits
+                -1,                         // frame size (auto)
+                channels[channelIndex],     // channels
+                sampleRate,                 // sample rate
+                DAUDIO_PCM,                 // only accept PCM
+                bits == 8 ? FALSE : TRUE,   // signed
+                bits == 8 ? FALSE           // little-endian for 8bit
+                    : UTIL_IsBigEndianPlatform());
+        }
+    }
+    // add default format
+    if (addDefault) {
+        DAUDIO_AddAudioFormat(creator,
+            defBits,                        // 16 bits
+            -1,                             // automatically calculate frame size
+            defChannels,                    // channels
+            defSampleRate,                  // sample rate
+            DAUDIO_PCM,                     // PCM
+            TRUE,                           // signed
+            UTIL_IsBigEndianPlatform());    // native endianess
+    }
+
+    TRACE0("<<DAUDIO_GetFormats\n");
+}
+
+
+// =======================================
+// Source/Target DataLine functions implementation
+
+// ====
+/* 1writer-1reader ring buffer class with flush() support */
+class RingBuffer {
+public:
+    RingBuffer() : pBuffer(NULL), nBufferSize(0) {
+        pthread_mutex_init(&lockMutex, NULL);
+    }
+    ~RingBuffer() {
+        Deallocate();
+        pthread_mutex_destroy(&lockMutex);
+    }
+
+    // extraBytes: number of additionally allocated bytes to prevent data
+    // overlapping when almost whole buffer is filled
+    // (required only if Write() can override the buffer)
+    bool Allocate(int requestedBufferSize, int extraBytes) {
+        int fullBufferSize = requestedBufferSize + extraBytes;
+        int powerOfTwo = 1;
+        while (powerOfTwo < fullBufferSize) {
+            powerOfTwo <<= 1;
+        }
+        pBuffer = (Byte*)malloc(powerOfTwo);
+        if (pBuffer == NULL) {
+            ERROR0("RingBuffer::Allocate: OUT OF MEMORY\n");
+            return false;
+        }
+
+        nBufferSize = requestedBufferSize;
+        nAllocatedBytes = powerOfTwo;
+        nPosMask = powerOfTwo - 1;
+        nWritePos = 0;
+        nReadPos = 0;
+        nFlushPos = -1;
+
+        TRACE2("RingBuffer::Allocate: OK, bufferSize=%d, allocated:%d\n", nBufferSize, nAllocatedBytes);
+        return true;
+    }
+
+    void Deallocate() {
+        if (pBuffer) {
+            free(pBuffer);
+            pBuffer = NULL;
+            nBufferSize = 0;
+        }
+    }
+
+    inline int GetBufferSize() {
+        return nBufferSize;
+    }
+
+    inline int GetAllocatedSize() {
+        return nAllocatedBytes;
+    }
+
+    // gets number of bytes available for reading
+    int GetValidByteCount() {
+        lock();
+        INT64 result = nWritePos - (nFlushPos >= 0 ? nFlushPos : nReadPos);
+        unlock();
+        return result > (INT64)nBufferSize ? nBufferSize : (int)result;
+    }
+
+    int Write(void *srcBuffer, int len, bool preventOverflow) {
+        lock();
+        TRACE2("RingBuffer::Write (%d bytes, preventOverflow=%d)\n", len, preventOverflow ? 1 : 0);
+        TRACE2("  writePos = %lld (%d)", (long long)nWritePos, Pos2Offset(nWritePos));
+        TRACE2("  readPos=%lld (%d)", (long long)nReadPos, Pos2Offset(nReadPos));
+        TRACE2("  flushPos=%lld (%d)\n", (long long)nFlushPos, Pos2Offset(nFlushPos));
+
+        INT64 writePos = nWritePos;
+        if (preventOverflow) {
+            INT64 avail_read = writePos - (nFlushPos >= 0 ? nFlushPos : nReadPos);
+            if (avail_read >= (INT64)nBufferSize) {
+                // no space
+                TRACE0("  preventOverlow: OVERFLOW => len = 0;\n");
+                len = 0;
+            } else {
+                int avail_write = nBufferSize - (int)avail_read;
+                if (len > avail_write) {
+                    TRACE2("  preventOverlow: desrease len: %d => %d\n", len, avail_write);
+                    len = avail_write;
+                }
+            }
+        }
+        unlock();
+
+        if (len > 0) {
+
+            write((Byte *)srcBuffer, Pos2Offset(writePos), len);
+
+            lock();
+            TRACE4("--RingBuffer::Write writePos: %lld (%d) => %lld, (%d)\n",
+                (long long)nWritePos, Pos2Offset(nWritePos), (long long)nWritePos + len, Pos2Offset(nWritePos + len));
+            nWritePos += len;
+            unlock();
+        }
+        return len;
+    }
+
+    int Read(void *dstBuffer, int len) {
+        lock();
+        TRACE1("RingBuffer::Read (%d bytes)\n", len);
+        TRACE2("  writePos = %lld (%d)", (long long)nWritePos, Pos2Offset(nWritePos));
+        TRACE2("  readPos=%lld (%d)", (long long)nReadPos, Pos2Offset(nReadPos));
+        TRACE2("  flushPos=%lld (%d)\n", (long long)nFlushPos, Pos2Offset(nFlushPos));
+
+        applyFlush();
+        INT64 avail_read = nWritePos - nReadPos;
+        // check for overflow
+        if (avail_read > (INT64)nBufferSize) {
+            nReadPos = nWritePos - nBufferSize;
+            avail_read = nBufferSize;
+            TRACE0("  OVERFLOW\n");
+        }
+        INT64 readPos = nReadPos;
+        unlock();
+
+        if (len > (int)avail_read) {
+            TRACE2("  RingBuffer::Read - don't have enough data, len: %d => %d\n", len, (int)avail_read);
+            len = (int)avail_read;
+        }
+
+        if (len > 0) {
+
+            read((Byte *)dstBuffer, Pos2Offset(readPos), len);
+
+            lock();
+            if (applyFlush()) {
+                // just got flush(), results became obsolete
+                TRACE0("--RingBuffer::Read, got Flush, return 0\n");
+                len = 0;
+            } else {
+                TRACE4("--RingBuffer::Read readPos: %lld (%d) => %lld (%d)\n",
+                    (long long)nReadPos, Pos2Offset(nReadPos), (long long)nReadPos + len, Pos2Offset(nReadPos + len));
+                nReadPos += len;
+            }
+            unlock();
+        } else {
+            // underrun!
+        }
+        return len;
+    }
+
+    // returns number of the flushed bytes
+    int Flush() {
+        lock();
+        INT64 flushedBytes = nWritePos - (nFlushPos >= 0 ? nFlushPos : nReadPos);
+        nFlushPos = nWritePos;
+        unlock();
+        return flushedBytes > (INT64)nBufferSize ? nBufferSize : (int)flushedBytes;
+    }
+
+private:
+    Byte *pBuffer;
+    int nBufferSize;
+    int nAllocatedBytes;
+    INT64 nPosMask;
+
+    pthread_mutex_t lockMutex;
+
+    volatile INT64 nWritePos;
+    volatile INT64 nReadPos;
+    // Flush() sets nFlushPos value to nWritePos;
+    // next Read() sets nReadPos to nFlushPos and resests nFlushPos to -1
+    volatile INT64 nFlushPos;
+
+    inline void lock() {
+        pthread_mutex_lock(&lockMutex);
+    }
+    inline void unlock() {
+        pthread_mutex_unlock(&lockMutex);
+    }
+
+    inline bool applyFlush() {
+        if (nFlushPos >= 0) {
+            nReadPos = nFlushPos;
+            nFlushPos = -1;
+            return true;
+        }
+        return false;
+    }
+
+    inline int Pos2Offset(INT64 pos) {
+        return (int)(pos & nPosMask);
+    }
+
+    void write(Byte *srcBuffer, int dstOffset, int len) {
+        int dstEndOffset = dstOffset + len;
+
+        int lenAfterWrap = dstEndOffset - nAllocatedBytes;
+        if (lenAfterWrap > 0) {
+            // dest.buffer does wrap
+            len = nAllocatedBytes - dstOffset;
+            memcpy(pBuffer+dstOffset, srcBuffer, len);
+            memcpy(pBuffer, srcBuffer+len, lenAfterWrap);
+        } else {
+            // dest.buffer does not wrap
+            memcpy(pBuffer+dstOffset, srcBuffer, len);
+        }
+    }
+
+    void read(Byte *dstBuffer, int srcOffset, int len) {
+        int srcEndOffset = srcOffset + len;
+
+        int lenAfterWrap = srcEndOffset - nAllocatedBytes;
+        if (lenAfterWrap > 0) {
+            // need to unwrap data
+            len = nAllocatedBytes - srcOffset;
+            memcpy(dstBuffer, pBuffer+srcOffset, len);
+            memcpy(dstBuffer+len, pBuffer, lenAfterWrap);
+        } else {
+            // source buffer is not wrapped
+            memcpy(dstBuffer, pBuffer+srcOffset, len);
+        }
+    }
+};
+
+
+struct OSX_DirectAudioDevice {
+    AudioUnit   audioUnit;
+    RingBuffer  ringBuffer;
+    AudioStreamBasicDescription asbd;
+
+    // only for target lines
+    UInt32      inputBufferSizeInBytes;
+
+    OSX_DirectAudioDevice() : audioUnit(NULL), asbd() {
+    }
+
+    ~OSX_DirectAudioDevice() {
+        if (audioUnit) {
+            CloseComponent(audioUnit);
+        }
+    }
+};
+
+static AudioUnit CreateOutputUnit(AudioDeviceID deviceID, int isSource)
+{
+    OSStatus err;
+    AudioUnit unit;
+    UInt32 size;
+
+        ComponentDescription desc;
+        desc.componentType         = kAudioUnitType_Output;
+        desc.componentSubType      = (deviceID == 0 && isSource) ? kAudioUnitSubType_DefaultOutput : kAudioUnitSubType_HALOutput;
+        desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+        desc.componentFlags        = 0;
+        desc.componentFlagsMask    = 0;
+
+    Component comp = FindNextComponent(NULL, &desc);
+        err = OpenAComponent(comp, &unit);
+
+    if (err) {
+        OS_ERROR0(err, "CreateOutputUnit:OpenAComponent");
+        return NULL;
+    }
+
+    if (!isSource) {
+        int enableIO = 0;
+        err = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output,
+                                    0, &enableIO, sizeof(enableIO));
+        if (err) {
+            OS_ERROR0(err, "SetProperty (output EnableIO)");
+        }
+        enableIO = 1;
+        err = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input,
+                                    1, &enableIO, sizeof(enableIO));
+        if (err) {
+            OS_ERROR0(err, "SetProperty (input EnableIO)");
+        }
+
+        if (!deviceID) {
+            // get real AudioDeviceID for default input device (macosx current input device)
+            deviceID = GetDefaultDevice(isSource);
+            if (!deviceID) {
+                CloseComponent(unit);
+                return NULL;
+            }
+        }
+    }
+
+    if (deviceID) {
+        err = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global,
+                                    0, &deviceID, sizeof(deviceID));
+        if (err) {
+            OS_ERROR0(err, "SetProperty (CurrentDevice)");
+            CloseComponent(unit);
+            return NULL;
+        }
+    }
+
+    return unit;
+}
+
+static OSStatus OutputCallback(void                         *inRefCon,
+                               AudioUnitRenderActionFlags   *ioActionFlags,
+                               const AudioTimeStamp         *inTimeStamp,
+                               UInt32                       inBusNumber,
+                               UInt32                       inNumberFrames,
+                               AudioBufferList              *ioData)
+{
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)inRefCon;
+
+    int nchannels = ioData->mNumberBuffers; // should be always == 1 (interleaved channels)
+    AudioBuffer *audioBuffer = ioData->mBuffers;
+
+    TRACE3(">>OutputCallback: busNum=%d, requested %d frames (%d bytes)\n",
+        (int)inBusNumber, (int)inNumberFrames, (int)(inNumberFrames * device->asbd.mBytesPerFrame));
+    TRACE3("  abl: %d buffers, buffer[0].channels=%d, buffer.size=%d\n",
+        nchannels, (int)audioBuffer->mNumberChannels, (int)audioBuffer->mDataByteSize);
+
+    int bytesToRead = inNumberFrames * device->asbd.mBytesPerFrame;
+    if (bytesToRead > (int)audioBuffer->mDataByteSize) {
+        TRACE0("--OutputCallback: !!! audioBuffer IS TOO SMALL!!!\n");
+        bytesToRead = audioBuffer->mDataByteSize / device->asbd.mBytesPerFrame * device->asbd.mBytesPerFrame;
+    }
+    int bytesRead = device->ringBuffer.Read(audioBuffer->mData, bytesToRead);
+    if (bytesRead < bytesToRead) {
+        // no enough data (underrun)
+        TRACE2("--OutputCallback: !!! UNDERRUN (read %d bytes of %d)!!!\n", bytesRead, bytesToRead);
+        // silence the rest
+        memset((Byte*)audioBuffer->mData + bytesRead, 0, bytesToRead-bytesRead);
+        bytesRead = bytesToRead;
+    }
+
+    audioBuffer->mDataByteSize = (UInt32)bytesRead;
+    // SAFETY: set mDataByteSize for all other AudioBuffer in the AudioBufferList to zero
+    while (--nchannels > 0) {
+        audioBuffer++;
+        audioBuffer->mDataByteSize = 0;
+    }
+    TRACE1("<<OutputCallback (returns %d)\n", bytesRead);
+
+    return noErr;
+}
+
+static OSStatus InputCallback(void                          *inRefCon,
+                              AudioUnitRenderActionFlags    *ioActionFlags,
+                              const AudioTimeStamp          *inTimeStamp,
+                              UInt32                        inBusNumber,
+                              UInt32                        inNumberFrames,
+                              AudioBufferList               *ioData)
+{
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)inRefCon;
+
+    TRACE4(">>InputCallback: busNum=%d, timeStamp=%lld, %d frames (%d bytes)\n",
+        (int)inBusNumber, (long long)inTimeStamp->mSampleTime, (int)inNumberFrames, (int)(inNumberFrames * device->asbd.mBytesPerFrame));
+
+    AudioBufferList abl;    // by default it contains 1 AudioBuffer
+    abl.mNumberBuffers = 1;
+    abl.mBuffers[0].mNumberChannels = device->asbd.mChannelsPerFrame;
+    abl.mBuffers[0].mDataByteSize   = device->inputBufferSizeInBytes;   // assume this is == (inNumberFrames * device->asbd.mBytesPerFrame)
+    abl.mBuffers[0].mData           = NULL;     // request for the audioUnit's buffer
+
+    // TODO: is it possible device->inputBufferSizeInBytes != inNumberFrames * device->asbd.mBytesPerFrame??
+
+    OSStatus err = AudioUnitRender(device->audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &abl);
+    if (err) {
+        OS_ERROR0(err, "<<InputCallback: AudioUnitRender");
+    } else {
+        int bytesWritten = device->ringBuffer.Write(abl.mBuffers[0].mData, (int)abl.mBuffers[0].mDataByteSize, false);
+        TRACE2("<<InputCallback (saved %d bytes of %d)\n", bytesWritten, (int)abl.mBuffers[0].mDataByteSize);
+    }
+
+    return noErr;
+}
+
+void* DAUDIO_Open(INT32 mixerIndex, INT32 deviceID, int isSource,
+                  int encoding, float sampleRate, int sampleSizeInBits,
+                  int frameSize, int channels,
+                  int isSigned, int isBigEndian, int bufferSizeInBytes)
+{
+    TRACE3(">>DAUDIO_Open: mixerIndex=%d deviceID=0x%x isSource=%d\n", (int)mixerIndex, (unsigned int)deviceID, isSource);
+    TRACE3("  sampleRate=%d sampleSizeInBits=%d channels=%d\n", (int)sampleRate, sampleSizeInBits, channels);
+#ifdef USE_TRACE
+    {
+        AudioDeviceID audioDeviceID = deviceID;
+        if (audioDeviceID == 0) {
+            // default device
+            audioDeviceID = GetDefaultDevice(isSource);
+        }
+        char name[256];
+        OSStatus err = GetAudioObjectProperty(audioDeviceID, kAudioUnitScope_Global, kAudioDevicePropertyDeviceName, 256, &name, 0);
+        if (err != noErr) {
+            OS_ERROR1(err, "  audioDeviceID=0x%x, name is N/A:", (int)audioDeviceID);
+        } else {
+            TRACE2("  audioDeviceID=0x%x, name=%s\n", (int)audioDeviceID, name);
+        }
+    }
+#endif
+
+    if (encoding != DAUDIO_PCM) {
+        ERROR1("<<DAUDIO_Open: ERROR: unsupported encoding (%d)\n", encoding);
+        return NULL;
+    }
+
+    // TODO: for target lines we should ensure that sampleRate == current device sample rate
+    // (othewise we get error -10863 (kAudioUnitErr_CannotDoInCurrentContext in AUComponent.h) from AudioUnitRender(in InputCallback))
+
+    OSX_DirectAudioDevice *device = new OSX_DirectAudioDevice();
+
+    AudioUnitScope scope = isSource ? kAudioUnitScope_Input : kAudioUnitScope_Output;
+    int element = isSource ? 0 : 1;
+    OSStatus err = noErr;
+    int extraBufferBytes = 0;
+
+    device->audioUnit = CreateOutputUnit(deviceID, isSource);
+
+    if (!device->audioUnit) {
+        delete device;
+        return NULL;
+    }
+
+    FillOutASBDForLPCM(device->asbd, sampleRate, channels, sampleSizeInBits, sampleSizeInBits, 0, isBigEndian);
+    // Workaround for FillOutASBDForLPCM - it always set kAudioFormatFlagIsSignedInteger for non-float formats
+    if (!isSigned) {
+        device->asbd.mFormatFlags &= ~(UInt32)kAudioFormatFlagIsSignedInteger;
+    }
+
+    err = AudioUnitSetProperty(device->audioUnit, kAudioUnitProperty_StreamFormat, scope, element, &device->asbd, sizeof(device->asbd));
+    if (err) {
+        OS_ERROR0(err, "<<DAUDIO_Open set StreamFormat");
+        delete device;
+        return NULL;
+    }
+
+    AURenderCallbackStruct output;
+    output.inputProc       = isSource ? OutputCallback : InputCallback;
+    output.inputProcRefCon = device;
+
+    err = AudioUnitSetProperty(device->audioUnit,
+                                isSource
+                                    ? (AudioUnitPropertyID)kAudioUnitProperty_SetRenderCallback
+                                    : (AudioUnitPropertyID)kAudioOutputUnitProperty_SetInputCallback,
+                                kAudioUnitScope_Global, 0, &output, sizeof(output));
+    if (err) {
+        OS_ERROR0(err, "<<DAUDIO_Open set RenderCallback");
+        delete device;
+        return NULL;
+    }
+
+    err = AudioUnitInitialize(device->audioUnit);
+    if (err) {
+        OS_ERROR0(err, "<<DAUDIO_Open UnitInitialize");
+        delete device;
+        return NULL;
+    }
+
+    if (!isSource) {
+        // for target lines we need extra bytes in the buffer
+        // to prevent collisions when InputCallback overrides data on overflow
+        UInt32 size;
+        OSStatus err;
+
+        size = sizeof(device->inputBufferSizeInBytes);
+        err  = AudioUnitGetProperty(device->audioUnit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global,
+                                    0, &device->inputBufferSizeInBytes, &size);
+        if (err) {
+            OS_ERROR0(err, "<<DAUDIO_Open (TargetDataLine)GetBufferSize\n");
+            delete device;
+            return NULL;
+        }
+        device->inputBufferSizeInBytes *= device->asbd.mBytesPerFrame;  // convert frames by bytes
+        extraBufferBytes = (int)device->inputBufferSizeInBytes;
+    }
+
+    if (!device->ringBuffer.Allocate(bufferSizeInBytes, extraBufferBytes)) {
+        ERROR0("<<DAUDIO_Open: Ring buffer allocation error\n");
+        delete device;
+        return NULL;
+    }
+
+    TRACE0("<<DAUDIO_Open: OK\n");
+    return device;
+}
+
+int DAUDIO_Start(void* id, int isSource) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+    TRACE0("DAUDIO_Start\n");
+
+    OSStatus err = AudioOutputUnitStart(device->audioUnit);
+
+    if (err != noErr) {
+        OS_ERROR0(err, "DAUDIO_Start");
+    }
+
+    return err == noErr ? TRUE : FALSE;
+}
+
+int DAUDIO_Stop(void* id, int isSource) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+    TRACE0("DAUDIO_Stop\n");
+
+    OSStatus err = AudioOutputUnitStop(device->audioUnit);
+
+    return err == noErr ? TRUE : FALSE;
+}
+
+void DAUDIO_Close(void* id, int isSource) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+    TRACE0("DAUDIO_Close\n");
+
+    delete device;
+}
+
+int DAUDIO_Write(void* id, char* data, int byteSize) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+    TRACE1(">>DAUDIO_Write: %d bytes to write\n", byteSize);
+
+    int result = device->ringBuffer.Write(data, byteSize, true);
+
+    TRACE1("<<DAUDIO_Write: %d bytes written\n", result);
+    return result;
+}
+
+int DAUDIO_Read(void* id, char* data, int byteSize) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+    TRACE1(">>DAUDIO_Read: %d bytes to read\n", byteSize);
+
+    int result = device->ringBuffer.Read(data, byteSize);
+
+    TRACE1("<<DAUDIO_Read: %d bytes has been read\n", result);
+    return result;
+}
+
+int DAUDIO_GetBufferSize(void* id, int isSource) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+
+    int bufferSizeInBytes = device->ringBuffer.GetBufferSize();
+
+    TRACE1("DAUDIO_GetBufferSize returns %d\n", bufferSizeInBytes);
+    return bufferSizeInBytes;
+}
+
+int DAUDIO_StillDraining(void* id, int isSource) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+
+    int draining = device->ringBuffer.GetValidByteCount() > 0 ? TRUE : FALSE;
+
+    TRACE1("DAUDIO_StillDraining returns %d\n", draining);
+    return draining;
+}
+
+int DAUDIO_Flush(void* id, int isSource) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+    TRACE0("DAUDIO_Flush\n");
+
+    device->ringBuffer.Flush();
+
+    return TRUE;
+}
+
+int DAUDIO_GetAvailable(void* id, int isSource) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+
+    int bytesInBuffer = device->ringBuffer.GetValidByteCount();
+    if (isSource) {
+        return device->ringBuffer.GetBufferSize() - bytesInBuffer;
+    } else {
+        return bytesInBuffer;
+    }
+}
+
+INT64 DAUDIO_GetBytePosition(void* id, int isSource, INT64 javaBytePos) {
+    OSX_DirectAudioDevice *device = (OSX_DirectAudioDevice*)id;
+    INT64 position;
+
+    if (isSource) {
+        position = javaBytePos - device->ringBuffer.GetValidByteCount();
+    } else {
+        position = javaBytePos + device->ringBuffer.GetValidByteCount();
+    }
+
+    TRACE2("DAUDIO_GetBytePosition returns %lld (javaBytePos = %lld)\n", (long long)position, (long long)javaBytePos);
+    return position;
+}
+
+void DAUDIO_SetBytePosition(void* id, int isSource, INT64 javaBytePos) {
+    // no need javaBytePos (it's available in DAUDIO_GetBytePosition)
+}
+
+int DAUDIO_RequiresServicing(void* id, int isSource) {
+    return FALSE;
+}
+
+void DAUDIO_Service(void* id, int isSource) {
+    // unreachable
+}
+
+#endif  // USE_DAUDIO == TRUE
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.c b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.c
new file mode 100644
index 0000000..ef9c5ea
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.c
@@ -0,0 +1,550 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_ERROR
+//#define USE_TRACE
+
+#include <CoreAudio/CoreAudio.h>
+#include <IOKit/audio/IOAudioTypes.h>
+#include "Ports.h"
+#include "PLATFORM_API_MacOSX_Utils.h"
+
+#if USE_PORTS == TRUE
+
+/*
+ TODO
+
+ Test devices with >2 channels.
+ Compare control names and tree structure to other platforms.
+ Implement virtual controls (balance, pan, master volume).
+ */
+
+typedef struct {
+    struct PortMixer *mixer;
+
+    AudioObjectID control;
+    AudioClassID class; // kAudioVolumeControlClassID etc.
+    UInt32 scope; // input, output
+
+    void *jcontrol;
+    char *jcontrolType; // CONTROL_TYPE_VOLUME etc.
+
+    int channel; // master = 0, channels = 1 2 ...
+
+    AudioValueRange range;
+} PortControl;
+
+typedef struct {
+    AudioDeviceID deviceID;
+
+    // = # of ports on the mixer
+    // cached here in case the values can change
+    int numInputStreams;
+    int numOutputStreams;
+    // streams[0..numInputStreams-1] contains inputs,
+    // streams[numInputStreams..numInputStreams+numOutputStreams-1] contains outputs
+    AudioStreamID *streams;
+
+    int numDeviceControls;
+    PortControl *deviceControls;
+
+    int *numStreamControls;
+    PortControl **streamControls;
+} PortMixer;
+
+INT32 PORT_GetPortMixerCount() {
+    int count = GetAudioDeviceCount();
+    TRACE1("< PORT_GetPortMixerCount = %d\n", count);
+
+    return count;
+}
+
+INT32 PORT_GetPortMixerDescription(INT32 mixerIndex, PortMixerDescription* mixerDescription) {
+    AudioDeviceDescription description;
+
+    description.strLen = PORT_STRING_LENGTH;
+    description.name   = mixerDescription->name;
+    description.vendor = mixerDescription->vendor;
+    description.description = NULL;
+
+    /*
+     We can't fill out the 'version' and 'description' fields.
+     */
+
+    return GetAudioDeviceDescription(mixerIndex, &description);
+}
+
+void* PORT_Open(INT32 mixerIndex) {
+    AudioDeviceDescription description = {0};
+    PortMixer *mixer = calloc(1, sizeof(PortMixer));
+
+    GetAudioDeviceDescription(mixerIndex, &description);
+    mixer->deviceID = description.deviceID;
+    mixer->numInputStreams  = description.numInputStreams;
+    mixer->numOutputStreams = description.numOutputStreams;
+
+    if (mixer->numInputStreams || mixer->numOutputStreams) {
+        mixer->streams = calloc(mixer->numInputStreams + mixer->numOutputStreams, sizeof(AudioStreamID));
+
+        GetAudioObjectProperty(mixer->deviceID, kAudioDevicePropertyScopeInput, kAudioDevicePropertyStreams,
+                               mixer->numInputStreams * sizeof(AudioStreamID), mixer->streams, 0);
+
+        GetAudioObjectProperty(mixer->deviceID, kAudioDevicePropertyScopeOutput, kAudioDevicePropertyStreams,
+                               mixer->numOutputStreams * sizeof(AudioStreamID),
+                               mixer->streams + mixer->numInputStreams, 0);
+    }
+
+    TRACE1("< PORT_Open %p\n", mixer);
+    return mixer;
+}
+
+void PORT_Close(void* id) {
+    TRACE1("> PORT_Close %p\n", id);
+
+    if (id) {
+        PortMixer *mixer = id;
+        free(mixer->streams);
+        free(mixer);
+    }
+}
+
+INT32 PORT_GetPortCount(void* id) {
+    PortMixer *mixer = id;
+    int numStreams = mixer->numInputStreams + mixer->numOutputStreams;
+
+    TRACE1("< PORT_GetPortCount = %d\n", numStreams);
+    return numStreams;
+}
+
+INT32 PORT_GetPortType(void* id, INT32 portIndex) {
+    PortMixer *mixer = id;
+
+    AudioStreamID streamID = mixer->streams[portIndex];
+    UInt32 direction;
+    UInt32 terminalType;
+    UInt32 size;
+    int err, ret;
+
+    err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal, kAudioStreamPropertyTerminalType,
+                                 sizeof(terminalType), &terminalType, 1);
+    if (err) goto exit;
+
+    err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal, kAudioStreamPropertyDirection,
+                                 sizeof(direction), &direction, 1);
+    if (err) goto exit;
+
+    /*
+     Note that kAudioStreamPropertyTerminalType actually returns values from
+     IOAudioTypes.h, not the defined kAudioStreamTerminalType*.
+     */
+
+    if (direction) {
+        // input
+        switch (terminalType) {
+            case EXTERNAL_LINE_CONNECTOR:
+                ret = PORT_SRC_LINE_IN;
+                break;
+
+            case INPUT_MICROPHONE:
+                ret = PORT_SRC_MICROPHONE;
+                break;
+
+            case EXTERNAL_SPDIF_INTERFACE:
+                ret = PORT_SRC_UNKNOWN;
+                break;
+
+            default:
+                TRACE1("unknown input terminal type %#x\n", terminalType);
+#ifdef USE_TRACE
+                AudioObjectShow(mixer->deviceID);
+                AudioObjectShow(streamID);
+#endif
+                ret = PORT_SRC_UNKNOWN;
+        }
+    } else {
+        // output
+        switch (terminalType) {
+            case EXTERNAL_LINE_CONNECTOR:
+                ret = PORT_DST_LINE_OUT;
+                break;
+
+            case OUTPUT_SPEAKER:
+                ret = PORT_DST_SPEAKER;
+                break;
+
+            case OUTPUT_HEADPHONES:
+                ret = PORT_DST_HEADPHONE;
+                break;
+
+            case EXTERNAL_SPDIF_INTERFACE:
+                ret = PORT_DST_UNKNOWN;
+                break;
+
+            default:
+                TRACE1("unknown output terminal type %#x\n", terminalType);
+#ifdef USE_TRACE
+                AudioObjectShow(mixer->deviceID);
+                AudioObjectShow(streamID);
+#endif
+                ret = PORT_DST_UNKNOWN;
+        }
+    }
+
+    TRACE1("< PORT_GetPortType = %d\n", ret);
+    return ret;
+exit:
+    ERROR1("< PORT_GetPortType error %d\n", err);
+    return -1;
+}
+
+INT32 PORT_GetPortName(void* id, INT32 portIndex, char* name, INT32 len) {
+    PortMixer *mixer = id;
+    AudioStreamID streamID = mixer->streams[portIndex];
+
+    CFStringRef cfname = NULL;
+    OSStatus err = noErr;
+
+    err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyName,
+                                 sizeof(cfname), &cfname, 1);
+    if (err && err != kAudioHardwareUnknownPropertyError) goto exit;
+
+    if (!cfname) {
+        // use the device's name if the stream has no name (usually the case)
+        err = GetAudioObjectProperty(mixer->deviceID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyName,
+                                     sizeof(cfname), &cfname, 1);
+    }
+
+    if (cfname) {
+        CFStringGetCString(cfname, name, len, kCFStringEncodingUTF8);
+    }
+
+exit:
+    if (cfname) CFRelease(cfname);
+
+    TRACE1("< PORT_GetPortName %s\n", name);
+
+    return FALSE;
+}
+
+static void CreateVolumeControl(PortControlCreator *creator, PortControl *control)
+{
+    Float32 min = 0, max = 1, precision;
+    AudioValueRange *range = &control->range;
+    UInt32 size;
+
+    control->jcontrolType = CONTROL_TYPE_VOLUME;
+
+    GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioLevelControlPropertyDecibelRange,
+                           sizeof(control->range), &control->range, 1);
+    precision = 1. / (range->mMaximum - range->mMinimum);
+
+    control->jcontrol = creator->newFloatControl(creator, control, CONTROL_TYPE_VOLUME, min, max, precision, "");
+}
+
+static void CreateMuteControl(PortControlCreator *creator, PortControl *control)
+{
+    control->jcontrolType = CONTROL_TYPE_MUTE;
+    control->jcontrol = creator->newBooleanControl(creator, control, CONTROL_TYPE_MUTE);
+}
+
+void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
+    PortMixer *mixer = id;
+    AudioStreamID streamID = mixer->streams[portIndex];
+
+    UInt32 size;
+    OSStatus err;
+    int i;
+
+    int numVolumeControls = 0, numMuteControls = 0; // not counting the master
+    int hasChannelVolume  = 0, hasChannelMute  = 0;
+    PortControl *masterVolume = NULL, *masterMute = NULL;
+
+    UInt32 wantedScope = portIndex < mixer->numInputStreams ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+
+    // initialize the device controls if this is the first stream
+    if (!mixer->numDeviceControls) {
+        // numDeviceControls / numStreamControls are overestimated
+        // because we don't actually filter by if the owned objects are controls
+        err = GetAudioObjectPropertySize(mixer->deviceID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyOwnedObjects,
+                                         &size);
+        if (err) goto exit;
+
+        mixer->numDeviceControls = size / sizeof(AudioObjectID);
+
+        if (mixer->numDeviceControls) {
+            AudioObjectID *controlIDs = calloc(mixer->numDeviceControls, sizeof(AudioObjectID));
+            mixer->deviceControls     = calloc(mixer->numDeviceControls, sizeof(PortControl));
+
+            err = GetAudioObjectProperty(mixer->deviceID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyOwnedObjects,
+                                         mixer->numDeviceControls * sizeof(AudioObjectID), controlIDs, 1);
+            if (err) goto exit;
+
+            for (i = 0; i < mixer->numDeviceControls; i++) {
+                PortControl *control = &mixer->deviceControls[i];
+
+                control->control = controlIDs[i];
+                control->mixer = mixer;
+
+                GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyClass,
+                                       sizeof(control->class), &control->class, 1);
+                err = GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioControlPropertyElement,
+                                       sizeof(control->channel), &control->channel, 1);
+
+                if (err) { // not a control
+                    control->class = 0;
+                    continue;
+                }
+
+                GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioControlPropertyScope,
+                                       sizeof(control->scope), &control->scope, 1);
+
+                TRACE3("%.4s control, channel %d scope %.4s\n", &control->class, control->channel, &control->scope);
+            }
+        }
+    }
+
+    // count the number of device controls with the appropriate scope
+    if (mixer->numDeviceControls) {
+        for (i = 0; i < mixer->numDeviceControls; i++) {
+            PortControl *control = &mixer->deviceControls[i];
+
+            if (control->scope != wantedScope)
+                continue;
+
+            switch (control->class) {
+                case kAudioVolumeControlClassID:
+                    if (control->channel == 0)
+                        masterVolume = control;
+                    else {
+                        numVolumeControls++;
+                        hasChannelVolume = 1;
+                    }
+                    break;
+
+                case kAudioMuteControlClassID:
+                    if (control->channel == 0)
+                        masterMute = control;
+                    else {
+                        numMuteControls++;
+                        hasChannelMute = 1;
+                    }
+                    break;
+            }
+        }
+    }
+
+    TRACE4("volume: channel %d master %d, mute: channel %d master %d\n", numVolumeControls, masterVolume != NULL, numMuteControls, masterMute != NULL);
+
+    if (masterVolume) {
+        if (!masterVolume->jcontrol)
+            CreateVolumeControl(creator, masterVolume);
+        creator->addControl(creator, masterVolume->jcontrol);
+    }
+
+    if (masterMute) {
+        if (!masterMute->jcontrol)
+            CreateMuteControl(creator, masterMute);
+        creator->addControl(creator, masterMute->jcontrol);
+    }
+
+    if (numVolumeControls) {
+        void **jControls = calloc(numVolumeControls, sizeof(void*));
+        int j = 0;
+        for (i = 0; i < mixer->numDeviceControls && j < numVolumeControls; i++) {
+            PortControl *control = &mixer->deviceControls[i];
+
+            if (control->class != kAudioVolumeControlClassID || control->channel == 0 || control->scope != wantedScope)
+                continue;
+
+            if (!control->jcontrol)
+                CreateVolumeControl(creator, control);
+            jControls[j++] = control->jcontrol;
+        }
+
+        void *compoundControl = creator->newCompoundControl(creator, "Volume", jControls, numVolumeControls);
+        creator->addControl(creator, compoundControl);
+        free(jControls);
+    }
+
+    if (numMuteControls) {
+        void **jControls = calloc(numMuteControls, sizeof(void*));
+        int j = 0;
+        for (i = 0; i < mixer->numDeviceControls && j < numMuteControls; i++) {
+            PortControl *control = &mixer->deviceControls[i];
+
+            if (control->class != kAudioMuteControlClassID || control->channel == 0 || control->scope != wantedScope)
+                continue;
+
+            if (!control->jcontrol)
+                CreateMuteControl(creator, control);
+            jControls[j++] = control->jcontrol;
+        }
+
+        void *compoundControl = creator->newCompoundControl(creator, "Mute", jControls, numMuteControls);
+        creator->addControl(creator, compoundControl);
+        free(jControls);
+    }
+
+    if (!mixer->numStreamControls)
+        mixer->numStreamControls = calloc(mixer->numInputStreams + mixer->numOutputStreams, sizeof(int));
+
+    err = GetAudioObjectPropertySize(streamID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyOwnedObjects,
+                                     &size);
+    if (err) goto exit;
+
+    mixer->numStreamControls[portIndex] = size / sizeof(AudioObjectID);
+
+    TRACE2("%d controls on device, %d on stream\n", mixer->numDeviceControls, mixer->numStreamControls[portIndex]);
+
+exit:
+    if (err) {
+        ERROR1("PORT_GetControls err %.4s\n", &err);
+        free(mixer->deviceControls);
+    }
+
+    TRACE0("< PORT_GetControls\n");
+}
+
+INT32 PORT_GetIntValue(void* controlIDV) {
+    PortControl *control = controlIDV;
+    UInt32 value = 0;
+    OSStatus err = 0;
+    UInt32 size;
+
+    switch (control->class) {
+        case kAudioMuteControlClassID:
+        {
+            err = GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal,
+                                         kAudioBooleanControlPropertyValue, sizeof(value), &value, 1);
+            if (err) goto exit;
+        }
+            break;
+
+        default:
+            ERROR0("SetIntValue requested for non-Int control\n");
+            goto exit;
+    }
+
+    TRACE1("< PORT_GetIntValue = %d\n", value);
+    return value;
+
+exit:
+    if (err) {
+        ERROR1("PORT_GetIntValue err %d\n", err);
+    }
+    return FALSE;
+}
+
+void PORT_SetIntValue(void* controlIDV, INT32 value) {
+    TRACE1("> PORT_SetIntValue = %d\n", value);
+    PortControl *control = controlIDV;
+    OSStatus err = 0;
+
+    switch (control->class) {
+        case kAudioMuteControlClassID:
+        {
+            const AudioObjectPropertyAddress address =
+            { kAudioBooleanControlPropertyValue, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+            err = AudioObjectSetPropertyData(control->control, &address, 0, NULL, sizeof(value), &value);
+            if (err) goto exit;
+        }
+            break;
+
+        default:
+            ERROR0("SetIntValue requested for non-Int control\n");
+    }
+
+    return;
+
+exit:
+    if (err) {
+        ERROR1("PORT_SetIntValue err %d\n", err);
+    }
+}
+
+float PORT_GetFloatValue(void* controlIDV) {
+    PortControl *control = controlIDV;
+    Float32 value = 0;
+    OSStatus err = 0;
+    UInt32 size;
+
+    switch (control->class) {
+        case kAudioVolumeControlClassID:
+        {
+            err = GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal,
+                                             kAudioLevelControlPropertyDecibelValue, sizeof(value), &value, 1);
+            if (err) goto exit;
+
+            // convert decibel to 0-1 logarithmic
+            value = (value - control->range.mMinimum) / (control->range.mMaximum - control->range.mMinimum);
+        }
+            break;
+
+        default:
+            ERROR0("GetFloatValue requested for non-Float control\n");
+            break;
+    }
+
+    TRACE1("< PORT_GetFloatValue = %f\n", value);
+    return value;
+
+exit:
+    if (err) {
+        ERROR1("PORT_GetFloatValue err %d\n", err);
+    }
+    return 0;
+}
+
+void PORT_SetFloatValue(void* controlIDV, float value) {
+    TRACE1("> PORT_SetFloatValue = %f\n", value);
+    PortControl *control = controlIDV;
+    OSStatus err = 0;
+
+    switch (control->class) {
+        case kAudioVolumeControlClassID:
+        {
+            const AudioObjectPropertyAddress address =
+            { kAudioLevelControlPropertyDecibelValue, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+
+            value = (value * (control->range.mMaximum - control->range.mMinimum)) + control->range.mMinimum;
+            err = AudioObjectSetPropertyData(control->control, &address, 0, NULL, sizeof(value), &value);
+            if (err) goto exit;
+        }
+            break;
+
+        default:
+            ERROR0("SetFloatValue requested for non-Float control\n");
+            break;
+    }
+
+    return;
+
+exit:
+    if (err) {
+        ERROR1("PORT_GetFloatValue err %d\n", err);
+    }
+}
+
+#endif // USE_PORTS
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.cpp b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.cpp
new file mode 100644
index 0000000..102c2a5
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.cpp
@@ -0,0 +1,528 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_ERROR
+//#define USE_TRACE
+
+#include <CoreAudio/CoreAudio.h>
+#include <IOKit/audio/IOAudioTypes.h>
+
+#include "PLATFORM_API_MacOSX_Utils.h"
+
+extern "C" {
+#include "Ports.h"
+}
+
+#if USE_PORTS == TRUE
+
+/*
+ TODO
+
+ Test devices with >2 channels.
+ Compare control names and tree structure to other platforms.
+ Implement virtual controls (balance, pan, master volume).
+ */
+
+static DeviceList deviceCache;
+
+struct PortMixer;
+
+struct PortControl {
+    PortMixer *mixer;
+
+    AudioObjectID control;
+    AudioClassID classID; // kAudioVolumeControlClassID etc.
+    UInt32 scope; // input, output
+
+    void *jcontrol;
+    char *jcontrolType; // CONTROL_TYPE_VOLUME etc.
+
+    int channel; // master = 0, channels = 1 2 ...
+
+    AudioValueRange range;
+};
+
+struct PortMixer {
+    AudioDeviceID deviceID;
+
+    // = # of ports on the mixer
+    // cached here in case the values can change
+    int numInputStreams;
+    int numOutputStreams;
+    // streams[0..numInputStreams-1] contains inputs,
+    // streams[numInputStreams..numInputStreams+numOutputStreams-1] contains outputs
+    AudioStreamID *streams;
+
+    int numDeviceControls;
+    PortControl *deviceControls;
+
+    int *numStreamControls;
+    PortControl **streamControls;
+};
+
+INT32 PORT_GetPortMixerCount() {
+    deviceCache.Refresh();
+    int count = deviceCache.GetCount();
+    TRACE1("< PORT_GetPortMixerCount = %d\n", count);
+
+    return count;
+}
+
+INT32 PORT_GetPortMixerDescription(INT32 mixerIndex, PortMixerDescription* mixerDescription) {
+    bool result = deviceCache.GetDeviceInfo(mixerIndex, NULL, PORT_STRING_LENGTH,
+            mixerDescription->name, mixerDescription->vendor, mixerDescription->description, mixerDescription->version);
+
+    return result ? TRUE : FALSE;
+}
+
+void* PORT_Open(INT32 mixerIndex) {
+    OSStatus err;
+    PortMixer *mixer = (PortMixer *)calloc(1, sizeof(PortMixer));
+    memset(mixer, 0, sizeof(mixer));
+
+    mixer->deviceID = deviceCache.GetDeviceID(mixerIndex);
+    if (mixer->deviceID != 0) {
+        UInt32 sizeIn = 0, sizeOut = 0;
+        GetAudioObjectPropertySize(mixer->deviceID, kAudioDevicePropertyScopeInput, kAudioDevicePropertyStreams, &sizeIn);
+        GetAudioObjectPropertySize(mixer->deviceID, kAudioDevicePropertyScopeOutput, kAudioDevicePropertyStreams, &sizeOut);
+
+        if (sizeIn > 0 || sizeOut > 0) {
+            mixer->numInputStreams  = sizeIn / sizeof(AudioStreamID);
+            mixer->numOutputStreams = sizeOut / sizeof(AudioStreamID);
+
+            mixer->streams = (AudioStreamID *)calloc(mixer->numInputStreams + mixer->numOutputStreams, sizeof(AudioStreamID));
+
+            GetAudioObjectProperty(mixer->deviceID, kAudioDevicePropertyScopeInput, kAudioDevicePropertyStreams,
+                                mixer->numInputStreams * sizeof(AudioStreamID), mixer->streams, 0);
+            GetAudioObjectProperty(mixer->deviceID, kAudioDevicePropertyScopeOutput, kAudioDevicePropertyStreams,
+                                mixer->numOutputStreams * sizeof(AudioStreamID),
+                                mixer->streams + mixer->numInputStreams, 0);
+        }
+    }
+
+    TRACE1("< PORT_Open %p\n", mixer);
+    return mixer;
+}
+
+void PORT_Close(void* id) {
+    PortMixer *mixer = (PortMixer *)id;
+    TRACE1("> PORT_Close %p\n", id);
+
+    if (mixer) {
+        free(mixer->streams);
+        free(mixer);
+    }
+}
+
+INT32 PORT_GetPortCount(void* id) {
+    PortMixer *mixer = (PortMixer *)id;
+    int numStreams = mixer->numInputStreams + mixer->numOutputStreams;
+
+    TRACE1("< PORT_GetPortCount = %d\n", numStreams);
+    return numStreams;
+}
+
+INT32 PORT_GetPortType(void* id, INT32 portIndex) {
+    PortMixer *mixer = (PortMixer *)id;
+
+    AudioStreamID streamID = mixer->streams[portIndex];
+    UInt32 direction;
+    UInt32 terminalType;
+    UInt32 size;
+    INT32 ret = 0;
+    OSStatus err;
+
+    err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal, kAudioStreamPropertyTerminalType,
+                                 sizeof(terminalType), &terminalType, 1);
+    if (err) {
+        OS_ERROR1(err, "PORT_GetPortType(kAudioStreamPropertyTerminalType), portIndex=%d", portIndex);
+        return 0;
+    }
+    err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal, kAudioStreamPropertyDirection,
+                                 sizeof(direction), &direction, 1);
+    if (err) {
+        OS_ERROR1(err, "PORT_GetPortType(kAudioStreamPropertyDirection), portIndex=%d", portIndex);
+        return 0;
+    }
+
+    // Note that kAudioStreamPropertyTerminalType actually returns values from
+    // IOAudioTypes.h, not the defined kAudioStreamTerminalType*.
+
+    if (direction) {
+        // input
+        switch (terminalType) {
+        case EXTERNAL_LINE_CONNECTOR:
+            ret = PORT_SRC_LINE_IN;
+            break;
+        case INPUT_MICROPHONE:
+            ret = PORT_SRC_MICROPHONE;
+            break;
+        case EXTERNAL_SPDIF_INTERFACE:
+            ret = PORT_SRC_UNKNOWN;
+            break;
+        default:
+            TRACE1("unknown input terminal type %#x\n", terminalType);
+#ifdef USE_TRACE
+            AudioObjectShow(mixer->deviceID);
+            AudioObjectShow(streamID);
+#endif
+            ret = PORT_SRC_UNKNOWN;
+        }
+    } else {
+        // output
+        switch (terminalType) {
+        case EXTERNAL_LINE_CONNECTOR:
+            ret = PORT_DST_LINE_OUT;
+            break;
+        case OUTPUT_SPEAKER:
+            ret = PORT_DST_SPEAKER;
+            break;
+        case OUTPUT_HEADPHONES:
+            ret = PORT_DST_HEADPHONE;
+            break;
+        case EXTERNAL_SPDIF_INTERFACE:
+            ret = PORT_DST_UNKNOWN;
+            break;
+        default:
+            TRACE1("unknown output terminal type %#x\n", terminalType);
+#ifdef USE_TRACE
+            AudioObjectShow(mixer->deviceID);
+            AudioObjectShow(streamID);
+#endif
+            ret = PORT_DST_UNKNOWN;
+        }
+    }
+
+    TRACE2("< PORT_GetPortType (portIndex=%d) = %d\n", portIndex, ret);
+    return ret;
+}
+
+INT32 PORT_GetPortName(void* id, INT32 portIndex, char* name, INT32 len) {
+    PortMixer *mixer = (PortMixer *)id;
+    AudioStreamID streamID = mixer->streams[portIndex];
+
+    CFStringRef cfname = NULL;
+    OSStatus err = noErr;
+
+    err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyName,
+                                 sizeof(cfname), &cfname, 1);
+    if (err && err != kAudioHardwareUnknownPropertyError) {
+        OS_ERROR1(err, "PORT_GetPortName(stream name), portIndex=%d", portIndex);
+        return FALSE;
+    }
+
+    if (!cfname) {
+        // use the device's name if the stream has no name (usually the case)
+        err = GetAudioObjectProperty(mixer->deviceID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyName,
+                                     sizeof(cfname), &cfname, 1);
+        if (err) {
+            OS_ERROR1(err, "PORT_GetPortName(device name), portIndex=%d", portIndex);
+            return FALSE;
+        }
+    }
+
+    if (cfname) {
+        CFStringGetCString(cfname, name, len, kCFStringEncodingUTF8);
+        CFRelease(cfname);
+    }
+
+    TRACE2("< PORT_GetPortName (portIndex = %d) = %s\n", portIndex, name);
+    return TRUE;
+}
+
+static void CreateVolumeControl(PortControlCreator *creator, PortControl *control)
+{
+    Float32 min = 0, max = 1, precision;
+    AudioValueRange *range = &control->range;
+    UInt32 size;
+
+    control->jcontrolType = CONTROL_TYPE_VOLUME;
+
+    GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioLevelControlPropertyDecibelRange,
+                           sizeof(control->range), &control->range, 1);
+    precision = 1. / (range->mMaximum - range->mMinimum);
+
+    control->jcontrol = creator->newFloatControl(creator, control, CONTROL_TYPE_VOLUME, min, max, precision, "");
+}
+
+static void CreateMuteControl(PortControlCreator *creator, PortControl *control)
+{
+    control->jcontrolType = CONTROL_TYPE_MUTE;
+    control->jcontrol = creator->newBooleanControl(creator, control, CONTROL_TYPE_MUTE);
+}
+
+void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
+    PortMixer *mixer = (PortMixer *)id;
+    AudioStreamID streamID = mixer->streams[portIndex];
+
+    UInt32 size;
+    OSStatus err;
+    int i;
+
+    int numVolumeControls = 0, numMuteControls = 0; // not counting the master
+    int hasChannelVolume  = 0, hasChannelMute  = 0;
+    PortControl *masterVolume = NULL, *masterMute = NULL;
+
+    UInt32 wantedScope = portIndex < mixer->numInputStreams ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+
+    // initialize the device controls if this is the first stream
+    if (!mixer->numDeviceControls) {
+        // numDeviceControls / numStreamControls are overestimated
+        // because we don't actually filter by if the owned objects are controls
+        err = GetAudioObjectPropertySize(mixer->deviceID, kAudioObjectPropertyScopeGlobal,
+                                         kAudioObjectPropertyOwnedObjects, &size);
+        mixer->numDeviceControls = size / sizeof(AudioObjectID);
+
+        if (err == noErr && mixer->numDeviceControls) {
+            AudioObjectID controlIDs[mixer->numDeviceControls];
+            mixer->deviceControls = (PortControl *)calloc(mixer->numDeviceControls, sizeof(PortControl));
+
+            err = GetAudioObjectProperty(mixer->deviceID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyOwnedObjects,
+                                         sizeof(controlIDs), &controlIDs, 1);
+
+            if (err == noErr) {
+                for (i = 0; i < mixer->numDeviceControls; i++) {
+                    PortControl *control = &mixer->deviceControls[i];
+
+                    control->control = controlIDs[i];
+                    control->mixer = mixer;
+
+                    GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyClass,
+                                           sizeof(control->classID), &control->classID, 1);
+                    err = GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioControlPropertyElement,
+                                           sizeof(control->channel), &control->channel, 1);
+
+                    if (err) { // not a control
+                        control->classID = 0;
+                        continue;
+                    }
+
+                    GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal, kAudioControlPropertyScope,
+                                           sizeof(control->scope), &control->scope, 1);
+
+                    TRACE3("%.4s control, channel %d scope %.4s\n", &control->classID, control->channel, &control->scope);
+                }
+            }
+        }
+        if (err) {
+            mixer->numDeviceControls = 0;
+            if (mixer->deviceControls) {
+                free(mixer->deviceControls);
+                mixer->deviceControls = NULL;
+            }
+        }
+    }
+
+    // count the number of device controls with the appropriate scope
+    if (mixer->numDeviceControls) {
+        for (i = 0; i < mixer->numDeviceControls; i++) {
+            PortControl *control = &mixer->deviceControls[i];
+
+            if (control->scope != wantedScope)
+                continue;
+
+            switch (control->classID) {
+            case kAudioVolumeControlClassID:
+                if (control->channel == 0)
+                    masterVolume = control;
+                else {
+                    numVolumeControls++;
+                    hasChannelVolume = 1;
+                }
+                break;
+            case kAudioMuteControlClassID:
+                if (control->channel == 0)
+                    masterMute = control;
+                else {
+                    numMuteControls++;
+                    hasChannelMute = 1;
+                }
+                break;
+            }
+        }
+    }
+
+    TRACE4("volume: channel %d master %d, mute: channel %d master %d\n", numVolumeControls, masterVolume != NULL, numMuteControls, masterMute != NULL);
+
+    if (masterVolume) {
+        if (!masterVolume->jcontrol)
+            CreateVolumeControl(creator, masterVolume);
+        creator->addControl(creator, masterVolume->jcontrol);
+    }
+
+    if (masterMute) {
+        if (!masterMute->jcontrol)
+            CreateMuteControl(creator, masterMute);
+        creator->addControl(creator, masterMute->jcontrol);
+    }
+
+    if (numVolumeControls) {
+        void **jControls = (void **)calloc(numVolumeControls, sizeof(void*));
+        int j = 0;
+        for (i = 0; i < mixer->numDeviceControls && j < numVolumeControls; i++) {
+            PortControl *control = &mixer->deviceControls[i];
+
+            if (control->classID != kAudioVolumeControlClassID || control->channel == 0 || control->scope != wantedScope)
+                continue;
+
+            if (!control->jcontrol)
+                CreateVolumeControl(creator, control);
+            jControls[j++] = control->jcontrol;
+        }
+
+        void *compoundControl = creator->newCompoundControl(creator, "Volume", jControls, numVolumeControls);
+        creator->addControl(creator, compoundControl);
+        free(jControls);
+    }
+
+    if (numMuteControls) {
+        void **jControls = (void **)calloc(numMuteControls, sizeof(void*));
+        int j = 0;
+        for (i = 0; i < mixer->numDeviceControls && j < numMuteControls; i++) {
+            PortControl *control = &mixer->deviceControls[i];
+
+            if (control->classID != kAudioMuteControlClassID || control->channel == 0 || control->scope != wantedScope)
+                continue;
+
+            if (!control->jcontrol)
+                CreateMuteControl(creator, control);
+            jControls[j++] = control->jcontrol;
+        }
+
+        void *compoundControl = creator->newCompoundControl(creator, "Mute", jControls, numMuteControls);
+        creator->addControl(creator, compoundControl);
+        free(jControls);
+    }
+
+    if (!mixer->numStreamControls)
+        mixer->numStreamControls = (int *)calloc(mixer->numInputStreams + mixer->numOutputStreams, sizeof(int));
+
+    err = GetAudioObjectPropertySize(streamID, kAudioObjectPropertyScopeGlobal,
+                                     kAudioObjectPropertyOwnedObjects, &size);
+    if (err != noErr) {
+        mixer->numStreamControls[portIndex] = size / sizeof(AudioObjectID);
+    }
+
+    TRACE2("< PORT_GetControls, %d controls on device, %d on stream\n", mixer->numDeviceControls, mixer->numStreamControls[portIndex]);
+}
+
+INT32 PORT_GetIntValue(void* controlIDV) {
+    PortControl *control = (PortControl *)controlIDV;
+    UInt32 value = 0;
+    OSStatus err = 0;
+    UInt32 size;
+
+    switch (control->classID) {
+    case kAudioMuteControlClassID:
+        err = GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal,
+                                     kAudioBooleanControlPropertyValue, sizeof(value), &value, 1);
+        break;
+    default:
+        ERROR0("PORT_GetIntValue requested for non-Int control\n");
+        return 0;
+    }
+
+    if (err) {
+        OS_ERROR0(err, "PORT_GetIntValue");
+        return 0;
+    }
+
+    TRACE1("< PORT_GetIntValue = %d\n", value);
+    return value;
+}
+
+void PORT_SetIntValue(void* controlIDV, INT32 value) {
+    TRACE1("> PORT_SetIntValue = %d\n", value);
+    PortControl *control = (PortControl *)controlIDV;
+    OSStatus err = noErr;
+
+    switch (control->classID) {
+    case kAudioMuteControlClassID:
+        err = SetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal,
+                                     kAudioBooleanControlPropertyValue, sizeof(value), &value);
+        break;
+    default:
+        ERROR0("PORT_SetIntValue requested for non-Int control\n");
+        return;
+    }
+
+    if (err) {
+        OS_ERROR0(err, "PORT_SetIntValue");
+        return;
+    }
+}
+
+float PORT_GetFloatValue(void* controlIDV) {
+    PortControl *control = (PortControl *)controlIDV;
+    Float32 value = 0;
+    OSStatus err = 0;
+    UInt32 size;
+
+    switch (control->classID) {
+    case kAudioVolumeControlClassID:
+        err = GetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal,
+                                     kAudioLevelControlPropertyDecibelValue, sizeof(value), &value, 1);
+        if (err == noErr) {
+            // convert decibel to 0-1 logarithmic
+            value = (value - control->range.mMinimum) / (control->range.mMaximum - control->range.mMinimum);
+        }
+        break;
+    default:
+        ERROR0("GetFloatValue requested for non-Float control\n");
+        break;
+    }
+
+    if (err) {
+        OS_ERROR0(err, "PORT_GetFloatValue");
+        return 0;
+    }
+
+    TRACE1("< PORT_GetFloatValue = %f\n", value);
+    return value;
+}
+
+void PORT_SetFloatValue(void* controlIDV, float value) {
+    TRACE1("> PORT_SetFloatValue = %f\n", value);
+    PortControl *control = (PortControl *)controlIDV;
+    OSStatus err = 0;
+
+    switch (control->classID) {
+    case kAudioVolumeControlClassID:
+        value = (value * (control->range.mMaximum - control->range.mMinimum)) + control->range.mMinimum;
+        err = SetAudioObjectProperty(control->control, kAudioObjectPropertyScopeGlobal,
+                                     kAudioLevelControlPropertyDecibelValue, sizeof(value), &value);
+        break;
+    default:
+        ERROR0("PORT_SetFloatValue requested for non-Float control\n");
+        break;
+    }
+
+    if (err) {
+        OS_ERROR0(err, "PORT_SetFloatValue");
+        return;
+    }
+}
+
+#endif // USE_PORTS
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.c b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.c
new file mode 100644
index 0000000..6655f63
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_TRACE
+//#define USE_ERROR
+
+#include "PLATFORM_API_MacOSX_Utils.h"
+#include "Ports.h"
+
+typedef struct OSXAudioDevice {
+    AudioDeviceID deviceID;
+    int numInputStreams;
+    int numOutputStreams;
+
+    int numInputChannels;
+    int numOutputChannels;
+    Float64 inputSampleRate;
+} OSXAudioDevice;
+
+typedef struct {
+    int numDevices;
+    OSXAudioDevice *devices;
+
+    OSXAudioDevice defaultAudioDevice;
+} AudioDeviceContext;
+
+static AudioDeviceContext deviceCtx;
+
+static int UpdateAudioDeviceInfo(OSXAudioDevice *device)
+{
+    AudioStreamBasicDescription asbd = {0};
+    AudioDeviceID deviceID, inputDeviceID;
+    int streamID, inputStreamID;
+    OSStatus err = noErr;
+    UInt32 size;
+
+    if (device->deviceID == 0) {
+        err = GetAudioObjectProperty(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal, kAudioHardwarePropertyDefaultOutputDevice,
+                               sizeof(deviceID), &deviceID, 1);
+        if (err) goto exit;
+        err = GetAudioObjectProperty(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal, kAudioHardwarePropertyDefaultInputDevice,
+                               sizeof(inputDeviceID), &inputDeviceID, 1);
+        if (err) goto exit;
+    } else {
+        inputDeviceID = deviceID = device->deviceID;
+    }
+
+    err = GetAudioObjectPropertySize(inputDeviceID, kAudioDevicePropertyScopeInput, kAudioDevicePropertyStreams,
+                               &size);
+    device->numInputStreams  = size / sizeof(AudioStreamID);
+    if (err) goto exit;
+
+    err = GetAudioObjectPropertySize(deviceID, kAudioDevicePropertyScopeOutput, kAudioDevicePropertyStreams,
+                               &size);
+    device->numOutputStreams = size / sizeof(AudioStreamID);
+    if (err) goto exit;
+
+    if (device->numOutputStreams) {
+        err = GetAudioObjectProperty(deviceID, kAudioDevicePropertyScopeOutput, kAudioDevicePropertyStreams,
+                                     sizeof(streamID), &streamID, 1);
+        if (err) goto exit;
+
+        if (streamID) {
+            err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal, kAudioStreamPropertyVirtualFormat,
+                                         sizeof(asbd), &asbd, 1);
+            if (err) goto exit;
+
+            device->numOutputChannels = asbd.mChannelsPerFrame;
+        }
+    }
+
+    if (device->numInputStreams) {
+        err = GetAudioObjectProperty(inputDeviceID, kAudioDevicePropertyScopeInput, kAudioDevicePropertyStreams,
+                                     sizeof(inputStreamID), &inputStreamID, 1);
+        if (err) goto exit;
+
+        if (streamID) {
+            err = GetAudioObjectProperty(inputStreamID, kAudioObjectPropertyScopeGlobal, kAudioStreamPropertyVirtualFormat,
+                                         sizeof(asbd), &asbd, 1);
+            if (err) goto exit;
+
+            device->numInputChannels = asbd.mChannelsPerFrame;
+            device->inputSampleRate  = asbd.mSampleRate;
+        }
+    }
+
+    return noErr;
+
+exit:
+    ERROR1("UpdateAudioDeviceInfo err %#x\n", err);
+    return err;
+}
+
+int GetAudioDeviceCount()
+{
+    const AudioObjectPropertyAddress devicesAddress = {kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster};
+    UInt32 size;
+    int i;
+
+    if (!deviceCtx.numDevices) {
+        GetAudioObjectPropertySize(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal, kAudioHardwarePropertyDevices,
+                                   &size);
+        deviceCtx.numDevices = size / sizeof(AudioDeviceID);
+
+        if (deviceCtx.numDevices) {
+            AudioDeviceID deviceIDs[deviceCtx.numDevices];
+            deviceCtx.devices = calloc(deviceCtx.numDevices, sizeof(OSXAudioDevice));
+
+            size = deviceCtx.numDevices * sizeof(AudioDeviceID);
+            AudioObjectGetPropertyData(kAudioObjectSystemObject, &devicesAddress, 0, NULL, &size, deviceIDs);
+            deviceCtx.numDevices = size / sizeof(AudioDeviceID); // in case of an unplug
+
+            for (i = 0; i < deviceCtx.numDevices; i++) {
+                OSXAudioDevice *device = &deviceCtx.devices[i];
+
+                device->deviceID = deviceIDs[i];
+                UpdateAudioDeviceInfo(device);
+            }
+        }
+
+        UpdateAudioDeviceInfo(&deviceCtx.defaultAudioDevice);
+    }
+
+    return deviceCtx.numDevices;
+}
+
+int GetAudioDeviceDescription(int index, AudioDeviceDescription *description)
+{
+    OSXAudioDevice *device;
+    CFStringRef name = NULL, vendor = NULL;
+    OSStatus err = noErr;
+    int isDefault = index == -1;
+    UInt32 size;
+
+    device = isDefault ? &deviceCtx.defaultAudioDevice : &deviceCtx.devices[index];
+
+    description->deviceID         = device->deviceID;
+    description->numInputStreams  = device->numInputStreams;
+    description->numOutputStreams = device->numOutputStreams;
+    description->numInputChannels = device->numInputChannels;
+    description->numOutputChannels= device->numOutputChannels;
+    description->inputSampleRate  = device->inputSampleRate;
+
+    if (isDefault) {
+        if (description->name)
+            strncpy(description->name, "Default Audio Device", description->strLen);
+        if (description->description)
+            strncpy(description->description, "Default Audio Device", description->strLen);
+    } else {
+        if (description->name) {
+            err = GetAudioObjectProperty(device->deviceID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyName,
+                                         sizeof(name), &name, 1);
+            if (err) goto exit;
+
+            CFStringGetCString(name, description->name, description->strLen, kCFStringEncodingUTF8);
+            if (description->description)
+                CFStringGetCString(name, description->description, description->strLen, kCFStringEncodingUTF8);
+        }
+
+        if (description->vendor) {
+            err = GetAudioObjectProperty(device->deviceID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyManufacturer,
+                                         sizeof(vendor), &vendor, 1);
+            if (err) goto exit;
+
+            CFStringGetCString(vendor, description->vendor, description->strLen, kCFStringEncodingUTF8);
+        }
+    }
+
+exit:
+    if (err) {
+        ERROR1("GetAudioDeviceDescription error %.4s\n", &err);
+    }
+    if (name)   CFRelease(name);
+    if (vendor) CFRelease(vendor);
+
+    return err ? FALSE : TRUE;
+}
+
+OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector property, UInt32 size, void *data, int checkSize)
+{
+    const AudioObjectPropertyAddress address = {property, scope, kAudioObjectPropertyElementMaster};
+    UInt32 oldSize = size;
+    OSStatus err;
+
+    err = AudioObjectGetPropertyData(object, &address, 0, NULL, &size, data);
+
+    if (!err && checkSize && size != oldSize)
+        return kAudioHardwareBadPropertySizeError;
+    return err;
+}
+
+OSStatus GetAudioObjectPropertySize(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector property, UInt32 *size)
+{
+    const AudioObjectPropertyAddress address = {property, scope, kAudioObjectPropertyElementMaster};
+    OSStatus err;
+
+    err = AudioObjectGetPropertyDataSize(object, &address, 0, NULL, size);
+
+    return err;
+}
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.cpp b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.cpp
new file mode 100644
index 0000000..661622c
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.cpp
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_TRACE
+//#define USE_ERROR
+
+#include "PLATFORM_API_MacOSX_Utils.h"
+
+int MACOSX_DAUDIO_Init() {
+    static int initialized = 0;
+    if (!initialized) {
+        CFRunLoopRef runLoop = NULL;
+
+        OSStatus err = SetAudioObjectProperty(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal,
+            kAudioHardwarePropertyRunLoop, sizeof(CFRunLoopRef), &runLoop);
+
+        if (err) {
+            OS_ERROR0(err, "MACOSX_DAUDIO_Init(kAudioHardwarePropertyRunLoop)");
+        } else {
+            TRACE0("MACOSX_DAUDIO_Init(kAudioHardwarePropertyRunLoop): OK\n");
+            initialized = 1;
+        }
+    }
+    return initialized;
+}
+
+DeviceList::DeviceList(): count(0), devices(NULL) {
+    MACOSX_DAUDIO_Init();
+
+    AudioObjectPropertyAddress address = {kAudioHardwarePropertyDevices,
+        kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster};
+    OSStatus err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &address, NotificationCallback, this);
+    if (err) {
+        OS_ERROR0(err, "AudioObjectAddPropertyListener(kAudioHardwarePropertyDevices)");
+    } else {
+        TRACE0("AudioObjectAddPropertyListener(kAudioHardwarePropertyDevices): OK\n");
+    }
+}
+
+DeviceList::~DeviceList() {
+    Free();
+
+    AudioObjectPropertyAddress address = {kAudioHardwarePropertyDevices,
+        kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster};
+    AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &address, NotificationCallback, this);
+}
+
+OSStatus DeviceList::Refresh() {
+    MutexLock::Locker locker(lock);
+    Free();
+
+    OSStatus err;
+    UInt32 size;
+    err = GetAudioObjectPropertySize(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal, kAudioHardwarePropertyDevices, &size);
+    if (err == noErr) {
+        devices = (AudioDeviceID *)malloc(size);
+        err = GetAudioObjectProperty(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal, kAudioHardwarePropertyDevices, &size, devices);
+        if (err == noErr) {
+            count = size/sizeof(AudioDeviceID);
+        }
+    }
+    if (err) {
+        OS_ERROR0(err, "DeviceList::Refresh");
+        Free();
+    }
+#ifdef USE_TRACE
+    TRACE1("<<DeviceList::Refresh, %d devices {", count);
+    for (int i=0; i<count; i++) {
+        if (i > 0)
+            TRACE0(", ");
+        TRACE1("0x%x", (int)devices[i]);
+    }
+    TRACE0("}\n");
+#endif
+
+    return err;
+}
+
+int DeviceList::GetCount() {
+    MutexLock::Locker locker(lock);
+    return count;
+}
+
+AudioDeviceID DeviceList::GetDeviceID(int index) {
+    MutexLock::Locker locker(lock);
+    return index < 0 ? 0 : index >= count ? 0 : devices[index];
+}
+
+bool DeviceList::GetDeviceInfo(int index, AudioDeviceID *pDeviceID, int stringLength, char *name, char *vendor, char *description, char *version) {
+    MutexLock::Locker locker(lock);
+    if (index < 0 || index >= count) {
+        return false;
+    }
+
+    AudioDeviceID deviceID = devices[index];
+    if (pDeviceID != NULL)
+        *pDeviceID = deviceID;
+
+    OSStatus err = noErr;
+
+    if (name != NULL || description != NULL) {
+        CFStringRef cfName = NULL;
+        err = GetAudioObjectProperty(deviceID, kAudioObjectPropertyScopeGlobal,
+            kAudioObjectPropertyName, sizeof(cfName), &cfName, 1);
+        if (err == noErr) {
+            if (name != NULL)
+                CFStringGetCString(cfName, name, stringLength, kCFStringEncodingUTF8);
+            if (description)
+                CFStringGetCString(cfName, description, stringLength, kCFStringEncodingUTF8);
+            CFRelease(cfName);
+        }
+    }
+
+    if (vendor != NULL) {
+        CFStringRef cfManufacturer = NULL;
+        err = GetAudioObjectProperty(deviceID, kAudioObjectPropertyScopeGlobal,
+            kAudioObjectPropertyManufacturer, sizeof(cfManufacturer), &cfManufacturer, 1);
+        if (err == noErr) {
+            CFStringGetCString(cfManufacturer, vendor, stringLength, kCFStringEncodingUTF8);
+            CFRelease(cfManufacturer);
+        }
+    }
+
+    return true;
+}
+
+void DeviceList::Free() {
+    if (devices != NULL) {
+        free(devices);
+        devices = NULL;
+        count = 0;
+    }
+}
+
+/*static*/
+OSStatus DeviceList::NotificationCallback(AudioObjectID inObjectID,
+    UInt32 inNumberAddresses, const AudioObjectPropertyAddress inAddresses[], void *inClientData)
+{
+    DeviceList *pThis = (DeviceList *)inClientData;
+
+    for (UInt32 i=0; i<inNumberAddresses; i++) {
+        switch (inAddresses[i].mSelector) {
+        case kAudioHardwarePropertyDevices:
+            TRACE0("NOTIFICATION: kAudioHardwarePropertyDevices\n");
+            break;
+        }
+    }
+
+    return noErr;
+}
+
+
+
+AudioDeviceID GetDefaultDevice(int isSource) {
+    AudioDeviceID deviceID;
+    OSStatus err = GetAudioObjectProperty(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal,
+        isSource ? kAudioHardwarePropertyDefaultOutputDevice : kAudioHardwarePropertyDefaultInputDevice,
+        sizeof(deviceID), &deviceID, 1);
+    if (err) {
+        OS_ERROR1(err, "GetDefaultDevice(isSource=%d)", isSource);
+        return 0;
+    }
+    return deviceID;
+}
+
+int GetChannelCount(AudioDeviceID deviceID, int isSource) {
+    int result = 0;
+    OSStatus err;
+    UInt32 size, i;
+    AudioObjectPropertyScope scope = isSource ? kAudioDevicePropertyScopeOutput : kAudioDevicePropertyScopeInput;
+
+    err = GetAudioObjectPropertySize(deviceID, scope, kAudioDevicePropertyStreamConfiguration, &size);
+    if (err) {
+        OS_ERROR2(err, "GetChannelCount(getSize), deviceID=0x%x, isSource=%d", (int)deviceID, isSource);
+    } else {
+        AudioBufferList *pBufferList = (AudioBufferList *)malloc(size);
+        memset(pBufferList, 0, size);
+        err = GetAudioObjectProperty(deviceID, scope, kAudioDevicePropertyStreamConfiguration, &size, pBufferList);
+        if (err == noErr) {
+            for (i=0; i<pBufferList->mNumberBuffers; i++) {
+                result += pBufferList->mBuffers[i].mNumberChannels;
+            }
+        } else {
+            OS_ERROR2(err, "GetChannelCount(getData), deviceID=0x%x, isSource=%d", (int)deviceID, isSource);
+        }
+        free(pBufferList);
+    }
+    TRACE2("GetChannelCount (deviceID=0x%x): total %d channels\n", (int)deviceID, result);
+    return result;
+}
+
+float GetSampleRate(AudioDeviceID deviceID, int isSource) {
+    Float64 result;
+    AudioObjectPropertyScope scope = isSource ? kAudioDevicePropertyScopeOutput : kAudioDevicePropertyScopeInput;
+    OSStatus err = GetAudioObjectProperty(deviceID, scope, kAudioDevicePropertyActualSampleRate, sizeof(result), &result, 1);
+    if (err) {
+        OS_ERROR2(err, "GetSampleRate(ActualSampleRate), deviceID=0x%x, isSource=%d", (int)deviceID, isSource);
+        // try to get NominalSampleRate
+        err = GetAudioObjectProperty(deviceID, scope, kAudioDevicePropertyNominalSampleRate, sizeof(result), &result, 1);
+        if (err) {
+            OS_ERROR2(err, "GetSampleRate(NominalSampleRate), deviceID=0x%x, isSource=%d", (int)deviceID, isSource);
+            return 0;
+        }
+    }
+    return (float)result;
+}
+
+
+OSStatus GetAudioObjectPropertySize(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size)
+{
+    const AudioObjectPropertyAddress address = {prop, scope, kAudioObjectPropertyElementMaster};
+    OSStatus err;
+
+    err = AudioObjectGetPropertyDataSize(object, &address, 0, NULL, size);
+
+    return err;
+}
+
+OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size, void *data)
+{
+    const AudioObjectPropertyAddress address = {prop, scope, kAudioObjectPropertyElementMaster};
+    OSStatus err;
+
+    err = AudioObjectGetPropertyData(object, &address, 0, NULL, size, data);
+
+    return err;
+}
+
+OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data, int checkSize)
+{
+    const AudioObjectPropertyAddress address = {prop, scope, kAudioObjectPropertyElementMaster};
+    UInt32 oldSize = size;
+    OSStatus err;
+
+    err = AudioObjectGetPropertyData(object, &address, 0, NULL, &size, data);
+
+    if (!err && checkSize && size != oldSize)
+        return kAudioHardwareBadPropertySizeError;
+    return err;
+}
+
+// wrapper for AudioObjectSetPropertyData (kAudioObjectPropertyElementMaster)
+OSStatus SetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data)
+{
+    AudioObjectPropertyAddress address = {prop, scope, kAudioObjectPropertyElementMaster};
+
+    OSStatus err = AudioObjectSetPropertyData(object, &address, 0, NULL, size, data);
+
+    return err;
+}
diff --git a/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.h b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.h
new file mode 100644
index 0000000..186da66
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Utils.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <CoreAudio/CoreAudio.h>
+#include <pthread.h>
+
+extern "C" {
+#include "Utilities.h"
+}
+
+
+#ifdef USE_ERROR
+#define OS_ERROR_END(err) {                     \
+    char errStr[32];                            \
+    snprintf(errStr, 32, "%d('%c%c%c%c')>", (int)err, (char)(err >> 24), (char)(err >> 16), (char)(err >> 8), (char)err); \
+    ERROR1(" ERROR %s\n", errStr);              \
+}
+#define OS_ERROR0(err, string)                  { ERROR0(string); OS_ERROR_END(err); }
+#define OS_ERROR1(err, string, p1)              { ERROR1(string, p1); OS_ERROR_END(err); }
+#define OS_ERROR2(err, string, p1, p2)          { ERROR2(string, p1, p2); OS_ERROR_END(err); }
+#define OS_ERROR3(err, string, p1, p2, p3)      { ERROR3(string, p1, p2, p3); OS_ERROR_END(err); }
+#define OS_ERROR4(err, string, p1, p2, p3, p4)  { ERROR4(string, p1, p2, p3, p4); OS_ERROR_END(err); }
+#else
+#define OS_ERROR0(err, string)
+#define OS_ERROR1(err, string, p1)
+#define OS_ERROR2(err, string, p1, p2)
+#define OS_ERROR3(err, string, p1, p2, p3)
+#define OS_ERROR4(err, string, p1, p2, p3, p4)
+#endif
+
+
+// Simple mutex wrapper class
+class MutexLock {
+private:
+    pthread_mutex_t lockMutex;
+public:
+    MutexLock() { pthread_mutex_init(&lockMutex, NULL); }
+    ~MutexLock() { pthread_mutex_destroy(&lockMutex); }
+
+    void Lock() { pthread_mutex_lock(&lockMutex); }
+    void Unlock() { pthread_mutex_unlock(&lockMutex); }
+
+    class Locker {
+    public:
+        Locker(MutexLock &lock) : pLock(&lock) { pLock->Lock(); }
+        ~Locker() { pLock->Unlock(); }
+    private:
+        MutexLock *pLock;
+    };
+};
+
+
+// DirectAudio and Ports need own caches of the device list
+class DeviceList {
+public:
+    DeviceList();
+    ~DeviceList();
+
+    OSStatus Refresh();
+
+    int GetCount();
+    AudioDeviceID GetDeviceID(int index);
+    // stringLength specified length of name, vendor, description & version strings
+    bool GetDeviceInfo(int index, AudioDeviceID *deviceID, int stringLength, char *name, char *vendor, char *description, char *version);
+
+private:
+    int count;
+    AudioDeviceID *devices;
+    MutexLock lock;
+    void Free();
+
+    static OSStatus NotificationCallback(AudioObjectID inObjectID,
+        UInt32 inNumberAddresses, const AudioObjectPropertyAddress inAddresses[], void *inClientData);
+
+};
+
+int MACOSX_DAUDIO_Init();
+
+AudioDeviceID GetDefaultDevice(int isSource);
+int GetChannelCount(AudioDeviceID deviceID, int isSource);
+float GetSampleRate(AudioDeviceID deviceID, int isSource);
+
+
+// wrappers for AudioObjectGetPropertyDataSize/AudioObjectGetPropertyData (master element)
+OSStatus GetAudioObjectPropertySize(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size);
+OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size, void *data);
+OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data, int checkSize);
+
+// wrapper for AudioObjectSetPropertyData (kAudioObjectPropertyElementMaster)
+OSStatus SetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data);
+
diff --git a/jdk/src/macosx/native/java/util/MacOSXPreferencesFile.m b/jdk/src/macosx/native/java/util/MacOSXPreferencesFile.m
new file mode 100644
index 0000000..a564e4b
--- /dev/null
+++ b/jdk/src/macosx/native/java/util/MacOSXPreferencesFile.m
@@ -0,0 +1,994 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+   Hierarchical storage layout:
+
+   <dict>
+     <key>/</key>
+     <dict>
+       <key>foo</key>
+       <string>/foo's value</string>
+       <key>foo/</key>
+       <dict>
+         <key>bar</key>
+         <string>/foo/bar's value</string>
+       </dict>
+     </dict>
+   </dict>
+
+   Java pref nodes are stored in several different files. Pref nodes
+   with at least three components in the node name (e.g. /com/MyCompany/MyApp/)
+   are stored in a CF prefs file with the first three components as the name.
+   This way, all preferences for MyApp end up in com.MyCompany.MyApp.plist .
+   Pref nodes with shorter names are stored in com.apple.java.util.prefs.plist
+
+   The filesystem is assumed to be case-insensitive (like HFS+).
+   Java pref node names are case-sensitive. If two pref node names differ
+   only in case, they may end up in the same pref file. This is ok
+   because the CF keys identifying the node span the entire absolute path
+   to the node and are case-sensitive.
+
+   Java node names may contain '.' . When mapping to the CF file name,
+   these dots are left as-is, even though '/' is mapped to '.' .
+   This is ok because the CF key contains the correct node name.
+*/
+
+
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include "jni_util.h"
+#include "jlong.h"
+#include "jvm.h"
+
+
+// Throw an OutOfMemoryError with the given message.
+static void throwOutOfMemoryError(JNIEnv *env, const char *msg)
+{
+    static jclass exceptionClass = NULL;
+    jclass c;
+
+    if (exceptionClass) {
+        c = exceptionClass;
+    } else {
+        c = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
+        if ((*env)->ExceptionOccurred(env)) return;
+        exceptionClass = (*env)->NewGlobalRef(env, c);
+    }
+
+    (*env)->ThrowNew(env, c, msg);
+}
+
+
+// throwIfNull macro
+// If var is NULL, throw an OutOfMemoryError and goto badvar.
+// var must be a variable. env must be the current JNIEnv.
+// fixme throw BackingStoreExceptions sometimes?
+#define throwIfNull(var, msg) \
+    do { \
+        if (var == NULL) { \
+            throwOutOfMemoryError(env, msg); \
+            goto bad##var; \
+        } \
+    } while (0)
+
+
+// Converts CFNumber, CFBoolean, CFString to CFString
+// returns NULL if value is of some other type
+// throws and returns NULL on memory error
+// result must be released (even if value was already a CFStringRef)
+// value must not be null
+static CFStringRef copyToCFString(JNIEnv *env, CFTypeRef value)
+{
+    CFStringRef result;
+    CFTypeID type;
+
+    type = CFGetTypeID(value);
+
+    if (type == CFStringGetTypeID()) {
+        result = (CFStringRef)CFRetain(value);
+    }
+    else if (type == CFBooleanGetTypeID()) {
+        // Java Preferences API expects "true" and "false" for boolean values.
+        result = CFStringCreateCopy(NULL, (value == kCFBooleanTrue) ? CFSTR("true") : CFSTR("false"));
+        throwIfNull(result, "copyToCFString failed");
+    }
+    else if (type == CFNumberGetTypeID()) {
+        CFNumberRef number = (CFNumberRef) value;
+        if (CFNumberIsFloatType(number)) {
+            double d;
+            CFNumberGetValue(number, kCFNumberDoubleType, &d);
+            result = CFStringCreateWithFormat(NULL, NULL, CFSTR("%g"), d);
+            throwIfNull(result, "copyToCFString failed");
+        }
+        else {
+            long l;
+            CFNumberGetValue(number, kCFNumberLongType, &l);
+            result = CFStringCreateWithFormat(NULL, NULL, CFSTR("%ld"), l);
+            throwIfNull(result, "copyToCFString failed");
+        }
+    }
+    else {
+        // unknown type - return NULL
+        result = NULL;
+    }
+
+ badresult:
+    return result;
+}
+
+
+// Create a Java string from the given CF string.
+// returns NULL if cfString is NULL
+// throws and returns NULL on memory error
+static jstring toJavaString(JNIEnv *env, CFStringRef cfString)
+{
+    if (cfString == NULL) {
+        return NULL;
+    } else {
+        jstring javaString = NULL;
+
+        CFIndex length = CFStringGetLength(cfString);
+        const UniChar *constchars = CFStringGetCharactersPtr(cfString);
+        if (constchars) {
+            javaString = (*env)->NewString(env, constchars, length);
+        } else {
+            UniChar *chars = malloc(length * sizeof(UniChar));
+            throwIfNull(chars, "toJavaString failed");
+            CFStringGetCharacters(cfString, CFRangeMake(0, length), chars);
+            javaString = (*env)->NewString(env, chars, length);
+            free(chars);
+        }
+    badchars:
+        return javaString;
+    }
+}
+
+
+
+// Create a CF string from the given Java string.
+// returns NULL if javaString is NULL
+// throws and returns NULL on memory error
+static CFStringRef toCF(JNIEnv *env, jstring javaString)
+{
+    if (javaString == NULL) {
+        return NULL;
+    } else {
+        CFStringRef result = NULL;
+        jsize length = (*env)->GetStringLength(env, javaString);
+        const jchar *chars = (*env)->GetStringChars(env, javaString, NULL);
+        throwIfNull(chars, "toCF failed");
+        result =
+            CFStringCreateWithCharacters(NULL, (const UniChar *)chars, length);
+        (*env)->ReleaseStringChars(env, javaString, chars);
+        throwIfNull(result, "toCF failed");
+    badchars:
+    badresult:
+        return result;
+    }
+}
+
+
+// Create an empty Java string array of the given size.
+// Throws and returns NULL on error.
+static jarray createJavaStringArray(JNIEnv *env, CFIndex count)
+{
+    static jclass stringClass = NULL;
+    jclass c;
+
+    if (stringClass) {
+        c = stringClass;
+    } else {
+        c = (*env)->FindClass(env, "java/lang/String");
+        if ((*env)->ExceptionOccurred(env)) return NULL;
+        stringClass = (*env)->NewGlobalRef(env, c);
+    }
+
+    return (*env)->NewObjectArray(env, count, c, NULL); // AWT_THREADING Safe (known object)
+}
+
+
+// Java accessors for CF constants.
+JNIEXPORT jlong JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_currentUser(JNIEnv *env,
+                                                       jobject klass)
+{
+    return ptr_to_jlong(kCFPreferencesCurrentUser);
+}
+
+JNIEXPORT jlong JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_anyUser(JNIEnv *env, jobject klass)
+{
+    return ptr_to_jlong(kCFPreferencesAnyUser);
+}
+
+JNIEXPORT jlong JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_currentHost(JNIEnv *env,
+                                                       jobject klass)
+{
+    return ptr_to_jlong(kCFPreferencesCurrentHost);
+}
+
+JNIEXPORT jlong JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_anyHost(JNIEnv *env, jobject klass)
+{
+    return ptr_to_jlong(kCFPreferencesAnyHost);
+}
+
+
+// Create an empty node.
+// Does not store the node in any prefs file.
+// returns NULL on memory error
+static CFMutableDictionaryRef createEmptyNode(void)
+{
+    return CFDictionaryCreateMutable(NULL, 0,
+                                     &kCFTypeDictionaryKeyCallBacks,
+                                     &kCFTypeDictionaryValueCallBacks);
+}
+
+
+// Create a string that consists of path minus its last component.
+// path must end with '/'
+// The result will end in '/' (unless path itself is '/')
+static CFStringRef copyParentOf(CFStringRef path)
+{
+    CFRange searchRange;
+    CFRange slashRange;
+    CFRange parentRange;
+    Boolean found;
+
+    searchRange = CFRangeMake(0, CFStringGetLength(path) - 1);
+    found = CFStringFindWithOptions(path, CFSTR("/"), searchRange,
+                                    kCFCompareBackwards, &slashRange);
+    if (!found) return CFSTR("");
+    parentRange = CFRangeMake(0, slashRange.location + 1); // include '/'
+    return CFStringCreateWithSubstring(NULL, path, parentRange);
+}
+
+
+// Create a string that consists of path's last component.
+// path must end with '/'
+// The result will end in '/'.
+// The result will not start with '/' (unless path itself is '/')
+static CFStringRef copyChildOf(CFStringRef path)
+{
+    CFRange searchRange;
+    CFRange slashRange;
+    CFRange childRange;
+    Boolean found;
+    CFIndex length = CFStringGetLength(path);
+
+    searchRange = CFRangeMake(0, length - 1);
+    found = CFStringFindWithOptions(path, CFSTR("/"), searchRange,
+                                    kCFCompareBackwards, &slashRange);
+    if (!found) return CFSTR("");
+    childRange = CFRangeMake(slashRange.location + 1,
+                             length - slashRange.location - 1); // skip '/'
+    return CFStringCreateWithSubstring(NULL, path, childRange);
+}
+
+
+// Return the first three components of path, with leading and trailing '/'.
+// If path does not have three components, return NULL.
+// path must begin and end in '/'
+static CFStringRef copyFirstThreeComponentsOf(CFStringRef path)
+{
+    CFRange searchRange;
+    CFRange slashRange;
+    CFRange prefixRange;
+    CFStringRef prefix;
+    Boolean found;
+    CFIndex length = CFStringGetLength(path);
+
+    searchRange = CFRangeMake(1, length - 1);  // skip leading '/'
+    found = CFStringFindWithOptions(path, CFSTR("/"), searchRange, 0,
+                                    &slashRange);
+    if (!found) return NULL;  // no second slash!
+
+    searchRange = CFRangeMake(slashRange.location + 1,
+                              length - slashRange.location - 1);
+    found = CFStringFindWithOptions(path, CFSTR("/"), searchRange, 0,
+                                    &slashRange);
+    if (!found) return NULL;  // no third slash!
+
+    searchRange = CFRangeMake(slashRange.location + 1,
+                              length - slashRange.location - 1);
+    found = CFStringFindWithOptions(path, CFSTR("/"), searchRange, 0,
+                                    &slashRange);
+    if (!found) return NULL;  // no fourth slash!
+
+    prefixRange = CFRangeMake(0, slashRange.location + 1); // keep last '/'
+    prefix = CFStringCreateWithSubstring(NULL, path, prefixRange);
+
+    return prefix;
+}
+
+
+// Copy the CFPreferences key and value at the base of path's tree.
+// path must end in '/'
+// topKey or topValue may be NULL
+// Returns NULL on error or if there is no tree for path in this file.
+static void copyTreeForPath(CFStringRef path, CFStringRef name,
+                            CFStringRef user, CFStringRef host,
+                            CFStringRef *topKey, CFDictionaryRef *topValue)
+{
+    CFStringRef key;
+    CFPropertyListRef value;
+
+    if (topKey) *topKey = NULL;
+    if (topValue) *topValue = NULL;
+
+    if (CFEqual(name, CFSTR("com.apple.java.util.prefs"))) {
+        // Top-level file. Only key "/" is an acceptable root.
+        key = (CFStringRef) CFRetain(CFSTR("/"));
+    } else {
+        // Second-level file. Key must be the first three components of path.
+        key = copyFirstThreeComponentsOf(path);
+        if (!key) return;
+    }
+
+    value = CFPreferencesCopyValue(key, name, user, host);
+    if (value) {
+        if (CFGetTypeID(value) == CFDictionaryGetTypeID()) {
+            // (key, value) is acceptable
+            if (topKey) *topKey = (CFStringRef)CFRetain(key);
+            if (topValue) *topValue = (CFDictionaryRef)CFRetain(value);
+        }
+        CFRelease(value);
+    }
+    CFRelease(key);
+}
+
+
+// Find the node for path in the given tree.
+// Returns NULL on error or if path doesn't have a node in this tree.
+// path must end in '/'
+static CFDictionaryRef copyNodeInTree(CFStringRef path, CFStringRef topKey,
+                                      CFDictionaryRef topValue)
+{
+    CFMutableStringRef p;
+    CFDictionaryRef result = NULL;
+
+    p = CFStringCreateMutableCopy(NULL, 0, path);
+    if (!p) return NULL;
+    CFStringDelete(p, CFRangeMake(0, CFStringGetLength(topKey)));
+    result = topValue;
+
+    while (CFStringGetLength(p) > 0) {
+        CFDictionaryRef child;
+        CFStringRef part = NULL;
+        CFRange slashRange = CFStringFind(p, CFSTR("/"), 0);
+        // guaranteed to succeed because path must end in '/'
+        CFRange partRange = CFRangeMake(0, slashRange.location + 1);
+        part = CFStringCreateWithSubstring(NULL, p, partRange);
+        if (!part) { result = NULL; break; }
+        CFStringDelete(p, partRange);
+
+        child = CFDictionaryGetValue(result, part);
+        CFRelease(part);
+        if (child  &&  CFGetTypeID(child) == CFDictionaryGetTypeID()) {
+            // continue search
+            result = child;
+        } else {
+            // didn't find target node
+            result = NULL;
+            break;
+        }
+    }
+
+    CFRelease(p);
+    if (result) return (CFDictionaryRef)CFRetain(result);
+    else return NULL;
+}
+
+
+// Return a retained copy of the node at path from the given file.
+// path must end in '/'
+// returns NULL if node doesn't exist.
+// returns NULL if the value for key "path" isn't a valid node.
+static CFDictionaryRef copyNodeIfPresent(CFStringRef path, CFStringRef name,
+                                         CFStringRef user, CFStringRef host)
+{
+    CFStringRef topKey;
+    CFDictionaryRef topValue;
+    CFDictionaryRef result;
+
+    copyTreeForPath(path, name, user, host, &topKey, &topValue);
+    if (!topKey) return NULL;
+
+    result = copyNodeInTree(path, topKey, topValue);
+
+    CFRelease(topKey);
+    if (topValue) CFRelease(topValue);
+    return result;
+}
+
+
+// Create a new tree that would store path in the given file.
+// Only the root of the tree is created, not all of the links leading to path.
+// returns NULL on error
+static void createTreeForPath(CFStringRef path, CFStringRef name,
+                              CFStringRef user, CFStringRef host,
+                              CFStringRef *outTopKey,
+                              CFMutableDictionaryRef *outTopValue)
+{
+    *outTopKey = NULL;
+    *outTopValue = NULL;
+
+    // if name is "com.apple.java.util.prefs" then create tree "/"
+    // else create tree "/foo/bar/baz/"
+    // "com.apple.java.util.prefs.plist" is also in MacOSXPreferences.java
+    if (CFEqual(name, CFSTR("com.apple.java.util.prefs"))) {
+        *outTopKey = CFSTR("/");
+        *outTopValue = createEmptyNode();
+    } else {
+        CFStringRef prefix = copyFirstThreeComponentsOf(path);
+        if (prefix) {
+            *outTopKey = prefix;
+            *outTopValue = createEmptyNode();
+        }
+    }
+}
+
+
+// Return a mutable copy of the tree containing path and the dict for
+//   path itself. *outTopKey and *outTopValue can be used to write the
+//   modified tree back to the prefs file.
+// *outTopKey and *outTopValue must be released iff the actual return
+//   value is not NULL.
+static CFMutableDictionaryRef
+copyMutableNode(CFStringRef path, CFStringRef name,
+                CFStringRef user, CFStringRef host,
+                CFStringRef *outTopKey,
+                CFMutableDictionaryRef *outTopValue)
+{
+    CFStringRef topKey = NULL;
+    CFDictionaryRef oldTopValue = NULL;
+    CFMutableDictionaryRef topValue;
+    CFMutableDictionaryRef result = NULL;
+    CFMutableStringRef p;
+
+    if (outTopKey) *outTopKey = NULL;
+    if (outTopValue) *outTopValue = NULL;
+
+    copyTreeForPath(path, name, user, host, &topKey, &oldTopValue);
+    if (!topKey) {
+        createTreeForPath(path, name, user, host, &topKey, &topValue);
+    } else {
+        topValue = (CFMutableDictionaryRef)
+            CFPropertyListCreateDeepCopy(NULL, (CFPropertyListRef)oldTopValue,
+                                         kCFPropertyListMutableContainers);
+    }
+    if (!topValue) goto badtopValue;
+
+    p = CFStringCreateMutableCopy(NULL, 0, path);
+    if (!p) goto badp;
+    CFStringDelete(p, CFRangeMake(0, CFStringGetLength(topKey)));
+    result = topValue;
+
+    while (CFStringGetLength(p) > 0) {
+        CFMutableDictionaryRef child;
+        CFStringRef part = NULL;
+        CFRange slashRange = CFStringFind(p, CFSTR("/"), 0);
+        // guaranteed to succeed because path must end in '/'
+        CFRange partRange = CFRangeMake(0, slashRange.location + 1);
+        part = CFStringCreateWithSubstring(NULL, p, partRange);
+        if (!part) { result = NULL; break; }
+        CFStringDelete(p, partRange);
+
+        child = (CFMutableDictionaryRef)CFDictionaryGetValue(result, part);
+        if (child  &&  CFGetTypeID(child) == CFDictionaryGetTypeID()) {
+            // continue search
+            result = child;
+        } else {
+            // didn't find target node - add it and continue
+            child = createEmptyNode();
+            if (!child) { CFRelease(part); result = NULL; break; }
+            CFDictionaryAddValue(result, part, child);
+            result = child;
+        }
+        CFRelease(part);
+    }
+
+    if (result) {
+        *outTopKey = (CFStringRef)CFRetain(topKey);
+        *outTopValue = (CFMutableDictionaryRef)CFRetain(topValue);
+        CFRetain(result);
+    }
+
+    CFRelease(p);
+ badp:
+    CFRelease(topValue);
+ badtopValue:
+    if (topKey) CFRelease(topKey);
+    if (oldTopValue) CFRelease(oldTopValue);
+    return result;
+}
+
+
+JNIEXPORT jboolean JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_addNode
+(JNIEnv *env, jobject klass, jobject jpath,
+ jobject jname, jlong juser, jlong jhost)
+{
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFDictionaryRef node = NULL;
+    jboolean neededNewNode = false;
+
+    if (!path  ||  !name) goto badparams;
+
+    node = copyNodeIfPresent(path, name, user, host);
+
+    if (node) {
+        neededNewNode = false;
+        CFRelease(node);
+    } else {
+        CFStringRef topKey = NULL;
+        CFMutableDictionaryRef topValue = NULL;
+
+        neededNewNode = true;
+
+        // copyMutableNode creates the node if necessary
+        node = copyMutableNode(path, name, user, host, &topKey, &topValue);
+        throwIfNull(node, "copyMutableNode failed");
+
+        CFPreferencesSetValue(topKey, topValue, name, user, host);
+
+        CFRelease(node);
+        if (topKey) CFRelease(topKey);
+        if (topValue) CFRelease(topValue);
+    }
+
+ badnode:
+ badparams:
+    if (path) CFRelease(path);
+    if (name) CFRelease(name);
+
+    return neededNewNode;
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_removeNode
+(JNIEnv *env, jobject klass, jobject jpath,
+ jobject jname, jlong juser, jlong jhost)
+{
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFStringRef parentName;
+    CFStringRef childName;
+    CFDictionaryRef constParent;
+
+    if (!path  ||  !name) goto badparams;
+
+    parentName = copyParentOf(path);
+    throwIfNull(parentName, "copyParentOf failed");
+    childName  = copyChildOf(path);
+    throwIfNull(childName, "copyChildOf failed");
+
+    // root node is not allowed to be removed, so parentName is never empty
+
+    constParent = copyNodeIfPresent(parentName, name, user, host);
+    if (constParent  &&  CFDictionaryContainsKey(constParent, childName)) {
+        CFStringRef topKey;
+        CFMutableDictionaryRef topValue;
+        CFMutableDictionaryRef parent;
+
+        parent = copyMutableNode(parentName, name, user, host,
+                                 &topKey, &topValue);
+        throwIfNull(parent, "copyMutableNode failed");
+
+        CFDictionaryRemoveValue(parent, childName);
+        CFPreferencesSetValue(topKey, topValue, name, user, host);
+
+        CFRelease(parent);
+        if (topKey) CFRelease(topKey);
+        if (topValue) CFRelease(topValue);
+    } else {
+        // might be trying to remove the root itself in a non-root file
+        CFStringRef topKey;
+        CFDictionaryRef topValue;
+        copyTreeForPath(path, name, user, host, &topKey, &topValue);
+        if (topKey) {
+            if (CFEqual(topKey, path)) {
+                CFPreferencesSetValue(topKey, NULL, name, user, host);
+            }
+
+            if (topKey) CFRelease(topKey);
+            if (topValue) CFRelease(topValue);
+        }
+    }
+
+
+ badparent:
+    if (constParent) CFRelease(constParent);
+    CFRelease(childName);
+ badchildName:
+    CFRelease(parentName);
+ badparentName:
+ badparams:
+    if (path) CFRelease(path);
+    if (name) CFRelease(name);
+}
+
+
+// child must end with '/'
+JNIEXPORT void JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
+(JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
+ jobject jname, jlong juser, jlong jhost)
+{
+    // like addNode, but can put a three-level-deep dict into the root file
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef child = toCF(env, jchild);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFMutableDictionaryRef parent;
+    CFDictionaryRef node;
+    CFStringRef topKey;
+    CFMutableDictionaryRef topValue;
+
+    if (!path  ||  !child  ||  !name) goto badparams;
+
+    node = createEmptyNode();
+    throwIfNull(node, "createEmptyNode failed");
+
+    // copyMutableNode creates the node if necessary
+    parent = copyMutableNode(path, name, user, host, &topKey, &topValue);
+    throwIfNull(parent, "copyMutableNode failed");
+
+    CFDictionaryAddValue(parent, child, node);
+
+    CFPreferencesSetValue(topKey, topValue, name, user, host);
+
+    CFRelease(parent);
+    if (topKey) CFRelease(topKey);
+    if (topValue) CFRelease(topValue);
+ badparent:
+    CFRelease(node);
+ badnode:
+ badparams:
+    if (path) CFRelease(path);
+    if (child) CFRelease(child);
+    if (name) CFRelease(name);
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_removeChildFromNode
+(JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
+ jobject jname, jlong juser, jlong jhost)
+{
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef child = toCF(env, jchild);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFDictionaryRef constParent;
+
+    if (!path  ||  !child  ||  !name) goto badparams;
+
+    constParent = copyNodeIfPresent(path, name, user, host);
+    if (constParent  &&  CFDictionaryContainsKey(constParent, child)) {
+        CFStringRef topKey;
+        CFMutableDictionaryRef topValue;
+        CFMutableDictionaryRef parent;
+
+        parent = copyMutableNode(path, name, user, host, &topKey, &topValue);
+        throwIfNull(parent, "copyMutableNode failed");
+
+        CFDictionaryRemoveValue(parent, child);
+        CFPreferencesSetValue(topKey, topValue, name, user, host);
+
+        CFRelease(parent);
+        if (topKey) CFRelease(topKey);
+        if (topValue) CFRelease(topValue);
+    }
+
+ badparent:
+    if (constParent) CFRelease(constParent);
+ badparams:
+    if (path) CFRelease(path);
+    if (child) CFRelease(child);
+    if (name) CFRelease(name);
+}
+
+
+
+JNIEXPORT void JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_addKeyToNode
+(JNIEnv *env, jobject klass, jobject jpath, jobject jkey, jobject jvalue,
+ jobject jname, jlong juser, jlong jhost)
+{
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef key = toCF(env, jkey);
+    CFStringRef value = toCF(env, jvalue);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFMutableDictionaryRef node = NULL;
+    CFStringRef topKey;
+    CFMutableDictionaryRef topValue;
+
+    if (!path  ||  !key  || !value  ||  !name) goto badparams;
+
+    // fixme optimization: check whether old value and new value are identical
+    node = copyMutableNode(path, name, user, host, &topKey, &topValue);
+    throwIfNull(node, "copyMutableNode failed");
+
+    CFDictionarySetValue(node, key, value);
+    CFPreferencesSetValue(topKey, topValue, name, user, host);
+
+    CFRelease(node);
+    if (topKey) CFRelease(topKey);
+    if (topValue) CFRelease(topValue);
+
+ badnode:
+ badparams:
+    if (path) CFRelease(path);
+    if (key) CFRelease(key);
+    if (value) CFRelease(value);
+    if (name) CFRelease(name);
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_removeKeyFromNode
+(JNIEnv *env, jobject klass, jobject jpath, jobject jkey,
+ jobject jname, jlong juser, jlong jhost)
+{
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef key = toCF(env, jkey);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFDictionaryRef constNode;
+
+    if (!path  ||  !key  ||  !name) goto badparams;
+
+    constNode = copyNodeIfPresent(path, name, user, host);
+    if (constNode  &&  CFDictionaryContainsKey(constNode, key)) {
+        CFStringRef topKey;
+        CFMutableDictionaryRef topValue;
+        CFMutableDictionaryRef node;
+
+        node = copyMutableNode(path, name, user, host, &topKey, &topValue);
+        throwIfNull(node, "copyMutableNode failed");
+
+        CFDictionaryRemoveValue(node, key);
+        CFPreferencesSetValue(topKey, topValue, name, user, host);
+
+        CFRelease(node);
+        if (topKey) CFRelease(topKey);
+        if (topValue) CFRelease(topValue);
+    }
+
+ badnode:
+    if (constNode) CFRelease(constNode);
+ badparams:
+    if (path) CFRelease(path);
+    if (key) CFRelease(key);
+    if (name) CFRelease(name);
+}
+
+
+// path must end in '/'
+JNIEXPORT jstring JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_getKeyFromNode
+(JNIEnv *env, jobject klass, jobject jpath, jobject jkey,
+ jobject jname, jlong juser, jlong jhost)
+{
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef key = toCF(env, jkey);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFPropertyListRef value;
+    CFDictionaryRef node;
+    jstring result = NULL;
+
+    if (!path  ||  !key  ||  !name) goto badparams;
+
+    node = copyNodeIfPresent(path, name, user, host);
+    if (node) {
+        value = (CFPropertyListRef)CFDictionaryGetValue(node, key);
+        if (!value) {
+            // key doesn't exist, or other error - no Java errors available
+            result = NULL;
+        } else {
+            CFStringRef cfString = copyToCFString(env, value);
+            if ((*env)->ExceptionOccurred(env)) {
+                // memory error in copyToCFString
+                result = NULL;
+            } else if (cfString == NULL) {
+                // bogus value type in prefs file - no Java errors available
+                result = NULL;
+            } else {
+                // good cfString
+                result = toJavaString(env, cfString);
+                CFRelease(cfString);
+            }
+        }
+        CFRelease(node);
+    }
+
+ badparams:
+    if (path) CFRelease(path);
+    if (key) CFRelease(key);
+    if (name) CFRelease(name);
+
+    return result;
+}
+
+
+typedef struct {
+    jarray result;
+    JNIEnv *env;
+    CFIndex used;
+    Boolean allowSlash;
+} BuildJavaArrayArgs;
+
+// CFDictionary applier function that builds an array of Java strings
+//   from a CFDictionary of CFPropertyListRefs.
+// If args->allowSlash, only strings that end in '/' are added to the array,
+//   with the slash removed. Otherwise, only strings that do not end in '/'
+//   are added.
+// args->result must already exist and be large enough to hold all
+//   strings from the dictionary.
+// After complete application, args->result may not be full because
+//   some of the dictionary values weren't convertible to string. In
+//   this case, args->used will be the count of used elements.
+static void BuildJavaArrayFn(const void *key, const void *value, void *context)
+{
+    BuildJavaArrayArgs *args = (BuildJavaArrayArgs *)context;
+    CFPropertyListRef propkey = (CFPropertyListRef)key;
+    CFStringRef cfString = NULL;
+    JNIEnv *env = args->env;
+
+    if ((*env)->ExceptionOccurred(env)) return; // already failed
+
+    cfString = copyToCFString(env, propkey);
+    if ((*env)->ExceptionOccurred(env)) {
+        // memory error in copyToCFString
+    } else if (!cfString) {
+        // bogus value type in prefs file - no Java errors available
+    } else if (args->allowSlash != CFStringHasSuffix(cfString, CFSTR("/"))) {
+        // wrong suffix - ignore
+    } else {
+        // good cfString
+        jstring javaString;
+        if (args->allowSlash) {
+            CFRange range = CFRangeMake(0, CFStringGetLength(cfString) - 1);
+            CFStringRef s = CFStringCreateWithSubstring(NULL, cfString, range);
+            CFRelease(cfString);
+            cfString = s;
+        }
+        if (CFStringGetLength(cfString) <= 0) goto bad; // ignore empty
+        javaString = toJavaString(env, cfString);
+        if ((*env)->ExceptionOccurred(env)) goto bad;
+        (*env)->SetObjectArrayElement(env, args->result,args->used,javaString);
+        if ((*env)->ExceptionOccurred(env)) goto bad;
+        args->used++;
+    }
+
+ bad:
+    if (cfString) CFRelease(cfString);
+}
+
+
+static jarray getStringsForNode(JNIEnv *env, jobject klass, jobject jpath,
+                                jobject jname, jlong juser, jlong jhost,
+                                Boolean allowSlash)
+{
+    CFStringRef path = toCF(env, jpath);
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    CFDictionaryRef node;
+    jarray result = NULL;
+    CFIndex count;
+
+    if (!path  ||  !name) goto badparams;
+
+    node = copyNodeIfPresent(path, name, user, host);
+    if (!node) {
+        result = createJavaStringArray(env, 0);
+    } else {
+        count = CFDictionaryGetCount(node);
+        result = createJavaStringArray(env, count);
+        if (result) {
+            BuildJavaArrayArgs args;
+            args.result = result;
+            args.env = env;
+            args.used = 0;
+            args.allowSlash = allowSlash;
+            CFDictionaryApplyFunction(node, BuildJavaArrayFn, &args);
+            if (!(*env)->ExceptionOccurred(env)) {
+                // array construction succeeded
+                if (args.used < count) {
+                    // finished array is smaller than expected.
+                    // Make a new array of precisely the right size.
+                    jarray newresult = createJavaStringArray(env, args.used);
+                    if (newresult) {
+                        JVM_ArrayCopy(env,0, result,0, newresult,0, args.used);
+                        result = newresult;
+                    }
+                }
+            }
+        }
+
+        CFRelease(node);
+    }
+
+ badparams:
+    if (path) CFRelease(path);
+    if (name) CFRelease(name);
+
+    return result;
+}
+
+
+JNIEXPORT jarray JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_getKeysForNode
+(JNIEnv *env, jobject klass, jobject jpath,
+ jobject jname, jlong juser, jlong jhost)
+{
+    return getStringsForNode(env, klass, jpath, jname, juser, jhost, false);
+}
+
+JNIEXPORT jarray JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_getChildrenForNode
+(JNIEnv *env, jobject klass, jobject jpath,
+ jobject jname, jlong juser, jlong jhost)
+{
+    return getStringsForNode(env, klass, jpath, jname, juser, jhost, true);
+}
+
+
+// Returns false on error instead of throwing.
+JNIEXPORT jboolean JNICALL
+Java_java_util_prefs_MacOSXPreferencesFile_synchronize
+(JNIEnv *env, jobject klass,
+ jstring jname, jlong juser, jlong jhost)
+{
+    CFStringRef name = toCF(env, jname);
+    CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
+    CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
+    jboolean result = 0;
+
+    if (name) {
+        result = CFPreferencesSynchronize(name, user, host);
+        CFRelease(name);
+    }
+
+    return result;
+}
diff --git a/jdk/src/macosx/native/java/util/SCDynamicStoreConfig.m b/jdk/src/macosx/native/java/util/SCDynamicStoreConfig.m
new file mode 100644
index 0000000..f18f0aa
--- /dev/null
+++ b/jdk/src/macosx/native/java/util/SCDynamicStoreConfig.m
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <SystemConfiguration/SystemConfiguration.h>
+
+
+@interface JNFVectorCoercion : NSObject <JNFTypeCoercion> { }
+@end
+
+@implementation JNFVectorCoercion
+
+- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    static JNF_CLASS_CACHE(jc_Vector, "java/util/Vector");
+    static JNF_CTOR_CACHE(jm_Vector_ctor, jc_Vector, "(I)V");
+    static JNF_MEMBER_CACHE(jm_Vector_add, jc_Vector, "add", "(Ljava/lang/Object;)Z");
+
+    NSArray *nsArray = (NSArray *)obj;
+    jobject javaArray = JNFNewObject(env, jm_Vector_ctor, (jint)[nsArray count]);
+
+    for (id obj in nsArray) {
+        jobject jobj = [coercer coerceNSObject:obj withEnv:env usingCoercer:coercer];
+        JNFCallBooleanMethod(env, javaArray, jm_Vector_add, jobj);
+        if (jobj != NULL) (*env)->DeleteLocalRef(env, jobj);
+    }
+
+    return javaArray;
+}
+
+- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    return nil;
+}
+
+@end
+
+
+@interface JNFHashtableCoercion : NSObject <JNFTypeCoercion> { }
+@end
+
+@implementation JNFHashtableCoercion
+
+- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    static JNF_CLASS_CACHE(jc_Hashtable, "java/util/Hashtable");
+    static JNF_CTOR_CACHE(jm_Hashtable_ctor, jc_Hashtable, "()V");
+    static JNF_MEMBER_CACHE(jm_Hashtable_put, jc_Hashtable, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+
+    NSDictionary *nsDict = (NSDictionary *)obj;
+    NSEnumerator *keyEnum = [nsDict keyEnumerator];
+
+    jobject jHashTable = JNFNewObject(env, jm_Hashtable_ctor);
+
+    id key = nil;
+    while ((key = [keyEnum nextObject]) != nil) {
+        jobject jkey = [coercer coerceNSObject:key withEnv:env usingCoercer:coercer];
+
+        id value = [nsDict objectForKey:key];
+        jobject jvalue = [coercer coerceNSObject:value withEnv:env usingCoercer:coercer];
+
+        JNFCallObjectMethod(env, jHashTable, jm_Hashtable_put, jkey, jvalue);
+
+        if (jkey != NULL) (*env)->DeleteLocalRef(env, jkey);
+        if (jvalue != NULL) (*env)->DeleteLocalRef(env, jvalue);
+    }
+
+    return jHashTable;
+}
+
+- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer {
+    return nil;
+}
+
+@end
+
+
+
+NSDictionary *realmConfigsForRealms(SCDynamicStoreRef store, NSArray *realms) {
+    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+
+    for (NSString *realm in realms) {
+        CFTypeRef realmInfo = SCDynamicStoreCopyValue(store, (CFStringRef) [NSString stringWithFormat:@"Kerberos:%@", realm]);
+
+        if (CFGetTypeID(realmInfo) != CFDictionaryGetTypeID()) {
+            NSLog(@"Unexpected CFType for realm Info: %lu", CFGetTypeID(realmInfo));
+            return nil;
+        }
+
+        [dict setObject:(NSArray *)realmInfo forKey:realm];
+        CFRelease(realmInfo);
+    }
+
+    return dict;
+}
+
+
+#define KERBEROS_DEFAULT_REALMS @"Kerberos-Default-Realms"
+#define KERBEROS_DEFAULT_REALM_MAPPINGS @"Kerberos-Domain-Realm-Mappings"
+
+void _SCDynamicStoreCallBack(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) {
+   NSArray *keys = (NSArray *)changedKeys;
+    if ([keys count] == 0) return;
+    if (![keys containsObject:KERBEROS_DEFAULT_REALMS] && ![keys containsObject:KERBEROS_DEFAULT_REALM_MAPPINGS]) return;
+
+    JNFPerformEnvBlock(JNFThreadDetachOnThreadDeath | JNFThreadSetSystemClassLoaderOnAttach | JNFThreadAttachAsDaemon, ^(JNIEnv *env) {
+        static JNF_CLASS_CACHE(jc_Config, "sun/security/krb5/Config");
+        static JNF_STATIC_MEMBER_CACHE(jm_Config_refresh, jc_Config, "refresh", "()V");
+        JNFCallStaticVoidMethod(env, jm_Config_refresh);
+    });
+}
+
+/*
+ * Class:     sun_security_krb5_SCDynamicStoreConfig
+ * Method:    installNotificationCallback
+ */
+JNIEXPORT void JNICALL Java_sun_security_krb5_SCDynamicStoreConfig_installNotificationCallback(JNIEnv *env, jclass klass) {
+
+JNF_COCOA_ENTER(env);
+
+    SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java"), _SCDynamicStoreCallBack, NULL);
+    if (store == NULL) {
+        NSLog(@"Unable to load SCDynamicStore to install NotificationCallback");
+        return;
+    }
+
+    NSArray *keys = [NSArray arrayWithObjects:KERBEROS_DEFAULT_REALMS, KERBEROS_DEFAULT_REALM_MAPPINGS, nil];
+    SCDynamicStoreSetNotificationKeys(store, (CFArrayRef) keys, NULL);
+
+    CFRunLoopSourceRef rls = SCDynamicStoreCreateRunLoopSource(NULL, store, 0);
+    if (rls != NULL) {
+        CFRunLoopAddSource(CFRunLoopGetMain(), rls, kCFRunLoopDefaultMode);
+        CFRelease(rls);
+    }
+
+    CFRelease(store);
+
+JNF_COCOA_EXIT(env);
+
+}
+
+/*
+ * Class:     sun_security_krb5_SCDynamicStoreConfig
+ * Method:    getKerberosConfig
+ * Signature: ()Ljava/util/Hashtable;
+ */
+JNIEXPORT jobject JNICALL Java_sun_security_krb5_SCDynamicStoreConfig_getKerberosConfig(JNIEnv *env, jclass klass) {
+    jobject jHashTable = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java-kerberos"), NULL, NULL);
+    if (store == NULL) {
+        NSLog(@"Unable to load SCDynamicStore");
+        return NULL;
+    }
+
+    // Create the store if it is NULL and set it.
+    if (store == NULL) {
+        NSLog(@"Invalid value for SCDynamicStore");
+        return NULL;
+    }
+
+    CFTypeRef realms = SCDynamicStoreCopyValue(store, (CFStringRef) KERBEROS_DEFAULT_REALMS);
+    if (realms == NULL || CFGetTypeID(realms) != CFArrayGetTypeID()) {
+        NSLog(@"Unable to load realm info from SCDynamicStore");
+        if (realms) CFRelease(realms);
+        CFRelease(store);
+        return NULL;
+    }
+
+    CFTypeRef realmMappings = SCDynamicStoreCopyValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS);
+
+    if (realmMappings == NULL || CFGetTypeID(realmMappings) != CFArrayGetTypeID()) {
+        NSLog(@"Unable to load realm mapping info from SCDynamicStore");
+        if (realmMappings) CFRelease(realmMappings);
+        CFRelease(realms);
+        CFRelease(store);
+        return NULL;
+    }
+
+    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+
+    if (CFArrayGetCount(realms) > 0) {
+        NSDictionary *defaultRealmsDict = [NSDictionary dictionaryWithObject:[(NSArray *)realms objectAtIndex:0] forKey:@"default_realm"];
+        [dict setObject:defaultRealmsDict forKey:@"libdefaults"];
+
+        NSDictionary *realmConfigs = realmConfigsForRealms(store, (NSArray *)realms);
+        [dict setObject:realmConfigs forKey:@"realms"];
+    }
+    CFRelease(realms);
+    CFRelease(store);
+
+    if (CFArrayGetCount(realmMappings) > 0) {
+        [dict setObject:[(NSArray *)realmMappings objectAtIndex:0] forKey:@"domain_realm"];
+    }
+    CFRelease(realmMappings);
+
+
+    // create and load a coercer with all of the different coercions to convert each type of object
+    JNFTypeCoercer *coercer = [[[JNFTypeCoercer alloc] init] autorelease];
+    [JNFDefaultCoercions addStringCoercionTo:coercer];
+    [JNFDefaultCoercions addNumberCoercionTo:coercer];
+    [coercer addCoercion:[[[JNFHashtableCoercion alloc] init] autorelease] forNSClass:[NSDictionary class] javaClass:@"java/util/Map"];
+    [coercer addCoercion:[[[JNFVectorCoercion alloc] init] autorelease] forNSClass:[NSArray class] javaClass:@"java/util/List"];
+
+    // convert Cocoa graph to Java graph
+    jHashTable = [coercer coerceNSObject:dict withEnv:env];
+
+JNF_COCOA_EXIT(env);
+
+    return jHashTable;
+}
diff --git a/jdk/src/macosx/native/jobjc/JObjC.xcodeproj/default.pbxuser b/jdk/src/macosx/native/jobjc/JObjC.xcodeproj/default.pbxuser
new file mode 100644
index 0000000..aca0138
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/JObjC.xcodeproj/default.pbxuser
@@ -0,0 +1,207 @@
+// !$*UTF8*$!
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+{
+        00E6828EFEC88D1A11DB9C8B /* Project object */ = {
+                activeBuildConfigurationName = Release;
+                activeExecutable = 6A9FA6570246BA6C0CC91562 /* JObjC */;
+                activeTarget = EB9FD8610AEECCF5008E157E /* JObjC */;
+                addToTargets = (
+                        4CEBA78E08679EF10015D03E /* JNILib */,
+                );
+                breakpointsGroup = 0AB3651F0B2F67B300788B6C /* XCBreakpointsBucket */;
+                codeSenseManager = 0AB364DB0B2F66FD00788B6C /* Code sense */;
+                executables = (
+                        6A9FA6570246BA6C0CC91562 /* JObjC */,
+                );
+                perUserDictionary = {
+                        PBXConfiguration.PBXFileTableDataSource3.PBXExecutablesDataSource = {
+                                PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
+                                PBXFileTableDataSourceColumnSortingKey = PBXExecutablesDataSource_NameID;
+                                PBXFileTableDataSourceColumnWidthsKey = (
+                                        22,
+                                        300,
+                                        131,
+                                );
+                                PBXFileTableDataSourceColumnsKey = (
+                                        PBXExecutablesDataSource_ActiveFlagID,
+                                        PBXExecutablesDataSource_NameID,
+                                        PBXExecutablesDataSource_CommentsID,
+                                );
+                        };
+                        PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = {
+                                PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
+                                PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
+                                PBXFileTableDataSourceColumnWidthsKey = (
+                                        20,
+                                        245,
+                                        20,
+                                        48,
+                                        43,
+                                        43,
+                                        20,
+                                );
+                                PBXFileTableDataSourceColumnsKey = (
+                                        PBXFileDataSource_FiletypeID,
+                                        PBXFileDataSource_Filename_ColumnID,
+                                        PBXFileDataSource_Built_ColumnID,
+                                        PBXFileDataSource_ObjectSize_ColumnID,
+                                        PBXFileDataSource_Errors_ColumnID,
+                                        PBXFileDataSource_Warnings_ColumnID,
+                                        PBXFileDataSource_Target_ColumnID,
+                                );
+                        };
+                        PBXConfiguration.PBXTargetDataSource.PBXTargetDataSource = {
+                                PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
+                                PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
+                                PBXFileTableDataSourceColumnWidthsKey = (
+                                        20,
+                                        200,
+                                        65,
+                                        20,
+                                        48,
+                                        43,
+                                        43,
+                                );
+                                PBXFileTableDataSourceColumnsKey = (
+                                        PBXFileDataSource_FiletypeID,
+                                        PBXFileDataSource_Filename_ColumnID,
+                                        PBXTargetDataSource_PrimaryAttribute,
+                                        PBXFileDataSource_Built_ColumnID,
+                                        PBXFileDataSource_ObjectSize_ColumnID,
+                                        PBXFileDataSource_Errors_ColumnID,
+                                        PBXFileDataSource_Warnings_ColumnID,
+                                );
+                        };
+                };
+                sourceControlManager = 0AB364DA0B2F66FD00788B6C /* Source Control */;
+                userBuildSettings = {
+                };
+        };
+        0AB364DA0B2F66FD00788B6C /* Source Control */ = {
+                isa = PBXSourceControlManager;
+                fallbackIsa = XCSourceControlManager;
+                isSCMEnabled = 0;
+                scmConfiguration = {
+                };
+                scmType = "";
+        };
+        0AB364DB0B2F66FD00788B6C /* Code sense */ = {
+                isa = PBXCodeSenseManager;
+                indexTemplatePath = "";
+        };
+        0AB3651F0B2F67B300788B6C /* XCBreakpointsBucket */ = {
+                isa = XCBreakpointsBucket;
+                name = "Project Breakpoints";
+                objects = (
+                );
+        };
+        0AB365570B2F6ABB00788B6C /* JObjCdylib.c */ = {
+                uiCtxt = {
+                        sepNavIntBoundsRect = "{{0, 0}, {847, 783}}";
+                        sepNavSelRange = "{0, 0}";
+                        sepNavVisRect = "{{0, 0}, {847, 783}}";
+                        sepNavWindowFrame = "{{84, 198}, {886, 912}}";
+                };
+        };
+        0A3CC35E0B94BB8800F6BA26 /* java */ = {
+                isa = PBXFileReference;
+                explicitFileType = "compiled.mach-o.executable";
+                name = java;
+                path = /usr/bin/java;
+                sourceTree = "<absolute>";
+        };
+        363028F90383184400C91562 /* Manifest */ = {
+                uiCtxt = {
+                        sepNavIntBoundsRect = "{{0, 0}, {847, 783}}";
+                        sepNavSelRange = "{0, 0}";
+                        sepNavVisRect = "{{0, 0}, {847, 783}}";
+                        sepNavWindowFrame = "{{38, 240}, {886, 912}}";
+                };
+        };
+        4CEBA78E08679EF10015D03E /* Dylib */ = {
+                activeExec = 0;
+        };
+        6A9FA6570246BA6C0CC91562 /* JObjC */ = {
+                isa = PBXExecutable;
+                activeArgIndex = 0;
+                activeArgIndices = (
+                        YES,
+                );
+                argumentStrings = (
+                        "-cp JObjC.jar JObjC",
+                );
+                autoAttachOnCrash = 1;
+                configStateDict = {
+                        "PBXLSLaunchAction-0" = {
+                                PBXLSLaunchAction = 0;
+                                PBXLSLaunchStartAction = 1;
+                                PBXLSLaunchStdioStyle = 2;
+                                PBXLSLaunchStyle = 0;
+                                class = PBXLSRunLaunchConfig;
+                                displayName = "Executable Runner";
+                                identifier = com.apple.Xcode.launch.runConfig;
+                                remoteHostInfo = "";
+                                startActionInfo = "";
+                        };
+                        "PBXLSLaunchAction-1" = {
+                                PBXLSLaunchAction = 1;
+                                PBXLSLaunchStartAction = 1;
+                                PBXLSLaunchStdioStyle = 2;
+                                PBXLSLaunchStyle = 0;
+                                class = PBXJavaDebuggingNativeLaunchConfig;
+                                displayName = "Java Debugger";
+                                identifier = com.apple.Xcode.launch.JavaDebugNativeConfig;
+                                remoteHostInfo = "";
+                                startActionInfo = "";
+                        };
+                };
+                customDataFormattersEnabled = 1;
+                debuggerPlugin = GDBDebugging;
+                disassemblyDisplayState = 0;
+                dylibVariantSuffix = "";
+                enableDebugStr = 1;
+                environmentEntries = (
+                );
+                executableSystemSymbolLevel = 0;
+                executableUserSymbolLevel = 0;
+                launchableReference = 0A3CC35E0B94BB8800F6BA26 /* java */;
+                libgmallocEnabled = 0;
+                name = JObjC;
+                sourceDirectories = (
+                );
+                startupPath = "dist";
+        };
+        EB9FD8610AEECCF5008E157E /* JObjC */ = {
+                activeExec = 0;
+        };
+        EB9FD8720AEECD83008E157E /* build.xml */ = {
+                uiCtxt = {
+                        sepNavIntBoundsRect = "{{0, 0}, {847, 1260}}";
+                        sepNavSelRange = "{1260, 0}";
+                        sepNavVisRect = "{{0, 8}, {847, 783}}";
+                        sepNavWindowFrame = "{{752, 266}, {886, 912}}";
+                };
+        };
+}
diff --git a/jdk/src/macosx/native/jobjc/JObjC.xcodeproj/project.pbxproj b/jdk/src/macosx/native/jobjc/JObjC.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..61cf3948
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/JObjC.xcodeproj/project.pbxproj
@@ -0,0 +1,1397 @@
+// !$*UTF8*$!
+{
+        archiveVersion = 1;
+        classes = {
+        };
+        objectVersion = 44;
+        objects = {
+
+/* Begin PBXAggregateTarget section */
+                89EBD58C0C95F43D000F04A0 /* B&I */ = {
+                        isa = PBXAggregateTarget;
+                        buildConfigurationList = 89EBD5930C95F44E000F04A0 /* Build configuration list for PBXAggregateTarget "B&I" */;
+                        buildPhases = (
+                        );
+                        dependencies = (
+                                C592D6590E12F27400D076FF /* PBXTargetDependency */,
+                                C592D65B0E12F27600D076FF /* PBXTargetDependency */,
+                                C592D65D0E12F27E00D076FF /* PBXTargetDependency */,
+                                89D7CB9C0CDC64F800472EA2 /* PBXTargetDependency */,
+                                C592D65F0E12F28500D076FF /* PBXTargetDependency */,
+                                C592D6610E12F28E00D076FF /* PBXTargetDependency */,
+                                C592D6630E12F29200D076FF /* PBXTargetDependency */,
+                                89D7CC920CDE7A8200472EA2 /* PBXTargetDependency */,
+                        );
+                        name = "B&I";
+                        productName = "B&I";
+                };
+/* End PBXAggregateTarget section */
+
+/* Begin PBXBuildFile section */
+                89D7C9F70CDB900E00472EA2 /* CIF.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9EC0CDB900E00472EA2 /* CIF.m */; };
+                89D7C9F80CDB900E00472EA2 /* Coder.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9ED0CDB900E00472EA2 /* Coder.m */; };
+                89D7C9F90CDB900E00472EA2 /* Function.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9EE0CDB900E00472EA2 /* Function.m */; };
+                89D7C9FA0CDB900E00472EA2 /* ID.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9EF0CDB900E00472EA2 /* ID.m */; };
+                89D7C9FB0CDB900E00472EA2 /* JObjCRuntime.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F00CDB900E00472EA2 /* JObjCRuntime.m */; };
+                89D7C9FC0CDB900E00472EA2 /* MacOSXFramework.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F10CDB900E00472EA2 /* MacOSXFramework.m */; };
+                89D7C9FD0CDB900E00472EA2 /* NativeBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 89D7C9F20CDB900E00472EA2 /* NativeBuffer.h */; };
+                89D7C9FE0CDB900E00472EA2 /* NativeBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F30CDB900E00472EA2 /* NativeBuffer.m */; };
+                89D7C9FF0CDB900E00472EA2 /* NativeObjectLifecycleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F40CDB900E00472EA2 /* NativeObjectLifecycleManager.m */; };
+                89D7CA000CDB900E00472EA2 /* NSClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F50CDB900E00472EA2 /* NSClass.m */; };
+                89D7CA010CDB900E00472EA2 /* SEL.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F60CDB900E00472EA2 /* SEL.m */; };
+                89D7CB770CDC4A6500472EA2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 890FBACC0C6F782C00902C32 /* Foundation.framework */; };
+                89D7CB780CDC4A6500472EA2 /* JavaVM.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 890FBACA0C6F781000902C32 /* JavaVM.framework */; };
+                89D7CB790CDC4A6500472EA2 /* JavaNativeFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 896D90BB0CC2877C005625F5 /* JavaNativeFoundation.framework */; };
+                89D7CB7A0CDC4A6500472EA2 /* libffi.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 89E437680C97A7F200C756EE /* libffi.dylib */; };
+                89D7CCA40CDF9A2600472EA2 /* NativeBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 89D7C9F20CDB900E00472EA2 /* NativeBuffer.h */; };
+                89D7CCA60CDF9A2600472EA2 /* CIF.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9EC0CDB900E00472EA2 /* CIF.m */; };
+                89D7CCA70CDF9A2600472EA2 /* Coder.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9ED0CDB900E00472EA2 /* Coder.m */; };
+                89D7CCA80CDF9A2600472EA2 /* Function.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9EE0CDB900E00472EA2 /* Function.m */; };
+                89D7CCA90CDF9A2600472EA2 /* ID.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9EF0CDB900E00472EA2 /* ID.m */; };
+                89D7CCAA0CDF9A2600472EA2 /* JObjCRuntime.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F00CDB900E00472EA2 /* JObjCRuntime.m */; };
+                89D7CCAB0CDF9A2600472EA2 /* MacOSXFramework.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F10CDB900E00472EA2 /* MacOSXFramework.m */; };
+                89D7CCAC0CDF9A2600472EA2 /* NativeBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F30CDB900E00472EA2 /* NativeBuffer.m */; };
+                89D7CCAD0CDF9A2600472EA2 /* NativeObjectLifecycleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F40CDB900E00472EA2 /* NativeObjectLifecycleManager.m */; };
+                89D7CCAE0CDF9A2600472EA2 /* NSClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F50CDB900E00472EA2 /* NSClass.m */; };
+                89D7CCAF0CDF9A2600472EA2 /* SEL.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7C9F60CDB900E00472EA2 /* SEL.m */; };
+                89D7CCB10CDF9A2600472EA2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 890FBACC0C6F782C00902C32 /* Foundation.framework */; };
+                89D7CCB20CDF9A2600472EA2 /* JavaVM.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 890FBACA0C6F781000902C32 /* JavaVM.framework */; };
+                89D7CCB30CDF9A2600472EA2 /* JavaNativeFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 896D90BB0CC2877C005625F5 /* JavaNativeFoundation.framework */; };
+                89D7CCB40CDF9A2600472EA2 /* libffi.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 89E437680C97A7F200C756EE /* libffi.dylib */; };
+                89D7CCBB0CDF9AA200472EA2 /* NativeString.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7CCBA0CDF9AA200472EA2 /* NativeString.m */; };
+                89D7CCBD0CDF9AB100472EA2 /* NativeNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7CCBC0CDF9AB100472EA2 /* NativeNumber.m */; };
+                89D7CCBF0CDF9AC600472EA2 /* NativeThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 89D7CCBE0CDF9AC600472EA2 /* NativeThread.m */; };
+                C5742F6D0E316EFA00093838 /* Subclassing.m in Sources */ = {isa = PBXBuildFile; fileRef = C5742F6B0E316EFA00093838 /* Subclassing.m */; };
+                C5742F700E316F8600093838 /* Subclassing.m in Sources */ = {isa = PBXBuildFile; fileRef = C5742F6B0E316EFA00093838 /* Subclassing.m */; };
+                C5D196C90DF9E43C006F9FB9 /* FFIType.m in Sources */ = {isa = PBXBuildFile; fileRef = C5D196C80DF9E43C006F9FB9 /* FFIType.m */; };
+                C5D197D90DFB77C6006F9FB9 /* FFIType.m in Sources */ = {isa = PBXBuildFile; fileRef = C5D196C80DF9E43C006F9FB9 /* FFIType.m */; };
+                C5E4547B0E36729F0046D3E8 /* Invoke.m in Sources */ = {isa = PBXBuildFile; fileRef = C5E454790E36729F0046D3E8 /* Invoke.m */; };
+                C5E4547D0E367DAB0046D3E8 /* Invoke.m in Sources */ = {isa = PBXBuildFile; fileRef = C5E454790E36729F0046D3E8 /* Invoke.m */; };
+                C5F3B23D0E39948300B771AE /* FunCallBench.m in Sources */ = {isa = PBXBuildFile; fileRef = C5F3B1370E398F8E00B771AE /* FunCallBench.m */; };
+                C5F3B2620E3AB0F300B771AE /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C5F3B2610E3AB0F300B771AE /* AppKit.framework */; };
+                C5F3B2640E3AB0F300B771AE /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C5F3B2630E3AB0F300B771AE /* Cocoa.framework */; };
+                C5F3B2650E3AB0F300B771AE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 890FBACC0C6F782C00902C32 /* Foundation.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+                2CC7556013A1322100B09D1B /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = EB9FD8610AEECCF5008E157E;
+                        remoteInfo = "build-core-java";
+                };
+                2CC7556213A1322800B09D1B /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = C5F3B1530E39927900B771AE;
+                        remoteInfo = "build-test-java";
+                };
+                2CC7556413A1323700B09D1B /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CA160CDBA94D00472EA2;
+                        remoteInfo = "build-generator-java";
+                };
+                2CC7556613A1324300B09D1B /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CC600CDE75EC00472EA2;
+                        remoteInfo = "build-additions-java";
+                };
+                2CC7556813A1325700B09D1B /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CB870CDC4ED000472EA2;
+                        remoteInfo = "run-generator";
+                };
+                2CC7556A13A132AF00B09D1B /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 4CEBA78E08679EF10015D03E;
+                        remoteInfo = "build-core-native";
+                };
+                2CC7556C13A132B200B09D1B /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = EB9FD8610AEECCF5008E157E;
+                        remoteInfo = "build-core-java";
+                };
+                89D7CB9B0CDC64F800472EA2 /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CB870CDC4ED000472EA2;
+                        remoteInfo = "run-generator";
+                };
+                89D7CC910CDE7A8200472EA2 /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CC720CDE767500472EA2;
+                        remoteInfo = "assemble-product-java";
+                };
+                C592D6580E12F27400D076FF /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = EB9FD8610AEECCF5008E157E;
+                        remoteInfo = "build-core-java";
+                };
+                C592D65A0E12F27600D076FF /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 4CEBA78E08679EF10015D03E;
+                        remoteInfo = "build-core-native";
+                };
+                C592D65C0E12F27E00D076FF /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CA160CDBA94D00472EA2;
+                        remoteInfo = "build-generator-java";
+                };
+                C592D65E0E12F28500D076FF /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CC4C0CDE4C0400472EA2;
+                        remoteInfo = "build-generated-java";
+                };
+                C592D6600E12F28E00D076FF /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CC600CDE75EC00472EA2;
+                        remoteInfo = "build-additions-java";
+                };
+                C592D6620E12F29200D076FF /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 89D7CCA20CDF9A2600472EA2;
+                        remoteInfo = "build-additions-native";
+                };
+                C5D197DA0DFB77E4006F9FB9 /* PBXContainerItemProxy */ = {
+                        isa = PBXContainerItemProxy;
+                        containerPortal = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+                        proxyType = 1;
+                        remoteGlobalIDString = 4CEBA78E08679EF10015D03E;
+                        remoteInfo = "build-core-native";
+                };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+                0AB364E40B2F671600788B6C /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; path = src; sourceTree = "<group>"; };
+                890FBACA0C6F781000902C32 /* JavaVM.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaVM.framework; path = /System/Library/Frameworks/JavaVM.framework; sourceTree = "<absolute>"; };
+                890FBACC0C6F782C00902C32 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+                896D90BB0CC2877C005625F5 /* JavaNativeFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaNativeFoundation.framework; path = /System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework; sourceTree = "<absolute>"; };
+                896D91230CC2ED34005625F5 /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
+                89736E5F0CE819E5008C4205 /* JObjC.jar */ = {isa = PBXFileReference; lastKnownFileType = archive.jar; path = JObjC.jar; sourceTree = BUILT_PRODUCTS_DIR; };
+                89D7C9EC0CDB900E00472EA2 /* CIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CIF.m; sourceTree = "<group>"; };
+                89D7C9ED0CDB900E00472EA2 /* Coder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Coder.m; sourceTree = "<group>"; };
+                89D7C9EE0CDB900E00472EA2 /* Function.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Function.m; sourceTree = "<group>"; };
+                89D7C9EF0CDB900E00472EA2 /* ID.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ID.m; sourceTree = "<group>"; };
+                89D7C9F00CDB900E00472EA2 /* JObjCRuntime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JObjCRuntime.m; sourceTree = "<group>"; };
+                89D7C9F10CDB900E00472EA2 /* MacOSXFramework.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MacOSXFramework.m; sourceTree = "<group>"; };
+                89D7C9F20CDB900E00472EA2 /* NativeBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeBuffer.h; sourceTree = "<group>"; };
+                89D7C9F30CDB900E00472EA2 /* NativeBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NativeBuffer.m; sourceTree = "<group>"; };
+                89D7C9F40CDB900E00472EA2 /* NativeObjectLifecycleManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NativeObjectLifecycleManager.m; sourceTree = "<group>"; };
+                89D7C9F50CDB900E00472EA2 /* NSClass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSClass.m; sourceTree = "<group>"; };
+                89D7C9F60CDB900E00472EA2 /* SEL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SEL.m; sourceTree = "<group>"; };
+                89D7CCB80CDF9A2600472EA2 /* libJObjC.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libJObjC.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
+                89D7CCBA0CDF9AA200472EA2 /* NativeString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NativeString.m; sourceTree = "<group>"; };
+                89D7CCBC0CDF9AB100472EA2 /* NativeNumber.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NativeNumber.m; sourceTree = "<group>"; };
+                89D7CCBE0CDF9AC600472EA2 /* NativeThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NativeThread.m; sourceTree = "<group>"; };
+                89E437680C97A7F200C756EE /* libffi.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libffi.dylib; path = /usr/lib/libffi.dylib; sourceTree = "<absolute>"; };
+                C5742F6B0E316EFA00093838 /* Subclassing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Subclassing.m; sourceTree = "<group>"; };
+                C5D196C80DF9E43C006F9FB9 /* FFIType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FFIType.m; sourceTree = "<group>"; };
+                C5E454790E36729F0046D3E8 /* Invoke.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Invoke.m; sourceTree = "<group>"; };
+                C5F3B1370E398F8E00B771AE /* FunCallBench.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FunCallBench.m; sourceTree = "<group>"; };
+                C5F3B1450E39910500B771AE /* libJObjC-tests.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = "libJObjC-tests.dylib"; sourceTree = BUILT_PRODUCTS_DIR; };
+                C5F3B2610E3AB0F300B771AE /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
+                C5F3B2630E3AB0F300B771AE /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
+                EB9FD8720AEECD83008E157E /* build.xml */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = build.xml; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+                4CEBA78D08679EF10015D03E /* Frameworks */ = {
+                        isa = PBXFrameworksBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                89D7CB770CDC4A6500472EA2 /* Foundation.framework in Frameworks */,
+                                89D7CB780CDC4A6500472EA2 /* JavaVM.framework in Frameworks */,
+                                89D7CB790CDC4A6500472EA2 /* JavaNativeFoundation.framework in Frameworks */,
+                                89D7CB7A0CDC4A6500472EA2 /* libffi.dylib in Frameworks */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+                89D7CCB00CDF9A2600472EA2 /* Frameworks */ = {
+                        isa = PBXFrameworksBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                89D7CCB10CDF9A2600472EA2 /* Foundation.framework in Frameworks */,
+                                89D7CCB20CDF9A2600472EA2 /* JavaVM.framework in Frameworks */,
+                                89D7CCB30CDF9A2600472EA2 /* JavaNativeFoundation.framework in Frameworks */,
+                                89D7CCB40CDF9A2600472EA2 /* libffi.dylib in Frameworks */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+                C5F3B1430E39910500B771AE /* Frameworks */ = {
+                        isa = PBXFrameworksBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                C5F3B2620E3AB0F300B771AE /* AppKit.framework in Frameworks */,
+                                C5F3B2640E3AB0F300B771AE /* Cocoa.framework in Frameworks */,
+                                C5F3B2650E3AB0F300B771AE /* Foundation.framework in Frameworks */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+                00E6828FFEC88D1A11DB9C8B = {
+                        isa = PBXGroup;
+                        children = (
+                                896D91230CC2ED34005625F5 /* README.txt */,
+                                EB9FD8720AEECD83008E157E /* build.xml */,
+                                0AB364E40B2F671600788B6C /* src */,
+                                89D7C9EB0CDB900E00472EA2 /* native-core */,
+                                89D7CA020CDB902200472EA2 /* native-additions */,
+                                C5A9597F0E398F050057C96D /* native-tests */,
+                                89D7CA030CDB903000472EA2 /* products */,
+                                890FBAC90C6F77B700902C32 /* frameworks */,
+                                C5F3B1450E39910500B771AE /* libJObjC-tests.dylib */,
+                                C5F3B2610E3AB0F300B771AE /* AppKit.framework */,
+                                C5F3B2630E3AB0F300B771AE /* Cocoa.framework */,
+                        );
+                        sourceTree = "<group>";
+                };
+                890FBAC90C6F77B700902C32 /* frameworks */ = {
+                        isa = PBXGroup;
+                        children = (
+                                890FBACC0C6F782C00902C32 /* Foundation.framework */,
+                                890FBACA0C6F781000902C32 /* JavaVM.framework */,
+                                896D90BB0CC2877C005625F5 /* JavaNativeFoundation.framework */,
+                                89E437680C97A7F200C756EE /* libffi.dylib */,
+                        );
+                        name = frameworks;
+                        sourceTree = "<group>";
+                };
+                89D7C9EB0CDB900E00472EA2 /* native-core */ = {
+                        isa = PBXGroup;
+                        children = (
+                                89D7C9EC0CDB900E00472EA2 /* CIF.m */,
+                                89D7C9ED0CDB900E00472EA2 /* Coder.m */,
+                                C5D196C80DF9E43C006F9FB9 /* FFIType.m */,
+                                89D7C9EE0CDB900E00472EA2 /* Function.m */,
+                                89D7C9EF0CDB900E00472EA2 /* ID.m */,
+                                C5E454790E36729F0046D3E8 /* Invoke.m */,
+                                89D7C9F00CDB900E00472EA2 /* JObjCRuntime.m */,
+                                89D7C9F10CDB900E00472EA2 /* MacOSXFramework.m */,
+                                89D7C9F20CDB900E00472EA2 /* NativeBuffer.h */,
+                                89D7C9F30CDB900E00472EA2 /* NativeBuffer.m */,
+                                89D7C9F40CDB900E00472EA2 /* NativeObjectLifecycleManager.m */,
+                                89D7C9F50CDB900E00472EA2 /* NSClass.m */,
+                                89D7C9F60CDB900E00472EA2 /* SEL.m */,
+                                C5742F6B0E316EFA00093838 /* Subclassing.m */,
+                        );
+                        name = "native-core";
+                        path = src/core/native;
+                        sourceTree = "<group>";
+                };
+                89D7CA020CDB902200472EA2 /* native-additions */ = {
+                        isa = PBXGroup;
+                        children = (
+                                89D7CCBA0CDF9AA200472EA2 /* NativeString.m */,
+                                89D7CCBC0CDF9AB100472EA2 /* NativeNumber.m */,
+                                89D7CCBE0CDF9AC600472EA2 /* NativeThread.m */,
+                        );
+                        name = "native-additions";
+                        path = "src/runtime-additions/native";
+                        sourceTree = "<group>";
+                };
+                89D7CA030CDB903000472EA2 /* products */ = {
+                        isa = PBXGroup;
+                        children = (
+                                89736E5F0CE819E5008C4205 /* JObjC.jar */,
+                                89D7CCB80CDF9A2600472EA2 /* libJObjC.dylib */,
+                        );
+                        name = products;
+                        path = "src/runtime-additions/native";
+                        sourceTree = "<group>";
+                };
+                C5A9597F0E398F050057C96D /* native-tests */ = {
+                        isa = PBXGroup;
+                        children = (
+                                C5F3B1370E398F8E00B771AE /* FunCallBench.m */,
+                        );
+                        name = "native-tests";
+                        path = src/tests/native;
+                        sourceTree = "<group>";
+                };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+                4CEBA78B08679EF10015D03E /* Headers */ = {
+                        isa = PBXHeadersBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                89D7C9FD0CDB900E00472EA2 /* NativeBuffer.h in Headers */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+                89D7CCA30CDF9A2600472EA2 /* Headers */ = {
+                        isa = PBXHeadersBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                89D7CCA40CDF9A2600472EA2 /* NativeBuffer.h in Headers */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+                C5F3B1410E39910500B771AE /* Headers */ = {
+                        isa = PBXHeadersBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXLegacyTarget section */
+                89D7CA160CDBA94D00472EA2 /* build-generator-java */ = {
+                        isa = PBXLegacyTarget;
+                        buildArgumentsString = "-verbose -emacs $ACTION";
+                        buildConfigurationList = 89D7CA1C0CDBA9B000472EA2 /* Build configuration list for PBXLegacyTarget "build-generator-java" */;
+                        buildPhases = (
+                        );
+                        buildToolPath = /usr/bin/ant;
+                        dependencies = (
+                                2CC7556D13A132B200B09D1B /* PBXTargetDependency */,
+                                2CC7556B13A132AF00B09D1B /* PBXTargetDependency */,
+                        );
+                        name = "build-generator-java";
+                        passBuildSettingsInEnvironment = 1;
+                        productName = "generator-build-java";
+                };
+                89D7CB870CDC4ED000472EA2 /* run-generator */ = {
+                        isa = PBXLegacyTarget;
+                        buildArgumentsString = "-verbose -emacs $ACTION";
+                        buildConfigurationList = 89D7CB8E0CDC4ED900472EA2 /* Build configuration list for PBXLegacyTarget "run-generator" */;
+                        buildPhases = (
+                        );
+                        buildToolPath = /usr/bin/ant;
+                        dependencies = (
+                                2CC7556513A1323700B09D1B /* PBXTargetDependency */,
+                        );
+                        name = "run-generator";
+                        passBuildSettingsInEnvironment = 1;
+                        productName = "run-generator";
+                };
+                89D7CC4C0CDE4C0400472EA2 /* build-generated-java */ = {
+                        isa = PBXLegacyTarget;
+                        buildArgumentsString = "-verbose -emacs $ACTION";
+                        buildConfigurationList = 89D7CC510CDE4C5200472EA2 /* Build configuration list for PBXLegacyTarget "build-generated-java" */;
+                        buildPhases = (
+                        );
+                        buildToolPath = /usr/bin/ant;
+                        dependencies = (
+                                2CC7556913A1325700B09D1B /* PBXTargetDependency */,
+                        );
+                        name = "build-generated-java";
+                        passBuildSettingsInEnvironment = 1;
+                        productName = "build-generated-java";
+                };
+                89D7CC600CDE75EC00472EA2 /* build-additions-java */ = {
+                        isa = PBXLegacyTarget;
+                        buildArgumentsString = "-verbose -emacs $ACTION";
+                        buildConfigurationList = 89D7CC630CDE762000472EA2 /* Build configuration list for PBXLegacyTarget "build-additions-java" */;
+                        buildPhases = (
+                        );
+                        buildToolPath = /usr/bin/ant;
+                        dependencies = (
+                        );
+                        name = "build-additions-java";
+                        passBuildSettingsInEnvironment = 1;
+                        productName = "build-additions-java";
+                };
+                89D7CC720CDE767500472EA2 /* assemble-product-java */ = {
+                        isa = PBXLegacyTarget;
+                        buildArgumentsString = "-verbose -emacs $ACTION";
+                        buildConfigurationList = 89D7CC7A0CDE76F500472EA2 /* Build configuration list for PBXLegacyTarget "assemble-product-java" */;
+                        buildPhases = (
+                        );
+                        buildToolPath = /usr/bin/ant;
+                        dependencies = (
+                        );
+                        name = "assemble-product-java";
+                        passBuildSettingsInEnvironment = 1;
+                        productName = "package-product";
+                };
+                C5F3B1530E39927900B771AE /* build-test-java */ = {
+                        isa = PBXLegacyTarget;
+                        buildArgumentsString = "-verbose -emacs $ACTION";
+                        buildConfigurationList = C5F3B15B0E3992AC00B771AE /* Build configuration list for PBXLegacyTarget "build-test-java" */;
+                        buildPhases = (
+                        );
+                        buildToolPath = /usr/bin/ant;
+                        dependencies = (
+                        );
+                        name = "build-test-java";
+                        passBuildSettingsInEnvironment = 1;
+                        productName = "build-test";
+                };
+                EB9FD8610AEECCF5008E157E /* build-core-java */ = {
+                        isa = PBXLegacyTarget;
+                        buildArgumentsString = "-verbose -emacs $ACTION";
+                        buildConfigurationList = EB9FD8690AEECD13008E157E /* Build configuration list for PBXLegacyTarget "build-core-java" */;
+                        buildPhases = (
+                        );
+                        buildToolPath = /usr/bin/ant;
+                        buildWorkingDirectory = "";
+                        dependencies = (
+                        );
+                        name = "build-core-java";
+                        passBuildSettingsInEnvironment = 1;
+                        productName = AntJNIWrapper;
+                };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+                4CEBA78E08679EF10015D03E /* build-core-native */ = {
+                        isa = PBXNativeTarget;
+                        buildConfigurationList = 4CEBA79108679F100015D03E /* Build configuration list for PBXNativeTarget "build-core-native" */;
+                        buildPhases = (
+                                4CEBA78B08679EF10015D03E /* Headers */,
+                                4CEBA78C08679EF10015D03E /* Sources */,
+                                4CEBA78D08679EF10015D03E /* Frameworks */,
+                        );
+                        buildRules = (
+                        );
+                        dependencies = (
+                                2CC7556113A1322100B09D1B /* PBXTargetDependency */,
+                        );
+                        name = "build-core-native";
+                        productName = DylibN;
+                        productType = "com.apple.product-type.library.dynamic";
+                };
+                89D7CCA20CDF9A2600472EA2 /* build-additions-native */ = {
+                        isa = PBXNativeTarget;
+                        buildConfigurationList = 89D7CCB50CDF9A2600472EA2 /* Build configuration list for PBXNativeTarget "build-additions-native" */;
+                        buildPhases = (
+                                89D7CCA30CDF9A2600472EA2 /* Headers */,
+                                89D7CCA50CDF9A2600472EA2 /* Sources */,
+                                89D7CCB00CDF9A2600472EA2 /* Frameworks */,
+                        );
+                        buildRules = (
+                        );
+                        dependencies = (
+                                2CC7556713A1324300B09D1B /* PBXTargetDependency */,
+                                C5D197DB0DFB77E4006F9FB9 /* PBXTargetDependency */,
+                        );
+                        name = "build-additions-native";
+                        productName = DylibN;
+                        productReference = 89D7CCB80CDF9A2600472EA2 /* libJObjC.dylib */;
+                        productType = "com.apple.product-type.library.dynamic";
+                };
+                C5F3B1440E39910500B771AE /* build-test-native */ = {
+                        isa = PBXNativeTarget;
+                        buildConfigurationList = C5F3B1480E39917500B771AE /* Build configuration list for PBXNativeTarget "build-test-native" */;
+                        buildPhases = (
+                                C5F3B1410E39910500B771AE /* Headers */,
+                                C5F3B1420E39910500B771AE /* Sources */,
+                                C5F3B1430E39910500B771AE /* Frameworks */,
+                        );
+                        buildRules = (
+                        );
+                        dependencies = (
+                                2CC7556313A1322800B09D1B /* PBXTargetDependency */,
+                        );
+                        name = "build-test-native";
+                        productName = "build-tests-native";
+                        productReference = C5F3B1450E39910500B771AE /* libJObjC-tests.dylib */;
+                        productType = "com.apple.product-type.library.dynamic";
+                };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+                00E6828EFEC88D1A11DB9C8B /* Project object */ = {
+                        isa = PBXProject;
+                        attributes = {
+                                LastUpgradeCheck = 0410;
+                        };
+                        buildConfigurationList = 4CEBA75C08679E4D0015D03E /* Build configuration list for PBXProject "JObjC" */;
+                        compatibilityVersion = "Xcode 3.0";
+                        developmentRegion = English;
+                        hasScannedForEncodings = 1;
+                        knownRegions = (
+                                English,
+                                Japanese,
+                                French,
+                                German,
+                        );
+                        mainGroup = 00E6828FFEC88D1A11DB9C8B;
+                        productRefGroup = 00E6828FFEC88D1A11DB9C8B;
+                        projectDirPath = "";
+                        projectRoot = "";
+                        targets = (
+                                89EBD58C0C95F43D000F04A0 /* B&I */,
+                                EB9FD8610AEECCF5008E157E /* build-core-java */,
+                                4CEBA78E08679EF10015D03E /* build-core-native */,
+                                89D7CA160CDBA94D00472EA2 /* build-generator-java */,
+                                89D7CB870CDC4ED000472EA2 /* run-generator */,
+                                89D7CC4C0CDE4C0400472EA2 /* build-generated-java */,
+                                89D7CC600CDE75EC00472EA2 /* build-additions-java */,
+                                89D7CCA20CDF9A2600472EA2 /* build-additions-native */,
+                                89D7CC720CDE767500472EA2 /* assemble-product-java */,
+                                C5F3B1530E39927900B771AE /* build-test-java */,
+                                C5F3B1440E39910500B771AE /* build-test-native */,
+                        );
+                };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+                4CEBA78C08679EF10015D03E /* Sources */ = {
+                        isa = PBXSourcesBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                C5E4547B0E36729F0046D3E8 /* Invoke.m in Sources */,
+                                C5742F6D0E316EFA00093838 /* Subclassing.m in Sources */,
+                                89D7C9F70CDB900E00472EA2 /* CIF.m in Sources */,
+                                89D7C9F80CDB900E00472EA2 /* Coder.m in Sources */,
+                                89D7C9F90CDB900E00472EA2 /* Function.m in Sources */,
+                                89D7C9FA0CDB900E00472EA2 /* ID.m in Sources */,
+                                89D7C9FB0CDB900E00472EA2 /* JObjCRuntime.m in Sources */,
+                                89D7C9FC0CDB900E00472EA2 /* MacOSXFramework.m in Sources */,
+                                89D7C9FE0CDB900E00472EA2 /* NativeBuffer.m in Sources */,
+                                89D7C9FF0CDB900E00472EA2 /* NativeObjectLifecycleManager.m in Sources */,
+                                89D7CA000CDB900E00472EA2 /* NSClass.m in Sources */,
+                                89D7CA010CDB900E00472EA2 /* SEL.m in Sources */,
+                                C5D196C90DF9E43C006F9FB9 /* FFIType.m in Sources */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+                89D7CCA50CDF9A2600472EA2 /* Sources */ = {
+                        isa = PBXSourcesBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                C5E4547D0E367DAB0046D3E8 /* Invoke.m in Sources */,
+                                C5742F700E316F8600093838 /* Subclassing.m in Sources */,
+                                89D7CCA60CDF9A2600472EA2 /* CIF.m in Sources */,
+                                89D7CCA70CDF9A2600472EA2 /* Coder.m in Sources */,
+                                89D7CCA80CDF9A2600472EA2 /* Function.m in Sources */,
+                                89D7CCA90CDF9A2600472EA2 /* ID.m in Sources */,
+                                89D7CCAA0CDF9A2600472EA2 /* JObjCRuntime.m in Sources */,
+                                89D7CCAB0CDF9A2600472EA2 /* MacOSXFramework.m in Sources */,
+                                89D7CCAC0CDF9A2600472EA2 /* NativeBuffer.m in Sources */,
+                                89D7CCAD0CDF9A2600472EA2 /* NativeObjectLifecycleManager.m in Sources */,
+                                89D7CCAE0CDF9A2600472EA2 /* NSClass.m in Sources */,
+                                89D7CCAF0CDF9A2600472EA2 /* SEL.m in Sources */,
+                                89D7CCBB0CDF9AA200472EA2 /* NativeString.m in Sources */,
+                                89D7CCBD0CDF9AB100472EA2 /* NativeNumber.m in Sources */,
+                                89D7CCBF0CDF9AC600472EA2 /* NativeThread.m in Sources */,
+                                C5D197D90DFB77C6006F9FB9 /* FFIType.m in Sources */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+                C5F3B1420E39910500B771AE /* Sources */ = {
+                        isa = PBXSourcesBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                C5F3B23D0E39948300B771AE /* FunCallBench.m in Sources */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+                2CC7556113A1322100B09D1B /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = EB9FD8610AEECCF5008E157E /* build-core-java */;
+                        targetProxy = 2CC7556013A1322100B09D1B /* PBXContainerItemProxy */;
+                };
+                2CC7556313A1322800B09D1B /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = C5F3B1530E39927900B771AE /* build-test-java */;
+                        targetProxy = 2CC7556213A1322800B09D1B /* PBXContainerItemProxy */;
+                };
+                2CC7556513A1323700B09D1B /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CA160CDBA94D00472EA2 /* build-generator-java */;
+                        targetProxy = 2CC7556413A1323700B09D1B /* PBXContainerItemProxy */;
+                };
+                2CC7556713A1324300B09D1B /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CC600CDE75EC00472EA2 /* build-additions-java */;
+                        targetProxy = 2CC7556613A1324300B09D1B /* PBXContainerItemProxy */;
+                };
+                2CC7556913A1325700B09D1B /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CB870CDC4ED000472EA2 /* run-generator */;
+                        targetProxy = 2CC7556813A1325700B09D1B /* PBXContainerItemProxy */;
+                };
+                2CC7556B13A132AF00B09D1B /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 4CEBA78E08679EF10015D03E /* build-core-native */;
+                        targetProxy = 2CC7556A13A132AF00B09D1B /* PBXContainerItemProxy */;
+                };
+                2CC7556D13A132B200B09D1B /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = EB9FD8610AEECCF5008E157E /* build-core-java */;
+                        targetProxy = 2CC7556C13A132B200B09D1B /* PBXContainerItemProxy */;
+                };
+                89D7CB9C0CDC64F800472EA2 /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CB870CDC4ED000472EA2 /* run-generator */;
+                        targetProxy = 89D7CB9B0CDC64F800472EA2 /* PBXContainerItemProxy */;
+                };
+                89D7CC920CDE7A8200472EA2 /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CC720CDE767500472EA2 /* assemble-product-java */;
+                        targetProxy = 89D7CC910CDE7A8200472EA2 /* PBXContainerItemProxy */;
+                };
+                C592D6590E12F27400D076FF /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = EB9FD8610AEECCF5008E157E /* build-core-java */;
+                        targetProxy = C592D6580E12F27400D076FF /* PBXContainerItemProxy */;
+                };
+                C592D65B0E12F27600D076FF /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 4CEBA78E08679EF10015D03E /* build-core-native */;
+                        targetProxy = C592D65A0E12F27600D076FF /* PBXContainerItemProxy */;
+                };
+                C592D65D0E12F27E00D076FF /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CA160CDBA94D00472EA2 /* build-generator-java */;
+                        targetProxy = C592D65C0E12F27E00D076FF /* PBXContainerItemProxy */;
+                };
+                C592D65F0E12F28500D076FF /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CC4C0CDE4C0400472EA2 /* build-generated-java */;
+                        targetProxy = C592D65E0E12F28500D076FF /* PBXContainerItemProxy */;
+                };
+                C592D6610E12F28E00D076FF /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CC600CDE75EC00472EA2 /* build-additions-java */;
+                        targetProxy = C592D6600E12F28E00D076FF /* PBXContainerItemProxy */;
+                };
+                C592D6630E12F29200D076FF /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 89D7CCA20CDF9A2600472EA2 /* build-additions-native */;
+                        targetProxy = C592D6620E12F29200D076FF /* PBXContainerItemProxy */;
+                };
+                C5D197DB0DFB77E4006F9FB9 /* PBXTargetDependency */ = {
+                        isa = PBXTargetDependency;
+                        target = 4CEBA78E08679EF10015D03E /* build-core-native */;
+                        targetProxy = C5D197DA0DFB77E4006F9FB9 /* PBXContainerItemProxy */;
+                };
+/* End PBXTargetDependency section */
+
+/* Begin XCBuildConfiguration section */
+                4CEBA75D08679E4D0015D03E /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ARCHS = (
+                                        "$(NATIVE_ARCH_32_BIT)",
+                                        "$(NATIVE_ARCH_64_BIT)",
+                                );
+                                GCC_ENABLE_OBJC_GC = supported;
+                                SYMROOT = build;
+                        };
+                        name = Debug;
+                };
+                4CEBA75E08679E4D0015D03E /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                GCC_ENABLE_OBJC_GC = supported;
+                                INSTALL_PATH = /System/Library/Java/Extensions;
+                        };
+                        name = Release;
+                };
+                4CEBA79208679F100015D03E /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ARCHS = (
+                                        "$(NATIVE_ARCH_32_BIT)",
+                                        "$(NATIVE_ARCH_64_BIT)",
+                                );
+                                COPY_PHASE_STRIP = NO;
+                                DYLIB_COMPATIBILITY_VERSION = 1;
+                                DYLIB_CURRENT_VERSION = 1;
+                                EXECUTABLE_EXTENSION = dylib;
+                                EXECUTABLE_PREFIX = lib;
+                                FRAMEWORK_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                );
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+                                GCC_MODEL_TUNING = G5;
+                                GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+                                GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = YES;
+                                GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                                GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                                GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
+                                GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES;
+                                GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
+                                GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+                                GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+                                GCC_WARN_MISSING_PARENTHESES = YES;
+                                GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+                                GCC_WARN_PEDANTIC = NO;
+                                GCC_WARN_PROTOTYPE_CONVERSION = NO;
+                                GCC_WARN_SHADOW = YES;
+                                GCC_WARN_SIGN_COMPARE = YES;
+                                GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
+                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
+                                GCC_WARN_UNKNOWN_PRAGMAS = YES;
+                                GCC_WARN_UNUSED_FUNCTION = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                HEADER_SEARCH_PATHS = (
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                        /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers,
+                                );
+                                HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/core\" \"$(OBJROOT)/src/jni_headers/core\"";
+                                LIBRARY_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+                                );
+                                LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries\"";
+                                LIBRARY_STYLE = DYNAMIC;
+                                MACH_O_TYPE = mh_dylib;
+                                OTHER_LDFLAGS = "";
+                                OTHER_REZFLAGS = "";
+                                PRODUCT_NAME = JObjC;
+                                SECTORDER_FLAGS = "";
+                                VALID_ARCHS = "ppc7400 ppc970 i386 x86_64 ppc";
+                                WARNING_CFLAGS = (
+                                        "-Wmost",
+                                        "-Wno-four-char-constants",
+                                        "-Wno-unknown-pragmas",
+                                        "-Wformat",
+                                        "-Wformat-security",
+                                        "-Wcast-align",
+                                        "-Wwrite-strings",
+                                        "-Wuninitialized",
+                                        "-Wshadow",
+                                        "-Wshorten-64-to-32",
+                                        "-Wsign-compare",
+                                        "-Wpointer-arith",
+                                        "-Wall",
+                                );
+                                ZERO_LINK = NO;
+                        };
+                        name = Debug;
+                };
+                4CEBA79308679F100015D03E /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ARCHS = (
+                                        i386,
+                                        ppc,
+                                        x86_64,
+                                );
+                                COPY_PHASE_STRIP = YES;
+                                DYLIB_COMPATIBILITY_VERSION = 1;
+                                DYLIB_CURRENT_VERSION = 1;
+                                EXECUTABLE_EXTENSION = dylib;
+                                EXECUTABLE_PREFIX = lib;
+                                FRAMEWORK_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                );
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+                                GCC_MODEL_TUNING = G5;
+                                GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+                                GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = YES;
+                                GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                                GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                                GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
+                                GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES;
+                                GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
+                                GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+                                GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+                                GCC_WARN_MISSING_PARENTHESES = YES;
+                                GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+                                GCC_WARN_PEDANTIC = NO;
+                                GCC_WARN_PROTOTYPE_CONVERSION = NO;
+                                GCC_WARN_SHADOW = YES;
+                                GCC_WARN_SIGN_COMPARE = YES;
+                                GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
+                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
+                                GCC_WARN_UNKNOWN_PRAGMAS = YES;
+                                GCC_WARN_UNUSED_FUNCTION = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                HEADER_SEARCH_PATHS = (
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                        /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers,
+                                );
+                                HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/core\" \"$(OBJROOT)/src/jni_headers/core\"";
+                                LIBRARY_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                );
+                                LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries\"";
+                                LIBRARY_STYLE = DYNAMIC;
+                                MACH_O_TYPE = mh_dylib;
+                                OTHER_LDFLAGS = "";
+                                OTHER_REZFLAGS = "";
+                                PRODUCT_NAME = JObjC;
+                                SECTORDER_FLAGS = "";
+                                VALID_ARCHS = "ppc7400 ppc970 i386 x86_64 ppc";
+                                WARNING_CFLAGS = (
+                                        "-Wmost",
+                                        "-Wno-four-char-constants",
+                                        "-Wno-unknown-pragmas",
+                                        "-Wformat",
+                                        "-Wformat-security",
+                                        "-Wcast-align",
+                                        "-Wwrite-strings",
+                                        "-Wuninitialized",
+                                        "-Wshadow",
+                                        "-Wshorten-64-to-32",
+                                        "-Wsign-compare",
+                                        "-Wpointer-arith",
+                                        "-Wall",
+                                );
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                89D7CA170CDBA94D00472EA2 /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                PRODUCT_NAME = "build-generator";
+                        };
+                        name = Debug;
+                };
+                89D7CA180CDBA94D00472EA2 /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                PRODUCT_NAME = "build-generator";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                89D7CB880CDC4ED000472EA2 /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_OPTIMIZATION_LEVEL = "\U00010";
+                                PRODUCT_NAME = "run-generator";
+                        };
+                        name = Debug;
+                };
+                89D7CB890CDC4ED000472EA2 /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                PRODUCT_NAME = "run-generator";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                89D7CC4D0CDE4C0400472EA2 /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                PRODUCT_NAME = "build-generated";
+                        };
+                        name = Debug;
+                };
+                89D7CC4E0CDE4C0400472EA2 /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                PRODUCT_NAME = "build-generated";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                89D7CC610CDE75EC00472EA2 /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                PRODUCT_NAME = "build-additions";
+                        };
+                        name = Debug;
+                };
+                89D7CC620CDE75EC00472EA2 /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                PRODUCT_NAME = "build-additions";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                89D7CC730CDE767500472EA2 /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                PRODUCT_NAME = "assemble-product";
+                        };
+                        name = Debug;
+                };
+                89D7CC740CDE767500472EA2 /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                PRODUCT_NAME = "assemble-product";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                89D7CCB60CDF9A2600472EA2 /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ARCHS = (
+                                        "$(NATIVE_ARCH_32_BIT)",
+                                        "$(NATIVE_ARCH_64_BIT)",
+                                );
+                                COPY_PHASE_STRIP = NO;
+                                DYLIB_COMPATIBILITY_VERSION = 1;
+                                DYLIB_CURRENT_VERSION = 1;
+                                EXECUTABLE_EXTENSION = dylib;
+                                EXECUTABLE_PREFIX = lib;
+                                FRAMEWORK_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                );
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+                                GCC_MODEL_TUNING = G5;
+                                GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+                                GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = YES;
+                                GCC_TREAT_WARNINGS_AS_ERRORS = NO;
+                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                                GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                                GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
+                                GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES;
+                                GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
+                                GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+                                GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+                                GCC_WARN_MISSING_PARENTHESES = YES;
+                                GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+                                GCC_WARN_PEDANTIC = NO;
+                                GCC_WARN_PROTOTYPE_CONVERSION = NO;
+                                GCC_WARN_SHADOW = YES;
+                                GCC_WARN_SIGN_COMPARE = YES;
+                                GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
+                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
+                                GCC_WARN_UNKNOWN_PRAGMAS = YES;
+                                GCC_WARN_UNUSED_FUNCTION = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                HEADER_SEARCH_PATHS = (
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                        /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers,
+                                );
+                                HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/core\" \"$(OBJROOT)/src/jni_headers/core\"";
+                                HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/additions\" \"$(OBJROOT)/src/jni_headers/additions\"";
+                                INSTALL_PATH = /usr/local/lib;
+                                LIBRARY_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
+                                );
+                                LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries\"";
+                                LIBRARY_STYLE = DYNAMIC;
+                                MACH_O_TYPE = mh_dylib;
+                                OTHER_LDFLAGS = "";
+                                OTHER_REZFLAGS = "";
+                                PRODUCT_NAME = JObjC;
+                                SECTORDER_FLAGS = "";
+                                VALID_ARCHS = "ppc7400 ppc970 i386 x86_64 ppc";
+                                WARNING_CFLAGS = (
+                                        "-Wmost",
+                                        "-Wno-four-char-constants",
+                                        "-Wno-unknown-pragmas",
+                                        "-Wformat",
+                                        "-Wformat-security",
+                                        "-Wcast-align",
+                                        "-Wwrite-strings",
+                                        "-Wuninitialized",
+                                        "-Wshadow",
+                                        "-Wshorten-64-to-32",
+                                        "-Wsign-compare",
+                                        "-Wpointer-arith",
+                                        "-Wall",
+                                );
+                                ZERO_LINK = NO;
+                        };
+                        name = Debug;
+                };
+                89D7CCB70CDF9A2600472EA2 /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ARCHS = (
+                                        x86_64,
+                                        ppc,
+                                        i386,
+                                );
+                                COPY_PHASE_STRIP = YES;
+                                DYLIB_COMPATIBILITY_VERSION = 1;
+                                DYLIB_CURRENT_VERSION = 1;
+                                EXECUTABLE_EXTENSION = dylib;
+                                EXECUTABLE_PREFIX = lib;
+                                FRAMEWORK_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                );
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+                                GCC_MODEL_TUNING = G5;
+                                GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+                                GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = YES;
+                                GCC_TREAT_WARNINGS_AS_ERRORS = NO;
+                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                                GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                                GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
+                                GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES;
+                                GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
+                                GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+                                GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+                                GCC_WARN_MISSING_PARENTHESES = YES;
+                                GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+                                GCC_WARN_PEDANTIC = NO;
+                                GCC_WARN_PROTOTYPE_CONVERSION = NO;
+                                GCC_WARN_SHADOW = YES;
+                                GCC_WARN_SIGN_COMPARE = YES;
+                                GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
+                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
+                                GCC_WARN_UNKNOWN_PRAGMAS = YES;
+                                GCC_WARN_UNUSED_FUNCTION = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                HEADER_SEARCH_PATHS = (
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                        /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers,
+                                );
+                                HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/core\"  \"$(OBJROOT)/src/jni_headers/core\"";
+                                HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/additions\"  \"$(OBJROOT)/src/jni_headers/additions\"";
+                                LIBRARY_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                );
+                                LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries\"";
+                                LIBRARY_STYLE = DYNAMIC;
+                                MACH_O_TYPE = mh_dylib;
+                                OTHER_LDFLAGS = "";
+                                OTHER_REZFLAGS = "";
+                                PRODUCT_NAME = JObjC;
+                                SECTORDER_FLAGS = "";
+                                VALID_ARCHS = "ppc7400 ppc970 i386 x86_64 ppc";
+                                WARNING_CFLAGS = (
+                                        "-Wmost",
+                                        "-Wno-four-char-constants",
+                                        "-Wno-unknown-pragmas",
+                                        "-Wformat",
+                                        "-Wformat-security",
+                                        "-Wcast-align",
+                                        "-Wwrite-strings",
+                                        "-Wuninitialized",
+                                        "-Wshadow",
+                                        "-Wshorten-64-to-32",
+                                        "-Wsign-compare",
+                                        "-Wpointer-arith",
+                                        "-Wall",
+                                );
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                89EBD58D0C95F43D000F04A0 /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                PRODUCT_NAME = "B&I";
+                        };
+                        name = Debug;
+                };
+                89EBD58E0C95F43D000F04A0 /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                PRODUCT_NAME = "B&I";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                C5F3B1460E39910500B771AE /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = YES;
+                                ARCHS = (
+                                        x86_64,
+                                        i386,
+                                        ppc,
+                                );
+                                COPY_PHASE_STRIP = NO;
+                                DEBUG_INFORMATION_FORMAT = dwarf;
+                                EXECUTABLE_EXTENSION = dylib;
+                                EXECUTABLE_PREFIX = lib;
+                                FRAMEWORK_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                );
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_MODEL_TUNING = G5;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                HEADER_SEARCH_PATHS = (
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                        /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers,
+                                        "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/core\"",
+                                        "\"$(OBJROOT)/src/jni_headers/core\"",
+                                        "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/additions\"",
+                                        "\"$(OBJROOT)/src/jni_headers/additions\"",
+                                        "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/test\"",
+                                        "\"$(OBJROOT)/src/jni_headers/test\"",
+                                );
+                                INSTALL_PATH = /usr/local/lib;
+                                LIBRARY_STYLE = DYNAMIC;
+                                MACH_O_TYPE = mh_dylib;
+                                PRODUCT_NAME = "JObjC-tests";
+                                SKIP_INSTALL = YES;
+                        };
+                        name = Debug;
+                };
+                C5F3B1470E39910500B771AE /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = YES;
+                                ARCHS = (
+                                        x86_64,
+                                        i386,
+                                        ppc,
+                                );
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = dwarf;
+                                EXECUTABLE_EXTENSION = dylib;
+                                EXECUTABLE_PREFIX = lib;
+                                FRAMEWORK_SEARCH_PATHS = (
+                                        "$(inherited)",
+                                        "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                );
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_2 = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/JavaVM.framework/Versions/A/Frameworks\"";
+                                GCC_MODEL_TUNING = G5;
+                                HEADER_SEARCH_PATHS = (
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
+                                        "$(HEADER_SEARCH_PATHS_QUOTED_FOR_TARGET_2)",
+                                        /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers,
+                                        "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/core\"",
+                                        "\"$(OBJROOT)/src/jni_headers/core\"",
+                                        "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/additions\"",
+                                        "\"$(OBJROOT)/src/jni_headers/additions\"",
+                                        "\"$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/src/jni_headers/test\"",
+                                        "\"$(OBJROOT)/src/jni_headers/test\"",
+                                );
+                                INSTALL_PATH = /usr/local/lib;
+                                LIBRARY_STYLE = DYNAMIC;
+                                MACH_O_TYPE = mh_dylib;
+                                PRODUCT_NAME = "JObjC-tests";
+                                SKIP_INSTALL = YES;
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                C5F3B1540E39927A00B771AE /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                PRODUCT_NAME = "build-test";
+                        };
+                        name = Debug;
+                };
+                C5F3B1550E39927A00B771AE /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                                PRODUCT_NAME = "build-test";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+                EB9FD86A0AEECD13008E157E /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = NO;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                PRODUCT_NAME = "build-core";
+                        };
+                        name = Debug;
+                };
+                EB9FD86B0AEECD13008E157E /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                COPY_PHASE_STRIP = YES;
+                                GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+                                PRODUCT_NAME = "build-core";
+                                ZERO_LINK = NO;
+                        };
+                        name = Release;
+                };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+                4CEBA75C08679E4D0015D03E /* Build configuration list for PBXProject "JObjC" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                4CEBA75D08679E4D0015D03E /* Debug */,
+                                4CEBA75E08679E4D0015D03E /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                4CEBA79108679F100015D03E /* Build configuration list for PBXNativeTarget "build-core-native" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                4CEBA79208679F100015D03E /* Debug */,
+                                4CEBA79308679F100015D03E /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                89D7CA1C0CDBA9B000472EA2 /* Build configuration list for PBXLegacyTarget "build-generator-java" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                89D7CA170CDBA94D00472EA2 /* Debug */,
+                                89D7CA180CDBA94D00472EA2 /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                89D7CB8E0CDC4ED900472EA2 /* Build configuration list for PBXLegacyTarget "run-generator" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                89D7CB880CDC4ED000472EA2 /* Debug */,
+                                89D7CB890CDC4ED000472EA2 /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                89D7CC510CDE4C5200472EA2 /* Build configuration list for PBXLegacyTarget "build-generated-java" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                89D7CC4D0CDE4C0400472EA2 /* Debug */,
+                                89D7CC4E0CDE4C0400472EA2 /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                89D7CC630CDE762000472EA2 /* Build configuration list for PBXLegacyTarget "build-additions-java" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                89D7CC610CDE75EC00472EA2 /* Debug */,
+                                89D7CC620CDE75EC00472EA2 /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                89D7CC7A0CDE76F500472EA2 /* Build configuration list for PBXLegacyTarget "assemble-product-java" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                89D7CC730CDE767500472EA2 /* Debug */,
+                                89D7CC740CDE767500472EA2 /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                89D7CCB50CDF9A2600472EA2 /* Build configuration list for PBXNativeTarget "build-additions-native" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                89D7CCB60CDF9A2600472EA2 /* Debug */,
+                                89D7CCB70CDF9A2600472EA2 /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                89EBD5930C95F44E000F04A0 /* Build configuration list for PBXAggregateTarget "B&I" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                89EBD58D0C95F43D000F04A0 /* Debug */,
+                                89EBD58E0C95F43D000F04A0 /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                C5F3B1480E39917500B771AE /* Build configuration list for PBXNativeTarget "build-test-native" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                C5F3B1460E39910500B771AE /* Debug */,
+                                C5F3B1470E39910500B771AE /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                C5F3B15B0E3992AC00B771AE /* Build configuration list for PBXLegacyTarget "build-test-java" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                C5F3B1540E39927A00B771AE /* Debug */,
+                                C5F3B1550E39927A00B771AE /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                EB9FD8690AEECD13008E157E /* Build configuration list for PBXLegacyTarget "build-core-java" */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                EB9FD86A0AEECD13008E157E /* Debug */,
+                                EB9FD86B0AEECD13008E157E /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+/* End XCConfigurationList section */
+        };
+        rootObject = 00E6828EFEC88D1A11DB9C8B /* Project object */;
+}
diff --git a/jdk/src/macosx/native/jobjc/README.txt b/jdk/src/macosx/native/jobjc/README.txt
new file mode 100644
index 0000000..bfc63e3
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/README.txt
@@ -0,0 +1,132 @@
+#title JObjC
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+JObjC core provides a pure Java interface for calling C functions and
+sending ObjC messages. Given some information, it can marshal types
+automatically.
+
+It also parses BridgeSupport to generate Java wrappers around
+Framework bundles. These wrappers rely on the core to provide access
+to the C constants, enums, structs, functions, ObjC classes, etc of a
+framework.
+
+* How to build it
+
+Your best option is `ant all`. There's an Xcode "B&I" target that
+works for buildit.
+
+You'll need a recent JavaNativeFoundation, and perhaps some other
+things. Everything is usually there on SnowLeopard (or Leopard after
+the common ~javabuild/bin/update runs).
+
+The build process is quite involved. Xcode takes care of the native
+parts, ant takes care of the Java parts, and there's an unholy mix of
+external targets and hidden dependencies that keep Xcode and ant (and
+buildit on top of that) from stepping on each other. So a warning: the
+ant and Xcode targets don't have proper dependencies set up because of
+this. They have some dependencies configured, but not the entire
+chain. This is because of the jumping back and forth between
+externals. If you run the aggregate targets (Xcode B&I, ant all, ant
+test, ant bench), everything's is good. But if you manually invoke
+individual targets, chances are you'll miss something. Let's go over
+it all step by step:
+
+** ant gen-pcoder
+
+The PrimitiveCoder subclasses have a lot of boiler plate which
+simplifies the generated MixedPrimitiveCoder classes. So instead of
+maintaining it, I maintain a tiny Haskell script that spits out the
+Java code. This ant target runs that script if Haskell is available on
+the system. If it isn't available, this will silently fail. That's
+okay, because chances are the PrimitiveCoder.java that you got from
+svn is current and does not need to be updated.
+
+** ant build-core / Xcode build-core-java
+
+Build core simply builds the JObjC core java classes, and also
+generates headers for the JNI for Xcode.
+
+** ant build-core-native / Xcode build-core-native
+
+Xcode builds the native core, using the headers from the Java core. It
+generates libJObjC.dylib.
+
+** ant build-generator / Xcode build-generator-java
+
+ant builds the generator.
+
+** ant run-generator / Xcode run-generator
+
+ant runs the generator, using the core Java and native classes.
+
+What is rungen? And what's run-generator-old? run-generator-old is the
+preferred way to run the generator from ant, but there's a strange bug
+when running from buildit that causes run-generator-old to
+freeze. Pratik was helping me debug it, inspecting the stack and
+snooping dtrace probes, but we never found the reason for the
+block. So I figured that maybe if I just add a layer of indirection
+maybe it'll work around that. And it did. Sad but true.
+
+** ant build-generated / Xcode build-generated-java
+
+Build the generator output.
+
+** ant build-additions / Xcode build-additions-java
+
+Builds java additions.
+
+** ant build-additions-native / Xcode build-additions-native
+
+This builds a new version of libJObjC.dylib. It will rebuild
+everything from the core, and include everything from additions.
+
+** ant assemble-product / Xcode assemble-product-java
+
+Create a jar, copy products to destination, etc.
+
+* How to test it
+
+The test cases also contain a Java component and a native component,
+and are built similarly to the above. The benchmarks are built
+together with the tests. So "ant build-test" and "ant
+build-test-native" will build both the benchmarks and the test. "ant
+test" will run the test. "ant bench" will run benchmarks. If you only
+want to run a specific benchmark, you can pass a regexp in the
+environment variable BENCH_MATCH.
+
+<src>
+ant test
+ant bench
+BENCH_MATCH=Foo ant bench
+</src>
+
+Test and bench reports will end up in
+build/JObjC.build/Debug/test-reports/
+
+* How to use it
+
+Include the jar in your classpath and set your java.library.path to
+the directory that contains the dylib. Same thing for app bundles.
diff --git a/jdk/src/macosx/native/jobjc/TODOS b/jdk/src/macosx/native/jobjc/TODOS
new file mode 100644
index 0000000..b9b157f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/TODOS
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+#
+egrep "(TODO|FIXME|XXX|HACK)" -r src
diff --git a/jdk/src/macosx/native/jobjc/bridgesupport.gmk b/jdk/src/macosx/native/jobjc/bridgesupport.gmk
new file mode 100644
index 0000000..4a85650
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/bridgesupport.gmk
@@ -0,0 +1,54 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# makefile for generating a stable set of bridgesupport files that change timestamp
+# only when the bridgesupport data actually changes
+
+FRAMEWORKS_DIR = /System/Library/Frameworks
+GBM = /usr/bin/gen_bridge_metadata
+GEN_HEADERS = $(addsuffix .headers,$(FRAMEWORKS))
+GEN_BRIDGESUPPORT = $(addsuffix .bridgesupport,$(FRAMEWORKS))
+
+%.bridgesupport : %.headers $(FRAMEWORKS_DIR)/%.framework/Headers/*.h
+	@echo "generating bridge support for" $<
+	if [ -f $(FRAMEWORKS_DIR)/$(<:.headers=.framework)/Resources/BridgeSupport/$(<:.headers=Full.bridgesupport) ] ; \
+	  then cp $(FRAMEWORKS_DIR)/$(<:.headers=.framework)/Resources/BridgeSupport/$(<:.headers=Full.bridgesupport) $@ ; \
+	  else $(GBM) -F complete --framework $(<:.headers=.framework) -o $@ ; \
+	fi
+	if cmp -s $@ $(STABLE_GEN_DIR)/$(@:.bridgesupport=Full.bridgesupport) ; \
+	  then : ; \
+	  else cp $@ $(STABLE_GEN_DIR)/$(@:.bridgesupport=Full.bridgesupport) ; \
+	fi
+
+%.headers : $(FRAMEWORKS_DIR)/%.framework/Headers
+	@echo linking $<
+	ln -s $< $@
+
+$(STABLE_GEN_DIR):
+	mkdir -p $(STABLE_GEN_DIR)
+
+$(GEN_BRIDGESUPPORT): $(GEN_HEADERS) $(STABLE_GEN_DIR)
+
+all: $(GEN_BRIDGESUPPORT)
diff --git a/jdk/src/macosx/native/jobjc/build.xml b/jdk/src/macosx/native/jobjc/build.xml
new file mode 100644
index 0000000..46e726c
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/build.xml
@@ -0,0 +1,512 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+#
+-->
+<project name="JObjC" default="install" basedir=".">
+  <property environment="env"/>
+  <echoproperties/>
+
+  <target name="installhdrs">
+    <echo>Nothing to do for install-headers build phase</echo>
+  </target>
+
+  <target name="installsrc">
+    <echo>Nothing to do for install-source build phase</echo>
+  </target>
+
+  <property name="redirection-target-defined" value="${env.PRODUCT_NAME}"/>
+
+  <target name="install" description="Redirects to the target specified in $PRODUCT_NAME">
+    <fail unless="env.PRODUCT_NAME" status="-1">
+      This Ant build file depends on the native Xcode project to invoke
+      targets by defining $PRODUCT_NAME to specify the target.
+    </fail>
+
+    <echo>--- Redirecting to target "${env.PRODUCT_NAME}"</echo>
+    <antcall target="${env.PRODUCT_NAME}"/>
+  </target>
+
+  <property name="compile.debug" value="true"/>
+
+  <!-- building from the command line / xcode b&i -->
+  <condition property="src" value="." else="${env.SRCROOT}">
+    <not><isset property="env.SRCROOT"/></not>
+  </condition>
+
+  <condition property="cfg" value="Debug" else="${env.CONFIGURATION}">
+    <not><isset property="env.CONFIGURATION"/></not>
+  </condition>
+
+  <condition property="obj" value="build/JObjC.build/${cfg}" else="${env.OBJROOT}">
+    <not><isset property="env.OBJROOT"/></not>
+  </condition>
+
+  <condition property="dst" value="build/${cfg}" else="${env.DSTROOT}/${cfg}">
+    <not><isset property="env.DSTROOT"/></not>
+  </condition>
+
+  <condition property="ARCHS" value="ppc i386 x86_64" else="${env.RC_ARCHS}">
+    <not><isset property="env.RC_ARCHS"/></not>
+  </condition>
+
+  <!-- -/- -->
+
+  <property name="bin" location="${obj}/bin"/>
+  <property name="gendoc" location="${obj}/doc"/>
+
+  <condition property="nativelib.dir" value="${dst}">
+    <not><isset property="env.CONFIGURATION_BUILD_DIR"/></not>
+  </condition>
+  <condition property="nativelib.dir" value="${env.CONFIGURATION_BUILD_DIR}">
+    <isset property="env.CONFIGURATION_BUILD_DIR"/>
+  </condition>
+  <property name="nativelib.file" location="${nativelib.dir}/libJObjC.dylib" />
+
+  <property name="jniheaders" location="${obj}/src/jni_headers"/>
+
+  <property name="core.src" location="${src}/src/core/java"/>
+  <property name="core.bin" location="${bin}/core"/>
+  <property name="core.jniheaders" location="${jniheaders}/core"/>
+  <property name="core.nativelib.dir" location="${nativelib.dir}"/>
+
+  <property name="generator.src" location="${src}/src/generator/java"/>
+  <property name="generator.bin" location="${bin}/generator"/>
+
+  <property name="generated.src" location="${obj}/src/jobjc"/>
+  <property name="generated.bin" location="${bin}/generated"/>
+
+  <property name="additions.src" location="${src}/src/runtime-additions"/>
+  <property name="additions.bin" location="${bin}/additions"/>
+  <property name="additions.jniheaders" location="${jniheaders}/additions"/>
+  <property name="additions.nativelib.dir" location="${nativelib.dir}"/>
+
+  <property name="test.src" location="${src}/src/tests/java"/>
+  <property name="test.bin" location="${bin}/test"/>
+  <property name="test.jniheaders" location="${jniheaders}/test"/>
+  <property name="test.reports" location="${obj}/test-reports"/>
+
+  <condition property="product.target_path"
+             value="/System/Library/Java/Extensions"
+             else="${env.INSTALL_PATH}">
+    <not><isset property="env.INSTALL_PATH"/></not>
+  </condition>
+
+  <echo message="(Settings :src '${src}' :cfg '${cfg}' :obj '${obj}' :dst '${dst}')"/>
+
+  <path id="test.lib.path.id">
+    <fileset dir="/usr/share/java">
+      <include name="**/*.jar"/>
+    </fileset>
+  </path>
+
+  <property name="product.jarfile.dir" location="${obj}"/>
+  <property name="product.jarfile.name" value="JObjC.jar"/>
+  <property name="product.jarfile" location="${product.jarfile.dir}/${product.jarfile.name}"/>
+
+  <target name="gen-pcoder" description="Generate PrimitiveCoder.java">
+    <exec executable="ruby" failonerror="true">
+      <arg value="${src}/run-and-write-if-okay"/>
+      <arg value="${src}/src/core/PrimitiveCoder.hs"/>
+      <arg value="${src}/src/core/java/com/apple/jobjc/PrimitiveCoder.java"/>
+    </exec>
+  </target>
+
+  <target name="build-core" depends="gen-pcoder" description="Compile the core runtime classes">
+    <mkdir dir="${core.bin}" />
+    <!-- Compile PrimitiveCoder first to work around javac bug. -->
+    <javac srcdir="${core.src}" destdir="${core.bin}" source="1.5" target="1.5" debug="${compile.debug}"
+           includes="**/PrimitiveCoder.java"
+           includeantruntime="false" />
+    <javac srcdir="${core.src}" destdir="${core.bin}" source="1.5" target="1.5" debug="${compile.debug}" includeantruntime="false" />
+
+    <exec executable="/usr/bin/perl" outputproperty="core.classes" failonerror="true">
+      <arg value="${src}/extract_classes.pl"/>
+      <arg path="${core.bin}"/>
+    </exec>
+
+    <mkdir dir="${core.jniheaders}" />
+    <javah destdir="${core.jniheaders}" class="${core.classes}">
+      <classpath path="${core.bin}"/>
+    </javah>
+  </target>
+
+  <target name="build-core-native" depends="build-core">
+    <exec executable="xcodebuild" failonerror="true">
+      <env key="CC" value=""/>
+      <env key="CXX" value=""/>
+      <arg value="-configuration"/>
+      <arg value="${cfg}"/>
+      <arg value="-target"/>
+      <arg value="build-core-native"/>
+      <arg value="SRCROOT=${src}"/>
+      <arg value="OBJROOT=${obj}"/>
+      <arg value="DSTROOT=${dst}"/>
+      <arg value="TARGET_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="PROJECT_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="BUILD_DIR=${env.DSTROOT}"/>
+    </exec>
+  </target>
+
+  <!-- macosx jdk 7 puts jobjc core classes on the bootclasspath by default -->
+  <target name="build-generator" description="Compile and assemble the generator">
+    <mkdir dir="${generator.bin}"/>
+    <javac srcdir="${generator.src}" destdir="${generator.bin}" source="1.5" target="1.5" debug="${compile.debug}" includeantruntime="false">
+      <compilerarg value="-version"/>
+      <compilerarg value="-Xbootclasspath/p:${core.bin}"/>
+    </javac>
+  </target>
+
+  <!-- Use this indirection hack to work around buildit lockup when
+  running the generator. -->
+  <target name="run-generator" depends="build-generator" description="Invoke the assembled generator">
+    <mkdir dir="${generated.src}"/>
+    <exec executable="ruby" failonerror="true">
+      <arg value="${src}/rungen"/>
+      <arg value="install"/>
+      <arg value="${product.jarfile.name}"/>
+      <arg value="${nativelib.dir}"/>
+      <arg value="${obj}"/>
+      <arg value="${ARCHS}"/>
+      <arg value="${env.STABLE_GEN_DIR}"/>
+    </exec>
+  </target>
+
+  <target name="run-generator-old" depends="build-generator" description="Invoke the assembled generator">
+    <mkdir dir="${generated.src}"/>
+    <java classname="com.apple.internal.jobjc.generator.Generator" fork="true" failonerror="true">
+      <jvmarg value="-Xms128m" />
+      <jvmarg value="-Xmx512m" />
+      <assertions><enable/></assertions>
+      <classpath>
+        <path location="${core.bin}"/>
+        <path location="${generator.bin}"/>
+      </classpath>
+      <sysproperty key="java.library.path" value="${core.nativelib.dir}"/>
+      <arg value="dst=${generated.src}"/>
+    </java>
+  </target>
+
+  <target name="build-generated" description="Build and assemble the JObjC core and all generated frameworks">
+    <mkdir dir="${generated.bin}"/>
+    <javac srcdir="${generated.src}" destdir="${generated.bin}" source="1.5" target="1.5" fork="yes" memoryMaximumSize="512m" debug="${compile.debug}" includeantruntime="false">
+      <classpath>
+        <path location="${core.bin}"/>
+      </classpath>
+      <compilerarg value="-version"/>
+    </javac>
+  </target>
+
+  <target name="build-additions" depends="build-generated">
+    <mkdir dir="${additions.bin}"/>
+    <javac srcdir="${additions.src}" destdir="${additions.bin}" source="1.5" target="1.5" debug="${compile.debug}" includeantruntime="false">
+      <classpath>
+        <path location="${core.bin}"/>
+        <path location="${generated.bin}"/>
+      </classpath>
+      <compilerarg value="-version"/>
+    </javac>
+
+    <exec executable="/usr/bin/perl" outputproperty="additions.classes" failonerror="true">
+      <arg value="${src}/extract_classes.pl"/>
+      <arg path="${additions.bin}"/>
+    </exec>
+
+    <mkdir dir="${additions.jniheaders}"/>
+    <javah destdir="${additions.jniheaders}" class="${additions.classes}">
+      <classpath>
+        <path location="${core.bin}"/>
+        <path location="${generated.bin}"/>
+        <path location="${additions.bin}"/>
+      </classpath>
+    </javah>
+  </target>
+
+  <target name="build-additions-native">
+    <exec executable="xcodebuild" failonerror="true">
+      <env key="CC" value=""/>
+      <env key="CXX" value=""/>
+      <arg value="-configuration"/>
+      <arg value="${cfg}"/>
+      <arg value="-target"/>
+      <arg value="build-additions-native"/>
+      <arg value="SRCROOT=${src}"/>
+      <arg value="OBJROOT=${obj}"/>
+      <arg value="DSTROOT=${dst}"/>
+      <arg value="TARGET_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="PROJECT_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="BUILD_DIR=${env.DSTROOT}"/>
+    </exec>
+  </target>
+
+  <target name="assemble-product">
+    <mkdir dir="${product.jarfile.dir}"/>
+    <jar jarfile="${product.jarfile}" level="9" index="true">
+      <fileset dir="${core.bin}"/>
+      <fileset dir="${generated.bin}"/>
+      <fileset dir="${additions.bin}"/>
+    </jar>
+
+    <mkdir dir="${dst}/${product.target_path}"/>
+    <copy file="${product.jarfile}" toDir="${dst}/${product.target_path}" failonerror="true" verbose="true"/>
+    <copy file="${nativelib.file}" toDir="${dst}/${product.target_path}" failonerror="true" verbose="true"/>
+  </target>
+
+  <target name="doc-core">
+    <mkdir dir="${gendoc}"/>
+    <javadoc destdir="${gendoc}" access="protected">
+      <fileset dir="${src}/src" includes="**/*.java"/>
+    </javadoc>
+  </target>
+
+  <target name="build-test" description="compile unit tests">
+    <mkdir dir="${test.bin}"/>
+    <javac srcdir="${test.src}" destdir="${test.bin}" debug="false" includeantruntime="false">
+      <classpath>
+        <pathelement location="${core.bin}"/>
+        <pathelement location="${generator.bin}"/>
+        <pathelement location="${generated.bin}"/>
+        <pathelement location="${additions.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+      <compilerarg value="-version"/>
+    </javac>
+
+    <exec executable="/usr/bin/perl" outputproperty="test.classes" failonerror="true">
+      <arg value="${src}/extract_classes.pl"/>
+      <arg path="${test.bin}"/>
+    </exec>
+
+    <mkdir dir="${test.jniheaders}"/>
+    <javah destdir="${test.jniheaders}" class="${test.classes}">
+      <classpath>
+        <path location="${core.bin}"/>
+        <path location="${generated.bin}"/>
+        <path location="${additions.bin}"/>
+        <path location="${test.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+    </javah>
+  </target>
+
+  <target name="build-test-installed" description="compile unit tests">
+    <mkdir dir="${test.bin}"/>
+    <javac srcdir="${test.src}" destdir="${test.bin}" debug="false" includeantruntime="false">
+      <compilerarg value="-verbose"/>
+      <classpath>
+        <pathelement location="${generator.bin}"/>
+        <pathelement location="${generated.bin}"/>
+        <pathelement location="${additions.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+      <compilerarg value="-version"/>
+    </javac>
+
+    <exec executable="/usr/bin/perl" outputproperty="test.classes" failonerror="true">
+      <arg value="${src}/extract_classes.pl"/>
+      <arg path="${test.bin}"/>
+    </exec>
+
+    <mkdir dir="${test.jniheaders}"/>
+    <javah destdir="${test.jniheaders}" class="${test.classes}">
+      <classpath>
+        <path location="${generated.bin}"/>
+        <path location="${additions.bin}"/>
+        <path location="${test.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+    </javah>
+  </target>
+
+  <target name="build-test-native" depends="build-test">
+    <exec executable="xcodebuild" failonerror="true">
+      <env key="CC" value=""/>
+      <env key="CXX" value=""/>
+      <arg value="-configuration"/>
+      <arg value="${cfg}"/>
+      <arg value="-target"/>
+      <arg value="build-test-native"/>
+      <arg value="SRCROOT=${src}"/>
+      <arg value="OBJROOT=${obj}"/>
+      <arg value="DSTROOT=${dst}"/>
+      <arg value="TARGET_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="PROJECT_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="BUILD_DIR=${env.DSTROOT}"/>
+    </exec>
+  </target>
+
+  <target name="build-test-native-installed" depends="build-test-installed">
+    <exec executable="xcodebuild" failonerror="true">
+      <env key="CC" value=""/>
+      <env key="CXX" value=""/>
+      <arg value="-configuration"/>
+      <arg value="${cfg}"/>
+      <arg value="-target"/>
+      <arg value="build-test-native"/>
+      <arg value="SRCROOT=${src}"/>
+      <arg value="OBJROOT=${obj}"/>
+      <arg value="DSTROOT=${dst}"/>
+      <arg value="TARGET_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="PROJECT_TEMP_DIR=${env.DSTROOT}"/>
+      <arg value="BUILD_DIR=${env.DSTROOT}"/>
+    </exec>
+  </target>
+
+  <target name="test" depends="build-test-native" description="run unit tests">
+    <mkdir dir="${test.reports}"/>
+    <junit fork="yes" printsummary="yes">
+      <assertions>
+        <enable/>
+      </assertions>
+      <jvmarg value="-server" />
+
+      <sysproperty key="java.library.path" value="${nativelib.dir}" />
+      <classpath>
+        <pathelement location="${core.bin}"/>
+        <pathelement location="${generator.bin}"/>
+        <pathelement location="${generated.bin}"/>
+        <pathelement location="${additions.bin}"/>
+        <pathelement location="${test.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${test.src}">
+          <include name="**/*Test.java"/>
+          <exclude name="**/AllTests.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target name="test-installed" depends="build-test-native-installed" description="run unit tests">
+    <mkdir dir="${test.reports}"/>
+    <junit fork="yes" printsummary="yes">
+      <assertions>
+        <enable/>
+      </assertions>
+      <jvmarg value="-server" />
+
+      <sysproperty key="java.library.path" value="${nativelib.dir}" />
+      <classpath>
+        <pathelement location="${generator.bin}"/>
+        <pathelement location="${generated.bin}"/>
+        <pathelement location="${additions.bin}"/>
+        <pathelement location="${test.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${test.src}">
+          <include name="**/*Test.java"/>
+          <exclude name="**/AllTests.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+
+  <condition property="bench_match" value="*" else="${env.BENCH_MATCH}">
+    <not><isset property="env.BENCH_MATCH"/></not>
+  </condition>
+
+  <target name="bench" depends="build-test-native" description="run benchmarks">
+    <mkdir dir="${test.reports}"/>
+    <junit fork="yes" printsummary="yes">
+      <sysproperty key="java.library.path" value="${nativelib.dir}" />
+      <classpath>
+        <pathelement location="${core.bin}"/>
+        <pathelement location="${generator.bin}"/>
+        <pathelement location="${generated.bin}"/>
+        <pathelement location="${additions.bin}"/>
+        <pathelement location="${test.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+
+      <jvmarg value="-Xms256m" />
+      <jvmarg value="-Xmx1024m" />
+      <jvmarg value="-server" />
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${test.src}">
+          <include name="**/Bench*${bench_match}*.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target name="bench-installed" depends="build-test-native-installed" description="run benchmarks">
+    <mkdir dir="${test.reports}"/>
+    <junit fork="yes" printsummary="yes">
+      <sysproperty key="java.library.path" value="${nativelib.dir}" />
+      <classpath>
+        <pathelement location="${generator.bin}"/>
+        <pathelement location="${generated.bin}"/>
+        <pathelement location="${additions.bin}"/>
+        <pathelement location="${test.bin}"/>
+      </classpath>
+      <classpath refid="test.lib.path.id"/>
+
+      <jvmarg value="-Xms256m" />
+      <jvmarg value="-Xmx1024m" />
+      <jvmarg value="-server" />
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${test.src}">
+          <include name="**/Bench*${bench_match}*.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target name="clean">
+    <delete dir="build"/>
+    <delete dir="${obj}"/>
+    <delete dir="${dst}"/>
+    <delete dir="${gendoc}"/>
+    <delete dir="${test.reports}"/>
+  </target>
+
+
+  <target name="clean-all" depends="clean,build-core,build-core-native,build-generator,run-generator,build-generated,build-additions,build-additions-native,assemble-product">
+  </target>
+  <target name="all" depends="build-core,build-core-native,build-generator,run-generator,build-generated,build-additions,build-additions-native,assemble-product">
+  </target>
+  <target name="all-test" depends="build-core,build-core-native,build-generator,run-generator,build-generated,build-additions,build-additions-native,assemble-product,test-installed">
+  </target>
+  <target name="clean-all-test" depends="clean,build-core,build-core-native,build-generator,run-generator,build-generated,build-additions,build-additions-native,assemble-product,test-installed">
+  </target>
+  <target name="all-but-gen" depends="clean,build-core,build-core-native,build-generator,build-generated,build-additions,build-additions-native,assemble-product">
+  </target>
+</project>
diff --git a/jdk/src/macosx/native/jobjc/extract_classes.pl b/jdk/src/macosx/native/jobjc/extract_classes.pl
new file mode 100644
index 0000000..8617a2a
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/extract_classes.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+##
+
+$file_dir = $ARGV[0];
+@file_list = qx("/usr/bin/find" "$file_dir");
+
+foreach $file (@file_list) {
+        if ($file =~ s/\.class//) {
+            if ($file !~ s/\$[0-9]//) {
+                $file =~ s/$file_dir\///g;
+                $file =~ s/\//\./g;
+                chomp($file);
+                print "$file,";
+            }
+        }
+}
diff --git a/jdk/src/macosx/native/jobjc/run-and-write-if-okay b/jdk/src/macosx/native/jobjc/run-and-write-if-okay
new file mode 100644
index 0000000..6bb0d5d
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/run-and-write-if-okay
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+#
+
+if ARGV.length < 2
+  puts <<EOF
+Expects two args: EXEC and OUTPATH. First, it runs and prints
+`EXEC 2>&1`. If it returns successfully, it writes the output to OUTPATH.
+This script will return successfully unless writing the output fails.
+EOF
+  exit
+end
+
+EXECPATH = ARGV[0]
+OUTPATH  = ARGV[1]
+
+output = `#{EXECPATH}`
+puts output
+
+if $?.to_i == 0
+  puts "Writing output of #{EXECPATH} to #{OUTPATH}"
+  File.open(OUTPATH, 'w') {|f| f.write(output) }
+else
+  puts "#{EXECPATH} failed to run trial. Ignoring."
+end
diff --git a/jdk/src/macosx/native/jobjc/rungen b/jdk/src/macosx/native/jobjc/rungen
new file mode 100644
index 0000000..f053e29
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/rungen
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+#
+
+xcodeAction = ARGV[0]
+
+exit unless xcodeAction == "install"
+
+JOBJC_JAR = ARGV[1]
+LIBPATH = ARGV[2]
+OBJROOT = ARGV[3]
+ARCHS   = ARGV[4]
+STABLE_GEN_DIR = ARGV[5]
+
+ourJavaHome = ENV['JAVA_HOME']
+ourJavaVersion = `java -fullversion 2>&1`
+$stderr.puts "ENV['JAVA_HOME'] = #{ourJavaHome}"
+$stderr.puts "java -fullversion = #{ourJavaVersion}"
+
+$stderr.puts "jobjc_jar = #{JOBJC_JAR}"
+$stderr.puts "libpath = #{LIBPATH}"
+$stderr.puts "objroot = #{OBJROOT}"
+$stderr.puts "ARCHS   = #{ARCHS}"
+$stderr.puts "STABLE_GEN_DIR = #{STABLE_GEN_DIR}"
+
+jarch = if ARCHS =~ /x86_64/ then "-d64" else "-d32" end
+
+# compute the boot class path, but remove the JObjC jar file that may have been installed in the boot jdk
+
+bootclasspathcmd = "java -classpath #{OBJROOT}/bin/core:#{OBJROOT}/bin/generator com.apple.internal.jobjc.generator.BootClassPathMinus #{JOBJC_JAR}"
+$stderr.puts bootclasspathcmd
+bootclasspath = `#{bootclasspathcmd}`
+
+$stderr.puts "bootclasspath is: "
+$stderr.puts bootclasspath
+
+# we run the generator with our newly created JObjC.  The installed version (if available) has been removed from
+# the boot class path, so we are building with everything newly created.
+cmd = "java #{jarch} -Xms128m -Xmx512m -Djava.library.path=#{LIBPATH} -Xbootclasspath:#{bootclasspath.chomp} -classpath #{OBJROOT}/bin/core:#{OBJROOT}/bin/generator -ea com.apple.internal.jobjc.generator.Generator dst=#{OBJROOT}/src/jobjc frameworks=#{STABLE_GEN_DIR}"
+
+$stderr.puts cmd
+puts `#{cmd} 2>&1`
+
+raise $?.to_i if $?.to_i != 0
diff --git a/jdk/src/macosx/native/jobjc/runjava b/jdk/src/macosx/native/jobjc/runjava
new file mode 100644
index 0000000..796024b
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/runjava
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+#
+java -ea -classpath "lib/junit-4.4.jar:build/JObjC.build/Debug/bin/core:build/JObjC.build/Debug/bin/generator:build/JObjC.build/Debug/bin/additions:build/JObjC.build/Debug/bin/test:build/JObjC.build/Debug/bin/generated" -Djava.library.path=build/Debug $@
diff --git a/jdk/src/macosx/native/jobjc/src/core/PrimitiveCoder.hs b/jdk/src/macosx/native/jobjc/src/core/PrimitiveCoder.hs
new file mode 100644
index 0000000..544998e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/PrimitiveCoder.hs
@@ -0,0 +1,275 @@
+#!/usr/bin/env runhaskell
+
+{-
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+-}
+{-
+The simplest way to get Haskell is through MacPorts: sudo port install ghc
+
+Otherwise, see http://www.haskell.org/ghc/
+-}
+
+import Data.List
+import Data.Maybe
+import Char
+
+data Width = W32 | W64
+             deriving (Show, Eq, Bounded, Enum)
+
+data NType = NBOOL | Nschar | Nuchar | Nsshort | Nushort | Nsint | Nuint
+           | Nslong | Nulong | Nslonglong | Nulonglong | Nfloat | Ndouble
+             deriving (Show, Eq, Bounded, Enum)
+
+data JPrim = Jboolean | Jbyte | Jchar | Jshort | Jint | Jlong | Jfloat | Jdouble
+             deriving (Show, Eq, Bounded, Enum)
+
+data JClass = JBoolean | JByte | JCharacter | JShort | JInteger | JLong
+            | JFloat | JDouble
+              deriving (Show, Eq, Bounded, Enum)
+
+data FFIType = SINT8 | UINT8 | SINT16 | UINT16 | SINT32 | UINT32
+             | SINT64 | UINT64 | FLOAT | DOUBLE
+             deriving (Show, Eq, Bounded, Enum)
+
+widths = [minBound..maxBound] :: [Width]
+ntypes = [minBound..maxBound] :: [NType]
+jprims = [minBound..maxBound] :: [JPrim]
+jclasses = [minBound..maxBound] :: [JClass]
+ffitypes = [minBound..maxBound] :: [FFIType]
+
+-- What's the FFIType for a given Width and NType? For example: W32 NBOOL -> SINT8
+ffitype :: Width -> NType -> FFIType
+ffitype _ NBOOL   = SINT8
+ffitype _ Nschar  = SINT8
+ffitype _ Nuchar  = UINT8
+ffitype _ Nsshort = SINT16
+ffitype _ Nushort = UINT16
+ffitype _ Nsint   = SINT32
+ffitype _ Nuint   = UINT32
+ffitype W32 Nslong = SINT32
+ffitype W64 Nslong = SINT64
+ffitype W32 Nulong = UINT32
+ffitype W64 Nulong = UINT64
+ffitype _ Nslonglong = SINT64
+ffitype _ Nulonglong = UINT64
+ffitype _ Nfloat  = FLOAT
+ffitype _ Ndouble = DOUBLE
+
+sizeof :: FFIType -> Int
+sizeof SINT8  = 1
+sizeof UINT8  = 1
+sizeof SINT16 = 2
+sizeof UINT16 = 2
+sizeof SINT32 = 4
+sizeof UINT32 = 4
+sizeof SINT64 = 8
+sizeof UINT64 = 8
+sizeof FLOAT  = 4
+sizeof DOUBLE = 8
+
+-- What's the Obj-C encoding for a given NType? For example: unsigned char -> 'C'
+encoding nt = fromJust $ lookup nt $
+              [(NBOOL, 'B'), (Nschar, 'c'), (Nuchar, 'C'), (Nsshort, 's'),
+               (Nushort, 'S'), (Nsint, 'i'), (Nuint, 'I'), (Nslong, 'l'),
+               (Nulong, 'L'), (Nslonglong, 'q'), (Nulonglong, 'Q'),
+               (Nfloat, 'f'), (Ndouble, 'd')]
+
+-- What's the JPrim for a given NType? For example: native signed long long -> java long
+ntype2jprim nt = fromJust $ lookup nt $
+                 [(NBOOL, Jboolean), (Nschar, Jbyte), (Nuchar, Jbyte),
+                  (Nsshort, Jshort), (Nushort, Jshort), (Nsint, Jint), (Nuint, Jint),
+                  (Nslong, Jlong), (Nulong, Jlong),
+                  (Nslonglong, Jlong), (Nulonglong, Jlong),
+                  (Nfloat, Jfloat), (Ndouble, Jdouble)]
+
+-- What's the JClass for a given JPrim? For example: int -> Integer
+jprim2jclass jp = fromJust $ lookup jp $
+                  [(Jboolean, JBoolean), (Jbyte, JByte), (Jchar, JCharacter),
+                   (Jshort, JShort), (Jint, JInteger), (Jlong, JLong),
+                   (Jfloat, JFloat), (Jdouble, JDouble)]
+
+-- Convert a type to something suitable for Java code. For example: Jboolean -> boolean
+ntype2js nt = tail $ show nt
+jclass2js t = tail $ show t
+jprim2js p = tail $ show p
+ffitype2js f = "FFI_" ++ (show f)
+
+-- Capitalize the first letter of a String
+capitalize [] = []
+capitalize s = [toUpper $ head s] ++ tail s
+
+-- Given an Width and NType, return the Java code for reading said NType from memory.
+popAddr :: Width -> NType -> String
+popAddr _ NBOOL   = "rt.unsafe.getByte(addr) != 0"
+popAddr _ Nschar  = "rt.unsafe.getByte(addr)"
+popAddr _ Nuchar  = "rt.unsafe.getByte(addr)"
+popAddr W32 Nslong = "rt.unsafe.getInt(addr)"
+popAddr W32 Nulong = "rt.unsafe.getInt(addr)"
+popAddr _ ntype = "rt.unsafe.get" ++ (capitalize.jprim2js.ntype2jprim $ ntype) ++ "(addr)"
+
+-- Given an Width and NType, return the Java code for writing said NType to memory.
+pushAddr :: Width -> NType -> String
+pushAddr _ NBOOL   = "rt.unsafe.putByte(addr, (byte) (x ? 1 : 0));"
+pushAddr _ Nschar  = "rt.unsafe.putByte(addr, x);"
+pushAddr _ Nuchar  = "rt.unsafe.putByte(addr, x);"
+pushAddr W32 Nslong = "rt.unsafe.putInt(addr, (int) x);"
+pushAddr W32 Nulong = "rt.unsafe.putInt(addr, (int) x);"
+pushAddr _ ntype = "rt.unsafe.put" ++ (capitalize jprimS) ++ "(addr, (" ++ jprimS ++ ") x);"
+    where jprimS = jprim2js.ntype2jprim $ ntype
+
+-- Helpers for generating Java ternarnies and conditionals.
+archExpr x32 x64 = if x32 /= x64 then retdiff else x32
+    where retdiff = "(JObjCRuntime.IS64 ? (" ++ x64 ++ ") : (" ++ x32 ++ "))"
+
+archStmt x32 x64 = if x32 /= x64 then retdiff else x32
+    where retdiff = "if(JObjCRuntime.IS64){ " ++ x64 ++ " }else{ " ++ x32 ++ " }"
+
+-- Get a Java expression for the correct FFIType at runtime. For example: (JObjCRuntime.IS64 ? FFI_SINT64 : FFI_SINT32)
+ffitypeVal nt = archExpr (ffitype2js $ ffitype W32 nt)
+                         (ffitype2js $ ffitype W64 nt)
+
+-- Similar to ffiTypeVal. Get the correct pop expression and push statement.
+popAddrVal nt = archExpr (popAddr W32 nt) (popAddr W64 nt)
+pushAddrVal nt = archStmt (pushAddr W32 nt) (pushAddr W64 nt)
+
+-- What's the Coder class name we're using for a given NType?
+coderName nt = aux nt ++ "Coder"
+    where
+      aux NBOOL   = "Bool"
+      aux Nschar  = "SChar"
+      aux Nuchar  = "UChar"
+      aux Nsshort = "SShort"
+      aux Nushort = "UShort"
+      aux Nsint   = "SInt"
+      aux Nuint   = "UInt"
+      aux Nslong  = "SLong"
+      aux Nulong  = "ULong"
+      aux Nslonglong   = "SLongLong"
+      aux Nulonglong   = "ULongLong"
+      aux Nfloat  = "Float"
+      aux Ndouble = "Double"
+
+-- Operation for converting between primitives. Usually it just casts, but booleans are special.
+jconvertPrims sym Jboolean Jboolean = sym
+jconvertPrims sym Jboolean b = "((" ++ jprim2js b ++ ")(" ++ sym ++ " ? 1 : 0))"
+jconvertPrims sym a Jboolean = "(" ++ sym ++ " != 0)"
+jconvertPrims sym a b = if a == b then sym else "((" ++ jprim2js b ++ ")" ++ sym ++ ")"
+
+sizeofRet nt =
+    let ffitypes = map (\w -> ffitype w nt) widths
+        sizes = map sizeof ffitypes in
+    if (length $ nub sizes) == 1
+    then "\t\treturn " ++ (show.head $ sizes) ++ ";"
+    else unlines [
+              "\t\tswitch(w){",
+              (unlines $ map casestmt widths),
+              "\t\tdefault: return -1;",
+               "\t\t}"]
+    where
+      casestmt w = "\t\t\tcase " ++ (show w) ++ ": return " ++
+                   (show.sizeof $ ffitype w nt) ++ ";"
+
+-- Generate a coder class for a given NType.
+c2java ntype =
+    unlines [
+ "// native " ++ ntypeS ++ " -> java " ++ jprimS,
+ "public static final class " ++ className ++ " extends PrimitiveCoder<" ++ jclassS ++ ">{",
+ "\tpublic static final " ++ className ++ " INST = new " ++ className ++ "();",
+ "\tpublic " ++ className ++ "(){ super("++ffitypeVal ntype++", \"" ++ [encoding ntype] ++ "\", "++jclassS++".class, "++jprimS++".class); }",
+ "\t// compile time",
+ "\t@Override public void push(JObjCRuntime rt, long addr, " ++ jprimS ++ " x){",
+ "\t\t" ++ pushAddrVal ntype,
+ "\t}",
+ "\t@Override public " ++ jprimS ++ " pop" ++ capitalize jprimS ++ "(JObjCRuntime rt, long addr){",
+ "\t\treturn " ++ popAddrVal ntype ++ ";",
+ "\t}",
+ "\t// for runtime coding",
+ "\t@Override public int sizeof(Width w){",
+ sizeofRet ntype,
+ "\t}",
+ "\t@Override public void push(JObjCRuntime rt, long addr, " ++ jclassS ++ " x){ " ++
+ "push(rt, addr, (" ++ jprimS ++ ") x); }",
+ "\t@Override public " ++ jclassS ++ " pop(JObjCRuntime rt, long addr){ " ++
+ "return pop" ++ capitalize jprimS ++ "(rt, addr); }",
+ "\t// proxies for mixed encoding",
+ makeProxyMethods ntype,
+ "}"
+ ]
+     where
+       jprim = ntype2jprim ntype
+       jclass = jprim2jclass jprim
+       jprimS = jprim2js jprim
+       jclassS = jclass2js jclass
+       ntypeS = ntype2js ntype
+       className = coderName ntype
+
+-- Generate push and pop methods that convert and proxy to actual implementation.
+makeProxyMethods nt = unlines $ map aux jprims
+    where
+      targetJPrim = ntype2jprim nt
+      targetJPrimS = jprim2js targetJPrim
+      aux jprim = if targetJPrim == jprim then "" else unlines [
+                   "\t@Override public void push(JObjCRuntime rt, long addr, " ++ jprimS ++ " x){ " ++
+                   "push(rt, addr, " ++ pushConversion "x" ++ "); }",
+                   "\t@Override public " ++ jprimS ++ " pop" ++ capitalize jprimS ++ "(JObjCRuntime rt, long addr){ " ++
+                   "return " ++ (popConversion ("pop" ++ capitalize targetJPrimS ++ "(rt, addr)")) ++ "; }"
+                  ]
+          where
+            jprimS = jprim2js jprim
+            pushConversion sym = jconvertPrims sym jprim targetJPrim
+            popConversion sym = jconvertPrims sym targetJPrim jprim
+
+main = do
+  putStrLn "package com.apple.jobjc;"
+
+  putStrLn "import com.apple.jobjc.JObjCRuntime.Width;"
+
+  putStrLn "// Auto generated by PrimitiveCoder.hs"
+  putStrLn "// Do not edit by hand."
+
+  putStrLn "public abstract class PrimitiveCoder<T> extends Coder<T>{"
+
+  putStrLn "\tpublic PrimitiveCoder(int ffiTypeCode, String objCEncoding, Class jclass, Class jprim){"
+  putStrLn "\t\tsuper(ffiTypeCode, objCEncoding, jclass, jprim);"
+  putStrLn "\t}"
+
+  mapM_ (\p -> putStrLn $ unlines [makePopI p, makePushI p]) jprims
+
+  mapM_ (putStrLn . c2java) ntypes
+
+  putStrLn "}"
+    where
+      makePopI jprim = unlines ["\tpublic final " ++ jprim2js jprim ++ " pop" ++ (capitalize.jprim2js $ jprim)
+                                   ++ "(NativeArgumentBuffer args){\n"
+                                   ++ "\t\treturn pop" ++ (capitalize.jprim2js $ jprim) ++ "(args.runtime, args.retValPtr);\n"
+                                   ++ "\t}",
+                                "\tpublic abstract " ++ jprim2js jprim ++ " pop" ++ (capitalize.jprim2js $ jprim) ++ "(JObjCRuntime runtime, long addr);"]
+      makePushI jprim = unlines ["\tpublic final void push"
+          ++ "(NativeArgumentBuffer args, " ++ jprim2js jprim ++ " x){\n"
+          ++ "\t\tpush(args.runtime, args.argValuesPtr, x);\n"
+          ++ "\t\targs.didPutArgValue(sizeof());\n"
+          ++ "\t}",
+        "\tpublic abstract void push(JObjCRuntime runtime, long addr, " ++ jprim2js jprim ++ " x);"]
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/CFType.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/CFType.java
new file mode 100644
index 0000000..aeeca30
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/CFType.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+public class CFType extends Pointer<Void> {
+    protected CFType(long ptr) { super(ptr); }
+    protected CFType(Pointer<?> ptr) { super(ptr.ptr); }
+
+    protected ID getTollFreeBridge(JObjCRuntime runtime){
+        return ID.getObjCObjectFor(runtime, super.ptr);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/CIF.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/CIF.java
new file mode 100644
index 0000000..b40df1e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/CIF.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+
+class CIF {
+    private static native int getSizeofCIF();
+    private static final int SIZEOF = getSizeofCIF();
+    private static native boolean prepCIF(long cifPtr, int nargs, long retFFITypePtr, long argsPtr);
+
+    public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
+        NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
+        final long argsPtr = cifBuf.bufferPtr + SIZEOF;
+
+        {
+            long argsIterPtr = argsPtr;
+            for(final Coder coder : argCoders){
+                PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
+                argsIterPtr += JObjCRuntime.PTR_LEN;
+            }
+        }
+
+        boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
+        if(!ok)
+            throw new RuntimeException("ffi_prep_cif failed.");
+
+        return new CIF(cifBuf, returnCoder, argCoders);
+    }
+
+    final NativeBuffer cif;
+    // CIF needs to keep refs to the Coders, so they don't get finalized and their FFITypes freed.
+    final Coder returnCoder;
+    final Coder[] argCoders;
+
+    private CIF(final NativeBuffer cif, Coder returnCoder, Coder... argCoders) {
+        this.cif = cif;
+        this.returnCoder = returnCoder;
+        this.argCoders = argCoders;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Coder.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Coder.java
new file mode 100644
index 0000000..a6a714f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Coder.java
@@ -0,0 +1,289 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+
+import com.apple.jobjc.JObjCRuntime.Width;
+import com.apple.jobjc.PrimitiveCoder.BoolCoder;
+import com.apple.jobjc.PrimitiveCoder.DoubleCoder;
+import com.apple.jobjc.PrimitiveCoder.FloatCoder;
+import com.apple.jobjc.PrimitiveCoder.SCharCoder;
+import com.apple.jobjc.PrimitiveCoder.SIntCoder;
+import com.apple.jobjc.PrimitiveCoder.SLongLongCoder;
+import com.apple.jobjc.PrimitiveCoder.SShortCoder;
+
+public abstract class Coder<T> {
+    private static native long getNativeFFITypePtrForCode(final int code);
+
+    static final int FFI_VOID        = 0;
+    static final int FFI_PTR        = FFI_VOID+1;
+
+    static final int FFI_SINT8        = FFI_PTR+1;
+    static final int FFI_UINT8        = FFI_SINT8+1;
+    static final int FFI_SINT16        = FFI_UINT8+1;
+    static final int FFI_UINT16        = FFI_SINT16+1;
+    static final int FFI_SINT32        = FFI_UINT16+1;
+    static final int FFI_UINT32        = FFI_SINT32+1;
+    static final int FFI_SINT64        = FFI_UINT32+1;
+    static final int FFI_UINT64        = FFI_SINT64+1;
+
+    static final int FFI_FLOAT        = FFI_UINT64+1;
+    static final int FFI_DOUBLE        = FFI_FLOAT+1;
+    static final int FFI_LONGDOUBLE    = FFI_DOUBLE+1;
+
+    private static long[] ffiCodesToFFITypePtrs;
+    static{
+        System.loadLibrary("JObjC");
+        ffiCodesToFFITypePtrs = new long[FFI_LONGDOUBLE + 1];
+        for (int i = 0; i < FFI_LONGDOUBLE + 1; i++) ffiCodesToFFITypePtrs[i] = getNativeFFITypePtrForCode(i);
+    }
+
+    long getFFITypePtr() {
+        return ffiCodesToFFITypePtrs[getTypeCode()];
+    }
+
+    // runtime coding
+    public abstract void push(final JObjCRuntime runtime, final long addr, final T x);
+    public abstract T pop(final JObjCRuntime runtime, final long addr);
+
+    public void push(final NativeArgumentBuffer args, final T x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+
+    public T pop(final NativeArgumentBuffer args){
+        return pop(args.runtime, args.retValPtr);
+    }
+
+    public abstract int sizeof(Width w);
+    final public int sizeof(){ return sizeof(JObjCRuntime.WIDTH); }
+
+    //
+
+    public Coder(int ffiTypeCode, String objCEncoding, Class jclass, Class jprim) {
+        this.ffiTypeCode = ffiTypeCode;
+        this.objCEncoding = objCEncoding;
+        this.jclass = jclass;
+        this.jprim = jprim;
+    }
+
+    public Coder(int ffiTypeCode, String objCEncoding, Class jclass) {
+        this(ffiTypeCode, objCEncoding, jclass, null);
+    }
+
+    private final int ffiTypeCode;
+    private final String objCEncoding;
+    private final Class jclass;
+    private final Class jprim;
+
+    final int getTypeCode() { return ffiTypeCode; }
+    final String getObjCEncoding(){ return objCEncoding; }
+    public final Class getJavaClass() { return jclass; }
+    public final Class getJavaPrimitive() { return jprim; }
+
+    // runtime coding
+
+    private static Coder[] runtimeCoders;
+    static public Coder getCoderAtRuntimeForType(Class cls){
+        if(runtimeCoders == null) runtimeCoders = new Coder[]{
+            NSClassCoder.INST, IDCoder.INST, PointerCoder.INST,
+            DoubleCoder.INST, FloatCoder.INST, SLongLongCoder.INST,
+            SIntCoder.INST, SShortCoder.INST, SCharCoder.INST, BoolCoder.INST,
+            VoidCoder.INST
+        };
+
+        for(Coder c : runtimeCoders)
+            if((c.getJavaClass() != null && c.getJavaClass().isAssignableFrom(cls)) ||
+                    (c.getJavaPrimitive() != null && c.getJavaPrimitive().isAssignableFrom(cls)))
+                return c;
+
+        if(Struct.class.isAssignableFrom(cls)){
+            try {
+                Method m = cls.getDeclaredMethod("getStructCoder");
+                m.setAccessible(true);
+                return (Coder) m.invoke(null);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        throw new RuntimeException("Could not find suitable coder for " + cls);
+    }
+
+    static public Coder getCoderAtRuntime(Object inst){
+        if(inst == null)              return PointerCoder.INST;
+        if(inst instanceof Struct)    return ((Struct) inst).getCoder();
+        return getCoderAtRuntimeForType(inst.getClass());
+    }
+
+    //
+
+    public static final class VoidCoder extends Coder<Object>{
+        public static final VoidCoder INST = new VoidCoder();
+        public VoidCoder(){ super(FFI_VOID, "v", Void.class, void.class); }
+        @Override public int sizeof(Width w) { return -1; }
+        @Override public Object pop(JObjCRuntime runtime, long addr) { throw new RuntimeException("Trying to pop a Void."); }
+        @Override public void push(JObjCRuntime runtime, long addr, Object x) { throw new RuntimeException("Trying to push a Void."); }
+    }
+
+    public static final class UnknownCoder extends Coder<Object> {
+        public static final UnknownCoder INST = new UnknownCoder();
+        public UnknownCoder(){ super(-1, "?", null, null); }
+        @Override public int sizeof(Width w) { return -1; }
+        @Override public void push(JObjCRuntime runtime, long addr, Object x) { throw new RuntimeException("Coder not implemented");}
+        @Override public Object pop(JObjCRuntime runtime, long addr) { throw new RuntimeException("Coder not implemented"); }
+    }
+
+    public static final class PrimitivePointerCoder extends Coder<Long> {
+        public static final PrimitivePointerCoder INST = new PrimitivePointerCoder();
+        public PrimitivePointerCoder(){ super(Coder.FFI_PTR, "^?", Long.class, long.class); }
+        @Override public int sizeof(Width w) { return JObjCRuntime.PTR_LEN; }
+
+        public void push(JObjCRuntime runtime, long addr, long x) {
+            if(JObjCRuntime.IS64)
+                runtime.unsafe.putLong(addr, x);
+            else
+                runtime.unsafe.putInt(addr, (int) x);
+        }
+
+        public void push(final JObjCRuntime runtime, final NativeArgumentBuffer argBuf, final long ptr) {
+            push(runtime, argBuf.argValuesPtr, ptr);
+            argBuf.didPutArgValue(sizeof());
+        }
+
+        public long popPtr(final JObjCRuntime runtime, final long addr) {
+            return JObjCRuntime.IS64 ? runtime.unsafe.getLong(addr) : runtime.unsafe.getInt(addr);
+        }
+
+        public long popPtr(final JObjCRuntime runtime, final NativeArgumentBuffer argBuf) {
+            return popPtr(runtime, argBuf.retValPtr);
+        }
+
+        @Override public Long pop(JObjCRuntime runtime, long addr) { return popPtr(runtime, addr); }
+        @Override public void push(JObjCRuntime runtime, long addr, Long x) { push(runtime, addr, (long) x); }
+    }
+
+    public static final class PointerCoder extends Coder<Pointer> {
+        public static final PointerCoder INST = new PointerCoder();
+        public PointerCoder(){ super(FFI_PTR, "^?", Pointer.class); }
+        @Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }
+
+        @Override public Pointer pop(JObjCRuntime runtime, long addr) {
+            return new Pointer(PrimitivePointerCoder.INST.popPtr(runtime, addr));
+        }
+        @Override public void push(JObjCRuntime runtime, long addr, Pointer x) {
+            PrimitivePointerCoder.INST.push(runtime, addr, x == null ? 0 : x.ptr);
+        }
+    }
+
+    public static final class SELCoder extends Coder<SEL> {
+        public static final SELCoder INST = new SELCoder();
+        public SELCoder(){ super(FFI_PTR, ":", SEL.class); }
+        @Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }
+
+        @Override public void push(JObjCRuntime runtime, long addr, SEL x) {
+            PrimitivePointerCoder.INST.push(runtime, addr, x == null ? 0 : x.selPtr);
+        }
+        @Override public SEL pop(JObjCRuntime runtime, long addr) {
+            return new SEL(PrimitivePointerCoder.INST.popPtr(runtime, addr));
+        }
+    }
+
+    public static abstract class StructCoder extends Coder<Struct> {
+        private final FFIType ffiType;
+        final int sizeof;
+
+        public StructCoder(final int sizeof, final Coder... elementCoders){
+            super(-1, objCEncoding(elementCoders), null);
+            this.ffiType = new FFIType(elementCoders);
+            this.sizeof = sizeof;
+        }
+
+        @Override public int sizeof(Width w) { return sizeof; }
+
+        private static String objCEncoding(final Coder[] elementCoders) {
+            StringWriter str = new StringWriter();
+            str.append("{?=");
+            for(Coder c : elementCoders)
+                str.append(c.getObjCEncoding());
+            str.append("}");
+            return str.toString();
+        }
+
+        @Override long getFFITypePtr() { return ffiType.getPtr(); }
+
+        @Override public void push(NativeArgumentBuffer argBuf, Struct x) {
+            // Just point to the instance on the heap instead of copying it onto the arg buf.
+            argBuf.doPutArgPtr(x.raw.bufferPtr);
+        }
+
+        @Override public void push(JObjCRuntime rt, long addr, Struct x) {
+            rt.unsafe.copyMemory(x.raw.bufferPtr, addr, sizeof);
+        }
+
+        protected abstract Struct newInstance(JObjCRuntime runtime);
+
+        @Override public Struct pop(final JObjCRuntime runtime, final long addr) {
+            Struct s = newInstance(runtime);
+            runtime.unsafe.copyMemory(addr, s.raw.bufferPtr, sizeof);
+            return s;
+        }
+    }
+
+    public static final class IDCoder extends Coder<ID>{
+        public static final IDCoder INST = new IDCoder();
+        public IDCoder(){ super(FFI_PTR, "@", ID.class); }
+        @Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }
+
+        public <T extends ID> T newID(final JObjCRuntime runtime, final long objPtr) {
+            return (T) ID.getObjCObjectFor(runtime, objPtr);
+        }
+
+        @Override public ID pop(final JObjCRuntime runtime, final long addr) {
+            return newID(runtime, PrimitivePointerCoder.INST.popPtr(runtime, addr));
+        }
+
+        @Override public void push(final JObjCRuntime runtime, final long addr, final ID x) {
+            PointerCoder.INST.push(runtime, addr, x);
+        }
+    }
+
+    public static final class NSClassCoder extends Coder<NSClass>{
+        public static final NSClassCoder INST = new NSClassCoder();
+        public NSClassCoder(){ super(FFI_PTR, "#", NSClass.class); }
+        @Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }
+
+        @Override public NSClass pop(JObjCRuntime runtime, long addr) {
+            final long clsPtr = PrimitivePointerCoder.INST.popPtr(runtime, addr);
+            if (clsPtr == 0) return null;
+            return NSClass.getObjCClassFor(runtime, clsPtr);
+        }
+        @Override public void push(JObjCRuntime runtime, long addr, NSClass x) {
+            PointerCoder.INST.push(runtime, addr, x);
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/FFIType.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/FFIType.java
new file mode 100644
index 0000000..fcfddd6
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/FFIType.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+
+class FFIType{
+    private static native void makeFFIType(long ffi_type_buf, long elements_buf);
+    private static native int  getFFITypeSizeof();
+    private static int FFI_TYPE_SIZEOF = getFFITypeSizeof();
+    final NativeBuffer ffi_type;
+    final NativeBuffer elements;
+    final Coder[] elementCoders;
+
+    public FFIType(final Coder... elementCoders){
+        final JObjCRuntime runtime = JObjCRuntime.inst();
+        this.elementCoders = elementCoders;
+        this.ffi_type = new NativeBuffer(FFI_TYPE_SIZEOF);
+        this.elements = new NativeBuffer(JObjCRuntime.PTR_LEN * (elementCoders.length + 1));
+
+        long elIterPtr = elements.bufferPtr;
+        for(Coder c : elementCoders){
+            PrimitivePointerCoder.INST.push(runtime, elIterPtr, c.getFFITypePtr());
+            elIterPtr += PrimitivePointerCoder.INST.sizeof();
+        }
+        PrimitivePointerCoder.INST.push(runtime, elIterPtr, 0);
+
+        makeFFIType(ffi_type.bufferPtr, elements.bufferPtr);
+    }
+
+    public long getPtr(){
+        return ffi_type.bufferPtr;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Function.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Function.java
new file mode 100644
index 0000000..0acfccc
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Function.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+public class Function {
+    private static native long getFxnPtrForFunctionName(final String functionName);
+    private static native long getFxnPtrForFunctionNameAndLib(final long libPtr, final String functionName);
+
+    final long fxnPtr;
+
+    Function(final long fxnPtr) {
+        this.fxnPtr = fxnPtr;
+    }
+
+    public Function(final String name) {
+        this(getFxnPtr(name));
+    }
+
+    public Function(final MacOSXFramework framework, final String name) {
+        this(getFxnPtr(name, framework));
+    }
+
+    static long getFxnPtr(final String name){
+        long fxnPtr = getFxnPtrForFunctionName(name);
+        if(fxnPtr == 0) throw new RuntimeException("Function pointer for " + name + " not found in runtime.");
+        return fxnPtr;
+    }
+
+    static long getFxnPtr(final String name, final MacOSXFramework framework){
+        long fxnPtr = 0;
+        for(int i = 0; fxnPtr == 0 && i < framework.nativeLibPtrs.length; i++){
+            fxnPtr = getFxnPtrForFunctionNameAndLib(framework.nativeLibPtrs[i], name);
+            if(fxnPtr != 0) return fxnPtr;
+        }
+        throw new RuntimeException("Function pointer for " + name + " not found in framework " + framework + ".");
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/ID.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/ID.java
new file mode 100644
index 0000000..f2b3718
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/ID.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Constructor;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class ID extends Pointer<Void>{
+    static native String getNativeDescription(final long objPtr);
+
+    final JObjCRuntime runtime;
+
+    static final Class[] CTOR_ARGS = { long.class, JObjCRuntime.class };
+    protected ID(final long objPtr, final JObjCRuntime runtime) {
+        super(objPtr);
+        runtime.assertOK();
+        this.runtime = runtime;
+    }
+
+    protected ID(final ID obj, final JObjCRuntime runtime) {
+        this(obj.ptr, runtime);
+    }
+
+    @Override protected NativeObjectLifecycleManager getNativeObjectLifecycleManager() {
+        return NativeObjectLifecycleManager.CFRetainRelease.INST;
+    }
+
+    protected final JObjCRuntime getRuntime() { return runtime; }
+
+    @Override public String toString(){
+        String s = super.toString();
+        return s + " (ObjC: " + ptr + " / " + Long.toHexString(ptr) + ")";
+    }
+
+    //
+
+    public static <T extends ID> T getInstance(final long ptr, final JObjCRuntime runtime){
+        return (T) getObjCObjectFor(runtime, ptr);
+    }
+
+    static <T extends ID> T getObjCObjectFor(final JObjCRuntime runtime, final long objPtr){
+        if (objPtr == 0) return null;
+
+        final WeakReference cachedObj = objectCache.get().get(objPtr);
+        if(cachedObj != null && cachedObj.get() != null) return (T) cachedObj.get();
+
+        final long clsPtr = NSClass.getClass(objPtr);
+
+        final T newObj = (T) (runtime.subclassing.isUserClass(clsPtr) ?
+                Subclassing.getJObjectFromIVar(objPtr)
+                : createNewObjCObjectFor(runtime, objPtr, clsPtr));
+
+        objectCache.get().put(objPtr, new WeakReference(newObj));
+        return newObj;
+    }
+
+    static <T extends ID> T createNewObjCObjectFor(final JObjCRuntime runtime, final long objPtr, final long clsPtr) {
+        final Constructor<T> ctor = getConstructorForClassPtr(runtime, clsPtr);
+        return (T) createNewObjCObjectForConstructor(ctor, objPtr, runtime);
+    }
+
+    @SuppressWarnings("unchecked")
+    static <T extends ID> Constructor<T> getConstructorForClassPtr(final JObjCRuntime runtime, final long clazzPtr){
+        final Constructor<T> cachedCtor = (Constructor<T>) constructorCache.get().get(clazzPtr);
+        if(cachedCtor != null) return cachedCtor;
+
+        final Class<T> clazz = getClassForClassPtr(runtime, clazzPtr);
+        Constructor<T> ctor;
+        try {
+            ctor = clazz.getDeclaredConstructor(CTOR_ARGS);
+        } catch (SecurityException e) {
+            throw new RuntimeException(e);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
+        }
+        ctor.setAccessible(true);
+        constructorCache.get().put(clazzPtr, (Constructor<ID>) ctor);
+        return ctor;
+    }
+
+    @SuppressWarnings("unchecked")
+    static <T extends ID> Class<T> getClassForClassPtr(final JObjCRuntime runtime, final long clazzPtr){
+        final String className = NSClass.getClassNameOfClass(clazzPtr);
+        final Class<T> clazz = (Class<T>) runtime.getClassForNativeClassName(className);
+        if(clazz == null){
+            final long superClazzPtr = NSClass.getSuperClassOfClass(clazzPtr);
+            if(superClazzPtr != 0)
+                return getClassForClassPtr(runtime, superClazzPtr);
+        }
+        return clazz;
+    }
+
+    static <T extends ID> T createNewObjCObjectForConstructor(final Constructor ctor, final long objPtr, final JObjCRuntime runtime) {
+        try {
+            final T newInstance = (T) ctor.newInstance(new Object[] { Long.valueOf(objPtr), runtime });
+            objectCache.get().put(objPtr, new WeakReference(newInstance));
+            return newInstance;
+        } catch (final Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    static <T extends ID> T createNewObjCObjectForClass(final Class<T> clazz, final long objPtr, final JObjCRuntime runtime) {
+        try {
+            final Constructor<T> constructor = clazz.getDeclaredConstructor(CTOR_ARGS);
+            constructor.setAccessible(true);
+            return (T) createNewObjCObjectForConstructor(constructor, objPtr, runtime);
+        } catch (final Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    //
+
+    static final ThreadLocal<LinkedHashMap<Long, Constructor>> constructorCache = new ThreadLocal<LinkedHashMap<Long, Constructor>>(){
+        @Override protected LinkedHashMap<Long, Constructor> initialValue(){
+            final int MAX_ENTRIES = 1000;
+            final float LOAD_FACTOR = 0.75f;
+            return new LinkedHashMap<Long, Constructor>((int) (MAX_ENTRIES/LOAD_FACTOR), LOAD_FACTOR, true) {
+                @Override protected boolean removeEldestEntry(Map.Entry<Long, Constructor> eldest) {
+                    return size() > MAX_ENTRIES;
+                }
+            };
+        }
+    };
+
+    static final ThreadLocal<LinkedHashMap<Long, WeakReference>> objectCache = new ThreadLocal<LinkedHashMap<Long, WeakReference>>(){
+        @Override protected LinkedHashMap<Long, WeakReference> initialValue(){
+            final int MAX_ENTRIES = 1000;
+            final float LOAD_FACTOR = 0.75f;
+            return new LinkedHashMap<Long, WeakReference>((int) (MAX_ENTRIES/LOAD_FACTOR), LOAD_FACTOR, true) {
+                @Override protected boolean removeEldestEntry(Map.Entry<Long, WeakReference> eldest) {
+                    return size() > MAX_ENTRIES || eldest.getValue().get() == null;
+                }
+            };
+        }
+    };
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Invoke.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Invoke.java
new file mode 100644
index 0000000..c6cab30
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Invoke.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Coder.IDCoder;
+import com.apple.jobjc.Coder.NSClassCoder;
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+import com.apple.jobjc.Coder.SELCoder;
+import com.apple.jobjc.Coder.StructCoder;
+
+public abstract class Invoke {
+    public abstract void invoke(NativeArgumentBuffer argBuf);
+    public abstract void invoke(NativeArgumentBuffer buffer, Struct retvalStruct);
+
+    //
+
+    public static final class FunCall extends Invoke{
+        static native void invoke(long cifPtr, long fxnPtr, long retValPtr, long argsPtr);
+
+        final long fxnPtr;
+        final CIF cif;
+
+        FunCall(long fxnPtr, CIF cif) {
+            this.fxnPtr = fxnPtr;
+            this.cif = cif;
+        }
+
+        public FunCall(final JObjCRuntime runtime, final String name, final Coder returnCoder, final Coder ... argCoders) {
+            this(Function.getFxnPtr(name), CIF.createCIFFor(runtime.getThreadLocalState(), returnCoder, argCoders));
+        }
+
+        public FunCall(final MacOSXFramework framework, final String name, final Coder returnCoder, final Coder ... argCoders) {
+            this(Function.getFxnPtr(name, framework), CIF.createCIFFor(framework.getRuntime().getThreadLocalState(), returnCoder, argCoders));
+        }
+
+        public void init(final NativeArgumentBuffer argBuf) {
+            argBuf.reset();
+        }
+
+        @Override public void invoke(final NativeArgumentBuffer argBuf) {
+            invoke(argBuf, argBuf.retValPtr);
+        }
+
+        @Override public void invoke(final NativeArgumentBuffer buffer, final Struct retvalStruct) {
+            invoke(buffer, retvalStruct.raw.bufferPtr);
+        }
+
+        void invoke(final NativeArgumentBuffer argBuf, final long retValPtr) {
+            invoke(cif.cif.bufferPtr, fxnPtr, retValPtr, argBuf.buffer.bufferPtr);
+        }
+    }
+
+    public static final class MsgSend extends Invoke{
+        static{ System.load("/usr/lib/libobjc.dylib"); }
+
+        private static final long OBJC_MSG_SEND_FXN_PTR = new Function("objc_msgSend").fxnPtr;
+        private static final long OBJC_MSG_SEND_FPRET_FXN_PTR = new Function("objc_msgSend_fpret").fxnPtr;
+        private static final long OBJC_MSG_SEND_STRET_FXN_PTR = new Function("objc_msgSend_stret").fxnPtr;
+
+        final FunCall funCall;
+        final long selPtr;
+
+        public MsgSend(final JObjCRuntime runtime, final String name, final Coder returnCoder, final Coder ... argCoders) {
+            this.funCall = new FunCall(getMsgSendFxnPtr(returnCoder),
+                    CIF.createCIFFor(runtime.getThreadLocalState(), returnCoder, getSelCoders(argCoders)));
+            this.selPtr = SEL.getSelectorPtr(name);
+        }
+
+        public void init(final NativeArgumentBuffer nativeBuffer, final ID obj) {
+            funCall.init(nativeBuffer);
+            IDCoder.INST.push(nativeBuffer, obj);
+            PrimitivePointerCoder.INST.push(nativeBuffer.runtime, nativeBuffer, selPtr);
+        }
+
+        @Override public void invoke(final NativeArgumentBuffer argBuf) {
+            funCall.invoke(argBuf);
+        }
+
+        @Override public void invoke(final NativeArgumentBuffer buffer, final Struct retvalStruct) {
+            funCall.invoke(buffer, retvalStruct);
+        }
+
+        // support
+
+        static Coder[] getSelCoders(final Coder[] argCoders) {
+            final Coder[] selArgCoders = new Coder[argCoders.length + 2];
+            selArgCoders[0] = IDCoder.INST;
+            selArgCoders[1] = SELCoder.INST;
+            for (int i = 0; i < argCoders.length; i++)
+                selArgCoders[i + 2] = argCoders[i];
+            return selArgCoders;
+        }
+
+        static long getMsgSendFxnPtr(final Coder returnCoder) {
+            if(returnCoder instanceof StructCoder){
+                StructCoder scoder = (StructCoder) returnCoder;
+
+                switch(JObjCRuntime.ARCH){
+                case ppc:
+                    return OBJC_MSG_SEND_STRET_FXN_PTR;
+                case i386:
+                    switch(scoder.sizeof){
+                    case 1: case 2: case 4: case 8:
+                        return OBJC_MSG_SEND_FXN_PTR;
+                    }
+                    return OBJC_MSG_SEND_STRET_FXN_PTR;
+                case x86_64:
+                    if(scoder.sizeof > 16)
+                        return OBJC_MSG_SEND_STRET_FXN_PTR;
+                    else
+                        return OBJC_MSG_SEND_FXN_PTR;
+                default:
+                    throw new RuntimeException();
+                }
+            }
+
+            final int typeCode = returnCoder.getTypeCode();
+
+            switch(JObjCRuntime.ARCH){
+            case ppc:
+                return OBJC_MSG_SEND_FXN_PTR;
+            case i386:
+                switch(typeCode) {
+                case Coder.FFI_FLOAT: case Coder.FFI_DOUBLE: case Coder.FFI_LONGDOUBLE:
+                    return OBJC_MSG_SEND_FPRET_FXN_PTR;
+                }
+                return OBJC_MSG_SEND_FXN_PTR;
+            case x86_64:
+                if(typeCode == Coder.FFI_LONGDOUBLE)
+                    return OBJC_MSG_SEND_FPRET_FXN_PTR;
+                return OBJC_MSG_SEND_FXN_PTR;
+            default:
+                throw new RuntimeException();
+            }
+        }
+    }
+
+    public static final class MsgSendSuper extends Invoke{
+        static{ System.load("/usr/lib/libobjc.dylib"); }
+
+        private static final long OBJC_MSG_SEND_SUPER_FXN_PTR = new Function("objc_msgSendSuper").fxnPtr;
+        private static final long OBJC_MSG_SEND_SUPER_STRET_FXN_PTR = new Function("objc_msgSendSuper_stret").fxnPtr;
+
+        final FunCall funCall;
+        final long selPtr;
+
+        public MsgSendSuper(final JObjCRuntime runtime, final String name, final Coder returnCoder, final Coder ... argCoders) {
+            this.funCall = new FunCall(getMsgSendSuperFxnPtr(returnCoder),
+                    CIF.createCIFFor(runtime.getThreadLocalState(), returnCoder, getSuperSelCoders(argCoders)));
+            this.selPtr = SEL.getSelectorPtr(name);
+        }
+
+        public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
+            funCall.init(argBuf);
+
+            // Instead of mallocing a struct, or keeping another thread local,
+            // let's write objc_super out to the argbuf, and then point an argument
+            // to the data.
+
+            final long valPtr = argBuf.argValuesPtr;
+            final int ptrLen = JObjCRuntime.PTR_LEN;
+
+            IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
+            NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
+            argBuf.argValuesPtr += ptrLen + ptrLen;
+
+            PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
+            PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
+        }
+
+        @Override public void invoke(final NativeArgumentBuffer argBuf) {
+            funCall.invoke(argBuf);
+        }
+
+        @Override public void invoke(final NativeArgumentBuffer buffer, final Struct retvalStruct) {
+            funCall.invoke(buffer, retvalStruct);
+        }
+
+        //
+
+        private final static StructCoder objc_super_coder = new StructCoder(JObjCRuntime.PTR_LEN*2, IDCoder.INST, NSClassCoder.INST){
+            @Override protected Struct newInstance(JObjCRuntime runtime) { return null; }};
+
+        static Coder[] getSuperSelCoders(final Coder[] argCoders) {
+            final Coder[] selArgCoders = new Coder[argCoders.length + 2];
+            selArgCoders[0] = objc_super_coder;
+            selArgCoders[1] = SELCoder.INST;
+            for (int i = 0; i < argCoders.length; i++)
+                selArgCoders[i + 2] = argCoders[i];
+            return selArgCoders;
+        }
+
+        static long getMsgSendSuperFxnPtr(final Coder returnCoder){
+            long normal = MsgSend.getMsgSendFxnPtr(returnCoder);
+            if(normal == MsgSend.OBJC_MSG_SEND_STRET_FXN_PTR)
+                return OBJC_MSG_SEND_SUPER_STRET_FXN_PTR;
+            else
+                return OBJC_MSG_SEND_SUPER_FXN_PTR;
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/JObjCRuntime.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/JObjCRuntime.java
new file mode 100644
index 0000000..10699b7
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/JObjCRuntime.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.lang.reflect.Field;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.List;
+
+import sun.misc.Unsafe;
+
+public final class JObjCRuntime {
+    static { System.loadLibrary("JObjC"); }
+
+    public static enum Arch{ ppc, i386, x86_64 };
+    public static enum Width{ W32, W64 };
+
+    public static final Arch ARCH = getArch();
+    public static final Width WIDTH = getWidth();
+
+    private static Arch getArch(){
+        String arch = System.getProperty("os.arch");
+        if("ppc".equals(arch)) return Arch.ppc;
+        if("i386".equals(arch)) return Arch.i386;
+        if("x86_64".equals(arch)) return Arch.x86_64;
+        if("universal".equals(arch)) return Arch.x86_64;
+        throw new RuntimeException("Did not recognize os.arch system property: '" + arch + "'");
+    }
+
+    private static Width getWidth(){
+        String width = System.getProperty("sun.arch.data.model");
+        if("32".equals(width)) return Width.W32;
+        if("64".equals(width)) return Width.W64;
+        throw new RuntimeException("Did not recognize sun.arch.data.model system property: '" + width + "'");
+    }
+
+    public static final boolean IS32 = System.getProperty("sun.arch.data.model").equals("32");
+    public static final boolean IS64 = System.getProperty("sun.arch.data.model").equals("64");
+    public static final int PTR_LEN = IS64 ? 8 : 4;
+    public static final boolean IS_BIG_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
+    static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("JObjC.debug"));
+
+    static void checkPermission(){
+        final SecurityManager security = System.getSecurityManager();
+        if (security != null) security.checkPermission(new RuntimePermission("canProcessApplicationEvents"));
+    }
+
+    public final void assertOK(){
+        if(this != instance)
+            throw new SecurityException("runtime");
+    }
+
+    private JObjCRuntime(){}
+
+    private static JObjCRuntime instance;
+    static JObjCRuntime inst() {
+        if (instance == null) instance = new JObjCRuntime();
+        return instance;
+    }
+
+    public static JObjCRuntime getInstance() {
+        checkPermission();
+        return inst();
+    }
+
+    public final NativeArgumentBuffer getThreadLocalState() {
+        return NativeArgumentBuffer.getThreadLocalBuffer(this);
+    }
+
+    final Unsafe unsafe = getUnsafe();
+    final Subclassing subclassing = new Subclassing(this);
+    final List<String> registeredPackages = new ArrayList<String>();
+
+    @SuppressWarnings("unchecked")
+    Class<? extends ID> getClassForNativeClassName(final String className) {
+        for (final String pkg : registeredPackages) {
+            try {
+                final Class<?> clazz = Class.forName(pkg + "." + className);
+                if (clazz != null) return (Class<? extends ID>)clazz;
+            } catch (final ClassNotFoundException e) { }
+        }
+
+        return null;
+    }
+
+    private final static Unsafe getUnsafe() {
+        Unsafe inst = null;
+        try {
+            Field f = Unsafe.class.getDeclaredField("theUnsafe");
+            f.setAccessible(true);
+            inst = (Unsafe) f.get(null);
+            if(inst == null) throw new NullPointerException("Unsafe.theUnsafe == null");
+        } catch (Exception e) {
+            throw new RuntimeException("Unable to get instance of Unsafe.", e);
+        }
+        return inst;
+    }
+
+    public void registerPackage(final String pkg) {
+        registeredPackages.add(pkg);
+    }
+
+    /**
+     * Register a subclass of NSObject to allow the native side to send
+     * messages which in turn call java methods declared on the class.
+     * If a native class by the same name already exists, registerClass
+     * will simply return without doing anything.
+     *
+     * For a usage example, see the SubclassingTest.
+     */
+    public boolean registerUserClass(Class<? extends ID> clazz, Class<? extends NSClass> clazzClazz) {
+        return subclassing.registerUserClass(clazz, clazzClazz);
+    }
+
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/MacOSXFramework.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/MacOSXFramework.java
new file mode 100644
index 0000000..bfc7750
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/MacOSXFramework.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+
+public class MacOSXFramework {
+    private static native long retainFramework(final String frameworkName);
+    private static native void releaseFramework(final long frameworkPtr);
+    private static native void getConstant(final long frameworkPtr, String symbol, final long bufferPtr, final int size);
+
+    private final JObjCRuntime runtime;
+    protected final long[] nativeLibPtrs;
+
+    final long getFrameworkPtr() { return nativeLibPtrs.length > 0 ? nativeLibPtrs[0] : 0; }
+
+    private static long[] createFrameworkPtrsFromPaths(final String[] frameworkLibPaths) {
+        final long[] libPtrs = new long[frameworkLibPaths.length];
+        for(int i = 0; i < libPtrs.length; i++){
+            libPtrs[i] = retainFramework(frameworkLibPaths[i]);
+            if(libPtrs[i] == 0) throw new RuntimeException("Could not open library at " + frameworkLibPaths[i]);
+        }
+        return libPtrs;
+    }
+
+    protected MacOSXFramework(final JObjCRuntime runtime, final String[] nativeLibPaths) {
+        runtime.assertOK();
+        this.runtime = runtime;
+        this.nativeLibPtrs = createFrameworkPtrsFromPaths(nativeLibPaths);
+    }
+
+    @Override protected final synchronized void finalize() throws Throwable {
+        for(long lib : nativeLibPtrs)
+            if(lib != 0) releaseFramework(lib);
+    }
+
+    protected final JObjCRuntime getRuntime(){ return runtime; }
+
+    protected void getConstant(final String symbol, final long retValPtr, final int size){
+        assert size >= 0;
+        assert retValPtr != 0;
+        getConstant(getFrameworkPtr(), symbol, retValPtr, size);
+    }
+
+    protected void getConstant(final String symbol, final NativeArgumentBuffer out, final int size){
+        getConstant(symbol, out.retValPtr, size);
+    }
+
+    protected void getConstant(final String symbol, final Struct out, final int size){
+        getConstant(symbol, out.raw.bufferPtr, size);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NSClass.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NSClass.java
new file mode 100644
index 0000000..dbc784f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NSClass.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Constructor;
+
+public class NSClass<T extends ID> extends ID {
+    public static class NSClassNotFoundException extends RuntimeException{
+        public NSClassNotFoundException(String m){ super(m); }
+        public NSClassNotFoundException(String m, Throwable cause){ super(m, cause); }
+    }
+
+    static native long getNativeClassByName(String name);
+    static native long getSuperClassOfClass(long classPtr);
+    static native String getClassNameOfClass(long classPtr);
+    static native long getClass(long objPtr);
+
+    public NSClass(final long ptr, final JObjCRuntime runtime) {
+        super(ptr, runtime);
+    }
+
+    public NSClass(final String name, final JObjCRuntime runtime) {
+        this(getNativeClassByName(name), runtime);
+        if(ptr == 0) throw new NSClassNotFoundException("NSClass pointer is 0. Found no class named " + name);
+    }
+
+    protected NSClass(final JObjCRuntime runtime){
+        super(0, runtime);
+        final String sn = getClass().getSimpleName();
+        final String name = sn.substring(0, sn.lastIndexOf("Class"));
+        ptr = getNativeClassByName(name);
+        if(ptr == 0) throw new NSClassNotFoundException("NSClass pointer is 0. Found no class named " + name);
+    }
+
+    NSClass<? super T> getSuperClass() {
+        return new NSClass<T>(getSuperClassOfClass(ptr), runtime);
+    }
+
+    String getClassName() { return getClassNameOfClass(ptr); }
+
+    @Override protected NativeObjectLifecycleManager getNativeObjectLifecycleManager() {
+        return NativeObjectLifecycleManager.Nothing.INST;
+    }
+
+    @Override public boolean equals(Object o){
+        return (o instanceof NSClass) && (this.ptr == ((NSClass) o).ptr);
+    }
+
+    //
+
+    static <T extends NSClass> T getObjCClassFor(final JObjCRuntime runtime, final long clsPtr){
+        if (clsPtr == 0) return null;
+
+        final WeakReference cachedObj = objectCache.get().get(clsPtr);
+        if(cachedObj != null && cachedObj.get() != null) return (T) cachedObj.get();
+
+        final T newObj = (T) createNewObjCClassFor(runtime, clsPtr);
+        objectCache.get().put(clsPtr, new WeakReference(newObj));
+        return newObj;
+    }
+
+    static <T extends NSClass> T createNewObjCClassFor(final JObjCRuntime runtime, final long clsPtr) {
+        final Constructor<T> ctor = getNSClassConstructorForClassPtr(runtime, clsPtr);
+        return (T) createNewObjCObjectForConstructor(ctor, clsPtr, runtime);
+    }
+
+    @SuppressWarnings("unchecked")
+    static <T extends NSClass> Constructor<T> getNSClassConstructorForClassPtr(final JObjCRuntime runtime, final long clazzPtr){
+        final Class<T> clazz = getNSClassForClassPtr(runtime, clazzPtr);
+        Constructor<T> ctor;
+        try {
+            ctor = clazz.getDeclaredConstructor(CTOR_ARGS);
+        } catch (SecurityException e) {
+            throw new RuntimeException(e);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
+        }
+        ctor.setAccessible(true);
+        return ctor;
+    }
+
+    @SuppressWarnings("unchecked")
+    static <T extends ID> Class<T> getNSClassForClassPtr(final JObjCRuntime runtime, final long clazzPtr){
+        final String className = NSClass.getClassNameOfClass(clazzPtr);
+        final Class<T> clazz = (Class<T>) runtime.getClassForNativeClassName(className + "Class");
+        if(clazz == null){
+            final long superClazzPtr = NSClass.getSuperClassOfClass(clazzPtr);
+            if(superClazzPtr != 0)
+                return getNSClassForClassPtr(runtime, superClazzPtr);
+        }
+        return clazz;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeArgumentBuffer.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeArgumentBuffer.java
new file mode 100644
index 0000000..1e3c424
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeArgumentBuffer.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.nio.ByteOrder;
+
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+
+public final class NativeArgumentBuffer{
+    private static final ThreadLocal<NativeArgumentBuffer> threadLocal = new ThreadLocal<NativeArgumentBuffer>();
+
+    static NativeArgumentBuffer getThreadLocalBuffer(final JObjCRuntime runtime) {
+        runtime.assertOK();
+        final NativeArgumentBuffer alreadyCreated = threadLocal.get();
+        if (alreadyCreated != null) return alreadyCreated;
+
+        final NativeArgumentBuffer newThreadLocalState = new NativeArgumentBuffer(runtime);
+        threadLocal.set(newThreadLocalState);
+        return newThreadLocalState;
+    }
+
+    final JObjCRuntime runtime;
+
+    final NativeBuffer buffer;
+
+    long argPtrsPtr;
+    long argValuesPtr;
+    final long retValPtr;
+
+    private static final int MAX_ARGS = 512;
+    private static final int BUF_SIZE = MAX_ARGS * 8 * 2;
+    private static final int ARG_VALS_OFFSET = BUF_SIZE/2;
+
+    private NativeArgumentBuffer(final JObjCRuntime runtime) {
+        runtime.assertOK();
+        this.runtime = runtime;
+        this.buffer = new NativeBuffer(BUF_SIZE);
+        this.buffer.buffer.order(ByteOrder.nativeOrder());
+
+        reset();
+        this.retValPtr = buffer.bufferPtr;
+    }
+
+
+    // Call before each new call
+    public void reset() {
+        argPtrsPtr = buffer.bufferPtr;
+        argValuesPtr = buffer.bufferPtr + ARG_VALS_OFFSET;
+        assert buffer.ptrInBounds(argValuesPtr);
+    }
+
+    // Push a pointer to a block of memory
+    public void doPutArgPtr(long ptr) {
+        assert buffer.ptrInBounds(argPtrsPtr);
+        PrimitivePointerCoder.INST.push(runtime, argPtrsPtr, ptr);
+        argPtrsPtr += JObjCRuntime.PTR_LEN;
+    }
+
+    // Call this after having written a value of size `sizeof` to `argValuesPtr`.
+    public void didPutArgValue(int sizeof) {
+        assert buffer.ptrInBounds(argValuesPtr);
+        doPutArgPtr(argValuesPtr);
+        argValuesPtr += sizeof;
+    }
+
+
+    @Override public String toString() {
+        final StringBuilder builder = new StringBuilder();
+        final long bptr = buffer.bufferPtr;
+
+        for(long i = bptr; i < bptr + ARG_VALS_OFFSET; i += JObjCRuntime.PTR_LEN){
+            if(argPtrsPtr == i)
+                builder.append("*");
+            builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
+            builder.append(" ");
+        }
+
+        builder.append("\n");
+
+        for(long i = bptr + ARG_VALS_OFFSET; i < bptr + BUF_SIZE; i += JObjCRuntime.PTR_LEN){
+            if(argValuesPtr == i)
+                builder.append("*");
+            builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
+            builder.append(" ");
+        }
+
+        return builder.toString();
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeBuffer.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeBuffer.java
new file mode 100644
index 0000000..ee0ac05
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeBuffer.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * A wrapper around a direct ByteBuffer and its native pointer. For documentation, @see java.nio.ByteBuffer
+ */
+public class NativeBuffer {
+    static native long getPtrOfBuffer(final ByteBuffer byteBuffer);
+
+    public final ByteBuffer buffer;
+    public final long bufferPtr;
+
+    public NativeBuffer(final int capacity){
+        this(ByteBuffer.allocateDirect(capacity));
+    }
+
+    /**
+     * Wrap a ByteBuffer and set the ByteOrder to nativeOrder.
+     */
+    public NativeBuffer(ByteBuffer buffer){
+        this.buffer = buffer;
+        this.bufferPtr = getPtrOfBuffer(buffer);
+        assert buffer != null;
+        assert bufferPtr != 0;
+        this.buffer.order(ByteOrder.nativeOrder());
+    }
+
+    public byte   get() { return buffer.get(); }
+    public char   getChar() { return buffer.getChar(); }
+    public double getDouble() { return buffer.getDouble(); }
+    public float  getFloat() { return buffer.getFloat(); }
+    public int    getInt() { return buffer.getInt(); }
+    public long   getLong() { return buffer.getLong(); }
+    public short  getShort() { return buffer.getShort(); }
+    public NativeBuffer put(byte b) { buffer.put(b); return this; }
+    public NativeBuffer put(NativeBuffer src) { buffer.put(src.buffer); return this; }
+    public NativeBuffer putChar(char c) { buffer.putChar(c); return this; }
+    public NativeBuffer putDouble(double d) { buffer.putDouble(d); return this; }
+    public NativeBuffer putFloat(float f) { buffer.putFloat(f); return this; }
+    public NativeBuffer putInt(int i) { buffer.putInt(i); return this; }
+    public NativeBuffer putLong(long l) { buffer.putLong(l); return this; }
+    public NativeBuffer putShort(short s) { buffer.putShort(s); return this; }
+
+    public int capacity() { return buffer.capacity(); }
+    public int position() { return buffer.position(); }
+    public NativeBuffer position(int newPosition) { buffer.position(newPosition); return this; }
+    public NativeBuffer rewind(){ buffer.rewind(); return this; }
+
+    public int limit() { return buffer.limit(); }
+    public NativeBuffer limit(final int sizeof) { buffer.limit(sizeof); return this; }
+
+    public int remaining() { return buffer.remaining(); }
+
+    public NativeBuffer slice(){ return new NativeBuffer(buffer.slice()); }
+
+    @Override public String toString() {
+        final StringBuilder builder = new StringBuilder();
+
+        for(int i = 0; i < limit(); i += JObjCRuntime.PTR_LEN){
+            if(position() == i)
+                builder.append("*");
+            if(JObjCRuntime.IS32)
+                builder.append(buffer.getInt(i));
+            else
+                builder.append(buffer.getLong(i));
+            builder.append(" ");
+        }
+
+        return builder.toString();
+    }
+
+    public long positionPtr() {
+        return bufferPtr + position();
+    }
+
+    /**
+     * bufferPtr <= ptr && ptr < bufferPtr + capacity();
+     */
+    public boolean ptrInBounds(final long ptr){
+        return bufferPtr <= ptr && ptr < bufferPtr + capacity();
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeObjectLifecycleManager.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeObjectLifecycleManager.java
new file mode 100644
index 0000000..b4d3dbf
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/NativeObjectLifecycleManager.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+public abstract class NativeObjectLifecycleManager {
+    private static native void retainNativeObject(final long ptr);
+    private static native void releaseNativeObject(final long ptr);
+    private static native void freeNativeObject(final long ptr);
+
+    abstract void begin(final long ptr);
+    abstract void end(final long ptr);
+    boolean shouldPreRetain() { return false; }
+
+    public static class CFRetainRelease extends NativeObjectLifecycleManager {
+        public static final NativeObjectLifecycleManager INST = new CFRetainRelease();
+        @Override void begin(final long ptr) { retainNativeObject(ptr); }
+        @Override void end(final long ptr) { releaseNativeObject(ptr); }
+        @Override boolean shouldPreRetain() { return true; }
+    }
+
+    public static class Free extends NativeObjectLifecycleManager {
+        public static final NativeObjectLifecycleManager INST = new Free();
+        @Override void begin(final long ptr) { }
+        @Override void end(final long ptr) { freeNativeObject(ptr); }
+    }
+
+    public static class Nothing extends NativeObjectLifecycleManager {
+        public static final NativeObjectLifecycleManager INST = new Nothing();
+        @Override void begin(final long ptr) { }
+        @Override void end(final long ptr) { }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Opaque.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Opaque.java
new file mode 100644
index 0000000..cbc5acc
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Opaque.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+public class Opaque extends Pointer<Void> {
+    protected Opaque(long ptr) { super(ptr); }
+    protected Opaque(Pointer<?> ptr) { super(ptr.ptr); }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Pointer.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Pointer.java
new file mode 100644
index 0000000..5d8c3c8
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Pointer.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+public class Pointer <T> implements Comparable<Pointer<T>>{
+    long ptr;
+
+    protected Pointer(final long ptr) {
+        this.ptr = ptr;
+        getNativeObjectLifecycleManager().begin(ptr);
+    }
+
+    @Override protected final synchronized void finalize() throws Throwable {
+        long pptr = ptr;
+        ptr = 0;
+        if (pptr != 0) getNativeObjectLifecycleManager().end(pptr);
+    }
+
+    protected NativeObjectLifecycleManager getNativeObjectLifecycleManager() {
+        return NativeObjectLifecycleManager.Nothing.INST;
+    }
+
+    @Override public boolean equals(Object o) {
+        return o instanceof Pointer && ptr == ((Pointer) o).ptr;
+    }
+
+    @Override public int hashCode() { return (int)(ptr^(ptr>>>32)); }
+
+    public int compareTo(Pointer<T> o) {
+        if(this==o || ptr==o.ptr) return 0;
+        if(ptr < o.ptr) return -1;
+        return 1;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/PrimitiveCoder.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/PrimitiveCoder.java
new file mode 100644
index 0000000..8dcc424
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/PrimitiveCoder.java
@@ -0,0 +1,700 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+import com.apple.jobjc.JObjCRuntime.Width;
+// Auto generated by PrimitiveCoder.hs
+// Do not edit by hand.
+public abstract class PrimitiveCoder<T> extends Coder<T>{
+    public PrimitiveCoder(int ffiTypeCode, String objCEncoding, Class jclass, Class jprim){
+        super(ffiTypeCode, objCEncoding, jclass, jprim);
+    }
+    public final boolean popBoolean(NativeArgumentBuffer args){
+        return popBoolean(args.runtime, args.retValPtr);
+    }
+    public abstract boolean popBoolean(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, boolean x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, boolean x);
+
+
+    public final byte popByte(NativeArgumentBuffer args){
+        return popByte(args.runtime, args.retValPtr);
+    }
+    public abstract byte popByte(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, byte x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, byte x);
+
+
+    public final char popChar(NativeArgumentBuffer args){
+        return popChar(args.runtime, args.retValPtr);
+    }
+    public abstract char popChar(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, char x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, char x);
+
+
+    public final short popShort(NativeArgumentBuffer args){
+        return popShort(args.runtime, args.retValPtr);
+    }
+    public abstract short popShort(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, short x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, short x);
+
+
+    public final int popInt(NativeArgumentBuffer args){
+        return popInt(args.runtime, args.retValPtr);
+    }
+    public abstract int popInt(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, int x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, int x);
+
+
+    public final long popLong(NativeArgumentBuffer args){
+        return popLong(args.runtime, args.retValPtr);
+    }
+    public abstract long popLong(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, long x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, long x);
+
+
+    public final float popFloat(NativeArgumentBuffer args){
+        return popFloat(args.runtime, args.retValPtr);
+    }
+    public abstract float popFloat(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, float x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, float x);
+
+
+    public final double popDouble(NativeArgumentBuffer args){
+        return popDouble(args.runtime, args.retValPtr);
+    }
+    public abstract double popDouble(JObjCRuntime runtime, long addr);
+
+    public final void push(NativeArgumentBuffer args, double x){
+        push(args.runtime, args.argValuesPtr, x);
+        args.didPutArgValue(sizeof());
+    }
+    public abstract void push(JObjCRuntime runtime, long addr, double x);
+
+
+// native BOOL -> java boolean
+public static final class BoolCoder extends PrimitiveCoder<Boolean>{
+    public static final BoolCoder INST = new BoolCoder();
+    public BoolCoder(){ super(FFI_SINT8, "B", Boolean.class, boolean.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){
+        rt.unsafe.putByte(addr, (byte) (x ? 1 : 0));
+    }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){
+        return rt.unsafe.getByte(addr) != 0;
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 1;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Boolean x){ push(rt, addr, (boolean) x); }
+    @Override public Boolean pop(JObjCRuntime rt, long addr){ return popBoolean(rt, addr); }
+    // proxies for mixed encoding
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, (x != 0)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)(popBoolean(rt, addr) ? 1 : 0)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, (x != 0)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)(popBoolean(rt, addr) ? 1 : 0)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, (x != 0)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)(popBoolean(rt, addr) ? 1 : 0)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, (x != 0)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)(popBoolean(rt, addr) ? 1 : 0)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, (x != 0)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)(popBoolean(rt, addr) ? 1 : 0)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, (x != 0)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)(popBoolean(rt, addr) ? 1 : 0)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, (x != 0)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)(popBoolean(rt, addr) ? 1 : 0)); }
+
+
+}
+
+// native schar -> java byte
+public static final class SCharCoder extends PrimitiveCoder<Byte>{
+    public static final SCharCoder INST = new SCharCoder();
+    public SCharCoder(){ super(FFI_SINT8, "c", Byte.class, byte.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, byte x){
+        rt.unsafe.putByte(addr, x);
+    }
+    @Override public byte popByte(JObjCRuntime rt, long addr){
+        return rt.unsafe.getByte(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 1;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Byte x){ push(rt, addr, (byte) x); }
+    @Override public Byte pop(JObjCRuntime rt, long addr){ return popByte(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((byte)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popByte(rt, addr) != 0); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((byte)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((byte)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((byte)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((byte)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((byte)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((byte)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popByte(rt, addr)); }
+
+
+}
+
+// native uchar -> java byte
+public static final class UCharCoder extends PrimitiveCoder<Byte>{
+    public static final UCharCoder INST = new UCharCoder();
+    public UCharCoder(){ super(FFI_UINT8, "C", Byte.class, byte.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, byte x){
+        rt.unsafe.putByte(addr, x);
+    }
+    @Override public byte popByte(JObjCRuntime rt, long addr){
+        return rt.unsafe.getByte(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 1;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Byte x){ push(rt, addr, (byte) x); }
+    @Override public Byte pop(JObjCRuntime rt, long addr){ return popByte(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((byte)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popByte(rt, addr) != 0); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((byte)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((byte)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((byte)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((byte)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((byte)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popByte(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((byte)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popByte(rt, addr)); }
+
+
+}
+
+// native sshort -> java short
+public static final class SShortCoder extends PrimitiveCoder<Short>{
+    public static final SShortCoder INST = new SShortCoder();
+    public SShortCoder(){ super(FFI_SINT16, "s", Short.class, short.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, short x){
+        rt.unsafe.putShort(addr, (short) x);
+    }
+    @Override public short popShort(JObjCRuntime rt, long addr){
+        return rt.unsafe.getShort(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 2;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Short x){ push(rt, addr, (short) x); }
+    @Override public Short pop(JObjCRuntime rt, long addr){ return popShort(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((short)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popShort(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((short)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((short)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popShort(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((short)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((short)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((short)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((short)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popShort(rt, addr)); }
+
+
+}
+
+// native ushort -> java short
+public static final class UShortCoder extends PrimitiveCoder<Short>{
+    public static final UShortCoder INST = new UShortCoder();
+    public UShortCoder(){ super(FFI_UINT16, "S", Short.class, short.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, short x){
+        rt.unsafe.putShort(addr, (short) x);
+    }
+    @Override public short popShort(JObjCRuntime rt, long addr){
+        return rt.unsafe.getShort(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 2;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Short x){ push(rt, addr, (short) x); }
+    @Override public Short pop(JObjCRuntime rt, long addr){ return popShort(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((short)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popShort(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((short)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((short)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popShort(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((short)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((short)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((short)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popShort(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((short)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popShort(rt, addr)); }
+
+
+}
+
+// native sint -> java int
+public static final class SIntCoder extends PrimitiveCoder<Integer>{
+    public static final SIntCoder INST = new SIntCoder();
+    public SIntCoder(){ super(FFI_SINT32, "i", Integer.class, int.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, int x){
+        rt.unsafe.putInt(addr, (int) x);
+    }
+    @Override public int popInt(JObjCRuntime rt, long addr){
+        return rt.unsafe.getInt(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 4;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Integer x){ push(rt, addr, (int) x); }
+    @Override public Integer pop(JObjCRuntime rt, long addr){ return popInt(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((int)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popInt(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((int)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((int)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((int)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popInt(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((int)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((int)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((int)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popInt(rt, addr)); }
+
+
+}
+
+// native uint -> java int
+public static final class UIntCoder extends PrimitiveCoder<Integer>{
+    public static final UIntCoder INST = new UIntCoder();
+    public UIntCoder(){ super(FFI_UINT32, "I", Integer.class, int.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, int x){
+        rt.unsafe.putInt(addr, (int) x);
+    }
+    @Override public int popInt(JObjCRuntime rt, long addr){
+        return rt.unsafe.getInt(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 4;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Integer x){ push(rt, addr, (int) x); }
+    @Override public Integer pop(JObjCRuntime rt, long addr){ return popInt(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((int)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popInt(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((int)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((int)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((int)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popInt(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((int)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((int)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popInt(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((int)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popInt(rt, addr)); }
+
+
+}
+
+// native slong -> java long
+public static final class SLongCoder extends PrimitiveCoder<Long>{
+    public static final SLongCoder INST = new SLongCoder();
+    public SLongCoder(){ super((JObjCRuntime.IS64 ? (FFI_SINT64) : (FFI_SINT32)), "l", Long.class, long.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, long x){
+        if(JObjCRuntime.IS64){ rt.unsafe.putLong(addr, (long) x); }else{ rt.unsafe.putInt(addr, (int) x); }
+    }
+    @Override public long popLong(JObjCRuntime rt, long addr){
+        return (JObjCRuntime.IS64 ? (rt.unsafe.getLong(addr)) : (rt.unsafe.getInt(addr)));
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        switch(w){
+            case W32: return 4;
+            case W64: return 8;
+
+        default: return -1;
+        }
+
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Long x){ push(rt, addr, (long) x); }
+    @Override public Long pop(JObjCRuntime rt, long addr){ return popLong(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((long)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popLong(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((long)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((long)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((long)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((long)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popLong(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((long)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((long)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popLong(rt, addr)); }
+
+
+}
+
+// native ulong -> java long
+public static final class ULongCoder extends PrimitiveCoder<Long>{
+    public static final ULongCoder INST = new ULongCoder();
+    public ULongCoder(){ super((JObjCRuntime.IS64 ? (FFI_UINT64) : (FFI_UINT32)), "L", Long.class, long.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, long x){
+        if(JObjCRuntime.IS64){ rt.unsafe.putLong(addr, (long) x); }else{ rt.unsafe.putInt(addr, (int) x); }
+    }
+    @Override public long popLong(JObjCRuntime rt, long addr){
+        return (JObjCRuntime.IS64 ? (rt.unsafe.getLong(addr)) : (rt.unsafe.getInt(addr)));
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        switch(w){
+            case W32: return 4;
+            case W64: return 8;
+
+        default: return -1;
+        }
+
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Long x){ push(rt, addr, (long) x); }
+    @Override public Long pop(JObjCRuntime rt, long addr){ return popLong(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((long)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popLong(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((long)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((long)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((long)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((long)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popLong(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((long)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((long)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popLong(rt, addr)); }
+
+
+}
+
+// native slonglong -> java long
+public static final class SLongLongCoder extends PrimitiveCoder<Long>{
+    public static final SLongLongCoder INST = new SLongLongCoder();
+    public SLongLongCoder(){ super(FFI_SINT64, "q", Long.class, long.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, long x){
+        rt.unsafe.putLong(addr, (long) x);
+    }
+    @Override public long popLong(JObjCRuntime rt, long addr){
+        return rt.unsafe.getLong(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 8;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Long x){ push(rt, addr, (long) x); }
+    @Override public Long pop(JObjCRuntime rt, long addr){ return popLong(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((long)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popLong(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((long)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((long)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((long)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((long)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popLong(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((long)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((long)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popLong(rt, addr)); }
+
+
+}
+
+// native ulonglong -> java long
+public static final class ULongLongCoder extends PrimitiveCoder<Long>{
+    public static final ULongLongCoder INST = new ULongLongCoder();
+    public ULongLongCoder(){ super(FFI_UINT64, "Q", Long.class, long.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, long x){
+        rt.unsafe.putLong(addr, (long) x);
+    }
+    @Override public long popLong(JObjCRuntime rt, long addr){
+        return rt.unsafe.getLong(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 8;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Long x){ push(rt, addr, (long) x); }
+    @Override public Long pop(JObjCRuntime rt, long addr){ return popLong(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((long)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popLong(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((long)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((long)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((long)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((long)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popLong(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((long)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popLong(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((long)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popLong(rt, addr)); }
+
+
+}
+
+// native float -> java float
+public static final class FloatCoder extends PrimitiveCoder<Float>{
+    public static final FloatCoder INST = new FloatCoder();
+    public FloatCoder(){ super(FFI_FLOAT, "f", Float.class, float.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, float x){
+        rt.unsafe.putFloat(addr, (float) x);
+    }
+    @Override public float popFloat(JObjCRuntime rt, long addr){
+        return rt.unsafe.getFloat(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 4;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Float x){ push(rt, addr, (float) x); }
+    @Override public Float pop(JObjCRuntime rt, long addr){ return popFloat(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((float)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popFloat(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((float)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popFloat(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((float)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popFloat(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((float)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popFloat(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((float)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popFloat(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((float)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popFloat(rt, addr)); }
+
+
+    @Override public void push(JObjCRuntime rt, long addr, double x){ push(rt, addr, ((float)x)); }
+    @Override public double popDouble(JObjCRuntime rt, long addr){ return ((double)popFloat(rt, addr)); }
+
+
+}
+
+// native double -> java double
+public static final class DoubleCoder extends PrimitiveCoder<Double>{
+    public static final DoubleCoder INST = new DoubleCoder();
+    public DoubleCoder(){ super(FFI_DOUBLE, "d", Double.class, double.class); }
+    // compile time
+    @Override public void push(JObjCRuntime rt, long addr, double x){
+        rt.unsafe.putDouble(addr, (double) x);
+    }
+    @Override public double popDouble(JObjCRuntime rt, long addr){
+        return rt.unsafe.getDouble(addr);
+    }
+    // for runtime coding
+    @Override public int sizeof(Width w){
+        return 8;
+    }
+    @Override public void push(JObjCRuntime rt, long addr, Double x){ push(rt, addr, (double) x); }
+    @Override public Double pop(JObjCRuntime rt, long addr){ return popDouble(rt, addr); }
+    // proxies for mixed encoding
+    @Override public void push(JObjCRuntime rt, long addr, boolean x){ push(rt, addr, ((double)(x ? 1 : 0))); }
+    @Override public boolean popBoolean(JObjCRuntime rt, long addr){ return (popDouble(rt, addr) != 0); }
+
+    @Override public void push(JObjCRuntime rt, long addr, byte x){ push(rt, addr, ((double)x)); }
+    @Override public byte popByte(JObjCRuntime rt, long addr){ return ((byte)popDouble(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, char x){ push(rt, addr, ((double)x)); }
+    @Override public char popChar(JObjCRuntime rt, long addr){ return ((char)popDouble(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, short x){ push(rt, addr, ((double)x)); }
+    @Override public short popShort(JObjCRuntime rt, long addr){ return ((short)popDouble(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, int x){ push(rt, addr, ((double)x)); }
+    @Override public int popInt(JObjCRuntime rt, long addr){ return ((int)popDouble(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, long x){ push(rt, addr, ((double)x)); }
+    @Override public long popLong(JObjCRuntime rt, long addr){ return ((long)popDouble(rt, addr)); }
+
+    @Override public void push(JObjCRuntime rt, long addr, float x){ push(rt, addr, ((double)x)); }
+    @Override public float popFloat(JObjCRuntime rt, long addr){ return ((float)popDouble(rt, addr)); }
+
+
+
+}
+
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/SEL.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/SEL.java
new file mode 100644
index 0000000..b6d719e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/SEL.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+public class SEL {
+    static native long getSelectorPtr(String selectorName);
+    static native String getSelectorName(long ptr);
+
+    final long selPtr;
+
+    SEL(long ptr) {
+        this.selPtr = ptr;
+    }
+
+    public SEL(final String name) {
+        this(getSelectorPtr(name));
+    }
+
+    @Override public String toString(){
+        return ((int)selPtr) + " / " + selPtr + " : " + getSelectorName(selPtr);
+    }
+
+    /**
+     * Converts something like "performSelectorOnMainThread_withObject_wait"
+     * to "performSelectorOnMainThread:withObject:wait:"
+     */
+    public static String selectorName(String jMethodName, boolean hasArgs){
+        String b = jMethodName.replaceAll("_", ":");
+        return hasArgs ? b + ":" : b;
+    }
+
+    public static String jMethodName(String selectorName){
+        return selectorName.replaceAll(":", "_").replaceAll("_$", "");
+    }
+
+    public static boolean validName(String selectorName){
+        return selectorName.matches("^[a-zA-Z_][a-zA-Z0-9_:]*$");
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Struct.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Struct.java
new file mode 100644
index 0000000..8329cf1
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Struct.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+/**
+ * A struct is malloced on the C heap and accessed in Java through a ByteBuffer.
+ */
+public abstract class Struct{
+    protected final NativeBuffer raw;
+    private final JObjCRuntime runtime;
+    protected final JObjCRuntime getRuntime(){ return runtime; }
+
+    /**
+     * Create a brand new struct from nothing.
+     */
+    protected Struct(final JObjCRuntime runtime, final int SIZEOF){
+        this(runtime, new NativeBuffer(SIZEOF), SIZEOF);
+    }
+
+    /**
+     * Create a struct by taking ownership of an existing buffer.
+     * Used for struct fields of type struct. For example, the origin and size fields
+     * in NSRect would be initialized with this constructor.
+     */
+    protected Struct(final JObjCRuntime runtime, final NativeBuffer buffer, final int SIZEOF){
+        if(runtime == null) throw new NullPointerException("runtime");
+        this.runtime = runtime;
+        this.raw = buffer;
+        this.raw.limit(SIZEOF);
+    }
+
+    abstract public Coder getCoder();
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Subclassing.java b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Subclassing.java
new file mode 100644
index 0000000..b2084df
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Subclassing.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+import com.apple.jobjc.Coder.VoidCoder;
+import com.apple.jobjc.Invoke.MsgSend;
+
+final class Subclassing {
+    static native long allocateClassPair(long superClass, String name);
+    static native boolean addIVarForJObj(long clazz);
+    static native boolean patchAlloc(long classPtr);
+    static native boolean addMethod(long cls, String name, Method jMethod, CIF cif, long cifPtr, String objCEncodedType);
+    static native void registerClassPair(long clazz);
+
+    static native <T extends ID> T getJObjectFromIVar(long objPtr);
+    static native void initJObjectToIVar(long objPtr, ID object);
+
+    final Set<Long> registeredUserSubclasses = new HashSet<Long>();
+    final JObjCRuntime runtime;
+
+    Subclassing(JObjCRuntime runtime){
+        this.runtime = runtime;
+    }
+
+    boolean registerUserClass(final Class<? extends ID> clazz, final Class<? extends NSClass> clazzClazz) {
+        final String nativeClassName = clazz.getSimpleName();
+        // Is it already registered?
+        if(0 != NSClass.getNativeClassByName(nativeClassName))
+            return false;
+
+        if(clazz.isAnonymousClass())
+            throw new RuntimeException("JObjC cannot register anonymous classes.");
+
+        // Verify superclass
+        long superClass = NSClass.getNativeClassByName(clazz.getSuperclass().getSimpleName());
+        if(0 == superClass)
+            throw new RuntimeException(clazz.getSuperclass() + ", the superclass of " + clazz + ", must be a registered class.");
+
+        runtime.registerPackage(clazz.getPackage().getName());
+
+        // Create class
+        long classPtr = Subclassing.allocateClassPair(superClass, nativeClassName);
+        if(classPtr == 0) throw new RuntimeException("objc_allocateClassPair returned 0.");
+
+        // Add ivar to hold jobject
+        boolean addedI = Subclassing.addIVarForJObj(classPtr);
+        if(!addedI) throw new RuntimeException("class_addIvar returned false.");
+
+        // Verify constructor
+        try {
+            clazz.getConstructor(ID.CTOR_ARGS);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not access required constructor: " + ID.CTOR_ARGS, e);
+        }
+
+        // Patch alloc to create corresponding jobject on invoke
+        patchAlloc(classPtr);
+
+        // Add methods
+        Set<String> takenSelNames = new HashSet<String>();
+        for(Method method : clazz.getDeclaredMethods()){
+            // No overloading
+            String selName = SEL.selectorName(method.getName(), method.getParameterTypes().length > 0);
+            if(takenSelNames.contains(selName))
+                throw new RuntimeException("Obj-C does not allow method overloading. The Objective-C selector '"
+                        + selName + "' appears more than once in class " + clazz.getCanonicalName() + " / " + nativeClassName + ".");
+
+            method.setAccessible(true);
+
+            // Divine CIF
+            Coder returnCoder = Coder.getCoderAtRuntimeForType(method.getReturnType());
+            Class[] paramTypes = method.getParameterTypes();
+            Coder[] argCoders = new Coder[paramTypes.length];
+            for(int i = 0; i < paramTypes.length; i++)
+                argCoders[i] = Coder.getCoderAtRuntimeForType(paramTypes[i]);
+
+            CIF cif = new MsgSend(runtime, selName, returnCoder, argCoders).funCall.cif;
+
+            // .. and objc encoding
+            StringWriter encType = new StringWriter();
+            encType.append(returnCoder.getObjCEncoding());
+            encType.append("@:");
+            for(int i = 0; i < argCoders.length; i++)
+                encType.append(argCoders[i].getObjCEncoding());
+
+            // Add it!
+            boolean addedM = Subclassing.addMethod(classPtr, selName, method, cif, cif.cif.bufferPtr, encType.toString());
+            if(!addedM) throw new RuntimeException("Failed to add method.");
+            takenSelNames.add(selName);
+        }
+
+        // Seal it
+        Subclassing.registerClassPair(classPtr);
+        registeredUserSubclasses.add(classPtr);
+
+        return true;
+    }
+
+    boolean isUserClass(long clsPtr) {
+        return registeredUserSubclasses.contains(clsPtr);
+    }
+
+    // Called from JNI
+
+    private static void initJObject(final long objPtr){
+//        System.err.println("initJObject " + objPtr + " / " + Long.toHexString(objPtr));
+        ID newObj = ID.createNewObjCObjectFor(JObjCRuntime.inst(), objPtr, NSClass.getClass(objPtr));
+//        System.err.println("... " + newObj);
+        initJObjectToIVar(objPtr, newObj);
+    }
+
+    private static void invokeFromJNI(ID obj, Method method, CIF cif, long result, long args){
+        assert obj != null;
+        assert obj.getClass().equals(method.getDeclaringClass()) :
+            obj.getClass().toString() + " != " + method.getDeclaringClass().toString();
+
+        final int argCount = method.getParameterTypes().length;
+
+        // The first two args & coders are for objc id and sel. Skip them.
+        final Object[] argObjects = new Object[argCount];
+        for(int i = 0; i < argCount; i++){
+            final long argAddrAddr = args + ((i+2) * JObjCRuntime.PTR_LEN);
+            final long argAddr = PrimitivePointerCoder.INST.popPtr(obj.runtime, argAddrAddr);
+            argObjects[i] = cif.argCoders[i + 2].pop(obj.runtime, argAddr);
+        }
+
+        Object retVal;
+        try {
+            retVal = method.invoke(obj, argObjects);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+
+        if(!(cif.returnCoder instanceof VoidCoder))
+            cif.returnCoder.push(obj.runtime, result, retVal);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/CIF.m b/jdk/src/macosx/native/jobjc/src/core/native/CIF.m
new file mode 100644
index 0000000..5e18a20
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/CIF.m
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_CIF.h"
+
+#define MACOSX
+#include <ffi/ffi.h>
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#include "NativeBuffer.h"
+
+JNIEXPORT jint JNICALL Java_com_apple_jobjc_CIF_getSizeofCIF
+(JNIEnv *env, jclass clazz)
+{
+    return (jint) sizeof(ffi_cif);
+}
+
+JNIEXPORT jboolean JNICALL Java_com_apple_jobjc_CIF_prepCIF
+(JNIEnv *env, jclass clazz, jlong jCIFPtr, jint jNargs, jlong jRetTypePtr, jlong jArgsPtr)
+{
+    ffi_cif *cif = jlong_to_ptr(jCIFPtr);
+    unsigned int nargs = jNargs;
+    ffi_type *rtype = jlong_to_ptr(jRetTypePtr);
+    ffi_type **atypes = jlong_to_ptr(jArgsPtr);
+
+//    NSLog(@"rtype->(size: %d, alignment: %d, type: %d)", rtype->size, rtype->alignment, rtype->type);
+    return (jboolean) (FFI_OK == ffi_prep_cif(cif, FFI_DEFAULT_ABI, nargs, rtype, atypes));
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/Coder.m b/jdk/src/macosx/native/jobjc/src/core/native/Coder.m
new file mode 100644
index 0000000..0905e7a
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/Coder.m
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_Coder.h"
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+#define MACOSX
+#include <ffi/ffi.h>
+#include <AppKit/AppKit.h>
+
+/*
+ * Class:     com_apple_jobjc_Coder
+ * Method:    getNativeFFITypeCodeForCode
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_Coder_getNativeFFITypePtrForCode
+(JNIEnv *env, jclass clazz, jint code)
+{
+    switch ((long)code) {
+        case com_apple_jobjc_Coder_FFI_VOID:        return ptr_to_jlong(&ffi_type_void);
+        case com_apple_jobjc_Coder_FFI_PTR:            return ptr_to_jlong(&ffi_type_pointer);
+        case com_apple_jobjc_Coder_FFI_SINT8:        return ptr_to_jlong(&ffi_type_sint8);
+        case com_apple_jobjc_Coder_FFI_UINT8:        return ptr_to_jlong(&ffi_type_uint8);
+        case com_apple_jobjc_Coder_FFI_SINT16:        return ptr_to_jlong(&ffi_type_sint16);
+        case com_apple_jobjc_Coder_FFI_UINT16:        return ptr_to_jlong(&ffi_type_uint16);
+        case com_apple_jobjc_Coder_FFI_SINT32:        return ptr_to_jlong(&ffi_type_sint32);
+        case com_apple_jobjc_Coder_FFI_UINT32:        return ptr_to_jlong(&ffi_type_uint32);
+        case com_apple_jobjc_Coder_FFI_SINT64:        return ptr_to_jlong(&ffi_type_sint64);
+        case com_apple_jobjc_Coder_FFI_UINT64:        return ptr_to_jlong(&ffi_type_uint64);
+        case com_apple_jobjc_Coder_FFI_FLOAT:        return ptr_to_jlong(&ffi_type_float);
+        case com_apple_jobjc_Coder_FFI_DOUBLE:        return ptr_to_jlong(&ffi_type_double);
+        case com_apple_jobjc_Coder_FFI_LONGDOUBLE:    return ptr_to_jlong(&ffi_type_longdouble);
+    }
+
+    return ptr_to_jlong(NULL);
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/FFIType.m b/jdk/src/macosx/native/jobjc/src/core/native/FFIType.m
new file mode 100644
index 0000000..add7689
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/FFIType.m
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+#include <ffi/ffi.h>
+
+#include "com_apple_jobjc_FFIType.h"
+
+JNIEXPORT void JNICALL Java_com_apple_jobjc_FFIType_makeFFIType
+(JNIEnv *env, jclass clazz, jlong ffi_type_jlong, jlong ffi_type_elements_jlong)
+{
+    ffi_type *type = jlong_to_ptr(ffi_type_jlong);
+    type->elements = jlong_to_ptr(ffi_type_elements_jlong);
+    type->type = FFI_TYPE_STRUCT;
+    type->size = type->alignment = 0;
+}
+
+JNIEXPORT jint JNICALL Java_com_apple_jobjc_FFIType_getFFITypeSizeof
+(JNIEnv *env, jclass clazz)
+{
+    return (jint) sizeof(ffi_type);
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/Function.m b/jdk/src/macosx/native/jobjc/src/core/native/Function.m
new file mode 100644
index 0000000..384912c
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/Function.m
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_Function.h"
+
+#define MACOSX
+#include <dlfcn.h>
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_Function_getFxnPtrForFunctionName
+(JNIEnv *env, jclass clazz, jstring fxnName)
+{
+    const char *functionName = (*env)->GetStringUTFChars(env, fxnName, NULL);
+    void *fxnPtr = dlsym(RTLD_SELF, functionName);
+    (*env)->ReleaseStringUTFChars(env, fxnName, functionName);
+    return ptr_to_jlong(fxnPtr);
+}
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_Function_getFxnPtrForFunctionNameAndLib
+(JNIEnv *env, jclass clazz, jlong frameworkPtr, jstring fxnName)
+{
+    void *frameworkHandle = jlong_to_ptr(frameworkPtr);
+
+    const char *functionName = (*env)->GetStringUTFChars(env, fxnName, NULL);
+    void *fxnPtr = dlsym(frameworkHandle, functionName);
+    (*env)->ReleaseStringUTFChars(env, fxnName, functionName);
+
+    return ptr_to_jlong(fxnPtr);
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/ID.m b/jdk/src/macosx/native/jobjc/src/core/native/ID.m
new file mode 100644
index 0000000..1f1da24
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/ID.m
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_ID.h"
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#include <objc/runtime.h>
+#include <objc/message.h>
+
+/*
+ * Class:     com_apple_jobjc_ID
+ * Method:    getNativeDescription
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_jobjc_ID_getNativeDescription
+(JNIEnv *env, jclass clazz, jlong objPtr)
+{
+    jstring ret = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    NSString *desc = [((id)jlong_to_ptr(objPtr)) description];
+    ret = JNFNSToJavaString(env, desc);
+
+JNF_COCOA_EXIT(env);
+
+    return ret;
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/Invoke.m b/jdk/src/macosx/native/jobjc/src/core/native/Invoke.m
new file mode 100644
index 0000000..56cfc0f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/Invoke.m
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_Invoke_FunCall.h"
+#include "com_apple_jobjc_Invoke_MsgSend.h"
+#include "com_apple_jobjc_Invoke_MsgSendSuper.h"
+#include <ffi/ffi.h>
+#include <objc/message.h>
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+JNIEXPORT void JNICALL Java_com_apple_jobjc_Invoke_00024FunCall_invoke
+(JNIEnv *env, jclass clazz, jlong cifPtr, jlong fxnPtr, jlong retValPtr, jlong argsPtr)
+{
+    ffi_cif *cif = jlong_to_ptr(cifPtr);
+    void *fxn    = jlong_to_ptr(fxnPtr);
+    void *retVal = jlong_to_ptr(retValPtr);
+    void **args  = jlong_to_ptr(argsPtr);
+
+    ffi_call(cif, fxn, retVal, args);
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/JObjCRuntime.m b/jdk/src/macosx/native/jobjc/src/core/native/JObjCRuntime.m
new file mode 100644
index 0000000..bc7e8b1
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/JObjCRuntime.m
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_JObjCRuntime.h"
+#include "Cocoa/Cocoa.h"
+
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/MacOSXFramework.m b/jdk/src/macosx/native/jobjc/src/core/native/MacOSXFramework.m
new file mode 100644
index 0000000..83bd678
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/MacOSXFramework.m
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_MacOSXFramework.h"
+
+#include <dlfcn.h>
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ * Class:     com_apple_jobjc_MacOSXFramework
+ * Method:    retainFramework
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_MacOSXFramework_retainFramework
+(JNIEnv *env, jclass clazz, jstring frameworkName)
+{
+    if (frameworkName == NULL) return ptr_to_jlong(NULL);
+    const char *frameworkNameCStr = (*env)->GetStringUTFChars(env, frameworkName, JNI_FALSE);
+    const void *library = dlopen(frameworkNameCStr, RTLD_LOCAL);
+    (*env)->ReleaseStringUTFChars(env, frameworkName, frameworkNameCStr);
+    return ptr_to_jlong(library);
+}
+
+/*
+ * Class:     com_apple_jobjc_MacOSXFramework
+ * Method:    releaseFramework
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_jobjc_MacOSXFramework_releaseFramework
+(JNIEnv *env, jclass clazz, jlong frameworkPtr)
+{
+    dlclose(jlong_to_ptr(frameworkPtr));
+}
+
+JNIEXPORT void JNICALL Java_com_apple_jobjc_MacOSXFramework_getConstant
+(JNIEnv *env, jclass clazz, jlong frameworkPtr, jstring constSymbol, jlong retBuffer, jint size)
+{
+    const char *symbol = (*env)->GetStringUTFChars(env, constSymbol, JNI_FALSE);
+    void *handle = frameworkPtr ? jlong_to_ptr(frameworkPtr) : RTLD_DEFAULT;
+    void *data = dlsym(handle, symbol);
+    (*env)->ReleaseStringUTFChars(env, constSymbol, symbol);
+
+    if(!data)
+        (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"), dlerror());
+    else
+        memcpy(jlong_to_ptr(retBuffer), data, (size_t) size);
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/NSClass.m b/jdk/src/macosx/native/jobjc/src/core/native/NSClass.m
new file mode 100644
index 0000000..7366396
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/NSClass.m
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_NSClass.h"
+#include <objc/runtime.h>
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ * Class:     com_apple_jobjc_NSClass
+ * Method:    getNativeClassByName
+ * Signature: (JLjava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_NSClass_getNativeClassByName
+(JNIEnv *env, jclass clazz, jstring className)
+{
+    if (className == NULL) return ptr_to_jlong(NULL);
+    const char *classNameCStr = (*env)->GetStringUTFChars(env, className, JNI_FALSE);
+    const id obj = objc_getClass(classNameCStr);
+    (*env)->ReleaseStringUTFChars(env, className, classNameCStr);
+
+    if (obj == nil) return ptr_to_jlong(NULL);
+    return ptr_to_jlong(obj);
+}
+
+/*
+ * Class:     com_apple_jobjc_NSClass
+ * Method:    getSuperClass
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_NSClass_getSuperClassOfClass
+(JNIEnv *env, jclass clazz, jlong clazzPtr)
+{
+    if (clazzPtr == 0L) return ptr_to_jlong(NULL);
+    const Class objClazz = (Class)jlong_to_ptr(clazzPtr);
+    return ptr_to_jlong(class_getSuperclass(objClazz));
+}
+
+/*
+ * Class:     com_apple_jobjc_NSClass
+ * Method:    getClassName
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_jobjc_NSClass_getClassNameOfClass
+(JNIEnv *env, jclass clazz, jlong clazzPtr)
+{
+    const char *clazzName = (char *)class_getName((Class)jlong_to_ptr(clazzPtr));
+    return (*env)->NewStringUTF(env, clazzName);
+}
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_NSClass_getClass
+(JNIEnv *env, jclass clazz, jlong objPtr)
+{
+    id obj = (id)jlong_to_ptr(objPtr);
+    return ptr_to_jlong(object_getClass(obj));
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/NativeBuffer.h b/jdk/src/macosx/native/jobjc/src/core/native/NativeBuffer.h
new file mode 100644
index 0000000..5a5047c
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/NativeBuffer.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ *  NativeBuffer.h
+ *  Copyright 2007 Apple Inc. All rights reserved.
+ *
+ */
+
+#define BUFFER_AT(buffer, offset)                (((UInt8 *)buffer) + offset)
+#define GET_VALUE(type, buffer, offset)            (*((type *)BUFFER_AT(buffer, offset)))
+#define PUT_VALUE(type, buffer, offset, value)    (*((type *)BUFFER_AT(buffer, offset)) = value)
+
+#define GET_INT_AT(buffer, offset)                GET_VALUE(jint, buffer, offset)
+#define GET_LONG_AT(buffer, offset)                GET_VALUE(jlong, buffer, offset)
+
+#define PUT_INT_AT(buffer, offset, value)        PUT_VALUE(jint, buffer, offset, value)
+#define PUT_LONG_AT(buffer, offset, value)        PUT_VALUE(jlong, buffer, offset, value)
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/NativeBuffer.m b/jdk/src/macosx/native/jobjc/src/core/native/NativeBuffer.m
new file mode 100644
index 0000000..aef0fd7
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/NativeBuffer.m
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_NativeBuffer.h"
+
+#define MACOSX
+#include <ffi/ffi.h>
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_NativeBuffer_getPtrOfBuffer
+(JNIEnv *env, jclass clazz, jobject buffer)
+{
+    if (buffer == NULL) return ptr_to_jlong(0);
+    return ptr_to_jlong((*env)->GetDirectBufferAddress(env, buffer));
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/NativeObjectLifecycleManager.m b/jdk/src/macosx/native/jobjc/src/core/native/NativeObjectLifecycleManager.m
new file mode 100644
index 0000000..9a76b36
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/NativeObjectLifecycleManager.m
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_NativeObjectLifecycleManager.h"
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+/*
+ * Class:     com_apple_jobjc_NativeObjectLifecycleManager
+ * Method:    retainNativeObject
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_jobjc_NativeObjectLifecycleManager_retainNativeObject
+(JNIEnv *env, jclass clazz, jlong ptr)
+{
+    if (ptr == 0L) return;
+    CFRetain(jlong_to_ptr(ptr));
+}
+
+/*
+ * Class:     com_apple_jobjc_NativeObjectLifecycleManager
+ * Method:    releaseNativeObject
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_jobjc_NativeObjectLifecycleManager_releaseNativeObject
+(JNIEnv *env, jclass clazz, jlong ptr)
+{
+    if (ptr == 0L) return;
+    CFRelease(jlong_to_ptr(ptr));
+}
+
+/*
+ * Class:     com_apple_jobjc_NativeObjectLifecycleManager
+ * Method:    freeNativeObject
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_jobjc_NativeObjectLifecycleManager_freeNativeObject
+(JNIEnv *env, jclass clazz, jlong ptr)
+{
+    if (ptr == 0L) return;
+    free(jlong_to_ptr(ptr));
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/SEL.m b/jdk/src/macosx/native/jobjc/src/core/native/SEL.m
new file mode 100644
index 0000000..e6c5b47
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/SEL.m
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_SEL.h"
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+#include <objc/message.h>
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_SEL_getSelectorPtr
+(JNIEnv *env, jclass jclazz, jstring selName)
+{
+    const char *selNameAsChars = (*env)->GetStringUTFChars(env, selName, JNI_FALSE);
+    const SEL sel = sel_registerName(selNameAsChars);
+    (*env)->ReleaseStringUTFChars(env, selName, selNameAsChars);
+    return ptr_to_jlong(sel);
+}
+
+JNIEXPORT jstring JNICALL Java_com_apple_jobjc_SEL_getSelectorName
+(JNIEnv *env, jclass jclazz, jlong selPtr)
+{
+    return (*env)->NewStringUTF(env, sel_getName(jlong_to_ptr(selPtr)));
+}
diff --git a/jdk/src/macosx/native/jobjc/src/core/native/Subclassing.m b/jdk/src/macosx/native/jobjc/src/core/native/Subclassing.m
new file mode 100644
index 0000000..14c2442
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/native/Subclassing.m
@@ -0,0 +1,301 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_Subclassing.h"
+
+#include <math.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <objc/runtime.h>
+#include <objc/message.h>
+
+#include <ffi/ffi.h>
+#include <sys/mman.h>
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+// Subclassing of Obj-C classes in Java
+//
+// See:
+//  - Objective-C Runtime documentation
+//  - man ffi_prep_closure
+//  - Subclassing.java
+
+
+#pragma mark Accessing object in IVar
+
+#define JOBJ_IVAR_NAME "jObjWrapper"
+static jobject getJObjectFromIVar(id obj);
+
+jobject getJObjectFromIVar(id obj)
+{
+    JNFJObjectWrapper *wrapper = NULL;
+    object_getInstanceVariable(obj, JOBJ_IVAR_NAME, (void**) &wrapper);
+    return wrapper ? [wrapper jObject] : NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_com_apple_jobjc_Subclassing_getJObjectFromIVar
+(JNIEnv *env, jclass jClass, jlong jPtr)
+{
+    id obj = (id) jlong_to_ptr(jPtr);
+    if(obj == NULL){
+        (*env)->ThrowNew(env, (*env)->FindClass(env,
+            "java/lang/NullPointerException"), "obj");
+        return NULL;
+    }
+
+    JNFJObjectWrapper *wrapper;
+
+    if(!object_getInstanceVariable(obj, JOBJ_IVAR_NAME, (void**) &wrapper)){
+        NSLog(@"IVar '%s' not found. obj: %@", JOBJ_IVAR_NAME, obj);
+        (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"),
+            "Could not find instance variable that holds Java object.");
+        return NULL;
+    }
+
+    return wrapper ? [wrapper jObject] : NULL;
+}
+
+JNIEXPORT void JNICALL Java_com_apple_jobjc_Subclassing_initJObjectToIVar
+(JNIEnv *env, jclass jClass, jlong jPtr, jobject jObject)
+{
+    id obj = (id) jlong_to_ptr(jPtr);
+    JNFJObjectWrapper *wrapper = [[JNFJObjectWrapper alloc]
+        initWithJObject:jObject withEnv:env];
+    [wrapper retain];
+
+    if(!object_setInstanceVariable(obj, JOBJ_IVAR_NAME, wrapper)){
+        NSLog(@"IVar '%s' not found. obj: %@", JOBJ_IVAR_NAME, obj);
+        (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"),
+            "Could not find instance variable that holds Java object.");
+        return;
+    }
+}
+
+#pragma mark Registering class
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_Subclassing_allocateClassPair
+(JNIEnv *env, jclass clazz, jlong jSuperClass, jstring jName)
+{
+    const Class superClass = (Class)jlong_to_ptr(jSuperClass);
+    assert(superClass);
+
+    const char *name = (*env)->GetStringUTFChars(env, jName, JNI_FALSE);
+    const Class newClass = objc_allocateClassPair(superClass, name, 0);
+    (*env)->ReleaseStringUTFChars(env, jName, name);
+
+    return ptr_to_jlong(newClass);
+}
+
+JNIEXPORT jboolean JNICALL Java_com_apple_jobjc_Subclassing_addIVarForJObj
+(JNIEnv *env, jclass clazz, jlong jSynthClass)
+{
+    return class_addIvar(
+        jlong_to_ptr(jSynthClass),
+        JOBJ_IVAR_NAME,
+        sizeof(id),
+        (uint8_t)log2((double)sizeof(id)),
+        "@");
+}
+
+JNIEXPORT void JNICALL Java_com_apple_jobjc_Subclassing_registerClassPair
+(JNIEnv *env, jclass clazz, jlong jClass)
+{
+    Class c = jlong_to_ptr(jClass);
+//    NSLog(@"Registering class pair %p / %s", c, class_getName(c));
+    objc_registerClassPair(c);
+}
+
+
+#pragma mark Patching +alloc
+
+static id patchedAllocIMP(id obj, SEL sel);
+static void addJavaInstance(id obj);
+
+JNIEXPORT jboolean JNICALL Java_com_apple_jobjc_Subclassing_patchAlloc
+(JNIEnv *env, jclass clazz, jlong jNativeClass)
+{
+    Class metaClass = object_getClass(jlong_to_ptr(jNativeClass));
+    return class_addMethod(metaClass,
+       sel_registerName("alloc"),
+       (IMP) patchedAllocIMP,
+       "@@:");
+}
+
+static id patchedAllocIMP(id cls, SEL sel){
+    id inst = class_createInstance(cls, 0);
+    addJavaInstance(inst);
+    return inst;
+}
+
+static void addJavaInstance(id obj){
+//    NSLog(@"addJavaInstance %p", obj);
+//    NSLog(@"... calling up to Java");
+
+    static JNF_CLASS_CACHE(jc_Subclassing, "com/apple/jobjc/Subclassing");
+    static JNF_STATIC_MEMBER_CACHE(jm_Subclassing_initJObject,
+        jc_Subclassing,
+        "initJObject",
+        "(J)V");
+
+    JNFThreadContext threadWasAttached = JNFThreadDetachOnThreadDeath;
+    JNIEnv *env = JNFObtainEnv(&threadWasAttached);
+    JNFCallStaticVoidMethod(env, jm_Subclassing_initJObject,
+        ptr_to_jlong(obj));
+
+    JNFReleaseEnv(env, &threadWasAttached);
+}
+
+
+#pragma mark Adding methods
+
+static ffi_closure *make_closure(ffi_cif *cif, void *user_data);
+static void sel_closure_call(ffi_cif* cif, void* result, void** args, void* user_data);
+
+typedef struct closure_data_t{
+    JNFJObjectWrapper *jMethod;
+    JNFJObjectWrapper *jCIF;
+} closure_data_t;
+
+static ffi_closure *make_closure(ffi_cif *cif, void *user_data){
+    // Allocate a page to hold the closure with read and write permissions.
+    ffi_closure *closure;
+    if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
+                        MAP_ANON | MAP_PRIVATE, -1, (off_t) 0)) == (void*)-1)
+    {
+        fprintf(stderr, "mmap failed with errno: %d", errno);
+        return NULL;
+    }
+
+    // Prepare the ffi_closure structure.
+    ffi_status status;
+    if ((status = ffi_prep_closure(closure, cif, sel_closure_call, (void *)user_data)) != FFI_OK)
+    {
+        fprintf(stderr, "ffi_prep_closure failed with ffi_status: %d", status);
+        munmap(closure, sizeof(ffi_closure));
+        return NULL;
+    }
+
+    // Ensure that the closure will execute on all architectures.
+    if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1)
+    {
+        fprintf(stderr, "mprotect failed with errno: %d", errno);
+        munmap(closure, sizeof(ffi_closure));
+        return NULL;
+    }
+    return closure;
+}
+
+JNIEXPORT jboolean JNICALL Java_com_apple_jobjc_Subclassing_addMethod
+(JNIEnv *env, jclass clazz, jlong jClass, jstring jSelName, jobject jMethod,
+    jobject jCIF, jlong jCIFPtr, jstring jObjCEncodedType)
+{
+    ffi_cif *cif = jlong_to_ptr(jCIFPtr);
+
+    closure_data_t *user_data = malloc(sizeof(closure_data_t));
+    user_data->jMethod = [[JNFJObjectWrapper alloc] initWithJObject:jMethod withEnv:env];
+    user_data->jCIF = [[JNFJObjectWrapper alloc] initWithJObject:jCIF withEnv:env];
+
+    ffi_closure *closure;;
+    if(!(closure = make_closure(cif, user_data))){
+        [user_data->jMethod release];
+        [user_data->jCIF release];
+        free(user_data);
+        return NO;
+    }
+
+    const Class objcClass = (Class)jlong_to_ptr(jClass);
+
+    const char *selName = (*env)->GetStringUTFChars(env, jSelName, JNI_FALSE);
+    const char *objCEncodedType = (*env)->GetStringUTFChars(env, jObjCEncodedType, JNI_FALSE);
+
+//    NSLog(@"Adding method '%s' :: '%s' to '%s' / %p",
+//        selName,
+//        objCEncodedType,
+//        class_getName(objcClass),
+//        objcClass);
+
+    BOOL ret = class_addMethod(objcClass, sel_registerName(selName), (IMP) closure, objCEncodedType);
+
+    (*env)->ReleaseStringUTFChars(env, jSelName, selName);
+    (*env)->ReleaseStringUTFChars(env, jObjCEncodedType, objCEncodedType);
+
+    if(!ret){
+        NSLog(@"class_addMethod failed");
+        munmap(closure, sizeof(ffi_closure));
+        [user_data->jMethod release];
+        [user_data->jCIF release];
+        free(user_data);
+        return NO;
+    }
+
+    return ret;
+}
+
+static void sel_closure_call(ffi_cif* cif, void* result, void** args, void* user_data)
+{
+    id obj = *(id*) args[0];
+//    SEL sel = *(SEL*) args[1];
+
+//    NSLog(@"Subclassing: sel_closure_call: %p %p", obj, sel);
+//    NSLog(@"Subclassing: sel_closure_call: obj class: %@  sel name: %s", object_getClass(obj), sel_getName(sel));
+
+    jobject jObj = getJObjectFromIVar(obj);
+
+    if(!jObj){
+        addJavaInstance(obj);
+        jObj = getJObjectFromIVar(obj);
+    }
+
+    closure_data_t *jmeta = user_data;
+    jobject jMethod = [jmeta->jMethod jObject];
+    jobject jCIF = [jmeta->jCIF jObject];
+
+    JNFThreadContext threadWasAttached = JNFThreadDetachOnThreadDeath;
+    JNIEnv *env = JNFObtainEnv(&threadWasAttached);
+
+    if((*env)->ExceptionOccurred(env)) goto bail;
+
+        static JNF_CLASS_CACHE(jc, "com/apple/jobjc/Subclassing");
+        static JNF_STATIC_MEMBER_CACHE(jm_invokeFromJNI, jc, "invokeFromJNI",
+        "(Lcom/apple/jobjc/ID;Ljava/lang/reflect/Method;Lcom/apple/jobjc/CIF;JJ)V");
+
+    JNFCallStaticVoidMethod(env, jm_invokeFromJNI,
+        jObj,
+        jMethod,
+        jCIF,
+        ptr_to_jlong(result),
+        ptr_to_jlong(args));
+
+bail:
+    JNFReleaseEnv(env, &threadWasAttached);
+
+    if((*env)->ExceptionOccurred(env)){
+        NSLog(@"Exception!");
+        (*env)->ExceptionDescribe(env);
+    }
+    JNFReleaseEnv(env, &threadWasAttached);
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/BootClassPathMinus.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/BootClassPathMinus.java
new file mode 100644
index 0000000..9c1bee7
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/BootClassPathMinus.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+public class BootClassPathMinus {
+
+    /*
+     * return the default boot class path with all parts mentioned in arguments removed
+     */
+    public static void main(String[] args) {
+    String bootClassPath = System.getProperty("sun.boot.class.path");
+    StringBuffer newPath = new StringBuffer(bootClassPath.length());
+    String[] bootClassPathParts = bootClassPath.split(java.io.File.pathSeparator, 0);
+    for (String part : bootClassPathParts) {
+        boolean found = false;
+        for (String minus : args) {
+        if (part.endsWith(minus)) {
+            found = true;
+        }
+        }
+        if (!found) {
+        if (newPath.length() > 0) newPath.append(java.io.File.pathSeparatorChar);
+        newPath.append(part);
+        }
+    }
+    System.out.println(newPath.toString());
+    }
+
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/ClassConsolidator.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/ClassConsolidator.java
new file mode 100644
index 0000000..e3e5b7f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/ClassConsolidator.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.apple.internal.jobjc.generator.model.Category;
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Framework;
+
+public class ClassConsolidator {
+    private static String[] PREFERRED_FRAMEWORKS = { "Foundation", "AppKit" };
+
+    static void consolidateClassesForFrameworks(final List<Framework> frameworks) throws Throwable {
+        System.out.println("--2-- Resolving duplicate classes:");
+        final Map<String, List<Clazz>> allClasses = new HashMap<String, List<Clazz>>();
+
+        for (final Framework framework : frameworks) {
+            for (final Clazz clazz : framework.classes) {
+                final List<Clazz> existingClazzList = allClasses.get(clazz.name);
+                if(existingClazzList != null)
+                    existingClazzList.add(clazz);
+                else
+                    allClasses.put(clazz.name, new ArrayList<Clazz>(Arrays.asList(clazz)));
+            }
+        }
+
+        final Map<String, Clazz> filteredClasses = new HashMap<String, Clazz>();
+        final List<List<Clazz>> dreggs = new ArrayList<List<Clazz>>();
+
+        final Collection<List<Clazz>> clazzLists = allClasses.values();
+        for (final List<Clazz> clazzList : clazzLists) {
+            if (clazzList.size() > 1) {
+                // add to the list for later analysis
+                dreggs.add(clazzList);
+                continue;
+            }
+
+            // if there is only one class definition, go with it!
+            final Clazz clazz = clazzList.get(0);
+            filteredClasses.put(clazz.name, clazz);
+        }
+
+        // figure out which class is the real class, and convert the rest to categories
+        for (final List<Clazz> dreg : dreggs)
+            deriveCategoriesFrom(dreg, filteredClasses);
+
+        // patch up the inheritance hierarchy
+        System.out.println("Determining super classes:");
+        for (final Framework framework : frameworks)
+            framework.resolveSuperClasses(filteredClasses);
+    }
+
+    private static void deriveCategoriesFrom(final List<Clazz> clazzes, final Map<String, Clazz> filteredClasses) {
+        final List<Clazz> clazzesToDerive = new ArrayList<Clazz>(clazzes);
+
+        for (final String preferredFrameworkName : PREFERRED_FRAMEWORKS) {
+            for (final Clazz clazz : clazzesToDerive) {
+                if (!preferredFrameworkName.equals(clazz.parent.name)) continue;
+
+                System.out.print("\t" + clazz.parent.name + " owns \"" + clazz.name + "\", ");
+                addCategoriesAndPatchClasses(clazzes, clazz);
+                filteredClasses.put(clazz.name, clazz);
+                return;
+            }
+        }
+
+        final List<String> frameworkNameList = new ArrayList<String>(clazzes.size());
+        for (final Clazz clazz : clazzes) frameworkNameList.add(clazz.parent.name);
+        throw new RuntimeException("Could not derived a preferred framework for: " + clazzes.get(0).name + ", from (" + Utils.joinWComma(frameworkNameList) + ")");
+    }
+
+    private static void addCategoriesAndPatchClasses(final List<Clazz> clazzes, final Clazz clazz) {
+        final List<String> fwNames = new ArrayList<String>(clazzes.size());
+
+        for (final Clazz cls : clazzes) {
+            if (cls == clazz) continue;
+            fwNames.add(cls.parent.name);
+            cls.parent.classes.remove(cls);
+            cls.parent.categories.add(new Category(cls, clazz));
+        }
+
+        System.out.println("creating categories in: " + Utils.joinWComma(fwNames));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/ClassGenerator.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/ClassGenerator.java
new file mode 100644
index 0000000..afcfae7
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/ClassGenerator.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.util.*;
+
+import com.apple.internal.jobjc.generator.classes.*;
+import com.apple.internal.jobjc.generator.model.Framework;
+
+public class ClassGenerator {
+    public static final String JOBJC_PACKAGE = "com.apple.jobjc";
+
+    public static List<OutputFile> generateClasses(final List<Framework> frameworks) {
+        final List<OutputFile> generatedClassFiles = new ArrayList<OutputFile>();
+
+        generatedClassFiles.add(new RootJObjCClass(frameworks));
+        for (final Framework f : frameworks) {
+            f.generateClasses(generatedClassFiles);
+        }
+
+        return generatedClassFiles;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FileCopier.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FileCopier.java
new file mode 100644
index 0000000..22adde1
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FileCopier.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.io.File;
+import java.util.*;
+
+import com.apple.internal.jobjc.generator.classes.*;
+
+public class FileCopier {
+    public static List<OutputFile> addSourceFilesFrom(final String srcPath) {
+        final List<OutputFile> outputFileList = new ArrayList<OutputFile>();
+
+        final List<File> fileList = getFileList(srcPath);
+        for (final File file : fileList) {
+            outputFileList.add(new CopiedFile(file, ClassGenerator.JOBJC_PACKAGE, file.getName().replace("\\.java", "")));
+        }
+
+        return outputFileList;
+    }
+
+    private static List<File> getFileList(final String srcPath) {
+        final File srcRoot = new File(srcPath);
+        if (!srcRoot.exists()) throw new RuntimeException("Source root " + srcRoot + " does not exist. Nowhere to copy base runtime objects from.");
+
+        final File targetDir = new File(srcRoot, ClassGenerator.JOBJC_PACKAGE.replaceAll("\\.", "\\/"));
+        if (!targetDir.exists() || !targetDir.isDirectory()) throw new RuntimeException("Base runtime object source directory " + targetDir + " does not exist. No runtime class files to copy.");
+
+        final List<File> fileList = new ArrayList<File>();
+        final File[] targetDirFileList = targetDir.listFiles();
+        for (final File file : targetDirFileList) {
+            if (!file.isFile()) continue;
+            if (!file.getName().endsWith(".java")) continue;
+            fileList.add(file);
+        }
+
+        return fileList;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FrameworkGenerator.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FrameworkGenerator.java
new file mode 100644
index 0000000..d2f01d8
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FrameworkGenerator.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.model.Framework.FrameworkDependency;
+import com.apple.internal.jobjc.generator.utils.Fp;
+import com.apple.internal.jobjc.generator.utils.StructOffsetResolverBigBang;
+import com.apple.jobjc.JObjCRuntime;
+
+public class FrameworkGenerator {
+    private static final String BRIDGESUPPORT_FILE_EXTENSION = "Full.bridgesupport";
+    private static final String FRAMEWORK_MATCH = "^.*Full\\.bridgesupport$";
+    private static final String FRAMEWORK_PRUNE = "^.*(PyObjC|/Versions|\\.lproj|/Headers|/PrivateHeaders).*$";
+
+    static List<File> findFrameworkFilesIn(final File file) throws IOException{
+        final List<File> bridgeSupportFiles = Utils.find(file, FRAMEWORK_MATCH, FRAMEWORK_PRUNE);
+        System.out.println("found " + bridgeSupportFiles.size() + " frameworks");
+        return bridgeSupportFiles;
+    }
+
+    static List<Framework> parseFrameworksFrom(final List<File> bridgeSupportFiles) {
+        final List<Framework> frameworks = new ArrayList<Framework>();
+
+        System.out.println("Parsing XML");
+        for (final File file : bridgeSupportFiles){
+            Framework f = new Framework(extractFrameworkNameFrom(file), file);
+            try{
+                f.load();
+                frameworks.add(f);
+                System.out.println("Generator@" + JObjCRuntime.ARCH + " loaded "
+                        + f.name + " (" + Fp.join(":", f.binaries) + ")");
+            }
+            catch(Exception x){
+                System.out.println("!! Generator@" + JObjCRuntime.ARCH + " failed to load "
+                        + f.name + " (" + Fp.join(":", f.binaries) + "). SKIPPING");
+            }
+        }
+
+        System.out.println("Parsing dependencies");
+        for (final Framework f : frameworks) f.parseDependencies(frameworks);
+
+        Set<String> alreadyWarnedDependency = new HashSet<String>();
+        for(final Framework f : frameworks)
+            for(final FrameworkDependency dep : f.dependencies)
+                if(dep.object == null && !alreadyWarnedDependency.contains(dep.name)){
+                    System.out.println(String.format("Warning: unresolved dependency: %1$30s -> %2$s", f.name, dep.name));
+                    alreadyWarnedDependency.add(dep.name);
+                }
+        if(alreadyWarnedDependency.size() > 0)
+            System.out.println("Unresolved dependencies lead to unresolved types.");
+
+        Utils.topologicalSort(frameworks);
+        List<Framework> cycle = Utils.getDependencyCycle(frameworks);
+        if(cycle != null)
+            System.out.println("Warning: cycle found in framework dependencies: " + Fp.join(" -> ", cycle));
+
+        System.out.println("Parsing types");
+        for (final Framework f : frameworks){
+            f.parseCFTypes();
+            f.parseOpaques();
+        }
+        for (final Framework f : frameworks) f.parseStructs();
+
+        new StructOffsetResolverBigBang().resolve(frameworks);
+
+        System.out.println("Parsing classes");
+        for (final Framework f : frameworks) f.parseClasses();
+
+        System.out.println("Parsing constants");
+        for (final Framework f : frameworks) f.parseConstants();
+
+        System.out.println("Parsing functions");
+        for (final Framework f : frameworks) f.parseFunctions();
+
+        return frameworks;
+    }
+
+    private static String extractFrameworkNameFrom(final File file) {
+        final String fileName = file.getName();
+        return fileName.substring(0, fileName.lastIndexOf(BRIDGESUPPORT_FILE_EXTENSION));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FunctionGenerator.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FunctionGenerator.java
new file mode 100644
index 0000000..6aefa35
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/FunctionGenerator.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.io.PrintStream;
+import java.io.StringWriter;
+
+import com.apple.internal.jobjc.generator.model.Arg;
+import com.apple.internal.jobjc.generator.model.Function;
+import com.apple.internal.jobjc.generator.model.Method;
+import com.apple.internal.jobjc.generator.model.types.JType;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLCall;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLField;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLMethod;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLTertiary;
+import com.apple.jobjc.Coder;
+import com.apple.jobjc.Invoke;
+import com.apple.jobjc.Invoke.FunCall;
+import com.apple.jobjc.Invoke.MsgSend;
+
+public class FunctionGenerator {
+    private final static String VARARGS_NAME = "varargs";
+
+    private static String createFieldCache(final Class<? extends Invoke> type, final Function fxn) {
+        final String identifier = makeInstanceName(fxn);
+
+        JLField field = new JLField("private static", type.getCanonicalName(), identifier);
+        // It's okay to make it static, because the getter isn't static, so the only way to access it is through an instance.
+        JLMethod getter = new JLMethod("private final", type.getCanonicalName(), "get_" + identifier);
+
+        JLCall createIt = new JLCall("new " + type.getCanonicalName());
+        createIt.args.add(firstArg(fxn));
+        createIt.args.add("\"" + fxn.name + "\"");
+        createIt.args.add(fxn.returnValue.type.getJType().getCoderDescriptor().getCoderInstanceName());
+        for (final Arg arg : fxn.args)
+            createIt.args.add(arg.type.getJType().getCoderDescriptor().getCoderInstanceName());
+
+        getter.body.add("return " + new JLTertiary(identifier + " != null", identifier, identifier + " = " + createIt) + ";");
+
+        return field.toString() + getter.toString();
+    }
+
+    private static String createLocalForward(final Class<? extends Invoke> type, final Function fxn) {
+        final String identifier = makeInstanceName(fxn);
+        return new JLField("final", type.getCanonicalName(), identifier, new JLCall("get_" + identifier)).toString();
+    }
+
+    private static String createLocalNew(final Class<? extends Invoke> type, final Function fxn) {
+        final String identifier = makeInstanceName(fxn);
+        StringWriter out = new StringWriter();
+
+        out.append(String.format("%3$s[] argCoders = new %3$s[%1$d + %2$s.length];\n", fxn.args.size(), VARARGS_NAME, Coder.class.getCanonicalName()));
+
+        for(int i = 0; i < fxn.args.size(); i++)
+            out.append(String.format("argCoders[%1$d] = %2$s;\n", i, fxn.args.get(0).type.getJType().getCoderDescriptor().getCoderInstanceName()));
+
+        if(fxn.variadic){
+            out.append(String.format("for(int i = %1$d; i < (%1$d + %2$s.length); i++)\n", fxn.args.size(), VARARGS_NAME));
+            out.append(String.format("\targCoders[i] = %1$s.getCoderAtRuntime(%2$s[i - %3$s]);\n", Coder.class.getCanonicalName(), VARARGS_NAME, fxn.args.size()));
+        }
+
+        out.append("final " + type.getCanonicalName() + " " + identifier + " = new " + type.getCanonicalName() + "(" + firstArg(fxn) + ", \"" + fxn.name + "\", "
+                + fxn.returnValue.type.getJType().getCoderDescriptor().getCoderInstanceName() + ", argCoders);");
+
+        return out.toString();
+    }
+
+    private static final String CONTEXT_NAME = "nativeBuffer";
+
+    public static void writeOutFunction(final PrintStream out, final Class<? extends Invoke> type, final Function fxn, final String initWithObj) {
+        final String instName = makeInstanceName(fxn);
+        final JType returnJavaType = fxn.returnValue.type.getJType();
+
+        if(!fxn.variadic){
+            out.print(createFieldCache(type, fxn));
+            out.println();
+        }
+
+        JLMethod meth = new JLMethod("public", returnJavaType.getJavaReturnTypeName(), fxn.getJavaName());
+
+        for(Arg arg : fxn.args)
+            meth.args.add("final " + arg.type.getJType().getTypeNameAsParam() + " " + arg.javaName);
+
+        if(fxn.variadic)
+            meth.args.add("final Object... " + VARARGS_NAME);
+
+        if(fxn instanceof Method && ((Method)fxn).ignore){
+            String suggestion = ((Method)fxn).suggestion == null ? "" : (" Suggested work-around: " + ((Method)fxn).suggestion);
+            meth.jdoc.add("@deprecated The framework recommends that this method be ignored. (It may be deprecated.)" + suggestion);
+            meth.attrs.add("@Deprecated");
+        }
+
+        // type mismatch warning
+        {
+            {
+                String retMsg = fxn.returnValue.type.getJType().getCoderDescriptor().mismatchMessage();
+                if(retMsg != null){
+                    meth.jdoc.add("@deprecated Possible type mismatch: (return value) " + retMsg);
+                    meth.attrs.add("@Deprecated");
+                }
+            }
+
+            for(int i = 0; i < fxn.args.size(); i++){
+                final Arg arg = fxn.args.get(i);
+                String argMsg = arg.type.getJType().getCoderDescriptor().mismatchMessage();
+                if(argMsg != null){
+                    meth.jdoc.add("@deprecated Possible type mismatch: (arg" + i + ": " + arg.javaName + ") " + argMsg);
+                    meth.attrs.add("@Deprecated");
+                }
+            }
+        }
+
+        if(fxn.variadic)
+            meth.body.add(createLocalNew(coreType(fxn), fxn));
+        else
+            meth.body.add(createLocalForward(coreType(fxn), fxn));
+
+        meth.body.add(returnJavaType.createDeclareBuffer(CONTEXT_NAME));
+        meth.body.add(returnJavaType.createInit(CONTEXT_NAME, instName, initWithObj));
+
+        for(final Arg arg : fxn.args)
+            meth.body.add(arg.type.getJType().getCoderDescriptor().getPushStatementFor(CONTEXT_NAME, arg.javaName));
+
+        if(fxn.variadic){
+            meth.body.add(String.format("for(int i = %1$d; i < (%1$d + %2$s.length); i++)", fxn.args.size(), VARARGS_NAME));
+            meth.body.add(String.format("\targCoders[i].push(%1$s, %2$s[i - %3$d]);", CONTEXT_NAME, VARARGS_NAME, fxn.args.size()));
+        }
+
+        meth.body.add(returnJavaType.createInvoke(CONTEXT_NAME, instName));
+        meth.body.add(returnJavaType.createPop(CONTEXT_NAME));
+        meth.body.add(returnJavaType.createReturn());
+
+        out.print(meth.toString());
+        out.println();
+    }
+
+    private static Class<? extends Invoke> coreType(final Function fxn){
+        return fxn instanceof Method ? MsgSend.class : FunCall.class;
+    }
+
+    private static String firstArg(Function fxn){
+        return fxn instanceof Method ? "getRuntime()" : "this";
+    }
+
+    private static String makeInstanceName(Function fxn){
+        String ext;
+        if(fxn instanceof Method){
+            if(((Method) fxn).isClassMethod) ext = "CMetInst";
+            else                             ext = "IMetInst";
+        }
+        else
+            ext = "FxnInst";
+
+        return fxn.getJavaName() + "_" + ext;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/Generator.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/Generator.java
new file mode 100644
index 0000000..058a87e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/Generator.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import com.apple.internal.jobjc.generator.classes.MixedPrimitiveCoderClassFile;
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.model.coders.ComplexCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.types.Type;
+import com.apple.internal.jobjc.generator.model.types.TypeCache;
+import com.apple.internal.jobjc.generator.utils.Fp.Pair;
+
+public class Generator {
+    private static final String DEFAULT_FRAMEWORKS_PATH = "/System/Library/Frameworks";
+    private static final String DEFAULT_OUTPUT_PATH = "/tmp/JObjC";
+
+    public static void main(final String...args) throws Throwable {
+        final Map<String, String> argMap = Utils.getArgs(args);
+
+        final String dst = get(argMap, "dst", DEFAULT_OUTPUT_PATH);
+        System.out.println("Cleaning up: " + dst);
+        final File dstLoc = new File(dst);
+        Utils.recDelete(dstLoc);
+        dstLoc.mkdirs();
+        System.out.println("Outputting classes to: " + dst);
+
+        final String frameworksPath = get(argMap, "frameworks", DEFAULT_FRAMEWORKS_PATH);
+        System.out.println("Searching for bridged frameworks in: " + frameworksPath);
+
+        final List<File> bridgeSupportFiles = FrameworkGenerator.findFrameworkFilesIn(new File(frameworksPath));
+        final List<Framework> frameworks = FrameworkGenerator.parseFrameworksFrom(bridgeSupportFiles);
+
+        System.out.println("--1-- Generator: consolidateClassesForFrameworks");
+        ClassConsolidator.consolidateClassesForFrameworks(frameworks);
+
+        System.out.println("--1-- Generator: TypeCache load");
+        TypeCache.inst().load(frameworks);
+
+        System.out.println("--1-- Generator: disambiguateMethodNames");
+        MethodDisambiguator.disambiguateMethodNames();
+
+        System.out.println("--1-- Generator: disambiguateFunctionsIn");
+        MethodDisambiguator.disambiguateFunctionsIn(frameworks);
+
+        System.out.println("--1-- Generator: generateClasses");
+        final List<OutputFile> sourceFiles = ClassGenerator.generateClasses(frameworks);
+        sourceFiles.add(new MixedPrimitiveCoderClassFile(ComplexCoderDescriptor.getMixedEncoders()));
+
+        System.out.println("--1-- Generator: writing " + sourceFiles.size() + " files");
+        for (final OutputFile sourceFile : sourceFiles) sourceFile.write(dstLoc);
+
+        System.out.println("I have " + TypeCache.inst().getUnknownTypes().size() + " unresolved types.");
+        for (final Type type : TypeCache.inst().getUnknownTypes())
+            System.out.println("[Warning] unknown type: " + type);
+
+        for(Type type : TypeCache.inst().typesByNTypes.values()){
+            if(!type.type32.getClass().equals(type.type64.getClass())){
+                System.out.format("Type with differing NTypes: %1$15s: %2$s\n", type.name, new Pair(type.type32, type.type64));
+            }
+        }
+    }
+
+    private static String get(final Map<String, String> defaults, final String key, final String defaultValue) {
+        final String value = defaults.get(key);
+        if (value != null) return value;
+        return defaultValue;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/MethodDisambiguator.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/MethodDisambiguator.java
new file mode 100644
index 0000000..db0b5f0
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/MethodDisambiguator.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.util.List;
+
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.model.Function;
+import com.apple.internal.jobjc.generator.model.types.TypeCache;
+
+public class MethodDisambiguator {
+    static void disambiguateMethodNames() {
+        // link all subclassers off their parents
+        for (final Clazz clazz : TypeCache.inst().getAllClasses()) {
+            final Clazz superClazz = clazz.superClass;
+            if (superClazz != null) superClazz.subClassers.add(clazz);
+        }
+
+        // recursively call all subclassers, starting from NSObject on down
+        disambiguateMethodNamesFor(TypeCache.inst().getClassForName("NSObject"));
+
+        // NSProxy does not appear to subclass from NSObject, but it is still a real full class...?
+        disambiguateMethodNamesFor(TypeCache.inst().getClassForName("NSProxy"));
+    }
+
+    static void disambiguateMethodNamesFor(final Clazz clazz) {
+        clazz.disambiguateMethods();
+        for (final Clazz subClazz : clazz.subClassers) {
+            disambiguateMethodNamesFor(subClazz);
+        }
+    }
+
+    public static void disambiguateFunctionsIn(final List<Framework> frameworks) {
+        for (final Framework framework : frameworks) {
+            disambiguateFunctionsInFramework(framework);
+        }
+    }
+
+    static void disambiguateFunctionsInFramework(final Framework framework) {
+        for (final Function fxn : framework.functions)
+            fxn.disambiguateArgs();
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/RestrictedKeywords.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/RestrictedKeywords.java
new file mode 100644
index 0000000..6c04411
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/RestrictedKeywords.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class RestrictedKeywords {
+    static final String[] JAVA_KEYWORD_CONFLICTS = {
+        "wait", "null", "class", "new", "toString", "finalize", "boolean", "interface", "final", "static"
+    };
+
+    static final Set<String> originalRestrictedSet = new HashSet<String>(Arrays.asList(JAVA_KEYWORD_CONFLICTS));
+
+    public static Set<String> getNewRestrictedSet() {
+        return new HashSet<String>(originalRestrictedSet);
+    }
+
+    public static boolean isRestricted(String s){
+        return originalRestrictedSet.contains(s);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/Utils.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/Utils.java
new file mode 100644
index 0000000..952dca1
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/Utils.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Pattern;
+
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.model.Framework.FrameworkDependency;
+import com.apple.internal.jobjc.generator.utils.Fp;
+
+public class Utils {
+    public static boolean isLeopard = System.getProperty("os.version").startsWith("10.5");
+    public static boolean isSnowLeopard = System.getProperty("os.version").startsWith("10.6");
+
+    @SuppressWarnings("unchecked")
+    public static <T> List<T> list(final Object...args) {
+        final ArrayList<Object> list = new ArrayList<Object>(args.length);
+        for (final Object arg : args) list.add(arg);
+        return (List<T>)list;
+    }
+
+    /**
+     * A small implementation of UNIX find.
+     * @param matchRegex Only collect paths that match this regex.
+     * @param pruneRegex Don't recurse down a path that matches this regex. May be null.
+     * @throws IOException if File.getCanonicalPath() fails.
+     */
+    public static List<File> find(final File startpath, final String matchRegex, final String pruneRegex) throws IOException{
+        final Pattern matchPattern = Pattern.compile(matchRegex, Pattern.CASE_INSENSITIVE);
+        final Pattern prunePattern = pruneRegex == null ? null : Pattern.compile(pruneRegex, Pattern.CASE_INSENSITIVE);
+        final Set<String> visited = new HashSet<String>();
+        final List<File> found = new ArrayList<File>();
+        class Search{
+            void search(final File path) throws IOException{
+                if(prunePattern != null && prunePattern.matcher(path.getAbsolutePath()).matches()) return;
+                String cpath = path.getCanonicalPath();
+                if(!visited.add(cpath))  return;
+                if(matchPattern.matcher(path.getAbsolutePath()).matches())
+                    found.add(path);
+                if(path.isDirectory())
+                    for(File sub : path.listFiles())
+                        search(sub);
+            }
+        }
+        new Search().search(startpath);
+        return found;
+    }
+
+    public static String joinWComma(final List<?> list) { return Fp.join(", ", list); }
+    public static String joinWComma(final Object[] list) { return Fp.join(", ", Arrays.asList(list)); }
+
+    public static class Substituter {
+        String str;
+
+        public Substituter(final String str) {
+            this.str = str.replaceAll("\\#", "\t").replaceAll("\\~", "\n");
+        }
+
+        public void replace(final String key, final String value) {
+            str = str.replaceAll("\\$" + key, value);
+        }
+
+        /**
+         * Apply String.format first, and then pass through Substituter.
+         */
+        public static String format(String format, Object... args){
+            return new Substituter(String.format(format, args)).toString();
+        }
+
+        @Override public String toString() {
+            return str;
+        }
+    }
+
+    static Map<String, String> getArgs(final String...args) {
+        final Map<String, String> argMap = new HashMap<String, String>();
+        for (final String arg : args) {
+            final String[] splitArg = arg.split("\\=");
+            if (splitArg.length != 2) continue;
+            argMap.put(splitArg[0], splitArg[1]);
+        }
+        return argMap;
+    }
+
+    static void recDelete(final File file) {
+        if (!file.exists()) return;
+        if (file.isDirectory()) for (final File f : file.listFiles()) recDelete(f);
+        file.delete();
+    }
+
+    public static String capitalize(String s){
+        if(s.length() == 0) return s;
+        return Character.toString(Character.toUpperCase(s.charAt(0))) + s.substring(1);
+    }
+
+    /**
+     * Sort frameworks by dependencies. If A is a dependency of B,
+     * then A will come before B in the list.
+     */
+    public static void topologicalSort(final List<Framework> frameworks) {
+        final Set<Framework> visited = new TreeSet<Framework>();
+        final List<Framework> sorted = new ArrayList<Framework>(frameworks.size());
+        class Rec{
+            void visit(final Framework fw){
+                if(!visited.add(fw)) return;
+                for(FrameworkDependency dep : fw.dependencies)
+                    if(dep.object != null)
+                        visit(dep.object);
+                sorted.add(fw);
+            }
+        }
+        for(Framework fw : frameworks) new Rec().visit(fw);
+        frameworks.clear();
+        frameworks.addAll(sorted);
+    }
+
+    /**
+     * If there is a cycle it is returned. Otherwise null is returned.
+     */
+    public static List<Framework> getDependencyCycle(List<Framework> frameworks) {
+        @SuppressWarnings("serial")
+        class FoundCycle extends Throwable{
+            public final List<Framework> cycle;
+            public FoundCycle(List<Framework> cycle){
+                this.cycle = cycle;
+            }
+        };
+        class Rec{
+            void visit(final Framework fw, List<Framework> visited) throws FoundCycle{
+                visited = new LinkedList<Framework>(visited);
+                if(visited.contains(fw)){
+                    visited.add(fw);
+                    throw new FoundCycle(visited);
+                }
+                visited.add(fw);
+                for(FrameworkDependency dep : fw.dependencies)
+                    if(dep.object != null)
+                        visit(dep.object, visited);
+            }
+        }
+        try{ for(Framework fw : frameworks){ new Rec().visit(fw, new LinkedList<Framework>()); }}
+        catch(FoundCycle x){ return x.cycle; }
+        return null;
+    }
+
+    public static String getCanonicalPath(File file) throws RuntimeException{
+        try {
+            return file.getCanonicalPath();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/AbstractObjCClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/AbstractObjCClassFile.java
new file mode 100644
index 0000000..e2fedf1
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/AbstractObjCClassFile.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import com.apple.internal.jobjc.generator.model.Clazz;
+
+public abstract class AbstractObjCClassFile extends GeneratedClassFile {
+    final Clazz clazz;
+
+    public AbstractObjCClassFile(final Clazz clazz, final String classname, final String genericArgs, final String superClass) {
+        super(clazz.getPackage(), classname, genericArgs, superClass);
+        this.clazz = clazz;
+    }
+
+    public AbstractObjCClassFile(final Clazz clazz, final String classname, final String superClass) {
+        super(clazz.getPackage(), classname, superClass);
+        this.clazz = clazz;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CFTypeClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CFTypeClassFile.java
new file mode 100644
index 0000000..03504ef
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CFTypeClassFile.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+
+import com.apple.internal.jobjc.generator.model.CFType;
+import com.apple.jobjc.Pointer;
+
+public class CFTypeClassFile extends GeneratedClassFile {
+    final CFType cftype;
+
+    public CFTypeClassFile(final CFType cftype) {
+        super(cftype.parent.pkg, cftype.type.getJType().getJavaClassName(), com.apple.jobjc.CFType.class.getCanonicalName());
+        this.cftype = cftype;
+    }
+
+    @Override public void writeBeginning(PrintStream out){
+        out.println("\tpublic " + className + "(" + Pointer.class.getName() + "<?> ptr){");
+        out.println("\t\tsuper(ptr);");
+        out.println("\t}");
+        out.println("");
+        out.println("\tpublic " + className + "(long ptr){");
+        out.println("\t\tsuper(ptr);");
+        out.println("\t}");
+    }
+
+    @Override public void writeBody(PrintStream out){
+        if(cftype.getTypeIdFunc != null){
+            out.println("\tpublic static long getTypeId(){");
+            out.println("\t\treturn " + RootJObjCClass.runtimeFrameworkInst(cftype.parent.name) + "." + cftype.getTypeIdFunc + "();");
+            out.println("\t}");
+        }
+        else
+            out.println("\t// getTypeIdFunc not found");
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CategoryClassClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CategoryClassClassFile.java
new file mode 100644
index 0000000..45e1a7c
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CategoryClassClassFile.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.apple.internal.jobjc.generator.FunctionGenerator;
+import com.apple.internal.jobjc.generator.model.Category;
+import com.apple.internal.jobjc.generator.model.Method;
+import com.apple.jobjc.JObjCRuntime;
+import com.apple.jobjc.Invoke.MsgSend;
+
+public class CategoryClassClassFile extends AbstractObjCClassFile {
+    final Category category;
+
+    public CategoryClassClassFile(final Category category) {
+        super(category.category, category.category.name + "Class",
+                category.category.superClass.getFullPath() + "Class");
+        this.category = category;
+    }
+
+    @Override public void writeBeginning(final PrintStream out) {
+        out.format(
+                "\t%1$s(%2$s runtime) {\n" +
+                "\t\tsuper(\"%3$s\", runtime);\n" +
+                "\t}\n",
+                className, JObjCRuntime.class.getCanonicalName(), category.category.superClass.name);
+    }
+
+    @Override public void writeBody(final PrintStream out) {
+        Set<String> written = new HashSet<String>();
+        for(final Method method : this.clazz.classMethods)
+            if(written.add(method.name))
+                FunctionGenerator.writeOutFunction(out, MsgSend.class, method, "this");
+            else
+                System.out.format("Duplicate method: %1$s %2$s -%3$s\n", clazz.parent.name, className, method.name);
+    }
+
+    @Override protected boolean isFinal(){ return true; }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CategoryClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CategoryClassFile.java
new file mode 100644
index 0000000..b28c95d
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CategoryClassFile.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+
+import com.apple.internal.jobjc.generator.model.Category;
+import com.apple.jobjc.JObjCRuntime;
+
+public class CategoryClassFile extends JObjCClassFile {
+    private final Category category;
+
+    public CategoryClassFile(final Category category) {
+        super(category.category);
+        this.category = category;
+    }
+
+    @Override public void writeBeginning(final PrintStream out) {
+        String targetCls = category.category.superClass.getFullPath();
+        out.format("\tpublic %1$s(final %2$s obj, final %3$s runtime) {\n" +
+                "\t\tsuper(obj, runtime);\n" +
+                "\t}\n",
+            className, targetCls, JObjCRuntime.class.getCanonicalName());
+        super.writeBeginning(out);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CopiedFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CopiedFile.java
new file mode 100644
index 0000000..3eb1d42
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/CopiedFile.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.*;
+
+public class CopiedFile extends OutputFile {
+    final File sourceFile;
+
+    public CopiedFile(final File sourceFile, final String pkg, final String filename) {
+        super(pkg, filename);
+        this.sourceFile = sourceFile;
+    }
+
+    @Override
+    public void write(final File parentDir) {
+        try {
+            final PrintStream out = open(parentDir);
+            final InputStream in = new FileInputStream(sourceFile);
+
+            copy(in, out);
+            close(out);
+        } catch (final IOException e) { throw new RuntimeException(e); }
+    }
+
+    private static void copy(final InputStream in, final PrintStream out) throws IOException {
+        int bit;
+        while (-1 != (bit = in.read())) {
+            out.write(bit);
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/FrameworkClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/FrameworkClassFile.java
new file mode 100644
index 0000000..20b27b6
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/FrameworkClassFile.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.apple.internal.jobjc.generator.FunctionGenerator;
+import com.apple.internal.jobjc.generator.Utils;
+import com.apple.internal.jobjc.generator.model.Category;
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Constant;
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.model.Function;
+import com.apple.internal.jobjc.generator.model.NativeEnum;
+import com.apple.internal.jobjc.generator.model.StringConstant;
+import com.apple.internal.jobjc.generator.model.Struct;
+import com.apple.internal.jobjc.generator.model.types.JType;
+import com.apple.internal.jobjc.generator.model.types.JType.JStruct;
+import com.apple.internal.jobjc.generator.utils.Fp;
+import com.apple.internal.jobjc.generator.utils.JavaLang;
+import com.apple.internal.jobjc.generator.utils.Fp.Map1;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLCall;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLField;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLMethod;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLReturn;
+import com.apple.jobjc.JObjCRuntime;
+import com.apple.jobjc.MacOSXFramework;
+import com.apple.jobjc.Invoke.FunCall;
+
+public class FrameworkClassFile extends GeneratedClassFile {
+    final Framework framework;
+
+    public FrameworkClassFile(final Framework framework) {
+        super(framework.pkg, framework.name + "Framework", MacOSXFramework.class.getName());
+        this.framework = framework;
+    }
+
+    @Override public void writeBeginning(final PrintStream out) {
+        List<String> binPaths = Fp.map(new Map1<File,String>(){
+            public String apply(File a) { return "\"" + a.getAbsolutePath() + "\""; }},
+            framework.binaries);
+        out.println(new Utils.Substituter(
+                "#public " + className + "(" + JObjCRuntime.class.getName() + " runtime) {~" +
+                "##super(runtime, new String[]{" + Fp.join(", ", binPaths) + "});~" +
+                "#}~"
+        ));
+    }
+
+    @Override public void writeBody(final PrintStream out) {
+        for(final Struct struct : new ArrayList<Struct>(framework.structs)){
+            out.println("\tpublic " + struct.name + " make" + struct.name + "(){");
+            out.println("\t\treturn new " + struct.name + "(getRuntime());");
+            out.println("\t}");
+            out.println("\tpublic " + struct.name + " make" + struct.name + "(com.apple.jobjc.NativeBuffer base){");
+            out.println("\t\treturn new " + struct.name + "(getRuntime(), base);");
+            out.println("\t}");
+        }
+
+        for(final NativeEnum nenum : framework.enums){
+            if(nenum.ignore){
+                out.println("\t/**");
+                out.println("\t * @deprecated Suggestion: " + nenum.suggestion);
+                out.println("\t */");
+                out.println("\t@Deprecated");
+            }
+            out.println(String.format("\tpublic final %3$s %1$s(){ return %2$s; }",
+                    nenum.name, nenum.valueToString(), nenum.type.getJType().getJavaReturnTypeName()));
+        }
+
+        for(final Constant konst : framework.constants){
+            String cacheName = "_" + konst.name;
+            final JType jtype = konst.type.getJType();
+            final String cast = jtype.getReturnTypeCast() == null ? "" : "(" + jtype.getReturnTypeCast() + ")";
+            out.println();
+
+            out.print(new JLField("private", jtype.getJavaTypeName(), cacheName, jtype.getDefaultReturnValue()));
+
+            JLMethod reader = new JLMethod("public final", jtype.getJavaReturnTypeName(), konst.name);
+            reader.body.add("if(" + cacheName + " != " + jtype.getDefaultReturnValue() + ") return " + cast + cacheName + ";");
+
+            String contextName = jtype instanceof JStruct ? "returnValue" : "nativeBuffer";
+
+            if(jtype instanceof JStruct)
+                reader.body.add(((JStruct)jtype).createReturnValue());
+            else
+                reader.body.add(jtype.createDeclareBuffer(contextName));
+
+            reader.body.add("getConstant(\"" + konst.name + "\", " + contextName + ", " + jtype.getCoderDescriptor().getCoderInstanceName() + ".sizeof());");
+
+            reader.body.add(jtype.createPop(contextName));
+            reader.body.add(cacheName + " = returnValue;");
+            reader.body.add(jtype.createReturn());
+
+            out.print(reader);
+        }
+
+        for(final StringConstant konst : framework.stringConstants){
+            if(Fp.any(new Map1<Constant,Boolean>(){ public Boolean apply(Constant a) {
+                return a.name.equals(konst.name);
+                }}, new ArrayList<Constant>(framework.constants))){
+                System.out.println("Warning: [" + framework.name + "] String constant " + konst.name + " is already defined in constants. Skipping.");
+            }
+            else{
+                out.println("\tpublic final String " + konst.name + "(){ return \"" + escapeQuotes(konst.value) + "\"; }");
+            }
+        }
+
+        for (final Clazz clazz : framework.classes) {
+            final String classClassName = clazz.name + "Class";
+            out.println(JavaLang.makeSingleton("_" + classClassName, clazz.name, classClassName, "getRuntime()"));
+        }
+
+        for (final Category cat : framework.categories) {
+            final String classClassName = cat.category.name + "Class";
+            out.println(JavaLang.makeSingleton("_" + classClassName, cat.category.name, classClassName, "getRuntime()"));
+
+            JLMethod jlm = new JLMethod("public", cat.category.name, cat.category.name, "final " + cat.category.superClass.getFullPath() + " obj");
+            jlm.body.add(new JLReturn(new JLCall("new " + cat.category.name, "obj", "getRuntime()")));
+            out.println(jlm);
+        }
+
+        for (final Function fxn : framework.functions){
+            FunctionGenerator.writeOutFunction(out, FunCall.class, fxn, null);
+        }
+    }
+
+    private String escapeQuotes(String s){
+        return s.replace("\"", "\\\"");
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/GeneratedClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/GeneratedClassFile.java
new file mode 100644
index 0000000..b1a147a
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/GeneratedClassFile.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+
+public class GeneratedClassFile extends OutputFile {
+    protected final String className;
+    protected final String genericArgs;
+    protected final String superClass;
+
+    public GeneratedClassFile(final String pkg, final String classname, final String superClass) {
+        this(pkg, classname, null, superClass);
+    }
+
+    public GeneratedClassFile(final String pkg, final String classname, final String genericArgs, final String superClass) {
+        super(pkg, classname + ".java");
+        this.className = classname;
+        this.genericArgs = genericArgs;
+        this.superClass = superClass;
+    }
+
+    @Override
+    public void write(final File parentDir) {
+        try {
+            final PrintStream out = open(parentDir);
+            out.println("package " + pkg + ";");
+            out.println();
+            out.print("public " + (isFinal() ? "final" : "") + " class " + className);
+            if(genericArgs != null) out.print("<" + genericArgs + ">");
+            if (superClass != null) out.print(" extends " + superClass);
+            out.println(" {");
+            writeBeginning(out);
+            writeBody(out);
+            writeEnd(out);
+            out.println("}");
+            close(out);
+        } catch (final IOException e) { throw new RuntimeException(e); }
+    }
+
+    public void writeBeginning(final PrintStream out) {
+
+    }
+
+    public void writeBody(final PrintStream out) {
+
+    }
+
+    public void writeEnd(final PrintStream out) {
+
+    }
+
+    protected boolean isFinal(){ return false; }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/JObjCClassClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/JObjCClassClassFile.java
new file mode 100644
index 0000000..0be389b
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/JObjCClassClassFile.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.apple.internal.jobjc.generator.ClassGenerator;
+import com.apple.internal.jobjc.generator.FunctionGenerator;
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Method;
+import com.apple.jobjc.JObjCRuntime;
+import com.apple.jobjc.Invoke.MsgSend;
+
+public class JObjCClassClassFile extends AbstractObjCClassFile {
+    public JObjCClassClassFile(final Clazz clazz) {
+        super(clazz, clazz.name + "Class", clazz.superClass != null ? clazz.superClass.getFullPath() + "Class" : ClassGenerator.JOBJC_PACKAGE + ".NSClass<" + clazz.name + ">");
+    }
+
+    @Override public void writeBeginning(final PrintStream out) {
+        out.format(
+                "\tpublic %1$s(%2$s runtime) {\n" +
+                "\t\tsuper(runtime);\n" +
+                "\t}\n",
+                className, JObjCRuntime.class.getCanonicalName());
+        out.format(
+                "\tpublic %1$s(String name, %2$s runtime) {\n" +
+                "\t\tsuper(name, runtime);\n" +
+                "\t}\n",
+                className, JObjCRuntime.class.getCanonicalName());
+        out.format(
+                "\tpublic %1$s(long ptr, %2$s runtime) {\n" +
+                "\t\tsuper(ptr, runtime);\n" +
+                "\t}\n",
+                className, JObjCRuntime.class.getCanonicalName());
+    }
+
+    @Override public void writeBody(final PrintStream out) {
+        Set<String> written = new HashSet<String>();
+        for(final Method method : this.clazz.classMethods)
+            if(written.add(method.name))
+                FunctionGenerator.writeOutFunction(out, MsgSend.class, method, "this");
+            else
+                System.out.format("Duplicate method: %1$s %2$s -%3$s\n", clazz.parent.name, className, method.name);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/JObjCClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/JObjCClassFile.java
new file mode 100644
index 0000000..bf43f3c
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/JObjCClassFile.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import com.apple.internal.jobjc.generator.FunctionGenerator;
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Method;
+import com.apple.jobjc.JObjCRuntime;
+import com.apple.jobjc.NativeObjectLifecycleManager;
+import com.apple.jobjc.Invoke.MsgSend;
+
+public class JObjCClassFile extends AbstractObjCClassFile {
+    public JObjCClassFile(final Clazz clazz) {
+        super(clazz, clazz.name,
+                clazz.superClass == null ? "com.apple.jobjc.ID"
+                        : clazz.superClass.getFullPath());
+    }
+
+    private static Map<String, NativeObjectLifecycleManager> nolmForClass =
+        new TreeMap<String, NativeObjectLifecycleManager>();
+    static{
+        nolmForClass.put("NSAutoreleasePool", NativeObjectLifecycleManager.Nothing.INST);
+    }
+
+    @Override public void writeBeginning(final PrintStream out) {
+        out.format("\tpublic %1$s(final long objPtr, final %2$s runtime) {\n" +
+                "\t\tsuper(objPtr, runtime);\n" +
+                "\t}\n",
+            className, JObjCRuntime.class.getCanonicalName());
+
+        out.format("\tpublic %1$s(final %1$s obj, final %2$s runtime) {\n" +
+                "\t\tsuper(obj, runtime);\n" +
+                "\t}\n",
+            className, JObjCRuntime.class.getCanonicalName());
+
+        NativeObjectLifecycleManager nolm = nolmForClass.get(clazz.name);
+        if(nolm != null)
+            out.format("\t@Override\n"+
+                    "\tprotected %1$s getNativeObjectLifecycleManager() {\n" +
+                    "\t\treturn %2$s.INST;\n" +
+                    "\t}\n",
+                    NativeObjectLifecycleManager.class.getCanonicalName(), nolm.getClass().getCanonicalName());
+    }
+
+    @Override public void writeBody(final PrintStream out) {
+        Set<String> written = new HashSet<String>();
+        for(final Method method : this.clazz.instanceMethods)
+            if(written.add(method.name))
+                FunctionGenerator.writeOutFunction(out, MsgSend.class, method, "this");
+            else
+                System.out.format("Duplicate method: %1$s %2$s -%3$s\n", clazz.parent.name, className, method.name);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/MixedPrimitiveCoderClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/MixedPrimitiveCoderClassFile.java
new file mode 100644
index 0000000..a6ff16a
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/MixedPrimitiveCoderClassFile.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+import java.util.Collection;
+
+import com.apple.internal.jobjc.generator.ClassGenerator;
+import com.apple.internal.jobjc.generator.model.coders.ComplexCoderDescriptor.MixedEncodingDescriptor;
+import com.apple.jobjc.PrimitiveCoder;
+
+public class MixedPrimitiveCoderClassFile extends GeneratedClassFile {
+    private static final String MULTI_CODER_CLASSNAME = "MixedPrimitiveCoder";
+    public static final String FULL_MULTI_CODER_CLASSNAME = ClassGenerator.JOBJC_PACKAGE + "." + MULTI_CODER_CLASSNAME;
+
+    final Collection<MixedEncodingDescriptor> coderDescs;
+
+    public MixedPrimitiveCoderClassFile(final Collection<MixedEncodingDescriptor> coderDescs) {
+        super(ClassGenerator.JOBJC_PACKAGE, MULTI_CODER_CLASSNAME, "java.lang.Object");
+        this.coderDescs = coderDescs;
+    }
+
+    @Override
+    public void writeBody(final PrintStream out) {
+        for (final MixedEncodingDescriptor desc : coderDescs) {
+            out.println("\tpublic static final " + PrimitiveCoder.class.getCanonicalName() + " " + desc.getMixedName() + " = " + desc.getDefinition() + ";");
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/OpaqueClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/OpaqueClassFile.java
new file mode 100644
index 0000000..617c74bd
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/OpaqueClassFile.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+
+import com.apple.internal.jobjc.generator.model.Opaque;
+import com.apple.jobjc.Pointer;
+
+public class OpaqueClassFile extends GeneratedClassFile {
+    final Opaque opaque;
+
+    public OpaqueClassFile(final Opaque opaque) {
+        super(opaque.parent.pkg, opaque.type.getJType().getJavaClassName(), com.apple.jobjc.Opaque.class.getCanonicalName());
+        this.opaque = opaque;
+    }
+
+    @Override public void writeBeginning(PrintStream out){
+        out.println("\t// " + opaque.type);
+        out.println("\t// " + opaque.type.getJType());
+        out.println("");
+        out.println("\tpublic " + className + "(" + Pointer.class.getName() + "<?> ptr){");
+        out.println("\t\tsuper(ptr);");
+        out.println("\t}");
+        out.println("");
+        out.println("\tpublic " + className + "(long ptr){");
+        out.println("\t\tsuper(ptr);");
+        out.println("\t}");
+    }
+
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/OutputFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/OutputFile.java
new file mode 100644
index 0000000..10635b7
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/OutputFile.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.*;
+
+public abstract class OutputFile {
+    final String pkg;
+    final String fileName;
+
+    public OutputFile(final String pkg, final String filename) {
+        this.pkg = pkg;
+        this.fileName = filename;
+    }
+
+    public PrintStream open(final File parentDir) throws IOException {
+        final File pkgDir = new File(parentDir, pkg.replace('.', '/'));
+        pkgDir.mkdirs();
+        final File classFile = new File(pkgDir, fileName);
+        classFile.createNewFile();
+        return new PrintStream(classFile);
+    }
+
+    public void close(final PrintStream out) {
+        out.close();
+    }
+
+    public abstract void write(final File parentDir);
+
+    public boolean isClass(final Class<?> clazz) {
+        final String pkgName = clazz.getPackage().getName();
+        if (!pkgName.equals(pkg)) return false;
+
+        return fileName.contains(clazz.getSimpleName());
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/RootJObjCClass.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/RootJObjCClass.java
new file mode 100644
index 0000000..45eb40f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/RootJObjCClass.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+import java.util.List;
+
+import com.apple.internal.jobjc.generator.ClassGenerator;
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.utils.JavaLang;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLCtor;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLField;
+import com.apple.internal.jobjc.generator.utils.JavaLang.JLMethod;
+import com.apple.jobjc.JObjCRuntime;
+
+public class RootJObjCClass extends GeneratedClassFile {
+    private static final String JOBJC_CLASSNAME = "JObjC";
+    public static final String FULL_JOBJC_CLASSNAME = ClassGenerator.JOBJC_PACKAGE + "." + JOBJC_CLASSNAME;
+    public static final String JOBJC_RUNTIME_INST = FULL_JOBJC_CLASSNAME + ".getInstance()";
+    public static final String JOBJC_RUNTIME_INST_R = FULL_JOBJC_CLASSNAME + ".getInstance(getRuntime())";
+
+    public static final String runtimeFrameworkInst(String fwname){
+        return JOBJC_RUNTIME_INST + "." + fwname + "()";
+    }
+
+    public static final String runtimeFrameworkInstR(String fwname){
+        return JOBJC_RUNTIME_INST_R + "." + fwname + "()";
+    }
+
+    final List<Framework> frameworks;
+
+    public RootJObjCClass(final List<Framework> frameworks) {
+        super(ClassGenerator.JOBJC_PACKAGE, JOBJC_CLASSNAME, "java.lang.Object");
+        this.frameworks = frameworks;
+    }
+
+    @Override public void writeBeginning(final PrintStream out) {
+        out.print(new JLField("private static", JOBJC_CLASSNAME, "instance"));
+        out.print(new JLField("private final", JObjCRuntime.class.getName(), "runtime"));
+
+        JLMethod getInstR = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance", "final JObjCRuntime runtime");
+        getInstR.body.add("if(runtime == null) throw new NullPointerException(\"runtime\");");
+        getInstR.body.add("if(instance == null) instance = new JObjC(runtime);");
+        getInstR.body.add("return instance;");
+        out.print(getInstR);
+
+        JLMethod getInst = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance");
+        getInst.body.add("return getInstance(JObjCRuntime.getInstance());");
+        out.print(getInst);
+
+        JLCtor ctor = new JLCtor("private", JOBJC_CLASSNAME, "final JObjCRuntime runtime");
+        ctor.body.add("this.runtime = runtime;");
+        for (final Framework f : frameworks)
+            ctor.body.add("runtime.registerPackage(\"" + f.pkg + "\");");
+        out.print(ctor);
+    }
+
+    @Override public void writeBody(final PrintStream out) {
+        for (final Framework f : frameworks)
+            out.println(JavaLang.makeSingleton("_" + f.name, f.name, f.pkg + "." + f.name + "Framework", "runtime"));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/StructClassFile.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/StructClassFile.java
new file mode 100644
index 0000000..95fb75b
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/classes/StructClassFile.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.classes;
+
+import java.io.PrintStream;
+
+import com.apple.internal.jobjc.generator.model.Struct;
+import com.apple.internal.jobjc.generator.model.Struct.Field;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor;
+import com.apple.internal.jobjc.generator.model.types.JType;
+import com.apple.internal.jobjc.generator.model.types.JType.JStruct;
+import com.apple.internal.jobjc.generator.model.types.NType.NBitfield;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.utils.Fp;
+import com.apple.internal.jobjc.generator.utils.Fp.Map1;
+import com.apple.jobjc.JObjCRuntime;
+import com.apple.jobjc.Coder.StructCoder;
+
+public class StructClassFile extends GeneratedClassFile {
+    final Struct struct;
+
+    public StructClassFile(final Struct struct) {
+        super(struct.parent.pkg, struct.name, com.apple.jobjc.Struct.class.getName());
+        this.struct = struct;
+    }
+
+    @Override public boolean isFinal(){ return true; }
+
+    @Override public void writeBeginning(final PrintStream out) {
+        out.println();
+        out.println("\tpublic static int SIZEOF = " + JObjCRuntime.class.getName() + ".IS64 ? "
+                + ((NStruct) struct.type.type64).sizeof64() + " : " + ((NStruct) struct.type.type32).sizeof32() + ";");
+        out.println();
+        out.format("\tpublic final static %1$s getStructCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
+        out.format("\t@Override public final %1$s getCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
+        out.format("\tprivate final static %1$s coder = new %1$s(SIZEOF%2$s%3$s){\n", StructCoder.class.getCanonicalName(),
+                (struct.fields.size() > 0 ? ",\n\t\t" : ""),
+                Fp.join(",\n\t\t", Fp.map(new Map1<Field,String>(){
+                    public String apply(Field a) {
+                        return a.type.getJType().getCoderDescriptor().getCoderInstanceName();
+                    }}, struct.fields)));
+        out.format("\t\t@Override protected %1$s newInstance(%2$s runtime){ return new %1$s(runtime); }\n",
+                struct.name,
+                JObjCRuntime.class.getCanonicalName());
+        out.println("\t};");
+        out.println();
+        out.println("\t" + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime){");
+        out.println("\t\tsuper(runtime, SIZEOF);");
+        out.println("\t}");
+        out.println();
+        out.println("\tpublic " + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime, final com.apple.jobjc.NativeBuffer buffer) {");
+        out.println("\t\tsuper(runtime, buffer, SIZEOF);");
+        out.println("\t}");
+    }
+
+    @Override public void writeBody(final PrintStream out) {
+        for(Struct.Field field : struct.fields){
+            if(field.type.type64 instanceof NStruct && field.type.type32 instanceof NStruct)
+                writeStructField(field, out);
+            else
+                writeField(field, out);
+        }
+    }
+
+    private void writeField(final Struct.Field field, final PrintStream out){
+        if(field.type.type32 instanceof NBitfield){
+            out.format("\t// Skipping bitfield '%1$s'\n", field.name);
+            return;
+        }
+        String privName = field.name + "__";
+        String offsetName = field.name.toUpperCase() + "_OFFSET";
+        JType jtype = field.type.getJType();
+        String retType = jtype.getJavaReturnTypeName();
+        CoderDescriptor cdesc = jtype.getCoderDescriptor();
+        out.println();
+        out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName()
+                + ".IS64 ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");
+
+        out.println("\t//" + cdesc.getClass().toString());
+        out.println("\tpublic " + retType + " " + getterName(field) + "(){");
+        out.println(jtype.createPopAddr("getRuntime()", "this.raw.bufferPtr + " + offsetName));
+        out.println(jtype.createReturn());
+        out.println("\t}");
+        out.println();
+        out.println("\tpublic void " + setterName(field.name) + "(final " + retType + " " + privName + "){");
+        out.println("\t\t" + cdesc.getPushAddrStatementFor("getRuntime()", "this.raw.bufferPtr + " + offsetName, privName));
+        out.println("\t}");
+    }
+
+    private void writeStructField(final Struct.Field field, final PrintStream out){
+        if(field.type.getJType() == null || !(field.type.getJType() instanceof JStruct)){
+            out.println("\t// Found bad JavaType (" + field.type.getJType() + ") for field (" + field.name + ") of type (" + field.type + ")");
+            return;
+        }
+        String privName = field.name + "__";
+        String offsetName = field.name.toUpperCase() + "_OFFSET";
+        JStruct jstype = (JStruct) field.type.getJType();
+        String retTypeName = jstype.getJavaReturnTypeName();
+        out.println();
+        out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName() + ".IS64"
+                + " ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");
+
+        out.println("\tprivate " + retTypeName + " " + privName + " = null;");
+        out.println("\tpublic " + retTypeName + " " + getterName(field) + "(){");
+        out.println("\t\tif(null==" + privName + "){");
+        out.println("\t\t\tthis.raw.position(" + offsetName + ");");
+        out.println("\t\t\t" + privName + " = " + RootJObjCClass.runtimeFrameworkInstR(struct.parent.name) + ".make" + jstype.struct.name + "(this.raw.slice());");
+        out.println("\t\t}");
+        out.println("\t\treturn " + privName + ";");
+        out.println("\t}");
+    }
+
+    private String getterName(Struct.Field field) {
+        if(com.apple.internal.jobjc.generator.RestrictedKeywords.isRestricted(field.name))
+            return field.name + field.type.getJType().getAppendableDescription();
+        return field.name;
+    }
+
+    private String setterName(String name) {
+        return "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
+    }
+
+    @Override public void writeEnd(final PrintStream out) {
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Arg.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Arg.java
new file mode 100644
index 0000000..60cdb1d
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Arg.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import org.w3c.dom.Node;
+
+public class Arg extends ElementWType<Function>{
+    public String javaName;
+
+    public Arg(final Node node, final Function parent) {
+        super(node, parent);
+        javaName = name;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/CFType.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/CFType.java
new file mode 100644
index 0000000..cc0598e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/CFType.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.List;
+
+import org.w3c.dom.Node;
+
+import com.apple.internal.jobjc.generator.classes.CFTypeClassFile;
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+
+public class CFType extends TypeElement<Framework> implements OutputFileGenerator {
+    public final String getTypeIdFunc;
+    public final String tollfree;
+
+    public CFType(final Node node, final Framework parent) {
+        super(node, getAttr(node, "name"), parent);
+        getTypeIdFunc = getAttr(node, "gettypeid_func");
+        tollfree = getAttr(node, "tollfree");
+    }
+
+    public void generateClasses(final List<OutputFile> generatedClassFiles) {
+        generatedClassFiles.add(new CFTypeClassFile(this));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Category.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Category.java
new file mode 100644
index 0000000..76fcdb6
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Category.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.List;
+
+import com.apple.internal.jobjc.generator.classes.CategoryClassClassFile;
+import com.apple.internal.jobjc.generator.classes.CategoryClassFile;
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+
+public class Category implements OutputFileGenerator{
+    public final Clazz category;
+
+    public Category(Clazz fromClass, Clazz target) {
+        this.category = new Clazz(fromClass.name + "Category", fromClass.classMethods, fromClass.instanceMethods, target, fromClass.parent);
+    }
+
+    public void generateClasses(List<OutputFile> generatedClassFiles) {
+        generatedClassFiles.add(new CategoryClassFile(this));
+        generatedClassFiles.add(new CategoryClassClassFile(this));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Clazz.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Clazz.java
new file mode 100644
index 0000000..9dfb822
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Clazz.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import com.apple.internal.jobjc.generator.RestrictedKeywords;
+import com.apple.internal.jobjc.generator.classes.JObjCClassClassFile;
+import com.apple.internal.jobjc.generator.classes.JObjCClassFile;
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+import com.apple.jobjc.MacOSXFramework;
+import com.apple.jobjc.SuperClassExtractor;
+import com.apple.jobjc.UnsafeRuntimeAccess;
+import com.apple.jobjc.NSClass.NSClassNotFoundException;
+import com.apple.jobjc.SEL;
+
+public class Clazz extends Element<Framework> implements OutputFileGenerator {
+    private final Map<String, Method> instanceMethodsByName = new HashMap<String, Method>();
+    private final Map<String, Method> classMethodsByName = new HashMap<String, Method>();
+
+    public final List<Method> classMethods;
+    public final List<Method> instanceMethods;
+
+    public final List<Clazz> subClassers = new ArrayList<Clazz>(0);
+    public Clazz superClass;
+
+    public Clazz(String name, List<Method> classMethods, List<Method> instanceMethods, Clazz superClass, Framework parent){
+        super(name, parent);
+        this.classMethods = classMethods;
+        this.instanceMethods = instanceMethods;
+        this.superClass = superClass;
+    }
+
+    public Clazz(final Node classNode, final Framework parent) {
+        super(classNode, parent);
+        this.classMethods = new ArrayList<Method>();
+        this.instanceMethods = new ArrayList<Method>();
+
+        final NodeList methodNodes = classNode.getChildNodes();
+        for (int i = 0; i < methodNodes.getLength(); i++) {
+            final Node node = methodNodes.item(i);
+            if (!"method".equals(node.getLocalName())) continue;
+
+            final String selName = Element.getAttr(node, "selector");
+            if(selName == null || !SEL.validName(selName)){
+                System.err.format("Warning: Discarding method %1$s:%2$s:%3$s"
+                        + " -- Invalid selector name. Verify.\n",
+                        parent.name, name, selName);
+                continue;
+            }
+
+            final Method method = new Method(node, parent);
+            if (method.isClassMethod) {
+                classMethods.add(method);
+            } else {
+                instanceMethods.add(method);
+            }
+        }
+    }
+
+    public String getPackage() {
+        return parent.pkg;
+    }
+
+    public String getFullPath(){
+        return parent.pkg + "." + name;
+    }
+
+    @Override
+    public String toString() {
+        return super.toString() + " " + classMethods + " " + instanceMethods;
+    }
+
+    public boolean doesActuallyExist(){
+        try{
+            UnsafeRuntimeAccess.getNSClass(parent.load(), name);
+        }catch(NSClassNotFoundException x){
+            return false;
+        }
+        return true;
+    }
+
+    void resolveSuperClass(final MacOSXFramework nativeFramework, final Map<String, Clazz> allClasses) throws Throwable {
+        superClass = SuperClassExtractor.getSuperClassFor(name, nativeFramework, allClasses);
+    }
+
+    public void disambiguateMethods() {
+        disambiguateMethods(instanceMethods, instanceMethodsByName);
+        disambiguateMethods(classMethods, classMethodsByName);
+    }
+
+    private void disambiguateMethods(final List<Method> methods, final Map<String, Method> methodMap) {
+        final Set<String> existingMethodNames = RestrictedKeywords.getNewRestrictedSet();
+        for (final Method method : methods) {
+            method.disambiguateNameAndArgs(this, existingMethodNames);
+            methodMap.put(method.javaName, method);
+        }
+    }
+
+    public void generateClasses(final List<OutputFile> generatedClassFiles) {
+        generatedClassFiles.add(new JObjCClassClassFile(this));
+        generatedClassFiles.add(new JObjCClassFile(this));
+    }
+
+    Method getParentMethodMatchingName(final String methodName) {
+        if(superClass == null) return null;
+        Method m = superClass.getMethodNamed(methodName);
+        if(m != null) return m;
+        return superClass.getParentMethodMatchingName(methodName);
+    }
+
+    private Method getMethodNamed(final String methodName) {
+        final Method instanceMethod = instanceMethodsByName.get(methodName);
+        if (instanceMethod != null) return instanceMethod;
+
+        final Method classMethod = classMethodsByName.get(methodName);
+        if (classMethod != null) return classMethod;
+
+        return null;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Constant.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Constant.java
new file mode 100644
index 0000000..411b4bf
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Constant.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import org.w3c.dom.Node;
+
+public class Constant extends ElementWType<Framework> {
+    public Constant(final Node node, final Framework parent) {
+        super(node, parent);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Element.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Element.java
new file mode 100644
index 0000000..ad85bf8
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Element.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import com.apple.internal.jobjc.generator.model.types.Type;
+import com.apple.internal.jobjc.generator.utils.ObjectInspector;
+
+/**
+ * Subclasses must implement ctor(Node, P)
+ */
+public class Element <P extends Element<?>> implements Comparable<Element<?>>{
+    public final String name;
+    public final P parent;
+
+    public Element(final String name, final P parent) {
+        this.name = Type.cleanName(name);
+        this.parent = parent;
+    }
+
+    public Element(final Node node, final P parent) {
+        this(getAttr(node, "name"), parent);
+    }
+
+    public static String getAttr(final Node node, final String key) {
+        final NamedNodeMap attrs = node.getAttributes();
+        if (attrs == null) return null;
+        final Node name = attrs.getNamedItem(key);
+        if (name == null) return null;
+        return name.getNodeValue();
+    }
+
+    static <P extends Element<?>, T extends Element<P>> List<T> getNodesFor(final Node parentNode, final String selection, final Class<T> clazz, final P parent) {
+        Constructor<T> ctor;
+        try {
+            ctor = clazz.getConstructor(new Class[] { Node.class, parent.getClass() });
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        final NodeList childNodes = parentNode.getChildNodes();
+        final List<T> nodes = new ArrayList<T>();
+        for (int i = 0; i < childNodes.getLength(); i++) {
+            final Node node = childNodes.item(i);
+            if (!selection.equals(node.getLocalName())) continue;
+
+            T obj;
+            try {
+                obj = ctor.newInstance(new Object[] { node, parent });
+            } catch (InvocationTargetException e) {
+                throw new RuntimeException(e.getCause());
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            nodes.add(obj);
+        }
+
+        return nodes;
+    }
+
+    @Override public String toString() {
+        return name;
+    }
+
+    public String reflectOnMySelf() {
+        return ObjectInspector.inspect(this);
+    }
+
+    public int compareTo(Element<?> o) {
+        return name.compareTo(o.name);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/ElementWType.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/ElementWType.java
new file mode 100644
index 0000000..2794aba
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/ElementWType.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import com.apple.internal.jobjc.generator.model.types.NType;
+import org.w3c.dom.Node;
+
+import com.apple.internal.jobjc.generator.model.types.Type;
+import com.apple.internal.jobjc.generator.utils.NTypeParser;
+
+/**
+ * An ElementWType has a type but does not necessarily represent a type. Examples are constants, enums, arguments, return values.
+ */
+public class ElementWType<P extends Element<?>> extends Element<P> {
+    public final Type type;
+
+    public ElementWType(final String name, final Type t, final P parent) {
+        super(name, parent);
+        this.type = t;
+    }
+
+    public ElementWType(final Node node, final Type t, final P parent) {
+        super(node, parent);
+        this.type = t;
+    }
+
+    public ElementWType(final Node node, final String declType, final P parent) {
+        super(node, parent);
+        final String type32 = getAttr(node, "type");
+        final String type64 = getAttr(node, "type64");
+        this.type = Type.getType(declType,
+                        type32 == null ? NType.NUnknown.inst() : NTypeParser.parseFrom(type32),
+                        type64 == null ? null : NTypeParser.parseFrom(type64));
+    }
+
+    public ElementWType(final Node node, final P parent){
+        this(node, getAttr(node, "declared_type"), parent);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Framework.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Framework.java
new file mode 100644
index 0000000..0f7999d
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Framework.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import com.apple.internal.jobjc.generator.ClassGenerator;
+import com.apple.internal.jobjc.generator.Utils;
+import com.apple.internal.jobjc.generator.classes.FrameworkClassFile;
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+import com.apple.internal.jobjc.generator.utils.Fp;
+import com.apple.internal.jobjc.generator.utils.Fp.Map1;
+import com.apple.jobjc.MacOSXFramework;
+import com.apple.jobjc.UnsafeRuntimeAccess;
+
+public class Framework extends Element<Element<?>> implements OutputFileGenerator {
+    public final String path;
+    public final String pkg;
+    public final List<File> binaries;
+    public MacOSXFramework nativeFramework;
+
+    public MacOSXFramework load(){
+        if(nativeFramework == null){
+            String[] bins = new String[binaries.size()];
+            for(int i = 0; i < binaries.size(); ++i)
+                bins[i] = Utils.getCanonicalPath(binaries.get(i));
+            nativeFramework = UnsafeRuntimeAccess.getFramework(bins);
+        }
+        return nativeFramework;
+    }
+
+    public File getMainFrameworkBinary(){ return binaries.get(0); }
+
+    final Node rootNode;
+
+    public Set<Clazz> classes;
+    public List<Struct> structs;
+    public List<CFType> cfTypes;
+    public List<Opaque> opaques;
+    public List<Constant> constants;
+    public List<StringConstant> stringConstants;
+    public List<NativeEnum> enums;
+    public List<Function> functions;
+    public List<FunctionAlias> functionAliases;
+    public List<InformalProtocol> informalProtocols;
+    public List<Protocol> protocols;
+    public List<Category> categories;
+    public List<FrameworkDependency> dependencies;
+
+    public static class FrameworkDependency extends Element<Framework>{
+        final String path;
+        public Framework object = null;
+
+        public FrameworkDependency(final Node node, final Framework parent) {
+            super(getAttr(node, "path").replaceFirst("^.*/([^/]+)\\.framework$", "$1"), parent);
+            this.path = getAttr(node, "path");
+        }
+    }
+
+    public static final XPath XPATH = XPathFactory.newInstance().newXPath();
+    public Framework(final String name, final File bsFile) {
+        super(name, null);
+        try {
+            final File pathf = bsFile.getCanonicalFile().getParentFile().getParentFile().getParentFile();
+            path = pathf.getParentFile().getParentFile().getCanonicalPath();
+        } catch (IOException x) {
+            throw new RuntimeException(x);
+        }
+        binaries = findBinaries(path, name);
+
+        pkg = ClassGenerator.JOBJC_PACKAGE + "." + name.toLowerCase();
+        try {
+            rootNode = (Node)XPATH.evaluate("signatures", new InputSource(bsFile.getAbsolutePath()), XPathConstants.NODE);
+        } catch (final XPathExpressionException e) { throw new RuntimeException(e); }
+        protocols = new ArrayList<Protocol>();
+        categories = new ArrayList<Category>();
+    }
+
+    private static List<File> findBinaries(final String rootPath, final String name){
+        List<File> bins = new ArrayList<File>(2);
+
+        File mainBin = new File(rootPath, name);
+        if(mainBin.exists()) bins.add(mainBin);
+
+        File bsBin = new File(rootPath, "Resources/BridgeSupport/" + name + ".dylib");
+        if(bsBin.exists()) bins.add(bsBin);
+
+        return bins;
+    }
+
+    public void parseDependencies(final Collection<Framework> frameworks) {
+        // Parse
+        dependencies = getNodesFor(rootNode, "depends_on", FrameworkDependency.class, this);
+        // Resolve
+        for(final FrameworkDependency dep : dependencies)
+            dep.object = Fp.find(new Map1<Framework,Boolean>(){
+                public Boolean apply(Framework f) {
+                    return f.path.equals(dep.path);
+                }}, frameworks);
+    }
+
+    public void parseStructs() {
+        structs = getNodesFor(rootNode, "struct", Struct.class, this);
+
+        // HACK BS bug #6100313
+        if(Utils.isSnowLeopard && name.equals("IOBluetooth"))
+            structs.remove(getStructByName("BluetoothHCIRequestNotificationInfo"));
+
+        // GLIFunctionDispatch is frequently out of sync in BS / system
+        if(name.equals("OpenGL"))
+            structs.remove(getStructByName("GLIFunctionDispatch"));
+    }
+
+    public void parseCFTypes() {
+        cfTypes = getNodesFor(rootNode, "cftype", CFType.class, this);
+    }
+
+    public void parseOpaques() {
+        opaques = getNodesFor(rootNode, "opaque", Opaque.class, this);
+    }
+
+    public void parseConstants() {
+        constants = getNodesFor(rootNode, "constant", Constant.class, this);
+        stringConstants = getNodesFor(rootNode, "string_constant", StringConstant.class, this);
+        enums = getNodesFor(rootNode, "enum", NativeEnum.class, this);
+    }
+
+    public void parseFunctions() {
+        functions = getNodesFor(rootNode, "function", Function.class, this);
+        functionAliases = getNodesFor(rootNode, "function_alias", FunctionAlias.class, this);
+    }
+
+    public void parseClasses() {
+        classes = new HashSet<Clazz>(getNodesFor(rootNode, "class", Clazz.class, this));
+        classes = Fp.filterSet(new Map1<Clazz,Boolean>(){
+            public Boolean apply(Clazz a) {
+                if(a.doesActuallyExist())
+                    return true;
+                else{
+                    System.out.println("Could not find class " + name + ":" + a.name + " in runtime. Discarding.");
+                    return false;
+                }
+            }}, classes);
+        informalProtocols = getNodesFor(rootNode, "informal_protocol", InformalProtocol.class, this);
+    }
+
+    public void resolveSuperClasses(final Map<String, Clazz> allClasses) throws Throwable {
+        load();
+        for (final Clazz clazz : classes)
+            clazz.resolveSuperClass(nativeFramework, allClasses);
+    }
+
+    public void generateClasses(final List<OutputFile> generatedClassFiles) {
+        generatedClassFiles.add(new FrameworkClassFile(this));
+
+        final List<List<OutputFileGenerator>> generatorLists =
+                  Utils.list(new ArrayList<Clazz>(classes), structs, cfTypes, opaques, categories);
+        for (final List<OutputFileGenerator> generators : generatorLists) {
+            for (final OutputFileGenerator generator : generators)
+                generator.generateClasses(generatedClassFiles);
+        }
+    }
+
+    @Override public String toString() { return reflectOnMySelf(); }
+
+    public Struct getStructByName(final String stname) {
+        return Fp.find(new Fp.Map1<Struct,Boolean>(){
+            public Boolean apply(Struct a) {
+                return stname.equals(a.name);
+            }}, structs);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Function.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Function.java
new file mode 100644
index 0000000..6126895
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Function.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.*;
+
+import org.w3c.dom.*;
+
+import com.apple.internal.jobjc.generator.RestrictedKeywords;
+
+public class Function extends Element<Framework> {
+    public final boolean variadic;
+    public final List<Arg> args;
+    public final ReturnValue returnValue;
+
+    public Function(final Node node, final Framework parent) {
+        this(node, getAttr(node, "name"), parent);
+    }
+
+    public Function(final Node node, final String name, final Framework parent) {
+        super(name, parent);
+
+        this.variadic = "true".equals(getAttr(node, "variadic"));
+        this.args = new ArrayList<Arg>();
+
+        ReturnValue returnValue = null;
+
+        final NodeList children = node.getChildNodes();
+        for (int i = 0; i < children.getLength(); i++) {
+            final Node child = children.item(i);
+            final String childName = child.getLocalName();
+
+            if ("retval".equals(childName)) {
+                returnValue = new ReturnValue(child, this);
+            }
+
+            if ("arg".equals(childName)) {
+                final Arg arg = new Arg(child, this);
+                if (arg.name == null || "".equals(arg.name)) {
+                    arg.javaName = "arg" + i;
+                }
+                args.add(arg);
+            }
+        }
+
+        if (returnValue == null) returnValue = ReturnValue.VOID;
+        this.returnValue = returnValue;
+    }
+
+    public String getJavaName(){ return name; }
+
+    public void disambiguateArgs() {
+        final Set<String> priorArgs = RestrictedKeywords.getNewRestrictedSet();
+        for (int i = 0; i < args.size(); i++) {
+            final Arg arg = args.get(i);
+            if (priorArgs.contains(arg.name)) arg.javaName = arg.javaName + i;
+            priorArgs.add(arg.javaName);
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/FunctionAlias.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/FunctionAlias.java
new file mode 100644
index 0000000..88cc1c2
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/FunctionAlias.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import org.w3c.dom.Node;
+
+public class FunctionAlias extends Element<Framework> {
+    public FunctionAlias(final Node node, final Framework parent) {
+        super(node, parent);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/InformalProtocol.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/InformalProtocol.java
new file mode 100644
index 0000000..b870cf9
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/InformalProtocol.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import org.w3c.dom.Node;
+
+public class InformalProtocol extends Element<Framework> {
+    public InformalProtocol(final Node node, final Framework parent) {
+        super(node, parent);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Method.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Method.java
new file mode 100644
index 0000000..f9b776d
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Method.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.Set;
+import org.w3c.dom.Node;
+import com.apple.jobjc.SEL;
+import com.apple.internal.jobjc.generator.Utils;
+
+public class Method extends Function {
+    public final boolean isClassMethod;
+
+    public String javaName;
+
+    public boolean ignore;
+    public String suggestion;
+
+    public Method(final Node node, final Framework fw) {
+        super(node, getAttr(node, "selector"), fw);
+        this.javaName = SEL.jMethodName(name);
+        this.isClassMethod = "true".equals(getAttr(node, "class_method"));
+        this.ignore = "true".equals(getAttr(node, "ignore"));
+        this.suggestion = getAttr(node, "suggestion");
+    }
+
+    @Override public String getJavaName(){ return javaName; }
+
+    @Override public String toString() {
+        return returnValue + " " + super.toString() + args;
+    }
+
+    public boolean returnTypeEquals(final ReturnValue returnValueIn) {
+        return returnValue.type.getJType().getJavaReturnTypeName().equals(returnValueIn.type.getJType().getJavaReturnTypeName());
+    }
+
+    public void disambiguateNameAndArgs(final Clazz parentClazz, final Set<String> existingMethodNames) {
+        javaName = getDisambiguatedNameFor(parentClazz, javaName, existingMethodNames);
+        disambiguateArgs();
+    }
+
+    private String getDisambiguatedNameFor(final Clazz parentClazz, final String proposedName, final Set<String> existingNames) {
+        // Does this method override a parent class method and change the return type? Example: IOBlueToothSDPUUID length
+        {
+            final Method superClassMethod = parentClazz.getParentMethodMatchingName(proposedName);
+            if (superClassMethod != null && !superClassMethod.returnValue.equals(returnValue)) {
+                final String usingReturnType = createMethodNameAppendingReturnType(proposedName);
+                if(existingNames.add(usingReturnType))
+                    return usingReturnType;
+            }
+        }
+
+        if(existingNames.add(proposedName))
+            return proposedName;
+
+        final String usingReturnType = createMethodNameAppendingReturnType(proposedName);
+        if(existingNames.add(usingReturnType))
+            return usingReturnType;
+
+        throw new RuntimeException("Unable to disambiguate method: " + this);
+    }
+
+    private String createMethodNameAppendingReturnType(final String proposedName) {
+        return proposedName + Utils.capitalize(returnValue.type.getJType().getAppendableDescription().replaceAll(".+\\.", ""));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/NativeEnum.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/NativeEnum.java
new file mode 100644
index 0000000..2992eee
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/NativeEnum.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.Arrays;
+
+import org.w3c.dom.Node;
+
+import com.apple.internal.jobjc.generator.model.types.Type;
+import com.apple.internal.jobjc.generator.model.types.JType.JPrimitive;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.internal.jobjc.generator.utils.Fp;
+import com.apple.jobjc.JObjCRuntime;
+
+public class NativeEnum extends ElementWType<Framework> {
+    public final String value, value64, le_value, be_value;
+    public boolean ignore;
+    public String suggestion;
+    public NativeEnum(final Node node, final Framework parent) {
+        super(node, typeForEnum(getAttr(node, "name"),
+                getAttr(node, "value"), getAttr(node, "value64"),
+                getAttr(node, "le_value"), getAttr(node, "be_value"),
+                getAttr(node, "ignore")), parent);
+        this.value = getAttr(node, "value");
+        this.value64 = getAttr(node, "value64");
+        this.le_value = getAttr(node, "le_value");
+        this.be_value = getAttr(node, "be_value");
+        String ignoreS = getAttr(node, "ignore");
+        this.ignore = ignoreS == null ? false : Boolean.parseBoolean(ignoreS);
+        this.suggestion = getAttr(node, "suggestion");
+        assert valueToString() != null;
+    }
+
+    private static Type typeForEnum(String name, String value32, String value64, String le_value, String be_value, String ignore){
+        if("true".equals(ignore)) return Type.getType(null, NPrimitive.inst('i'), null);
+
+        NumTest[] tests = new NumTest[]{new IntTest(), new LongTest(), new FloatTest(), new DoubleTest()};
+        for(NumTest t : tests)
+            if(t.confirm(value32, value64, le_value, be_value))
+                return t.getType();
+
+        throw new NumberFormatException(String.format("Failed to parse type for enum: %1$s = 32: %2$s / 64: %3$s / le: %4$s / be: %5$s\n",
+                name, value32, value64, le_value, be_value));
+    }
+
+    public String valueToString(){
+        if(ignore == true) return "0";
+        JPrimitive jprim = (JPrimitive) type.getJType();
+        if(le_value == null && be_value == null){
+            if(value == null && value64 != null)
+                return value64 + jprim.getLiteralSuffix();
+            else if(value != null && value64 == null)
+                return value + jprim.getLiteralSuffix();
+            else
+                return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
+                        value64, value, jprim.getLiteralSuffix());
+        }
+        else if(value == null && value64 == null){
+            return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
+                    JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
+        }
+
+        throw new RuntimeException("Unable to produce a value for enum " + name);
+    }
+
+    // Used to find the best type to use for the enum.
+
+    static abstract class NumTest{
+        public boolean confirm(String... values){
+            return Fp.all(new Fp.Map1<String,Boolean>(){
+                public Boolean apply(String a) {
+                    try{ return a == null || confirm(a); }
+                    catch(Exception x){ return false; }
+                }},
+                Arrays.asList(values));
+        }
+
+        public abstract boolean confirm(String v);
+        public abstract Type getType();
+    }
+
+    static class IntTest extends NumTest{
+        @Override public boolean confirm(String v) {
+            Integer.parseInt(v);
+            return true;
+        }
+
+        @Override public Type getType() { return Type.getType(null, NPrimitive.inst('i'), null); }
+    }
+
+    static class LongTest extends NumTest{
+        @Override public boolean confirm(String v) {
+            Long.parseLong(v);
+            return true;
+        }
+
+        @Override public Type getType() { return Type.getType(null, NPrimitive.inst('l'), null); }
+    }
+
+    static class FloatTest extends NumTest{
+        @Override public boolean confirm(String v) {
+            return Float.parseFloat(v) == Double.parseDouble(v);
+        }
+
+        @Override public Type getType() { return Type.getType(null, NPrimitive.inst('f'), null); }
+    }
+
+    static class DoubleTest extends NumTest{
+        @Override public boolean confirm(String v) {
+            double d = Double.parseDouble(v);
+            return !Double.isInfinite(d) && !Double.isNaN(d);
+        }
+
+        @Override public Type getType() { return Type.getType(null, NPrimitive.inst('d'), null); }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Opaque.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Opaque.java
new file mode 100644
index 0000000..808565b
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Opaque.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.List;
+
+import org.w3c.dom.Node;
+
+import com.apple.internal.jobjc.generator.classes.OpaqueClassFile;
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+
+public class Opaque extends TypeElement<Framework> implements OutputFileGenerator {
+    public Opaque(final Node node, final Framework parent) {
+        super(node, getAttr(node, "name"), parent);
+    }
+
+    public void generateClasses(final List<OutputFile> generatedClassFiles) {
+        generatedClassFiles.add(new OpaqueClassFile(this));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/OutputFileGenerator.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/OutputFileGenerator.java
new file mode 100644
index 0000000..417401e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/OutputFileGenerator.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.List;
+
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+
+public interface OutputFileGenerator {
+    public void generateClasses(final List<OutputFile> generatedClassFiles);
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Protocol.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Protocol.java
new file mode 100644
index 0000000..d74faf4
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Protocol.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+public class Protocol {
+
+    public Protocol(final Clazz protocol) {
+
+    }
+
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/ReturnValue.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/ReturnValue.java
new file mode 100644
index 0000000..b8202ee
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/ReturnValue.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import org.w3c.dom.Node;
+
+import com.apple.internal.jobjc.generator.model.types.Type;
+
+public class ReturnValue extends ElementWType<Function>{
+    public static ReturnValue VOID = new ReturnValue(Type.VOID);
+
+    public ReturnValue(final Node node, final Function parent) {
+        super(node, parent);
+    }
+
+    public ReturnValue(Type type) {
+        super("return value", type, null); // TODO bad style, the null might lead to trouble
+    }
+
+    @Override public boolean equals(Object o){
+        return o instanceof ReturnValue && type.equals(((ReturnValue)o).type);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/StringConstant.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/StringConstant.java
new file mode 100644
index 0000000..a0a4dfd
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/StringConstant.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import org.w3c.dom.Node;
+
+public class StringConstant extends Element<Framework> {
+    public final String value;
+
+    public StringConstant(final Node node, final Framework parent) {
+        super(node, parent);
+        this.value = getAttr(node, "value");
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Struct.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Struct.java
new file mode 100644
index 0000000..179b59f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/Struct.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import java.util.List;
+
+import org.w3c.dom.Node;
+
+import com.apple.internal.jobjc.generator.classes.OutputFile;
+import com.apple.internal.jobjc.generator.classes.StructClassFile;
+import com.apple.internal.jobjc.generator.model.types.Type;
+import com.apple.internal.jobjc.generator.model.types.NType.NField;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.utils.Fp;
+import com.apple.internal.jobjc.generator.utils.QA;
+import com.apple.internal.jobjc.generator.utils.Fp.Map2;
+
+/**
+ * A struct has the following restrictions:
+ *
+ *    - type32.fields.count == type64.fields.count
+ *    - forAll i: type32.field[i].name == type64.field[i].name
+ *    - forAll i: type32.field[i].class == type64.field[i].class
+ */
+public class Struct extends TypeElement<Framework> implements OutputFileGenerator {
+    public final List<Field> fields;
+    public static class Field{
+        public final String name;
+        public final Type type;
+        public final NField field32, field64;
+        public Field(String name, NField field32, NField field64) {
+            QA.nonNull(name);
+            this.name = name;
+            // TODO <field> really should have a declared_type attr. See if BS patch is possible.
+            this.type = Type.getType(null, field32.type, field64.type);
+            this.field32 = field32;
+            this.field64 = field64;
+        }
+    }
+
+    public Struct(final Node node, final Framework parent) throws Throwable {
+        super(node, getAttr(node, "name"), parent);
+        NStruct nstruct32 = (NStruct) type.type32;
+        NStruct nstruct64 = (NStruct) type.type64;
+        this.fields = Fp.map2(new Map2<NField,NField,Field>(){
+            public Field apply(NField f32, NField f64) {
+                assert f32.name.equals(f64.name);
+                return new Field(f32.name, f32, f64);
+            }
+        }, nstruct32.fields, nstruct64.fields);
+    }
+
+    public void generateClasses(final List<OutputFile> generatedClassFiles) {
+        generatedClassFiles.add(new StructClassFile(this));
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/TypeElement.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/TypeElement.java
new file mode 100644
index 0000000..c4c1573
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/TypeElement.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model;
+
+import org.w3c.dom.Node;
+
+import com.apple.internal.jobjc.generator.model.types.Type;
+
+/**
+ * A TypeElement represents a Type, such as a struct or cftype.
+ */
+public abstract class TypeElement<P extends Element<?>> extends ElementWType<P> {
+    public TypeElement(String name, Type type, final P parent) {
+        super(name, type, parent);
+    }
+
+    public TypeElement(final Node node, final String declType, final P parent) {
+        super(node, declType, parent);
+    }
+
+    public TypeElement(final Node node, final P parent) {
+        super(node, parent);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/CoderDescriptor.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/CoderDescriptor.java
new file mode 100644
index 0000000..83d9254
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/CoderDescriptor.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.coders;
+
+import com.apple.internal.jobjc.generator.model.types.JType.JStruct;
+import com.apple.jobjc.Coder;
+import com.apple.jobjc.Coder.IDCoder;
+import com.apple.jobjc.Coder.NSClassCoder;
+import com.apple.jobjc.Coder.PointerCoder;
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+import com.apple.jobjc.Coder.SELCoder;
+import com.apple.jobjc.Coder.UnknownCoder;
+import com.apple.jobjc.Coder.VoidCoder;
+
+public class CoderDescriptor {
+    public static final CoderDescriptor VOID_DESC = new CoderDescriptor(VoidCoder.INST, null, null);
+
+    final Coder coder;
+    private final String coderInstanceName;
+    final String pushName;
+    final String popName;
+
+    public String mismatchMessage(){ return null; }
+
+    public CoderDescriptor(final Coder coder, final String pushName, final String popName) {
+        this.coder = coder;
+        this.coderInstanceName = coder.getClass().getCanonicalName() + ".INST";
+        if (coderInstanceName == null) throw new NullPointerException();
+
+        this.pushName = pushName;
+        this.popName = popName;
+    }
+
+    public CoderDescriptor(final String pushName, final String popName) {
+        this.coder = null;
+        this.coderInstanceName = null;
+        this.pushName = pushName;
+        this.popName = popName;
+    }
+
+    public CoderDescriptor(final Coder coder) { this(coder, "push", "pop"); }
+    public CoderDescriptor(){ this("push", "pop"); }
+
+    public String getPopStatementFor(final String contextName, final String returnValueType, final String returnValueName, final String transform) {
+        return "final " + returnValueType + " " + returnValueName + " = " + "(" + returnValueType + ") " + (transform == null ? "" : transform)
+        + "(" + getCoderInstanceName() + "." + popName + "(" + contextName + "));";
+    }
+
+    public final String getPushStatementFor(final String contextName, final String argumentName) {
+        return getCoderInstanceName() + "." + pushName + "(" + contextName + ", " + argumentName + ");";
+    }
+
+    public String getPopAddrStatementFor(final String runtime, final String addr, final String returnValueType, final String returnValueName, final String transform) {
+        return "final " + returnValueType + " " + returnValueName + " = " + "(" + returnValueType + ") " + (transform == null ? "" : transform)
+        + "(" + getCoderInstanceName() + "." + popName + "(" + runtime + ", " + addr + "));";
+    }
+
+    public final String getPushAddrStatementFor(final String runtime, final String addr, final String argumentName) {
+        return getCoderInstanceName() + "." + pushName + "(" + runtime + ", " + addr + ", " + argumentName + ");";
+    }
+
+    public String getCoderInstanceName() { return coderInstanceName; }
+    public Coder getCoder() { return coder; }
+    public String getDefaultReturnValue() { return "null"; }
+
+    //
+    // Specialized
+    //
+
+    static public class UnknownCoderDescriptor extends CoderDescriptor {
+        public static final CoderDescriptor UNKNOWN_DESC = new UnknownCoderDescriptor();
+        public UnknownCoderDescriptor() { super(UnknownCoder.INST); }
+    }
+
+    static public class PrimitivePointerCoderDescriptor extends CoderDescriptor {
+        public static final PrimitivePointerCoderDescriptor POINTER_DESC = new PrimitivePointerCoderDescriptor();
+        public PrimitivePointerCoderDescriptor() { super(PrimitivePointerCoder.INST, "push", "popPtr"); }
+    }
+
+    static public class PointerCoderDescriptor extends CoderDescriptor {
+        public static final PointerCoderDescriptor INST = new PointerCoderDescriptor();
+        public PointerCoderDescriptor() { super(PointerCoder.INST); }
+    }
+
+    static public class SELCoderDescriptor extends CoderDescriptor {
+        public static final SELCoderDescriptor INST = new SELCoderDescriptor();
+        public SELCoderDescriptor() { super(SELCoder.INST); }
+    }
+
+    static public class IDCoderDescriptor extends CoderDescriptor {
+        public static final IDCoderDescriptor INST = new IDCoderDescriptor();
+        public IDCoderDescriptor() { super(IDCoder.INST); }
+    }
+
+    static public class NSClassCoderDescriptor extends CoderDescriptor {
+        public static final NSClassCoderDescriptor INST = new NSClassCoderDescriptor();
+        public NSClassCoderDescriptor() { super(NSClassCoder.INST); }
+    }
+
+    static public class StructCoderDescriptor extends CoderDescriptor {
+        public final JStruct jstruct;
+        public StructCoderDescriptor(JStruct jst) { this.jstruct = jst; }
+        @Override public String getCoderInstanceName(){ return jstruct.getJavaTypeName() + ".getStructCoder()"; }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/ComplexCoderDescriptor.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/ComplexCoderDescriptor.java
new file mode 100644
index 0000000..11ee8cc
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/ComplexCoderDescriptor.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.coders;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import com.apple.internal.jobjc.generator.classes.MixedPrimitiveCoderClassFile;
+import com.apple.internal.jobjc.generator.model.types.NType;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.internal.jobjc.generator.utils.Fp.Pair;
+import com.apple.jobjc.JObjCRuntime;
+
+/**
+ * Used to code two primitives of different 32/64 types.
+ */
+public class ComplexCoderDescriptor extends CoderDescriptor {
+    static Map<Pair<NType,NType>, ComplexCoderDescriptor> cache = new HashMap<Pair<NType,NType>, ComplexCoderDescriptor>();
+    static Set<MixedEncodingDescriptor> mixedEncodingDescriptors = new HashSet<MixedEncodingDescriptor>();
+
+    public static Set<MixedEncodingDescriptor> getMixedEncoders() { return mixedEncodingDescriptors; }
+
+    public static ComplexCoderDescriptor getCoderDescriptorFor(final NType nt32, final NType nt64) {
+        Pair<NType,NType> cacheKey = new Pair(nt32, nt64);
+        if(cache.containsKey(cacheKey)) return cache.get(cacheKey);
+
+        final PrimitiveCoderDescriptor desc32 = PrimitiveCoderDescriptor.getCoderDescriptorFor((NPrimitive) nt32);
+        final PrimitiveCoderDescriptor desc64 = PrimitiveCoderDescriptor.getCoderDescriptorFor((NPrimitive) nt64);
+
+        final ComplexCoderDescriptor newDesc = nt32.equals(nt64) ? new ComplexCoderDescriptor(desc64) : new MixedEncodingDescriptor(desc32, desc64);
+        cache.put(cacheKey, newDesc);
+        if(newDesc instanceof MixedEncodingDescriptor)
+            mixedEncodingDescriptors.add((MixedEncodingDescriptor) newDesc);
+
+        return newDesc;
+    }
+
+    protected final PrimitiveCoderDescriptor desc64;
+
+    public ComplexCoderDescriptor(final PrimitiveCoderDescriptor desc64) {
+        super(desc64.coder, desc64.pushName, desc64.popName);
+        this.desc64 = desc64;
+    }
+
+    public String getName() { return desc64.javaPrimitiveClazz.getName(); }
+    @Override public String getDefaultReturnValue() { return desc64.defaultReturnValue; }
+    public String getJavaObjectClass() { return desc64.javaObjectClazz.getName(); }
+    public String getDefinition() { return get64CoderName(); }
+    public String getCoderAccessor() { return get64CoderName(); }
+    String get64CoderName() { return desc64.getCoderInstanceName(); }
+
+    // ** Subclasses
+    // -------------
+
+    public static class MixedEncodingDescriptor extends ComplexCoderDescriptor {
+        protected final PrimitiveCoderDescriptor desc32;
+
+        public MixedEncodingDescriptor(final PrimitiveCoderDescriptor desc32, final PrimitiveCoderDescriptor desc64) {
+            super(desc64);
+            this.desc32 = desc32;
+        }
+
+        @Override public String getDefinition() { return JObjCRuntime.class.getName() + ".IS64 ? " + get64CoderName() + " : " + get32CoderName(); }
+        @Override public String getCoderAccessor() { return MixedPrimitiveCoderClassFile.FULL_MULTI_CODER_CLASSNAME + "." + getMixedName(); }
+        String get32CoderName() { return desc32.getCoderInstanceName(); }
+        @Override public String getCoderInstanceName(){ return getCoderAccessor(); }
+        @Override public String toString() { return getMixedName(); }
+
+        public String getMixedName() {
+            final String coder32Name = getBaseNameOfCoder(desc32.primitiveCoderName);
+            final String coder64Name = getBaseNameOfCoder(desc64.primitiveCoderName);
+            return coder32Name + coder64Name + "Coder";
+        }
+
+        static String getBaseNameOfCoder(final String coderName) { return coderName.substring(0, coderName.indexOf("Coder")); }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/PrimitiveCoderDescriptor.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/PrimitiveCoderDescriptor.java
new file mode 100644
index 0000000..4de7d4d
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/coders/PrimitiveCoderDescriptor.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.coders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.jobjc.Coder;
+import com.apple.jobjc.PrimitiveCoder;
+import com.apple.jobjc.PrimitiveCoder.BoolCoder;
+import com.apple.jobjc.PrimitiveCoder.SCharCoder;
+import com.apple.jobjc.PrimitiveCoder.SIntCoder;
+import com.apple.jobjc.PrimitiveCoder.SLongCoder;
+import com.apple.jobjc.PrimitiveCoder.SLongLongCoder;
+import com.apple.jobjc.PrimitiveCoder.SShortCoder;
+import com.apple.jobjc.PrimitiveCoder.UCharCoder;
+import com.apple.jobjc.PrimitiveCoder.UIntCoder;
+import com.apple.jobjc.PrimitiveCoder.ULongCoder;
+import com.apple.jobjc.PrimitiveCoder.ULongLongCoder;
+import com.apple.jobjc.PrimitiveCoder.UShortCoder;
+import com.apple.internal.jobjc.generator.Utils;
+
+public class PrimitiveCoderDescriptor extends CoderDescriptor {
+    static Map<Character, PrimitiveCoderDescriptor> descriptors = new HashMap<Character, PrimitiveCoderDescriptor>();
+
+    public static PrimitiveCoderDescriptor getCoderDescriptorFor(NPrimitive nt) {
+        return getCoderDescriptorFor(nt.type);
+    }
+
+    public static PrimitiveCoderDescriptor getCoderDescriptorFor(char c) {
+        final PrimitiveCoderDescriptor desc = descriptors.get(c);
+        if (desc != null) return desc;
+        final PrimitiveCoderDescriptor newDesc = createCoderDescriptorFor(c);
+        descriptors.put(c, newDesc);
+        return newDesc;
+    }
+
+    public static PrimitiveCoderDescriptor createCoderDescriptorFor(final char encoding) {
+        switch(encoding) {
+            case 'B': return new PrimitiveCoderDescriptor(BoolCoder.INST, "false");
+
+            case 'c': return new PrimitiveCoderDescriptor(SCharCoder.INST, "0");
+            case 'C': return new PrimitiveCoderDescriptor(UCharCoder.INST, "0");
+
+            case 's': return new PrimitiveCoderDescriptor(SShortCoder.INST, "0");
+            case 'S': return new PrimitiveCoderDescriptor(UShortCoder.INST, "0");
+
+            case 'i': return new PrimitiveCoderDescriptor(SIntCoder.INST, "0");
+            case 'I': return new PrimitiveCoderDescriptor(UIntCoder.INST, "0");
+
+            case 'l': return new PrimitiveCoderDescriptor(SLongCoder.INST, "0");
+            case 'L': return new PrimitiveCoderDescriptor(ULongCoder.INST, "0", "x86_64: no suitable Java primitive for unsigned long.");
+            case 'q': return new PrimitiveCoderDescriptor(SLongLongCoder.INST, "0");
+            case 'Q': return new PrimitiveCoderDescriptor(ULongLongCoder.INST, "0", "x86_64: no suitable Java primitive for unsigned long long.");
+
+            case 'f': return new PrimitiveCoderDescriptor(PrimitiveCoder.FloatCoder.INST, "0");
+            case 'd': return new PrimitiveCoderDescriptor(PrimitiveCoder.DoubleCoder.INST, "0");
+            default: throw new RuntimeException("unknown encoding: " + encoding);
+        }
+    }
+
+    public final Class<?> javaPrimitiveClazz;
+    final Class<?> javaObjectClazz;
+    final String defaultReturnValue;
+    final String primitiveCoderName;
+    final String _mismatchMessage;
+
+    public PrimitiveCoderDescriptor(final Coder coder, final String defaultRetVal) {
+        this(coder, defaultRetVal, null);
+    }
+
+    public PrimitiveCoderDescriptor(final Coder coder,
+            final String defaultReturnValue, final String mismatchMessage) {
+        super(coder, "push", "pop" + Utils.capitalize(coder.getJavaPrimitive().getSimpleName()));
+        this.javaPrimitiveClazz = coder.getJavaPrimitive();
+        this.javaObjectClazz = coder.getJavaClass();
+        this.defaultReturnValue = defaultReturnValue;
+        this.primitiveCoderName = coder.getClass().getSimpleName();
+        this._mismatchMessage = mismatchMessage;
+    }
+
+    @Override public PrimitiveCoder getCoder(){ return (PrimitiveCoder) super.getCoder(); }
+    @Override public String mismatchMessage(){ return _mismatchMessage; }
+    @Override public String getDefaultReturnValue() { return defaultReturnValue; }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/JType.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/JType.java
new file mode 100644
index 0000000..b3f88c3
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/JType.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.types;
+
+import com.apple.internal.jobjc.generator.classes.RootJObjCClass;
+import com.apple.internal.jobjc.generator.model.CFType;
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Opaque;
+import com.apple.internal.jobjc.generator.model.Struct;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor;
+import com.apple.internal.jobjc.generator.model.coders.ComplexCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor.IDCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor.NSClassCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor.PointerCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor.SELCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor.StructCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.coders.CoderDescriptor.UnknownCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.jobjc.ID;
+import com.apple.jobjc.NSClass;
+import com.apple.jobjc.NativeArgumentBuffer;
+import com.apple.jobjc.Pointer;
+import com.apple.jobjc.SEL;
+
+public abstract class JType {
+    public abstract String getJavaTypeName();
+    public String getJavaClassName() { return getJavaTypeName().substring(getJavaTypeName().lastIndexOf('.') + 1); }
+    public String getJavaReturnTypeName() { return getJavaTypeName(); }
+    public String getReturnTypeCast() { return null; }
+    public String getTypeNameAsParam() { return getJavaTypeName(); }
+
+    public abstract CoderDescriptor getCoderDescriptor();
+    public String getDefaultReturnValue() { return "null"; }
+    public String getAppendableDescription() { return getJavaTypeName().substring(getJavaTypeName().lastIndexOf('.') + 1); }
+
+    /**
+     * Used for primitive types (like int) that can't be used as generic arguments. This returns an appropriate Java class (like Integer).
+     */
+    public JType getParameterizableType() { return this; }
+
+    //
+    // Writer ops
+    //
+
+    public String createDeclareBuffer(String contextName) {
+        return "final " + NativeArgumentBuffer.class.getName() + " " + contextName + " = getRuntime().getThreadLocalState();";
+    }
+
+    public String createInit(final String contextName, final String functionIdentifier, final String initWithObj) {
+        return functionIdentifier + ".init(" + contextName + (initWithObj != null ? ", " + initWithObj : "") + ");";
+    }
+
+    public String createInvoke(final String contextName, final String functionIdentifier) {
+        return functionIdentifier + ".invoke(" + contextName + ");";
+    }
+
+    public String createPop(final String contextName) {
+        return getCoderDescriptor().getPopStatementFor(contextName, getJavaTypeName(), "returnValue", null);
+    }
+
+    public String createPopAddr(final String runtime, final String addr) {
+        return getCoderDescriptor().getPopAddrStatementFor(runtime, addr, getJavaTypeName(), "returnValue", null);
+    }
+
+    public String createReturn() {
+        final String preCast = getReturnTypeCast();
+        return "return " + (preCast == null ? "" : "(" + preCast + ")") + "returnValue;";
+    }
+
+    //
+    // Specialized
+    //
+
+    static public class JUnknown extends JType {
+        final Type type;
+        protected JUnknown(final Type type) {
+            this.type = type;
+            TypeCache.inst().getUnknownTypes().add(type);
+        }
+        @Override public String getJavaTypeName() { return "Object /* " + type + " */"; }
+        @Override public String getAppendableDescription() { return "Unknown"; }
+        @Override public CoderDescriptor getCoderDescriptor() { return UnknownCoderDescriptor.UNKNOWN_DESC; }
+    }
+
+    static class JVoid extends JType {
+        public static JVoid INST = new JVoid();
+        @Override public String getJavaTypeName() { return "Void"; }
+        @Override public String getJavaReturnTypeName() { return "void"; }
+        @Override public CoderDescriptor getCoderDescriptor(){ return CoderDescriptor.VOID_DESC; }
+        @Override public String createPop(final String contextName){ return ""; }
+        @Override public String createReturn(){ return ""; }
+    };
+
+    static class JSelector extends JType {
+        public static JSelector INST = new JSelector();
+        @Override public String getJavaTypeName() { return SEL.class.getName(); }
+        @Override public CoderDescriptor getCoderDescriptor() { return SELCoderDescriptor.INST; }
+    };
+
+    static class JCFType extends JType{
+        final CFType cfType;
+        public JCFType(final CFType cfType){ this.cfType = cfType; }
+        @Override public String getJavaTypeName() { return cfType.parent.pkg + "." + cfType.name + "CFType"; }
+        @Override public CoderDescriptor getCoderDescriptor() { return PointerCoderDescriptor.INST; }
+        @Override public String createPop(final String contextName) {
+            return "\t\t" + getCoderDescriptor().getPopStatementFor(contextName, getJavaReturnTypeName(), "returnValue", "new " + getJavaTypeName());
+        }
+    }
+
+    static class JOpaque extends JType{
+        final Opaque opaque;
+        public JOpaque(final Opaque opaque){ this.opaque = opaque; }
+        @Override public String getJavaTypeName() { return opaque.parent.pkg + "." + opaque.name + "Opaque"; }
+        @Override public CoderDescriptor getCoderDescriptor() { return PointerCoderDescriptor.INST; }
+        @Override public String createPop(final String contextName) {
+            return "\t\t" + getCoderDescriptor().getPopStatementFor(contextName, getJavaReturnTypeName(), "returnValue", "new " + getJavaTypeName());
+        }
+    }
+
+    static class JPointer extends JType {
+        static JType VOID_PTR = new JPointer(JVoid.INST);
+
+        final JType subject;
+        protected JPointer(final JType javaType) { this.subject = javaType; }
+
+        @Override public String getJavaTypeName() { return Pointer.class.getName() + "<" + subject.getParameterizableType().getJavaTypeName() + ">"; }
+        @Override public String getAppendableDescription() { return "PointerTo" + subject.getAppendableDescription(); }
+        @Override public CoderDescriptor getCoderDescriptor() { return PointerCoderDescriptor.INST; }
+    }
+
+    static class JObject extends JType {
+        public static JType ID_TYPE = new JType() {
+            @Override public String getJavaTypeName() { return ID.class.getName(); }
+            @Override public String getJavaReturnTypeName() { return "<T extends " + getJavaTypeName() + "> T"; }
+            @Override public String getReturnTypeCast() { return "T"; }
+            @Override public CoderDescriptor getCoderDescriptor() { return IDCoderDescriptor.INST; }
+        };
+
+        final Type type;
+        final Clazz clazz;
+
+        public JObject(final Type type, final Clazz clazz) {
+            this.type = type;
+            this.clazz = clazz;
+        }
+
+        @Override public String getJavaTypeName() { return clazz.getFullPath();}
+        @Override public CoderDescriptor getCoderDescriptor() { return IDCoderDescriptor.INST; }
+    }
+
+    static class JClass extends JType {
+        public static JClass INST = new JClass();
+        @Override public String getJavaTypeName() { return NSClass.class.getName(); }
+        @Override public String getJavaReturnTypeName() { return "<T extends " + super.getJavaReturnTypeName() + "> T"; }
+        @Override public String getTypeNameAsParam() { return super.getTypeNameAsParam(); }
+        @Override public String getReturnTypeCast() { return "T"; }
+        @Override public CoderDescriptor getCoderDescriptor() { return NSClassCoderDescriptor.INST; }
+    };
+
+    public static class JStruct extends JType {
+        public final Struct struct;
+        public JStruct(final Struct struct) { this.struct = struct; }
+
+        @Override public String getJavaTypeName() { return struct.parent.pkg + "." + struct.name; }
+        @Override public String getJavaReturnTypeName() { return getJavaTypeName(); }
+
+        StructCoderDescriptor coderDescriptor = new StructCoderDescriptor(this);
+        @Override public CoderDescriptor getCoderDescriptor() { return coderDescriptor; }
+
+        public String createReturnValue() {
+            return "\t\t" + getJavaReturnTypeName() + " returnValue = " + RootJObjCClass.runtimeFrameworkInstR(struct.parent.name)
+            + ".make" + struct.name + "();";
+        }
+
+        @Override public String createInvoke(final String contextName, final String functionIdentifier) {
+            return createReturnValue() + "\n\t\t" + functionIdentifier + ".invoke(" + contextName + ", returnValue);";
+        }
+
+        @Override public String createPop(final String contextName){ return ""; }
+    }
+
+    public static class JPrimitive extends JType {
+        final Type type;
+        final ComplexCoderDescriptor coderDescriptor;
+        final JType parameterizable;
+
+        public JPrimitive(final Type type, final ComplexCoderDescriptor coderDesc) {
+            this.type = type;
+            this.coderDescriptor = coderDesc;
+
+            this.parameterizable = new JType() {
+                @Override public String getJavaTypeName() { return coderDescriptor.getJavaObjectClass(); }
+                @Override public CoderDescriptor getCoderDescriptor() { throw new RuntimeException(); }
+            };
+        }
+
+        @Override public String getJavaTypeName() { return coderDescriptor.getName(); }
+        @Override public String getDefaultReturnValue() { return coderDescriptor.getDefaultReturnValue(); }
+        @Override public JType getParameterizableType() { return parameterizable; }
+        @Override public CoderDescriptor getCoderDescriptor() { return coderDescriptor; }
+
+        /**
+         * Return the suffix placed on java literals to indicate the type. If none applies, return ' '.
+         */
+        public char getLiteralSuffix() {
+            char t = ((NPrimitive)type.type64).type;
+            switch(t){
+                case 'l': case 'L': case 'f': case 'd': return t;
+                case 'q': case 'Q': return 'L';
+            }
+            return ' ';
+        }
+    }
+
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/NType.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/NType.java
new file mode 100644
index 0000000..d1b807b
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/NType.java
@@ -0,0 +1,280 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.types;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.apple.internal.jobjc.generator.Utils;
+import com.apple.internal.jobjc.generator.model.coders.PrimitiveCoderDescriptor;
+import com.apple.internal.jobjc.generator.utils.Fp;
+import com.apple.internal.jobjc.generator.utils.NTypePrinter;
+import com.apple.internal.jobjc.generator.utils.QA;
+import com.apple.jobjc.JObjCRuntime.Width;
+
+/**
+ * NType (Native Type) bridges the type and type64 attributes in BridgeSupport.
+ *
+ * For example:
+ *
+ * <pre>
+ *   type="c"                 // BridgeSupport attribute
+ *   (NPrimitive type: 'c')   // Java object (in sexp form here, for readability)
+ *
+ *   type="^v"
+ *   (NPointer subject: (NVoid))
+ *
+ *   type="{foo_t="a"c"b"b8"c"[32^v]}"
+ *   (NStruct
+ *     name: "foo_t"
+ *     fields:
+ *       (List<NField>
+ *         0: (NField name:"a" type: (NPrimitive type: 'c'))
+ *         1: (NField name:"b" type: (NBitfield size: 8))
+ *         2: (NField name:"c" type:
+ *              (NArray size: 32
+ *                      type: (NPointer subject: (NVoid))))))
+ * </pre>
+ */
+public abstract class NType implements Comparable<NType>{
+    public final Map<Width, Integer> sizeof;
+
+    public NType(Map<Width, Integer> sizeof) {
+        this.sizeof = sizeof;
+    }
+
+    public NType(){
+        this(new HashMap<Width, Integer>());
+    }
+
+    public NType(int sz32, int sz64){
+        this();
+        this.sizeof.put(Width.W32, sz32);
+        this.sizeof.put(Width.W64, sz32);
+    }
+
+    public int sizeof32(){ return sizeof.get(Width.W32); }
+    public int sizeof64(){ return sizeof.get(Width.W64); }
+
+    protected abstract boolean equals2(NType nt);
+
+    private String _toString;
+    @Override public String toString(){ return _toString != null ? _toString : (_toString = NTypePrinter.inst().print(this)); }
+    @Override public boolean equals(Object o) {
+        return o!=null && (o==this || (getClass().isInstance(o)
+                && this.sizeof.equals(((NType) o).sizeof)
+                && equals2((NType) o)));
+    }
+    public int compareTo(NType o){ return toString().compareTo(o.toString()); }
+
+    // ** NType subclasses
+    // -------------------
+
+    public static class NBitfield extends NType{
+        public final int length;
+
+        public NBitfield(int length){
+            super(-1, -1);
+            this.length = length;
+        }
+
+        @Override protected boolean equals2(NType nt) { return ((NBitfield) nt).length == length; }
+        @Override public int hashCode() { return Integer.valueOf(length).hashCode(); }
+    }
+
+    public static class NPrimitive extends NType{
+        public static Collection<Character> CODES = Arrays.asList(
+                'B', 'c', 'C', 's', 'S', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd');
+
+        public final char type;
+
+        protected NPrimitive(char c){
+            super(PrimitiveCoderDescriptor.createCoderDescriptorFor(c).getCoder().sizeof(Width.W32),
+                    PrimitiveCoderDescriptor.createCoderDescriptorFor(c).getCoder().sizeof(Width.W64));
+            type = c;
+        }
+        private static final Map<Character, NPrimitive> cache = new HashMap<Character, NPrimitive>();
+        public static final NPrimitive inst(final char c){
+            if(!cache.containsKey(c)) cache.put(c, new NPrimitive(c));
+            return cache.get(c);
+        }
+
+        @Override protected boolean equals2(NType nt) { return ((NPrimitive)nt).type == type; }
+        @Override public int hashCode() { return Character.valueOf(type).hashCode(); }
+    }
+
+    public static class NVoid extends NType{
+        protected NVoid(){ super(); }
+        private final static NVoid INST = new NVoid();
+        public static NVoid inst() { return INST; }
+
+        @Override protected boolean equals2(NType nt) { return true; }
+    }
+
+    public static class NPointer extends NType{
+        public final NType subject;
+
+        public NPointer(NType subject){
+            super(4, 8);
+            QA.nonNull(subject);
+            this.subject = subject;
+        }
+
+        @Override protected boolean equals2(NType nt) { return ((NPointer)nt).subject.equals(subject); }
+        @Override public int hashCode() { return subject.hashCode(); }
+    }
+
+    public static class NObject extends NType{
+        protected NObject(){ super(4, 8); }
+        private final static NObject INST = new NObject();
+        public static NObject inst() { return INST; }
+
+        @Override protected boolean equals2(NType nt) { return true; }
+    }
+
+    public static class NClass extends NType{
+        protected NClass(){ super(4, 8); }
+        private final static NClass INST = new NClass();
+        public static NClass inst() { return INST; }
+
+        @Override protected boolean equals2(NType nt) { return true; }
+    }
+
+    public static class NSelector extends NType{
+        protected NSelector(){ super(4, 8); }
+        private final static NSelector INST = new NSelector();
+        public static NSelector inst() { return INST; }
+
+        @Override protected boolean equals2(NType nt) { return true;}
+    }
+
+    public static class NField{
+        public final Map<Width,Integer> offset;
+        public final String name;
+        public final NType type;
+
+        public NField(String name, NType type, Map<Width,Integer> offset) {
+            QA.nonNull(name, type, offset);
+            this.name = name;
+            this.type = type;
+            this.offset = offset;
+        }
+
+        public NField(String name, NType type) {
+            this(name, type, new HashMap());
+        }
+
+        public int offset32(){ return offset.get(Width.W32); }
+        public int offset64(){ return offset.get(Width.W64); }
+
+        @Override public int hashCode() { return name.hashCode() + type.hashCode(); }
+        @Override public boolean equals(Object o) {
+            return o!=null && (o==this ||
+                    (o instanceof NField
+                            && this.offset.equals(((NField) o).offset)
+                            && ((NField) o).name.equals(this.name)
+                            && ((NField) o).type.equals(this.type)));
+        }
+    }
+
+    public static class NStruct extends NType{
+        public final String name;
+        public final List<NField> fields;
+
+        public NStruct(String name, List<NField> fields, Map<Width,Integer> sizeof){
+            super(sizeof);
+            QA.nonNull(name, fields);
+            this.name = name;
+            this.fields = fields;
+        }
+
+        public NStruct(String name, List<NField> fields){
+            super();
+            QA.nonNull(name, fields);
+            this.name = name;
+            this.fields = fields;
+        }
+
+        @Override protected boolean equals2(NType nt) {
+            return ((NStruct)nt).name.equals(name) && ((NStruct)nt).fields.equals(fields);
+        }
+
+        @Override public int hashCode() { return name.hashCode() + fields.hashCode(); }
+    }
+
+    // A Union is like a Struct, but the offset of every field is 0.
+    public static class NUnion extends NStruct{
+        public NUnion(String concreteName, List<NField> fields){
+            super(concreteName, fields);
+            assert Fp.all(hasZeroOffsets, fields) : Utils.joinWComma(fields);
+        }
+
+        public NUnion(String name, List<NField> fields, Map<Width,Integer> sizeof) {
+            super(name, fields, sizeof);
+            assert Fp.all(hasZeroOffsets, fields) : Utils.joinWComma(fields);
+        }
+
+        public static final Fp.Map1<NField,Boolean> hasZeroOffsets = new Fp.Map1<NField,Boolean>(){
+            public Boolean apply(NField a) {
+                for(int i : a.offset.values())
+                    if(i != 0)
+                        return false;
+                return true;
+            }};
+        public static final Fp.Map1<NField,NField> zeroOffsets = new Fp.Map1<NField,NField>(){
+            public NField apply(NField a) {
+                Map<Width,Integer> off = new HashMap();
+                for(Width w : a.offset.keySet())
+                    off.put(w, 0);
+                return new NField(a.name, a.type, off);
+            }};
+    }
+
+    public static class NArray extends NType{
+        public final int length;
+        public final NType type;
+
+        public NArray(int length, NType type){
+            QA.nonNull(type);
+            this.length = length;
+            this.type = type;
+        }
+
+        @Override protected boolean equals2(NType nt) { return ((NArray)nt).length == length && ((NArray)nt).type.equals(type); }
+        @Override public int hashCode(){ return Long.valueOf(length).hashCode() + type.hashCode(); }
+    }
+
+    // Seems to be used for callbacks
+    public static class NUnknown extends NType{
+        protected NUnknown(){ super(); }
+        private final static NUnknown INST = new NUnknown();
+        public static NUnknown inst() { return INST; }
+
+        @Override protected boolean equals2(NType nt) { return true;}
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/Type.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/Type.java
new file mode 100644
index 0000000..a4ed340
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/Type.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.types;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.apple.internal.jobjc.generator.model.types.NType.NObject;
+import com.apple.internal.jobjc.generator.model.types.NType.NPointer;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.internal.jobjc.generator.model.types.NType.NVoid;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.model.types.NType.NField;
+import com.apple.internal.jobjc.generator.utils.NTypeMerger;
+import com.apple.internal.jobjc.generator.utils.QA;
+import com.apple.internal.jobjc.generator.utils.Fp.Pair;
+import com.apple.internal.jobjc.generator.utils.NTypeMerger.MergeFailed;
+
+public class Type implements Comparable<Type>{
+    public static Type VOID = Type.getType("void", NVoid.inst(), null);
+    public static Type VOID_PTR = Type.getType("void*", new NPointer(NVoid.inst()), null);
+
+    final public String name;
+    final public NType type32;
+    final public NType type64;
+
+    // HACK BS bug where some types have inconsistent definitions in the metadata,
+    // e.g. (l / i) in some places and just (l) (and thus (l / l)) in others.
+    // This is a mapping from the type name to a Type object with the correct definition.
+    private static final Map<String, Type> exceptions;
+    static {
+        exceptions = new HashMap<String, Type>();
+        exceptions.put("OSStatus", getType("OSStatus", new NPrimitive('l'), new NPrimitive('i'))); // (l / i) vs. (l)
+        exceptions.put("CGFloat", getType("CGFloat", new NPrimitive('f'), new NPrimitive('d'))); // (f / d) vs. (f)
+        exceptions.put("NSRect", getType("NSRect", getNSRectType(), getCGRectType())); // ({{_NSPoint}{_NSSize}} / {{CGPoint}{CGSize}}) vs. ({{_NSPoint}{_NSSize}})
+        exceptions.put("NSPoint", getType("NSPoint", getNSPointType(), getCGPointType())); // (_NSPoint / CGPoint) vs. (_NSPoint)
+        exceptions.put("NSSize", getType("NSSize", getNSSizeType(), getCGSizeType())); // (_NSSize / CGSize) vs. (_NSSize)
+        exceptions.put("NSInteger", getType("NSInteger", new NPrimitive('i'), new NPrimitive('q'))); // (i / q) vs. (i)
+        exceptions.put("NSPointArray", getType("NSPointArray", new NPointer(getNSPointType()), new NPointer(getCGPointType()))); // (^_NSPoint / ^CGPoint) vs. (^_NSPoint)
+        exceptions.put("NSMultibyteGlyphPacking", getType("NSMultibyteGlyphPacking", new NPrimitive('I'), new NPrimitive('Q'))); // (I / Q) vs. (I)
+        exceptions.put("CFTypeRef", getType("CFTypeRef", new NPointer(NVoid.inst()), new NPointer(NVoid.inst()))); // (^v, ^v) vs. (@, @)
+    }
+
+    public static Type getType(final String name, final NType t32, final NType t64){
+        return TypeCache.inst().pingType(new Type(name, t32, t64));
+    }
+
+    private Type(final String name, final NType t32, final NType t64) {
+        QA.nonNull(t32);
+        this.name = cleanName(name);
+        this.type32 = t32;
+        this.type64 = t64 == null || t32.equals(t64) ? t32 : t64;
+    }
+
+    private JType _getJType;
+    public JType getJType() {
+        return _getJType!=null ? _getJType : (_getJType = TypeToJType.inst().getJTypeFor(TypeCache.inst().pingType(this)));
+    }
+
+    private String _toString;
+    @Override public String toString() {
+        return _toString != null ? _toString : (_toString = name + " " + new Pair(type32, type64).toString());
+    }
+
+    @Override public boolean equals(Object o){
+        if(o==null || !(o instanceof Type)) return false;
+        Type t = (Type) o;
+        return QA.bothNullOrEquals(t.name, this.name)
+        && t.type32.equals(this.type32)
+        && t.type64.equals(this.type64);
+    }
+
+    @Override public int hashCode(){
+        return (name == null ? 0 : name.hashCode())
+        + type32.hashCode() + type64.hashCode();
+    }
+
+    public int compareTo(Type o) { return toString().compareTo(o.toString()); }
+
+    public static Type merge(Type a, Type b) throws MergeFailed{
+        if(a!=null && b==null) return a;
+        if(a==null && b!=null) return b;
+        if(QA.bothNullOrEquals(a, b)) return a;
+        if (exceptions.containsKey(a.name)) return exceptions.get(a.name); // HACK BS bug
+        if(a.name != null && b.name != null && !a.name.equals(b.name)){
+            System.out.println("Merging:");
+            System.out.println("\ta.....: " + a.toString());
+            System.out.println("\tb.....: " + b.toString());
+        }
+        final Type merged = new Type(NTypeMerger.inst().mergeName(a.name, b.name),
+                NTypeMerger.inst().merge(a.type32, b.type32),
+                NTypeMerger.inst().merge(a.type64, b.type64));
+        if(a.name != null && b.name != null && !a.name.equals(b.name)){
+            System.out.println("\tmerged: " + merged.toString());
+        }
+        return merged;
+    }
+
+    // HACK BS bug where sometimes the name is declared as "id <A, B..." and sometimes it's "id<A,B..."
+    public static String cleanName(String name){ return name == null ? null : name.replaceAll("\\s+", ""); }
+
+    // HACK BS bug where NSRect has inconsistent definitions in the metadata
+    // Methods return NTypes created according to the correct definitions below:
+    //
+    // {_NSRect="origin"{_NSPoint="x"f"y"f}"size"{_NSSize="width"f"height"f}} *** 32-bit
+    // {CGRect="origin"{CGPoint="x"d"y"d}"size"{CGSize="width"d"height"d}} *** 64-bit
+
+    private static NType getCGRectType() {
+        List<NField> fields = new ArrayList<NField>();
+        fields.add(new NField("origin", getCGPointType()));
+        fields.add(new NField("size", getCGSizeType()));
+        return new NStruct("CGRect", fields);
+    }
+
+    private static NType getNSRectType() {
+        List<NField> fields = new ArrayList<NField>();
+        fields.add(new NField("origin", getNSPointType()));
+        fields.add(new NField("size", getNSSizeType()));
+        return new NStruct("_NSRect", fields);
+    }
+
+    private static NType getCGPointType() {
+        List<NField> fields = new ArrayList<NField>();
+        fields.add(new NField("x", new NPrimitive('d')));
+        fields.add(new NField("y", new NPrimitive('d')));
+        return new NStruct("CGPoint", fields);
+    }
+
+    private static NType getNSPointType() {
+        List<NField> fields = new ArrayList<NField>();
+        fields.add(new NField("x", new NPrimitive('f')));
+        fields.add(new NField("y", new NPrimitive('f')));
+        return new NStruct("_NSPoint", fields);
+    }
+
+    private static NType getCGSizeType() {
+        List<NField> fields = new ArrayList<NField>();
+        fields.add(new NField("width", new NPrimitive('d')));
+        fields.add(new NField("height", new NPrimitive('d')));
+        return new NStruct("CGSize", fields);
+    }
+
+    private static NType getNSSizeType() {
+        List<NField> fields = new ArrayList<NField>();
+        fields.add(new NField("width", new NPrimitive('f')));
+        fields.add(new NField("height", new NPrimitive('f')));
+        return new NStruct("_NSSize", fields);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/TypeCache.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/TypeCache.java
new file mode 100644
index 0000000..b876497
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/TypeCache.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.types;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import com.apple.internal.jobjc.generator.model.CFType;
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.model.Opaque;
+import com.apple.internal.jobjc.generator.model.Struct;
+import com.apple.internal.jobjc.generator.utils.Fp.Pair;
+
+/**
+ * Central store for types found in the frameworks.
+ */
+public class TypeCache {
+    private static TypeCache INST = new TypeCache();
+    public static TypeCache inst(){ return INST; }
+    protected TypeCache(){}
+
+    /**
+     * When a new Type is discovered, pass it through here to
+     * hit the cache, potentially merge with other types, etc.
+     *
+     * Always do:
+     *
+     *   Type type = TypeCache.inst().pingType(new Type(a,b,c));
+     *
+     * because this should return a better merge for you.
+     */
+    public Type pingType(final Type type_){
+        Type typex = type_;
+
+        // XXX Exception for void* clashes: void* (^{OpaqueCMProfileRef}), void* (^{X}), etc
+        if("void*".equals(typex.name) && getTypeByName(typex.name)!=null)
+            return getTypeByName(typex.name);
+
+        if(typex.name != null)
+            typex = Type.merge(typex, getTypeByName(typex.name));
+        else // type.name == null
+            typex = Type.merge(typex, getTypeByNTypes(new Pair(typex.type32, typex.type64)));
+        putTypeByName(typex.name, typex);
+        putTypeByNTypes(new Pair(typex.type32, typex.type64), typex);
+        return typex;
+    }
+
+    public final Map<String, Type> typesByName = new HashMap<String, Type>();
+    public Type getTypeByName(final String name) { return typesByName.get(Type.cleanName(name)); }
+    public void putTypeByName(String name, Type type) { if(name!=null) typesByName.put(name, type);    }
+
+    public final Map<Pair<NType,NType>, Type> typesByNTypes = new HashMap<Pair<NType,NType>, Type>();
+    public Type getTypeByNTypes(Pair<NType,NType> pair) { return typesByNTypes.get(pair); }
+    public void putTypeByNTypes(Pair<NType,NType> pair, Type type) { if(pair!=null) typesByNTypes.put(pair, type); }
+
+    private final Map<String, Clazz> classesByName = new HashMap<String, Clazz>();
+    private final Map<String, Struct> structsByName = new HashMap<String, Struct>();
+    private final Map<String, CFType> cfTypesByName = new HashMap<String, CFType>();
+    private final Map<String, Opaque> opaquesByName = new HashMap<String, Opaque>();
+
+    public void load(final List<Framework> frameworks) {
+        for (final Framework framework : frameworks) {
+            for (final Clazz obj : framework.classes) {
+                final Clazz previous = classesByName.put(obj.name, obj);
+                if(previous != null)
+                    throw new RuntimeException(String.format(
+                            "TypeCache: naming collision: class name: %1$-10s -- framework1: %2$-10s -- framework2: %3$-10s \n",
+                            obj.name, obj.parent.name, previous.parent.name));
+            }
+
+            for (final Struct obj : framework.structs) {
+                final Struct previous = structsByName.put(obj.name, obj);
+                if(previous != null)
+                    throw new RuntimeException(String.format(
+                            "TypeCache: naming collision: name: %1$-10s -- type1: %2$-10s -- type2: %3$-10s \n",
+                            obj.name, obj.type, previous.type));
+            }
+
+            for (final CFType obj : framework.cfTypes) {
+                final CFType previous = cfTypesByName.put(obj.name, obj);
+                if(previous != null)
+                    throw new RuntimeException(String.format(
+                            "TypeCache: naming collision: name: %1$-10s -- type1: %2$-10s -- type2: %3$-10s \n",
+                            obj.name, obj.type, previous.type));
+            }
+
+            for (final Opaque obj : framework.opaques) {
+                final Opaque previous = opaquesByName.put(obj.name, obj);
+                if(previous != null)
+                    throw new RuntimeException(String.format(
+                            "TypeCache: naming collision: name: %1$-10s -- type1: %2$-10s -- type2: %3$-10s \n",
+                            obj.name, obj.type, previous.type));
+            }
+        }
+    }
+
+    public Collection<Clazz> getAllClasses() { return classesByName.values(); }
+    public Clazz getClassForName(final String className) { return classesByName.get(className); }
+    public Struct getStructForName(final String declaredType) { return structsByName.get(declaredType); }
+    public CFType getCFTypeForName(final String declaredType) { return cfTypesByName.get(declaredType); }
+    public Opaque getOpaqueForName(final String declaredType) { return opaquesByName.get(declaredType); }
+
+    final Set<Type> unknownTypes = new TreeSet<Type>();
+    public Set<Type> getUnknownTypes() { return unknownTypes; }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/TypeToJType.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/TypeToJType.java
new file mode 100644
index 0000000..47003ab
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/model/types/TypeToJType.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.model.types;
+
+import com.apple.internal.jobjc.generator.model.CFType;
+import com.apple.internal.jobjc.generator.model.Clazz;
+import com.apple.internal.jobjc.generator.model.Opaque;
+import com.apple.internal.jobjc.generator.model.Struct;
+import com.apple.internal.jobjc.generator.model.coders.ComplexCoderDescriptor;
+import com.apple.internal.jobjc.generator.model.types.JType.JCFType;
+import com.apple.internal.jobjc.generator.model.types.JType.JClass;
+import com.apple.internal.jobjc.generator.model.types.JType.JObject;
+import com.apple.internal.jobjc.generator.model.types.JType.JOpaque;
+import com.apple.internal.jobjc.generator.model.types.JType.JPointer;
+import com.apple.internal.jobjc.generator.model.types.JType.JPrimitive;
+import com.apple.internal.jobjc.generator.model.types.JType.JSelector;
+import com.apple.internal.jobjc.generator.model.types.JType.JStruct;
+import com.apple.internal.jobjc.generator.model.types.JType.JUnknown;
+import com.apple.internal.jobjc.generator.model.types.JType.JVoid;
+import com.apple.internal.jobjc.generator.model.types.NType.NClass;
+import com.apple.internal.jobjc.generator.model.types.NType.NObject;
+import com.apple.internal.jobjc.generator.model.types.NType.NPointer;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.internal.jobjc.generator.model.types.NType.NSelector;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.model.types.NType.NVoid;
+import com.apple.internal.jobjc.generator.utils.Fp.CacheMap;
+import com.apple.internal.jobjc.generator.utils.Fp.Dispatcher;
+import com.apple.internal.jobjc.generator.utils.Fp.Map0;
+
+public class TypeToJType {
+    private static TypeToJType INST = new TypeToJType();
+    public static TypeToJType inst(){ return INST; }
+
+    private CacheMap<Type,JType> cache = new CacheMap<Type,JType>();
+    public JType getJTypeFor(final Type type){
+        return cache.get(type, new Map0<JType>(){
+            public JType apply() {
+                try {
+                    return Dispatcher.dispatch(TypeToJType.this.getClass(), TypeToJType.this, "accept", type, type.type32, type.type64);
+                } catch (NoSuchMethodException e) {
+                    return new JUnknown(type);
+                }
+            }});
+    }
+
+    protected JType accept(Type type, NObject nt32, NObject nt64){
+        if ("id".equals(type.name)) return JObject.ID_TYPE;
+
+        final String className = type.name.replaceAll("\\*$", "");
+        assert !className.endsWith("*");
+
+        final Clazz clazz = TypeCache.inst().getClassForName(className);
+        if (clazz == null) return new JUnknown(type);
+        // TODO Instead of JUnknown, ID_TYPE might be more appropriate. Investigate.
+
+        return new JObject(type, clazz);
+    }
+
+    protected JType accept(Type type, NPointer nt32, NPointer nt64){
+        final CFType cfType = TypeCache.inst().getCFTypeForName(type.name);
+        if(cfType != null) return new JCFType(cfType);
+
+        final Opaque opaque = TypeCache.inst().getOpaqueForName(type.name);
+        if(opaque != null) return new JOpaque(opaque);
+
+        if("void*".equals(type.name)) return JPointer.VOID_PTR;
+
+        if(type.name != null && type.name.endsWith("*")){
+            final String subDeclaredType = type.name.substring(0, type.name.length() - 1);
+            final Type subType = TypeCache.inst().getTypeByName(subDeclaredType);
+            if (subType == null) return new JUnknown(type);
+            // TODO Instead of JUnknown, VOID_PTR might be a good fallback. Investigate.
+
+            final JType javaType = TypeToJType.inst().getJTypeFor(subType).getParameterizableType();
+
+            final JPointer pointer = new JPointer(javaType);
+            return pointer;
+        }
+
+        return new JUnknown(type);
+    }
+
+    protected JType accept(Type type, NPrimitive nt32, NPrimitive nt64){
+        final ComplexCoderDescriptor coderDesc = ComplexCoderDescriptor.getCoderDescriptorFor(type.type32, type.type64);
+        if (coderDesc == null) return null;
+        return new JPrimitive(type, coderDesc);
+    }
+
+    protected JType accept(Type type, NVoid nt32, NVoid nt64){
+        return JVoid.INST;
+    }
+
+    protected JType accept(Type type, NSelector nt32, NSelector nt64){
+        return JSelector.INST;
+    }
+
+    protected JType accept(Type type, NClass nt32, NClass nt64){
+        return JClass.INST;
+    }
+
+    protected JType accept(Type type, NStruct nt32, NStruct nt64){
+        Struct st = TypeCache.inst().getStructForName(type.name);
+        return st != null ? new JStruct(st) : new JUnknown(type);
+        // TODO We could probably generate a struct here based on the type. But we need access to its parent framework.
+        // Maybe we could use a fallback anonymous struct, but we need the SIZEOF.
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/Fp.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/Fp.java
new file mode 100644
index 0000000..c1db766
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/Fp.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * Functional programming constructs and utilities. Java for Lisp and Haskell nerds.
+ */
+public abstract class Fp {
+    /**
+     * Multiple dynamic dispatch (multi-methods) for Java.
+     *
+     * This is implemented with Java reflection:
+     * Class.getDeclaredMethod and Method.invoke.
+     * It is about 20-40 times slower than chains of
+     * "if instanceof" statements.
+     */
+    public static abstract class Dispatcher{
+        /**
+         * Shorthand, works only if no arg is null.
+         */
+        public static final <R> R dispatch(Class clazz, Object instance, String method, Object... args) throws NoSuchMethodException{
+            Class[] types = new Class[args.length];
+            for(int i = 0; i < args.length; i++) types[i] = args[i].getClass();
+            return (R) dispatch(clazz, instance, method, args, types);
+        }
+
+        /**
+         * Dispatch `args` of `types` to `method` on `clazz` for `instance`. If `method` is static, `instance` should be null.
+         */
+        public static final <R> R dispatch(Class clazz, Object instance, String method, Object[] args, Class[] types) throws NoSuchMethodException{
+            try{
+                java.lang.reflect.Method m = clazz.getDeclaredMethod(method, types);
+                m.setAccessible(true);
+                return (R) m.invoke(instance, args);
+            }
+            catch(NoSuchMethodException x){
+                if(clazz.getSuperclass() != null)  return (R) dispatch(clazz.getSuperclass(), instance, method, args, types);
+                else                               throw x;
+            }
+            catch(Exception x){
+                throw new RuntimeException(x);
+            }
+        }
+    }
+
+    /**
+     * The "Maybe" type encapsulates an optional value. A value of type
+     * "Maybe a" either contains a value of type "a" (represented as "Just a"),
+     * or it is empty (represented as "Nothing").
+     *
+     * http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html
+     */
+    public static abstract class Maybe<A>{
+        public abstract boolean isJust();
+        public abstract boolean isNothing();
+        public abstract A fromJust() throws ClassCastException;
+        public abstract A fromMaybe(final A fallback);
+
+        public static class Nothing<A> extends Maybe<A>{
+            @Override public A fromJust() throws ClassCastException { throw new ClassCastException("Cannot extract value from Nothing."); }
+            @Override public A fromMaybe(A fallback) { return fallback; }
+            @Override public boolean isJust() { return false; }
+            @Override public boolean isNothing() { return true; }
+        }
+        public static class Just<A> extends Maybe<A>{
+            public final A a;
+            public Just(A a){ this.a = a; }
+            @Override public A fromJust(){ return a; }
+            @Override public A fromMaybe(A fallback) { return a; }
+            @Override public boolean isJust() { return true; }
+            @Override public boolean isNothing() { return false; }
+        }
+    }
+
+    public static class NonNull<A>{
+        public final A obj;
+        public NonNull(A o){
+            if(o==null) throw new RuntimeException("o may not be null.");
+            this.obj = o;
+        }
+    }
+
+    // Closures
+    public static interface Map0<A>{ A apply(); }
+    public static interface Map1<A,B>{ B apply(final A a); }
+    public static interface Map2<A,B,C>{ C apply(final A a, final B b); }
+
+    public static class CacheMap<K extends Comparable<K>,V>{
+        private Map<K,V> cache = new TreeMap<K,V>();
+        public V get(K key, Map0<V> create){
+            if(cache.containsKey(key)) return cache.get(key);
+            V value = create.apply();
+            cache.put(key, value);
+            return value;
+        }
+    }
+
+    public static class Curry2to1<A,B,C> implements Map1<B,C>{
+        private Map2<A,B,C> target; private A a;
+        public Curry2to1(Map2<A, B, C> targett, A aa) { target = targett; a = aa; }
+        public C apply(B b) { return target.apply(a, b); }
+    }
+
+    // Tuple
+    public static class Pair <A,B> implements Comparable<Pair<A,B>>{
+        public final A a; public final B b;
+        public Pair(final A aa, final B bb){ a=aa; b=bb; }
+        @Override public int hashCode(){ return (a==null ? 0 : a.hashCode()) + (b==null ? 0 : b.hashCode()); }
+        @Override public boolean equals(Object o){
+            if(!(o instanceof Pair)) return false;
+            Pair<?,?> p = (Pair<?,?>) o;
+            return QA.bothNullOrEquals(a, p.a) && QA.bothNullOrEquals(b, p.b);
+        }
+        @Override public String toString(){ return "(" + a + ", " + b + ")"; }
+        public int compareTo(Pair<A, B> o){ return toString().compareTo(o.toString()); }
+    }
+
+    /**
+     * @return [fn(x) | x <- items]
+     */
+    public static <A,B> List<B> map(Map1<A,B> fn, final Collection<A> xs){
+        ArrayList<B> rs = new ArrayList<B>(xs.size());
+        for(A x : xs) rs.add(fn.apply(x));
+        return rs;
+    }
+
+    public static <A,B,C> List<C> map2(Map2<A,B,C> fn, final Collection<A> as, final Collection<B> bs){
+        assert as.size() == bs.size();
+        ArrayList<C> cs = new ArrayList<C>(as.size());
+        Iterator<A> aiter = as.iterator();
+        Iterator<B> biter = bs.iterator();
+        while(aiter.hasNext() && biter.hasNext())
+            cs.add(fn.apply(aiter.next(), biter.next()));
+        return cs;
+    }
+
+    /**
+     * Same as map, but does not retain results.
+     */
+    public static <A> void each(Map1<A,?> fn, final Collection<A> xs){
+        for(A x : xs) fn.apply(x);
+    }
+
+    /**
+     * @return [x | x <- items, take(x)]
+     */
+    public static <A> List<A> filter(Map1<A,Boolean> take, final Collection<A> xs){
+        List<A> rs = new ArrayList<A>(xs.size());
+        for(A x : xs) if(take.apply(x)) rs.add(x);
+        return rs;
+    }
+
+    /**
+     * @return [x | x <- items, take(x)]
+     */
+    public static <A> Set<A> filterSet(Map1<A,Boolean> take, final Collection<A> xs){
+        Set<A> rs = new HashSet<A>(xs.size());
+        for(A x : xs) if(take.apply(x)) rs.add(x);
+        return rs;
+    }
+
+    /**
+     * @return the first x in items that satisfies take(x), or null if none
+     */
+    public static <X> X find(Map1<X,Boolean> take, final Collection<X> xs){
+        for(X x : xs) if(take.apply(x)) return x;
+        return null;
+    }
+
+    public static <A,B> A foldl(final Map2<A,B,A> f, A a, final Collection<B> xs){
+        for(B b : xs) a = f.apply(a, b);
+        return a;
+    }
+
+    /**
+     * @return All x : p(x) == true
+     */
+    public static <A> boolean all(Map1<A,Boolean> p, Collection<A> xs) {
+        for(A x : xs) if(!p.apply(x)) return false;
+        return true;
+    }
+
+    /**
+     * @return Any x : p(x) == true
+     */
+    public static <A> boolean any(Map1<A,Boolean> p, Collection<A> xs) {
+        for(A x : xs) if(p.apply(x)) return true;
+        return false;
+    }
+
+    public static <A> String join(final String sep, final Collection<A> xs) {
+        if(xs.size() == 0) return "";
+        if(xs.size() == 1) return xs.iterator().next().toString();
+        return Fp.foldl(new Fp.Map2<String, A, String>(){
+            public String apply(String a, A b) {
+                String sb = b==null? "null" : b.toString();
+                return a == null ? sb : a + sep + sb;
+            }}, null, xs);
+    }
+
+    public static Map2<Integer,Integer,Integer> operatorPlus = new Map2<Integer, Integer, Integer>(){
+        public Integer apply(Integer a, Integer b) { return (int)a + (int)b;}
+    };
+
+    public static int sum(Collection<Integer> xs){ return foldl(operatorPlus, 0, xs); }
+
+    public static <A> List<A> append(Collection<A> xs, Collection<A> ys) {
+        List<A> rs = new ArrayList<A>(xs.size() + ys.size());
+        rs.addAll(xs);
+        rs.addAll(ys);
+        return rs;
+    }
+
+    public static <A> Set<A> appendSet(Collection<A> xs, Collection<A> ys) {
+        Set<A> rs = new HashSet<A>(xs.size() + ys.size());
+        rs.addAll(xs);
+        rs.addAll(ys);
+        return rs;
+    }
+
+    public static <K,V> Map<K,V> litMap(K key, V value, Object... pairs){
+        Map ret = new HashMap(1 + pairs.length/2);
+        ret.put(key, value);
+        for(int i = 0; i < pairs.length; i += 2)
+            ret.put(pairs[i], pairs[i+1]);
+        return ret;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/JavaLang.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/JavaLang.java
new file mode 100644
index 0000000..4c8a653
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/JavaLang.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import com.apple.internal.jobjc.generator.Utils;
+import com.apple.internal.jobjc.generator.Utils.Substituter;
+
+/**
+ * Utility for generating Java source code.
+ */
+public abstract class JavaLang {
+
+    public static String makeSingleton(final String instanceVariable, final String methodName, final String className, final String...constructorArgs) {
+        return generateSingleton(new Substituter(
+            "#private $CLASS $IVAR = null;~" +
+            "#public $CLASS $METHOD() {~" +
+            "##return $IVAR != null ? $IVAR : ($IVAR = new $CLASS($CTORARGS));~" +
+            "#}~"),
+        instanceVariable, methodName, className, constructorArgs);
+    }
+
+    public static String makeStaticSingleton(final String instanceVariable, final String methodName, final String className, final String...constructorArgs) {
+        return generateSingleton(new Substituter(
+            "#private static $CLASS $IVAR = null;~" +
+            "#public static $CLASS $METHOD() {~" +
+            "##return $IVAR != null ? $IVAR : ($IVAR = new $CLASS($CTORARGS));~" +
+            "#}~"),
+        instanceVariable, methodName, className, constructorArgs);
+    }
+
+    private static String generateSingleton(final Substituter singleton, final String instanceVariable, final String methodName, final String className, final String...constructorArgs) {
+        singleton.replace("IVAR", instanceVariable);
+        singleton.replace("METHOD", methodName);
+        singleton.replace("CLASS", className);
+        singleton.replace("CTORARGS", Utils.joinWComma(constructorArgs));
+        return singleton.toString();
+    }
+
+    ///
+
+    public static class JLTertiary{
+        public Object cond, tExp, fExp;
+        public JLTertiary(){}
+        public JLTertiary(Object cond, Object tExp, Object fExp){
+            this.cond = cond;
+            this.tExp = tExp;
+            this.fExp = fExp;
+        }
+        @Override public String toString() {
+            return "((" + cond + ")\n\t? (" + tExp + ")\n\t: (" + fExp + "))";
+        }
+    }
+
+    public static class JLCall{
+        public String fun;
+        public List<Object> args = new ArrayList<Object>();
+        public JLCall(String fun, Object... args){
+            this.fun = fun;
+            this.args.addAll(Arrays.asList(args));
+        }
+        @Override public String toString(){
+            return fun + "(" + Fp.join(", ", args) + ")";
+        }
+    }
+
+    public static class JLField{
+        public Set<String> mods = new TreeSet<String>();
+        public String type;
+        public String name;
+        public Object value;
+
+        public JLField(String mods, String type, String name){
+            this(mods, type, name, null);
+        }
+
+        public JLField(String mods, String type, String name, Object value){
+            this.mods.addAll(Arrays.asList(mods.split("\\s")));
+            this.type = type;
+            this.name = name;
+            this.value = value;
+        }
+
+        @Override public String toString(){
+            return "\t" + Fp.join(" ", mods) + " " + type + " " + name + (value==null ? "" : " = " + value) + ";\n";
+        }
+    }
+
+    public static class JLCtor extends JLMethod{
+        public JLCtor(String mods, String name, Object... args) {
+            super(mods, "", name, args);
+        }
+
+        @Override public String toString(){
+            this.type = "";
+            return super.toString();
+        }
+    }
+
+    public static class JLReturn{
+        public Object target;
+        public JLReturn(Object target){
+            this.target = target;
+        }
+        @Override public String toString(){
+            return "return " + target + ";";
+        }
+    }
+
+    public static class JLMethod{
+        public List<String> jdoc = new ArrayList<String>();
+        public Set<String> attrs = new TreeSet<String>();
+        public Set<String> mods = new TreeSet<String>();
+        public String type;
+        public String name;
+        public List<Object> args = new ArrayList<Object>();
+        public List<Object> body = new ArrayList<Object>();
+
+        public JLMethod(){}
+        public JLMethod(String mods, String type, String name, Object... args) {
+            this.mods.addAll(Arrays.asList(mods.split("\\s")));
+            this.type = type;
+            this.name = name;
+            this.args.addAll(Arrays.asList(args));
+        }
+
+        @Override public String toString(){
+            StringWriter out = new StringWriter();
+            if(jdoc.size() > 0){
+                out.append("\t/**\n");
+                out.append("\t * " + Fp.join("\n\t * ", jdoc));
+                out.append("\t */\n");
+            }
+            out.append("\t" + Fp.join(" ", attrs) + " " + Fp.join(" ", mods) + " " + type + " " + name + "(" + Fp.join(", ", args) + "){\n");
+            out.append("\t\t" + Fp.join("\n\t\t", body) + "\n");
+            out.append("\t}\n");
+            return out.toString();
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypeMerger.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypeMerger.java
new file mode 100644
index 0000000..cae05a3
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypeMerger.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.apple.internal.jobjc.generator.model.types.NType;
+import com.apple.internal.jobjc.generator.model.types.NType.NArray;
+import com.apple.internal.jobjc.generator.model.types.NType.NBitfield;
+import com.apple.internal.jobjc.generator.model.types.NType.NClass;
+import com.apple.internal.jobjc.generator.model.types.NType.NField;
+import com.apple.internal.jobjc.generator.model.types.NType.NObject;
+import com.apple.internal.jobjc.generator.model.types.NType.NPointer;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.internal.jobjc.generator.model.types.NType.NSelector;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.model.types.NType.NUnion;
+import com.apple.internal.jobjc.generator.model.types.NType.NUnknown;
+import com.apple.internal.jobjc.generator.model.types.NType.NVoid;
+import com.apple.internal.jobjc.generator.utils.Fp.Dispatcher;
+import com.apple.internal.jobjc.generator.utils.Fp.Map2;
+import com.apple.jobjc.JObjCRuntime.Width;
+
+/**
+ * Merges two NTypes. All merge does is fill out missing information. It doesn't choose the larger primitive when there's a conflict or anything like that.
+ *
+ * Example:
+ *<pre>
+ * a: {_NSRect={_NSPoint="x"f"y"f}"size"{_NSSize=ff}}
+ * b: {_NSRect="origin"{_NSPoint=ff}{_NSSize="width"f"height"f}}
+ * c: {_NSRect="origin"{_NSPoint="x"f"y"f}"size"{_NSSize="width"f"height"f}}
+ *</pre>
+ */
+public class NTypeMerger {
+    public static class MergeFailed extends RuntimeException{
+        public MergeFailed(String reason, Object a, Object b){
+            super(reason
+                    + " -- (" + a.getClass().getSimpleName() + ") a: " + a
+                    + " -- (" + b.getClass().getSimpleName() + ") b: " + b);
+        }
+    }
+
+    private static NTypeMerger INST = new NTypeMerger();
+    public static NTypeMerger inst(){ return INST; }
+
+    /**
+     * Merge a and b.
+     */
+    public NType merge(NType a, NType b) throws MergeFailed{
+        if(a!=null && b==null) return a;
+        if(a==null && b!=null) return b;
+        if(a==null && b==null) return null;
+        if(a.equals(b)) return a;
+        try {
+            return Dispatcher.dispatch(getClass(), this, "accept", a, b);
+        } catch (NoSuchMethodException e) {
+            throw new MergeFailed("a and b are of different NType", a, b);
+        }
+    }
+
+    private static Collection<String> emptyNames = Arrays.asList(null, "", "?");
+    /**
+     * Merge two identifiers:
+     *  - If they're equal, return one.
+     *  - If one is null, "", "?", return the other one.
+     *  - else throw MergeFailed
+     *
+     *  Exception: Due to a bug in BridgeSupport, this will return
+     *  a (the first arg) instead of throwing MergeFailed.
+     */
+    public String mergeName(String a, String b) throws MergeFailed{
+        if(QA.bothNullOrEquals(a, b)) return a;
+        if(emptyNames.contains(a) && !emptyNames.contains(b)) return b;
+        if(emptyNames.contains(b) && !emptyNames.contains(a)) return a;
+        return a; // HACK BS bug #5954843
+//        throw new MergeFailed("a and b have different names");
+    }
+
+    private Map mergeMap(Map a, Map b) throws MergeFailed{
+        if(a.equals(b)) return a;
+        Map ret = new HashMap();
+        Set keys = new HashSet(Fp.append(a.keySet(), b.keySet()));
+        for(Object key : keys){
+            Object ai = a.get(key);
+            Object bi = b.get(key);
+            if(ai != null && bi == null) ret.put(key, ai);
+            else if(ai == null && bi != null) ret.put(key, bi);
+            else if(ai.equals(bi)) ret.put(key, ai);
+            else throw new MergeFailed("a and b are different", ai, bi);
+        }
+        return ret;
+    }
+
+    public Map<Width,Integer> mergeSizeOf(Map<Width,Integer> a, Map<Width,Integer> b) throws MergeFailed{
+        return mergeMap(a, b);
+    }
+
+    public Map<Width,Integer> mergeOffset(Map<Width,Integer> a, Map<Width,Integer> b) throws MergeFailed{
+        return mergeMap(a, b);
+    }
+
+    //
+
+    private void mustEqual(NType a, NType b){
+        if(!a.equals(b)) throw new MergeFailed("a must equal b", a, b);
+    }
+
+    protected NType accept(NBitfield a, NBitfield b) {
+        mustEqual(a, b);
+        return a;
+    }
+
+    protected NType accept(NPrimitive a, NPrimitive b) {
+        mustEqual(a, b);
+        return a;
+    }
+
+    protected NType accept(NPointer a, NPointer b) {
+        return new NPointer(NTypeMerger.inst().merge(a.subject, b.subject));
+    }
+
+    // Merge structs
+
+    protected NField mergeNFields(NField a, NField b) {
+        return new NField(mergeName(a.name, b.name),
+                NTypeMerger.inst().merge(a.type, b.type),
+                mergeOffset(a.offset, b.offset));
+    }
+
+    protected NStruct mergeStructs(NStruct a, NStruct b){
+        if(a.fields.size() != b.fields.size())
+            throw new MergeFailed("a and b have different numbers of fields", a, b);
+
+        List<NField> fields = Fp.map2(new Map2<NField,NField,NField>(){
+            public NField apply(NField f32, NField f64) { return mergeNFields(f32, f64); }
+        }, a.fields, b.fields);
+
+        return new NStruct(mergeName(a.name, b.name),
+                fields, mergeSizeOf(a.sizeof, b.sizeof));
+    }
+
+    protected NType accept(NStruct a, NStruct b) {
+        return mergeStructs(a, b);
+    }
+
+    protected NType accept(NUnion a, NUnion b) {
+        NStruct nst = mergeStructs(a, b);
+        return new NUnion(nst.name, Fp.map(NUnion.zeroOffsets, nst.fields), nst.sizeof);
+    }
+
+    protected NType accept(NArray a, NArray b) {
+        if(a.length != b.length)
+            throw new MergeFailed("a and b are of different sizes", a, b);
+        return new NArray(a.length, NTypeMerger.inst().merge(a.type, b.type));
+    }
+
+    protected NType accept(NVoid a, NVoid b) { return NVoid.inst(); }
+    protected NType accept(NObject a, NObject b) { return NObject.inst(); }
+    protected NType accept(NClass a, NClass b) { return NClass.inst(); }
+    protected NType accept(NSelector a, NSelector b) { return NSelector.inst(); }
+    protected NType accept(NUnknown a, NUnknown b) { return NUnknown.inst(); }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypeParser.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypeParser.java
new file mode 100644
index 0000000..c90339b
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypeParser.java
@@ -0,0 +1,273 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.apple.internal.jobjc.generator.model.types.NType;
+import com.apple.internal.jobjc.generator.model.types.NType.NArray;
+import com.apple.internal.jobjc.generator.model.types.NType.NBitfield;
+import com.apple.internal.jobjc.generator.model.types.NType.NClass;
+import com.apple.internal.jobjc.generator.model.types.NType.NObject;
+import com.apple.internal.jobjc.generator.model.types.NType.NPointer;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.internal.jobjc.generator.model.types.NType.NSelector;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.model.types.NType.NUnion;
+import com.apple.internal.jobjc.generator.model.types.NType.NUnknown;
+import com.apple.internal.jobjc.generator.model.types.NType.NVoid;
+
+/**
+ * NTypeParser (Native Type Parser) parses type & type64 attributes from BridgeSupport.
+ *
+ * See Obj-C Language: Type Encodings
+ */
+public abstract class NTypeParser {
+    // ** Parser entry point
+
+    private static Map<String, NType> cached = new HashMap<String, NType>();
+    public static NType parseFrom(String s) {
+        if(!cached.containsKey(s)) cached.put(s, parseFrom(new StringStream(s)));
+        return cached.get(s);
+    }
+
+    // ** Parser driver
+
+    private static List<NTypeParser> PARSERS = new ArrayList<NTypeParser>(
+            Arrays.asList(new NBitfieldParser(), new NPrimitiveParser(), new NVoidParser(),
+            new NPointerParser(), new NStructParser(), new NUnionParser(),
+            new NObjectParser(), new NClassParser(), new NSelectorParser(),
+            new NArrayParser(), new NUnknownParser(), new NSpecifierParser()));
+
+    protected static NType parseFrom(StringStream ss) {
+        if(ss.left() == 0)
+            return null;
+        try{
+            for(NTypeParser nt : PARSERS)
+                if(nt.parsePossible(ss))
+                    return nt.parse(ss);
+        }
+        catch(RuntimeException x){
+            throw new RuntimeException("Exception while parsing '" + ss.remainingToString()
+                    + "' from '" + ss.toString() + "'", x);
+        }
+        throw new RuntimeException("Found no parser for '" + ss.remainingToString()
+                + "' from '" + ss.toString() + "'");
+    }
+
+    // ** Methods for parsers
+
+    protected abstract boolean parsePossible(StringStream ss);
+    protected abstract NType parse(StringStream ss);
+
+    // ** Individual parsers
+
+    public static class NBitfieldParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.left() >= 2 && ss.peekAt(0) == 'b' && Character.isDigit(ss.peekAt(1));
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            assert parsePossible(ss);
+            ss.eat('b');
+            return new NBitfield(Integer.parseInt(ss.readWhileDigits()));
+        }
+    }
+
+    public static class NPrimitiveParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return NPrimitive.CODES.contains(ss.peek());
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            assert parsePossible(ss);
+            return NPrimitive.inst(ss.read());
+        }
+    }
+
+    public static class NVoidParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.peek() == 'v';
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            ss.eat('v');
+            return NVoid.inst();
+        }
+    }
+
+    public static class NPointerParser extends NTypeParser{
+        private static NPointer CHAR_PTR = new NPointer(NPrimitive.inst('C'));
+
+        @Override protected boolean parsePossible(StringStream ss) {
+            return (ss.left() >= 2 && ss.peek() == '^') || (ss.peek() == '*');
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            if(ss.peek() == '*'){
+                ss.eat('*');
+                return CHAR_PTR;
+            }
+            else{
+                ss.eat('^');
+                return new NPointer(NTypeParser.parseFrom(ss));
+            }
+        }
+    }
+
+    public static class NStructParser extends NTypeParser{
+        protected char getOpen(){ return '{'; };
+        protected char getClose(){ return '}'; };
+
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.left() >= 2 && ss.peek() == getOpen();
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            assert parsePossible(ss);
+            // {_NSRect=
+            //   "origin"{_NSPoint="x"f"y"f}
+            //   "size"{_NSSize="width"f"height"f}}
+            ss.eat(getOpen());
+            String cname = ss.readUntilEither("=" + getClose());
+            List<NStruct.NField> fields = new ArrayList<NStruct.NField>();
+            if(ss.peek() == '='){
+                ss.eat('=');
+                while(ss.peek() != getClose()){
+                    String fname = "";
+                    if(ss.peek() == '"'){
+                        ss.eat('"');
+                        fname = ss.readUntil('"');
+                        ss.eat('"');
+                    }
+                    NType type = NTypeParser.parseFrom(ss);
+                    fields.add(new NStruct.NField(fname, type));
+                }
+            }
+            ss.eat(getClose());
+            return getNew(cname, fields);
+        }
+
+        protected NType getNew(String cname, List<NStruct.NField> fields){
+            return new NStruct(cname, fields);
+        }
+    }
+
+    // A Union is very much like a Struct.
+    public static class NUnionParser extends NStructParser{
+        @Override protected char getOpen(){ return '('; };
+
+        @Override protected char getClose(){ return ')'; };
+
+        @Override protected NType getNew(String cname, List<NStruct.NField> fields){
+            return new NUnion(cname, Fp.map(NUnion.zeroOffsets, fields));
+        }
+    }
+
+    public static class NArrayParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.peek() == '[';
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            ss.eat('[');
+            int size = Integer.parseInt(ss.readWhileDigits());
+            NType type = NTypeParser.parseFrom(ss);
+            ss.eat(']');
+            return new NArray(size, type);
+        }
+    }
+
+    public static class NObjectParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.peek() == '@';
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            ss.eat('@');
+            return NObject.inst();
+        }
+    }
+
+    public static class NClassParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.peek() == '#';
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            ss.eat('#');
+            return NClass.inst();
+        }
+    }
+
+    public static class NSelectorParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.peek() == ':';
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            ss.eat(':');
+            return NSelector.inst();
+        }
+    }
+
+    public static class NUnknownParser extends NTypeParser{
+        @Override protected boolean parsePossible(StringStream ss) {
+            return ss.peek() == '?';
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            ss.eat('?');
+            return NUnknown.inst();
+        }
+    }
+
+    /**
+     * Specifier     Encoding
+     * const         r
+     * in             n
+     * inout         N
+     * out             o
+     * bycopy         O
+     * oneway         V
+     */
+    public static class NSpecifierParser extends NTypeParser{
+        private static Collection<Character> SPECS = Arrays.asList('r', 'n', 'N', 'o', 'O', 'V');
+        @Override protected boolean parsePossible(StringStream ss) {
+            return SPECS.contains(ss.peek());
+        }
+
+        @Override protected NType parse(StringStream ss) {
+            assert parsePossible(ss);
+            ss.seek(); // XXX Just ignore specs for now and return the affected type.
+            return NTypeParser.parseFrom(ss);
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypePrinter.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypePrinter.java
new file mode 100644
index 0000000..8c612c6
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/NTypePrinter.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.io.StringWriter;
+
+import com.apple.internal.jobjc.generator.model.types.NType;
+import com.apple.internal.jobjc.generator.model.types.NType.NArray;
+import com.apple.internal.jobjc.generator.model.types.NType.NBitfield;
+import com.apple.internal.jobjc.generator.model.types.NType.NClass;
+import com.apple.internal.jobjc.generator.model.types.NType.NField;
+import com.apple.internal.jobjc.generator.model.types.NType.NObject;
+import com.apple.internal.jobjc.generator.model.types.NType.NPointer;
+import com.apple.internal.jobjc.generator.model.types.NType.NPrimitive;
+import com.apple.internal.jobjc.generator.model.types.NType.NSelector;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.model.types.NType.NUnion;
+import com.apple.internal.jobjc.generator.model.types.NType.NUnknown;
+import com.apple.internal.jobjc.generator.model.types.NType.NVoid;
+import com.apple.internal.jobjc.generator.utils.Fp.Dispatcher;
+
+/**
+ * Print an NType to the BridgeSupport encoding.
+ */
+public class NTypePrinter{
+    private static NTypePrinter INST = new NTypePrinter();
+    public static NTypePrinter inst(){ return INST; }
+
+    public String print(NType nt){
+        try {
+            return Dispatcher.dispatch(getClass(), this, "accept", nt);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected String accept(NBitfield nt) {
+        return "b" + nt.length;
+    }
+
+    protected String accept(NPrimitive nt) {
+        return Character.toString(nt.type);
+    }
+
+    protected String accept(NPointer nt) {
+        if(nt.subject instanceof NPrimitive && ((NPrimitive) nt.subject).type == 'C')
+            return "*";
+        else
+            return "^" + print(nt.subject);
+    }
+
+    protected String printStruct(NStruct nt, char open, char close){
+        StringWriter sw = new StringWriter();
+        sw.append(open);
+        sw.append(nt.name);
+        if(nt.fields.size() > 0){
+            sw.append('=');
+            for(NField f : nt.fields){
+                if(f.name != null && f.name.length() > 0)
+                    sw.append("\"" + f.name + "\"");
+                sw.append(print(f.type));
+            }
+        }
+        sw.append(close);
+        return sw.toString();
+    }
+
+    protected String accept(NStruct nt) {
+        return printStruct(nt, '{', '}');
+    }
+
+    protected String accept(NUnion nt) {
+        return printStruct(nt, '(', ')');
+    }
+
+    protected String accept(NArray nt) {
+        return "[" + nt.length + print(nt.type) + "]";
+    }
+
+    protected String accept(NObject nt) { return "@"; }
+    protected String accept(NVoid nt) { return "v"; }
+    protected String accept(NClass nt) { return "#"; }
+    protected String accept(NSelector nt) { return ":"; }
+    protected String accept(NUnknown nt) { return "?"; }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/ObjectInspector.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/ObjectInspector.java
new file mode 100644
index 0000000..6d3b12c
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/ObjectInspector.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.io.StringWriter;
+import java.lang.reflect.Field;
+
+public abstract class ObjectInspector {
+    /**
+     * @return  a string representation of object internals.
+     */
+    public static String inspect(Object obj) {
+        StringWriter sw = new StringWriter();
+        inspectForClass(obj, obj.getClass(), sw);
+        return sw.toString();
+    }
+
+    private static void inspectForClass(Object instance, Class clazz, StringWriter sw){
+        boolean willGoSuper = clazz.getSuperclass() != null && !clazz.getSuperclass().getName().equals("java.lang.Object");
+
+        sw.append(clazz.getSimpleName());
+        sw.append("{");
+        Field[] fs = clazz.getDeclaredFields();
+        for(int i = 0; i < fs.length; i++){
+            Field f = fs[i];
+            f.setAccessible(true);
+            sw.append(f.getName());
+            sw.append(": ");
+            try {
+                Object o = f.get(instance);
+                sw.append(o == null ? "null" : o.toString());
+            } catch (IllegalArgumentException ex) {
+                throw new RuntimeException(ex);
+            } catch (IllegalAccessException ex) {
+                throw new RuntimeException(ex);
+            }
+            if(i < fs.length - 1 || willGoSuper)
+                sw.append(", ");
+        }
+
+        if(willGoSuper){
+            sw.append("super: ");
+            inspectForClass(instance, clazz.getSuperclass(), sw);
+        }
+
+        sw.append("}");
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/QA.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/QA.java
new file mode 100644
index 0000000..b68a8ec3
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/QA.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import com.apple.internal.jobjc.generator.Utils;
+
+public class QA {
+    public static void nonNull(Object... os){
+        for(Object o : os) if(o == null) throw new NullPointerException(Utils.joinWComma(os));
+    }
+
+    public static boolean bothNullOrEquals(Object a, Object b) {
+        if(a == null && b == null) return true;
+        if(a == null || b == null) return false;
+        return a.equals(b);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StringStream.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StringStream.java
new file mode 100644
index 0000000..10140ef
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StringStream.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.io.StringWriter;
+
+/**
+ * Stream-like class backed by a string. Useful for parsers.
+ */
+public class StringStream{
+    private String data;
+    private int pos;
+
+    public StringStream(String s){
+        QA.nonNull(s);
+        this.data = s;
+        this.pos = 0;
+    }
+
+    /**
+     * Number of characters left.
+     */
+    public int left(){ return data.length() - pos; }
+
+    /**
+     * Are there any characters left?
+     */
+    public boolean atEOF(){ return left() <= 0; }
+
+    /**
+     * Read next character.
+     */
+    public char read(){ return data.charAt(pos++); }
+
+    /**
+     * Read n characters and return string.
+     */
+    public String readN(int n){
+        String s = data.substring(pos, pos + n);
+        pos += n;
+        return s;
+    }
+
+    /**
+     * Read until the next char is c, and return the string.
+     */
+    public String readUntil(char c){
+        int ix = data.indexOf(c, pos);
+        if(ix == -1) throw new RuntimeException("readUntil did not find character '" + c + "'");
+        return readN(data.indexOf(c, pos) - pos);
+    }
+
+    /**
+     * Read until the next char is one in s, and return the string.
+     */
+    public String readUntilEither(String s) {
+        int ix = Integer.MAX_VALUE;
+
+        for(char c : s.toCharArray()){
+            int ixx = data.indexOf(c, pos);
+            if(ixx >= 0 && ixx < ix)
+                ix = ixx;
+        }
+
+        if(ix == -1) throw new RuntimeException("readUntilEither did not find any character in '" + s + "'");
+        return readN(ix - pos);
+    }
+
+    public String readWhile(String s) {
+        StringWriter sw = new StringWriter();
+        while(s.indexOf(peek()) != -1)
+            sw.append(read());
+        return sw.toString();
+    }
+
+    public String readWhileDigits() {
+        return readWhile("0123456789");
+    }
+
+    /**
+     * @return the nth char from the current position.
+     */
+    public char peekAt(int n){ return data.charAt(pos + n); }
+
+    /**
+     * @return the next n chars.
+     */
+    public String peekN(int n){ return data.substring(pos, pos + n); }
+
+    /**
+     * @return the next char.
+     */
+    public char peek(){ return peekAt(0); }
+
+    /**
+     * Skip n chars ahead.
+     */
+    public void seekN(int n){ pos += n; }
+
+    /**
+     * Skip 1 char ahead.
+     */
+    public void seek(){ seekN(1); }
+
+    /**
+     * If the next character is c, seek over it. Otherwise throw RuntimeException.
+     */
+    public void eat(char c) {
+        if(peek() != c) throw new RuntimeException("Parser expected '" + c + "' but got '" + peek() + "'.");
+        seek();
+    }
+
+    /**
+     * If the next characters are the same as those in s, seek over them. Otherwise throw RuntimeException.
+     */
+    public void eat(String s) {
+        String pn = peekN(s.length());
+        if(!pn.equals(s)) throw new RuntimeException("Parser expected '" + s + "' but got '" + pn + "'.");
+        seekN(s.length());
+    }
+
+    @Override
+    public String toString(){
+        return data;
+    }
+
+    /**
+     * @return the remaining characters as a String.
+     */
+    public String remainingToString() {
+        return data.substring(pos);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StructOffsetResolver.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StructOffsetResolver.java
new file mode 100644
index 0000000..5807de5
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StructOffsetResolver.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.apple.internal.jobjc.generator.Utils;
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.model.Struct;
+import com.apple.internal.jobjc.generator.model.types.NType;
+import com.apple.internal.jobjc.generator.model.types.TypeCache;
+import com.apple.internal.jobjc.generator.model.types.NType.NField;
+import com.apple.internal.jobjc.generator.model.types.NType.NStruct;
+import com.apple.internal.jobjc.generator.utils.Fp.Map1;
+import com.apple.jobjc.JObjCRuntime.Width;
+import java.util.Date;
+
+/**
+ * Takes a framework, compiles a native source file with all its structs,
+ * and figures out their sizes and field offsets.
+ */
+public class StructOffsetResolver {
+    public void resolve(Collection<Framework> fws){
+        try {
+            _resolve(fws);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected void _resolve(final Collection<Framework> fws) throws Exception{
+        for(final Framework fw : fws){
+            for(final Width width : Width.values()){
+                System.out.println("SOR -- Getting Struct offsets @" + width + " for " + fw.name);
+                String nativeSrc = generateFileForFramework(fw, width);
+                String executable = compileObjC(nativeSrc, width);
+                execute(executable, new Map1<String,Object>(){
+                    public Object apply(String ln) {
+                        try {
+                            processLine(ln, fws, width);
+                            return null;
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                    }
+                });
+            }
+        }
+    }
+
+    static Set<String> alwaysHeaders_shared = new TreeSet<String>(Arrays.asList(
+            "<Cocoa/Cocoa.h>",
+    "\"/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/HIToolbox.h\""));
+    static Map<Width,Set<String>> alwaysHeaders = Fp.litMap(
+            Width.W32, alwaysHeaders_shared,
+            Width.W64, alwaysHeaders_shared);
+
+    static Set<String> bannedHeaders_shared = new TreeSet<String>(Arrays.asList(
+            "NSJavaSetup.h", "IMKInputController.h", "NSSimpleHorizontalTypesetter.h", "NSSpellServer.h", "IMKServer.h", "IKImageBrowserCell.h"));
+    static Map<Width,Set<String>> bannedHeaders = Fp.litMap(
+            Width.W32, bannedHeaders_shared,
+            Width.W64, Fp.appendSet(bannedHeaders_shared,
+                    Arrays.asList("npapi.h", "npruntime.h", "npfunctions.h")));
+
+    // We can cache the last accessed framework because, 99% of the time,
+    // the caller will ask for the same one, over and over again.
+    protected Framework cachedFw;
+    protected Framework findFrameworkByName(Collection<Framework> fws, String name){
+        if(cachedFw != null && cachedFw.name.equals(name))
+            return cachedFw;
+        cachedFw = null;
+        for(Framework fw : fws)
+            if(fw.name.equals(name)){
+                cachedFw = fw;
+                break;
+            }
+        return cachedFw;
+    }
+
+    protected void processLine(String ln, Collection<Framework> fws, Width arch) throws Exception{
+        System.out.println("\tSOR '" + ln + "'");
+        if(ln.trim().length() == 0) return;
+        Pattern stinfo = Pattern.compile("^(.*) (.*):(\\d+).*$");
+        Matcher m = stinfo.matcher(ln);
+        if(!m.matches()) throw new RuntimeException("Failed to parse line from exec: " + ln);
+        String fwname = m.group(1);
+        String stname = m.group(2);
+        int stsize = Integer.parseInt(m.group(3));
+
+        Framework fw = findFrameworkByName(fws, fwname);
+
+        Struct st = fw.getStructByName(stname);
+        NStruct nst = wget(arch, st.type.type32, st.type.type64);
+        nst.sizeof.put(arch, stsize);
+
+//        System.out.println(st.name + " : " + stsize);
+
+        Pattern finfo = Pattern.compile(" (-?\\d+)");
+        Matcher fm = finfo.matcher(ln);
+        int fi = 0;
+        while(fm.find()){
+            NField sf = nst.fields.get(fi++);
+            sf.offset.put(arch, Integer.parseInt(fm.group(1)));
+//            System.out.println("\t" + sf.name + " : " + off);
+        }
+
+        TypeCache.inst().pingType(st.type);
+    }
+
+    /**
+     * Generates Objective-C file and returns absolute path name.
+     */
+    private String generateFileForFramework(Framework fw, Width arch) throws Exception{
+        File tempfile = File.createTempFile("JObjC-SOR-" + fw.name + "-" + arch + "-", ".mm");
+        PrintWriter out = new PrintWriter(new FileWriter(tempfile));
+        out.println("#include<iostream>");
+        printHeaderLines(fw, arch, out);
+        out.println("");
+        out.println("int main(int argc, char** argv){");
+        printStructInfos(fw, arch, out);
+        out.println("\treturn 0;");
+        out.println("}");
+        out.close();
+        return tempfile.getAbsolutePath();
+    }
+
+    protected void execute(String executable, Fp.Map1<String,Object> lineProcessor) throws Exception {
+//        System.out.println(">>>> Executing " + new Date().toString());
+        Process p = Runtime.getRuntime().exec(new String[]{executable});
+
+        if(lineProcessor != null){
+            BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            String line;
+            while ((line = stdout.readLine()) != null)
+                lineProcessor.apply(line);
+            stdout.close();
+        }
+        p.waitFor();
+        if(p.exitValue() != 0)
+            throw new RuntimeException(executable + " did not execute successfully: " + p.exitValue());
+    }
+
+    private static Map<Width,String> gccFlag = Fp.litMap(Width.W32, "-m32", Width.W64, "-m64");
+
+    static boolean isDone(Process p){
+        try{
+            p.exitValue();
+            return true;
+        }
+        catch(Exception x){
+            return false;
+        }
+    }
+
+    protected static String compileObjC(String nativeSrc, Width arch) throws Exception {
+        String execPath = nativeSrc.replace(".mm", "");
+        Process p = Runtime.getRuntime().exec(new String[]{
+                "llvm-g++", "-Wall", gccFlag.get(arch), "-ObjC++", "-framework", "Foundation", "-o", execPath, nativeSrc
+        });
+        BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+        while(!isDone(p)){
+            while(stdout.ready()) System.out.println(stdout.readLine());
+            while(stderr.ready()) System.out.println(stderr.readLine());
+        }
+        p.waitFor();
+        while(stdout.ready() || stderr.ready()){
+            if(stdout.ready()) System.out.println(stdout.readLine());
+            if(stderr.ready()) System.out.println(stderr.readLine());
+        }
+        if(p.exitValue() != 0)
+            throw new RuntimeException("gcc did not compile '" + nativeSrc + "' successfully: " + p.exitValue());
+        return execPath;
+    }
+
+    static void printStructInfos(Framework fw, Width arch, PrintWriter out){
+        for(Struct st : fw.structs){
+            NStruct nst = wget(arch, st.type.type32, st.type.type64);
+            out.println("std::cout << \"" + fw.name + " " + st.name + "\" << ':' << sizeof("+st.name+")");
+            for(NField sf : nst.fields){
+                out.print("\t<< ' ' << ");
+                out.println(sf.type instanceof NType.NBitfield
+                          ? "-1"
+                          : "offsetof("+st.name+","+sf.name+")");
+            }
+            out.println("\t<< std::endl;");
+        }
+    }
+
+    static void printHeaderLines(Framework fw, Width arch, PrintWriter out) throws Exception {
+        Collection<String> always = alwaysHeaders.get(arch);
+        Collection<String> banned = bannedHeaders.get(arch);
+        out.println("#define COREFOUNDATION_CFPLUGINCOM_SEPARATE 0");
+        for(String header : always)
+            out.println("#import " + header);
+
+        out.println("#undef COREFOUNDATION_CFPLUGINCOM_SEPARATE");
+        String umbrella = fw.path + "/Headers/" + fw.name;
+        if(new File(umbrella).exists())
+            out.println("#import \"" + umbrella + "\"");
+
+        for(File header : getHeaders(fw))
+            if(!banned.contains(header.getName()))
+                out.println("#import \"" + header.getAbsolutePath() + "\"");
+    }
+
+    static <A,B> A wget(Width arch, B x32, B x64){
+        switch(arch){
+        case W32: return (A) x32;
+        case W64: return (A) x64;
+        default: throw new RuntimeException();
+        }
+    }
+
+    /**
+     * Gets the absolute path to every header in FOO.framework/Headers
+     */
+    static Collection<File> getHeaders(Framework fw) throws Exception {
+        String hpath = fw.path + "/Headers";
+        return Utils.find(new File(hpath), "^.*\\.h$", "");
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StructOffsetResolverBigBang.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StructOffsetResolverBigBang.java
new file mode 100644
index 0000000..1a28f66
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/internal/jobjc/generator/utils/StructOffsetResolverBigBang.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.internal.jobjc.generator.utils;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.Collection;
+
+import com.apple.internal.jobjc.generator.model.Framework;
+import com.apple.internal.jobjc.generator.utils.Fp.Map1;
+import com.apple.jobjc.JObjCRuntime.Width;
+
+/**
+ * Takes a framework, compiles a native source file with all its structs,
+ * and figures out their sizes and field offsets.
+ *
+ * BigBang significantly speeds up the process by
+ * compiling all frameworks as one big Objective-C file.
+ */
+public class StructOffsetResolverBigBang extends StructOffsetResolver{
+
+    @Override protected void _resolve(final Collection<Framework> fws) throws Exception{
+        for(final Width arch : Width.values()){
+            System.out.println("SORBB -- Getting Struct offsets @" + arch.toString());
+            String nativeSrc = generateFileForFrameworks(fws, arch);
+            String executable = compileObjC(nativeSrc, arch);
+            execute(executable, new Map1<String,Object>(){
+                public Object apply(String ln) {
+                    try {
+                        processLine(ln, fws, arch);
+                        return null;
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            });
+        }
+    }
+
+    /**
+     * Generates Objective-C file and returns absolute path name.
+     */
+    protected String generateFileForFrameworks(final Collection<Framework> fws, final Width arch) throws Exception{
+        File tempfile = File.createTempFile("JObjC-SORBB-" + arch + "-", ".mm");
+        PrintWriter out = new PrintWriter(new FileWriter(tempfile));
+
+        out.println("#include<iostream>");
+        for(Framework fw : fws) printHeaderLines(fw, arch, out);
+        out.println("int main(int argc, char** argv){");
+        for(Framework fw : fws) printStructInfos(fw, arch, out);
+        out.println("\treturn 0;");
+        out.println("}");
+
+        out.close();
+        return tempfile.getAbsolutePath();
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/jobjc/SuperClassExtractor.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/jobjc/SuperClassExtractor.java
new file mode 100644
index 0000000..1a827fd
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/jobjc/SuperClassExtractor.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.util.Map;
+
+import com.apple.internal.jobjc.generator.model.Clazz;
+
+/*
+ * Isolating all the reflection trickery to hijack the runtime into giving up its secrets
+ * without actually having a full working version of JObjC. Below is a bunch of evil reflection,
+ * but it allows the generated output to have a cleaner design.
+ */
+public class SuperClassExtractor {
+    public static Clazz getSuperClassFor(final String className, final MacOSXFramework nativeFramework, final Map<String, Clazz> allClasses) throws Throwable {
+        final NSClass<ID> nativeClass = new NSClass<ID>(className, nativeFramework.getRuntime());
+        final NSClass<? extends ID> nativeSuperClass = UnsafeRuntimeAccess.getSuperClass(nativeClass);
+        final String superClassName = UnsafeRuntimeAccess.getClassNameFor(nativeSuperClass);
+        if ("nil".equals(superClassName)) return null;
+
+        final Clazz superClazz = allClasses.get(superClassName);
+        if (superClazz != null) return superClazz;
+
+        final Clazz superClazzX = getSuperClassFor(superClassName, nativeFramework, allClasses);
+        System.out.print("[Warning] class \"" + superClassName + "\" not found in bridge support files, ");
+        System.out.println("using \"" + superClazzX.name + "\" as superclass for \"" + className + "\"");
+        return superClazzX;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/jobjc/UnsafeRuntimeAccess.java b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/jobjc/UnsafeRuntimeAccess.java
new file mode 100644
index 0000000..59813a6
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/generator/java/com/apple/jobjc/UnsafeRuntimeAccess.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Invoke.FunCall;
+import com.apple.jobjc.Invoke.MsgSend;
+
+public class UnsafeRuntimeAccess {
+    public static NativeArgumentBuffer getNativeBuffer() {
+        return NativeArgumentBuffer.getThreadLocalBuffer(JObjCRuntime.getInstance());
+    }
+
+    public static String getClassNameFor(final long obj) {
+        return NSClass.getClassNameOfClass(obj);
+    }
+
+    public static String getClassNameFor(final NSClass cls) {
+        return NSClass.getClassNameOfClass(cls.ptr);
+    }
+
+    public static NSClass<?> getSuperClass(final NSClass<? extends ID> clazz) {
+        return clazz.getSuperClass();
+    }
+
+    public static String getDescriptionForPtr(final long objPtr) {
+        return ID.getNativeDescription(objPtr);
+    }
+
+    public static MacOSXFramework getFramework(final String[] frameworkLibs) {
+        return new MacOSXFramework(JObjCRuntime.getInstance(), frameworkLibs);
+    }
+
+    public static FunCall createFunCall(final MacOSXFramework framework, final String fxnName, final Coder returnCoder, final Coder ... argCoders) {
+        return new FunCall(framework, fxnName, returnCoder, argCoders);
+    }
+
+    public static MsgSend createMsgSend(final NSClass<?> clazz, final String selName, final Coder returnCoder, final Coder ... argCoders) {
+        return new MsgSend(clazz.getRuntime(), selName, returnCoder, argCoders);
+    }
+
+    public static NSClass<ID> getNSClass(final MacOSXFramework framework, final String name) {
+        return new NSClass<ID>(name, framework.getRuntime());
+    }
+
+    public static long getObjPtr(final ID obj) {
+        return obj.ptr;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/runtime-additions/java/com/apple/jobjc/Utils.java b/jdk/src/macosx/native/jobjc/src/runtime-additions/java/com/apple/jobjc/Utils.java
new file mode 100644
index 0000000..8d62113
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/runtime-additions/java/com/apple/jobjc/Utils.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.util.concurrent.Callable;
+
+import com.apple.jobjc.foundation.NSNumber;
+import com.apple.jobjc.foundation.NSString;
+
+public class Utils {
+    JObjCRuntime runtime;
+    Utils(JObjCRuntime runtime){ this.runtime = runtime; }
+
+    private static Utils utils;
+    public static Utils get() {
+        JObjCRuntime runtime = JObjCRuntime.getInstance(); // enforce security check
+        return utils != null ? utils : (utils = new Utils(runtime));
+    }
+
+    private Strings strings_;
+    public Strings strings() {
+        return strings_ != null ? strings_ : (strings_ = new Strings(runtime));
+    }
+
+    private Numbers numbers_;
+    public Numbers numbers() {
+        return numbers_ != null ? numbers_ : (numbers_ = new Numbers(runtime));
+    }
+
+    private Threads threads_;
+    public Threads threads() {
+        return threads_ != null ? threads_ : (threads_ = new Threads(runtime));
+    }
+
+    public static class Strings {
+        private static native long getNativeNSStringForJavaString(final String javaString);
+        private static native String getNativeJavaStringForNSString(final long nsString);
+
+        JObjCRuntime runtime;
+        Strings(JObjCRuntime runtime) { this.runtime = runtime; }
+
+        public NSString nsString(final String str) {
+            if (str == null) return null;
+            final long nsString = getNativeNSStringForJavaString(str);
+            return ID.createNewObjCObjectForClass(NSString.class, nsString, runtime);
+        }
+
+        public String javaString(final NSString str) {
+            if (str == null) return null;
+            return getNativeJavaStringForNSString(((ID)str).ptr);
+        }
+
+//        static public CString cStringForJavaString(final String str) {
+//            return null;
+//        }
+    }
+
+    public static class Numbers {
+        private static native long getNativeNSNumberForJavaNumber(final Number num);
+        private static native Number getNativeJavaNumberForNSNumber(final long num);
+
+        JObjCRuntime runtime;
+        Numbers(JObjCRuntime runtime) { this.runtime = runtime; }
+
+        public NSNumber nsNumber(final Number num) {
+            if (num == null) return null;
+            final long nsNumber = getNativeNSNumberForJavaNumber(num);
+            return ID.createNewObjCObjectForClass(NSNumber.class, nsNumber, runtime);
+        }
+
+        public Number javaNumber(final NSNumber num) {
+            if (num == null) return null;
+            return getNativeJavaNumberForNSNumber(((ID)num).ptr);
+        }
+    }
+
+    public static class Threads {
+        private static native void performRunnableOnMainThread(final Runnable runnable, final boolean wait);
+        private static native <V> V performCallableOnMainThread(final Callable<V> callable) throws Exception;
+
+        JObjCRuntime runtime;
+        Threads(JObjCRuntime runtime) { this.runtime = runtime; }
+
+        /**
+         * Perform callable on main thread. Exceptions that are thrown on the main thread are ignored.
+         */
+        public void performOnMainThread(final Runnable runnable, final boolean wait) {
+            performRunnableOnMainThread(runnable, wait);
+        }
+
+        /**
+         * Perform callable on main thread, block until done, and return the result.
+         * This also catches any exceptions on the main thread, brings them back and throws them to the caller.
+         */
+        public <V> V performOnMainThread(final Callable<V> callable) throws Exception{
+            return performCallableOnMainThread(callable);
+        }
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeNumber.m b/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeNumber.m
new file mode 100644
index 0000000..096919e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeNumber.m
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_Utils_Numbers.h"
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ * Class:     com_apple_jobjc_Utils_Numbers
+ * Method:    getNativeNSNumberForJavaNumber
+ * Signature: (Ljava/lang/Number;)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_Utils_00024Numbers_getNativeNSNumberForJavaNumber
+(JNIEnv *env, jclass clazz, jobject javaNumber)
+{
+    return ptr_to_jlong(JNFJavaToNSNumber(env, javaNumber));
+}
+
+/*
+ * Class:     com_apple_jobjc_Utils_Numbers
+ * Method:    getNativeJavaNumberForNSNumber
+ * Signature: (J)Ljava/lang/Number;
+ */
+JNIEXPORT jobject JNICALL Java_com_apple_jobjc_Utils_00024Numbers_getNativeJavaNumberForNSNumber
+(JNIEnv *env, jclass clazz, jlong nativeNumber)
+{
+    return JNFNSToJavaNumber(env, (NSNumber *)jlong_to_ptr(nativeNumber));
+}
diff --git a/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeString.m b/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeString.m
new file mode 100644
index 0000000..5a9b552
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeString.m
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_Utils_Strings.h"
+
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ * Class:     com_apple_jobjc_Utils_Strings
+ * Method:    getNativeNSStringForJavaString
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_Utils_00024Strings_getNativeNSStringForJavaString
+(JNIEnv *env, jclass clazz, jstring javaString)
+{
+    return ptr_to_jlong(JNFJavaToNSString(env, javaString));
+}
+
+/*
+ * Class:     com_apple_jobjc_Utils_Strings
+ * Method:    getNativeJavaStringForNSString
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_apple_jobjc_Utils_00024Strings_getNativeJavaStringForNSString
+(JNIEnv *env, jclass clazz, jlong nativeString)
+{
+    return JNFNSToJavaString(env, (NSString *)jlong_to_ptr(nativeString));
+}
diff --git a/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeThread.m b/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeThread.m
new file mode 100644
index 0000000..fc19d20
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/runtime-additions/native/NativeThread.m
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_apple_jobjc_Utils_Threads.h"
+
+#import <AppKit/AppKit.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+@interface JObjCCallable : NSObject {
+    @public jobject returnValue;
+    @public jthrowable exception;
+}
+@property jobject returnValue;
+@property jthrowable exception;
+- (void) performCallable:(JNFJObjectWrapper *)callableWrapper;
+@end
+
+/*
+ * Class:     com_apple_jobjc_Utils_Threads
+ * Method:    performRunnableOnMainThreadNative
+ * Signature: (Ljava/lang/Runnable;Z)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_jobjc_Utils_00024Threads_performRunnableOnMainThread
+(JNIEnv *env, jclass clazz, jobject runnable, jboolean jWaitUntilDone)
+{
+JNF_COCOA_ENTER(env);
+    [JNFRunLoop performOnMainThreadWaiting:jWaitUntilDone
+                                 withBlock:[JNFRunnable blockWithRunnable:runnable
+                                                                  withEnv:env]];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_jobjc_Utils_Threads
+ * Method:    performCallableOnMainThreadNative
+ * Signature: (Ljava/util/concurrent/Callable;)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_com_apple_jobjc_Utils_00024Threads_performCallableOnMainThread
+(JNIEnv *env, jclass clazz, jobject callable)
+{
+    jobject returnValue = NULL;
+
+JNF_COCOA_ENTER(env);
+    JNFJObjectWrapper *callableWrapper = [[JNFJObjectWrapper alloc] initWithJObject:callable withEnv:env];
+    JObjCCallable *ncallable = [JObjCCallable alloc];
+
+    [ncallable performSelectorOnMainThread:@selector(performCallable:)
+                                withObject:callableWrapper
+                             waitUntilDone:true];
+
+    returnValue = ncallable.returnValue;
+    jthrowable exception = ncallable.exception;
+
+    [ncallable release];
+    if(exception) (*env)->Throw(env, exception);
+
+JNF_COCOA_EXIT(env);
+
+    return returnValue;
+}
+
+
+@implementation JObjCCallable
+@synthesize returnValue;
+@synthesize exception;
+
+- (void) performCallable:(JNFJObjectWrapper *)callableWrapper {
+    static JNF_CLASS_CACHE(jc_Callable, "java/util/concurrent/Callable");
+    static JNF_MEMBER_CACHE(jm_Callable_call, jc_Callable, "call", "()Ljava/lang/Object;");
+
+    JNFThreadContext threadWasAttached = JNFThreadDetachOnThreadDeath;
+    JNIEnv *env = JNFObtainEnv(&threadWasAttached);
+    jobject callable = [callableWrapper jObject];
+
+    @try{
+        self.returnValue = JNFCallObjectMethod(env, callable, jm_Callable_call);
+    } @catch (JNFException *x) {
+        [x raiseToJava:env];
+    }
+
+    self.exception = (*env)->ExceptionOccurred(env);
+    (*env)->ExceptionClear(env);
+
+    [callableWrapper release];
+    JNFReleaseEnv(env, &threadWasAttached);
+}
+
+@end
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BaseBench.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BaseBench.java
new file mode 100644
index 0000000..67d96c1
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BaseBench.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import sun.misc.Unsafe;
+
+public class BaseBench extends PooledTestCase {
+    protected final static JObjCRuntime RUNTIME = JObjCRuntime.getInstance();
+    protected final static JObjC JOBJC = JObjC.getInstance();
+    protected final static Unsafe UNSAFE = JObjCRuntime.getInstance().unsafe;
+    protected final static NativeArgumentBuffer ARGS = JObjCRuntime.getInstance().getThreadLocalState();
+
+    public abstract static class Task{
+        final String name;
+        public Task(String name){ this.name = name; }
+        public abstract void run();
+    }
+
+    public void bench(final String title, final long warmup, final long runs, final long iterations, final Task... tasks){
+        final long[] runtimes = new long[tasks.length];
+
+        for(int t = 0; t < tasks.length; ++t){
+            long runtime = 0;
+            for(int i = 0; i < warmup; ++i)
+                singleBench(iterations, tasks[t]);
+            for(int i = 0; i < runs; ++i)
+                runtime = runtime + singleBench(iterations, tasks[t]);
+            runtimes[t] = runtime;
+        }
+
+        final float[] relatives = new float[tasks.length];
+
+        for(int t = 0; t < tasks.length; ++t)
+            relatives[t] = ((float) runtimes[t] / (float) runs);
+
+        float min = relatives[0];
+        for(float t : relatives)
+            if(t < min)
+                min = t;
+
+        for(int t = 0; t < tasks.length; ++t)
+            relatives[t] = relatives[t] / min;
+
+        System.out.format("\n* %1$s\n", title);
+        for(int t = 0; t < tasks.length; ++t)
+            System.out.format("%1$60s : %2$.1f\n", tasks[t].name, relatives[t]);
+    }
+
+    public long singleBench(final long iterations, final Task task){
+        long start = System.currentTimeMillis();
+        for(long i = 0; i < iterations; ++i)
+            task.run();
+        long end = System.currentTimeMillis();
+        return end - start;
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchFunCall.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchFunCall.java
new file mode 100644
index 0000000..95e003a
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchFunCall.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Invoke.FunCall;
+import com.apple.jobjc.PrimitiveCoder.DoubleCoder;
+
+public final class BenchFunCall extends BaseBench{
+    final static int ITERS  = 1000;
+    final static FunCall fc = new FunCall(JObjCRuntime.getInstance(), "sin", DoubleCoder.INST, DoubleCoder.INST);
+    final static double ARG = 3.14159265 / 2.0;
+    final static double RET = 1.0;
+
+    private static native double jniSin(double arg);
+
+    public void testBench(){
+        this.bench("Calling functions", 5, 3, 10000L,
+
+                new Task("JNI Invoke"){
+            @Override public void run() {
+                for(int i = 0; i < ITERS; ++i)
+                    jniSin(ARG);
+            }},
+
+            new Task("JObjC FunCall"){
+                @Override public void run() {
+                    for(int i = 0; i < ITERS; ++i){
+                        fc.init(ARGS);
+                        DoubleCoder.INST.push(ARGS, ARG);
+                        fc.invoke(ARGS);
+                        DoubleCoder.INST.pop(ARGS);
+                    }
+                }},
+
+                new Task("JObjC FunCall (inlined)"){
+                    @Override public void run() {
+                        for(int i = 0; i < ITERS; ++i){
+                            // init
+                            ARGS.argPtrsPtr = ARGS.buffer.bufferPtr;
+                            ARGS.argValuesPtr = ARGS.buffer.bufferPtr + 256;
+                            // push double
+                            //// push arg ptr
+                            if(JObjCRuntime.IS64)
+                                UNSAFE.putLong(ARGS.argPtrsPtr, ARGS.argValuesPtr);
+                            else
+                                UNSAFE.putInt(ARGS.argPtrsPtr, (int) ARGS.argValuesPtr);
+                            ARGS.argPtrsPtr += JObjCRuntime.PTR_LEN;
+                            //// push arg value
+                            UNSAFE.putDouble(ARGS.argValuesPtr, ARG);
+                            ARGS.argValuesPtr += 8;
+                            // invoke
+                            FunCall.invoke(fc.cif.cif.bufferPtr, fc.fxnPtr, ARGS.retValPtr, ARGS.buffer.bufferPtr);
+                            // pop
+                            UNSAFE.getDouble(ARGS.retValPtr);
+                        }
+                    }}
+        );
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchIDPop.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchIDPop.java
new file mode 100644
index 0000000..37b243e
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchIDPop.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.foundation.FoundationFramework;
+import com.apple.jobjc.foundation.NSString;
+
+public class BenchIDPop extends BaseBench{
+    static native long jniNSStringAlloc();
+    static native long jniNSStringAllocAndRetain();
+    static native long jniNSStringCached();
+    static native void jniCFRetain(long x);
+    static native void jniCFRelease(long x);
+
+    final static int ITERS = 1000;
+    final static FoundationFramework FND = JOBJC.Foundation();
+
+    private static class LongWrap{
+        long l;
+        public LongWrap(long l){ this.l = l; }
+    }
+
+    public void testIt(){
+        bench("Alloc, retain, pop a new NSString", 2, 3, 2000,
+                new Task("jniNSStringAllocAndRetain()"){
+            @Override public void run() {
+                for(int i = 0; i < ITERS; i++)
+                    jniNSStringAllocAndRetain();
+            }},
+
+            new Task("new LongWrap(jniNSStringAllocAndRetain())"){
+                @Override public void run() {
+                    for(int i = 0; i < ITERS; i++)
+                        new LongWrap(jniNSStringAllocAndRetain());
+                }},
+
+                new Task("FND.NSString().alloc()"){
+                    @Override public void run() {
+                        for(int i = 0; i < ITERS; i++)
+                            FND.NSString().alloc();
+                    }},
+
+                    new Task("new NSString(jniNSStringAlloc(), RUNTIME)"){
+                        @Override public void run() {
+                            for(int i = 0; i < ITERS; i++)
+                                new NSString(jniNSStringAlloc(), RUNTIME);
+                        }}
+        );
+
+        final long nsstringPtr = jniNSStringAlloc();
+
+        bench("Get and hold an existing object", 2, 3, 2000,
+                new Task("jniCFRetain(nsstringPtr)"){
+            @Override public void run() {
+                for(int i = 0; i < ITERS; i++)
+                    jniCFRetain(nsstringPtr);
+            }},
+
+            new Task("jniCFRetain(new LongWrap(nsstringPtr).l"){
+                @Override public void run() {
+                    for(int i = 0; i < ITERS; i++)
+                        jniCFRetain(new LongWrap(nsstringPtr).l);
+                }},
+
+                new Task("ID.getInstance(nsstringPtr, RUNTIME)"){
+                    @Override public void run() {
+                        for(int i = 0; i < ITERS; i++)
+                            ID.getInstance(nsstringPtr, RUNTIME);
+                    }}
+        );
+    }
+
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchStructCoding.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchStructCoding.java
new file mode 100644
index 0000000..2485e5f
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchStructCoding.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Coder.StructCoder;
+import com.apple.jobjc.Invoke.FunCall;
+import com.apple.jobjc.foundation.FoundationFramework;
+import com.apple.jobjc.foundation.NSRect;
+
+public class BenchStructCoding extends BaseBench {
+    final static FoundationFramework FND = JOBJC.Foundation();
+    final static int ITERS = 1000;
+    final static PrimitiveCoder CODER = com.apple.jobjc.MixedPrimitiveCoder.FloatDoubleCoder;
+    final static StructCoder RCODER = NSRect.getStructCoder();
+    final static FunCall nsMakePoint =
+        new com.apple.jobjc.Invoke.FunCall(FND, "NSMakeRect", com.apple.jobjc.foundation.NSRect.getStructCoder(),
+                com.apple.jobjc.MixedPrimitiveCoder.FloatDoubleCoder,
+                com.apple.jobjc.MixedPrimitiveCoder.FloatDoubleCoder,
+                com.apple.jobjc.MixedPrimitiveCoder.FloatDoubleCoder,
+                com.apple.jobjc.MixedPrimitiveCoder.FloatDoubleCoder);
+
+    public void testFoo(){
+        bench("NSMakeRect", 3, 3, 10,
+                new Task("FND.NSMakeRect"){
+            @Override public void run() {
+                for(int i = 0; i < ITERS; ++i){
+                    NSRect s = FND.NSMakeRect(0, 1, 2, 3);
+//                    assertEquals(1.0D, s.origin().y());
+                }
+            }},
+
+            new Task("nsMakeRect.invoke(..., s)"){
+                @Override public void run() {
+                    for(int i = 0; i < ITERS; ++i){
+                        nsMakePoint.init(ARGS);
+                        CODER.push(ARGS, 0.0D);
+                        CODER.push(ARGS, 1.0D);
+                        CODER.push(ARGS, 2.0D);
+                        CODER.push(ARGS, 3.0D);
+                        NSRect s = FND.makeNSRect();
+                        nsMakePoint.invoke(ARGS, s);
+//                        assertEquals(1.0D, s.origin().y());
+                    }
+                }},
+
+                new Task("nsMakeRect.invoke(..); NSRect r = pop(..);"){
+                    @Override public void run() {
+                        for(int i = 0; i < ITERS; ++i){
+                            nsMakePoint.init(ARGS);
+                            CODER.push(ARGS, 0.0D);
+                            CODER.push(ARGS, 1.0D);
+                            CODER.push(ARGS, 2.0D);
+                            CODER.push(ARGS, 3.0D);
+                            nsMakePoint.invoke(ARGS);
+                            NSRect s = (NSRect) RCODER.pop(ARGS);
+//                            assertEquals(1.0D, s.origin().y());
+                        }
+                    }}
+        );
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchUnsafe.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchUnsafe.java
new file mode 100644
index 0000000..768e0d6
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/BenchUnsafe.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.nio.ByteBuffer;
+
+public class BenchUnsafe extends BaseBench{
+    final static int ITERS = 1000000;
+
+    final static NativeBuffer NBUF = new NativeBuffer(2 * ITERS);
+    final static ByteBuffer BBUF = NBUF.buffer;
+    final static long ADDR = NBUF.bufferPtr;
+    final static long ADDR_MAX = NBUF.bufferPtr + ITERS;
+
+    final static NativeBuffer NBUF2 = new NativeBuffer(2 * ITERS);
+    final static ByteBuffer BBUF2 = NBUF2.buffer;
+    final static long ADDR2 = NBUF2.bufferPtr;
+    final static long ADDR2_MAX = NBUF2.bufferPtr + ITERS;
+
+    final static long ARG = 345;
+
+    final static long BUFSIZE = BBUF.limit();
+
+    public void testIt(){
+        this.bench("Memory writes", 5, 3, 100L,
+
+                new Task("buffer.putLong"){
+            @Override public void run() {
+                for(long i = 0; i < ITERS; i++)
+                    BBUF.putLong((int) i, ARG);
+            }},
+
+            new Task("unsafe.putLong"){
+                @Override public void run() {
+                    for(long i = ADDR; i < ADDR_MAX; i++)
+                        UNSAFE.putLong(i, ARG);
+                }});
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/CategoryTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/CategoryTest.java
new file mode 100644
index 0000000..0e376b7
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/CategoryTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.appkit.AppKitFramework;
+import com.apple.jobjc.appkit.NSStringCategory;
+import com.apple.jobjc.foundation.NSSize;
+import com.apple.jobjc.foundation.NSString;
+
+public class CategoryTest extends PooledTestCase {
+    public void testAppKit_NSString(){
+        AppKitFramework APPKIT = JObjC.getInstance().AppKit();
+
+        NSString nstr = Utils.get().strings().nsString("mirzapirza");
+        NSStringCategory nstrx = APPKIT.NSStringCategory(nstr);
+        NSSize sz = nstrx.sizeWithAttributes(null);
+
+        assertEquals(57.0, sz.width());
+        assertEquals(15.0, sz.height());
+    }
+
+    public static void main(String[] args){
+        junit.textui.TestRunner.run(CategoryTest.class);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/FunctionTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/FunctionTest.java
new file mode 100644
index 0000000..28e8018
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/FunctionTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Coder.PointerCoder;
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+import com.apple.jobjc.Coder.VoidCoder;
+import com.apple.jobjc.Invoke.FunCall;
+
+public class FunctionTest extends PooledTestCase {
+    NativeArgumentBuffer nativeBuffer;
+    JObjCRuntime runtime;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        nativeBuffer = UnsafeRuntimeAccess.getNativeBuffer();
+        runtime = nativeBuffer.runtime;
+    }
+
+    public void testInvokeNoParamNoReturn() throws Throwable {
+        final FunCall fxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSBeep", VoidCoder.INST);
+
+        fxn.init(nativeBuffer);
+        fxn.invoke(nativeBuffer);
+    }
+
+    public void testInvokeNoParams() throws Throwable {
+        final FunCall fxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSFullUserName", PointerCoder.INST);
+
+        fxn.init(nativeBuffer);
+        fxn.invoke(nativeBuffer);
+
+        final long ptr = PrimitivePointerCoder.INST.pop(nativeBuffer);
+        System.out.println("0x" + Long.toHexString(ptr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(ptr));
+    }
+
+    public void testInvokeOneParam() throws Throwable {
+        final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);
+
+        getHomeDirFxn.init(nativeBuffer);
+        getHomeDirFxn.invoke(nativeBuffer);
+
+        final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
+        System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));
+
+        final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
+        getTypeOfFxn.init(nativeBuffer);
+        PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
+        getTypeOfFxn.invoke(nativeBuffer);
+
+    //    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
+    //    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
+    }
+
+    public static void main(final String[] args) {
+        junit.textui.TestRunner.run(FunctionTest.class);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/GUIDemo.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/GUIDemo.java
new file mode 100644
index 0000000..41fa81a
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/GUIDemo.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Utils.Strings;
+import com.apple.jobjc.appkit.NSApplication;
+import com.apple.jobjc.appkit.NSButton;
+import com.apple.jobjc.appkit.NSDrawer;
+import com.apple.jobjc.appkit.NSMenu;
+import com.apple.jobjc.appkit.NSWindow;
+import com.apple.jobjc.foundation.NSAutoreleasePool;
+import com.apple.jobjc.foundation.NSObject;
+import com.apple.jobjc.foundation.NSObjectClass;
+import com.apple.jobjc.foundation.NSRect;
+import com.apple.jobjc.foundation.NSSize;
+
+class MyDelegate extends NSObject{
+    static final JObjC objc = JObjC.getInstance();
+    static final Strings str = Utils.get().strings();
+
+    public MyDelegate(long ptr, JObjCRuntime r) { super(ptr, r); }
+
+    private NSWindow myWindow;
+    private NSDrawer myDrawer;
+
+    public void printHello(ID sender){
+        System.out.println("Hello!");
+        myDrawer.toggle(this);
+    }
+
+    public void createMenu(){
+        NSMenu menu = objc.AppKit().NSMenu().newID();
+        menu.addItemWithTitle_action_keyEquivalent(
+                str.nsString("Quit"),
+                new SEL("terminate:"),
+                str.nsString("q"));
+        NSApplication app = objc.AppKit().NSApp();
+        app.setMainMenu(menu);
+    }
+
+    public void createWindow(){
+        NSRect rect;
+        int styleMask = objc.AppKit().NSTitledWindowMask() | objc.AppKit().NSMiniaturizableWindowMask();
+        NSButton myButton;
+        NSSize buttonSize;
+        myButton = objc.AppKit().NSButton().newID();
+        myButton.setTitle(str.nsString("Print Hello!"));
+        myButton.sizeToFit();
+        myButton.setTarget(this);
+        myButton.setAction(new SEL("printHello:"));
+        buttonSize = myButton.frame().size();
+        rect = objc.Foundation().NSMakeRect(100, 100, 2*buttonSize.width(), 2*buttonSize.height());
+        myWindow = objc.AppKit().NSWindow().alloc();
+        myWindow = myWindow.initWithContentRect_styleMask_backing_defer(
+                rect, styleMask, objc.AppKit().NSBackingStoreBuffered(), false);
+        myWindow.setTitle(str.nsString("This is a test window."));
+        myWindow.setContentView(myButton);
+
+        myDrawer = objc.AppKit().NSDrawer().alloc();
+        myDrawer = myDrawer.initWithContentSize_preferredEdge(
+                  objc.Foundation().NSMakeSize(100, 40), objc.Foundation().NSMinYEdge());
+        myDrawer.setParentWindow(myWindow);
+    }
+
+    public void applicationWillFinishLaunching(ID not){
+        createMenu();
+        createWindow();
+    }
+
+    public void applicationDidFinishLaunching(ID not){
+        myWindow.makeKeyAndOrderFront(null);
+    }
+}
+
+class MyDelegateClass extends NSObjectClass{
+    public MyDelegateClass(JObjCRuntime r){ super(r); }
+}
+
+public class GUIDemo{
+    static final JObjC objc = JObjC.getInstance();
+
+    public static void main(String[] args){
+        JObjCRuntime.getInstance().registerUserClass(MyDelegate.class, MyDelegateClass.class);
+
+        objc.AppKit().NSApplication().sharedApplication();
+        NSApplication app = objc.AppKit().NSApp();
+
+        NSAutoreleasePool pool = objc.Foundation().NSAutoreleasePool().alloc();
+        pool = pool.init();
+        app.setDelegate(new MyDelegateClass(JObjCRuntime.getInstance()).newID());
+        app.run();
+        pool.drain();
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/IBDemo.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/IBDemo.java
new file mode 100644
index 0000000..82155c8
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/IBDemo.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+/**
+ * To locate the nib correctly, this demo must run from
+ * a .app (created with Jar Bundler...).
+ *
+ * TODO Add .app/Jar Bundler as ant task
+ */
+
+package com.apple.jobjc;
+
+import java.awt.Toolkit;
+
+import com.apple.jobjc.appkit.AppKitFramework;
+import com.apple.jobjc.appkit.NSApplication;
+import com.apple.jobjc.appkit.NSView;
+import com.apple.jobjc.appkit.NSViewClass;
+import com.apple.jobjc.foundation.FoundationFramework;
+import com.apple.jobjc.foundation.NSRect;
+import com.apple.jobjc.foundation.NSString;
+
+class MyView extends NSView{
+    static final AppKitFramework APPKIT = JObjC.getInstance().AppKit();
+
+    public MyView(long objPtr, JObjCRuntime runtime) { super(objPtr, runtime); }
+
+    @Override public void drawRect(NSRect r){
+        APPKIT.NSColor().redColor().set();
+        APPKIT.NSBezierPath().fillRect(r);
+    }
+}
+
+class MyViewClass extends NSViewClass{
+    protected MyViewClass(String name, JObjCRuntime runtime) { super(name, runtime); }
+    public MyViewClass(JObjCRuntime runtime){ this(MyView.class.getSimpleName(), runtime); }
+}
+
+public class IBDemo{
+    final static FoundationFramework FOUNDATION = JObjC.getInstance().Foundation();
+    final static AppKitFramework APPKIT = JObjC.getInstance().AppKit();
+
+    // Works if the JVM is launched on the main thread,
+    // but JavaApplicationStub does not understand -XstartOnFirstThread
+    public static void mainWithAppMain(String[] args){
+        APPKIT.NSApplicationMain(0, null);
+    }
+
+    // Work around: let someone else init, and then
+    // get on the main thread to load the nib.
+    public static void mainWithoutAppMain(String[] args){
+        Toolkit.getDefaultToolkit();
+
+        Utils.get().threads().performOnMainThread(new Runnable(){
+            public void run() {
+                APPKIT.NSApplication().sharedApplication();
+                NSApplication APP = APPKIT.NSApp();
+
+                NSString nibName = Utils.get().strings().nsString("MainMenu");
+                boolean loadedNib = APPKIT.NSBundleCategory().loadNibNamed_owner(nibName, APP);
+                if(!loadedNib) throw new RuntimeException("Failed to load nib.");
+            }}, false);
+    }
+
+    public static void main(String[] args){
+        JObjCRuntime.getInstance().registerUserClass(MyView.class, MyViewClass.class);
+        mainWithoutAppMain(args);
+        //mainWithAppMain(args);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/IntroTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/IntroTest.java
new file mode 100644
index 0000000..2a5cea9
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/IntroTest.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import junit.framework.TestCase;
+
+import com.apple.jobjc.Invoke.FunCall;
+import com.apple.jobjc.PrimitiveCoder.DoubleCoder;
+import com.apple.jobjc.appkit.AppKitFramework;
+import com.apple.jobjc.appkit.NSApplication;
+import com.apple.jobjc.appkit.NSApplicationClass;
+import com.apple.jobjc.appkit.NSColorPanel;
+import com.apple.jobjc.appkit.NSWorkspace;
+import com.apple.jobjc.foundation.FoundationFramework;
+import com.apple.jobjc.foundation.NSAutoreleasePool;
+import com.apple.jobjc.foundation.NSPoint;
+import com.apple.jobjc.foundation.NSString;
+import com.apple.jobjc.foundation.NSStringClass;
+
+public class IntroTest extends TestCase{
+    // The low-level core makes function calls, sends messages, marshals data, etc.
+    public void testCore(){
+        // pass security check and get ahold of a runtime (should cache this)
+        final JObjCRuntime RUNTIME = JObjCRuntime.getInstance();
+        final NativeArgumentBuffer ARGS = JObjCRuntime.getInstance().getThreadLocalState();
+
+        // create a funcall (should cache this)
+        final FunCall fc = new FunCall(RUNTIME, "sin", DoubleCoder.INST, DoubleCoder.INST);
+
+        // start function call
+        fc.init(ARGS);
+        // push an arg
+        DoubleCoder.INST.push(ARGS, 3.14159265 / 2.0);
+        // make the call
+        fc.invoke(ARGS);
+        // read the return value
+        double ret = DoubleCoder.INST.pop(ARGS);
+
+        assertEquals(1.0, ret);
+    }
+
+    // Frameworks bridge the Mac OS X frameworks
+    public void testFrameworks(){
+        // First, get an instance of JObjC:
+        final JObjC JOBJC = com.apple.jobjc.JObjC.getInstance();
+
+        // It's your gateway to the frameworks.
+        final FoundationFramework FND = JOBJC.Foundation();
+        final AppKitFramework APP = JOBJC.AppKit();
+
+        // From which you can then access...
+
+        // enums, defines, constants
+        int nsmye = FND.NSMaxYEdge();
+        boolean debug = FND.NSDebugEnabled();
+
+        // structs
+        NSPoint p = FND.makeNSPoint();
+        p.setX(3);
+        assertEquals(3.0, p.x());
+
+        // C functions
+        NSPoint p2 = FND.NSMakePoint(12, 34);
+        assertEquals(12.0, p2.x());
+
+        // ... Let's create an AutoreleasePool before we go on
+        NSAutoreleasePool pool = ((NSAutoreleasePool) FND.NSAutoreleasePool().alloc()).init();
+
+        // Objective-C classes
+        NSStringClass nsc = FND.NSString();
+
+        // class-methods
+        NSString nsStringClassDescr = nsc.description();
+
+        // instances
+        NSString nsi = ((NSString) FND.NSString().alloc()).init();
+
+        // instance methods
+        NSString d = nsi.description();
+
+        // The bridge marshals some types for you, but it doesn't
+        // convert between NSString and Java String automatically.
+        // For that we use Utils.get().strings().nsString(String)
+        // and Utils.get().strings().javaString(NSString);
+
+        assertEquals("NSString", Utils.get().strings().javaString(nsStringClassDescr));
+
+        NSString format = Utils.get().strings().nsString("Foo bar %d baz");
+
+        NSString formatted = ((NSString) FND.NSString().alloc()).initWithFormat(format, 34);
+        String jformatted = Utils.get().strings().javaString(formatted);
+
+        assertEquals("Foo bar 34 baz", jformatted);
+
+        // Reveal in Finder
+//        NSString file = Utils.get().strings().nsString(
+//                "/Applications/Calculator.app/Contents/Resources/Calculator.icns");
+//        APP.NSWorkspace().sharedWorkspace()
+//           .selectFile_inFileViewerRootedAtPath(file, null);
+
+        pool.drain();
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NSClassTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NSClassTest.java
new file mode 100644
index 0000000..13a2d3d
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NSClassTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.foundation.FoundationFramework;
+import com.apple.jobjc.foundation.NSString;
+import com.apple.jobjc.foundation.NSStringClass;
+
+public class NSClassTest extends PooledTestCase{
+    JObjC JOBJC = JObjC.getInstance();
+    FoundationFramework FND = JOBJC.Foundation();
+
+    public void testNSClassName(){
+        NSString s = ((NSString) FND.NSString().alloc()).init();
+
+        NSString cname = s.className();
+        String jcname = Utils.get().strings().javaString(cname);
+        assertEquals("NSCFString", jcname);
+    }
+
+    public void testNSClassPop(){
+        NSString s = ((NSString) FND.NSString().alloc()).init();
+
+        NSStringClass c = s.classNSClass();
+        String jdescr = Utils.get().strings().javaString(c.description());
+        assertEquals("NSCFString", jdescr);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NativeBufferTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NativeBufferTest.java
new file mode 100644
index 0000000..c6c4cff
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NativeBufferTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import junit.framework.TestCase;
+
+public class NativeBufferTest extends TestCase{
+    public void testSlicePtrs(){
+        JObjC.getInstance();
+
+        NativeBuffer b = new NativeBuffer(123);
+        b.position(1);
+        NativeBuffer c = b.slice();
+        assertEquals(b.bufferPtr + 1, c.bufferPtr);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NativeTypeTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NativeTypeTest.java
new file mode 100644
index 0000000..00daecb
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/NativeTypeTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.internal.jobjc.generator.model.types.NType;
+import com.apple.internal.jobjc.generator.utils.NTypeMerger;
+import com.apple.internal.jobjc.generator.utils.NTypeParser;
+
+public class NativeTypeTest extends PooledTestCase{
+
+    private NType doParse(String type){
+        NType nt = NTypeParser.parseFrom(type);
+        String printed = nt.toString();
+        System.out.println("Original: " + type);
+        System.out.println("Printed.: " + printed);
+        assertEquals(type, printed);
+        return nt;
+    }
+
+    // {_NSRect=
+    //   "origin"{_NSPoint="x"f"y"f}
+    //   "size"{_NSSize="width"f"height"f}}
+    public void testStruct(){
+        doParse("{_NSRect=\"origin\"{_NSPoint=\"x\"f\"y\"f}\"size\"{_NSSize=\"width\"f\"height\"f}}");
+    }
+
+    // {IOBluetoothL2CAPChannelEvent=
+    //   "eventType"i
+    //   "u"(?=
+    //     "data"{IOBluetoothL2CAPChannelDataBlock=
+    //       "dataPtr"^v
+    //       "dataSize"I}
+    //     "writeRefCon"^v
+    //     "padding"[32C])
+    //   "status"i}
+    public void testUnion(){
+        doParse("{IOBluetoothL2CAPChannelEvent=\"eventType\"i\"u\"(?=\"data\"{IOBluetoothL2CAPChannelDataBlock=\"dataPtr\"^v\"dataSize\"I}\"writeRefCon\"^v\"padding\"[32C])\"status\"i}");
+    }
+
+    public void testUnknown(){
+        doParse("{_CFSocketContext=\"version\"i\"info\"^v\"retain\"^?\"release\"^?\"copyDescription\"^?}");
+    }
+
+    public void testEmptyStruct(){
+        doParse("{_CFSocketSignature=\"protocolFamily\"i\"socketType\"i\"protocol\"i\"address\"^{__CFData}}");
+    }
+
+    public void testCharPtr(){
+        doParse("^*");
+    }
+
+    public void doEquals(final String s){
+        assertEquals(doParse(s), doParse(s));
+    }
+
+    public void testEquals(){
+        doEquals("{_NSRect=\"origin\"{_NSPoint=\"x\"f\"y\"f}\"size\"{_NSSize=\"width\"f\"height\"f}}");
+        doEquals("{IOBluetoothL2CAPChannelEvent=\"eventType\"i\"u\"(?=\"data\"{IOBluetoothL2CAPChannelDataBlock=\"dataPtr\"^v\"dataSize\"I}\"writeRefCon\"^v\"padding\"[32C])\"status\"i}");
+        doEquals("{_CFSocketContext=\"version\"i\"info\"^v\"retain\"^?\"release\"^?\"copyDescription\"^?}");
+        doEquals("{_CFSocketSignature=\"protocolFamily\"i\"socketType\"i\"protocol\"i\"address\"^{__CFData}}");
+    }
+
+    public void testMerge(){
+        NType a = doParse("{_NSRect={_NSPoint=\"x\"f\"y\"f}\"size\"{_NSSize=ff}}");
+        NType b = doParse("{_NSRect=\"origin\"{_NSPoint=ff}{_NSSize=\"width\"f\"height\"f}}");
+        NType c = NTypeMerger.inst().merge(a, b);
+        NType expected = doParse("{_NSRect=\"origin\"{_NSPoint=\"x\"f\"y\"f}\"size\"{_NSSize=\"width\"f\"height\"f}}");
+        System.out.println("Merge results:");
+        System.out.println("\ta: " + a.toString());
+        System.out.println("\tb: " + b.toString());
+        System.out.println("\tc: " + c.toString());
+        System.out.println("\tx: " + expected.toString());
+        assertEquals(expected, c);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/PooledTestCase.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/PooledTestCase.java
new file mode 100644
index 0000000..fa36883
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/PooledTestCase.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import junit.framework.TestCase;
+
+import com.apple.jobjc.foundation.FoundationFramework;
+import com.apple.jobjc.foundation.NSAutoreleasePool;
+
+public class PooledTestCase extends TestCase {
+    static{
+        System.loadLibrary("JObjC-tests");
+    }
+    NSAutoreleasePool pool;
+
+    @Override public void setUp() throws Exception {
+        FoundationFramework foundation = JObjC.getInstance().Foundation();
+        pool = foundation.NSAutoreleasePool().alloc();
+        pool.init();
+    }
+
+    @Override public void tearDown() throws Exception {
+        pool.drain();
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/SELTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/SELTest.java
new file mode 100644
index 0000000..749ca85
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/SELTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Coder.PointerCoder;
+import com.apple.jobjc.Coder.PrimitivePointerCoder;
+import com.apple.jobjc.Invoke.MsgSend;
+
+public class SELTest extends PooledTestCase {
+
+    NativeArgumentBuffer nativeBuffer;
+    JObjCRuntime runtime;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        nativeBuffer = UnsafeRuntimeAccess.getNativeBuffer();
+        runtime = nativeBuffer.runtime;
+    }
+
+    public void testGetBlackColor() throws Throwable {
+        final MacOSXFramework appKit = TestUtils.getAppKit();
+        final NSClass<? extends ID> clazz = UnsafeRuntimeAccess.getNSClass(appKit, "NSColor");
+        final MsgSend sel = UnsafeRuntimeAccess.createMsgSend(clazz, "redColor", PointerCoder.INST);
+
+        sel.init(nativeBuffer, clazz);
+        sel.invoke(nativeBuffer);
+
+        final long blackColorPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
+        String dscr = UnsafeRuntimeAccess.getDescriptionForPtr(blackColorPtr);
+
+        System.out.println("0x" + Long.toHexString(blackColorPtr) + ": " + dscr);
+        assertEquals("NSCalibratedRGBColorSpace 1 0 0 1", dscr);
+    }
+
+    public static void main(final String[] args) {
+        junit.textui.TestRunner.run(SELTest.class);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/StructTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/StructTest.java
new file mode 100644
index 0000000..02ac23a
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/StructTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.io.StringWriter;
+
+import com.apple.jobjc.coreaudio.AudioBuffer;
+import com.apple.jobjc.foundation.NSPoint;
+import com.apple.jobjc.foundation.NSRect;
+
+public class StructTest extends PooledTestCase {
+    public void testSimpleStruct(){
+        AudioBuffer b = JObjC.getInstance().CoreAudio().makeAudioBuffer();
+        assertEquals(0, b.mNumberChannels());
+        assertEquals(0, b.mDataByteSize());
+        b.setMNumberChannels(1);
+        b.setMDataByteSize(3);
+        assertEquals(1, b.mNumberChannels());
+        assertEquals(3, b.mDataByteSize());
+    }
+
+    public void testNestedStruct(){
+        NSRect r = JObjC.getInstance().Foundation().makeNSRect();
+        assertTrue(0f == r.size().width());
+        r.size().setWidth(3f);
+        assertTrue(3f == r.size().width());
+        assertTrue(r.size() == r.size());
+    }
+
+    public void testSTRET(){
+        NSPoint point = JObjC.getInstance().Foundation().NSMakePoint(3, 4);
+        assertTrue(point.x() == 3);
+        assertTrue(point.y() == 4);
+
+        NSRect rect = JObjC.getInstance().Foundation().NSMakeRect(0, 1, 2, 3);
+        assertTrue(rect.origin().x() == 0);
+        assertTrue(rect.origin().y() == 1);
+        assertTrue(rect.size().width() == 2);
+        assertTrue(rect.size().height() == 3);
+    }
+
+    //
+
+    private char halfByteToHex(int b){
+        return (b >= 0x0 && b < 0xA) ? (char) ('0' + b) : (char) ('A' + (b-0xA));
+    }
+
+    private String byteToHexString(Byte b){
+        StringWriter sw = new StringWriter();
+        sw.append(halfByteToHex(b & 0xF));
+        sw.append(halfByteToHex((b & 0xF0) >> 4));
+        return sw.toString();
+    }
+
+    String print(Struct st){
+        StringWriter sw = new StringWriter();
+        st.raw.position(0);
+        sw.append(st.getClass().getSimpleName() + ":" + st.raw.limit() + " @ " + Long.toHexString(st.raw.bufferPtr) + " : ");
+        for(int i = 0; i < st.raw.limit(); i++){
+            sw.append(byteToHexString(st.raw.get()) + " ");
+            if((i+1) % 4 == 0)
+                sw.append(" ");
+        }
+        System.out.println(sw.toString().trim());
+        return sw.toString().trim();
+    }
+
+    public static void main(String[] args){
+        junit.textui.TestRunner.run(StructTest.class);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/SubclassingTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/SubclassingTest.java
new file mode 100644
index 0000000..46be0ed
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/SubclassingTest.java
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.Coder.IDCoder;
+import com.apple.jobjc.Coder.VoidCoder;
+import com.apple.jobjc.Invoke.MsgSend;
+import com.apple.jobjc.Invoke.MsgSendSuper;
+import com.apple.jobjc.PrimitiveCoder.DoubleCoder;
+import com.apple.jobjc.PrimitiveCoder.FloatCoder;
+import com.apple.jobjc.PrimitiveCoder.SIntCoder;
+import com.apple.jobjc.PrimitiveCoder.SLongLongCoder;
+import com.apple.jobjc.foundation.NSObject;
+import com.apple.jobjc.foundation.NSObjectClass;
+import com.apple.jobjc.foundation.NSPoint;
+import com.apple.jobjc.foundation.NSString;
+
+public class SubclassingTest extends PooledTestCase{
+    JObjCRuntime runtime;
+    NativeArgumentBuffer ctx;
+
+    @Override public void setUp() throws Exception{
+        super.setUp();
+        this.runtime = JObjCRuntime.getInstance();
+        this.ctx = runtime.getThreadLocalState();
+
+        runtime.registerUserClass(MyObject.class, MyObjectClass.class);
+    }
+
+    public void testClass(){
+        final MyObjectClass cls = new MyObjectClass(runtime);
+        assertEquals(MyObject.class.getSimpleName(), UnsafeRuntimeAccess.getClassNameFor(cls));
+    }
+
+    public void testInst(){
+        final MyObjectClass cls = new MyObjectClass(runtime);
+        final MyObject instObj = cls.alloc();
+        final MyObject retrievedObj = Subclassing.getJObjectFromIVar(UnsafeRuntimeAccess.getObjPtr(instObj));
+        assertTrue(instObj == retrievedObj);
+    }
+
+    public void testVoidVoidMethod(){
+        final MyObject instObj = new MyObjectClass(runtime).alloc();
+
+        assertEquals(0, instObj.myMethodHits);
+        MsgSend sel = new MsgSend(runtime, "myMethod", VoidCoder.INST);
+        sel.init(ctx, instObj);
+        sel.invoke(ctx);
+        assertEquals(1, instObj.myMethodHits);
+    }
+
+    public void testMsgSendSuper(){
+        final MyObjectClass cls = new MyObjectClass(runtime);
+        final MyObject obj = ((MyObject) cls.alloc()).init();
+
+        // direct descr
+
+        assertEquals("foo", Utils.get().strings().javaString(obj.description()));
+
+        // indirect (from native) descr
+        {
+            MsgSend msgSend = new MsgSend(runtime, "description", IDCoder.INST);
+            msgSend.init(ctx, obj);
+            msgSend.invoke(ctx);
+            assertEquals("foo", Utils.get().strings().javaString((NSString) IDCoder.INST.pop(ctx)));
+        }
+
+        // indirect (from native) descr
+        {
+            MsgSendSuper msgSendSuper = new MsgSendSuper(runtime, "description", IDCoder.INST);
+            msgSendSuper.init(ctx, obj, cls);
+            msgSendSuper.invoke(ctx);
+            assertEquals("foo", Utils.get().strings().javaString((NSString) IDCoder.INST.pop(ctx)));
+        }
+
+        // nso descr
+        {
+            MsgSendSuper msgSendSuper = new MsgSendSuper(runtime, "description", IDCoder.INST);
+            msgSendSuper.init(ctx, obj, JObjC.getInstance().Foundation().NSObject());
+            msgSendSuper.invoke(ctx);
+
+            final NSString nsod = (NSString) IDCoder.INST.pop(ctx);
+            String jde = Utils.get().strings().javaString(nsod);
+            assertEquals(jde.substring(0, 9), "<MyObject");
+        }
+    }
+
+    public void testPerformSelector(){
+        final MyObject instObj = new MyObjectClass(runtime).alloc();
+
+        assertEquals(0, instObj.myMethodHits);
+        instObj.performSelector(new SEL("myMethod"));
+        assertEquals(1, instObj.myMethodHits);
+
+        instObj.performSelectorOnMainThread_withObject_waitUntilDone(
+                new SEL("myMethod"), null, true);
+        assertEquals(2, instObj.myMethodHits);
+    }
+
+    public void testVoidIntMethod(){
+        final MyObject instObj = new MyObjectClass(runtime).alloc();
+
+        MsgSend sel2 = new MsgSend(runtime, "intMethod", SIntCoder.INST);
+        sel2.init(ctx, instObj);
+        sel2.invoke(ctx);
+        int ret = SIntCoder.INST.popInt(ctx);
+        assertEquals(3, ret);
+    }
+
+    public void testStructStructMethod(){
+        final MyObject instObj = new MyObjectClass(runtime).alloc();
+
+        NSPoint p = JObjC.getInstance().Foundation().NSMakePoint(3, 3);
+
+        MsgSend sel2 = new MsgSend(runtime, "doubleIt:", p.getCoder(), p.getCoder());
+        sel2.init(ctx, instObj);
+        p.getCoder().push(ctx, p);
+        sel2.invoke(ctx, p);
+
+        assertEquals(6.0, p.x());
+    }
+
+    public void testNSStringNSStringMethod(){
+        final MyObject instObj = new MyObjectClass(runtime).alloc();
+
+        final NSString orig = Utils.get().strings().nsString("foobar");
+        final String expected = "foobarfoobarfoobar";
+
+        final MsgSend sel = new MsgSend(runtime, "stringTimesThree:", IDCoder.INST, IDCoder.INST);
+        sel.init(ctx, instObj);
+        IDCoder.INST.push(ctx, orig);
+        sel.invoke(ctx);
+        NSString ret = (NSString) IDCoder.INST.pop(ctx);
+        assertEquals(expected, Utils.get().strings().javaString(ret));
+    }
+
+    public void testDoubleIntLongMethod(){
+        final MyObject instObj = new MyObjectClass(runtime).alloc();
+
+        final int arg1 = 3;
+        final long arg2 = 4;
+        final float arg3 = 5.5F;
+        final double expected = 12.5D;
+
+        final MsgSend sel = new MsgSend(runtime, "add:and:and:", DoubleCoder.INST,
+                SIntCoder.INST, SLongLongCoder.INST, FloatCoder.INST);
+        sel.init(ctx, instObj);
+        SIntCoder.INST.push(ctx, arg1);
+        SLongLongCoder.INST.push(ctx, arg2);
+        FloatCoder.INST.push(ctx, arg3);
+        sel.invoke(ctx);
+        final double ret = DoubleCoder.INST.pop(ctx);
+        assertEquals(expected, ret);
+    }
+
+    public static void main(String[] args){
+        junit.textui.TestRunner.run(SubclassingTest.class);
+    }
+}
+
+class MyObject extends NSObject{
+    public MyObject(long objPtr, JObjCRuntime runtime) {
+        super(objPtr, runtime);
+    }
+
+    public int myMethodHits = 0;
+
+    public void myMethod(){
+        myMethodHits++;
+    }
+
+    public int intMethod(){
+        return 3;
+    }
+
+    public NSString stringTimesThree(NSString nss){
+        int count = 3;
+        String jss = Utils.get().strings().javaString(nss);
+        String js2 = "";
+        while(count-- > 0)
+            js2 += jss;
+        return Utils.get().strings().nsString(js2);
+    }
+
+    public double add_and_and(int a, long b, float c){
+        return a + b + c;
+    }
+
+    public NSPoint doubleIt(NSPoint p){
+        System.out.println("Doubling NSPoint(" + p.x() + ", " + p.y() + ").");
+        p.setX(p.x() * 2);
+        p.setY(p.y() * 2);
+        return p;
+    }
+
+    @Override public NSString description(){
+        return Utils.get().strings().nsString("foo");
+    }
+}
+
+class MyObjectClass extends NSObjectClass{
+    protected MyObjectClass(String name, JObjCRuntime runtime) {
+        super(name, runtime);
+    }
+
+    public MyObjectClass(JObjCRuntime runtime){
+        this("MyObject", runtime);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/TestUtils.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/TestUtils.java
new file mode 100644
index 0000000..54ae708
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/TestUtils.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+
+public class TestUtils {
+    static MacOSXFramework getAppKit() {
+        return UnsafeRuntimeAccess.getFramework(new String[]{"/System/Library/Frameworks/AppKit.framework/AppKit"});
+    }
+
+    static MacOSXFramework getFoundation() {
+        return UnsafeRuntimeAccess.getFramework(new String[]{"/System/Library/Frameworks/Foundation.framework/Foundation"});
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/UtilsTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/UtilsTest.java
new file mode 100644
index 0000000..6b506fc
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/UtilsTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import java.util.concurrent.Callable;
+
+import com.apple.jobjc.foundation.NSString;
+
+public class UtilsTest extends PooledTestCase{
+    public void testStrings(){
+        String s = "fooBarBazDazzle";
+        NSString ns = Utils.get().strings().nsString(s);
+        String t = Utils.get().strings().javaString(ns);
+        assertEquals(s, t);
+    }
+
+    public void testThreadsPerformRunnableOnMainThread(){
+        final long testThreadId = Thread.currentThread().getId();
+        class Wrap{ public long x = testThreadId; }
+        final Wrap wrap = new Wrap();
+        assertTrue(testThreadId == wrap.x);
+
+        Utils.get().threads().performOnMainThread(new Runnable(){
+            public void run() {
+                wrap.x = Thread.currentThread().getId();
+            }
+        }, true);
+
+        assertTrue(testThreadId != wrap.x);
+    }
+
+    public void testThreadsPerformCallableOnMainThread() throws Exception{
+        final long testThreadId = Thread.currentThread().getId();
+        final long mainThreadId = Utils.get().threads().performOnMainThread(new Callable<Long>(){
+            public Long call() { return Thread.currentThread().getId(); }
+        });
+        assertTrue(testThreadId != mainThreadId);
+    }
+
+    public void testThreadsPerformCallableOnMainThreadException() throws Exception{
+        class FooException extends RuntimeException{}
+        try {
+            Utils.get().threads().performOnMainThread(new Callable<Object>(){
+                public Object call() { throw new FooException(); }
+            });
+        } catch (FooException e) {
+            return;
+        }
+        fail("Failed to catch exception.");
+    }
+
+    public static void main(String[] args){
+        junit.textui.TestRunner.run(UtilsTest.class);
+    }
+}
+
diff --git a/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/VarArgsTest.java b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/VarArgsTest.java
new file mode 100644
index 0000000..8e97feb
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/java/com/apple/jobjc/VarArgsTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.apple.jobjc;
+
+import com.apple.jobjc.foundation.FoundationFramework;
+import com.apple.jobjc.foundation.NSDictionary;
+import com.apple.jobjc.foundation.NSString;
+
+public class VarArgsTest extends PooledTestCase {
+    FoundationFramework FND = JObjC.getInstance().Foundation();
+
+    public void testNSString_initWithFormat(){
+        String expected = "1 + 0.2 = 1.2 abracadabra";
+        NSString format = Utils.get().strings().nsString("%d + %.1f = %.1f %@");
+
+        NSString abra = Utils.get().strings().nsString("abracadabra");
+
+        NSString nstr = ((NSString)FND.NSString().alloc()).initWithFormat(format, 1, 0.2, 1.2, abra);
+        String actual = Utils.get().strings().javaString(nstr);
+
+        assertEquals(expected, actual);
+    }
+
+    public void testNSDictionary(){
+        NSString v1 = Utils.get().strings().nsString("value1");
+        NSString v2 = Utils.get().strings().nsString("value2");
+        NSString k1 = Utils.get().strings().nsString("key1");
+        NSString k2 = Utils.get().strings().nsString("key2");
+
+        NSDictionary dict = ((NSDictionary)FND.NSDictionary().alloc()).initWithObjectsAndKeys(v1, k1, v2, k2, null);
+
+        NSString nsdescr = dict.description();
+        String jdescr = Utils.get().strings().javaString(nsdescr);
+
+        assertEquals("{\n    key1 = value1;\n    key2 = value2;\n}", jdescr);
+    }
+
+    public static void main(String[] args){
+        junit.textui.TestRunner.run(VarArgsTest.class);
+    }
+}
diff --git a/jdk/src/macosx/native/jobjc/src/tests/native/FunCallBench.m b/jdk/src/macosx/native/jobjc/src/tests/native/FunCallBench.m
new file mode 100644
index 0000000..556f182
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/tests/native/FunCallBench.m
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+#include <Cocoa/Cocoa.h>
+
+#include "com_apple_jobjc_BenchFunCall.h"
+#include <math.h>
+
+JNIEXPORT jdouble JNICALL Java_com_apple_jobjc_BenchFunCall_jniSin
+(JNIEnv *env, jclass clazz, jdouble x)
+{
+    return (jdouble) sin((double) x);
+}
+
+
+#include "com_apple_jobjc_BenchIDPop.h"
+
+JNIEXPORT void JNICALL Java_com_apple_jobjc_BenchIDPop_jniCFRetain
+(JNIEnv *env, jclass clazz, jlong x)
+{
+    CFRetain(jlong_to_ptr(x));
+}
+
+JNIEXPORT void JNICALL Java_com_apple_jobjc_BenchIDPop_jniCFRelease
+(JNIEnv *env, jclass clazz, jlong x)
+{
+    CFRelease(jlong_to_ptr(x));
+}
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_BenchIDPop_jniNSStringAlloc
+(JNIEnv *env, jclass clazz)
+{
+    return ptr_to_jlong([NSString alloc]);
+}
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_BenchIDPop_jniNSStringAllocAndRetain
+(JNIEnv *env, jclass clazz)
+{
+    return ptr_to_jlong(CFRetain([NSString alloc]));
+}
+
+JNIEXPORT jlong JNICALL Java_com_apple_jobjc_BenchIDPop_jniNSStringCached
+(JNIEnv *env, jclass clazz)
+{
+    static jlong str = 0;
+    if(!str) str = ptr_to_jlong([NSString alloc]);
+    return str;
+}
diff --git a/jdk/src/macosx/native/sun/awt/AWTEvent.h b/jdk/src/macosx/native/sun/awt/AWTEvent.h
new file mode 100644
index 0000000..0f4eb14
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTEvent.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef __AWTEVENT_H
+#define __AWTEVENT_H
+
+#import "LWCToolkit.h"
+
+jlong UTC(NSEvent *event);
+void DeliverJavaKeyEvent(JNIEnv *env, NSEvent *event, jobject peer);
+void DeliverJavaMouseEvent(JNIEnv *env, NSEvent *event, jobject peer);
+void SendAdditionalJavaEvents(JNIEnv *env, NSEvent *nsEvent, jobject peer);
+jint GetJavaMouseModifiers(NSEvent *event);
+
+#endif /* __AWTEVENT_H */
diff --git a/jdk/src/macosx/native/sun/awt/AWTEvent.m b/jdk/src/macosx/native/sun/awt/AWTEvent.m
new file mode 100644
index 0000000..70ed85a
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTEvent.m
@@ -0,0 +1,975 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+#import <sys/time.h>
+
+#import "LWCToolkit.h"
+#import "ThreadUtilities.h"
+
+#import "java_awt_event_InputEvent.h"
+#import "java_awt_event_KeyEvent.h"
+#import "java_awt_event_MouseEvent.h"
+
+/*
+ * Table to map typed characters to their Java virtual key equivalent and back.
+ * We use the incoming unichar (ignoring all modifiers) and try to figure out
+ * which virtual key code is appropriate. A lot of them just have direct
+ * mappings (the function keys, arrow keys, etc.) so they aren't a problem.
+ * We had to do something a little funky to catch the keys on the numeric
+ * key pad (i.e. using event mask to distinguish between period on regular
+ * keyboard and decimal on keypad). We also have to do something incredibly
+ * hokey with regards to the shifted punctuation characters. For examples,
+ * consider '&' which is usually Shift-7.  For the Java key typed events,
+ * that's no problem, we just say pass the unichar. But for the
+ * KeyPressed/Released events, we need to identify the virtual key code
+ * (which roughly correspond to hardware keys) which means we are supposed
+ * to say the virtual 7 key was pressed.  But how are we supposed to know
+ * when we get a punctuation char what was the real hardware key was that
+ * was pressed?  Although '&' often comes from Shift-7 the keyboard can be
+ * remapped!  I don't think there really is a good answer, and hopefully
+ * all good applets are only interested in logical key typed events not
+ * press/release.  Meanwhile, we are hard-coding the shifted punctuation
+ * to trigger the virtual keys that are the expected ones under a standard
+ * keymapping. Looking at Windows & Mac, they don't actually do this, the
+ * Mac seems to just put the ascii code in for the shifted punctuation
+ * (which means they actually end up with bogus key codes on the Java side),
+ * Windows I can't even figure out what it's doing.
+ */
+#define KL_STANDARD java_awt_event_KeyEvent_KEY_LOCATION_STANDARD
+#define KL_NUMPAD   java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD
+#define KL_UNKNOWN  java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN
+static struct _key
+{
+    unsigned short keyCode;
+    BOOL postsTyped;
+    jint javaKeyLocation;
+    jint javaKeyCode;
+}
+const keyTable[] =
+{
+    {0x00, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_A},
+    {0x01, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_S},
+    {0x02, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_D},
+    {0x03, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_F},
+    {0x04, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_H},
+    {0x05, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_G},
+    {0x06, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Z},
+    {0x07, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_X},
+    {0x08, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_C},
+    {0x09, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_V},
+    {0x0A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE},
+    {0x0B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_B},
+    {0x0C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Q},
+    {0x0D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_W},
+    {0x0E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_E},
+    {0x0F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_R},
+    {0x10, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Y},
+    {0x11, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_T},
+    {0x12, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_1},
+    {0x13, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_2},
+    {0x14, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_3},
+    {0x15, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_4},
+    {0x16, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_6},
+    {0x17, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_5},
+    {0x18, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_EQUALS},
+    {0x19, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_9},
+    {0x1A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_7},
+    {0x1B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_MINUS},
+    {0x1C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_8},
+    {0x1D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_0},
+    {0x1E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_CLOSE_BRACKET},
+    {0x1F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_O},
+    {0x20, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_U},
+    {0x21, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_OPEN_BRACKET},
+    {0x22, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_I},
+    {0x23, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_P},
+    {0x24, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_ENTER},
+    {0x25, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_L},
+    {0x26, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_J},
+    {0x27, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_QUOTE},
+    {0x28, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_K},
+    {0x29, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SEMICOLON},
+    {0x2A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SLASH},
+    {0x2B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_COMMA},
+    {0x2C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SLASH},
+    {0x2D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_N},
+    {0x2E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_M},
+    {0x2F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_PERIOD},
+    {0x30, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_TAB},
+    {0x31, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SPACE},
+    {0x32, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE},
+    {0x33, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SPACE},
+    {0x34, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ENTER},
+    {0x35, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_ESCAPE},
+    {0x36, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x37, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_META},      // ****
+    {0x38, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_SHIFT},     // ****
+    {0x39, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_CAPS_LOCK},
+    {0x3A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_ALT},       // ****
+    {0x3B, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_CONTROL},   // ****
+    {0x3C, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x3D, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x3E, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x3F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED}, // the 'fn' key on PowerBooks
+    {0x40, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x41, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_DECIMAL},
+    {0x42, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x43, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_MULTIPLY},
+    {0x44, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x45, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ADD},
+    {0x46, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x47, NO,  KL_NUMPAD,   java_awt_event_KeyEvent_VK_CLEAR},
+    {0x48, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x49, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x4A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x4B, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_DIVIDE},
+    {0x4C, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ENTER},
+    {0x4D, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x4E, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_SUBTRACT},
+    {0x4F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x50, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x51, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_EQUALS},
+    {0x52, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD0},
+    {0x53, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD1},
+    {0x54, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD2},
+    {0x55, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD3},
+    {0x56, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD4},
+    {0x57, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD5},
+    {0x58, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD6},
+    {0x59, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD7},
+    {0x5A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x5B, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD8},
+    {0x5C, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD9},
+    {0x5D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SLASH}, // This is a combo yen/backslash on JIS keyboards.
+    {0x5E, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_UNDERSCORE},
+    {0x5F, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_COMMA},
+    {0x60, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F5},
+    {0x61, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F6},
+    {0x62, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F7},
+    {0x63, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F3},
+    {0x64, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F8},
+    {0x65, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F9},
+    {0x66, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_ALPHANUMERIC},
+    {0x67, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F11},
+    {0x68, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_KATAKANA},
+    {0x69, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F13},
+    {0x6A, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F16},
+    {0x6B, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F14},
+    {0x6C, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x6D, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F10},
+    {0x6E, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x6F, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F12},
+    {0x70, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+    {0x71, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F15},
+    {0x72, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_HELP},
+    {0x73, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_HOME},
+    {0x74, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_PAGE_UP},
+    {0x75, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_DELETE},
+    {0x76, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F4},
+    {0x77, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_END},
+    {0x78, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F2},
+    {0x79, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_PAGE_DOWN},
+    {0x7A, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F1},
+    {0x7B, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_LEFT},
+    {0x7C, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_RIGHT},
+    {0x7D, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_DOWN},
+    {0x7E, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_UP},
+    {0x7F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
+};
+
+/*
+ * This table was stolen from the Windows implementation for mapping
+ * Unicode values to VK codes for dead keys.  On Windows, some layouts
+ * return ASCII punctuation for dead accents, while some return spacing
+ * accent chars, so both should be listed.  However, in all of the
+ * keyboard layouts I tried only the Unicode values are used.
+ */
+struct CharToVKEntry {
+    UniChar c;
+    jint javaKey;
+};
+static const struct CharToVKEntry charToDeadVKTable[] = {
+    {0x0060, java_awt_event_KeyEvent_VK_DEAD_GRAVE},
+    {0x00B4, java_awt_event_KeyEvent_VK_DEAD_ACUTE},
+    {0x0384, java_awt_event_KeyEvent_VK_DEAD_ACUTE}, // Unicode "GREEK TONOS" -- Greek keyboard, semicolon key
+    {0x005E, java_awt_event_KeyEvent_VK_DEAD_CIRCUMFLEX},
+    {0x007E, java_awt_event_KeyEvent_VK_DEAD_TILDE},
+    {0x02DC, java_awt_event_KeyEvent_VK_DEAD_TILDE}, // Unicode "SMALL TILDE"
+    {0x00AF, java_awt_event_KeyEvent_VK_DEAD_MACRON},
+    {0x02D8, java_awt_event_KeyEvent_VK_DEAD_BREVE},
+    {0x02D9, java_awt_event_KeyEvent_VK_DEAD_ABOVEDOT},
+    {0x00A8, java_awt_event_KeyEvent_VK_DEAD_DIAERESIS},
+    {0x02DA, java_awt_event_KeyEvent_VK_DEAD_ABOVERING},
+    {0x02DD, java_awt_event_KeyEvent_VK_DEAD_DOUBLEACUTE},
+    {0x02C7, java_awt_event_KeyEvent_VK_DEAD_CARON},
+    {0x00B8, java_awt_event_KeyEvent_VK_DEAD_CEDILLA},
+    {0x02DB, java_awt_event_KeyEvent_VK_DEAD_OGONEK},
+    {0x037A, java_awt_event_KeyEvent_VK_DEAD_IOTA},
+    {0x309B, java_awt_event_KeyEvent_VK_DEAD_VOICED_SOUND},
+    {0x309C, java_awt_event_KeyEvent_VK_DEAD_SEMIVOICED_SOUND},
+    {0,0}
+};
+
+// TODO: some constants below are part of CGS (private interfaces)...
+// for now we will look at the raw key code to determine left/right status
+// but not sure this is foolproof...
+static struct _nsKeyToJavaModifier
+{
+    NSUInteger nsMask;
+    //NSUInteger cgsLeftMask;
+    //NSUInteger cgsRightMask;
+    unsigned short leftKeyCode;
+    unsigned short rightKeyCode;
+    jint javaMask;
+    jint javaKey;
+}
+const nsKeyToJavaModifierTable[] =
+{
+    {
+        NSAlphaShiftKeyMask,
+        0,
+        0,
+        0, // no Java equivalent
+        java_awt_event_KeyEvent_VK_CAPS_LOCK
+    },
+    {
+        NSShiftKeyMask,
+        //kCGSFlagsMaskAppleShiftKey,
+        //kCGSFlagsMaskAppleRightShiftKey,
+        56,
+        60,
+        java_awt_event_InputEvent_SHIFT_DOWN_MASK,
+        java_awt_event_KeyEvent_VK_SHIFT
+    },
+    {
+        NSControlKeyMask,
+        //kCGSFlagsMaskAppleControlKey,
+        //kCGSFlagsMaskAppleRightControlKey,
+        59,
+        62,
+        java_awt_event_InputEvent_CTRL_DOWN_MASK,
+        java_awt_event_KeyEvent_VK_CONTROL
+    },
+    {
+        NSAlternateKeyMask,
+        //kCGSFlagsMaskAppleLeftAlternateKey,
+        //kCGSFlagsMaskAppleRightAlternateKey,
+        58,
+        61,
+        java_awt_event_InputEvent_ALT_DOWN_MASK,
+        java_awt_event_KeyEvent_VK_ALT
+    },
+    {
+        NSCommandKeyMask,
+        //kCGSFlagsMaskAppleLeftCommandKey,
+        //kCGSFlagsMaskAppleRightCommandKey,
+        55,
+        54,
+        java_awt_event_InputEvent_META_DOWN_MASK,
+        java_awt_event_KeyEvent_VK_META
+    },
+    // NSNumericPadKeyMask
+    {
+        NSHelpKeyMask,
+        0,
+        0,
+        0, // no Java equivalent
+        java_awt_event_KeyEvent_VK_HELP
+    },
+    // NSFunctionKeyMask
+    {0, 0, 0, 0, 0}
+};
+
+/*
+ * Almost all unicode characters just go from NS to Java with no translation.
+ *  For the few exceptions, we handle it here with this small table.
+ */
+static struct _char {
+    NSUInteger modifier;
+    unichar nsChar;
+    unichar javaChar;
+}
+const charTable[] = {
+    // map enter on keypad to same as return key
+    {0,              NSEnterCharacter,          NSNewlineCharacter},
+
+    // [3134616] return newline instead of carriage return
+    {0,              NSCarriageReturnCharacter, NSNewlineCharacter},
+
+    // "delete" means backspace in Java
+    {0,              NSDeleteCharacter,         NSBackspaceCharacter},
+    {0,              NSDeleteFunctionKey,     NSDeleteCharacter},
+
+    // back-tab is only differentiated from tab by Shift flag
+    {NSShiftKeyMask, NSBackTabCharacter,     NSTabCharacter},
+
+    {0, 0, 0}
+};
+
+static unichar
+NsCharToJavaChar(unichar nsChar, NSUInteger modifiers)
+{
+    const struct _char *cur;
+    NSUInteger keyModifierFlags =
+        NSShiftKeyMask | NSControlKeyMask |
+        NSAlternateKeyMask | NSCommandKeyMask;
+
+    // Mask off just the keyboard modifiers from the event modifier mask.
+    NSUInteger testableFlags = (modifiers & keyModifierFlags);
+
+    // walk through table & find the match
+    for (cur = charTable; cur->nsChar != 0 ; cur++) {
+        // <rdar://Problem/3476426> Need to determine if we are looking at
+        // a plain keypress or a modified keypress.  Don't adjust the
+        // character of a keypress with a modifier.
+        if (cur->nsChar == nsChar) {
+            if (cur->modifier == 0 && testableFlags == 0) {
+                // If the modifier field is 0, that means to transform
+                // this character if no additional keyboard modifiers are set.
+                // This lets ctrl-C be reported as ctrl-C and not transformed
+                // into Newline.
+                return cur->javaChar;
+            } else if (cur->modifier != 0 &&
+                       (testableFlags & cur->modifier) == testableFlags)
+            {
+                // Likewise, if the modifier field is nonzero, that means
+                // transform this character if only these modifiers are
+                // set in the testable flags.
+                return cur->javaChar;
+            }
+        }
+    }
+
+    if (nsChar >= NSUpArrowFunctionKey && nsChar <= NSModeSwitchFunctionKey) {
+        return java_awt_event_KeyEvent_CHAR_UNDEFINED;
+    }
+
+    // otherwise return character unchanged
+    return nsChar;
+}
+
+/*
+ * This is the function that uses the table above to take incoming
+ * NSEvent keyCodes and translate to the Java virtual key code.
+ */
+static void
+NsCharToJavaVirtualKeyCode(unichar ch, unichar deadChar,
+                           NSUInteger flags, unsigned short key,
+                           jint *keyCode, jint *keyLocation, BOOL *postsTyped)
+{
+    static size_t size = sizeof(keyTable) / sizeof(struct _key);
+    NSInteger offset;
+
+    if (deadChar) {
+        const struct CharToVKEntry *map;
+        for (map = charToDeadVKTable; map->c != 0; ++map) {
+            if (deadChar == map->c) {
+                *keyCode = map->javaKey;
+                *postsTyped = NO;
+                // TODO: use UNKNOWN here?
+                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+                return;
+            }
+        }
+        // If we got here, we keep looking for a normal key.
+    }
+
+    if ([[NSCharacterSet letterCharacterSet] characterIsMember:ch]) {
+        // key is an alphabetic character
+        unichar lower;
+        lower = tolower(ch);
+        offset = lower - 'a';
+        if (offset >= 0 && offset <= 25) {
+            // some chars in letter set are NOT actually A-Z characters?!
+            // skip them...
+            *postsTyped = YES;
+            // do quick conversion
+            *keyCode = java_awt_event_KeyEvent_VK_A + offset;
+            *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
+            return;
+        }
+    }
+
+    if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:ch]) {
+        // key is a digit
+        offset = ch - '0';
+        // make sure in range for decimal digits
+        if (offset >= 0 && offset <= 9)    {
+            jboolean numpad = (flags & NSNumericPadKeyMask) != 0;
+            *postsTyped = YES;
+            if (numpad) {
+                *keyCode = offset + java_awt_event_KeyEvent_VK_NUMPAD0;
+                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD;
+            } else {
+                *keyCode = offset + java_awt_event_KeyEvent_VK_0;
+                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
+            }
+            return;
+        }
+    }
+
+    if (key < size) {
+        *postsTyped = keyTable[key].postsTyped;
+        *keyCode = keyTable[key].javaKeyCode;
+        *keyLocation = keyTable[key].javaKeyLocation;
+    } else {
+        // Should we report this? This means we've got a keyboard
+        // we don't know about...
+        *postsTyped = NO;
+        *keyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
+        *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+    }
+}
+
+/*
+ * This returns the java key data for the key NSEvent modifiers
+ * (after NSFlagChanged).
+ */
+static void
+NsKeyModifiersToJavaKeyInfo(NSUInteger nsFlags, unsigned short eventKeyCode,
+                            jint *javaKeyCode,
+                            jint *javaKeyLocation,
+                            jint *javaKeyType)
+{
+    static NSUInteger sPreviousNSFlags = 0;
+
+    const struct _nsKeyToJavaModifier* cur;
+    NSUInteger oldNSFlags = sPreviousNSFlags;
+    NSUInteger changedNSFlags = oldNSFlags ^ nsFlags;
+    sPreviousNSFlags = nsFlags;
+
+    *javaKeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
+    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+    *javaKeyType = java_awt_event_KeyEvent_KEY_PRESSED;
+
+    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
+        if (changedNSFlags & cur->nsMask) {
+            *javaKeyCode = cur->javaKey;
+            *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
+            // TODO: uses SPI...
+            //if (changedNSFlags & cur->cgsLeftMask) {
+            //    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_LEFT;
+            //} else if (changedNSFlags & cur->cgsRightMask) {
+            //    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_RIGHT;
+            //}
+            if (eventKeyCode == cur->leftKeyCode) {
+                *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_LEFT;
+            } else if (eventKeyCode == cur->rightKeyCode) {
+                *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_RIGHT;
+            }
+            *javaKeyType = (cur->nsMask & nsFlags) ?
+                java_awt_event_KeyEvent_KEY_PRESSED :
+                java_awt_event_KeyEvent_KEY_RELEASED;
+            break;
+        }
+    }
+}
+
+/*
+ * This returns the java modifiers for a key NSEvent.
+ */
+static jint
+NsKeyModifiersToJavaModifiers(NSUInteger nsFlags)
+{
+    jint javaModifiers = 0;
+    const struct _nsKeyToJavaModifier* cur;
+
+    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
+        if ((cur->nsMask & nsFlags) != 0) {
+            javaModifiers |= cur->javaMask;
+        }
+    }
+
+    return javaModifiers;
+}
+
+/*
+ * Returns the correct java character for a key event.  Most unicode
+ * characters don't require any fussing, but a few seem to need adjusting,
+ * see nsCharToJavaChar.
+ */
+static unichar
+GetJavaCharacter(NSEvent *event, unsigned int index)
+{
+    unichar returnValue = java_awt_event_KeyEvent_CHAR_UNDEFINED;
+    NSString *chars = nil;
+    unichar testChar = 0, testDeadChar = 0;
+    jint javaModifiers = NsKeyModifiersToJavaModifiers([event modifierFlags]);
+
+    switch ([event type]) {
+    case NSFlagsChanged:
+        // no character for modifier keys
+        returnValue = java_awt_event_KeyEvent_CHAR_UNDEFINED;
+        break;
+
+    case NSKeyDown:
+    case NSKeyUp:
+        chars = [event characters];
+        if ([chars length] > 0) {
+            testChar = [chars characterAtIndex:index];
+        }
+
+        if (javaModifiers == 0) {
+            // TODO: uses SPI...
+            //if (TSMGetDeadKeyState() != 0) {
+            //    testDeadChar = [self deadKeyCharacter];
+            //}
+        }
+
+        if (testChar != 0) {
+            returnValue = NsCharToJavaChar(testChar, [event modifierFlags]);
+        } else if (testDeadChar != 0) {
+            returnValue = NsCharToJavaChar(testDeadChar, [event modifierFlags]);
+        } else {
+            returnValue = java_awt_event_KeyEvent_CHAR_UNDEFINED;
+        }
+        break;
+
+    default:
+        //[NSException raise:@"AWT error" format:@"Attempt to get character code from non-key event!"];
+        break;
+    }
+
+    return returnValue;
+}
+
+/*
+static jchar
+GetDeadKeyCharacter(NSEvent *event)
+{
+    // If the current event is not a dead key, return 0.
+    // TODO: this uses SPI; it's an optimization but not strictly necessary
+    //if (TSMGetDeadKeyState() == 0) {
+    //    return 0;
+    //}
+
+    // AppKit does not track dead-key states directly, but TSM does. Even then,
+    // it's not necessarily all that accurate, because the dead key can change
+    // given some combination of modifier keys on certain layouts.
+    // As a result, finding the unicode value for the front end of the dead
+    // key is a bit of a heuristic.
+
+    // This algorithm was suggested by Aki Inoue.
+    // When you get a dead key, you need to simiulate what would happen in
+    // the current dead-key and modifier state if the user hit the spacebar.
+    // That will tell you the front end of the dead-key combination.
+
+    unichar returnValue = 0;
+    const UInt16 VIRTUAL_KEY_SPACE = 49;
+    UInt32 deadKeyState = 0;
+    UInt32 appkitFlags = [event modifierFlags];
+    UniCharCount actualStringLength;
+    UniChar unicodeInputString[16];
+    TISInputSourceRef keyLayout;
+    const void *chrData;
+
+    keyLayout = TISCopyCurrentKeyboardLayoutInputSource();
+    CFDataRef cfUchrData =
+        TISGetInputSourceProperty(keyLayout, kTISPropertyUnicodeKeyLayoutData);
+
+    if (cfUchrData == NULL) {
+        return returnValue;
+    }
+
+    // The actual 'uchr' table is inside the CFDataRef.
+    chrData = CFDataGetBytePtr(cfUchrData);
+
+    UInt8 keyboardType = LMGetKbdType();
+    UInt32 keyEventModifiers = 0;
+    if (appkitFlags & NSShiftKeyMask)      keyEventModifiers |= shiftKey;
+    if (appkitFlags & NSCommandKeyMask)    keyEventModifiers |= cmdKey;
+    if (appkitFlags & NSAlphaShiftKeyMask) keyEventModifiers |= alphaLock;
+    if (appkitFlags & NSControlKeyMask)    keyEventModifiers |= controlKey;
+    if (appkitFlags & NSAlternateKeyMask)  keyEventModifiers |= optionKey;
+
+    if (noErr == UCKeyTranslate(chrData,
+        VIRTUAL_KEY_SPACE,
+        ([event type] == NSKeyDown ? kUCKeyActionDown : kUCKeyActionUp),
+        keyEventModifiers,
+        keyboardType,
+        kUCKeyTranslateNoDeadKeysMask,
+        &deadKeyState,
+        16,
+        &actualStringLength,
+        unicodeInputString))
+    {
+        if (actualStringLength > 0) {
+            returnValue = unicodeInputString[0];
+        }
+    }
+
+    return returnValue;
+}
+*/
+
+void
+DeliverJavaKeyEvent(JNIEnv *env, NSEvent *event, jobject peer)
+{
+    jint javaKeyType = java_awt_event_KeyEvent_KEY_PRESSED;
+    jint javaKeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
+    jint javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+    NSString *chars = nil;
+    BOOL postsTyped;
+    unichar testChar = java_awt_event_KeyEvent_CHAR_UNDEFINED;
+    unichar testDeadChar = 0;
+    jint javaModifiers = 0;
+
+    switch ([event type]) {
+    case NSFlagsChanged:
+        NsKeyModifiersToJavaKeyInfo([event modifierFlags],
+                                    [event keyCode],
+                                    &javaKeyCode,
+                                    &javaKeyLocation,
+                                    &javaKeyType);
+        break;
+
+    case NSKeyDown:
+    case NSKeyUp:
+        chars = [event charactersIgnoringModifiers];
+        if ([chars length] > 0) {
+            testChar = [chars characterAtIndex:0];
+        }
+
+        javaModifiers = NsKeyModifiersToJavaModifiers([event modifierFlags]);
+        if (javaModifiers == 0) {
+      // TODO: dead key chars
+//            testDeadChar = GetDeadKeyCharacter(event);
+        }
+
+        NsCharToJavaVirtualKeyCode(testChar, testDeadChar,
+                                   [event modifierFlags], [event keyCode],
+                                   &javaKeyCode, &javaKeyLocation, &postsTyped);
+        if( !postsTyped ) {
+            testChar = java_awt_event_KeyEvent_CHAR_UNDEFINED;
+        }
+
+        javaKeyType = ([event type] == NSKeyDown) ?
+            java_awt_event_KeyEvent_KEY_PRESSED :
+            java_awt_event_KeyEvent_KEY_RELEASED;
+        break;
+
+    default:
+        //[NSException raise:@"AWT error" format:@"Attempt to get virtual key code from non-key event!"];
+        break;
+    }
+
+    if (env != NULL) {
+        static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
+        static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_CPlatformView, "deliverKeyEvent", "(IICII)V");
+        JNFCallVoidMethod(env, peer, jm_deliverKeyEvent,
+                          javaKeyType, javaModifiers,
+                          testChar, javaKeyCode, javaKeyLocation);
+    }
+}
+
+/*
+ * Converts the NSEvent type to a Java mouse button mask.
+ */
+static jint
+NsMouseModifiersToJavaModifiers(NSEvent *event)
+{
+    switch ([event type]) {
+    case NSLeftMouseDown:
+        return java_awt_event_InputEvent_BUTTON1_DOWN_MASK;
+    case NSRightMouseDown:
+        return java_awt_event_InputEvent_BUTTON3_DOWN_MASK;
+    case NSOtherMouseDown:
+        return java_awt_event_InputEvent_BUTTON2_DOWN_MASK;
+    default:
+        return 0;
+    }
+}
+
+jint GetJavaMouseModifiers(NSEvent *event)
+{
+    static NSInteger sMaxMouseButton = 2;
+
+    NSInteger button = [event buttonNumber];
+    if (button > sMaxMouseButton) {
+        sMaxMouseButton = button;
+    }
+
+    // Mousing needs the key modifiers
+    jint modifiers = NsKeyModifiersToJavaModifiers([event modifierFlags]);
+
+
+    /*
+     * Ask Quartz about mouse buttons state
+     */
+
+    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
+                                 kCGMouseButtonLeft)) {
+        modifiers |= java_awt_event_InputEvent_BUTTON1_DOWN_MASK;
+    }
+
+    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
+                                 kCGMouseButtonRight)) {
+        modifiers |= java_awt_event_InputEvent_BUTTON3_DOWN_MASK;
+    }
+
+    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
+                                 kCGMouseButtonCenter)) {
+        modifiers |= java_awt_event_InputEvent_BUTTON2_DOWN_MASK;
+    }
+
+    // like JDK 1.6, we pretend that additional buttons are BUTTON2
+    NSInteger otherButton = 3;
+    for (; otherButton <= sMaxMouseButton; otherButton++) {
+        if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
+                                 otherButton)) {
+            modifiers |= java_awt_event_InputEvent_BUTTON2_DOWN_MASK;
+        }
+    }
+
+    return modifiers;
+}
+
+/*
+ * Converts an NSEvent button number to a MouseEvent constant.
+ */
+static jint
+NSButtonToJavaButton(NSInteger nsButtonNumber)
+{
+    jint jbutton = java_awt_event_MouseEvent_NOBUTTON;
+
+    if (nsButtonNumber == 0) { // left
+        jbutton = java_awt_event_MouseEvent_BUTTON1;
+    } else if (nsButtonNumber == 1) { // right
+        jbutton = java_awt_event_MouseEvent_BUTTON3;
+    } else if (nsButtonNumber == 2) { // middle
+        jbutton = java_awt_event_MouseEvent_BUTTON2;
+    }
+
+    return jbutton;
+}
+
+
+static BOOL isDragging = NO;
+
+void
+DeliverMouseClickedEvent(JNIEnv *env, NSEvent *event, jobject peer)
+{
+    NSPoint pt = [event locationInWindow];
+    NSPoint pOnScreen = [NSEvent mouseLocation];
+    jint etype = java_awt_event_MouseEvent_MOUSE_CLICKED;
+    jint modifiers = GetJavaMouseModifiers(event);
+    jint clickCount = [event clickCount];
+    jint button = NSButtonToJavaButton([event buttonNumber]);
+
+    if (env != NULL) {
+        static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
+        static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_CPlatformView,
+                                "deliverMouseEvent", "(IIIIFFFF)V");
+        JNFCallVoidMethod(env, peer, jm_deliverMouseEvent,
+                          etype, modifiers,
+                          clickCount, button,
+                          pt.x, pt.y,
+                          pOnScreen.x, pOnScreen.y);
+    }
+}
+
+/*
+ * After every key down event, this is called to make the matching
+ * KEY_TYPED (if this key posts those).  We use the same NSEvent for it,
+ * but create a KEY_TYPED java event this time.
+ * If this key doesn't post typed, we don't post the event.
+ *
+ * TODO: some duplicated effort here; could just fold it
+ * into DeliverJavaKeyEvent...
+ */
+static void
+DeliverKeyTypedEvents(JNIEnv *env, NSEvent *nsEvent, jobject peer)
+{
+    if (peer == NULL) {
+        return;
+    }
+
+    jint javaKeyCode, javaKeyLocation;
+    BOOL postsTyped = NO;
+    unichar testChar, testDeadChar = 0;
+    jint javaModifiers = NsKeyModifiersToJavaModifiers([nsEvent modifierFlags]);
+
+    if (javaModifiers == 0) {
+        testDeadChar = [nsEvent deadKeyCharacter];
+    }
+
+    NSString *theChars = [nsEvent characters];
+    unsigned i, stringLength = [theChars length];
+
+    for (i = 0; i < stringLength; i++) {
+        testChar = [theChars characterAtIndex:i];
+        NsCharToJavaVirtualKeyCode(testChar, testDeadChar,
+                                   [nsEvent modifierFlags], [nsEvent keyCode],
+                                   &javaKeyCode, &javaKeyLocation, &postsTyped);
+
+        if (postsTyped) {
+            // Some keys may generate a KEY_TYPED, but we can't determine
+            // what that character is. That's likely a bug, but for now we
+            // just check for CHAR_UNDEFINED.
+            unichar theChar = GetJavaCharacter(nsEvent, i);
+            if (theChar != java_awt_event_KeyEvent_CHAR_UNDEFINED) {
+                if (env != NULL) {
+                    static JNF_CLASS_CACHE(jc_CPlatformView,
+                                           "sun/lwawt/macosx/CPlatformView");
+                    static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_CPlatformView,
+                                            "deliverKeyEvent", "(IICII)V");
+                    JNFCallVoidMethod(env, peer, jm_deliverKeyEvent,
+                                      java_awt_event_KeyEvent_KEY_TYPED,
+                                      javaModifiers,
+                                      theChar,
+                                      java_awt_event_KeyEvent_VK_UNDEFINED,
+                                      java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN);
+                }
+            }
+        }
+    }
+}
+
+/*
+ * There are a couple of extra events that Java expects to get that don't
+ * actually correspond to a direct NSEvent, KEY_TYPED and MOUSE_CLICKED are
+ * both extra events that are sort of redundant with ordinary
+ * key downs and mouse ups.  In this extra message, we take the original
+ * input event and if necessary, cons up a special follow-on event which
+ * we dispatch over to Java.
+ *
+ * For Java, keyDown's generate a KeyPressed (for each hardware key as it
+ * goes down) and then a "logical KeyTyped" event for the key event. (So
+ * a shift-a generates two presses, one keytyped of "A", and then two
+ * releases).  The standard event utility function converts a key down to
+ * a key pressed. When appropriate, we need to cons up another event
+ * (KEY_TYPED) to follow a keyDown.
+ *
+ * Java expects you to send a clicked event if you got a down & up, with no
+ * intervening drag. So in addition to the MOUSE_RELEASED event that a
+ * mouseUp is translated to, we also have to cons up a MOUSE_CLICKED event
+ * for that case. Mike Paquette, god of Window Server event handling,
+ * confirmed this fact about how to determine if a mouse up event had an
+ * intervening drag:
+ * An initial mouse-down gets a click count of 1. Subsequent left or right
+ * mouse-downs within the space/time tolerance limits increment the click
+ * count.  A mouse-up will have the clickCount of the last mouseDown if
+ * mouse is not outside the tolerance limits, but 0 otherwise.  Thus, a
+ * down-up sequence without any intervening drag will have a click count
+ * of 0 in the mouse-up event.  NOTE: The problem with this is that
+ * clickCount goes to zero after some point in time. So a long, click &
+ * hold without moving and then release the mouse doesn't create a
+ * MOUSE_CLICK event as it should. Java AWT now tracks the drag state itself.
+ *
+ * As another add-on, we also check for the status of mouse-motion events
+ * after a mouse-down, so we know whether to generate mouse-dragged events
+ * during this down sequence.
+ */
+void
+SendAdditionalJavaEvents(JNIEnv *env, NSEvent *nsEvent, jobject peer)
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    NSEventType type = [nsEvent type];
+    switch (type) {
+    case NSKeyDown:
+        break;
+
+    case NSLeftMouseUp:
+    case NSRightMouseUp:
+    case NSOtherMouseUp:
+        // TODO: we may need to pull in changedDragToMove here...
+        //if (!isDragging && ([NSViewAWT changedDragToMove]==NO)) {
+        if (!isDragging) {
+            // got down/up pair with no dragged in between; ignores drag events
+            // that have been morphed to move events
+            DeliverMouseClickedEvent(env, nsEvent, peer);
+        }
+        break;
+
+// TODO: to be implemented...
+#if 0
+    case NSLeftMouseDragged:
+    case NSRightMouseDragged:
+    case NSOtherMouseDragged:
+        //
+        // During a drag, the AppKit does not send mouseEnter and mouseExit
+        // events.  It turns out that doing a hitTest causes the window's
+        // view hierarchy to be locked from drawing and that, of course,
+        // slows everything way down.  Synthesize mouseEnter and mouseExit
+        // then forward.
+        //
+        NSView *hitView = [[source model] hitTest:[nsEvent locationInWindow]];
+
+        if ((hitView != nil) &&
+            ([hitView conformsToProtocol:@protocol(AWTPeerControl)]))
+        {
+            if (sLastMouseDraggedView == nil) {
+                sLastMouseDraggedView = hitView;
+            }
+            else if (hitView != sLastMouseDraggedView) {
+                // We know sLastMouseDraggedView is a AWTPeerControl.
+                jobject lastPeer =
+                    [(id <AWTPeerControl>)sLastMouseDraggedView peer];
+
+                // Send mouseExit to sLastMouseDraggedView
+                jobject exitEvent =
+                    makeMouseEvent(env, nsEvent, lastPeer,
+                                   sLastMouseDraggedView,
+                                   java_awt_event_MouseEvent_MOUSE_EXITED);
+                pushEventForward(exitEvent, env);
+                (*env)->DeleteLocalRef(env, exitEvent);
+
+                // Send mouseEnter to hitView
+                jobject enterEvent =
+                    makeMouseEvent(env, nsEvent, peer, hitView,
+                                   java_awt_event_MouseEvent_MOUSE_ENTERED);
+                pushEventForward(enterEvent, env);
+
+                (*env)->DeleteLocalRef(env, enterEvent);
+
+                // Set sLastMouseDraggedView = hitView
+                sLastMouseDraggedView = hitView;
+            }
+        }
+        break;
+#endif
+
+    default:
+        break;
+    }
+}
+
+jlong UTC(NSEvent *event) {
+    struct timeval tv;
+    if (gettimeofday(&tv, NULL) == 0) {
+        long long sec = (long long)tv.tv_sec;
+        return (sec*1000) + (tv.tv_usec/1000);
+    }
+    return 0;
+}
+
+JNIEXPORT void JNICALL
+Java_java_awt_AWTEvent_nativeSetSource
+    (JNIEnv *env, jobject self, jobject newSource)
+{
+}
diff --git a/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.h b/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.h
new file mode 100644
index 0000000..820be37
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// REMIND: import <jawt_md.h>
+#import <JavaVM/jawt_md.h>
+
+/*
+ * The CALayer-based rendering model returns an object conforming
+ * to the JAWT_SurfaceLayers protocol
+ *
+ * @protocol JAWT_SurfaceLayers
+ * @property (readwrite, retain) CALayer *layer;
+ * @property (readonly) CALayer *windowLayer;
+ * @end
+ */
+
+@interface AWTSurfaceLayers : NSObject<JAWT_SurfaceLayers> {
+@private
+    CALayer *layer;
+    CALayer *windowLayer;
+}
+
+- (id) initWithWindowLayer: (CALayer *)windowLayer;
+- (void) setBounds: (CGRect)rect;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.m b/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.m
new file mode 100644
index 0000000..f3ab2d7
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.m
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "AWTSurfaceLayers.h"
+#import "ThreadUtilities.h"
+#import "LWCToolkit.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+@implementation AWTSurfaceLayers
+
+@synthesize windowLayer;
+
+- (id) initWithWindowLayer:(CALayer *)aWindowLayer {
+    self = [super init];
+    if (self == nil) return self;
+
+    windowLayer = aWindowLayer;
+
+    return self;
+}
+
+
+- (CALayer *) layer {
+    return layer;
+}
+
+- (void) setLayer:(CALayer *)newLayer {
+    if (layer != newLayer) {
+        if (layer != nil || newLayer == nil) {
+            [layer removeFromSuperlayer];
+            [layer release];
+        }
+
+        if (newLayer != nil) {
+            layer = [newLayer retain];
+            // REMIND: window layer -> container layer
+            [windowLayer addSublayer: layer];
+        }
+    }
+}
+
+// Updates back buffer size of the layer if it's an OpenGL layer
+// including all OpenGL sublayers
++ (void) repaintLayersRecursively:(CALayer*)aLayer {
+    if ([aLayer isKindOfClass:[CAOpenGLLayer class]]) {
+        [aLayer setNeedsDisplay];
+    }
+    for(CALayer *child in aLayer.sublayers) {
+        [AWTSurfaceLayers repaintLayersRecursively: child];
+    }
+}
+
+- (void) setBounds:(CGRect)rect {
+    layer.anchorPoint = CGPointMake(0, 0);
+
+    // translates values to the coordinate system of the "root" layer
+    CGFloat newY = windowLayer.bounds.size.height - rect.origin.y - rect.size.height;
+
+    // REMIND: why do we need to inverse position?
+    CGRect newRect = CGRectMake(-rect.origin.x, -newY, rect.size.width, rect.size.height);
+
+    layer.bounds = newRect;
+    [AWTSurfaceLayers repaintLayersRecursively:layer];
+}
+
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformComponent
+ * Method:    nativeCreateLayer
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CPlatformComponent_nativeCreateComponent
+(JNIEnv *env, jobject obj, jlong windowLayerPtr)
+{
+  __block AWTSurfaceLayers *surfaceLayers = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+  [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+      AWT_ASSERT_APPKIT_THREAD;
+
+      CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
+      surfaceLayers = [[AWTSurfaceLayers alloc] initWithWindowLayer: windowLayer];
+      CFRetain(surfaceLayers);
+      [surfaceLayers release];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+  return ptr_to_jlong(surfaceLayers);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformComponent
+ * Method:    nativeSetBounds
+ * Signature: (JIIII)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformComponent_nativeSetBounds
+(JNIEnv *env, jclass clazz, jlong surfaceLayersPtr, jint x, jint y, jint width, jint height)
+{
+JNF_COCOA_ENTER(env);
+
+  AWTSurfaceLayers *surfaceLayers = OBJC(surfaceLayersPtr);
+  [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+      AWT_ASSERT_APPKIT_THREAD;
+
+      CGRect rect = CGRectMake(x, y, width, height);
+      [surfaceLayers setBounds: rect];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/AWTView.h b/jdk/src/macosx/native/sun/awt/AWTView.h
new file mode 100644
index 0000000..e6733e6
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTView.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CDragSource.h"
+#import "CDropTarget.h"
+
+@interface AWTView : NSView<NSTextInputClient> {
+@private
+    jobject m_cPlatformView;
+
+    // Handler for the tracking rect needed for Enter/Exit events management.
+    NSTrackingRectTag rolloverTrackingRectTag;
+
+    // TODO: NSMenu *contextualMenu;
+
+    // dnd support (see AppKit/NSDragging.h, NSDraggingSource/Destination):
+    CDragSource *_dragSource;
+    CDropTarget *_dropTarget;
+
+    // Input method data
+    jobject fInputMethodLOCKABLE;
+    BOOL fKeyEventsNeeded;
+    BOOL fProcessingKeystroke;
+
+    BOOL fEnablePressAndHold;
+    BOOL fInPressAndHold;
+    BOOL fPAHNeedsToSelect;
+
+    id cglLayer; // is a sublayer of view.layer
+}
+
+@property (nonatomic, retain) id cglLayer;
+
+- (id) initWithRect:(NSRect) rect platformView:(jobject)cPlatformView windowLayer:(CALayer*)windowLayer;
+- (void) deliverJavaMouseEvent: (NSEvent *) event;
+- (void) resetTrackingRect;
+- (void) deliverJavaKeyEventHelper: (NSEvent *) event;
+- (jobject) awtComponent:(JNIEnv *)env;
+
+- (void) setDragSource:(CDragSource *)source;
+- (void) setDropTarget:(CDropTarget *)target;
+
+
+// Input method-related events
+- (void)setInputMethod:(jobject)inputMethod;
+- (void)abandonInput;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/AWTView.m b/jdk/src/macosx/native/sun/awt/AWTView.m
new file mode 100644
index 0000000..8b987f8
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTView.m
@@ -0,0 +1,1184 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CGLGraphicsConfig.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "ThreadUtilities.h"
+#import "AWTView.h"
+#import "AWTEvent.h"
+#import "AWTWindow.h"
+#import "LWCToolkit.h"
+#import "JavaComponentAccessibility.h"
+#import "JavaTextAccessibility.h"
+#import "GeomUtilities.h"
+#import "OSVersion.h"
+#import "CGLLayer.h"
+
+@interface AWTView()
+@property (retain) CDropTarget *_dropTarget;
+@property (retain) CDragSource *_dragSource;
+@end
+
+// Uncomment this line to see fprintfs of each InputMethod API being called on this View
+//#define IM_DEBUG TRUE
+//#define EXTRA_DEBUG
+
+
+static BOOL shouldUsePressAndHold() {
+    static int shouldUsePressAndHold = -1;
+    if (shouldUsePressAndHold != -1) return shouldUsePressAndHold;
+    shouldUsePressAndHold = !isSnowLeopardOrLower();
+    return shouldUsePressAndHold;
+}
+
+@implementation AWTView
+
+@synthesize _dropTarget;
+@synthesize _dragSource;
+@synthesize cglLayer;
+
+// Note: Must be called on main (AppKit) thread only
+- (id) initWithRect: (NSRect) rect
+       platformView: (jobject) cPlatformView
+       windowLayer: (CALayer*) windowLayer
+{
+AWT_ASSERT_APPKIT_THREAD;
+    // Initialize ourselves
+    self = [super initWithFrame: rect];
+    if (self == nil) return self;
+
+    m_cPlatformView = cPlatformView;
+    fInputMethodLOCKABLE = NULL;
+    fKeyEventsNeeded = NO;
+    fProcessingKeystroke = NO;
+
+    fEnablePressAndHold = shouldUsePressAndHold();
+    fInPressAndHold = NO;
+    fPAHNeedsToSelect = NO;
+
+    if (windowLayer != nil) { 
+        self.cglLayer = windowLayer;
+        [self setWantsLayer: YES];
+        [self.layer addSublayer: (CALayer *)cglLayer];
+        [self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
+        [self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
+        [self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];    
+    }
+    
+#if USE_INTERMEDIATE_BUFFER
+    self.cglLayer = windowLayer;
+    [self setWantsLayer: YES];
+    [self.layer addSublayer: (CALayer *)cglLayer];
+    [self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
+    [self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
+    [self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
+#ifdef REMOTELAYER
+    CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
+    parentLayer.parentLayer = NULL;
+    parentLayer.remoteLayer = NULL;
+    if (JRSRemotePort != 0 && remoteSocketFD > 0) {
+        CGLLayer *remoteLayer = [CGLLayer layer];
+        remoteLayer.target = GL_TEXTURE_2D;
+        NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer);
+        parentLayer.remoteLayer = remoteLayer;
+        remoteLayer.parentLayer = parentLayer;
+        remoteLayer.remoteLayer = NULL;
+        remoteLayer.jrsRemoteLayer = [remoteLayer createRemoteLayerBoundTo:JRSRemotePort];
+        CFRetain(remoteLayer);  // REMIND
+        remoteLayer.frame = CGRectMake(0, 0, 720, 500); // REMIND
+        CFRetain(remoteLayer.jrsRemoteLayer); // REMIND
+        int layerID = [remoteLayer.jrsRemoteLayer layerID];
+        NSLog(@"layer id to send = %d", layerID);
+        sendLayerID(layerID);
+    }
+#endif /* REMOTELAYER */
+#endif
+    return self;
+}
+
+- (void) dealloc {
+AWT_ASSERT_APPKIT_THREAD;
+
+    self.cglLayer = nil;
+#if USE_INTERMEDIATE_BUFFER
+    self.cglLayer = nil;
+#endif
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    (*env)->DeleteGlobalRef(env, m_cPlatformView);
+    m_cPlatformView = NULL;
+
+    if (fInputMethodLOCKABLE != NULL)
+    {
+        JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+        JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
+        fInputMethodLOCKABLE = NULL;
+    }
+
+
+    [super dealloc];
+}
+
+- (void) viewDidMoveToWindow {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [AWTToolkit eventCountPlusPlus];
+
+    [[self window] makeFirstResponder: self];
+    if ([self window] != NULL) {
+        [self resetTrackingRect];
+    }
+}
+
+- (BOOL) acceptsFirstMouse: (NSEvent *)event {
+    return YES;
+}
+
+- (BOOL) acceptsFirstResponder {
+    return YES;
+}
+
+- (BOOL) becomeFirstResponder {
+    return YES;
+}
+
+- (BOOL) preservesContentDuringLiveResize {
+    return YES;
+}
+
+/*
+ * Automatically triggered functions.
+ */
+
+/*
+ * MouseEvents support
+ */
+
+- (void) mouseDown: (NSEvent *)event {
+    NSInputManager *inputManager = [NSInputManager currentInputManager];
+    if ([inputManager wantsToHandleMouseEvents]) {
+#if IM_DEBUG
+        NSLog(@"-> IM wants to handle event");
+#endif
+        if (![inputManager handleMouseEvent:event]) {
+            [self deliverJavaMouseEvent: event];
+        } else {
+#if IM_DEBUG
+            NSLog(@"-> Event was handled.");
+#endif
+        }
+    } else {
+        NSLog(@"-> IM does not want to handle event");
+        [self deliverJavaMouseEvent: event];
+    }
+}
+
+- (void) mouseUp: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) rightMouseDown: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) rightMouseUp: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) otherMouseDown: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) otherMouseUp: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) mouseMoved: (NSEvent *)event {
+    // TODO: better way to redirect move events to the "under" view
+
+    NSPoint eventLocation = [event locationInWindow];
+    NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
+
+    if  ([self mouse: localPoint inRect: [self bounds]]) {
+        [self deliverJavaMouseEvent: event];
+    } else {
+        [[self nextResponder] mouseDown:event];
+    }
+}
+
+- (void) mouseDragged: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) rightMouseDragged: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) otherMouseDragged: (NSEvent *)event {
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) mouseEntered: (NSEvent *)event {
+    [[self window] setAcceptsMouseMovedEvents:YES];
+    //[[self window] makeFirstResponder:self];
+    [self deliverJavaMouseEvent: event];
+}
+
+- (void) mouseExited: (NSEvent *)event {
+    [[self window] setAcceptsMouseMovedEvents:NO];
+    [self deliverJavaMouseEvent: event];
+    //Restore the cursor back.
+    //[CCursorManager _setCursor: [NSCursor arrowCursor]];
+}
+
+- (void) scrollWheel: (NSEvent*) event {
+    [self deliverJavaMouseEvent: event];
+}
+
+/*
+ * KeyEvents support
+ */
+
+- (void) keyDown: (NSEvent *)event {
+
+    fProcessingKeystroke = YES;
+    fKeyEventsNeeded = YES;
+
+    // Allow TSM to look at the event and potentially send back NSTextInputClient messages.
+    [self interpretKeyEvents:[NSArray arrayWithObject:event]];
+
+    if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod]) {
+        fProcessingKeystroke = NO;
+        if (!fInPressAndHold) {
+            fInPressAndHold = YES;
+            fPAHNeedsToSelect = YES;
+        }
+        return;
+    }
+
+    if (![self hasMarkedText] && fKeyEventsNeeded) {
+        [self deliverJavaKeyEventHelper: event];
+    }
+
+    fProcessingKeystroke = NO;
+}
+
+- (void) keyUp: (NSEvent *)event {
+    [self deliverJavaKeyEventHelper: event];}
+
+- (void) flagsChanged: (NSEvent *)event {
+    [self deliverJavaKeyEventHelper: event];
+}
+
+/**
+ * Utility methods and accessors
+ */
+
+-(void) deliverJavaMouseEvent: (NSEvent *) event {
+    [AWTToolkit eventCountPlusPlus];
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    NSPoint eventLocation = [event locationInWindow];
+    NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
+    NSPoint absP = [NSEvent mouseLocation];
+    NSEventType type = [event type];
+
+    // Convert global numbers between Cocoa's coordinate system and Java.
+    // TODO: need consitent way for doing that both with global as well as with local coordinates.
+    // The reason to do it here is one more native method for getting screen dimension otherwise.
+
+    NSRect screenRect = [[NSScreen mainScreen] frame];
+    absP.y = screenRect.size.height - absP.y;
+    jint clickCount;
+
+    if (type == NSMouseEntered || 
+        type == NSMouseExited || 
+        type == NSScrollWheel ||
+        type == NSMouseMoved) {
+        clickCount = 0;
+    } else {
+        clickCount = [event clickCount];
+    }
+    
+    jint modifiers = GetJavaMouseModifiers(event);
+    static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent");
+    static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
+    jobject jEvent = JNFNewObject(env, jctor_NSEvent,
+                                  type, 
+                                  modifiers,
+                                  clickCount,
+                                  [event buttonNumber],
+                                  (jint)localPoint.x, (jint)localPoint.y,
+                                  (jint)absP.x, (jint)absP.y,
+                                  [event deltaY],
+                                  [event deltaX]);
+    if (jEvent == nil) {
+        // Unable to create event by some reason.
+        return;
+    }
+
+    static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
+    static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V");
+    JNFCallVoidMethod(env, m_cPlatformView, jm_deliverMouseEvent, jEvent);
+}
+
+
+- (void) clearTrackingRect {
+    if (rolloverTrackingRectTag > 0) {
+        [self removeTrackingRect:rolloverTrackingRectTag];
+        rolloverTrackingRectTag = 0;
+    }
+}
+
+- (void) resetTrackingRect {
+    [self clearTrackingRect];
+    rolloverTrackingRectTag = [self addTrackingRect:[self visibleRect]
+                                              owner:self
+                                           userData:NULL
+                                       assumeInside:NO];
+}
+
+- (void) resetCursorRects {
+    [super resetCursorRects];
+    [self resetTrackingRect];
+}
+
+-(void) deliverJavaKeyEventHelper: (NSEvent *) event {
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    // Pulled as-is as it's highly-depend on native code.
+    DeliverJavaKeyEvent(env, event, m_cPlatformView);
+}
+
+- (void) drawRect:(NSRect)dirtyRect {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [super drawRect:dirtyRect];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    if (env != NULL) {
+/*
+        if ([self inLiveResize]) {
+        NSRect rs[4];
+        NSInteger count;
+        [self getRectsExposedDuringLiveResize:rs count:&count];
+        for (int i = 0; i < count; i++) {
+            JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
+                 "deliverWindowDidExposeEvent", "(FFFF)V",
+                 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
+                 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
+        if ((*env)->ExceptionOccurred(env)) {
+            (*env)->ExceptionDescribe(env);
+            (*env)->ExceptionClear(env);
+        }
+        }
+        } else {
+*/
+        static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
+        static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");
+        JNFCallVoidMethod(env, m_cPlatformView, jm_deliverWindowDidExposeEvent);
+/*
+        }
+*/
+    }
+}
+
+// NSAccessibility support
+- (jobject)awtComponent:(JNIEnv*)env
+{
+    static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
+    static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;");
+    if ((env == NULL) || (m_cPlatformView == NULL)) {
+        NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters.");
+        if (env != NULL)
+        {
+            JNFDumpJavaStack(env);
+        }
+        return NULL;
+    }
+    jobject peer = JNFGetObjectField(env, m_cPlatformView, jf_Peer);
+    static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer");
+    static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;");
+    if (peer == NULL) {
+        NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView");
+        JNFDumpJavaStack(env);
+        return NULL;
+    }
+    return JNFGetObjectField(env, peer, jf_Target);
+}
+
+- (id)getAxData:(JNIEnv*)env
+{
+    return [[[JavaComponentAccessibility alloc] initWithParent:self withEnv:env withAccessible:[self awtComponent:env] withIndex:-1 withView:self withJavaRole:nil] autorelease];
+}
+
+- (NSArray *)accessibilityAttributeNames
+{
+    return [[super accessibilityAttributeNames] arrayByAddingObject:NSAccessibilityChildrenAttribute];
+}
+
+// NSAccessibility messages
+// attribute methods
+- (id)accessibilityAttributeValue:(NSString *)attribute
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
+    {
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+        (*env)->PushLocalFrame(env, 4);
+
+        id result = NSAccessibilityUnignoredChildrenForOnlyChild([self getAxData:env]);
+
+        (*env)->PopLocalFrame(env, NULL);
+
+        return result;
+    }
+    else
+    {
+        return [super accessibilityAttributeValue:attribute];
+    }
+}
+- (BOOL)accessibilityIsIgnored
+{
+    return YES;
+}
+
+- (id)accessibilityHitTest:(NSPoint)point
+{
+    AWT_ASSERT_APPKIT_THREAD;
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    (*env)->PushLocalFrame(env, 4);
+
+    id result = [[self getAxData:env] accessibilityHitTest:point withEnv:env];
+
+    (*env)->PopLocalFrame(env, NULL);
+
+    return result;
+}
+
+- (id)accessibilityFocusedUIElement
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    (*env)->PushLocalFrame(env, 4);
+
+    id result = [[self getAxData:env] accessibilityFocusedUIElement];
+
+    (*env)->PopLocalFrame(env, NULL);
+
+    return result;
+}
+
+// --- Services menu support for lightweights ---
+
+// finds the focused accessable element, and if it's a text element, obtains the text from it
+- (NSString *)accessibleSelectedText
+{
+    id focused = [self accessibilityFocusedUIElement];
+    if (![focused isKindOfClass:[JavaTextAccessibility class]]) return nil;
+    return [(JavaTextAccessibility *)focused accessibilitySelectedTextAttribute];
+}
+
+// same as above, but converts to RTFD
+- (NSData *)accessibleSelectedTextAsRTFD
+{
+    NSString *selectedText = [self accessibleSelectedText];
+    NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];
+    NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length]) documentAttributes:nil];
+    [styledText release];
+    return rtfdData;
+}
+
+// finds the focused accessable element, and if it's a text element, sets the text in it
+- (BOOL)replaceAccessibleTextSelection:(NSString *)text
+{
+    id focused = [self accessibilityFocusedUIElement];
+    if (![focused isKindOfClass:[JavaTextAccessibility class]]) return NO;
+    [(JavaTextAccessibility *)focused accessibilitySetSelectedTextAttribute:text];
+    return YES;
+}
+
+// called for each service in the Services menu - only handle text for now
+- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
+{
+    if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves
+
+    if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {
+        NSString *selectedText = [self accessibleSelectedText];
+        if (selectedText) return self;
+    }
+
+    return nil;
+}
+
+// fetch text from Java and hand off to the service
+- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types
+{
+    if ([types containsObject:NSStringPboardType])
+    {
+        [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
+        return [pboard setString:[self accessibleSelectedText] forType:NSStringPboardType];
+    }
+
+    if ([types containsObject:NSRTFDPboardType])
+    {
+        [pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
+        return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];
+    }
+
+    return NO;
+}
+
+// write text back to Java from the service
+- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
+{
+    if ([[pboard types] containsObject:NSStringPboardType])
+    {
+        NSString *text = [pboard stringForType:NSStringPboardType];
+        return [self replaceAccessibleTextSelection:text];
+    }
+
+    if ([[pboard types] containsObject:NSRTFDPboardType])
+    {
+        NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];
+        NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:nil];
+        NSString *text = [styledText string];
+        [styledText release];
+
+        return [self replaceAccessibleTextSelection:text];
+    }
+
+    return NO;
+}
+
+
+-(void) setDragSource:(CDragSource *)source {
+    self._dragSource = source;
+}
+
+
+- (void) setDropTarget:(CDropTarget *)target {
+    self._dropTarget = target;
+    [ThreadUtilities performOnMainThread:@selector(controlModelControlValid) onObject:self._dropTarget withObject:nil waitUntilDone:YES awtMode:YES];
+}
+
+/********************************  BEGIN NSDraggingSource Interface  ********************************/
+
+- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag
+{
+    // If draggingSource is nil route the message to the superclass (if responding to the selector):
+    CDragSource *dragSource = self._dragSource;
+    NSDragOperation dragOp = NSDragOperationNone;
+
+    if (dragSource != nil)
+        dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];
+    else if ([super respondsToSelector:@selector(draggingSourceOperationMaskForLocal:)])
+        dragOp = [super draggingSourceOperationMaskForLocal:flag];
+
+    return dragOp;
+}
+
+- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
+{
+    // If draggingSource is nil route the message to the superclass (if responding to the selector):
+    CDragSource *dragSource = self._dragSource;
+    NSArray* array = nil;
+
+    if (dragSource != nil)
+        array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];
+    else if ([super respondsToSelector:@selector(namesOfPromisedFilesDroppedAtDestination:)])
+        array = [super namesOfPromisedFilesDroppedAtDestination:dropDestination];
+
+    return array;
+}
+
+- (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint
+{
+    // If draggingSource is nil route the message to the superclass (if responding to the selector):
+    CDragSource *dragSource = self._dragSource;
+
+    if (dragSource != nil)
+        [dragSource draggedImage:image beganAt:screenPoint];
+    else if ([super respondsToSelector:@selector(draggedImage::)])
+        [super draggedImage:image beganAt:screenPoint];
+}
+
+- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation
+{
+    // If draggingSource is nil route the message to the superclass (if responding to the selector):
+    CDragSource *dragSource = self._dragSource;
+
+    if (dragSource != nil)
+        [dragSource draggedImage:image endedAt:screenPoint operation:operation];
+    else if ([super respondsToSelector:@selector(draggedImage:::)])
+        [super draggedImage:image endedAt:screenPoint operation:operation];
+}
+
+- (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint
+{
+    // If draggingSource is nil route the message to the superclass (if responding to the selector):
+    CDragSource *dragSource = self._dragSource;
+
+    if (dragSource != nil)
+        [dragSource draggedImage:image movedTo:screenPoint];
+    else if ([super respondsToSelector:@selector(draggedImage::)])
+        [super draggedImage:image movedTo:screenPoint];
+}
+
+- (BOOL)ignoreModifierKeysWhileDragging
+{
+    // If draggingSource is nil route the message to the superclass (if responding to the selector):
+    CDragSource *dragSource = self._dragSource;
+    BOOL result = FALSE;
+
+    if (dragSource != nil)
+        result = [dragSource ignoreModifierKeysWhileDragging];
+    else if ([super respondsToSelector:@selector(ignoreModifierKeysWhileDragging)])
+        result = [super ignoreModifierKeysWhileDragging];
+
+    return result;
+}
+
+/********************************  END NSDraggingSource Interface  ********************************/
+
+/********************************  BEGIN NSDraggingDestination Interface  ********************************/
+
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
+{
+    // If draggingDestination is nil route the message to the superclass:
+    CDropTarget *dropTarget = self._dropTarget;
+    NSDragOperation dragOp = NSDragOperationNone;
+
+    if (dropTarget != nil)
+        dragOp = [dropTarget draggingEntered:sender];
+    else if ([super respondsToSelector:@selector(draggingEntered:)])
+        dragOp = [super draggingEntered:sender];
+
+    return dragOp;
+}
+
+- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
+{
+    // If draggingDestination is nil route the message to the superclass:
+    CDropTarget *dropTarget = self._dropTarget;
+    NSDragOperation dragOp = NSDragOperationNone;
+
+    if (dropTarget != nil)
+        dragOp = [dropTarget draggingUpdated:sender];
+    else if ([super respondsToSelector:@selector(draggingUpdated:)])
+        dragOp = [super draggingUpdated:sender];
+
+    return dragOp;
+}
+
+- (void)draggingExited:(id <NSDraggingInfo>)sender
+{
+    // If draggingDestination is nil route the message to the superclass:
+    CDropTarget *dropTarget = self._dropTarget;
+
+    if (dropTarget != nil)
+        [dropTarget draggingExited:sender];
+    else if ([super respondsToSelector:@selector(draggingExited:)])
+        [super draggingExited:sender];
+}
+
+- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
+{
+    // If draggingDestination is nil route the message to the superclass:
+    CDropTarget *dropTarget = self._dropTarget;
+    BOOL result = FALSE;
+
+    if (dropTarget != nil)
+        result = [dropTarget prepareForDragOperation:sender];
+    else if ([super respondsToSelector:@selector(prepareForDragOperation:)])
+        result = [super prepareForDragOperation:sender];
+
+    return result;
+}
+
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{
+    // If draggingDestination is nil route the message to the superclass:
+    CDropTarget *dropTarget = self._dropTarget;
+    BOOL result = FALSE;
+
+    if (dropTarget != nil)
+        result = [dropTarget performDragOperation:sender];
+    else if ([super respondsToSelector:@selector(performDragOperation:)])
+        result = [super performDragOperation:sender];
+
+    return result;
+}
+
+- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
+{
+    // If draggingDestination is nil route the message to the superclass:
+    CDropTarget *dropTarget = self._dropTarget;
+
+    if (dropTarget != nil)
+        [dropTarget concludeDragOperation:sender];
+    else if ([super respondsToSelector:@selector(concludeDragOperation:)])
+        [super concludeDragOperation:sender];
+}
+
+- (void)draggingEnded:(id <NSDraggingInfo>)sender
+{
+    // If draggingDestination is nil route the message to the superclass:
+    CDropTarget *dropTarget = self._dropTarget;
+
+    if (dropTarget != nil)
+        [dropTarget draggingEnded:sender];
+    else if ([super respondsToSelector:@selector(draggingEnded:)])
+        [super draggingEnded:sender];
+}
+
+/********************************  END NSDraggingDestination Interface  ********************************/
+
+/********************************  BEGIN NSTextInputClient Protocol  ********************************/
+
+
+JNF_CLASS_CACHE(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod");
+
+- (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
+#endif // IM_DEBUG
+
+    if (fInputMethodLOCKABLE == NULL) {
+        return;
+    }
+
+    // Insert happens at the end of PAH
+    fInPressAndHold = NO;
+
+    // insertText gets called when the user commits text generated from an input method.  It also gets
+    // called during ordinary input as well.  We only need to send an input method event when we have marked
+    // text, or 'text in progress'.  We also need to send the event if we get an insert text out of the blue!
+    // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex
+    // Unicode value.
+    NSUInteger utf8Length = [aString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+
+    if ([self hasMarkedText] || !fProcessingKeystroke || (utf8Length > 2)) {
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+        static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
+        // We need to select the previous glyph so that it is overwritten.
+        if (fPAHNeedsToSelect) {
+            JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
+            fPAHNeedsToSelect = NO;
+        }
+
+        static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
+        jstring insertedText =  JNFNSToJavaString(env, aString);
+        JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
+        (*env)->DeleteLocalRef(env, insertedText);
+
+        // The input method event will create psuedo-key events for each character in the committed string.
+        // We also don't want to send the character that triggered the insertText, usually a return. [3337563]
+        fKeyEventsNeeded = NO;
+    }
+
+    fPAHNeedsToSelect = NO;
+
+}
+
+- (void) doCommandBySelector:(SEL)aSelector
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [doCommandBySelector]\n");
+    NSLog(@"%@", NSStringFromSelector(aSelector));
+#endif // IM_DEBUG
+    if (@selector(insertNewline:) == aSelector || @selector(insertTab:) == aSelector || @selector(deleteBackward:) == aSelector)
+    {
+        fKeyEventsNeeded = YES;
+    }
+}
+
+// setMarkedText: cannot take a nil first argument. aString can be NSString or NSAttributedString
+- (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replacementRange:(NSRange)replacementRange
+{
+    if (!fInputMethodLOCKABLE)
+        return;
+
+    BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];
+    NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil);
+    NSString *incomingString = (isAttributedString ? [aString string] : aString);
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [setMarkedText] \"%s\", loc=%lu, length=%lu\n", [incomingString UTF8String], (unsigned long)selectionRange.location, (unsigned long)selectionRange.length);
+#endif // IM_DEBUG
+    static JNF_MEMBER_CACHE(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V");
+    static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V");
+    static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    // NSInputContext already did the analysis of the TSM event and created attributes indicating
+    // the underlining and color that should be done to the string.  We need to look at the underline
+    // style and color to determine what kind of Java hilighting needs to be done.
+    jstring inProcessText = JNFNSToJavaString(env, incomingString);
+    JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode)
+    (*env)->DeleteLocalRef(env, inProcessText);
+
+    if (isAttributedString) {
+        NSUInteger length;
+        NSRange effectiveRange;
+        NSDictionary *attributes;
+        length = [attrString length];
+        effectiveRange = NSMakeRange(0, 0);
+        while (NSMaxRange(effectiveRange) < length) {
+            attributes = [attrString attributesAtIndex:NSMaxRange(effectiveRange)
+                                        effectiveRange:&effectiveRange];
+            if (attributes) {
+                BOOL isThickUnderline, isGray;
+                NSNumber *underlineSizeObj =
+                (NSNumber *)[attributes objectForKey:NSUnderlineStyleAttributeName];
+                NSInteger underlineSize = [underlineSizeObj integerValue];
+                isThickUnderline = (underlineSize > 1);
+
+                NSColor *underlineColorObj =
+                (NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName];
+                isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);
+
+                JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
+            }
+        }
+    }
+
+    static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
+    // We need to select the previous glyph so that it is overwritten.
+    if (fPAHNeedsToSelect) {
+        JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
+        fPAHNeedsToSelect = NO;
+    }
+
+    JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode)
+
+    // If the marked text is being cleared (zero-length string) don't handle the key event.
+    if ([incomingString length] == 0) {
+        fKeyEventsNeeded = NO;
+    }
+}
+
+- (void) unmarkText
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");
+#endif // IM_DEBUG
+
+    if (!fInputMethodLOCKABLE) {
+        return;
+    }
+
+    // unmarkText cancels any input in progress and commits it to the text field.
+    static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode)
+
+}
+
+- (BOOL) hasMarkedText
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [hasMarkedText]\n");
+#endif // IM_DEBUG
+
+    if (!fInputMethodLOCKABLE) {
+        return NO;
+    }
+
+    static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;");
+    static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText);
+
+    jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength);
+
+    BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0);
+
+    if (currentText != NULL) {
+        (*env)->DeleteLocalRef(env, currentText);
+    }
+
+    return hasMarkedText;
+}
+
+- (NSInteger) conversationIdentifier
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [conversationIdentifier]\n");
+#endif // IM_DEBUG
+
+    return (NSInteger) self;
+}
+
+/* Returns attributed string at the range.  This allows input mangers to
+ query any range in backing-store (Andy's request)
+ */
+- (NSAttributedString *) attributedSubstringForProposedRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);
+#endif // IM_DEBUG
+
+    static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
+
+    id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease];
+#ifdef IM_DEBUG
+    NSLog(@"attributedSubstringFromRange returning \"%@\"", result);
+#endif // IM_DEBUG
+
+    (*env)->DeleteLocalRef(env, theString);
+    return result;
+}
+
+/* This method returns the range for marked region.  If hasMarkedText == false,
+ it'll return NSNotFound location & 0 length range.
+ */
+- (NSRange) markedRange
+{
+
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [markedRange]\n");
+#endif // IM_DEBUG
+
+    if (!fInputMethodLOCKABLE) {
+        return NSMakeRange(NSNotFound, 0);
+    }
+
+    static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jarray array;
+    jboolean isCopy;
+    jint *_array;
+    NSRange range;
+
+    array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode)
+
+    if (array) {
+        _array = (*env)->GetIntArrayElements(env, array, &isCopy);
+        range = NSMakeRange(_array[0], _array[1]);
+
+#ifdef IM_DEBUG
+        fprintf(stderr, "markedRange returning (%lu, %lu)\n", (unsigned long)range.location, (unsigned long)range.length);
+#endif // IM_DEBUG
+        (*env)->ReleaseIntArrayElements(env, array, _array, 0);
+        (*env)->DeleteLocalRef(env, array);
+    } else {
+        range = NSMakeRange(NSNotFound, 0);
+    }
+
+    return range;
+}
+
+/* This method returns the range for selected region.  Just like markedRange method,
+ its location field contains char index from the text beginning.
+ */
+- (NSRange) selectedRange
+{
+    if (!fInputMethodLOCKABLE) {
+        return NSMakeRange(NSNotFound, 0);
+    }
+
+    static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jarray array;
+    jboolean isCopy;
+    jint *_array;
+    NSRange range;
+
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");
+#endif // IM_DEBUG
+
+    array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode)
+    if (array) {
+        _array = (*env)->GetIntArrayElements(env, array, &isCopy);
+        range = NSMakeRange(_array[0], _array[1]);
+        (*env)->ReleaseIntArrayElements(env, array, _array, 0);
+        (*env)->DeleteLocalRef(env, array);
+    } else {
+        range = NSMakeRange(NSNotFound, 0);
+    }
+
+    return range;
+
+}
+
+/* This method returns the first frame of rects for theRange in screen coordindate system.
+ */
+- (NSRect) firstRectForCharacterRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange
+{
+    if (!fInputMethodLOCKABLE) {
+        return NSMakeRect(0, 0, 0, 0);
+    }
+
+    static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod,
+                            "firstRectForCharacterRange", "(I)[I");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jarray array;
+    jboolean isCopy;
+    jint *_array;
+    NSRect rect;
+
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);
+#endif // IM_DEBUG
+
+    array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange, theRange.location); // AWT_THREADING Safe (AWTRunLoopMode)
+
+    _array = (*env)->GetIntArrayElements(env, array, &isCopy);
+    rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3]));
+    (*env)->ReleaseIntArrayElements(env, array, _array, 0);
+    (*env)->DeleteLocalRef(env, array);
+
+#ifdef IM_DEBUG
+    fprintf(stderr, "firstRectForCharacterRange returning x=%f, y=%f, width=%f, height=%f\n", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
+#endif // IM_DEBUG
+    return rect;
+}
+
+/* This method returns the index for character that is nearest to thePoint.  thPoint is in
+ screen coordinate system.
+ */
+- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
+{
+    if (!fInputMethodLOCKABLE) {
+        return NSNotFound;
+    }
+
+    static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod,
+                            "characterIndexForPoint", "(II)I");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint);
+
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y);
+#endif // IM_DEBUG
+
+    jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode)
+
+#ifdef IM_DEBUG
+    fprintf(stderr, "characterIndexForPoint returning %ld\n", index);
+#endif // IM_DEBUG
+
+    if (index == -1) {
+        return NSNotFound;
+    } else {
+        return (NSUInteger)index;
+    }
+}
+
+- (NSArray*) validAttributesForMarkedText
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [validAttributesForMarkedText]\n");
+#endif // IM_DEBUG
+
+    return [NSArray array];
+}
+
+- (void)setInputMethod:(jobject)inputMethod
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [setInputMethod]\n");
+#endif // IM_DEBUG
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    // Get rid of the old one
+    if (fInputMethodLOCKABLE) {
+        JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
+    }
+
+    // Save a global ref to the new input method.
+    if (inputMethod != NULL)
+        fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
+    else
+        fInputMethodLOCKABLE = NULL;
+}
+
+- (void)abandonInput
+{
+#ifdef IM_DEBUG
+    fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");
+#endif // IM_DEBUG
+
+    [ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) onObject:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES awtMode:YES];
+    [self unmarkText];
+}
+
+/********************************   END NSTextInputClient Protocol   ********************************/
+
+
+
+
+@end // AWTView
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformView
+ * Method:    nativeCreateView
+ * Signature: (IIII)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CPlatformView_nativeCreateView
+(JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
+{
+    __block AWTView *newView = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    NSRect rect = NSMakeRect(originX, originY, width, height);
+    jobject cPlatformView = (*env)->NewGlobalRef(env, obj);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
+        AWTView *view = [[AWTView alloc] initWithRect:rect
+                                         platformView:cPlatformView
+                                         windowLayer:windowLayer];
+        CFRetain(view);
+        [view release]; // GC
+
+        newView = view;
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(newView);
+}
diff --git a/jdk/src/macosx/native/sun/awt/AWTWindow.h b/jdk/src/macosx/native/sun/awt/AWTWindow.h
new file mode 100644
index 0000000..9c8c355
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef _AWTWINDOW_H
+#define _AWTWINDOW_H
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CMenuBar.h"
+#import "LWCToolkit.h"
+
+
+@class AWTView;
+
+@interface AWTWindow : NSPanel <NSWindowDelegate> {
+@private
+    JNFWeakJObjectWrapper *javaPlatformWindow;
+    CMenuBar *javaMenuBar;
+    NSWindow *growBoxWindow;
+    NSSize javaMinSize;
+    NSSize javaMaxSize;
+    jint styleBits;
+}
+
+@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
+@property (nonatomic, retain) CMenuBar *javaMenuBar;
+@property (nonatomic, retain) NSWindow *growBoxWindow;
+@property (nonatomic) NSSize javaMinSize;
+@property (nonatomic) NSSize javaMaxSize;
+@property (nonatomic) jint styleBits;
+
+- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
+                    styleBits:(jint)styleBits
+                    frameRect:(NSRect)frameRect
+                  contentView:(NSView *)contentView;
+
+- (void) adjustGrowBoxWindow;
+@end
+
+#endif _AWTWINDOW_H
diff --git a/jdk/src/macosx/native/sun/awt/AWTWindow.m b/jdk/src/macosx/native/sun/awt/AWTWindow.m
new file mode 100644
index 0000000..f1aeba7
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m
@@ -0,0 +1,979 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "sun_lwawt_macosx_CPlatformWindow.h"
+#import "com_apple_eawt_event_GestureHandler.h"
+#import "com_apple_eawt_FullScreenHandler.h"
+
+#import "AWTWindow.h"
+#import "AWTView.h"
+#import "CMenu.h"
+#import "CMenuBar.h"
+#import "LWCToolkit.h"
+#import "GeomUtilities.h"
+#import "ThreadUtilities.h"
+#import "OSVersion.h"
+
+
+#define MASK(KEY) \
+    (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
+
+#define IS(BITS, KEY) \
+    ((BITS & MASK(KEY)) != 0)
+
+#define SET(BITS, KEY, VALUE) \
+    BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
+
+
+static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
+
+@interface JavaResizeGrowBoxOverlayWindow : NSWindow { }
+
+@end
+
+@implementation JavaResizeGrowBoxOverlayWindow
+
+- (BOOL) accessibilityIsIgnored
+{
+    return YES;
+}
+
+- (NSArray *)accessibilityChildrenAttribute
+{
+    return nil;
+}
+@end
+
+@implementation AWTWindow
+
+@synthesize javaPlatformWindow;
+@synthesize javaMenuBar;
+@synthesize growBoxWindow;
+@synthesize javaMinSize;
+@synthesize javaMaxSize;
+@synthesize styleBits;
+
+- (void) updateMinMaxSize:(BOOL)resizable {
+    if (resizable) {
+        [self setMinSize:self.javaMinSize];
+        [self setMaxSize:self.javaMaxSize];
+    } else {
+        NSRect currentFrame = [self frame];
+        [self setMinSize:currentFrame.size];
+        [self setMaxSize:currentFrame.size];
+    }
+}
+
+// creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
++ (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
+    NSUInteger type = 0;
+    if (IS(styleBits, DECORATED)) {
+        type |= NSTitledWindowMask;
+        if (IS(styleBits, CLOSEABLE))   type |= NSClosableWindowMask;
+        if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
+        if (IS(styleBits, RESIZABLE))   type |= NSResizableWindowMask;
+    } else {
+        type |= NSBorderlessWindowMask;
+    }
+
+    if (IS(styleBits, TEXTURED))    type |= NSTexturedBackgroundWindowMask;
+    if (IS(styleBits, UNIFIED))     type |= NSUnifiedTitleAndToolbarWindowMask;
+    if (IS(styleBits, UTILITY))     type |= NSUtilityWindowMask;
+    if (IS(styleBits, HUD))         type |= NSHUDWindowMask;
+    if (IS(styleBits, SHEET))       type |= NSDocModalWindowMask;
+
+    return type;
+}
+
+// updates _METHOD_PROP_BITMASK based properties on the window
+- (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask {
+    if (IS(mask, RESIZABLE)) {
+        BOOL resizable = IS(bits, RESIZABLE);
+        [self updateMinMaxSize:resizable];
+        [self setShowsResizeIndicator:resizable];
+    }
+
+    if (IS(mask, HAS_SHADOW)) {
+        [self setHasShadow:IS(bits, HAS_SHADOW)];
+    }
+
+    if (IS(mask, ZOOMABLE)) {
+        [[self standardWindowButton:NSWindowZoomButton] setEnabled:IS(bits, ZOOMABLE)];
+    }
+
+    if (IS(mask, ALWAYS_ON_TOP)) {
+        [self setLevel:IS(bits, ALWAYS_ON_TOP) ? NSFloatingWindowLevel : NSNormalWindowLevel];
+    }
+
+    if (IS(mask, HIDES_ON_DEACTIVATE)) {
+        [self setHidesOnDeactivate:IS(bits, HIDES_ON_DEACTIVATE)];
+    }
+
+    if (IS(mask, DRAGGABLE_BACKGROUND)) {
+        [self setMovableByWindowBackground:IS(bits, DRAGGABLE_BACKGROUND)];
+    }
+
+    if (IS(mask, DOCUMENT_MODIFIED)) {
+        [self setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)];
+    }
+    
+    if ([self respondsToSelector:@selector(toggleFullScreen:)]) {
+        if (IS(mask, FULLSCREENABLE)) {
+            [self setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/];
+        } else {
+            [self setCollectionBehavior:NSWindowCollectionBehaviorDefault];
+        }
+    }
+
+}
+
+- (BOOL) shouldShowGrowBox {
+    return isSnowLeopardOrLower() && IS(self.styleBits, RESIZABLE);
+}
+
+- (NSImage *) createGrowBoxImage {
+    NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(12, 12)];
+    JRSUIControlRef growBoxWidget = JRSUIControlCreate(FALSE);
+    JRSUIControlSetWidget(growBoxWidget, kJRSUI_Widget_growBoxTextured);
+    JRSUIControlSetWindowType(growBoxWidget, kJRSUI_WindowType_utility);
+    JRSUIRendererRef renderer = JRSUIRendererCreate();
+    [image lockFocus]; // sets current graphics context to that of the image
+    JRSUIControlDraw(renderer, growBoxWidget, [[NSGraphicsContext currentContext] graphicsPort], CGRectMake(0, 1, 11, 11));
+    [image unlockFocus];
+    JRSUIRendererRelease(renderer);
+    JRSUIControlRelease(growBoxWidget);
+    return image;
+}
+
+- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
+                    styleBits:(jint)bits
+                    frameRect:(NSRect)rect
+                  contentView:(NSView *)view
+{
+AWT_ASSERT_APPKIT_THREAD;
+
+    NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits];
+    NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask];
+    if (contentRect.size.width <= 0.0) {
+        contentRect.size.width = 1.0;
+    }
+    if (contentRect.size.height <= 0.0) {
+        contentRect.size.height = 1.0;
+    }
+
+    self = [super initWithContentRect:contentRect
+                            styleMask:styleMask
+                              backing:NSBackingStoreBuffered
+                                defer:NO];
+
+    if (self == nil) return nil; // no hope
+
+    self.javaPlatformWindow = platformWindow;
+    self.styleBits = bits;
+    [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
+
+    [self setDelegate:self];
+    [self setContentView:view];
+    [self setInitialFirstResponder:view];
+    [self setReleasedWhenClosed:NO];
+    [self setPreservesContentDuringLiveResize:YES];
+
+    if ([self shouldShowGrowBox]) {
+        NSImage *growBoxImage = [self createGrowBoxImage];
+        growBoxWindow = [[JavaResizeGrowBoxOverlayWindow alloc] initWithContentRect:NSMakeRect(0, 0, [growBoxImage size].width, [growBoxImage size].height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
+        [self.growBoxWindow setIgnoresMouseEvents:YES];
+        [self.growBoxWindow setOpaque:NO];
+        [self.growBoxWindow setBackgroundColor:[NSColor clearColor]];
+        [self.growBoxWindow setHasShadow:NO];
+        [self.growBoxWindow setReleasedWhenClosed:NO];
+
+        NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]];
+        [imageView setEditable:NO];
+        [imageView setAnimates:NO];
+        [imageView setAllowsCutCopyPaste:NO];
+        [self.growBoxWindow setContentView:imageView];
+        [imageView setImage:growBoxImage];
+        [growBoxImage release];
+        [imageView release];
+
+        [self addChildWindow:self.growBoxWindow ordered:NSWindowAbove];
+        [self adjustGrowBoxWindow];
+    } else growBoxWindow = nil;
+
+    return self;
+}
+
+- (void) dealloc {
+AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    [self.javaPlatformWindow setJObject:nil withEnv:env];
+    self.growBoxWindow = nil;
+
+    [super dealloc];
+}
+
+
+// NSWindow overrides
+- (BOOL) canBecomeKeyWindow {
+AWT_ASSERT_APPKIT_THREAD;
+    return IS(self.styleBits, SHOULD_BECOME_KEY);
+}
+
+- (BOOL) canBecomeMainWindow {
+AWT_ASSERT_APPKIT_THREAD;
+    return IS(self.styleBits, SHOULD_BECOME_MAIN);
+}
+
+- (BOOL) worksWhenModal {
+AWT_ASSERT_APPKIT_THREAD;
+    return IS(self.styleBits, MODAL_EXCLUDED);
+}
+
+
+// Gesture support
+- (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
+AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow == NULL) return; // shouldn't occur
+
+    // extract the target AWT Window object out of the CPlatformWindow
+    static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
+    jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
+    if (awtWindow == NULL) return; // shouldn't occur
+
+    // translate the point into Java coordinates
+    NSPoint loc = [event locationInWindow];
+    loc.y = [self frame].size.height - loc.y;
+
+    // send up to the GestureHandler to recursively dispatch on the AWT event thread
+    static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler");
+    static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V");
+    JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b);
+}
+
+- (void)beginGestureWithEvent:(NSEvent *)event {
+    [self postGesture:event
+                   as:com_apple_eawt_event_GestureHandler_PHASE
+                    a:-1.0
+                    b:0.0];
+}
+
+- (void)endGestureWithEvent:(NSEvent *)event {
+    [self postGesture:event
+                   as:com_apple_eawt_event_GestureHandler_PHASE
+                    a:1.0
+                    b:0.0];
+}
+
+- (void)magnifyWithEvent:(NSEvent *)event {
+    [self postGesture:event
+                   as:com_apple_eawt_event_GestureHandler_MAGNIFY
+                    a:[event magnification]
+                    b:0.0];
+}
+
+- (void)rotateWithEvent:(NSEvent *)event {
+    [self postGesture:event
+                   as:com_apple_eawt_event_GestureHandler_ROTATE
+                    a:[event rotation]
+                    b:0.0];
+}
+
+- (void)swipeWithEvent:(NSEvent *)event {
+    [self postGesture:event
+                   as:com_apple_eawt_event_GestureHandler_SWIPE
+                    a:[event deltaX]
+                    b:[event deltaY]];
+}
+
+
+// NSWindowDelegate methods
+
+- (void) adjustGrowBoxWindow {
+    if (self.growBoxWindow != nil) {
+        NSRect parentRect = [self frame];
+        parentRect.origin.x += (parentRect.size.width - [self.growBoxWindow frame].size.width);
+        [self.growBoxWindow setFrameOrigin:parentRect.origin];
+    }
+}
+
+- (void) _deliverMoveResizeEvent {
+AWT_ASSERT_APPKIT_THREAD;
+
+    // deliver the event if this is a user-initiated live resize or as a side-effect
+    // of a Java initiated resize, because AppKit can override the bounds and force
+    // the bounds of the window to avoid the Dock or remain on screen.
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow == NULL) {
+        // TODO: create generic AWT assert
+    }
+
+    [self adjustGrowBoxWindow];
+
+    NSRect frame = ConvertNSScreenRect(env, [self frame]);
+
+    static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V");
+    JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent,
+                      (jint)frame.origin.x,
+                      (jint)frame.origin.y,
+                      (jint)frame.size.width,
+                      (jint)frame.size.height);
+}
+
+- (void)windowDidMove:(NSNotification *)notification {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [self _deliverMoveResizeEvent];
+}
+
+- (void)windowDidResize:(NSNotification *)notification {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [self _deliverMoveResizeEvent];
+}
+
+- (void)windowDidExpose:(NSNotification *)notification {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [AWTToolkit eventCountPlusPlus];
+    // TODO: don't see this callback invoked anytime so we track
+    // window exposing in _setVisible:(BOOL)
+}
+
+- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)proposedFrame {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    static JNF_MEMBER_CACHE(jm_deliverZoom, jc_CPlatformWindow, "deliverZoom", "(Z)V");
+    JNFCallVoidMethod(env, platformWindow, jm_deliverZoom, ![window isZoomed]);
+
+    return YES;
+}
+
+- (void) _deliverIconify:(BOOL)iconify {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    static JNF_MEMBER_CACHE(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V");
+    JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify);
+}
+
+- (void)windowDidMiniaturize:(NSNotification *)notification {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [self _deliverIconify:JNI_TRUE];
+}
+
+- (void)windowDidDeminiaturize:(NSNotification *)notification {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [self _deliverIconify:JNI_FALSE];
+}
+
+- (void) _deliverWindowFocusEvent:(BOOL)focused {
+//AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(Z)V");
+    JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused);
+}
+
+
+- (void) windowDidBecomeKey: (NSNotification *) notification {
+AWT_ASSERT_APPKIT_THREAD;
+    [AWTToolkit eventCountPlusPlus];
+    [CMenuBar activate:self.javaMenuBar modallyDisabled:NO];
+    [self _deliverWindowFocusEvent:YES];
+}
+
+- (void) windowDidResignKey: (NSNotification *) notification {
+    // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
+AWT_ASSERT_APPKIT_THREAD;
+    [AWTToolkit eventCountPlusPlus];
+    [self.javaMenuBar deactivate];
+    [self _deliverWindowFocusEvent:NO];
+}
+
+- (void) windowDidBecomeMain: (NSNotification *) notification {
+AWT_ASSERT_APPKIT_THREAD;
+    [AWTToolkit eventCountPlusPlus];
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
+    JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
+}
+
+- (BOOL)windowShouldClose:(id)sender {
+AWT_ASSERT_APPKIT_THREAD;
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    static JNF_MEMBER_CACHE(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V");
+    JNFCallVoidMethod(env, platformWindow, jm_deliverWindowClosingEvent);
+
+    // The window will be closed (if allowed) as result of sending Java event
+    return NO;
+}
+
+
+- (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env {
+        static JNF_CLASS_CACHE(jc_FullScreenHandler, "com/apple/eawt/FullScreenHandler");
+    static JNF_STATIC_MEMBER_CACHE(jm_notifyFullScreenOperation, jc_FullScreenHandler, "handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V");
+    static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
+    jobject awtWindow = JNFGetObjectField(env, [self.javaPlatformWindow jObjectWithEnv:env], jf_target);
+    if (awtWindow == NULL) return; // shouldn't occur
+
+    JNFCallStaticVoidMethod(env, jm_notifyFullScreenOperation, awtWindow, op);
+}
+
+
+- (void)windowWillEnterFullScreen:(NSNotification *)notification {
+        static JNF_MEMBER_CACHE(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+    JNFCallVoidMethod(env, [self.javaPlatformWindow jObjectWithEnv:env], jm_windowWillEnterFullScreen);
+
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_ENTER withEnv:env];
+}
+
+- (void)windowDidEnterFullScreen:(NSNotification *)notification {
+        static JNF_MEMBER_CACHE(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        JNFCallVoidMethod(env, [self.javaPlatformWindow jObjectWithEnv:env], jm_windowDidEnterFullScreen);
+
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_ENTER withEnv:env];
+}
+
+- (void)windowWillExitFullScreen:(NSNotification *)notification {
+        static JNF_MEMBER_CACHE(jm_windowWillExitFullScreen, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        JNFCallVoidMethod(env, [self.javaPlatformWindow jObjectWithEnv:env], jm_windowWillExitFullScreen);
+
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env];
+}
+
+- (void)windowDidExitFullScreen:(NSNotification *)notification {
+        static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        JNFCallVoidMethod(env, [self.javaPlatformWindow jObjectWithEnv:env], jm_windowDidExitFullScreen);
+
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env];
+}
+@end // AWTWindow
+
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeCreateNSWindow
+ * Signature: (JJIIII)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
+(JNIEnv *env, jobject obj, jlong contentViewPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h)
+{
+    __block AWTWindow *window = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
+    NSView *contentView = OBJC(contentViewPtr);
+    NSRect frameRect = NSMakeRect(x, y, w, h);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow
+                                                  styleBits:styleBits
+                                                  frameRect:frameRect
+                                                contentView:contentView];
+
+        if (window) CFRetain(window);
+        [window release]; // GC
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(window);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowStyleBits
+ * Signature: (JII)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits
+(JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        // scans the bit field, and only updates the values requested by the mask
+        // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads)
+        jint newBits = window.styleBits & ~mask | bits & mask;
+
+        // resets the NSWindow's style mask if the mask intersects any of those bits
+        if (mask & MASK(_STYLE_PROP_BITMASK)) {
+            [window setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]];
+        }
+
+        // calls methods on NSWindow to change other properties, based on the mask
+        if (mask & MASK(_METHOD_PROP_BITMASK)) {
+            [window setPropertiesForStyleBits:bits mask:mask];
+        }
+
+        window.styleBits = newBits;
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowMenuBar
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar
+(JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    CMenuBar *menuBar = OBJC(menuBarPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        if ([window isKeyWindow]) [window.javaMenuBar deactivate];
+        window.javaMenuBar = menuBar;
+
+        // if ([self isKeyWindow]) {
+        [CMenuBar activate:window.javaMenuBar modallyDisabled:NO];
+        // }
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeGetNSWindowInsets
+ * Signature: (J)Ljava/awt/Insets;
+ */
+JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+    jobject ret = NULL;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    __block NSRect contentRect = NSZeroRect;
+    __block NSRect frame = NSZeroRect;
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        frame = [window frame];
+        contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]];
+    }];
+
+    jint top = (jint)(frame.size.height - contentRect.size.height);
+    jint left = (jint)(contentRect.origin.x - frame.origin.x);
+    jint bottom = (jint)(contentRect.origin.y - frame.origin.y);
+    jint right = (jint)(frame.size.width - (contentRect.size.width + left));
+
+    static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
+    static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
+    ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
+
+JNF_COCOA_EXIT(env);
+    return ret;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowBounds
+ * Signature: (JDDDD)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds
+(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    NSRect jrect = NSMakeRect(originX, originY, width, height);
+
+    // TODO: not sure we need displayIfNeeded message in our view
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        NSRect rect = ConvertNSScreenRect(NULL, jrect);
+        [window setFrame:rect display:YES];
+
+        // only start tracking events if pointer is above the toplevel
+        // TODO: should post an Entered event if YES.
+        NSPoint mLocation = [NSEvent mouseLocation];
+        [window setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
+
+        // ensure we repaint the whole window after the resize operation
+        // (this will also re-enable screen updates, which were disabled above)
+        // TODO: send PaintEvent
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowMinMax
+ * Signature: (JDDDD)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
+(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    if (minW < 1) minW = 1;
+    if (minH < 1) minH = 1;
+    if (maxW < 1) maxW = 1;
+    if (maxH < 1) maxH = 1;
+
+    NSSize min = { minW, minH };
+    NSSize max = { maxW, maxH };
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        window.javaMinSize = min;
+        window.javaMaxSize = max;
+        [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativePushNSWindowToBack
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [window orderBack:nil];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativePushNSWindowToFront
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        if (![window isKeyWindow]) {
+            [window makeKeyAndOrderFront:window];
+        } else {
+            [window orderFront:window];
+        }
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowTitle
+ * Signature: (JLjava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle
+(JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    [window performSelectorOnMainThread:@selector(setTitle:)
+                              withObject:JNFJavaToNSString(env, jtitle)
+                           waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowAlpha
+ * Signature: (JF)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowAlpha
+(JNIEnv *env, jclass clazz, jlong windowPtr, jfloat alpha)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [window setAlphaValue:alpha];
+        [window.growBoxWindow setAlphaValue:alpha];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeRevalidateNSWindowShadow
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [window invalidateShadow];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeScreenOn_AppKitThread
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+    jint ret = 0;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    NSDictionary *props = [[window screen] deviceDescription];
+    ret = [[props objectForKey:@"NSScreenNumber"] intValue];
+
+JNF_COCOA_EXIT(env);
+
+    return ret;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowMinimizedIcon
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon
+(JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    NSImage *image = OBJC(nsImagePtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [window setMiniwindowImage:image];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowRepresentedFilename
+ * Signature: (JLjava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename
+(JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)];
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [window setRepresentedURL:url];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowSecurityWarningPositioning
+ * Signature: (JDDFF)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSecurityWarningPositioning
+(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble x, jdouble y, jfloat biasX, jfloat biasY)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    [JNFException raise:env as:kRuntimeException reason:"unimplemented"];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeGetScreenNSWindowIsOn_AppKitThread
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetScreenNSWindowIsOn_1AppKitThread
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+    jint index = -1;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_APPKIT_THREAD;
+
+    AWTWindow *window = OBJC(windowPtr);
+    NSScreen* screen = [window screen];
+
+    //+++gdb NOTE: This is using a linear search of the screens. If it should
+    //  prove to be a bottleneck, this can definitely be improved. However,
+    //  many screens should prove to be the exception, rather than the rule.
+    NSArray* screens = [NSScreen screens];
+    NSUInteger i;
+    for (i = 0; i < [screens count]; i++)
+    {
+        if ([[screens objectAtIndex:i] isEqualTo:screen])
+        {
+            index = i;
+            break;
+        }
+    }
+
+JNF_COCOA_EXIT(env);
+    return 1;
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    _toggleFullScreenMode
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode
+(JNIEnv *env, jobject peer, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = OBJC(windowPtr);
+    SEL toggleFullScreenSelector = @selector(toggleFullScreen:);
+    if (![window respondsToSelector:toggleFullScreenSelector]) return;
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window performSelector:toggleFullScreenSelector withObject:nil];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    isApplicationActive
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeIsApplicationActive
+(JNIEnv *env, jclass clazz)
+{
+JNF_COCOA_ENTER(env);
+
+    return (jboolean)[NSRunningApplication currentApplication].active;
+
+JNF_COCOA_EXIT(env);
+}
+
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CMouseInfoPeer_nativeIsWindowUnderMouse
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+    __block jboolean underMouse = JNI_FALSE;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTWindow *aWindow = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() {
+        AWT_ASSERT_APPKIT_THREAD;
+
+        NSPoint pt = [aWindow mouseLocationOutsideOfEventStream];
+        underMouse = [[aWindow contentView] hitTest:pt] != nil;
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return underMouse;
+}
diff --git a/jdk/src/macosx/native/sun/awt/ApplicationDelegate.h b/jdk/src/macosx/native/sun/awt/ApplicationDelegate.h
new file mode 100644
index 0000000..b4b7b8f
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/ApplicationDelegate.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@class CMenuBar;
+
+//
+// This class supplies the native implementation for the com.apple.eawt.Application class.  We
+// implement this as a delegate rather than extend NSApplication because we can not rely on AWT always
+// being the creator of the NSApplication NSApp instance.
+//
+@interface ApplicationDelegate : NSObject<NSApplicationDelegate>
+{
+    NSMenuItem *fPreferencesMenu;
+    NSMenuItem *fAboutMenu;
+
+    NSMenu *fDockMenu;
+    CMenuBar *fDefaultMenuBar;
+
+    BOOL fHandlesDocumentTypes;
+    BOOL fHandlesURLTypes;
+}
+
+@property (nonatomic, retain) NSMenuItem *fPreferencesMenu;
+@property (nonatomic, retain) NSMenuItem *fAboutMenu;
+
+@property (nonatomic, retain) NSMenu *fDockMenu;
+@property (nonatomic, retain) CMenuBar *fDefaultMenuBar;
+
+// Returns the shared delegate, creating if necessary
++ (ApplicationDelegate *)sharedDelegate;
+
+// called by the window machinery to setup a default menu bar
+- (CMenuBar *)defaultMenuBar;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/ApplicationDelegate.m b/jdk/src/macosx/native/sun/awt/ApplicationDelegate.m
new file mode 100644
index 0000000..7ba5fcf
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/ApplicationDelegate.m
@@ -0,0 +1,809 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "ApplicationDelegate.h"
+
+#import "com_apple_eawt_Application.h"
+#import "com_apple_eawt__AppDockIconHandler.h"
+#import "com_apple_eawt__AppEventHandler.h"
+#import "com_apple_eawt__AppMenuBarHandler.h"
+#import "com_apple_eawt__AppMenuBarHandler.h"
+#import "com_apple_eawt__AppMiscHandlers.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CPopupMenu.h"
+#import "ThreadUtilities.h"
+#import "NSApplicationAWT.h"
+
+
+#pragma mark App Menu helpers
+
+// The following is a AWT convention?
+#define PREFERENCES_TAG  42
+
+static void addMenuItem(NSMenuItem* menuItem, NSInteger index) {
+AWT_ASSERT_APPKIT_THREAD;
+
+    NSMenu *menuBar = [[NSApplication sharedApplication] mainMenu];
+    NSMenu *appMenu = [[menuBar itemAtIndex:0] submenu];
+
+    [appMenu insertItem:menuItem atIndex:index];
+    [appMenu insertItem:[NSMenuItem separatorItem] atIndex:index + 1]; // Add the following separator
+}
+
+static void removeMenuItem(NSMenuItem* menuItem) {
+AWT_ASSERT_APPKIT_THREAD;
+
+    NSMenu *menuBar = [[NSApplication sharedApplication] mainMenu];
+    NSMenu *appMenu = [[menuBar itemAtIndex:0] submenu];
+
+    NSInteger index = [appMenu indexOfItem:menuItem];
+    if (index < 0) return; // something went wrong
+
+    [appMenu removeItemAtIndex:index + 1]; // Get the following separator
+    [appMenu removeItem:menuItem];
+}
+
+@interface NSBundle (EAWTOverrides)
+- (BOOL)_hasEAWTOverride:(NSString *)key;
+@end
+
+
+@implementation NSBundle (EAWTOverrides)
+
+- (BOOL)_hasEAWTOverride:(NSString *)key {
+    return [[[[self objectForInfoDictionaryKey:@"Java"] objectForKey:@"EAWTOverride"] objectForKey:key] boolValue];
+}
+
+@end
+
+
+// used by JavaRuntimeSupport.framework's [JRSAppKitAWT awtAppDelegate]
+// to expose our app delegate to the SWT or other apps that have knoledge
+// of Java's AWT and want to install their own app delegate that will delegate
+// to the AWT for some operations
+
+@interface JavaAWTAppDelegateLoader : NSObject { }
+@end
+
+@implementation JavaAWTAppDelegateLoader
++ (ApplicationDelegate *) awtAppDelegate {
+    return [ApplicationDelegate sharedDelegate];
+}
+@end
+
+
+@implementation ApplicationDelegate
+
+@synthesize fPreferencesMenu;
+@synthesize fAboutMenu;
+
+@synthesize fDockMenu;
+@synthesize fDefaultMenuBar;
+
+
++ (ApplicationDelegate *)sharedDelegate {
+    static ApplicationDelegate *sApplicationDelegate = nil;
+    static BOOL checked = NO;
+
+    if (sApplicationDelegate != nil) return sApplicationDelegate;
+    if (checked) return nil;
+
+AWT_ASSERT_APPKIT_THREAD;
+
+    // don't install the EAWT delegate if another kind of NSApplication is installed, like say, Safari
+    BOOL shouldInstall = NO;
+    if (NSApp != nil) {
+        if ([NSApp isMemberOfClass:[NSApplication class]]) shouldInstall = YES;
+        if ([NSApp isKindOfClass:[NSApplicationAWT class]]) shouldInstall = YES;
+    }
+    checked = YES;
+    if (!shouldInstall) return nil;
+
+    sApplicationDelegate = [[ApplicationDelegate alloc] init];
+    return sApplicationDelegate;
+}
+
+- (void)_updatePreferencesMenu:(BOOL)prefsAvailable enabled:(BOOL)prefsEnabled {
+AWT_ASSERT_APPKIT_THREAD;
+
+    if (prefsAvailable) {
+        // Make sure Prefs is around
+        if ([self.fPreferencesMenu menu] == nil) {
+            // Position of Prefs depends upon About availability.
+            NSInteger index = ([self.fAboutMenu menu] != nil) ? 2 : 0;
+
+            addMenuItem(self.fPreferencesMenu, index);
+        }
+
+        if (prefsEnabled) {
+            [self.fPreferencesMenu setEnabled:YES];
+            [self.fPreferencesMenu setTarget:self];
+            [self.fPreferencesMenu setAction:@selector(_preferencesMenuHandler)];
+        } else {
+            [self.fPreferencesMenu setEnabled:NO];
+            [self.fPreferencesMenu setTarget:nil];
+            [self.fPreferencesMenu setAction:nil];
+        }
+    } else {
+        if ([self.fPreferencesMenu menu] == nil) return;
+
+        // Remove the preferences item
+        removeMenuItem(self.fPreferencesMenu);
+    }
+}
+
+- (void)_updateAboutMenu:(BOOL)aboutAvailable enabled:(BOOL)aboutEnabled {
+AWT_ASSERT_APPKIT_THREAD;
+
+    if (aboutAvailable) {
+        // Make sure About is around
+        if ([self.fAboutMenu menu] == nil) {
+            addMenuItem(self.fAboutMenu, 0);
+        }
+
+        if (aboutEnabled) {
+            [self.fAboutMenu setEnabled:YES];
+            [self.fAboutMenu setTarget:self];
+            [self.fAboutMenu setAction:@selector(_aboutMenuHandler)];
+        } else {
+            [self.fAboutMenu setEnabled:NO];
+            [self.fAboutMenu setTarget:nil];
+            [self.fAboutMenu setAction:nil];
+        }
+    } else {
+        if ([self.fAboutMenu menu] == nil) return;
+
+        // Remove About item.
+        removeMenuItem(self.fAboutMenu);
+    }
+}
+
+- (id) init {
+AWT_ASSERT_APPKIT_THREAD;
+
+    self = [super init];
+    if (!self) return self;
+
+    // Prep for about and preferences menu
+    BOOL usingDefaultNib = YES;
+    if ([NSApp isKindOfClass:[NSApplicationAWT class]]) {
+        usingDefaultNib = [NSApp usingDefaultNib];
+    }
+    if (!usingDefaultNib) return self;
+
+    NSMenu *menuBar = [[NSApplication sharedApplication] mainMenu];
+    NSMenu *appMenu = [[menuBar itemAtIndex:0] submenu];
+
+    self.fPreferencesMenu = (NSMenuItem*)[appMenu itemWithTag:PREFERENCES_TAG];
+    self.fAboutMenu = (NSMenuItem*)[appMenu itemAtIndex:0];
+
+    // If the java application has a bundle with an Info.plist file with
+    //  a CFBundleDocumentTypes entry, then it is set up to handle Open Doc
+    //  and Print Doc commands for these files. Therefore java AWT will
+    //  cache Open Doc and Print Doc events that are sent prior to a
+    //  listener being installed by the client java application.
+    NSBundle *bundle = [NSBundle mainBundle];
+    fHandlesDocumentTypes = [bundle objectForInfoDictionaryKey:@"CFBundleDocumentTypes"] != nil || [bundle _hasEAWTOverride:@"DocumentHandler"];
+    fHandlesURLTypes = [bundle objectForInfoDictionaryKey:@"CFBundleURLTypes"] != nil || [bundle _hasEAWTOverride:@"URLHandler"];
+    if (fHandlesURLTypes) {
+        [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
+                                                           andSelector:@selector(_handleOpenURLEvent:withReplyEvent:)
+                                                         forEventClass:kInternetEventClass
+                                                            andEventID:kAEGetURL];
+    }
+
+    // By HIG, Preferences are not available unless there is a handler. By default in Mac OS X,
+    //  there is not a handler, but it is in the nib file for convenience.
+    removeMenuItem(self.fPreferencesMenu);
+
+    [self _updateAboutMenu:YES enabled:YES];
+
+    // Now that the AppKit objects are known and set up, initialize the model data
+    BOOL aboutAvailable = ([self.fAboutMenu menu] != nil);
+    BOOL aboutEnabled = (aboutAvailable && [self.fAboutMenu isEnabled] && ([self.fAboutMenu target] != nil));
+
+    BOOL prefsAvailable = ([self.fPreferencesMenu menu] != nil);
+    BOOL prefsEnabled = (prefsAvailable && [self.fPreferencesMenu isEnabled] && ([self.fPreferencesMenu target] != nil));
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_CLASS_CACHE(sjc_AppMenuBarHandler, "com/apple/eawt/_AppMenuBarHandler");
+    static JNF_STATIC_MEMBER_CACHE(sjm_initMenuStates, sjc_AppMenuBarHandler, "initMenuStates", "(ZZZZ)V");
+    JNFCallStaticVoidMethod(env, sjm_initMenuStates, aboutAvailable, aboutEnabled, prefsAvailable, prefsEnabled);
+
+    // register for the finish launching and system power off notifications by default
+    NSNotificationCenter *ctr = [NSNotificationCenter defaultCenter];
+    Class clz = [ApplicationDelegate class];
+    [ctr addObserver:clz selector:@selector(_willFinishLaunching) name:NSApplicationWillFinishLaunchingNotification object:nil];
+    [ctr addObserver:clz selector:@selector(_systemWillPowerOff) name:NSWorkspaceWillPowerOffNotification object:nil];
+    [ctr addObserver:clz selector:@selector(_appDidActivate) name:NSApplicationDidBecomeActiveNotification object:nil];
+    [ctr addObserver:clz selector:@selector(_appDidDeactivate) name:NSApplicationDidResignActiveNotification object:nil];
+    [ctr addObserver:clz selector:@selector(_appDidHide) name:NSApplicationDidHideNotification object:nil];
+    [ctr addObserver:clz selector:@selector(_appDidUnhide) name:NSApplicationDidUnhideNotification object:nil];
+
+    return self;
+}
+
+- (void)dealloc {
+    self.fPreferencesMenu = nil;
+    self.fAboutMenu = nil;
+    self.fDockMenu = nil;
+    self.fDefaultMenuBar = nil;
+
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; } // GC
+
+
+#pragma mark Callbacks from AppKit
+
+static JNF_CLASS_CACHE(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler");
+
+- (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
+AWT_ASSERT_APPKIT_THREAD;
+    if (!fHandlesURLTypes) return;
+
+    NSString *url = [[openURLEvent paramDescriptorForKeyword:keyDirectObject] stringValue];
+
+    //fprintf(stderr,"jm_handleOpenURL\n");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jstring jURL = JNFNSToJavaString(env, url);
+    static JNF_STATIC_MEMBER_CACHE(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V");
+    JNFCallStaticVoidMethod(env, jm_handleOpenURI, jURL); // AWT_THREADING Safe (event)
+    (*env)->DeleteLocalRef(env, jURL);
+
+    [replyEvent insertDescriptor:[NSAppleEventDescriptor nullDescriptor] atIndex:0];
+}
+
+// Helper for both open file and print file methods
+// Creates a Java list of files from a native list of files
+- (jobject)_createFilePathArrayFrom:(NSArray *)filenames withEnv:(JNIEnv *)env {
+    static JNF_CLASS_CACHE(sjc_ArrayList, "java/util/ArrayList");
+    static JNF_CTOR_CACHE(jm_ArrayList_ctor, sjc_ArrayList, "(I)V");
+    static JNF_MEMBER_CACHE(jm_ArrayList_add, sjc_ArrayList, "add", "(Ljava/lang/Object;)Z");
+
+    jobject jFileNamesArray = JNFNewObject(env, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object)
+    for (NSString *filename in filenames) {
+        jstring jFileName = JNFNormalizedJavaStringForPath(env, filename);
+        JNFCallVoidMethod(env, jFileNamesArray, jm_ArrayList_add, jFileName);
+    }
+
+    return jFileNamesArray;
+}
+
+// Open file handler
+- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)fileNames {
+AWT_ASSERT_APPKIT_THREAD;
+    if (!fHandlesDocumentTypes) {
+        [theApplication replyToOpenOrPrint:NSApplicationDelegateReplyCancel];
+        return;
+    }
+
+    //fprintf(stderr,"jm_handleOpenFile\n");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    // if these files were opened from a Spotlight query, try to get the search text from the current AppleEvent
+    NSAppleEventDescriptor *currentEvent = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent];
+    NSString *searchString = [[currentEvent paramDescriptorForKeyword:keyAESearchText] stringValue];
+    jstring jSearchString = JNFNSToJavaString(env, searchString);
+
+    // convert the file names array
+    jobject jFileNamesArray = [self _createFilePathArrayFrom:fileNames withEnv:env];
+
+    static JNF_STATIC_MEMBER_CACHE(jm_handleOpenFiles, sjc_AppEventHandler, "handleOpenFiles", "(Ljava/util/List;Ljava/lang/String;)V");
+    JNFCallStaticVoidMethod(env, jm_handleOpenFiles, jFileNamesArray, jSearchString);
+    (*env)->DeleteLocalRef(env, jFileNamesArray);
+    (*env)->DeleteLocalRef(env, jSearchString);
+
+    [theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
+}
+
+// Print handler
+- (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels {
+AWT_ASSERT_APPKIT_THREAD;
+    if (!fHandlesDocumentTypes) return NSPrintingCancelled;
+
+    //fprintf(stderr,"jm_handlePrintFile\n");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject jFileNamesArray = [self _createFilePathArrayFrom:fileNames withEnv:env];
+    static JNF_STATIC_MEMBER_CACHE(jm_handlePrintFile, sjc_AppEventHandler, "handlePrintFiles", "(Ljava/util/List;)V");
+    JNFCallStaticVoidMethod(env, jm_handlePrintFile, jFileNamesArray); // AWT_THREADING Safe (event)
+    (*env)->DeleteLocalRef(env, jFileNamesArray);
+
+    return NSPrintingSuccess;
+}
+
+// Open app handler, registered in -init
++ (void)_notifyJava:(jint)notificationType {
+AWT_ASSERT_APPKIT_THREAD;
+
+    //fprintf(stderr,"jm_handleOpenApplication\n");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V");
+    JNFCallStaticVoidMethod(env, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event)
+}
+
+// About menu handler
+- (void)_aboutMenuHandler {
+    [ApplicationDelegate _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_ABOUT];
+}
+
+// Preferences handler
+- (void)_preferencesMenuHandler {
+    [ApplicationDelegate _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_PREFS];
+}
+
+// Open app handler, registered in -init
++ (void)_willFinishLaunching {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_OPEN_APP];
+}
+
+// ReOpen app handler
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
+    [ApplicationDelegate _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_REOPEN_APP];
+    return YES;
+}
+
+// Quit handler
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app {
+    [ApplicationDelegate _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_QUIT];
+    return NSTerminateLater;
+}
+
++ (void)_systemWillPowerOff {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_SHUTDOWN];
+}
+
++ (void)_appDidActivate {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_ACTIVE_APP_GAINED];
+}
+
++ (void)_appDidDeactivate {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_ACTIVE_APP_LOST];
+}
+
++ (void)_appDidHide {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_APP_HIDDEN];
+}
+
++ (void)_appDidUnhide {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_APP_SHOWN];
+}
+
++ (void)_sessionDidActivate {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_USER_SESSION_ACTIVE];
+}
+
++ (void)_sessionDidDeactivate {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_USER_SESSION_INACTIVE];
+}
+
++ (void)_screenDidSleep {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_SCREEN_SLEEP];
+}
+
++ (void)_screenDidWake {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_SCREEN_WAKE];
+}
+
++ (void)_systemDidSleep {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_SYSTEM_SLEEP];
+}
+
++ (void)_systemDidWake {
+    [self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_SYSTEM_WAKE];
+}
+
++ (void)_registerForNotification:(NSNumber *)notificationTypeNum {
+    NSNotificationCenter *ctr = [[NSWorkspace sharedWorkspace] notificationCenter];
+    Class clz = [ApplicationDelegate class];
+
+    jint notificationType = [notificationTypeNum intValue];
+    switch (notificationType) {
+        case com_apple_eawt__AppEventHandler_REGISTER_USER_SESSION:
+            [ctr addObserver:clz selector:@selector(_sessionDidActivate) name:NSWorkspaceSessionDidBecomeActiveNotification object:nil];
+            [ctr addObserver:clz selector:@selector(_sessionDidDeactivate) name:NSWorkspaceSessionDidResignActiveNotification object:nil];
+            break;
+        case com_apple_eawt__AppEventHandler_REGISTER_SCREEN_SLEEP:
+            [ctr addObserver:clz selector:@selector(_screenDidSleep) name:NSWorkspaceScreensDidSleepNotification object:nil];
+            [ctr addObserver:clz selector:@selector(_screenDidWake) name:NSWorkspaceScreensDidWakeNotification object:nil];
+            break;
+        case com_apple_eawt__AppEventHandler_REGISTER_SYSTEM_SLEEP:
+            [ctr addObserver:clz selector:@selector(_systemDidSleep) name:NSWorkspaceWillSleepNotification object:nil];
+            [ctr addObserver:clz selector:@selector(_systemDidWake) name:NSWorkspaceDidWakeNotification object:nil];
+            break;
+        default:
+            NSLog(@"EAWT attempting to register for unknown notification: %d", (int)notificationType);
+            break;
+    }
+}
+
+// Retrieves the menu to be attached to the Dock icon (AppKit callback)
+- (NSMenu *)applicationDockMenu:(NSApplication *)sender {
+AWT_ASSERT_APPKIT_THREAD;
+    return self.fDockMenu;
+}
+
+- (CMenuBar *)defaultMenuBar {
+    return [[self.fDefaultMenuBar retain] autorelease];
+}
+
+
+#pragma mark Helpers called on the main thread from Java
+
+// Sets a new NSImageView on the Dock tile
++ (void)_setDockIconImage:(NSImage *)image {
+AWT_ASSERT_APPKIT_THREAD;
+
+    NSDockTile *dockTile = [NSApp dockTile];
+    if (image == nil) {
+        [dockTile setContentView:nil];
+        return;
+    }
+
+    // setup an image view for the dock tile
+    NSRect frame = NSMakeRect(0, 0, dockTile.size.width, dockTile.size.height);
+    NSImageView *dockImageView = [[NSImageView alloc] initWithFrame: frame];
+    [dockImageView setImageScaling:NSImageScaleProportionallyUpOrDown];
+    [dockImageView setImage:image];
+
+    // add it to the NSDockTile
+    [dockTile setContentView: dockImageView];
+    [dockTile display];
+
+    [dockImageView release];
+}
+
+// Obtains the image of the Dock icon, either manually set, a drawn copy, or the default NSApplicationIcon
++ (NSImage *)_dockIconImage {
+AWT_ASSERT_APPKIT_THREAD;
+
+    NSDockTile *dockTile = [NSApp dockTile];
+    NSView *view = [dockTile contentView];
+
+    if ([view isKindOfClass:[NSImageView class]]) {
+        NSImage *img = [((NSImageView *)view) image];
+        if (img) return img;
+    }
+
+    if (view == nil) {
+        return [NSImage imageNamed:@"NSApplicationIcon"];
+    }
+
+    NSRect frame = [view frame];
+    NSImage *image = [[NSImage alloc] initWithSize:frame.size];
+    [image lockFocus];
+    [view drawRect:frame];
+    [image unlockFocus];
+    [image autorelease];
+    return image;
+}
+
+@end
+
+
+#pragma mark Native JNI calls
+
+/*
+ * Class:     com_apple_eawt_Application
+ * Method:    nativeInitializeApplicationDelegate
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt_Application_nativeInitializeApplicationDelegate
+(JNIEnv *env, jclass clz)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+    // Force initialization to happen on AppKit thread!
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [ApplicationDelegate sharedDelegate];
+    }];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppEventHandler
+ * Method:    nativeOpenCocoaAboutWindow
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppEventHandler_nativeOpenCocoaAboutWindow
+(JNIEnv *env, jclass clz)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [NSApp orderFrontStandardAboutPanel:nil];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppEventHandler
+ * Method:    nativeReplyToAppShouldTerminate
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppEventHandler_nativeReplyToAppShouldTerminate
+(JNIEnv *env, jclass clz, jboolean doTerminate)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [NSApp replyToApplicationShouldTerminate:doTerminate];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppEventHandler
+ * Method:    nativeRegisterForNotification
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppEventHandler_nativeRegisterForNotification
+(JNIEnv *env, jclass clz, jint notificationType)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+    [ThreadUtilities performOnMainThread:@selector(_registerForNotification:)
+                                onObject:[ApplicationDelegate class]
+                              withObject:[NSNumber numberWithInt:notificationType]
+                           waitUntilDone:NO
+                                 awtMode:NO]; // AWT_THREADING Safe (non-blocking)
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppDockIconHandler
+ * Method:    nativeSetDockMenu
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeSetDockMenu
+(JNIEnv *env, jclass clz, jlong nsMenuPtr)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    NSMenu *menu = (NSMenu *)jlong_to_ptr(nsMenuPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [ApplicationDelegate sharedDelegate].fDockMenu = menu;
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppDockIconHandler
+ * Method:    nativeSetDockIconImage
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeSetDockIconImage
+(JNIEnv *env, jclass clz, jlong nsImagePtr)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    NSImage *_image = (NSImage *)jlong_to_ptr(nsImagePtr);
+    [JNFRunLoop performOnMainThread:@selector(_setDockIconImage:)
+                                 on:[ApplicationDelegate class]
+                         withObject:_image
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppDockIconHandler
+ * Method:    nativeGetDockIconImage
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeGetDockIconImage
+(JNIEnv *env, jclass clz)
+{
+    __block NSImage *image = nil;
+
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        image = [ApplicationDelegate _dockIconImage];
+        CFRetain(image);
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(image);
+}
+
+/*
+ * Class:     com_apple_eawt__AppDockIconHandler
+ * Method:    nativeSetDockIconBadge
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeSetDockIconBadge
+(JNIEnv *env, jclass clz, jstring badge)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    NSString *badgeString = JNFJavaToNSString(env, badge);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        NSDockTile *dockTile = [NSApp dockTile];
+        [dockTile setBadgeLabel:badgeString];
+        [dockTile display];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppMiscHandlers
+ * Method:    nativeRequestActivation
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeRequestActivation
+(JNIEnv *env, jclass clz, jboolean allWindows)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        NSApplicationActivationOptions options = allWindows ? NSApplicationActivateAllWindows : 0;
+        options |= NSApplicationActivateIgnoringOtherApps; // without this, nothing happens!
+        [[NSRunningApplication currentApplication] activateWithOptions:options];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppMiscHandlers
+ * Method:    nativeRequestUserAttention
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeRequestUserAttention
+(JNIEnv *env, jclass clz, jboolean critical)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [NSApp requestUserAttention:critical ? NSCriticalRequest : NSInformationalRequest];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppMiscHandlers
+ * Method:    nativeOpenHelpViewer
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeOpenHelpViewer
+(JNIEnv *env, jclass clz)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThread:@selector(showHelp:)
+                                 on:NSApp
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppMiscHandlers
+ * Method:    nativeEnableSuddenTermination
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeEnableSuddenTermination
+(JNIEnv *env, jclass clz)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [[NSProcessInfo processInfo] enableSuddenTermination]; // Foundation thread-safe
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppMiscHandlers
+ * Method:    nativeDisableSuddenTermination
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeDisableSuddenTermination
+(JNIEnv *env, jclass clz)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [[NSProcessInfo processInfo] disableSuddenTermination]; // Foundation thread-safe
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppMenuBarHandler
+ * Method:    nativeSetMenuState
+ * Signature: (IZZ)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMenuBarHandler_nativeSetMenuState
+(JNIEnv *env, jclass clz, jint menuID, jboolean visible, jboolean enabled)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        ApplicationDelegate *delegate = [ApplicationDelegate sharedDelegate];
+        switch (menuID) {
+            case com_apple_eawt__AppMenuBarHandler_MENU_ABOUT:
+                [delegate _updateAboutMenu:visible enabled:enabled];
+                break;
+            case com_apple_eawt__AppMenuBarHandler_MENU_PREFS:
+                [delegate _updatePreferencesMenu:visible enabled:enabled];
+                break;
+        }
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     com_apple_eawt__AppMenuBarHandler
+ * Method:    nativeSetDefaultMenuBar
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMenuBarHandler_nativeSetDefaultMenuBar
+(JNIEnv *env, jclass clz, jlong cMenuBarPtr)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    CMenuBar *menu = (CMenuBar *)jlong_to_ptr(cMenuBarPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+        [ApplicationDelegate sharedDelegate].fDefaultMenuBar = menu;
+    }];
+
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CClipboard.h b/jdk/src/macosx/native/sun/awt/CClipboard.h
new file mode 100644
index 0000000..a62bebd
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CClipboard.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import "jni.h"
+
+@interface CClipboard : NSObject {
+    jobject fClipboardOwner;
+
+    // Track pasteboard changes. Initialized once at the start, and then updated
+    // on an application resume event.  If it's different than the last time we claimed
+    // the clipboard that means we lost the clipboard to someone else.
+    NSInteger fChangeCount;
+}
+
++ (CClipboard *) sharedClipboard;
+
+- (void) javaDeclareTypes:(NSArray *)inTypes withOwner:(jobject)inClipboard jniEnv:(JNIEnv *)inEnv;
+- (void) javaSetData:(NSData *)inData forType:(NSString *) inFormat;
+
+- (NSArray *) javaGetTypes;
+- (NSData *) javaGetDataForType:(NSString *)inFormat;
+
+- (void) pasteboardChangedOwner:(NSPasteboard *)sender;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CClipboard.m b/jdk/src/macosx/native/sun/awt/CClipboard.m
new file mode 100644
index 0000000..3667597
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CClipboard.m
@@ -0,0 +1,378 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "CClipboard.h"
+#include "CDataTransferer.h"
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#include "ThreadUtilities.h"
+
+
+static CClipboard *sClipboard = nil;
+
+//
+// CClipboardUpdate is used for mulitple calls to setData that happen before
+// the model and AppKit can get back in sync.
+//
+
+@interface CClipboardUpdate : NSObject {
+    NSData *fData;
+    NSString *fFormat;
+}
+
+- (id)initWithData:(NSData *)inData withFormat:(NSString *)inFormat;
+- (NSData *)data;
+- (NSString *)format;
+
+@end
+
+@implementation CClipboardUpdate
+
+- (id)initWithData:(NSData *)inData withFormat:(NSString *)inFormat
+{
+    self = [super init];
+
+    if (self != nil) {
+        fData = [inData retain];
+        fFormat = [inFormat retain];
+    }
+
+    return self;
+}
+
+- (void)dealloc
+{
+    [fData release];
+    fData = nil;
+
+    [fFormat release];
+    fFormat = nil;
+
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+- (NSData *)data {
+    return fData;
+}
+
+- (NSString *)format {
+    return fFormat;
+}
+@end
+
+@implementation CClipboard
+
+// Clipboard creation is synchronized at the Java level.
++ (CClipboard *) sharedClipboard
+{
+    if (sClipboard == nil) {
+        sClipboard = [[CClipboard alloc] init];
+        [[NSNotificationCenter defaultCenter] addObserver:sClipboard selector: @selector(checkPasteboard:) name: NSApplicationDidBecomeActiveNotification object: nil];
+    }
+
+    return sClipboard;
+}
+
+- (id) init
+{
+    self = [super init];
+
+    if (self != nil) {
+        fChangeCount = [[NSPasteboard generalPasteboard] changeCount];
+    }
+
+    return self;
+}
+
+- (void) javaDeclareTypes:(NSArray *)inTypes withOwner:(jobject)inClipboard jniEnv:(JNIEnv *)inEnv {
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    //NSLog(@"CClipboard javaDeclareTypes %@ withOwner", inTypes);
+
+    @synchronized(self) {
+        if (inClipboard != NULL) {
+            if (fClipboardOwner != NULL) {
+                JNFDeleteGlobalRef(inEnv, fClipboardOwner);
+            }
+            fClipboardOwner = JNFNewGlobalRef(inEnv, inClipboard);
+        }
+    }
+    [ThreadUtilities performOnMainThread:@selector(_nativeDeclareTypes:) onObject:self withObject:inTypes waitUntilDone:YES awtMode:YES];
+}
+
+- (void) _nativeDeclareTypes:(NSArray *)inTypes {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    //NSLog(@"CClipboard _nativeDeclareTypes %@ withOwner", inTypes);
+
+    fChangeCount = [[NSPasteboard generalPasteboard] declareTypes:inTypes owner:self];
+}
+
+
+- (NSArray *) javaGetTypes {
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    NSMutableArray *args = [NSMutableArray arrayWithCapacity:1];
+    [ThreadUtilities performOnMainThread:@selector(_nativeGetTypes:) onObject:self withObject:args waitUntilDone:YES awtMode:YES];
+
+    //NSLog(@"CClipboard getTypes returns %@", [args lastObject]);
+    return [args lastObject];
+}
+
+- (void) _nativeGetTypes:(NSMutableArray *)args {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    [args addObject:[[NSPasteboard generalPasteboard] types]];
+
+    //NSLog(@"CClipboard getTypes returns %@", [args lastObject]);
+}
+
+- (void) javaSetData:(NSData *)inData forType:(NSString *) inFormat {
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    CClipboardUpdate *newUpdate = [[CClipboardUpdate alloc] initWithData:inData withFormat:inFormat];
+    [ThreadUtilities performOnMainThread:@selector(_nativeSetData:) onObject:self withObject:newUpdate waitUntilDone:YES awtMode:YES];
+    [newUpdate release];
+
+    //NSLog(@"CClipboard javaSetData forType %@", inFormat);
+}
+
+- (void) _nativeSetData:(CClipboardUpdate *)newUpdate {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    [[NSPasteboard generalPasteboard] setData:[newUpdate data] forType:[newUpdate format]];
+
+    //NSLog(@"CClipboard _nativeSetData setData %@", [newUpdate data]);
+    //NSLog(@"CClipboard _nativeSetData forType %@", [newUpdate format]);
+}
+
+- (NSData *) javaGetDataForType:(NSString *) inFormat {
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    NSMutableArray *args = [NSMutableArray arrayWithObject:inFormat];
+    [ThreadUtilities performOnMainThread:@selector(_nativeGetDataForType:) onObject:self withObject:args waitUntilDone:YES awtMode:YES];
+
+    //NSLog(@"CClipboard javaGetDataForType %@ returns an NSData", inFormat);
+    return [args lastObject];
+}
+
+- (void) _nativeGetDataForType:(NSMutableArray *) args {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    NSData *returnValue = [[NSPasteboard generalPasteboard] dataForType:[args objectAtIndex:0]];
+
+    if (returnValue) [args replaceObjectAtIndex:0 withObject:returnValue];
+    else [args removeLastObject];
+
+    //NSLog(@"CClipboard _nativeGetDataForType");
+}
+
+- (void) checkPasteboard:(id)application {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    //NSLog(@"CClipboard checkPasteboard oldCount %d newCount %d newTypes %@", fChangeCount, [[NSPasteboard generalPasteboard] changeCount], [[NSPasteboard generalPasteboard] types]);
+
+    // This is called via NSApplicationDidBecomeActiveNotification.
+
+    // If the change count on the general pasteboard is different than when we set it
+    // someone else put data on the clipboard.  That means the current owner lost ownership.
+    NSInteger newChangeCount = [[NSPasteboard generalPasteboard] changeCount];
+
+    if (fChangeCount != newChangeCount) {
+        fChangeCount = newChangeCount;
+
+        [self pasteboardChangedOwner:[NSPasteboard generalPasteboard]];
+    }
+}
+
+- (void)pasteboardChangedOwner:(NSPasteboard *)sender; {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
+    static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "lostSelectionOwnershipImpl", "()V");
+
+    //NSLog(@"CClipboard pasteboardChangedOwner");
+
+    // If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore.
+    @synchronized(self) {
+        if (fClipboardOwner) {
+            JNIEnv *env = [ThreadUtilities getJNIEnv];
+            JNFCallVoidMethod(env, fClipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
+            JNFDeleteGlobalRef(env, fClipboardOwner);
+            fClipboardOwner = NULL;
+        }
+    }
+}
+
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CClipboard
+ * Method:    declareTypes
+ * Signature: ([JLsun/awt/datatransfer/SunClipboard;)V
+*/
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_declareTypes
+(JNIEnv *env, jobject inObject, jlongArray inTypes, jobject inJavaClip)
+{
+JNF_COCOA_ENTER(env);
+
+    jint i;
+    jint nElements = (*env)->GetArrayLength(env, inTypes);
+    NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:nElements];
+    jlong *elements = (*env)->GetPrimitiveArrayCritical(env, inTypes, NULL);
+
+    for (i = 0; i < nElements; i++) {
+        NSString *pbFormat = formatForIndex(elements[i]);
+        if (pbFormat)
+            [formatArray addObject:pbFormat];
+    }
+
+    (*env)->ReleasePrimitiveArrayCritical(env, inTypes, elements, JNI_ABORT);
+    [[CClipboard sharedClipboard] javaDeclareTypes:formatArray withOwner:inJavaClip jniEnv:env];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CClipboard
+ * Method:    setData
+ * Signature: ([BJ)V
+*/
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_setData
+(JNIEnv *env, jobject inObject, jbyteArray inBytes, jlong inFormat)
+{
+    if (inBytes == NULL) {
+        return;
+    }
+
+JNF_COCOA_ENTER(env);
+
+    //NSLog(@"Java_sun_lwawt_macosx_CClipboard_setData");
+
+    jint nBytes = (*env)->GetArrayLength(env, inBytes);
+    jbyte *rawBytes = (*env)->GetPrimitiveArrayCritical(env, inBytes, NULL);
+    NSData *bytesAsData = [NSData dataWithBytes:rawBytes length:nBytes];
+    (*env)->ReleasePrimitiveArrayCritical(env, inBytes, rawBytes, JNI_ABORT);
+    NSString *format = formatForIndex(inFormat);
+    [[CClipboard sharedClipboard] javaSetData:bytesAsData forType:format];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CClipboard
+ * Method:    getClipboardFormats
+ * Signature: (J)[J
+     */
+JNIEXPORT jlongArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardFormats
+(JNIEnv *env, jobject inObject)
+{
+    jlongArray returnValue = NULL;
+JNF_COCOA_ENTER(env);
+
+    //NSLog(@"Java_sun_lwawt_macosx_CClipboard_getClipboardFormats");
+
+    NSArray *dataTypes = [[CClipboard sharedClipboard] javaGetTypes];
+    NSUInteger nFormats = [dataTypes count];
+    NSUInteger knownFormats = 0;
+    NSUInteger i;
+
+    // There can be any number of formats on the general pasteboard.  Find out which ones
+    // we know about (i.e., live in the flavormap.properties).
+    for (i = 0; i < nFormats; i++) {
+        NSString *format = (NSString *)[dataTypes objectAtIndex:i];
+        if (indexForFormat(format) != -1)
+            knownFormats++;
+    }
+
+    returnValue = (*env)->NewLongArray(env, knownFormats);
+    if (returnValue == NULL) {
+        return NULL;
+    }
+
+    if (knownFormats == 0) {
+        return returnValue;
+    }
+
+    // Now go back and map the formats we found back to Java indexes.
+    jboolean isCopy;
+    jlong *lFormats = (*env)->GetLongArrayElements(env, returnValue, &isCopy);
+    jlong *saveFormats = lFormats;
+
+    for (i = 0; i < nFormats; i++) {
+        NSString *format = (NSString *)[dataTypes objectAtIndex:i];
+        jlong index = indexForFormat(format);
+
+        if (index != -1) {
+            *lFormats = index;
+            lFormats++;
+        }
+    }
+
+    (*env)->ReleaseLongArrayElements(env, returnValue, saveFormats, JNI_COMMIT);
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CClipboard
+ * Method:    getClipboardData
+ * Signature: (JJ)[B
+     */
+JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardData
+(JNIEnv *env, jobject inObject, jlong format)
+{
+    jbyteArray returnValue = NULL;
+
+    // Note that this routine makes no attempt to interpret the data, since we're returning
+    // a byte array back to Java.  CDataTransferer will do that if necessary.
+JNF_COCOA_ENTER(env);
+
+    //NSLog(@"Java_sun_lwawt_macosx_CClipboard_getClipboardData");
+
+    NSString *formatAsString = formatForIndex(format);
+    NSData *clipData = [[CClipboard sharedClipboard] javaGetDataForType:formatAsString];
+
+    if (clipData == NULL) {
+        [JNFException raise:env as:"java/io/IOException" reason:"Font transform has NaN position"];
+        return NULL;
+    }
+
+    NSUInteger dataSize = [clipData length];
+    returnValue = (*env)->NewByteArray(env, dataSize);
+    if (returnValue == NULL) {
+        return NULL;
+    }
+
+    if (dataSize != 0) {
+        const void *dataBuffer = [clipData bytes];
+        (*env)->SetByteArrayRegion(env, returnValue, 0, dataSize, (jbyte *)dataBuffer);
+    }
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+
diff --git a/jdk/src/macosx/native/sun/awt/CCursorManager.m b/jdk/src/macosx/native/sun/awt/CCursorManager.m
new file mode 100644
index 0000000..0293329
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CCursorManager.m
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "sun_lwawt_macosx_CCursorManager.h"
+
+#include <Cocoa/Cocoa.h>
+#include <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#include "GeomUtilities.h"
+#include "ThreadUtilities.h"
+
+#include "java_awt_Cursor.h"
+
+
+static SEL lookupCursorSelectorForType(jint type) {
+    switch (type) {
+        case java_awt_Cursor_DEFAULT_CURSOR:        return @selector(arrowCursor);
+        case java_awt_Cursor_CROSSHAIR_CURSOR:      return @selector(crosshairCursor);
+        case java_awt_Cursor_TEXT_CURSOR:           return @selector(IBeamCursor);
+        case java_awt_Cursor_WAIT_CURSOR:           return @selector(javaBusyButClickableCursor);
+        case java_awt_Cursor_SW_RESIZE_CURSOR:      return @selector(javaResizeSWCursor);
+        case java_awt_Cursor_SE_RESIZE_CURSOR:      return @selector(javaResizeSECursor);
+        case java_awt_Cursor_NW_RESIZE_CURSOR:      return @selector(javaResizeNWCursor);
+        case java_awt_Cursor_NE_RESIZE_CURSOR:      return @selector(javaResizeNECursor);
+        case java_awt_Cursor_N_RESIZE_CURSOR:       return @selector(resizeUpDownCursor);
+        case java_awt_Cursor_S_RESIZE_CURSOR:       return @selector(resizeUpDownCursor);
+        case java_awt_Cursor_W_RESIZE_CURSOR:       return @selector(resizeLeftRightCursor);
+        case java_awt_Cursor_E_RESIZE_CURSOR:       return @selector(resizeLeftRightCursor);
+        case java_awt_Cursor_HAND_CURSOR:           return @selector(pointingHandCursor);
+        case java_awt_Cursor_MOVE_CURSOR:           return @selector(javaMoveCursor);
+    }
+
+    return nil;
+}
+
+static SEL lookupCursorSelectorForName(NSString *name) {
+    if ([@"DnD.Cursor.CopyDrop" isEqual:name]) return @selector(dragCopyCursor);
+    if ([@"DnD.Cursor.LinkDrop" isEqual:name]) return @selector(dragLinkCursor);
+    if ([@"DnD.Cursor.MoveDrop" isEqual:name]) return @selector(_genericDragCursor);
+    if ([@"DnD.Cursor.CopyNoDrop" isEqual:name]) return @selector(operationNotAllowedCursor);
+    if ([@"DnD.Cursor.LinkNoDrop" isEqual:name]) return @selector(operationNotAllowedCursor);
+    if ([@"DnD.Cursor.MoveNoDrop" isEqual:name]) return @selector(operationNotAllowedCursor);
+    return nil;
+}
+
+static void setCursorOnAppKitThread(NSCursor *cursor) {
+    [cursor set];
+}
+
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CCursorManager_nativeSetBuiltInCursor
+(JNIEnv *env, jclass class, jint type, jstring name)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    NSString *cursorName = JNFJavaToNSString(env, name);
+    SEL cursorSelector = (type == sun_lwawt_macosx_CCursorManager_NAMED_CURSOR) ? lookupCursorSelectorForName(cursorName) : lookupCursorSelectorForType(type);
+    if (cursorSelector == nil) {
+        NSString *reason = [NSString stringWithFormat:@"unimplemented built-in cursor type: %d / %@", type, cursorName];
+        [JNFException raise:env as:kIllegalArgumentException reason:[reason UTF8String]];
+    }
+
+    if (![[NSCursor class] respondsToSelector:cursorSelector]) {
+        [JNFException raise:env as:kNoSuchMethodException reason:"missing NSCursor selector"];
+    }
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        setCursorOnAppKitThread([[NSCursor class] performSelector:cursorSelector]);
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CCursorManager_nativeSetCustomCursor
+(JNIEnv *env, jclass class, jlong imgPtr, jdouble x, jdouble y)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+    NSImage *image = (NSImage *)jlong_to_ptr(imgPtr);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        NSCursor *cursor = [[NSCursor alloc] initWithImage:image
+                                                   hotSpot:(NSPoint){ x, y }];
+        setCursorOnAppKitThread(cursor);
+        [cursor release];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+JNIEXPORT jobject JNICALL
+Java_sun_lwawt_macosx_CCursorManager_nativeGetCursorPosition
+(JNIEnv *env, jclass class)
+{
+    jobject jpt = NULL;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    __block NSPoint pt = NSZeroPoint;
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        pt = ConvertNSScreenPoint(env, [NSEvent mouseLocation]);
+    }];
+    jpt = NSToJavaPoint(env, pt);
+
+JNF_COCOA_EXIT(env);
+
+    return jpt;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CDataTransferer.h b/jdk/src/macosx/native/sun/awt/CDataTransferer.h
new file mode 100644
index 0000000..00e2b2b
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDataTransferer.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import "jni.h"
+
+/*
+ * Sets up the dictionary of numbers to NSStrings
+ */
+extern void initializeMappingTable();
+
+/*
+ * Convert from a standard NSPasteboard data type to an index in our mapping table.
+ */
+extern jlong indexForFormat(NSString *format);
+
+/*
+ * Inverse of above -- given a long int index, get the matching data format NSString.
+ */
+extern NSString* formatForIndex(jlong inFormatCode);
+
+/*
+ * Register a non-standard NSPasteboard data type in our mapping table and return its index.
+ */
+extern jlong registerFormatWithPasteboard(NSString *format);
diff --git a/jdk/src/macosx/native/sun/awt/CDataTransferer.m b/jdk/src/macosx/native/sun/awt/CDataTransferer.m
new file mode 100644
index 0000000..5be5098
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDataTransferer.m
@@ -0,0 +1,349 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CDataTransferer.h"
+#include "sun_lwawt_macosx_CDataTransferer.h"
+
+#import <AppKit/AppKit.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#include "ThreadUtilities.h"
+
+
+// ***** NOTE ***** This dictionary corresponds to the static array predefinedClipboardNames
+// in CDataTransferer.java.
+NSMutableDictionary *sStandardMappings = nil;
+
+NSMutableDictionary *getMappingTable() {
+    if (sStandardMappings == nil) {
+        sStandardMappings = [[NSMutableDictionary alloc] init];
+        [sStandardMappings setObject:NSStringPboardType
+                              forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_STRING]];
+        [sStandardMappings setObject:NSFilenamesPboardType
+                              forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_FILE]];
+        [sStandardMappings setObject:NSTIFFPboardType
+                              forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_TIFF]];
+        [sStandardMappings setObject:NSRTFPboardType
+                              forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_RICH_TEXT]];
+        [sStandardMappings setObject:NSHTMLPboardType
+                              forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_HTML]];
+        [sStandardMappings setObject:NSPDFPboardType
+                              forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_PDF]];
+        [sStandardMappings setObject:NSURLPboardType
+                              forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_URL]];
+    }
+    return sStandardMappings;
+}
+
+/*
+ * Convert from a standard NSPasteboard data type to an index in our mapping table.
+ */
+jlong indexForFormat(NSString *format) {
+    jlong returnValue = -1;
+
+    NSMutableDictionary *mappingTable = getMappingTable();
+    NSArray *matchingKeys = [mappingTable allKeysForObject:format];
+
+    // There should only be one matching key here...
+    if ([matchingKeys count] > 0) {
+        NSNumber *formatID = (NSNumber *)[matchingKeys objectAtIndex:0];
+        returnValue = [formatID longValue];
+    }
+
+    // If we don't recognize the format, but it's a Java "custom" format register it
+    if (returnValue == -1 && ([format hasPrefix:@"JAVA_DATAFLAVOR:"]) ) {
+        returnValue = registerFormatWithPasteboard(format);
+    }
+
+    return returnValue;
+}
+
+/*
+ * Inverse of above -- given a long int index, get the matching data format NSString.
+ */
+NSString *formatForIndex(jlong inFormatCode) {
+    return [getMappingTable() objectForKey:[NSNumber numberWithLong:inFormatCode]];
+}
+
+jlong registerFormatWithPasteboard(NSString *format) {
+    NSMutableDictionary *mappingTable = getMappingTable();
+    NSUInteger nextID = [mappingTable count] + 1;
+    [mappingTable setObject:format forKey:[NSNumber numberWithLong:nextID]];
+    return nextID;
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CDataTransferer
+ * Method:    registerFormatWithPasteboard
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDataTransferer_registerFormatWithPasteboard
+(JNIEnv *env, jobject jthis, jstring newformat)
+{
+    jlong returnValue = -1;
+JNF_COCOA_ENTER(env);
+    returnValue = registerFormatWithPasteboard(JNFJavaToNSString(env, newformat));
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDataTransferer
+ * Method:    formatForIndex
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_sun_lwawt_macosx_CDataTransferer_formatForIndex
+  (JNIEnv *env, jobject jthis, jlong index)
+{
+    jstring returnValue = NULL;
+JNF_COCOA_ENTER(env);
+    returnValue = JNFNSToJavaString(env, formatForIndex(index));
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDataTransferer
+ * Method:    imageDataToPlatformImageBytes
+ * Signature: ([III)[B
+     */
+JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CDataTransferer_imageDataToPlatformImageBytes
+(JNIEnv *env, jobject obj, jintArray inPixelData, jint inWidth, jint inHeight)
+{
+    jbyteArray returnValue = nil;
+JNF_COCOA_ENTER(env);
+    UInt32 *rawImageData = (UInt32 *)(*env)->GetPrimitiveArrayCritical(env, inPixelData, 0);
+
+    // The pixel data is in premultiplied ARGB format. That's exactly what
+    // we need for the bitmap image rep.
+    if (rawImageData != NULL) {
+        NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
+                                                                             pixelsWide:inWidth
+                                                                             pixelsHigh:inHeight
+                                                                          bitsPerSample:8
+                                                                        samplesPerPixel:4
+                                                                               hasAlpha:YES
+                                                                               isPlanar:NO
+                                                                         colorSpaceName:NSCalibratedRGBColorSpace
+                                                                            bytesPerRow:(inWidth*4)
+                                                                           bitsPerPixel:32];
+
+        // Conver the ARGB data into RGBA data that the bitmap can draw.
+        unsigned char *destData = [imageRep bitmapData];
+        unsigned char *currentRowBase;
+        jint x, y;
+
+        for (y = 0; y < inHeight; y++) {
+            currentRowBase = destData + y * (inWidth * 4);
+            unsigned char *currElement = currentRowBase;
+            for (x = 0; x < inWidth; x++) {
+                UInt32 currPixel = rawImageData[y * inWidth + x];
+                *currElement++ = ((currPixel & 0xFF0000) >> 16);
+                *currElement++ = ((currPixel & 0xFF00) >> 8);
+                *currElement++ = (currPixel & 0xFF);
+                *currElement++ = ((currPixel & 0xFF000000) >> 24);
+            }
+        }
+
+        (*env)->ReleasePrimitiveArrayCritical(env, inPixelData, rawImageData, JNI_ABORT);
+        NSData *tiffImage = [imageRep TIFFRepresentation];
+        jsize tiffSize = (jsize)[tiffImage length]; // #warning 64-bit: -length returns NSUInteger, but NewByteArray takes jsize
+        returnValue = (*env)->NewByteArray(env, tiffSize);
+        jbyte *tiffData = (jbyte *)(*env)->GetPrimitiveArrayCritical(env, returnValue, 0);
+        [tiffImage getBytes:tiffData];
+        (*env)->ReleasePrimitiveArrayCritical(env, returnValue, tiffData, 0); // Do not use JNI_COMMIT, as that will not free the buffer copy when +ProtectJavaHeap is on.
+        [imageRep release];
+    }
+JNF_COCOA_EXIT(env);
+    return returnValue;
+
+}
+
+static jobject getImageForByteStream(JNIEnv *env, jbyteArray sourceData)
+{
+    if (sourceData == NULL) return NULL;
+
+    jsize sourceSize = (*env)->GetArrayLength(env, sourceData);
+    if (sourceSize == 0) return NULL;
+
+    jbyte *sourceBytes = (*env)->GetPrimitiveArrayCritical(env, sourceData, NULL);
+    NSData *rawData = [NSData dataWithBytes:sourceBytes length:sourceSize];
+
+    NSImage *newImage = [[NSImage alloc] initWithData:rawData];
+    if (newImage) CFRetain(newImage); // GC
+    [newImage release];
+
+    (*env)->ReleasePrimitiveArrayCritical(env, sourceData, sourceBytes, JNI_ABORT);
+
+    if (newImage == nil) return NULL;
+
+    // The ownership of the NSImage is passed to the new CImage jobject. No need to release it.
+    static JNF_CLASS_CACHE(jc_CImage, "sun/lwawt/macosx/CImage");
+    static JNF_STATIC_MEMBER_CACHE(jm_CImage_getCreator, jc_CImage, "getCreator", "()Lsun/lwawt/macosx/CImage$Creator;");
+    jobject creator = JNFCallStaticObjectMethod(env, jm_CImage_getCreator);
+
+    static JNF_CLASS_CACHE(jc_CImage_Generator, "sun/lwawt/macosx/CImage$Creator");
+    static JNF_MEMBER_CACHE(jm_CImage_Generator_createImageUsingNativeSize, jc_CImage_Generator, "createImageUsingNativeSize", "(J)Ljava/awt/image/BufferedImage;");
+    return JNFCallObjectMethod(env, creator, jm_CImage_Generator_createImageUsingNativeSize, ptr_to_jlong(newImage)); // AWT_THREADING Safe (known object)
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDataTransferer
+ * Method:    getImageForByteStream
+ * Signature: ([B)Ljava/awt/Image;
+ */
+JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CDataTransferer_getImageForByteStream
+  (JNIEnv *env, jobject obj, jbyteArray sourceData)
+{
+    jobject img = NULL;
+JNF_COCOA_ENTER(env);
+    img = getImageForByteStream(env, sourceData);
+JNF_COCOA_EXIT(env);
+    return img;
+}
+
+static jobjectArray CreateJavaFilenameArray(JNIEnv *env, NSArray *filenameArray)
+{
+    NSUInteger filenameCount = [filenameArray count];
+    if (filenameCount == 0) return nil;
+
+    // Get the java.lang.String class object:
+    jclass stringClazz = (*env)->FindClass(env, "java/lang/String"); // can't be null
+    jobject jfilenameArray = (*env)->NewObjectArray(env, filenameCount, stringClazz, NULL); // AWT_THREADING Safe (known object)
+    if ((*env)->ExceptionOccurred(env)) {
+        (*env)->ExceptionDescribe(env);
+        (*env)->ExceptionClear(env);
+        return nil;
+    }
+    if (!jfilenameArray) {
+        NSLog(@"CDataTransferer_CreateJavaFilenameArray: couldn't create jfilenameArray.");
+        return nil;
+    }
+    (*env)->DeleteLocalRef(env, stringClazz);
+
+    // Iterate through all the filenames:
+    NSUInteger i;
+    for (i = 0; i < filenameCount; i++) {
+        NSMutableString *stringVal = [[NSMutableString alloc] initWithString:[filenameArray objectAtIndex:i]];
+        CFStringNormalize((CFMutableStringRef)stringVal, kCFStringNormalizationFormC);
+        const char* stringBytes = [stringVal UTF8String];
+
+        // Create a Java String:
+        jstring string = (*env)->NewStringUTF(env, stringBytes);
+        if ((*env)->ExceptionOccurred(env)) {
+            (*env)->ExceptionDescribe(env);
+            (*env)->ExceptionClear(env);
+            continue;
+        }
+        if (!string) {
+            NSLog(@"CDataTransferer_CreateJavaFilenameArray: couldn't create jstring[%lu] for [%@].", (unsigned long) i, stringVal);
+            continue;
+        }
+
+        // Set the Java array element with our String:
+        (*env)->SetObjectArrayElement(env, jfilenameArray, i, string);
+        if ((*env)->ExceptionOccurred(env)) {
+            (*env)->ExceptionDescribe(env);
+            (*env)->ExceptionClear(env);
+            continue;
+        }
+
+        // Release local String reference:
+        (*env)->DeleteLocalRef(env, string);
+    }
+
+    return jfilenameArray;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDataTransferer
+ * Method:    draqQueryFile
+ * Signature: ([B)[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL
+Java_sun_lwawt_macosx_CDataTransferer_nativeDragQueryFile
+(JNIEnv *env, jclass clazz, jbyteArray jbytearray)
+{
+    // Decodes a byte array into a set of String filenames.
+    // bytes here is an XML property list containing all of the filenames in the drag.
+    // Parse the XML list into strings and return an array of Java strings matching all of the
+    // files in the list.
+
+    jobjectArray jreturnArray = NULL;
+
+JNF_COCOA_ENTER(env);
+    // Get byte array elements:
+    jboolean isCopy;
+    jbyte* jbytes = (*env)->GetByteArrayElements(env, jbytearray, &isCopy);
+    if (jbytes == NULL) {
+        return NULL;
+    }
+
+    // Wrap jbytes in an NSData object:
+    jsize jbytesLength = (*env)->GetArrayLength(env, jbytearray);
+    NSData *xmlData = [NSData dataWithBytesNoCopy:jbytes length:jbytesLength freeWhenDone:NO];
+
+    // Create a property list from the Java data:
+    NSString *errString = nil;
+    NSPropertyListFormat plistFormat = 0;
+    id plist = [NSPropertyListSerialization propertyListFromData:xmlData mutabilityOption:NSPropertyListImmutable
+        format:&plistFormat errorDescription:&errString];
+
+    // The property list must be an array of strings:
+    if (plist == nil || [plist isKindOfClass:[NSArray class]] == FALSE) {
+        NSLog(@"CDataTransferer_dragQueryFile: plist not a valid NSArray (error %@):\n%@", errString, plist);
+        (*env)->ReleaseByteArrayElements(env, jbytearray, jbytes, JNI_ABORT);
+        return NULL;
+    }
+
+    // Transfer all string items from the plistArray to filenameArray. This wouldn't be necessary
+    // if we could trust the array to contain all valid elements but this way we'll be sure.
+    NSArray *plistArray = (NSArray *)plist;
+    NSUInteger plistItemCount = [plistArray count];
+    NSMutableArray *filenameArray = [[NSMutableArray alloc] initWithCapacity:plistItemCount];
+
+    NSUInteger i;
+    for (i = 0; i < plistItemCount; i++) {
+        // Filenames must be strings:
+        id idVal = [plistArray objectAtIndex:i];
+        if ([idVal isKindOfClass:[NSString class]] == FALSE) {
+            NSLog(@"CDataTransferer_dragQueryFile: plist[%lu] not an NSString:\n%@", (unsigned long) i, idVal);
+            continue;
+        }
+
+        [filenameArray addObject:idVal];
+    }
+
+    // Convert our array of filenames into a Java array of String filenames:
+    jreturnArray = CreateJavaFilenameArray(env, filenameArray);
+
+    [filenameArray release];
+
+    // We're done with the jbytes (backing the plist/plistArray):
+    (*env)->ReleaseByteArrayElements(env, jbytearray, jbytes, JNI_ABORT);
+JNF_COCOA_EXIT(env);
+    return jreturnArray;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CDesktopPeer.m b/jdk/src/macosx/native/sun/awt/CDesktopPeer.m
new file mode 100644
index 0000000..af9f319
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDesktopPeer.m
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+#import <CoreFoundation/CoreFoundation.h>
+#import <ApplicationServices/ApplicationServices.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+/*
+ * Class:     sun_lwawt_macosx_CDesktopPeer
+ * Method:    _lsOpenURI
+ * Signature: (Ljava/lang/String;)I;
+ */
+JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CDesktopPeer__1lsOpenURI
+(JNIEnv *env, jclass clz, jstring uri)
+{
+    // AWT_ASSERT_ANY_THREAD
+
+    OSStatus status = noErr;
+JNF_COCOA_ENTER(env);
+
+    // I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know.
+    // So we use LaunchServices directly.
+
+    NSURL *url = [NSURL URLWithString:JNFJavaToNSString(env, uri)];
+
+    LSLaunchFlags flags = kLSLaunchDefaults;
+
+    LSApplicationParameters params = {0, flags, NULL, NULL, NULL, NULL, NULL};
+    status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, &params, NULL, 0);
+
+JNF_COCOA_EXIT(env);
+    return status;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDesktopPeer
+ * Method:    _lsOpenFile
+ * Signature: (Ljava/lang/String;Z)I;
+ */
+JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CDesktopPeer__1lsOpenFile
+(JNIEnv *env, jclass clz, jstring jpath, jboolean print)
+{
+    // AWT_ASSERT_ANY_THREAD
+
+    OSStatus status = noErr;
+JNF_COCOA_ENTER(env);
+
+    // I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know.
+    // So we use LaunchServices directly.
+
+    NSString *path  = JNFNormalizedNSStringForPath(env, jpath);
+
+    NSURL *url = [NSURL fileURLWithPath:(NSString *)path];
+
+    // This byzantine workaround is necesary, or else directories won't open in Finder
+    url = (NSURL *)CFURLCreateWithFileSystemPath(NULL, (CFStringRef)[url path], kCFURLPOSIXPathStyle, false);
+
+    LSLaunchFlags flags = kLSLaunchDefaults;
+    if (print) flags |= kLSLaunchAndPrint;
+
+    LSApplicationParameters params = {0, flags, NULL, NULL, NULL, NULL, NULL};
+    status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, &params, NULL, 0);
+    CFRelease(url);
+
+JNF_COCOA_EXIT(env);
+    return status;
+}
+
diff --git a/jdk/src/macosx/native/sun/awt/CDragSource.h b/jdk/src/macosx/native/sun/awt/CDragSource.h
new file mode 100644
index 0000000..224bba1
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDragSource.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef CDragSource_h
+#define CDragSource_h
+
+#import <Cocoa/Cocoa.h>
+#include <jni.h>
+
+@interface CDragSource : NSObject {
+@private
+    NSView*        fView;
+    jobject            fComponent;
+    jobject            fComponentPeer;
+    jobject            fDragSourceContextPeer;
+
+    jobject            fTransferable;
+    jobject            fTriggerEvent;
+    jlong            fTriggerEventTimeStamp;
+    NSPoint            fDragPos;
+    jint                fClickCount;
+    jint                fModifiers;
+
+    jobject            fCursor;
+
+    NSImage*        fDragImage;
+    NSPoint            fDragImageOffset;
+
+    jint                fSourceActions;
+    jlongArray        fFormats;
+    jobject            fFormatMap;
+
+    jint                     fDragKeyModifiers;
+    jint                     fDragMouseModifiers;
+}
+
++ (CDragSource *) currentDragSource;
+
+// Common methods:
+- (id)init:(jobject)jdragsourcecontextpeer component:(jobject)jcomponent peer:(jobject)jpeer control:(id)control
+    transferable:(jobject)jtransferable triggerEvent:(jobject)jtrigger
+    dragPosX:(jint)dragPosX dragPosY:(jint)dragPosY modifiers:(jint)extModifiers clickCount:(jint)clickCount timeStamp:(jlong)timeStamp
+    cursor:(jobject)jcursor
+    dragImage:(jlong)jnsdragimage dragImageOffsetX:(jint)jdragimageoffsetx dragImageOffsetY:(jint)jdragimageoffsety
+    sourceActions:(jint)jsourceactions formats:(jlongArray)jformats formatMap:(jobject)jformatmap;
+
+- (void)removeFromView:(JNIEnv *)env;
+
+- (void)drag;
+
+// dnd APIs (see AppKit/NSDragging.h, NSDraggingSource):
+- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag;
+- (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint;
+- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation;
+- (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint;
+- (BOOL)ignoreModifierKeysWhileDragging;
+
+// Updates from the destination to the source
+- (void) postDragEnter;
+- (void) postDragExit;
+
+// Utility
+- (NSPoint) mapNSScreenPointToJavaWithOffset:(NSPoint) point;
+
+@end
+
+#endif // CDragSource_h
diff --git a/jdk/src/macosx/native/sun/awt/CDragSource.m b/jdk/src/macosx/native/sun/awt/CDragSource.m
new file mode 100644
index 0000000..80aac26
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDragSource.m
@@ -0,0 +1,743 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define DND_DEBUG TRUE
+
+#import "java_awt_dnd_DnDConstants.h"
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "AWTEvent.h"
+#import "AWTView.h"
+#import "CDataTransferer.h"
+#import "CDropTarget.h"
+#import "CDragSource.h"
+#import "DnDUtilities.h"
+#import "ThreadUtilities.h"
+
+
+// When sIsJavaDragging is true Java drag gesture has been recognized and a drag is/has been initialized.
+// We must stop posting MouseEvent.MOUSE_DRAGGED events for the duration of the drag or all hell will break
+// loose in shared code - tracking state going haywire.
+static BOOL sIsJavaDragging;
+
+
+@interface NSEvent(AWTAdditions)
+
++ (void)javaDraggingBegin;
++ (void)javaDraggingEnd;
+
+@end
+
+
+@implementation NSEvent(AWTAdditions)
+
+
++ (void)javaDraggingBegin
+{
+    sIsJavaDragging = YES;
+}
+
++ (void)javaDraggingEnd
+{
+    // sIsJavaDragging is reset on mouseDown as well.
+    sIsJavaDragging = NO;
+}
+@end
+
+JNF_CLASS_CACHE(DataTransfererClass, "sun/awt/datatransfer/DataTransferer");
+JNF_CLASS_CACHE(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer");
+
+static NSDragOperation    sDragOperation;
+static NSPoint            sDraggingLocation;
+
+static CDragSource*        sCurrentDragSource;
+static BOOL                sNeedsEnter;
+
+@implementation CDragSource
+
++ (CDragSource *) currentDragSource {
+    return sCurrentDragSource;
+}
+
+- (id)init:(jobject)jdragsourcecontextpeer component:(jobject)jcomponent peer:(jobject)jpeer control:(id)control
+    transferable:(jobject)jtransferable triggerEvent:(jobject)jtrigger
+    dragPosX:(jint)dragPosX dragPosY:(jint)dragPosY modifiers:(jint)extModifiers clickCount:(jint)clickCount
+    timeStamp:(jlong)timeStamp cursor:(jobject)jcursor
+    dragImage:(jlong)jnsdragimage dragImageOffsetX:(jint)jdragimageoffsetx dragImageOffsetY:(jint)jdragimageoffsety
+    sourceActions:(jint)jsourceactions formats:(jlongArray)jformats formatMap:(jobject)jformatmap
+{
+    self = [super init];
+    DLog2(@"[CDragSource init]: %@\n", self);
+
+    fView = nil;
+    fComponent = nil;
+
+    // Construct the object if we have a valid model for it:
+    if (control != nil) {
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        fComponent = JNFNewGlobalRef(env, jcomponent);
+        fComponentPeer = JNFNewGlobalRef(env, jpeer);
+        fDragSourceContextPeer = JNFNewGlobalRef(env, jdragsourcecontextpeer);
+
+        fTransferable = JNFNewGlobalRef(env, jtransferable);
+        fTriggerEvent = JNFNewGlobalRef(env, jtrigger);
+        fCursor = JNFNewGlobalRef(env, jcursor);
+
+        fDragImage = (NSImage*) jlong_to_ptr(jnsdragimage); // Double-casting prevents compiler 'different size' warning.
+        [fDragImage retain];
+        fDragImageOffset = NSMakePoint(jdragimageoffsetx, jdragimageoffsety);
+
+        fSourceActions = jsourceactions;
+        fFormats = JNFNewGlobalRef(env, jformats);
+        fFormatMap = JNFNewGlobalRef(env, jformatmap);
+
+        fTriggerEventTimeStamp = timeStamp;
+        fDragPos = NSMakePoint(dragPosX, dragPosY);
+        fClickCount = clickCount;
+        fModifiers = extModifiers;
+
+        // Set this object as a dragging source:
+
+        AWTView *awtView = [((NSWindow *) control) contentView];
+        fView = [awtView retain];
+        [awtView setDragSource:self];
+
+        // Let AWTEvent know Java drag is getting underway:
+        [NSEvent javaDraggingBegin];
+    }
+
+    else {
+        [self release];
+        self = nil;
+    }
+
+    return self;
+}
+
+- (void)removeFromView:(JNIEnv *)env
+{
+    DLog2(@"[CDragSource removeFromView]: %@\n", self);
+
+    // Remove this dragging source from the view:
+    [((AWTView *) fView) setDragSource:nil];
+
+    // Clean up JNI refs
+    if (fComponent != NULL) {
+        JNFDeleteGlobalRef(env, fComponent);
+        fComponent = NULL;
+    }
+
+    if (fComponentPeer != NULL) {
+        JNFDeleteGlobalRef(env, fComponentPeer);
+        fComponentPeer = NULL;
+    }
+
+    if (fDragSourceContextPeer != NULL) {
+        JNFDeleteGlobalRef(env, fDragSourceContextPeer);
+        fDragSourceContextPeer = NULL;
+    }
+
+    if (fTransferable != NULL) {
+        JNFDeleteGlobalRef(env, fTransferable);
+        fTransferable = NULL;
+    }
+
+    if (fTriggerEvent != NULL) {
+        JNFDeleteGlobalRef(env, fTriggerEvent);
+        fTriggerEvent = NULL;
+    }
+
+    if (fCursor != NULL) {
+        JNFDeleteGlobalRef(env, fCursor);
+        fCursor = NULL;
+    }
+
+    if (fFormats != NULL) {
+        JNFDeleteGlobalRef(env, fFormats);
+        fFormats = NULL;
+    }
+
+    if (fFormatMap != NULL) {
+        JNFDeleteGlobalRef(env, fFormatMap);
+        fFormatMap = NULL;
+    }
+
+    CFRelease(self); // GC
+}
+
+- (void)dealloc
+{
+    DLog2(@"[CDragSource dealloc]: %@\n", self);
+
+    // Delete or release local data:
+    [fView release];
+    fView = nil;
+
+    [fDragImage release];
+    fDragImage = nil;
+
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+
+// Appropriated from Windows' awt_DataTransferer.cpp:
+//
+// * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value.
+//
+- (jobject)dataTransferer:(JNIEnv*)env
+{
+    JNF_STATIC_MEMBER_CACHE(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;");
+    return JNFCallStaticObjectMethod(env, getInstanceMethod);
+}
+
+// Appropriated from Windows' awt_DataTransferer.cpp:
+//
+// * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value.
+//
+- (jbyteArray)convertData:(jlong)format
+{
+    JNIEnv*    env = [ThreadUtilities getJNIEnv];
+    jobject    transferer = [self dataTransferer:env];
+    jbyteArray data = nil;
+
+    if (transferer != NULL) {
+        JNF_MEMBER_CACHE(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B");
+        data = JNFCallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE);
+    }
+
+    return data;
+}
+
+
+// Encodes a byte array of zero-terminated filenames into an NSArray of NSStrings representing them.
+// Borrowed and adapted from awt_DataTransferer.c, convertFileType().
+- (id)getFileList:(jbyte *)jbytes dataLength:(jsize)jbytesLength
+{
+    jsize  strings = 0;
+    jsize  i;
+
+    // Get number of filenames while making sure to skip over empty strings.
+    for (i = 1; i < jbytesLength; i++) {
+        if (jbytes[i] == '\0' && jbytes[i - 1] != '\0')
+            strings++;
+    }
+
+    // Create the file list to return:
+    NSMutableArray* fileList = [NSMutableArray arrayWithCapacity:strings];
+
+    for (i = 0; i < jbytesLength; i++) {
+        char* start = (char *) &jbytes[i];
+
+        // Skip over empty strings:
+        if (start[0] == '\0') {
+            continue;
+        }
+
+        // Update the position marker:
+        i += strlen(start);
+
+        // Add this filename to the file list:
+        NSMutableString* fileName = [NSMutableString stringWithUTF8String:start];
+        // Decompose the filename
+        CFStringNormalize((CFMutableStringRef)fileName, kCFStringNormalizationFormD);
+        [fileList addObject:fileName];
+    }
+
+    // 03-01-09 Note: keep this around for debugging.
+    // return [NSArray arrayWithObjects:@"/tmp/foo1", @"/tmp/foo2", nil];
+
+    return ([fileList count] > 0 ? fileList : nil);
+}
+
+
+// Set up the pasteboard for dragging:
+- (BOOL)declareTypesToPasteboard:(NSPasteboard *)pb withEnv:(JNIEnv *) env {
+    // 9-20-02 Note: leave this here for debugging:
+    //[pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: self];
+    //return TRUE;
+
+    // Get byte array elements:
+    jboolean isCopy;
+    jlong* jformats = (*env)->GetLongArrayElements(env, fFormats, &isCopy);
+    if (jformats == nil)
+        return FALSE;
+
+    // Allocate storage arrays for dragging types to register with the pasteboard:
+    jsize formatsLength = (*env)->GetArrayLength(env, fFormats);
+    NSMutableArray* pbTypes = [[NSMutableArray alloc] initWithCapacity:formatsLength];
+
+    // And assume there are no NS-type data: [Radar 3065621]
+    // This is to be able to drop transferables containing only a serialized object flavor, e.g.:
+    //   "JAVA_DATAFLAVOR:application/x-java-serialized-object; class=java.awt.Label".
+    BOOL hasNSTypeData = false;
+
+    // Collect all supported types in a pasteboard format into the storage arrays:
+    jsize i;
+    for (i = 0; i < formatsLength; i++) {
+        jlong jformat = jformats[i];
+
+        if (jformat >= 0) {
+            NSString* type = formatForIndex(jformat);
+
+            // Add element type to the storage array.
+            if (type != nil) {
+                if ([type hasPrefix:@"JAVA_DATAFLAVOR:application/x-java-jvm-local-objectref;"] == false) {
+                    [pbTypes addObject:type];
+
+                    // This is a good approximation if not perfect. A conclusive search would
+                    // have to be done matching all defined strings in AppKit's commonStrings.h.
+                    if ([type hasPrefix:@"NS"] || [type hasPrefix:@"NeXT"])
+                        hasNSTypeData = true;
+                }
+            }
+        }
+    }
+
+    // 1-16-03 Note: [Radar 3065621]
+    // When TransferHandler is used with Swing components it puts only a type like this on the pasteboard:
+    //   "JAVA_DATAFLAVOR:application/x-java-jvm-local-objectref; class=java.lang.String"
+    // And there's similar type for serialized object only transferables.
+    // Since our drop targets aren't trained for arbitrary data types yet we need to fake an empty string
+    // which will cause drop target handlers to fire.
+    // KCH  - 3550405 If the drag is between Swing components, formatsLength == 0, so expand the check.
+    // Also, use a custom format rather than NSString, since that will prevent random views from accepting the drag
+    if (hasNSTypeData == false && formatsLength >= 0) {
+        [pbTypes addObject:[DnDUtilities javaPboardType]];
+    }
+
+    (*env)->ReleaseLongArrayElements(env, fFormats, jformats, JNI_ABORT);
+
+    // Declare pasteboard types. If the types array is empty we still want to declare them
+    // as otherwise an old set of types/data would remain on the pasteboard.
+    NSUInteger typesCount = [pbTypes count];
+    [pb declareTypes:pbTypes owner: self];
+
+    // KCH - Lame conversion bug between Cocoa and Carbon drag types
+    // If I provide the filenames _right now_, NSFilenamesPboardType is properly converted to CoreDrag flavors
+    // If I try to wait until pasteboard:provideDataForType:, the conversion won't happen
+    // and pasteboard:provideDataForType: won't even get called! (unless I go over a Cocoa app)
+    if ([pbTypes containsObject:NSFilenamesPboardType]) {
+        [self pasteboard:pb provideDataForType:NSFilenamesPboardType];
+    }
+
+    [pbTypes release];
+
+    return typesCount > 0 ? TRUE : FALSE;
+}
+
+// This is an NSPasteboard callback. In declareTypesToPasteboard:withEnv:, we only declared the types
+// When the AppKit DnD system actually needs the data, this method will be invoked.
+// Note that if the transfer is handled entirely from Swing (as in a local-vm drag), this method may never be called.
+- (void)pasteboard:(NSPasteboard *)pb provideDataForType:(NSString *)type {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    // 9-20-02 Note: leave this here for debugging:
+    //[pb setString: @"Hello, World!" forType: NSStringPboardType];
+    // return;
+
+    // Set up Java environment:
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    id pbData = nil;
+
+    // Collect data in a pasteboard format:
+    jlong jformat = indexForFormat(type);
+    if (jformat >= 0) {
+        // Convert DataTransfer data to a Java byte array:
+        // Note that this will eventually call getTransferData()
+        jbyteArray jdata = [self convertData:jformat];
+
+        if (jdata != nil) {
+            jboolean isCopy;
+            jsize jdataLength = (*env)->GetArrayLength(env, jdata);
+            jbyte* jbytedata = (*env)->GetByteArrayElements(env, jdata, &isCopy);
+
+            if (jdataLength > 0 && jbytedata != nil) {
+                // Get element data to the storage array. For NSFilenamesPboardType type we use
+                // an NSArray-type data - NSData-type data would cause a crash.
+                if (type != nil) {
+                    pbData = ([type isEqualTo:NSFilenamesPboardType]) ?
+                        [self getFileList:jbytedata dataLength:jdataLength] :
+                        [NSData dataWithBytes:jbytedata length:jdataLength];
+                }
+            }
+
+            (*env)->ReleaseByteArrayElements(env, jdata, jbytedata, JNI_ABORT);
+
+            (*env)->DeleteLocalRef(env, jdata);
+        }
+    }
+
+    // If we are the custom type that matches local-vm drags, set an empty NSData
+    if ( (pbData == nil) && ([type isEqualTo:[DnDUtilities javaPboardType]]) ) {
+        pbData = [NSData dataWithBytes:"" length:1];
+    }
+
+    // Add pasteboard data for the type:
+    // Remember, NSFilenamesPboardType's data is NSArray (property list), not NSData!
+    // We must use proper pb accessor depending on the data type.
+    if ([pbData isKindOfClass:[NSArray class]])
+        [pb setPropertyList:pbData forType:type];
+    else
+        [pb setData:pbData forType:type];
+}
+
+
+- (void)validateDragImage
+{
+    // Make a small blank image if we don't have a drag image:
+    if (fDragImage == nil) {
+        // 9-30-02 Note: keep this around for debugging:
+        fDragImage = [[NSImage alloc] initWithSize:NSMakeSize(21, 21)];
+        NSSize imageSize = [fDragImage size];
+
+        NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
+            pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:4
+            hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:32];
+
+        [fDragImage addRepresentation:imageRep];
+        fDragImageOffset = NSMakePoint(0, 0);
+
+        [imageRep release];
+    }
+}
+
+- (NSEvent*)nsDragEvent:(BOOL)isDrag
+{
+    // Get NSView for the drag source:
+    NSWindow* window = [fView window];
+
+    NSInteger windowNumber = [window windowNumber];
+    NSGraphicsContext* graphicsContext = [NSGraphicsContext graphicsContextWithWindow:window];
+
+    // Convert mouse coordinates to NS:
+    NSPoint location = NSMakePoint(fDragPos.x, fDragPos.y);
+    NSPoint eventLocation = [fView convertPoint:location toView:nil];
+
+    // Convert fTriggerEventTimeStamp to NS - AWTEvent.h defines UTC(nsEvent) as ((jlong)[event timestamp] * 1000):
+    NSTimeInterval timeStamp = fTriggerEventTimeStamp / 1000;
+
+    // Convert fModifiers (extModifiers) to NS:
+    NSEventType mouseButtons = 0;
+    float pressure = 0.0;
+    if (isDrag) {
+        mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseDownButtons:fModifiers];
+        pressure = 1.0;
+    } else {
+        mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseUpButtons:fModifiers];
+    }
+
+    // Convert fModifiers (extModifiers) to NS:
+    NSUInteger modifiers = [DnDUtilities mapJavaExtModifiersToNSKeyModifiers:fModifiers];
+
+    // Just a dummy value ...
+    NSInteger eventNumber = 0;
+
+    // Make a native autoreleased dragging event:
+    NSEvent* dragEvent = [NSEvent mouseEventWithType:mouseButtons location:eventLocation
+        modifierFlags:modifiers timestamp:timeStamp windowNumber:windowNumber context:graphicsContext
+        eventNumber:eventNumber clickCount:fClickCount pressure:pressure];
+
+    return dragEvent;
+}
+
+- (void)doDrag
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    DLog2(@"[CDragSource doDrag]: %@\n", self);
+
+    // Set up Java environment:
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    // Set up the pasteboard:
+    NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSDragPboard];
+    [self declareTypesToPasteboard:pb withEnv:env];
+
+    // Make a native autoreleased NS dragging event:
+    NSEvent *dragEvent = [self nsDragEvent:YES];
+
+    // Get NSView for the drag source:
+    NSView *view = fView;
+
+    // Make sure we have a valid drag image:
+    [self validateDragImage];
+    NSImage* dragImage = fDragImage;
+
+    // Get drag origin and offset:
+    NSPoint dragOrigin;
+    dragOrigin.x = fDragPos.x;
+    dragOrigin.y = fDragPos.y;
+    dragOrigin = [view convertPoint:[dragEvent locationInWindow] fromView:nil];
+    dragOrigin.x += fDragImageOffset.x;
+    dragOrigin.y += [dragImage size].height + fDragImageOffset.y;
+
+    // Drag offset values don't seem to matter:
+    NSSize dragOffset = NSMakeSize(0, 0);
+
+    // These variables should be set based on the transferable:
+    BOOL isFileDrag = FALSE;
+    BOOL fileDragPromises = FALSE;
+
+    DLog(@"[CDragSource drag]: calling dragImage/File:");
+    DLog3(@"  - drag origin: %f, %f", fDragPos.x, fDragPos.y);
+    DLog5(@"  - drag image: %f, %f (%f x %f)", fDragImageOffset.x, fDragImageOffset.y, [dragImage size].width, [dragImage size].height);
+    DLog3(@"  - event point (window) %f, %f", [dragEvent locationInWindow].x, [dragEvent locationInWindow].y);
+    DLog3(@"  - drag point (view) %f, %f", dragOrigin.x, dragOrigin.y);
+
+    // Set up the fDragKeyModifier, so we know if the operation has changed
+    // Set up the fDragMouseModifier, so we can |= it later (since CoreDrag doesn't tell us mouse states during a drag)
+    fDragKeyModifiers = [DnDUtilities extractJavaExtKeyModifiersFromJavaExtModifiers:fModifiers];
+    fDragMouseModifiers = [DnDUtilities extractJavaExtMouseModifiersFromJavaExtModifiers:fModifiers];
+
+    // Set the current DragSource
+    sCurrentDragSource = self;
+    sNeedsEnter = YES;
+
+    @try {
+        // Data dragging:
+        if (isFileDrag == FALSE) {
+            [view dragImage:dragImage at:dragOrigin offset:dragOffset event:dragEvent pasteboard:pb source:view slideBack:YES];
+        } else if (fileDragPromises == FALSE) {
+            // File dragging:
+            NSLog(@"[CDragSource drag]: file dragging is unsupported.");
+            NSString* fileName = nil;                                // This should be set based on the transferable.
+            NSRect    fileLocationRect = NSMakeRect(0, 0, 0, 0);    // This should be set based on the filename.
+
+            BOOL success = [view dragFile:fileName fromRect:fileLocationRect slideBack:YES event:dragEvent];
+            if (success == TRUE) {                                    // One would erase dragged file if this was a move operation.
+            }
+        } else {
+            // Promised file dragging:
+            NSLog(@"[CDragSource drag]: file dragging promises are unsupported.");
+            NSArray* fileTypesArray = nil;                            // This should be set based on the transferable.
+            NSRect   fileLocationRect = NSMakeRect(0, 0, 0, 0);        // This should be set based on all filenames.
+
+            BOOL success = [view dragPromisedFilesOfTypes:fileTypesArray fromRect:fileLocationRect source:view slideBack:YES event:dragEvent];
+            if (success == TRUE) {                                    // One would write out the promised files here.
+            }
+        }
+
+        NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation];
+
+        // Convert drag operation to Java:
+        jint dragOp = [DnDUtilities mapNSDragOperationToJava:sDragOperation];
+
+        // Drag success must acount for DragOperationNone:
+        jboolean success = (dragOp != java_awt_dnd_DnDConstants_ACTION_NONE);
+
+        // We have a problem here... we don't send DragSource dragEnter/Exit messages outside of our own process
+        // because we don't get anything from AppKit/CoreDrag
+        // This means that if you drag outside of the app and drop, even if it's valid, a dragDropFinished is posted without dragEnter
+        // I'm worried that this might confuse Java, so we're going to send a "bogus" dragEnter if necessary (only if the drag succeeded)
+        if (success && sNeedsEnter) {
+            [self postDragEnter];
+        }
+
+        // DragSourceContextPeer.dragDropFinished() should be called even if there was an error:
+        JNF_MEMBER_CACHE(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V");
+        DLog3(@"  -> posting dragDropFinished, point %f, %f", point.x, point.y);
+        JNFCallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
+		JNF_MEMBER_CACHE(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V");
+        JNFCallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable
+    } @finally {
+        // Clear the current DragSource
+        sCurrentDragSource = nil;
+        sNeedsEnter = NO;
+    }
+
+    // We have to do this, otherwise AppKit doesn't know we're finished dragging. Yup, it's that bad.
+    if ([[[NSRunLoop currentRunLoop] currentMode] isEqualTo:NSEventTrackingRunLoopMode]) {
+        [NSApp postEvent:[self nsDragEvent:NO] atStart:YES];
+    }
+
+    DLog2(@"[CDragSource doDrag] end: %@\n", self);
+}
+
+- (void)drag
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    // Set the drag cursor (or not 3839999)
+    //JNIEnv *env = [ThreadUtilities getJNIEnv];
+    //jobject gCursor = JNFNewGlobalRef(env, fCursor);
+    //[EventFactory setJavaCursor:gCursor withEnv:env];
+
+    [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; // AWT_THREADING Safe (called from unique asynchronous thread)
+}
+
+/********************************  BEGIN NSDraggingSource Interface  ********************************/
+
+- (void)draggingOperationChanged:(NSDragOperation)dragOp {
+    //DLog2(@"[CDragSource draggingOperationChanged]: %@\n", self);
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    jint targetActions = fSourceActions;
+    if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions];
+
+    NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation];
+    DLog3(@"  -> posting operationChanged, point %f, %f", point.x, point.y);
+    jint modifiedModifiers = fDragKeyModifiers | fDragMouseModifiers | [DnDUtilities javaKeyModifiersForNSDragOperation:dragOp];
+
+    JNF_MEMBER_CACHE(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V");
+    JNFCallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
+}
+
+- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)localDrag {
+    //DLog2(@"[CDragSource draggingSourceOperationMaskForLocal]: %@\n", self);
+    return [DnDUtilities mapJavaDragOperationToNS:fSourceActions];
+}
+
+/* 9-16-02 Note: we don't support promises yet.
+- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination {
+}*/
+
+- (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint {
+    DLog4(@"[CDragSource draggedImage beganAt]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);
+
+    // Initialize static variables:
+    sDragOperation = NSDragOperationNone;
+    sDraggingLocation = screenPoint;
+}
+
+- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation {
+    DLog4(@"[CDragSource draggedImage endedAt:]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);
+
+    sDraggingLocation = screenPoint;
+    sDragOperation = operation;
+}
+
+- (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint {
+    //DLog4(@"[CDragSource draggedImage moved]: (%d, %d) %@\n", (int) screenPoint.x, (int) screenPoint.y, self);
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+JNF_COCOA_ENTER(env);
+    // There are two things we would be interested in:
+    // a) mouse pointer has moved
+    // b) drag actions (key modifiers) have changed
+
+    BOOL notifyJava = FALSE;
+
+    // a) mouse pointer has moved:
+    if (NSEqualPoints(screenPoint, sDraggingLocation) == FALSE) {
+        //DLog2(@"[CDragSource draggedImage:movedTo]: mouse moved, %@\n", self);
+        notifyJava = TRUE;
+    }
+
+    // b) drag actions (key modifiers) have changed:
+    jint modifiers = [DnDUtilities currentJavaExtKeyModifiers];
+    if (fDragKeyModifiers != modifiers) {
+        NSDragOperation currentOp = [DnDUtilities nsDragOperationForModifiers:[NSEvent modifierFlags]];
+        NSDragOperation allowedOp = [DnDUtilities mapJavaDragOperationToNS:fSourceActions] & currentOp;
+
+        fDragKeyModifiers = modifiers;
+
+        if (sDragOperation != allowedOp) {
+            sDragOperation = allowedOp;
+            [self draggingOperationChanged:allowedOp];
+        }
+    }
+
+    // Should we notify Java things have changed?
+    if (notifyJava) {
+        sDraggingLocation = screenPoint;
+
+        NSPoint point = [self mapNSScreenPointToJavaWithOffset:screenPoint];
+
+        jint targetActions = fSourceActions;
+        if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions];
+
+        // Motion: dragMotion, dragMouseMoved
+        DLog4(@"[CDragSource draggedImage moved]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);
+
+        DLog3(@"  -> posting dragMotion, point %f, %f", point.x, point.y);
+        JNF_MEMBER_CACHE(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V");
+        JNFCallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
+
+        DLog3(@"  -> posting dragMouseMoved, point %f, %f", point.x, point.y);
+        JNF_MEMBER_CACHE(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V");
+        JNFCallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
+    }
+JNF_COCOA_EXIT(env);
+}
+
+- (BOOL)ignoreModifierKeysWhileDragging {
+    //DLog2(@"[CDragSource ignoreModifierKeysWhileDragging]: %@\n", self);
+    return NO;
+}
+
+/********************************  END NSDraggingSource Interface  ********************************/
+
+
+// postDragEnter and postDragExit are called from CDropTarget when possible and appropriate
+// Currently only possible if source and target are in the same process
+- (void) postDragEnter {
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    sNeedsEnter = NO;
+
+    jint targetActions = fSourceActions;
+    if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions];
+
+    NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation];
+    DLog3(@"  -> posting dragEnter, point %f, %f", point.x, point.y);
+    JNF_MEMBER_CACHE(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V");
+    JNFCallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
+}
+
+- (void) postDragExit {
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    sNeedsEnter = YES;
+
+    NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation];
+    DLog3(@"  -> posting dragExit, point %f, %f", point.x, point.y);
+    JNF_MEMBER_CACHE(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V");
+    JNFCallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
+}
+
+
+// Java assumes that the origin is the top-left corner of the screen.
+// Cocoa assumes that the origin is the bottom-left corner of the screen.
+// Adjust the y coordinate to account for this.
+// NOTE: Also need to take into account the 0 screen relative screen coords.
+//  This is because all screen coords in Cocoa are relative to the 0 screen.
+// Also see +[CWindow convertAWTToCocoaScreenRect]
+// NSScreen-to-JavaScreen mapping:
+- (NSPoint) mapNSScreenPointToJavaWithOffset:(NSPoint)screenPoint {
+    NSRect mainR = [[[NSScreen screens] objectAtIndex:0] frame];
+    NSPoint point = NSMakePoint(screenPoint.x, mainR.size.height - (screenPoint.y));
+
+    // Adjust the point with the drag image offset to get the real mouse hotspot:
+    // The point should remain in screen coordinates (as per DragSourceEvent.getLocation() documentation)
+    point.x -= fDragImageOffset.x;
+    point.y -= ([fDragImage size].height + fDragImageOffset.y);
+
+    return point;
+}
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CDragSourceContextPeer.m b/jdk/src/macosx/native/sun/awt/CDragSourceContextPeer.m
new file mode 100644
index 0000000..80d296d
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDragSourceContextPeer.m
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "sun_lwawt_macosx_CDragSourceContextPeer.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CDragSource.h"
+#import "ThreadUtilities.h"
+
+
+/*
+ * Class:     sun_lwawt_macosx_CDragSourceContextPeer
+ * Method:    createNativeDragSource
+ * Signature: (Ljava/awt/Component;Ljava/awt/peer/ComponentPeer;JLjava/awt/datatransfer/Transferable;Ljava/awt/event/InputEvent;IIIIJLjava/awt/Cursor;IJIII[JLjava/util/Map;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_createNativeDragSource
+  (JNIEnv *env, jobject jthis, jobject jcomponent, jobject jpeer, jlong jnativepeer, jobject jtransferable,
+   jobject jtrigger, jint jdragposx, jint jdragposy, jint jextmodifiers, jint jclickcount, jlong jtimestamp,
+   jobject jcursor, jlong jnsdragimage, jint jdragimageoffsetx, jint jdragimageoffsety,
+   jint jsourceactions, jlongArray jformats, jobject jformatmap)
+{
+    id controlObj = (id) jlong_to_ptr(jnativepeer);
+    __block CDragSource* dragSource = nil;
+
+JNF_COCOA_ENTER(env);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        dragSource = [[CDragSource alloc] init:jthis component:jcomponent peer:jpeer control:controlObj
+            transferable:jtransferable triggerEvent:jtrigger dragPosX:jdragposx
+            dragPosY:jdragposy modifiers:jextmodifiers clickCount:jclickcount timeStamp:jtimestamp
+            cursor:jcursor dragImage:jnsdragimage dragImageOffsetX:jdragimageoffsetx
+            dragImageOffsetY:jdragimageoffsety sourceActions:jsourceactions
+            formats:jformats formatMap:jformatmap];
+    }];
+JNF_COCOA_EXIT(env);
+
+    if (dragSource) {
+        CFRetain(dragSource); // GC
+        [dragSource release];
+    }
+    return ptr_to_jlong(dragSource);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDragSourceContextPeer
+ * Method:    doDragging
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_doDragging
+  (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal);
+
+JNF_COCOA_ENTER(env);
+    [dragSource drag];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDragSourceContextPeer
+ * Method:    releaseNativeDragSource
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_releaseNativeDragSource
+  (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal)
+{
+      CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal);
+
+JNF_COCOA_ENTER(env);
+    [dragSource removeFromView:env];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDragSourceContextPeer
+ * Method:    setNativeCursor
+ * Signature: (JLjava/awt/Cursor;I)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_setNativeCursor
+  (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal, jobject jcursor, jint jcursortype)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+//JNF_COCOA_ENTER(env);
+//    jobject gCursor = JNFNewGlobalRef(env, jcursor);
+//    [EventFactory setJavaCursor:gCursor withEnv:env];
+//JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CDropTarget.h b/jdk/src/macosx/native/sun/awt/CDropTarget.h
new file mode 100644
index 0000000..33e0946
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDropTarget.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef CDropTarget_h
+#define CDropTarget_h
+
+#import <AppKit/AppKit.h>
+#import <jni.h>
+
+@class ControlModel;
+
+@interface CDropTarget : NSObject {
+@private
+    NSView*        fView;
+    jobject            fComponent;
+    jobject            fDropTarget;
+    jobject            fDropTargetContextPeer;
+}
+
++ (CDropTarget *) currentDropTarget;
+
+// Common methods:
+- (id)init:(jobject)dropTarget component:(jobject)jcomponent peer:(jobject)jpeer control:(id)control;
+- (void)controlModelControlValid;
+- (void)removeFromView:(JNIEnv *)env;
+
+- (NSInteger)getDraggingSequenceNumber;
+- (jobject)copyDraggingDataForFormat:(jlong)format;
+- (void)javaDraggingEnded:(jlong)draggingSequenceNumber success:(BOOL)jsuccess action:(jint)jdropaction;
+
+// dnd APIs (see AppKit/NSDragging.h, NSDraggingDestination):
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
+- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
+- (void)draggingExited:(id <NSDraggingInfo>)sender;
+- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender;
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
+- (void)concludeDragOperation:(id <NSDraggingInfo>)sender;
+- (void)draggingEnded:(id <NSDraggingInfo>)sender;
+
+- (jint)currentJavaActions;
+
+@end
+
+#endif // CDropTarget_h
diff --git a/jdk/src/macosx/native/sun/awt/CDropTarget.m b/jdk/src/macosx/native/sun/awt/CDropTarget.m
new file mode 100644
index 0000000..b05e36f
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDropTarget.m
@@ -0,0 +1,742 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define DND_DEBUG TRUE
+
+#import "CDropTarget.h"
+#import "AWTView.h"
+
+#import "sun_lwawt_macosx_CDropTarget.h"
+#import "java_awt_dnd_DnDConstants.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+#include <objc/objc-runtime.h>
+
+
+#import "CDragSource.h"
+#import "CDataTransferer.h"
+#import "DnDUtilities.h"
+#import "ThreadUtilities.h"
+
+
+static NSInteger        sDraggingSequenceNumber = -1;
+static NSDragOperation    sDragOperation;
+static NSDragOperation    sUpdateOperation;
+static jint                sJavaDropOperation;
+static NSPoint            sDraggingLocation;
+static BOOL                sDraggingExited;
+static BOOL                sDraggingError;
+
+static NSUInteger        sPasteboardItemsCount = 0;
+static NSArray*            sPasteboardTypes = nil;
+static NSArray*            sPasteboardData = nil;
+static jlongArray        sDraggingFormats = nil;
+
+static CDropTarget*        sCurrentDropTarget;
+
+extern JNFClassInfo jc_CDropTargetContextPeer;
+
+@implementation CDropTarget
+
++ (CDropTarget *) currentDropTarget {
+    return sCurrentDropTarget;
+}
+
+- (id)init:(jobject)jdropTarget component:(jobject)jcomponent peer:(jobject)jpeer control:(id)control
+{
+    self = [super init];
+    DLog2(@"[CDropTarget init]: %@\n", self);
+
+    fView = nil;
+    fComponent = nil;
+    fDropTarget = nil;
+    fDropTargetContextPeer = nil;
+
+
+    if (control != nil) {
+        JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+        fComponent = JNFNewGlobalRef(env, jcomponent);
+        fDropTarget = JNFNewGlobalRef(env, jdropTarget);
+
+        AWTView *awtView = [((NSWindow *) control) contentView];
+        fView = [awtView retain];
+        [awtView setDropTarget:self];
+
+
+    } else {
+        // This would be an error.
+        [self release];
+        self = nil;
+    }
+    return self;
+}
+
+// When [CDropTarget init] is called the ControlModel's fView may not have been set up yet. ControlModel
+// (soon after) calls [CDropTarget controlModelControlValid] on the native event thread, once per CDropTarget,
+// to let it know it's been set up now.
+- (void)controlModelControlValid
+{
+    // 9-30-02 Note: [Radar 3065621]
+    // List all known pasteboard types here (see AppKit's NSPasteboard.h)
+    // How to register for non-standard data types remains to be determined.
+    NSArray* dataTypes = [[NSArray alloc] initWithObjects:
+        NSStringPboardType,
+        NSFilenamesPboardType,
+        NSPostScriptPboardType,
+        NSTIFFPboardType,
+        NSRTFPboardType,
+        NSTabularTextPboardType,
+        NSFontPboardType,
+        NSRulerPboardType,
+        NSFileContentsPboardType,
+        NSColorPboardType,
+        NSRTFDPboardType,
+        NSHTMLPboardType,
+        NSURLPboardType,
+        NSPDFPboardType,
+        NSVCardPboardType,
+        NSFilesPromisePboardType,
+        [DnDUtilities javaPboardType],
+        nil];
+
+    // Enable dragging events over this object:
+    [fView registerForDraggedTypes:dataTypes];
+
+    [dataTypes release];
+}
+
+- (void)releaseDraggingData
+{
+    DLog2(@"[CDropTarget releaseDraggingData]: %@\n", self);
+
+    // Release any old pasteboard types, data and properties:
+    [sPasteboardTypes release];
+    sPasteboardTypes = nil;
+
+    [sPasteboardData release];
+    sPasteboardData = nil;
+
+    if (sDraggingFormats != NULL) {
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        JNFDeleteGlobalRef(env, sDraggingFormats);
+        sDraggingFormats = NULL;
+    }
+
+    sPasteboardItemsCount = 0;
+    sDraggingSequenceNumber = -1;
+}
+
+- (void)removeFromView:(JNIEnv *)env
+{
+    DLog2(@"[CDropTarget removeFromView]: %@\n", self);
+
+    // Remove this dragging destination from the view:
+    [((AWTView *) fView) setDropTarget:nil];
+
+    // Clean up JNI refs
+    if (fComponent != NULL) {
+        JNFDeleteGlobalRef(env, fComponent);
+        fComponent = NULL;
+    }
+    if (fDropTarget != NULL) {
+        JNFDeleteGlobalRef(env, fDropTarget);
+        fDropTarget = NULL;
+    }
+    if (fDropTargetContextPeer != NULL) {
+        JNFDeleteGlobalRef(env, fDropTargetContextPeer);
+        fDropTargetContextPeer = NULL;
+    }
+
+    CFRelease(self);
+}
+
+- (void)dealloc
+{
+    DLog2(@"[CDropTarget dealloc]: %@\n", self);
+
+    [fView release];
+    fView = nil;
+
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+- (NSInteger) getDraggingSequenceNumber
+{
+    return sDraggingSequenceNumber;
+}
+
+// Debugging help:
+- (void)dumpPasteboard:(NSPasteboard*)pasteboard
+{
+    NSArray* pasteboardTypes = [pasteboard types];
+    NSUInteger pasteboardItemsCount = [pasteboardTypes count];
+    NSUInteger i;
+
+    // For each flavor on the pasteboard show the type, its data, and its property if there is one:
+    for (i = 0; i < pasteboardItemsCount; i++) {
+        NSString* pbType = [pasteboardTypes objectAtIndex:i];
+        CFShow(pbType);
+
+        NSData*    pbData = [pasteboard dataForType:pbType];
+        CFShow(pbData);
+
+        if ([pbType hasPrefix:@"CorePasteboardFlavorType"] == NO) {
+            id pbDataProperty = [pasteboard propertyListForType:pbType];
+            CFShow(pbDataProperty);
+        }
+    }
+}
+
+- (BOOL)copyDraggingTypes:(id<NSDraggingInfo>)sender
+{
+    DLog2(@"[CDropTarget copyDraggingTypes]: %@\n", self);
+    JNIEnv*    env = [ThreadUtilities getJNIEnv];
+
+    // Release any old pasteboard data:
+    [self releaseDraggingData];
+
+    NSPasteboard* pb = [sender draggingPasteboard];
+    sPasteboardTypes = [[pb types] retain];
+    sPasteboardItemsCount = [sPasteboardTypes count];
+    if (sPasteboardItemsCount == 0)
+        return FALSE;
+
+    jlongArray formats = (*env)->NewLongArray(env, sPasteboardItemsCount);
+    if (formats == nil)
+        return FALSE;
+
+    sDraggingFormats = (jlongArray) JNFNewGlobalRef(env, formats);
+    (*env)->DeleteLocalRef(env, formats);
+    if (sDraggingFormats == nil)
+        return FALSE;
+
+    jboolean isCopy;
+    jlong* jformats = (*env)->GetLongArrayElements(env, sDraggingFormats, &isCopy);
+    if (jformats == nil) {
+        return FALSE;
+    }
+
+    // Copy all data formats and properties. In case of properties, if they are nil, we need to use
+    // a special NilProperty since [NSArray addObject] would crash on adding a nil object.
+    DLog2(@"[CDropTarget copyDraggingTypes]: typesCount = %lu\n", (unsigned long) sPasteboardItemsCount);
+    NSUInteger i;
+    for (i = 0; i < sPasteboardItemsCount; i++) {
+        NSString* pbType = [sPasteboardTypes objectAtIndex:i];
+        DLog3(@"[CDropTarget copyDraggingTypes]: type[%lu] = %@\n", (unsigned long) i, pbType);
+
+        // 01-10-03 Note: until we need data properties for doing something useful don't copy them.
+        // They're often copies of their flavor's data and copying them for all available pasteboard flavors
+        // (which are often auto-translation of one another) can be a significant time/space hit.
+
+        // If this is a remote object type (not a pre-defined format) register it with the pasteboard:
+        jformats[i] = indexForFormat(pbType);
+        if (jformats[i] == -1 && [pbType hasPrefix:@"JAVA_DATAFLAVOR:application/x-java-remote-object;"])
+            jformats[i] = registerFormatWithPasteboard(pbType);
+    }
+
+    (*env)->ReleaseLongArrayElements(env, sDraggingFormats, jformats, JNI_COMMIT);
+
+    return TRUE;
+}
+
+- (BOOL)copyDraggingData:(id<NSDraggingInfo>)sender
+{
+    DLog2(@"[CDropTarget copyDraggingData]: %@\n", self);
+
+    sPasteboardData = [[NSMutableArray alloc] init];
+    if (sPasteboardData == nil)
+        return FALSE;
+
+    // Copy all data items to a safe place since the pasteboard may go away before we'll need them:
+    NSPasteboard* pb = [sender draggingPasteboard];
+    NSUInteger i;
+    for (i = 0; i < sPasteboardItemsCount; i++) {
+        // Get a type and its data and save the data:
+        NSString* pbType = [sPasteboardTypes objectAtIndex:i];
+        // 01-10-03 Note: copying only NS-type data (until Java-specified types can make it through the AppKit)
+        // would be a good idea since we can't do anything with those CoreFoundation unknown types anyway.
+        // But I'm worried that it would break something in Fuller so I'm leaving this here as a reminder,
+        // to be evaluated later.
+        //id pbData = [pbType hasPrefix:@"NS"] ? [pb dataForType:pbType] : nil; // Copy only NS-type data!
+        id pbData = [pb dataForType:pbType];
+
+        // If the data is null we can't store it in the array - an exception would be thrown.
+        // We use the special object NSNull instead which is kosher.
+        if (pbData == nil)
+            pbData = [NSNull null];
+
+        [((NSMutableArray*) sPasteboardData) addObject:pbData];
+    }
+
+    return TRUE;
+}
+
+- (NSData*) getDraggingDataForURL:(NSData*)data
+{
+    NSData* result = nil;
+
+    // Convert data into a property list if possible:
+    NSPropertyListFormat propertyListFormat;
+    NSString* errorString = nil;
+    id propertyList = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable
+        format:&propertyListFormat errorDescription:&errorString];
+
+    // URL types have only a single URL string in an array:
+    if (propertyList != nil && errorString == nil && [propertyList isKindOfClass:[NSArray class]]) {
+        NSArray*  array = (NSArray*) propertyList;
+        if ([array count] > 0) {
+            NSString* url = (NSString*) [array objectAtIndex:0];
+            if (url != nil && [url length] > 0)
+                result = [url dataUsingEncoding:[url fastestEncoding]];
+        }
+    }
+
+    return result;
+}
+
+- (jobject) copyDraggingDataForFormat:(jlong)format
+{
+    JNIEnv*      env = [ThreadUtilities getJNIEnvUncached]; // Join the main thread by requesting uncached environment
+
+    NSData*      data = nil;
+
+    // Convert the Java format (datatransferer int index) to a pasteboard format (NSString):
+    NSString* pbType = formatForIndex(format);
+    if ([sPasteboardTypes containsObject:pbType]) {
+        NSUInteger dataIndex = [sPasteboardTypes indexOfObject:pbType];
+        data = [sPasteboardData objectAtIndex:dataIndex];
+
+        if ((id) data == [NSNull null])
+            data = nil;
+
+        // format == 8 (CF_URL in CDataTransferer): we need a URL-to-String conversion:
+        else if ([pbType isEqualToString:@"Apple URL pasteboard type"])
+            data = [self getDraggingDataForURL:data];
+    }
+
+    // Get NS data:
+    char* dataBytes = (data != nil) ? (char*) [data bytes] : "Unsupported type";
+    NSUInteger dataLength = (data != nil) ? [data length] : sizeof("Unsupported type");
+
+    // Create a global byte array:
+    jbyteArray lbyteArray = (*env)->NewByteArray(env, dataLength);
+    if (lbyteArray == nil)
+        return nil;
+    jbyteArray gbyteArray = (jbyteArray) JNFNewGlobalRef(env, lbyteArray);
+    (*env)->DeleteLocalRef(env, lbyteArray);
+    if (gbyteArray == nil)
+        return nil;
+
+    // Get byte array elements:
+    jboolean isCopy;
+    jbyte* jbytes = (*env)->GetByteArrayElements(env, gbyteArray, &isCopy);
+    if (jbytes == nil)
+        return nil;
+
+    // Copy data to byte array and release elements:
+    memcpy(jbytes, dataBytes, dataLength);
+    (*env)->ReleaseByteArrayElements(env, gbyteArray, jbytes, JNI_COMMIT);
+
+    // In case of an error make sure to return nil:
+    if ((*env)->ExceptionOccurred(env)) {
+		(*env)->ExceptionDescribe(env);
+        gbyteArray = nil;
+	}
+
+    return gbyteArray;
+}
+
+- (void)safeReleaseDraggingData:(NSNumber *)arg
+{
+    jlong draggingSequenceNumber = [arg longLongValue];
+
+    // Make sure dragging data is released only if no new drag is under way. If a new drag
+    // has been initiated it has released the old dragging data already. This has to be called
+    // on the native event thread - otherwise we'd need to start synchronizing.
+    if (draggingSequenceNumber == sDraggingSequenceNumber)
+        [self releaseDraggingData];
+}
+
+- (void)javaDraggingEnded:(jlong)draggingSequenceNumber success:(BOOL)jsuccess action:(jint)jdropaction
+{
+    NSNumber *draggingSequenceNumberID = [NSNumber numberWithLongLong:draggingSequenceNumber];
+        // Report back actual Swing success, not what AppKit thinks
+        sDraggingError = !jsuccess;
+        sDragOperation = [DnDUtilities mapJavaDragOperationToNS:jdropaction];
+
+    // Release dragging data if any when Java's AWT event thread is all finished.
+    // Make sure dragging data is released on the native event thread.
+    [ThreadUtilities performOnMainThread:@selector(safeReleaseDraggingData:) onObject:self
+                              withObject:draggingSequenceNumberID waitUntilDone:NO awtMode:NO];
+}
+
+- (jint)currentJavaActions {
+    return [DnDUtilities mapNSDragOperationToJava:sUpdateOperation];
+}
+
+/********************************  BEGIN NSDraggingDestination Interface  ********************************/
+
+
+// Private API to calculate the current Java actions
+- (void) calculateCurrentSourceActions:(jint *)actions dropAction:(jint *)dropAction
+{
+    // Get the raw (unmodified by keys) source actions
+    id jrsDrag = objc_lookUpClass("JRSDrag");
+    if (jrsDrag != nil) {
+        NSDragOperation rawDragActions = (NSDragOperation) [jrsDrag performSelector:@selector(currentAllowableActions)];
+        if (rawDragActions != NSDragOperationNone) {
+            // Both actions and dropAction default to the rawActions
+            *actions = [DnDUtilities mapNSDragOperationMaskToJava:rawDragActions];
+            *dropAction = *actions;
+
+            // Get the current key modifiers.
+            NSUInteger dragModifiers = (NSUInteger) [jrsDrag performSelector:@selector(currentModifiers)];
+            // Either the drop action is narrowed as per Java rules (MOVE, COPY, LINK, NONE) or by the drag modifiers
+            if (dragModifiers) {
+                // Get the user selected operation based on the drag modifiers, then return the intersection
+                NSDragOperation currentOp = [DnDUtilities nsDragOperationForModifiers:dragModifiers];
+                NSDragOperation allowedOp = rawDragActions & currentOp;
+
+                *dropAction = [DnDUtilities mapNSDragOperationToJava:allowedOp];
+            }
+        }
+    }
+    *dropAction = [DnDUtilities narrowJavaDropActions:*dropAction];
+}
+
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender
+{
+    DLog2(@"[CDropTarget draggingEntered]: %@\n", self);
+
+    sCurrentDropTarget = self;
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    NSInteger draggingSequenceNumber = [sender draggingSequenceNumber];
+
+    // Set the initial drag operation return value:
+    NSDragOperation dragOp = NSDragOperationNone;
+        sJavaDropOperation = java_awt_dnd_DnDConstants_ACTION_NONE;
+
+    // We could probably special-case some stuff if drag and drop objects match:
+    //if ([sender dragSource] == fView)
+
+    if (draggingSequenceNumber != sDraggingSequenceNumber) {
+        sDraggingSequenceNumber = draggingSequenceNumber;
+        sDraggingError = FALSE;
+
+        // Delete any drop target context peer left over from a previous drag:
+        if (fDropTargetContextPeer != NULL) {
+            JNFDeleteGlobalRef(env, fDropTargetContextPeer);
+            fDropTargetContextPeer = NULL;
+        }
+
+        // Look up the CDropTargetContextPeer class:
+        JNF_STATIC_MEMBER_CACHE(getDropTargetContextPeerMethod, jc_CDropTargetContextPeer, "getDropTargetContextPeer", "()Lsun/lwawt/macosx/CDropTargetContextPeer;");
+        if (sDraggingError == FALSE) {
+            // Create a new drop target context peer:
+            jobject dropTargetContextPeer = JNFCallStaticObjectMethod(env, getDropTargetContextPeerMethod);
+
+            if (dropTargetContextPeer != nil) {
+                fDropTargetContextPeer = JNFNewGlobalRef(env, dropTargetContextPeer);
+                (*env)->DeleteLocalRef(env, dropTargetContextPeer);
+            }
+        }
+
+        // Get dragging types (dragging data is only copied if dropped):
+        if (sDraggingError == FALSE && [self copyDraggingTypes:sender] == FALSE)
+            sDraggingError = TRUE;
+    }
+
+    if (sDraggingError == FALSE) {
+        sDraggingExited = FALSE;
+        sDraggingLocation = [sender draggingLocation];
+        NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil];
+        DLog5(@"+ dragEnter: loc native %f, %f, java %f, %f\n", sDraggingLocation.x, sDraggingLocation.y, javaLocation.x, javaLocation.y);
+
+                ////////// BEGIN Calculate the current drag actions //////////
+                jint actions = java_awt_dnd_DnDConstants_ACTION_NONE;
+        jint dropAction = actions;
+
+                [self calculateCurrentSourceActions:&actions dropAction:&dropAction];
+
+                sJavaDropOperation = dropAction;
+                ////////// END Calculate the current drag actions //////////
+
+        jlongArray formats = sDraggingFormats;
+
+        JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I");
+        if (sDraggingError == FALSE) {
+            // Double-casting self gets rid of 'different size' compiler warning:
+            actions = JNFCallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler)
+        }
+
+        if (sDraggingError == FALSE) {
+            // Initialize drag operation:
+            sDragOperation = NSDragOperationNone;
+
+            // Map Java actions back to NSDragOperation.
+            // 1-6-03 Note: if the entry point of this CDropTarget isn't covered by a droppable component
+            // (as can be the case with lightweight children) we must not return NSDragOperationNone
+            // since that would prevent dropping into any of the contained drop targets.
+            // Unfortunately there is no easy way to test this so we just test actions and override them
+            // with GENERIC if necessary. Proper drag operations will be returned by draggingUpdated: which is
+            // called right away, taking care of setting the right cursor and snap-back action.
+            dragOp = ((actions != java_awt_dnd_DnDConstants_ACTION_NONE) ?
+                [DnDUtilities mapJavaDragOperationToNS:dropAction] : NSDragOperationGeneric);
+
+            // Remember the dragOp for no-op'd update messages:
+            sUpdateOperation = dragOp;
+        }
+
+        // If we are in the same process as the sender, make the sender post the appropriate message
+        if (sender) {
+            [[CDragSource currentDragSource] postDragEnter];
+        }
+    }
+
+    // 9-11-02 Note: the native event thread would not handle an exception gracefully:
+    //if (sDraggingError == TRUE)
+    //    [NSException raise:NSGenericException format:@"[CDropTarget draggingEntered] failed."];
+
+    DLog2(@"[CDropTarget draggingEntered]: returning %lu\n", (unsigned long) dragOp);
+
+    return dragOp;
+}
+
+- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender
+{
+    //DLog2(@"[CDropTarget draggingUpdated]: %@\n", self);
+
+    sCurrentDropTarget = self;
+
+    // Set the initial drag operation return value:
+    NSDragOperation dragOp = (sDraggingError == FALSE ? sUpdateOperation : NSDragOperationNone);
+
+    // There are two things we would be interested in:
+    // a) mouse pointer has moved
+    // b) drag actions (key modifiers) have changed
+
+    NSPoint draggingLocation = [sender draggingLocation];
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    BOOL notifyJava = FALSE;
+
+    // a) mouse pointer has moved:
+    if (NSEqualPoints(draggingLocation, sDraggingLocation) == FALSE) {
+        //DLog2(@"[CDropTarget draggingUpdated]: mouse moved, %@\n", self);
+        sDraggingLocation = draggingLocation;
+        notifyJava = TRUE;
+    }
+
+    // b) drag actions (key modifiers) have changed (handleMotionMessage() will do proper notifications):
+        ////////// BEGIN Calculate the current drag actions //////////
+        jint actions = java_awt_dnd_DnDConstants_ACTION_NONE;
+        jint dropAction = actions;
+
+        [self calculateCurrentSourceActions:&actions dropAction:&dropAction];
+
+        if (sJavaDropOperation != dropAction) {
+            sJavaDropOperation = dropAction;
+            notifyJava = TRUE;
+        }
+        ////////// END Calculate the current drag actions //////////
+
+    jint userAction = dropAction;
+
+    // Should we notify Java things have changed?
+    if (sDraggingError == FALSE && notifyJava) {
+        NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil];
+		// For some reason even after the convertPoint drag events come with the y coordinate reverted
+		javaLocation.y = fView.frame.size.height - javaLocation.y;
+        //DLog5(@"  : dragMoved: loc native %f, %f, java %f, %f\n", sDraggingLocation.x, sDraggingLocation.y, javaLocation.x, javaLocation.y);
+
+        jlongArray formats = sDraggingFormats;
+
+        JNF_MEMBER_CACHE(handleMotionMessageMethod, jc_CDropTargetContextPeer, "handleMotionMessage", "(Ljava/awt/Component;IIII[JJ)I");
+        if (sDraggingError == FALSE) {
+            DLog3(@"  >> posting handleMotionMessage, point %f, %f", javaLocation.x, javaLocation.y);
+            userAction = JNFCallIntMethod(env, fDropTargetContextPeer, handleMotionMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler)
+        }
+
+        if (sDraggingError == FALSE) {
+            dragOp = [DnDUtilities mapJavaDragOperationToNS:userAction];
+
+            // Remember the dragOp for no-op'd update messages:
+            sUpdateOperation = dragOp;
+        } else {
+            dragOp = NSDragOperationNone;
+        }
+    }
+
+    DLog2(@"[CDropTarget draggingUpdated]: returning %lu\n", (unsigned long) dragOp);
+
+    return dragOp;
+}
+
+- (void)draggingExited:(id<NSDraggingInfo>)sender
+{
+    DLog2(@"[CDropTarget draggingExited]: %@\n", self);
+
+    sCurrentDropTarget = nil;
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    if (sDraggingExited == FALSE && sDraggingError == FALSE) {
+        JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V");
+        if (sDraggingError == FALSE) {
+            DLog3(@"  - dragExit: loc native %f, %f\n", sDraggingLocation.x, sDraggingLocation.y);
+            JNFCallVoidMethod(env, fDropTargetContextPeer, handleExitMessageMethod, fComponent, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler)
+            // If we are in the same process as the sender, make the sender post the appropriate message
+            if (sender) {
+                [[CDragSource currentDragSource] postDragExit];
+            }
+        }
+
+        // 5-27-03 Note: [Radar 3270455]
+        // -draggingExited: can be called both by the AppKit and by -performDragOperation: but shouldn't execute
+        // twice per drop since cleanup code like that in swing/plaf/basic/BasicDropTargetListener would throw NPEs.
+        sDraggingExited = TRUE;
+    }
+
+    DLog(@"[CDropTarget draggingExited]: returning.\n");
+}
+
+- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
+{
+    DLog2(@"[CDropTarget prepareForDragOperation]: %@\n", self);
+    DLog2(@"[CDropTarget prepareForDragOperation]: returning %@\n", (sDraggingError ? @"NO" : @"YES"));
+
+    return sDraggingError ? NO : YES;
+}
+
+- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender
+{
+    DLog2(@"[CDropTarget performDragOperation]: %@\n", self);
+
+    sCurrentDropTarget = nil;
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    // Now copy dragging data:
+    if (sDraggingError == FALSE && [self copyDraggingData:sender] == FALSE)
+        sDraggingError = TRUE;
+
+    if (sDraggingError == FALSE) {
+        sDraggingLocation = [sender draggingLocation];
+        NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil];
+
+        jint actions = [DnDUtilities mapNSDragOperationMaskToJava:[sender draggingSourceOperationMask]];
+        jint dropAction = sJavaDropOperation;
+
+        jlongArray formats = sDraggingFormats;
+
+        JNF_MEMBER_CACHE(handleDropMessageMethod, jc_CDropTargetContextPeer, "handleDropMessage", "(Ljava/awt/Component;IIII[JJ)V");
+
+        if (sDraggingError == FALSE) {
+            JNFCallVoidMethod(env, fDropTargetContextPeer, handleDropMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (event)
+        }
+
+        if (sDraggingError == FALSE) {
+            JNF_MEMBER_CACHE(flushEventsMethod, jc_CDropTargetContextPeer, "flushEvents", "(Ljava/awt/Component;)V");
+            if (sDraggingError == FALSE) {
+                JNFCallVoidMethod(env, fDropTargetContextPeer, flushEventsMethod, fComponent); // AWT_THREADING Safe (AWTRunLoopMode)
+            }
+        }
+    } else {
+        // 8-19-03 Note: [Radar 3368754]
+        // draggingExited: is not called after a drop - we must do that here ... but only in case
+        // of an error, instead of drop(). Otherwise we get twice the cleanup in shared code.
+        [self draggingExited:sender];
+    }
+
+// TODO:BG
+//   [(id)sender _setLastDragDestinationOperation:sDragOperation];
+
+
+    DLog2(@"[CDropTarget performDragOperation]: returning %@\n", (sDraggingError ? @"NO" : @"YES"));
+
+    return !sDraggingError;
+}
+
+- (void)concludeDragOperation:(id<NSDraggingInfo>)sender
+{
+    sCurrentDropTarget = nil;
+
+    DLog2(@"[CDropTarget concludeDragOperation]: %@\n", self);
+    DLog(@"[CDropTarget concludeDragOperation]: returning.\n");
+}
+
+// 9-11-02 Note: draggingEnded is not yet implemented by the AppKit.
+- (void)draggingEnded:(id<NSDraggingInfo>)sender
+{
+    sCurrentDropTarget = nil;
+
+    DLog2(@"[CDropTarget draggingEnded]: %@\n", self);
+    DLog(@"[CDropTarget draggingEnded]: returning.\n");
+}
+
+/********************************  END NSDraggingDestination Interface  ********************************/
+
+@end
+
+
+/*
+ * Class:     sun_lwawt_macosx_CDropTarget
+ * Method:    createNativeDropTarget
+ * Signature: (Ljava/awt/dnd/DropTarget;Ljava/awt/Component;Ljava/awt/peer/ComponentPeer;J)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTarget_createNativeDropTarget
+  (JNIEnv *env, jobject jthis, jobject jdroptarget, jobject jcomponent, jobject jpeer, jlong jnativepeer)
+{
+    CDropTarget* dropTarget = nil;
+
+JNF_COCOA_ENTER(env);
+    id controlObj = (id) jlong_to_ptr(jnativepeer);
+    dropTarget = [[CDropTarget alloc] init:jdroptarget component:jcomponent peer:jpeer control:controlObj];
+JNF_COCOA_EXIT(env);
+
+    if (dropTarget) {
+        CFRetain(dropTarget); // GC
+        [dropTarget release];
+    }
+    return ptr_to_jlong(dropTarget);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDropTarget
+ * Method:    releaseNativeDropTarget
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTarget_releaseNativeDropTarget
+  (JNIEnv *env, jobject jthis, jlong nativeDropTargetVal)
+{
+    id dropTarget = (id)jlong_to_ptr(nativeDropTargetVal);
+
+JNF_COCOA_ENTER(env);
+    [dropTarget removeFromView:env];
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CDropTargetContextPeer.m b/jdk/src/macosx/native/sun/awt/CDropTargetContextPeer.m
new file mode 100644
index 0000000..0e64b07
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CDropTargetContextPeer.m
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "sun_lwawt_macosx_CDropTargetContextPeer.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CDataTransferer.h"
+#import "CDropTarget.h"
+#import "DnDUtilities.h"
+#import "ThreadUtilities.h"
+
+JNF_CLASS_CACHE(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer");
+
+
+static void TransferFailed(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat) {
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+    JNF_MEMBER_CACHE(transferFailedMethod, jc_CDropTargetContextPeer, "transferFailed", "(J)V");
+    JNFCallVoidMethod(env, jthis, transferFailedMethod, jformat); // AWT_THREADING Safe (!appKit)
+}
+
+static CDropTarget* GetCDropTarget(jlong jdroptarget) {
+    CDropTarget* dropTarget = (CDropTarget*) jlong_to_ptr(jdroptarget);
+
+    // Make sure the drop target is of the right kind:
+    if ([dropTarget isKindOfClass:[CDropTarget class]]) {
+        return dropTarget;
+    }
+
+    return nil;
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CDropTargetContextPeer
+ * Method:    startTransfer
+ * Signature: (JJ)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer
+  (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jformat)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    jlong result = (jlong) 0L;
+
+    // Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]
+    // works off a data copy and doesn't have to go to the native event thread to get the data.
+    // We can have endTransfer just call startTransfer.
+
+JNF_COCOA_ENTER(env);
+    // Get the drop target native object:
+    CDropTarget* dropTarget = GetCDropTarget(jdroptarget);
+    if (dropTarget == nil) {
+        DLog2(@"[CDropTargetContextPeer startTransfer]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);
+        TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
+        return result;
+    }
+
+    JNF_MEMBER_CACHE(newDataMethod, jc_CDropTargetContextPeer, "newData", "(J[B)V");
+    if ((*env)->ExceptionOccurred(env) || !newDataMethod) {
+        DLog2(@"[CDropTargetContextPeer startTransfer]: couldn't get newData method for %d.\n", (NSInteger) jdroptarget);
+        TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
+        return result;
+    }
+
+    // Get data from drop target:
+    jobject jdropdata = [dropTarget copyDraggingDataForFormat:jformat];
+    if (!jdropdata) {
+        DLog2(@"[CDropTargetContextPeer startTransfer]: copyDraggingDataForFormat failed for %d.\n", (NSInteger) jdroptarget);
+        TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
+        return result;
+    }
+
+    // Pass the data to drop target:
+    @try {
+        JNFCallVoidMethod(env, jthis, newDataMethod, jformat, jdropdata); // AWT_THREADING Safe (!appKit)
+    } @catch (NSException *ex) {
+        DLog2(@"[CDropTargetContextPeer startTransfer]: exception in newData() for %d.\n", (NSInteger) jdroptarget);
+        JNFDeleteGlobalRef(env, jdropdata);
+        TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
+        return result;
+    }
+
+    // if no error return dropTarget's draggingSequence
+    result = [dropTarget getDraggingSequenceNumber];
+JNF_COCOA_EXIT(env);
+
+    return result;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDropTargetContextPeer
+ * Method:    addTransfer
+ * Signature: (JJJ)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_addTransfer
+  (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat)
+{
+    // Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]
+    // works off a data copy and doesn't have to go to the native event thread to get the data.
+    // We can have endTransfer just call startTransfer.
+
+    Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer(env, jthis, jdroptarget, jformat);
+
+    return;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CDropTargetContextPeer
+ * Method:    dropDone
+ * Signature: (JJZZI)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_dropDone
+  (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jboolean jislocal, jboolean jsuccess, jint jdropaction)
+{
+    // Get the drop target native object:
+JNF_COCOA_ENTER(env);
+    CDropTarget* dropTarget = GetCDropTarget(jdroptarget);
+    if (dropTarget == nil) {
+        DLog2(@"[CDropTargetContextPeer dropDone]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);
+        return;
+    }
+
+    // Notify drop target Java is all done with this dragging sequence:
+    [dropTarget javaDraggingEnded:(jlong)jdroptransfer success:jsuccess action:jdropaction];
+JNF_COCOA_EXIT(env);
+
+    return;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CFRetainedResource.m b/jdk/src/macosx/native/sun/awt/CFRetainedResource.m
new file mode 100644
index 0000000..183aa1b
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CFRetainedResource.m
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "sun_lwawt_macosx_CFRetainedResource.h"
+
+
+/*
+ * Class:     sun_lwawt_macosx_CFRetainedResource
+ * Method:    nativeCFRelease
+ * Signature: (JZ)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CFRetainedResource_nativeCFRelease
+(JNIEnv *env, jclass clazz, jlong ptr, jboolean releaseOnAppKitThread)
+{
+    if (releaseOnAppKitThread) {
+        [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+            CFRelease(jlong_to_ptr(ptr));
+        }];
+    } else {
+
+JNF_COCOA_ENTER(env);
+
+        CFRelease(jlong_to_ptr(ptr));
+
+JNF_COCOA_EXIT(env);
+
+    }
+}
diff --git a/jdk/src/macosx/native/sun/awt/CFileDialog.h b/jdk/src/macosx/native/sun/awt/CFileDialog.h
new file mode 100644
index 0000000..c901589
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CFileDialog.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+@interface CFileDialog : NSObject <NSOpenSavePanelDelegate> {
+    // Should we query back to Java for a file filter?
+    jboolean fHasFileFilter;
+
+    // sun.awt.CFileDialog
+    jobject fFileDialog;
+
+    // Return value from dialog
+    NSInteger fPanelResult;
+
+    // Dialog's title
+    NSString *fTitle;
+
+    // Starting directory and file
+    NSString *fDirectory;
+    NSString *fFile;
+
+    // File dialog's mode
+    jint fMode;
+
+    // Should we navigate into apps?
+    BOOL fNavigateApps;
+
+    // panel's filename
+    NSString *fReturnedFilename;
+}
+
+// Allocator
+- (id) initWithFilter:(jboolean)inHasFilter
+           fileDialog:(jobject)inDialog
+                title:(NSString *)inTitle
+            directory:(NSString *)inPath
+                 file:(NSString *)inFile
+                 mode:(jint)inMode
+       shouldNavigate:(BOOL)inNavigateApps
+              withEnv:(JNIEnv*)env;
+
+// Invoked from the main thread
+- (void) safeSaveOrLoad;
+
+// Get dialog return value
+- (BOOL) userClickedOK;
+
+// Filename user chose
+- (NSString *) filename;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CFileDialog.m b/jdk/src/macosx/native/sun/awt/CFileDialog.m
new file mode 100644
index 0000000..129ffd9
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CFileDialog.m
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <sys/stat.h>
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CFileDialog.h"
+#import "ThreadUtilities.h"
+
+#import "java_awt_FileDialog.h"
+#import "sun_lwawt_macosx_CFileDialog.h"
+
+@implementation CFileDialog
+
+- (id)initWithFilter:(jboolean)inHasFilter
+          fileDialog:(jobject)inDialog
+               title:(NSString *)inTitle
+           directory:(NSString *)inPath
+                file:(NSString *)inFile
+                mode:(jint)inMode
+      shouldNavigate:(BOOL)inNavigateApps
+             withEnv:(JNIEnv*)env;
+{
+    if (self == [super init]) {
+        fHasFileFilter = inHasFilter;
+        fFileDialog = JNFNewGlobalRef(env, inDialog);
+        fDirectory = inPath;
+        [fDirectory retain];
+        fFile = inFile;
+        [fFile retain];
+        fTitle = inTitle;
+        [fTitle retain];
+        fMode = inMode;
+        fNavigateApps = inNavigateApps;
+        fPanelResult = NSCancelButton;
+    }
+
+    return self;
+}
+
+-(void) disposer {
+    if (fFileDialog != NULL) {
+        JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+        JNFDeleteGlobalRef(env, fFileDialog);
+        fFileDialog = NULL;
+    }
+}
+
+-(void) dealloc {
+    [fDirectory release];
+    fDirectory = nil;
+
+    [fFile release];
+    fFile = nil;
+
+    [fTitle release];
+    fTitle = nil;
+
+    [fReturnedFilename release];
+    fReturnedFilename = nil;
+
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+- (void)safeSaveOrLoad {
+    NSSavePanel *thePanel = nil;
+
+    if (fMode == java_awt_FileDialog_SAVE) {
+        thePanel = [NSSavePanel savePanel];
+        [thePanel setAllowsOtherFileTypes:YES];
+    } else {
+        thePanel = [NSOpenPanel openPanel];
+    }
+
+    if (thePanel != nil) {
+        [thePanel setTitle:fTitle];
+
+        if (fNavigateApps) {
+            [thePanel setTreatsFilePackagesAsDirectories:YES];
+        }
+
+        if (fMode == java_awt_FileDialog_LOAD) {
+            NSOpenPanel *openPanel = (NSOpenPanel *)thePanel;
+            [openPanel setAllowsMultipleSelection:NO];
+            [openPanel setCanChooseFiles:YES];
+            [openPanel setCanChooseDirectories:NO];
+            [openPanel setCanCreateDirectories:YES];
+        }
+
+        [thePanel setDelegate:self];
+        fPanelResult = [thePanel runModalForDirectory:fDirectory file:fFile];
+        [thePanel setDelegate:nil];
+        fReturnedFilename = [thePanel filename];
+        [fReturnedFilename retain];
+    }
+
+    [self disposer];
+}
+
+- (BOOL) askFilenameFilter:(NSString *)filename {
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jstring jString = JNFNormalizedJavaStringForPath(env, filename);
+
+    static JNF_CLASS_CACHE(jc_CFileDialog, "sun/lwawt/macosx/CFileDialog");
+    static JNF_MEMBER_CACHE(jm_queryFF, jc_CFileDialog, "queryFilenameFilter", "(Ljava/lang/String;)Z");
+    BOOL returnValue = JNFCallBooleanMethod(env, fFileDialog, jm_queryFF, jString); // AWT_THREADING Safe (AWTRunLoopMode)
+    (*env)->DeleteLocalRef(env, jString);
+
+    return returnValue;
+}
+
+- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url {
+    if (!fHasFileFilter) return YES; // no filter, no problem!
+
+    // check if it's not a normal file
+    NSNumber *isFile = nil;
+    if ([url getResourceValue:&isFile forKey:NSURLIsRegularFileKey error:nil]) {
+        if (![isFile boolValue]) return YES; // always show directories and non-file entities (browsing servers/mounts, etc)
+    }
+
+    // if in directory-browsing mode, don't offer files
+    if ((fMode != java_awt_FileDialog_LOAD) && (fMode != java_awt_FileDialog_SAVE)) {
+        return NO;
+    }
+
+    // ask the file filter up in Java
+    CFStringRef filePath = CFURLCopyFileSystemPath((CFURLRef)url, kCFURLPOSIXPathStyle);
+    BOOL shouldEnableFile = [self askFilenameFilter:(NSString *)filePath];
+    CFRelease(filePath);
+    return shouldEnableFile;
+}
+
+- (BOOL) userClickedOK {
+    return fPanelResult == NSOKButton;
+}
+
+- (NSString *)filename {
+    return [[fReturnedFilename retain] autorelease];
+}
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CFileDialog
+ * Method:    nativeRunFileDialog
+ * Signature: (Ljava/lang/String;ILjava/io/FilenameFilter;
+ *             Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_sun_lwawt_macosx_CFileDialog_nativeRunFileDialog
+(JNIEnv *env, jobject peer, jstring title, jint mode, jboolean navigateApps, jboolean hasFilter, jstring directory, jstring file)
+{
+    jstring returnValue = NULL;
+
+JNF_COCOA_ENTER(env);
+    NSString *dialogTitle = JNFJavaToNSString(env, title);
+    if ([dialogTitle length] == 0) {
+        dialogTitle = @" ";
+    }
+
+    CFileDialog *dialogDelegate = [[CFileDialog alloc] initWithFilter:hasFilter
+                                                           fileDialog:peer
+                                                                title:dialogTitle
+                                                            directory:JNFJavaToNSString(env, directory)
+                                                                 file:JNFJavaToNSString(env, file)
+                                                                 mode:mode
+                                                       shouldNavigate:navigateApps
+                                                              withEnv:env];
+
+    [JNFRunLoop performOnMainThread:@selector(safeSaveOrLoad)
+                                 on:dialogDelegate
+                         withObject:nil
+                      waitUntilDone:YES];
+
+    if ([dialogDelegate userClickedOK]) {
+        NSString *filename = [dialogDelegate filename];
+        returnValue = JNFNSToJavaString(env, filename);
+    }
+
+    [dialogDelegate release];
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CGraphicsConfig.m b/jdk/src/macosx/native/sun/awt/CGraphicsConfig.m
new file mode 100644
index 0000000..563bdf5
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CGraphicsConfig.m
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "LWCToolkit.h"
+#include "GeomUtilities.h"
+
+#include "sun_awt_CGraphicsConfig.h"
+
+
+/*
+ * Class:     sun_awt_CGraphicsConfig
+ * Method:    nativeGetBounds
+ * Signature: (I)Ljava/awt/Rectangle;
+ */
+JNIEXPORT jobject JNICALL Java_sun_awt_CGraphicsConfig_nativeGetBounds
+(JNIEnv *env, jclass class, jint displayID)
+{
+    jobject jrect = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    CGRect rect = CGDisplayBounds((CGDirectDisplayID)displayID);
+    jrect = CGToJavaRect(env, rect);
+
+JNF_COCOA_EXIT(env);
+
+    return jrect;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CGraphicsDevice.m b/jdk/src/macosx/native/sun/awt/CGraphicsDevice.m
new file mode 100644
index 0000000..d43f78c
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CGraphicsDevice.m
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "LWCToolkit.h"
+
+/*
+ * Class:     apple_awt_CGraphicsDevice
+ * Method:    nativeGetXResolution
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_sun_awt_CGraphicsDevice_nativeGetXResolution
+  (JNIEnv *env, jclass class, jint displayID)
+{
+    // TODO: this is the physically correct answer, but we probably want
+    // to use NSScreen API instead...
+    CGSize size = CGDisplayScreenSize(displayID);
+    CGRect rect = CGDisplayBounds(displayID);
+    // 1 inch == 25.4 mm
+    jfloat inches = size.width / 25.4f;
+    jfloat dpi = rect.size.width / inches;
+    return dpi;
+}
+
+/*
+ * Class:     sun_awt_CGraphicsDevice
+ * Method:    nativeGetYResolution
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_sun_awt_CGraphicsDevice_nativeGetYResolution
+  (JNIEnv *env, jclass class, jint displayID)
+{
+    // TODO: this is the physically correct answer, but we probably want
+    // to use NSScreen API instead...
+    CGSize size = CGDisplayScreenSize(displayID);
+    CGRect rect = CGDisplayBounds(displayID);
+    // 1 inch == 25.4 mm
+    jfloat inches = size.height / 25.4f;
+    jfloat dpi = rect.size.height / inches;
+    return dpi;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CGraphicsEnv.m b/jdk/src/macosx/native/sun/awt/CGraphicsEnv.m
new file mode 100644
index 0000000..da018a2
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CGraphicsEnv.m
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "LWCToolkit.h"
+#import "AWT_debug.h"
+
+
+/*
+ * Class:     sun_awt_CGraphicsEnvironment
+ * Method:    initCocoa
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_awt_CGraphicsEnvironment_initCocoa
+(JNIEnv *env, jclass self)
+{
+JNF_COCOA_ENTER(env);
+
+    // Inform Cocoa that we're multi-threaded.
+    // Creating a short-lived NSThread is the recommended way of doing so.
+    [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSObject class] withObject:nil];
+
+JNF_COCOA_EXIT(env);
+}
+
+#define MAX_DISPLAYS 64
+
+/*
+ * Class:     sun_awt_CGraphicsEnvironment
+ * Method:    getDisplayIDs
+ * Signature: ()[I
+ */
+JNIEXPORT jintArray JNICALL
+Java_sun_awt_CGraphicsEnvironment_getDisplayIDs
+(JNIEnv *env, jclass class)
+{
+    jintArray ret = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    /* Get the count */
+    CGDisplayCount displayCount;
+    if (CGGetActiveDisplayList(MAX_DISPLAYS, NULL, &displayCount) != kCGErrorSuccess) {
+        [JNFException raise:env
+                         as:kInternalError
+                     reason:"CGGetOnlineDisplayList() failed to get display count"];
+        return NULL;
+    }
+
+    /* Allocate an array and get the size list of display Ids */
+    CGDirectDisplayID displays[MAX_DISPLAYS];
+    if (CGGetActiveDisplayList(displayCount, displays, &displayCount) != kCGErrorSuccess) {
+        [JNFException raise:env
+                         as:kInternalError
+                     reason:"CGGetOnlineDisplayList() failed to get display list"];
+        return NULL;
+    }
+
+    /* Allocate a java array for display identifiers */
+    ret = JNFNewIntArray(env, displayCount);
+
+    /* Initialize and return the backing int array */
+    assert(sizeof(jint) >= sizeof(CGDirectDisplayID));
+    jint *elems = (*env)->GetIntArrayElements(env, ret, 0);
+
+    CGDisplayCount i;
+    for (i = 0; i < displayCount; i++) {
+        elems[i] = displays[i];
+    }
+
+    (*env)->ReleaseIntArrayElements(env, ret, elems, 0);
+
+JNF_COCOA_EXIT(env);
+
+    return ret;
+}
+
+/*
+ * Class:     sun_awt_CGraphicsEnvironment
+ * Method:    getMainDisplayID
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL
+Java_sun_awt_CGraphicsEnvironment_getMainDisplayID
+(JNIEnv *env, jclass class)
+{
+    return CGMainDisplayID();
+}
+
+/*
+ * Post the display reconfiguration event.
+ */
+static void displaycb_handle
+(CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo)
+{
+    if (flags == kCGDisplayBeginConfigurationFlag) return;
+
+    JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) {
+        JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo;
+
+        jobject graphicsEnv = [wrapper jObjectWithEnv:env];
+        if (graphicsEnv == NULL) return; // ref already GC'd
+
+        static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment");
+        static JNF_MEMBER_CACHE(jm_displayReconfiguration, jc_CGraphicsEnvironment, "_displayReconfiguration", "(J)V");
+        JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration);
+    });
+}
+
+/*
+ * Class:     sun_awt_CGraphicsEnvironment
+ * Method:    registerDisplayReconfiguration
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_awt_CGraphicsEnvironment_registerDisplayReconfiguration
+(JNIEnv *env, jobject this)
+{
+    jlong ret = 0L;
+
+JNF_COCOA_ENTER(env);
+
+    JNFWeakJObjectWrapper *wrapper = [JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env];
+    CFRetain(wrapper); // pin from ObjC-GC
+
+    /* Register the callback */
+    if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
+        [JNFException raise:env
+                         as:kInternalError
+                     reason:"CGDisplayRegisterReconfigurationCallback() failed"];
+        return 0L;
+    }
+
+    ret = ptr_to_jlong(wrapper);
+
+JNF_COCOA_EXIT(env);
+
+    return ret;
+}
+
+/*
+ * Class:     sun_awt_CGraphicsEnvironment
+ * Method:    deregisterDisplayReconfiguration
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_awt_CGraphicsEnvironment_deregisterDisplayReconfiguration
+(JNIEnv *env, jobject this, jlong p)
+{
+JNF_COCOA_ENTER(env);
+
+    JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)jlong_to_ptr(p);
+    if (!wrapper) return;
+
+    /* Remove the registration */
+    if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
+        [JNFException raise:env
+                         as:kInternalError
+                     reason:"CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!"];
+        return;
+    }
+
+    [wrapper setJObject:NULL withEnv:env]; // more efficiant to pre-clear
+
+    CFRelease(wrapper);
+
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CImage.m b/jdk/src/macosx/native/sun/awt/CImage.m
new file mode 100644
index 0000000..787315f
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CImage.m
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "GeomUtilities.h"
+#import "ThreadUtilities.h"
+
+#import "sun_lwawt_macosx_CImage.h"
+
+
+static void CImage_CopyArrayIntoNSImageRep
+(jint *srcPixels, jint *dstPixels, int width, int height)
+{
+    int x, y;
+    // TODO: test this on big endian systems (not sure if its correct)...
+    for (y = 0; y < height; y++) {
+        for (x = 0; x < width; x++) {
+            jint pix = srcPixels[x];
+            jint a = (pix >> 24) & 0xff;
+            jint r = (pix >> 16) & 0xff;
+            jint g = (pix >>  8) & 0xff;
+            jint b = (pix      ) & 0xff;
+            dstPixels[x] = (b << 24) | (g << 16) | (r << 8) | a;
+        }
+        srcPixels += width; // TODO: use explicit scanStride
+        dstPixels += width;
+    }
+}
+
+static void CImage_CopyNSImageIntoArray
+(NSImage *srcImage, jint *dstPixels, int width, int height)
+{
+    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
+    CGContextRef cgRef = CGBitmapContextCreate(dstPixels, width, height, 8, width * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
+    CGColorSpaceRelease(colorspace);
+    NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithGraphicsPort:cgRef flipped:NO];
+    CGContextRelease(cgRef);
+    NSGraphicsContext *oldContext = [[NSGraphicsContext currentContext] retain];
+    [NSGraphicsContext setCurrentContext:context];
+    NSRect rect = NSMakeRect(0, 0, width, height);
+    [srcImage drawInRect:rect
+                fromRect:rect
+               operation:NSCompositeSourceOver
+                fraction:1.0];
+    [NSGraphicsContext setCurrentContext:oldContext];
+    [oldContext release];
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeCreateNSImageFromArray
+ * Signature: ([III)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArray
+(JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height)
+{
+    jlong result = 0L;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_ANY_THREAD;
+
+    NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
+                                                                         pixelsWide:width
+                                                                         pixelsHigh:height
+                                                                      bitsPerSample:8
+                                                                    samplesPerPixel:4
+                                                                           hasAlpha:YES
+                                                                           isPlanar:NO
+                                                                     colorSpaceName:NSDeviceRGBColorSpace
+                                                                       bitmapFormat:NSAlphaFirstBitmapFormat
+                                                                        bytesPerRow:width*4 // TODO: use explicit scanStride
+                                                                       bitsPerPixel:32];
+
+    jint *imgData = (jint *)[imageRep bitmapData];
+    if (imgData == NULL) return 0L;
+
+    jint *src = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
+    if (src == NULL) return 0L;
+
+    CImage_CopyArrayIntoNSImageRep(src, imgData, width, height);
+
+    (*env)->ReleasePrimitiveArrayCritical(env, buffer, src, JNI_ABORT);
+
+    NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
+    [nsImage addRepresentation:imageRep];
+    [imageRep release];
+
+    if (nsImage != nil) {
+        CFRetain(nsImage); // GC
+    }
+
+    result = ptr_to_jlong(nsImage);
+
+JNF_COCOA_EXIT(env);
+
+    return result;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeCreateNSImageFromIconSelector
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromIconSelector
+(JNIEnv *env, jclass klass, jint selector)
+{
+    NSImage *image = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_ANY_THREAD;
+
+    IconRef iconRef;
+    if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) {
+        image = [[NSImage alloc] initWithIconRef:iconRef];
+        if (image) CFRetain(image); // GC
+        ReleaseIconRef(iconRef);
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(image);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeCreateNSImageFromFileContents
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromFileContents
+(JNIEnv *env, jclass klass, jstring file)
+{
+    NSImage *image = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_ANY_THREAD;
+
+    NSString *path = JNFNormalizedNSStringForPath(env, file);
+    image = [[NSImage alloc] initByReferencingFile:path];
+    if (image) CFRetain(image); // GC
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(image);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeCreateNSImageOfFileFromLaunchServices
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageOfFileFromLaunchServices
+(JNIEnv *env, jclass klass, jstring file)
+{
+    __block NSImage *image = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_ANY_THREAD;
+
+    NSString *path = JNFNormalizedNSStringForPath(env, file);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        image = [[NSWorkspace sharedWorkspace] iconForFile:path];
+        [image setScalesWhenResized:TRUE];
+        if (image) CFRetain(image); // GC
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(image);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeCreateNSImageFromImageName
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromImageName
+(JNIEnv *env, jclass klass, jstring name)
+{
+    NSImage *image = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_ANY_THREAD;
+
+    image = [NSImage imageNamed:JNFJavaToNSString(env, name)];
+    if (image) CFRetain(image); // GC
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(image);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeCopyNSImageIntoArray
+ * Signature: (J[III)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeCopyNSImageIntoArray
+(JNIEnv *env, jclass klass, jlong nsImgPtr, jintArray buffer, jint w, jint h)
+{
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_ANY_THREAD;
+
+    NSImage *img = (NSImage *)jlong_to_ptr(nsImgPtr);
+    jint *dst = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
+    if (dst) {
+        CImage_CopyNSImageIntoArray(img, dst, w, h);
+        (*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT);
+    }
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeGetNSImageSize
+ * Signature: (J)Ljava/awt/geom/Dimension2D;
+ */
+JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CImage_nativeGetNSImageSize
+(JNIEnv *env, jclass klass, jlong nsImgPtr)
+{
+    jobject size = NULL;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_ANY_THREAD;
+
+    size = NSToJavaSize(env, [(NSImage *)jlong_to_ptr(nsImgPtr) size]);
+
+JNF_COCOA_EXIT(env);
+
+    return size;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CImage
+ * Method:    nativeSetNSImageSize
+ * Signature: (JDD)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeSetNSImageSize
+(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h)
+{
+    if (!image) return;
+    NSImage *i = (NSImage *)jlong_to_ptr(image);
+
+JNF_COCOA_ENTER(env);
+
+    [i setScalesWhenResized:TRUE];
+    [i setSize:NSMakeSize(w, h)];
+
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CInputMethod.m b/jdk/src/macosx/native/sun/awt/CInputMethod.m
new file mode 100644
index 0000000..764e2db
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CInputMethod.m
@@ -0,0 +1,319 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#include <objc/objc-runtime.h>
+
+#import "sun_lwawt_macosx_CInputMethod.h"
+#import "sun_lwawt_macosx_CInputMethodDescriptor.h"
+#import "ThreadUtilities.h"
+#import "AWTView.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#define JAVA_LIST @"JAVA_LIST"
+#define CURRENT_KB_DESCRIPTION @"CURRENT_KB_DESCRIPTION"
+
+static JNF_CLASS_CACHE(jc_localeClass, "java/util/Locale");
+static JNF_CTOR_CACHE(jm_localeCons, jc_localeClass, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
+static JNF_CLASS_CACHE(jc_arrayListClass, "java/util/ArrayList");
+static JNF_CTOR_CACHE(jm_arrayListCons, jc_arrayListClass, "()V");
+static JNF_MEMBER_CACHE(jm_listAdd, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
+static JNF_MEMBER_CACHE(jm_listContains, jc_arrayListClass, "contains", "(Ljava/lang/Object;)Z");
+
+
+
+//
+// NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value.
+//
+static jobject CreateLocaleObjectFromNSString(JNIEnv *env, NSString *name)
+{
+    // Break apart the string into its components.
+    // First, duplicate the NSString into a C string, since we're going to modify it.
+    char * language = strdup([name UTF8String]);
+    char * country;
+    char * variant;
+
+    // Convert _ to NULL -- this gives us three null terminated strings in place.
+    for (country = language; *country != '_' && *country != '\0'; country++);
+    if (*country == '_') {
+        *country++ = '\0';
+        for (variant = country; *variant != '_' && *variant != '\0'; variant++);
+        if (*variant == '_') {
+            *variant++ = '\0';
+        }
+    } else {
+        variant = country;
+    }
+
+    // Create the java.util.Locale object
+    jobject langObj = (*env)->NewStringUTF(env, language);
+    jobject ctryObj = (*env)->NewStringUTF(env, country);
+    jobject vrntObj = (*env)->NewStringUTF(env, variant);
+    jobject localeObj = JNFNewObject(env, jm_localeCons, langObj, ctryObj, vrntObj); // AWT_THREADING Safe (known object)
+
+    // Clean up and return.
+    free(language);
+    (*env)->DeleteLocalRef(env, langObj);
+    (*env)->DeleteLocalRef(env, ctryObj);
+    (*env)->DeleteLocalRef(env, vrntObj);
+
+    return localeObj;
+}
+
+static id inputMethodController = nil;
+
+static void initializeInputMethodController() {
+    static BOOL checkedJRSInputMethodController = NO;
+    if (!checkedJRSInputMethodController && (inputMethodController == nil)) {
+        id jrsInputMethodController = objc_lookUpClass("JRSInputMethodController");
+        if (jrsInputMethodController != nil) {
+            inputMethodController = [jrsInputMethodController performSelector:@selector(controller)];
+        }
+        checkedJRSInputMethodController = YES;
+    }
+}
+
+
+@interface CInputMethod : NSObject {}
+@end
+
+@implementation CInputMethod
+
++ (void) setKeyboardLayout:(NSString *)theLocale
+{
+    AWT_ASSERT_APPKIT_THREAD;
+    if (!inputMethodController) return;
+
+    [inputMethodController performSelector:@selector(setCurrentInputMethodForLocale) withObject:theLocale];
+}
+
++ (void) _nativeNotifyPeerWithView:(AWTView *)view inputMethod:(JNFJObjectWrapper *) inputMethod {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    if (!view) return;
+    if (!inputMethod) return;
+
+    [view setInputMethod:[inputMethod jObject]];
+}
+
++ (void) _nativeEndComposition:(AWTView *)view {
+    if (view == nil) return;
+
+    [view abandonInput];
+}
+
+
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethod
+ * Method:    nativeInit
+ * Signature: ();
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeInit
+(JNIEnv *env, jclass klass)
+{
+    initializeInputMethodController();
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethod
+ * Method:    nativeGetCurrentInputMethodInfo
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeGetCurrentInputMethodInfo
+(JNIEnv *env, jclass klass)
+{
+    if (!inputMethodController) return NULL;
+    jobject returnValue = 0;
+    __block NSString *keyboardInfo = NULL;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        keyboardInfo = [inputMethodController performSelector:@selector(currentInputMethodName)];
+        [keyboardInfo retain];
+    }];
+
+    if (keyboardInfo == nil) return NULL;
+    returnValue = JNFNSToJavaString(env, keyboardInfo);
+    [keyboardInfo release];
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethod
+ * Method:    nativeActivate
+ * Signature: (JLsun/lwawt/macosx/CInputMethod;)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeNotifyPeer
+(JNIEnv *env, jobject this, jlong nativePeer, jobject inputMethod)
+{
+JNF_COCOA_ENTER(env);
+    AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
+    JNFJObjectWrapper *inputMethodWrapper = [[JNFJObjectWrapper alloc] initWithJObject:inputMethod withEnv:env];
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [CInputMethod _nativeNotifyPeerWithView:view inputMethod:inputMethodWrapper];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethod
+ * Method:    nativeEndComposition
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeEndComposition
+(JNIEnv *env, jobject this, jlong nativePeer)
+{
+JNF_COCOA_ENTER(env);
+   AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
+
+   [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [CInputMethod _nativeEndComposition:view];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethod
+ * Method:    getNativeLocale
+ * Signature: ()Ljava/util/Locale;
+ */
+JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethod_getNativeLocale
+(JNIEnv *env, jobject this)
+{
+    if (!inputMethodController) return NULL;
+    jobject returnValue = 0;
+    __block NSString *isoAbbreviation;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        isoAbbreviation = (NSString *) [inputMethodController performSelector:@selector(currentInputMethodLocale)];
+        [isoAbbreviation retain];
+    }];
+
+    if (isoAbbreviation == nil) return NULL;
+
+    static NSString *sLastKeyboardStr = nil;
+    static jobject sLastKeyboardLocaleObj = NULL;
+
+    if (![isoAbbreviation isEqualTo:sLastKeyboardStr]) {
+        [sLastKeyboardStr release];
+        sLastKeyboardStr = [isoAbbreviation retain];
+        jobject localObj = CreateLocaleObjectFromNSString(env, isoAbbreviation);
+        [isoAbbreviation release];
+
+        if (sLastKeyboardLocaleObj) {
+            JNFDeleteGlobalRef(env, sLastKeyboardLocaleObj);
+        }
+
+        sLastKeyboardLocaleObj = JNFNewGlobalRef(env, localObj);
+        (*env)->DeleteLocalRef(env, localObj);
+    }
+
+    returnValue = sLastKeyboardLocaleObj;
+
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethod
+ * Method:    setNativeLocale
+ * Signature: (Ljava/lang/String;Z)Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CInputMethod_setNativeLocale
+(JNIEnv *env, jobject this, jstring locale, jboolean isActivating)
+{
+JNF_COCOA_ENTER(env);
+    NSString *localeStr = JNFJavaToNSString(env, locale);
+    [localeStr retain];
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        [CInputMethod setKeyboardLayout:localeStr];
+    }];
+
+    [localeStr release];
+JNF_COCOA_EXIT(env);
+    return JNI_TRUE;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethodDescriptor
+ * Method:    nativeInit
+ * Signature: ();
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeInit
+(JNIEnv *env, jclass klass)
+{
+    initializeInputMethodController();
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CInputMethodDescriptor
+ * Method:    nativeGetAvailableLocales
+ * Signature: ()[Ljava/util/Locale;
+     */
+JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeGetAvailableLocales
+(JNIEnv *env, jclass klass)
+{
+    if (!inputMethodController) return NULL;
+    jobject returnValue = 0;
+
+    __block NSArray *selectableArray = nil;
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        selectableArray = (NSArray *)[inputMethodController performSelector:@selector(availableInputMethodLocales)];
+        [selectableArray retain];
+    }];
+
+    if (selectableArray == nil) return NULL;
+
+     // Create an ArrayList to return back to the caller.
+    returnValue = JNFNewObject(env, jm_arrayListCons);
+
+    for(NSString *locale in selectableArray) {
+        jobject localeObj = CreateLocaleObjectFromNSString(env, locale);
+
+        if (JNFCallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) { // AWT_THREADING Safe (known object)
+            JNFCallBooleanMethod(env, returnValue, jm_listAdd, localeObj); // AWT_THREADING Safe (known object)
+        }
+
+        (*env)->DeleteLocalRef(env, localeObj);
+    }
+    [selectableArray release];
+JNF_COCOA_EXIT(env);
+    return returnValue;
+}
+
diff --git a/jdk/src/macosx/native/sun/awt/CMenu.h b/jdk/src/macosx/native/sun/awt/CMenu.h
new file mode 100644
index 0000000..f7cd4f6
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenu.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CMenuItem.h"
+
+extern NSString *JAVA_MENU_NAME;
+
+@interface CMenu : CMenuItem {
+    NSMenu *fMenu;
+}
+
+// Initializers
+- (id)initWithPeer:(jobject)peer;
+
+- (void)setNativeMenuTitle_OnAppKitThread:(NSString *)title;
+- (void)addNativeItem_OnAppKitThread:(CMenuItem *)itemModified;
+- (void)deleteNativeJavaItem_OnAppKitThread:(NSNumber *)number;
+- (void)setNativeEnabled_OnAppKitThread:(NSNumber *)boolNumber;
+
+// Actions
+- (void)addJavaSubmenu:(CMenu *)submenu;
+- (void)addJavaMenuItem:(CMenuItem *)newItem;
+- (void)setJavaMenuTitle:(NSString *)title;
+- (void)deleteJavaItem:(jint)index;
+- (void)addNSMenuItemToMenu:(NSMenu *)inMenu;
+- (void)addSeparator;
+
+// Accessors
+- (NSMenu *)menu;
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CMenu.m b/jdk/src/macosx/native/sun/awt/CMenu.m
new file mode 100644
index 0000000..32a9d5b
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenu.m
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+
+#import "CMenu.h"
+#import "CMenuBar.h"
+#import "ThreadUtilities.h"
+
+#import "sun_lwawt_macosx_CMenu.h"
+
+@implementation CMenu
+
+- (id)initWithPeer:(jobject)peer {
+AWT_ASSERT_APPKIT_THREAD;
+    // Create the new NSMenu
+    self = [super initWithPeer:peer asSeparator:[NSNumber numberWithBool:NO]];
+    if (self) {
+        fMenu = [NSMenu javaMenuWithTitle:@""];
+        [fMenu retain];
+        [fMenu setAutoenablesItems:NO];
+    }
+    return self;
+}
+
+- (void)dealloc {
+    [fMenu release];
+    fMenu = nil;
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+- (void)addJavaSubmenu:(CMenu *)submenu {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+    [ThreadUtilities performOnMainThread:@selector(addNativeItem_OnAppKitThread:) onObject:self withObject:submenu waitUntilDone:YES awtMode:YES];
+}
+
+- (void)addJavaMenuItem:(CMenuItem *)theMenuItem {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+    [ThreadUtilities performOnMainThread:@selector(addNativeItem_OnAppKitThread:) onObject:self withObject:theMenuItem waitUntilDone:YES awtMode:YES];
+}
+
+- (void)addNativeItem_OnAppKitThread:(CMenuItem *)itemModified {
+AWT_ASSERT_APPKIT_THREAD;
+    [itemModified addNSMenuItemToMenu:[self menu]];
+}
+
+- (void)setJavaMenuTitle:(NSString *)title {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    if (title) {
+        [ThreadUtilities performOnMainThread:@selector(setNativeMenuTitle_OnAppKitThread:) onObject:self withObject:title waitUntilDone:YES awtMode:YES];
+    }
+}
+
+- (void)setNativeMenuTitle_OnAppKitThread:(NSString *)title {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [fMenu setTitle:title];
+    // If we are a submenu we need to set our name in the parent menu's menu item.
+    NSMenu *parent = [fMenu supermenu];
+    if (parent) {
+        NSInteger index = [parent indexOfItemWithSubmenu:fMenu];
+        NSMenuItem *menuItem = [parent itemAtIndex:index];
+        [menuItem setTitle:title];
+    }
+}
+
+- (void)addSeparator {
+    // Nothing calls this, which is good because we need a CMenuItem here.
+}
+
+- (void)deleteJavaItem:(jint)index {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    [ThreadUtilities performOnMainThread:@selector(deleteNativeJavaItem_OnAppKitThread:) onObject:self withObject:[NSNumber numberWithInt:index] waitUntilDone:YES awtMode:YES];
+}
+
+- (void)deleteNativeJavaItem_OnAppKitThread:(NSNumber *)number {
+AWT_ASSERT_APPKIT_THREAD;
+
+    int n = [number intValue];
+    if (n < [[self menu] numberOfItems]) {
+        [[self menu] removeItemAtIndex:n];
+    }
+}
+
+- (void)addNSMenuItemToMenu:(NSMenu *)inMenu {
+    if (fMenuItem == nil) return;
+    [fMenuItem setSubmenu:fMenu];
+    [inMenu addItem:fMenuItem];
+}
+
+- (NSMenu *)menu {
+    return [[fMenu retain] autorelease];
+}
+
+- (void)setNativeEnabled_OnAppKitThread:(NSNumber *)boolNumber {
+AWT_ASSERT_APPKIT_THREAD;
+
+    @synchronized(self) {
+        fIsEnabled = [boolNumber boolValue];
+
+        NSMenu* supermenu = [fMenu supermenu];
+        [[supermenu itemAtIndex:[supermenu indexOfItemWithSubmenu:fMenu]] setEnabled:fIsEnabled];
+    }
+}
+
+- (NSString *)description {
+    return [NSString stringWithFormat:@"CMenu[ %@ ]", fMenu];
+}
+
+@end
+
+CMenu * createCMenu (jobject cPeerObjGlobal) {
+
+    CMenu *aCMenu = nil;
+
+    // We use an array here only to be able to get a return value
+    NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], nil];
+
+    [ThreadUtilities performOnMainThread:@selector(_create_OnAppKitThread:) onObject:[CMenu alloc] withObject:args waitUntilDone:YES awtMode:YES];
+
+    aCMenu = (CMenu *)[args objectAtIndex: 0];
+
+    if (aCMenu == nil) {
+        return 0L;
+    }
+
+    return aCMenu;
+
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenu
+ * Method:    nativeCreateSubMenu
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CMenu_nativeCreateSubMenu
+(JNIEnv *env, jobject peer, jlong parentMenu)
+{
+    CMenu *aCMenu = nil;
+JNF_COCOA_ENTER(env);
+
+    jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
+
+    aCMenu = createCMenu (cPeerObjGlobal);
+
+    // Add it to the parent menu
+    [((CMenu *)jlong_to_ptr(parentMenu)) addJavaSubmenu: aCMenu];
+    if (aCMenu) {
+        CFRetain(aCMenu); // GC
+        [aCMenu release];
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(aCMenu);
+}
+
+
+
+/*
+ * Class:     sun_lwawt_macosx_CMenu
+ * Method:    nativeCreateMenu
+ * Signature: (JZ)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CMenu_nativeCreateMenu
+(JNIEnv *env, jobject peer,
+        jlong parentMenuBar, jboolean isHelpMenu, jint insertLocation)
+{
+    CMenu *aCMenu = nil;
+    CMenuBar *parent = (CMenuBar *)jlong_to_ptr(parentMenuBar);
+JNF_COCOA_ENTER(env);
+
+    jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
+
+    aCMenu = createCMenu (cPeerObjGlobal);
+
+    // Add it to the menu bar.
+    [parent javaAddMenu:aCMenu atIndex:insertLocation];
+
+    // If the menu is already the help menu (because we are creating an entire
+    // menu bar) we need to note that now, because we can't rely on
+    // setHelpMenu() being called again.
+    if (isHelpMenu == JNI_TRUE) {
+        [parent javaSetHelpMenu: aCMenu];
+    }
+
+    if (aCMenu) {
+        CFRetain(aCMenu); // GC
+        [aCMenu release];
+    }
+JNF_COCOA_EXIT(env);
+    return ptr_to_jlong(aCMenu);
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CMenu
+ * Method:    nativeSetMenuTitle
+ * Signature: (JLjava/lang/String;)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenu_nativeSetMenuTitle
+(JNIEnv *env, jobject peer, jlong menuObject, jstring label)
+{
+JNF_COCOA_ENTER(env);
+    // Set the menu's title.
+    [((CMenu *)jlong_to_ptr(menuObject)) setJavaMenuTitle:JNFJavaToNSString(env, label)];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenu
+ * Method:    nativeAddSeparator
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenu_nativeAddSeparator
+(JNIEnv *env, jobject peer, jlong menuObject)
+{
+JNF_COCOA_ENTER(env);
+    // Add a separator item.
+    [((CMenu *)jlong_to_ptr(menuObject))addSeparator];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenu
+ * Method:    nativeDeleteItem
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenu_nativeDeleteItem
+(JNIEnv *env, jobject peer, jlong menuObject, jint index)
+{
+JNF_COCOA_ENTER(env);
+    // Remove the specified item.
+    [((CMenu *)jlong_to_ptr(menuObject)) deleteJavaItem: index];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenu
+ * Method:    nativeGetNSMenu
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CMenu_nativeGetNSMenu
+(JNIEnv *env, jobject peer, jlong menuObject)
+{
+    NSMenu* nsMenu = NULL;
+
+JNF_COCOA_ENTER(env);
+    nsMenu = [((CMenu *)jlong_to_ptr(menuObject)) menu];
+JNF_COCOA_EXIT(env);
+
+    // Strong retain this menu; it'll get released in Java_apple_laf_ScreenMenu_addMenuListeners
+    if (nsMenu) {
+        CFRetain(nsMenu); // GC
+    }
+
+    return ptr_to_jlong(nsMenu);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CMenuBar.h b/jdk/src/macosx/native/sun/awt/CMenuBar.h
new file mode 100644
index 0000000..93dddf1
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenuBar.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CMenuComponent.h"
+
+extern NSString *CMenuBarDidReuseItemNotification;
+
+@class CMenu;
+
+@interface CMenuBar : CMenuComponent {
+    // Menus in this menubar.  Objects in fMenuList must be CMenu's.
+    NSMutableArray *fMenuList;
+    CMenu *fHelpMenu;
+    BOOL fModallyDisabled;
+}
+- (void) nativeAddMenuAtIndex_OnAppKitThread:(NSArray *)args;
+- (void) nativeDeleteMenu_OnAppKitThread:(id)indexObj;
+
++ (void)clearMenuBarExcludingAppleMenu_OnAppKitThread:(BOOL) excludingAppleMenu;
++ (BOOL) isActiveMenuBar:(CMenuBar *)menuBar;
+- (id) initWithPeer:(jobject)peer;
++ (void) activate:(CMenuBar *)menubar modallyDisabled:(BOOL)modallyDisabled;
+- (void) deactivate;
+- (void) javaAddMenu: (CMenu *)theMenu;
+- (void) javaAddMenu: (CMenu *)theMenu atIndex:(jint)index;
+- (void) javaDeleteMenu: (jint)index;
+- (void) javaSetHelpMenu:(CMenu *)theMenu;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CMenuBar.m b/jdk/src/macosx/native/sun/awt/CMenuBar.m
new file mode 100644
index 0000000..23c7949
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenuBar.m
@@ -0,0 +1,456 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+
+#import "CMenuBar.h"
+#import "CMenu.h"
+#import "ThreadUtilities.h"
+
+#import "sun_lwawt_macosx_CMenuBar.h"
+
+__attribute__((visibility("default")))
+NSString *CMenuBarDidReuseItemNotification =
+    @"CMenuBarDidReuseItemNotification";
+
+static CMenuBar *sActiveMenuBar = nil;
+static NSMenu *sDefaultHelpMenu = nil;
+static BOOL sSetupHelpMenu = NO;
+
+@interface CMenuBar (CMenuBar_Private)
++ (void) addDefaultHelpMenu;
+@end
+
+@implementation CMenuBar
+
++ (void)clearMenuBarExcludingAppleMenu_OnAppKitThread:(BOOL) excludingAppleMenu {
+    AWT_ASSERT_APPKIT_THREAD;
+    // Remove all Java menus from the main bar.
+    NSMenu *theMainMenu = [NSApp mainMenu];
+    NSUInteger i, menuCount = [theMainMenu numberOfItems];
+
+    for (i = menuCount; i > 1; i--) {
+        NSUInteger index = i-1;
+
+        NSMenuItem *currItem = [theMainMenu itemAtIndex:index];
+        NSMenu *currMenu = [currItem submenu];
+
+        if (excludingAppleMenu && ![currMenu isJavaMenu]) {
+            continue;
+        }
+
+        [theMainMenu removeItemAtIndex:index];
+    }
+
+    [CMenuBar addDefaultHelpMenu];
+}
+
++ (BOOL) isActiveMenuBar:(CMenuBar *)inMenuBar {
+    return (sActiveMenuBar == inMenuBar);
+}
+
+- (id) initWithPeer:(jobject)peer {
+    AWT_ASSERT_APPKIT_THREAD;
+    self = [super initWithPeer: peer];
+    if (self) {
+        fMenuList = [[NSMutableArray alloc] init];
+    }
+    return self;
+}
+
+-(void) dealloc {
+    [fMenuList release];
+    fMenuList = nil;
+
+    [fHelpMenu release];
+    fHelpMenu = nil;
+
+    [super dealloc];
+}
+
++ (void) activate:(CMenuBar *)menubar modallyDisabled:(BOOL)modallyDisabled {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    if (!menubar) {
+        [CMenuBar clearMenuBarExcludingAppleMenu_OnAppKitThread:YES];
+        return;
+    }
+
+    @synchronized([CMenuBar class]) {
+        sActiveMenuBar = menubar;
+    }
+
+    @synchronized(menubar) {
+        menubar->fModallyDisabled = modallyDisabled;
+    }
+
+    NSUInteger i = 0, newMenuListSize = [menubar->fMenuList count];
+
+    NSMenu *theMainMenu = [NSApp mainMenu];
+    NSUInteger menuIndex, menuCount = [theMainMenu numberOfItems];
+
+    NSUInteger cmenuIndex = 0, cmenuCount = newMenuListSize;
+    NSMutableArray *removedMenuArray = [NSMutableArray array];
+
+    for (menuIndex = 0; menuIndex < menuCount; menuIndex++) {
+        NSMenuItem *currItem = [theMainMenu itemAtIndex:menuIndex];
+        NSMenu *currMenu = [currItem submenu];
+
+        if ([currMenu isJavaMenu]) {
+            // Ready to replace, find next candidate
+            CMenu *newMenu = nil;
+            if (cmenuIndex < cmenuCount) {
+                newMenu = (CMenu *)[menubar->fMenuList objectAtIndex:cmenuIndex];
+                if (newMenu == menubar->fHelpMenu) {
+                    cmenuIndex++;
+                    if (cmenuIndex < cmenuCount) {
+                        newMenu = (CMenu *)[menubar->fMenuList objectAtIndex:cmenuIndex];
+                    }
+                }
+            }
+            if (newMenu) {
+                NSMenu *menuToAdd = [newMenu menu];
+                if ([theMainMenu indexOfItemWithSubmenu:menuToAdd] == -1) {
+                    [[NSNotificationCenter defaultCenter] postNotificationName:CMenuBarDidReuseItemNotification object:theMainMenu];
+
+                    [currItem setSubmenu:menuToAdd];
+                    [currItem setTitle:[menuToAdd title]];
+                    cmenuIndex++;
+                }
+
+                BOOL newEnabledState = [newMenu isEnabled] && !menubar->fModallyDisabled;
+                [currItem setEnabled:newEnabledState];
+            } else {
+                [removedMenuArray addObject:[NSNumber numberWithInteger:menuIndex]];
+            }
+        }
+    }
+
+    // Clean up extra items
+    NSUInteger removedIndex, removedCount = [removedMenuArray count];
+    for (removedIndex=removedCount; removedIndex > 0; removedIndex--) {
+        [theMainMenu removeItemAtIndex:[[removedMenuArray objectAtIndex:(removedIndex-1)] integerValue]];
+    }
+
+    i = cmenuIndex;
+
+    // Add all of the menus in the menu list.
+    for (; i < newMenuListSize; i++) {
+        CMenu *newMenu = (CMenu *)[menubar->fMenuList objectAtIndex:i];
+
+        if (newMenu != menubar->fHelpMenu) {
+            NSArray *args = [NSArray arrayWithObjects:newMenu, [NSNumber numberWithInt:-1], nil];
+            [menubar nativeAddMenuAtIndex_OnAppKitThread:args];
+        }
+    }
+
+    // Add the help menu last.
+    if (menubar->fHelpMenu) {
+        NSArray *args = [NSArray arrayWithObjects:menubar->fHelpMenu, [NSNumber numberWithInt:-1], nil];
+        [menubar nativeAddMenuAtIndex_OnAppKitThread:args];
+    } else {
+        [CMenuBar addDefaultHelpMenu];
+    }
+}
+
+-(void) deactivate {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    @synchronized([CMenuBar class]) {
+        sActiveMenuBar = nil;
+    }
+
+    @synchronized(self) {
+        fModallyDisabled = NO;
+    }
+}
+
+-(void) javaAddMenu: (CMenu *)theMenu {
+    @synchronized(self) {
+        [fMenuList addObject: theMenu];
+    }
+
+    if (self == sActiveMenuBar) {
+        NSArray *args = [[NSArray alloc] initWithObjects:theMenu, [NSNumber numberWithInt:-1], nil];
+        [ThreadUtilities performOnMainThread:@selector(nativeAddMenuAtIndex_OnAppKitThread:) onObject:self withObject:args waitUntilDone:YES awtMode:YES];
+        [args release];
+    }
+}
+
+// This method is a special case for use by the screen menu bar.
+// See ScreenMenuBar.java -- used to implement setVisible(boolean) by
+// removing or adding the menu from the current menu bar's list.
+-(void) javaAddMenu: (CMenu *)theMenu atIndex:(jint)index {
+    @synchronized(self) {
+        if (index == -1){
+            [fMenuList addObject:theMenu];
+        }else{
+            [fMenuList insertObject:theMenu atIndex:index];
+        }
+    }
+
+    if (self == sActiveMenuBar) {
+        NSArray *args = [[NSArray alloc] initWithObjects:theMenu, [NSNumber numberWithInt:index], nil];
+        [ThreadUtilities performOnMainThread:@selector(nativeAddMenuAtIndex_OnAppKitThread:) onObject:self withObject:args waitUntilDone:YES awtMode:YES];
+        [args release];
+    }
+}
+
+- (NSInteger) javaIndexToNSMenuIndex_OnAppKitThread:(jint)javaIndex {
+    AWT_ASSERT_APPKIT_THREAD;
+    NSInteger returnValue = -1;
+    NSMenu *theMainMenu = [NSApp mainMenu];
+
+    if (javaIndex == -1) {
+        if (fHelpMenu) {
+            returnValue = [theMainMenu indexOfItemWithSubmenu:[fHelpMenu menu]];
+        }
+    } else {
+        CMenu *requestedMenu = [fMenuList objectAtIndex:javaIndex];
+
+        if (requestedMenu == fHelpMenu) {
+            returnValue = [theMainMenu indexOfItemWithSubmenu:[fHelpMenu menu]];
+        } else {
+            NSUInteger i, menuCount = [theMainMenu numberOfItems];
+            jint currJavaMenuIndex = 0;
+            for (i = 0; i < menuCount; i++) {
+                NSMenuItem *currItem = [theMainMenu itemAtIndex:i];
+                NSMenu *currMenu = [currItem submenu];
+
+                if ([currMenu isJavaMenu]) {
+                    if (javaIndex == currJavaMenuIndex) {
+                        returnValue = i;
+                        break;
+                    }
+
+                    currJavaMenuIndex++;
+                }
+            }
+        }
+    }
+
+    return returnValue;
+}
+
+- (void) nativeAddMenuAtIndex_OnAppKitThread:(NSArray *)args {
+    AWT_ASSERT_APPKIT_THREAD;
+    CMenu *theNewMenu = (CMenu*)[args objectAtIndex:0];
+    jint index = [(NSNumber*)[args objectAtIndex:1] intValue];
+    NSApplication *theApp = [NSApplication sharedApplication];
+    NSMenu *theMainMenu = [theApp mainMenu];
+    NSMenu *menuToAdd = [theNewMenu menu];
+
+    if ([theMainMenu indexOfItemWithSubmenu:menuToAdd] == -1) {
+        NSMenuItem *newItem = [[NSMenuItem alloc] init];
+        [newItem setSubmenu:[theNewMenu menu]];
+        [newItem setTitle:[[theNewMenu menu] title]];
+
+        NSInteger nsMenuIndex = [self javaIndexToNSMenuIndex_OnAppKitThread:index];
+
+        if (nsMenuIndex == -1) {
+            [theMainMenu addItem:newItem];
+        } else {
+            [theMainMenu insertItem:newItem atIndex:nsMenuIndex];
+        }
+
+        BOOL newEnabledState = [theNewMenu isEnabled] && !fModallyDisabled;
+        [newItem setEnabled:newEnabledState];
+        [newItem release];
+    }
+}
+
+- (void) javaDeleteMenu: (jint)index {
+    if (self == sActiveMenuBar) {
+        [ThreadUtilities performOnMainThread:@selector(nativeDeleteMenu_OnAppKitThread:) onObject:self withObject:[NSNumber numberWithInt:index] waitUntilDone:YES awtMode:YES];
+    }
+
+    @synchronized(self) {
+        CMenu *menuToRemove = [fMenuList objectAtIndex:index];
+
+        if (menuToRemove == fHelpMenu) {
+            [fHelpMenu release];
+            fHelpMenu = nil;
+        }
+
+        [fMenuList removeObjectAtIndex:index];
+    }
+}
+
+- (void) nativeDeleteMenu_OnAppKitThread:(id)indexObj {
+    AWT_ASSERT_APPKIT_THREAD;
+    NSApplication *theApp = [NSApplication sharedApplication];
+    NSMenu *theMainMenu = [theApp mainMenu];
+    jint menuToRemove = [(NSNumber *)indexObj intValue];
+    NSInteger nsMenuToRemove = [self javaIndexToNSMenuIndex_OnAppKitThread:menuToRemove];
+
+    if (nsMenuToRemove != -1) {
+        [theMainMenu removeItemAtIndex:nsMenuToRemove];
+    }
+}
+
+- (void) javaSetHelpMenu:(CMenu *)theMenu {
+    @synchronized(self) {
+        [theMenu retain];
+        [fHelpMenu release];
+        fHelpMenu = theMenu;
+    }
+}
+
++ (void) addDefaultHelpMenu {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    // Look for a help book tag. If it's there, add the help menu.
+    @synchronized ([CMenuBar class]) {
+        if (!sSetupHelpMenu) {
+            if (sDefaultHelpMenu == nil) {
+                // If we are embedded, don't make a help menu.
+                // TODO(cpc): we don't have NSApplicationAWT yet...
+                //if (![NSApp isKindOfClass:[NSApplicationAWT class]]) {
+                //    sSetupHelpMenu = YES;
+                //    return;
+                //}
+
+                // If the developer specified a NIB, don't make a help menu.
+                // TODO(cpc): usingDefaultNib only defined on NSApplicationAWT
+                //if (![NSApp usingDefaultNib]) {
+                //    sSetupHelpMenu = YES;
+                //    return;
+                //}
+
+            // TODO: not implemented
+            }
+
+            sSetupHelpMenu = YES;
+        }
+    }
+
+    if (sDefaultHelpMenu) {
+        NSMenu *theMainMenu = [NSApp mainMenu];
+
+        if ([theMainMenu indexOfItemWithSubmenu:sDefaultHelpMenu] == -1) {
+            // Since we're re-using this NSMenu, we need to clear its parent before
+            // adding it to a new menu item, or else AppKit will complain.
+            [sDefaultHelpMenu setSupermenu:nil];
+
+            // Add the help menu to the main menu.
+            NSMenuItem *newItem = [[NSMenuItem alloc] init];
+            [newItem setSubmenu:sDefaultHelpMenu];
+            [newItem setTitle:[sDefaultHelpMenu title]];
+            [theMainMenu addItem:newItem];
+
+            // Release it so the main menu owns it.
+            [newItem release];
+        }
+    }
+}
+
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuBar
+ * Method:    nativeCreateMenuBar
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CMenuBar_nativeCreateMenuBar
+    (JNIEnv *env, jobject peer)
+{
+    CMenuBar *aCMenuBar = nil;
+    JNF_COCOA_ENTER(env);
+
+    jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
+
+    // We use an array here only to be able to get a return value
+    NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], nil];
+
+    [ThreadUtilities performOnMainThread:@selector(_create_OnAppKitThread:) onObject:[CMenuBar alloc] withObject:args waitUntilDone:YES awtMode:YES];
+
+    aCMenuBar = (CMenuBar *)[args objectAtIndex: 0];
+
+    if (aCMenuBar == nil) {
+        return 0L;
+    }
+
+    // [args release];
+
+    // A strange memory managment after that.
+
+
+    JNF_COCOA_EXIT(env);
+    if (aCMenuBar) {
+        CFRetain(aCMenuBar); // GC
+        [aCMenuBar release];
+    }
+    return ptr_to_jlong(aCMenuBar);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuBar
+ * Method:    nativeAddAtIndex
+ * Signature: (JJI)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuBar_nativeAddAtIndex
+    (JNIEnv *env, jobject peer,
+     jlong menuBarObject, jlong menuObject, jint index)
+{
+    JNF_COCOA_ENTER(env);
+    // Remove the specified item.
+    [((CMenuBar *) jlong_to_ptr(menuBarObject)) javaAddMenu:(CMenu *) jlong_to_ptr(menuObject) atIndex:index];
+    JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuBar
+ * Method:    nativeDelMenu
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuBar_nativeDelMenu
+    (JNIEnv *env, jobject peer, jlong menuBarObject, jint index)
+{
+    JNF_COCOA_ENTER(env);
+    // Remove the specified item.
+    [((CMenuBar *) jlong_to_ptr(menuBarObject)) javaDeleteMenu: index];
+    JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuBar
+ * Method:    nativeSetHelpMenu
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuBar_nativeSetHelpMenu
+    (JNIEnv *env, jobject peer, jlong menuBarObject, jlong menuObject)
+{
+    JNF_COCOA_ENTER(env);
+    // Remove the specified item.
+    [((CMenuBar *) jlong_to_ptr(menuBarObject)) javaSetHelpMenu: ((CMenu *)jlong_to_ptr(menuObject))];
+    JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CMenuComponent.h b/jdk/src/macosx/native/sun/awt/CMenuComponent.h
new file mode 100644
index 0000000..2e0a645
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenuComponent.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import <JavaVM/jni.h>
+
+@interface CMenuComponent : NSObject {
+
+@public
+    jobject fPeer;
+}
+
+// Setup
+- (id) initWithPeer:(jobject)peer;
+- (void) disposer;
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CMenuComponent.m b/jdk/src/macosx/native/sun/awt/CMenuComponent.m
new file mode 100644
index 0000000..9787625
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenuComponent.m
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CMenuComponent.h"
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "ThreadUtilities.h"
+
+@class CMenuItem;
+
+@implementation CMenuComponent
+
+-(id) initWithPeer:(jobject)peer {
+    self = [super init];
+    if (self) {
+        // the peer has been made clobal ref before
+        fPeer = peer;
+    }
+    return self;
+}
+
+-(void) cleanup {
+    // Used by subclasses
+}
+
+-(void) disposer {
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+    JNFDeleteGlobalRef(env, fPeer);
+    fPeer = NULL;
+
+    [self cleanup];
+
+    CFRelease(self); // GC
+}
+
+// The method is used by all subclasses, since the process of the creation
+// is the same. The only exception is the CMenuItem class.
+- (void) _create_OnAppKitThread: (NSMutableArray *)argValue {
+    jobject cPeerObjGlobal = (jobject)[[argValue objectAtIndex: 0] pointerValue];
+    CMenuItem *aCMenuItem = [self initWithPeer:cPeerObjGlobal];
+    [argValue removeAllObjects];
+    [argValue addObject: aCMenuItem];
+}
+
+//-(void) dealloc { [super dealloc]; }
+//- (void)finalize { [super finalize]; }
+
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuComponent
+ * Method:    nativeDispose
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuComponent_nativeDispose
+(JNIEnv *env, jobject peer, jlong menuItemObj)
+{
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThread:@selector(disposer)
+                                 on:((id)jlong_to_ptr(menuItemObj))
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CMenuItem.h b/jdk/src/macosx/native/sun/awt/CMenuItem.h
new file mode 100644
index 0000000..4d92e07
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenuItem.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CMenuComponent.h"
+
+@interface CMenuItem : CMenuComponent {
+    NSMenuItem *fMenuItem;
+    BOOL fIsCheckbox;
+    BOOL fIsEnabled;
+}
+
+// Setup
+- (id) initWithPeer:(jobject)peer asSeparator: (NSNumber *) asSeparator;
+- (void) setIsCheckbox;
+
+// Events
+- (void) handleAction:(NSMenuItem *) sender;
+
+- (void) setJavaLabel:(NSString *)theLabel
+             shortcut:(NSString *)theKeyEquivalent
+         modifierMask:(jint)modifiers;
+
+- (void) setJavaImage:(NSImage *)theImage;
+- (void) setJavaToolTipText:(NSString *)theText;
+- (void) setJavaEnabled:(BOOL) enabled;
+- (void) setJavaState:(BOOL)newState;
+- (void) addNSMenuItemToMenu:(NSMenu *)inMenu;
+- (NSMenuItem *)menuItem;
+- (BOOL) isEnabled;
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CMenuItem.m b/jdk/src/macosx/native/sun/awt/CMenuItem.m
new file mode 100644
index 0000000..ca81685
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CMenuItem.m
@@ -0,0 +1,469 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CMenuItem.h"
+#import "CMenu.h"
+#import "AWTEvent.h"
+#import "ThreadUtilities.h"
+
+#import "java_awt_Event.h"
+#import "java_awt_event_KeyEvent.h"
+#import "sun_lwawt_macosx_CMenuItem.h"
+
+#define NOT_A_CHECKBOXMENU -2
+
+
+@implementation CMenuItem
+
+- (id) initWithPeer:(jobject)peer asSeparator: (NSNumber *) asSeparator{
+AWT_ASSERT_APPKIT_THREAD;
+    self = [super initWithPeer:peer];
+    if (self) {
+        if ([asSeparator boolValue]) {
+            fMenuItem = (NSMenuItem*)[NSMenuItem separatorItem];
+            [fMenuItem retain];
+        } else {
+            fMenuItem = [[NSMenuItem alloc] init];
+            [fMenuItem setAction:@selector(handleAction:)];
+            [fMenuItem setTarget:self];
+        }
+        fIsCheckbox = NO;
+        fIsEnabled = YES;
+    }
+    return self;
+}
+
+// This is because NSApplication doesn't check the target's window when sending
+// actions; they only check the target itself.  We always return YES,
+// since we shouldn't even be installed unless our window is active.
+- (BOOL) worksWhenModal {
+    return YES;
+}
+
+// Events
+- (void)handleAction:(NSMenuItem *)sender {
+AWT_ASSERT_APPKIT_THREAD;
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+JNF_COCOA_ENTER(env);
+
+    if (fIsCheckbox) {
+        static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
+        static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
+
+        // Send the opposite of what's currently checked -- the action
+        // indicates what state we're going to.
+        NSInteger state = [sender state];
+        jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE);
+        JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
+    } else {
+        static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
+        static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
+
+        NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
+        NSUInteger modifiers = [currEvent modifierFlags];
+        jint javaModifiers = 0;
+
+        if ((modifiers & NSCommandKeyMask) != 0)   javaModifiers |= java_awt_Event_META_MASK;
+        if ((modifiers & NSShiftKeyMask) != 0)     javaModifiers |= java_awt_Event_SHIFT_MASK;
+        if ((modifiers & NSControlKeyMask) != 0)   javaModifiers |= java_awt_Event_CTRL_MASK;
+        if ((modifiers & NSAlternateKeyMask) != 0) javaModifiers |= java_awt_Event_ALT_MASK;
+
+        JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
+    }
+JNF_COCOA_EXIT(env);
+}
+
+- (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString *)theKeyEquivalent modifierMask:(jint)modifiers {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    NSUInteger modifierMask = 0;
+
+    if (![theKeyEquivalent isEqualToString:@""]) {
+        // Force the key equivalent to lower case if not using the shift key.
+        // Otherwise AppKit will draw a Shift glyph in the menu.
+        if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) == 0) {
+            theKeyEquivalent = [theKeyEquivalent lowercaseString];
+        }
+
+        // Hack for the question mark -- SHIFT and / means use the question mark.
+        if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0 &&
+            [theKeyEquivalent isEqualToString:@"/"])
+        {
+            theKeyEquivalent = @"?";
+            modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;
+        }
+
+        if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0) modifierMask |= NSShiftKeyMask;
+        if ((modifiers & java_awt_event_KeyEvent_CTRL_MASK) != 0)  modifierMask |= NSControlKeyMask;
+        if ((modifiers & java_awt_event_KeyEvent_ALT_MASK) != 0)   modifierMask |= NSAlternateKeyMask;
+        if ((modifiers & java_awt_event_KeyEvent_META_MASK) != 0)  modifierMask |= NSCommandKeyMask;
+    }
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        if (![theKeyEquivalent isEqualToString:@""]) {
+            [fMenuItem setKeyEquivalent:theKeyEquivalent];
+            [fMenuItem setKeyEquivalentModifierMask:modifierMask];
+        }
+        [fMenuItem setTitle:theLabel];
+    }];
+}
+
+- (void) setJavaImage:(NSImage *)theImage {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [fMenuItem setImage:theImage];
+    }];
+}
+
+- (void) setJavaToolTipText:(NSString *)theText {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        [fMenuItem setToolTip:theText];
+    }];
+}
+
+
+- (void)setJavaEnabled:(BOOL) enabled {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        @synchronized(self) {
+            fIsEnabled = enabled;
+
+            // Warning:  This won't work if the parent menu is disabled.
+            // See [CMenu syncFromJava]. We still need to call it here so
+            // the NSMenuItem itself gets properly updated.
+            [fMenuItem setEnabled:fIsEnabled];
+        }
+    }];
+}
+
+- (BOOL)isEnabled {
+    // AWT_ASSERT_ANY_THREAD;
+
+    BOOL enabled = NO;
+    @synchronized(self) {
+        enabled = fIsEnabled;
+    }
+    return enabled;
+}
+
+
+- (void)setJavaState:(BOOL)newState {
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+AWT_ASSERT_APPKIT_THREAD;
+
+        [fMenuItem setState:(newState ? NSOnState : NSOffState)];
+    }];
+}
+
+- (void)cleanup {
+    [fMenuItem setAction:NULL];
+    [fMenuItem setTarget:nil];
+}
+
+- (void)dealloc {
+    [fMenuItem release];
+    fMenuItem = nil;
+
+    [super dealloc];
+}
+
+- (void)addNSMenuItemToMenu:(NSMenu *)inMenu {
+    [inMenu addItem:fMenuItem];
+}
+
+- (NSMenuItem *)menuItem {
+    return [[fMenuItem retain] autorelease];
+}
+
+- (void)setIsCheckbox {
+    fIsCheckbox = YES;
+}
+
+- (void) _createMenuItem_OnAppKitThread: (NSMutableArray *)argValue {
+    jobject cPeerObjGlobal = (jobject)[[argValue objectAtIndex: 0] pointerValue];
+    NSNumber * asSeparator = (NSNumber *)[argValue objectAtIndex: 1];
+    CMenuItem *aCMenuItem = [self initWithPeer: cPeerObjGlobal asSeparator: asSeparator];
+    [argValue removeAllObjects];
+    [argValue addObject: aCMenuItem];
+}
+
+- (NSString *)description {
+    return [NSString stringWithFormat:@"CMenuItem[ %@ ]", fMenuItem];
+}
+
+@end
+
+/** Convert a Java keycode for SetMenuItemCmd */
+static unichar AWTKeyToMacShortcut(jint awtKey, BOOL doShift) {
+    unichar macKey = 0;
+
+    if ((awtKey >= java_awt_event_KeyEvent_VK_0 && awtKey <= java_awt_event_KeyEvent_VK_9) ||
+        (awtKey >= java_awt_event_KeyEvent_VK_A && awtKey <= java_awt_event_KeyEvent_VK_Z))
+    {
+        // These ranges are the same in ASCII
+        macKey = awtKey;
+    } else if (awtKey >= java_awt_event_KeyEvent_VK_F1 && awtKey <= java_awt_event_KeyEvent_VK_F12) {
+        // Support for F1 - F12 has been around since Java 1.0 and fall into a lower range.
+        macKey = awtKey - java_awt_event_KeyEvent_VK_F1 + NSF1FunctionKey;
+    } else if (awtKey >= java_awt_event_KeyEvent_VK_F13 && awtKey <= java_awt_event_KeyEvent_VK_F24) {
+        // Support for F13-F24 came in Java 1.2 and are at a different range.
+        macKey = awtKey - java_awt_event_KeyEvent_VK_F13 + NSF13FunctionKey;
+    } else {
+        // Special characters
+        switch (awtKey) {
+        case java_awt_event_KeyEvent_VK_BACK_QUOTE      : macKey = '`'; break;
+        case java_awt_event_KeyEvent_VK_QUOTE           : macKey = '\''; break;
+
+        case java_awt_event_KeyEvent_VK_ESCAPE          : macKey = 0x1B; break;
+//        case java_awt_event_KeyEvent_VK_SPACE           : macKey = kMenuSpaceGlyph; break;
+        case java_awt_event_KeyEvent_VK_PAGE_UP         : macKey = NSPageUpFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_PAGE_DOWN       : macKey = NSPageDownFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_END             : macKey = NSEndFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_HOME            : macKey = NSHomeFunctionKey; break;
+
+        case java_awt_event_KeyEvent_VK_LEFT            : macKey = NSLeftArrowFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_UP              : macKey = NSUpArrowFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_RIGHT           : macKey = NSRightArrowFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_DOWN            : macKey = NSDownArrowFunctionKey; break;
+
+        case java_awt_event_KeyEvent_VK_COMMA           : macKey = ','; break;
+
+        // Mac OS doesn't distinguish between the two '-' keys...
+        case java_awt_event_KeyEvent_VK_MINUS           :
+        case java_awt_event_KeyEvent_VK_SUBTRACT        : macKey = '-'; break;
+
+        // or the two '.' keys...
+        case java_awt_event_KeyEvent_VK_DECIMAL         :
+        case java_awt_event_KeyEvent_VK_PERIOD          : macKey = '.'; break;
+
+        // or the two '/' keys.
+        case java_awt_event_KeyEvent_VK_DIVIDE          :
+        case java_awt_event_KeyEvent_VK_SLASH           : macKey = '/'; break;
+
+        case java_awt_event_KeyEvent_VK_SEMICOLON       : macKey = ';'; break;
+        case java_awt_event_KeyEvent_VK_EQUALS          : macKey = '='; break;
+
+        case java_awt_event_KeyEvent_VK_OPEN_BRACKET    : macKey = '['; break;
+        case java_awt_event_KeyEvent_VK_BACK_SLASH      : macKey = '\\'; break;
+        case java_awt_event_KeyEvent_VK_CLOSE_BRACKET   : macKey = ']'; break;
+
+        case java_awt_event_KeyEvent_VK_MULTIPLY        : macKey = '*'; break;
+        case java_awt_event_KeyEvent_VK_ADD             : macKey = '+'; break;
+
+        case java_awt_event_KeyEvent_VK_HELP            : macKey = NSHelpFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_TAB             : macKey = NSTabCharacter; break;
+        case java_awt_event_KeyEvent_VK_ENTER           : macKey = NSCarriageReturnCharacter; break;
+        case java_awt_event_KeyEvent_VK_BACK_SPACE      : macKey = NSBackspaceCharacter; break;
+        case java_awt_event_KeyEvent_VK_DELETE          : macKey = NSDeleteCharacter; break;
+        case java_awt_event_KeyEvent_VK_CLEAR           : macKey = NSClearDisplayFunctionKey; break;
+        case java_awt_event_KeyEvent_VK_AMPERSAND       : macKey = '&'; break;
+        case java_awt_event_KeyEvent_VK_ASTERISK        : macKey = '*'; break;
+        case java_awt_event_KeyEvent_VK_QUOTEDBL        : macKey = '\"'; break;
+        case java_awt_event_KeyEvent_VK_LESS            : macKey = '<'; break;
+        case java_awt_event_KeyEvent_VK_GREATER         : macKey = '>'; break;
+        case java_awt_event_KeyEvent_VK_BRACELEFT       : macKey = '{'; break;
+        case java_awt_event_KeyEvent_VK_BRACERIGHT      : macKey = '}'; break;
+        case java_awt_event_KeyEvent_VK_AT              : macKey = '@'; break;
+        case java_awt_event_KeyEvent_VK_COLON           : macKey = ':'; break;
+        case java_awt_event_KeyEvent_VK_CIRCUMFLEX      : macKey = '^'; break;
+        case java_awt_event_KeyEvent_VK_DOLLAR          : macKey = '$'; break;
+        case java_awt_event_KeyEvent_VK_EXCLAMATION_MARK : macKey = '!'; break;
+        case java_awt_event_KeyEvent_VK_LEFT_PARENTHESIS : macKey = '('; break;
+        case java_awt_event_KeyEvent_VK_NUMBER_SIGN     : macKey = '#'; break;
+        case java_awt_event_KeyEvent_VK_PLUS            : macKey = '+'; break;
+        case java_awt_event_KeyEvent_VK_RIGHT_PARENTHESIS: macKey = ')'; break;
+        case java_awt_event_KeyEvent_VK_UNDERSCORE      : macKey = '_'; break;
+        }
+    }
+    return macKey;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuItem
+ * Method:    nativeSetLabel
+ * Signature: (JLjava/lang/String;CII)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuItem_nativeSetLabel
+(JNIEnv *env, jobject peer,
+     jlong menuItemObj, jstring label,
+     jchar shortcutKey, jint shortcutKeyCode, jint mods)
+{
+JNF_COCOA_ENTER(env);
+    NSString *theLabel = JNFJavaToNSString(env, label);
+    NSString *theKeyEquivalent = nil;
+    unichar macKey = shortcutKey;
+
+    if (macKey == 0) {
+        macKey = AWTKeyToMacShortcut(shortcutKeyCode, (mods & java_awt_event_KeyEvent_SHIFT_MASK) != 0);
+    }
+
+    if (macKey != 0) {
+        unichar equivalent[1] = {macKey};
+        theKeyEquivalent = [NSString stringWithCharacters:equivalent length:1];
+    } else {
+        theKeyEquivalent = @"";
+    }
+
+    [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaLabel:theLabel shortcut:theKeyEquivalent modifierMask:mods];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuItem
+ * Method:    nativeSetTooltip
+ * Signature: (JLjava/lang/String;)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuItem_nativeSetTooltip
+(JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip)
+{
+JNF_COCOA_ENTER(env);
+    NSString *theTooltip = JNFJavaToNSString(env, tooltip);
+    [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     apple_awt_CMenuItem
+ * Method:    nativeSetImage
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuItem_nativeSetImage
+(JNIEnv *env, jobject peer, jlong menuItemObj, jlong image)
+{
+JNF_COCOA_ENTER(env);
+    [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaImage:(NSImage*)jlong_to_ptr(image)];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuItem
+ * Method:    nativeCreate
+ * Signature: (JZ)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CMenuItem_nativeCreate
+    (JNIEnv *env, jobject peer, jlong parentCMenuObj, jboolean isSeparator)
+{
+
+    CMenuItem *aCMenuItem = nil;
+    CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj);
+JNF_COCOA_ENTER(env);
+
+    jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
+
+    NSMutableArray *args = nil;
+
+    // Create a new item....
+    if (isSeparator == JNI_TRUE) {
+        args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], [NSNumber numberWithBool:YES],  nil];
+    } else {
+        args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], [NSNumber numberWithBool:NO],  nil];
+    }
+
+    [ThreadUtilities performOnMainThread:@selector(_createMenuItem_OnAppKitThread:) onObject:[CMenuItem alloc] withObject:args waitUntilDone:YES awtMode:YES];
+
+    aCMenuItem = (CMenuItem *)[args objectAtIndex: 0];
+
+    if (aCMenuItem == nil) {
+        return 0L;
+    }
+
+    // and add it to the parent item.
+    [parentCMenu addJavaMenuItem: aCMenuItem];
+
+    // setLabel will be called after creation completes.
+
+    if (aCMenuItem) {
+        CFRetain(aCMenuItem); // GC
+        [aCMenuItem release];
+    }
+
+JNF_COCOA_EXIT(env);
+    return ptr_to_jlong(aCMenuItem);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CMenuItem
+ * Method:    nativeSetEnabled
+ * Signature: (JZ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CMenuItem_nativeSetEnabled
+(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean enable)
+{
+JNF_COCOA_ENTER(env);
+    CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
+    [item setJavaEnabled: (enable == JNI_TRUE)];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CCheckboxMenuItem
+ * Method:    nativeSetState
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetState
+(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean state)
+{
+JNF_COCOA_ENTER(env);
+    CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
+    [item setJavaState: (state == JNI_TRUE)];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CCheckboxMenuItem
+ * Method:    nativeSetState
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetIsCheckbox
+(JNIEnv *env, jobject peer, jlong menuItemObj)
+{
+JNF_COCOA_ENTER(env);
+    CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
+    [item setIsCheckbox];
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CPopupMenu.h b/jdk/src/macosx/native/sun/awt/CPopupMenu.h
new file mode 100644
index 0000000..87ad0c7
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CPopupMenu.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CMenu.h"
+
+@interface CPopupMenu : CMenu {}
+
+//steal from CMenu.h:
+- (id) initWithPeer:(jobject)peer;
+
+@end //implementationCPopupMenu : CMenu
diff --git a/jdk/src/macosx/native/sun/awt/CPopupMenu.m b/jdk/src/macosx/native/sun/awt/CPopupMenu.m
new file mode 100644
index 0000000..49f4ceb
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CPopupMenu.m
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "AWTWindow.h"
+#import "AWTView.h"
+#import "CPopupMenu.h"
+#import "ThreadUtilities.h"
+#import "LWCToolkit.h"
+#import "GeomUtilities.h"
+
+@implementation CPopupMenu
+
+- (id) initWithPeer:(jobject)peer {
+    self = [super initWithPeer:peer];
+    if (self == nil) {
+        // TODO: not implemented
+    }
+    return self;
+}
+
+- (NSString *)description {
+    return [NSString stringWithFormat:@"CMenuItem[ %@ ]", fMenuItem];
+}
+
+@end // implementationCPopupMenu : CMenu
+
+
+  /*
+   * Class:     sun_lwawt_macosx_CPopupMenu
+   * Method:    nativeCreatePopupMenu
+   * Signature: (JII)J
+   */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPopupMenu_nativeCreatePopupMenu
+(JNIEnv *env, jobject peer) {
+
+    __block CPopupMenu *aCPopupMenu = nil;
+
+JNF_COCOA_ENTER(env);
+
+    jobject cPeerObjGlobal = JNFNewGlobalRef(env, peer);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        aCPopupMenu = [[CPopupMenu alloc] initWithPeer:cPeerObjGlobal];
+        CFRetain(aCPopupMenu);
+        [aCPopupMenu release];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(aCPopupMenu);
+}
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPopupMenu_nativeShowPopupMenu
+(JNIEnv *env, jobject peer, jlong menuPtr, jint x, jint y) {
+
+    JNF_COCOA_ENTER(env);
+
+    CPopupMenu* cPopupMenu = (CPopupMenu*)jlong_to_ptr(menuPtr);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        NSPoint loc = ConvertNSScreenPoint(env, NSMakePoint(x, y));
+
+        [[cPopupMenu menu] popUpMenuPositioningItem: nil
+                                         atLocation: loc
+                                             inView: nil];
+    }];
+
+    JNF_COCOA_EXIT(env);
+
+}
+
diff --git a/jdk/src/macosx/native/sun/awt/CPrinterJob.m b/jdk/src/macosx/native/sun/awt/CPrinterJob.m
new file mode 100644
index 0000000..52976f3
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CPrinterJob.m
@@ -0,0 +1,661 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+#import "java_awt_print_PageFormat.h"
+#import "java_awt_print_Pageable.h"
+#import "sun_lwawt_macosx_CPrinterJob.h"
+#import "sun_lwawt_macosx_CPrinterPageDialog.h"
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "PrinterView.h"
+#import "PrintModel.h"
+#import "ThreadUtilities.h"
+#import "GeomUtilities.h"
+
+static JNF_CLASS_CACHE(sjc_Paper, "java/awt/print/Paper");
+static JNF_CLASS_CACHE(sjc_PageFormat, "java/awt/print/PageFormat");
+static JNF_CLASS_CACHE(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob");
+static JNF_CLASS_CACHE(sjc_CPrinterDialog, "sun/lwawt/macosx/CPrinterDialog");
+static JNF_MEMBER_CACHE(sjm_getNSPrintInfo, sjc_CPrinterJob, "getNSPrintInfo", "()J");
+static JNF_MEMBER_CACHE(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;");
+
+static NSPrintInfo* createDefaultNSPrintInfo();
+
+static void makeBestFit(NSPrintInfo* src);
+
+static void nsPrintInfoToJavaPaper(JNIEnv* env, NSPrintInfo* src, jobject dst);
+static void javaPaperToNSPrintInfo(JNIEnv* env, jobject src, NSPrintInfo* dst);
+
+static void nsPrintInfoToJavaPageFormat(JNIEnv* env, NSPrintInfo* src, jobject dst);
+static void javaPageFormatToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageFormat, NSPrintInfo* dst);
+
+static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable);
+static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst);
+
+
+static NSPrintInfo* createDefaultNSPrintInfo(JNIEnv* env, jstring printer)
+{
+    NSPrintInfo* defaultPrintInfo = [[NSPrintInfo sharedPrintInfo] copy];
+    if (printer != NULL)
+    {
+        NSPrinter* nsPrinter = [NSPrinter printerWithName:JNFJavaToNSString(env, printer)];
+        if (nsPrinter != nil)
+        {
+            [defaultPrintInfo setPrinter:nsPrinter];
+        }
+    }
+    [defaultPrintInfo setUpPrintOperationDefaultValues];
+
+    // cmc 05/18/04 radr://3160443 : setUpPrintOperationDefaultValues sets the
+    // page margins to 72, 72, 90, 90 - need to use [NSPrintInfo imageablePageBounds]
+    // to get values from the printer.
+    // NOTE: currently [NSPrintInfo imageablePageBounds] does not update itself when
+    // the user selects a different printer - see radr://3657453. However, rather than
+    // directly querying the PPD here, we'll let AppKit printing do the work. The AppKit
+    // printing bug above is set to be fixed for Tiger.
+    NSRect imageableRect = [defaultPrintInfo imageablePageBounds];
+    [defaultPrintInfo setLeftMargin: imageableRect.origin.x];
+    [defaultPrintInfo setBottomMargin: imageableRect.origin.y]; //top and bottom are flipped because [NSPrintInfo imageablePageBounds] returns a flipped NSRect (bottom-left to top-right).
+    [defaultPrintInfo setRightMargin: [defaultPrintInfo paperSize].width-imageableRect.origin.x-imageableRect.size.width];
+    [defaultPrintInfo setTopMargin: [defaultPrintInfo paperSize].height-imageableRect.origin.y-imageableRect.size.height];
+
+    return defaultPrintInfo;
+}
+
+static void makeBestFit(NSPrintInfo* src)
+{
+    // This will look at the NSPrintInfo's margins. If they are out of bounds to the
+    // imageable area of the page, it will set them to the largest possible size.
+
+    NSRect imageable = [src imageablePageBounds];
+
+    NSSize paperSize = [src paperSize];
+
+    CGFloat fullLeftM = imageable.origin.x;
+    CGFloat fullRightM = paperSize.width - (imageable.origin.x + imageable.size.width);
+
+    // These are flipped because [NSPrintInfo imageablePageBounds] returns a flipped
+    //  NSRect (bottom-left to top-right).
+    CGFloat fullTopM = paperSize.height - (imageable.origin.y + imageable.size.height);
+    CGFloat fullBottomM = imageable.origin.y;
+
+    if (fullLeftM > [src leftMargin])
+    {
+        [src setLeftMargin:fullLeftM];
+    }
+
+    if (fullRightM > [src rightMargin])
+    {
+        [src setRightMargin:fullRightM];
+    }
+
+    if (fullTopM > [src topMargin])
+    {
+        [src setTopMargin:fullTopM];
+    }
+
+    if (fullBottomM > [src bottomMargin])
+    {
+        [src setBottomMargin:fullBottomM];
+    }
+}
+
+// In AppKit Printing, the rectangle is always oriented. In AppKit Printing, setting
+//  the rectangle will always set the orientation.
+// In java printing, the rectangle is oriented if accessed from PageFormat. It is
+//  not oriented when accessed from Paper.
+
+static void nsPrintInfoToJavaPaper(JNIEnv* env, NSPrintInfo* src, jobject dst)
+{
+    static JNF_MEMBER_CACHE(jm_setSize, sjc_Paper, "setSize", "(DD)V");
+    static JNF_MEMBER_CACHE(jm_setImageableArea, sjc_Paper, "setImageableArea", "(DDDD)V");
+
+    jdouble jPaperW, jPaperH;
+
+    // NSPrintInfo paperSize is oriented. java Paper is not oriented. Take
+    //  the -[NSPrintInfo orientation] into account when setting the Paper
+    //  rectangle.
+
+    NSSize paperSize = [src paperSize];
+    switch ([src orientation]) {
+        case NSPortraitOrientation:
+            jPaperW = paperSize.width;
+            jPaperH = paperSize.height;
+            break;
+
+        case NSLandscapeOrientation:
+            jPaperW = paperSize.height;
+            jPaperH = paperSize.width;
+            break;
+
+        default:
+            jPaperW = paperSize.width;
+            jPaperH = paperSize.height;
+            break;
+    }
+
+    JNFCallVoidMethod(env, dst, jm_setSize, jPaperW, jPaperH); // AWT_THREADING Safe (known object - always actual Paper)
+
+    // Set the imageable area from the margins
+    CGFloat leftM = [src leftMargin];
+    CGFloat rightM = [src rightMargin];
+    CGFloat topM = [src topMargin];
+    CGFloat bottomM = [src bottomMargin];
+
+    jdouble jImageX = leftM;
+    jdouble jImageY = topM;
+    jdouble jImageW = jPaperW - (leftM + rightM);
+    jdouble jImageH = jPaperH - (topM + bottomM);
+
+    JNFCallVoidMethod(env, dst, jm_setImageableArea, jImageX, jImageY, jImageW, jImageH); // AWT_THREADING Safe (known object - always actual Paper)
+}
+
+static void javaPaperToNSPrintInfo(JNIEnv* env, jobject src, NSPrintInfo* dst)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_getWidth, sjc_Paper, "getWidth", "()D");
+    static JNF_MEMBER_CACHE(jm_getHeight, sjc_Paper, "getHeight", "()D");
+    static JNF_MEMBER_CACHE(jm_getImageableX, sjc_Paper, "getImageableX", "()D");
+    static JNF_MEMBER_CACHE(jm_getImageableY, sjc_Paper, "getImageableY", "()D");
+    static JNF_MEMBER_CACHE(jm_getImageableW, sjc_Paper, "getImageableWidth", "()D");
+    static JNF_MEMBER_CACHE(jm_getImageableH, sjc_Paper, "getImageableHeight", "()D");
+
+    // java Paper is always Portrait oriented. Set NSPrintInfo with this
+    //  rectangle, and it's orientation may change. If necessary, be sure to call
+    //  -[NSPrintInfo setOrientation] after this call, which will then
+    //  adjust the -[NSPrintInfo paperSize] as well.
+
+    jdouble jPhysicalWidth = JNFCallDoubleMethod(env, src, jm_getWidth); // AWT_THREADING Safe (!appKit)
+    jdouble jPhysicalHeight = JNFCallDoubleMethod(env, src, jm_getHeight); // AWT_THREADING Safe (!appKit)
+
+    [dst setPaperSize:NSMakeSize(jPhysicalWidth, jPhysicalHeight)];
+
+    // Set the margins from the imageable area
+    jdouble jImageX = JNFCallDoubleMethod(env, src, jm_getImageableX); // AWT_THREADING Safe (!appKit)
+    jdouble jImageY = JNFCallDoubleMethod(env, src, jm_getImageableY); // AWT_THREADING Safe (!appKit)
+    jdouble jImageW = JNFCallDoubleMethod(env, src, jm_getImageableW); // AWT_THREADING Safe (!appKit)
+    jdouble jImageH = JNFCallDoubleMethod(env, src, jm_getImageableH); // AWT_THREADING Safe (!appKit)
+
+    [dst setLeftMargin:(CGFloat)jImageX];
+    [dst setTopMargin:(CGFloat)jImageY];
+    [dst setRightMargin:(CGFloat)(jPhysicalWidth - jImageW - jImageX)];
+    [dst setBottomMargin:(CGFloat)(jPhysicalHeight - jImageH - jImageY)];
+}
+
+static void nsPrintInfoToJavaPageFormat(JNIEnv* env, NSPrintInfo* src, jobject dst)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_setOrientation, sjc_PageFormat, "setOrientation", "(I)V");
+    static JNF_MEMBER_CACHE(jm_setPaper, sjc_PageFormat, "setPaper", "(Ljava/awt/print/Paper;)V");
+    static JNF_CTOR_CACHE(jm_Paper_ctor, sjc_Paper, "()V");
+
+    jint jOrientation;
+    NSPrintingOrientation nsOrientation = [src orientation];
+    switch (nsOrientation) {
+        case NSPortraitOrientation:
+            jOrientation = java_awt_print_PageFormat_PORTRAIT;
+            break;
+
+        case NSLandscapeOrientation:
+            jOrientation = java_awt_print_PageFormat_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
+            break;
+
+/*
+        // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
+        case NSReverseLandscapeOrientation:
+            jOrientation = java_awt_print_PageFormat.REVERSE_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
+            break;
+*/
+
+        default:
+            jOrientation = java_awt_print_PageFormat_PORTRAIT;
+            break;
+    }
+
+    JNFCallVoidMethod(env, dst, jm_setOrientation, jOrientation); // AWT_THREADING Safe (!appKit)
+
+    // Create a new Paper
+    jobject paper = JNFNewObject(env, jm_Paper_ctor); // AWT_THREADING Safe (known object)
+
+    nsPrintInfoToJavaPaper(env, src, paper);
+
+    // Set the Paper in the PageFormat
+    JNFCallVoidMethod(env, dst, jm_setPaper, paper); // AWT_THREADING Safe (!appKit)
+
+    (*env)->DeleteLocalRef(env, paper);
+}
+
+static void javaPageFormatToNSPrintInfo(JNIEnv* env, jobject srcPrintJob, jobject srcPageFormat, NSPrintInfo* dstPrintInfo)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I");
+    static JNF_MEMBER_CACHE(jm_getPaper, sjc_PageFormat, "getPaper", "()Ljava/awt/print/Paper;");
+    static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
+
+    // When setting page information (orientation, size) in NSPrintInfo, set the
+    //  rectangle first. This is because setting the orientation will change the
+    //  rectangle to match.
+
+    // Set up the paper. This will force Portrait since java Paper is
+    //  not oriented. Then setting the NSPrintInfo orientation below
+    //  will flip NSPrintInfo's info as necessary.
+    jobject paper = JNFCallObjectMethod(env, srcPageFormat, jm_getPaper); // AWT_THREADING Safe (!appKit)
+    javaPaperToNSPrintInfo(env, paper, dstPrintInfo);
+    (*env)->DeleteLocalRef(env, paper);
+
+    switch (JNFCallIntMethod(env, srcPageFormat, jm_getOrientation)) { // AWT_THREADING Safe (!appKit)
+        case java_awt_print_PageFormat_PORTRAIT:
+            [dstPrintInfo setOrientation:NSPortraitOrientation];
+            break;
+
+        case java_awt_print_PageFormat_LANDSCAPE:
+            [dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
+            break;
+
+        // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
+        case java_awt_print_PageFormat_REVERSE_LANDSCAPE:
+            [dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
+            break;
+
+        default:
+            [dstPrintInfo setOrientation:NSPortraitOrientation];
+            break;
+    }
+
+    // <rdar://problem/4022422> NSPrinterInfo is not correctly set to the selected printer
+    // from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted.
+    if (srcPrintJob == NULL) return;
+    jobject printerNameObj = JNFCallObjectMethod(env, srcPrintJob, jm_getPrinterName);
+    if (printerNameObj == NULL) return;
+    NSString *printerName = JNFJavaToNSString(env, printerNameObj);
+    if (printerName == nil) return;
+    NSPrinter *printer = [NSPrinter printerWithName:printerName];
+    if (printer == nil) return;
+    [dstPrintInfo setPrinter:printer];
+}
+
+static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable)
+{
+    static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V");
+    static JNF_MEMBER_CACHE(jm_setCopies, sjc_CPrinterJob, "setCopies", "(I)V");
+    static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V");
+    static JNF_MEMBER_CACHE(jm_setPageRange, sjc_CPrinterJob, "setPageRange", "(II)V");
+
+    // get the selected printer's name, and set the appropriate PrintService on the Java side
+    NSString *name = [[src printer] name];
+    jstring printerName = JNFNSToJavaString(env, name);
+    JNFCallVoidMethod(env, dstPrinterJob, jm_setService, printerName);
+
+
+    NSMutableDictionary* printingDictionary = [src dictionary];
+
+    NSNumber* nsCopies = [printingDictionary objectForKey:NSPrintCopies];
+    if ([nsCopies respondsToSelector:@selector(integerValue)])
+    {
+        JNFCallVoidMethod(env, dstPrinterJob, jm_setCopies, [nsCopies integerValue]); // AWT_THREADING Safe (known object)
+    }
+
+    NSNumber* nsCollated = [printingDictionary objectForKey:NSPrintMustCollate];
+    if ([nsCollated respondsToSelector:@selector(boolValue)])
+    {
+        JNFCallVoidMethod(env, dstPrinterJob, jm_setCollated, [nsCollated boolValue] ? JNI_TRUE : JNI_FALSE); // AWT_THREADING Safe (known object)
+    }
+
+    NSNumber* nsPrintAllPages = [printingDictionary objectForKey:NSPrintAllPages];
+    if ([nsPrintAllPages respondsToSelector:@selector(boolValue)])
+    {
+        jint jFirstPage = 0, jLastPage = java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES;
+        if (![nsPrintAllPages boolValue])
+        {
+            NSNumber* nsFirstPage = [printingDictionary objectForKey:NSPrintFirstPage];
+            if ([nsFirstPage respondsToSelector:@selector(integerValue)])
+            {
+                jFirstPage = [nsFirstPage integerValue] - 1;
+            }
+
+            NSNumber* nsLastPage = [printingDictionary objectForKey:NSPrintLastPage];
+            if ([nsLastPage respondsToSelector:@selector(integerValue)])
+            {
+                jLastPage = [nsLastPage integerValue] - 1;
+            }
+        }
+
+        JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRange, jFirstPage, jLastPage); // AWT_THREADING Safe (known object)
+    }
+}
+
+static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable");
+    static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I");
+    static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
+    static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
+
+    NSMutableDictionary* printingDictionary = [dst dictionary];
+
+    jint copies = JNFCallIntMethod(env, srcPrinterJob, jm_getCopies); // AWT_THREADING Safe (known object)
+    [printingDictionary setObject:[NSNumber numberWithInteger:copies] forKey:NSPrintCopies];
+
+    jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object)
+    [printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate];
+
+    jint jNumPages = JNFCallIntMethod(env, srcPageable, jm_getNumberOfPages); // AWT_THREADING Safe (!appKit)
+    if (jNumPages != java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES)
+    {
+        [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
+
+        [printingDictionary setObject:[NSNumber numberWithInteger:1] forKey:NSPrintFirstPage];
+        [printingDictionary setObject:[NSNumber numberWithInteger:jNumPages] forKey:NSPrintLastPage];
+    }
+    else
+    {
+        [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
+    }
+}
+
+/*
+ * Class:     sun_lwawt_macosx_EventDispatchAccess
+ * Method:    pumpEventsAndWait
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_EventDispatchAccess_pumpEventsAndWait
+(JNIEnv *env, jobject eda)
+{
+    static JNF_CLASS_CACHE(jc_Thread, "java/lang/Thread");
+    static JNF_STATIC_MEMBER_CACHE(jm_currentThread, jc_Thread, "currentThread", "()Ljava/lang/Thread;");
+    static JNF_CLASS_CACHE(jc_EventDispatchThread, "java/awt/EventDispatchThread");
+    static JNF_MEMBER_CACHE(jm_macosxGetConditional, jc_EventDispatchThread, "_macosxGetConditional", "(Ljava/lang/Object;)Ljava/awt/Conditional;");
+    static JNF_MEMBER_CACHE(jm_pumpEvents, jc_EventDispatchThread, "pumpEvents", "(Ljava/awt/Conditional;)V");
+
+JNF_COCOA_DURING(env);
+
+    jobject thread = JNFCallStaticObjectMethod(env, jm_currentThread);
+    jobject conditional = JNFCallObjectMethod(env, thread, jm_macosxGetConditional, eda);
+    if (conditional != NULL) {
+        JNFCallVoidMethod(env, thread, jm_pumpEvents, conditional);
+    }
+
+JNF_COCOA_HANDLE(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJob
+ * Method:    abortDoc
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_abortDoc
+  (JNIEnv *env, jobject jthis)
+{
+JNF_COCOA_ENTER(env);
+    // This is only called during the printLoop from the printLoop thread
+    NSPrintOperation* printLoop = [NSPrintOperation currentOperation];
+    NSPrintInfo* printInfo = [printLoop printInfo];
+    [printInfo setJobDisposition:NSPrintCancelJob];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJob
+ * Method:    getDefaultPage
+ * Signature: (Ljava/awt/print/PageFormat;)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_getDefaultPage
+  (JNIEnv *env, jobject jthis, jobject page)
+{
+JNF_COCOA_ENTER(env);
+    NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL);
+
+    nsPrintInfoToJavaPageFormat(env, printInfo, page);
+
+    [printInfo release];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJob
+ * Method:    validatePaper
+ * Signature: (Ljava/awt/print/Paper;Ljava/awt/print/Paper;)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_validatePaper
+  (JNIEnv *env, jobject jthis, jobject origpaper, jobject newpaper)
+{
+JNF_COCOA_ENTER(env);
+
+    NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL);
+    javaPaperToNSPrintInfo(env, origpaper, printInfo);
+    makeBestFit(printInfo);
+    nsPrintInfoToJavaPaper(env, printInfo, newpaper);
+    [printInfo release];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJob
+ * Method:    createNSPrintInfo
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPrinterJob_createNSPrintInfo
+  (JNIEnv *env, jobject jthis)
+{
+    jlong result = -1;
+JNF_COCOA_ENTER(env);
+    // This is used to create the NSPrintInfo for this PrinterJob. Thread
+    //  safety is assured by the java side of this call.
+
+    NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL);
+    if (printInfo) CFRetain(printInfo); // GC
+    [printInfo release];
+
+    result = ptr_to_jlong(printInfo);
+
+JNF_COCOA_EXIT(env);
+    return result;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJob
+ * Method:    dispose
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_dispose
+  (JNIEnv *env, jobject jthis, jlong nsPrintInfo)
+{
+JNF_COCOA_ENTER(env);
+    if (nsPrintInfo != -1)
+    {
+        NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(nsPrintInfo);
+        if (printInfo) CFRelease(printInfo); // GC
+    }
+JNF_COCOA_EXIT(env);
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJob
+ * Method:    printLoop
+ * Signature: ()V
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPrinterJob_printLoop
+  (JNIEnv *env, jobject jthis, jboolean blocks, jint firstPage, jint lastPage)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormat", "(I)Ljava/awt/print/PageFormat;");
+    static JNF_MEMBER_CACHE(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;");
+    static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
+    static JNF_MEMBER_CACHE(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;");
+
+    jboolean retVal = JNI_FALSE;
+
+JNF_COCOA_ENTER(env);
+    // Get the first page's PageFormat for setting things up (This introduces
+    //  and is a facet of the same problem in Radar 2818593/2708932).
+    jobject page = JNFCallObjectMethod(env, jthis, jm_getPageFormat, 0); // AWT_THREADING Safe (!appKit)
+    if (page != NULL) {
+        jobject pageFormatArea = JNFCallObjectMethod(env, jthis, jm_getPageFormatArea, page); // AWT_THREADING Safe (!appKit)
+
+        PrinterView* printerView = [[PrinterView alloc] initWithFrame:JavaToNSRect(env, pageFormatArea) withEnv:env withPrinterJob:jthis];
+        [printerView setFirstPage:firstPage lastPage:lastPage];
+
+        NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
+
+        // <rdar://problem/4156975> passing jthis CPrinterJob as well, so we can extract the printer name from the current job
+        javaPageFormatToNSPrintInfo(env, jthis, page, printInfo);
+
+        // <rdar://problem/4093799> NSPrinterInfo is not correctly set to the selected printer
+        // from the Java side of CPrinterJob. Had always assumed the default printer was the one we wanted.
+        jobject printerNameObj = JNFCallObjectMethod(env, jthis, jm_getPrinterName);
+        if (printerNameObj != NULL) {
+            NSString *printerName = JNFJavaToNSString(env, printerNameObj);
+            if (printerName != nil) {
+                NSPrinter *printer = [NSPrinter printerWithName:printerName];
+                if (printer != nil) [printInfo setPrinter:printer];
+            }
+        }
+
+        // <rdar://problem/4367998> JTable.print attributes are ignored
+        jobject pageable = JNFCallObjectMethod(env, jthis, jm_getPageable); // AWT_THREADING Safe (!appKit)
+        javaPrinterJobToNSPrintInfo(env, jthis, pageable, printInfo);
+
+        PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo];
+
+        (void)[printModel runPrintLoopWithView:printerView waitUntilDone:blocks withEnv:env];
+
+        // Only set this if we got far enough to call runPrintLoopWithView, or we will spin CPrinterJob.print() forever!
+        retVal = JNI_TRUE;
+
+        [printModel release];
+        [printerView release];
+
+        if (page != NULL)
+        {
+            (*env)->DeleteLocalRef(env, page);
+        }
+
+        if (pageFormatArea != NULL)
+        {
+            (*env)->DeleteLocalRef(env, pageFormatArea);
+        }
+    }
+JNF_COCOA_EXIT(env);
+    return retVal;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterPageDialog
+ * Method:    showDialog
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPrinterPageDialog_showDialog
+  (JNIEnv *env, jobject jthis)
+{
+
+    static JNF_CLASS_CACHE(jc_CPrinterPageDialog, "sun/lwawt/macosx/CPrinterPageDialog");
+    static JNF_MEMBER_CACHE(jm_page, jc_CPrinterPageDialog, "fPage", "Ljava/awt/print/PageFormat;");
+
+    jboolean result = JNI_FALSE;
+JNF_COCOA_ENTER(env);
+    jobject printerJob = JNFGetObjectField(env, jthis, sjm_printerJob);
+    NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
+
+    jobject page = JNFGetObjectField(env, jthis, jm_page);
+
+    // <rdar://problem/4156975> passing NULL, because only a CPrinterJob has a real printer associated with it
+    javaPageFormatToNSPrintInfo(env, NULL, page, printInfo);
+
+    PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo];
+    result = [printModel runPageSetup];
+    [printModel release];
+
+    if (result)
+    {
+        nsPrintInfoToJavaPageFormat(env, printInfo, page);
+    }
+
+    if (printerJob != NULL)
+    {
+        (*env)->DeleteLocalRef(env, printerJob);
+    }
+
+    if (page != NULL)
+    {
+        (*env)->DeleteLocalRef(env, page);
+    }
+
+JNF_COCOA_EXIT(env);
+    return result;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJobDialog
+ * Method:    showDialog
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPrinterJobDialog_showDialog
+  (JNIEnv *env, jobject jthis)
+{
+    static JNF_CLASS_CACHE(jc_CPrinterJobDialog, "sun/lwawt/macosx/CPrinterJobDialog");
+    static JNF_MEMBER_CACHE(jm_pageable, jc_CPrinterJobDialog, "fPageable", "Ljava/awt/print/Pageable;");
+
+    jboolean result = JNI_FALSE;
+JNF_COCOA_ENTER(env);
+    jobject printerJob = JNFGetObjectField(env, jthis, sjm_printerJob);
+    NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
+
+    jobject pageable = JNFGetObjectField(env, jthis, jm_pageable);
+
+    javaPrinterJobToNSPrintInfo(env, printerJob, pageable, printInfo);
+
+    PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo];
+    result = [printModel runJobSetup];
+    [printModel release];
+
+    if (result)
+    {
+        nsPrintInfoToJavaPrinterJob(env, printInfo, printerJob, pageable);
+    }
+
+    if (printerJob != NULL)
+    {
+        (*env)->DeleteLocalRef(env, printerJob);
+    }
+
+    if (pageable != NULL)
+    {
+        (*env)->DeleteLocalRef(env, pageable);
+    }
+
+JNF_COCOA_EXIT(env);
+    return result;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CRobot.m b/jdk/src/macosx/native/sun/awt/CRobot.m
new file mode 100644
index 0000000..c7142a9
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CRobot.m
@@ -0,0 +1,609 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <ApplicationServices/ApplicationServices.h>
+
+
+#import "LWCToolkit.h"
+#import "sun_lwawt_macosx_CRobot.h"
+
+// Theoretically, Quarts works with up to 32 buttons.
+#define k_JAVA_ROBOT_NUMBER_KNOWN_BUTTONS    3
+#define k_JAVA_ROBOT_WHEEL_COUNT 1
+
+#if !defined(kCGBitmapByteOrder32Host)
+#define kCGBitmapByteOrder32Host 0
+#endif
+
+// In OS X, left and right mouse button share the same click count.
+// That is, if one starts clicking the left button rapidly and then
+// switches to the right button, then the click count will continue
+// increasing, without dropping to 1 in between. The middle button,
+// however, has its own click count.
+// For robot, we aren't going to emulate all that complexity. All our
+// synhtetic clicks share the same click count.
+static int gsClickCount;
+static NSTimeInterval gsLastClickTime;
+
+static inline CGKeyCode GetCGKeyCode(jint javaKeyCode);
+
+static void postMouseEvent(const CGPoint point, CGMouseButton button, 
+                           CGEventType type, int clickCount);
+
+static int GetClickCount(BOOL isDown);
+
+static void
+CreateJavaException(JNIEnv* env, CGError err)
+{
+    // Throw a java exception indicating what is wrong.
+    NSString* s = [NSString stringWithFormat:@"Robot: CGError: %d", err];
+    (*env)->ThrowNew(env, (*env)->FindClass(env, "java/awt/AWTException"),
+                     [s UTF8String]);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CRobot
+ * Method:    initRobot
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CRobot_initRobot
+(JNIEnv *env, jobject peer)
+{
+    // Set things up to let our app act like a synthetic keyboard and mouse.
+    // Always set all states, in case Apple ever changes default behaviors.
+    static int setupDone = 0;
+    if (!setupDone) {        
+        setupDone = 1;
+        // Don't block local events after posting ours
+        CGSetLocalEventsSuppressionInterval(0.0);
+
+        // Let our event's modifier key state blend with local hardware events
+        CGEnableEventStateCombining(TRUE);
+
+        // Don't let our events block local hardware events
+        CGSetLocalEventsFilterDuringSupressionState(
+                                    kCGEventFilterMaskPermitAllEvents,
+                                    kCGEventSupressionStateSupressionInterval);
+        CGSetLocalEventsFilterDuringSupressionState(
+                                    kCGEventFilterMaskPermitAllEvents,
+                                    kCGEventSupressionStateRemoteMouseDrag);
+        
+        gsClickCount = 0;
+        gsLastClickTime = 0;
+    }
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CRobot
+ * Method:    mouseEvent
+ * Signature: (IIIIIIZ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CRobot_mouseEvent
+(JNIEnv *env, jobject peer,
+ jint screenIndex, jint mouseLastX, jint mouseLastY,
+ jint mouse1State, jint mouse2State,
+ jint mouse3State, jboolean mouseMoveAction)
+{
+    JNF_COCOA_ENTER(env);
+
+    // This is the native method called when Robot mouse events occur.
+    // The CRobot tracks the mouse position, and which button was
+    // pressed. If the mouse position is unknown it is obtained from
+    // CGEvents. The peer also tracks the mouse button desired state,
+    // the appropriate key modifier state, and whether the mouse action
+    // is simply a mouse move with no mouse button state changes.
+
+    CGError err = kCGErrorSuccess;
+
+    CGDirectDisplayID displayID =
+    FindCGDirectDisplayIDForScreenIndex(screenIndex);
+    CGRect globalDeviceBounds = CGDisplayBounds(displayID);
+
+    // Set unknown mouse location, if needed.
+    if ((mouseLastX == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN) ||
+        (mouseLastY == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN))
+    {
+        CGEventRef event = CGEventCreate(NULL);
+        if (event == NULL) {
+            return;
+        }
+
+        CGPoint globalPos = CGEventGetLocation(event);
+        CFRelease(event);
+
+        // Normalize the coords within this display device, as
+        // per Robot rules.
+        if (globalPos.x < CGRectGetMinX(globalDeviceBounds)) {
+            globalPos.x = CGRectGetMinX(globalDeviceBounds);
+        }
+        else if (globalPos.x > CGRectGetMaxX(globalDeviceBounds)) {
+            globalPos.x = CGRectGetMaxX(globalDeviceBounds);
+        }
+
+        if (globalPos.y < CGRectGetMinY(globalDeviceBounds)) {
+            globalPos.y = CGRectGetMinY(globalDeviceBounds);
+        }
+        else if (globalPos.y > CGRectGetMaxY(globalDeviceBounds)) {
+            globalPos.y = CGRectGetMaxY(globalDeviceBounds);
+        }
+
+        mouseLastX = (jint)globalPos.x;
+        mouseLastY = (jint)globalPos.y;
+    }
+
+    // volatile, otherwise it warns that it might be clobbered by 'longjmp'
+    volatile CGPoint point;
+
+    // Translate the device relative point into a valid global CGPoint.
+    point.x = mouseLastX + globalDeviceBounds.origin.x;
+    point.y = mouseLastY + globalDeviceBounds.origin.y;
+
+    BOOL isDown = NO;
+    CGMouseButton button = kCGMouseButtonLeft;
+    CGEventType type = kCGEventMouseMoved;
+    int clickCount = 0;
+
+    // When moving, the buttons aren't changed from their current state.
+    if (mouseMoveAction == JNI_FALSE) {
+        // Some of the buttons are changing state.
+
+        // Left
+        if (mouse1State != sun_lwawt_macosx_CRobot_BUTTON_STATE_UNKNOWN) {
+            button = kCGMouseButtonLeft;
+            if (mouse1State == sun_lwawt_macosx_CRobot_BUTTON_STATE_DOWN) {
+                type = kCGEventLeftMouseDown;
+                isDown = YES;
+            } else {
+                type = kCGEventLeftMouseUp;
+            }
+        }
+
+        // Other
+        if (mouse2State != sun_lwawt_macosx_CRobot_BUTTON_STATE_UNKNOWN) {
+            button = kCGMouseButtonCenter;
+            if (mouse2State == sun_lwawt_macosx_CRobot_BUTTON_STATE_DOWN) {
+                type = kCGEventOtherMouseDown;
+                isDown = YES;
+            } else {
+                type = kCGEventOtherMouseUp;
+            }
+        }
+
+        // Right
+        if (mouse3State != sun_lwawt_macosx_CRobot_BUTTON_STATE_UNKNOWN) {
+            button = kCGMouseButtonRight;
+            if (mouse3State == sun_lwawt_macosx_CRobot_BUTTON_STATE_DOWN) {
+                type = kCGEventRightMouseDown;
+                isDown = YES;
+            } else {
+                type = kCGEventRightMouseUp;
+            }
+        }
+        
+        clickCount = GetClickCount(isDown);        
+    } else {
+        // could be mouse moved or mouse dragged
+        if (mouse1State == sun_lwawt_macosx_CRobot_BUTTON_STATE_DOWN) {
+            type = kCGEventLeftMouseDragged;
+        } else if (mouse2State == sun_lwawt_macosx_CRobot_BUTTON_STATE_DOWN) {
+            type = kCGEventOtherMouseDragged;
+        } else if (mouse3State == sun_lwawt_macosx_CRobot_BUTTON_STATE_DOWN) {
+            type = kCGEventRightMouseDragged;
+        } else {
+            type = kCGEventMouseMoved;
+        }
+    }
+
+    postMouseEvent(point, button, type, clickCount);    
+
+    JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CRobot
+ * Method:    mouseWheel
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CRobot_mouseWheel
+(JNIEnv *env, jobject peer, jint wheelAmt)
+{
+    CGEventRef event = CGEventCreateScrollWheelEvent(NULL,
+                                            kCGScrollEventUnitLine,
+                                            k_JAVA_ROBOT_WHEEL_COUNT, wheelAmt);
+
+    if (event != NULL) {
+        CGEventPost(kCGSessionEventTap, event);
+        CFRelease(event);
+    }
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CRobot
+ * Method:    keyEvent
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CRobot_keyEvent
+(JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed)
+{
+    /*
+     * Well, using CGEventCreateKeyboardEvent/CGEventPost would have been 
+     * a better solution, however, it gives me all kinds of trouble and I have
+     * no idea how to solve them without inserting delays between simulated 
+     * events. So, I've ended up disabling it and opted for another approach 
+     * that uses Accessibility API instead. 
+     */
+    CGKeyCode keyCode = GetCGKeyCode(javaKeyCode);
+    AXUIElementRef elem = AXUIElementCreateSystemWide();    
+    AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed);
+    CFRelease(elem);
+
+    
+#if 0
+    CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed);
+    if (event != NULL) {
+        CGEventPost(kCGSessionEventTap, event);
+        CFRelease(event);
+    }
+#endif
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CRobot
+ * Method:    nativeGetScreenPixels
+ * Signature: (IIIII[I)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CRobot_nativeGetScreenPixels
+(JNIEnv *env, jobject peer,
+ jint x, jint y, jint width, jint height, jintArray pixels)
+{
+    JNF_COCOA_ENTER(env);
+
+    jint picX = x;
+    jint picY = y;
+    jint picWidth = width;
+    jint picHeight = height;
+
+    CGRect screenRect = CGRectMake(picX, picY, picWidth, picHeight);
+    CGImageRef screenPixelsImage = CGWindowListCreateImage(screenRect,
+                                        kCGWindowListOptionOnScreenOnly,
+                                        kCGNullWindowID, kCGWindowImageDefault);
+
+    if (screenPixelsImage == NULL) {
+        return;
+    }
+
+    // get a pointer to the Java int array
+    void *jPixelData = (*env)->GetPrimitiveArrayCritical(env, pixels, 0);
+
+    // create a graphics context around the Java int array
+    CGColorSpaceRef picColorSpace = CGColorSpaceCreateWithName(
+                                            kCGColorSpaceGenericRGB);
+    CGContextRef jPicContextRef = CGBitmapContextCreate(
+                                            jPixelData,
+                                            picWidth, picHeight,
+                                            8, picWidth * sizeof(jint),
+                                            picColorSpace,
+                                            kCGBitmapByteOrder32Host |
+                                            kCGImageAlphaPremultipliedFirst);
+
+    CGColorSpaceRelease(picColorSpace);
+
+    // flip, scale, and color correct the screen image into the Java pixels
+    CGRect bounds = { { 0, 0 }, { picWidth, picHeight } };
+    CGContextDrawImage(jPicContextRef, bounds, screenPixelsImage);
+    CGContextFlush(jPicContextRef);
+
+    // cleanup
+    CGContextRelease(jPicContextRef);
+    CGImageRelease(screenPixelsImage);
+
+    // release the Java int array back up to the JVM
+    (*env)->ReleasePrimitiveArrayCritical(env, pixels, jPixelData, 0);
+
+    JNF_COCOA_EXIT(env);
+}
+
+/****************************************************
+ * Helper methods
+ ****************************************************/
+
+static void postMouseEvent(const CGPoint point, CGMouseButton button,
+                           CGEventType type, int clickCount)
+{ 
+    CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL, type, point, button);
+    if (mouseEvent != NULL) {
+        CGEventSetIntegerValueField(mouseEvent, kCGMouseEventClickState, clickCount); 
+        CGEventPost(kCGSessionEventTap, mouseEvent);
+        CFRelease(mouseEvent);
+    }
+}
+
+// NOTE: Don't modify this table directly. It is machine generated. See below.
+static const unsigned char javaToMacKeyCode[] = {
+    127,    //     0     0 VK_UNDEFINED                      No_Equivalent
+    127,    //     1   0x1 Not_Used
+    127,    //     2   0x2 Not_Used
+    127,    //     3   0x3 VK_CANCEL                         No_Equivalent
+    127,    //     4   0x4 Not_Used
+    127,    //     5   0x5 Not_Used
+    127,    //     6   0x6 Not_Used
+    127,    //     7   0x7 Not_Used
+     51,    //     8   0x8 VK_BACK_SPACE
+     48,    //     9   0x9 VK_TAB
+     36,    //    10   0xa VK_ENTER
+    127,    //    11   0xb Not_Used
+     71,    //    12   0xc VK_CLEAR
+    127,    //    13   0xd Not_Used
+    127,    //    14   0xe Not_Used
+    127,    //    15   0xf Not_Used
+     56,    //    16  0x10 VK_SHIFT
+     59,    //    17  0x11 VK_CONTROL
+     58,    //    18  0x12 VK_ALT
+    113,    //    19  0x13 VK_PAUSE
+     57,    //    20  0x14 VK_CAPS_LOCK
+    127,    //    21  0x15 VK_KANA                           No_Equivalent
+    127,    //    22  0x16 Not_Used
+    127,    //    23  0x17 Not_Used
+    127,    //    24  0x18 VK_FINAL                          No_Equivalent
+    127,    //    25  0x19 VK_KANJI                          No_Equivalent
+    127,    //    26  0x1a Not_Used
+     53,    //    27  0x1b VK_ESCAPE
+    127,    //    28  0x1c VK_CONVERT                        No_Equivalent
+    127,    //    29  0x1d VK_NONCONVERT                     No_Equivalent
+    127,    //    30  0x1e VK_ACCEPT                         No_Equivalent
+    127,    //    31  0x1f VK_MODECHANGE                     No_Equivalent
+     49,    //    32  0x20 VK_SPACE
+    116,    //    33  0x21 VK_PAGE_UP
+    121,    //    34  0x22 VK_PAGE_DOWN
+    119,    //    35  0x23 VK_END
+    115,    //    36  0x24 VK_HOME
+    123,    //    37  0x25 VK_LEFT
+    126,    //    38  0x26 VK_UP
+    124,    //    39  0x27 VK_RIGHT
+    125,    //    40  0x28 VK_DOWN
+    127,    //    41  0x29 Not_Used
+    127,    //    42  0x2a Not_Used
+    127,    //    43  0x2b Not_Used
+     43,    //    44  0x2c VK_COMMA
+     27,    //    45  0x2d VK_MINUS
+     47,    //    46  0x2e VK_PERIOD
+     44,    //    47  0x2f VK_SLASH
+     29,    //    48  0x30 VK_0
+     18,    //    49  0x31 VK_1
+     19,    //    50  0x32 VK_2
+     20,    //    51  0x33 VK_3
+     21,    //    52  0x34 VK_4
+     23,    //    53  0x35 VK_5
+     22,    //    54  0x36 VK_6
+     26,    //    55  0x37 VK_7
+     28,    //    56  0x38 VK_8
+     25,    //    57  0x39 VK_9
+    127,    //    58  0x3a Not_Used
+     41,    //    59  0x3b VK_SEMICOLON
+    127,    //    60  0x3c Not_Used
+     24,    //    61  0x3d VK_EQUALS
+    127,    //    62  0x3e Not_Used
+    127,    //    63  0x3f Not_Used
+    127,    //    64  0x40 Not_Used
+      0,    //    65  0x41 VK_A
+     11,    //    66  0x42 VK_B
+      8,    //    67  0x43 VK_C
+      2,    //    68  0x44 VK_D
+     14,    //    69  0x45 VK_E
+      3,    //    70  0x46 VK_F
+      5,    //    71  0x47 VK_G
+      4,    //    72  0x48 VK_H
+     34,    //    73  0x49 VK_I
+     38,    //    74  0x4a VK_J
+     40,    //    75  0x4b VK_K
+     37,    //    76  0x4c VK_L
+     46,    //    77  0x4d VK_M
+     45,    //    78  0x4e VK_N
+     31,    //    79  0x4f VK_O
+     35,    //    80  0x50 VK_P
+     12,    //    81  0x51 VK_Q
+     15,    //    82  0x52 VK_R
+      1,    //    83  0x53 VK_S
+     17,    //    84  0x54 VK_T
+     32,    //    85  0x55 VK_U
+      9,    //    86  0x56 VK_V
+     13,    //    87  0x57 VK_W
+      7,    //    88  0x58 VK_X
+     16,    //    89  0x59 VK_Y
+      6,    //    90  0x5a VK_Z
+     33,    //    91  0x5b VK_OPEN_BRACKET
+     42,    //    92  0x5c VK_BACK_SLASH
+     30,    //    93  0x5d VK_CLOSE_BRACKET
+    127,    //    94  0x5e Not_Used
+    127,    //    95  0x5f Not_Used
+     82,    //    96  0x60 VK_NUMPAD0
+     83,    //    97  0x61 VK_NUMPAD1
+     84,    //    98  0x62 VK_NUMPAD2
+     85,    //    99  0x63 VK_NUMPAD3
+     86,    //   100  0x64 VK_NUMPAD4
+     87,    //   101  0x65 VK_NUMPAD5
+     88,    //   102  0x66 VK_NUMPAD6
+     89,    //   103  0x67 VK_NUMPAD7
+     91,    //   104  0x68 VK_NUMPAD8
+     92,    //   105  0x69 VK_NUMPAD9
+     67,    //   106  0x6a VK_MULTIPLY
+     69,    //   107  0x6b VK_ADD
+    127,    //   108  0x6c VK_SEPARATER                      No_Equivalent
+     78,    //   109  0x6d VK_SUBTRACT
+     65,    //   110  0x6e VK_DECIMAL
+     75,    //   111  0x6f VK_DIVIDE
+    122,    //   112  0x70 VK_F1
+    120,    //   113  0x71 VK_F2
+     99,    //   114  0x72 VK_F3
+    118,    //   115  0x73 VK_F4
+     96,    //   116  0x74 VK_F5
+     97,    //   117  0x75 VK_F6
+     98,    //   118  0x76 VK_F7
+    100,    //   119  0x77 VK_F8
+    101,    //   120  0x78 VK_F9
+    109,    //   121  0x79 VK_F10
+    103,    //   122  0x7a VK_F11
+    111,    //   123  0x7b VK_F12
+    127,    //   124  0x7c Not_Used
+    127,    //   125  0x7d Not_Used
+    127,    //   126  0x7e Not_Used
+    117,    //   127  0x7f VK_DELETE
+    127,    //   128  0x80 VK_DEAD_GRAVE                     No_Equivalent
+    127,    //   129  0x81 VK_DEAD_ACUTE                     No_Equivalent
+    127,    //   130  0x82 VK_DEAD_CIRCUMFLEX                No_Equivalent
+    127,    //   131  0x83 VK_DEAD_TILDE                     No_Equivalent
+    127,    //   132  0x84 VK_DEAD_MACRON                    No_Equivalent
+    127,    //   133  0x85 VK_DEAD_BREVE                     No_Equivalent
+    127,    //   134  0x86 VK_DEAD_ABOVEDOT                  No_Equivalent
+    127,    //   135  0x87 VK_DEAD_DIAERESIS                 No_Equivalent
+    127,    //   136  0x88 VK_DEAD_ABOVERING                 No_Equivalent
+    127,    //   137  0x89 VK_DEAD_DOUBLEACUTE               No_Equivalent
+    127,    //   138  0x8a VK_DEAD_CARON                     No_Equivalent
+    127,    //   139  0x8b VK_DEAD_CEDILLA                   No_Equivalent
+    127,    //   140  0x8c VK_DEAD_OGONEK                    No_Equivalent
+    127,    //   141  0x8d VK_DEAD_IOTA                      No_Equivalent
+    127,    //   142  0x8e VK_DEAD_VOICED_SOUND              No_Equivalent
+    127,    //   143  0x8f VK_DEAD_SEMIVOICED_SOUND          No_Equivalent
+    127,    //   144  0x90 VK_NUM_LOCK                       No_Equivalent
+    107,    //   145  0x91 VK_SCROLL_LOCK
+    127,    //   146  0x92 Not_Used
+    127,    //   147  0x93 Not_Used
+    127,    //   148  0x94 Not_Used
+    127,    //   149  0x95 Not_Used
+    127,    //   150  0x96 VK_AMPERSAND                      No_Equivalent
+    127,    //   151  0x97 VK_ASTERISK                       No_Equivalent
+    127,    //   152  0x98 VK_QUOTEDBL                       No_Equivalent
+    127,    //   153  0x99 VK_LESS                           No_Equivalent
+    105,    //   154  0x9a VK_PRINTSCREEN
+    127,    //   155  0x9b VK_INSERT                         No_Equivalent
+    114,    //   156  0x9c VK_HELP
+     55,    //   157  0x9d VK_META
+    127,    //   158  0x9e Not_Used
+    127,    //   159  0x9f Not_Used
+    127,    //   160  0xa0 VK_GREATER                        No_Equivalent
+    127,    //   161  0xa1 VK_BRACELEFT                      No_Equivalent
+    127,    //   162  0xa2 VK_BRACERIGHT                     No_Equivalent
+    127,    //   163  0xa3 Not_Used
+    127,    //   164  0xa4 Not_Used
+    127,    //   165  0xa5 Not_Used
+    127,    //   166  0xa6 Not_Used
+    127,    //   167  0xa7 Not_Used
+    127,    //   168  0xa8 Not_Used
+    127,    //   169  0xa9 Not_Used
+    127,    //   170  0xaa Not_Used
+    127,    //   171  0xab Not_Used
+    127,    //   172  0xac Not_Used
+    127,    //   173  0xad Not_Used
+    127,    //   174  0xae Not_Used
+    127,    //   175  0xaf Not_Used
+    127,    //   176  0xb0 Not_Used
+    127,    //   177  0xb1 Not_Used
+    127,    //   178  0xb2 Not_Used
+    127,    //   179  0xb3 Not_Used
+    127,    //   180  0xb4 Not_Used
+    127,    //   181  0xb5 Not_Used
+    127,    //   182  0xb6 Not_Used
+    127,    //   183  0xb7 Not_Used
+    127,    //   184  0xb8 Not_Used
+    127,    //   185  0xb9 Not_Used
+    127,    //   186  0xba Not_Used
+    127,    //   187  0xbb Not_Used
+    127,    //   188  0xbc Not_Used
+    127,    //   189  0xbd Not_Used
+    127,    //   190  0xbe Not_Used
+    127,    //   191  0xbf Not_Used
+     50,    //   192  0xc0 VK_BACK_QUOTE
+    127,    //   193  0xc1 Not_Used
+    127,    //   194  0xc2 Not_Used
+    127,    //   195  0xc3 Not_Used
+    127,    //   196  0xc4 Not_Used
+    127,    //   197  0xc5 Not_Used
+    127,    //   198  0xc6 Not_Used
+    127,    //   199  0xc7 Not_Used
+    127,    //   200  0xc8 Not_Used
+    127,    //   201  0xc9 Not_Used
+    127,    //   202  0xca Not_Used
+    127,    //   203  0xcb Not_Used
+    127,    //   204  0xcc Not_Used
+    127,    //   205  0xcd Not_Used
+    127,    //   206  0xce Not_Used
+    127,    //   207  0xcf Not_Used
+    127,    //   208  0xd0 Not_Used
+    127,    //   209  0xd1 Not_Used
+    127,    //   210  0xd2 Not_Used
+    127,    //   211  0xd3 Not_Used
+    127,    //   212  0xd4 Not_Used
+    127,    //   213  0xd5 Not_Used
+    127,    //   214  0xd6 Not_Used
+    127,    //   215  0xd7 Not_Used
+    127,    //   216  0xd8 Not_Used
+    127,    //   217  0xd9 Not_Used
+    127,    //   218  0xda Not_Used
+    127,    //   219  0xdb Not_Used
+    127,    //   220  0xdc Not_Used
+    127,    //   221  0xdd Not_Used
+     39     //   222  0xde VK_QUOTE
+};
+
+// NOTE: All values above 222 don't have an equivalent on MacOSX.
+static inline CGKeyCode GetCGKeyCode(jint javaKeyCode)
+{
+    if (javaKeyCode > 222) {
+        return 127;
+    } else {
+        return javaToMacKeyCode[javaKeyCode];
+    }
+}
+
+static int GetClickCount(BOOL isDown) {    
+    NSTimeInterval now = [[NSDate date] timeIntervalSinceReferenceDate];
+    NSTimeInterval clickInterval = now - gsLastClickTime;
+    BOOL isWithinTreshold = clickInterval < [NSEvent doubleClickInterval]; 
+    
+    if (isDown) {
+        if (isWithinTreshold) {
+            gsClickCount++;
+        } else {
+            gsClickCount = 1;        
+        }
+        
+        gsLastClickTime = now;
+    } else { 
+        // In OS X, a mouse up has the click count of the last mouse down 
+        // if an interval between up and down is within the double click
+        // threshold, and 0 otherwise.
+        if (!isWithinTreshold) {
+            gsClickCount = 0;
+        }
+    }
+    
+    return gsClickCount;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CSystemColors.h b/jdk/src/macosx/native/sun/awt/CSystemColors.h
new file mode 100644
index 0000000..4ff3c64
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CSystemColors.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import "jni.h"
+
+// This is a class that only has class methods. This is so that the +initialize method is
+//  called when the class is first accessed so that sColors is created and filled out
+//  lazily.
+__attribute__((visibility("default")))
+@interface CSystemColors : NSObject {
+
+}
+
++ (void)reloadColors;
+
++ (NSColor*)getColor:(NSUInteger)colorIndex useAppleColor:(BOOL)useAppleColor;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CSystemColors.m b/jdk/src/macosx/native/sun/awt/CSystemColors.m
new file mode 100644
index 0000000..f7b8f99
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CSystemColors.m
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CSystemColors.h"
+
+#import "java_awt_SystemColor.h"
+#import "sun_lwawt_macosx_LWCToolkit.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "ThreadUtilities.h"
+
+NSColor **sColors = nil;
+NSColor **appleColors = nil;
+
+@implementation CSystemColors
+
++ (void)initialize {
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+JNF_COCOA_ENTER(env);
+    [CSystemColors reloadColors];
+    [[NSNotificationCenter defaultCenter] addObserver:[CSystemColors class] selector:@selector(systemColorsDidChange:) name:NSSystemColorsDidChangeNotification object:nil];
+JNF_COCOA_EXIT(env);
+}
+
+static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit");
+static JNF_STATIC_MEMBER_CACHE(jm_systemColorsChanged, jc_LWCToolkit, "systemColorsChanged", "()V");
+
++ (void)systemColorsDidChange:(NSNotification *)notification {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    [CSystemColors reloadColors];
+
+    // Call LWCToolkit with the news. LWCToolkit makes certain to do its duties
+    // from a new thread.
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    JNFCallStaticVoidMethod(env, jm_systemColorsChanged); // AWT_THREADING Safe (event)
+}
+
+
++ (void)reloadColors {
+    // NOTE: <rdar://problem/3447825> was filed to make this code even lazier. Each
+    //  color below could be set lazily when it was first accessed. This way the
+    //  arrays would be sparse, and filled in as SystemColors were used.
+    int i;
+    if (sColors == nil) {
+        sColors = (NSColor**)malloc(sizeof(NSColor*) * java_awt_SystemColor_NUM_COLORS);
+    } else {
+        for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) {
+            if (sColors[i] != NULL) CFRelease(sColors[i]); // GC
+        }
+    }
+
+    sColors[java_awt_SystemColor_DESKTOP] =                    [NSColor greenColor];
+    sColors[java_awt_SystemColor_ACTIVE_CAPTION] =            [NSColor whiteColor];
+    sColors[java_awt_SystemColor_ACTIVE_CAPTION_TEXT] =        [NSColor blackColor];
+    sColors[java_awt_SystemColor_ACTIVE_CAPTION_BORDER] =    [NSColor whiteColor];
+    sColors[java_awt_SystemColor_INACTIVE_CAPTION] =        [NSColor grayColor];
+    sColors[java_awt_SystemColor_INACTIVE_CAPTION_TEXT] =    [NSColor grayColor];
+    sColors[java_awt_SystemColor_INACTIVE_CAPTION_BORDER] =    [NSColor grayColor];
+    sColors[java_awt_SystemColor_WINDOW] =                    [NSColor grayColor];
+    sColors[java_awt_SystemColor_WINDOW_BORDER] =            [NSColor windowFrameColor];
+    sColors[java_awt_SystemColor_WINDOW_TEXT] =                [NSColor windowFrameTextColor];
+    sColors[java_awt_SystemColor_MENU] =                    [NSColor controlBackgroundColor];
+    sColors[java_awt_SystemColor_MENU_TEXT] =                [NSColor controlTextColor];
+    sColors[java_awt_SystemColor_TEXT] =                    [NSColor textBackgroundColor];
+    sColors[java_awt_SystemColor_TEXT_TEXT] =                [NSColor textColor];
+    sColors[java_awt_SystemColor_TEXT_HIGHLIGHT] =            [NSColor selectedTextBackgroundColor];
+    sColors[java_awt_SystemColor_TEXT_HIGHLIGHT_TEXT] =        [NSColor selectedTextColor];
+    sColors[java_awt_SystemColor_TEXT_INACTIVE_TEXT] =        [NSColor disabledControlTextColor];
+    sColors[java_awt_SystemColor_CONTROL] =                    [NSColor controlColor];
+    sColors[java_awt_SystemColor_CONTROL_TEXT] =            [NSColor controlTextColor];
+    sColors[java_awt_SystemColor_CONTROL_HIGHLIGHT] =        [NSColor alternateSelectedControlColor];
+    sColors[java_awt_SystemColor_CONTROL_LT_HIGHLIGHT] =    [NSColor alternateSelectedControlTextColor];
+    sColors[java_awt_SystemColor_CONTROL_SHADOW] =            [NSColor controlShadowColor];
+    sColors[java_awt_SystemColor_CONTROL_DK_SHADOW] =        [NSColor controlDarkShadowColor];
+    sColors[java_awt_SystemColor_SCROLLBAR] =                [NSColor scrollBarColor];
+    sColors[java_awt_SystemColor_INFO] =                    [NSColor textBackgroundColor];
+    sColors[java_awt_SystemColor_INFO_TEXT] =                [NSColor textColor];
+
+    for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) {
+        if (sColors[i] != NULL) CFRetain(sColors[i]); // GC
+    }
+
+    if (appleColors == nil) {
+        appleColors = (NSColor**)malloc(sizeof(NSColor*) * sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS);
+    } else {
+        for (i = 0; i < sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS; i++) {
+            if (appleColors[i] != NULL) CFRelease(appleColors[i]); // GC
+        }
+    }
+
+    appleColors[sun_lwawt_macosx_LWCToolkit_KEYBOARD_FOCUS_COLOR] =                    [NSColor keyboardFocusIndicatorColor];
+    appleColors[sun_lwawt_macosx_LWCToolkit_INACTIVE_SELECTION_BACKGROUND_COLOR] =    [NSColor secondarySelectedControlColor];
+    appleColors[sun_lwawt_macosx_LWCToolkit_INACTIVE_SELECTION_FOREGROUND_COLOR] =    [NSColor controlDarkShadowColor];
+
+    for (i = 0; i < sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS; i++) {
+        if (appleColors[i] != NULL) CFRetain(appleColors[i]); // GC
+    }
+}
+
++ (NSColor*)getColor:(NSUInteger)colorIndex useAppleColor:(BOOL)useAppleColor {
+    NSColor* result = nil;
+
+    if (colorIndex < (useAppleColor) ? sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS : java_awt_SystemColor_NUM_COLORS) {
+        result = (useAppleColor ? appleColors : sColors)[colorIndex];
+    }
+    else {
+        NSLog(@"%s: %s %sColor: %ld not found, returning black.", __FILE__, __FUNCTION__, (useAppleColor) ? "Apple" : "System", colorIndex);
+        result = [NSColor blackColor];
+    }
+
+    return result;
+}
+@end
diff --git a/jdk/src/macosx/native/sun/awt/CTextPipe.m b/jdk/src/macosx/native/sun/awt/CTextPipe.m
new file mode 100644
index 0000000..37e8d4a
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CTextPipe.m
@@ -0,0 +1,653 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//  Native side of the Quartz text pipe, paints on Quartz Surface Datas.
+//  Interesting Docs : /Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/FontHandling/FontHandling.html
+
+#import "sun_awt_SunHints.h"
+#import "sun_lwawt_macosx_CTextPipe.h"
+#import "sun_java2d_OSXSurfaceData.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CoreTextSupport.h"
+#import "QuartzSurfaceData.h"
+#include "AWTStrike.h"
+
+
+static const CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
+
+
+#pragma mark --- CoreText Support ---
+
+
+// Translates a Unicode into a CGGlyph/CTFontRef pair
+// Returns the substituted font, and places the appropriate glyph into "glyphRef"
+CTFontRef JavaCT_CopyCTFallbackFontAndGlyphForUnicode
+(const AWTFont *font, const UTF16Char *charRef, CGGlyph *glyphRef, int count) {
+    CTFontRef fallback = JRSFontCreateFallbackFontForCharacters((CTFontRef)font->fFont, charRef, count);
+    if (fallback == NULL)
+    {
+        // use the original font if we somehow got duped into trying to fallback something we can't
+        fallback = (CTFontRef)font->fFont;
+        CFRetain(fallback);
+    }
+
+    CTFontGetGlyphsForCharacters(fallback, charRef, glyphRef, count);
+    return fallback;
+}
+
+// Translates a Java glyph code int (might be a negative unicode value) into a CGGlyph/CTFontRef pair
+// Returns the substituted font, and places the appropriate glyph into "glyph"
+CTFontRef JavaCT_CopyCTFallbackFontAndGlyphForJavaGlyphCode
+(const AWTFont *font, const jint glyphCode, CGGlyph *glyphRef)
+{
+    // negative glyph codes are really unicodes, which were placed there by the mapper
+    // to indicate we should use CoreText to substitute the character
+    if (glyphCode >= 0)
+    {
+        *glyphRef = glyphCode;
+        CFRetain(font->fFont);
+        return (CTFontRef)font->fFont;
+    }
+
+    UTF16Char character = -glyphCode;
+    return JavaCT_CopyCTFallbackFontAndGlyphForUnicode(font, &character, glyphRef, 1);
+}
+
+// Breakup a 32 bit unicode value into the component surrogate pairs
+void JavaCT_BreakupUnicodeIntoSurrogatePairs(int uniChar, UTF16Char charRef[]) {
+    int value = uniChar - 0x10000;
+    UTF16Char low_surrogate = (value & 0x3FF) | LO_SURROGATE_START;
+    UTF16Char high_surrogate = (((int)(value & 0xFFC00)) >> 10) | HI_SURROGATE_START;
+    charRef[0] = high_surrogate;
+    charRef[1] = low_surrogate;
+}
+
+
+
+/*
+ * Callback for CoreText which uses the CoreTextProviderStruct to feed CT UniChars
+ * We only use it for one-off lines, and don't attempt to fragment our strings
+ */
+const UniChar *Java_CTProvider
+(CFIndex stringIndex, CFIndex *charCount, CFDictionaryRef *attributes, void *refCon)
+{
+    // if we have a zero length string we can just return NULL for the string
+    // or if the index anything other than 0 we are not using core text
+    // correctly since we only have one run.
+    if (stringIndex != 0)
+    {
+        return NULL;
+    }
+
+    CTS_ProviderStruct *ctps = (CTS_ProviderStruct *)refCon;
+    *charCount = ctps->length;
+    *attributes = ctps->attributes;
+    return ctps->unicodes;
+}
+
+
+/*
+ *    Gets a Dictionary filled with common details we want to use for CoreText when we are interacting
+ *    with it from Java.
+ */
+static NSDictionary* ctsDictionaryFor(const NSFont *font, BOOL useFractionalMetrics)
+{
+    NSNumber *gZeroNumber = [NSNumber numberWithInt:0];
+    NSNumber *gOneNumber = [NSNumber numberWithInt:1];
+
+    return [NSDictionary dictionaryWithObjectsAndKeys:
+             font, NSFontAttributeName,
+             gOneNumber,  (id)kCTForegroundColorFromContextAttributeName,
+             useFractionalMetrics ? gZeroNumber : gOneNumber, @"CTIntegerMetrics", // force integer hack in CoreText to help with Java's integer assumptions
+             gZeroNumber, NSLigatureAttributeName,
+             gZeroNumber, NSKernAttributeName,
+             nil];
+}
+
+// Itterates though each glyph, and if a transform is present for that glyph, apply it to the CGContext, and strike the glyph.
+// If there is no per-glyph transform, just strike the glyph. Advances must also be transformed on-the-spot as well.
+void JavaCT_DrawGlyphVector
+(const QuartzSDOps *qsdo, const AWTStrike *strike, const BOOL useSubstituion, const int uniChars[], const CGGlyph glyphs[], CGSize advances[], const jint g_gvTXIndicesAsInts[], const jdouble g_gvTransformsAsDoubles[], const CFIndex length)
+{
+    CGPoint pt = { 0, 0 };
+
+    // get our baseline transform and font
+    CGContextRef cgRef = qsdo->cgRef;
+    CGAffineTransform ctmText = CGContextGetTextMatrix(cgRef);
+    //CGFontRef cgFont = CGContextGetFont(cgRef);
+
+    CGContextSaveGState(cgRef);
+    CGAffineTransform invTx = CGAffineTransformInvert(strike->fTx);
+
+    NSUInteger i;
+    for (i = 0; i < length; i++)
+    {
+        CGGlyph glyph = glyphs[i];
+        int uniChar = uniChars[i];
+        // if we found a unichar instead of a glyph code, get the fallback font,
+        // find the glyph code for the fallback font, and set the font on the current context
+        if (uniChar != 0)
+        {
+            CTFontRef fallback;
+            if (uniChar > 0xFFFF) {
+                UTF16Char charRef[2];
+                JavaCT_BreakupUnicodeIntoSurrogatePairs(uniChar, charRef);
+                CGGlyph glyphTmp[2];
+                fallback = JavaCT_CopyCTFallbackFontAndGlyphForUnicode(strike->fAWTFont, (const UTF16Char *)&charRef, (CGGlyph *)&glyphTmp, 2);
+                glyph = glyphTmp[0];
+            } else {
+                const UTF16Char u = uniChar;
+                fallback = JavaCT_CopyCTFallbackFontAndGlyphForUnicode(strike->fAWTFont, &u, (CGGlyph *)&glyph, 1);
+            }
+            if (fallback) {
+                const CGFontRef cgFallback = CTFontCopyGraphicsFont(fallback, NULL);
+                CFRelease(fallback);
+
+                if (cgFallback) {
+                    CGContextSetFont(cgRef, cgFallback);
+                    CFRelease(cgFallback);
+                }
+            }
+        }
+
+        // if we have per-glyph transformations
+        int tin = (g_gvTXIndicesAsInts == NULL) ? -1 : (g_gvTXIndicesAsInts[i] - 1) * 6;
+        if (tin < 0)
+        {
+            CGContextShowGlyphsAtPoint(cgRef, pt.x, pt.y, &glyph, 1);
+        }
+        else
+        {
+            CGAffineTransform tx = CGAffineTransformMake(
+                                                         (CGFloat)g_gvTransformsAsDoubles[tin + 0], (CGFloat)g_gvTransformsAsDoubles[tin + 2],
+                                                         (CGFloat)g_gvTransformsAsDoubles[tin + 1], (CGFloat)g_gvTransformsAsDoubles[tin + 3],
+                                                         0, 0);
+
+            CGPoint txOffset = { (CGFloat)g_gvTransformsAsDoubles[tin + 4], (CGFloat)g_gvTransformsAsDoubles[tin + 5] };
+
+            txOffset = CGPointApplyAffineTransform(txOffset, invTx);
+
+            // apply the transform, strike the glyph, can change the transform back
+            CGContextSetTextMatrix(cgRef, CGAffineTransformConcat(ctmText, tx));
+            CGContextShowGlyphsAtPoint(cgRef, txOffset.x + pt.x, txOffset.y + pt.y, &glyph, 1);
+            CGContextSetTextMatrix(cgRef, ctmText);
+
+            // transform the measured advance for this strike
+            advances[i] = CGSizeApplyAffineTransform(advances[i], tx);
+            advances[i].width += txOffset.x;
+            advances[i].height += txOffset.y;
+        }
+
+        // move our next x,y
+        pt.x += advances[i].width;
+        pt.y += advances[i].height;
+
+        // reset the font on the context after striking a unicode with CoreText
+        if (uniChar != 0)
+        {
+           // CGContextSetFont(cgRef, cgFont);
+            CGContextSaveGState(cgRef);
+        }
+    }
+}
+
+// Using the Quartz Surface Data context, draw a hot-substituted character run
+void JavaCT_DrawTextUsingQSD(JNIEnv *env, const QuartzSDOps *qsdo, const AWTStrike *strike, const jchar *chars, const jsize length)
+{
+    CGContextRef cgRef = qsdo->cgRef;
+
+    AWTFont *awtFont = strike->fAWTFont;
+    CGFloat ptSize = strike->fSize;
+    CGAffineTransform tx = strike->fFontTx;
+
+    NSFont *nsFont = [NSFont fontWithName:[awtFont->fFont fontName] size:ptSize];
+
+    if (ptSize != 0) {
+        CGFloat invScale = 1 / ptSize;
+        tx = CGAffineTransformConcat(tx, CGAffineTransformMakeScale(invScale, invScale));
+        CGContextConcatCTM(cgRef, tx);
+    }
+
+    CGContextSetTextMatrix(cgRef, CGAffineTransformIdentity); // resets the damage from CoreText
+
+    NSString *string = [NSString stringWithCharacters:chars length:length];
+    NSAttributedString *attribString = [[NSAttributedString alloc] initWithString:string];
+
+    CTTypesetterRef typeSetterRef = CTTypesetterCreateWithAttributedStringAndOptions((CFAttributedStringRef) attribString, (CFDictionaryRef) ctsDictionaryFor(nsFont, JRSFontStyleUsesFractionalMetrics(strike->fStyle)));
+
+    CFRange range = {0, length};
+    CTLineRef lineRef = CTTypesetterCreateLine(typeSetterRef, range);
+
+    CTLineDraw(lineRef, cgRef);
+
+    [attribString release];
+    CFRelease(lineRef);
+    CFRelease(typeSetterRef);
+}
+
+
+/*----------------------
+    DrawTextContext is the funnel for all of our CoreText drawing.
+    All three JNI apis call through this method.
+ ----------------------*/
+static void DrawTextContext
+(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, const jchar *chars, const jsize length, const jdouble x, const jdouble y)
+{
+    if (length == 0)
+    {
+        return;
+    }
+
+    qsdo->BeginSurface(env, qsdo, SD_Text);
+    if (qsdo->cgRef == NULL)
+    {
+        qsdo->FinishSurface(env, qsdo);
+        return;
+    }
+
+    CGContextRef cgRef = qsdo->cgRef;
+
+
+    CGContextSaveGState(cgRef);
+    JRSFontSetRenderingStyleOnContext(cgRef, strike->fStyle);
+
+    // we want to translate before we transform (scale or rotate) <rdar://4042541> (vm)
+    CGContextTranslateCTM(cgRef, x, y);
+
+    AWTFont *awtfont = strike->fAWTFont; //(AWTFont *)(qsdo->fontInfo.awtfont);
+    NSCharacterSet *charSet = [awtfont->fFont coveredCharacterSet];
+
+    JavaCT_DrawTextUsingQSD(env, qsdo, strike, chars, length);   // Draw with CoreText
+
+    CGContextRestoreGState(cgRef);
+
+    qsdo->FinishSurface(env, qsdo);
+}
+
+#pragma mark --- Glyph Vector Pipeline ---
+
+/*-----------------------------------
+    Glyph Vector Pipeline
+
+    doDrawGlyphs() has been separated into several pipelined functions to increase performance,
+    and improve accountability for JNI resources, malloc'd memory, and error handling.
+
+    Each stage of the pipeline is responsible for doing only one major thing, like allocating buffers,
+    aquiring transform arrays from JNI, filling buffers, or striking glyphs. All resources or memory
+    aquired at a given stage, must be released in that stage. Any error that occurs (like a failed malloc)
+    is to be handled in the stage it occurs in, and is to return immediatly after freeing it's resources.
+
+-----------------------------------*/
+
+static JNF_CLASS_CACHE(jc_StandardGlyphVector, "sun/font/StandardGlyphVector");
+
+// Checks the GlyphVector Java object for any transforms that were applied to individual characters. If none are present,
+// strike the glyphs immediately in Core Graphics. Otherwise, obtain the arrays, and defer to above.
+static inline void doDrawGlyphsPipe_checkForPerGlyphTransforms
+(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, BOOL useSubstituion, int *uniChars, CGGlyph *glyphs, CGSize *advances, size_t length)
+{
+    // if we have no character substitution, and no per-glyph transformations - strike now!
+    static JNF_MEMBER_CACHE(jm_StandardGlyphVector_gti, jc_StandardGlyphVector, "gti", "Lsun/font/StandardGlyphVector$GlyphTransformInfo;");
+    jobject gti = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_gti);
+    if (gti == 0)
+    {
+        if (useSubstituion)
+        {
+            // quasi-simple case, substitution, but no per-glyph transforms
+            JavaCT_DrawGlyphVector(qsdo, strike, TRUE, uniChars, glyphs, advances, NULL, NULL, length);
+        }
+        else
+        {
+            // fast path, straight to CG without per-glyph transforms
+            CGContextShowGlyphsWithAdvances(qsdo->cgRef, glyphs, advances, length);
+        }
+        return;
+    }
+
+    static JNF_CLASS_CACHE(jc_StandardGlyphVector_GlyphTransformInfo, "sun/font/StandardGlyphVector$GlyphTransformInfo");
+    static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_transforms, jc_StandardGlyphVector_GlyphTransformInfo, "transforms", "[D");
+    jdoubleArray g_gtiTransformsArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_transforms); //(*env)->GetObjectField(env, gti, g_gtiTransforms);
+    jdouble *g_gvTransformsAsDoubles = (*env)->GetPrimitiveArrayCritical(env, g_gtiTransformsArray, NULL);
+
+    static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_indices, jc_StandardGlyphVector_GlyphTransformInfo, "indices", "[I");
+    jintArray g_gtiTXIndicesArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_indices);
+    jint *g_gvTXIndicesAsInts = (*env)->GetPrimitiveArrayCritical(env, g_gtiTXIndicesArray, NULL);
+
+    // slowest case, we have per-glyph transforms, and possibly glyph substitution as well
+    JavaCT_DrawGlyphVector(qsdo, strike, useSubstituion, uniChars, glyphs, advances, g_gvTXIndicesAsInts, g_gvTransformsAsDoubles, length);
+
+    (*env)->ReleasePrimitiveArrayCritical(env, g_gtiTransformsArray, g_gvTransformsAsDoubles, JNI_ABORT);
+    (*env)->DeleteLocalRef(env, g_gtiTransformsArray);
+
+    (*env)->ReleasePrimitiveArrayCritical(env, g_gtiTXIndicesArray, g_gvTXIndicesAsInts, JNI_ABORT);
+    (*env)->DeleteLocalRef(env, g_gtiTXIndicesArray);
+}
+
+// Retrieves advances for translated unicodes
+// Uses "glyphs" as a temporary buffer for the glyph-to-unicode translation
+void JavaCT_GetAdvancesForUnichars
+(const NSFont *font, const int uniChars[], CGGlyph glyphs[], const size_t length, CGSize advances[])
+{
+    // cycle over each spot, and if we discovered a unicode to substitute, we have to calculate the advance for it
+    size_t i;
+    for (i = 0; i < length; i++)
+    {
+        UniChar uniChar = uniChars[i];
+        if (uniChar == 0) continue;
+
+        CGGlyph glyph = 0;
+        const CTFontRef fallback = JRSFontCreateFallbackFontForCharacters((CTFontRef)font, &uniChar, 1);
+        if (fallback) {
+            CTFontGetGlyphsForCharacters(fallback, &uniChar, &glyph, 1);
+            CTFontGetAdvancesForGlyphs(fallback, kCTFontDefaultOrientation, &glyph, &(advances[i]), 1);
+            CFRelease(fallback);
+        }
+
+        glyphs[i] = glyph;
+    }
+}
+
+// Fills the glyph buffer with glyphs from the GlyphVector object. Also checks to see if the glyph's positions have been
+// already caculated from GlyphVector, or we simply ask Core Graphics to make some advances for us. Pre-calculated positions
+// are translated into advances, since CG only understands advances.
+static inline void doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers
+(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, CGGlyph *glyphs, int *uniChars, CGSize *advances, size_t length, jintArray glyphsArray)
+{
+    // fill the glyph buffer
+    jint *glyphsAsInts = (*env)->GetPrimitiveArrayCritical(env, glyphsArray, NULL);
+
+    // if a glyph code from Java is negative, that means it is really a unicode value
+    // which we can use in CoreText to strike the character in another font
+    size_t i;
+    BOOL complex = NO;
+    for (i = 0; i < length; i++)
+    {
+        jint code = glyphsAsInts[i];
+        if (code < 0)
+        {
+            complex = YES;
+            uniChars[i] = -code;
+            glyphs[i] = 0;
+        }
+        else
+        {
+            uniChars[i] = 0;
+            glyphs[i] = code;
+        }
+    }
+
+    (*env)->ReleasePrimitiveArrayCritical(env, glyphsArray, glyphsAsInts, JNI_ABORT);
+
+    // fill the advance buffer
+    static JNF_MEMBER_CACHE(jm_StandardGlyphVector_positions, jc_StandardGlyphVector, "positions", "[F");
+    jfloatArray posArray = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_positions);
+    if (posArray != NULL)
+    {
+        // in this case, the positions have already been pre-calculated for us on the Java side
+
+        jfloat *positions = (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
+        CGPoint prev;
+        prev.x = positions[0];
+        prev.y = positions[1];
+
+        // <rdar://problem/4294061> take the first point, and move the context to that location
+        CGContextTranslateCTM(qsdo->cgRef, prev.x, prev.y);
+
+        CGAffineTransform invTx = CGAffineTransformInvert(strike->fFontTx);
+
+        // for each position, figure out the advance (since CG won't take positions directly)
+        size_t i;
+        for (i = 0; i < length - 1; i++)
+        {
+            size_t i2 = (i+1) * 2;
+            CGPoint pt;
+            pt.x = positions[i2];
+            pt.y = positions[i2+1];
+            pt = CGPointApplyAffineTransform(pt, invTx);
+            advances[i].width = pt.x - prev.x;
+            advances[i].height = -(pt.y - prev.y); // negative to translate to device space
+            prev.x = pt.x;
+            prev.y = pt.y;
+        }
+
+        (*env)->ReleasePrimitiveArrayCritical(env, posArray, positions, JNI_ABORT);
+        (*env)->DeleteLocalRef(env, posArray);
+    }
+    else
+    {
+        // in this case, we have to go and calculate the positions ourselves
+        // there were no pre-calculated positions from the glyph buffer on the Java side
+        AWTFont *awtFont = strike->fAWTFont;
+        CTFontGetAdvancesForGlyphs((CTFontRef)awtFont->fFont, kCTFontDefaultOrientation, glyphs, advances, length);
+
+        if (complex)
+        {
+            JavaCT_GetAdvancesForUnichars(awtFont->fFont, uniChars, glyphs, length, advances);
+        }
+    }
+
+    // continue on to the next stage of the pipe
+    doDrawGlyphsPipe_checkForPerGlyphTransforms(env, qsdo, strike, gVector, complex, uniChars, glyphs, advances, length);
+}
+
+// Obtains the glyph array to determine the number of glyphs we are dealing with. If we are dealing a large number of glyphs,
+// we malloc a buffer to hold the glyphs and their advances, otherwise we use stack allocated buffers.
+static inline void doDrawGlyphsPipe_getGlyphVectorLengthAndAlloc
+(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector)
+{
+    static JNF_MEMBER_CACHE(jm_StandardGlyphVector_glyphs, jc_StandardGlyphVector, "glyphs", "[I");
+    jintArray glyphsArray = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_glyphs);
+    jsize length = (*env)->GetArrayLength(env, glyphsArray);
+
+    if (length == 0)
+    {
+        // nothing to draw
+        (*env)->DeleteLocalRef(env, glyphsArray);
+        return;
+    }
+
+    if (length < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE)
+    {
+        // if we are small enough, fit everything onto the stack
+        CGGlyph glyphs[length];
+        int uniChars[length];
+        CGSize advances[length];
+        doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
+    }
+    else
+    {
+        // otherwise, we should malloc and free buffers for this large run
+        CGGlyph *glyphs = (CGGlyph *)malloc(sizeof(CGGlyph) * length);
+        int *uniChars = (int *)malloc(sizeof(int) * length);
+        CGSize *advances = (CGSize *)malloc(sizeof(CGSize) * length);
+
+        if (glyphs == NULL || advances == NULL)
+        {
+            (*env)->DeleteLocalRef(env, glyphsArray);
+            [NSException raise:NSMallocException format:@"%s-%s:%d", __FILE__, __FUNCTION__, __LINE__];
+            return;
+        }
+
+        doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
+
+        free(glyphs);
+        free(uniChars);
+        free(advances);
+    }
+
+    (*env)->DeleteLocalRef(env, glyphsArray);
+}
+
+// Setup and save the state of the CGContext, and apply any java.awt.Font transforms to the context.
+static inline void doDrawGlyphsPipe_applyFontTransforms
+(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, const jfloat x, const jfloat y)
+{
+    CGContextRef cgRef = qsdo->cgRef;
+    CGContextSetFontSize(cgRef, 1.0);
+    CGContextSetFont(cgRef, strike->fAWTFont->fNativeCGFont);
+    CGContextSetTextMatrix(cgRef, CGAffineTransformIdentity);
+
+    CGAffineTransform tx = strike->fFontTx;
+    tx.tx += x;
+    tx.ty += y;
+    CGContextConcatCTM(cgRef, tx);
+
+    doDrawGlyphsPipe_getGlyphVectorLengthAndAlloc(env, qsdo, strike, gVector);
+}
+
+
+#pragma mark --- CTextPipe JNI ---
+
+
+/*
+ * Class:     sun_lwawt_macosx_CTextPipe
+ * Method:    doDrawString
+ * Signature: (Lsun/java2d/SurfaceData;JLjava/lang/String;DD)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTextPipe_doDrawString
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jstring str, jdouble x, jdouble y)
+{
+    QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
+    AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+
+JNF_COCOA_ENTER(env);
+
+    jsize len = (*env)->GetStringLength(env, str);
+
+    if (len < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation <rdar://problem/4285041>
+    {
+        jchar unichars[len];
+        (*env)->GetStringRegion(env, str, 0, len, unichars);
+        JNF_CHECK_AND_RETHROW_EXCEPTION(env);
+
+        // Draw the text context
+        DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y);
+    }
+    else
+    {
+        // Get string to draw and the length
+        const jchar *unichars = JNFGetStringUTF16UniChars(env, str);
+
+        // Draw the text context
+        DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y);
+
+        JNFReleaseStringUTF16UniChars(env, str, unichars);
+    }
+
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CTextPipe
+ * Method:    doUnicodes
+ * Signature: (Lsun/java2d/SurfaceData;J[CIIFF)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTextPipe_doUnicodes
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jcharArray unicodes, jint offset, jint length, jfloat x, jfloat y)
+{
+    QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
+    AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+
+JNF_COCOA_ENTER(env);
+
+    // Setup the text context
+    if (length < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation
+    {
+        jchar copyUnichars[length];
+        (*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars);
+        JNF_CHECK_AND_RETHROW_EXCEPTION(env);
+        DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y);
+    }
+    else
+    {
+        jchar *copyUnichars = malloc(length * sizeof(jchar));
+        if (!copyUnichars) {
+            [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory to create the glyphs for string drawing"];
+        }
+
+        @try {
+            (*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars);
+            JNF_CHECK_AND_RETHROW_EXCEPTION(env);
+            DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y);
+        } @finally {
+            free(copyUnichars);
+        }
+    }
+
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CTextPipe
+ * Method:    doOneUnicode
+ * Signature: (Lsun/java2d/SurfaceData;JCFF)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTextPipe_doOneUnicode
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jchar aUnicode, jfloat x, jfloat y)
+{
+    QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
+    AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+
+JNF_COCOA_ENTER(env);
+
+    DrawTextContext(env, qsdo, awtStrike, &aUnicode, 1, x, y);
+
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class: sun_lwawt_macosx_CTextPipe
+ * Method: doDrawGlyphs
+ * Signature: (Lsun/java2d/SurfaceData;JLjava/awt/font/GlyphVector;FF)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTextPipe_doDrawGlyphs
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jobject gVector, jfloat x, jfloat y)
+{
+    QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
+    AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+
+JNF_COCOA_ENTER(env);
+
+    qsdo->BeginSurface(env, qsdo, SD_Text);
+    if (qsdo->cgRef == NULL)
+    {
+        qsdo->FinishSurface(env, qsdo);
+        return;
+    }
+
+    CGContextSaveGState(qsdo->cgRef);
+    JRSFontSetRenderingStyleOnContext(qsdo->cgRef, JRSFontGetRenderingStyleForHints(sun_awt_SunHints_INTVAL_FRACTIONALMETRICS_ON, sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_ON));
+
+    doDrawGlyphsPipe_applyFontTransforms(env, qsdo, awtStrike, gVector, x, y);
+
+    CGContextRestoreGState(qsdo->cgRef);
+
+    qsdo->FinishSurface(env, qsdo);
+
+JNF_COCOA_RENDERER_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/CTrayIcon.h b/jdk/src/macosx/native/sun/awt/CTrayIcon.h
new file mode 100644
index 0000000..c5ceebf
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CTrayIcon.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <jni.h>
+#import <Foundation/Foundation.h>
+#import <AppKit/AppKit.h>
+
+#import "CPopupMenu.h"
+
+#ifndef _Included_sun_awt_lwmacosx_CTrayIcon
+#define _Included_sun_awt_lwmacosx_CTrayIcon
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+@class AWTTrayIconView;
+
+/*
+ * AWTTrayIcon
+ */
+@interface AWTTrayIcon : NSObject {
+    jobject peer;
+    AWTTrayIconView *view;
+    NSStatusItem *theItem;
+}
+
+- (id) initWithPeer:(jobject)thePeer;
+- (void) setTooltip:(NSString *)tooltip;
+- (NSStatusItem *)theItem;
+- (jobject) peer;
+- (void) setImage:(NSImage *) imagePtr sizing:(BOOL)autosize;
+- (NSPoint) getLocationOnScreen;
+
+@end //AWTTrayIcon
+
+//==================================================================================
+/*
+ * AWTTrayIconView */
+@interface AWTTrayIconView : NSView <NSMenuDelegate> {
+@public
+    AWTTrayIcon *trayIcon;
+    NSImage* image;
+    BOOL isHighlighted;
+}
+-(id)initWithTrayIcon:(AWTTrayIcon *)theTrayIcon;
+-(void)setHighlighted:(BOOL)aFlag;
+-(void)setImage:(NSImage*)anImage;
+
+@end //AWTTrayIconView
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/jdk/src/macosx/native/sun/awt/CTrayIcon.m b/jdk/src/macosx/native/sun/awt/CTrayIcon.m
new file mode 100644
index 0000000..431af34
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CTrayIcon.m
@@ -0,0 +1,316 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CTrayIcon.h"
+#import "ThreadUtilities.h"
+#include "GeomUtilities.h"
+
+#define kImageInset 4.0
+
+/**
+ * If the image of the specified size won't fit into the status bar,
+ * then scale it down proprtionally. Otherwise, leave it as is.
+ */
+static NSSize ScaledImageSizeForStatusBar(NSSize imageSize) {
+    NSRect imageRect = NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height);
+    
+    // There is a black line at the bottom of the status bar  
+    // that we don't want to cover with image pixels.
+    CGFloat desiredHeight = [[NSStatusBar systemStatusBar] thickness] - 1.0;
+    CGFloat scaleFactor = MIN(1.0, desiredHeight/imageSize.height);
+    
+    imageRect.size.width *= scaleFactor;
+    imageRect.size.height *= scaleFactor;
+    imageRect = NSIntegralRect(imageRect);
+    
+    return imageRect.size;
+}
+
+@implementation AWTTrayIcon
+
+- (id) initWithPeer:(jobject)thePeer {
+    if (!(self = [super init])) return nil;
+
+    peer = thePeer;
+
+    theItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];  
+    [theItem retain];
+
+    view = [[AWTTrayIconView alloc] initWithTrayIcon:self];
+    [theItem setView:view];
+
+    return self;
+}
+
+-(void) dealloc {
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+    JNFDeleteGlobalRef(env, peer);
+
+    [[NSStatusBar systemStatusBar] removeStatusItem: theItem];
+
+    // Its a bad idea to force the item to release our view by setting
+    // the item's view to nil: it can lead to a crash in some scenarios.
+    // The item will release the view later on, so just set the view's image
+    // to nil since we are done with it.
+    [view setImage: nil];
+    [view release];
+
+    [theItem release];
+
+    [super dealloc];
+}
+
+- (void) setTooltip:(NSString *) tooltip{
+    [view setToolTip:tooltip];
+}
+
+-(NSStatusItem *) theItem{
+    return theItem;
+}
+
+- (jobject) peer{
+    return peer;
+}
+
+- (void) setImage:(NSImage *) imagePtr sizing:(BOOL)autosize{
+    NSSize imageSize = [imagePtr size];
+    NSSize scaledSize = ScaledImageSizeForStatusBar(imageSize);
+    if (imageSize.width != scaledSize.width || 
+        imageSize.height != scaledSize.height) {
+        [imagePtr setSize: scaledSize];
+    }
+    
+    CGFloat itemLength = scaledSize.width + 2.0*kImageInset;
+    [theItem setLength:itemLength];
+
+    [view setImage:imagePtr];
+}
+
+- (NSPoint) getLocationOnScreen {
+    return [[view window] convertBaseToScreen: NSZeroPoint];
+}
+
+@end //AWTTrayIcon
+//================================================
+
+@implementation AWTTrayIconView
+
+-(id)initWithTrayIcon:(AWTTrayIcon *)theTrayIcon {    
+    self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)];
+
+    trayIcon = theTrayIcon;
+    isHighlighted = NO;
+    image = nil;    
+        
+    return self;
+}
+
+-(void) dealloc {
+    [image release];
+    [super dealloc];
+}
+
+- (void)setHighlighted:(BOOL)aFlag 
+{
+    if (isHighlighted != aFlag) {
+        isHighlighted = aFlag;
+        [self setNeedsDisplay:YES];
+    }
+}
+
+- (void)setImage:(NSImage*)anImage {
+    [anImage retain];
+    [image release];   
+    image = anImage;
+
+    if (image != nil) {
+        [self setNeedsDisplay:YES];
+    }
+}
+
+- (void)menuWillOpen:(NSMenu *)menu 
+{
+    [self setHighlighted:YES];
+}
+
+- (void)menuDidClose:(NSMenu *)menu 
+{
+    [menu setDelegate:nil];
+    [self setHighlighted:NO];
+}
+
+- (void)drawRect:(NSRect)dirtyRect
+{
+    if (image == nil) {
+        return;
+    }
+
+    NSRect bounds = [self bounds];
+    NSSize imageSize = [image size];
+
+    NSRect drawRect = {{ (bounds.size.width - imageSize.width) / 2.0, 
+        (bounds.size.height - imageSize.height) / 2.0 }, imageSize};
+
+    // don't cover bottom pixels of the status bar with the image 
+    if (drawRect.origin.y < 1.0) {
+        drawRect.origin.y = 1.0;
+    }
+    drawRect = NSIntegralRect(drawRect);    
+    
+    [trayIcon.theItem drawStatusBarBackgroundInRect:bounds
+                                withHighlight:isHighlighted];       
+    [image drawInRect:drawRect 
+             fromRect:NSZeroRect 
+            operation:NSCompositeSourceOver 
+             fraction:1.0
+     ];
+}
+
+- (void) mouseDown:(NSEvent *)e {
+    //find CTrayIcon.getPopupMenuModel method and call it to get popup menu ptr.
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon");
+    static JNF_MEMBER_CACHE(jm_getPopupMenuModel, jc_CTrayIcon, "getPopupMenuModel", "()J");
+    static JNF_MEMBER_CACHE(jm_performAction, jc_CTrayIcon, "performAction", "()V");
+    jlong res = JNFCallLongMethod(env, trayIcon.peer, jm_getPopupMenuModel);
+    if (res != 0) {
+        CPopupMenu *cmenu = jlong_to_ptr(res);
+        NSMenu* menu = [cmenu menu];
+        [menu setDelegate:self];
+        [trayIcon.theItem popUpStatusItemMenu:menu];
+        [self setNeedsDisplay:YES];        
+    } else {
+        JNFCallVoidMethod(env, trayIcon.peer, jm_performAction);
+    }
+}
+
+- (void) rightMouseDown:(NSEvent *)e {
+    // Call CTrayIcon.performAction() method on right mouse press
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon");
+    static JNF_MEMBER_CACHE(jm_performAction, jc_CTrayIcon, "performAction", "()V");
+    JNFCallVoidMethod(env, trayIcon.peer, jm_performAction);
+}
+
+
+@end //AWTTrayIconView
+//================================================
+
+/*
+ * Class:     sun_lwawt_macosx_CTrayIcon
+ * Method:    nativeCreate
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CTrayIcon_nativeCreate
+(JNIEnv *env, jobject peer) {
+    __block AWTTrayIcon *trayIcon = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    jobject thePeer = JNFNewGlobalRef(env, peer);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        trayIcon = [[AWTTrayIcon alloc] initWithPeer:thePeer];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(trayIcon);
+}
+
+
+/*
+ * Class: java_awt_TrayIcon
+ * Method: initIDs
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_awt_TrayIcon_initIDs
+(JNIEnv *env, jclass cls) {
+    //Do nothing.
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CTrayIcon
+ * Method:    nativeSetToolTip
+ * Signature: (JLjava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_nativeSetToolTip
+(JNIEnv *env, jobject self, jlong model, jstring jtooltip) {
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTTrayIcon *icon = jlong_to_ptr(model);
+    NSString *tooltip = JNFJavaToNSString(env, jtooltip);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [icon setTooltip:tooltip];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CTrayIcon
+ * Method:    setNativeImage
+ * Signature: (JJZ)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_setNativeImage
+(JNIEnv *env, jobject self, jlong model, jlong imagePtr, jboolean autosize) {
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    AWTTrayIcon *icon = jlong_to_ptr(model);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        [icon setImage:jlong_to_ptr(imagePtr) sizing:autosize];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+JNIEXPORT jobject JNICALL
+Java_sun_lwawt_macosx_CTrayIcon_nativeGetIconLocation
+(JNIEnv *env, jobject self, jlong model) {
+    jobject jpt = NULL;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+  
+    __block NSPoint pt = NSZeroPoint;
+    AWTTrayIcon *icon = jlong_to_ptr(model);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+    
+        NSPoint loc = [icon getLocationOnScreen];        
+        pt = ConvertNSScreenPoint(env, loc);
+    }];
+
+    jpt = NSToJavaPoint(env, pt);
+   
+JNF_COCOA_EXIT(env);
+    
+    return jpt;
+}
diff --git a/jdk/src/macosx/native/sun/awt/CWrapper.h b/jdk/src/macosx/native/sun/awt/CWrapper.h
new file mode 100644
index 0000000..24ac9c5
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CWrapper.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
diff --git a/jdk/src/macosx/native/sun/awt/CWrapper.m b/jdk/src/macosx/native/sun/awt/CWrapper.m
new file mode 100644
index 0000000..5d5ebcd
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CWrapper.m
@@ -0,0 +1,702 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CWrapper.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "AWTWindow.h"
+#import "LWCToolkit.h"
+#import "GeomUtilities.h"
+#import "ThreadUtilities.h"
+
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSObject
+ * Method:    release
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSObject_release
+(JNIEnv *env, jclass cls, jlong objectPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    id obj = (id)jlong_to_ptr(objectPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        CFRelease(obj);
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    makeKeyAndOrderFront
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeKeyAndOrderFront
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(makeKeyAndOrderFront:)
+                                 on:window
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    makeMainWindow
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeMainWindow
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(makeMainWindow)
+                                 on:window
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    canBecomeMainWindow
+ * Signature: (J)V
+ */
+JNIEXPORT jboolean JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_canBecomeMainWindow
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+    __block jboolean canBecomeMainWindow = JNI_FALSE;
+
+JNF_COCOA_ENTER(env);
+    
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+	canBecomeMainWindow = [window canBecomeMainWindow];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return canBecomeMainWindow;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    isKeyWindow
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_isKeyWindow
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+    __block jboolean isKeyWindow = JNI_FALSE;
+
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        isKeyWindow = [window isKeyWindow];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return isKeyWindow;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    orderFront
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderFront
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(orderFront:)
+                                 on:window
+                         withObject:window
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    orderOut
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderOut
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(orderOut:)
+                                 on:window
+                         withObject:window
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    orderFrontRegardless
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderFrontRegardless
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(orderFrontRegardless)
+                                 on:window
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    orderWindow
+ * Signature: (JIJ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderWindow
+(JNIEnv *env, jclass cls, jlong windowPtr, jint order, jlong relativeToPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    NSWindow *relativeTo = (NSWindow *)jlong_to_ptr(relativeToPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window orderWindow:(NSWindowOrderingMode)order relativeTo:[relativeTo windowNumber]];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    addChildWindow
+ * Signature: (JJI)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_addChildWindow
+(JNIEnv *env, jclass cls, jlong parentPtr, jlong childPtr, jint order)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *parent = (NSWindow *)jlong_to_ptr(parentPtr);
+    NSWindow *child = (NSWindow *)jlong_to_ptr(childPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [parent addChildWindow:child ordered:order];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    removeChildWindow
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_removeChildWindow
+(JNIEnv *env, jclass cls, jlong parentPtr, jlong childPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *parent = (AWTWindow *)jlong_to_ptr(parentPtr);
+    AWTWindow *child = (AWTWindow *)jlong_to_ptr(childPtr);
+    [JNFRunLoop performOnMainThread:@selector(removeChildWindow:)
+                                 on:parent
+                         withObject:child
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    setFrame
+ * Signature: (JIIIIZ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setFrame
+(JNIEnv *env, jclass cls, jlong windowPtr, jint x, jint y, jint w, jint h, jboolean display)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
+    NSRect frame = NSMakeRect(x, y, w, h);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window setFrame:frame display:display];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    setAlphaValue
+ * Signature: (JF)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setAlphaValue
+(JNIEnv *env, jclass cls, jlong windowPtr, jfloat alpha)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window setAlphaValue:(CGFloat)alpha];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    setOpaque
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setOpaque
+(JNIEnv *env, jclass cls, jlong windowPtr, jboolean opaque)
+{
+JNF_COCOA_ENTER(env);
+    
+    AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window setOpaque:(BOOL)opaque];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    setBackgroundColor
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setBackgroundColor
+(JNIEnv *env, jclass cls, jlong windowPtr, jlong colorPtr)
+{
+JNF_COCOA_ENTER(env);
+    
+    AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
+    NSColor *color = (NSColor *)jlong_to_ptr(colorPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window setBackgroundColor:color];
+    }];
+    
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    screen
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_screen
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+    __block jlong screenPtr = 0L;
+
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        const NSScreen *screen = [window screen];
+        CFRetain(screen); // GC
+        screenPtr = ptr_to_jlong(screen);
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return screenPtr;
+}
+
+/*
+ * Method:    miniaturize
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_miniaturize
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(miniaturize:)
+                                 on:window
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    deminiaturize
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_deminiaturize
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(deminiaturize:)
+                                 on:window
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    zoom
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_zoom
+(JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [JNFRunLoop performOnMainThread:@selector(zoom:)
+                                 on:window
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    makeFirstResponder
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeFirstResponder
+(JNIEnv *env, jclass cls, jlong windowPtr, jlong responderPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    NSResponder *responder = (NSResponder *)jlong_to_ptr(responderPtr);
+    [JNFRunLoop performOnMainThread:@selector(makeFirstResponder:)
+                                 on:window
+                         withObject:responder
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSView
+ * Method:    addSubview
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSView_addSubview
+(JNIEnv *env, jclass cls, jlong viewPtr, jlong subviewPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+    NSView *subview = (NSView *)jlong_to_ptr(subviewPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        [view addSubview:subview];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSView
+ * Method:    removeFromSuperview
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSView_removeFromSuperview
+(JNIEnv *env, jclass cls, jlong viewPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+    [JNFRunLoop performOnMainThread:@selector(removeFromSuperview)
+                                 on:view
+                         withObject:nil
+                      waitUntilDone:NO];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSView
+ * Method:    setFrame
+ * Signature: (JIIII)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSView_setFrame
+(JNIEnv *env, jclass cls, jlong viewPtr, jint x, jint y, jint w, jint h)
+{
+JNF_COCOA_ENTER(env);
+
+    NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [view setFrame:NSMakeRect(x, y, w, h)];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSView
+ * Method:    frame
+ * Signature: (J)Ljava/awt/Rectangle;
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSView_frame
+(JNIEnv *env, jclass cls, jlong viewPtr)
+{
+    jobject jRect = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    __block NSRect rect = NSZeroRect;
+
+    NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        rect = [view frame];
+    }];
+
+    jRect = NSToJavaRect(env, rect);
+
+JNF_COCOA_EXIT(env);
+
+    return jRect;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSView
+ * Method:    enterFullScreenMode
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSView_enterFullScreenMode
+(JNIEnv *env, jclass cls, jlong viewPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        NSScreen *screen = [[view window] screen];
+        NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], NSFullScreenModeAllScreens, nil];
+        [view enterFullScreenMode:screen withOptions:opts];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSView
+ * Method:    exitFullScreenMode
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSView_exitFullScreenMode
+(JNIEnv *env, jclass cls, jlong viewPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [view exitFullScreenModeWithOptions:nil];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSView
+ * Method:    window
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSView_window
+(JNIEnv *env, jclass cls, jlong viewPtr)
+{
+    __block jlong windowPtr = 0L;
+
+JNF_COCOA_ENTER(env);
+
+    NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        windowPtr = ptr_to_jlong([view window]);
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return windowPtr;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSScreen
+ * Method:    frame
+ * Signature: (J)Ljava/awt/Rectangle;
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSScreen_frame
+(JNIEnv *env, jclass cls, jlong screenPtr)
+{
+    jobject jRect = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    __block NSRect rect = NSZeroRect;
+
+    NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        rect = [screen frame];
+    }];
+
+    jRect = NSToJavaRect(env, rect);
+
+JNF_COCOA_EXIT(env);
+
+    return jRect;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper_NSScreen
+ * Method:    visibleFrame
+ * Signature: (J)Ljava/awt/geom/Rectangle2D;
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSScreen_visibleFrame
+(JNIEnv *env, jclass cls, jlong screenPtr)
+{
+    jobject jRect = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    __block NSRect rect = NSZeroRect;
+
+    NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        rect = [screen visibleFrame];
+    }];
+
+    jRect = NSToJavaRect(env, rect);
+
+JNF_COCOA_EXIT(env);
+
+    return jRect;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper_NSScreen
+ * Method:    screenByDisplayId
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSScreen_screenByDisplayId
+(JNIEnv *env, jclass cls, jint displayID)
+{
+    __block jlong screenPtr = 0L;
+
+JNF_COCOA_ENTER(env);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        NSArray *screens = [NSScreen screens];
+        for (NSScreen *screen in screens) {
+            NSDictionary *screenInfo = [screen deviceDescription];
+            NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
+            if ([screenID intValue] == displayID){
+                CFRetain(screen); // GC
+                screenPtr = ptr_to_jlong(screen);
+                break;
+            }
+        }
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return screenPtr;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSColor
+ * Method:    clearColor
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSColor_clearColor
+(JNIEnv *env, jclass cls)
+{
+    __block jlong clearColorPtr = 0L;
+    
+JNF_COCOA_ENTER(env);
+    
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        clearColorPtr = ptr_to_jlong([NSColor clearColor]);
+    }];
+    
+JNF_COCOA_EXIT(env);
+    
+    return clearColorPtr;
+}
+
diff --git a/jdk/src/macosx/native/sun/awt/DnDUtilities.h b/jdk/src/macosx/native/sun/awt/DnDUtilities.h
new file mode 100644
index 0000000..24b4847
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/DnDUtilities.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef DnDUtilities_h
+#define DnDUtilities_h
+
+#import <Cocoa/Cocoa.h>
+#include <jni.h>
+
+@interface DnDUtilities : NSObject {
+}
+
+// Common methods:
++ (NSString *) javaPboardType;
+
+// Dragging action mapping:
++ (jint)mapNSDragOperationToJava:(NSDragOperation)dragOperation;
++ (NSDragOperation)mapJavaDragOperationToNS:(jint)dragOperation;
++ (jint)mapNSDragOperationMaskToJava:(NSDragOperation)dragOperation;
++ (jint)narrowJavaDropActions:(jint)actions;
+
+// Mouse and key modifiers mapping:
++ (NSUInteger)mapJavaExtModifiersToNSKeyModifiers:(jint)modifiers;
++ (NSUInteger)mapJavaExtModifiersToNSMouseDownButtons:(jint)modifiers;
++ (NSUInteger)mapJavaExtModifiersToNSMouseUpButtons:(jint)modifiers;
+
+// Specialized key and mouse modifiers mapping (for operationChanged)
++ (jint)extractJavaExtKeyModifiersFromJavaExtModifiers:(jint)modifiers;
++ (jint)extractJavaExtMouseModifiersFromJavaExtModifiers:(jint)modifiers;
+
+// Get the current keyboard modifier keys as java modifiers (for operationChanged)
++ (jint)currentJavaExtKeyModifiers;
+
+// Getting the state of the current Drag
++ (NSDragOperation)nsDragOperationForModifiers:(NSUInteger)modifiers;
++ (jint) javaKeyModifiersForNSDragOperation:(NSDragOperation)dragOp;
+@end
+
+
+// Global debugging flag (for drag-and-drop) - this can be overriden locally per file:
+#ifndef DND_DEBUG
+//    #define DND_DEBUG TRUE
+#endif
+
+#if DND_DEBUG
+    // Turn DLog (debug log) on for debugging:
+    #define    DLog(arg1)                        NSLog(arg1)
+    #define    DLog2(arg1, arg2)                NSLog(arg1, arg2)
+    #define    DLog3(arg1, arg2, arg3)            NSLog(arg1, arg2, arg3)
+    #define    DLog4(arg1, arg2, arg3, arg4)    NSLog(arg1, arg2, arg3, arg4)
+    #define    DLog5(arg1, arg2, arg3, arg4, arg5)            NSLog(arg1, arg2, arg3, arg4, arg5)
+    #define    DLog6(arg1, arg2, arg3, arg4, arg5, arg6)    NSLog(arg1, arg2, arg3, arg4, arg5, arg6)
+#else
+    #define    DLog(arg1);
+    #define    DLog2(arg1, arg2);
+    #define    DLog3(arg1, arg2, arg3);
+    #define    DLog4(arg1, arg2, arg3, arg4);
+    #define    DLog5(arg1, arg2, arg3, arg4, arg5);
+    #define    DLog6(arg1, arg2, arg3, arg4, arg5, arg6);
+#endif
+
+#endif // DnDUtilities_h
diff --git a/jdk/src/macosx/native/sun/awt/DnDUtilities.m b/jdk/src/macosx/native/sun/awt/DnDUtilities.m
new file mode 100644
index 0000000..a998c03
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/DnDUtilities.m
@@ -0,0 +1,315 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+Documentation for Drag and Drop (Radar 3065640)
+There are several problems with Drag and Drop - notably, the mismatch between Java, Cocoa, and Carbon
+
+ Java reports both the original source actions, and the user-selected actions (selected using KB modifiers) to both the source and target during the drag. AppKit only reports to the destination during the drag. This was solved by directly asking CGS for the KB state during the source's image moved callback.
+
+ Java uses Shift/Move, Control/Copy and Shift+Control/Link. AppKit uses Command/Move, Alternate/Copy and Control/Link. Carbon uses Command/Move, Alternate/Copy and Command+Alternate/Link. This is bad, because Control overlaps between Java and AppKit. In this case, we choose compatibility between Carbon and Java (Java wins over AppKit wrt Control). This means that drags between Java applications will work correctly, regardless of whether you use the Carbon or the Java key modifiers. Drags to Java applications will work correctly regardless of whether you use the Carbon or the Java key modifiers. Drags from Java applications to non-Java applications will only work if you use the Carbon modifiers.
+
+ The reason we can't just set the CoreDrag(G/S)etAllowableActions directly (while ignoring the modifier keys) is because Carbon apps traditionally don't pay any attention - they only look at the modifier keys.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import "DnDUtilities.h"
+#import "java_awt_dnd_DnDConstants.h"
+#import "java_awt_event_InputEvent.h"
+
+@implementation DnDUtilities
+
+// Make sure we don't let other apps see local drags by using a process unique pasteboard type.
+// This may not work in the Applet case, since they are all running in the same VM
++ (NSString *) javaPboardType {
+    static NSString *customJavaPboardType = nil;
+    if (customJavaPboardType == nil)
+        customJavaPboardType = [[NSString stringWithFormat:@"NSJavaPboardType-%@", [[NSProcessInfo processInfo] globallyUniqueString]] retain];
+    return customJavaPboardType;
+}
+
++ (jint)mapNSDragOperationToJava:(NSDragOperation)dragOperation
+{
+    jint result = java_awt_dnd_DnDConstants_ACTION_NONE;
+
+    if ((dragOperation & NSDragOperationCopy) != 0)                    // 1
+        result = ((dragOperation & NSDragOperationMove) == 0) ? java_awt_dnd_DnDConstants_ACTION_COPY : java_awt_dnd_DnDConstants_ACTION_COPY_OR_MOVE;
+
+    else if ((dragOperation & NSDragOperationMove) != 0)            // 16
+        result = java_awt_dnd_DnDConstants_ACTION_MOVE;
+
+    else if ((dragOperation & NSDragOperationLink) != 0)            // 2
+        result = java_awt_dnd_DnDConstants_ACTION_LINK;
+
+    else if ((dragOperation & NSDragOperationGeneric) != 0)            // 4
+        result = java_awt_dnd_DnDConstants_ACTION_MOVE;
+
+    // Pre-empted by the above cases:
+    //else if (dragOperation == NSDragOperationEvery)                    // UINT_MAX
+    //    result = java_awt_dnd_DnDConstants_ACTION_COPY_OR_MOVE;
+
+    // To be rejected:
+    //else if ((dragOperation & NSDragOperationPrivate) != 0)        // 8
+    //else if ((dragOperation & NSDragOperationAll_Obsolete) != 0)    // 15
+    //else if ((dragOperation & NSDragOperationDelete) != 0)        // 32
+
+    return result;
+}
+
++ (jint)mapNSDragOperationMaskToJava:(NSDragOperation)dragOperation
+{
+    jint result = java_awt_dnd_DnDConstants_ACTION_NONE;
+
+    if (dragOperation & NSDragOperationMove)
+        result |= java_awt_dnd_DnDConstants_ACTION_MOVE;
+
+    if (dragOperation & NSDragOperationCopy)
+        result |= java_awt_dnd_DnDConstants_ACTION_COPY;
+
+    if (dragOperation & NSDragOperationLink)
+        result |= java_awt_dnd_DnDConstants_ACTION_LINK;
+
+    // Only look at Generic if none of the other options are specified
+    if ( (dragOperation & NSDragOperationGeneric) && !(dragOperation & (NSDragOperationMove|NSDragOperationCopy|NSDragOperationLink)) )
+        result |= java_awt_dnd_DnDConstants_ACTION_MOVE;
+
+    return result;
+}
+
++ (jint)narrowJavaDropActions:(jint)actions
+{
+    if (YES) {
+        // Order is defined in the java.awt.dnd.DropTargetDropEvent JavaDoc
+        if (actions & java_awt_dnd_DnDConstants_ACTION_MOVE) {
+            return java_awt_dnd_DnDConstants_ACTION_MOVE;
+        }
+        if (actions & java_awt_dnd_DnDConstants_ACTION_COPY) {
+            return java_awt_dnd_DnDConstants_ACTION_COPY;
+        }
+        if (actions & java_awt_dnd_DnDConstants_ACTION_LINK) {
+            return java_awt_dnd_DnDConstants_ACTION_LINK;
+        }
+    } else {
+        // Order is what is most intuitive on Mac OS X
+        if (actions & java_awt_dnd_DnDConstants_ACTION_COPY) {
+            return java_awt_dnd_DnDConstants_ACTION_COPY;
+        }
+        if (actions & java_awt_dnd_DnDConstants_ACTION_LINK) {
+            return java_awt_dnd_DnDConstants_ACTION_LINK;
+        }
+        if (actions & java_awt_dnd_DnDConstants_ACTION_MOVE) {
+            return java_awt_dnd_DnDConstants_ACTION_MOVE;
+        }
+    }
+
+    return java_awt_dnd_DnDConstants_ACTION_NONE;
+}
+
++ (NSDragOperation)mapJavaDragOperationToNS:(jint)dragOperation
+{
+    NSDragOperation result = NSDragOperationNone;
+
+    switch (dragOperation) {
+        case java_awt_dnd_DnDConstants_ACTION_NONE:            // 0
+            result = NSDragOperationNone;
+            break;
+        case java_awt_dnd_DnDConstants_ACTION_COPY:            // 1
+            result = NSDragOperationCopy;
+            break;
+        case java_awt_dnd_DnDConstants_ACTION_MOVE:            // 2
+            result = NSDragOperationMove;
+            break;
+        case java_awt_dnd_DnDConstants_ACTION_COPY_OR_MOVE:    // 3
+            result = NSDragOperationCopy | NSDragOperationMove;
+            break;
+        case java_awt_dnd_DnDConstants_ACTION_LINK:            // 1073741824L
+            result = NSDragOperationLink;
+            break;
+        case (java_awt_dnd_DnDConstants_ACTION_COPY_OR_MOVE | java_awt_dnd_DnDConstants_ACTION_LINK):
+            result = NSDragOperationCopy | NSDragOperationMove | NSDragOperationLink;
+            break;
+    }
+
+        if (result != NSDragOperationNone) {
+            result |= NSDragOperationGeneric;
+        }
+
+    return result;
+}
+
+// Mouse and key modifiers mapping:
++ (NSUInteger)mapJavaExtModifiersToNSKeyModifiers:(jint)modifiers
+{
+    NSUInteger result = 0;
+
+    if ((modifiers & java_awt_event_InputEvent_SHIFT_DOWN_MASK) != 0)
+        result |= NSShiftKeyMask;
+
+    if ((modifiers & java_awt_event_InputEvent_CTRL_DOWN_MASK) != 0)
+        result |= NSControlKeyMask;
+
+    if ((modifiers & java_awt_event_InputEvent_META_DOWN_MASK) != 0)
+        result |= NSCommandKeyMask;
+
+    if ((modifiers & java_awt_event_InputEvent_ALT_DOWN_MASK) != 0)
+        result |= NSAlternateKeyMask;
+
+    if ((modifiers & java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK) != 0)
+        result |= NSAlternateKeyMask;
+
+    return result;
+}
+
++ (NSUInteger)mapJavaExtModifiersToNSMouseDownButtons:(jint)modifiers
+{
+    NSUInteger result = NSLeftMouseDown;
+
+    if ((modifiers & java_awt_event_InputEvent_BUTTON1_DOWN_MASK) != 0)
+        result = NSLeftMouseDown;
+
+    if ((modifiers & java_awt_event_InputEvent_BUTTON2_DOWN_MASK) != 0)
+        result = NSOtherMouseDown;
+
+    if ((modifiers & java_awt_event_InputEvent_BUTTON3_DOWN_MASK) != 0)
+        result = NSRightMouseDown;
+
+    return result;
+}
+
++ (NSUInteger)mapJavaExtModifiersToNSMouseUpButtons:(jint)modifiers
+{
+    NSUInteger result = NSLeftMouseUp;
+
+    if ((modifiers & java_awt_event_InputEvent_BUTTON1_DOWN_MASK) != 0)
+        result = NSLeftMouseUp;
+
+    if ((modifiers & java_awt_event_InputEvent_BUTTON2_DOWN_MASK) != 0)
+        result = NSOtherMouseUp;
+
+    if ((modifiers & java_awt_event_InputEvent_BUTTON3_DOWN_MASK) != 0)
+        result = NSRightMouseUp;
+
+    return result;
+}
+
+
+// Specialized key modifiers mappings (for DragSource.operationChanged)
+
+// Returns just the key modifiers from a java modifier flag
++ (jint)extractJavaExtKeyModifiersFromJavaExtModifiers:(jint)modifiers
+{
+    // Build the mask
+    static jint mask = java_awt_event_InputEvent_SHIFT_DOWN_MASK | java_awt_event_InputEvent_CTRL_DOWN_MASK | java_awt_event_InputEvent_META_DOWN_MASK | java_awt_event_InputEvent_ALT_DOWN_MASK;
+    //static int mask = java_awt_event_InputEvent_SHIFT_DOWN_MASK | java_awt_event_InputEvent_CTRL_DOWN_MASK;
+
+    // Get results
+    jint result = modifiers & mask;
+
+    // Java appears to have 2 ALT buttons - combine them.
+    if (modifiers & java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK)
+        result |= java_awt_event_InputEvent_ALT_DOWN_MASK;
+
+    return result;
+}
+
+// Returns just the mouse modifiers from a java modifier flag
++ (jint)extractJavaExtMouseModifiersFromJavaExtModifiers:(jint)modifiers
+{
+    // Build the mask
+    static jint mask = java_awt_event_InputEvent_BUTTON1_DOWN_MASK | java_awt_event_InputEvent_BUTTON2_DOWN_MASK | java_awt_event_InputEvent_BUTTON3_DOWN_MASK;
+
+    // Get results
+    return modifiers & mask;
+}
+
+
++ (jint)currentJavaExtKeyModifiers
+{
+    NSUInteger modifiers = [NSEvent modifierFlags];
+    jint jmodifiers = 0;
+
+    if(modifiers & NSShiftKeyMask) {
+        jmodifiers |= java_awt_event_InputEvent_SHIFT_DOWN_MASK;
+    }
+
+    if(modifiers & NSControlKeyMask) {
+        jmodifiers |= java_awt_event_InputEvent_CTRL_DOWN_MASK;
+    }
+
+    if(modifiers & NSAlternateKeyMask) {
+        jmodifiers |= java_awt_event_InputEvent_ALT_DOWN_MASK;
+    }
+
+    if(modifiers & NSCommandKeyMask) {
+        jmodifiers |= java_awt_event_InputEvent_META_DOWN_MASK;
+    }
+
+    return jmodifiers;
+}
+
+
++ (NSDragOperation) nsDragOperationForModifiers:(NSUInteger)modifiers {
+
+    // Java first
+    if ( (modifiers & NSShiftKeyMask) && (modifiers & NSControlKeyMask) ) {
+        return NSDragOperationLink;
+    }
+    if (modifiers & NSShiftKeyMask) {
+        return NSDragOperationMove;
+    }
+    if (modifiers & NSControlKeyMask) {
+        return NSDragOperationCopy;
+    }
+
+    // Then native
+    if ( (modifiers & NSCommandKeyMask) && (modifiers & NSAlternateKeyMask) ) {
+        return NSDragOperationLink;
+    }
+    if (modifiers & NSCommandKeyMask) {
+        return NSDragOperationMove;
+    }
+    if (modifiers & NSAlternateKeyMask) {
+        return NSDragOperationCopy;
+    }
+
+    // Otherwise, we allow anything
+    return NSDragOperationEvery;
+}
+
++ (jint) javaKeyModifiersForNSDragOperation:(NSDragOperation)dragOperation {
+    if (dragOperation & NSDragOperationMove)
+        return java_awt_event_InputEvent_SHIFT_DOWN_MASK;
+
+    if (dragOperation & NSDragOperationCopy)
+        return java_awt_event_InputEvent_CTRL_DOWN_MASK;
+
+    if (dragOperation & NSDragOperationLink) {
+        return java_awt_event_InputEvent_SHIFT_DOWN_MASK | java_awt_event_InputEvent_CTRL_DOWN_MASK;
+    }
+    return 0;
+}
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/GeomUtilities.h b/jdk/src/macosx/native/sun/awt/GeomUtilities.h
new file mode 100644
index 0000000..b757097
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/GeomUtilities.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+jobject CGToJavaRect(JNIEnv *env, CGRect rect);
+CGRect JavaToCGRect(JNIEnv *env, jobject rect);
+
+jobject NSToJavaRect(JNIEnv *env, NSRect rect);
+NSRect JavaToNSRect(JNIEnv *env, jobject rect);
+
+jobject NSToJavaPoint(JNIEnv *env, NSPoint point);
+NSPoint JavaToNSPoint(JNIEnv *env, jobject point);
+
+jobject NSToJavaSize(JNIEnv *env, NSSize size);
+NSSize JavaToNSSize(JNIEnv *env, jobject);
+
+NSPoint ConvertNSScreenPoint(JNIEnv *env, NSPoint point);
+NSRect ConvertNSScreenRect(JNIEnv *env, NSRect rect);
diff --git a/jdk/src/macosx/native/sun/awt/GeomUtilities.m b/jdk/src/macosx/native/sun/awt/GeomUtilities.m
new file mode 100644
index 0000000..9deb8da
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/GeomUtilities.m
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "GeomUtilities.h"
+
+static JNF_CLASS_CACHE(sjc_Point2D, "java/awt/geom/Point2D");
+static JNF_MEMBER_CACHE(jm_pt_getX, sjc_Point2D, "getX", "()D");
+static JNF_MEMBER_CACHE(jm_pt_getY, sjc_Point2D, "getY", "()D");
+
+static JNF_CLASS_CACHE(sjc_Dimension2D, "java/awt/geom/Dimension2D");
+static JNF_MEMBER_CACHE(jm_sz_getWidth, sjc_Dimension2D, "getWidth", "()D");
+static JNF_MEMBER_CACHE(jm_sz_getHeight, sjc_Dimension2D, "getHeight", "()D");
+
+static JNF_CLASS_CACHE(sjc_Rectangle2D, "java/awt/geom/Rectangle2D");
+static JNF_MEMBER_CACHE(jm_rect_getX, sjc_Rectangle2D, "getX", "()D");
+static JNF_MEMBER_CACHE(jm_rect_getY, sjc_Rectangle2D, "getY", "()D");
+static JNF_MEMBER_CACHE(jm_rect_getWidth, sjc_Rectangle2D, "getWidth", "()D");
+static JNF_MEMBER_CACHE(jm_rect_getHeight, sjc_Rectangle2D, "getHeight", "()D");
+
+
+static jobject NewJavaRect(JNIEnv *env, jdouble x, jdouble y, jdouble w, jdouble h) {
+    static JNF_CLASS_CACHE(sjc_Rectangle2DDouble, "java/awt/geom/Rectangle2D$Double");
+    static JNF_CTOR_CACHE(ctor_Rectangle2DDouble, sjc_Rectangle2DDouble, "(DDDD)V");
+    return JNFNewObject(env, ctor_Rectangle2DDouble, x, y, w, h);
+}
+
+jobject CGToJavaRect(JNIEnv *env, CGRect rect) {
+   return NewJavaRect(env,
+                      rect.origin.x,
+                      rect.origin.y,
+                      rect.size.width,
+                      rect.size.height);
+}
+
+jobject NSToJavaRect(JNIEnv *env, NSRect rect) {
+    return NewJavaRect(env,
+                       rect.origin.x,
+                       rect.origin.y,
+                       rect.size.width,
+                       rect.size.height);
+}
+
+CGRect JavaToCGRect(JNIEnv *env, jobject rect) {
+    return CGRectMake(JNFCallDoubleMethod(env, rect, jm_rect_getX),
+                      JNFCallDoubleMethod(env, rect, jm_rect_getY),
+                      JNFCallDoubleMethod(env, rect, jm_rect_getWidth),
+                      JNFCallDoubleMethod(env, rect, jm_rect_getHeight));
+}
+
+NSRect JavaToNSRect(JNIEnv *env, jobject rect) {
+    return NSMakeRect(JNFCallDoubleMethod(env, rect, jm_rect_getX),
+                      JNFCallDoubleMethod(env, rect, jm_rect_getY),
+                      JNFCallDoubleMethod(env, rect, jm_rect_getWidth),
+                      JNFCallDoubleMethod(env, rect, jm_rect_getHeight));
+}
+
+jobject NSToJavaPoint(JNIEnv *env, NSPoint point) {
+    static JNF_CLASS_CACHE(sjc_Point2DDouble, "java/awt/geom/Point2D$Double");
+    static JNF_CTOR_CACHE(ctor_Point2DDouble, sjc_Point2DDouble, "(DD)V");
+    return JNFNewObject(env, ctor_Point2DDouble, (jdouble)point.x, (jdouble)point.y);
+}
+
+NSPoint JavaToNSPoint(JNIEnv *env, jobject point) {
+    return NSMakePoint(JNFCallDoubleMethod(env, point, jm_pt_getX),
+                       JNFCallDoubleMethod(env, point, jm_pt_getY));
+}
+
+jobject NSToJavaSize(JNIEnv *env, NSSize size) {
+    static JNF_CLASS_CACHE(sjc_Dimension2DDouble, "java/awt/Dimension"); // No Dimension2D$Double :-(
+    static JNF_CTOR_CACHE(ctor_Dimension2DDouble, sjc_Dimension2DDouble, "(II)V");
+    return JNFNewObject(env, ctor_Dimension2DDouble, (jint)size.width, (jint)size.height);
+}
+
+NSSize JavaToNSSize(JNIEnv *env, jobject dimension) {
+    return NSMakeSize(JNFCallDoubleMethod(env, dimension, jm_sz_getWidth),
+                      JNFCallDoubleMethod(env, dimension, jm_sz_getHeight));
+}
+
+static NSScreen *primaryScreen(JNIEnv *env) {
+    NSScreen *primaryScreen = [[NSScreen screens] objectAtIndex:0];
+    if (primaryScreen != nil) return primaryScreen;
+    if (env != NULL) [JNFException raise:env as:kRuntimeException reason:"Failed to convert, no screen."];
+    return nil;
+}
+
+NSPoint ConvertNSScreenPoint(JNIEnv *env, NSPoint point) {
+    point.y = [primaryScreen(env) frame].size.height - point.y;
+    return point;
+}
+
+NSRect ConvertNSScreenRect(JNIEnv *env, NSRect rect) {
+    rect.origin.y = [primaryScreen(env) frame].size.height - rect.origin.y - rect.size.height;
+    return rect;
+}
diff --git a/jdk/src/macosx/native/sun/awt/ImageSurfaceData.h b/jdk/src/macosx/native/sun/awt/ImageSurfaceData.h
new file mode 100644
index 0000000..0e4d306
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/ImageSurfaceData.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "QuartzSurfaceData.h"
+#import <pthread.h>
+
+typedef UInt8 Pixel8bit;
+typedef UInt16 Pixel16bit;
+typedef UInt32 Pixel32bit;
+
+typedef struct _ImageSDOps ImageSDOps;
+
+ImageSDOps*    LockImage(JNIEnv* env, jobject imageSurfaceData);
+void        UnlockImage(JNIEnv* env, ImageSDOps* isdo);
+ImageSDOps*    LockImagePixels(JNIEnv* env, jobject imageSurfaceData);
+void        UnlockImagePixels(JNIEnv* env, ImageSDOps* isdo);
+
+// if there is no image created for isdo.imgRef, it creates and image using the isdo.dataProvider
+// If there is an image present, this is a no-op
+void makeSureImageIsCreated(ImageSDOps* isdo);
+
+struct _ContextInfo
+{
+    BOOL                useWindowContextReference;
+    BOOL                canUseJavaPixelsAsContext;
+    size_t                bitsPerComponent;
+    size_t                bytesPerPixel;
+    size_t                bytesPerRow;
+    CGImageAlphaInfo    alphaInfo;
+    CGColorSpaceRef        colorSpace;
+}
+typedef ContextInfo;
+
+struct _ImageInfo
+{
+    size_t                bitsPerComponent;
+    size_t                bitsPerPixel;
+    size_t                bytesPerPixel;
+    size_t                bytesPerRow;
+    CGImageAlphaInfo    alphaInfo;
+    CGColorSpaceRef        colorSpace;
+}
+typedef ImageInfo;
+
+struct _ImageSDOps
+{
+    QuartzSDOps                qsdo; // must be the first entry!
+
+    ContextInfo                contextInfo;
+    ImageInfo                imageInfo;
+    BOOL                    isSubImage;
+
+    jint*                    javaImageInfo;
+
+    // parameters specifying this BufferedImage given to us from Java
+    jobject                    array;
+    jint                    offset;
+    jint                    width;
+    jint                    height;
+    jint                    javaPixelBytes;
+    jint                    javaPixelsBytesPerRow;
+    jobject                    icm;
+    jint                    type;
+
+    Pixel8bit*                pixels;
+    Pixel8bit*                pixelsLocked;
+
+    // needed by TYPE_BYTE_INDEXED
+    UInt16*                    indexedColorTable;
+    UInt32*                    lutData;
+    UInt32                    lutDataSize;
+
+    // Used as a cached image ref created from the isdo.dataprovider. This is only a chached image, and it might become invalid
+    // if somebody draws on the bitmap context, or the pixels are changed in java. In that case, we need to NULL out
+    // this image and recreate it from the data provider.
+    CGImageRef                imgRef;
+
+    // Cached instance of CGDataProvider. dataProvider is alloced the first time a bitmap context is created, providing the
+    // native pixels as a source of the data. The dataProviders life cycle is the same as ISDO. The reference gets
+    // released when we are done with the ISDO.
+    CGDataProviderRef        dataProvider;
+
+    // Pointer in memory that is used for create the CGBitmapContext and the CGDataProvider (used for imgRef). This is a native
+    // copy of the pixels for the Image. There is a spearate copy of the pixels that lives in Java heap. There are two main
+    // reasons why we keep those pixels spearate: 1) CG doesn't support all the Java pixel formats 2) The Garbage collector can
+    // move the java pixels at any time. There are possible workarounds for both problems. Number 2) seems to be a more serious issue, since
+    // we can solve 1) by only supporting certain image types.
+    void *                    nativePixels;
+    NSGraphicsContext*        nsRef;
+
+    pthread_mutex_t            lock;
+    jint                    nrOfPixelsOwners;
+};
+
diff --git a/jdk/src/macosx/native/sun/awt/ImageSurfaceData.m b/jdk/src/macosx/native/sun/awt/ImageSurfaceData.m
new file mode 100644
index 0000000..f2ebd28
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/ImageSurfaceData.m
@@ -0,0 +1,2002 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "ImageSurfaceData.h"
+
+#import "java_awt_Transparency.h"
+#import "java_awt_image_BufferedImage.h"
+#import "sun_awt_image_BufImgSurfaceData.h"
+#import "sun_java2d_OSXOffScreenSurfaceData.h"
+
+#import "jni_util.h"
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "BufImgSurfaceData.h"
+#import "ThreadUtilities.h"
+
+
+
+//#define DEBUG 1
+#if defined DEBUG
+    #define IMAGE_SURFACE_INLINE
+    #define PRINT(msg) {fprintf(stderr, "%s\n", msg);fflush(stderr);}
+#else
+    #define IMAGE_SURFACE_INLINE static inline
+    #define PRINT(msg) {}
+#endif
+
+// same value as defined in Sun's own code
+#define XOR_ALPHA_CUTOFF 128
+
+// for vImage framework headers
+#include <Accelerate/Accelerate.h>
+
+
+// private Quartz routines needed here
+CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx);
+
+static ContextInfo sDefaultContextInfo[sun_java2d_OSXOffScreenSurfaceData_TYPE_3BYTE_RGB+1] =
+{
+    {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_CUSTOM            // special case
+    {YES,    YES,    8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_RGB
+    {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_INT_ARGB
+    {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_INT_ARGB_PRE
+    {YES,    YES,    8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_BGR
+    {YES,    NO,        8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_3BYTE_BGR        // use the default ARGB_PRE context synce we have to sync by hand anyway
+    {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_4BYTE_ABGR
+    {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_4BYTE_ABGR_PRE
+#ifdef __LITTLE_ENDIAN__
+    {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_565_RGB
+    {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_555_RGB
+#else
+    {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_565_RGB
+    {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_555_RGB
+#endif
+    {YES,    YES,    8,        1,        0,        kCGImageAlphaNone,                                            NULL},    // TYPE_BYTE_GRAY
+    {YES,    NO,        8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_USHORT_GRAY        // use the default ARGB_PRE context synce we have to sync by hand anyway
+    {NO,    NO,        8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_BYTE_BINARY        mapped to TYPE_CUSTOM
+    {YES,    NO,        8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_BYTE_INDEXED    // use the default ARGB_PRE context synce we have to sync by hand anyway
+    {YES,    NO,        8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_3BYTE_RGB
+};
+
+static ImageInfo sDefaultImageInfo[sun_java2d_OSXOffScreenSurfaceData_TYPE_3BYTE_RGB+1] =
+{
+    {8,        32,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_CUSTOM
+    {8,        32,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_RGB
+    {8,        32,        4,        0,        kCGImageAlphaFirst | kCGBitmapByteOrder32Host,                NULL},    // TYPE_INT_ARGB
+    {8,        32,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_INT_ARGB_PRE
+    {8,        32,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_BGR
+    {8,        32,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_3BYTE_BGR
+    {8,        32,        4,        0,        kCGImageAlphaFirst | kCGBitmapByteOrder32Host,                NULL},    // TYPE_4BYTE_ABGR
+    {8,        32,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_4BYTE_ABGR_PRE
+#ifdef __LITTLE_ENDIAN__
+    {5,        16,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_565_RGB
+    {5,        16,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_555_RGB
+#else
+    {5,        16,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_565_RGB
+    {5,        16,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_555_RGB
+#endif
+    {8,        8,        1,        0,        kCGImageAlphaNone,                                            NULL},    // TYPE_BYTE_GRAY
+    {16,    16,        2,        0,        kCGImageAlphaNone | kCGBitmapByteOrder16Host,                NULL},    // TYPE_USHORT_GRAY
+    {0,        0,        0,        0,        -1,                                                            NULL},    // TYPE_BYTE_BINARY        mapped to TYPE_CUSTOM
+    {8,        32,        4,        0,        kCGImageAlphaFirst | kCGBitmapByteOrder32Host,                NULL},    // TYPE_BYTE_INDEXED  // Fully OPAQUE INDEXED images will use kCGImageAlphaNoneSkipFirst for performance reasosn. see <rdar://4224874>
+    {8,        32,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_3BYTE_RGB
+};
+
+static jfieldID        rgbID;
+static jfieldID        mapSizeID;
+static jfieldID        CMpDataID;
+static jfieldID        allGrayID;
+
+
+static JNF_CLASS_CACHE(jc_OSXOffScreenSurfaceData, "sun/java2d/OSXOffScreenSurfaceData");
+static JNF_MEMBER_CACHE(jm_syncFromCustom, jc_OSXOffScreenSurfaceData, "syncFromCustom", "()V");
+static JNF_MEMBER_CACHE(jm_syncToCustom, jc_OSXOffScreenSurfaceData, "syncToCustom", "()V");
+static JNF_CLASS_CACHE(jc_BufferedImage, "java/awt/image/BufferedImage");
+static JNF_MEMBER_CACHE(jm_SurfaceData, jc_BufferedImage, "sData", "Lsun/java2d/SurfaceData;");
+static JNF_CLASS_CACHE(jc_IndexColorModel, "java/awt/image/IndexColorModel");
+static JNF_MEMBER_CACHE(jm_rgb, jc_IndexColorModel, "rgb", "[I");
+static JNF_MEMBER_CACHE(jm_transparency, jc_IndexColorModel, "transparency", "I");
+static JNF_MEMBER_CACHE(jm_transparent_index, jc_IndexColorModel, "transparent_index", "I");
+
+CGColorSpaceRef gColorspaceRGB = NULL;
+CGColorSpaceRef gColorspaceGray = NULL;
+
+IMAGE_SURFACE_INLINE void PrintImageInfo(ImageSDOps* isdo)
+{
+    fprintf(stderr, "\n");
+    fprintf(stderr, "PrintImageInfo:\n");
+    fprintf(stderr, "\t \n");
+    //fprintf(stderr, "\t magicID=%d\n", (jint)isdo->magicID);
+    //fprintf(stderr, "\n");
+    fprintf(stderr, "\t isdo=%p\n", isdo);
+    fprintf(stderr, "\t \n");
+    fprintf(stderr, "\t contextInfo:\n");
+    fprintf(stderr, "\t        useWindowContextReference=%d\n", isdo->contextInfo.useWindowContextReference);
+    fprintf(stderr, "\t        canUseJavaPixelsAsContext=%d\n", isdo->contextInfo.canUseJavaPixelsAsContext);
+    fprintf(stderr, "\t        bitsPerComponent=%ld\n", (long)isdo->contextInfo.bitsPerComponent);
+    fprintf(stderr, "\t        bytesPerPixel=%ld\n", (long)isdo->contextInfo.bytesPerPixel);
+    fprintf(stderr, "\t        bytesPerRow=%ld\n", (long)isdo->contextInfo.bytesPerRow);
+    fprintf(stderr, "\t        alphaInfo=%ld\n", (long)isdo->contextInfo.alphaInfo);
+    fprintf(stderr, "\t \n");
+    fprintf(stderr, "\t imageInfo:\n");
+    fprintf(stderr, "\t        bitsPerComponent=%ld\n", (long)isdo->imageInfo.bitsPerComponent);
+    fprintf(stderr, "\t        bitsPerPixel=%ld\n", (long)isdo->imageInfo.bitsPerPixel);
+    fprintf(stderr, "\t        bytesPerPixel=%ld\n", (long)isdo->imageInfo.bytesPerPixel);
+    fprintf(stderr, "\t        bytesPerRow=%ld\n", (long)isdo->imageInfo.bytesPerRow);
+    fprintf(stderr, "\t        alphaInfo=%ld\n", (long)isdo->imageInfo.alphaInfo);
+    fprintf(stderr, "\t \n");
+    fprintf(stderr, "\t isSubImage=%d\n", isdo->isSubImage);
+    fprintf(stderr, "\t \n");
+    fprintf(stderr, "\t java info:\n");
+    fprintf(stderr, "\t        array=%p\n", isdo->array);
+    fprintf(stderr, "\t        offset=%d\n", (int)isdo->offset);
+    fprintf(stderr, "\t        width=%d\n", (int)isdo->width);
+    fprintf(stderr, "\t        height=%d\n", (int)isdo->height);
+    fprintf(stderr, "\t        javaPixelBytes=%d\n", (int)isdo->javaPixelBytes);
+    fprintf(stderr, "\t        javaPixelsBytesPerRow=%d\n", (int)isdo->javaPixelsBytesPerRow);
+    fprintf(stderr, "\t        icm=%p\n", isdo->icm);
+    fprintf(stderr, "\t        type=%d\n", (int)isdo->type);
+    fprintf(stderr, "\n");
+    fprintf(stderr, "\t cgRef=%p\n", isdo->qsdo.cgRef);
+    fprintf(stderr, "\t nsRef=%p\n", isdo->nsRef);
+    fprintf(stderr, "\n");
+    fprintf(stderr, "\t pixelsLocked=%p\n", isdo->pixelsLocked);
+    fprintf(stderr, "\t pixels=%p\n", isdo->pixels);
+    fprintf(stderr, "\n");
+    fprintf(stderr, "\t indexedColorTable=%p\n", isdo->indexedColorTable);
+    fprintf(stderr, "\t lutData=%p\n", isdo->lutData);
+    fprintf(stderr, "\t lutDataSize=%u\n", (unsigned)isdo->lutDataSize);
+    fprintf(stderr, "\n");
+    fprintf(stderr, "\t nrOfPixelsOwners=%u\n", (unsigned)isdo->nrOfPixelsOwners);
+    fprintf(stderr, "\n");
+}
+
+// if there is no image created for isdo.imgRef, it creates and image using the isdo.dataProvider
+// If there is an image present, this is a no-op
+void makeSureImageIsCreated(ImageSDOps* isdo)
+{
+    if (isdo->imgRef == NULL)  // create the image
+    {
+        isdo->imgRef = CGImageCreate(isdo->width,
+                                      isdo->height,
+                                      isdo->contextInfo.bitsPerComponent,
+                                      isdo->contextInfo.bytesPerPixel * 8,
+                                      isdo->contextInfo.bytesPerRow,
+                                      isdo->contextInfo.colorSpace,
+                                      isdo->contextInfo.alphaInfo,
+                                      isdo->dataProvider,
+                                      NULL,
+                                      NO,
+                                      kCGRenderingIntentDefault);
+    }
+}
+
+IMAGE_SURFACE_INLINE void customPixelsFromJava(JNIEnv *env, ImageSDOps *isdo)
+{
+PRINT("    customPixelsFromJava")
+
+    SurfaceDataOps *sdo = (SurfaceDataOps*)isdo;
+    JNFCallVoidMethod([ThreadUtilities getJNIEnv], sdo->sdObject, jm_syncFromCustom); // AWT_THREADING Safe (known object)
+}
+
+
+IMAGE_SURFACE_INLINE void copyBits(jint w, jint h, jint javaPixelsBytesPerRow, Pixel8bit *pixelsSrc, jint dstPixelsBytesPerRow, Pixel8bit *pixelsDst)
+{
+PRINT("    copyBits")
+
+    if (javaPixelsBytesPerRow == dstPixelsBytesPerRow)
+    {
+        memcpy(pixelsDst, pixelsSrc, h*javaPixelsBytesPerRow);
+    }
+    else
+    {
+        register jint y;
+        for (y=0; y<h; y++)
+        {
+            memcpy(pixelsDst, pixelsSrc, dstPixelsBytesPerRow);
+
+            pixelsSrc += javaPixelsBytesPerRow;
+            pixelsDst += dstPixelsBytesPerRow;
+        }
+    }
+}
+
+IMAGE_SURFACE_INLINE void copySwapRandB_32bit_TYPE_4BYTE(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
+{
+PRINT("    copySwapRandB_32bit_TYPE_4BYTE")
+
+    register Pixel8bit *p8Bit = NULL;
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register Pixel32bit pixel, red, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc++;
+
+#ifdef __LITTLE_ENDIAN__
+            pixel = CFSwapInt32BigToHost(pixel);   // the jint is in big endian format, we need to swap the bits
+#endif
+
+            red        = (pixel & 0x00ff0000) >> 16; // get original red and shift to new position
+            blue    = (pixel & 0x000000ff) << 16; // get original blue and shift to new position
+
+            pixel    = (pixel & 0xff00ff00); // erase original red&blue
+
+            pixel    = pixel | red | blue; // construct new pixel
+
+            *pixelsDst++ = pixel;
+        }
+        pixelsSrc += skip;
+
+        p8Bit = (Pixel8bit *) pixelsDst;
+        p8Bit += extraBytesPerRow;
+        pixelsDst = (Pixel32bit *) p8Bit;
+    }
+}
+
+
+IMAGE_SURFACE_INLINE void copySwapRandB_32bit_TYPE_INT(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
+{
+PRINT("    copySwapRandB_32bit_TYPE_INT")
+
+    register Pixel8bit *p8Bit = NULL;
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register Pixel32bit pixel, red, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc++;
+
+            red        = (pixel & 0x00ff0000) >> 16; // get original red and shift to new position
+            blue    = (pixel & 0x000000ff) << 16; // get original blue and shift to new position
+
+            pixel    = (pixel & 0xff00ff00); // erase original red&blue
+
+            pixel    = pixel | red | blue; // construct new pixel
+
+            *pixelsDst++ = pixel;
+        }
+        pixelsSrc += skip;
+
+        p8Bit = (Pixel8bit *) pixelsDst;
+        p8Bit += extraBytesPerRow;
+        pixelsDst = (Pixel32bit *) p8Bit;
+    }
+}
+
+
+IMAGE_SURFACE_INLINE void copyBGR_24bitToXRGB_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
+{
+PRINT("    copyBGR_24bitToXRGB_32bit")
+
+    register Pixel8bit *p8Bit = NULL;
+    register jint skip = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsSrc units
+    register Pixel32bit red, green, blue, pixel;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel        = *pixelsSrc++;
+            blue        = pixel << 0;
+
+            pixel        = *pixelsSrc++;
+            green        = pixel << 8;
+
+            pixel        = *pixelsSrc++;
+            red            = pixel << 16;
+
+            *pixelsDst    = red | green | blue;
+
+            *pixelsDst = 0xff000000 | *pixelsDst;
+
+            pixelsDst++;
+        }
+        pixelsSrc += skip;
+
+        p8Bit = (Pixel8bit *) pixelsDst;
+        p8Bit += extraBytesPerRow;
+        pixelsDst = (Pixel32bit *) p8Bit;
+    }
+}
+
+IMAGE_SURFACE_INLINE void copyRGB_24bitToXRGB_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
+{
+PRINT("    copyRGB_24bitToXRGB_32bit")
+
+    register Pixel8bit *p8Bit = NULL;
+    register jint skip = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsSrc units
+    register Pixel32bit red, green, blue, pixel;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel        = *pixelsSrc++;
+            red            = pixel << 16;
+
+            pixel        = *pixelsSrc++;
+            green        = pixel << 8;
+
+            pixel        = *pixelsSrc++;
+            blue        = pixel << 0;
+
+            *pixelsDst    = red | green | blue;
+
+            *pixelsDst = 0xff000000 | *pixelsDst;
+
+            pixelsDst++;
+        }
+        pixelsSrc += skip;
+
+        p8Bit = (Pixel8bit *) pixelsDst;
+        p8Bit += extraBytesPerRow;
+        pixelsDst = (Pixel32bit *) p8Bit;
+    }
+}
+
+IMAGE_SURFACE_INLINE void copyIndexed_8bitToARGB_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsSrc,
+                                                        Pixel32bit* lutdata, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
+{
+PRINT("    copyIndexed_8bitToARGB_32bit")
+
+    //gznote: how is the performance if the extraBytesPerRow != 0 ?
+    const vImage_Buffer src = {pixelsSrc, h, w, javaPixelsBytesPerRow};
+    const vImage_Buffer dest = {pixelsDst, h, w, w*sizeof(Pixel32bit)+extraBytesPerRow};
+    vImage_Error err = vImageLookupTable_Planar8toPlanarF(&src, &dest, (Pixel_F*)lutdata, kvImageDoNotTile);
+    if (err != kvImageNoError)
+    {
+        fprintf(stderr, "Error in copyIndexed_8bitToARGB_32bit: vImageLookupTable_Planar8toPlanarF returns %ld\n", (long)err);
+        register Pixel8bit *p8Bit = NULL;
+        register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+        register jint x, y;
+        for (y=0; y<h; y++)
+        {
+            for (x=0; x<w; x++)
+            {
+                *pixelsDst++ = lutdata[*pixelsSrc++];        // case 1
+                //*pixelsDst++ = *(lutdata + *pixelsSrc++);    // case 2: at best ~1% better than case 1
+            }
+            pixelsSrc += skip;
+
+            p8Bit = (Pixel8bit *) pixelsDst;
+            p8Bit += extraBytesPerRow;
+            pixelsDst = (Pixel32bit *) p8Bit;
+        }
+    }
+}
+
+IMAGE_SURFACE_INLINE void copy565_16bitTo555_16bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel16bit *pixelsSrc, Pixel16bit *pixelsDst, size_t extraBytesPerRow)
+{
+PRINT("    copy565_16bitTo555_16bit")
+
+    register Pixel8bit *p8Bit = NULL;
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register jint green;
+    register Pixel16bit pixel;
+    register jint x, y;
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc++;
+
+            green = ((pixel >> 5) & 63);  // rrrrrggggggbbbbb => shift 5 right = 00000rrrrrgggggg => and 63 = 0000000000gggggg
+            green = ((jint) (((CGFloat) green / 63.0f) * 31.0f)) & 31; // first normalize to value between 0 and 1 and then un-normalize to 5 bit (31 = 0000000000011111)
+
+            *pixelsDst++ = ((pixel&0xf800)>>1) | (green << 5) | (pixel&0x01f);
+        }
+        pixelsSrc += skip;
+
+        p8Bit = (Pixel8bit *) pixelsDst;
+        p8Bit += extraBytesPerRow;
+        pixelsDst = (Pixel16bit *) p8Bit;
+    }
+}
+
+
+IMAGE_SURFACE_INLINE void customPixelsToJava(JNIEnv *env, ImageSDOps *isdo)
+{
+PRINT("    customPixelsToJava")
+
+    SurfaceDataOps *sdo = (SurfaceDataOps*)isdo;
+    JNFCallVoidMethod([ThreadUtilities getJNIEnv], sdo->sdObject, jm_syncToCustom); // AWT_THREADING Safe (known object)
+}
+
+IMAGE_SURFACE_INLINE void removeAlphaPre_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
+{
+PRINT("    removeAlphaPre_32bit")
+
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register Pixel32bit pixel, alpha, red, green, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc;
+
+            alpha        = (pixel >> 24) & 0xff;
+
+            if (alpha != 0)
+            {
+                // get color components
+                red            = (pixel >> 16) & 0xff;
+                green        = (pixel >> 8) & 0xff;
+                blue        = (pixel >> 0) & 0xff;
+
+                // remove alpha pre
+                red            = ((red * 0xff) + 0x7f) / alpha;
+                green        = ((green * 0xff) + 0x7f) / alpha;
+                blue        = ((blue * 0xff) + 0x7f) / alpha;
+
+                // clamp
+                red            = (red <= 0xff) ? red : 0xff;
+                green        = (green <= 0xff) ? green : 0xff;
+                blue        = (blue <= 0xff) ? blue : 0xff;
+
+                *pixelsSrc++ = (alpha<<24) | (red<<16) | (green<<8) | blue; // construct new pixel
+            }
+            else
+            {
+                *pixelsSrc++ = 0;
+            }
+        }
+
+        pixelsSrc += skip;
+    }
+}
+
+IMAGE_SURFACE_INLINE void swapRandBAndRemoveAlphaPre_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
+{
+PRINT("    swapRandBAndRemoveAlphaPre_32bit")
+
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register Pixel32bit pixel, alpha, red, green, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc;
+
+            alpha        = (pixel & 0xff000000) >> 24;
+
+            if (alpha != 0)
+            {
+                // get color components
+                red            = (pixel & 0x00ff0000) >> 16;
+                green        = (pixel & 0x0000ff00) >> 8;
+                blue        = (pixel & 0x000000ff) >> 0;
+
+                // remove alpha pre
+                red            = ((red * 0xff) + 0x7f) / alpha;
+                green        = ((green * 0xff) + 0x7f) / alpha;
+                blue        = ((blue * 0xff) + 0x7f) / alpha;
+
+                // clamp
+                red            = (red <= 0xff) ? red : 0xff;
+                green        = (green <= 0xff) ? green : 0xff;
+                blue        = (blue <= 0xff) ? blue : 0xff;
+
+                pixel = (alpha<<24) | (blue<<16) | (green<<8) | red; // construct new pixel
+
+#ifdef __LITTLE_ENDIAN__
+                pixel = CFSwapInt32HostToBig(pixel);  // the jint is little endian, we need to swap the bits before we send it back to Java
+#endif
+
+                *pixelsSrc++ = pixel;
+            }
+            else
+            {
+                *pixelsSrc++ = 0;
+            }
+        }
+
+        pixelsSrc += skip;
+    }
+}
+
+IMAGE_SURFACE_INLINE void swapRandB_32bit_TYPE_INT(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
+{
+PRINT("    swapRandB_32bit_TYPE_INT")
+
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register Pixel32bit pixel, red, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc;
+
+            red        = (pixel & 0x00ff0000) >> 16; // get original red and shift to new position
+            blue    = (pixel & 0x000000ff) << 16; // get original blue and shift to new position
+
+            pixel    = (pixel & 0xff00ff00); // erase original red&blue
+
+            pixel    = pixel | red | blue; // construct new pixel
+
+            *pixelsSrc++ = pixel;
+        }
+
+        pixelsSrc += skip;
+    }
+}
+
+IMAGE_SURFACE_INLINE void swapRandB_32bit_TYPE_4BYTE(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
+{
+PRINT("    swapRandB_32bit_TYPE_4BYTE")
+
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register Pixel32bit pixel, red, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc;
+
+            red        = (pixel & 0x00ff0000) >> 16; // get original red and shift to new position
+            blue    = (pixel & 0x000000ff) << 16; // get original blue and shift to new position
+
+            pixel    = (pixel & 0xff00ff00); // erase original red&blue
+
+            pixel    = pixel | red | blue; // construct new pixel
+
+#ifdef __LITTLE_ENDIAN__
+            pixel = CFSwapInt32HostToBig(pixel); // the jint is little endian, we need to swap the bits before we send it back to Java
+#endif
+
+            *pixelsSrc++ = pixel;
+        }
+
+        pixelsSrc += skip;
+    }
+}
+
+IMAGE_SURFACE_INLINE void map555_16bitTo565_16bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel16bit *pixelsSrc)
+{
+PRINT("    map555_16bitTo565_16bit")
+    register jint skip = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register jint green;
+    register Pixel16bit pixel;
+    register jint x, y;
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc;
+
+            green = ((pixel >> 5)  & 31);   // rrrrrgggggbbbbb => shift 5 right = 000000rrrrrggggg => and 31 = 00000000000ggggg
+            green = ((jint) (((CGFloat) green / 31.0f) * 63.0f)) & 63; // first normalize between 0 and 1 and then un-normalize to 6 bit (63 = 0000000000111111)
+
+            *pixelsSrc++ = ((pixel&0x7c00)<<1) | (green << 5) | (pixel&0x01f);
+        }
+
+        pixelsSrc += skip;
+    }
+}
+
+IMAGE_SURFACE_INLINE void copyARGB_PRE_32bitToBGR_24bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsDst)
+{
+PRINT("    copyARGB_PRE_32bitToBGR_24bit")
+
+    static const jint mask = 0x000000ff;
+    register jint skipSrc = (nativePixelsBytesPerRow/sizeof(Pixel32bit))-w; // in pixelsSrc units
+    register jint skipDst = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsDst units
+    register Pixel32bit pixel, alpha, red, green, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc;
+
+            alpha        = (pixel >> 24) & mask;
+
+            if (alpha != 0)
+            {
+                // extract color components
+                red            = (pixel >> 16) & mask;
+                green        = (pixel >> 8) & mask;
+                blue        = (pixel >> 0) & mask;
+
+                // remove alpha pre
+                red            = ((red * 0xff) + 0x7f) / alpha;
+                green        = ((green * 0xff) + 0x7f) / alpha;
+                blue        = ((blue * 0xff) + 0x7f) / alpha;
+
+                // clamp
+                *pixelsDst++ = (blue <= 0xff) ? blue : 0xff;
+                *pixelsDst++ = (green <= 0xff) ? green : 0xff;
+                *pixelsDst++ = (red <= 0xff) ? red : 0xff;
+            }
+            else
+            {
+                *pixelsDst++ = 0; // blue
+                *pixelsDst++ = 0; // green
+                *pixelsDst++ = 0; // red
+            }
+
+            pixelsSrc++;
+        }
+
+        pixelsSrc += skipSrc;
+        pixelsDst += skipDst;
+    }
+}
+
+
+IMAGE_SURFACE_INLINE void copyARGB_PRE_32bitToRGB_24bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsDst)
+{
+    PRINT("    copyARGB_PRE_32bitToRGB_24bit")
+
+    static const jint mask = 0x000000ff;
+    register jint skipSrc = (nativePixelsBytesPerRow/sizeof(Pixel32bit))-w; // in pixelsSrc units
+    register jint skipDst = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsDst units
+    register Pixel32bit pixel, alpha, red, green, blue;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel = *pixelsSrc;
+
+            alpha        = (pixel >> 24) & mask;
+
+            if (alpha != 0)
+            {
+                // extract color components
+                red            = (pixel >> 16) & mask;
+                green        = (pixel >> 8) & mask;
+                blue        = (pixel >> 0) & mask;
+
+                // remove alpha pre
+                red            = ((red * 0xff) + 0x7f) / alpha;
+                green        = ((green * 0xff) + 0x7f) / alpha;
+                blue        = ((blue * 0xff) + 0x7f) / alpha;
+
+                // clamp
+                *pixelsDst++ = (red <= 0xff) ? red : 0xff;
+                *pixelsDst++ = (green <= 0xff) ? green : 0xff;
+                *pixelsDst++ = (blue <= 0xff) ? blue : 0xff;
+            }
+            else
+            {
+                *pixelsDst++ = 0; // blue
+                *pixelsDst++ = 0; // green
+                *pixelsDst++ = 0; // red
+            }
+
+            pixelsSrc++;
+        }
+
+        pixelsSrc += skipSrc;
+        pixelsDst += skipDst;
+    }
+}
+
+
+// gray = 0.3red + 0.59green + 0.11blue - NTSC standard (according to Luke Wallis)
+IMAGE_SURFACE_INLINE void copyARGB_PRE_32bitToGray_16bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel16bit *pixelsDst)
+{
+PRINT("    copyARGB_PRE_32bitToGray_16bit")
+
+    static const jint mask = 0x000000ff;
+    register jint skipSrc = (nativePixelsBytesPerRow/sizeof(Pixel32bit))-w; // in pixelsSrc units
+    register jint skipDst = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsDst units
+    register Pixel32bit alpha;
+    register Pixel32bit pixel, red, green, blue;
+    register CGFloat pixelFloat;
+    register jint x, y;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            pixel        = *pixelsSrc;
+
+            // gznote: do we remove alpha pre here?
+            alpha        = ((pixel >> 24) & mask); //extract
+
+            if (alpha != 0)
+            {
+                red            = ((pixel >> 16) & mask); // extract
+                green        = ((pixel >> 8) & mask); // extract
+                blue        = ((pixel >> 0) & mask); // extract
+
+                alpha        *= 0xff; // upsample to 16bit
+                red            *= 0xff; // upsample to 16bit
+                green        *= 0xff; // upsample to 16bit
+                blue        *= 0xff; // upsample to 16bit
+
+                red            = ((red * 0xffff) + 0x7fff) / alpha; // remove alpha pre
+                red            = (red <= 0xffff) ? red : 0xffff;
+                green        = ((green * 0xffff) + 0x7fff) / alpha; // remove alpha pre
+                green        = (green <= 0xffff) ? green : 0xffff;
+                blue        = ((blue * 0xffff) + 0x7fff) / alpha; // remove alpha pre
+                blue        = (blue <= 0xffff) ? blue : 0xffff;
+
+                pixelFloat    = red*0.3f + green*0.59f + blue*0.11f; // rgb->gray NTSC conversion
+            }
+            else
+            {
+                pixelFloat = 0;
+            }
+
+            *pixelsDst    = (jint)pixelFloat;
+            pixelsDst++;
+
+            pixelsSrc++;
+        }
+
+        pixelsSrc += skipSrc;
+        pixelsDst += skipDst;
+    }
+}
+
+// 1. first "dither" the true color down by creating a 16 bit value of the real color that will serve as an index into the cache of indexes
+// 2. if the cache has a valid entry use it otherwise go through 3 and 4
+// 3. go through the color table and calculate Euclidian distance between the true color and the indexed colors
+// 4. map the shortest distance into the one and true index color and stick it into the dst (and cache)
+IMAGE_SURFACE_INLINE UInt16* copyARGB_PRE_bitToIndexed_8bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsDst, Pixel32bit* lutdata, UInt32 lutDataSize, UInt16 *indexedColorTable)
+{
+PRINT("    copyARGB_PRE_bitToIndexed_8bit")
+    static const UInt32 mask            = 0x000000ff;
+
+    static const UInt32 indexSize        = 65536;        // 2^16 - 16 bits of precision
+    static const UInt32 indexMask        = 0x000000f0;    // 00000000000000000000000011110000
+    static const UInt16 invalidIndex    = 0xffff;        // 1111111111111111
+
+    register jint skipSrc = (nativePixelsBytesPerRow/sizeof(Pixel32bit))-w; // in pixelsSrc units
+    register jint skipDst = (javaPixelsBytesPerRow/javaPixelBytes)-w; // in pixelsSrc units
+    register jint indexOfBest, indexOfBestCached = -1;
+    register CGFloat distanceOfBest, distance;
+    register UInt32 p1, p1Cached = 0, p1a, p1r, p1g, p1b, p2;
+    register SInt32 da, dr, dg, db;
+    register jint x, y, i;
+    BOOL cachedValueReady = NO;
+
+    if (indexedColorTable == NULL)
+    {
+        indexedColorTable = (UInt16*)malloc(indexSize*sizeof(UInt16));    // 15 bit precision, each entry capable of holding a 2 byte value
+                                                                        // (lower byte for the actual index, higher byte to mark it valid/invalid)
+
+        if (indexedColorTable != NULL)
+        {
+            memset((void*)indexedColorTable, invalidIndex, indexSize*sizeof(UInt16));
+        }
+        else
+        {
+            fprintf(stderr, "ERROR: malloc returns NULL for isdo->indexedColorTable in copyARGB_PRE_bitToIndexed_8bit");
+            return NULL;
+        }
+    }
+
+    register UInt16 cacheIndex;
+
+    for (y=0; y<h; y++)
+    {
+        for (x=0; x<w; x++)
+        {
+            p1 = *pixelsSrc;
+
+            if ((p1Cached != p1) || (cachedValueReady == NO))
+            {
+                p1a = ((p1 >> 24) & mask);
+
+                if (p1a != 0)
+                {
+                    // extract color components
+                    p1r = ((p1 >> 16) & mask);
+                    p1g = ((p1 >> 8) & mask);
+                    p1b = ((p1 >> 0) & mask);
+
+                    // remove alpha pre
+                    p1r = ((p1r * 0xff) + 0x7f) / p1a;
+                    p1g = ((p1g * 0xff) + 0x7f) / p1a;
+                    p1b = ((p1b * 0xff) + 0x7f) / p1a;
+
+                    // clamp
+                    p1r = (p1r <= 0xff) ? p1r : 0xff;
+                    p1g = (p1g <= 0xff) ? p1g : 0xff;
+                    p1b = (p1b <= 0xff) ? p1b : 0xff;
+                }
+                else
+                {
+                    p1r = 0;
+                    p1g = 0;
+                    p1b = 0;
+                }
+
+                cacheIndex = (UInt16)(((p1a & indexMask) << 8) | ((p1r & indexMask) << 4) | ((p1g & indexMask) << 0) | ((p1b & indexMask) >> 4));
+                if (indexedColorTable[cacheIndex] == invalidIndex)
+                {
+                    indexOfBest = 0;
+                    distanceOfBest = DBL_MAX;
+
+                    for (i=0; i<lutDataSize; i++)
+                    {
+                        p2 = lutdata[i];
+
+                        da = p1a - ((p2 >> 24) & mask);
+                        dr = p1r - ((p2 >> 16) & mask);
+                        dg = p1g - ((p2 >> 8) & mask);
+                        db = p1b - ((p2 >> 0) & mask);
+
+                        distance = sqrt((da*da)+(dr*dr)+(dg*dg)+(db*db));
+                        if (distance < distanceOfBest)
+                        {
+                            distanceOfBest = distance;
+                            indexOfBest = i;
+                        }
+                    }
+
+                    indexedColorTable[cacheIndex] = indexOfBest;
+                }
+                else
+                {
+                    indexOfBest = indexedColorTable[cacheIndex];
+                }
+
+                cachedValueReady = YES;
+                p1Cached = p1;
+                indexOfBestCached = indexOfBest;
+            }
+            else
+            {
+                indexOfBest = indexOfBestCached;
+            }
+
+            *pixelsDst = indexOfBest;
+
+            pixelsDst++;
+            pixelsSrc++;
+        }
+        pixelsSrc += skipSrc;
+        pixelsDst += skipDst;
+    }
+
+    return indexedColorTable;
+}
+
+// callback from CG telling us it's done with the data. <rdar://problem/4762033>
+static void releaseDataFromProvider(void *info, const void *data, size_t size)
+{
+    if (data != NULL)
+    {
+        free(data);
+    }
+}
+
+IMAGE_SURFACE_INLINE void createContext(JNIEnv *env, ImageSDOps *isdo)
+{
+PRINT("createContext")
+
+    QuartzSDOps *qsdo = (QuartzSDOps*)isdo;
+    if (qsdo->cgRef == NULL)  // lazy creation
+    {
+        size_t bitsPerComponent = isdo->contextInfo.bitsPerComponent;
+        CGColorSpaceRef colorSpace = isdo->contextInfo.colorSpace;
+        CGImageAlphaInfo alphaInfo = isdo->contextInfo.alphaInfo;
+
+        size_t bytesPerRow = isdo->contextInfo.bytesPerRow;
+        size_t size = bytesPerRow * isdo->height;
+        isdo->nativePixels = malloc(size);
+
+        if (isdo->nativePixels == NULL)
+        {
+            fprintf(stderr, "malloc failed for size %d bytes in ImageSurfaceData.createContext()\n", (int) size);
+        }
+
+//fprintf(stderr, "isdo=%p isdo->type=%d, bitsPerComponent=%d, bytesPerRow=%d, colorSpace=%p, alphaInfo=%d, width=%d, height=%d, size=%d\n", isdo, type, (jint)bitsPerComponent, (jint)bytesPerRow, colorSpace, (jint)alphaInfo, (jint) isdo->width, (jint) isdo->height, (jint) size);
+
+        qsdo->cgRef = CGBitmapContextCreate(isdo->nativePixels, isdo->width, isdo->height, bitsPerComponent, bytesPerRow, colorSpace, alphaInfo);
+        isdo->dataProvider = CGDataProviderCreateWithData(NULL, isdo->nativePixels, size, releaseDataFromProvider);
+    }
+
+//fprintf(stderr, "cgRef=%p\n", qsdo->cgRef);
+    if (qsdo->cgRef == NULL)
+    {
+        fprintf(stderr, "ERROR: (qsdo->cgRef == NULL) in createContext!\n");
+    }
+
+    // intitalize the context to match the Java coordinate system
+
+    // BG, since the context is created above, we can just concat
+    //CGContextSetCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, -1, 0, isdo->height));
+    CGContextConcatCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, -1, 0, isdo->height));
+
+    CGContextSaveGState(qsdo->cgRef); // this will make sure we don't go pass device context settings
+    CGContextSaveGState(qsdo->cgRef); // this will put user settings on top, used by LazyStateManagement code
+    qsdo->newContext = YES;
+}
+
+IMAGE_SURFACE_INLINE void holdJavaPixels(JNIEnv* env, ImageSDOps* isdo)
+{
+PRINT("holdJavaPixels")
+
+    if (isdo->type != java_awt_image_BufferedImage_TYPE_CUSTOM)
+    {
+        Pixel8bit* pixels = NULL;
+        if (isdo->nrOfPixelsOwners == 0)
+        {
+            pixels = (Pixel8bit*)((*env)->GetPrimitiveArrayCritical(env, isdo->array, NULL));
+            if (pixels != NULL)
+            {
+                isdo->pixelsLocked = pixels;
+
+                isdo->pixels = isdo->pixelsLocked + isdo->offset;
+            }
+            else
+            {
+                fprintf(stderr, "ERROR: GetPrimitiveArrayCritical returns NULL for pixels in holdJavaPixels!\n");
+            }
+        }
+        isdo->nrOfPixelsOwners++;
+    }
+    else if (isdo->pixels == NULL)
+    {
+        isdo->pixels = (Pixel8bit*)((*env)->GetDirectBufferAddress(env, isdo->array));
+    }
+}
+
+IMAGE_SURFACE_INLINE void unholdJavaPixels(JNIEnv* env, ImageSDOps* isdo)
+{
+PRINT("unholdJavaPixels")
+
+    if (isdo->type != java_awt_image_BufferedImage_TYPE_CUSTOM)
+    {
+        isdo->nrOfPixelsOwners--;
+        if (isdo->nrOfPixelsOwners == 0)
+        {
+            isdo->pixels = NULL;
+
+            (*env)->ReleasePrimitiveArrayCritical(env, isdo->array, isdo->pixelsLocked, 0); // Do not use JNI_COMMIT, as that will not free the buffer copy when +ProtectJavaHeap is on.
+            isdo->pixelsLocked = NULL;
+        }
+    }
+}
+
+static void imageDataProvider_UnholdJavaPixels(void *info, const void *data, size_t size)
+{
+PRINT("imageDataProvider_UnholdJavaPixels")
+
+    ImageSDOps* isdo = (ImageSDOps*)info;
+    unholdJavaPixels([ThreadUtilities getJNIEnv], isdo);
+}
+static void imageDataProvider_FreeTempPixels(void *info, const void *data, size_t size)
+{
+PRINT("imageDataProvider_FreeTempPixels")
+
+    free((void *)data);
+}
+IMAGE_SURFACE_INLINE void syncFromJavaPixels(JNIEnv* env, ImageSDOps* isdo)
+{
+PRINT("syncFromJavaPixels")
+
+    // check to see if we have any work to do
+    if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] == 1)
+    {
+        // if we do, lock down Java pixels, this halts GarbageCollector!
+        holdJavaPixels(env, isdo);
+        if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] == 1)
+        {
+            isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 0;
+
+            void *dataProviderData = NULL;
+            void *dataProviderInfo = NULL;
+            void *dataProviderCallback = NULL;
+            size_t dataProviderDataSize = 0;
+            size_t width = isdo->width;
+            size_t height = isdo->height;
+            size_t bitsPerComponent = isdo->imageInfo.bitsPerComponent;
+            size_t bitsPerPixel = isdo->imageInfo.bitsPerPixel;
+            size_t bytesPerRow = 0;
+            size_t extraBytesPerRow = 0; // these are the extra bytesPerRow used for alignement
+
+            switch (isdo->type)
+            {
+                //case java_awt_image_BufferedImage_TYPE_BYTE_BINARY: // mapped to TYPE_CUSTOM
+                case java_awt_image_BufferedImage_TYPE_CUSTOM:
+                    holdJavaPixels(env, isdo);    // we lock again since we are reusing pixels, but we must ensure CGImageRef immutability
+                                                // we can lock these pixels down because they are nio based, so we don't halt the GarbageCollector
+                    bytesPerRow = isdo->javaPixelsBytesPerRow;
+                    dataProviderDataSize = bytesPerRow*isdo->height;
+                    dataProviderData = isdo->pixels;
+                    dataProviderInfo = isdo;
+                    dataProviderCallback = imageDataProvider_UnholdJavaPixels;
+                    break;
+                default:
+                    bytesPerRow = isdo->imageInfo.bytesPerRow;
+                    dataProviderDataSize = bytesPerRow*height;
+                    dataProviderData = malloc(dataProviderDataSize);
+                    dataProviderInfo = isdo;
+                    dataProviderCallback = imageDataProvider_FreeTempPixels;
+            }
+
+            switch (isdo->type)
+            {
+                //case java_awt_image_BufferedImage_TYPE_BYTE_BINARY: // mapped to TYPE_CUSTOM
+                case java_awt_image_BufferedImage_TYPE_CUSTOM:
+                    customPixelsFromJava(env, isdo);
+                    break;
+                case java_awt_image_BufferedImage_TYPE_INT_RGB:
+                case java_awt_image_BufferedImage_TYPE_INT_ARGB:
+                case java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE:
+                case java_awt_image_BufferedImage_TYPE_USHORT_555_RGB:
+                case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
+                case java_awt_image_BufferedImage_TYPE_BYTE_GRAY:
+                    copyBits(width, height, isdo->javaPixelsBytesPerRow, (Pixel8bit*)isdo->pixels, bytesPerRow, dataProviderData);
+                    break;
+                case java_awt_image_BufferedImage_TYPE_INT_BGR:
+                    copySwapRandB_32bit_TYPE_INT(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels, dataProviderData, extraBytesPerRow);
+                    break;
+                case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR:
+                case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR_PRE:
+                    copySwapRandB_32bit_TYPE_4BYTE(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels, dataProviderData, extraBytesPerRow);
+                    break;
+                case java_awt_image_BufferedImage_TYPE_3BYTE_BGR:
+                    copyBGR_24bitToXRGB_32bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, dataProviderData, extraBytesPerRow);
+                    break;
+                case sun_java2d_OSXOffScreenSurfaceData_TYPE_3BYTE_RGB:
+                    copyRGB_24bitToXRGB_32bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, dataProviderData, extraBytesPerRow);
+                    break;
+                case java_awt_image_BufferedImage_TYPE_USHORT_565_RGB:
+                    copy565_16bitTo555_16bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel16bit*)isdo->pixels, dataProviderData, extraBytesPerRow);
+                    break;
+                case java_awt_image_BufferedImage_TYPE_BYTE_INDEXED:
+                    copyIndexed_8bitToARGB_32bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, isdo->lutData, dataProviderData, extraBytesPerRow);
+                    break;
+                default:
+                    break;
+            }
+
+            CGDataProviderRef provider = CGDataProviderCreateWithData(dataProviderInfo, dataProviderData, dataProviderDataSize, dataProviderCallback);
+            CGImageRef javaImg = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow,
+                                                isdo->imageInfo.colorSpace, isdo->imageInfo.alphaInfo, provider, NULL, NO, kCGRenderingIntentDefault);
+//fprintf(stderr, "javaImg=%p\n", javaImg);
+            CGDataProviderRelease(provider);
+
+            if (javaImg != NULL)
+            {
+                QuartzSDOps *qsdo = (QuartzSDOps*)isdo;
+
+                if (isdo->imgRef != NULL)
+                {
+                    CGImageRelease(isdo->imgRef);
+                    isdo->imgRef = NULL;
+                }
+
+                if (qsdo->cgRef == NULL)
+                {
+                    createContext(env, isdo);
+                }
+
+                if (qsdo->cgRef != NULL)
+                {
+                    CGContextSaveGState(qsdo->cgRef);
+                    CGContextSetCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, 1, 0, 0));
+                    CGContextSetBlendMode(qsdo->cgRef, kCGBlendModeCopy);
+                    CGContextSetAlpha(qsdo->cgRef, 1.0f);
+                    CGContextDrawImage(qsdo->cgRef, CGRectMake(0, 0, width, height), javaImg);
+                    CGContextFlush(qsdo->cgRef);
+                    CGContextRestoreGState(qsdo->cgRef);
+                    CGImageRelease(javaImg);
+                }
+                else
+                {
+                    fprintf(stderr, "ERROR: (cgRef == NULL) in syncFromJavaPixels!\n");
+                }
+            }
+            else
+            {
+//fprintf(stderr, "isdo->type=%d, isdo->width=%d, isdo->height=%d, isdo->imageInfo.bitsPerComponent=%d, isdo->imageInfo.bytesPerPixel=%d, isdo->imageInfo.bitsPerPixel=%d, isdo->imageInfo.bytesPerRow=%d, isdo->imageInfo.colorSpace=%p, isdo->imageInfo.alphaInfo=%d\n",
+//(jint)isdo->type, (jint)isdo->width, (jint)isdo->height, (jint)isdo->imageInfo.bitsPerComponent, (jint)isdo->imageInfo.bytesPerPixel, (jint)isdo->imageInfo.bitsPerPixel, (jint)isdo->imageInfo.bytesPerRow, isdo->imageInfo.colorSpace, (jint)isdo->imageInfo.alphaInfo);
+                fprintf(stderr, "ERROR: (javaImg == NULL) in syncFromJavaPixels!\n");
+            }
+        }
+
+        unholdJavaPixels(env, isdo);
+    }
+}
+
+IMAGE_SURFACE_INLINE void processPixels(ImageSDOps* isdo, jint x, jint y, jint width, jint height, void (*processPixelsCallback) (ImageSDOps *, jint, Pixel32bit *, jint, jint, jint, jint))
+{
+    processPixelsCallback(isdo, (jint) isdo->contextInfo.bytesPerRow, (Pixel32bit *) isdo->nativePixels, x, y, width, height);
+}
+
+IMAGE_SURFACE_INLINE void syncToJavaPixels_processPixelsCallback(ImageSDOps* isdo, jint nativePixelsBytesPerRow, Pixel32bit *dataSrc, jint x, jint y, jint width, jint height)
+{
+    switch (isdo->type)
+    {
+        case java_awt_image_BufferedImage_TYPE_3BYTE_BGR:
+            copyARGB_PRE_32bitToBGR_24bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels);
+            break;
+        case sun_java2d_OSXOffScreenSurfaceData_TYPE_3BYTE_RGB:
+            copyARGB_PRE_32bitToRGB_24bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels);
+            break;
+        case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
+            copyARGB_PRE_32bitToGray_16bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel16bit*)isdo->pixels);
+            break;
+        case java_awt_image_BufferedImage_TYPE_BYTE_INDEXED:
+            isdo->indexedColorTable = copyARGB_PRE_bitToIndexed_8bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, isdo->lutData, isdo->lutDataSize, isdo->indexedColorTable);
+            break;
+        default:
+            break;
+    }
+}
+
+
+IMAGE_SURFACE_INLINE void syncToJavaPixels(JNIEnv* env, ImageSDOps* isdo)
+{
+PRINT("syncToJavaPixels")
+
+    holdJavaPixels(env, isdo);
+
+    QuartzSDOps *qsdo = (QuartzSDOps*)isdo;
+    if (qsdo->cgRef == NULL)
+    {
+        createContext(env, isdo);
+    }
+
+    isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNativePixelsChangedIndex] = 0;
+
+    if (isdo->contextInfo.canUseJavaPixelsAsContext == YES)
+    {
+
+        jint srcBytesPerRow = isdo->contextInfo.bytesPerRow;
+        jint dstBytesPerRow = isdo->javaPixelsBytesPerRow;
+        jint h = isdo->height;
+        Pixel8bit *pixelsSrc = isdo->nativePixels;
+        Pixel8bit *pixelsDst = isdo->pixels;
+
+        if (srcBytesPerRow == dstBytesPerRow)
+        {
+            memcpy(pixelsDst, pixelsSrc, h * dstBytesPerRow);
+        }
+        else
+        {
+            jint widthInBytes = isdo->width * isdo->contextInfo.bytesPerPixel;
+            jint y;
+            for (y=0; y < h; y++)
+            {
+                memcpy(pixelsDst, pixelsSrc, widthInBytes);
+
+                pixelsSrc += srcBytesPerRow;
+                pixelsDst += dstBytesPerRow;
+            }
+        }
+
+        switch (isdo->type)
+        {
+            //case java_awt_image_BufferedImage_TYPE_BYTE_BINARY: // mapped to TYPE_CUSTOM
+            case java_awt_image_BufferedImage_TYPE_CUSTOM:
+                customPixelsToJava(env, isdo);
+                break;
+            case java_awt_image_BufferedImage_TYPE_INT_ARGB:
+                removeAlphaPre_32bit(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
+                break;
+            case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR:
+                swapRandBAndRemoveAlphaPre_32bit(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
+                break;
+            case java_awt_image_BufferedImage_TYPE_INT_BGR:
+                swapRandB_32bit_TYPE_INT(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
+                break;
+            case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR_PRE:
+                swapRandB_32bit_TYPE_4BYTE(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
+                break;
+            case java_awt_image_BufferedImage_TYPE_USHORT_565_RGB:
+                map555_16bitTo565_16bit(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel16bit*)isdo->pixels);
+                break;
+            default:
+                break;
+        }
+    }
+    else
+    {
+        processPixels(isdo, 0, 0, isdo->width, isdo->height, &syncToJavaPixels_processPixelsCallback);
+    }
+
+    unholdJavaPixels(env, isdo);
+}
+
+
+IMAGE_SURFACE_INLINE jboolean xorSurfacePixels(JNIEnv *env, jobject dstIsd, jobject srcIsd, jint colorXOR, jint x, jint y, jint w, jint h)
+{
+PRINT("xorSurfacePixels")
+
+    jboolean handled = JNI_FALSE;
+
+JNF_COCOA_ENTER(env);
+    ImageSDOps* srcIsdo = LockImagePixels(env, srcIsd);
+    ImageSDOps* dstIsdo = LockImagePixels(env, dstIsd);
+
+    if ((x < 0) || (y < 0) || (x+w > dstIsdo->width) || (y+h > dstIsdo->height) || (w > srcIsdo->width) || (h > srcIsdo->height))
+    {
+#ifdef PRINT_WARNINGS
+fprintf(stderr, "xorSurfacePixels INVALID parameters: x=%d, y=%d, w=%d, h=%d\n", x, y, w, h);
+fprintf(stderr, "   dstIsdo->width=%d, dstIsdo->height=%d, biqsdoPixels->width=%d, biqsdoPixels->height=%d\n",
+                        dstIsdo->width, dstIsdo->height, srcIsdo->width, srcIsdo->height);
+#endif
+        UnlockImagePixels(env, srcIsdo);
+        UnlockImagePixels(env, dstIsdo);
+
+        return JNI_FALSE;
+    }
+
+    jint offset = (dstIsdo->width*y)+x;
+    register Pixel32bit* dstPixels = (Pixel32bit*)dstIsdo->pixels;
+    register jint skip = dstIsdo->width - w;
+    register Pixel32bit* srcPixels = (Pixel32bit*)srcIsdo->pixels;
+    register jint skipPixels = srcIsdo->width - w;
+    register jint i, j;
+
+    dstPixels += offset;
+
+    switch (dstIsdo->type)
+    {
+        case java_awt_image_BufferedImage_TYPE_INT_RGB:
+        case java_awt_image_BufferedImage_TYPE_INT_ARGB:
+        case java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE:
+        {
+            dstIsdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 1;
+
+            if (dstIsdo->type == java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE)
+            {
+                Pixel8bit alpha = (colorXOR>>24)&0xff;
+                Pixel8bit red = (colorXOR>>16)&0xff;
+                red = (jint)(((CGFloat)red/255.0f * (CGFloat)alpha/255.0f)*255.0f);
+                Pixel8bit green = (colorXOR>>8)&0xff;
+                green = (jint)(((CGFloat)green/255.0f * (CGFloat)alpha/255.0f)*255.0f);
+                Pixel8bit blue = (colorXOR>>0)&0xff;
+                blue = (jint)(((CGFloat)blue/255.0f * (CGFloat)alpha/255.0f)*255.0f);
+                colorXOR = (alpha<<24) | (red<<16) | (green<<8) | blue; // the color is now alpha premultiplied
+            }
+
+            for (i=0; i<h; i++)
+            {
+                for (j=0; j<w; j++)
+                {
+                    Pixel32bit srcPixel = *srcPixels;
+                    Pixel8bit pixelAlpha = (srcPixel>>24);
+                    if (pixelAlpha > XOR_ALPHA_CUTOFF)
+                    {
+                        *dstPixels = (*dstPixels ^ (srcPixel ^ colorXOR));
+                    }
+                    dstPixels++; srcPixels++;
+                }
+
+                dstPixels += skip;
+                srcPixels += skipPixels;
+            }
+
+            handled = JNI_TRUE;
+            break;
+        }
+        default:
+        {
+            handled = JNI_FALSE;
+#if defined(PRINT_WARNINGS)
+            fprintf(stderr, "WARNING: unknown type (%d) in compositeXOR\n", dstIsdo->type);
+            PrintImageInfo(dstIsdo);
+#endif
+        }
+    }
+
+    UnlockImagePixels(env, srcIsdo);
+    UnlockImagePixels(env, dstIsdo);
+
+JNF_COCOA_EXIT(env);
+    return handled;
+}
+
+IMAGE_SURFACE_INLINE jboolean clearSurfacePixels(JNIEnv *env, jobject bisd, jint w, jint h)
+{
+PRINT("clearSurfacePixels")
+    jboolean handled = JNI_FALSE;
+
+JNF_COCOA_ENTER(env);
+
+    ImageSDOps *isdo = LockImagePixels(env, bisd);
+
+    if (isdo->type == java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE)
+    {
+        isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 1;
+
+        w = (w < isdo->width) ? w : isdo->width;
+        h = (h < isdo->height) ? h : isdo->height;
+
+        register Pixel32bit* data = (Pixel32bit*)isdo->pixels;
+        register jint i;
+        if ((w < isdo->width) || (h < isdo->height)) //cmcnote: necessary to special-case for small height? wouldn't 4*w*h do it?
+        {
+            register jint skip = isdo->width;
+            register jint row = 4*w;
+            for (i=0; i<h; i++)
+            {
+                bzero(data, row);
+                data += skip;
+            }
+        }
+        else
+        {
+            bzero(data, 4*w*h);
+        }
+
+        handled = JNI_TRUE;
+    }
+    UnlockImagePixels(env, isdo);
+
+JNF_COCOA_EXIT(env);
+
+    return handled;
+}
+
+static void ImageSD_startCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType)
+{
+PRINT("ImageSD_startCGContext")
+
+    ImageSDOps *isdo = (ImageSDOps*)qsdo;
+
+    pthread_mutex_lock(&isdo->lock);
+
+    if (isdo->imgRef != NULL)
+    {
+        CGImageRelease(isdo->imgRef);
+        isdo->imgRef = NULL;
+    }
+
+    if (qsdo->cgRef == NULL)
+    {
+        createContext(env, isdo);
+    }
+    else
+    {
+        qsdo->newContext = NO;
+    }
+
+    if (qsdo->cgRef != NULL)
+    {
+        if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kImageStolenIndex] == 1)
+        {
+            isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 1;
+        }
+
+        // sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex can be set right above or somewhere else
+        if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] == 1)
+        {
+            syncFromJavaPixels(env, isdo);
+        }
+
+        isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNativePixelsChangedIndex] = 1;
+
+        SetUpCGContext(env, qsdo, renderType);
+    }
+}
+static void ImageSD_finishCGContext(JNIEnv *env, QuartzSDOps *qsdo)
+{
+PRINT("ImageSD_finishCGContext")
+
+    ImageSDOps *isdo = (ImageSDOps*)qsdo;
+
+    if (qsdo->cgRef != NULL)
+    {
+        CompleteCGContext(env, qsdo);
+
+        if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kImageStolenIndex] == 1)
+        {
+            syncToJavaPixels(env, isdo);
+            isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 1;
+        }
+    }
+
+    pthread_mutex_unlock(&isdo->lock);
+}
+
+static void ImageSD_dispose(JNIEnv *env, SurfaceDataOps *ops)
+{
+PRINT("ImageSD_dispose")
+
+    // copied from BufImg_Dispose in BufImgSurfaceData.c
+    {
+        /* ops is assumed non-null as it is checked in SurfaceData_DisposeOps */
+        BufImgSDOps *bisdo = (BufImgSDOps *)ops;
+        (*env)->DeleteWeakGlobalRef(env, bisdo->array);
+        if (bisdo->lutarray != NULL) {
+        (*env)->DeleteWeakGlobalRef(env, bisdo->lutarray);
+        }
+        if (bisdo->icm != NULL) {
+        (*env)->DeleteWeakGlobalRef(env, bisdo->icm);
+        }
+    }
+
+    QuartzSDOps *qsdo = (QuartzSDOps *)ops;
+
+    if (qsdo->graphicsStateInfo.batchedLines != NULL)
+    {
+        free(qsdo->graphicsStateInfo.batchedLines);
+        qsdo->graphicsStateInfo.batchedLines = NULL;
+    }
+
+    JNFDeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects);
+
+    if (qsdo->cgRef != NULL)
+    {
+        CGContextRelease(qsdo->cgRef);
+        qsdo->cgRef = NULL;
+    }
+
+    ImageSDOps *isdo = (ImageSDOps *)ops;
+
+    if (isdo->dataProvider != NULL)
+    {
+        CGDataProviderRelease(isdo->dataProvider);
+        isdo->dataProvider = NULL;
+    }
+    if (isdo->imgRef != NULL)
+    {
+        CGImageRelease(isdo->imgRef);
+        isdo->imgRef = NULL;
+    }
+    if (isdo->indexedColorTable != NULL)
+    {
+        free(isdo->indexedColorTable);
+        isdo->indexedColorTable = NULL;
+    }
+    if (isdo->lutData != NULL)
+    {
+        free(isdo->lutData);
+        isdo->indexedColorTable = NULL;
+    }
+    if (isdo->array != NULL)
+    {
+        JNFDeleteGlobalRef(env, isdo->array);
+        isdo->array = NULL;
+    }
+    if (isdo->icm != NULL)
+    {
+        JNFDeleteGlobalRef(env, isdo->icm);
+        isdo->icm = NULL;
+    }
+
+    if (isdo->nsRef) {
+        CFRelease(isdo->nsRef); // GC
+        isdo->nsRef = nil;
+    }
+
+    pthread_mutex_destroy(&isdo->lock);
+}
+
+// used by XOR (Java pixels must be up to date)
+ImageSDOps* LockImagePixels(JNIEnv* env, jobject imageSurfaceData)
+{
+PRINT("LockImagePixels")
+
+    ImageSDOps* isdo = (ImageSDOps*)SurfaceData_GetOps(env, imageSurfaceData);
+
+    pthread_mutex_lock(&isdo->lock);
+
+    holdJavaPixels(env, isdo);
+
+    // if we need to access this image's pixels we need to convert native pixels (if any) back to Java
+    if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNativePixelsChangedIndex] == 1)
+    {
+        syncToJavaPixels(env, isdo);
+        isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 1;
+    }
+
+    return isdo;
+}
+void UnlockImagePixels(JNIEnv* env, ImageSDOps* isdo)
+{
+PRINT("UnlockImagePixels")
+    // don't do that since the native pixels haven't changed (Java pixels == native pixels)
+    //syncToJavaPixels(env, isdo);
+
+    unholdJavaPixels(env, isdo);
+
+    pthread_mutex_unlock(&isdo->lock);
+}
+
+// used by drawImage (native pixels must be up to date)
+ImageSDOps* LockImage(JNIEnv* env, jobject imageSurfaceData)
+{
+PRINT("LockImage")
+
+    ImageSDOps* isdo = (ImageSDOps*)SurfaceData_GetOps(env, imageSurfaceData);
+
+    pthread_mutex_lock(&isdo->lock);
+
+    // if we need to access this image's pixels we need to convert native pixels (if any) back to Java
+    // for those images whose context type doesn't match layer type or is a custom image
+    if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kImageStolenIndex] == 1)
+    {
+        isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 1;
+    }
+
+    // sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex can be set right above or somewhere else
+    if (isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] == 1)
+    {
+        syncFromJavaPixels(env, isdo);
+    }
+
+    return isdo;
+}
+void UnlockImage(JNIEnv* env, ImageSDOps* isdo)
+{
+PRINT("UnlockImage")
+
+    // don't do that since the native pixels haven't changed (Java pixels == native pixels)
+    //syncToJavaPixels(env, isdo);
+
+    pthread_mutex_unlock(&isdo->lock);
+}
+
+JNIEXPORT jobject JNICALL Java_sun_awt_image_BufImgSurfaceData_getSurfaceData
+    (JNIEnv *env, jclass bisd, jobject bufImg)
+{
+    static jfieldID sDataID = 0;
+    if (sDataID == 0)
+    {
+        static char *bimgName = "java/awt/image/BufferedImage";
+        jclass bimg = (*env)->FindClass(env, bimgName);
+        sDataID = (*env)->GetFieldID(env, bimg, "sData", "Lsun/java2d/SurfaceData;");
+    }
+
+    return (*env)->GetObjectField(env, bufImg, sDataID);
+}
+
+JNIEXPORT void JNICALL Java_sun_awt_image_BufImgSurfaceData_setSurfaceData
+    (JNIEnv *env, jclass bisd, jobject bufImg, jobject sData)
+{
+    static jfieldID sDataID = 0;
+    if (sDataID == 0)
+    {
+        static char *bimgName = "java/awt/image/BufferedImage";
+        jclass bimg = (*env)->FindClass(env, bimgName);
+        sDataID = (*env)->GetFieldID(env, bimg, "sData", "Lsun/java2d/SurfaceData;");
+    }
+
+    (*env)->SetObjectField(env, bufImg, sDataID, sData);
+}
+
+JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_initIDs(JNIEnv *env, jclass bisd)
+{
+//PRINT("initIDs")
+    // copied from Java_sun_awt_image_BufImgSurfaceData_initIDs in BufImgSurfaceData.c
+    {
+        static char *icmName = "java/awt/image/IndexColorModel";
+        jclass icm;
+
+        if (sizeof(BufImgRIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
+        JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
+        return;
+        }
+
+        icm = (*env)->FindClass(env, icmName);
+        if (icm == NULL) {
+            return;
+        }
+
+        rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I");
+        allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z");
+        mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I");
+        CMpDataID = (*env)->GetFieldID(env, icm, "pData", "J");
+        if (allGrayID == 0 || rgbID == 0 || mapSizeID == 0 || CMpDataID == 0) {
+        JNU_ThrowInternalError(env, "Could not get field IDs");
+        }
+    }
+
+    gColorspaceRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+    gColorspaceGray = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray);
+//fprintf(stderr, "gColorspaceRGB=%p, gColorspaceGray=%p\n", gColorspaceRGB, gColorspaceGray);
+}
+
+JNIEXPORT jobject JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_getSurfaceData
+    (JNIEnv *env, jclass bisd, jobject bufImg)
+{
+PRINT("getSurfaceData")
+
+    return JNFGetObjectField(env, bufImg, jm_SurfaceData);
+}
+
+JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_setSurfaceData
+    (JNIEnv *env, jclass bisd, jobject bufImg, jobject sData)
+{
+PRINT("setSurfaceData")
+
+    JNFSetObjectField(env, bufImg, jm_SurfaceData, sData);
+}
+
+static jint ImageSD_Lock(JNIEnv *env, SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo, jint lockflags)
+{
+    ImageSDOps *isdo = (ImageSDOps*)ops;
+    pthread_mutex_lock(&isdo->lock);
+
+    // copied from BufImg_Lock in BufImgSurfaceData.c
+    {
+        BufImgSDOps *bisdo = (BufImgSDOps *)ops;
+        BufImgRIPrivate *bipriv = (BufImgRIPrivate *) &(pRasInfo->priv);
+
+        if ((lockflags & (SD_LOCK_LUT)) != 0 && !bisdo->lutarray) {
+            /* REMIND: Should this be an InvalidPipe exception? */
+            JNU_ThrowNullPointerException(env, "Attempt to lock missing colormap");
+            return SD_FAILURE;
+        }
+// TODO:BG
+        /*
+        if ((lockflags & SD_LOCK_INVCOLOR) != 0 ||
+            (lockflags & SD_LOCK_INVGRAY) != 0)
+        {
+            bipriv->cData = BufImg_SetupICM(env, bisdo);
+            if (bipriv->cData == NULL) {
+                JNU_ThrowNullPointerException(env, "Could not initialize "
+                                              "inverse tables");
+                return SD_FAILURE;
+            }
+        } else {
+            bipriv->cData = NULL;
+        }
+        */
+        bipriv->cData = NULL;
+
+        bipriv->lockFlags = lockflags;
+        bipriv->base = NULL;
+        bipriv->lutbase = NULL;
+
+        SurfaceData_IntersectBounds(&pRasInfo->bounds, &bisdo->rasbounds);
+
+        /* TODO:BG
+        if ((bipriv->lockFlags & SD_LOCK_WRITE) &&
+            bisdo->sdOps.dirty != TRUE) {
+            SurfaceData_MarkDirty(env, &bisdo->sdOps);
+        } */
+        return SD_SUCCESS;
+    }
+}
+static void ImageSD_Unlock(JNIEnv *env, SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo)
+{
+    ImageSDOps *isdo = (ImageSDOps*)ops;
+
+    // For every ImageSD_Unlock, we need to be be conservative and mark the pixels
+    // as modified by the Sun2D renderer.
+    isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex] = 1;
+
+    pthread_mutex_unlock(&isdo->lock);
+}
+static void ImageSD_GetRasInfo(JNIEnv *env, SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo)
+{
+    // copied from BufImg_GetRasInfo in BufImgSurfaceData.c
+    {
+        BufImgSDOps *bisdo = (BufImgSDOps *)ops;
+        BufImgRIPrivate *bipriv = (BufImgRIPrivate *) &(pRasInfo->priv);
+
+        if ((bipriv->lockFlags & (SD_LOCK_RD_WR)) != 0) {
+            bipriv->base =
+                (*env)->GetPrimitiveArrayCritical(env, bisdo->array, NULL);
+        }
+        if ((bipriv->lockFlags & (SD_LOCK_LUT)) != 0) {
+            bipriv->lutbase =
+                (*env)->GetPrimitiveArrayCritical(env, bisdo->lutarray, NULL);
+        }
+
+        if (bipriv->base == NULL) {
+            pRasInfo->rasBase = NULL;
+            pRasInfo->pixelStride = 0;
+            pRasInfo->scanStride = 0;
+        } else {
+            pRasInfo->rasBase = (void *)
+                (((uintptr_t) bipriv->base) + bisdo->offset);
+            pRasInfo->pixelStride = bisdo->pixStr;
+            pRasInfo->scanStride = bisdo->scanStr;
+        }
+        if (bipriv->lutbase == NULL) {
+            pRasInfo->lutBase = NULL;
+            pRasInfo->lutSize = 0;
+        } else {
+            pRasInfo->lutBase = bipriv->lutbase;
+            pRasInfo->lutSize = bisdo->lutsize;
+        }
+        if (bipriv->cData == NULL) {
+            pRasInfo->invColorTable = NULL;
+            pRasInfo->redErrTable = NULL;
+            pRasInfo->grnErrTable = NULL;
+            pRasInfo->bluErrTable = NULL;
+        } else {
+            pRasInfo->invColorTable = bipriv->cData->img_clr_tbl;
+            pRasInfo->redErrTable = bipriv->cData->img_oda_red;
+            pRasInfo->grnErrTable = bipriv->cData->img_oda_green;
+            pRasInfo->bluErrTable = bipriv->cData->img_oda_blue;
+            pRasInfo->invGrayTable = bipriv->cData->pGrayInverseLutData;
+        }
+    }
+}
+static void ImageSD_Release(JNIEnv *env, SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo)
+{
+    // copied from BufImg_Release in BufImgSurfaceData.c
+    {
+        BufImgSDOps *bisdo = (BufImgSDOps *)ops;
+        BufImgRIPrivate *bipriv = (BufImgRIPrivate *) &(pRasInfo->priv);
+
+        if (bipriv->base != NULL) {
+            jint mode = (((bipriv->lockFlags & (SD_LOCK_WRITE)) != 0)
+                         ? 0 : JNI_ABORT);
+            (*env)->ReleasePrimitiveArrayCritical(env, bisdo->array,
+                                                  bipriv->base, mode);
+        }
+        if (bipriv->lutbase != NULL) {
+            (*env)->ReleasePrimitiveArrayCritical(env, bisdo->lutarray,
+                                                  bipriv->lutbase, JNI_ABORT);
+        }
+    }
+}
+
+JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_initRaster(JNIEnv *env, jobject bisd, jobject array, jint offset, jint width, jint height,
+                                                                                jint pixelStride, jint scanStride, jobject icm, jint type,
+                                                                                    jobject jGraphicsState, jobjectArray jGraphicsStateObject, jobject jImageInfo)
+{
+PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_initRaster")
+
+    ImageSDOps* isdo = (ImageSDOps*)SurfaceData_InitOps(env, bisd, sizeof(ImageSDOps));
+
+    pthread_mutexattr_t attr;
+    pthread_mutexattr_init(&attr);
+    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+    pthread_mutex_init(&isdo->lock, &attr);
+    pthread_mutex_lock(&isdo->lock);
+    pthread_mutexattr_destroy(&attr);
+
+    // copied (and modified) from Java_sun_awt_image_BufImgSurfaceData_initRaster in BufImgSurfaceData.c
+    {
+        BufImgSDOps *bisdo =
+        //(BufImgSDOps*)SurfaceData_InitOps(env, bisd, sizeof(BufImgSDOps));
+        (BufImgSDOps*)isdo;
+        //bisdo->sdOps.Lock = BufImg_Lock;
+        //bisdo->sdOps.GetRasInfo = BufImg_GetRasInfo;
+        //bisdo->sdOps.Release = BufImg_Release;
+        //bisdo->sdOps.Unlock = NULL;
+        //bisdo->sdOps.Dispose = BufImg_Dispose;
+
+        bisdo->array = (*env)->NewWeakGlobalRef(env, array);
+        bisdo->offset = offset;
+        //bisdo->scanStr = scanStr;
+        bisdo->scanStr = scanStride;
+        //bisdo->pixStr = pixStr;
+        bisdo->pixStr = pixelStride;
+        if (!icm) {
+        bisdo->lutarray = NULL;
+        bisdo->lutsize = 0;
+        bisdo->icm = NULL;
+        } else {
+        jobject lutarray = (*env)->GetObjectField(env, icm, rgbID);
+        bisdo->lutarray = (*env)->NewWeakGlobalRef(env, lutarray);
+        bisdo->lutsize = (*env)->GetIntField(env, icm, mapSizeID);
+        bisdo->icm = (*env)->NewWeakGlobalRef(env, icm);
+        }
+        bisdo->rasbounds.x1 = 0;
+        bisdo->rasbounds.y1 = 0;
+        bisdo->rasbounds.x2 = width;
+        bisdo->rasbounds.y2 = height;
+    }
+
+    isdo->nrOfPixelsOwners = 0;
+
+    isdo->contextInfo                    = sDefaultContextInfo[type];
+    isdo->imageInfo                        = sDefaultImageInfo[type];
+
+    isdo->contextInfo.bytesPerRow        = width*isdo->contextInfo.bytesPerPixel;
+    isdo->imageInfo.bytesPerRow            = width*isdo->imageInfo.bytesPerPixel;
+
+    switch (type)
+    {
+        case java_awt_image_BufferedImage_TYPE_BYTE_GRAY:
+            isdo->contextInfo.colorSpace = isdo->imageInfo.colorSpace = gColorspaceGray;
+            break;
+        case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
+            isdo->contextInfo.colorSpace = gColorspaceRGB;
+            isdo->imageInfo.colorSpace = gColorspaceGray;
+            break;
+        default:
+            isdo->contextInfo.colorSpace = isdo->imageInfo.colorSpace = gColorspaceRGB;
+            break;
+    }
+    isdo->isSubImage                    = (offset%scanStride != 0) || (scanStride != (pixelStride*width));
+
+    // parameters specifying this image given to us from Java
+    isdo->javaImageInfo                    = (jint*)((*env)->GetDirectBufferAddress(env, jImageInfo));
+    isdo->array                            = (array != NULL) ? JNFNewGlobalRef(env, array) : NULL;
+    isdo->offset                        = offset;
+    isdo->width                            = width;
+    isdo->height                        = height;
+    isdo->javaPixelBytes                = pixelStride;
+    isdo->javaPixelsBytesPerRow            = scanStride;
+    isdo->icm                            = (icm != NULL) ? JNFNewGlobalRef(env, icm) : NULL;
+    isdo->type                            = type;
+
+    if ((isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kImageStolenIndex] == 1) ||
+        (isdo->type == java_awt_image_BufferedImage_TYPE_CUSTOM))
+    {
+        // don't waste (precious, precious) VRAM on stolen or custom images that will be slow no matter what
+        isdo->contextInfo.useWindowContextReference = NO;
+    }
+
+    // needed by TYPE_BYTE_INDEXED
+    isdo->indexedColorTable                = NULL;
+    isdo->lutData                        = NULL;
+    isdo->lutDataSize                    = 0;
+    if ((type == java_awt_image_BufferedImage_TYPE_BYTE_INDEXED) && ((*env)->IsSameObject(env, icm, NULL) == NO))
+    {
+        jarray lutarray = JNFGetObjectField(env, icm, jm_rgb);
+        isdo->lutDataSize = (*env)->GetArrayLength(env, lutarray);
+        if (isdo->lutDataSize > 0)
+        {
+            jint transparency = JNFGetIntField(env, icm, jm_transparency);
+            jint transparent_index = -1;
+            if (transparency == java_awt_Transparency_BITMASK)
+            {
+                transparent_index = JNFGetIntField(env, icm, jm_transparent_index);
+            }
+
+            Pixel32bit* lutdata = (Pixel32bit*)((*env)->GetPrimitiveArrayCritical(env, lutarray, NULL));
+            if (lutdata != NULL)
+            {
+                isdo->lutData = NULL;
+
+                isdo->lutData = malloc(isdo->lutDataSize * sizeof(Pixel32bit));
+                if (isdo->lutData != NULL)
+                {
+                    if (transparency == java_awt_Transparency_BITMASK)
+                    {
+                        Pixel32bit* src = lutdata;
+                        Pixel32bit* dst = isdo->lutData;
+                        jint i;
+                        for (i=0; i<isdo->lutDataSize; i++)
+                        {
+                            if (i != transparent_index)
+                            {
+                                *dst = *src;
+                                // rdar://problem/3390518 - don't force all indexed colors
+                                // to be fully opaque. They could be set up for us.
+                                // we used to call:  *dst = 0xff000000 | *src;
+                                // but that was forcing colors to be opaque when developers
+                                // could have set the alpha.
+                            }
+                            else
+                            {
+                                *dst = 0x00000000; // mark as translucent color
+                            }
+                            dst++; src++;
+                        }
+                    }
+                    else //if ((transparency == java_awt_Transparency_OPAQUE) || (transparency == java_awt_Transparency_TRANSLUCENT))
+                    {
+                        jint mask = 0x00000000;
+                        // <rdar://4224874> If the color model is OPAQUE than we need to create an opaque image for performance purposes.
+                        // the default alphaInfo for INDEXED images is kCGImageAlphaFirst. Therefore we need to special case this.
+                        if ((transparency == java_awt_Transparency_OPAQUE))
+                        {
+                            isdo->imageInfo.alphaInfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
+                            mask = 0xff000000; // this is just a safeguard to make sure we fill the alpha
+                        }
+
+                        Pixel32bit* src = lutdata;
+                        Pixel32bit* dst = isdo->lutData;
+                        jint i;
+                        for (i=0; i<isdo->lutDataSize; i++)
+                        {
+                            *dst = *src | mask;
+                            dst++; src++;
+                        }
+                    }
+
+                    (*env)->ReleasePrimitiveArrayCritical(env, lutarray, lutdata, 0);
+                }
+                else
+                {
+                    fprintf(stderr, "ERROR: malloc returns NULL for isdo->lutData in initRaster!\n");
+                }
+            }
+            else
+            {
+                fprintf(stderr, "ERROR: GetPrimitiveArrayCritical returns NULL for lutdata in initRaster!\n");
+            }
+        }
+        (*env)->DeleteLocalRef(env, lutarray);
+    }
+
+    QuartzSDOps *qsdo = (QuartzSDOps*)isdo;
+    qsdo->BeginSurface                    = ImageSD_startCGContext;
+    qsdo->FinishSurface                    = ImageSD_finishCGContext;
+
+    qsdo->javaGraphicsStates            = (jint*)((*env)->GetDirectBufferAddress(env, jGraphicsState));
+    qsdo->javaGraphicsStatesObjects        = JNFNewGlobalRef(env, jGraphicsStateObject);
+
+    qsdo->graphicsStateInfo.batchedLines = NULL;
+    qsdo->graphicsStateInfo.batchedLinesCount = 0;
+
+    SurfaceDataOps *sdo = (SurfaceDataOps*)qsdo;
+    sdo->Lock        = ImageSD_Lock;
+    sdo->Unlock        = ImageSD_Unlock;
+    sdo->GetRasInfo    = ImageSD_GetRasInfo;
+    sdo->Release    = ImageSD_Release;
+    sdo->Setup        = NULL;
+    sdo->Dispose    = ImageSD_dispose;
+
+    pthread_mutex_unlock(&isdo->lock);
+
+//PrintImageInfo(isdo);
+}
+
+JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_initCustomRaster(JNIEnv* env, jobject bisd, jobject array, jint width, jint height,
+                                                                                    jobject jGraphicsState, jobject jGraphicsStateObject, jobject jImageInfo)
+{
+PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_initCustomRaster")
+    jint offset = 0;
+    jint pixelStride = 4;
+    jint scanStride = pixelStride*width;
+    jobject icm = NULL;
+    jint type = java_awt_image_BufferedImage_TYPE_CUSTOM;
+
+    Java_sun_java2d_OSXOffScreenSurfaceData_initRaster(env, bisd, array, offset, width, height, pixelStride, scanStride, icm, type, jGraphicsState, jGraphicsStateObject, jImageInfo);
+}
+
+JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_syncToJavaPixels(JNIEnv *env, jobject bisd)
+{
+PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_syncToJavaPixels")
+
+    syncToJavaPixels(env, (ImageSDOps*)SurfaceData_GetOps(env, bisd));
+}
+
+JNIEXPORT jboolean JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_xorSurfacePixels
+  (JNIEnv *env, jobject dstIsd, jobject srcIsd, jint colorXOR, jint x, jint y, jint w, jint h)
+{
+PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_xorSurfacePixels")
+    return xorSurfacePixels(env, dstIsd, srcIsd, colorXOR, x, y, w, h);
+}
+
+JNIEXPORT jboolean JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_clearSurfacePixels
+  (JNIEnv *env, jobject bisd, jint w, jint h)
+{
+PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_clearSurfacePixels")
+    return clearSurfacePixels(env, bisd, w, h);
+
+}
diff --git a/jdk/src/macosx/native/sun/awt/InitIDs.h b/jdk/src/macosx/native/sun/awt/InitIDs.h
new file mode 100644
index 0000000..24ac9c5
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/InitIDs.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
diff --git a/jdk/src/macosx/native/sun/awt/InitIDs.m b/jdk/src/macosx/native/sun/awt/InitIDs.m
new file mode 100644
index 0000000..d8b0fdc
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/InitIDs.m
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <jni.h>
+
+#import "InitIDs.h"
+
+JNIEXPORT void JNICALL Java_java_awt_AWTEvent_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Button_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Checkbox_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_CheckboxMenuItem_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+
+
+JNIEXPORT void JNICALL Java_java_awt_Color_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Component_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Container_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Cursor_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Dialog_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Dimension_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Event_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_FileDialog_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Font_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_FontMetrics_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Frame_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Insets_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_KeyboardFocusManager_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Label_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Menu_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_MenuBar_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_MenuComponent_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_MenuItem_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Rectangle_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_ScrollPane_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_ScrollPaneAdjustable_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Scrollbar_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_TextArea_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_TextField_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Toolkit_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_Window_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_event_InputEvent_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_event_KeyEvent_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
+
+JNIEXPORT void JNICALL Java_java_awt_event_MouseEvent_initIDs
+(JNIEnv *env, jclass cls)
+{
+}
diff --git a/jdk/src/macosx/native/sun/awt/JavaAccessibilityAction.h b/jdk/src/macosx/native/sun/awt/JavaAccessibilityAction.h
new file mode 100644
index 0000000..f1ac007
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaAccessibilityAction.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import <jni.h>
+
+
+@protocol JavaAccessibilityAction
+
+- (NSString *)getDescription;
+- (void)perform;
+
+@end
+
+
+@interface JavaAxAction : NSObject <JavaAccessibilityAction> {
+    jobject fAccessibleAction;
+    jint fIndex;
+    jobject fComponent;
+}
+
+- (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction withIndex:(jint)index withComponent:(jobject)component;
+
+- (NSString *)getDescription;
+- (void)perform;
+
+@end
+
+
+@interface TabGroupAction : NSObject <JavaAccessibilityAction> {
+    jobject fTabGroup;
+    jint fIndex;
+    jobject fComponent;
+}
+
+- (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)index withComponent:(jobject)component;
+
+- (NSString *)getDescription;
+- (void)perform;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/JavaAccessibilityAction.m b/jdk/src/macosx/native/sun/awt/JavaAccessibilityAction.m
new file mode 100644
index 0000000..826cc08
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaAccessibilityAction.m
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "JavaAccessibilityAction.h"
+#import "JavaAccessibilityUtilities.h"
+
+#import "ThreadUtilities.h"
+
+
+@implementation JavaAxAction
+
+- (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction withIndex:(jint)index withComponent:(jobject)component
+{
+    self = [super init];
+    if (self) {
+        fAccessibleAction = JNFNewGlobalRef(env, accessibleAction);
+        fIndex = index;
+        fComponent = JNFNewGlobalRef(env, component);
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    JNFDeleteGlobalRef(env, fAccessibleAction);
+    fAccessibleAction = NULL;
+
+    JNFDeleteGlobalRef(env, fComponent);
+    fComponent = NULL;
+
+    [super dealloc];
+}
+
+- (void)finalize
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    JNFDeleteGlobalRef(env, fAccessibleAction);
+    fAccessibleAction = NULL;
+
+    JNFDeleteGlobalRef(env, fComponent);
+    fComponent = NULL;
+
+    [super finalize];
+}
+
+
+- (NSString *)getDescription
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;");
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    return JNFJavaToNSString(env, JNFCallStaticObjectMethod(env, jm_getAccessibleActionDescription, fAccessibleAction, fIndex, fComponent)); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+- (void)perform
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V");
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    JNFCallStaticVoidMethod(env, jm_doAccessibleAction, fAccessibleAction, fIndex, fComponent); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+@end
+
+
+@implementation TabGroupAction
+
+- (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)index withComponent:(jobject)component
+{
+    self = [super init];
+    if (self) {
+        fTabGroup = JNFNewGlobalRef(env, tabGroup);
+        fIndex = index;
+        fComponent = JNFNewGlobalRef(env, component);
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    JNFDeleteGlobalRef(env, fTabGroup);
+    fTabGroup = NULL;
+
+    JNFDeleteGlobalRef(env, fComponent);
+    fComponent = NULL;
+
+    [super dealloc];
+}
+
+- (void)finalize
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    JNFDeleteGlobalRef(env, fTabGroup);
+    fTabGroup = NULL;
+
+    JNFDeleteGlobalRef(env, fComponent);
+    fComponent = NULL;
+
+    [super finalize];
+}
+
+- (NSString *)getDescription
+{
+    return @"click";
+}
+
+- (void)perform
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    setAxContextSelection(env, fTabGroup, fIndex, fComponent);
+}
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/JavaAccessibilityUtilities.h b/jdk/src/macosx/native/sun/awt/JavaAccessibilityUtilities.h
new file mode 100644
index 0000000..d8d7923
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaAccessibilityUtilities.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+extern NSString *const JavaAccessibilityIgnore;
+
+extern NSMutableDictionary *sRoles;
+extern void initializeRoles();
+
+extern JNFClassInfo sjc_CAccessibility;
+extern JNFClassInfo sjc_AccessibleComponent;
+extern JNFClassInfo sjc_AccessibleContext;
+extern JNFClassInfo sjc_Accessible;
+extern JNFClassInfo sjc_AccessibleRole;
+extern JNFClassInfo sjc_Point;
+extern JNFClassInfo sjc_AccessibleText;
+
+extern JNFMemberInfo *sjm_getAccessibleRole;
+extern JNFMemberInfo *sjf_key;
+extern JNFMemberInfo *sjf_X;
+extern JNFMemberInfo *sjf_Y;
+
+NSSize getAxComponentSize(JNIEnv *env, jobject axComponent, jobject component);
+NSString *getJavaRole(JNIEnv *env, jobject axComponent, jobject component);
+jobject getAxSelection(JNIEnv *env, jobject axContext, jobject component);
+jobject getAxContextSelection(JNIEnv *env, jobject axContext, jint index, jobject component);
+void setAxContextSelection(JNIEnv *env, jobject axContext, jint index, jobject component);
+jobject getAxContext(JNIEnv *env, jobject accessible, jobject component);
+BOOL isChildSelected(JNIEnv *env, jobject accessible, jint index, jobject component);
+jobject getAxStateSet(JNIEnv *env, jobject axContext, jobject component);
+BOOL containsAxState(JNIEnv *env, jobject axContext, jobject axState, jobject component);
+BOOL isVertical(JNIEnv *env, jobject axContext, jobject component);
+BOOL isHorizontal(JNIEnv *env, jobject axContext, jobject component);
+BOOL isShowing(JNIEnv *env, jobject axContext, jobject component);
+NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject component);
+jint getAxTextCharCount(JNIEnv *env, jobject axText, jobject component);
+
+// these methods are copied from the corresponding NSAccessibility methods
+id JavaAccessibilityAttributeValue(id element, NSString *attribute);
+BOOL JavaAccessibilityIsAttributeSettable(id element, NSString *attribute);
+void JavaAccessibilitySetAttributeValue(id element, NSString *attribute, id value);
+
+// these methods are copied from the corresponding NSAccessibilityErrors methods
+void JavaAccessibilityRaiseSetAttributeToIllegalTypeException(const char *functionName, id element, NSString *attribute, id value);
+void JavaAccessibilityRaiseUnimplementedAttributeException(const char *functionName, id element, NSString *attribute);
+void JavaAccessibilityRaiseIllegalParameterTypeException(const char *functionName, id element, NSString *attribute, id parameter);
diff --git a/jdk/src/macosx/native/sun/awt/JavaAccessibilityUtilities.m b/jdk/src/macosx/native/sun/awt/JavaAccessibilityUtilities.m
new file mode 100644
index 0000000..4c0236e
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaAccessibilityUtilities.m
@@ -0,0 +1,361 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "JavaAccessibilityUtilities.h"
+
+#import <AppKit/AppKit.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+static BOOL JavaAccessibilityIsSupportedAttribute(id element, NSString *attribute);
+static void JavaAccessibilityLogError(NSString *message);
+static void _JavaAccessibilityRaiseException(NSString *reason, SInt32 errorCode);
+static NSString *AttributeWithoutAXPrefix(NSString *attribute);
+static SEL JavaAccessibilityAttributeGetter(NSString *attribute);
+static SEL JavaAccessibilityAttributeSettableTester(NSString *attribute);
+static SEL JavaAccessibilityAttributeSetter(NSString *attribute);
+
+NSString *const JavaAccessibilityIgnore = @"JavaAxIgnore";
+
+NSMutableDictionary *sRoles = nil;
+void initializeRoles();
+
+// Unique
+static JNF_CLASS_CACHE(sjc_AccessibleState, "javax/accessibility/AccessibleState");
+
+// Duplicate
+JNF_CLASS_CACHE(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility");
+JNF_CLASS_CACHE(sjc_AccessibleComponent, "javax/accessibility/AccessibleComponent");
+JNF_CLASS_CACHE(sjc_AccessibleContext, "javax/accessibility/AccessibleContext");
+JNF_CLASS_CACHE(sjc_Accessible, "javax/accessibility/Accessible");
+JNF_CLASS_CACHE(sjc_AccessibleRole, "javax/accessibility/AccessibleRole");
+JNF_CLASS_CACHE(sjc_Point, "java/awt/Point");
+JNF_CLASS_CACHE(sjc_AccessibleText, "javax/accessibility/AccessibleText");
+
+JNF_MEMBER_CACHE(sjf_key, sjc_AccessibleRole, "key", "Ljava/lang/String;");
+JNF_MEMBER_CACHE(sjf_X, sjc_Point, "x", "I");
+JNF_MEMBER_CACHE(sjf_Y, sjc_Point, "y", "I");
+
+NSSize getAxComponentSize(JNIEnv *env, jobject axComponent, jobject component)
+{
+    static JNF_CLASS_CACHE(jc_Dimension, "java/awt/Dimension");
+    static JNF_MEMBER_CACHE(jf_width, jc_Dimension, "width", "I");
+    static JNF_MEMBER_CACHE(jf_height, jc_Dimension, "height", "I");
+    static JNF_STATIC_MEMBER_CACHE(jm_getSize, sjc_CAccessibility, "getSize", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Dimension;");
+
+    jobject dimension = JNFCallStaticObjectMethod(env, jm_getSize, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode)
+
+    if (dimension == NULL) return NSZeroSize;
+    return NSMakeSize(JNFGetIntField(env, dimension, jf_width), JNFGetIntField(env, dimension, jf_height));
+}
+
+NSString *getJavaRole(JNIEnv *env, jobject axComponent, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleRole, sjc_CAccessibility, "getAccessibleRole", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;");
+    jobject axRole = JNFCallStaticObjectMethod(env, sjm_getAccessibleRole, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode)
+    if (axRole == NULL) return @"unknown";
+
+    return JNFJavaToNSString(env, axRole);
+}
+
+jobject getAxSelection(JNIEnv *env, jobject axContext, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleSelection, sjc_CAccessibility, "getAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleSelection;");
+    return JNFCallStaticObjectMethod(env, jm_getAccessibleSelection, axContext, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+jobject getAxContextSelection(JNIEnv *env, jobject axContext, jint index, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_ax_getAccessibleSelection, sjc_CAccessibility, "ax_getAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)Ljavax/accessibility/Accessible;");
+    return JNFCallStaticObjectMethod(env, jm_ax_getAccessibleSelection, axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+void setAxContextSelection(JNIEnv *env, jobject axContext, jint index, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_addAccessibleSelection, sjc_CAccessibility, "addAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)V");
+    JNFCallStaticVoidMethod(env, jm_addAccessibleSelection, axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+jobject getAxContext(JNIEnv *env, jobject accessible, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleContext, sjc_CAccessibility, "getAccessibleContext", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleContext;");
+    return JNFCallStaticObjectMethod(env, jm_getAccessibleContext, accessible, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+BOOL isChildSelected(JNIEnv *env, jobject accessible, jint index, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_isAccessibleChildSelected, sjc_CAccessibility, "isAccessibleChildSelected", "(Ljavax/accessibility/Accessible;ILjava/awt/Component;)Z");
+    return JNFCallStaticBooleanMethod(env, jm_isAccessibleChildSelected, accessible, index, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+jobject getAxStateSet(JNIEnv *env, jobject axContext, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleStateSet, sjc_CAccessibility, "getAccessibleStateSet", "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleStateSet;");
+    return JNFCallStaticObjectMethod(env, jm_getAccessibleStateSet, axContext, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+BOOL containsAxState(JNIEnv *env, jobject axContext, jobject axState, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_contains, sjc_CAccessibility, "contains", "(Ljavax/accessibility/AccessibleContext;Ljavax/accessibility/AccessibleState;Ljava/awt/Component;)Z");
+    return JNFCallStaticBooleanMethod(env, jm_contains, axContext, axState, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+BOOL isVertical(JNIEnv *env, jobject axContext, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_VERTICAL, sjc_AccessibleState, "VERTICAL", "Ljavax/accessibility/AccessibleState;");
+    jobject axVertState = JNFGetStaticObjectField(env, jm_VERTICAL);
+    return containsAxState(env, axContext, axVertState, component);
+}
+
+BOOL isHorizontal(JNIEnv *env, jobject axContext, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_HORIZONTAL, sjc_AccessibleState, "HORIZONTAL", "Ljavax/accessibility/AccessibleState;");
+    jobject axHorizState = JNFGetStaticObjectField(env, jm_HORIZONTAL);
+    return containsAxState(env, axContext, axHorizState, component);
+}
+
+BOOL isShowing(JNIEnv *env, jobject axContext, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_SHOWING, sjc_AccessibleState, "SHOWING", "Ljavax/accessibility/AccessibleState;");
+    jobject axVisibleState = JNFGetStaticObjectField(env, jm_SHOWING);
+    return containsAxState(env, axContext, axVisibleState, component);
+}
+
+NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getLocationOnScreen, sjc_CAccessibility, "getLocationOnScreen", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Point;");
+    jobject jpoint = JNFCallStaticObjectMethod(env, jm_getLocationOnScreen, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode)
+    if (jpoint == NULL) return NSZeroPoint;
+    return NSMakePoint(JNFGetIntField(env, jpoint, sjf_X), JNFGetIntField(env, jpoint, sjf_Y));
+}
+
+jint getAxTextCharCount(JNIEnv *env, jobject axText, jobject component)
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getCharCount, sjc_CAccessibility, "getCharCount", "(Ljavax/accessibility/AccessibleText;Ljava/awt/Component;)I");
+    return JNFCallStaticIntMethod(env, jm_getCharCount, axText, component); // AWT_THREADING Safe (AWTRunLoopMode)
+}
+
+// The following JavaAccessibility methods are copied from the corresponding
+// NSAccessibility methods in NSAccessibility.m.
+//
+// They implement a key-value-like coding scheme to transform messages like
+//        [self accessibilityAttributeValue:NSAccessibilityEnabledAttribute]
+// into calls on to specific methods like
+//        [self accessibilityEnabledAttribute].
+
+static NSString *AttributeWithoutAXPrefix(NSString *attribute)
+{
+    return [attribute hasPrefix:@"AX"] ? [attribute substringFromIndex:2] : attribute;
+}
+
+static SEL JavaAccessibilityAttributeGetter(NSString *attribute)
+{
+    return NSSelectorFromString([NSString stringWithFormat:@"accessibility%@Attribute", AttributeWithoutAXPrefix(attribute)]);
+}
+
+static SEL JavaAccessibilityAttributeSettableTester(NSString *attribute)
+{
+    return NSSelectorFromString([NSString stringWithFormat:@"accessibilityIs%@AttributeSettable", AttributeWithoutAXPrefix(attribute)]);
+}
+
+static SEL JavaAccessibilityAttributeSetter(NSString *attribute)
+{
+    return NSSelectorFromString([NSString stringWithFormat:@"accessibilitySet%@Attribute:", AttributeWithoutAXPrefix(attribute)]);
+}
+
+id JavaAccessibilityAttributeValue(id element, NSString *attribute)
+{
+    if (!JavaAccessibilityIsSupportedAttribute(element, attribute)) return nil;
+
+    SEL getter = JavaAccessibilityAttributeGetter(attribute);
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (![element respondsToSelector:getter]) {
+        JavaAccessibilityRaiseUnimplementedAttributeException(__FUNCTION__, element, attribute);
+        return nil;
+    }
+#endif
+
+    return [element performSelector:getter];
+}
+
+BOOL JavaAccessibilityIsAttributeSettable(id element, NSString *attribute)
+{
+    if (!JavaAccessibilityIsSupportedAttribute(element, attribute)) return NO;
+
+    SEL tester = JavaAccessibilityAttributeSettableTester(attribute);
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (![element respondsToSelector:tester]) {
+        JavaAccessibilityRaiseUnimplementedAttributeException(__FUNCTION__, element, attribute);
+        return NO;
+    }
+#endif
+
+    return [element performSelector:tester] != nil;
+}
+
+void JavaAccessibilitySetAttributeValue(id element, NSString *attribute ,id value)
+{
+    if (!JavaAccessibilityIsSupportedAttribute(element, attribute)) return;
+
+    SEL setter = JavaAccessibilityAttributeSetter(attribute);
+    if (![element accessibilityIsAttributeSettable:attribute]) return;
+
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (![element respondsToSelector:setter]) {
+        JavaAccessibilityRaiseUnimplementedAttributeException(__FUNCTION__, element, attribute);
+        return;
+    }
+#endif
+
+    [element performSelector:setter withObject:value];
+}
+
+static BOOL JavaAccessibilityIsSupportedAttribute(id element, NSString *attribute)
+{
+    return [[element accessibilityAttributeNames] indexOfObject:attribute] != NSNotFound;
+}
+
+/*
+ * Class:     apple_awt_CAccessibility
+ * Method:    roleKey
+ * Signature: (Ljavax/accessibility/AccessibleRole;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_apple_awt_CAccessibility_roleKey
+(JNIEnv *env, jclass clz, jobject axRole)
+{
+    return JNFGetObjectField(env, axRole, sjf_key);
+}
+
+
+// errors from NSAccessibilityErrors
+void JavaAccessibilityRaiseSetAttributeToIllegalTypeException(const char *functionName, id element, NSString *attribute, id value)
+{
+    NSString *reason = [NSString stringWithFormat:@"%s: Attempt set \"%@\" attribute to illegal type of value (%@:%@) for element: %@", functionName, attribute, [value class], value, element];
+    _JavaAccessibilityRaiseException(reason, kAXErrorIllegalArgument);
+}
+
+void JavaAccessibilityRaiseUnimplementedAttributeException(const char *functionName, id element, NSString *attribute)
+{
+    NSString *reason = [NSString stringWithFormat:@"%s: \"%@\" attribute unimplemented by element: %@", functionName, attribute, element];
+    _JavaAccessibilityRaiseException(reason, kAXErrorFailure);
+}
+
+void JavaAccessibilityRaiseIllegalParameterTypeException(const char *functionName, id element, NSString *attribute, id parameter)
+{
+    NSString *reason = [NSString stringWithFormat:@"%s: \"%@\" parameterized attribute passed illegal type of parameter (%@:%@) for element: %@", functionName, attribute, [parameter class], parameter, element];
+    _JavaAccessibilityRaiseException(reason, kAXErrorIllegalArgument);
+}
+
+static void _JavaAccessibilityRaiseException(NSString *reason, SInt32 errorCode)
+{
+    JavaAccessibilityLogError(reason);
+    [[NSException exceptionWithName:NSAccessibilityException reason:reason userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:errorCode], NSAccessibilityErrorCodeExceptionInfo, nil]] raise];
+}
+
+static void JavaAccessibilityLogError(NSString *message)
+{
+    NSLog(@"!!! %@", message);
+}
+
+// end appKit copies
+
+/*
+ To get the roles below, verify the perl has table below called macRoleCodes is correct.
+ Then copy the perl code into a perl script called makeAxTables.pl (make
+ sure to chmod +x makeAxTables.pl). Then run the perl script like this:
+
+ ./makeAxTables.pl /Builds/jdk1_4_1/
+
+ It will then write the void initializeRoles() method below to stdout.
+
+ Any new AccessibleRole items that aren't in the perl hash table will be written out as follows:
+ // Unknown AccessibleRole: <role>
+
+ Add these unknowns to the perl hash table and re-run the script, and use the new generated table.
+*/
+
+// NOTE: Don't modify this directly. It is machine generated. See below
+void initializeRoles()
+{
+    sRoles = [[NSMutableDictionary alloc] initWithCapacity:56];
+
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"alert"];
+    [sRoles setObject:NSAccessibilityGroupRole forKey:@"awtcomponent"];
+    [sRoles setObject:NSAccessibilityGroupRole forKey:@"canvas"];
+    [sRoles setObject:NSAccessibilityCheckBoxRole forKey:@"checkbox"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"colorchooser"];
+    [sRoles setObject:NSAccessibilityColumnRole forKey:@"columnheader"];
+    [sRoles setObject:NSAccessibilityComboBoxRole forKey:@"combobox"];
+    [sRoles setObject:NSAccessibilityTextFieldRole forKey:@"dateeditor"];
+    [sRoles setObject:NSAccessibilityImageRole forKey:@"desktopicon"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"desktoppane"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"dialog"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"directorypane"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"filechooser"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"filler"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"fontchooser"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"frame"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"glasspane"];
+    [sRoles setObject:NSAccessibilityGroupRole forKey:@"groupbox"];
+    [sRoles setObject:NSAccessibilityStaticTextRole forKey:@"hyperlink"]; //maybe a group?
+    [sRoles setObject:NSAccessibilityImageRole forKey:@"icon"];
+    [sRoles setObject:NSAccessibilityGroupRole forKey:@"internalframe"];
+    [sRoles setObject:NSAccessibilityStaticTextRole forKey:@"label"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"layeredpane"];
+    [sRoles setObject:NSAccessibilityListRole forKey:@"list"]; // maybe a group? AccessibleRole.java says a list is: "An object that presents a list of objects to the user and allows the user to select one or more of them."
+    [sRoles setObject:NSAccessibilityListRole forKey:@"listitem"];
+    [sRoles setObject:NSAccessibilityMenuRole forKey:@"menu"];
+    [sRoles setObject:NSAccessibilityMenuBarRole forKey:@"menubar"];
+    [sRoles setObject:NSAccessibilityMenuItemRole forKey:@"menuitem"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"optionpane"];
+    [sRoles setObject:NSAccessibilityRadioButtonRole forKey:@"pagetab"]; // cmcnote: cocoa tabs are radio buttons - one selected button out of a group of options
+    [sRoles setObject:NSAccessibilityTabGroupRole forKey:@"pagetablist"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"panel"];
+    [sRoles setObject:NSAccessibilityTextFieldRole forKey:@"passwordtext"];
+    [sRoles setObject:NSAccessibilityPopUpButtonRole forKey:@"popupmenu"];
+    [sRoles setObject:NSAccessibilityProgressIndicatorRole forKey:@"progressbar"];
+    [sRoles setObject:NSAccessibilityButtonRole forKey:@"pushbutton"];
+    [sRoles setObject:NSAccessibilityRadioButtonRole forKey:@"radiobutton"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"rootpane"];
+    [sRoles setObject:NSAccessibilityRowRole forKey:@"rowheader"];
+    [sRoles setObject:NSAccessibilityScrollBarRole forKey:@"scrollbar"];
+    [sRoles setObject:NSAccessibilityScrollAreaRole forKey:@"scrollpane"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"separator"];
+    [sRoles setObject:NSAccessibilitySliderRole forKey:@"slider"];
+    [sRoles setObject:NSAccessibilityIncrementorRole forKey:@"spinbox"];
+    [sRoles setObject:NSAccessibilitySplitGroupRole forKey:@"splitpane"];
+    [sRoles setObject:NSAccessibilityValueIndicatorRole forKey:@"statusbar"];
+    [sRoles setObject:NSAccessibilityGroupRole forKey:@"swingcomponent"];
+    [sRoles setObject:NSAccessibilityTableRole forKey:@"table"];
+    [sRoles setObject:NSAccessibilityTextFieldRole forKey:@"text"];
+    [sRoles setObject:NSAccessibilityTextAreaRole forKey:@"textarea"]; // supports top/bottom of document notifications: CAccessability.getAccessibleRole()
+    [sRoles setObject:NSAccessibilityCheckBoxRole forKey:@"togglebutton"];
+    [sRoles setObject:NSAccessibilityToolbarRole forKey:@"toolbar"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"tooltip"];
+    [sRoles setObject:NSAccessibilityBrowserRole forKey:@"tree"];
+    [sRoles setObject:NSAccessibilityUnknownRole forKey:@"unknown"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"viewport"];
+    [sRoles setObject:JavaAccessibilityIgnore forKey:@"window"];
+}
diff --git a/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.h b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.h
new file mode 100644
index 0000000..2a70aff
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.h
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+//#define JAVA_AX_DEBUG 1
+//#define JAVA_AX_NO_IGNORES 1
+//#define JAVA_AX_DEBUG_PARMS 1
+
+
+@interface JavaComponentAccessibility : NSObject {
+    NSView *fView;
+    NSObject *fParent;
+
+    NSString *fNSRole;
+    NSString *fJavaRole;
+
+    jint fIndex;
+    jobject fAccessible;
+    jobject fComponent;
+
+    NSMutableDictionary *fActions;
+    NSObject *fActionsLOCK;
+}
+
+- (id)initWithParent:(NSObject*)parent withEnv:(JNIEnv *)env withAccessible:(jobject)accessible withIndex:(jint)index withView:(NSView *)view withJavaRole:(NSString *)javaRole;
+- (void)unregisterFromCocoaAXSystem;
+- (void)postValueChanged;
+- (void)postSelectionChanged;
+- (BOOL)isEqual:(id)anObject;
+- (BOOL)isAccessibleWithEnv:(JNIEnv *)env forAccessible:(jobject)accessible;
+
++ (void)postFocusChanged:(id)message;
+
++ (NSArray*)childrenOfParent:(JavaComponentAccessibility*)parent withEnv:(JNIEnv *)env withChildrenCode:(NSInteger)whichChildren allowIgnored:(BOOL)allowIgnored;
++ (JavaComponentAccessibility *) createWithParent:(JavaComponentAccessibility *)parent accessible:(jobject)jaccessible role:(NSString *)javaRole index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view;
++ (JavaComponentAccessibility *) createWithAccessible:(jobject)jaccessible role:(NSString *)role index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view;
++ (JavaComponentAccessibility *) createWithAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env withView:(NSView *)view;
+
+- (NSDictionary*)getActions:(JNIEnv *)env;
+- (void)getActionsWithEnv:(JNIEnv *)env;
+
+- (jobject)axContextWithEnv:(JNIEnv *)env;
+- (NSView*)view;
+- (NSWindow*)window;
+- (id)parent;
+- (NSString *)javaRole;
+- (BOOL)isMenu;
+- (BOOL)isSelected:(JNIEnv *)env;
+- (BOOL)isVisible:(JNIEnv *)env;
+
+// attribute names
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env;
+- (NSArray *)accessibilityAttributeNames;
+
+// attributes
+- (id)accessibilityAttributeValue:(NSString *)attribute;
+- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute;
+- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute;
+
+- (NSArray *)accessibilityChildrenAttribute;
+- (BOOL)accessibilityIsChildrenAttributeSettable;
+- (NSUInteger)accessibilityIndexOfChild:(id)child;
+- (NSNumber *)accessibilityEnabledAttribute;
+- (BOOL)accessibilityIsEnabledAttributeSettable;
+- (NSNumber *)accessibilityFocusedAttribute;
+- (BOOL)accessibilityIsFocusedAttributeSettable;
+- (void)accessibilitySetFocusedAttribute:(id)value;
+- (NSString *)accessibilityHelpAttribute;
+- (BOOL)accessibilityIsHelpAttributeSettable;
+- (id)accessibilityMaxValueAttribute;
+- (BOOL)accessibilityIsMaxValueAttributeSettable;
+- (id)accessibilityMinValueAttribute;
+- (BOOL)accessibilityIsMinValueAttributeSettable;
+- (id)accessibilityOrientationAttribute;
+- (BOOL)accessibilityIsOrientationAttributeSettable;
+- (id)accessibilityParentAttribute;
+- (BOOL)accessibilityIsParentAttributeSettable;
+- (NSValue *)accessibilityPositionAttribute;
+- (BOOL)accessibilityIsPositionAttributeSettable;
+- (NSString *)accessibilityRoleAttribute;
+- (BOOL)accessibilityIsRoleAttributeSettable;
+- (NSString *)accessibilityRoleDescriptionAttribute;
+- (BOOL)accessibilityIsRoleDescriptionAttributeSettable;
+- (NSArray *)accessibilitySelectedChildrenAttribute;
+- (BOOL)accessibilityIsSelectedChildrenAttributeSettable;
+- (NSValue *)accessibilitySizeAttribute;
+- (BOOL)accessibilityIsSizeAttributeSettable;
+- (NSString *)accessibilitySubroleAttribute;
+- (BOOL)accessibilityIsSubroleAttributeSettable;
+- (NSString *)accessibilityTitleAttribute;
+- (BOOL)accessibilityIsTitleAttributeSettable;
+- (NSWindow *)accessibilityTopLevelUIElementAttribute;
+- (BOOL)accessibilityIsTopLevelUIElementAttributeSettable;
+- (id)accessibilityValueAttribute;
+- (BOOL)accessibilityIsValueAttributeSettable;
+- (void)accessibilitySetValueAttribute:(id)value;
+- (NSArray *)accessibilityVisibleChildrenAttribute;
+- (BOOL)accessibilityIsVisibleChildrenAttributeSettable;
+- (id)accessibilityWindowAttribute;
+- (BOOL)accessibilityIsWindowAttributeSettable;
+
+// actions
+- (NSArray *)accessibilityActionNames;
+- (NSString *)accessibilityActionDescription:(NSString *)action;
+- (void)accessibilityPerformAction:(NSString *)action;
+
+- (BOOL)accessibilityIsIgnored;
+- (id)accessibilityHitTest:(NSPoint)point withEnv:(JNIEnv *)env;
+- (id)accessibilityFocusedUIElement;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m
new file mode 100644
index 0000000..5aa5f94
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m
@@ -0,0 +1,1569 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// External Java Accessibility links:
+//
+// <http://java.sun.com/j2se/1.4.2/docs/guide/access/index.html>
+// <http://www-106.ibm.com/developerworks/library/j-access/?n-j-10172>
+// <http://archives.java.sun.com/archives/java-access.html> (Sun's mailing list for Java accessibility)
+
+#import "JavaComponentAccessibility.h"
+
+#import "sun_lwawt_macosx_CAccessibility.h"
+
+#import <AppKit/AppKit.h>
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import <dlfcn.h>
+
+#import "JavaAccessibilityAction.h"
+#import "JavaAccessibilityUtilities.h"
+#import "JavaTextAccessibility.h"
+#import "ThreadUtilities.h"
+#import "AWTView.h"
+
+
+// these constants are duplicated in CAccessibility.java
+#define JAVA_AX_ALL_CHILDREN (-1)
+#define JAVA_AX_SELECTED_CHILDREN (-2)
+#define JAVA_AX_VISIBLE_CHILDREN (-3)
+// If the value is >=0, it's an index
+
+static JNF_STATIC_MEMBER_CACHE(jm_getChildrenAndRoles, sjc_CAccessibility, "getChildrenAndRoles", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;IZ)[Ljava/lang/Object;");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleComponent, sjc_CAccessibility, "getAccessibleComponent", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleComponent;");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleValue, sjc_CAccessibility, "getAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleValue;");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleDescription, sjc_CAccessibility, "getAccessibleDescription", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;");
+static JNF_STATIC_MEMBER_CACHE(sjm_isFocusTraversable, sjc_CAccessibility, "isFocusTraversable", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Z");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleIndexInParent, sjc_CAccessibility, "getAccessibleIndexInParent", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)I");
+
+static JNF_CLASS_CACHE(sjc_CAccessible, "sun/lwawt/macosx/CAccessible");
+
+static JNF_MEMBER_CACHE(jf_ptr, sjc_CAccessible, "ptr", "J");
+static JNF_STATIC_MEMBER_CACHE(sjm_getCAccessible, sjc_CAccessible, "getCAccessible", "(Ljavax/accessibility/Accessible;)Lsun/lwawt/macosx/CAccessible;");
+
+
+static jobject sAccessibilityClass = NULL;
+
+// sAttributeNamesForRoleCache holds the names of the attributes to which each java
+// AccessibleRole responds (see AccessibleRole.java).
+// This cache is queried before attempting to access a given attribute for a particular role.
+static NSMutableDictionary *sAttributeNamesForRoleCache = nil;
+static NSObject *sAttributeNamesLOCK = nil;
+
+
+@interface TabGroupAccessibility : JavaComponentAccessibility {
+    NSInteger _numTabs;
+}
+
+- (id)currentTabWithEnv:(JNIEnv *)env withAxContext:(jobject)axContext;
+- (NSArray *)tabControlsWithEnv:(JNIEnv *)env withTabGroupAxContext:(jobject)axContext withTabCode:(NSInteger)whichTabs allowIgnored:(BOOL)allowIgnored;
+- (NSArray *)contentsWithEnv:(JNIEnv *)env withTabGroupAxContext:(jobject)axContext withTabCode:(NSInteger)whichTabs allowIgnored:(BOOL)allowIgnored;
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env;
+
+- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
+- (NSArray *)accessibilityChildrenAttribute;
+- (id) accessibilityTabsAttribute;
+- (BOOL)accessibilityIsTabsAttributeSettable;
+- (NSArray *)accessibilityContentsAttribute;
+- (BOOL)accessibilityIsContentsAttributeSettable;
+- (id) accessibilityValueAttribute;
+
+@end
+
+
+@interface TabGroupControlAccessibility : JavaComponentAccessibility {
+    jobject fTabGroupAxContext;
+}
+- (id)initWithParent:(NSObject *)parent withEnv:(JNIEnv *)env withAccessible:(jobject)accessible withIndex:(jint)index withTabGroup:(jobject)tabGroup withView:(NSView *)view withJavaRole:(NSString *)javaRole;
+- (jobject)tabGroup;
+- (void)getActionsWithEnv:(JNIEnv *)env;
+
+- (id)accessibilityValueAttribute;
+@end
+
+
+@interface ScrollAreaAccessibility : JavaComponentAccessibility {
+
+}
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env;
+- (NSArray *)accessibilityContentsAttribute;
+- (BOOL)accessibilityIsContentsAttributeSettable;
+- (id)accessibilityVerticalScrollBarAttribute;
+- (BOOL)accessibilityIsVerticalScrollBarAttributeSettable;
+- (id)accessibilityHorizontalScrollBarAttribute;
+- (BOOL)accessibilityIsHorizontalScrollBarAttributeSettable;
+@end
+
+
+@implementation JavaComponentAccessibility
+
+- (NSString *)description
+{
+    return [NSString stringWithFormat:@"%@(title:'%@', desc:'%@', value:'%@')", [self accessibilityRoleAttribute],
+        [self accessibilityTitleAttribute], [self accessibilityRoleDescriptionAttribute], [self accessibilityValueAttribute]];
+}
+
+- (id)initWithParent:(NSObject *)parent withEnv:(JNIEnv *)env withAccessible:(jobject)accessible withIndex:(jint)index withView:(NSView *)view withJavaRole:(NSString *)javaRole
+{
+    self = [super init];
+    if (self)
+    {
+        fParent = [parent retain];
+        fView = [view retain];
+        fJavaRole = [javaRole retain];
+
+        fAccessible = JNFNewGlobalRef(env, accessible);
+        fComponent = JNFNewGlobalRef(env, [(AWTView *)fView awtComponent:env]);
+
+        fIndex = index;
+
+        fActions = nil;
+        fActionsLOCK = [[NSObject alloc] init];
+    }
+    return self;
+}
+
+- (void)unregisterFromCocoaAXSystem
+{
+    AWT_ASSERT_APPKIT_THREAD;
+    static dispatch_once_t initialize_unregisterUniqueId_once;
+    static void (*unregisterUniqueId)(id);
+    dispatch_once(&initialize_unregisterUniqueId_once, ^{
+        void *jrsFwk = dlopen("/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/JavaRuntimeSupport", RTLD_LAZY | RTLD_LOCAL);
+        unregisterUniqueId = dlsym(jrsFwk, "JRSAccessibilityUnregisterUniqueIdForUIElement");
+    });
+    if (unregisterUniqueId) unregisterUniqueId(self);
+}
+
+- (void)dealloc
+{
+    [self unregisterFromCocoaAXSystem];
+
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    JNFDeleteGlobalRef(env, fAccessible);
+    fAccessible = NULL;
+
+    JNFDeleteGlobalRef(env, fComponent);
+    fComponent = NULL;
+
+    [fParent release];
+    fParent = nil;
+
+    [fNSRole release];
+    fNSRole = nil;
+
+    [fJavaRole release];
+    fJavaRole = nil;
+
+    [fView release];
+    fView = nil;
+
+    [fActions release];
+    fActions = nil;
+
+    [fActionsLOCK release];
+    fActionsLOCK = nil;
+
+    [super dealloc];
+}
+- (void)finalize
+{
+    [self unregisterFromCocoaAXSystem];
+
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    JNFDeleteGlobalRef(env, fAccessible);
+    fAccessible = NULL;
+
+    JNFDeleteGlobalRef(env, fComponent);
+    fComponent = NULL;
+
+    [super finalize];
+}
+
+- (void)postValueChanged
+{
+    AWT_ASSERT_APPKIT_THREAD;
+    NSAccessibilityPostNotification(self, NSAccessibilityValueChangedNotification);
+}
+
+- (void)postSelectionChanged
+{
+    AWT_ASSERT_APPKIT_THREAD;
+    NSAccessibilityPostNotification(self, NSAccessibilitySelectedTextChangedNotification);
+}
+
+- (BOOL)isEqual:(id)anObject
+{
+    if (![anObject isKindOfClass:[self class]]) return NO;
+    JavaComponentAccessibility *accessibility = (JavaComponentAccessibility *)anObject;
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    return (*env)->IsSameObject(env, accessibility->fAccessible, fAccessible);
+}
+
+- (BOOL)isAccessibleWithEnv:(JNIEnv *)env forAccessible:(jobject)accessible
+{
+    return (*env)->IsSameObject(env, fAccessible, accessible);
+}
+
++ (void)initialize
+{
+    if (sAttributeNamesForRoleCache == nil) {
+        sAttributeNamesLOCK = [[NSObject alloc] init];
+        sAttributeNamesForRoleCache = [[NSMutableDictionary alloc] initWithCapacity:10];
+    }
+
+    if (sRoles == nil) {
+        initializeRoles();
+    }
+
+    if (sAccessibilityClass == NULL) {
+        JNF_STATIC_MEMBER_CACHE(jm_getAccessibility, sjc_CAccessibility, "getAccessibility", "([Ljava/lang/String;)Lsun/lwawt/macosx/CAccessibility;");
+
+#ifdef JAVA_AX_NO_IGNORES
+        NSArray *ignoredKeys = [NSArray array];
+#else
+        NSArray *ignoredKeys = [sRoles allKeysForObject:JavaAccessibilityIgnore];
+#endif
+        jobjectArray result = NULL;
+        jsize count = [ignoredKeys count];
+
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        jclass clazz = (*env)->FindClass(env, "java/lang/String");
+        result = (*env)->NewObjectArray(env, count, clazz, NULL); // AWT_THREADING Safe (known object)
+        (*env)->DeleteLocalRef(env, clazz);
+
+        NSUInteger i;
+        for (i = 0; i < count; i++) {
+            jstring jString = JNFNSToJavaString(env, [ignoredKeys objectAtIndex:i]);
+            (*env)->SetObjectArrayElement(env, result, i, jString);
+            (*env)->DeleteLocalRef(env, jString);
+        }
+
+        sAccessibilityClass = JNFCallStaticObjectMethod(env, jm_getAccessibility, result); // AWT_THREADING Safe (known object)
+    }
+}
+
++ (void)postFocusChanged:(id)message
+{
+    AWT_ASSERT_APPKIT_THREAD;
+    NSAccessibilityPostNotification([NSApp accessibilityFocusedUIElement], NSAccessibilityFocusedUIElementChangedNotification);
+}
+
++ (jobject) getCAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env {
+    if (JNFIsInstanceOf(env, jaccessible, &sjc_CAccessible)) {
+        return jaccessible;
+    }
+    else if (JNFIsInstanceOf(env, jaccessible, &sjc_Accessible)) {
+        return JNFCallStaticObjectMethod(env, sjm_getCAccessible, jaccessible);
+    }
+    return NULL;
+}
+
++ (NSArray *)childrenOfParent:(JavaComponentAccessibility *)parent withEnv:(JNIEnv *)env withChildrenCode:(NSInteger)whichChildren allowIgnored:(BOOL)allowIgnored
+{
+    jobjectArray jchildrenAndRoles = JNFCallStaticObjectMethod(env, jm_getChildrenAndRoles, parent->fAccessible, parent->fComponent, whichChildren, allowIgnored); // AWT_THREADING Safe (AWTRunLoop)
+    if (jchildrenAndRoles == NULL) return nil;
+
+    jsize arrayLen = (*env)->GetArrayLength(env, jchildrenAndRoles);
+    NSMutableArray *children = [NSMutableArray arrayWithCapacity:arrayLen/2]; //childrenAndRoles array contains two elements (child, role) for each child
+
+    NSUInteger i;
+    NSUInteger childIndex = (whichChildren >= 0) ? whichChildren : 0; // if we're getting one particular child, make sure to set its index correctly
+    for(i = 0; i < arrayLen; i+=2)
+    {
+        jobject /* Accessible */ jchild = (*env)->GetObjectArrayElement(env, jchildrenAndRoles, i);
+        jobject /* String */ jchildJavaRole = (*env)->GetObjectArrayElement(env, jchildrenAndRoles, i+1);
+
+        NSString *childJavaRole = nil;
+        if (jchildJavaRole != NULL) {
+            childJavaRole = JNFJavaToNSString(env, JNFGetObjectField(env, jchildJavaRole, sjf_key));
+        }
+
+        JavaComponentAccessibility *child = [self createWithParent:parent accessible:jchild role:childJavaRole index:childIndex withEnv:env withView:parent->fView];
+        [children addObject:child];
+        childIndex++;
+    }
+
+    return children;
+}
+
++ (JavaComponentAccessibility *)createWithAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env withView:(NSView *)view
+{
+    jobject jcomponent = [(AWTView *)view awtComponent:env];
+    jint index = JNFCallStaticIntMethod(env, sjm_getAccessibleIndexInParent, jaccessible, jcomponent);
+    NSString *javaRole = getJavaRole(env, jaccessible, jcomponent);
+
+    return [self createWithAccessible:jaccessible role:javaRole index:index withEnv:env withView:view];
+}
+
++ (JavaComponentAccessibility *) createWithAccessible:(jobject)jaccessible role:(NSString *)javaRole index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view
+{
+    return [self createWithParent:nil accessible:jaccessible role:javaRole index:index withEnv:env withView:view];
+}
+
++ (JavaComponentAccessibility *) createWithParent:(JavaComponentAccessibility *)parent accessible:(jobject)jaccessible role:(NSString *)javaRole index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view
+{
+    // try to fetch the jCAX from Java, and return autoreleased
+    jobject jCAX = [JavaComponentAccessibility getCAccessible:jaccessible withEnv:env];
+    if (jCAX == NULL) return nil;
+    JavaComponentAccessibility *value = (JavaComponentAccessibility *) jlong_to_ptr(JNFGetLongField(env, jCAX, jf_ptr));
+    if (value != nil) return [[value retain] autorelease];
+
+    // otherwise, create a new instance
+    JavaComponentAccessibility *newChild = nil;
+    if ([javaRole isEqualToString:@"pagetablist"]) {
+        newChild = [TabGroupAccessibility alloc];
+    } else if ([javaRole isEqualToString:@"scrollpane"]) {
+        newChild = [ScrollAreaAccessibility alloc];
+    } else {
+        NSString *nsRole = [sRoles objectForKey:javaRole];
+        if ([nsRole isEqualToString:NSAccessibilityStaticTextRole] || [nsRole isEqualToString:NSAccessibilityTextAreaRole] || [nsRole isEqualToString:NSAccessibilityTextFieldRole]) {
+            newChild = [JavaTextAccessibility alloc];
+        } else {
+            newChild = [JavaComponentAccessibility alloc];
+        }
+    }
+
+    // must init freshly -alloc'd object
+    [newChild initWithParent:parent withEnv:env withAccessible:jCAX withIndex:index withView:view withJavaRole:javaRole]; // must init new instance
+
+    // must hard CFRetain() pointer poked into Java object
+    CFRetain(newChild);
+    JNFSetLongField(env, jCAX, jf_ptr, ptr_to_jlong(newChild));
+
+    // return autoreleased instance
+    return [newChild autorelease];
+}
+
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getInitialAttributeStates, sjc_CAccessibility, "getInitialAttributeStates", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[Z");
+
+    NSMutableArray *attributeNames = [NSMutableArray arrayWithCapacity:10];
+    [attributeNames retain];
+
+    // all elements respond to parent, role, role description, window, topLevelUIElement, help
+    [attributeNames addObject:NSAccessibilityParentAttribute];
+    [attributeNames addObject:NSAccessibilityRoleAttribute];
+    [attributeNames addObject:NSAccessibilityRoleDescriptionAttribute];
+    [attributeNames addObject:NSAccessibilityHelpAttribute];
+
+    // cmcnote: AXMenu usually doesn't respond to window / topLevelUIElement. But menus within a Java app's window
+    // probably should. Should we use some role other than AXMenu / AXMenuBar for Java menus?
+    [attributeNames addObject:NSAccessibilityWindowAttribute];
+    [attributeNames addObject:NSAccessibilityTopLevelUIElementAttribute];
+
+    // set accessible subrole
+    NSString *javaRole = [self javaRole];
+    if (javaRole != nil && [javaRole isEqualToString:@"passwordtext"]) {
+        //cmcnote: should turn this into a constant
+        [attributeNames addObject:NSAccessibilitySubroleAttribute];
+    }
+
+    // Get all the other accessibility attributes states we need in one swell foop.
+    // javaRole isn't pulled in because we need protected access to AccessibleRole.key
+    jbooleanArray attributeStates = JNFCallStaticObjectMethod(env, jm_getInitialAttributeStates, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (attributeStates == NULL) return NULL;
+    jboolean *attributeStatesArray = (*env)->GetBooleanArrayElements(env, attributeStates, 0);
+
+    // if there's a component, it can be enabled and it has a size/position
+    if (attributeStatesArray[0]) {
+        [attributeNames addObject:NSAccessibilityEnabledAttribute];
+        [attributeNames addObject:NSAccessibilitySizeAttribute];
+        [attributeNames addObject:NSAccessibilityPositionAttribute];
+    }
+
+    // According to javadoc, a component that is focusable will return true from isFocusTraversable,
+    // as well as having AccessibleState.FOCUSABLE in it's AccessibleStateSet.
+    // We use the former heuristic; if the component focus-traversable, add a focused attribute
+    // See also: accessibilityIsFocusedAttributeSettable
+    if (attributeStatesArray[1])
+    {
+        [attributeNames addObject:NSAccessibilityFocusedAttribute];
+    }
+
+    // if it's a pagetab / radiobutton, it has a value but no min/max value.
+    BOOL hasAxValue = attributeStatesArray[2];
+    if ([javaRole isEqualToString:@"pagetab"] || [javaRole isEqualToString:@"radiobutton"]) {
+        [attributeNames addObject:NSAccessibilityValueAttribute];
+    } else {
+        // if not a pagetab/radio button, and it has a value, it has a min/max/current value.
+        if (hasAxValue) {
+            // er, it has a min/max/current value if it's not a button.
+            // See AppKit/NSButtonCellAccessibility.m
+            if (![javaRole isEqualToString:@"pushbutton"]) {
+                //cmcnote: make this (and "passwordtext") constants instead of magic strings
+                [attributeNames addObject:NSAccessibilityMinValueAttribute];
+                [attributeNames addObject:NSAccessibilityMaxValueAttribute];
+                [attributeNames addObject:NSAccessibilityValueAttribute];
+            }
+        }
+    }
+
+    // does it have an orientation?
+    if (attributeStatesArray[4]) {
+        [attributeNames addObject:NSAccessibilityOrientationAttribute];
+    }
+
+    // name
+    if (attributeStatesArray[5]) {
+        [attributeNames addObject:NSAccessibilityTitleAttribute];
+    }
+
+    // children
+    if (attributeStatesArray[6]) {
+        [attributeNames addObject:NSAccessibilityChildrenAttribute];
+//        [attributeNames addObject:NSAccessibilitySelectedChildrenAttribute];
+//        [attributeNames addObject:NSAccessibilityVisibleChildrenAttribute];
+                //According to AXRoles.txt:
+                //VisibleChildren: radio group, list, row, table row subrole
+                //SelectedChildren: list
+    }
+
+    // Cleanup
+    (*env)->ReleaseBooleanArrayElements(env, attributeStates, attributeStatesArray, JNI_ABORT);
+
+    return attributeNames;
+}
+
+- (NSDictionary *)getActions:(JNIEnv *)env
+{
+    @synchronized(fActionsLOCK) {
+        if (fActions == nil) {
+            fActions = [[NSMutableDictionary alloc] initWithCapacity:3];
+            [self getActionsWithEnv:env];
+        }
+    }
+
+    return fActions;
+}
+
+- (void)getActionsWithEnv:(JNIEnv *)env
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleAction, sjc_CAccessibility, "getAccessibleAction", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleAction;");
+
+    // On MacOSX, text doesn't have actions, in java it does.
+    // cmcnote: NOT TRUE - Editable text has AXShowMenu. Textfields have AXConfirm. Static text has no actions.
+    jobject axAction = JNFCallStaticObjectMethod(env, jm_getAccessibleAction, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (axAction != NULL) {
+        //+++gdb NOTE: In MacOSX, there is just a single Action, not multiple. In java,
+        //  the first one seems to be the most basic, so this will be used.
+        // cmcnote: NOT TRUE - Sometimes there are multiple actions, eg sliders have AXDecrement AND AXIncrement (radr://3893192)
+        JavaAxAction *action = [[JavaAxAction alloc] initWithEnv:env withAccessibleAction:axAction withIndex:0 withComponent:fComponent];
+        [fActions setObject:action forKey:[self isMenu] ? NSAccessibilityPickAction : NSAccessibilityPressAction];
+        [action release];
+    }
+}
+
+- (jobject)axContextWithEnv:(JNIEnv *)env
+{
+    return getAxContext(env, fAccessible, fComponent);
+}
+
+- (id)parent
+{
+    static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleParent, sjc_CAccessibility, "getAccessibleParent", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/Accessible;");
+
+    if(fParent == nil) {
+        JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+        jobject jparent = JNFCallStaticObjectMethod(env, sjm_getAccessibleParent, fAccessible, fComponent);
+
+        if (jparent == NULL) {
+            fParent = fView;
+        } else {
+            fParent = [JavaComponentAccessibility createWithAccessible:jparent withEnv:env withView:fView];
+            if (fParent == nil) {
+                fParent = fView;
+            }
+        }
+        [fParent retain];
+    }
+    return fParent;
+}
+
+- (NSView *)view
+{
+    return fView;
+}
+
+- (NSWindow *)window
+{
+    return [[self view] window];
+}
+
+- (NSString *)javaRole
+{
+    if(fJavaRole == nil) {
+        JNIEnv* env = [ThreadUtilities getJNIEnv];
+        fJavaRole = getJavaRole(env, fAccessible, fComponent);
+        [fJavaRole retain];
+    }
+    return fJavaRole;
+}
+
+- (BOOL)isMenu
+{
+    id role = [self accessibilityRoleAttribute];
+    return [role isEqualToString:NSAccessibilityMenuBarRole] || [role isEqualToString:NSAccessibilityMenuRole] || [role isEqualToString:NSAccessibilityMenuItemRole];
+}
+
+- (BOOL)isSelected:(JNIEnv *)env
+{
+    if (fIndex == -1) {
+        return NO;
+    }
+
+    return isChildSelected(env, ((JavaComponentAccessibility *)[self parent])->fAccessible, fIndex, fComponent);
+}
+
+- (BOOL)isVisible:(JNIEnv *)env
+{
+    if (fIndex == -1) {
+        return NO;
+    }
+
+    return isShowing(env, [self axContextWithEnv:env], fComponent);
+}
+
+// the array of names for each role is cached in the sAttributeNamesForRoleCache
+- (NSArray *)accessibilityAttributeNames
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    @synchronized(sAttributeNamesLOCK) {
+        NSString *javaRole = [self javaRole];
+        NSArray *names = (NSArray *)[sAttributeNamesForRoleCache objectForKey:javaRole];
+        if (names != nil) return names;
+
+        names = [self initializeAttributeNamesWithEnv:env];
+        if (names != nil) {
+#ifdef JAVA_AX_DEBUG
+            NSLog(@"Initializing: %s for %@: %@", __FUNCTION__, javaRole, names);
+#endif
+            [sAttributeNamesForRoleCache setObject:names forKey:javaRole];
+            return names;
+        }
+    }
+
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"Warning in %s: could not find attribute names for role: %@", __FUNCTION__, javaRole);
+#endif
+
+    return nil;
+}
+
+// -- accessibility attributes --
+
+- (BOOL)accessibilityShouldUseUniqueId {
+    return YES;
+}
+
+- (BOOL)accessibilitySupportsOverriddenAttributes {
+    return YES;
+}
+
+
+// generic getters & setters
+// cmcnote: it would make more sense if these generic getters/setters were in JavaAccessibilityUtilities
+- (id)accessibilityAttributeValue:(NSString *)attribute
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    // turns attribute "NSAccessibilityEnabledAttribute" into getter "accessibilityEnabledAttribute",
+    // calls getter on self
+    return JavaAccessibilityAttributeValue(self, attribute);
+}
+
+- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    // turns attribute "NSAccessibilityParentAttribute" into selector "accessibilityIsParentAttributeSettable",
+    // calls selector on self
+    return JavaAccessibilityIsAttributeSettable(self, attribute);
+}
+
+- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    if ([self accessibilityIsAttributeSettable:attribute]) {
+        // turns attribute "NSAccessibilityFocusAttribute" into setter "accessibilitySetFocusAttribute",
+        // calls setter on self
+        JavaAccessibilitySetAttributeValue(self, attribute, value);
+    }
+}
+
+
+// specific attributes, in alphabetical order a la
+// http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Protocols/NSAccessibility.html
+
+// Elements that current element contains (NSArray)
+- (NSArray *)accessibilityChildrenAttribute
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    NSArray *children = [JavaComponentAccessibility childrenOfParent:self withEnv:env withChildrenCode:JAVA_AX_VISIBLE_CHILDREN allowIgnored:NO];
+
+    NSArray *value = nil;
+    if ([children count] > 0) {
+        value = children;
+    }
+
+    return value;
+}
+- (BOOL)accessibilityIsChildrenAttributeSettable
+{
+    return NO;
+}
+
+- (NSUInteger)accessibilityIndexOfChild:(id)child
+{
+    // Only special-casing for Lists, for now. This allows lists to be accessible, fixing radr://3856139 "JLists are broken".
+    // Will probably want to special-case for Tables when we implement them (radr://3096643 "Accessibility: Table").
+    // In AppKit, NSMatrixAccessibility (which uses NSAccessibilityListRole), NSTableRowAccessibility, and NSTableViewAccessibility are the
+    // only ones that override the default implementation in NSAccessibility
+    if (![[self accessibilityRoleAttribute] isEqualToString:NSAccessibilityListRole]) {
+        return [super accessibilityIndexOfChild:child];
+    }
+
+    return JNFCallStaticIntMethod([ThreadUtilities getJNIEnv], sjm_getAccessibleIndexInParent, ((JavaComponentAccessibility *)child)->fAccessible, ((JavaComponentAccessibility *)child)->fComponent);
+}
+
+// Without this optimization accessibilityChildrenAttribute is called in order to get the entire array of children.
+- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount {
+    if ( (maxCount == 1) && [attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
+        // Children codes for ALL, SELECTED, VISIBLE are <0. If the code is >=0, we treat it as an index to a single child
+        NSArray *child = [JavaComponentAccessibility childrenOfParent:self withEnv:[ThreadUtilities getJNIEnv] withChildrenCode:(NSInteger)index allowIgnored:NO];
+        if ([child count] > 0) {
+            return child;
+        }
+    }
+    return [super accessibilityArrayAttributeValues:attribute index:index maxCount:maxCount];
+}
+
+// Flag indicating enabled state of element (NSNumber)
+- (NSNumber *)accessibilityEnabledAttribute
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_isEnabled, sjc_CAccessibility, "isEnabled", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Z");
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    NSNumber *value = [NSNumber numberWithBool:JNFCallStaticBooleanMethod(env, jm_isEnabled, fAccessible, fComponent)]; // AWT_THREADING Safe (AWTRunLoop)
+    if (value == nil) {
+        NSLog(@"WARNING: %s called on component that has no accessible component: %@", __FUNCTION__, self);
+    }
+    return value;
+}
+
+- (BOOL)accessibilityIsEnabledAttributeSettable
+{
+    return NO;
+}
+
+// Flag indicating presence of keyboard focus (NSNumber)
+- (NSNumber *)accessibilityFocusedAttribute
+{
+    if ([self accessibilityIsFocusedAttributeSettable]) {
+        return [NSNumber numberWithBool:[self isEqual:[NSApp accessibilityFocusedUIElement]]];
+    }
+    return [NSNumber numberWithBool:NO];
+}
+
+- (BOOL)accessibilityIsFocusedAttributeSettable
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    // According to javadoc, a component that is focusable will return true from isFocusTraversable,
+    // as well as having AccessibleState.FOCUSABLE in its AccessibleStateSet.
+    // We use the former heuristic; if the component focus-traversable, add a focused attribute
+    // See also initializeAttributeNamesWithEnv:
+    if (JNFCallStaticBooleanMethod(env, sjm_isFocusTraversable, fAccessible, fComponent)) { // AWT_THREADING Safe (AWTRunLoop)
+        return YES;
+    }
+
+    return NO;
+}
+
+- (void)accessibilitySetFocusedAttribute:(id)value
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_requestFocus, sjc_CAccessibility, "requestFocus", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V");
+
+    if ([(NSNumber*)value boolValue])
+    {
+        JNIEnv* env = [ThreadUtilities getJNIEnv];
+        JNFCallStaticVoidMethod(env, jm_requestFocus, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    }
+}
+
+// Instance description, such as a help tag string (NSString)
+- (NSString *)accessibilityHelpAttribute
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleDescription, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    return JNFJavaToNSString(env, val);
+}
+
+- (BOOL)accessibilityIsHelpAttributeSettable
+{
+    return NO;
+}
+
+// Element's maximum value (id)
+- (id)accessibilityMaxValueAttribute
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getMaximumAccessibleValue, sjc_CAccessibility, "getMaximumAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;");
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    jobject axValue = JNFCallStaticObjectMethod(env, jm_getMaximumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    return JNFJavaToNSNumber(env, axValue);
+}
+
+- (BOOL)accessibilityIsMaxValueAttributeSettable
+{
+    return NO;
+}
+
+// Element's minimum value (id)
+- (id)accessibilityMinValueAttribute
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getMinimumAccessibleValue, sjc_CAccessibility, "getMinimumAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;");
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    jobject axValue = JNFCallStaticObjectMethod(env, jm_getMinimumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    return JNFJavaToNSNumber(env, axValue);
+}
+
+- (BOOL)accessibilityIsMinValueAttributeSettable
+{
+    return NO;
+}
+
+- (id)accessibilityOrientationAttribute
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    jobject axContext = [self axContextWithEnv:env];
+
+    // cmcnote - should batch these two calls into one that returns an array of two bools, one for vertical and one for horiz
+    if (isVertical(env, axContext, fComponent)) {
+        return NSAccessibilityVerticalOrientationValue;
+    }
+
+    if (isHorizontal(env, axContext, fComponent)) {
+        return NSAccessibilityHorizontalOrientationValue;
+    }
+
+    return nil;
+}
+
+- (BOOL)accessibilityIsOrientationAttributeSettable
+{
+    return NO;
+}
+
+// Element containing current element (id)
+- (id)accessibilityParentAttribute
+{
+    return NSAccessibilityUnignoredAncestor([self parent]);
+}
+
+- (BOOL)accessibilityIsParentAttributeSettable
+{
+    return NO;
+}
+
+// Screen position of element's lower-left corner in lower-left relative screen coordinates (NSValue)
+- (NSValue *)accessibilityPositionAttribute
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    jobject axComponent = JNFCallStaticObjectMethod(env, sjm_getAccessibleComponent, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+
+    // NSAccessibility wants the bottom left point of the object in
+    // bottom left based screen coords
+
+    // Get the java screen coords, and make a NSPoint of the bottom left of the AxComponent.
+    NSSize size = getAxComponentSize(env, axComponent, fComponent);
+    NSPoint point = getAxComponentLocationOnScreen(env, axComponent, fComponent);
+
+    point.y += size.height;
+
+    // Now make it into Cocoa screen coords.
+    point.y = [[[[self view] window] screen] frame].size.height - point.y;
+
+    return [NSValue valueWithPoint:point];
+}
+
+- (BOOL)accessibilityIsPositionAttributeSettable
+{
+    // In AppKit, position is only settable for a window (NSAccessibilityWindowRole). Our windows are taken care of natively, so we don't need to deal with this here
+    // We *could* make use of Java's AccessibleComponent.setLocation() method. Investigate. radr://3953869
+    return NO;
+}
+
+// Element type, such as NSAccessibilityRadioButtonRole (NSString). See the role table
+// at http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Protocols/NSAccessibility.html
+- (NSString *)accessibilityRoleAttribute
+{
+    if (fNSRole == nil) {
+        NSString *javaRole = [self javaRole];
+        fNSRole = [sRoles objectForKey:javaRole];
+        if (fNSRole == nil) {
+            // this component has assigned itself a custom AccessibleRole not in the sRoles array
+            fNSRole = javaRole;
+        }
+        [fNSRole retain];
+    }
+    return fNSRole;
+}
+- (BOOL)accessibilityIsRoleAttributeSettable
+{
+    return NO;
+}
+
+// Localized, user-readable description of role, such as radio button (NSString)
+- (NSString *)accessibilityRoleDescriptionAttribute
+{
+    // first ask AppKit for its accessible role description for a given AXRole
+    NSString *value = NSAccessibilityRoleDescription([self accessibilityRoleAttribute], nil);
+
+    if (value == nil) {
+        // query java if necessary
+        static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleRoleDisplayString, sjc_CAccessibility, "getAccessibleRoleDisplayString", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;");
+
+        JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+        jobject axRole = JNFCallStaticObjectMethod(env, jm_getAccessibleRoleDisplayString, fAccessible, fComponent);
+        if(axRole != NULL) {
+            value = JNFJavaToNSString(env, axRole);
+        } else {
+            value = @"unknown";
+        }
+    }
+
+    return value;
+}
+
+- (BOOL)accessibilityIsRoleDescriptionAttributeSettable
+{
+    return NO;
+}
+
+// Currently selected children (NSArray)
+- (NSArray *)accessibilitySelectedChildrenAttribute
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    NSArray *selectedChildren = [JavaComponentAccessibility childrenOfParent:self withEnv:env withChildrenCode:JAVA_AX_SELECTED_CHILDREN allowIgnored:NO];
+    if ([selectedChildren count] > 0) {
+        return selectedChildren;
+    }
+
+    return nil;
+}
+
+- (BOOL)accessibilityIsSelectedChildrenAttributeSettable
+{
+    return NO; // cmcnote: actually it should be. so need to write accessibilitySetSelectedChildrenAttribute also
+}
+
+// Element size (NSValue)
+- (NSValue *)accessibilitySizeAttribute {
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    jobject axComponent = JNFCallStaticObjectMethod(env, sjm_getAccessibleComponent, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    return [NSValue valueWithSize:getAxComponentSize(env, axComponent, fComponent)];
+}
+
+- (BOOL)accessibilityIsSizeAttributeSettable
+{
+    // SIZE is settable in windows if [self styleMask] & NSResizableWindowMask - but windows are heavyweight so we're ok here
+    // SIZE is settable in columns if [[self tableValue] allowsColumnResizing - haven't dealt with columns yet
+    return NO;
+}
+
+// Element subrole type, such as NSAccessibilityTableRowSubrole (NSString). See the subrole attribute table at
+// http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Protocols/NSAccessibility.html
+- (NSString *)accessibilitySubroleAttribute
+{
+    NSString *value = nil;
+    if ([[self javaRole] isEqualToString:@"passwordtext"])
+    {
+        value = NSAccessibilitySecureTextFieldSubrole;
+    }
+    /*
+    // other subroles. TableRow and OutlineRow may be relevant to us
+     NSAccessibilityCloseButtonSubrole // no, heavyweight window takes care of this
+     NSAccessibilityMinimizeButtonSubrole // "
+     NSAccessibilityOutlineRowSubrole    // maybe?
+     NSAccessibilitySecureTextFieldSubrole // currently used
+     NSAccessibilityTableRowSubrole        // maybe?
+     NSAccessibilityToolbarButtonSubrole // maybe?
+     NSAccessibilityUnknownSubrole
+     NSAccessibilityZoomButtonSubrole    // no, heavyweight window takes care of this
+     NSAccessibilityStandardWindowSubrole// no, heavyweight window takes care of this
+     NSAccessibilityDialogSubrole        // maybe?
+     NSAccessibilitySystemDialogSubrole    // no
+     NSAccessibilityFloatingWindowSubrole // in 1.5 if we implement these, heavyweight will take care of them anyway
+     NSAccessibilitySystemFloatingWindowSubrole
+     NSAccessibilityIncrementArrowSubrole  // no
+     NSAccessibilityDecrementArrowSubrole  // no
+     NSAccessibilityIncrementPageSubrole   // no
+     NSAccessibilityDecrementPageSubrole   // no
+     NSAccessibilitySearchFieldSubrole    //no
+     */
+    return value;
+}
+
+- (BOOL)accessibilityIsSubroleAttributeSettable
+{
+    return NO;
+}
+
+// Title of element, such as button text (NSString)
+- (NSString *)accessibilityTitleAttribute
+{
+    // Return empty string for labels, since their value and tile end up being the same thing and this leads to repeated text.
+    if ([[self accessibilityRoleAttribute] isEqualToString:NSAccessibilityStaticTextRole]) {
+        return @"";
+    }
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    return JNFJavaToNSString(env, val);
+}
+
+- (BOOL)accessibilityIsTitleAttributeSettable
+{
+    return NO;
+}
+
+- (NSWindow *)accessibilityTopLevelUIElementAttribute
+{
+    return [self window];
+}
+
+- (BOOL)accessibilityIsTopLevelUIElementAttributeSettable
+{
+    return NO;
+}
+
+// Element's value (id)
+// note that the appKit meaning of "accessibilityValue" is different from the java
+// meaning of "accessibleValue", which is specific to numerical values
+// (http://java.sun.com/j2se/1.3/docs/api/javax/accessibility/AccessibleValue.html#setCurrentAccessibleValue(java.lang.Number))
+- (id)accessibilityValueAttribute
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getCurrentAccessibleValue, sjc_CAccessibility, "getCurrentAccessibleValue", "(Ljavax/accessibility/AccessibleValue;Ljava/awt/Component;)Ljava/lang/Number;");
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+
+    // ask Java for the component's accessibleValue. In java, the "accessibleValue" just means a numerical value
+    // a text value is taken care of in JavaTextAccessibility
+
+    // cmcnote should coalesce these calls into one java call
+    jobject axValue = JNFCallStaticObjectMethod(env, sjm_getAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    return JNFJavaToNSNumber(env, JNFCallStaticObjectMethod(env, jm_getCurrentAccessibleValue, axValue, fComponent)); // AWT_THREADING Safe (AWTRunLoop)
+}
+
+- (BOOL)accessibilityIsValueAttributeSettable
+{
+    // according ot AppKit sources, in general the value attribute is not settable, except in the cases
+    // of an NSScroller, an NSSplitView, and text that's both enabled & editable
+    BOOL isSettable = NO;
+    NSString *role = [self accessibilityRoleAttribute];
+
+    if ([role isEqualToString:NSAccessibilityScrollBarRole] || // according to NSScrollerAccessibility
+        [role isEqualToString:NSAccessibilitySplitGroupRole] ) // according to NSSplitViewAccessibility
+    {
+        isSettable = YES;
+    }
+    return isSettable;
+}
+
+- (void)accessibilitySetValueAttribute:(id)value
+{
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"Not yet implemented: %s\n", __FUNCTION__); // radr://3954018
+#endif
+}
+
+
+// Child elements that are visible (NSArray)
+- (NSArray *)accessibilityVisibleChildrenAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    NSArray *visibleChildren = [JavaComponentAccessibility childrenOfParent:self withEnv:env withChildrenCode:JAVA_AX_VISIBLE_CHILDREN allowIgnored:NO];
+    if ([visibleChildren count] <= 0) return nil;
+    return visibleChildren;
+}
+
+- (BOOL)accessibilityIsVisibleChildrenAttributeSettable
+{
+    return NO;
+}
+
+// Window containing current element (id)
+- (id)accessibilityWindowAttribute
+{
+    return [self window];
+}
+
+- (BOOL)accessibilityIsWindowAttributeSettable
+{
+    return NO;
+}
+
+
+// -- accessibility actions --
+- (NSArray *)accessibilityActionNames
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    return [[self getActions:env] allKeys];
+}
+
+- (NSString *)accessibilityActionDescription:(NSString *)action
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    return [(id <JavaAccessibilityAction>)[[self getActions:env] objectForKey:action] getDescription];
+}
+
+- (void)accessibilityPerformAction:(NSString *)action
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    [(id <JavaAccessibilityAction>)[[self getActions:env] objectForKey:action] perform];
+}
+
+
+// -- misc accessibility --
+- (BOOL)accessibilityIsIgnored
+{
+#ifdef JAVA_AX_NO_IGNORES
+    return NO;
+#else
+    return [[self accessibilityRoleAttribute] isEqualToString:JavaAccessibilityIgnore];
+#endif /* JAVA_AX_NO_IGNORES */
+}
+
+- (id)accessibilityHitTest:(NSPoint)point withEnv:(JNIEnv *)env
+{
+    static JNF_CLASS_CACHE(jc_Container, "java/awt/Container");
+    static JNF_STATIC_MEMBER_CACHE(jm_accessibilityHitTest, sjc_CAccessibility, "accessibilityHitTest", "(Ljava/awt/Container;FF)Ljavax/accessibility/Accessible;");
+
+    // Make it into java screen coords
+    point.y = [[[[self view] window] screen] frame].size.height - point.y;
+
+    jobject jparent = fComponent;
+
+    id value = nil;
+    if (JNFIsInstanceOf(env, jparent, &jc_Container)) {
+        jobject jaccessible = JNFCallStaticObjectMethod(env, jm_accessibilityHitTest, jparent, (jfloat)point.x, (jfloat)point.y); // AWT_THREADING Safe (AWTRunLoop)
+        value = [JavaComponentAccessibility createWithAccessible:jaccessible withEnv:env withView:fView];
+    }
+
+    if (value == nil) {
+        value = self;
+    }
+
+    if ([value accessibilityIsIgnored]) {
+        value = NSAccessibilityUnignoredAncestor(value);
+    }
+
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"%s: %@", __FUNCTION__, value);
+#endif
+    return value;
+}
+
+- (id)accessibilityFocusedUIElement
+{
+    static JNF_STATIC_MEMBER_CACHE(jm_getFocusOwner, sjc_CAccessibility, "getFocusOwner", "(Ljava/awt/Component;)Ljavax/accessibility/Accessible;");
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    id value = nil;
+
+    // This code frequently gets called indirectly by Java when VoiceOver is active.
+    // Basically, we just have to know when we going to be a bad state, and do something "special".
+    // Note that while NSApplication isn't technically correct, we post a focus changed notification
+    // (which will call this method, but with the correct codepath) shortly afterwards. See +postFocusChanged.
+    if (sInPerformFromJava) {
+        return [NSApplication sharedApplication];
+    } else {
+        jobject focused = JNFCallStaticObjectMethod(env, jm_getFocusOwner, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+        if (focused != NULL) {
+            if (JNFIsInstanceOf(env, focused, &sjc_Accessible)) {
+                value = [JavaComponentAccessibility createWithAccessible:focused withEnv:env withView:fView];
+            }
+        }
+    }
+
+    if (value == nil) {
+        value = self;
+    }
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"%s: %@", __FUNCTION__, value);
+#endif
+    return value;
+}
+
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CAccessibility
+ * Method:    focusChanged
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessibility_focusChanged
+(JNIEnv *env, jobject jthis)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+JNF_COCOA_ENTER(env);
+    [ThreadUtilities performOnMainThread:@selector(postFocusChanged:) onObject:[JavaComponentAccessibility class] withObject:nil waitUntilDone:NO awtMode:NO];
+JNF_COCOA_EXIT(env);
+}
+
+
+
+/*
+ * Class:     sun_lwawt_macosx_CAccessible
+ * Method:    valueChanged
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_valueChanged
+(JNIEnv *env, jclass jklass, jlong element)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+    [ThreadUtilities performOnMainThread:@selector(postValueChanged) onObject:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO awtMode:NO];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CAccessible
+ * Method:    selectionChanged
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_selectionChanged
+(JNIEnv *env, jclass jklass, jlong element)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+    [ThreadUtilities performOnMainThread:@selector(postSelectionChanged) onObject:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO awtMode:NO];
+JNF_COCOA_EXIT(env);
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_CAccessible
+ * Method:    unregisterFromCocoaAXSystem
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_unregisterFromCocoaAXSystem
+(JNIEnv *env, jclass jklass, jlong element)
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+    [ThreadUtilities performOnMainThread:@selector(unregisterFromCocoaAXSystem) onObject:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO awtMode:NO];
+JNF_COCOA_EXIT(env);
+}
+
+@implementation TabGroupAccessibility
+
+- (id)initWithParent:(NSObject *)parent withEnv:(JNIEnv *)env withAccessible:(jobject)accessible withIndex:(jint)index withView:(NSView *)view withJavaRole:(NSString *)javaRole
+{
+    self = [super initWithParent:parent withEnv:env withAccessible:accessible withIndex:index withView:view withJavaRole:javaRole];
+    if (self) {
+        _numTabs = -1; //flag for uninitialized numTabs
+    }
+    return self;
+}
+
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env
+{
+    NSMutableArray *names = (NSMutableArray *)[super initializeAttributeNamesWithEnv:env];
+
+    [names addObject:NSAccessibilityTabsAttribute];
+    [names addObject:NSAccessibilityContentsAttribute];
+    [names addObject:NSAccessibilityValueAttribute];
+
+    return names;
+}
+
+- (id)currentTabWithEnv:(JNIEnv *)env withAxContext:(jobject)axContext
+{
+    NSArray *tabs = [self tabControlsWithEnv:env withTabGroupAxContext:axContext withTabCode:JAVA_AX_ALL_CHILDREN allowIgnored:NO];
+
+    // Looking at the JTabbedPane sources, there is always one AccessibleSelection.
+    jobject selAccessible = getAxContextSelection(env, axContext, 0, fComponent);
+    if (selAccessible == NULL) return nil;
+
+    // Go through the tabs and find selAccessible
+    _numTabs = [tabs count];
+    JavaComponentAccessibility *aTab;
+    NSUInteger i;
+    for (i = 0; i < _numTabs; i++) {
+        aTab = (JavaComponentAccessibility *)[tabs objectAtIndex:i];
+        if ([aTab isAccessibleWithEnv:env forAccessible:selAccessible]) {
+            return aTab;
+        }
+    }
+
+    return nil;
+}
+
+- (NSArray *)tabControlsWithEnv:(JNIEnv *)env withTabGroupAxContext:(jobject)axContext withTabCode:(NSInteger)whichTabs allowIgnored:(BOOL)allowIgnored
+{
+    jobjectArray jtabsAndRoles = JNFCallStaticObjectMethod(env, jm_getChildrenAndRoles, fAccessible, fComponent, whichTabs, allowIgnored); // AWT_THREADING Safe (AWTRunLoop)
+    if(jtabsAndRoles == NULL) return nil;
+
+    jsize arrayLen = (*env)->GetArrayLength(env, jtabsAndRoles);
+    if (arrayLen == 0) return nil;
+
+    NSMutableArray *tabs = [NSMutableArray arrayWithCapacity:(arrayLen/2)];
+
+    // all of the tabs have the same role, so we can just find out what that is here and use it for all the tabs
+    jobject jtabJavaRole = (*env)->GetObjectArrayElement(env, jtabsAndRoles, 1); // the array entries alternate between tab/role, starting with tab. so the first role is entry 1.
+    if (jtabJavaRole == NULL) return nil;
+
+    NSString *tabJavaRole = JNFJavaToNSString(env, JNFGetObjectField(env, jtabJavaRole, sjf_key));
+
+    NSUInteger i;
+    NSUInteger tabIndex = (whichTabs >= 0) ? whichTabs : 0; // if we're getting one particular child, make sure to set its index correctly
+    for(i = 0; i < arrayLen; i+=2) {
+        jobject jtab = (*env)->GetObjectArrayElement(env, jtabsAndRoles, i);
+        JavaComponentAccessibility *tab = [[[TabGroupControlAccessibility alloc] initWithParent:self withEnv:env withAccessible:jtab withIndex:tabIndex withTabGroup:axContext withView:[self view] withJavaRole:tabJavaRole] autorelease];
+        [tabs addObject:tab];
+        tabIndex++;
+    }
+
+    return tabs;
+}
+
+- (NSArray *)contentsWithEnv:(JNIEnv *)env withTabGroupAxContext:(jobject)axContext withTabCode:(NSInteger)whichTabs allowIgnored:(BOOL)allowIgnored
+{
+    // Contents are the children of the selected tab.
+    id currentTab = [self currentTabWithEnv:env withAxContext:axContext];
+    if (currentTab == nil) return nil;
+
+    NSArray *contents = [JavaComponentAccessibility childrenOfParent:currentTab withEnv:env withChildrenCode:whichTabs allowIgnored:allowIgnored];
+    if ([contents count] <= 0) return nil;
+    return contents;
+}
+
+- (id) accessibilityTabsAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject axContext = [self axContextWithEnv:env];
+    return [self tabControlsWithEnv:env withTabGroupAxContext:axContext withTabCode:JAVA_AX_ALL_CHILDREN allowIgnored:NO];
+}
+
+- (BOOL)accessibilityIsTabsAttributeSettable
+{
+    return NO; //cmcnote: not sure.
+}
+
+- (NSInteger)numTabs
+{
+    if (_numTabs == -1) {
+        _numTabs = [[self accessibilityTabsAttribute] count];
+    }
+    return _numTabs;
+}
+
+- (NSArray *) accessibilityContentsAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject axContext = [self axContextWithEnv:env];
+    return [self contentsWithEnv:env withTabGroupAxContext:axContext withTabCode:JAVA_AX_ALL_CHILDREN allowIgnored:NO];
+}
+
+- (BOOL)accessibilityIsContentsAttributeSettable
+{
+    return NO;
+}
+
+// axValue is the currently selected tab
+-(id) accessibilityValueAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject axContext = [self axContextWithEnv:env];
+    return [self currentTabWithEnv:env withAxContext:axContext];
+}
+
+- (BOOL)accessibilityIsValueAttributeSettable
+{
+    return YES;
+}
+
+- (void)accessibilitySetValueAttribute:(id)value //cmcnote: not certain this is ever actually called. investigate.
+{
+    // set the current tab
+    NSNumber *number = (NSNumber *)value;
+    if (![number boolValue]) return;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject axContext = [self axContextWithEnv:env];
+    setAxContextSelection(env, axContext, fIndex, fComponent);
+}
+
+- (NSArray *)accessibilityChildrenAttribute
+{
+    //children = AXTabs + AXContents
+    NSArray *tabs = [self accessibilityTabsAttribute];
+    NSArray *contents = [self accessibilityContentsAttribute];
+
+    NSMutableArray *children = [NSMutableArray arrayWithCapacity:[tabs count] + [contents count]];
+    [children addObjectsFromArray:tabs];
+    [children addObjectsFromArray:contents];
+
+    return (NSArray *)children;
+}
+
+// Without this optimization accessibilityChildrenAttribute is called in order to get the entire array of children.
+// See similar optimization in JavaComponentAccessibility. We have to extend the base implementation here, since
+// children of tabs are AXTabs + AXContents
+- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount {
+    NSArray *result = nil;
+    if ( (maxCount == 1) && [attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
+        // Children codes for ALL, SELECTED, VISIBLE are <0. If the code is >=0, we treat it as an index to a single child
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        jobject axContext = [self axContextWithEnv:env];
+
+        //children = AXTabs + AXContents
+        NSArray *children = [self tabControlsWithEnv:env withTabGroupAxContext:axContext withTabCode:index allowIgnored:NO]; // first look at the tabs
+        if ([children count] > 0) {
+            result = children;
+         } else {
+            children= [self contentsWithEnv:env withTabGroupAxContext:axContext withTabCode:(index-[self numTabs]) allowIgnored:NO];
+            if ([children count] > 0) {
+                result = children;
+            }
+        }
+    } else {
+        result = [super accessibilityArrayAttributeValues:attribute index:index maxCount:maxCount];
+    }
+    return result;
+}
+
+@end
+
+
+static BOOL ObjectEquals(JNIEnv *env, jobject a, jobject b, jobject component);
+
+@implementation TabGroupControlAccessibility
+
+- (id)initWithParent:(NSObject *)parent withEnv:(JNIEnv *)env withAccessible:(jobject)accessible withIndex:(jint)index withTabGroup:(jobject)tabGroup withView:(NSView *)view withJavaRole:(NSString *)javaRole
+{
+    self = [super initWithParent:parent withEnv:env withAccessible:accessible withIndex:index withView:view withJavaRole:javaRole];
+    if (self) {
+        if (tabGroup != NULL) {
+            fTabGroupAxContext = JNFNewGlobalRef(env, tabGroup);
+        } else {
+            fTabGroupAxContext = NULL;
+        }
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    if (fTabGroupAxContext != NULL) {
+        JNFDeleteGlobalRef(env, fTabGroupAxContext);
+        fTabGroupAxContext = NULL;
+    }
+
+    [super dealloc];
+}
+
+- (void)finalize
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+
+    if (fTabGroupAxContext != NULL) {
+        JNFDeleteGlobalRef(env, fTabGroupAxContext);
+        fTabGroupAxContext = NULL;
+    }
+
+    [super finalize];
+}
+
+- (id)accessibilityValueAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject axContext = [self axContextWithEnv:env];
+
+    // Returns the current selection of the page tab list
+    return [NSNumber numberWithBool:ObjectEquals(env, axContext, getAxContextSelection(env, [self tabGroup], fIndex, fComponent), fComponent)];
+}
+
+- (void)getActionsWithEnv:(JNIEnv *)env
+{
+    TabGroupAction *action = [[TabGroupAction alloc] initWithEnv:env withTabGroup:[self tabGroup] withIndex:fIndex withComponent:fComponent];
+    [fActions setObject:action forKey:NSAccessibilityPressAction];
+    [action release];
+}
+
+- (jobject)tabGroup
+{
+    if (fTabGroupAxContext == NULL) {
+        JNIEnv* env = [ThreadUtilities getJNIEnv];
+        jobject tabGroupAxContext = [(JavaComponentAccessibility *)[self parent] axContextWithEnv:env];
+        fTabGroupAxContext = JNFNewGlobalRef(env, tabGroupAxContext);
+    }
+    return fTabGroupAxContext;
+}
+
+@end
+
+
+@implementation ScrollAreaAccessibility
+
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env
+{
+    NSMutableArray *names = (NSMutableArray *)[super initializeAttributeNamesWithEnv:env];
+
+    [names addObject:NSAccessibilityHorizontalScrollBarAttribute];
+    [names addObject:NSAccessibilityVerticalScrollBarAttribute];
+    [names addObject:NSAccessibilityContentsAttribute];
+
+    return names;
+}
+
+- (id)accessibilityHorizontalScrollBarAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    NSArray *children = [JavaComponentAccessibility childrenOfParent:self withEnv:env withChildrenCode:JAVA_AX_ALL_CHILDREN allowIgnored:YES];
+    if ([children count] <= 0) return nil;
+
+    // The scroll bars are in the children.
+    JavaComponentAccessibility *aElement;
+    NSEnumerator *enumerator = [children objectEnumerator];
+    while ((aElement = (JavaComponentAccessibility *)[enumerator nextObject])) {
+        if ([[aElement accessibilityRoleAttribute] isEqualToString:NSAccessibilityScrollBarRole]) {
+            jobject elementAxContext = [aElement axContextWithEnv:env];
+            if (isHorizontal(env, elementAxContext, fComponent)) {
+                return aElement;
+            }
+        }
+    }
+
+    return nil;
+}
+
+- (BOOL)accessibilityIsHorizontalScrollBarAttributeSettable
+{
+    return NO;
+}
+
+- (id)accessibilityVerticalScrollBarAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    NSArray *children = [JavaComponentAccessibility childrenOfParent:self withEnv:env withChildrenCode:JAVA_AX_ALL_CHILDREN allowIgnored:YES];
+    if ([children count] <= 0) return nil;
+
+    // The scroll bars are in the children.
+    NSEnumerator *enumerator = [children objectEnumerator];
+    JavaComponentAccessibility *aElement;
+    while ((aElement = (JavaComponentAccessibility *)[enumerator nextObject])) {
+        if ([[aElement accessibilityRoleAttribute] isEqualToString:NSAccessibilityScrollBarRole]) {
+            jobject elementAxContext = [aElement axContextWithEnv:env];
+            if (isVertical(env, elementAxContext, fComponent)) {
+                return aElement;
+            }
+        }
+    }
+
+    return nil;
+}
+
+- (BOOL)accessibilityIsVerticalScrollBarAttributeSettable
+{
+    return NO;
+}
+
+- (NSArray *)accessibilityContentsAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    NSArray *children = [JavaComponentAccessibility childrenOfParent:self withEnv:env withChildrenCode:JAVA_AX_ALL_CHILDREN allowIgnored:YES];
+
+    if ([children count] <= 0) return nil;
+    NSArray *contents = [NSMutableArray arrayWithCapacity:[children count]];
+
+    // The scroll bars are in the children. children less the scroll bars is the contents
+    NSEnumerator *enumerator = [children objectEnumerator];
+    JavaComponentAccessibility *aElement;
+    while ((aElement = (JavaComponentAccessibility *)[enumerator nextObject])) {
+        if (![[aElement accessibilityRoleAttribute] isEqualToString:NSAccessibilityScrollBarRole]) {
+            // no scroll bars in contents
+            [(NSMutableArray *)contents addObject:aElement];
+        }
+    }
+
+    return contents;
+}
+
+- (BOOL)accessibilityIsContentsAttributeSettable
+{
+    return NO;
+}
+
+@end
+
+/*
+ * Returns Object.equals for the two items
+ * This may use LWCToolkit.invokeAndWait(); don't call while holding fLock
+ * and try to pass a component so the event happens on the correct thread.
+ */
+static JNF_CLASS_CACHE(sjc_Object, "java/lang/Object");
+static BOOL ObjectEquals(JNIEnv *env, jobject a, jobject b, jobject component)
+{
+    static JNF_MEMBER_CACHE(jm_equals, sjc_Object, "equals", "(Ljava/lang/Object;)Z");
+
+    if ((a == NULL) && (b == NULL)) return YES;
+    if ((a == NULL) || (b == NULL)) return NO;
+
+    if (pthread_main_np() != 0) {
+        // If we are on the AppKit thread
+        static JNF_CLASS_CACHE(sjc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit");
+        static JNF_STATIC_MEMBER_CACHE(jm_doEquals, sjc_LWCToolkit, "doEquals", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/awt/Component;)Z");
+        return JNFCallStaticBooleanMethod(env, jm_doEquals, a, b, component); // AWT_THREADING Safe (AWTRunLoopMode)
+    }
+
+    return JNFCallBooleanMethod(env, a, jm_equals, b); // AWT_THREADING Safe (!appKit)
+}
diff --git a/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.h b/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.h
new file mode 100644
index 0000000..b963273
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "JavaComponentAccessibility.h"
+
+#import <AppKit/NSAccessibility.h>
+
+
+@interface JavaTextAccessibility : JavaComponentAccessibility {
+
+}
+// attributes
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env;
+- (NSString *)accessibilityValueAttribute;
+- (BOOL)accessibilityIsValueAttributeSettable;
+- (void)accessibilitySetValueAttribute:(id)value;
+- (NSString *)accessibilitySelectedTextAttribute;
+- (BOOL)accessibilityIsSelectedTextAttributeSettable;
+- (NSValue *)accessibilitySelectedTextRangeAttribute;
+- (BOOL)accessibilityIsSelectedTextRangeAttributeSettable;
+- (NSNumber *)accessibilityNumberOfCharactersAttribute;
+- (BOOL)accessibilityIsNumberOfCharactersAttributeSettable;
+- (NSValue *)accessibilityVisibleCharacterRangeAttribute;
+- (BOOL)accessibilityIsVisibleCharacterRangeAttributeSettable;
+- (NSValue *)accessibilityInsertionPointLineNumberAttribute;
+- (BOOL)accessibilityIsInsertionPointLineNumberAttributeSettable;
+- (void)accessibilitySetSelectedTextAttribute:(id)value;
+- (NSValue *)accessibilitySelectedTextRangeAttribute;
+- (NSValue *)accessibilityInsertionPointLineNumberAttribute;
+- (BOOL)accessibilityIsInsertionPointLineNumberAttributeSettable;
+
+// parameterized attributes
+- (NSArray *)accessibilityParameterizedAttributeNames;
+- (NSValue *)accessibilityBoundsForRangeAttributeForParameter:(id)parameter;
+- (NSNumber *)accessibilityLineForIndexAttributeForParameter:(id)parameter;
+- (NSValue *)accessibilityRangeForLineAttributeForParameter:(id)parameter;
+- (NSString *)accessibilityStringForRangeAttributeForParameter:(id)parameter;
+- (NSValue *)accessibilityRangeForPositionAttributeForParameter:(id)parameter;
+- (NSValue *)accessibilityRangeForIndexAttributeForParameter:(id)parameter;
+
+// actions
+- (NSDictionary *)getActions:(JNIEnv *)env;
+@end
diff --git a/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.m b/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.m
new file mode 100644
index 0000000..7ab40b9
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.m
@@ -0,0 +1,414 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "JavaTextAccessibility.h"
+#import "JavaAccessibilityAction.h"
+#import "JavaAccessibilityUtilities.h"
+#import "ThreadUtilities.h"
+
+
+static JNF_CLASS_CACHE(sjc_CAccessibleText, "sun/lwawt/macosx/CAccessibleText");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleText, sjc_CAccessibility, "getAccessibleText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleText;");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleEditableText, sjc_CAccessibleText, "getAccessibleEditableText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleEditableText;");
+static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;");
+
+/*
+ * Converts an int array to an NSRange wrapped inside an NSValue
+ * takes [start, end] values and returns [start, end - start]
+ */
+NSValue *javaIntArrayToNSRangeValue(JNIEnv* env, jintArray array) {
+    jint *values = (*env)->GetIntArrayElements(env, array, 0);
+    NSValue *value = [NSValue valueWithRange:NSMakeRange(values[0], values[1] - values[0])];
+    (*env)->ReleaseIntArrayElements(env, array, values, 0);
+    return value;
+}
+
+@implementation JavaTextAccessibility
+
+// based strongly upon NSTextViewAccessibility:accessibilityAttributeNames
+- (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env
+{
+    static NSArray *attributes = nil;
+
+    if (attributes == nil) {
+        //APPKIT_LOCK;
+        if (attributes == nil) {
+            NSMutableArray *temp = [[super initializeAttributeNamesWithEnv:env] mutableCopy];
+            //[temp removeObject:NSAccessibilityTitleAttribute]; // title may have been set in the superclass implementation - some static text reports from java that it has a name
+            [temp addObjectsFromArray:[NSArray arrayWithObjects:
+                NSAccessibilityValueAttribute,
+                NSAccessibilitySelectedTextAttribute,
+                NSAccessibilitySelectedTextRangeAttribute,
+                NSAccessibilityNumberOfCharactersAttribute,
+                NSAccessibilityVisibleCharacterRangeAttribute,
+                NSAccessibilityInsertionPointLineNumberAttribute,
+                //    NSAccessibilitySharedTextUIElementsAttribute, // cmcnote: investigate what these two are for. currently unimplemented
+                //    NSAccessibilitySharedCharacterRangeAttribute,
+                nil]];
+            attributes = [[NSArray alloc] initWithArray:temp];
+            [temp release];
+        }
+        //APPKIT_UNLOCK;
+    }
+    return attributes;
+}
+
+// copied from NSTextViewAccessibility.
+- (NSArray *)accessibilityParameterizedAttributeNames
+{
+    static NSArray *attributes = nil;
+
+    if (attributes == nil) {
+        //APPKIT_LOCK;
+        if (attributes == nil) {
+            attributes = [[NSArray alloc] initWithObjects:
+                NSAccessibilityLineForIndexParameterizedAttribute,
+                NSAccessibilityRangeForLineParameterizedAttribute,
+                NSAccessibilityStringForRangeParameterizedAttribute,
+                NSAccessibilityRangeForPositionParameterizedAttribute,
+                NSAccessibilityRangeForIndexParameterizedAttribute,
+                NSAccessibilityBoundsForRangeParameterizedAttribute,
+                //NSAccessibilityRTFForRangeParameterizedAttribute, // cmcnote: not sure when/how these three are used. Investigate. radr://3960026
+                //NSAccessibilityStyleRangeForIndexParameterizedAttribute,
+                //NSAccessibilityAttributedStringForRangeParameterizedAttribute,
+                nil];
+        }
+        //APPKIT_UNLOCK;
+    }
+    return attributes;
+}
+
+- (NSString *)accessibilityValueAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    if ([[self accessibilityRoleAttribute] isEqualToString:NSAccessibilityStaticTextRole]) {
+        // if it's static text, the AppKit AXValue is the java accessibleName
+        jobject axName = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+        if (axName != NULL) {
+            return JNFJavaToNSString(env, axName);
+        }
+        // value is still nil if no accessibleName for static text. Below, try to get the accessibleText.
+    }
+
+    // cmcnote: inefficient to make three distinct JNI calls. Coalesce. radr://3951923
+    jobject axText = JNFCallStaticObjectMethod(env, sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (axText == NULL) return nil;
+
+    jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (axEditableText == NULL) return nil;
+
+    static JNF_STATIC_MEMBER_CACHE(jm_getTextRange, sjc_CAccessibleText, "getTextRange", "(Ljavax/accessibility/AccessibleEditableText;IILjava/awt/Component;)Ljava/lang/String;");
+    NSString *string = JNFJavaToNSString(env, JNFCallStaticObjectMethod(env, jm_getTextRange, axEditableText, 0, getAxTextCharCount(env, axEditableText, fComponent), fComponent)); // AWT_THREADING Safe (AWTRunLoop)
+    if (string == nil) string = @"";
+    return string;
+}
+
+- (BOOL)accessibilityIsValueAttributeSettable
+{
+    // if text is enabled and editable, it's settable (according to NSCellTextAttributesAccessibility)
+    BOOL isEnabled = [(NSNumber *)[self accessibilityEnabledAttribute] boolValue];
+    if (!isEnabled) return NO;
+
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (axEditableText == NULL) return NO;
+    return YES;
+}
+
+- (void)accessibilitySetValueAttribute:(id)value
+{
+// cmcnote: should set the accessibleEditableText to the stringValue of value - AccessibleEditableText.setTextContents(String s)
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"Not yet implemented: %s\n", __FUNCTION__); // radr://3954018
+#endif
+}
+
+// Currently selected text (NSString)
+- (NSString *)accessibilitySelectedTextAttribute
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getSelectedText, sjc_CAccessibleText, "getSelectedText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;");
+    jobject axText = JNFCallStaticObjectMethod(env, jm_getSelectedText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (axText == NULL) return @"";
+    return JNFJavaToNSString(env, axText);
+}
+
+- (BOOL)accessibilityIsSelectedTextAttributeSettable
+{
+    return YES; //cmcnote: for AXTextField that's selectable, it's settable. Investigate further.
+}
+
+- (void)accessibilitySetSelectedTextAttribute:(id)value
+{
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (![value isKindOfClass:[NSString class]]) {
+        JavaAccessibilityRaiseSetAttributeToIllegalTypeException(__FUNCTION__, self, NSAccessibilitySelectedTextAttribute, value);
+        return;
+    }
+#endif
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jstring jstringValue = JNFNSToJavaString(env, (NSString *)value);
+    static JNF_STATIC_MEMBER_CACHE(jm_setSelectedText, sjc_CAccessibleText, "setSelectedText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;Ljava/lang/String;)V");
+    JNFCallStaticVoidMethod(env, jm_setSelectedText, fAccessible, fComponent, jstringValue); // AWT_THREADING Safe (AWTRunLoop)
+}
+
+// Range of selected text (NSValue)
+- (NSValue *)accessibilitySelectedTextRangeAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getSelectedTextRange, sjc_CAccessibleText, "getSelectedTextRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I");
+    jintArray axTextRange = JNFCallStaticObjectMethod(env, jm_getSelectedTextRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (axTextRange == NULL) return nil;
+
+    return javaIntArrayToNSRangeValue(env, axTextRange);
+}
+
+- (BOOL)accessibilityIsSelectedTextRangeAttributeSettable
+{
+    return [(NSNumber *)[self accessibilityEnabledAttribute] boolValue]; // cmcnote: also may want to find out if isSelectable. Investigate.
+}
+
+- (void)accessibilitySetSelectedTextRangeAttribute:(id)value
+{
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (!([value isKindOfClass:[NSValue class]] && strcmp([(NSValue *)value objCType], @encode(NSRange)) == 0)) {
+        JavaAccessibilityRaiseSetAttributeToIllegalTypeException(__FUNCTION__, self, NSAccessibilitySelectedTextRangeAttribute, value);
+        return;
+    }
+#endif
+
+    NSRange range = [(NSValue *)value rangeValue];
+    jint startIndex = range.location;
+    jint endIndex = startIndex + range.length;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_setSelectedTextRange, sjc_CAccessibleText, "setSelectedTextRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)V");
+    JNFCallStaticVoidMethod(env, jm_setSelectedTextRange, fAccessible, fComponent, startIndex, endIndex); // AWT_THREADING Safe (AWTRunLoop)
+}
+
+- (NSNumber *)accessibilityNumberOfCharactersAttribute
+{
+    // cmcnote: should coalesce these two calls - radr://3951923
+    // also, static text doesn't always have accessibleText. if axText is null, should get the charcount of the accessibleName instead
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject axText = JNFCallStaticObjectMethod(env, sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    return [NSNumber numberWithInt:getAxTextCharCount(env, axText, fComponent)];
+}
+
+- (BOOL)accessibilityIsNumberOfCharactersAttributeSettable
+{
+    return NO; // according to NSTextViewAccessibility.m and NSCellTextAttributesAccessibility.m
+}
+
+- (NSValue *)accessibilityVisibleCharacterRangeAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getVisibleCharacterRange, sjc_CAccessibleText, "getVisibleCharacterRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I");
+    jintArray axTextRange = JNFCallStaticObjectMethod(env, jm_getVisibleCharacterRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (axTextRange == NULL) return nil;
+
+    return javaIntArrayToNSRangeValue(env, axTextRange);
+}
+
+- (BOOL)accessibilityIsVisibleCharacterRangeAttributeSettable
+{
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"Not yet implemented: %s\n", __FUNCTION__);
+#endif
+    return NO;
+}
+
+- (NSValue *)accessibilityInsertionPointLineNumberAttribute
+{
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getLineNumberForInsertionPoint, sjc_CAccessibleText, "getLineNumberForInsertionPoint", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)I");
+    jint row = JNFCallStaticIntMethod(env, jm_getLineNumberForInsertionPoint, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
+    if (row < 0) return nil;
+    return [NSNumber numberWithInt:row];
+}
+
+- (BOOL)accessibilityIsInsertionPointLineNumberAttributeSettable
+{
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"Not yet implemented: %s\n", __FUNCTION__);
+#endif
+    return NO;
+}
+
+// parameterized attributes
+
+//
+// Usage of accessibilityBoundsForRangeAttributeForParameter:
+// ---
+// called by VoiceOver when interacting with text via ctrl-option-shift-downArrow.
+// Need to know bounding box for the character / word / line of interest in
+// order to draw VoiceOver cursor
+//
+- (NSValue *)accessibilityBoundsForRangeAttributeForParameter:(id)parameter
+{
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (!([parameter isKindOfClass:[NSValue class]] && strcmp([(NSValue *)parameter objCType], @encode(NSRange)) == 0)) {
+        JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityBoundsForRangeParameterizedAttribute, parameter);
+        return nil;
+    }
+#endif
+
+    NSRange range = [(NSValue *)parameter rangeValue];
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getBoundsForRange, sjc_CAccessibleText, "getBoundsForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)[D");
+    jdoubleArray axBounds = JNFCallStaticObjectMethod(env, jm_getBoundsForRange, fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop)
+    if (axBounds == NULL) return nil;
+
+    // We cheat because we know that the array is 4 elements long (x, y, width, height)
+    jdouble *values = (*env)->GetDoubleArrayElements(env, axBounds, 0);
+    NSRect bounds;
+    bounds.origin.x = values[0];
+    bounds.origin.y = [[[[self view] window] screen] frame].size.height - values[1] - values[3]; //values[1] is y-coord from top-left of screen. Flip. Account for the height (values[3]) when flipping
+    bounds.size.width = values[2];
+    bounds.size.height = values[3];
+    NSValue *result = [NSValue valueWithRect:bounds];
+    (*env)->ReleaseDoubleArrayElements(env, axBounds, values, 0);
+    return result;
+}
+
+- (NSNumber *)accessibilityLineForIndexAttributeForParameter:(id)parameter
+{
+    NSNumber *line = (NSNumber *) parameter;
+    if (line == nil) return nil;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getLineNumberForIndex, sjc_CAccessibleText, "getLineNumberForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)I");
+    jint row = JNFCallStaticIntMethod(env, jm_getLineNumberForIndex, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop)
+    if (row < 0) return nil;
+    return [NSNumber numberWithInt:row];
+}
+
+- (NSValue *)accessibilityRangeForLineAttributeForParameter:(id)parameter
+{
+    NSNumber *line = (NSNumber *) parameter;
+    if (line == nil) return nil;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getRangeForLine, sjc_CAccessibleText, "getRangeForLine", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I");
+    jintArray axTextRange = JNFCallStaticObjectMethod(env, jm_getRangeForLine, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop)
+    if (axTextRange == NULL) return nil;
+
+    return javaIntArrayToNSRangeValue(env,axTextRange);
+}
+
+//
+// Usage of accessibilityStringForRangeAttributeForParameter:
+// ---
+// called by VoiceOver when interacting with text via ctrl-option-shift-downArrow.
+// VO needs to know the particular string its currently dealing with so it can
+// speak the string
+//
+- (NSString *)accessibilityStringForRangeAttributeForParameter:(id)parameter
+{
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (!([parameter isKindOfClass:[NSValue class]] && strcmp([(NSValue *)parameter objCType], @encode(NSRange)) == 0)) {
+        JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityBoundsForRangeParameterizedAttribute, parameter);
+        return nil;
+    }
+#endif
+
+    NSRange range = [(NSValue *)parameter rangeValue];
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getStringForRange, sjc_CAccessibleText, "getStringForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)Ljava/lang/String;");
+    jstring jstringForRange = JNFCallStaticObjectMethod(env, jm_getStringForRange, fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop)
+
+    if (jstringForRange == NULL) return @"";
+    return JNFJavaToNSString(env, jstringForRange);
+}
+
+//
+// Usage of accessibilityRangeForPositionAttributeForParameter:
+// ---
+// cmcnote: I'm not sure when this is called / how it's used. Investigate.
+// probably could be used in a special text-only accessibilityHitTest to
+// find the index of the string under the mouse?
+//
+- (NSValue *)accessibilityRangeForPositionAttributeForParameter:(id)parameter
+{
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (!([parameter isKindOfClass:[NSValue class]] && strcmp([(NSValue *)parameter objCType], @encode(NSPoint)) == 0)) {
+        JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityRangeForPositionParameterizedAttribute, parameter);
+        return nil;
+    }
+#endif
+
+    NSPoint point = [(NSValue *)parameter pointValue]; // point is in screen coords
+    point.y = [[[[self view] window] screen] frame].size.height - point.y; // flip into java screen coords (0 is at upper-left corner of screen)
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getCharacterIndexAtPosition, sjc_CAccessibleText, "getCharacterIndexAtPosition", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)I");
+    jint charIndex = JNFCallStaticIntMethod(env, jm_getCharacterIndexAtPosition, fAccessible, fComponent, point.x, point.y); // AWT_THREADING Safe (AWTRunLoop)
+    if (charIndex == -1) return nil;
+
+    // AccessibleText.getIndexAtPoint returns -1 for an invalid point
+    NSRange range = NSMakeRange(charIndex, 1); //range's length is 1 - one-character range
+    return [NSValue valueWithRange:range];
+}
+
+//
+// Usage of accessibilityRangeForIndexAttributeForParameter:
+// ---
+// cmcnote: I'm not sure when this is called / how it's used. Investigate.
+// AppKit version calls: [string rangeOfComposedCharacterSequenceAtIndex:index]
+// We call: CAccessibility.getRangeForIndex, which calls AccessibleText.getAtIndex(AccessibleText.WORD, index)
+// to determine the word closest to the given index. Then we find the length/location of this string.
+//
+- (NSValue *)accessibilityRangeForIndexAttributeForParameter:(id)parameter
+{
+#ifdef JAVA_AX_DEBUG_PARMS
+    if (![parameter isKindOfClass:[NSNumber class]]) {
+        JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityRangeForIndexParameterizedAttribute, parameter);
+        return nil;
+    }
+#endif
+
+    NSUInteger index = [(NSNumber *)parameter unsignedIntegerValue];
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_STATIC_MEMBER_CACHE(jm_getRangeForIndex, sjc_CAccessibleText, "getRangeForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I");
+    jintArray axTextRange = JNFCallStaticObjectMethod(env, jm_getRangeForIndex, fAccessible, fComponent, index); // AWT_THREADING Safe (AWTRunLoop)
+    if (axTextRange == NULL) return nil;
+
+    return javaIntArrayToNSRangeValue(env, axTextRange);
+}
+
+- (NSDictionary *)getActions:(JNIEnv *)env {
+    // cmcnote: this isn't correct; text can have actions. Not yet implemented. radr://3941691
+    // Editable text has AXShowMenu. Textfields have AXConfirm. Static text has no actions.
+#ifdef JAVA_AX_DEBUG
+    NSLog(@"Not yet implemented: %s\n", __FUNCTION__);
+#endif
+    return nil;
+}
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/LWCToolkit.h b/jdk/src/macosx/native/sun/awt/LWCToolkit.h
new file mode 100644
index 0000000..5bc1d9c
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <pthread.h>
+#import <assert.h>
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <CoreServices/CoreServices.h>
+#import <AudioToolbox/AudioToolbox.h>
+
+#define DEBUG 1
+
+
+@interface AWTToolkit : NSObject { }
++ (long) getEventCount;
++ (void) eventCountPlusPlus;
+@end
+
+CGDirectDisplayID FindCGDirectDisplayIDForScreenIndex(jint screenIndex);
+
+/*
+ * Utility Macros
+ */
+
+/** Macro to cast a jlong to an Objective-C object (id). Casts to long on 32-bit systems to quiesce the compiler. */
+#define OBJC(jl) ((id)jlong_to_ptr(jl))
diff --git a/jdk/src/macosx/native/sun/awt/LWCToolkit.m b/jdk/src/macosx/native/sun/awt/LWCToolkit.m
new file mode 100644
index 0000000..78a890d
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <dlfcn.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CMenuBar.h"
+#import "InitIDs.h"
+#import "LWCToolkit.h"
+#import "ThreadUtilities.h"
+#import "AWT_debug.h"
+#import "CSystemColors.h"
+
+#import "sun_lwawt_macosx_LWCToolkit.h"
+
+
+@implementation AWTToolkit
+
+static long eventCount;
+
++ (long) getEventCount{
+    return eventCount;
+}
+
++ (void) eventCountPlusPlus{
+    eventCount++;
+}
+
+@end
+
+
+@interface AWTRunLoopObject : NSObject {
+    BOOL _shouldEndRunLoop;
+}
+@end
+
+@implementation AWTRunLoopObject
+
+- (id) init {
+    self = [super init];
+    if (self != nil) {
+        _shouldEndRunLoop = NO;
+    }
+    return self;
+}
+
+- (BOOL) shouldEndRunLoop {
+    return _shouldEndRunLoop;
+}
+
+- (void) endRunLoop {
+    _shouldEndRunLoop = YES;
+}
+
+@end
+
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    nativeSyncQueue
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue
+(JNIEnv *env, jobject self, jlong timeout)
+{
+    int currentEventNum = [AWTToolkit getEventCount];
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){}];
+
+    if (([AWTToolkit getEventCount] - currentEventNum) != 0) {
+        return JNI_TRUE;
+    }
+
+    return JNI_FALSE;
+}
+
+
+static JNF_CLASS_CACHE(jc_Component, "java/awt/Component");
+static JNF_MEMBER_CACHE(jf_Component_appContext, jc_Component, "appContext", "Lsun/awt/AppContext;");
+static JNF_CLASS_CACHE(jc_MenuComponent, "java/awt/MenuComponent");
+static JNF_MEMBER_CACHE(jf_MenuComponent_appContext, jc_MenuComponent, "appContext", "Lsun/awt/AppContext;");
+
+/*
+ * Class:     sun_awt_SunToolkit
+ * Method:    getAppContext
+ * Signature: (Ljava/awt/Object;)Lsun/awt/AppContext;
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_awt_SunToolkit_getAppContext
+(JNIEnv *env, jclass cls, jobject obj)
+{
+    jobject appContext = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    if (JNFIsInstanceOf(env, obj, &jc_Component)) {
+        appContext = JNFGetObjectField(env, obj, jf_Component_appContext);
+    } else if (JNFIsInstanceOf(env, obj, &jc_MenuComponent)) {
+        appContext = JNFGetObjectField(env, obj, jf_MenuComponent_appContext);
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return appContext;
+}
+
+/*
+ * Class:     sun_awt_SunToolkit
+ * Method:    setAppContext
+ * Signature: (Ljava/lang/Object;Lsun/awt/AppContext;)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_sun_awt_SunToolkit_setAppContext
+(JNIEnv *env, jclass cls, jobject obj, jobject appContext)
+{
+    jboolean isComponent;
+
+JNF_COCOA_ENTER(env);
+
+    if (JNFIsInstanceOf(env, obj, &jc_Component)) {
+        JNFSetObjectField(env, obj, jf_Component_appContext, appContext);
+        isComponent = JNI_TRUE;
+    } else if (JNFIsInstanceOf(env, obj, &jc_MenuComponent)) {
+        JNFSetObjectField(env, obj, jf_MenuComponent_appContext, appContext);
+        isComponent = JNI_FALSE;
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return isComponent;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    beep
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_LWCToolkit_beep
+(JNIEnv *env, jobject self)
+{
+    NSBeep(); // produces both sound and visual flash, if configured in System Preferences
+}
+
+CGDirectDisplayID
+FindCGDirectDisplayIDForScreenIndex(jint screenIndex)
+{
+    // most common case - just one monitor
+    CGDirectDisplayID screenID = CGMainDisplayID();
+
+    CGDisplayCount displayCount = 0;
+    CGGetOnlineDisplayList(0, NULL, &displayCount);
+
+    if ((displayCount > 1) &&
+        (screenIndex >= 0) &&
+        (screenIndex < (jint)displayCount))
+    {
+        if (displayCount < 10) {
+            // stack allocated optimization for less than 10 monitors
+            CGDirectDisplayID onlineDisplays[displayCount];
+            CGGetOnlineDisplayList(displayCount, onlineDisplays, &displayCount);
+            screenID = (CGDirectDisplayID)onlineDisplays[screenIndex];
+        } else {
+            CGDirectDisplayID *onlineDisplays =
+            malloc(displayCount*sizeof(CGDirectDisplayID));
+            if (onlineDisplays != NULL) {
+                CGGetOnlineDisplayList(displayCount, onlineDisplays,
+                                       &displayCount);
+                screenID = (CGDirectDisplayID)onlineDisplays[screenIndex];
+                free(onlineDisplays);
+            }
+        }
+    }
+
+    return screenID;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    initIDs
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_LWCToolkit_initIDs
+(JNIEnv *env, jclass klass) {
+    // set thread names
+    dispatch_async(dispatch_get_main_queue(), ^(void){
+        [[NSThread currentThread] setName:@"AppKit Thread"];
+
+        JNIEnv *env = [ThreadUtilities getJNIEnv];
+        static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit");
+        static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadNameInJava, jc_LWCToolkit, "installToolkitThreadNameInJava", "()V");
+        JNFCallStaticVoidMethod(env, jsm_installToolkitThreadNameInJava);
+    });
+}
+
+static UInt32 RGB(NSColor *c) {
+    c = [c colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
+    if (c == nil)
+    {
+        return -1; // opaque white
+    }
+
+    CGFloat r, g, b, a;
+    [c getRed:&r green:&g blue:&b alpha:&a];
+
+    UInt32 ir = (UInt32) (r*255+0.5),
+    ig = (UInt32) (g*255+0.5),
+    ib = (UInt32) (b*255+0.5),
+    ia = (UInt32) (a*255+0.5);
+
+    //    NSLog(@"%@ %d, %d, %d", c, ir, ig, ib);
+
+    return ((ia & 0xFF) << 24) | ((ir & 0xFF) << 16) | ((ig & 0xFF) << 8) | ((ib & 0xFF) << 0);
+}
+
+void doLoadNativeColors(JNIEnv *env, jintArray jColors, BOOL useAppleColors) {
+    jint len = (*env)->GetArrayLength(env, jColors);
+
+    UInt32 colorsArray[len];
+    UInt32 *colors = colorsArray;
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        NSUInteger i;
+        for (i = 0; i < len; i++) {
+            colors[i] = RGB([CSystemColors getColor:i useAppleColor:useAppleColors]);
+        }
+    }];
+
+    jint *_colors = (*env)->GetPrimitiveArrayCritical(env, jColors, 0);
+    memcpy(_colors, colors, len * sizeof(UInt32));
+    (*env)->ReleasePrimitiveArrayCritical(env, jColors, _colors, 0);
+}
+
+/**
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    loadNativeColors
+ * Signature: ([I[I)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_loadNativeColors
+(JNIEnv *env, jobject peer, jintArray jSystemColors, jintArray jAppleColors)
+{
+JNF_COCOA_ENTER(env);
+    doLoadNativeColors(env, jSystemColors, NO);
+    doLoadNativeColors(env, jAppleColors, YES);
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    createAWTRunLoopMediator
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_LWCToolkit_createAWTRunLoopMediator
+(JNIEnv *env, jclass clz)
+{
+AWT_ASSERT_APPKIT_THREAD;
+
+    AWTRunLoopObject *o = nil;
+
+    // We double retain because this object is owned by both main thread and "other" thread
+    // We release in both doAWTRunLoop and stopAWTRunLoop
+    o = [[AWTRunLoopObject alloc] init];
+    if (o) {
+        CFRetain(o); // GC
+        CFRetain(o); // GC
+        [o release];
+    }
+    return ptr_to_jlong(o);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    doAWTRunLoop
+ * Signature: (JZZ)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoop
+(JNIEnv *env, jclass clz, jlong mediator, jboolean awtMode, jboolean detectDeadlocks)
+{
+AWT_ASSERT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
+
+    if (mediatorObject == nil) return;
+
+    if (!sInPerformFromJava || !detectDeadlocks) {
+
+        NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
+        NSDate *distantFuture = [NSDate distantFuture];
+        NSString *mode = (awtMode) ? [JNFRunLoop javaRunLoopMode] : NSDefaultRunLoopMode;
+
+        BOOL isRunning = YES;
+        while (isRunning && ![mediatorObject shouldEndRunLoop]) {
+            // Don't use acceptInputForMode because that doesn't setup autorelease pools properly
+            isRunning = [currentRunLoop runMode:mode beforeDate:distantFuture];
+        }
+
+    }
+#ifndef PRODUCT_BUILD
+    if (sInPerformFromJava) {
+        NSLog(@"Apple AWT: Short-circuiting CToolkit.invokeAndWait trampoline deadlock!!!!!");
+        NSLog(@"\tPlease file a bug report with this message and a reproducible test case.");
+    }
+#endif
+
+    CFRelease(mediatorObject);
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    stopAWTRunLoop
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopAWTRunLoop
+(JNIEnv *env, jclass clz, jlong mediator)
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+    AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
+
+    [ThreadUtilities performOnMainThread:@selector(endRunLoop) onObject:mediatorObject withObject:nil waitUntilDone:NO awtMode:YES];
+
+    CFRelease(mediatorObject);
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_awt_SunToolkit
+ * Method:    closeSplashScreen
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls)
+{
+    void *hSplashLib = dlopen(0, RTLD_LAZY);
+    if (!hSplashLib) return;
+
+    void (*splashClose)() = dlsym(hSplashLib, "SplashClose");
+    if (splashClose) {
+        splashClose();
+    }
+    dlclose(hSplashLib);
+}
+
+
+// TODO: definitely doesn't belong here (copied from fontpath.c in the
+// solaris tree)...
+
+JNIEXPORT jstring JNICALL
+Java_sun_font_FontManager_getFontPath
+(JNIEnv *env, jclass obj, jboolean noType1)
+{
+    return JNFNSToJavaString(env, @"/Library/Fonts");
+}
+
+// This isn't yet used on unix, the implementation is added since shared
+// code calls this method in preparation for future use.
+JNIEXPORT void JNICALL
+Java_sun_font_FontManager_populateFontFileNameMap
+(JNIEnv *env, jclass obj, jobject fontToFileMap, jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
+{
+
+}
diff --git a/jdk/src/macosx/native/sun/awt/OSVersion.h b/jdk/src/macosx/native/sun/awt/OSVersion.h
new file mode 100644
index 0000000..c0ec047
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/OSVersion.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// Support for detecting Mac OS X versions
+
+double getOSXMajorVersion();
+BOOL isSnowLeopardOrLower();
diff --git a/jdk/src/macosx/native/sun/awt/OSVersion.m b/jdk/src/macosx/native/sun/awt/OSVersion.m
new file mode 100644
index 0000000..10fe713
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/OSVersion.m
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// Support for detecting Mac OS X Versions
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+
+// returns 10.7 for Lion, 10.6 for SnowLeopard etc.
+double getOSXMajorVersion() {
+    char *version = JRSCopyOSVersion();
+
+    if (version == NULL) return 0.0;
+
+    char temp[32];
+    strlcpy(temp, version, sizeof(temp));
+    free(version);
+
+    if (strlen(temp) < 3) {
+        return 0.0;
+    }
+
+    if (temp[2] != '.')  { // Third char must be a '.'
+        return 0.0;
+    }
+
+    char *ptr = strchr(temp+3, '.'); // remove the second . if one exists.
+    if (ptr != NULL) {
+        *ptr = 0;
+    }
+
+    return atof(temp);
+}
+
+
+BOOL isSnowLeopardOrLower() {
+    return (getOSXMajorVersion() < 10.7);
+}
diff --git a/jdk/src/macosx/native/sun/awt/PrintModel.h b/jdk/src/macosx/native/sun/awt/PrintModel.h
new file mode 100644
index 0000000..3648f15
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/PrintModel.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+#import <Foundation/Foundation.h>
+#import <jni.h>
+
+@class NSPrintInfo;
+@class NSView;
+
+@interface PrintModel : NSObject {
+    NSPrintInfo* fPrintInfo;
+}
+
+- (id)initWithPrintInfo:(NSPrintInfo*)printInfo;
+- (BOOL)runPageSetup;
+- (BOOL)runJobSetup;
+- (BOOL)runPrintLoopWithView:(NSView*)printerView waitUntilDone:(BOOL)wait withEnv:(JNIEnv *)env;
+- (BOOL)safePrintLoop:(id)arg withEnv:(JNIEnv *)env;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/PrintModel.m b/jdk/src/macosx/native/sun/awt/PrintModel.m
new file mode 100644
index 0000000..b9dafc1
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/PrintModel.m
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+#import "PrintModel.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "PrinterView.h"
+#import "ThreadUtilities.h"
+
+@implementation PrintModel
+
+- (id)initWithPrintInfo:(NSPrintInfo*)printInfo {
+    self = [super init];
+    if (self) {
+        fPrintInfo = [printInfo retain];
+    }
+
+    return self;
+}
+
+- (void)dealloc {
+    [fPrintInfo release];
+    fPrintInfo = nil;
+
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+- (BOOL)runPageSetup {
+    __block BOOL fResult = NO;
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        NSPageLayout* pageLayout = [NSPageLayout pageLayout];
+        fResult = ([pageLayout runModalWithPrintInfo:fPrintInfo] == NSOKButton);
+    }];
+
+    return fResult;
+}
+
+- (BOOL)runJobSetup {
+    __block BOOL fResult = NO;
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        NSPrintPanel* printPanel = [NSPrintPanel printPanel];
+        fResult = ([printPanel runModalWithPrintInfo:fPrintInfo] == NSOKButton);
+    }];
+
+    return fResult;
+}
+
+- (BOOL)runPrintLoopWithView:(NSView*)printerView waitUntilDone:(BOOL)wait withEnv:(JNIEnv *)env
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    BOOL fResult = NO;
+
+    // <rdar://problem/4310184> Because people like to put up modal dialogs during print operations,
+    // we have to run the print operation on a non-AppKit thread or else we get a deadlock and errors
+    // the AppKit team believes it's OK for us to call runOperation from non-AppKit threads,
+    // as long as we don't show any panels, and we don't touch the NSPrintInfo or the NSView from other threads.
+    if (wait) {
+        fResult = [self safePrintLoop:printerView withEnv:env];
+    } else {
+        // Retain these so they don't go away while we're in Java
+        CFRetain(self); // GC
+        if (printerView) CFRetain(printerView); // GC
+
+        static JNF_CLASS_CACHE(jc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob");
+        static JNF_STATIC_MEMBER_CACHE(jm_detachPrintLoop, jc_CPrinterJob, "detachPrintLoop", "(JJ)V");
+        JNFCallStaticVoidMethod(env, jm_detachPrintLoop, ptr_to_jlong(self), ptr_to_jlong(printerView)); // AWT_THREADING Safe (known object)
+    }
+
+    return fResult;
+}
+
+- (BOOL) safePrintLoop:(id)arg withEnv:(JNIEnv *)env
+{
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    PrinterView* printerView = (PrinterView*)arg;
+    BOOL fResult;
+    @try {
+        NSPrintOperation* printLoop = [NSPrintOperation printOperationWithView:printerView printInfo:fPrintInfo];
+        [printLoop setShowPanels:NO];    //+++gdb Problem: This will avoid progress bars...
+        //[printLoop setCanSpawnSeparateThread:YES]; //+++gdb Need to check this...
+
+        fResult = [printLoop runOperation];
+    } @finally {
+        // Tell CPrinterJob that things are done.
+        [printerView complete:env];
+    }
+    return fResult;
+}
+
+@end
+
+/*
+ * Class:     sun_lwawt_macosx_CPrinterJob
+ * Method:    _safePrintLoop
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob__1safePrintLoop
+(JNIEnv *env, jclass clz, jlong target, jlong view)
+{
+JNF_COCOA_ENTER(env);
+
+    PrintModel *model = (PrintModel *)jlong_to_ptr(target);
+    PrinterView *arg = (PrinterView *)jlong_to_ptr(view);
+
+    [model safePrintLoop:arg withEnv:env];
+
+    // These are to match the retains in runPrintLoopWithView:
+    if (model) CFRelease(model); // GC
+    if (arg) CFRelease(arg); // GC
+
+JNF_COCOA_EXIT(env);
+}
+
diff --git a/jdk/src/macosx/native/sun/awt/PrinterSurfaceData.h b/jdk/src/macosx/native/sun/awt/PrinterSurfaceData.h
new file mode 100644
index 0000000..7f77f20
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/PrinterSurfaceData.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "QuartzSurfaceData.h"
+
+struct _PrintSDOps
+{
+    QuartzSDOps                qsdo; // must be the first entry!
+
+    NSGraphicsContext        *nsRef;
+
+    jint                    width;
+    jint                    height;
+};
+typedef struct _PrintSDOps PrintSDOps;
diff --git a/jdk/src/macosx/native/sun/awt/PrinterSurfaceData.m b/jdk/src/macosx/native/sun/awt/PrinterSurfaceData.m
new file mode 100644
index 0000000..4c02c71
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/PrinterSurfaceData.m
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+#import "PrinterSurfaceData.h"
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+//#define DEBUG 1
+#if defined DEBUG
+    #define PRINT(msg) {fprintf(stderr, "%s\n", msg);}
+#else
+    #define PRINT(msg) {}
+#endif
+
+static LockFunc PrintSD_Lock;
+static UnlockFunc PrintSD_Unlock;
+static GetRasInfoFunc PrintSD_GetRasInfo;
+static ReleaseFunc PrintSD_ReleaseRasInfo;
+static void flush(JNIEnv *env, QuartzSDOps *qsdo);
+
+static void PrintSD_startCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType)
+{
+PRINT(" PrintSD_startCGContext")
+
+    if (qsdo->cgRef != NULL)
+    {
+        flush(env, qsdo);
+
+        SetUpCGContext(env, qsdo, renderType);
+    }
+}
+
+static void PrintSD_finishCGContext(JNIEnv *env, QuartzSDOps *qsdo)
+{
+PRINT("    PrintSD_finishCGContext")
+
+    if (qsdo->cgRef != NULL)
+    {
+        CompleteCGContext(env, qsdo);
+    }
+}
+
+static void PrintSD_dispose(JNIEnv *env, SurfaceDataOps *sdo)
+{
+PRINT(" PrintSD_dispose")
+    QuartzSDOps *qsdo = (QuartzSDOps *)sdo;
+
+    (*env)->DeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects);
+
+    if (qsdo->graphicsStateInfo.batchedLines != NULL)
+    {
+        free(qsdo->graphicsStateInfo.batchedLines);
+        qsdo->graphicsStateInfo.batchedLines = NULL;
+    }
+
+    qsdo->BeginSurface            = NULL;
+    qsdo->FinishSurface            = NULL;
+}
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterSurfaceData_initOps(JNIEnv *env, jobject jthis, jlong nsRef, jobject jGraphicsState, jobjectArray jGraphicsStateObject, jint width, jint height)
+{
+JNF_COCOA_ENTER(env);
+
+PRINT("Java_sun_lwawt_macosx_CPrinterSurfaceData_initOps")
+
+    PrintSDOps *psdo = (PrintSDOps*)SurfaceData_InitOps(env, jthis, sizeof(PrintSDOps));
+    psdo->nsRef            = (NSGraphicsContext*)jlong_to_ptr(nsRef);
+    psdo->width            = width;
+    psdo->height        = height;
+
+    QuartzSDOps *qsdo = (QuartzSDOps*)psdo;
+    qsdo->BeginSurface            = PrintSD_startCGContext;
+    qsdo->FinishSurface            = PrintSD_finishCGContext;
+    qsdo->cgRef                    = [psdo->nsRef graphicsPort];
+
+    qsdo->javaGraphicsStates            = (jint*)((*env)->GetDirectBufferAddress(env, jGraphicsState));
+    qsdo->javaGraphicsStatesObjects        = (*env)->NewGlobalRef(env, jGraphicsStateObject);
+
+    qsdo->graphicsStateInfo.batchedLines        = NULL;
+    qsdo->graphicsStateInfo.batchedLinesCount    = 0;
+
+    SurfaceDataOps *sdo = (SurfaceDataOps*)qsdo;
+    sdo->Lock        = PrintSD_Lock;
+    sdo->Unlock        = PrintSD_Unlock;
+    sdo->GetRasInfo    = PrintSD_GetRasInfo;
+    sdo->Release    = PrintSD_ReleaseRasInfo;
+    sdo->Setup        = NULL;
+    sdo->Dispose    = PrintSD_dispose;
+
+JNF_COCOA_EXIT(env);
+}
+
+static jint PrintSD_Lock(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo, jint lockflags)
+{
+PRINT(" PrintSD_Lock")
+    jint status = SD_FAILURE;
+
+    //QuartzSDOps *qsdo = (QuartzSDOps*)sdo;
+    //PrintSD_startCGContext(env, qsdo, SD_Image);
+
+    status = SD_SUCCESS;
+
+    return status;
+}
+static void PrintSD_Unlock(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo)
+{
+PRINT(" PrintSD_Unlock")
+
+    //QuartzSDOps *qsdo = (QuartzSDOps*)sdo;
+    //PrintSD_finishCGContext(env, qsdo);
+}
+static void PrintSD_GetRasInfo(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo)
+{
+PRINT(" PrintSD_GetRasInfo")
+    PrintSDOps *psdo = (PrintSDOps*)sdo;
+
+    pRasInfo->pixelStride = 4; // ARGB
+    pRasInfo->scanStride = psdo->width * pRasInfo->pixelStride;
+
+    pRasInfo->rasBase = NULL; //psdo->dataForSun2D;
+}
+static void PrintSD_ReleaseRasInfo(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo)
+{
+PRINT(" PrintSD_ReleaseRasInfo")
+
+    pRasInfo->pixelStride = 0;
+    pRasInfo->scanStride = 0;
+    pRasInfo->rasBase = NULL;
+}
+
+static void dataProvider_FreeSun2DPixels(void *info, const void *data, size_t size)
+{
+PRINT("dataProvider_FreeSun2DPixels")
+   // CGBitmapFreeData(info);
+    free(info);
+}
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterSurfaceData__1flush
+  (JNIEnv *env, jobject jsurfacedata)
+{
+    flush(env, (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata));
+}
+static void flush(JNIEnv *env, QuartzSDOps *qsdo)
+{
+}
diff --git a/jdk/src/macosx/native/sun/awt/PrinterView.h b/jdk/src/macosx/native/sun/awt/PrinterView.h
new file mode 100644
index 0000000..f3f1fbe
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/PrinterView.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <jni.h>
+
+@interface PrinterView : NSView {
+    jobject fPrinterJob; // CPrinterJob
+    jobject fCurPageFormat;
+    jobject fCurPainter;
+    jobject fCurPeekGraphics;
+
+    jint fFirstPage, fLastPage;
+}
+
+- (id)initWithFrame:(NSRect)aRect withEnv:(JNIEnv*)env withPrinterJob:(jobject)printerJob;
+
+- (void)setFirstPage:(jint)firstPage lastPage:(jint)lastPage;
+
+- (void)releaseReferences:(JNIEnv*)env;
+
+- (void)drawRect:(NSRect)aRect;
+
+- (NSString*)printJobTitle;
+- (BOOL)knowsPageRange:(NSRangePointer)aRange;
+- (NSRect)rectForPage:(NSInteger)pageNumber;
+
+- (BOOL)cancelCheck:(JNIEnv*)env;
+
+- (void)complete:(JNIEnv*)env;
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/PrinterView.m b/jdk/src/macosx/native/sun/awt/PrinterView.m
new file mode 100644
index 0000000..84ddd0b
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/PrinterView.m
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "PrinterView.h"
+
+#import "java_awt_print_Pageable.h"
+#import "java_awt_print_Printable.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "ThreadUtilities.h"
+#import "GeomUtilities.h"
+
+
+static JNF_CLASS_CACHE(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob");
+
+@implementation PrinterView
+
+- (id)initWithFrame:(NSRect)aRect withEnv:(JNIEnv*)env withPrinterJob:(jobject)printerJob
+{
+    self = [super initWithFrame:aRect];
+    if (self)
+    {
+        fPrinterJob = JNFNewGlobalRef(env, printerJob);
+        fCurPageFormat = NULL;
+        fCurPainter = NULL;
+        fCurPeekGraphics = NULL;
+    }
+    return self;
+}
+
+- (void)releaseReferences:(JNIEnv*)env
+{
+    if (fCurPageFormat != NULL)
+    {
+        JNFDeleteGlobalRef(env, fCurPageFormat);
+        fCurPageFormat = NULL;
+    }
+    if (fCurPainter != NULL)
+    {
+        JNFDeleteGlobalRef(env, fCurPainter);
+        fCurPainter = NULL;
+    }
+    if (fCurPeekGraphics != NULL)
+    {
+        JNFDeleteGlobalRef(env, fCurPeekGraphics);
+        fCurPeekGraphics = NULL;
+    }
+}
+
+- (void)setFirstPage:(jint)firstPage lastPage:(jint)lastPage {
+    fFirstPage = firstPage;
+    fLastPage = lastPage;
+}
+
+- (void)drawRect:(NSRect)aRect
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_printToPathGraphics, sjc_CPrinterJob, "printToPathGraphics", "(Lsun/print/PeekGraphics;Ljava/awt/print/PrinterJob;Ljava/awt/print/Printable;Ljava/awt/print/PageFormat;IJ)V");
+
+    // Create and draw into a new CPrinterGraphics with the current Context.
+    assert(fCurPageFormat != NULL);
+    assert(fCurPainter != NULL);
+    assert(fCurPeekGraphics != NULL);
+
+    JNIEnv* env = [ThreadUtilities getJNIEnvUncached];
+
+    if ([self cancelCheck:env])
+    {
+        [self releaseReferences:env];
+        return;
+    }
+
+    NSPrintOperation* printLoop = [NSPrintOperation currentOperation];
+    jint jPageIndex = [printLoop currentPage] - 1;
+
+    jlong context = ptr_to_jlong([printLoop context]);
+    CGContextRef cgRef = (CGContextRef)[[printLoop context] graphicsPort];
+    CGContextSaveGState(cgRef); //04/28/2004: state needs to be saved here due to addition of lazy state management
+
+    JNFCallVoidMethod(env, fPrinterJob, jm_printToPathGraphics, fCurPeekGraphics, fPrinterJob, fCurPainter, fCurPageFormat, jPageIndex, context); // AWT_THREADING Safe (AWTRunLoop)
+
+    CGContextRestoreGState(cgRef);
+
+    [self releaseReferences:env];
+}
+
+- (NSString*)printJobTitle
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_getJobName, sjc_CPrinterJob, "getJobName", "()Ljava/lang/String;");
+
+    JNIEnv* env = [ThreadUtilities getJNIEnvUncached];
+
+    jobject o = JNFCallObjectMethod(env, fPrinterJob, jm_getJobName); // AWT_THREADING Safe (known object)
+    id result = JNFJavaToNSString(env, o);
+    (*env)->DeleteLocalRef(env, o);
+    return result;
+}
+
+- (BOOL)knowsPageRange:(NSRangePointer)aRange
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    JNIEnv* env = [ThreadUtilities getJNIEnvUncached];
+    if ([self cancelCheck:env])
+    {
+        return NO;
+    }
+
+    aRange->location = fFirstPage + 1;
+
+    if (fLastPage == java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES)
+    {
+        aRange->length = NSIntegerMax;
+    }
+    else
+    {
+        aRange->length = (fLastPage + 1) - fFirstPage;
+    }
+
+    return YES;
+}
+
+- (NSRect)rectForPage:(NSInteger)pageNumber
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_getPageformatPrintablePeekgraphics, sjc_CPrinterJob, "getPageformatPrintablePeekgraphics", "(I)[Ljava/lang/Object;");
+    static JNF_MEMBER_CACHE(jm_printAndGetPageFormatArea, sjc_CPrinterJob, "printAndGetPageFormatArea", "(Ljava/awt/print/Printable;Ljava/awt/Graphics;Ljava/awt/print/PageFormat;I)Ljava/awt/geom/Rectangle2D;");
+
+    // Assertions removed, and corresponding JNFDeleteGlobalRefs added, for radr://3962543
+    // Actual fix that will keep these assertions from being true is radr://3205462 ,
+    // which will hopefully be fixed by the blocking AppKit bug radr://3056694
+    //assert(fCurPageFormat == NULL);
+    //assert(fCurPainter == NULL);
+    //assert(fCurPeekGraphics == NULL);
+
+    JNIEnv* env = [ThreadUtilities getJNIEnvUncached];
+    if(fCurPageFormat != NULL) {
+        JNFDeleteGlobalRef(env, fCurPageFormat);
+    }
+    if(fCurPainter != NULL) {
+        JNFDeleteGlobalRef(env, fCurPainter);
+    }
+    if(fCurPeekGraphics != NULL) {
+        JNFDeleteGlobalRef(env, fCurPeekGraphics);
+    }
+
+    //+++gdb Check the pageNumber for validity (PageAttrs)
+
+    jint jPageNumber = pageNumber - 1;
+
+    NSRect result;
+
+    if ([self cancelCheck:env])
+    {
+        return NSZeroRect;
+    }
+
+    jobjectArray objectArray = JNFCallObjectMethod(env, fPrinterJob, jm_getPageformatPrintablePeekgraphics, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode)
+    if (objectArray != NULL) {
+        // Get references to the return objects -> PageFormat, Printable, PeekGraphics
+        // Cheat - we know we either got NULL or a 3 element array
+        jobject pageFormat = (*env)->GetObjectArrayElement(env, objectArray, 0);
+        fCurPageFormat = JNFNewGlobalRef(env, pageFormat);
+        (*env)->DeleteLocalRef(env, pageFormat);
+
+        jobject painter = (*env)->GetObjectArrayElement(env, objectArray, 1);
+        fCurPainter = JNFNewGlobalRef(env, painter);
+        (*env)->DeleteLocalRef(env, painter);
+
+        jobject peekGraphics = (*env)->GetObjectArrayElement(env, objectArray, 2);
+        fCurPeekGraphics = JNFNewGlobalRef(env, peekGraphics);
+        (*env)->DeleteLocalRef(env, peekGraphics);
+
+        // Actually print and get the PageFormatArea
+        jobject pageFormatArea = JNFCallObjectMethod(env, fPrinterJob, jm_printAndGetPageFormatArea, fCurPainter, fCurPeekGraphics, fCurPageFormat, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode)
+        if (pageFormatArea != NULL) {
+            result = JavaToNSRect(env, pageFormatArea);
+            (*env)->DeleteLocalRef(env, pageFormatArea);
+        } else {
+            [self releaseReferences:env];
+            result = NSZeroRect;
+        }
+
+        (*env)->DeleteLocalRef(env, objectArray);
+    } else {
+        [self releaseReferences:env];
+        result = NSZeroRect;
+    }
+
+    return result;
+}
+
+- (BOOL)cancelCheck:(JNIEnv*)env
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jm_cancelCheck, sjc_CPrinterJob, "cancelCheck", "()Z");
+
+    return JNFCallBooleanMethod(env, fPrinterJob, jm_cancelCheck); // AWT_THREADING Safe (known object)
+}
+
+// This is called by -[PrintModel safePrintLoop]
+- (void)complete:(JNIEnv*)env
+{
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    static JNF_MEMBER_CACHE(jf_completePrintLoop, sjc_CPrinterJob, "completePrintLoop", "()V");
+    JNFCallVoidMethod(env, fPrinterJob, jf_completePrintLoop);
+
+    // Clean up after ourselves
+    // Can't put these into -dealloc since that happens (potentially) after the JNIEnv is stale
+    [self releaseReferences:env];
+    if (fPrinterJob != NULL)
+    {
+        JNFDeleteGlobalRef(env, fPrinterJob);
+        fPrinterJob = NULL;
+    }
+}
+
+- (BOOL)isFlipped
+{
+    return TRUE;
+}
+
+@end
diff --git a/jdk/src/macosx/native/sun/awt/QuartzRenderer.m b/jdk/src/macosx/native/sun/awt/QuartzRenderer.m
new file mode 100644
index 0000000..e5784f6
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/QuartzRenderer.m
@@ -0,0 +1,794 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "java_awt_image_BufferedImage.h"
+#import "java_awt_geom_PathIterator.h"
+#import "sun_java2d_OSXSurfaceData.h"
+
+#import <stdio.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "ImageSurfaceData.h"
+
+
+//#define DEBUG 1
+#if defined DEBUG
+    #define QUARTZ_RENDERER_INLINE
+    #define PRINT(msg) {fprintf(stderr, "%s\n", msg);fflush(stderr);}
+#else
+    #define QUARTZ_RENDERER_INLINE static inline
+    #define PRINT(msg) {}
+#endif
+
+// Copied the following from Math.java
+#define PI 3.14159265358979323846f
+
+#define BATCHED_POINTS_SIZE 1024
+
+// same value as defined in Sun's own code
+#define XOR_ALPHA_CUTOFF 128
+
+// private Quartz routines needed here
+CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx);
+
+
+static CGFloat gRoundRectCtrlpts[10][12] =
+{
+    {0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+    {0.0f, 0.0f, 1.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+    {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f, 0.0f},
+    {1.0f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+    {1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, -0.5f},
+    {1.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+    {1.0f, 0.0f, 0.0f, 0.0f,  1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -0.5f, 0.0f, 0.0f},
+    {0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+    {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
+    {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+};
+
+CG_EXTERN CGRect CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t);
+
+
+CGRect sanitizedRect(CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2) {
+    CGFloat temp;
+    if (x1 > x2) {
+        temp = x2;
+        x2 = x1;
+        x1 = temp;
+    }
+    if (y1 > y2) {
+        temp = y2;
+        y2 = y1;
+        y1 = temp;
+    }
+    return CGRectMake(x1, y1, x2-x1, y2-y1);
+}
+
+QUARTZ_RENDERER_INLINE SDRenderType doLineUsingCG(CGContextRef cgRef, CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2, BOOL simple, CGFloat offsetX, CGFloat offsetY)
+{
+//fprintf(stderr, "doLine start=(%f, %f), end=(%f, %f), linewidth:%f, offsetX:%f, offsetY:%f\n", x1, y1, x2, y2, CGContextGetLineWidth(cgRef), offsetX, offsetY);
+    SDRenderType renderType = SD_Nothing;
+
+    if (simple == YES)
+    {
+        struct CGPoint oneLinePoints[2];
+
+        oneLinePoints[0] = CGPointMake(x1+offsetX, y1+offsetY);
+        oneLinePoints[1] = CGPointMake(x2+offsetX, y2+offsetY);
+
+        CGContextStrokeLineSegments(cgRef, oneLinePoints, 2);
+        renderType = SD_Nothing;
+    }
+    else
+    {
+        CGContextMoveToPoint(cgRef, x1+offsetX, y1+offsetY);
+        CGContextAddLineToPoint(cgRef, x2+offsetX, y2+offsetY);
+        renderType = SD_Stroke;
+    }
+
+    return renderType;
+}
+QUARTZ_RENDERER_INLINE SDRenderType doLine(QuartzSDOps *qsdo, CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2)
+{
+PRINT(" doLine")
+    if (YES)
+    {
+        return doLineUsingCG(qsdo->cgRef, x1, y1, x2, y2,
+                                qsdo->graphicsStateInfo.simpleStroke, qsdo->graphicsStateInfo.offsetX, qsdo->graphicsStateInfo.offsetY);
+    }
+    // here we can add other implementations (ex. using QuickDraw, OpenGL, etc.)
+}
+
+
+QUARTZ_RENDERER_INLINE SDRenderType doRectUsingCG(CGContextRef cgRef, CGFloat x, CGFloat y, CGFloat w, CGFloat h, BOOL fill, BOOL simple, CGFloat offsetX, CGFloat offsetY)
+{
+//fprintf(stderr, "doRect point=(%f, %f), size=(%f, %f), offsets=(%f, %f) fill=%d simple=%d\n", x, y, w, h, offsetX, offsetY, fill, simple);
+//CGRect clip = CGContextGetClipBoundingBox(cgRef);
+//fprintf(stderr, "    clip: ((%f, %f), (%f, %f))\n", clip.origin.x, clip.origin.y, clip.size.width, clip.size.height);
+//CGAffineTransform ctm = CGContextGetCTM(cgRef);
+//fprintf(stderr, "    ctm: (%f, %f, %f, %f, %f, %f)\n", ctm.a, ctm.b, ctm.c, ctm.d, ctm.tx, ctm.ty);
+    SDRenderType renderType = SD_Nothing;
+
+    if (fill == YES)
+    {
+        if (simple == YES)
+        {
+            CGContextFillRect(cgRef, CGRectMake(x, y, w, h));
+            renderType = SD_Nothing;
+        }
+        else
+        {
+            CGContextAddRect(cgRef, CGRectMake(x, y, w, h));
+            renderType = SD_Fill;
+        }
+    }
+    else
+    {
+        if (simple == YES)
+        {
+            CGContextStrokeRect(cgRef, CGRectMake(x+offsetX, y+offsetY, w, h));
+            renderType = SD_Nothing;
+        }
+        else
+        {
+            CGContextAddRect(cgRef, CGRectMake(x+offsetX, y+offsetY, w, h));
+            renderType = SD_Stroke;
+        }
+    }
+
+    return renderType;
+}
+QUARTZ_RENDERER_INLINE SDRenderType doRect(QuartzSDOps *qsdo, CGFloat x, CGFloat y, CGFloat w, CGFloat h, BOOL fill)
+{
+PRINT(" doRect")
+    if (YES)
+    {
+        return doRectUsingCG(qsdo->cgRef, x, y, w, h, fill,
+                                qsdo->graphicsStateInfo.simpleStroke, qsdo->graphicsStateInfo.offsetX, qsdo->graphicsStateInfo.offsetY);
+    }
+    // here we can add other implementations (ex. using QuickDraw, OpenGL, etc.)
+}
+
+// from RoundRectIterator.java
+QUARTZ_RENDERER_INLINE SDRenderType doRoundRectUsingCG(CGContextRef cgRef, CGFloat x, CGFloat y, CGFloat w, CGFloat h, CGFloat arcWidth, CGFloat arcHeight, BOOL fill, CGFloat offsetX, CGFloat offsetY)
+{
+    SDRenderType renderType = SD_Nothing;
+
+    if (fill == YES)
+    {
+        renderType = SD_Fill;
+    }
+    else
+    {
+        renderType = SD_Stroke;
+    }
+
+    // radr://3593731 RoundRects with corner width/height of 0 don't draw
+    arcWidth = (arcWidth > 0.0f) ? arcWidth : 0.0f;
+    arcHeight = (arcHeight > 0.0f) ? arcHeight : 0.0f;
+
+    CGFloat aw = (w < arcWidth) ? w : arcWidth;
+    CGFloat ah = (h < arcHeight) ? h : arcHeight;
+
+    CGFloat *ctrls, p1, q1, p2, q2, p3, q3;
+    ctrls = gRoundRectCtrlpts[0];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    CGContextMoveToPoint(cgRef, p1+offsetX, q1+offsetY);
+
+    ctrls = gRoundRectCtrlpts[1];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    CGContextAddLineToPoint(cgRef, p1+offsetX, q1+offsetY);
+
+    ctrls = gRoundRectCtrlpts[2];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    p2 = (x + ctrls[4] * w + ctrls[5] * aw);
+    q2 = (y + ctrls[6] * h + ctrls[7] * ah);
+    p3 = (x + ctrls[8] * w + ctrls[9] * aw);
+    q3 = (y + ctrls[10] * h + ctrls[11] * ah);
+    CGContextAddCurveToPoint(cgRef, p1+offsetX, q1+offsetY, p2+offsetX, q2+offsetY, p3+offsetX, q3+offsetY);
+
+    ctrls = gRoundRectCtrlpts[3];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    CGContextAddLineToPoint(cgRef, p1+offsetX, q1+offsetY);
+
+    ctrls = gRoundRectCtrlpts[4];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    p2 = (x + ctrls[4] * w + ctrls[5] * aw);
+    q2 = (y + ctrls[6] * h + ctrls[7] * ah);
+    p3 = (x + ctrls[8] * w + ctrls[9] * aw);
+    q3 = (y + ctrls[10] * h + ctrls[11] * ah);
+    CGContextAddCurveToPoint(cgRef, p1+offsetX, q1+offsetY, p2+offsetX, q2+offsetY, p3+offsetX, q3+offsetY);
+
+    ctrls = gRoundRectCtrlpts[5];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    CGContextAddLineToPoint(cgRef, p1+offsetX, q1+offsetY);
+
+    ctrls = gRoundRectCtrlpts[6];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    p2 = (x + ctrls[4] * w + ctrls[5] * aw);
+    q2 = (y + ctrls[6] * h + ctrls[7] * ah);
+    p3 = (x + ctrls[8] * w + ctrls[9] * aw);
+    q3 = (y + ctrls[10] * h + ctrls[11] * ah);
+    CGContextAddCurveToPoint(cgRef, p1+offsetX, q1+offsetY, p2+offsetX, q2+offsetY, p3+offsetX, q3+offsetY);
+
+    ctrls = gRoundRectCtrlpts[7];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    CGContextAddLineToPoint(cgRef, p1+offsetX, q1+offsetY);
+
+    ctrls = gRoundRectCtrlpts[8];
+    p1 = (x + ctrls[0] * w + ctrls[1] * aw);
+    q1 = (y + ctrls[2] * h + ctrls[3] * ah);
+    p2 = (x + ctrls[4] * w + ctrls[5] * aw);
+    q2 = (y + ctrls[6] * h + ctrls[7] * ah);
+    p3 = (x + ctrls[8] * w + ctrls[9] * aw);
+    q3 = (y + ctrls[10] * h + ctrls[11] * ah);
+    CGContextAddCurveToPoint(cgRef, p1+offsetX, q1+offsetY, p2+offsetX, q2+offsetY, p3+offsetX, q3+offsetY);
+
+    CGContextClosePath(cgRef);
+
+    return renderType;
+}
+
+QUARTZ_RENDERER_INLINE SDRenderType doRoundRect(QuartzSDOps *qsdo, CGFloat x, CGFloat y, CGFloat w, CGFloat h, CGFloat arcWidth, CGFloat arcHeight, BOOL fill)
+{
+PRINT(" doRoundRect")
+    if (YES)
+    {
+        return doRoundRectUsingCG(qsdo->cgRef, x, y, w, h, arcWidth, arcHeight, fill,
+                                    qsdo->graphicsStateInfo.offsetX, qsdo->graphicsStateInfo.offsetY);
+    }
+    // here we can add other implementations (ex. using QuickDraw, OpenGL, etc.)
+}
+
+// from EllipseIterator.java
+QUARTZ_RENDERER_INLINE SDRenderType doOvalUsingCG(CGContextRef cgRef, CGFloat x, CGFloat y, CGFloat w, CGFloat h, BOOL fill, BOOL simple, CGFloat offsetX, CGFloat offsetY)
+{
+    SDRenderType renderType = SD_Nothing;
+
+    if (simple == YES)
+    {
+        if (fill == YES)
+        {
+            CGContextFillEllipseInRect(cgRef, CGRectMake(x+offsetX, y+offsetY, w, h));
+        }
+        else
+        {
+            CGContextStrokeEllipseInRect(cgRef, CGRectMake(x+offsetX, y+offsetY, w, h));
+        }
+    }
+    else
+    {
+        if (fill == YES)
+        {
+            renderType = SD_Fill;
+        }
+        else
+        {
+            renderType = SD_Stroke;
+        }
+
+        CGContextAddEllipseInRect(cgRef, CGRectMake(x+offsetX, y+offsetY, w, h));
+    }
+
+    return renderType;
+}
+QUARTZ_RENDERER_INLINE SDRenderType doOval(QuartzSDOps *qsdo, CGFloat x, CGFloat y, CGFloat w, CGFloat h, BOOL fill)
+{
+PRINT(" doOval")
+    if (YES)
+    {
+        return doOvalUsingCG(qsdo->cgRef, x, y, w, h, fill,
+                                qsdo->graphicsStateInfo.simpleStroke, qsdo->graphicsStateInfo.offsetX, qsdo->graphicsStateInfo.offsetY);
+    }
+    // here we can add other implementations (ex. using QuickDraw, OpenGL, etc.)
+}
+
+// from ArcIterator.java
+QUARTZ_RENDERER_INLINE CGFloat btan(CGFloat increment)
+{
+    increment /= 2.0f;
+    CGFloat a = 1.0f - cos(increment);
+    CGFloat b = tan(increment);
+    CGFloat c = sqrt(1.0f + b * b) - 1.0f + a;
+
+    return 4.0f / 3.0f * a * b / c;
+}
+QUARTZ_RENDERER_INLINE SDRenderType doArcUsingCG(CGContextRef cgRef, CGFloat x, CGFloat y, CGFloat w, CGFloat h, CGFloat angleStart, CGFloat angleExtent, jint arcType, BOOL fill, CGFloat offsetX, CGFloat offsetY)
+{
+//fprintf(stderr, "doArc\n");
+    SDRenderType renderType = SD_Nothing;
+
+    if (fill == YES)
+    {
+        renderType = SD_Fill;
+    }
+    else
+    {
+        renderType = SD_Stroke;
+    }
+
+    CGFloat angStRad, angExtDeg;
+    jint arcSegs;
+    jint lineSegs;
+    jint index = 1;
+
+    w = w / 2.0f;
+    h = h / 2.0f;
+    x = x + w;
+    y = y + h;
+    angStRad = -(angleStart / 180.0f * PI);
+    angExtDeg = -angleExtent;
+    CGFloat ext = (angExtDeg>0) ? angExtDeg : -angExtDeg;
+    if (ext >= 360.0f)
+    {
+        arcSegs = 4;
+    }
+    else
+    {
+        arcSegs = (jint)ceil(ext/90.0f);
+    }
+    switch (arcType)
+    {
+        case 0:
+            lineSegs = 0;
+            break;
+        case 1:
+            lineSegs = 1;
+            break;
+        case 2:
+            lineSegs = 2;
+            break;
+    }
+    if (w < 0 || h < 0)
+    {
+        arcSegs = lineSegs = -1;
+    }
+
+    CGFloat angle = angStRad;
+    CGContextMoveToPoint(cgRef, (x + cos(angle) * w)+offsetX, (y + sin(angle) * h)+offsetY);
+
+    CGFloat increment = angExtDeg;
+    if (increment > 360.0f)
+    {
+        increment = 360.0f;
+    }
+    else if (increment < -360.0f)
+    {
+        increment = -360.0f;
+    }
+    increment /= arcSegs;
+    increment = (increment / 180.0f * PI);
+    CGFloat z = btan(increment);
+    CGFloat angleBase = angle;
+    CGFloat p1, q1, p2, q2, p3, q3;
+    while (index <= arcSegs)
+    {
+        angle = angleBase + increment * (index - 1);
+        CGFloat relx = cos(angle);
+        CGFloat rely = sin(angle);
+        p1 = (x + (relx - z * rely) * w);
+        q1 = (y + (rely + z * relx) * h);
+        angle += increment;
+        relx = cos(angle);
+        rely = sin(angle);
+        p2 = (x + (relx + z * rely) * w);
+        q2 = (y + (rely - z * relx) * h);
+        p3 = (x + relx * w);
+        q3 = (y + rely * h);
+
+        CGContextAddCurveToPoint(cgRef, p1+offsetX, q1+offsetY, p2+offsetX, q2+offsetY, p3+offsetX, q3+offsetY);
+
+        index++;
+    }
+
+    switch (arcType)
+    {
+        case 1:
+            CGContextClosePath(cgRef);
+            break;
+        case 2:
+            CGContextAddLineToPoint(cgRef, x+offsetX, y+offsetY);
+            CGContextClosePath(cgRef);
+            break;
+        default:
+            break;
+    }
+
+    return renderType;
+}
+QUARTZ_RENDERER_INLINE SDRenderType doArc(QuartzSDOps *qsdo, CGFloat x, CGFloat y, CGFloat w, CGFloat h, CGFloat angleStart, CGFloat angleExtent, jint arcType, BOOL fill)
+{
+PRINT(" doArc")
+    if (YES)
+    {
+        return doArcUsingCG(qsdo->cgRef, x, y, w, h, angleStart, angleExtent, arcType, fill,
+                                qsdo->graphicsStateInfo.offsetX, qsdo->graphicsStateInfo.offsetY);
+    }
+    // here we can add other implementations (ex. using QuickDraw, OpenGL, etc.)
+}
+
+QUARTZ_RENDERER_INLINE SDRenderType doPolyUsingCG(JNIEnv *env, CGContextRef cgRef, jintArray xpointsarray, jintArray ypointsarray, jint npoints, BOOL polygon, BOOL fill, CGFloat offsetX, CGFloat offsetY)
+{
+    SDRenderType renderType = SD_Nothing;
+
+    if (npoints > 1)
+    {
+        if (fill == YES)
+        {
+            renderType = SD_Fill;
+        }
+        else
+        {
+            renderType = SD_Stroke;
+        }
+
+        jint i;
+
+        jint* xpoints = (jint*)(*env)->GetPrimitiveArrayCritical(env, xpointsarray, NULL);
+        jint* ypoints = (jint*)(*env)->GetPrimitiveArrayCritical(env, ypointsarray, NULL);
+
+        CGContextMoveToPoint(cgRef, xpoints[0]+offsetX, ypoints[0]+offsetY);
+
+        for (i=1; i<npoints; i++)
+        {
+            CGContextAddLineToPoint(cgRef, xpoints[i]+offsetX, ypoints[i]+offsetY);
+        }
+
+        if (polygon == YES)
+        {
+            if ((xpoints[0] != xpoints[npoints-1]) || (ypoints[0] != ypoints[npoints-1])) // according to the specs (only applies to polygons, not polylines)
+            {
+                CGContextAddLineToPoint(cgRef, xpoints[0]+offsetX, ypoints[0]+offsetY);
+            }
+        }
+
+        (*env)->ReleasePrimitiveArrayCritical(env, ypointsarray, ypoints, 0);
+        (*env)->ReleasePrimitiveArrayCritical(env, xpointsarray, xpoints, 0);
+    }
+
+    return renderType;
+}
+QUARTZ_RENDERER_INLINE SDRenderType doPoly(JNIEnv *env, QuartzSDOps *qsdo, jintArray xpointsarray, jintArray ypointsarray, jint npoints, BOOL polygon, BOOL fill)
+{
+PRINT(" doPoly")
+    if (YES)
+    {
+        return doPolyUsingCG(env, qsdo->cgRef, xpointsarray, ypointsarray, npoints, polygon, fill,
+            qsdo->graphicsStateInfo.offsetX, qsdo->graphicsStateInfo.offsetY);
+    }
+    // here we can add other implementations (ex. using QuickDraw, OpenGL, etc.)
+}
+
+SDRenderType doShape(QuartzSDOps *qsdo, jint *types, jfloat *coords, jint numtypes, BOOL fill, BOOL shouldApplyOffset)
+{
+PRINT(" doShape")
+    if (YES)
+    {
+        CGFloat offsetX = 0.0f;
+        CGFloat offsetY = 0.0f;
+        if (shouldApplyOffset)
+        {
+            offsetX = qsdo->graphicsStateInfo.offsetX;
+            offsetY = qsdo->graphicsStateInfo.offsetY;
+        }
+        return DoShapeUsingCG(qsdo->cgRef, types, coords, numtypes, fill, offsetX, offsetY); // defined in QuartzSurfaceData.m
+    }
+    // here we can add other implementations (ex. using QuickDraw, OpenGL, etc.)
+}
+
+
+
+QUARTZ_RENDERER_INLINE void doImageCG(JNIEnv *env, CGContextRef cgRef, jobject imageSurfaceData,
+                                        jint interpolation, BOOL fliph, BOOL flipv, jint w, jint h, jint sx, jint sy, jint sw, jint sh, jint dx, jint dy, jint dw, jint dh)
+{
+//fprintf(stderr, "doImageCG\n");
+//fprintf(stderr, "    flip:(%d, %d), size:(%d, %d), src:(%d, %d, %d, %d), dst:(%d, %d, %d, %d)\n", (jint)fliph, (jint)flipv, w, h, sx, sy, sw, sh, dx, dy, dw, dh);
+    // gznote: need to handle interpolation
+    ImageSDOps* isdo = LockImage(env, imageSurfaceData);
+
+    CGFloat a = 1.0f;
+    CGFloat b = 0.0f;
+    CGFloat c = 0.0f;
+    CGFloat d = -1.0f;
+    CGFloat tx = dx;
+    CGFloat ty = dy+dh;
+
+    if (flipv == YES)
+    {
+        d = 1.0f;
+        ty -= dh;
+    }
+    if (fliph == YES)
+    {
+        a = -1.0f;
+        tx += dw;
+    }
+
+    makeSureImageIsCreated(isdo);
+
+    CGAffineTransform ctm = CGContextGetCTM(cgRef);
+    CGContextConcatCTM(cgRef, CGAffineTransformMake(a, b, c, d, tx, ty));
+    jint alphaInfo = isdo->contextInfo.alphaInfo & kCGBitmapAlphaInfoMask;
+
+    if ((sx == 0) && (sy == 0) && (sw == w) && (sh == h)) // no subimages allowed here
+    {
+        CGContextDrawImage(cgRef, CGRectMake(0, 0, dw, dh), isdo->imgRef);
+    }
+    else // handle subimages
+    {
+        CGImageRef subImg = CGImageCreateWithImageInRect(isdo->imgRef, CGRectMake(sx, sy, sw, sh));
+        CGContextDrawImage(cgRef, CGRectMake(0.0f, 0.0f, dw, dh), subImg);
+        CGImageRelease(subImg);
+    }
+
+    CGContextSetCTM(cgRef, ctm);
+    UnlockImage(env, isdo);
+}
+
+QUARTZ_RENDERER_INLINE void doImage(JNIEnv *env, QuartzSDOps *qsdo, jobject imageSurfaceData,
+                                jboolean fliph, jboolean flipv, jint w, jint h, jint sx, jint sy, jint sw, jint sh, jint dx, jint dy, jint dw, jint dh)
+{
+    if ((w > 0) && (h > 0) && (sw > 0) && (sh > 0) && (dw > 0) && (dh > 0))
+    {
+       doImageCG(env, qsdo->cgRef, imageSurfaceData,
+                            qsdo->graphicsStateInfo.interpolation, (BOOL)fliph, (BOOL)flipv, (jint)w, (jint)h, (jint)sx, (jint)sy, (jint)sw, (jint)sh, (jint)dx, (jint)dy, (jint)dw, (jint)dh);
+    }
+}
+
+
+
+QUARTZ_RENDERER_INLINE void completePath(JNIEnv *env, QuartzSDOps *qsdo, CGContextRef cgRef, jint renderType)
+{
+    switch (renderType)
+    {
+        case SD_Stroke:
+            if (CGContextIsPathEmpty(cgRef) == 0)
+            {
+                CGContextStrokePath(cgRef);
+            }
+            break;
+        case SD_Fill:
+            if (CGContextIsPathEmpty(cgRef) == 0)
+            {
+                CGContextFillPath(cgRef);
+            }
+            break;
+        case SD_Image:
+            break;
+        case SD_Nothing:
+                break;
+        default:
+fprintf(stderr, "completePath unknown renderType=%d\n", (int)renderType);
+            break;
+    }
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    init
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_init
+(JNIEnv *env, jobject jthis)
+{
+PRINT("Java_sun_java2d_CRenderer_init")
+    CGFloat angle = PI / 4.0f;
+    CGFloat a = 1.0f - cos(angle);
+    CGFloat b = tan(angle);
+    CGFloat c = sqrt(1.0f + b * b) - 1.0f + a;
+    CGFloat cv = 4.0f / 3.0f * a * b / c;
+    CGFloat acv = (1.0f - cv) / 2.0f;
+
+    gRoundRectCtrlpts[2][3] = -acv;
+    gRoundRectCtrlpts[2][5] = acv;
+    gRoundRectCtrlpts[4][1] = -acv;
+    gRoundRectCtrlpts[4][7] = -acv;
+    gRoundRectCtrlpts[6][3] = acv;
+    gRoundRectCtrlpts[6][5] = -acv;
+    gRoundRectCtrlpts[8][1] = acv;
+    gRoundRectCtrlpts[8][7] = acv;
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doLine
+ * Signature: (Lsun/java2d/SurfaceData;Ljava/nio/IntBuffer;Ljava/nio/FloatBuffer;[Ljava/lang/Object;FFFF)V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doLine
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jfloat x1, jfloat y1, jfloat x2, jfloat y2)
+{
+PRINT("Java_sun_java2d_CRenderer_doLine")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    SDRenderType renderType = SD_Stroke;
+    qsdo->BeginSurface(env, qsdo, renderType);
+    if (qsdo->cgRef != NULL)
+    {
+        doLine(qsdo, x1, y1, x2, y2);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doRect
+ * Signature: (Lsun/java2d/SurfaceData;Ljava/nio/IntBuffer;Ljava/nio/FloatBuffer;[Ljava/lang/Object;FFFF)V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doRect
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jfloat x, jfloat y, jfloat w, jfloat h, jboolean isfill)
+{
+PRINT("Java_sun_java2d_CRenderer_doRect")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    SDRenderType renderType    = (isfill? SD_Fill : SD_Stroke);
+    qsdo->BeginSurface(env, qsdo, renderType);
+    if (qsdo->cgRef != NULL)
+    {
+        doRect(qsdo, x, y, w, h, isfill);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doRoundRect
+ * Signature: (Lsun/java2d/SurfaceData;Ljava/nio/IntBuffer;Ljava/nio/FloatBuffer;[Ljava/lang/Object;IIIIII)V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doRoundRect
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jfloat x, jfloat y, jfloat w, jfloat h, jfloat arcWidth, jfloat arcHeight, jboolean isfill)
+{
+PRINT("Java_sun_java2d_CRenderer_doRoundRect")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    SDRenderType renderType    = (isfill? SD_Fill : SD_Stroke);
+    qsdo->BeginSurface(env, qsdo, renderType);
+    if (qsdo->cgRef != NULL)
+    {
+        doRoundRect(qsdo, x, y, w, h, arcWidth, arcHeight, isfill);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doOval
+ * Signature: (Lsun/java2d/SurfaceData;Ljava/nio/IntBuffer;Ljava/nio/FloatBuffer;[Ljava/lang/Object;IIII)V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doOval
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jfloat x, jfloat y, jfloat w, jfloat h, jboolean isfill)
+{
+PRINT("Java_sun_java2d_CRenderer_doOval")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    SDRenderType renderType    = (isfill? SD_Fill : SD_Stroke);
+    qsdo->BeginSurface(env, qsdo, renderType);
+    if (qsdo->cgRef != NULL)
+    {
+        doOval(qsdo, x, y, w, h, isfill);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doArc
+ * Signature: (Lsun/java2d/SurfaceData;Ljava/nio/IntBuffer;Ljava/nio/FloatBuffer;[Ljava/lang/Object;IIIIII)V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doArc
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jfloat x, jfloat y, jfloat w, jfloat h, jfloat angleStart, jfloat angleExtent, jint arcType, jboolean isfill)
+{
+PRINT("Java_sun_java2d_CRenderer_doArc")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    SDRenderType renderType    = (isfill? SD_Fill : SD_Stroke);
+    qsdo->BeginSurface(env, qsdo, renderType);
+    if (qsdo->cgRef != NULL)
+    {
+        doArc(qsdo, x, y, w, h, angleStart, angleExtent, arcType, isfill);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doPoly
+ * Signature:
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doPoly
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jintArray xpointsarray, jintArray ypointsarray, jint npoints, jboolean ispolygon, jboolean isfill)
+{
+PRINT("Java_sun_java2d_CRenderer_doPoly")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    BOOL eoFill = YES; // polys are WIND_EVEN_ODD by definition
+    SDRenderType renderType    = (isfill? (eoFill ? SD_EOFill : SD_Fill) : SD_Stroke);
+    qsdo->BeginSurface(env, qsdo, renderType);
+    if (qsdo->cgRef != NULL)
+    {
+        doPoly(env, qsdo, xpointsarray, ypointsarray, npoints, ispolygon, isfill);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doShape
+ * Signature: (Lsun/java2d/SurfaceData;Ljava/nio/IntBuffer;Ljava/nio/FloatBuffer;[Ljava/lang/Object;ILjava/nio/FloatBuffer;Ljava/nio/IntBuffer;IZ)V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doShape
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jint length, jobject jFloatCoordinates, jobject jIntTypes, jint windingRule, jboolean isfill, jboolean shouldApplyOffset)
+{
+PRINT("Java_sun_java2d_CRenderer_doShape")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    BOOL eoFill = (windingRule == java_awt_geom_PathIterator_WIND_EVEN_ODD);
+    SDRenderType renderType    = (isfill? (eoFill ? SD_EOFill : SD_Fill) : SD_Stroke);
+    qsdo->BeginSurface(env, qsdo, renderType);
+    if (qsdo->cgRef != NULL)
+    {
+        jfloat *coordinates = (jfloat*)((*env)->GetDirectBufferAddress(env, jFloatCoordinates));
+        jint *types = (jint*)((*env)->GetDirectBufferAddress(env, jIntTypes));
+        doShape(qsdo, types, coordinates, length, isfill, shouldApplyOffset);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
+
+#define invalidContext(c) \
+    ((c) == NULL /* || (c)->identifer != CGContextIdentifier */)
+
+/*
+ * Class:     sun_java2d_CRenderer
+ * Method:    doImage
+ * Signature: (Lsun/java2d/SurfaceData;Ljava/nio/IntBuffer;Ljava/nio/FloatBuffer;[Ljava/lang/Object;Lsun/java2d/SurfaceData;ZZIIIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_sun_java2d_CRenderer_doImage
+(JNIEnv *env, jobject jthis, jobject jsurfacedata, jobject imageSurfaceData, jboolean fliph, jboolean flipv, jint w, jint h, jint sx, jint sy, jint sw, jint sh, jint dx, jint dy, jint dw, jint dh)
+{
+PRINT("Java_sun_java2d_CRenderer_doImage")
+    QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+JNF_COCOA_ENTER(env);
+    qsdo->BeginSurface(env, qsdo, SD_Image);
+    if (qsdo->cgRef != NULL)
+    {
+        doImage(env, qsdo, imageSurfaceData, fliph, flipv, w, h, sx, sy, sw, sh, dx, dy, dw, dh);
+    }
+    qsdo->FinishSurface(env, qsdo);
+JNF_COCOA_RENDERER_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/awt/QuartzSurfaceData.h b/jdk/src/macosx/native/sun/awt/QuartzSurfaceData.h
new file mode 100644
index 0000000..4dc48e4
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/QuartzSurfaceData.h
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "SurfaceData.h"
+#import "BufImgSurfaceData.h"
+#import "AWTFont.h"
+#import <Cocoa/Cocoa.h>
+
+// these flags are not defined on Tiger on PPC, so we need to make them a no-op
+#if !defined(kCGBitmapByteOrder32Host)
+#define kCGBitmapByteOrder32Host 0
+#endif
+#if !defined(kCGBitmapByteOrder16Host)
+#define kCGBitmapByteOrder16Host 0
+#endif
+
+// NOTE : Modify the printSurfaceDataDiagnostics API if you change this enum
+enum SDRenderType
+{
+    SD_Nothing,
+    SD_Stroke,
+    SD_Fill,
+    SD_EOFill,
+    SD_Shade,
+    SD_Pattern,
+    SD_Image,
+    SD_Text,
+    SD_CopyArea,
+    SD_Queue,
+    SD_External
+};
+typedef enum SDRenderType SDRenderType;
+
+struct _stateShadingInfo
+{
+    CGPoint    start;
+    CGPoint    end;
+    CGFloat    colors[8];
+    BOOL    cyclic;
+    CGFloat    length; // of the total segment (used by the cyclic gradient)
+    CGFloat    period; // of the cycle (used by the cyclic gradient)
+    CGFloat    offset; // of the cycle from the start (used by the cyclic gradient)
+};
+typedef struct _stateShadingInfo StateShadingInfo;
+
+struct _statePatternInfo
+{
+    CGFloat    tx;
+    CGFloat    ty;
+    CGFloat    sx;
+    CGFloat    sy;
+    jint    width;
+    jint    height;
+    jobject    sdata;
+};
+typedef struct _statePatternInfo StatePatternInfo;
+
+struct _stateGraphicsInfo
+{
+    BOOL                adjustedLineWidth;
+    BOOL                adjustedAntialias;
+    BOOL                antialiased;
+    jint                interpolation;
+    BOOL                simpleColor;
+    BOOL                simpleStroke;
+    CGAffineTransform    ctm;
+    CGFloat                offsetX;
+    CGFloat                offsetY;
+    struct CGPoint*        batchedLines;
+    UInt32                batchedLinesCount;
+};
+typedef struct _stateGraphicsInfo StateGraphicsInfo;
+
+typedef struct _QuartzSDOps QuartzSDOps;
+typedef void BeginContextFunc(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType);
+typedef void FinishContextFunc(JNIEnv *env, QuartzSDOps *qsdo);
+struct _QuartzSDOps
+{
+    BufImgSDOps                sdo; // must be the first entry!
+
+    BeginContextFunc*        BeginSurface;        // used to set graphics states (clip, color, stroke, etc...)
+    FinishContextFunc*        FinishSurface;        // used to finish drawing primitives
+    BOOL                    newContext;
+    CGContextRef            cgRef;
+
+    jint*                    javaGraphicsStates;
+    jobject                    javaGraphicsStatesObjects;
+
+    SDRenderType            renderType;
+
+    // rdar://problem/5214320
+    // Gradient/Texture fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline).
+    BOOL                    isEvenOddFill;        // Tracks whether the original render type passed into
+                                                // SetUpCGContext(...) is SD_EOFILL.
+                                                // The reason for this field is because SetUpCGContext(...) can
+                                                // change the render type after calling SetUpPaint(...), and right
+                                                // after that, the possibly new render type is then assigned into
+                                                // qsdo->renderType.  Sigh!!!
+                                                // This field is potentially used within CompleteCGContext(...) or
+                                                // its callees.
+
+    StateShadingInfo*        shadingInfo;        // tracks shading and its parameters
+    StatePatternInfo*        patternInfo;        // tracks pattern and its parameters
+    StateGraphicsInfo        graphicsStateInfo;    // tracks other graphics state
+
+    BOOL  syncContentsToLayer;    // should changed pixels be synced to a CALayer
+    CGRect updateRect;     // used by the layer synchronization code to track update rects.
+};
+
+void SetUpCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType);
+SDRenderType DoShapeUsingCG(CGContextRef cgRef, jint *types, jfloat *coords, jint numtypes, BOOL fill, CGFloat offsetX, CGFloat offsetY);
+SDRenderType SetUpPaint(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType);
+void CompleteCGContext(JNIEnv *env, QuartzSDOps *qsdo);
+
+NSColor* ByteParametersToNSColor(JNIEnv* env, jint *javaGraphicsStates, NSColor* defColor);
+
+#define JNF_COCOA_RENDERER_EXIT(env) \
+} @catch(NSException *localException) { \
+    qsdo->FinishSurface(env, qsdo); \
+    [JNFException throwToJava:env exception:localException]; \
+} \
+        if (_token) JNFNativeMethodExit(_token); \
+}
diff --git a/jdk/src/macosx/native/sun/awt/QuartzSurfaceData.m b/jdk/src/macosx/native/sun/awt/QuartzSurfaceData.m
new file mode 100644
index 0000000..8d3784c
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/QuartzSurfaceData.m
@@ -0,0 +1,1115 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "QuartzSurfaceData.h"
+
+#import "java_awt_BasicStroke.h"
+#import "java_awt_AlphaComposite.h"
+#import "java_awt_geom_PathIterator.h"
+#import "java_awt_image_BufferedImage.h"
+#import "sun_awt_SunHints.h"
+#import "sun_java2d_CRenderer.h"
+#import "sun_java2d_OSXSurfaceData.h"
+#import "sun_lwawt_macosx_CPrinterSurfaceData.h"
+#import "ImageSurfaceData.h"
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import <AppKit/AppKit.h>
+#import "ThreadUtilities.h"
+
+// private Quartz routines needed here
+CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx);
+
+//#define DEBUG
+#if defined DEBUG
+    #define PRINT(msg) {fprintf(stderr, "%s\n", msg);}
+#else
+    #define PRINT(msg) {}
+#endif
+
+// from CGAffineTransformPrivate.h
+extern CGPoint CGPointApplyInverseAffineTransform(CGPoint point, CGAffineTransform t);
+
+#define kOffset (0.5f)
+
+BOOL gAdjustForJavaDrawing;
+
+#pragma mark
+#pragma mark --- Color Cache ---
+
+// Creating and deleting CGColorRefs can be expensive, therefore we have a color cache.
+// The color cache was first introduced with <rdar://problem/3923927>
+// With <rdar://problem/4280514>, the hashing function was improved
+// With <rdar://problem/4012223>, the color cache became global (per process) instead of per surface.
+
+// Must be power of 2. 1024 is the least power of 2 number that makes SwingSet2 run without any non-empty cache misses
+#define gColorCacheSize 1024
+struct _ColorCacheInfo
+{
+    UInt32        keys[gColorCacheSize];
+    CGColorRef    values[gColorCacheSize];
+};
+static struct _ColorCacheInfo colorCacheInfo;
+
+static pthread_mutex_t gColorCacheLock = PTHREAD_MUTEX_INITIALIZER;
+
+// given a UInt32 color, it tries to find that find the corresponding CGColorRef in the hash cache. If the CGColorRef
+// doesn't exist or there is a collision, it creates a new one CGColorRef and put's in the cache. Then,
+// it sets with current fill/stroke color for the the CGContext passed in (qsdo->cgRef).
+void setCachedColor(QuartzSDOps *qsdo, UInt32 color)
+{
+    static const CGFloat kColorConversionMultiplier = 1.0f/255.0f;
+
+    pthread_mutex_lock(&gColorCacheLock);
+
+    static CGColorSpaceRef colorspace = NULL;
+    if (colorspace == NULL)
+    {
+        colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+    }
+
+    CGColorRef cgColor = NULL;
+
+    // The colors passed have low randomness. That means we need to scramble the bits of the color
+    // to produce a good hash key. After some analysis, it looks like Thomas's Wang integer hasing algorithm
+    // seems a nice trade off between performance and effectivness.
+    UInt32 index = color;
+    index += ~(index << 15);
+    index ^=  (index >> 10);
+    index +=  (index << 3);
+    index ^=  (index >> 6);
+    index += ~(index << 11);
+    index ^=  (index >> 16);
+    index = index & (gColorCacheSize - 1);   // The bits are scrambled, we just need to make sure it fits inside our table
+
+    UInt32 key = colorCacheInfo.keys[index];
+    CGColorRef value = colorCacheInfo.values[index];
+    if ((key == color) && (value != NULL))
+    {
+        //fprintf(stderr, "+");fflush(stderr);//hit
+        cgColor = value;
+    }
+    else
+    {
+        if (value != NULL)
+        {
+            //fprintf(stderr, "!");fflush(stderr);//miss and replace - double ouch
+            CGColorRelease(value);
+        }
+        //fprintf(stderr, "-");fflush(stderr);// miss
+
+        CGFloat alpha = ((color>>24)&0xff)*kColorConversionMultiplier;
+        CGFloat red = ((color>>16)&0xff)*kColorConversionMultiplier;
+        CGFloat green = ((color>>8)&0xff)*kColorConversionMultiplier;
+        CGFloat blue = ((color>>0)&0xff)*kColorConversionMultiplier;
+        const CGFloat components[] = {red, green, blue, alpha, 1.0f};
+        value = CGColorCreate(colorspace, components);
+
+        colorCacheInfo.keys[index] = color;
+        colorCacheInfo.values[index] = value;
+
+        cgColor = value;
+    }
+
+    CGContextSetStrokeColorWithColor(qsdo->cgRef, cgColor);
+    CGContextSetFillColorWithColor(qsdo->cgRef, cgColor);
+
+    pthread_mutex_unlock(&gColorCacheLock);
+}
+
+#pragma mark
+#pragma mark --- Gradient ---
+
+// this function MUST NOT be inlined!
+void gradientLinearPaintEvaluateFunction(void *info, const CGFloat *in, CGFloat *out)
+{
+    StateShadingInfo *shadingInfo = (StateShadingInfo *)info;
+    CGFloat *colors = shadingInfo->colors;
+    CGFloat range = *in;
+    CGFloat c1, c2;
+    jint k;
+
+//fprintf(stderr, "range=%f\n", range);
+    for (k=0; k<4; k++)
+    {
+        c1 = colors[k];
+//fprintf(stderr, "    c1=%f", c1);
+        c2 = colors[k+4];
+//fprintf(stderr, ", c2=%f", c2);
+        if (c1 == c2)
+        {
+            *out++ = c2;
+//fprintf(stderr, ", %f", *(out-1));
+        }
+        else if (c1 > c2)
+        {
+            *out++ = c1 - ((c1-c2)*range);
+//fprintf(stderr, ", %f", *(out-1));
+        }
+        else// if (c1 < c2)
+        {
+            *out++ = c1 + ((c2-c1)*range);
+//fprintf(stderr, ", %f", *(out-1));
+        }
+//fprintf(stderr, "\n");
+    }
+}
+
+// this function MUST NOT be inlined!
+void gradientCyclicPaintEvaluateFunction(void *info, const CGFloat *in, CGFloat *out)
+{
+    StateShadingInfo *shadingInfo = (StateShadingInfo *)info;
+    CGFloat length = shadingInfo->length ;
+    CGFloat period = shadingInfo->period;
+    CGFloat offset = shadingInfo->offset;
+    CGFloat periodLeft = offset;
+    CGFloat periodRight = periodLeft+period;
+    CGFloat *colors = shadingInfo->colors;
+    CGFloat range = *in;
+    CGFloat c1, c2;
+    jint k;
+    jint count = 0;
+
+    range *= length;
+
+    // put the range within the period
+    if (range < periodLeft)
+    {
+        while (range < periodLeft)
+        {
+            range += period;
+            count++;
+        }
+
+        range = range-periodLeft;
+    }
+    else if (range > periodRight)
+    {
+        count = 1;
+
+        while (range > periodRight)
+        {
+            range -= period;
+            count++;
+        }
+
+        range = periodRight-range;
+    }
+    else
+    {
+        range = range - offset;
+    }
+    range = range/period;
+
+    // cycle up or down
+    if (count%2 == 0)
+    {
+        for (k=0; k<4; k++)
+        {
+            c1 = colors[k];
+            c2 = colors[k+4];
+            if (c1 == c2)
+            {
+                *out++ = c2;
+            }
+            else if (c1 > c2)
+            {
+                *out++ = c1 - ((c1-c2)*range);
+            }
+            else// if (c1 < c2)
+            {
+                *out++ = c1 + ((c2-c1)*range);
+            }
+        }
+    }
+    else
+    {
+        for (k=0; k<4; k++)
+        {
+            c1 = colors[k+4];
+            c2 = colors[k];
+            if (c1 == c2)
+            {
+                *out++ = c2;
+            }
+            else if (c1 > c2)
+            {
+                *out++ = c1 - ((c1-c2)*range);
+            }
+            else// if (c1 < c2)
+            {
+                *out++ = c1 + ((c2-c1)*range);
+            }
+        }
+    }
+ }
+
+// this function MUST NOT be inlined!
+void gradientPaintReleaseFunction(void *info)
+{
+PRINT("    gradientPaintReleaseFunction")
+    free(info);
+}
+
+static inline void contextGradientPath(QuartzSDOps* qsdo)
+{
+PRINT("    ContextGradientPath")
+    CGContextRef cgRef = qsdo->cgRef;
+    StateShadingInfo* shadingInfo = qsdo->shadingInfo;
+
+    CGRect bounds = CGContextGetClipBoundingBox(cgRef);
+
+    static const CGFloat domain[2] = {0.0f, 1.0f};
+    static const CGFloat range[8] = {0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f};
+    CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+    CGFunctionRef shadingFunc = NULL;
+    CGShadingRef shading = NULL;
+    if (shadingInfo->cyclic == NO)
+    {
+        static const CGFunctionCallbacks callbacks = {0, &gradientLinearPaintEvaluateFunction, &gradientPaintReleaseFunction};
+        shadingFunc = CGFunctionCreate((void *)shadingInfo, 1, domain, 4, range, &callbacks);
+        shading = CGShadingCreateAxial(colorspace, shadingInfo->start, shadingInfo->end, shadingFunc, 1, 1);
+    }
+    else
+    {
+//fprintf(stderr, "BOUNDING BOX x1=%f, y1=%f x2=%f, y2=%f\n", bounds.origin.x, bounds.origin.y, bounds.origin.x+bounds.size.width, bounds.origin.y+bounds.size.height);
+        // need to extend the line start-end
+
+        CGFloat x1 = shadingInfo->start.x;
+        CGFloat y1 = shadingInfo->start.y;
+        CGFloat x2 = shadingInfo->end.x;
+        CGFloat y2 = shadingInfo->end.y;
+//fprintf(stderr, "GIVEN x1=%f, y1=%f      x2=%f, y2=%f\n", x1, y1, x2, y2);
+
+        if (x1 == x2)
+        {
+            y1 = bounds.origin.y;
+            y2 = y1 + bounds.size.height;
+        }
+        else if (y1 == y2)
+        {
+            x1 = bounds.origin.x;
+            x2 = x1 + bounds.size.width;
+        }
+        else
+        {
+            // find the original line function y = mx + c
+            CGFloat m1 = (y2-y1)/(x2-x1);
+            CGFloat c1 = y1 - m1*x1;
+//fprintf(stderr, "         m1=%f, c1=%f\n", m1, c1);
+
+            // a line perpendicular to the original one will have the slope
+            CGFloat m2 = -(1/m1);
+//fprintf(stderr, "         m2=%f\n", m2);
+
+            // find the only 2 possible lines perpendicular to the original line, passing the two top corners of the bounding box
+            CGFloat x1A = bounds.origin.x;
+            CGFloat y1A = bounds.origin.y;
+            CGFloat c1A = y1A - m2*x1A;
+//fprintf(stderr, "         x1A=%f, y1A=%f, c1A=%f\n", x1A, y1A, c1A);
+            CGFloat x1B = bounds.origin.x+bounds.size.width;
+            CGFloat y1B = bounds.origin.y;
+            CGFloat c1B = y1B - m2*x1B;
+//fprintf(stderr, "         x1B=%f, y1B=%f, c1B=%f\n", x1B, y1B, c1B);
+
+            // find the crossing points of the original line and the two lines we computed above to find the new possible starting points
+            CGFloat x1Anew = (c1A-c1)/(m1-m2);
+            CGFloat y1Anew = m2*x1Anew + c1A;
+            CGFloat x1Bnew = (c1B-c1)/(m1-m2);
+            CGFloat y1Bnew = m2*x1Bnew + c1B;
+//fprintf(stderr, "NEW x1Anew=%f, y1Anew=%f      x1Bnew=%f, y1Bnew=%f\n", x1Anew, y1Anew, x1Bnew, y1Bnew);
+
+            // select the new starting point
+            if (y1Anew <= y1Bnew)
+            {
+                x1 = x1Anew;
+                y1 = y1Anew;
+            }
+            else
+            {
+                x1 = x1Bnew;
+                y1 = y1Bnew;
+            }
+//fprintf(stderr, "--- NEW x1=%f, y1=%f\n", x1, y1);
+
+            // find the only 2 possible lines perpendicular to the original line, passing the two bottom corners of the bounding box
+            CGFloat x2A = bounds.origin.x;
+            CGFloat y2A = bounds.origin.y+bounds.size.height;
+            CGFloat c2A = y2A - m2*x2A;
+//fprintf(stderr, "         x2A=%f, y2A=%f, c2A=%f\n", x2A, y2A, c2A);
+            CGFloat x2B = bounds.origin.x+bounds.size.width;
+            CGFloat y2B = bounds.origin.y+bounds.size.height;
+            CGFloat c2B = y2B - m2*x2B;
+//fprintf(stderr, "         x2B=%f, y2B=%f, c2B=%f\n", x2B, y2B, c2B);
+
+            // find the crossing points of the original line and the two lines we computed above to find the new possible ending points
+            CGFloat x2Anew = (c2A-c1)/(m1-m2);
+            CGFloat y2Anew = m2*x2Anew + c2A;
+            CGFloat x2Bnew = (c2B-c1)/(m1-m2);
+            CGFloat y2Bnew = m2*x2Bnew + c2B;
+//fprintf(stderr, "NEW x2Anew=%f, y2Anew=%f      x2Bnew=%f, y2Bnew=%f\n", x2Anew, y2Anew, x2Bnew, y2Bnew);
+
+            // select the new ending point
+            if (y2Anew >= y2Bnew)
+            {
+                x2 = x2Anew;
+                y2 = y2Anew;
+            }
+            else
+            {
+                x2 = x2Bnew;
+                y2 = y2Bnew;
+            }
+//fprintf(stderr, "--- NEW x2=%f, y2=%f\n", x2, y2);
+        }
+
+        qsdo->shadingInfo->period = sqrt(pow(shadingInfo->end.x-shadingInfo->start.x, 2.0) + pow(shadingInfo->end.y-shadingInfo->start.y, 2.0));
+        if ((qsdo->shadingInfo->period != 0))
+        {
+            // compute segment lengths that we will need for the gradient function
+            qsdo->shadingInfo->length = sqrt(pow(x2-x1, 2.0) + pow(y2-y1, 2.0));
+            qsdo->shadingInfo->offset = sqrt(pow(shadingInfo->start.x-x1, 2.0) + pow(shadingInfo->start.y-y1, 2.0));
+//fprintf(stderr, "length=%f, period=%f, offset=%f\n", qsdo->shadingInfo->length, qsdo->shadingInfo->period, qsdo->shadingInfo->offset);
+
+            CGPoint newStart = {x1, y1};
+            CGPoint newEnd = {x2, y2};
+
+            static const CGFunctionCallbacks callbacks = {0, &gradientCyclicPaintEvaluateFunction, &gradientPaintReleaseFunction};
+            shadingFunc = CGFunctionCreate((void *)shadingInfo, 1, domain, 4, range, &callbacks);
+            shading = CGShadingCreateAxial(colorspace, newStart, newEnd, shadingFunc, 0, 0);
+        }
+    }
+    CGColorSpaceRelease(colorspace);
+
+    if (shadingFunc != NULL)
+    {
+        CGContextSaveGState(cgRef);
+
+        // rdar://problem/5214320
+        // Gradient fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline).
+        if (qsdo->isEvenOddFill) {
+            CGContextEOClip(cgRef);
+        } else {
+            CGContextClip(cgRef);
+        }
+        CGContextDrawShading(cgRef, shading);
+
+        CGContextRestoreGState(cgRef);
+        CGShadingRelease(shading);
+        CGFunctionRelease(shadingFunc);
+        qsdo->shadingInfo = NULL;
+    }
+}
+
+#pragma mark
+#pragma mark --- Texture ---
+
+// this function MUST NOT be inlined!
+void texturePaintEvaluateFunction(void *info, CGContextRef cgRef)
+{
+    JNIEnv* env = [ThreadUtilities getJNIEnvUncached];
+
+    StatePatternInfo* patternInfo = (StatePatternInfo*)info;
+    ImageSDOps* isdo = LockImage(env, patternInfo->sdata);
+
+    makeSureImageIsCreated(isdo);
+    CGContextDrawImage(cgRef, CGRectMake(0.0f, 0.0f, patternInfo->width, patternInfo->height), isdo->imgRef);
+
+    UnlockImage(env, isdo);
+}
+
+// this function MUST NOT be inlined!
+void texturePaintReleaseFunction(void *info)
+{
+    PRINT("    texturePaintReleaseFunction")
+    JNIEnv* env = [ThreadUtilities getJNIEnvUncached];
+
+    StatePatternInfo* patternInfo = (StatePatternInfo*)info;
+    (*env)->DeleteGlobalRef(env, patternInfo->sdata);
+
+    free(info);
+}
+
+static inline void contextTexturePath(JNIEnv* env, QuartzSDOps* qsdo)
+{
+    PRINT("    ContextTexturePath")
+    CGContextRef cgRef = qsdo->cgRef;
+    StatePatternInfo* patternInfo = qsdo->patternInfo;
+
+    CGAffineTransform ctm = CGContextGetCTM(cgRef);
+    CGAffineTransform ptm = {patternInfo->sx, 0.0f, 0.0f, -patternInfo->sy, patternInfo->tx, patternInfo->ty};
+    CGAffineTransform tm = CGAffineTransformConcat(ptm, ctm);
+    CGFloat xStep = (CGFloat)qsdo->patternInfo->width;
+    CGFloat yStep = (CGFloat)qsdo->patternInfo->height;
+    CGPatternTiling tiling = kCGPatternTilingNoDistortion;
+    BOOL isColored = YES;
+    static const CGPatternCallbacks callbacks = {0, &texturePaintEvaluateFunction, &texturePaintReleaseFunction};
+    CGPatternRef pattern = CGPatternCreate((void*)patternInfo, CGRectMake(0.0f, 0.0f, xStep, yStep), tm, xStep, yStep, tiling, isColored, &callbacks);
+
+    CGColorSpaceRef colorspace = CGColorSpaceCreatePattern(NULL);
+    static const CGFloat alpha = 1.0f;
+
+    CGContextSaveGState(cgRef);
+
+    CGContextSetFillColorSpace(cgRef, colorspace);
+    CGContextSetFillPattern(cgRef, pattern, &alpha);
+    CGContextSetRGBStrokeColor(cgRef, 0.0f, 0.0f, 0.0f, 1.0f);
+    CGContextSetPatternPhase(cgRef, CGSizeMake(0.0f, 0.0f));
+    // rdar://problem/5214320
+    // Gradient fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline).
+    if (qsdo->isEvenOddFill) {
+        CGContextEOFillPath(cgRef);
+    } else {
+        CGContextFillPath(cgRef);
+    }
+
+    CGContextRestoreGState(cgRef);
+
+    CGColorSpaceRelease(colorspace);
+    CGPatternRelease(pattern);
+
+    qsdo->patternInfo = NULL;
+}
+
+#pragma mark
+#pragma mark --- Context Setup ---
+
+static inline void setDefaultColorSpace(CGContextRef cgRef)
+{
+    static CGColorSpaceRef colorspace = NULL;
+    if (colorspace == NULL)
+    {
+        colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+    }
+    CGContextSetStrokeColorSpace(cgRef, colorspace);
+    CGContextSetFillColorSpace(cgRef, colorspace);
+}
+
+void SetUpCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType)
+{
+PRINT(" SetUpCGContext")
+    CGContextRef cgRef = qsdo->cgRef;
+//fprintf(stderr, "%p ", cgRef);
+    jint *javaGraphicsStates = qsdo->javaGraphicsStates;
+    jfloat *javaFloatGraphicsStates = (jfloat*)(qsdo->javaGraphicsStates);
+
+    jint changeFlags            = javaGraphicsStates[sun_java2d_OSXSurfaceData_kChangeFlagIndex];
+    BOOL everyThingChanged        = qsdo->newContext || (changeFlags == sun_java2d_OSXSurfaceData_kEverythingChangedFlag);
+    BOOL clipChanged            = everyThingChanged || ((changeFlags&sun_java2d_OSXSurfaceData_kClipChangedBit) != 0);
+    BOOL transformChanged        = everyThingChanged || ((changeFlags&sun_java2d_OSXSurfaceData_kCTMChangedBit) != 0);
+    BOOL paintChanged            = everyThingChanged || ((changeFlags&sun_java2d_OSXSurfaceData_kColorChangedBit) != 0);
+    BOOL compositeChanged        = everyThingChanged || ((changeFlags&sun_java2d_OSXSurfaceData_kCompositeChangedBit) != 0);
+    BOOL strokeChanged            = everyThingChanged || ((changeFlags&sun_java2d_OSXSurfaceData_kStrokeChangedBit) != 0);
+//    BOOL fontChanged            = everyThingChanged || ((changeFlags&sun_java2d_OSXSurfaceData_kFontChangedBit) != 0);
+    BOOL renderingHintsChanged  = everyThingChanged || ((changeFlags&sun_java2d_OSXSurfaceData_kHintsChangedBit) != 0);
+
+//fprintf(stderr, "SetUpCGContext cgRef=%p new=%d changeFlags=%d, everyThingChanged=%d clipChanged=%d transformChanged=%d\n",
+//                    cgRef, qsdo->newContext, changeFlags, everyThingChanged, clipChanged, transformChanged);
+
+    if ((everyThingChanged == YES) || (clipChanged == YES) || (transformChanged == YES))
+    {
+        everyThingChanged = YES; // in case clipChanged or transformChanged
+
+        CGContextRestoreGState(cgRef);  // restore to the original state
+
+        CGContextSaveGState(cgRef);        // make our local copy of the state
+
+        setDefaultColorSpace(cgRef);
+    }
+
+    if ((everyThingChanged == YES) || (clipChanged == YES))
+    {
+        if (javaGraphicsStates[sun_java2d_OSXSurfaceData_kClipStateIndex] == sun_java2d_OSXSurfaceData_kClipRect)
+        {
+            CGFloat x = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kClipXIndex];
+            CGFloat y = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kClipYIndex];
+            CGFloat w = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kClipWidthIndex];
+            CGFloat h = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kClipHeightIndex];
+            CGContextClipToRect(cgRef, CGRectMake(x, y, w, h));
+        }
+        else
+        {
+            BOOL eoFill = (javaGraphicsStates[sun_java2d_OSXSurfaceData_kClipWindingRuleIndex] == java_awt_geom_PathIterator_WIND_EVEN_ODD);
+            jint numtypes = javaGraphicsStates[sun_java2d_OSXSurfaceData_kClipNumTypesIndex];
+
+            jobject coordsarray = (jobject)((*env)->GetObjectArrayElement(env, qsdo->javaGraphicsStatesObjects, sun_java2d_OSXSurfaceData_kClipCoordinatesIndex));
+            jobject typesarray = (jobject)((*env)->GetObjectArrayElement(env, qsdo->javaGraphicsStatesObjects, sun_java2d_OSXSurfaceData_kClipTypesIndex));
+
+            jfloat* coords = (jfloat*)(*env)->GetDirectBufferAddress(env, coordsarray);
+            jint* types = (jint*)(*env)->GetDirectBufferAddress(env, typesarray);
+
+            DoShapeUsingCG(cgRef, types, coords, numtypes, NO, qsdo->graphicsStateInfo.offsetX, qsdo->graphicsStateInfo.offsetY);
+
+            if (CGContextIsPathEmpty(cgRef) == 0)
+            {
+                if (eoFill)
+                {
+                    CGContextEOClip(cgRef);
+                }
+                else
+                {
+                    CGContextClip(cgRef);
+                }
+            }
+            else
+            {
+                CGContextClipToRect(cgRef, CGRectZero);
+            }
+        }
+    }
+// for debugging
+//CGContextResetClip(cgRef);
+
+    if ((everyThingChanged == YES) || (transformChanged == YES))
+    {
+        CGFloat a = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMaIndex];
+        CGFloat b = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMbIndex];
+        CGFloat c = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMcIndex];
+        CGFloat d = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMdIndex];
+        CGFloat tx = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMtxIndex];
+        CGFloat ty = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMtyIndex];
+
+        CGContextConcatCTM(cgRef, CGAffineTransformMake(a, b, c, d, tx, ty));
+
+        if (gAdjustForJavaDrawing == YES)
+        {
+            // find the offsets in the device corrdinate system
+            CGAffineTransform ctm = CGContextGetCTM(cgRef);
+            if ((qsdo->graphicsStateInfo.ctm.a != ctm.a) ||
+                    (qsdo->graphicsStateInfo.ctm.b != ctm.b) ||
+                        (qsdo->graphicsStateInfo.ctm.c != ctm.c) ||
+                            (qsdo->graphicsStateInfo.ctm.d != ctm.d))
+            {
+                qsdo->graphicsStateInfo.ctm = ctm;
+                // In CG affine xforms y' = bx+dy+ty
+                // We need to flip both y coefficeints to flip the offset point into the java coordinate system.
+                ctm.b = -ctm.b; ctm.d = -ctm.d; ctm.tx = 0.0f; ctm.ty = 0.0f;
+                CGPoint offsets = {kOffset, kOffset};
+                offsets = CGPointApplyInverseAffineTransform(offsets, ctm);
+                qsdo->graphicsStateInfo.offsetX = offsets.x;
+                qsdo->graphicsStateInfo.offsetY = offsets.y;
+            }
+        }
+        else
+        {
+            qsdo->graphicsStateInfo.offsetX = 0.0f;
+            qsdo->graphicsStateInfo.offsetY = 0.0f;
+        }
+    }
+
+// for debugging
+//CGContextResetCTM(cgRef);
+
+    if ((everyThingChanged == YES) || (compositeChanged == YES))
+    {
+        jint alphaCompositeRule = javaGraphicsStates[sun_java2d_OSXSurfaceData_kCompositeRuleIndex];
+        CGFloat alphaCompositeValue = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCompositeValueIndex];
+
+        NSCompositingOperation op;
+        switch (alphaCompositeRule)
+        {
+                case java_awt_AlphaComposite_CLEAR:
+                op = NSCompositeClear;
+                break;
+            case java_awt_AlphaComposite_SRC:
+                op = NSCompositeCopy;
+                break;
+            case java_awt_AlphaComposite_SRC_OVER:
+                op = NSCompositeSourceOver;
+                break;
+            case java_awt_AlphaComposite_DST_OVER:
+                op = NSCompositeDestinationOver;
+                break;
+            case java_awt_AlphaComposite_SRC_IN:
+                op = NSCompositeSourceIn;
+                break;
+            case java_awt_AlphaComposite_DST_IN:
+                op = NSCompositeDestinationIn;
+                break;
+            case java_awt_AlphaComposite_SRC_OUT:
+                op = NSCompositeSourceOut;
+                break;
+            case java_awt_AlphaComposite_DST_OUT:
+                op = NSCompositeDestinationOut;
+                break;
+            case java_awt_AlphaComposite_DST:
+                // Alpha must be set to 0 because we're using the kCGCompositeSover rule
+                op = NSCompositeSourceOver;
+                alphaCompositeValue = 0.0f;
+                break;
+            case java_awt_AlphaComposite_SRC_ATOP:
+                op = NSCompositeSourceAtop;
+                break;
+            case java_awt_AlphaComposite_DST_ATOP:
+                op = NSCompositeDestinationAtop;
+                break;
+            case java_awt_AlphaComposite_XOR:
+                op = NSCompositeXOR;
+                break;
+            default:
+                op = NSCompositeSourceOver;
+                alphaCompositeValue = 1.0f;
+                break;
+        }
+
+        NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithGraphicsPort:cgRef flipped:NO];
+        //CGContextSetCompositeOperation(cgRef, op);
+        [context setCompositingOperation:op];
+        CGContextSetAlpha(cgRef, alphaCompositeValue);
+    }
+
+    if ((everyThingChanged == YES) || (renderingHintsChanged == YES))
+    {
+        jint antialiasHint = javaGraphicsStates[sun_java2d_OSXSurfaceData_kHintsAntialiasIndex];
+//        jint textAntialiasHint = javaGraphicsStates[sun_java2d_OSXSurfaceData_kHintsTextAntialiasIndex];
+        jint renderingHint = javaGraphicsStates[sun_java2d_OSXSurfaceData_kHintsRenderingIndex];
+        jint interpolationHint = javaGraphicsStates[sun_java2d_OSXSurfaceData_kHintsInterpolationIndex];
+//        jint textFractionalMetricsHint = javaGraphicsStates[sun_java2d_OSXSurfaceData_kHintsFractionalMetricsIndex];
+
+        // 10-10-02 VL: since CoreGraphics supports only an interpolation quality attribute we have to map
+        // both interpolationHint and renderingHint to an attribute value that best represents their combination.
+        // (See Radar 3071704.) We'll go for the best quality. CG maps interpolation quality values as follows:
+        // kCGInterpolationNone - nearest_neighbor
+        // kCGInterpolationLow - bilinear
+        // kCGInterpolationHigh - Lanczos (better than bicubic)
+        CGInterpolationQuality interpolationQuality = kCGInterpolationDefault;
+        // First check if the interpolation hint is suggesting to turn off interpolation:
+        if (interpolationHint == sun_awt_SunHints_INTVAL_INTERPOLATION_NEAREST_NEIGHBOR)
+        {
+            interpolationQuality = kCGInterpolationNone;
+        }
+        else if ((interpolationHint >= sun_awt_SunHints_INTVAL_INTERPOLATION_BICUBIC) || (renderingHint >= sun_awt_SunHints_INTVAL_RENDER_QUALITY))
+        {
+            // Use >= just in case Sun adds some hint values in the future - this check wouldn't fall apart then:
+            interpolationQuality = kCGInterpolationHigh;
+        }
+        else if (interpolationHint == sun_awt_SunHints_INTVAL_INTERPOLATION_BILINEAR)
+        {
+            interpolationQuality = kCGInterpolationLow;
+        }
+        else if (renderingHint == sun_awt_SunHints_INTVAL_RENDER_SPEED)
+        {
+            interpolationQuality = kCGInterpolationNone;
+        }
+        // else interpolationHint == -1 || renderingHint == sun_awt_SunHints_INTVAL_CSURFACE_DEFAULT --> kCGInterpolationDefault
+        CGContextSetInterpolationQuality(cgRef, interpolationQuality);
+        qsdo->graphicsStateInfo.interpolation = interpolationQuality;
+
+        // antialiasing
+        BOOL antialiased = (antialiasHint == sun_awt_SunHints_INTVAL_ANTIALIAS_ON);
+        CGContextSetShouldAntialias(cgRef, antialiased);
+        qsdo->graphicsStateInfo.antialiased = antialiased;
+    }
+
+    if ((everyThingChanged == YES) || (strokeChanged == YES))
+    {
+        qsdo->graphicsStateInfo.simpleStroke = YES;
+
+        CGFloat linewidth = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kStrokeWidthIndex];
+        jint linejoin = javaGraphicsStates[sun_java2d_OSXSurfaceData_kStrokeJoinIndex];
+        jint linecap = javaGraphicsStates[sun_java2d_OSXSurfaceData_kStrokeCapIndex];
+        CGFloat miterlimit = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kStrokeLimitIndex];
+        jobject dasharray = ((*env)->GetObjectArrayElement(env, qsdo->javaGraphicsStatesObjects, sun_java2d_OSXSurfaceData_kStrokeDashArrayIndex));
+        CGFloat dashphase = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kStrokeDashPhaseIndex];
+
+        if (linewidth == 0.0f)
+        {
+            linewidth = (CGFloat)-109.05473e+14; // Don't ask !
+        }
+        CGContextSetLineWidth(cgRef, linewidth);
+
+        CGLineCap cap;
+        switch (linecap)
+        {
+            case java_awt_BasicStroke_CAP_BUTT:
+                qsdo->graphicsStateInfo.simpleStroke = NO;
+                cap = kCGLineCapButt;
+                break;
+            case java_awt_BasicStroke_CAP_ROUND:
+                qsdo->graphicsStateInfo.simpleStroke = NO;
+                cap = kCGLineCapRound;
+                break;
+            case java_awt_BasicStroke_CAP_SQUARE:
+            default:
+                cap = kCGLineCapSquare;
+                break;
+        }
+        CGContextSetLineCap(cgRef, cap);
+
+        CGLineJoin join;
+        switch (linejoin)
+        {
+            case java_awt_BasicStroke_JOIN_ROUND:
+                qsdo->graphicsStateInfo.simpleStroke = NO;
+                join = kCGLineJoinRound;
+                break;
+            case java_awt_BasicStroke_JOIN_BEVEL:
+                qsdo->graphicsStateInfo.simpleStroke = NO;
+                join = kCGLineJoinBevel;
+                break;
+            case java_awt_BasicStroke_JOIN_MITER:
+            default:
+                join = kCGLineJoinMiter;
+                break;
+        }
+        CGContextSetLineJoin(cgRef, join);
+        CGContextSetMiterLimit(cgRef, miterlimit);
+
+        if (dasharray != NULL)
+        {
+            qsdo->graphicsStateInfo.simpleStroke = NO;
+            jint length = (*env)->GetArrayLength(env, dasharray);
+            jfloat* jdashes = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, dasharray, NULL);
+            CGFloat* dashes = (CGFloat*)malloc(sizeof(CGFloat)*length);
+            if (dashes != NULL)
+            {
+                jint i;
+                for (i=0; i<length; i++)
+                {
+                    dashes[i] = (CGFloat)jdashes[i];
+                }
+            }
+            else
+            {
+                dashphase = 0;
+                length = 0;
+            }
+            CGContextSetLineDash(cgRef, dashphase, dashes, length);
+            if (dashes != NULL)
+            {
+                free(dashes);
+            }
+            (*env)->ReleasePrimitiveArrayCritical(env, dasharray, jdashes, 0);
+        }
+        else
+        {
+            CGContextSetLineDash(cgRef, 0, NULL, 0);
+        }
+    }
+
+    BOOL cocoaPaint = (javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorStateIndex] == sun_java2d_OSXSurfaceData_kColorSystem);
+    BOOL complexPaint = (javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorStateIndex] == sun_java2d_OSXSurfaceData_kColorGradient) ||
+                        (javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorStateIndex] == sun_java2d_OSXSurfaceData_kColorTexture);
+    if ((everyThingChanged == YES) || (paintChanged == YES) || (cocoaPaint == YES) || (complexPaint == YES))
+    {
+        // rdar://problem/5214320
+        // Gradient fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline).
+        // Notice the side effect of the stmt after this if-block.
+        if (renderType == SD_EOFill) {
+            qsdo->isEvenOddFill = YES;
+        }
+
+        renderType = SetUpPaint(env, qsdo, renderType);
+    }
+
+    qsdo->renderType = renderType;
+}
+
+SDRenderType SetUpPaint(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType)
+{
+    CGContextRef cgRef = qsdo->cgRef;
+
+    jint *javaGraphicsStates = qsdo->javaGraphicsStates;
+    jfloat *javaFloatGraphicsStates = (jfloat*)(qsdo->javaGraphicsStates);
+
+    static const CGFloat kColorConversionMultiplier = 1.0f/255.0f;
+    jint colorState = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorStateIndex];
+
+    switch (colorState)
+    {
+        case sun_java2d_OSXSurfaceData_kColorSimple:
+        {
+            if (qsdo->graphicsStateInfo.simpleColor == NO)
+            {
+                setDefaultColorSpace(cgRef);
+            }
+            qsdo->graphicsStateInfo.simpleColor = YES;
+
+            // sets the color on the CGContextRef (CGContextSetStrokeColorWithColor/CGContextSetFillColorWithColor)
+            setCachedColor(qsdo, javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorRGBValueIndex]);
+
+            break;
+        }
+        case sun_java2d_OSXSurfaceData_kColorSystem:
+        {
+            qsdo->graphicsStateInfo.simpleStroke = NO;
+            // All our custom Colors are NSPatternColorSpace so we are complex colors!
+            qsdo->graphicsStateInfo.simpleColor = NO;
+
+            NSColor *color = nil;
+            /* TODO:BG
+            {
+                color = getColor(javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorIndexValueIndex]);
+            }
+            */
+            [color set];
+            break;
+        }
+        case sun_java2d_OSXSurfaceData_kColorGradient:
+        {
+            qsdo->shadingInfo = (StateShadingInfo*)malloc(sizeof(StateShadingInfo));
+            if (qsdo->shadingInfo == NULL)
+            {
+                [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for gradient paint"];
+            }
+
+            qsdo->graphicsStateInfo.simpleStroke = NO;
+            qsdo->graphicsStateInfo.simpleColor = NO;
+
+            renderType = SD_Shade;
+
+            qsdo->shadingInfo->start.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx1Index];
+            qsdo->shadingInfo->start.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory1Index];
+            qsdo->shadingInfo->end.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx2Index];
+            qsdo->shadingInfo->end.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory2Index];
+            jint c1 = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorRGBValue1Index];
+            qsdo->shadingInfo->colors[0] = ((c1>>16)&0xff)*kColorConversionMultiplier;
+            qsdo->shadingInfo->colors[1] = ((c1>>8)&0xff)*kColorConversionMultiplier;
+            qsdo->shadingInfo->colors[2] = ((c1>>0)&0xff)*kColorConversionMultiplier;
+            qsdo->shadingInfo->colors[3] = ((c1>>24)&0xff)*kColorConversionMultiplier;
+            jint c2 = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorRGBValue2Index];
+            qsdo->shadingInfo->colors[4] = ((c2>>16)&0xff)*kColorConversionMultiplier;
+            qsdo->shadingInfo->colors[5] = ((c2>>8)&0xff)*kColorConversionMultiplier;
+            qsdo->shadingInfo->colors[6] = ((c2>>0)&0xff)*kColorConversionMultiplier;
+            qsdo->shadingInfo->colors[7] = ((c2>>24)&0xff)*kColorConversionMultiplier;
+            qsdo->shadingInfo->cyclic    = (javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorIsCyclicIndex] == sun_java2d_OSXSurfaceData_kColorCyclic);
+
+            break;
+        }
+        case sun_java2d_OSXSurfaceData_kColorTexture:
+        {
+            qsdo->patternInfo = (StatePatternInfo*)malloc(sizeof(StatePatternInfo));
+            if (qsdo->patternInfo == NULL)
+            {
+                [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for texture paint"];
+            }
+
+            qsdo->graphicsStateInfo.simpleStroke = NO;
+            qsdo->graphicsStateInfo.simpleColor = NO;
+
+            renderType = SD_Pattern;
+
+            qsdo->patternInfo->tx        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColortxIndex];
+            qsdo->patternInfo->ty        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColortyIndex];
+            qsdo->patternInfo->sx        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorsxIndex];
+            if (qsdo->patternInfo->sx == 0.0f)
+            {
+                return SD_Fill; // 0 is an invalid value, fill argb rect
+            }
+            qsdo->patternInfo->sy        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorsyIndex];
+            if (qsdo->patternInfo->sy == 0.0f)
+            {
+                return SD_Fill; // 0 is an invalid value, fill argb rect
+            }
+            qsdo->patternInfo->width    = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorWidthIndex];
+            qsdo->patternInfo->height    = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorHeightIndex];
+
+            jobject sData = ((*env)->GetObjectArrayElement(env, qsdo->javaGraphicsStatesObjects, sun_java2d_OSXSurfaceData_kTextureImageIndex)); //deleted next time through SetUpPaint and not before ( radr://3913190 )
+            if (sData != NULL)
+            {
+                qsdo->patternInfo->sdata = (*env)->NewGlobalRef(env, sData);
+                if (qsdo->patternInfo->sdata == NULL)
+                {
+                    renderType = SD_Fill;
+                }
+            }
+            else
+            {
+                renderType = SD_Fill;
+            }
+
+            break;
+        }
+    }
+
+    return renderType;
+}
+
+#pragma mark
+#pragma mark --- Shape Drawing Code ---
+
+SDRenderType DoShapeUsingCG(CGContextRef cgRef, jint *types, jfloat *coords, jint numtypes, BOOL fill, CGFloat offsetX, CGFloat offsetY)
+{
+//fprintf(stderr, "DoShapeUsingCG fill=%d\n", (jint)fill);
+    SDRenderType renderType = SD_Nothing;
+
+    if (gAdjustForJavaDrawing != YES)
+    {
+        offsetX = 0.0f;
+        offsetY = 0.0f;
+    }
+
+    if (fill == YES)
+    {
+        renderType = SD_Fill;
+    }
+    else
+    {
+        renderType = SD_Stroke;
+    }
+
+    if (numtypes > 0)
+    {
+        BOOL needNewSubpath = NO;
+
+        CGContextBeginPath(cgRef); // create new path
+//fprintf(stderr, "    CGContextBeginPath\n");
+
+        jint index = 0;
+        CGFloat mx = 0.0f, my = 0.0f, x1 = 0.0f, y1 = 0.0f, cpx1 = 0.0f, cpy1 = 0.0f, cpx2 = 0.0f, cpy2 = 0.0f;
+        jint i;
+
+        mx = (CGFloat)coords[index++] + offsetX;
+        my = (CGFloat)coords[index++] + offsetY;
+        CGContextMoveToPoint(cgRef, mx, my);
+
+        for (i=1; i<numtypes; i++)
+        {
+            jint pathType = types[i];
+
+            if (needNewSubpath == YES)
+            {
+                needNewSubpath = NO;
+                switch (pathType)
+                {
+                    case java_awt_geom_PathIterator_SEG_LINETO:
+                    case java_awt_geom_PathIterator_SEG_QUADTO:
+                    case java_awt_geom_PathIterator_SEG_CUBICTO:
+//fprintf(stderr, "    forced CGContextMoveToPoint (%f, %f)\n", mx, my);
+                        CGContextMoveToPoint(cgRef, mx, my); // force new subpath
+                        break;
+                }
+            }
+
+            switch (pathType)
+            {
+                case java_awt_geom_PathIterator_SEG_MOVETO:
+                    mx = x1 = (CGFloat)coords[index++] + offsetX;
+                    my = y1 = (CGFloat)coords[index++] + offsetY;
+                    CGContextMoveToPoint(cgRef, x1, y1); // start new subpath
+//fprintf(stderr, "    SEG_MOVETO CGContextMoveToPoint (%f, %f)\n", x1, y1);
+                    break;
+                case java_awt_geom_PathIterator_SEG_LINETO:
+                    x1 = (CGFloat)coords[index++] + offsetX;
+                    y1 = (CGFloat)coords[index++] + offsetY;
+                    CGContextAddLineToPoint(cgRef, x1, y1);
+//fprintf(stderr, "    SEG_LINETO CGContextAddLineToPoint (%f, %f)\n", x1, y1);
+                    break;
+                case java_awt_geom_PathIterator_SEG_QUADTO:
+                    cpx1 = (CGFloat)coords[index++] + offsetX;
+                    cpy1 = (CGFloat)coords[index++] + offsetY;
+                    x1 = (CGFloat)coords[index++] + offsetX;
+                    y1 = (CGFloat)coords[index++]+ offsetY;
+                    CGContextAddQuadCurveToPoint(cgRef, cpx1, cpy1, x1, y1);
+//fprintf(stderr, "    SEG_QUADTO CGContextAddQuadCurveToPoint (%f, %f), (%f, %f)\n", cpx1, cpy1, x1, y1);
+                    break;
+                case java_awt_geom_PathIterator_SEG_CUBICTO:
+                    cpx1 = (CGFloat)coords[index++] + offsetX;
+                    cpy1 = (CGFloat)coords[index++] + offsetY;
+                    cpx2 = (CGFloat)coords[index++] + offsetX;
+                    cpy2 = (CGFloat)coords[index++] + offsetY;
+                    x1 = (CGFloat)coords[index++] + offsetX;
+                    y1 = (CGFloat)coords[index++] + offsetY;
+                    CGContextAddCurveToPoint(cgRef, cpx1, cpy1, cpx2, cpy2, x1, y1);
+//fprintf(stderr, "    SEG_CUBICTO CGContextAddCurveToPoint (%f, %f), (%f, %f), (%f, %f)\n", cpx1, cpy1, cpx2, cpy2, x1, y1);
+                    break;
+                case java_awt_geom_PathIterator_SEG_CLOSE:
+                    CGContextClosePath(cgRef); // close subpath
+                    needNewSubpath = YES;
+//fprintf(stderr, "    SEG_CLOSE CGContextClosePath\n");
+                    break;
+            }
+        }
+    }
+
+    return renderType;
+}
+
+void CompleteCGContext(JNIEnv *env, QuartzSDOps *qsdo)
+{
+PRINT(" CompleteCGContext")
+    switch (qsdo->renderType)
+    {
+        case SD_Nothing:
+            break;
+
+        case SD_Stroke:
+            if (CGContextIsPathEmpty(qsdo->cgRef) == 0)
+            {
+                CGContextStrokePath(qsdo->cgRef);
+            }
+            break;
+
+        case SD_Fill:
+            if (CGContextIsPathEmpty(qsdo->cgRef) == 0)
+            {
+                CGContextFillPath(qsdo->cgRef);
+            }
+            break;
+
+        case SD_Shade:
+            if (CGContextIsPathEmpty(qsdo->cgRef) == 0)
+            {
+                contextGradientPath(qsdo);
+            }
+            break;
+
+        case SD_Pattern:
+            if (CGContextIsPathEmpty(qsdo->cgRef) == 0)
+            {
+                //TODO:BG
+                //contextTexturePath(env, qsdo);
+            }
+            break;
+
+        case SD_EOFill:
+            if (CGContextIsPathEmpty(qsdo->cgRef) == 0)
+            {
+                CGContextEOFillPath(qsdo->cgRef);
+            }
+            break;
+
+        case SD_Image:
+            break;
+
+        case SD_Text:
+            break;
+
+        case SD_CopyArea:
+            break;
+
+        case SD_Queue:
+            break;
+
+        case SD_External:
+            break;
+    }
+
+    if (qsdo->shadingInfo != NULL) {
+        gradientPaintReleaseFunction(qsdo->shadingInfo);
+        qsdo->shadingInfo = NULL;
+    }
+}
diff --git a/jdk/src/macosx/native/sun/awt/awt.m b/jdk/src/macosx/native/sun/awt/awt.m
new file mode 100644
index 0000000..50e34c3
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/awt.m
@@ -0,0 +1,451 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <pthread.h>
+#import <objc/runtime.h>
+#import <Cocoa/Cocoa.h>
+#import <Security/AuthSession.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "NSApplicationAWT.h"
+#import "PropertiesUtilities.h"
+#import "ThreadUtilities.h"
+#import "AWT_debug.h"
+#import "ApplicationDelegate.h"
+
+#define DEBUG 0
+
+
+// The symbol is defined in libosxapp.dylib (ThreadUtilities.m)
+extern JavaVM *jvm;
+
+static bool ShouldPrintVerboseDebugging() {
+    static int debug = -1;
+    if (debug == -1) {
+        debug = (int)(getenv("JAVA_AWT_VERBOSE") != NULL) || (DEBUG != 0);
+    }
+    return (bool)debug;
+}
+
+// This is the data necessary to have JNI_OnLoad wait for AppKit to start.
+static BOOL sAppKitStarted = NO;
+static pthread_mutex_t sAppKitStarted_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t sAppKitStarted_cv = PTHREAD_COND_INITIALIZER;
+
+void setBusy(BOOL isBusy);
+static void BusyObserver(CFRunLoopObserverRef ref, CFRunLoopActivity what, void* arg);
+static void NotBusyObserver(CFRunLoopObserverRef ref, CFRunLoopActivity what, void* arg);
+static void AWT_NSUncaughtExceptionHandler(NSException *exception);
+
+static CFRunLoopObserverRef busyObserver = NULL;
+static CFRunLoopObserverRef notBusyObserver = NULL;
+
+static void setUpAWTAppKit(BOOL swt_mode, BOOL headless) {
+AWT_ASSERT_APPKIT_THREAD;
+    BOOL verbose = ShouldPrintVerboseDebugging();
+    if (verbose) AWT_DEBUG_LOG(@"setting up busy observers");
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    // Add CFRunLoopObservers to call into AWT so that AWT knows that the
+    //  AWT thread (which is the AppKit main thread) is alive. This way AWT
+    //  will not automatically shutdown.
+    busyObserver = CFRunLoopObserverCreate(
+                        NULL,                        // CFAllocator
+                        kCFRunLoopAfterWaiting,      // CFOptionFlags
+                        true,                        // repeats
+                        NSIntegerMax,                // order
+                        &BusyObserver,               // CFRunLoopObserverCallBack
+                        NULL);                       // CFRunLoopObserverContext
+
+    notBusyObserver = CFRunLoopObserverCreate(
+                        NULL,                        // CFAllocator
+                        kCFRunLoopBeforeWaiting,     // CFOptionFlags
+                        true,                        // repeats
+                        NSIntegerMin,                // order
+                        &NotBusyObserver,            // CFRunLoopObserverCallBack
+                        NULL);                       // CFRunLoopObserverContext
+
+    CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
+    CFRunLoopAddObserver(runLoop, busyObserver, kCFRunLoopDefaultMode);
+    CFRunLoopAddObserver(runLoop, notBusyObserver, kCFRunLoopDefaultMode);
+
+    CFRelease(busyObserver);
+    CFRelease(notBusyObserver);
+
+    if (!headless) setBusy(YES);
+
+    // Set the java name of the AppKit main thread appropriately.
+    jclass threadClass = NULL;
+    jstring name = NULL;
+    jobject curThread = NULL;
+
+    if (!swt_mode) {
+        threadClass = (*env)->FindClass(env, "java/lang/Thread");
+        if (threadClass == NULL || (*env)->ExceptionCheck(env)) goto cleanup;
+        jmethodID currentThreadID = (*env)->GetStaticMethodID(env, threadClass, "currentThread", "()Ljava/lang/Thread;");
+        if (currentThreadID == NULL || (*env)->ExceptionCheck(env)) goto cleanup;
+        jmethodID setName = (*env)->GetMethodID(env, threadClass, "setName", "(Ljava/lang/String;)V");
+        if (setName == NULL || (*env)->ExceptionCheck(env)) goto cleanup;
+
+        curThread = (*env)->CallStaticObjectMethod(env, threadClass, currentThreadID); // AWT_THREADING Safe (known object)
+        if (curThread == NULL || (*env)->ExceptionCheck(env)) goto cleanup;
+        name = (*env)->NewStringUTF(env, "AWT-AppKit");
+        if (name == NULL || (*env)->ExceptionCheck(env)) goto cleanup;
+        (*env)->CallVoidMethod(env, curThread, setName, name); // AWT_THREADING Safe (known object)
+        if ((*env)->ExceptionCheck(env)) goto cleanup;
+    }
+
+cleanup:
+    if (threadClass != NULL) {
+        (*env)->DeleteLocalRef(env, threadClass);
+    }
+    if (name != NULL) {
+        (*env)->DeleteLocalRef(env, name);
+    }
+    if (curThread != NULL) {
+        (*env)->DeleteLocalRef(env, curThread);
+    }
+    if ((*env)->ExceptionCheck(env)) {
+        (*env)->ExceptionDescribe(env);
+        (*env)->ExceptionClear(env);
+    }
+
+    // Add the exception handler of last resort
+    NSSetUncaughtExceptionHandler(AWT_NSUncaughtExceptionHandler);
+
+    if (verbose) AWT_DEBUG_LOG(@"finished setting thread name");
+}
+
+
+
+// Returns true if java believes it is running headless
+BOOL isHeadless(JNIEnv *env) {
+    // Just access the property directly, instead of using GraphicsEnvironment.isHeadless.
+    //  This is because this may be called while AWT is being loaded, and calling AWT
+    //  while it is being loaded will deadlock.
+    static JNF_CLASS_CACHE(jc_Toolkit, "java/awt/GraphicsEnvironment");
+    static JNF_STATIC_MEMBER_CACHE(jm_isHeadless, jc_Toolkit, "isHeadless", "()Z");
+    return JNFCallStaticBooleanMethod(env, jm_isHeadless);
+}
+
+BOOL isSWTInWebStart(JNIEnv* env) {
+    NSString *swtWebStart = [PropertiesUtilities javaSystemPropertyForKey:@"com.apple.javaws.usingSWT" withEnv:env];
+    return [@"true" isCaseInsensitiveLike:swtWebStart];
+}
+
+void setBusy(BOOL busy) {
+AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_CLASS_CACHE(jc_AWTAutoShutdown, "sun/awt/AWTAutoShutdown");
+
+    if (busy) {
+        static JNF_STATIC_MEMBER_CACHE(jm_notifyBusyMethod, jc_AWTAutoShutdown, "notifyToolkitThreadBusy", "()V");
+        JNFCallStaticVoidMethod(env, jm_notifyBusyMethod);
+    } else {
+        static JNF_STATIC_MEMBER_CACHE(jm_notifyFreeMethod, jc_AWTAutoShutdown, "notifyToolkitThreadFree", "()V");
+        JNFCallStaticVoidMethod(env, jm_notifyFreeMethod);
+    }
+}
+
+static void BusyObserver(CFRunLoopObserverRef ref, CFRunLoopActivity what, void* arg) {
+AWT_ASSERT_APPKIT_THREAD;
+
+    // This is only called with the selector kCFRunLoopAfterWaiting.
+#ifndef PRODUCT_BUILD
+    assert(what == kCFRunLoopAfterWaiting);
+#endif /* PRODUCT_BUILD */
+
+    setBusy(YES);
+}
+
+static void NotBusyObserver(CFRunLoopObserverRef ref, CFRunLoopActivity what, void* arg) {
+AWT_ASSERT_APPKIT_THREAD;
+
+    // This is only called with the selector kCFRunLoopBeforeWaiting.
+#ifndef PRODUCT_BUILD
+    assert(what == kCFRunLoopBeforeWaiting);
+#endif /* PRODUCT_BUILD */
+
+    setBusy(NO);
+}
+
+static void AWT_NSUncaughtExceptionHandler(NSException *exception) {
+    NSLog(@"Apple AWT Internal Exception: %@", [exception description]);
+}
+
+// This is an empty Obj-C object just so that -peformSelectorOnMainThread can be used.
+@interface AWTStarter : NSObject { }
++ (void)start:(BOOL)headless swtMode:(BOOL)swtMode swtModeForWebStart:(BOOL)swtModeForWebStart;
+- (void)starter:(NSArray*)args;
++ (void)appKitIsRunning:(id)arg;
+@end
+
+@implementation AWTStarter
+
++ (BOOL) isConnectedToWindowServer {
+    SecuritySessionId session_id;
+    SessionAttributeBits session_info;
+    OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
+    if (status != noErr) return NO;
+    if (!(session_info & sessionHasGraphicAccess)) return NO;
+    return YES;
+}
+
++ (BOOL) markAppAsDaemon {
+    id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT");
+    SEL markAppSel = @selector(markAppIsDaemon);
+    if (![jrsAppKitAWTClass respondsToSelector:markAppSel]) return NO;
+    return (BOOL)[jrsAppKitAWTClass performSelector:markAppSel];
+}
+
++ (void)appKitIsRunning:(id)arg {
+    // Headless: NO
+    // Embedded: BOTH
+    // Multiple Calls: NO
+    //  Callers: AppKit's NSApplicationDidFinishLaunchingNotification or +[AWTStarter startAWT:]
+AWT_ASSERT_APPKIT_THREAD;
+
+    BOOL verbose = ShouldPrintVerboseDebugging();
+    if (verbose) AWT_DEBUG_LOG(@"about to message AppKit started");
+
+    // Signal that AppKit has started (or is already running).
+    pthread_mutex_lock(&sAppKitStarted_mutex);
+    sAppKitStarted = YES;
+    pthread_cond_signal(&sAppKitStarted_cv);
+    pthread_mutex_unlock(&sAppKitStarted_mutex);
+
+    if (verbose) AWT_DEBUG_LOG(@"finished messaging AppKit started");
+}
+
++ (void)start:(BOOL)headless swtMode:(BOOL)swtMode swtModeForWebStart:(BOOL)swtModeForWebStart
+{
+    BOOL verbose = ShouldPrintVerboseDebugging();
+
+    // Headless: BOTH
+    // Embedded: BOTH
+    // Multiple Calls: NO
+    //  Caller: JNI_OnLoad
+
+    // onMainThread is NOT the same at SWT mode!
+    // If the JVM was started on the first thread for SWT, but the SWT loads the AWT on a secondary thread,
+    // onMainThread here will be false but SWT mode will be true.  If we are currently on the main thread, we don't
+    // need to throw AWT startup over to another thread.
+    BOOL onMainThread = (pthread_main_np() != 0);
+
+    if (verbose) {
+        NSString *msg = [NSString stringWithFormat:@"+[AWTStarter start headless:%d swtMode:%d swtModeForWebStart:%d] { onMainThread:%d }", headless, swtMode, swtModeForWebStart, onMainThread];
+        AWT_DEBUG_LOG(msg);
+    }
+
+    if (!headless)
+    {
+        // Listen for the NSApp to start. This indicates that JNI_OnLoad can proceed.
+        //  It must wait because there is a chance that another java thread will grab
+        //  the AppKit lock before the +[NSApplication sharedApplication] returns.
+        //  See <rdar://problem/3492666> for an example.
+        [[NSNotificationCenter defaultCenter] addObserver:[AWTStarter class]
+                                                 selector:@selector(appKitIsRunning:)
+                                                     name:NSApplicationDidFinishLaunchingNotification
+                                                   object:nil];
+
+        if (verbose) NSLog(@"+[AWTStarter start:::]: registered NSApplicationDidFinishLaunchingNotification");
+    }
+
+    id st = [[AWTStarter alloc] init];
+
+    NSArray * args = [NSArray arrayWithObjects:
+                      [NSNumber numberWithBool: onMainThread],
+                      [NSNumber numberWithBool: swtMode],
+                      [NSNumber numberWithBool: headless],
+                      [NSNumber numberWithBool: swtModeForWebStart],
+                      [NSNumber numberWithBool: verbose],
+                      nil];
+
+    if (onMainThread) {
+        [st starter:args];
+    } else {
+        [st performSelectorOnMainThread: @selector(starter:) withObject:args waitUntilDone:NO];
+    }
+
+    if (!headless && !onMainThread) {
+        if (verbose) AWT_DEBUG_LOG(@"about to wait on AppKit startup mutex");
+
+        // Wait here for AppKit to have started (or for AWT to have been loaded into
+        //  an already running NSApplication).
+        pthread_mutex_lock(&sAppKitStarted_mutex);
+        while (sAppKitStarted == NO) {
+            pthread_cond_wait(&sAppKitStarted_cv, &sAppKitStarted_mutex);
+        }
+        pthread_mutex_unlock(&sAppKitStarted_mutex);
+
+        // AWT gets here AFTER +[AWTStarter appKitIsRunning:] is called.
+        if (verbose) AWT_DEBUG_LOG(@"got out of the AppKit startup mutex");
+    }
+}
+
+- (void)starter:(NSArray*)args {
+    NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+    BOOL onMainThread = [[args objectAtIndex:0] boolValue];
+    BOOL swtMode = [[args objectAtIndex:1] boolValue];
+    BOOL headless = [[args objectAtIndex:2] boolValue];
+    BOOL swtModeForWebStart = [[args objectAtIndex:3] boolValue];
+    BOOL verbose = [[args objectAtIndex:4] boolValue];
+
+    BOOL wasOnMainThread = onMainThread;
+
+    setUpAWTAppKit(swtMode, headless);
+
+    // Headless mode trumps either ordinary AWT or SWT-in-AWT mode.  Declare us a daemon and return.
+    if (headless) {
+        BOOL didBecomeDaemon = [AWTStarter markAppAsDaemon];
+        return;
+    }
+
+    if (swtMode || swtModeForWebStart) {
+        if (verbose) NSLog(@"in SWT or SWT/WebStart mode");
+
+        // The SWT should call NSApplicationLoad, but they don't know a priori that they will be using the AWT, so they don't.
+        NSApplicationLoad();
+    }
+
+    // This will create a NSApplicationAWT for standalone AWT programs, unless there is
+    //  already a NSApplication instance. If there is already a NSApplication instance,
+    //  and -[NSApplication isRunning] returns YES, AWT is embedded inside another
+    //  AppKit Application.
+    NSApplication *app = [NSApplicationAWT sharedApplication];
+
+    // Don't set the delegate until the NSApplication has been created.
+    //  ApplicationDelegate is the support code for com.apple.eawt.
+    OSXAPP_SetApplicationDelegate([ApplicationDelegate sharedDelegate]);
+
+    // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent.        
+    if (![app isRunning]) {
+        if (verbose) AWT_DEBUG_LOG(@"+[AWTStarter startAWT]: ![app isRunning]");
+
+        // This is where the AWT AppKit thread parks itself to process events.
+        [NSApplicationAWT runAWTLoopWithApp: app];
+    } else {
+        // We're either embedded, or showing a splash screen
+        if (![NSApp isKindOfClass:[NSApplicationAWT class]]) {
+            if (verbose) AWT_DEBUG_LOG(@"running embedded");
+
+            // Since we're embedded, no need to be swamping the runloop with the observers.
+            CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
+            CFRunLoopRemoveObserver(runLoop, busyObserver, kCFRunLoopDefaultMode);
+            CFRunLoopRemoveObserver(runLoop, notBusyObserver, kCFRunLoopDefaultMode);
+
+            busyObserver = NULL;
+            notBusyObserver = NULL;
+        } else {
+            if (verbose) AWT_DEBUG_LOG(@"running after showing a splash screen");
+        }
+
+        // Signal so that JNI_OnLoad can proceed.
+        if (!wasOnMainThread) [AWTStarter appKitIsRunning:nil];
+
+        // Proceed to exit this call as there is no reason to run the NSApplication event loop.
+    }
+
+    [pool drain];
+}
+    
+@end
+
+
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
+    BOOL verbose = ShouldPrintVerboseDebugging();
+    if (verbose) AWT_DEBUG_LOG(@"entered JNI_OnLoad");
+
+    // Headless: BOTH
+    // Embedded: BOTH
+    // Multiple Calls: NO
+    //  Caller: JavaVM classloader
+
+    // Keep a static reference for other archives.
+    OSXAPP_SetJavaVM(vm);
+
+    JNIEnv *env = NULL;
+
+    // Need JNIEnv for JNF_COCOA_ENTER(env); macro below
+    jint status = (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_4);
+    if (status != JNI_OK || env == NULL) {
+        AWT_DEBUG_LOG(@"Can't get JNIEnv");
+        return JNI_VERSION_1_4;
+    }
+
+    // The following is true when AWT is attempting to connect to the window server
+    // when it isn't set up properly to do so.
+    // BOOL AWTLoadFailure = YES;    For now we are skipping this check so i'm commenting out this variable as unused
+JNF_COCOA_ENTER(env);
+
+    // If -XstartOnFirstThread was used at invocation time, an environment variable will be set.
+    // (See java_md.c for the matching setenv call.) When that happens, we assume the SWT will be in use.
+    BOOL swt_compatible_mode = NO;
+
+    char envVar[80];
+    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
+    if (getenv(envVar) != NULL) {
+        swt_compatible_mode = YES;
+        unsetenv(envVar);
+    }
+
+    BOOL swt_in_webstart = isSWTInWebStart(env);
+    BOOL headless = isHeadless(env);
+
+    // Make sure we're on the right thread.  If not, we still need the JNIEnv to throw an exception.
+    if (pthread_main_np() != 0 && !swt_compatible_mode && !headless) {
+        AWT_DEBUG_LOG(@"Apple AWT Java VM was loaded on first thread -- can't start AWT.");
+        [JNFException raise:env as:kInternalError reason:"Can't start the AWT because Java was started on the first thread.  Make sure StartOnFirstThread is "
+         "not specified in your application's Info.plist or on the command line"];
+        return JNI_VERSION_1_4;
+    }
+
+    // We need to let Foundation know that this is a multithreaded application, if it isn't already.
+    if (![NSThread isMultiThreaded]) {
+        [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil];
+    }
+
+//    if (swt_compatible_mode || headless || [AWTStarter isConnectedToWindowServer] || [AWTStarter isRemoteSession]) {
+// No need in this check - we will try to launch AWTStarter anyways - to be able to run GUI application remotely
+//        AWTLoadFailure = NO;
+
+    [AWTStarter start:headless swtMode:swt_compatible_mode swtModeForWebStart:swt_in_webstart];
+
+//    }
+
+/*    if (AWTLoadFailure) { // We will not reach this code anyways
+        [JNFException raise:env as:kInternalError reason:"Can't connect to window server - not enough permissions."];
+    } */
+
+JNF_COCOA_EXIT(env);
+
+    if (verbose) AWT_DEBUG_LOG(@"exiting JNI_OnLoad");
+
+    return JNI_VERSION_1_4;
+}
diff --git a/jdk/src/macosx/native/sun/awt/awt_DrawingSurface.m b/jdk/src/macosx/native/sun/awt/awt_DrawingSurface.m
new file mode 100644
index 0000000..152e8fb
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/awt_DrawingSurface.m
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "AWTSurfaceLayers.h"
+
+JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL awt_DrawingSurface_GetDrawingSurfaceInfo
+(JAWT_DrawingSurface* ds)
+{
+    JAWT_DrawingSurfaceInfo* dsi = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo));
+
+    JNIEnv *env = ds->env;
+    jobject target = ds->target;
+
+    static JNF_CLASS_CACHE(jc_Component, "java/awt/Component");
+    static JNF_MEMBER_CACHE(jf_peer, jc_Component, "peer", "Ljava/awt/peer/ComponentPeer;");
+    jobject peer = JNFGetObjectField(env, target, jf_peer);
+
+    static JNF_CLASS_CACHE(jc_ComponentPeer, "sun/lwawt/LWComponentPeer");
+    static JNF_MEMBER_CACHE(jf_platformComponent, jc_ComponentPeer,
+                            "platformComponent", "Lsun/lwawt/PlatformComponent;");
+    jobject platformComponent = JNFGetObjectField(env, peer, jf_platformComponent);
+
+    static JNF_CLASS_CACHE(jc_PlatformComponent, "sun/lwawt/macosx/CPlatformComponent");
+    static JNF_MEMBER_CACHE(jm_getPointer, jc_PlatformComponent, "getPointer", "()J");
+    AWTSurfaceLayers *surfaceLayers = jlong_to_ptr(JNFCallLongMethod(env, platformComponent, jm_getPointer));
+    // REMIND: assert(surfaceLayers)
+
+    dsi->platformInfo = surfaceLayers;
+    dsi->ds = ds;
+
+    static JNF_MEMBER_CACHE(jf_x, jc_Component, "x", "I");
+    static JNF_MEMBER_CACHE(jf_y, jc_Component, "y", "I");
+    static JNF_MEMBER_CACHE(jf_width, jc_Component, "width", "I");
+    static JNF_MEMBER_CACHE(jf_height, jc_Component, "height", "I");
+
+    dsi->bounds.x = JNFGetIntField(env, target, jf_x);
+    dsi->bounds.y = JNFGetIntField(env, target, jf_y);
+    dsi->bounds.width = JNFGetIntField(env, target, jf_width);
+    dsi->bounds.height = JNFGetIntField(env, target, jf_height);
+
+    dsi->clipSize = 1;
+    dsi->clip = &(dsi->bounds);
+
+    return dsi;
+}
+
+JNIEXPORT jint JNICALL awt_DrawingSurface_Lock
+(JAWT_DrawingSurface* ds)
+{
+    // TODO: implement
+    return 0;
+}
+
+JNIEXPORT void JNICALL awt_DrawingSurface_Unlock
+(JAWT_DrawingSurface* ds)
+{
+    // TODO: implement
+}
+
+JNIEXPORT void JNICALL awt_DrawingSurface_FreeDrawingSurfaceInfo
+(JAWT_DrawingSurfaceInfo* dsi)
+{
+    free(dsi);
+}
+
+JNIEXPORT JAWT_DrawingSurface* JNICALL awt_GetDrawingSurface
+(JNIEnv* env, jobject target)
+{
+    JAWT_DrawingSurface* ds = (JAWT_DrawingSurface*)malloc(sizeof(JAWT_DrawingSurface));
+
+    // TODO: "target instanceof" check
+
+    ds->env = env;
+    ds->target = (*env)->NewGlobalRef(env, target);
+    ds->Lock = awt_DrawingSurface_Lock;
+    ds->GetDrawingSurfaceInfo = awt_DrawingSurface_GetDrawingSurfaceInfo;
+    ds->FreeDrawingSurfaceInfo = awt_DrawingSurface_FreeDrawingSurfaceInfo;
+    ds->Unlock = awt_DrawingSurface_Unlock;
+
+    return ds;
+}
+
+JNIEXPORT void JNICALL awt_FreeDrawingSurface
+(JAWT_DrawingSurface* ds)
+{
+    JNIEnv *env = ds->env;
+    (*env)->DeleteGlobalRef(env, ds->target);
+    free(ds);
+}
+
+JNIEXPORT void JNICALL awt_Lock
+(JNIEnv* env)
+{
+    // TODO: implement
+}
+
+JNIEXPORT void JNICALL awt_Unlock
+(JNIEnv* env)
+{
+    // TODO: implement
+}
+
+JNIEXPORT jobject JNICALL awt_GetComponent
+(JNIEnv* env, void* platformInfo)
+{
+    // TODO: implement
+    return NULL;
+}
diff --git a/jdk/src/macosx/native/sun/awt/jawt.m b/jdk/src/macosx/native/sun/awt/jawt.m
new file mode 100644
index 0000000..c295665
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/jawt.m
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <jawt.h>
+
+// REMIND: import <jawt_md.h>
+#import <JavaVM/jawt_md.h>
+
+#import "awt_DrawingSurface.h"
+
+/*
+ * Get the AWT native structure.
+ * This function returns JNI_FALSE if an error occurs.
+ */
+JNIEXPORT jboolean JNICALL JAWT_GetAWT
+(JNIEnv* env, JAWT* awt)
+{
+    if (awt == NULL) {
+        return JNI_FALSE;
+    }
+
+    if (awt->version != (JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER) &&
+        awt->version != JAWT_VERSION_1_7)
+    {
+        return JNI_FALSE;
+    }
+
+    awt->GetDrawingSurface = awt_GetDrawingSurface;
+    awt->FreeDrawingSurface = awt_FreeDrawingSurface;
+    if (awt->version >= JAWT_VERSION_1_4) {
+        awt->Lock = awt_Lock;
+        awt->Unlock = awt_Unlock;
+        awt->GetComponent = awt_GetComponent;
+    }
+
+    return JNI_TRUE;
+}
diff --git a/jdk/src/macosx/native/sun/awt/splashscreen/splashscreen_config.h b/jdk/src/macosx/native/sun/awt/splashscreen/splashscreen_config.h
new file mode 100644
index 0000000..4d8e4bf
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/splashscreen/splashscreen_config.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* platform-dependent definitions */
+
+#ifndef SPLASHSCREEN_CONFIG_H
+#define SPLASHSCREEN_CONFIG_H
+
+#include <sys/types.h>
+#include <sys/unistd.h>
+#include <signal.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <Cocoa/Cocoa.h>
+
+typedef uint32_t rgbquad_t;
+typedef uint16_t word_t;
+typedef uint8_t byte_t;
+
+
+// Actually the following Rect machinery is unused since we don't use shapes
+typedef int RECT_T;
+
+#define RECT_EQ_X(r1,r2)        ((r1) == (r2))
+#define RECT_SET(r,xx,yy,ww,hh) ;
+#define RECT_INC_HEIGHT(r)      ;
+
+#define SPLASHCTL_QUIT          'Q'
+#define SPLASHCTL_UPDATE        'U'
+#define SPLASHCTL_RECONFIGURE   'R'
+
+#define INLINE static
+
+#define SPLASHEXPORT
+
+#endif
diff --git a/jdk/src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m b/jdk/src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m
new file mode 100644
index 0000000..4d8f5e6
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m
@@ -0,0 +1,384 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "splashscreen_impl.h"
+
+#import <Cocoa/Cocoa.h>
+#import <objc/objc-auto.h>
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import "NSApplicationAWT.h"
+
+#include <sys/time.h>
+#include <pthread.h>
+#include <iconv.h>
+#include <langinfo.h>
+#include <locale.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <unistd.h>
+#include <dlfcn.h>
+
+
+static void SplashCenter(Splash * splash)
+{
+    // otherwise could use screens[0] to select the menu-bar screen
+    NSRect screenFrame = [[NSScreen mainScreen] visibleFrame];
+
+    splash->x = (screenFrame.size.width - splash->width) / 2;
+    splash->y = (screenFrame.size.height - splash->height) / 2 + screenFrame.origin.y;
+}
+
+unsigned
+SplashTime(void) {
+    struct timeval tv;
+    struct timezone tz;
+    unsigned long long msec;
+
+    gettimeofday(&tv, &tz);
+    msec = (unsigned long long) tv.tv_sec * 1000 +
+        (unsigned long long) tv.tv_usec / 1000;
+
+    return (unsigned) msec;
+}
+
+/* Could use npt but decided to cut down on linked code size */
+char* SplashConvertStringAlloc(const char* in, int* size) {
+    const char     *codeset;
+    const char     *codeset_out;
+    iconv_t         cd;
+    size_t          rc;
+    char           *buf = NULL, *out;
+    size_t          bufSize, inSize, outSize;
+    const char* old_locale;
+
+    if (!in) {
+        return NULL;
+    }
+    old_locale = setlocale(LC_ALL, "");
+
+    codeset = nl_langinfo(CODESET);
+    if ( codeset == NULL || codeset[0] == 0 ) {
+        goto done;
+    }
+    /* we don't need BOM in output so we choose native BE or LE encoding here */
+    codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ?
+        "UCS-2BE" : "UCS-2LE";
+
+    cd = iconv_open(codeset_out, codeset);
+    if (cd == (iconv_t)-1 ) {
+        goto done;
+    }
+    inSize = strlen(in);
+    bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is
+                        // 2 bytes per source byte max
+    buf = malloc(bufSize);
+    out = buf; outSize = bufSize;
+    /* linux iconv wants char** source and solaris wants const char**...
+       cast to void* */
+    rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
+    iconv_close(cd);
+
+    if (rc == (size_t)-1) {
+        free(buf);
+        buf = NULL;
+    } else {
+        if (size) {
+            *size = (bufSize-outSize)/2; /* bytes to wchars */
+        }
+    }
+done:
+    setlocale(LC_ALL, old_locale);
+    return buf;
+}
+
+
+void
+SplashInitPlatform(Splash * splash) {
+    pthread_mutex_init(&splash->lock, NULL);
+
+    splash->maskRequired = 0;
+
+
+    //TODO: the following is too much of a hack but should work in 90% cases.
+    //      besides we don't use device-dependant drawing, so probably
+    //      that's very fine indeed
+    splash->byteAlignment = 1;
+    initFormat(&splash->screenFormat, 0xff << 8,
+            0xff << 16, 0xff << 24, 0xff << 0);
+    splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
+    splash->screenFormat.depthBytes = 4;
+
+    dispatch_async(dispatch_get_main_queue(), ^(void) {
+            NSApplication * app = [NSApplicationAWT sharedApplication];
+            [NSApplicationAWT runAWTLoopWithApp: app];
+    });
+}
+
+void
+SplashCleanupPlatform(Splash * splash) {
+    splash->maskRequired = 0;
+}
+
+void
+SplashDonePlatform(Splash * splash) {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    pthread_mutex_destroy(&splash->lock);
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        if (splash->window) {
+            [splash->window orderOut:nil];
+            [splash->window release];
+        }
+    }];
+    [pool drain];
+}
+
+void
+SplashLock(Splash * splash) {
+    pthread_mutex_lock(&splash->lock);
+}
+
+void
+SplashUnlock(Splash * splash) {
+    pthread_mutex_unlock(&splash->lock);
+}
+
+void
+SplashInitFrameShape(Splash * splash, int imageIndex) {
+    // No shapes, we rely on alpha compositing
+}
+
+void * SplashScreenThread(void *param);
+void
+SplashCreateThread(Splash * splash) {
+    pthread_t thr;
+    pthread_attr_t attr;
+    int rc;
+
+    pthread_attr_init(&attr);
+    rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
+}
+
+void
+SplashRedrawWindow(Splash * splash) {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    SplashUpdateScreenData(splash);
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ?
+        NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]
+            initWithBitmapDataPlanes: (unsigned char**)&splash->screenData
+                          pixelsWide: splash->width
+                          pixelsHigh: splash->height
+                       bitsPerSample: 8
+                     samplesPerPixel: 4
+                            hasAlpha: YES
+                            isPlanar: NO
+                      colorSpaceName: NSDeviceRGBColorSpace
+                        bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat
+                         bytesPerRow: splash->width * 4
+                        bitsPerPixel: 32];
+
+        NSImage * image = [[NSImage alloc]
+            initWithSize: NSMakeSize(splash->width, splash->height)];
+        [image setBackgroundColor: [NSColor clearColor]];
+
+        [image addRepresentation: rep];
+
+        NSImageView * view = [[NSImageView alloc] init];
+
+        [view setImage: image];
+        [view setEditable: NO];
+        //NOTE: we don't set a 'wait cursor' for the view because:
+        //      1. The Cocoa GUI guidelines suggest to avoid it, and use a progress
+        //         bar instead.
+        //      2. There simply isn't an instance of NSCursor that represent
+        //         the 'wait cursor'. So that is undoable.
+
+        //TODO: only the first image in an animated gif preserves transparency.
+        //      Loos like the splash->screenData contains inappropriate data
+        //      for all but the first frame.
+
+        [image release];
+        [rep release];
+
+        [splash->window setContentView: view];
+        [splash->window orderFrontRegardless];
+    }];
+
+    [pool drain];
+}
+
+void SplashReconfigureNow(Splash * splash) {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        SplashCenter(splash);
+
+        if (!splash->window) {
+            return;
+        }
+
+        [splash->window orderOut:nil];
+        [splash->window setFrame: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
+                         display: NO];
+    }];
+
+    [pool drain];
+
+    SplashRedrawWindow(splash);
+}
+
+void
+SplashEventLoop(Splash * splash) {
+
+    /* we should have splash _locked_ on entry!!! */
+
+    while (1) {
+        struct pollfd pfd[1];
+        int timeout = -1;
+        int ctl = splash->controlpipe[0];
+        int rc;
+        int pipes_empty;
+
+        pfd[0].fd = ctl;
+        pfd[0].events = POLLIN | POLLPRI;
+
+        errno = 0;
+        if (splash->isVisible>0 && SplashIsStillLooping(splash)) {
+            timeout = splash->time + splash->frames[splash->currentFrame].delay
+                - SplashTime();
+            if (timeout < 0) {
+                timeout = 0;
+            }
+        }
+        SplashUnlock(splash);
+        rc = poll(pfd, 1, timeout);
+        SplashLock(splash);
+        if (splash->isVisible>0 && SplashTime() >= splash->time +
+                splash->frames[splash->currentFrame].delay) {
+            SplashNextFrame(splash);
+            SplashRedrawWindow(splash);
+        }
+        if (rc <= 0) {
+            errno = 0;
+            continue;
+        }
+        pipes_empty = 0;
+        while(!pipes_empty) {
+            char buf;
+
+            pipes_empty = 1;
+            if (read(ctl, &buf, sizeof(buf)) > 0) {
+                pipes_empty = 0;
+                switch (buf) {
+                case SPLASHCTL_UPDATE:
+                    if (splash->isVisible>0) {
+                        SplashRedrawWindow(splash);
+                    }
+                    break;
+                case SPLASHCTL_RECONFIGURE:
+                    if (splash->isVisible>0) {
+                        SplashReconfigureNow(splash);
+                    }
+                    break;
+                case SPLASHCTL_QUIT:
+                    return;
+                }
+            }
+        }
+    }
+}
+
+void *
+SplashScreenThread(void *param) {
+    objc_registerThreadWithCollector();
+
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    Splash *splash = (Splash *) param;
+
+    SplashLock(splash);
+    pipe(splash->controlpipe);
+    fcntl(splash->controlpipe[0], F_SETFL,
+        fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
+    splash->time = SplashTime();
+    splash->currentFrame = 0;
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        SplashCenter(splash);
+
+        splash->window = (void*) [[NSWindow alloc]
+            initWithContentRect: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
+                      styleMask: NSBorderlessWindowMask
+                        backing: NSBackingStoreBuffered
+                          defer: NO];
+
+        [splash->window setOpaque: NO];
+        [splash->window setBackgroundColor: [NSColor clearColor]];
+    }];
+    fflush(stdout);
+    if (splash->window) {
+        [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+            [splash->window orderFrontRegardless];
+        }];
+        SplashRedrawWindow(splash);
+        SplashEventLoop(splash);
+    }
+    SplashUnlock(splash);
+    SplashDone(splash);
+
+    splash->isVisible=-1;
+
+    [pool drain];
+
+    return 0;
+}
+
+void
+sendctl(Splash * splash, char code) {
+    if (splash && splash->controlpipe[1]) {
+        write(splash->controlpipe[1], &code, 1);
+    }
+}
+
+void
+SplashClosePlatform(Splash * splash) {
+    sendctl(splash, SPLASHCTL_QUIT);
+}
+
+void
+SplashUpdate(Splash * splash) {
+    sendctl(splash, SPLASHCTL_UPDATE);
+}
+
+void
+SplashReconfigure(Splash * splash) {
+    sendctl(splash, SPLASHCTL_RECONFIGURE);
+}
+
diff --git a/jdk/src/macosx/native/sun/font/AWTFont.h b/jdk/src/macosx/native/sun/font/AWTFont.h
new file mode 100644
index 0000000..0603bf3
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/AWTFont.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#define MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE 256
+
+@interface AWTFont : NSObject {
+@public
+    NSFont    *fFont;
+    CGFontRef  fNativeCGFont;
+    BOOL       fIsFakeItalic;
+}
+
++ (AWTFont *) awtFontForName:(NSString *)name
+    style:(int)style isFakeItalic:(BOOL)isFakeItalic;
+
++ (NSFont *) nsFontForJavaFont:(jobject)javaFont env:(JNIEnv *)env;
+
+@end
diff --git a/jdk/src/macosx/native/sun/font/AWTFont.m b/jdk/src/macosx/native/sun/font/AWTFont.m
new file mode 100644
index 0000000..20279c2
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/AWTFont.m
@@ -0,0 +1,418 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "java_awt_Font.h"
+#import "sun_awt_PlatformFont.h"
+#import "sun_awt_FontDescriptor.h"
+#import "sun_font_CFont.h"
+#import "sun_font_CFontManager.h"
+
+#import "AWTFont.h"
+#import "AWTStrike.h"
+#import "CoreTextSupport.h"
+
+
+#define DEBUG
+
+@implementation AWTFont
+
+- (id) initWithFont:(NSFont *)font isFakeItalic:(BOOL)isFakeItalic {
+    self = [super init];
+    if (self) {
+        fIsFakeItalic = isFakeItalic;
+        fFont = [font retain];
+        fNativeCGFont = CTFontCopyGraphicsFont((CTFontRef)font, NULL);
+    }
+    return self;
+}
+
+- (void) dealloc {
+    [fFont release];
+    fFont = nil;
+
+    if (fNativeCGFont) {
+        CGFontRelease(fNativeCGFont);
+    fNativeCGFont = NULL;
+    }
+
+    [super dealloc];
+}
+
+- (void) finalize {
+    if (fNativeCGFont) {
+        CGFontRelease(fNativeCGFont);
+    fNativeCGFont = NULL;
+    }
+    [super finalize];
+}
+
++ (AWTFont *) awtFontForName:(NSString *)name
+                       style:(int)style
+                isFakeItalic:(BOOL)isFakeItalic
+{
+    // create font with family & size
+    NSFont *nsFont = [NSFont fontWithName:name size:1.0];
+
+    if (nsFont == nil) {
+        // if can't get font of that name, substitute system default font
+        nsFont = [NSFont fontWithName:@"Lucida Grande" size:1.0];
+#ifdef DEBUG
+        NSLog(@"needed to substitute Lucida Grande for: %@", name);
+#endif
+    }
+
+    // create an italic style (if one is installed)
+    if (style & java_awt_Font_ITALIC) {
+        nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSItalicFontMask];
+    }
+
+    // create a bold style (if one is installed)
+    if (style & java_awt_Font_BOLD) {
+        nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSBoldFontMask];
+    }
+
+    return [[[AWTFont alloc] initWithFont:nsFont isFakeItalic:isFakeItalic] autorelease];
+}
+
++ (NSFont *) nsFontForJavaFont:(jobject)javaFont env:(JNIEnv *)env {
+    if (javaFont == NULL) {
+#ifdef DEBUG
+        NSLog(@"nil font");
+#endif
+        return nil;
+    }
+
+    static JNF_CLASS_CACHE(jc_Font, "java/awt/Font");
+
+    // obtain the Font2D
+    static JNF_MEMBER_CACHE(jm_Font_getFont2D, jc_Font, "getFont2D", "()Lsun/font/Font2D;");
+    jobject font2d = JNFCallObjectMethod(env, javaFont, jm_Font_getFont2D);
+    if (font2d == NULL) {
+#ifdef DEBUG
+        NSLog(@"nil font2d");
+#endif
+        return nil;
+    }
+
+    // if it's not a CFont, it's likely one of TTF or OTF fonts
+    // from the Sun rendering loops
+    static JNF_CLASS_CACHE(jc_CFont, "sun/font/CFont");
+    if (!JNFIsInstanceOf(env, font2d, &jc_CFont)) {
+#ifdef DEBUG
+        NSLog(@"font2d !instanceof CFont");
+#endif
+        return nil;
+    }
+
+    static JNF_MEMBER_CACHE(jm_CFont_getFontStrike, jc_CFont, "getStrike", "(Ljava/awt/Font;)Lsun/font/FontStrike;");
+    jobject fontStrike = JNFCallObjectMethod(env, font2d, jm_CFont_getFontStrike, javaFont);
+
+    static JNF_CLASS_CACHE(jc_CStrike, "sun/font/CStrike");
+    if (!JNFIsInstanceOf(env, fontStrike, &jc_CStrike)) {
+#ifdef DEBUG
+        NSLog(@"fontStrike !instanceof CStrike");
+#endif
+        return nil;
+    }
+
+    static JNF_MEMBER_CACHE(jm_CStrike_nativeStrikePtr, jc_CStrike, "getNativeStrikePtr", "()J");
+    jlong awtStrikePtr = JNFCallLongMethod(env, fontStrike, jm_CStrike_nativeStrikePtr);
+    if (awtStrikePtr == 0L) {
+#ifdef DEBUG
+        NSLog(@"nil nativeFontPtr from CFont");
+#endif
+        return nil;
+    }
+
+    AWTStrike *strike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+
+    return [NSFont fontWithName:[strike->fAWTFont->fFont fontName] matrix:(CGFloat *)(&(strike->fAltTx))];
+}
+
+@end
+
+
+#pragma mark --- Font Discovery and Loading ---
+
+static NSArray* sFilteredFonts = nil;
+static NSDictionary* sFontFamilyTable = nil;
+
+static NSString*
+GetFamilyNameForFontName(NSString* fontname)
+{
+    return [sFontFamilyTable objectForKey:fontname];
+}
+
+static NSArray*
+GetFilteredFonts()
+{
+    if (sFilteredFonts == nil) {
+        NSFontManager *fontManager = [NSFontManager sharedFontManager];
+        NSUInteger fontCount = [[fontManager availableFonts] count];
+
+        NSMutableArray *allFonts = [[NSMutableArray alloc] initWithCapacity:fontCount];
+        NSMutableDictionary* fontFamilyTable = [[NSMutableDictionary alloc] initWithCapacity:fontCount];
+        NSArray *allFamilies = [fontManager availableFontFamilies];
+
+        NSUInteger familyCount = [allFamilies count];
+
+        NSUInteger familyIndex;
+        for (familyIndex = 0; familyIndex < familyCount; familyIndex++) {
+            NSString *family = [allFamilies objectAtIndex:familyIndex];
+
+            if ((family == nil) || [family characterAtIndex:0] == '.') {
+                continue;
+            }
+
+            NSArray *fontFaces = [fontManager availableMembersOfFontFamily:family];
+            NSUInteger faceCount = [fontFaces count];
+
+            NSUInteger faceIndex;
+            for (faceIndex = 0; faceIndex < faceCount; faceIndex++) {
+                NSString* face = [[fontFaces objectAtIndex:faceIndex] objectAtIndex:0];
+                if (face != nil) {
+                    [allFonts addObject:face];
+                    [fontFamilyTable setObject:family forKey:face];
+                }
+            }
+        }
+
+        sFilteredFonts = allFonts;
+        sFontFamilyTable = fontFamilyTable;
+    }
+
+    return sFilteredFonts;
+}
+
+#pragma mark --- sun.font.CFontManager JNI ---
+
+static OSStatus CreateFSRef(FSRef *myFSRefPtr, NSString *inPath)
+{
+    return FSPathMakeRef((UInt8 *)[inPath fileSystemRepresentation],
+                         myFSRefPtr, NULL);
+}
+
+// /*
+//  * Class:     sun_font_CFontManager
+//  * Method:    loadFileFont
+//  * Signature: (Ljava/lang/String;)Lsun/font/Font2D;
+//  */
+// JNIEXPORT /* sun.font.CFont */ jobject JNICALL
+// Java_sun_font_CFontManager_loadFileFont
+//     (JNIEnv *env, jclass obj, jstring fontpath)
+// {
+//     jobject result = NULL;
+//
+// JNF_COCOA_ENTER(env);
+//
+//     NSString *nsFilePath = JNFJavaToNSString(env, fontpath);
+//     jstring javaFontName = NULL;
+//
+//     //
+//     // Note: This API uses ATS and can therefore return Carbon error codes.
+//     // These codes can be found at:
+//     // http://developer.apple.com/techpubs/macosx/Carbon/Files/FileManager/File_Manager/ResultCodes/ResultCodes.html
+//     //
+//
+//     FSRef iFile;
+//     OSStatus status = CreateFSRef(&iFile, nsFilePath);
+//
+//     if (status == noErr) {
+//         ATSFontContainerRef oContainer;
+//         status = ATSFontActivateFromFileReference(&iFile, kATSFontContextLocal,
+//                                                   kATSFontFormatUnspecified,
+//                                                   NULL,
+//                                                   kATSOptionFlagsUseDataFork,
+//                                                   &oContainer);
+//         if (status == noErr) {
+//             ATSFontRef ioArray[1];
+//             ItemCount oCount;
+//             status = ATSFontFindFromContainer(oContainer,
+//                                               kATSOptionFlagsUseDataFork,
+//                                               1, ioArray, &oCount);
+//
+//             if (status == noErr) {
+//                 CFStringRef oName;
+//                 status = ATSFontGetPostScriptName(ioArray[0],
+//                                                   kATSOptionFlagsUseDataFork,
+//                                                   &oName);
+//                 if (status == noErr) {
+//                     javaFontName = JNFNSToJavaString(env, (NSString *)oName);
+//                     CFRelease(oName);
+//                 }
+//             }
+//         }
+//     }
+//
+//     if (javaFontName != NULL) {
+//         // create the CFont!
+//         static JNF_CLASS_CACHE(sjc_CFont, "sun/font/CFont");
+//         static JNF_CTOR_CACHE(sjf_CFont_ctor,
+//                               sjc_CFont, "(Ljava/lang/String;)V");
+//         result = JNFNewObject(env, sjf_CFont_ctor, javaFontName);
+//     }
+//
+// JNF_COCOA_EXIT(env);
+//
+//     return result;
+// }
+
+/*
+ * Class:     sun_font_CFontManager
+ * Method:    loadNativeFonts
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_font_CFontManager_loadNativeFonts
+    (JNIEnv *env, jobject jthis)
+{
+    static JNF_CLASS_CACHE(jc_CFontManager,
+                           "sun/font/CFontManager");
+    static JNF_MEMBER_CACHE(jm_registerFont, jc_CFontManager,
+                            "registerFont",
+                            "(Ljava/lang/String;Ljava/lang/String;)V");
+
+    jint num = 0;
+
+JNF_COCOA_ENTER(env);
+
+    NSArray *filteredFonts = GetFilteredFonts();
+    num = (jint)[filteredFonts count];
+
+    jint i;
+    for (i = 0; i < num; i++) {
+        NSString *fontname = [filteredFonts objectAtIndex:i];
+        jobject jFontName = JNFNSToJavaString(env, fontname);
+        jobject jFontFamilyName =
+            JNFNSToJavaString(env, GetFamilyNameForFontName(fontname));
+
+        JNFCallVoidMethod(env, jthis,
+                          jm_registerFont, jFontName, jFontFamilyName);
+    }
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     Java_sun_font_CFontManager_loadNativeDirFonts
+ * Method:    loadNativeDirFonts
+ * Signature: (Ljava/lang/String;)V;
+ */
+JNIEXPORT void JNICALL
+Java_sun_font_CFontManager_loadNativeDirFonts
+(JNIEnv *env, jclass clz, jstring filename)
+{
+JNF_COCOA_ENTER(env);
+
+    NSString *nsFilePath = JNFJavaToNSString(env, filename);
+
+    FSRef iFile;
+    OSStatus status = CreateFSRef(&iFile, nsFilePath);
+
+    if (status == noErr) {
+        ATSFontContainerRef oContainer;
+        status = ATSFontActivateFromFileReference(&iFile, kATSFontContextLocal,
+                                                  kATSFontFormatUnspecified,
+                                                  NULL, kNilOptions,
+                                                  &oContainer);
+    }
+
+JNF_COCOA_EXIT(env);
+}
+
+#pragma mark --- sun.font.CFont JNI ---
+
+/*
+ * Class:     sun_font_CFont
+ * Method:    initNativeFont
+ * Signature: (Ljava/lang/String;I)J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_font_CFont_createNativeFont
+    (JNIEnv *env, jclass clazz,
+     jstring nativeFontName, jint style, jboolean isFakeItalic)
+{
+    AWTFont *awtFont = nil;
+
+JNF_COCOA_ENTER(env);
+
+    awtFont =
+        [AWTFont awtFontForName:JNFJavaToNSString(env, nativeFontName)
+         style:style
+         isFakeItalic:isFakeItalic]; // autoreleased
+
+    if (awtFont) {
+        CFRetain(awtFont); // GC
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(awtFont);
+}
+
+/*
+ * Class:     sun_font_CFont
+ * Method:    disposeNativeFont
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_font_CFont_disposeNativeFont
+    (JNIEnv *env, jclass clazz, jlong awtFontPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    if (awtFontPtr) {
+        CFRelease((AWTFont *)jlong_to_ptr(awtFontPtr)); // GC
+    }
+
+JNF_COCOA_EXIT(env);
+}
+
+
+#pragma mark --- Miscellaneous JNI ---
+
+/*
+ * Class:     sun_awt_PlatformFont
+ * Method:    initIDs
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_awt_PlatformFont_initIDs
+    (JNIEnv *env, jclass cls)
+{
+}
+
+/*
+ * Class:     sun_awt_FontDescriptor
+ * Method:    initIDs
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_sun_awt_FontDescriptor_initIDs
+    (JNIEnv *env, jclass cls)
+{
+}
diff --git a/jdk/src/macosx/native/sun/font/AWTStrike.h b/jdk/src/macosx/native/sun/font/AWTStrike.h
new file mode 100644
index 0000000..41bbe4d
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/AWTStrike.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "AWTFont.h"
+
+@interface AWTStrike : NSObject {
+@public
+    AWTFont *                fAWTFont;
+    CGFloat                    fSize;
+    JRSFontRenderingStyle    fStyle;
+    jint                    fAAStyle;
+
+    CGAffineTransform        fTx;
+    CGAffineTransform        fAltTx; // alternate strike tx used for Sun2D
+    CGAffineTransform        fFontTx;
+}
+
++ (AWTStrike *) awtStrikeForFont:(AWTFont *)awtFont tx:(CGAffineTransform)tx invDevTx:(CGAffineTransform)invDevTx style:(JRSFontRenderingStyle)style aaStyle:(jint)aaStyle;
+
+@end
diff --git a/jdk/src/macosx/native/sun/font/AWTStrike.m b/jdk/src/macosx/native/sun/font/AWTStrike.m
new file mode 100644
index 0000000..fbb3979
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/AWTStrike.m
@@ -0,0 +1,420 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import "java_awt_geom_PathIterator.h"
+#import "sun_awt_SunHints.h"
+#import "sun_font_CStrike.h"
+#import "CGGlyphImages.h"
+#import "CGGlyphOutlines.h"
+#import "AWTStrike.h"
+#import "CoreTextSupport.h"
+//#import "jni_util.h"
+
+@implementation AWTStrike
+
+static CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
+
+- (id) initWithFont:(AWTFont *)awtFont
+                 tx:(CGAffineTransform)tx
+           invDevTx:(CGAffineTransform)invDevTx
+              style:(JRSFontRenderingStyle)style
+            aaStyle:(jint)aaStyle {
+
+    self = [super init];
+    if (self) {
+        fAWTFont = [awtFont retain];
+        fStyle = style;
+        fAAStyle = aaStyle;
+
+        fTx = tx; // composited glyph and device transform
+
+        fAltTx = tx;
+        fAltTx.b *= -1;
+        fAltTx.d *= -1;
+
+        invDevTx.b *= -1;
+        invDevTx.c *= -1;
+        fFontTx = CGAffineTransformConcat(CGAffineTransformConcat(tx, invDevTx), sInverseTX);
+
+        // the "font size" is the square root of the determinant of the matrix
+        fSize = sqrt(abs(fFontTx.a * fFontTx.d - fFontTx.b * fFontTx.c));
+    }
+    return self;
+}
+
+- (void) dealloc {
+    [fAWTFont release];
+    fAWTFont = nil;
+
+    [super dealloc];
+}
+
++ (AWTStrike *) awtStrikeForFont:(AWTFont *)awtFont
+                              tx:(CGAffineTransform)tx
+                        invDevTx:(CGAffineTransform)invDevTx
+                           style:(JRSFontRenderingStyle)style
+                         aaStyle:(jint)aaStyle {
+
+    return [[[AWTStrike alloc] initWithFont:awtFont
+                                         tx:tx invDevTx:invDevTx
+                                      style:style
+                                    aaStyle:aaStyle] autorelease];
+}
+
+@end
+
+
+#define AWT_FONT_CLEANUP_SETUP \
+    BOOL _fontThrowJavaException = NO;
+
+#define AWT_FONT_CLEANUP_CHECK(a)                                       \
+    if ((a) == NULL) {                                                  \
+        _fontThrowJavaException = YES;                                  \
+        goto cleanup;                                                   \
+    }                                                                   \
+    if ((*env)->ExceptionCheck(env) == JNI_TRUE) {                      \
+        goto cleanup;                                                   \
+    }
+
+#define AWT_FONT_CLEANUP_FINISH                                         \
+    if (_fontThrowJavaException == YES) {                               \
+        char s[512];                                                    \
+        sprintf(s, "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__);       \
+        [JNFException raise:env as:kRuntimeException reason:s];         \
+    }
+
+
+/*
+ * Creates an affine transform from the corresponding doubles sent
+ * from CStrike.getGlyphTx().
+ */
+static inline CGAffineTransform
+GetTxFromDoubles(JNIEnv *env, jdoubleArray txArray)
+{
+    if (txArray == NULL) {
+        return CGAffineTransformIdentity;
+    }
+
+    jdouble *txPtr = (*env)->GetPrimitiveArrayCritical(env, txArray, NULL);
+
+    CGAffineTransform tx =
+        CGAffineTransformMake(txPtr[0], txPtr[1], txPtr[2],
+                              txPtr[3], txPtr[4], txPtr[5]);
+    tx = CGAffineTransformConcat(sInverseTX, tx);
+
+    (*env)->ReleasePrimitiveArrayCritical(env, txArray, txPtr, JNI_ABORT);
+
+    return tx;
+}
+
+/*
+ * Class:     sun_font_CStrike
+ * Method:    getNativeGlyphAdvance
+ * Signature: (JI)F
+ */
+JNIEXPORT jfloat JNICALL
+Java_sun_font_CStrike_getNativeGlyphAdvance
+    (JNIEnv *env, jclass clazz, jlong awtStrikePtr, jint glyphCode)
+{
+    CGSize advance;
+JNF_COCOA_ENTER(env);
+    AWTFont *awtFont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont;
+
+    // negative glyph codes are really unicodes, which were placed there by the mapper
+    // to indicate we should use CoreText to substitute the character
+    CGGlyph glyph;
+    const CTFontRef fallback = CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(awtFont, glyphCode, &glyph);
+    CTFontGetAdvancesForGlyphs(fallback, kCTFontDefaultOrientation, &glyph, &advance, 1);
+    CFRelease(fallback);
+
+JNF_COCOA_EXIT(env);
+    return advance.width;
+}
+
+/*
+ * Class:     sun_font_CStrike
+ * Method:    getNativeGlyphImageBounds
+ * Signature: (JJILjava/awt/geom/Rectangle2D/Float;DD)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_font_CStrike_getNativeGlyphImageBounds
+    (JNIEnv *env, jclass clazz,
+     jlong awtStrikePtr, jint glyphCode,
+     jobject result /*Rectangle*/, jdouble x, jdouble y)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+    AWTFont *awtFont = awtStrike->fAWTFont;
+
+    CGAffineTransform tx = awtStrike->fAltTx;
+    tx.tx += x;
+    tx.ty += y;
+
+    // negative glyph codes are really unicodes, which were placed there by the mapper
+    // to indicate we should use CoreText to substitute the character
+    CGGlyph glyph;
+    const CTFontRef fallback = CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(awtFont, glyphCode, &glyph);
+
+    CGRect bbox;
+    JRSFontGetBoundingBoxesForGlyphsAndStyle(fallback, &tx, awtStrike->fStyle, &glyph, 1, &bbox);
+    CFRelease(fallback);
+
+    // the origin of this bounding box is relative to the bottom-left corner baseline
+    CGFloat decender = -bbox.origin.y;
+    bbox.origin.y = -bbox.size.height + decender;
+
+    // Rectangle2D.Float.setRect(float x, float y, float width, float height);
+    static JNF_CLASS_CACHE(sjc_Rectangle2D_Float, "java/awt/geom/Rectangle2D$Float");    // cache class id for Rectangle
+    static JNF_MEMBER_CACHE(sjr_Rectangle2DFloat_setRect, sjc_Rectangle2D_Float, "setRect", "(FFFF)V");
+    JNFCallVoidMethod(env, result, sjr_Rectangle2DFloat_setRect, (jfloat)bbox.origin.x, (jfloat)bbox.origin.y, (jfloat)bbox.size.width, (jfloat)bbox.size.height);
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_font_CStrike
+ * Method:    getNativeGlyphOutline
+ * Signature: (JJIDD)Ljava/awt/geom/GeneralPath;
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_font_CStrike_getNativeGlyphOutline
+    (JNIEnv *env, jclass clazz,
+     jlong awtStrikePtr, jint glyphCode, jdouble xPos, jdouble yPos)
+{
+    jobject generalPath = NULL;
+
+JNF_COCOA_ENTER(env);
+
+    AWTPathRef path = NULL;
+    jfloatArray pointCoords = NULL;
+    jbyteArray pointTypes = NULL;
+
+AWT_FONT_CLEANUP_SETUP;
+
+    AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+    AWTFont *awtfont = awtStrike->fAWTFont;
+
+AWT_FONT_CLEANUP_CHECK(awtfont);
+
+    // inverting the shear order and sign to compensate for the flipped coordinate system
+    CGAffineTransform tx = awtStrike->fTx;
+    tx.tx += xPos;
+    tx.ty += yPos;
+
+    // get the right font and glyph for this "Java GlyphCode"
+
+    CGGlyph glyph;
+    const CTFontRef font = CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(awtfont, glyphCode, &glyph);
+
+    // get the advance of this glyph
+    CGSize advance;
+    CTFontGetAdvancesForGlyphs(font, kCTFontDefaultOrientation, &glyph, &advance, 1);
+
+    // Create AWTPath
+    path = AWTPathCreate(CGSizeMake(xPos, yPos));
+AWT_FONT_CLEANUP_CHECK(path);
+
+    // Get the paths
+    tx = awtStrike->fTx;
+    tx = CGAffineTransformConcat(tx, sInverseTX);
+    AWTGetGlyphOutline(&glyph, (NSFont *)font, &advance, &tx, 0, 1, &path);
+    CFRelease(font);
+
+    pointCoords = (*env)->NewFloatArray(env, path->fNumberOfDataElements);
+AWT_FONT_CLEANUP_CHECK(pointCoords);
+
+    (*env)->SetFloatArrayRegion(env, pointCoords, 0, path->fNumberOfDataElements, (jfloat*)path->fSegmentData);
+
+    // Copy the pointTypes to the general path
+    pointTypes = (*env)->NewByteArray(env, path->fNumberOfSegments);
+AWT_FONT_CLEANUP_CHECK(pointTypes);
+
+    (*env)->SetByteArrayRegion(env, pointTypes, 0, path->fNumberOfSegments, (jbyte*)path->fSegmentType);
+
+    static JNF_CLASS_CACHE(jc_GeneralPath, "java/awt/geom/GeneralPath");
+    static JNF_CTOR_CACHE(jc_GeneralPath_ctor, jc_GeneralPath, "(I[BI[FI)V");
+    generalPath = JNFNewObject(env, jc_GeneralPath_ctor, java_awt_geom_PathIterator_WIND_NON_ZERO, pointTypes, path->fNumberOfSegments, pointCoords, path->fNumberOfDataElements); // AWT_THREADING Safe (known object)
+
+    // Cleanup
+cleanup:
+    if (path != NULL) {
+        AWTPathFree(path);
+        path = NULL;
+    }
+
+    if (pointCoords != NULL) {
+        (*env)->DeleteLocalRef(env, pointCoords);
+        pointCoords = NULL;
+    }
+
+    if (pointTypes != NULL) {
+        (*env)->DeleteLocalRef(env, pointTypes);
+        pointTypes = NULL;
+    }
+
+    AWT_FONT_CLEANUP_FINISH;
+JNF_COCOA_EXIT(env);
+    return generalPath;
+}
+
+/*
+ * Class:     sun_font_CStrike
+ * Method:    getGlyphImagePtrsNative
+ * Signature: (JJ[J[II)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_font_CStrike_getGlyphImagePtrsNative
+    (JNIEnv *env, jclass clazz,
+     jlong awtStrikePtr, jlongArray glyphInfoLongArray,
+     jintArray glyphCodes, jint len)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
+
+    jlong *glyphInfos =
+        (*env)->GetPrimitiveArrayCritical(env, glyphInfoLongArray, NULL);
+    jint *rawGlyphCodes =
+        (*env)->GetPrimitiveArrayCritical(env, glyphCodes, NULL);
+
+    CGGlyphImages_GetGlyphImagePtrs(glyphInfos, awtStrike,
+                                    rawGlyphCodes, len);
+
+    (*env)->ReleasePrimitiveArrayCritical(env, glyphCodes,
+                                          rawGlyphCodes, JNI_ABORT);
+    // Do not use JNI_COMMIT, as that will not free the buffer copy
+    // when +ProtectJavaHeap is on.
+    (*env)->ReleasePrimitiveArrayCritical(env, glyphInfoLongArray,
+                                          glyphInfos, 0);
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_font_CStrike
+ * Method:    createNativeStrikePtr
+ * Signature: (J[D[DII)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_font_CStrike_createNativeStrikePtr
+(JNIEnv *env, jclass clazz, jlong nativeFontPtr, jdoubleArray glyphTxArray, jdoubleArray invDevTxArray, jint aaStyle, jint fmHint)
+{
+    AWTStrike *awtStrike = nil;
+JNF_COCOA_ENTER(env);
+
+    AWTFont *awtFont = (AWTFont *)jlong_to_ptr(nativeFontPtr);
+    JRSFontRenderingStyle style = JRSFontGetRenderingStyleForHints(fmHint, aaStyle);
+
+    CGAffineTransform glyphTx = GetTxFromDoubles(env, glyphTxArray);
+    CGAffineTransform invDevTx = GetTxFromDoubles(env, invDevTxArray);
+
+    awtStrike = [AWTStrike awtStrikeForFont:awtFont tx:glyphTx invDevTx:invDevTx style:style aaStyle:aaStyle]; // autoreleased
+
+    if (awtStrike)
+    {
+        CFRetain(awtStrike); // GC
+    }
+
+JNF_COCOA_EXIT(env);
+    return ptr_to_jlong(awtStrike);
+}
+
+/*
+ * Class:     sun_font_CStrike
+ * Method:    disposeNativeStrikePtr
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_font_CStrike_disposeNativeStrikePtr
+    (JNIEnv *env, jclass clazz, jlong awtStrike)
+{
+JNF_COCOA_ENTER(env);
+
+    if (awtStrike) {
+        CFRelease((AWTStrike *)jlong_to_ptr(awtStrike)); // GC
+    }
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_font_CStrike
+ * Method:    getFontMetrics
+ * Signature: (J)Lsun/font/StrikeMetrics;
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_font_CStrike_getFontMetrics
+    (JNIEnv *env, jclass clazz, jlong awtStrikePtr)
+{
+    jobject metrics = NULL;
+
+JNF_COCOA_ENTER(env);
+    AWT_FONT_CLEANUP_SETUP;
+
+    AWTFont *awtfont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont;
+    AWT_FONT_CLEANUP_CHECK(awtfont);
+
+    CGFontRef cgFont = awtfont->fNativeCGFont;
+
+    jfloat ay=0.0, dy=0.0, mx=0.0, ly=0.0;
+    int unitsPerEm = CGFontGetUnitsPerEm(cgFont);
+    CGFloat scaleX = (1.0 / unitsPerEm);
+    CGFloat scaleY = (1.0 / unitsPerEm);
+
+    // Ascent
+    ay = -(CGFloat)CGFontGetAscent(cgFont) * scaleY;
+
+    // Descent
+    dy = -(CGFloat)CGFontGetDescent(cgFont) * scaleY;
+
+    // Leading
+    ly = (CGFloat)CGFontGetLeading(cgFont) * scaleY;
+
+    // Max Advance for Font Direction (Strictly horizontal)
+    mx = [awtfont->fFont maximumAdvancement].width;
+
+    /*
+     * ascent:   no need to set ascentX - it will be zero.
+     * descent:  no need to set descentX - it will be zero.
+     * baseline: old releases "made up" a number and also seemed to
+     *           make it up for "X" and set "Y" to 0.
+     * leadingX: no need to set leadingX - it will be zero.
+     * leadingY: made-up number, but being compatible with what 1.4.x did.
+     * advance:  no need to set yMaxLinearAdvanceWidth - it will be zero.
+     */
+
+    JNF_CLASS_CACHE(sjc_StrikeMetrics, "sun/font/StrikeMetrics");
+    JNF_CTOR_CACHE(strikeMetricsCtr, sjc_StrikeMetrics, "(FFFFFFFFFF)V");
+    metrics = JNFNewObject(env, strikeMetricsCtr,
+                           0.0, ay, 0.0, dy, 1.0,
+                           0.0, 0.0, ly, mx, 0.0);
+
+cleanup:
+    AWT_FONT_CLEANUP_FINISH;
+JNF_COCOA_EXIT(env);
+
+    return metrics;
+}
diff --git a/jdk/src/macosx/native/sun/font/CCharToGlyphMapper.m b/jdk/src/macosx/native/sun/font/CCharToGlyphMapper.m
new file mode 100644
index 0000000..e0ceb01
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/CCharToGlyphMapper.m
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "AWTFont.h"
+#import "CoreTextSupport.h"
+
+#import "sun_font_CCharToGlyphMapper.h"
+
+/*
+ * Class:     sun_font_CCharToGlyphMapper
+ * Method:    countGlyphs
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL
+Java_sun_font_CCharToGlyphMapper_countGlyphs
+    (JNIEnv *env, jclass clazz, jlong awtFontPtr)
+{
+    jint numGlyphs = 0;
+
+JNF_COCOA_ENTER(env);
+
+    AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
+    numGlyphs = [awtFont->fFont numberOfGlyphs];
+
+JNF_COCOA_EXIT(env);
+
+    return numGlyphs;
+}
+
+static inline void
+GetGlyphsFromUnicodes(JNIEnv *env, AWTFont *awtFont,
+                      jint count, UniChar *unicodes,
+                      CGGlyph *cgGlyphs, jintArray glyphs)
+{
+    jint *glyphCodeInts = (*env)->GetPrimitiveArrayCritical(env, glyphs, 0);
+
+    CTS_GetGlyphsAsIntsForCharacters(awtFont, unicodes,
+                                     cgGlyphs, glyphCodeInts, count);
+
+    // Do not use JNI_COMMIT, as that will not free the buffer copy
+    // when +ProtectJavaHeap is on.
+    (*env)->ReleasePrimitiveArrayCritical(env, glyphs, glyphCodeInts, 0);
+}
+
+static inline void
+AllocateGlyphBuffer(JNIEnv *env, AWTFont *awtFont,
+                    jint count, UniChar *unicodes, jintArray glyphs)
+{
+    if (count < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) {
+        CGGlyph cgGlyphs[count];
+        GetGlyphsFromUnicodes(env, awtFont, count, unicodes, cgGlyphs, glyphs);
+    } else {
+        CGGlyph *cgGlyphs = (CGGlyph *)malloc(count * sizeof(CGGlyph));
+        GetGlyphsFromUnicodes(env, awtFont, count, unicodes, cgGlyphs, glyphs);
+        free(cgGlyphs);
+    }
+}
+
+/*
+ * Class:     sun_font_CCharToGlyphMapper
+ * Method:    nativeCharsToGlyphs
+ * Signature: (JI[C[I)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_font_CCharToGlyphMapper_nativeCharsToGlyphs
+    (JNIEnv *env, jclass clazz,
+     jlong awtFontPtr, jint count, jcharArray unicodes, jintArray glyphs)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
+
+    // check the array size
+    jint len = (*env)->GetArrayLength(env, glyphs);
+    if (len < count) {
+        count = len;
+    }
+
+    jchar *unicodesAsChars =
+        (*env)->GetPrimitiveArrayCritical(env, unicodes, NULL);
+
+    AllocateGlyphBuffer(env, awtFont, count, (UniChar *)unicodesAsChars, glyphs);
+
+    (*env)->ReleasePrimitiveArrayCritical(env, unicodes,
+                                          unicodesAsChars, JNI_ABORT);
+
+JNF_COCOA_EXIT(env);
+}
diff --git a/jdk/src/macosx/native/sun/font/CGGlyphImages.h b/jdk/src/macosx/native/sun/font/CGGlyphImages.h
new file mode 100644
index 0000000..27766e2
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/CGGlyphImages.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef __CGGLYPHIMAGES_H
+#define __CGGLYPHIMAGES_H
+
+#import "jni.h"
+#import "AWTStrike.h"
+
+void
+CGGlyphImages_GetGlyphImagePtrs(jlong glyphInfos[],
+                                const AWTStrike *strike,
+                                jint rawGlyphCodes[], const CFIndex len);
+
+#endif /* __CGGLYPHIMAGES_H */
diff --git a/jdk/src/macosx/native/sun/font/CGGlyphImages.m b/jdk/src/macosx/native/sun/font/CGGlyphImages.m
new file mode 100644
index 0000000..508c127
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/CGGlyphImages.m
@@ -0,0 +1,830 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Accelerate/Accelerate.h> // for vImage_Buffer
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "CGGlyphImages.h"
+#import "CoreTextSupport.h"
+#import "fontscalerdefs.h" // contains the definition of GlyphInfo struct
+
+#import "sun_awt_SunHints.h"
+
+//#define USE_IMAGE_ALIGNED_MEMORY 1
+//#define CGGI_DEBUG 1
+//#define CGGI_DEBUG_DUMP 1
+//#define CGGI_DEBUG_HIT_COUNT 1
+
+#define PRINT_TX(x) \
+    NSLog(@"(%f, %f, %f, %f, %f, %f)", x.a, x.b, x.c, x.d, x.tx, x.ty);
+
+/*
+ * The GlyphCanvas is a global shared CGContext that characters are struck into.
+ * For each character, the glyph is struck, copied into a GlyphInfo struct, and
+ * the canvas is cleared for the next glyph.
+ *
+ * If the necessary canvas is too large, the shared one will not be used and a
+ * temporary one will be provided.
+ */
+@interface CGGI_GlyphCanvas : NSObject {
+@public
+    CGContextRef context;
+    vImage_Buffer *image;
+}
+@end;
+
+@implementation CGGI_GlyphCanvas
+@end
+
+
+#pragma mark --- Debugging Helpers ---
+
+/*
+ * These debug functions are only compiled when CGGI_DEBUG is activated.
+ * They will print out a full UInt8 canvas and any pixels struck (assuming
+ * the canvas is not too big).
+ *
+ * As another debug feature, the entire canvas will be filled with a light
+ * alpha value so it is easy to see where the glyph painting regions are
+ * at runtime.
+ */
+
+#ifdef CGGI_DEBUG_DUMP
+static void
+DUMP_PIXELS(const char msg[], const UInt8 pixels[],
+            const size_t bytesPerPixel, const int width, const int height)
+{
+    printf("| %s: (%d, %d)\n", msg, width, height);
+
+    if (width > 80 || height > 80) {
+        printf("| too big\n");
+        return;
+    }
+
+    size_t i, j = 0, k, size = width * height;
+    for (i = 0; i < size; i++) {
+        for (k = 0; k < bytesPerPixel; k++) {
+            if (pixels[i * bytesPerPixel + k] > 0x80) j++;
+        }
+    }
+
+    if (j == 0) {
+        printf("| empty\n");
+        return;
+    }
+
+    printf("|_");
+    int x, y;
+    for (x = 0; x < width; x++) {
+        printf("__");
+    }
+    printf("_\n");
+
+    for (y = 0; y < height; y++) {
+        printf("| ");
+        for (x = 0; x < width; x++) {
+            int p = 0;
+            for(k = 0; k < bytesPerPixel; k++) {
+                p += pixels[(y * width + x) * bytesPerPixel + k];
+            }
+
+            if (p < 0x80) {
+                printf("  ");
+            } else {
+                printf("[]");
+            }
+        }
+        printf(" |\n");
+    }
+}
+
+static void
+DUMP_IMG_PIXELS(const char msg[], const vImage_Buffer *image)
+{
+    const void *pixels = image->data;
+    const size_t pixelSize = image->rowBytes / image->width;
+    const size_t width = image->width;
+    const size_t height = image->height;
+
+    DUMP_PIXELS(msg, pixels, pixelSize, width, height);
+}
+
+static void
+PRINT_CGSTATES_INFO(const CGContextRef cgRef)
+{
+    // TODO(cpc): lots of SPI use in this method; remove/rewrite?
+#if 0
+    CGRect clip = CGContextGetClipBoundingBox(cgRef);
+    fprintf(stderr, "    clip: ((%f, %f), (%f, %f))\n",
+            clip.origin.x, clip.origin.y, clip.size.width, clip.size.height);
+
+    CGAffineTransform ctm = CGContextGetCTM(cgRef);
+    fprintf(stderr, "    ctm: (%f, %f, %f, %f, %f, %f)\n",
+            ctm.a, ctm.b, ctm.c, ctm.d, ctm.tx, ctm.ty);
+
+    CGAffineTransform txtTx = CGContextGetTextMatrix(cgRef);
+    fprintf(stderr, "    txtTx: (%f, %f, %f, %f, %f, %f)\n",
+            txtTx.a, txtTx.b, txtTx.c, txtTx.d, txtTx.tx, txtTx.ty);
+
+    if (CGContextIsPathEmpty(cgRef) == 0) {
+        CGPoint pathpoint = CGContextGetPathCurrentPoint(cgRef);
+        CGRect pathbbox = CGContextGetPathBoundingBox(cgRef);
+        fprintf(stderr, "    [pathpoint: (%f, %f)] [pathbbox: ((%f, %f), (%f, %f))]\n",
+                pathpoint.x, pathpoint.y, pathbbox.origin.x, pathbbox.origin.y,
+                pathbbox.size.width, pathbbox.size.width);
+    }
+
+    CGFloat linewidth = CGContextGetLineWidth(cgRef);
+    CGLineCap linecap = CGContextGetLineCap(cgRef);
+    CGLineJoin linejoin = CGContextGetLineJoin(cgRef);
+    CGFloat miterlimit = CGContextGetMiterLimit(cgRef);
+    size_t dashcount = CGContextGetLineDashCount(cgRef);
+    fprintf(stderr, "    [linewidth: %f] [linecap: %d] [linejoin: %d] [miterlimit: %f] [dashcount: %lu]\n",
+            linewidth, linecap, linejoin, miterlimit, (unsigned long)dashcount);
+
+    CGFloat smoothness = CGContextGetSmoothness(cgRef);
+    bool antialias = CGContextGetShouldAntialias(cgRef);
+    bool smoothfont = CGContextGetShouldSmoothFonts(cgRef);
+    JRSFontRenderingStyle fRendMode = CGContextGetFontRenderingMode(cgRef);
+    fprintf(stderr, "    [smoothness: %f] [antialias: %d] [smoothfont: %d] [fontrenderingmode: %d]\n",
+            smoothness, antialias, smoothfont, fRendMode);
+#endif
+}
+#endif
+
+#ifdef CGGI_DEBUG
+
+static void
+DUMP_GLYPHINFO(const GlyphInfo *info)
+{
+    printf("size: (%d, %d) pixelSize: %d\n",
+           info->width, info->height, info->rowBytes / info->width);
+    printf("adv: (%f, %f) top: (%f, %f)\n",
+           info->advanceX, info->advanceY, info->topLeftX, info->topLeftY);
+
+#ifdef CGGI_DEBUG_DUMP
+    DUMP_PIXELS("Glyph Info Struct",
+                info->image, info->rowBytes / info->width,
+                info->width, info->height);
+#endif
+}
+
+#endif
+
+
+#pragma mark --- Font Rendering Mode Descriptors ---
+
+static inline void
+CGGI_CopyARGBPixelToRGBPixel(const UInt32 p, UInt8 *dst)
+{
+#if __LITTLE_ENDIAN__
+    *(dst + 2) = 0xFF - (p >> 24 & 0xFF);
+    *(dst + 1) = 0xFF - (p >> 16 & 0xFF);
+    *(dst) = 0xFF - (p >> 8 & 0xFF);
+#else
+    *(dst) = 0xFF - (p >> 16 & 0xFF);
+    *(dst + 1) = 0xFF - (p >> 8 & 0xFF);
+    *(dst + 2) = 0xFF - (p & 0xFF);
+#endif
+}
+
+static void
+CGGI_CopyImageFromCanvasToRGBInfo(CGGI_GlyphCanvas *canvas, GlyphInfo *info)
+{
+    UInt32 *src = (UInt32 *)canvas->image->data;
+    size_t srcRowWidth = canvas->image->width;
+
+    UInt8 *dest = (UInt8 *)info->image;
+    size_t destRowWidth = info->width;
+
+    size_t height = info->height;
+
+    size_t y;
+    for (y = 0; y < height; y++) {
+        size_t destRow = y * destRowWidth * 3;
+        size_t srcRow = y * srcRowWidth;
+
+        size_t x;
+        for (x = 0; x < destRowWidth; x++) {
+            // size_t x3 = x * 3;
+            // UInt32 p = src[srcRow + x];
+            // dest[destRow + x3] = 0xFF - (p >> 16 & 0xFF);
+            // dest[destRow + x3 + 1] = 0xFF - (p >> 8 & 0xFF);
+            // dest[destRow + x3 + 2] = 0xFF - (p & 0xFF);
+            CGGI_CopyARGBPixelToRGBPixel(src[srcRow + x],
+                                         dest + destRow + x * 3);
+        }
+    }
+}
+
+//static void CGGI_copyImageFromCanvasToAlphaInfo
+//(CGGI_GlyphCanvas *canvas, GlyphInfo *info)
+//{
+//    vImage_Buffer infoBuffer;
+//    infoBuffer.data = info->image;
+//    infoBuffer.width = info->width;
+//    infoBuffer.height = info->height;
+//    infoBuffer.rowBytes = info->width; // three bytes per RGB pixel
+//
+//    UInt8 scrapPixel[info->width * info->height];
+//    vImage_Buffer scrapBuffer;
+//    scrapBuffer.data = &scrapPixel;
+//    scrapBuffer.width = info->width;
+//    scrapBuffer.height = info->height;
+//    scrapBuffer.rowBytes = info->width;
+//
+//    vImageConvert_ARGB8888toPlanar8(canvas->image, &infoBuffer,
+//        &scrapBuffer, &scrapBuffer, &scrapBuffer, kvImageNoFlags);
+//}
+
+static inline UInt8
+CGGI_ConvertPixelToGreyBit(UInt32 p)
+{
+#ifdef __LITTLE_ENDIAN__
+    return 0xFF - ((p >> 24 & 0xFF) + (p >> 16 & 0xFF) + (p >> 8 & 0xFF)) / 3;
+#else
+    return 0xFF - ((p >> 16 & 0xFF) + (p >> 8 & 0xFF) + (p & 0xFF)) / 3;
+#endif
+}
+
+static void
+CGGI_CopyImageFromCanvasToAlphaInfo(CGGI_GlyphCanvas *canvas, GlyphInfo *info)
+{
+    UInt32 *src = (UInt32 *)canvas->image->data;
+    size_t srcRowWidth = canvas->image->width;
+
+    UInt8 *dest = (UInt8 *)info->image;
+    size_t destRowWidth = info->width;
+
+    size_t height = info->height;
+
+    size_t y;
+    for (y = 0; y < height; y++) {
+        size_t destRow = y * destRowWidth;
+        size_t srcRow = y * srcRowWidth;
+
+        size_t x;
+        for (x = 0; x < destRowWidth; x++) {
+            UInt32 p = src[srcRow + x];
+            dest[destRow + x] = CGGI_ConvertPixelToGreyBit(p);
+        }
+    }
+}
+
+
+#pragma mark --- Pixel Size, Modes, and Canvas Shaping Helper Functions ---
+
+typedef struct CGGI_GlyphInfoDescriptor {
+    size_t pixelSize;
+    void (*copyFxnPtr)(CGGI_GlyphCanvas *canvas, GlyphInfo *info);
+} CGGI_GlyphInfoDescriptor;
+
+typedef struct CGGI_RenderingMode {
+    CGGI_GlyphInfoDescriptor *glyphDescriptor;
+    JRSFontRenderingStyle cgFontMode;
+} CGGI_RenderingMode;
+
+static CGGI_GlyphInfoDescriptor grey =
+    { 1, &CGGI_CopyImageFromCanvasToAlphaInfo };
+static CGGI_GlyphInfoDescriptor rgb =
+    { 3, &CGGI_CopyImageFromCanvasToRGBInfo };
+
+static inline CGGI_RenderingMode
+CGGI_GetRenderingMode(const AWTStrike *strike)
+{
+    CGGI_RenderingMode mode;
+    mode.cgFontMode = strike->fStyle;
+
+    switch (strike->fAAStyle) {
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_DEFAULT:
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_OFF:
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_ON:
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_GASP:
+    default:
+        mode.glyphDescriptor = &grey;
+        break;
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_LCD_HBGR:
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
+    case sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_LCD_VBGR:
+        mode.glyphDescriptor = &rgb;
+        break;
+    }
+
+    return mode;
+}
+
+
+#pragma mark --- Canvas Managment ---
+
+/*
+ * Creates a new canvas of a fixed size, and initializes the CGContext as
+ * an 32-bit ARGB BitmapContext with some generic RGB color space.
+ */
+static inline void
+CGGI_InitCanvas(CGGI_GlyphCanvas *canvas,
+                const vImagePixelCount width, const vImagePixelCount height)
+{
+    // our canvas is *always* 4-byte ARGB
+    size_t bytesPerRow = width * sizeof(UInt32);
+    size_t byteCount = bytesPerRow * height;
+
+    canvas->image = malloc(sizeof(vImage_Buffer));
+    canvas->image->width = width;
+    canvas->image->height = height;
+    canvas->image->rowBytes = bytesPerRow;
+
+    canvas->image->data = (void *)calloc(byteCount, sizeof(UInt32));
+    if (canvas->image->data == NULL) {
+        [[NSException exceptionWithName:NSMallocException
+            reason:@"Failed to allocate memory for the buffer which backs the CGContext for glyph strikes." userInfo:nil] raise];
+    }
+
+    CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+    canvas->context = CGBitmapContextCreate(canvas->image->data,
+                                            width, height, 8, bytesPerRow,
+                                            colorSpace,
+                                            kCGImageAlphaPremultipliedFirst);
+
+    CGContextSetRGBFillColor(canvas->context, 0.0f, 0.0f, 0.0f, 1.0f);
+    CGContextSetFontSize(canvas->context, 1);
+    CGContextSaveGState(canvas->context);
+
+    CGColorSpaceRelease(colorSpace);
+}
+
+/*
+ * Releases the BitmapContext and the associated memory backing it.
+ */
+static inline void
+CGGI_FreeCanvas(CGGI_GlyphCanvas *canvas)
+{
+    if (canvas->context != NULL) {
+        CGContextRelease(canvas->context);
+    }
+
+    if (canvas->image != NULL) {
+        if (canvas->image->data != NULL) {
+            free(canvas->image->data);
+        }
+        free(canvas->image);
+    }
+}
+
+/*
+ * This is the slack space that is preallocated for the global GlyphCanvas
+ * when it needs to be expanded. It has been set somewhat liberally to
+ * avoid re-upsizing frequently.
+ */
+#define CGGI_GLYPH_CANVAS_SLACK 2.5
+
+/*
+ * Quick and easy inline to check if this canvas is big enough.
+ */
+static inline void
+CGGI_SizeCanvas(CGGI_GlyphCanvas *canvas, const vImagePixelCount width, const vImagePixelCount height, const JRSFontRenderingStyle style)
+{
+    if (canvas->image != NULL &&
+        width  < canvas->image->width &&
+        height < canvas->image->height)
+    {
+        return;
+    }
+
+    // if we don't have enough space to strike the largest glyph in the
+    // run, resize the canvas
+    CGGI_FreeCanvas(canvas);
+    CGGI_InitCanvas(canvas,
+                    width * CGGI_GLYPH_CANVAS_SLACK,
+                    height * CGGI_GLYPH_CANVAS_SLACK);
+    JRSFontSetRenderingStyleOnContext(canvas->context, style);
+}
+
+/*
+ * Clear the canvas by blitting white only into the region of interest
+ * (the rect which we will copy out of once the glyph is struck).
+ */
+static inline void
+CGGI_ClearCanvas(CGGI_GlyphCanvas *canvas, GlyphInfo *info)
+{
+    vImage_Buffer canvasRectToClear;
+    canvasRectToClear.data = canvas->image->data;
+    canvasRectToClear.height = info->height;
+    canvasRectToClear.width = info->width;
+    // use the row stride of the canvas, not the info
+    canvasRectToClear.rowBytes = canvas->image->rowBytes;
+
+    // clean the canvas
+#ifdef CGGI_DEBUG
+    Pixel_8888 opaqueWhite = { 0xE0, 0xE0, 0xE0, 0xE0 };
+#else
+    Pixel_8888 opaqueWhite = { 0xFF, 0xFF, 0xFF, 0xFF };
+#endif
+
+    vImageBufferFill_ARGB8888(&canvasRectToClear, opaqueWhite, kvImageNoFlags);
+}
+
+
+#pragma mark --- GlyphInfo Creation & Copy Functions ---
+
+/*
+ * Creates a GlyphInfo with exactly the correct size image and measurements.
+ */
+#define CGGI_GLYPH_BBOX_PADDING 2.0f
+static inline GlyphInfo *
+CGGI_CreateNewGlyphInfoFrom(CGSize advance, CGRect bbox,
+                            const CGGI_RenderingMode *mode)
+{
+    size_t pixelSize = mode->glyphDescriptor->pixelSize;
+
+    // adjust the bounding box to be 1px bigger on each side than what
+    // CGFont-whatever suggests - because it gives a bounding box that
+    // is too tight
+    bbox.size.width += CGGI_GLYPH_BBOX_PADDING * 2.0f;
+    bbox.size.height += CGGI_GLYPH_BBOX_PADDING * 2.0f;
+    bbox.origin.x -= CGGI_GLYPH_BBOX_PADDING;
+    bbox.origin.y -= CGGI_GLYPH_BBOX_PADDING;
+
+    vImagePixelCount width = ceilf(bbox.size.width);
+    vImagePixelCount height = ceilf(bbox.size.height);
+
+    // if the glyph is larger than 1MB, don't even try...
+    // the GlyphVector path should have taken over by now
+    // and zero pixels is ok
+    if (width * height > 1024 * 1024) {
+        width = 1;
+        height = 1;
+    }
+
+#ifdef USE_IMAGE_ALIGNED_MEMORY
+    // create separate memory
+    GlyphInfo *glyphInfo = (GlyphInfo *)malloc(sizeof(GlyphInfo));
+    void *image = (void *)malloc(height * width * pixelSize);
+#else
+    // create a GlyphInfo struct fused to the image it points to
+    GlyphInfo *glyphInfo = (GlyphInfo *)malloc(sizeof(GlyphInfo) +
+                                               height * width * pixelSize);
+#endif
+
+    glyphInfo->advanceX = advance.width;
+    glyphInfo->advanceY = advance.height;
+    glyphInfo->topLeftX = round(bbox.origin.x);
+    glyphInfo->topLeftY = round(bbox.origin.y);
+    glyphInfo->width = width;
+    glyphInfo->height = height;
+    glyphInfo->rowBytes = width * pixelSize;
+    glyphInfo->cellInfo = NULL;
+
+#ifdef USE_IMAGE_ALIGNED_MEMORY
+    glyphInfo->image = image;
+#else
+    glyphInfo->image = ((void *)glyphInfo) + sizeof(GlyphInfo);
+#endif
+
+    return glyphInfo;
+}
+
+
+#pragma mark --- Glyph Striking onto Canvas ---
+
+/*
+ * Clears the canvas, strikes the glyph with CoreGraphics, and then
+ * copies the struck pixels into the GlyphInfo image.
+ */
+static inline void
+CGGI_CreateImageForGlyph
+    (CGGI_GlyphCanvas *canvas, const CGGlyph glyph,
+     GlyphInfo *info, const CGGI_RenderingMode *mode)
+{
+    // clean the canvas
+    CGGI_ClearCanvas(canvas, info);
+
+    // strike the glyph in the upper right corner
+    CGContextShowGlyphsAtPoint(canvas->context,
+                               -info->topLeftX,
+                               canvas->image->height + info->topLeftY,
+                               &glyph, 1);
+
+    // copy the glyph from the canvas into the info
+    (*mode->glyphDescriptor->copyFxnPtr)(canvas, info);
+}
+
+/*
+ * CoreText path...
+ */
+static inline GlyphInfo *
+CGGI_CreateImageForUnicode
+    (CGGI_GlyphCanvas *canvas, const AWTStrike *strike,
+     const CGGI_RenderingMode *mode, const UniChar uniChar)
+{
+    // save the state of the world
+    CGContextSaveGState(canvas->context);
+
+    // get the glyph, measure it using CG
+    CGGlyph glyph;
+    CTFontRef fallback;
+    if (uniChar > 0xFFFF) {
+        UTF16Char charRef[2];
+        CTS_BreakupUnicodeIntoSurrogatePairs(uniChar, charRef);
+        CGGlyph glyphTmp[2];
+        fallback = CTS_CopyCTFallbackFontAndGlyphForUnicode(strike->fAWTFont, (const UTF16Char *)&charRef, (CGGlyph *)&glyphTmp, 2);
+        glyph = glyphTmp[0];
+    } else {
+        UTF16Char charRef;
+        charRef = (UTF16Char) uniChar; // truncate.
+        fallback = CTS_CopyCTFallbackFontAndGlyphForUnicode(strike->fAWTFont, (const UTF16Char *)&charRef, &glyph, 1);
+    }
+
+    CGAffineTransform tx = strike->fTx;
+    JRSFontRenderingStyle style = JRSFontAlignStyleForFractionalMeasurement(strike->fStyle);
+
+    CGRect bbox;
+    JRSFontGetBoundingBoxesForGlyphsAndStyle(fallback, &tx, style, &glyph, 1, &bbox);
+
+    CGSize advance;
+    JRSFontGetAdvancesForGlyphsAndStyle(fallback, &tx, strike->fStyle, &glyph, 1, &advance);
+
+    // create the Sun2D GlyphInfo we are going to strike into
+    GlyphInfo *info = CGGI_CreateNewGlyphInfoFrom(advance, bbox, mode);
+
+    // fix the context size, just in case the substituted character is unexpectedly large
+    CGGI_SizeCanvas(canvas, info->width, info->height, mode->cgFontMode);
+
+    // align the transform for the real CoreText strike
+    CGContextSetTextMatrix(canvas->context, strike->fAltTx);
+
+    const CGFontRef cgFallback = CTFontCopyGraphicsFont(fallback, NULL);
+    CGContextSetFont(canvas->context, cgFallback);
+    CFRelease(cgFallback);
+
+    // clean the canvas - align, strike, and copy the glyph from the canvas into the info
+    CGGI_CreateImageForGlyph(canvas, glyph, info, mode);
+
+    // restore the state of the world
+    CGContextRestoreGState(canvas->context);
+
+    CFRelease(fallback);
+#ifdef CGGI_DEBUG
+    DUMP_GLYPHINFO(info);
+#endif
+
+#ifdef CGGI_DEBUG_DUMP
+    DUMP_IMG_PIXELS("CGGI Canvas", canvas->image);
+#if 0
+    PRINT_CGSTATES_INFO(NULL);
+#endif
+#endif
+
+    return info;
+}
+
+
+#pragma mark --- GlyphInfo Filling and Canvas Managment ---
+
+/*
+ * Sets all the per-run properties for the canvas, and then iterates through
+ * the character run, and creates images in the GlyphInfo structs.
+ *
+ * Not inlined because it would create two copies in the function below
+ */
+static void
+CGGI_FillImagesForGlyphsWithSizedCanvas(CGGI_GlyphCanvas *canvas,
+                                        const AWTStrike *strike,
+                                        const CGGI_RenderingMode *mode,
+                                        jlong glyphInfos[],
+                                        const UniChar uniChars[],
+                                        const CGGlyph glyphs[],
+                                        const CFIndex len)
+{
+    CGContextSetTextMatrix(canvas->context, strike->fAltTx);
+
+    CGContextSetFont(canvas->context, strike->fAWTFont->fNativeCGFont);
+    JRSFontSetRenderingStyleOnContext(canvas->context, strike->fStyle);
+
+    CFIndex i;
+    for (i = 0; i < len; i++) {
+        GlyphInfo *info = (GlyphInfo *)jlong_to_ptr(glyphInfos[i]);
+        if (info != NULL) {
+            CGGI_CreateImageForGlyph(canvas, glyphs[i], info, mode);
+        } else {
+            info = CGGI_CreateImageForUnicode(canvas, strike, mode, uniChars[i]);
+            glyphInfos[i] = ptr_to_jlong(info);
+        }
+#ifdef CGGI_DEBUG
+        DUMP_GLYPHINFO(info);
+#endif
+
+#ifdef CGGI_DEBUG_DUMP
+        DUMP_IMG_PIXELS("CGGI Canvas", canvas->image);
+#endif
+    }
+#ifdef CGGI_DEBUG_DUMP
+    DUMP_IMG_PIXELS("CGGI Canvas", canvas->image);
+    PRINT_CGSTATES_INFO(canvas->context);
+#endif
+}
+
+static NSString *threadLocalCanvasKey =
+    @"Java CoreGraphics Text Renderer Cached Canvas";
+
+/*
+ * This is the maximum length and height times the above slack squared
+ * to determine if we go with the global canvas, or malloc one on the spot.
+ */
+#define CGGI_GLYPH_CANVAS_MAX 100
+
+/*
+ * Based on the space needed to strike the largest character in the run,
+ * either use the global shared canvas, or make one up on the spot, strike
+ * the glyphs, and destroy it.
+ */
+static inline void
+CGGI_FillImagesForGlyphs(jlong *glyphInfos, const AWTStrike *strike,
+                         const CGGI_RenderingMode *mode,
+                         const UniChar uniChars[], const CGGlyph glyphs[],
+                         const size_t maxWidth, const size_t maxHeight,
+                         const CFIndex len)
+{
+    if (maxWidth*maxHeight*CGGI_GLYPH_CANVAS_SLACK*CGGI_GLYPH_CANVAS_SLACK >
+        CGGI_GLYPH_CANVAS_MAX*CGGI_GLYPH_CANVAS_MAX*CGGI_GLYPH_CANVAS_SLACK*CGGI_GLYPH_CANVAS_SLACK)
+    {
+        CGGI_GlyphCanvas *tmpCanvas = [[CGGI_GlyphCanvas alloc] init];
+        CGGI_InitCanvas(tmpCanvas, maxWidth, maxHeight);
+        CGGI_FillImagesForGlyphsWithSizedCanvas(tmpCanvas, strike,
+                                                mode, glyphInfos, uniChars,
+                                                glyphs, len);
+        CGGI_FreeCanvas(tmpCanvas);
+
+        [tmpCanvas release];
+        return;
+    }
+
+    NSMutableDictionary *threadDict =
+        [[NSThread currentThread] threadDictionary];
+    CGGI_GlyphCanvas *canvas = [threadDict objectForKey:threadLocalCanvasKey];
+    if (canvas == nil) {
+        canvas = [[CGGI_GlyphCanvas alloc] init];
+        [threadDict setObject:canvas forKey:threadLocalCanvasKey];
+    }
+
+    CGGI_SizeCanvas(canvas, maxWidth, maxHeight, mode->cgFontMode);
+    CGGI_FillImagesForGlyphsWithSizedCanvas(canvas, strike, mode,
+                                            glyphInfos, uniChars, glyphs, len);
+}
+
+/*
+ * Finds the advances and bounding boxes of the characters in the run,
+ * cycles through all the bounds and calculates the maximum canvas space
+ * required by the largest glyph.
+ *
+ * Creates a GlyphInfo struct with a malloc that also encapsulates the
+ * image the struct points to.  This is done to meet memory layout
+ * expectations in the Sun text rasterizer memory managment code.
+ * The image immediately follows the struct physically in memory.
+ */
+static inline void
+CGGI_CreateGlyphInfos(jlong *glyphInfos, const AWTStrike *strike,
+                      const CGGI_RenderingMode *mode,
+                      const UniChar uniChars[], const CGGlyph glyphs[],
+                      CGSize advances[], CGRect bboxes[], const CFIndex len)
+{
+    AWTFont *font = strike->fAWTFont;
+    CGAffineTransform tx = strike->fTx;
+    JRSFontRenderingStyle bboxCGMode = JRSFontAlignStyleForFractionalMeasurement(strike->fStyle);
+
+    JRSFontGetBoundingBoxesForGlyphsAndStyle((CTFontRef)font->fFont, &tx, bboxCGMode, glyphs, len, bboxes);
+    JRSFontGetAdvancesForGlyphsAndStyle((CTFontRef)font->fFont, &tx, strike->fStyle, glyphs, len, advances);
+
+    size_t maxWidth = 1;
+    size_t maxHeight = 1;
+
+    CFIndex i;
+    for (i = 0; i < len; i++)
+    {
+        if (uniChars[i] != 0)
+        {
+            glyphInfos[i] = 0L;
+            continue; // will be handled later
+        }
+
+        CGSize advance = advances[i];
+        CGRect bbox = bboxes[i];
+
+        GlyphInfo *glyphInfo = CGGI_CreateNewGlyphInfoFrom(advance, bbox, mode);
+
+        if (maxWidth < glyphInfo->width)   maxWidth = glyphInfo->width;
+        if (maxHeight < glyphInfo->height) maxHeight = glyphInfo->height;
+
+        glyphInfos[i] = ptr_to_jlong(glyphInfo);
+    }
+
+    CGGI_FillImagesForGlyphs(glyphInfos, strike, mode, uniChars,
+                             glyphs, maxWidth, maxHeight, len);
+}
+
+
+#pragma mark --- Temporary Buffer Allocations and Initialization ---
+
+/*
+ * This stage separates the already valid glyph codes from the unicode values
+ * that need special handling - the rawGlyphCodes array is no longer used
+ * after this stage.
+ */
+static void
+CGGI_CreateGlyphsAndScanForComplexities(jlong *glyphInfos,
+                                        const AWTStrike *strike,
+                                        const CGGI_RenderingMode *mode,
+                                        jint rawGlyphCodes[],
+                                        UniChar uniChars[], CGGlyph glyphs[],
+                                        CGSize advances[], CGRect bboxes[],
+                                        const CFIndex len)
+{
+    CFIndex i;
+    for (i = 0; i < len; i++) {
+        jint code = rawGlyphCodes[i];
+        if (code < 0) {
+            glyphs[i] = 0;
+            uniChars[i] = -code;
+        } else {
+            glyphs[i] = code;
+            uniChars[i] = 0;
+        }
+    }
+
+    CGGI_CreateGlyphInfos(glyphInfos, strike, mode,
+                          uniChars, glyphs, advances, bboxes, len);
+
+#ifdef CGGI_DEBUG_HIT_COUNT
+    static size_t hitCount = 0;
+    hitCount++;
+    printf("%d\n", (int)hitCount);
+#endif
+}
+
+/*
+ * Conditionally stack allocates buffers for glyphs, bounding boxes,
+ * and advances.  Unfortunately to use CG or CT in bulk runs (which is
+ * faster than calling them per character), we have to copy into and out
+ * of these buffers. Still a net win though.
+ */
+void
+CGGlyphImages_GetGlyphImagePtrs(jlong glyphInfos[],
+                                const AWTStrike *strike,
+                                jint rawGlyphCodes[], const CFIndex len)
+{
+    const CGGI_RenderingMode mode = CGGI_GetRenderingMode(strike);
+
+    if (len < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) {
+        CGRect bboxes[len];
+        CGSize advances[len];
+        CGGlyph glyphs[len];
+        UniChar uniChars[len];
+
+        CGGI_CreateGlyphsAndScanForComplexities(glyphInfos, strike, &mode,
+                                                rawGlyphCodes, uniChars, glyphs,
+                                                advances, bboxes, len);
+
+        return;
+    }
+
+    // just do one malloc, and carve it up for all the buffers
+    void *buffer = malloc(sizeof(CGRect) * sizeof(CGSize) *
+                          sizeof(CGGlyph) * sizeof(UniChar) * len);
+    if (buffer == NULL) {
+        [[NSException exceptionWithName:NSMallocException
+            reason:@"Failed to allocate memory for the temporary glyph strike and measurement buffers." userInfo:nil] raise];
+    }
+
+    CGRect *bboxes = (CGRect *)(buffer);
+    CGSize *advances = (CGSize *)(bboxes + sizeof(CGRect) * len);
+    CGGlyph *glyphs = (CGGlyph *)(advances + sizeof(CGGlyph) * len);
+    UniChar *uniChars = (UniChar *)(glyphs + sizeof(UniChar) * len);
+
+    CGGI_CreateGlyphsAndScanForComplexities(glyphInfos, strike, &mode,
+                                            rawGlyphCodes, uniChars, glyphs,
+                                            advances, bboxes, len);
+
+    free(buffer);
+}
diff --git a/jdk/src/macosx/native/sun/font/CGGlyphOutlines.h b/jdk/src/macosx/native/sun/font/CGGlyphOutlines.h
new file mode 100644
index 0000000..de43dc9
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/CGGlyphOutlines.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Foundation/Foundation.h>
+#import <ApplicationServices/ApplicationServices.h>
+#import <AppKit/NSFont.h>
+#include <jni.h>
+
+#define kStorageSizeChangeOnGetMoreFactor 2
+#define kInitialAllocatedPathSegments 2048
+
+typedef enum  {
+    eMoveTo    = 0,
+    eLineTo    = 1,
+    eQuadTo    = 2,
+    eCubicTo   = 3,
+    eClosePath = 4
+} AWTPathSegmentType;
+
+typedef struct AWTPath {
+    CGSize  fTranslate;
+    UInt32  fNumberOfSegments;
+    jfloat* fSegmentData;
+    jbyte*  fSegmentType;
+    UInt32  fNumberOfDataElements;
+    UInt32  fAllocatedSegmentTypeSpace;
+    UInt32  fAllocatedSegmentDataSpace;
+} AWTPath, *AWTPathRef;
+
+AWTPathRef AWTPathCreate(CGSize translate);
+void AWTPathFree(AWTPathRef pathRef);
+OSStatus AWTGetGlyphOutline(CGGlyph *glyphs, NSFont *font,
+                            CGSize *advances,
+                            CGAffineTransform *inAffineTransform,
+                            UInt32 inStartIndex, size_t length,
+                            AWTPathRef* outPath);
diff --git a/jdk/src/macosx/native/sun/font/CGGlyphOutlines.m b/jdk/src/macosx/native/sun/font/CGGlyphOutlines.m
new file mode 100644
index 0000000..a0546bc
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/CGGlyphOutlines.m
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CGGlyphOutlines.h"
+
+static void
+AWTPathGetMoreSpaceIfNecessary(AWTPathRef path)
+{
+    while ((path->fAllocatedSegmentTypeSpace - path->fNumberOfSegments) < 1) {
+        size_t growth = sizeof(jbyte)*path->fAllocatedSegmentTypeSpace*kStorageSizeChangeOnGetMoreFactor;
+        path->fSegmentType = (jbyte*) realloc(path->fSegmentType, growth);
+        path->fAllocatedSegmentTypeSpace *= kStorageSizeChangeOnGetMoreFactor;
+    }
+
+    while ((path->fAllocatedSegmentDataSpace - path->fNumberOfDataElements) < 7) {
+        size_t growth = sizeof(jfloat)*path->fAllocatedSegmentDataSpace*kStorageSizeChangeOnGetMoreFactor;
+        path->fSegmentData = (jfloat*) realloc(path->fSegmentData, growth);
+        path->fAllocatedSegmentDataSpace *= kStorageSizeChangeOnGetMoreFactor;
+    }
+}
+
+static void
+AWTPathMoveTo(void* data, CGPoint p)
+{
+    CGFloat x = p.x;
+    CGFloat y = p.y;
+
+    AWTPathRef path = (AWTPathRef)data;
+    CGFloat tx    = path->fTranslate.width;
+    CGFloat ty    = path->fTranslate.height;
+    CGFloat pathX =  x+tx;
+    CGFloat pathY = -y+ty;
+
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "eMoveTo \n");
+    fprintf(stderr, "    tx=%f, ty=%f\n", tx, ty);
+    fprintf(stderr, "    x=%f, y=%f\n", x, y);
+    fprintf(stderr, "    pathX=%f, pathY=%f\n", pathX, pathY);
+#endif
+
+    AWTPathGetMoreSpaceIfNecessary(path);
+
+    path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eMoveTo;
+
+    path->fSegmentData[path->fNumberOfDataElements++] = pathX;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathY;
+}
+
+static void
+AWTPathLineTo(void* data, CGPoint p)
+{
+    CGFloat x = p.x;
+    CGFloat y = p.y;
+
+    AWTPathRef path = (AWTPathRef)data;
+    CGFloat tx    = path->fTranslate.width;
+    CGFloat ty    = path->fTranslate.height;
+    CGFloat pathX =  x+tx;
+    CGFloat pathY = -y+ty;
+
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "eLineTo \n");
+    fprintf(stderr, "    tx=%f, ty=%f\n", tx, ty);
+    fprintf(stderr, "    x=%f, y=%f\n", x, y);
+    fprintf(stderr, "    pathX=%f, pathY=%f\n", pathX, pathY);
+#endif
+
+    AWTPathGetMoreSpaceIfNecessary(path);
+
+    path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eLineTo;
+
+    path->fSegmentData[path->fNumberOfDataElements++] = pathX;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathY;
+}
+
+static void
+AWTPathQuadTo(void* data, CGPoint p1, CGPoint p2)
+{
+    CGFloat x1 = p1.x;
+    CGFloat y1 = p1.y;
+    CGFloat x2 = p2.x;
+    CGFloat y2 = p2.y;
+
+    AWTPathRef path = (AWTPathRef)data;
+    CGFloat tx     = path->fTranslate.width;
+    CGFloat ty     = path->fTranslate.height;
+    CGFloat pathX1 =  x1+tx;
+    CGFloat pathY1 = -y1+ty;
+    CGFloat pathX2 =  x2+tx;
+    CGFloat pathY2 = -y2+ty;
+
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "eQuadTo \n");
+    fprintf(stderr, "    tx=%f, ty=%f\n", tx, ty);
+    fprintf(stderr, "    x1=%f, y1=%f\n", x1, y1);
+    fprintf(stderr, "    x2=%f, y2=%f\n", x2, y2);
+    fprintf(stderr, "    pathX1=%f, path1Y=%f\n", pathX1, pathY1);
+    fprintf(stderr, "    pathX2=%f, pathY2=%f\n", pathX2, pathY2);
+#endif
+
+    AWTPathGetMoreSpaceIfNecessary(path);
+
+    path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eQuadTo;
+
+    path->fSegmentData[path->fNumberOfDataElements++] = pathX1;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathY1;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathX2;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathY2;
+}
+
+static void
+AWTPathCubicTo(void* data, CGPoint p1, CGPoint p2, CGPoint p3)
+{
+    CGFloat x1 = p1.x;
+    CGFloat y1 = p1.y;
+    CGFloat x2 = p2.x;
+    CGFloat y2 = p2.y;
+    CGFloat x3 = p3.x;
+    CGFloat y3 = p3.y;
+
+    AWTPathRef path = (AWTPathRef)data;
+    CGFloat tx     = path->fTranslate.width;
+    CGFloat ty     = path->fTranslate.height;
+    CGFloat pathX1 =  x1+tx;
+    CGFloat pathY1 = -y1+ty;
+    CGFloat pathX2 =  x2+tx;
+    CGFloat pathY2 = -y2+ty;
+    CGFloat pathX3 =  x3+tx;
+    CGFloat pathY3 = -y3+ty;
+
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "eCubicTo \n");
+    fprintf(stderr, "    tx=%f, ty=%f\n", tx, ty);
+    fprintf(stderr, "    x1=%f, y1=%f\n", x1, y1);
+    fprintf(stderr, "    x2=%f, y2=%f\n", x2, y2);
+    fprintf(stderr, "    x3=%f, y3=%f\n", x3, y3);
+    fprintf(stderr, "    pathX1=%f, path1Y=%f\n", pathX1, pathY1);
+    fprintf(stderr, "    pathX2=%f, pathY2=%f\n", pathX2, pathY2);
+    fprintf(stderr, "    pathX3=%f, pathY3=%f\n", pathX3, pathY3);
+#endif
+
+    AWTPathGetMoreSpaceIfNecessary(path);
+
+    path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eCubicTo;
+
+    path->fSegmentData[path->fNumberOfDataElements++] = pathX1;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathY1;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathX2;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathY2;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathX3;
+    path->fSegmentData[path->fNumberOfDataElements++] = pathY3;
+}
+
+static void
+AWTPathClose(void* data)
+{
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "GVGlyphPathCallBackClosePath \n");
+#endif
+
+    AWTPathRef path = (AWTPathRef) data;
+    AWTPathGetMoreSpaceIfNecessary(path);
+
+    path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eClosePath;
+}
+
+AWTPathRef
+AWTPathCreate(CGSize translate)
+{
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "AWTPathCreate \n");
+    fprintf(stderr, "    translate.width=%f \n", translate.width);
+    fprintf(stderr, "    translate.height=%f \n", translate.height);
+#endif
+
+    AWTPathRef path = (AWTPathRef) malloc(sizeof(AWTPath));
+    path->fTranslate    = translate;
+    path->fSegmentData  = (jfloat*)malloc(sizeof(jfloat) * kInitialAllocatedPathSegments);
+    path->fSegmentType  = (jbyte*)malloc(sizeof(jbyte) * kInitialAllocatedPathSegments);
+    path->fNumberOfDataElements = 0;
+    path->fNumberOfSegments = 0;
+    path->fAllocatedSegmentTypeSpace = kInitialAllocatedPathSegments;
+    path->fAllocatedSegmentDataSpace = kInitialAllocatedPathSegments;
+
+    return path;
+}
+
+void
+AWTPathFree(AWTPathRef pathRef)
+{
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "--B--AWTPathFree\n");
+    fprintf(stderr, "pathRef->fSegmentData (%p)\n",pathRef->fSegmentData);
+#endif
+
+    free(pathRef->fSegmentData);
+    //fprintf(stderr, "pathRef->fSegmentType (%d)\n",pathRef->fSegmentType);
+    free(pathRef->fSegmentType);
+    //fprintf(stderr, "pathRef (%d)\n", pathRef);
+    free(pathRef);
+    //fprintf(stderr, "--E--AWTPathFree\n");
+}
+
+static void
+AWTPathApplierCallback(void *info, const CGPathElement *element)
+{
+    switch (element->type) {
+    case kCGPathElementMoveToPoint:
+        AWTPathMoveTo(info, element->points[0]);
+        break;
+    case kCGPathElementAddLineToPoint:
+        AWTPathLineTo(info, element->points[0]);
+        break;
+    case kCGPathElementAddQuadCurveToPoint:
+        AWTPathQuadTo(info, element->points[0], element->points[1]);
+        break;
+    case kCGPathElementAddCurveToPoint:
+        AWTPathCubicTo(info, element->points[0],
+                       element->points[1], element->points[2]);
+        break;
+    case kCGPathElementCloseSubpath:
+        AWTPathClose(info);
+        break;
+    }
+}
+
+OSStatus
+AWTGetGlyphOutline(CGGlyph *glyphs, NSFont *font,
+                   CGSize *advanceArray, CGAffineTransform *tx,
+                   UInt32 inStartIndex, size_t length,
+                   AWTPathRef* outPath)
+{
+#ifdef AWT_GV_DEBUG
+    fprintf(stderr, "AWTGetGlyphOutline\n");
+    fprintf(stderr, "    inAffineTransform a=%f, b=%f, c=%f, d=%f, tx=%f, ty=%f \n", tx->a, tx->b, tx->c, tx->d, tx->tx, tx->ty);
+#endif
+
+    OSStatus status = noErr;
+
+    glyphs = glyphs + inStartIndex;
+//    advanceArray = advanceArray + inStartIndex; // TODO(cpc): use advance
+
+    CGPathRef cgPath = CTFontCreatePathForGlyph((CTFontRef)font, glyphs[0], tx);
+    CGPathApply(cgPath, *outPath, AWTPathApplierCallback);
+    CGPathRelease(cgPath);
+
+    return status;
+}
diff --git a/jdk/src/macosx/native/sun/font/CoreTextSupport.h b/jdk/src/macosx/native/sun/font/CoreTextSupport.h
new file mode 100644
index 0000000..0373544
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/CoreTextSupport.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaVM/jni.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#include "AWTFont.h"
+
+#pragma mark --- CoreText Support ---
+
+#define HI_SURROGATE_START 0xD800
+#define LO_SURROGATE_START 0xDC00
+
+/*
+ *    Transform Unicode characters into glyphs.
+ *
+ *    Fills the "glyphsAsInts" array with the glyph codes for the current font,
+ *    or the negative unicode value if we know the character can be hot-substituted.
+ *
+ *    This is the heart of "Universal Font Substitution" in Java.
+ */
+void CTS_GetGlyphsAsIntsForCharacters(const AWTFont *font, const UniChar unicodes[], CGGlyph glyphs[], jint glyphsAsInts[], const size_t count);
+
+// Translates a Java glyph code int (might be a negative unicode value) into a CGGlyph/CTFontRef pair
+// Returns the substituted font, and places the appropriate glyph into "glyph"
+CTFontRef CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(const AWTFont *font, const jint glyphCode, CGGlyph *glyphRef);
+
+// Translates a Unicode into a CGGlyph/CTFontRef pair
+// Returns the substituted font, and places the appropriate glyph into "glyphRef"
+CTFontRef CTS_CopyCTFallbackFontAndGlyphForUnicode(const AWTFont *font, const UTF16Char *charRef, CGGlyph *glyphRef, int count);
+
+// Breakup a 32 bit unicode value into the component surrogate pairs
+void CTS_BreakupUnicodeIntoSurrogatePairs(int uniChar, UTF16Char charRef[]);
+
+
+// Basic struct that holds everything CoreText is interested in
+typedef struct CTS_ProviderStruct {
+    const UniChar         *unicodes;
+    CFIndex                length;
+    CFMutableDictionaryRef attributes;
+} CTS_ProviderStruct;
diff --git a/jdk/src/macosx/native/sun/font/CoreTextSupport.m b/jdk/src/macosx/native/sun/font/CoreTextSupport.m
new file mode 100644
index 0000000..44b5170
--- /dev/null
+++ b/jdk/src/macosx/native/sun/font/CoreTextSupport.m
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import "CoreTextSupport.h"
+
+
+/*
+ * Callback for CoreText which uses the CoreTextProviderStruct to
+ * feed CT UniChars.  We only use it for one-off lines, and don't
+ * attempt to fragment our strings.
+ */
+const UniChar *
+CTS_Provider(CFIndex stringIndex, CFIndex *charCount,
+             CFDictionaryRef *attributes, void *refCon)
+{
+    // if we have a zero length string we can just return NULL for the string
+    // or if the index anything other than 0 we are not using core text
+    // correctly since we only have one run.
+    if (stringIndex != 0) {
+        return NULL;
+    }
+
+    CTS_ProviderStruct *ctps = (CTS_ProviderStruct *)refCon;
+    *charCount = ctps->length;
+    *attributes = ctps->attributes;
+    return ctps->unicodes;
+}
+
+
+#pragma mark --- Retain/Release CoreText State Dictionary ---
+
+/*
+ * Gets a Dictionary filled with common details we want to use for CoreText
+ * when we are interacting with it from Java.
+ */
+static inline CFMutableDictionaryRef
+GetCTStateDictionaryFor(const NSFont *font, BOOL useFractionalMetrics)
+{
+    NSNumber *gZeroNumber = [NSNumber numberWithInt:0];
+    NSNumber *gOneNumber = [NSNumber numberWithInt:1];
+
+    CFMutableDictionaryRef dictRef = (CFMutableDictionaryRef)
+        [[NSMutableDictionary alloc] initWithObjectsAndKeys:
+        font, NSFontAttributeName,
+        // TODO(cpc): following attribute is private...
+        //gOneNumber,  (id)kCTForegroundColorFromContextAttributeName,
+        // force integer hack in CoreText to help with Java integer assumptions
+        useFractionalMetrics ? gZeroNumber : gOneNumber, @"CTIntegerMetrics",
+        gZeroNumber, NSLigatureAttributeName,
+        gZeroNumber, NSKernAttributeName,
+        NULL];
+    CFRetain(dictRef); // GC
+    [(id)dictRef release];
+
+    return dictRef;
+}
+
+/*
+ * Releases the CoreText Dictionary - in the future we should hold on
+ * to these to improve performance.
+ */
+static inline void
+ReleaseCTStateDictionary(CFDictionaryRef ctStateDict)
+{
+    CFRelease(ctStateDict); // GC
+}
+
+/*
+ *    Transform Unicode characters into glyphs.
+ *
+ *    Fills the "glyphsAsInts" array with the glyph codes for the current font,
+ *    or the negative unicode value if we know the character can be hot-substituted.
+ *
+ *    This is the heart of "Universal Font Substitution" in Java.
+ */
+void CTS_GetGlyphsAsIntsForCharacters
+(const AWTFont *font, const UniChar unicodes[], CGGlyph glyphs[], jint glyphsAsInts[], const size_t count)
+{
+    CTFontGetGlyphsForCharacters((CTFontRef)font->fFont, unicodes, glyphs, count);
+
+    size_t i;
+    for (i = 0; i < count; i++) {
+        CGGlyph glyph = glyphs[i];
+        if (glyph > 0) {
+            glyphsAsInts[i] = glyph;
+            continue;
+        }
+
+        UniChar unicode = unicodes[i];
+        const CTFontRef fallback = JRSFontCreateFallbackFontForCharacters((CTFontRef)font->fFont, &unicode, 1);
+        if (fallback) {
+            CTFontGetGlyphsForCharacters(fallback, &unicode, &glyph, 1);
+            CFRelease(fallback);
+        }
+
+        if (glyph > 0) {
+            glyphsAsInts[i] = -unicode; // set the glyph code to the negative unicode value
+        } else {
+            glyphsAsInts[i] = 0; // CoreText couldn't find a glyph for this character either
+        }
+    }
+}
+
+/*
+ * Translates a Unicode into a CGGlyph/CTFontRef pair
+ * Returns the substituted font, and places the appropriate glyph into "glyphRef"
+ */
+CTFontRef CTS_CopyCTFallbackFontAndGlyphForUnicode
+(const AWTFont *font, const UTF16Char *charRef, CGGlyph *glyphRef, int count) {
+    CTFontRef fallback = JRSFontCreateFallbackFontForCharacters((CTFontRef)font->fFont, charRef, count);
+    if (fallback == NULL)
+    {
+        // use the original font if we somehow got duped into trying to fallback something we can't
+        fallback = (CTFontRef)font->fFont;
+        CFRetain(fallback);
+    }
+
+    CTFontGetGlyphsForCharacters(fallback, charRef, glyphRef, count);
+    return fallback;
+}
+
+/*
+ * Translates a Java glyph code int (might be a negative unicode value) into a CGGlyph/CTFontRef pair
+ * Returns the substituted font, and places the appropriate glyph into "glyphRef"
+ */
+CTFontRef CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode
+(const AWTFont *font, const jint glyphCode, CGGlyph *glyphRef)
+{
+    // negative glyph codes are really unicodes, which were placed there by the mapper
+    // to indicate we should use CoreText to substitute the character
+    if (glyphCode >= 0)
+    {
+        *glyphRef = glyphCode;
+        CFRetain(font->fFont);
+        return (CTFontRef)font->fFont;
+    }
+
+    UTF16Char character = -glyphCode;
+    return CTS_CopyCTFallbackFontAndGlyphForUnicode(font, &character, glyphRef, 1);
+}
+
+// Breakup a 32 bit unicode value into the component surrogate pairs
+void CTS_BreakupUnicodeIntoSurrogatePairs(int uniChar, UTF16Char charRef[]) {
+    int value = uniChar - 0x10000;
+    UTF16Char low_surrogate = (value & 0x3FF) | LO_SURROGATE_START;
+    UTF16Char high_surrogate = (((int)(value & 0xFFC00)) >> 10) | HI_SURROGATE_START;
+    charRef[0] = high_surrogate;
+    charRef[1] = low_surrogate;
+}
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.h b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.h
new file mode 100644
index 0000000..fb83dce
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef CGLGraphicsConfig_h_Included
+#define CGLGraphicsConfig_h_Included
+
+#import "jni.h"
+#import "J2D_GL/gl.h"
+#import "OGLSurfaceData.h"
+#import "OGLContext.h"
+#import <Cocoa/Cocoa.h>
+
+@interface GraphicsConfigUtil : NSObject {}
+@end
+
+// Prototyped CAOpenGLLayer drawing directly from Java2D OpenGL rendering
+// pipe fails to draw entire scene. So, the following enables alternative
+// codepath that uses a FBO backed with a texture as an intermediate buffer.
+// Java2D OpenGL rendering pipe performs rendering to the intermediate buffer
+// and CAOpenGLLayer copies the entire intermediate buffer to layer.
+
+// The prototype implementation creates a CAOpenGLLayer tied to a NSView/NSWindow.
+// To provide purely offscreen CAOpenGLLayer, disable the prototype and
+// enable the alternative codepath implemented as a part of MACOSX_PORT-766.
+//#define USE_INTERMEDIATE_BUFFER 1
+
+// Uncomment the next line to enable using IO Surface based drawing.
+// It has to be used *in conjunction* with USE_INTERMEDIATE_BUFFERS
+// It presently has more artifacts than the straight 2D texture drawing
+// but both seem to have some of the same issues.
+//#define USE_IOS 1
+
+// REMIND: Using an NSOpenGLPixelBuffer as the scratch surface has been
+// problematic thus far (seeing garbage and flickering when switching
+// between an NSView and the scratch surface), so the following enables
+// an alternate codepath that uses a hidden NSWindow/NSView as the scratch
+// surface, for the purposes of making a context current in certain
+// situations.  It appears that calling [NSOpenGLContext setView] too
+// frequently contributes to the bad behavior, so we should try to avoid
+// switching to the scratch surface whenever possible.
+#ifndef USE_IOS
+/* Do we we need this if we are using all off-screen drawing ? */
+#define USE_NSVIEW_FOR_SCRATCH 1
+
+/* Uncomment to have an additional CAOGLLayer instance tied to
+ * each instance, which can be used to test remoting the layer
+ * to an out of process window. The additional layer is needed
+ * because a layer can only be attached to one context (view/window).
+ * This is only for testing purposes and can be removed if/when no
+ * longer needed.
+ */
+//#ifdef USE_INTERMEDIATE_BUFFER
+//#define REMOTELAYER 1
+//#endif
+
+#ifdef REMOTELAYER
+#import <JavaRuntimeSupport/JRSRemoteLayer.h>
+#import <pthread.h>
+#include <unistd.h>
+#include <stdio.h>
+#import <sys/socket.h>
+#import <sys/un.h>
+
+extern mach_port_t JRSRemotePort;
+extern int remoteSocketFD;
+extern void sendLayerID(int layerID);
+
+#endif /* REMOTELAYER */
+
+#endif
+
+
+
+/**
+ * The CGLGraphicsConfigInfo structure contains information specific to a
+ * given CGLGraphicsConfig (pixel format).
+ *
+ *     jint screen;
+ * The screen and PixelFormat for the associated CGLGraphicsConfig.
+ *
+ *     NSOpenGLPixelFormat *pixfmt;
+ * The pixel format of the native NSOpenGL context.
+ *
+ *     OGLContext *context;
+ * The context associated with this CGLGraphicsConfig.
+ */
+typedef struct _CGLGraphicsConfigInfo {
+    jint                screen;
+    NSOpenGLPixelFormat *pixfmt;
+    OGLContext          *context;
+} CGLGraphicsConfigInfo;
+
+/**
+ * The CGLCtxInfo structure contains the native CGLContext information
+ * required by and is encapsulated by the platform-independent OGLContext
+ * structure.
+ *
+ *     NSOpenGLContext *context;
+ * The core native NSOpenGL context.  Rendering commands have no effect until
+ * a context is made current (active).
+ *
+ *     NSOpenGLPixelBuffer *scratchSurface;
+ * The scratch surface id used to make a context current when we do
+ * not otherwise have a reference to an OpenGL surface for the purposes of
+ * making a context current.
+ */
+typedef struct _CGLCtxInfo {
+    NSOpenGLContext     *context;
+#if USE_NSVIEW_FOR_SCRATCH
+    NSView              *scratchSurface;
+#else
+    NSOpenGLPixelBuffer *scratchSurface;
+#endif
+} CGLCtxInfo;
+
+#endif /* CGLGraphicsConfig_h_Included */
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
new file mode 100644
index 0000000..43336f9
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
@@ -0,0 +1,443 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <stdlib.h>
+#import <string.h>
+#import <ApplicationServices/ApplicationServices.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "sun_java2d_opengl_CGLGraphicsConfig.h"
+
+#import "jni.h"
+#import "jni_util.h"
+#import "CGLGraphicsConfig.h"
+#import "CGLSurfaceData.h"
+#import "LWCToolkit.h"
+#import "ThreadUtilities.h"
+
+#pragma mark -
+#pragma mark "--- Mac OS X specific methods for GL pipeline ---"
+
+/**
+ * Disposes all memory and resources associated with the given
+ * CGLGraphicsConfigInfo (including its native OGLContext data).
+ */
+void
+OGLGC_DestroyOGLGraphicsConfig(jlong pConfigInfo)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "OGLGC_DestroyOGLGraphicsConfig");
+
+    CGLGraphicsConfigInfo *cglinfo =
+        (CGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
+    if (cglinfo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR,
+                      "OGLGC_DestroyOGLGraphicsConfig: info is null");
+        return;
+    }
+
+    OGLContext *oglc = (OGLContext*)cglinfo->context;
+    if (oglc != NULL) {
+        OGLContext_DestroyContextResources(oglc);
+
+        CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+        if (ctxinfo != NULL) {
+            [NSOpenGLContext clearCurrentContext];
+            [ctxinfo->context clearDrawable];
+            [ctxinfo->context release];
+            if (ctxinfo->scratchSurface != 0) {
+                [ctxinfo->scratchSurface release];
+            }
+            free(ctxinfo);
+        }
+    }
+
+    free(cglinfo);
+}
+
+#pragma mark -
+#pragma mark "--- CGLGraphicsConfig methods ---"
+
+#ifdef REMOTELAYER
+mach_port_t JRSRemotePort;
+int remoteSocketFD = -1;
+
+static void *JRSRemoteThreadFn(void *data) {
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+    // Negotiate a unix domain socket to communicate the
+    // out of band data: to read the mach port server name, and
+    // subsequently write out the layer ID.
+    static char* sock_path = "/tmp/JRSRemoteDemoSocket";
+    struct sockaddr_un address;
+    int  socket_fd, nbytes;
+    int BUFLEN = 256;
+    char buffer[BUFLEN];
+
+    remoteSocketFD = socket(PF_LOCAL, SOCK_STREAM, 0);
+    if (remoteSocketFD < 0) {
+        NSLog(@"socket() failed");
+        return NULL;
+    }
+    memset(&address, 0, sizeof(struct sockaddr_un));
+    address.sun_family = AF_UNIX;
+    memcpy(address.sun_path, sock_path, strlen(sock_path)+1);
+    int tries=0, status=-1;
+    while (status !=0 && tries<600) {
+        status = connect(remoteSocketFD, (struct sockaddr *) &address,
+                         sizeof(struct sockaddr_un));
+        if (status != 0) {
+            tries++;
+            NSLog(@"connection attempt %d failed.", tries);
+            usleep(5000000);
+        }
+    }
+    if (status != 0) {
+        NSLog(@"failed to connect");
+        return NULL;
+    }
+    nbytes = read(remoteSocketFD, buffer, BUFLEN);
+    NSString* serverString = [[NSString alloc] initWithUTF8String:buffer];
+    CFRetain(serverString);
+    NSLog(@"Read server name %@", serverString);
+    JRSRemotePort = [JRSRenderServer recieveRenderServer:serverString];
+    NSLog(@"Read server port %d", JRSRemotePort);
+
+    [pool drain];
+    return NULL;
+}
+
+void sendLayerID(int layerID) {
+    if (JRSRemotePort == 0 || remoteSocketFD < 0) {
+        NSLog(@"No connection to send ID");
+        return;
+    }
+    int BUFLEN = 256;
+    char buffer[BUFLEN];
+    snprintf(buffer, BUFLEN, "%d", layerID);
+    write(remoteSocketFD, buffer, BUFLEN);
+}
+#endif  /* REMOTELAYER */
+
+/**
+ * This is a globally shared context used when creating textures.  When any
+ * new contexts are created, they specify this context as the "share list"
+ * context, which means any texture objects created when this shared context
+ * is current will be available to any other context in any other thread.
+ */
+NSOpenGLContext *sharedContext = NULL;
+NSOpenGLPixelFormat *sharedPixelFormat = NULL;
+
+/**
+ * Attempts to initialize CGL and the core OpenGL library.
+ */
+JNIEXPORT jboolean JNICALL
+Java_sun_java2d_opengl_CGLGraphicsConfig_initCGL
+    (JNIEnv *env, jclass cglgc)
+{
+    J2dRlsTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_initCGL");
+
+    if (!OGLFuncs_OpenLibrary()) {
+        return JNI_FALSE;
+    }
+
+    if (!OGLFuncs_InitPlatformFuncs() ||
+        !OGLFuncs_InitBaseFuncs() ||
+        !OGLFuncs_InitExtFuncs())
+    {
+        OGLFuncs_CloseLibrary();
+        return JNI_FALSE;
+    }
+#ifdef REMOTELAYER
+    pthread_t jrsRemoteThread;
+    pthread_create(&jrsRemoteThread, NULL, JRSRemoteThreadFn, NULL);
+#endif
+    return JNI_TRUE;
+}
+
+
+/**
+ * Determines whether the CGL pipeline can be used for a given GraphicsConfig
+ * provided its screen number and visual ID.  If the minimum requirements are
+ * met, the native CGLGraphicsConfigInfo structure is initialized for this
+ * GraphicsConfig with the necessary information (pixel format, etc.)
+ * and a pointer to this structure is returned as a jlong.  If
+ * initialization fails at any point, zero is returned, indicating that CGL
+ * cannot be used for this GraphicsConfig (we should fallback on an existing
+ * 2D pipeline).
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_java2d_opengl_CGLGraphicsConfig_getCGLConfigInfo
+    (JNIEnv *env, jclass cglgc,
+     jint screennum, jint pixfmt, jint swapInterval)
+{
+  jlong ret = 0L;
+  JNF_COCOA_ENTER(env);
+  NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
+  [retArray addObject: [NSNumber numberWithInt: (int)screennum]];
+  [retArray addObject: [NSNumber numberWithInt: (int)pixfmt]];
+  [retArray addObject: [NSNumber numberWithInt: (int)swapInterval]];
+  [GraphicsConfigUtil performSelectorOnMainThread: @selector(_getCGLConfigInfo:) withObject: retArray waitUntilDone: YES];
+  NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
+  ret = (jlong)[num longValue];
+  JNF_COCOA_EXIT(env);
+  return ret;
+}
+
+
+
+@implementation GraphicsConfigUtil
++ (void) _getCGLConfigInfo: (NSMutableArray *)argValue {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    jint screennum = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue];
+    jint pixfmt = (jint)[(NSNumber *)[argValue objectAtIndex: 1] intValue];
+    jint swapInterval = (jint)[(NSNumber *)[argValue objectAtIndex: 2] intValue];
+    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+    [argValue removeAllObjects];
+
+    J2dRlsTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo");
+
+    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+    CGOpenGLDisplayMask glMask = (CGOpenGLDisplayMask)pixfmt;
+    if (sharedContext == NULL) {
+        if (glMask == 0) {
+            CGDirectDisplayID id =
+                FindCGDirectDisplayIDForScreenIndex(screennum);
+            glMask = CGDisplayIDToOpenGLDisplayMask(id);
+        }
+
+        NSOpenGLPixelFormatAttribute attrs[] = {
+            NSOpenGLPFAClosestPolicy,
+            NSOpenGLPFANoRecovery,
+            NSOpenGLPFAAccelerated,
+            NSOpenGLPFAFullScreen,
+            NSOpenGLPFAWindow,
+            NSOpenGLPFAPixelBuffer,
+            NSOpenGLPFADoubleBuffer,
+            NSOpenGLPFAColorSize, 32,
+            NSOpenGLPFAAlphaSize, 8,
+            NSOpenGLPFADepthSize, 16,
+            NSOpenGLPFAScreenMask, glMask,
+            0
+        };
+
+        sharedPixelFormat =
+            [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+        if (sharedPixelFormat == nil) {
+            J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLPixelFormat is NULL");
+            [argValue addObject: [NSNumber numberWithLong: 0L]];
+            return;
+        }
+
+        sharedContext =
+            [[NSOpenGLContext alloc]
+                initWithFormat:sharedPixelFormat
+                shareContext: NULL];
+        if (sharedContext == nil) {
+            J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLContext is NULL");
+            [argValue addObject: [NSNumber numberWithLong: 0L]];
+            return;
+        }
+    }
+
+#if USE_NSVIEW_FOR_SCRATCH
+    NSRect contentRect = NSMakeRect(0, 0, 64, 64);
+    NSWindow *window =
+        [[NSWindow alloc]
+            initWithContentRect: contentRect
+            styleMask: NSBorderlessWindowMask
+            backing: NSBackingStoreBuffered
+            defer: false];
+    if (window == nil) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: NSWindow is NULL");
+        [argValue addObject: [NSNumber numberWithLong: 0L]];
+        return;
+    }
+
+    NSView *scratchSurface =
+        [[NSView alloc]
+            initWithFrame: contentRect];
+    if (scratchSurface == nil) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: NSView is NULL");
+        [argValue addObject: [NSNumber numberWithLong: 0L]];
+        return;
+    }
+    [window setContentView: scratchSurface];
+#else
+    NSOpenGLPixelBuffer *scratchSurface =
+        [[NSOpenGLPixelBuffer alloc]
+            initWithTextureTarget:GL_TEXTURE_2D
+            textureInternalFormat:GL_RGB
+            textureMaxMipMapLevel:0
+            pixelsWide:64
+            pixelsHigh:64];
+#endif
+
+    NSOpenGLContext *context =
+        [[NSOpenGLContext alloc]
+            initWithFormat: sharedPixelFormat
+            shareContext: sharedContext];
+    if (context == nil) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: NSOpenGLContext is NULL");
+        [argValue addObject: [NSNumber numberWithLong: 0L]];
+        return;
+    }
+
+    GLint contextVirtualScreen = [context currentVirtualScreen];
+#if USE_NSVIEW_FOR_SCRATCH
+    [context setView: scratchSurface];
+#else
+    [context
+        setPixelBuffer: scratchSurface
+        cubeMapFace:0
+        mipMapLevel:0
+        currentVirtualScreen: contextVirtualScreen];
+#endif
+    [context makeCurrentContext];
+
+    // get version and extension strings
+    const unsigned char *versionstr = j2d_glGetString(GL_VERSION);
+    if (!OGLContext_IsVersionSupported(versionstr)) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: OpenGL 1.2 is required");
+        [NSOpenGLContext clearCurrentContext];
+        [argValue addObject: [NSNumber numberWithLong: 0L]];
+        return;
+    }
+    J2dRlsTraceLn1(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo: OpenGL version=%s", versionstr);
+
+    jint caps = CAPS_EMPTY;
+    OGLContext_GetExtensionInfo(env, &caps);
+
+    GLint value = 0;
+    [sharedPixelFormat
+        getValues: &value
+        forAttribute: NSOpenGLPFADoubleBuffer
+        forVirtualScreen: contextVirtualScreen];
+    if (value != 0) {
+        caps |= CAPS_DOUBLEBUFFERED;
+    }
+    [sharedPixelFormat
+        getValues: &value
+        forAttribute: NSOpenGLPFAAlphaSize
+        forVirtualScreen: contextVirtualScreen];
+    if (value != 0) {
+        caps |= CAPS_STORED_ALPHA;
+    }
+
+    J2dRlsTraceLn2(J2D_TRACE_INFO,
+                   "CGLGraphicsConfig_getCGLConfigInfo: db=%d alpha=%d",
+                   (caps & CAPS_DOUBLEBUFFERED) != 0,
+                   (caps & CAPS_STORED_ALPHA) != 0);
+
+    // remove before shipping (?)
+#if 1
+    [sharedPixelFormat
+        getValues: &value
+        forAttribute: NSOpenGLPFAAccelerated
+        forVirtualScreen: contextVirtualScreen];
+    if (value == 0) {
+        [sharedPixelFormat
+            getValues: &value
+            forAttribute: NSOpenGLPFARendererID
+            forVirtualScreen: contextVirtualScreen];
+        fprintf(stderr, "WARNING: GL pipe is running in software mode (Renderer ID=0x%x)\n", (int)value);
+    }
+#endif
+
+    // 0: the buffers are swapped with no regard to the vertical refresh rate
+    // 1: the buffers are swapped only during the vertical retrace
+    GLint params = swapInterval;
+    [context setValues: &params forParameter: NSOpenGLCPSwapInterval];
+
+    CGLCtxInfo *ctxinfo = (CGLCtxInfo *)malloc(sizeof(CGLCtxInfo));
+    if (ctxinfo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGC_InitOGLContext: could not allocate memory for ctxinfo");
+        [NSOpenGLContext clearCurrentContext];
+        [argValue addObject: [NSNumber numberWithLong: 0L]];
+        return;
+    }
+    memset(ctxinfo, 0, sizeof(CGLCtxInfo));
+    ctxinfo->context = context;
+    ctxinfo->scratchSurface = scratchSurface;
+
+    OGLContext *oglc = (OGLContext *)malloc(sizeof(OGLContext));
+    if (oglc == 0L) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGC_InitOGLContext: could not allocate memory for oglc");
+        [NSOpenGLContext clearCurrentContext];
+        free(ctxinfo);
+        [argValue addObject: [NSNumber numberWithLong: 0L]];
+        return;
+    }
+    memset(oglc, 0, sizeof(OGLContext));
+    oglc->ctxInfo = ctxinfo;
+    oglc->caps = caps;
+
+    // create the CGLGraphicsConfigInfo record for this config
+    CGLGraphicsConfigInfo *cglinfo = (CGLGraphicsConfigInfo *)malloc(sizeof(CGLGraphicsConfigInfo));
+    if (cglinfo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: could not allocate memory for cglinfo");
+        [NSOpenGLContext clearCurrentContext];
+        free(oglc);
+        free(ctxinfo);
+        [argValue addObject: [NSNumber numberWithLong: 0L]];
+        return;
+    }
+    memset(cglinfo, 0, sizeof(CGLGraphicsConfigInfo));
+    cglinfo->screen = screennum;
+    cglinfo->pixfmt = sharedPixelFormat;
+    cglinfo->context = oglc;
+
+    [NSOpenGLContext clearCurrentContext];
+    [argValue addObject: [NSNumber numberWithLong:ptr_to_jlong(cglinfo)]];
+    [pool drain];
+}
+@end //GraphicsConfigUtil
+
+
+JNIEXPORT jint JNICALL
+Java_sun_java2d_opengl_CGLGraphicsConfig_getDefaultPixFmt
+    (JNIEnv *env, jclass cglgc, jint screennum)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getDefaultPixFmt");
+
+    CGDirectDisplayID id = FindCGDirectDisplayIDForScreenIndex(screennum);
+    return (jint)CGDisplayIDToOpenGLDisplayMask(id);
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_java2d_opengl_CGLGraphicsConfig_getOGLCapabilities
+    (JNIEnv *env, jclass cglgc, jlong configInfo)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getOGLCapabilities");
+
+    CGLGraphicsConfigInfo *cglinfo =
+        (CGLGraphicsConfigInfo *)jlong_to_ptr(configInfo);
+    if ((cglinfo == NULL) || (cglinfo->context == NULL)) {
+        return CAPS_EMPTY;
+    } else {
+        return cglinfo->context->caps;
+    }
+}
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.h b/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.h
new file mode 100644
index 0000000..d1ebe4a
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef CGLLayer_h_Included
+#define CGLLayer_h_Included
+
+#import "AWTView.h"
+
+@interface CGLLayer : CAOpenGLLayer
+{
+@private
+    jobject javaLayer;
+
+    // intermediate buffer, used the RQ lock to synchronize
+    GLuint textureID;
+    GLenum target;
+    float textureWidth;
+    float textureHeight;
+#ifdef REMOTELAYER
+    CGLLayer *parentLayer;
+    CGLLayer *remoteLayer;
+    NSObject<JRSRemoteLayer> *jrsRemoteLayer;
+#endif /* REMOTELAYER */
+}
+
+@property (readwrite, assign) GLuint textureID;
+@property (readwrite, assign) GLenum target;
+@property (readwrite, assign) float textureWidth;
+@property (readwrite, assign) float textureHeight;
+
+#ifdef REMOTELAYER
+@property (nonatomic, retain) CGLLayer *parentLayer;
+@property (nonatomic, retain) CGLLayer *remoteLayer;
+@property (nonatomic, retain) NSObject<JRSRemoteLayer> *jrsRemoteLayer;
+#endif
+
+- (id) initWithJavaLayer:(jobject)javaLayer;
+- (void) blitTexture;
+@end
+
+#endif /* CGLLayer_h_Included */
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.m b/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.m
new file mode 100644
index 0000000..e5b1436
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.m
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "CGLGraphicsConfig.h"
+#import "CGLLayer.h"
+#import "ThreadUtilities.h"
+#import "LWCToolkit.h"
+#import "CGLSurfaceData.h"
+
+
+extern NSOpenGLPixelFormat *sharedPixelFormat;
+extern NSOpenGLContext *sharedContext;
+
+@implementation CGLLayer
+
+@synthesize textureID;
+@synthesize target;
+@synthesize textureWidth;
+@synthesize textureHeight;
+#ifdef REMOTELAYER
+@synthesize parentLayer;
+@synthesize remoteLayer;
+@synthesize jrsRemoteLayer;
+#endif
+
+- (id) initWithJavaLayer:(jobject)layer;
+{
+AWT_ASSERT_APPKIT_THREAD;
+    // Initialize ourselves
+    self = [super init];
+    if (self == nil) return self;
+
+    javaLayer = layer;
+    
+    // NOTE: async=YES means that the layer is re-cached periodically
+    self.asynchronous = FALSE;
+    self.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
+    self.contentsGravity = kCAGravityTopLeft;
+    self.needsDisplayOnBoundsChange = YES;
+    textureID = 0; // texture will be created by rendering pipe
+    target = 0;
+
+    return self;
+}
+
+- (void) dealloc {
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    (*env)->DeleteGlobalRef(env, javaLayer);
+    javaLayer = NULL;
+    
+    [super dealloc];
+}
+
+- (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask {
+    return CGLRetainPixelFormat(sharedPixelFormat.CGLPixelFormatObj);
+}
+
+- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
+    CGLContextObj contextObj = NULL;
+    CGLCreateContext(pixelFormat, sharedContext.CGLContextObj, &contextObj);
+    return contextObj;
+}
+
+// use texture (intermediate buffer) as src and blit it to the layer
+- (void) blitTexture
+{
+    if (textureID == 0) {
+        return;
+    }
+
+    glEnable(target);
+    glBindTexture(target, textureID);
+
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // srccopy
+
+    float swid = 1.0f, shgt = 1.0f;
+    if (target == GL_TEXTURE_RECTANGLE_ARB) {
+        swid = textureWidth;
+        shgt = textureHeight;
+    }
+    glBegin(GL_QUADS);
+    glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f);
+    glTexCoord2f(swid, 0.0f); glVertex2f( 1.0f, -1.0f);
+    glTexCoord2f(swid, shgt); glVertex2f( 1.0f,  1.0f);
+    glTexCoord2f(0.0f, shgt); glVertex2f(-1.0f,  1.0f);
+    glEnd();
+
+    glBindTexture(target, 0);
+    glDisable(target);
+}
+
+-(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
+{
+    AWT_ASSERT_APPKIT_THREAD;
+
+    // Set the current context to the one given to us.
+    CGLSetCurrentContext(glContext);
+
+    glViewport(0, 0, textureWidth, textureHeight);
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    static JNF_CLASS_CACHE(jc_JavaLayer, "sun/java2d/opengl/CGLLayer");
+    static JNF_MEMBER_CACHE(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V");
+    JNFCallVoidMethod(env, javaLayer, jm_drawInCGLContext);
+
+    // Call super to finalize the drawing. By default all it does is call glFlush().
+    [super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:timeInterval displayTime:timeStamp];
+
+    CGLSetCurrentContext(NULL);
+}
+
+@end
+
+/*
+ * Class:     sun_java2d_opengl_CGLLayer
+ * Method:    nativeCreateLayer
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL
+Java_sun_java2d_opengl_CGLLayer_nativeCreateLayer
+(JNIEnv *env, jobject obj)
+{
+    __block CGLLayer *layer = nil;
+
+JNF_COCOA_ENTER(env);
+AWT_ASSERT_NOT_APPKIT_THREAD;
+
+    jobject javaLayer = (*env)->NewGlobalRef(env, obj);
+    
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+
+        layer = [[CGLLayer alloc] initWithJavaLayer: javaLayer];
+    }];
+
+JNF_COCOA_EXIT(env);
+
+    return ptr_to_jlong(layer);
+}
+
+// Must be called under the RQ lock.
+JNIEXPORT void JNICALL
+Java_sun_java2d_opengl_CGLLayer_validate
+(JNIEnv *env, jobject obj, jlong layerPtr, jobject surfaceData)
+{
+    CGLLayer *layer = OBJC(layerPtr);
+
+    if (surfaceData != NULL) {
+        OGLSDOps *oglsdo = (OGLSDOps*) SurfaceData_GetOps(env, surfaceData);
+        layer.textureID = oglsdo->textureID;
+        layer.target = GL_TEXTURE_2D;
+        layer.textureWidth = oglsdo->width;
+        layer.textureHeight = oglsdo->height;
+    } else {
+        layer.textureID = 0;            
+    }
+}    
+
+// Must be called on the AppKit thread and under the RQ lock.
+JNIEXPORT void JNICALL
+Java_sun_java2d_opengl_CGLLayer_blitTexture
+(JNIEnv *env, jobject obj, jlong layerPtr)
+{
+    CGLLayer *layer = jlong_to_ptr(layerPtr);
+
+    [layer blitTexture];
+}
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.h b/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.h
new file mode 100644
index 0000000..7629e4d
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef CGLSurfaceData_h_Included
+#define CGLSurfaceData_h_Included
+
+#import <IOSurface/IOSurface.h>
+
+#import "OGLSurfaceData.h"
+#import "CGLGraphicsConfig.h"
+#import "AWTWindow.h"
+#import "CGLLayer.h"
+
+/**
+ * The CGLSDOps structure contains the CGL-specific information for a given
+ * OGLSurfaceData.  It is referenced by the native OGLSDOps structure.
+ */
+typedef struct _CGLSDOps {
+    AWTView               *peerData;
+    CGLLayer              *layer;
+    GLclampf              argb[4]; // background clear color
+    NSOpenGLPixelBuffer   *pbuffer;
+    CGLGraphicsConfigInfo *configInfo;
+    IOSurfaceRef          surfaceRef;
+} CGLSDOps;
+
+#endif /* CGLSurfaceData_h_Included */
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m b/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m
new file mode 100644
index 0000000..6f327a4
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m
@@ -0,0 +1,865 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <stdlib.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#import "sun_java2d_opengl_CGLSurfaceData.h"
+
+#import "jni.h"
+#import "jni_util.h"
+#import "OGLRenderQueue.h"
+#import "CGLGraphicsConfig.h"
+#import "CGLSurfaceData.h"
+#import "CGLLayer.h"
+#import "ThreadUtilities.h"
+
+/* JDK's glext.h is already included and will prevent the Apple glext.h
+ * being included, so define the externs directly
+ */
+extern void glBindFramebufferEXT(GLenum target, GLuint framebuffer);
+extern CGLError CGLTexImageIOSurface2D(
+        CGLContextObj ctx, GLenum target, GLenum internal_format,
+        GLsizei width, GLsizei height, GLenum format, GLenum type,
+        IOSurfaceRef ioSurface, GLuint plane);
+
+/**
+ * The methods in this file implement the native windowing system specific
+ * layer (CGL) for the OpenGL-based Java 2D pipeline.
+ */
+
+#pragma mark -
+#pragma mark "--- Mac OS X specific methods for GL pipeline ---"
+
+// TODO: hack that's called from OGLRenderQueue to test out unlockFocus behavior
+#if 0
+void
+OGLSD_UnlockFocus(OGLContext *oglc, OGLSDOps *dstOps)
+{
+    CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+    CGLSDOps *cglsdo = (CGLSDOps *)dstOps->privOps;
+    fprintf(stderr, "about to unlock focus: %p %p\n",
+            cglsdo->peerData, ctxinfo->context);
+
+    NSOpenGLView *nsView = cglsdo->peerData;
+    if (nsView != NULL) {
+JNF_COCOA_ENTER(env);
+        [nsView unlockFocus];
+JNF_COCOA_EXIT(env);
+    }
+}
+#endif
+
+/**
+ * Makes the given context current to its associated "scratch" surface.  If
+ * the operation is successful, this method will return JNI_TRUE; otherwise,
+ * returns JNI_FALSE.
+ */
+static jboolean
+CGLSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "CGLSD_MakeCurrentToScratch");
+
+    if (oglc == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR,
+                      "CGLSD_MakeCurrentToScratch: context is null");
+        return JNI_FALSE;
+    }
+
+JNF_COCOA_ENTER(env);
+
+    CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+#if USE_NSVIEW_FOR_SCRATCH
+    [ctxinfo->context makeCurrentContext];
+    [ctxinfo->context setView: ctxinfo->scratchSurface];
+#else
+    [ctxinfo->context clearDrawable];
+    [ctxinfo->context makeCurrentContext];
+    [ctxinfo->context setPixelBuffer: ctxinfo->scratchSurface
+            cubeMapFace: 0
+            mipMapLevel: 0
+            currentVirtualScreen: [ctxinfo->context currentVirtualScreen]];
+#endif
+
+JNF_COCOA_EXIT(env);
+
+    return JNI_TRUE;
+}
+
+/**
+ * This function disposes of any native windowing system resources associated
+ * with this surface.  For instance, if the given OGLSDOps is of type
+ * OGLSD_PBUFFER, this method implementation will destroy the actual pbuffer
+ * surface.
+ */
+void
+OGLSD_DestroyOGLSurface(JNIEnv *env, OGLSDOps *oglsdo)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_DestroyOGLSurface");
+
+JNF_COCOA_ENTER(env);
+
+    CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
+    if (oglsdo->drawableType == OGLSD_PBUFFER) {
+        if (oglsdo->textureID != 0) {
+            j2d_glDeleteTextures(1, &oglsdo->textureID);
+            oglsdo->textureID = 0;
+        }
+        if (cglsdo->pbuffer != NULL) {
+            [cglsdo->pbuffer release];
+            cglsdo->pbuffer = NULL;
+        }
+    } else if (oglsdo->drawableType == OGLSD_WINDOW) {
+#if USE_INTERMEDIATE_BUFFER
+        // REMIND: duplicates code in OGLSD_Delete invoked from the Dispose thread
+        if (oglsdo->textureID != 0) {
+            j2d_glDeleteTextures(1, &oglsdo->textureID);
+            oglsdo->textureID = 0;
+        }
+        if (oglsdo->depthID != 0) {
+            j2d_glDeleteRenderbuffersEXT(1, &oglsdo->depthID);
+            oglsdo->depthID = 0;
+        }
+        if (oglsdo->fbobjectID != 0) {
+            j2d_glDeleteFramebuffersEXT(1, &oglsdo->fbobjectID);
+            oglsdo->fbobjectID = 0;
+        }
+#else
+        // detach the NSView from the NSOpenGLContext
+        CGLGraphicsConfigInfo *cglInfo = cglsdo->configInfo;
+        OGLContext *oglc = cglInfo->context;
+        CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+        [ctxinfo->context clearDrawable];
+#endif
+    }
+
+    oglsdo->drawableType = OGLSD_UNDEFINED;
+
+JNF_COCOA_EXIT(env);
+}
+
+/**
+ * Returns a pointer (as a jlong) to the native CGLGraphicsConfigInfo
+ * associated with the given OGLSDOps.  This method can be called from
+ * shared code to retrieve the native GraphicsConfig data in a platform-
+ * independent manner.
+ */
+jlong
+OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_GetNativeConfigInfo");
+
+    if (oglsdo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_GetNativeConfigInfo: ops are null");
+        return 0L;
+    }
+
+    CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
+    if (cglsdo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_GetNativeConfigInfo: cgl ops are null");
+        return 0L;
+    }
+
+    return ptr_to_jlong(cglsdo->configInfo);
+}
+
+/**
+ * Makes the given GraphicsConfig's context current to its associated
+ * "scratch" surface.  If there is a problem making the context current,
+ * this method will return NULL; otherwise, returns a pointer to the
+ * OGLContext that is associated with the given GraphicsConfig.
+ */
+OGLContext *
+OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
+
+    CGLGraphicsConfigInfo *cglInfo = (CGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
+    if (cglInfo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_SetScratchContext: cgl config info is null");
+        return NULL;
+    }
+
+    OGLContext *oglc = cglInfo->context;
+    CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+
+JNF_COCOA_ENTER(env);
+
+    // avoid changing the context's target view whenever possible, since
+    // calling setView causes flickering; as long as our context is current
+    // to some view, it's not necessary to switch to the scratch surface
+    if ([ctxinfo->context view] == nil) {
+        // it seems to be necessary to explicitly flush between context changes
+        OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();
+        if (currentContext != NULL) {
+            j2d_glFlush();
+        }
+
+        if (!CGLSD_MakeCurrentToScratch(env, oglc)) {
+            return NULL;
+        }
+    } else if ([NSOpenGLContext currentContext] == nil) {
+        [ctxinfo->context makeCurrentContext];
+    }
+
+    if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
+        // the GL_EXT_framebuffer_object extension is present, so this call
+        // will ensure that we are bound to the scratch surface (and not
+        // some other framebuffer object)
+        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return oglc;
+}
+
+/**
+ * Makes a context current to the given source and destination
+ * surfaces.  If there is a problem making the context current, this method
+ * will return NULL; otherwise, returns a pointer to the OGLContext that is
+ * associated with the destination surface.
+ */
+OGLContext *
+OGLSD_MakeOGLContextCurrent(JNIEnv *env, OGLSDOps *srcOps, OGLSDOps *dstOps)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_MakeOGLContextCurrent");
+
+    CGLSDOps *dstCGLOps = (CGLSDOps *)dstOps->privOps;
+
+    J2dTraceLn4(J2D_TRACE_VERBOSE, "  src: %d %p dst: %d %p", srcOps->drawableType, srcOps, dstOps->drawableType, dstOps);
+
+    OGLContext *oglc = dstCGLOps->configInfo->context;
+    if (oglc == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_MakeOGLContextCurrent: context is null");
+        return NULL;
+    }
+
+    CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+
+    // it seems to be necessary to explicitly flush between context changes
+    OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();
+    if (currentContext != NULL) {
+        j2d_glFlush();
+    }
+
+    if (dstOps->drawableType == OGLSD_FBOBJECT) {
+        // first make sure we have a current context (if the context isn't
+        // already current to some drawable, we will make it current to
+        // its scratch surface)
+        if (oglc != currentContext) {
+            if (!CGLSD_MakeCurrentToScratch(env, oglc)) {
+                return NULL;
+            }
+        }
+
+        // now bind to the fbobject associated with the destination surface;
+        // this means that all rendering will go into the fbobject destination
+        // (note that we unbind the currently bound texture first; this is
+        // recommended procedure when binding an fbobject)
+#ifndef USE_IOS
+        j2d_glBindTexture(GL_TEXTURE_2D, 0);
+#else
+        GLenum target = GL_TEXTURE_RECTANGLE_ARB;
+        j2d_glBindTexture(target, 0);
+        j2d_glDisable(target);
+#endif
+        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstOps->fbobjectID);
+
+        return oglc;
+    }
+
+JNF_COCOA_ENTER(env);
+
+    // set the current surface
+    if (dstOps->drawableType == OGLSD_PBUFFER) {
+        // REMIND: pbuffers are not fully tested yet...
+        [ctxinfo->context clearDrawable];
+        [ctxinfo->context makeCurrentContext];
+        [ctxinfo->context setPixelBuffer: dstCGLOps->pbuffer
+                cubeMapFace: 0
+                mipMapLevel: 0
+                currentVirtualScreen: [ctxinfo->context currentVirtualScreen]];
+    } else {
+#if USE_INTERMEDIATE_BUFFER
+#ifndef USE_IOS
+        j2d_glBindTexture(GL_TEXTURE_2D, 0);
+#else
+    GLenum target = GL_TEXTURE_RECTANGLE_ARB;
+    j2d_glBindTexture(target, 0);
+    j2d_glDisable(target);
+#endif
+        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstOps->fbobjectID);
+#else
+        CGLSDOps *cglsdo = (CGLSDOps *)dstOps->privOps;
+        NSView *nsView = (NSView *)cglsdo->peerData;
+
+        if ([ctxinfo->context view] != nsView) {
+            [ctxinfo->context makeCurrentContext];
+            [ctxinfo->context setView: nsView];
+        }
+#endif
+    }
+
+#ifndef USE_INTERMEDIATE_BUFFER
+    if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
+        // the GL_EXT_framebuffer_object extension is present, so we
+        // must bind to the default (windowing system provided)
+        // framebuffer
+        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+    }
+#endif
+
+    if ((srcOps != dstOps) && (srcOps->drawableType == OGLSD_PBUFFER)) {
+        // bind pbuffer to the render texture object (since we are preparing
+        // to copy from the pbuffer)
+        CGLSDOps *srcCGLOps = (CGLSDOps *)srcOps->privOps;
+        j2d_glBindTexture(GL_TEXTURE_2D, srcOps->textureID);
+        [ctxinfo->context
+                setTextureImageToPixelBuffer: srcCGLOps->pbuffer
+                colorBuffer: GL_FRONT];
+    }
+
+JNF_COCOA_EXIT(env);
+
+    return oglc;
+}
+
+/**
+ * Returns true if OpenGL textures can have non-power-of-two dimensions
+ * when using the basic GL_TEXTURE_2D target.
+ */
+BOOL isTexNonPow2Available(CGLGraphicsConfigInfo *cglinfo) {
+    jint caps;
+    if ((cglinfo == NULL) || (cglinfo->context == NULL)) {
+        return FALSE;
+    } else {
+        caps = cglinfo->context->caps;
+    }
+    return ((caps & CAPS_TEXNONPOW2) != 0);
+}
+
+/**
+ * Returns true if OpenGL textures can have non-power-of-two dimensions
+ * when using the GL_TEXTURE_RECTANGLE_ARB target (only available when the
+ * GL_ARB_texture_rectangle extension is present).
+ */
+BOOL isTexRectAvailable(CGLGraphicsConfigInfo *cglinfo) {
+    jint caps;
+    if ((cglinfo == NULL) || (cglinfo->context == NULL)) {
+        return FALSE;
+    } else {
+        caps = cglinfo->context->caps;
+    }
+    return ((caps & CAPS_EXT_TEXRECT) != 0);
+}
+
+/**
+ * Recreates the intermediate buffer associated with the given OGLSDOps
+ * and with the buffer's new size specified in OGLSDOps.
+ */
+jboolean RecreateBuffer(JNIEnv *env, OGLSDOps *oglsdo)
+{
+    // destroy previous buffer first
+    OGLSD_DestroyOGLSurface(env, oglsdo);
+
+    CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
+    jboolean result =
+        OGLSurfaceData_initFBObject(env, NULL, ptr_to_jlong(oglsdo), oglsdo->isOpaque,
+                                    isTexNonPow2Available(cglsdo->configInfo),
+                                    isTexRectAvailable(cglsdo->configInfo),
+                                    oglsdo->width, oglsdo->height);
+
+    // NOTE: OGLSD_WINDOW type is reused for offscreen rendering
+    //       when intermediate buffer is enabled
+    oglsdo->drawableType = OGLSD_WINDOW;
+
+    AWTView *view = cglsdo->peerData;
+    CGLLayer *layer = (CGLLayer *)view.cglLayer;
+    layer.textureID = oglsdo->textureID;
+    layer.target = GL_TEXTURE_2D;
+    layer.textureWidth = oglsdo->width;
+    layer.textureHeight = oglsdo->height;
+
+    return result;
+}
+
+
+static inline IOSurfaceRef createIoSurface(int width, int height)
+{
+    // Get an error return for 0 size. Maybe should skip creation
+    // for that case, but for now make a 1X1 surface
+    if (width <= 0) width = 1;
+    if (height <= 0) height = 1;
+
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithCapacity:4];
+    [properties setObject:[NSNumber numberWithInt:width] forKey:(id)kIOSurfaceWidth];
+    [properties setObject:[NSNumber numberWithInt:height] forKey:(id)kIOSurfaceHeight];
+    [properties setObject:[NSNumber numberWithInt:4] forKey:(id)kIOSurfaceBytesPerElement];
+    IOSurfaceRef surface = IOSurfaceCreate((CFDictionaryRef)properties);
+    CFRetain(surface); // REMIND: do I need to do this ?
+    [pool drain];
+
+    if (surface == NULL) {
+        NSLog(@"IOSurfaceCreate error, surface: %p", surface);
+    } else {
+        //NSLog(@"Plugin iosurface OK");
+        //NSLog(@"    surface: %p", surface);
+        //NSLog(@"    IOSurfaceGetID(self->surface): %d", IOSurfaceGetID(surface));
+    }
+    return surface;
+}
+
+/**
+ * Recreates the intermediate buffer associated with the given OGLSDOps
+ * and with the buffer's new size specified in OGLSDOps.
+ */
+jboolean RecreateIOSBuffer(JNIEnv *env, OGLSDOps *oglsdo)
+{
+    CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
+    // destroy previous buffer first
+    if (oglsdo->textureID != 0) {
+        OGLSD_DestroyOGLSurface(env, oglsdo);
+        if (cglsdo->surfaceRef != NULL) {
+            CFRelease(cglsdo->surfaceRef);
+            cglsdo->surfaceRef = NULL;
+        }
+    }
+
+    oglsdo->textureID = 0;
+    cglsdo->surfaceRef = NULL;
+    int width = oglsdo->width;
+    int height = oglsdo->height;
+    if (width <= 0) width = 1;
+    if (height <= 0) height = 1;
+    IOSurfaceRef _surfaceRef = createIoSurface(width, height);
+    if (_surfaceRef == NULL) {
+        return JNI_FALSE;
+    }
+
+    GLenum target = GL_TEXTURE_RECTANGLE_ARB;
+    glEnable(target);
+    GLuint texture;
+    glGenTextures(1, &texture);
+    glBindTexture(target, texture);
+    glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+    OGLContext *oglc = cglsdo->configInfo->context;
+    CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+    CGLContextObj context = ctxinfo->context.CGLContextObj;
+
+    /* These parameters are documented only in the header file
+     * and apart from the requirement that it must be one of
+     * the combinations listed there its not as clear as I'd like
+     * what the choices mean.
+     */
+    GLenum format = GL_BGRA;
+    GLenum internal_format = GL_RGB;
+    GLenum type = GL_UNSIGNED_INT_8_8_8_8_REV;
+
+    CGLError err =
+    CGLTexImageIOSurface2D(context, target, internal_format,
+         width, height, format, type, _surfaceRef, 0);
+
+    if (err != kCGLNoError) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR,
+                      "OGLSurfaceData_RecreateIOSBuffer: could not init texture");
+        j2d_glDeleteTextures(1, &texture);
+        CFRelease(_surfaceRef);
+        return JNI_FALSE;
+    }
+
+    oglsdo->drawableType = OGLSD_FBOBJECT;
+    oglsdo->xOffset = 0;
+    oglsdo->yOffset = 0;
+    oglsdo->width = width;
+    oglsdo->height = height;
+    oglsdo->textureID = texture;
+    oglsdo->textureWidth = width;
+    oglsdo->textureHeight = height;
+    // init_FBO fails if we don't use target GL_TEXTURE_RECTANGLE_ARB for the IOS texture.
+    oglsdo->textureTarget = target;
+    OGLSD_INIT_TEXTURE_FILTER(oglsdo, GL_NEAREST);
+    OGLSD_RESET_TEXTURE_WRAP(target);
+
+    // initialize framebuffer object using color texture created above
+    GLuint fbobjectID, depthID;
+    if (!OGLSD_InitFBObject(&fbobjectID, &depthID,
+                            oglsdo->textureID, oglsdo->textureTarget,
+                            oglsdo->textureWidth, oglsdo->textureHeight))
+    {
+        J2dRlsTraceLn(J2D_TRACE_ERROR,
+                      "OGLSurfaceData_RecreateIOSBuffer: could not init fbobject");
+        j2d_glDeleteTextures(1, &oglsdo->textureID);
+        CFRelease(_surfaceRef);
+        return JNI_FALSE;
+    }
+
+    oglsdo->fbobjectID = fbobjectID;
+    oglsdo->depthID = depthID;
+    // NOTE: OGLSD_WINDOW type is reused for offscreen rendering
+    //       when intermediate buffer is enabled
+    oglsdo->drawableType = OGLSD_WINDOW;
+
+    OGLSD_SetNativeDimensions(env, oglsdo,
+                              oglsdo->textureWidth, oglsdo->textureHeight);
+
+    cglsdo->surfaceRef = _surfaceRef;
+    AWTView *view = cglsdo->peerData;
+    CGLLayer *layer = (CGLLayer *)view.cglLayer;
+    layer.textureID = oglsdo->textureID;
+    layer.target = target;
+    layer.textureWidth = oglsdo->width;
+    layer.textureHeight = oglsdo->height;
+
+    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+
+    return JNI_TRUE;
+}
+
+/**
+ * This function initializes a native window surface and caches the window
+ * bounds in the given OGLSDOps.  Returns JNI_TRUE if the operation was
+ * successful; JNI_FALSE otherwise.
+ */
+jboolean
+OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_InitOGLWindow");
+
+    if (oglsdo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_InitOGLWindow: ops are null");
+        return JNI_FALSE;
+    }
+
+    CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
+    if (cglsdo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_InitOGLWindow: cgl ops are null");
+        return JNI_FALSE;
+    }
+
+    AWTView *v = cglsdo->peerData;
+    if (v == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_InitOGLWindow: view is invalid");
+        return JNI_FALSE;
+    }
+
+JNF_COCOA_ENTER(env);
+    NSRect surfaceBounds = [v bounds];
+    oglsdo->drawableType = OGLSD_WINDOW;
+#ifndef USE_INTERMEDIATE_BUFFER
+    oglsdo->isOpaque = JNI_TRUE;
+#endif
+
+    oglsdo->width = surfaceBounds.size.width;
+    oglsdo->height = surfaceBounds.size.height;
+JNF_COCOA_EXIT(env);
+
+    jboolean result = JNI_TRUE;
+
+#if USE_INTERMEDIATE_BUFFER
+#ifdef USE_IOS
+    result = RecreateIOSBuffer(env, oglsdo);
+#else
+    result = RecreateBuffer(env, oglsdo);
+#endif
+#endif
+
+    J2dTraceLn2(J2D_TRACE_VERBOSE, "  created window: w=%d h=%d", oglsdo->width, oglsdo->height);
+
+    return result;
+}
+
+void
+OGLSD_SwapBuffers(JNIEnv *env, jlong pPeerData)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SwapBuffers");
+
+JNF_COCOA_ENTER(env);
+    [[NSOpenGLContext currentContext] flushBuffer];
+JNF_COCOA_EXIT(env);
+}
+
+void
+OGLSD_Flush(JNIEnv *env)
+{
+    OGLSDOps *dstOps = OGLRenderQueue_GetCurrentDestination();
+    if (dstOps != NULL) {
+        CGLSDOps *dstCGLOps = (CGLSDOps *)dstOps->privOps;
+        CGLLayer *layer = (CGLLayer*)dstCGLOps->layer;
+        if (layer != NULL) {
+            [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+                AWT_ASSERT_APPKIT_THREAD;
+                [layer setNeedsDisplay];
+            }];
+        }
+    }
+#if USE_INTERMEDIATE_BUFFER
+    OGLSDOps *dstOps = OGLRenderQueue_GetCurrentDestination();
+    if (dstOps != NULL) {
+        [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+            AWT_ASSERT_APPKIT_THREAD;
+            CGLSDOps *dstCGLOps = (CGLSDOps *)dstOps->privOps;
+            AWTView *view = dstCGLOps->peerData;
+            [view.cglLayer setNeedsDisplay];
+#ifdef REMOTELAYER
+            /* If there's a remote layer (being used for testing)
+             * then we want to have that also receive the texture.
+             * First sync. up its dimensions with that of the layer
+             * we have attached to the local window and tell it that
+             * it also needs to copy the texture.
+             */
+             CGLLayer* cglLayer = (CGLLayer*)view.cglLayer;
+             if (cglLayer.remoteLayer != nil) {
+                 CGLLayer* remoteLayer = cglLayer.remoteLayer;
+                 remoteLayer.target = GL_TEXTURE_2D;
+                 remoteLayer.textureID = cglLayer.textureID;
+                 remoteLayer.textureWidth = cglLayer.textureWidth;
+                 remoteLayer.textureHeight = cglLayer.textureHeight;
+                 [remoteLayer setNeedsDisplay];
+            }
+#endif /* REMOTELAYER */
+        }];
+    }
+#endif
+}
+
+#pragma mark -
+#pragma mark "--- CGLSurfaceData methods ---"
+
+extern LockFunc        OGLSD_Lock;
+extern GetRasInfoFunc  OGLSD_GetRasInfo;
+extern UnlockFunc      OGLSD_Unlock;
+extern DisposeFunc     OGLSD_Dispose;
+
+JNIEXPORT void JNICALL
+Java_sun_java2d_opengl_CGLSurfaceData_initOps
+    (JNIEnv *env, jobject cglsd,
+     jlong pConfigInfo, jlong pPeerData, jlong layerPtr,
+     jint xoff, jint yoff, jboolean isOpaque)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "CGLSurfaceData_initOps");
+    J2dTraceLn1(J2D_TRACE_INFO, "  pPeerData=%p", jlong_to_ptr(pPeerData));
+    J2dTraceLn2(J2D_TRACE_INFO, "  xoff=%d, yoff=%d", (int)xoff, (int)yoff);
+
+    OGLSDOps *oglsdo = (OGLSDOps *)
+        SurfaceData_InitOps(env, cglsd, sizeof(OGLSDOps));
+    CGLSDOps *cglsdo = (CGLSDOps *)malloc(sizeof(CGLSDOps));
+    if (cglsdo == NULL) {
+        JNU_ThrowOutOfMemoryError(env, "creating native cgl ops");
+        return;
+    }
+
+    oglsdo->privOps = cglsdo;
+
+    oglsdo->sdOps.Lock               = OGLSD_Lock;
+    oglsdo->sdOps.GetRasInfo         = OGLSD_GetRasInfo;
+    oglsdo->sdOps.Unlock             = OGLSD_Unlock;
+    oglsdo->sdOps.Dispose            = OGLSD_Dispose;
+
+    oglsdo->drawableType = OGLSD_UNDEFINED;
+    oglsdo->activeBuffer = GL_FRONT;
+    oglsdo->needsInit = JNI_TRUE;
+    oglsdo->xOffset = xoff;
+    oglsdo->yOffset = yoff;
+    oglsdo->isOpaque = isOpaque;
+
+    cglsdo->peerData = (AWTView *)jlong_to_ptr(pPeerData);
+    cglsdo->layer = (CGLLayer *)jlong_to_ptr(layerPtr);    
+    cglsdo->configInfo = (CGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
+    
+    if (cglsdo->configInfo == NULL) {
+        free(cglsdo);
+        JNU_ThrowNullPointerException(env, "Config info is null in initOps");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_sun_java2d_opengl_CGLSurfaceData_clearWindow
+(JNIEnv *env, jobject cglsd)
+{
+    J2dTraceLn(J2D_TRACE_INFO, "CGLSurfaceData_clearWindow");
+
+    OGLSDOps *oglsdo = (OGLSDOps*) SurfaceData_GetOps(env, cglsd);
+    CGLSDOps *cglsdo = (CGLSDOps*) oglsdo->privOps;
+
+    cglsdo->peerData = NULL;
+    cglsdo->layer = NULL;
+}
+
+JNIEXPORT jboolean JNICALL
+Java_sun_java2d_opengl_CGLSurfaceData_initPbuffer
+    (JNIEnv *env, jobject cglsd,
+     jlong pData, jlong pConfigInfo, jboolean isOpaque,
+     jint width, jint height)
+{
+    J2dTraceLn3(J2D_TRACE_INFO, "CGLSurfaceData_initPbuffer: w=%d h=%d opq=%d", width, height, isOpaque);
+
+    OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
+    if (oglsdo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: ops are null");
+        return JNI_FALSE;
+    }
+
+    CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
+    if (cglsdo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: cgl ops are null");
+        return JNI_FALSE;
+    }
+
+    CGLGraphicsConfigInfo *cglInfo = (CGLGraphicsConfigInfo *)
+        jlong_to_ptr(pConfigInfo);
+    if (cglInfo == NULL) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: cgl config info is null");
+        return JNI_FALSE;
+    }
+
+    // find the maximum allowable texture dimensions (this value ultimately
+    // determines our maximum pbuffer size)
+    int pbMax = 0;
+    j2d_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &pbMax);
+
+    int pbWidth = 0;
+    int pbHeight = 0;
+    if (OGLC_IS_CAP_PRESENT(cglInfo->context, CAPS_TEXNONPOW2)) {
+        // use non-power-of-two dimensions directly
+        pbWidth = (width <= pbMax) ? width : 0;
+        pbHeight = (height <= pbMax) ? height : 0;
+    } else {
+        // find the appropriate power-of-two dimensions
+        pbWidth = OGLSD_NextPowerOfTwo(width, pbMax);
+        pbHeight = OGLSD_NextPowerOfTwo(height, pbMax);
+    }
+
+    J2dTraceLn3(J2D_TRACE_VERBOSE, "  desired pbuffer dimensions: w=%d h=%d max=%d", pbWidth, pbHeight, pbMax);
+
+    // if either dimension is 0, we cannot allocate a pbuffer/texture with the
+    // requested dimensions
+    if (pbWidth == 0 || pbHeight == 0) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: dimensions too large");
+        return JNI_FALSE;
+    }
+
+    int format = isOpaque ? GL_RGB : GL_RGBA;
+
+JNF_COCOA_ENTER(env);
+
+    cglsdo->pbuffer =
+        [[NSOpenGLPixelBuffer alloc]
+            initWithTextureTarget: GL_TEXTURE_2D
+            textureInternalFormat: format
+            textureMaxMipMapLevel: 0
+            pixelsWide: pbWidth
+            pixelsHigh: pbHeight];
+    if (cglsdo->pbuffer == nil) {
+        J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: could not create pbuffer");
+        return JNI_FALSE;
+    }
+
+    // make sure the actual dimensions match those that we requested
+    GLsizei actualWidth  = [cglsdo->pbuffer pixelsWide];
+    GLsizei actualHeight = [cglsdo->pbuffer pixelsHigh];
+    if (actualWidth != pbWidth || actualHeight != pbHeight) {
+        J2dRlsTraceLn2(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: actual (w=%d h=%d) != requested", actualWidth, actualHeight);
+        [cglsdo->pbuffer release];
+        return JNI_FALSE;
+    }
+
+    GLuint texID = 0;
+    j2d_glGenTextures(1, &texID);
+    j2d_glBindTexture(GL_TEXTURE_2D, texID);
+
+    oglsdo->drawableType = OGLSD_PBUFFER;
+    oglsdo->isOpaque = isOpaque;
+    oglsdo->width = width;
+    oglsdo->height = height;
+    oglsdo->textureID = texID;
+    oglsdo->textureWidth = pbWidth;
+    oglsdo->textureHeight = pbHeight;
+    oglsdo->activeBuffer = GL_FRONT;
+    oglsdo->needsInit = JNI_TRUE;
+
+    OGLSD_INIT_TEXTURE_FILTER(oglsdo, GL_NEAREST);
+
+JNF_COCOA_EXIT(env);
+
+    return JNI_TRUE;
+}
+
+#pragma mark -
+#pragma mark "--- CGLSurfaceData methods - Mac OS X specific ---"
+
+// Must be called on the QFT...
+JNIEXPORT void JNICALL
+Java_sun_java2d_opengl_CGLSurfaceData_validate
+    (JNIEnv *env, jobject jsurfacedata,
+     jint xoff, jint yoff, jint width, jint height, jboolean isOpaque)
+{
+    J2dTraceLn2(J2D_TRACE_INFO, "CGLSurfaceData_validate: w=%d h=%d", width, height);
+
+    OGLSDOps *oglsdo = (OGLSDOps*)SurfaceData_GetOps(env, jsurfacedata);
+    oglsdo->needsInit = JNI_TRUE;
+    oglsdo->xOffset = xoff;
+    oglsdo->yOffset = yoff;
+
+    BOOL newSize = (oglsdo->width != width || oglsdo->height != height);
+    BOOL newOpaque = (oglsdo->isOpaque != isOpaque);
+
+    oglsdo->width = width;
+    oglsdo->height = height;
+    oglsdo->isOpaque = isOpaque;
+
+    if (oglsdo->drawableType == OGLSD_WINDOW) {
+JNF_COCOA_ENTER(env);
+#ifdef USE_INTERMEDIATE_BUFFER
+        if (newSize || newOpaque) {
+#ifdef USE_IOS
+            RecreateIOSBuffer(env, oglsdo);
+#else
+            RecreateBuffer(env, oglsdo);
+#endif
+        }
+#endif
+JNF_COCOA_EXIT(env);
+
+        OGLContext_SetSurfaces(env, ptr_to_jlong(oglsdo), ptr_to_jlong(oglsdo));
+
+        // we have to explicitly tell the NSOpenGLContext that its target
+        // drawable has changed size
+        CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
+        OGLContext *oglc = cglsdo->configInfo->context;
+        CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+
+JNF_COCOA_ENTER(env);
+#ifndef USE_INTERMEDIATE_BUFFER
+        [ctxinfo->context update];
+#endif
+JNF_COCOA_EXIT(env);
+    }
+}
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/J2D_GL/cglext.h b/jdk/src/macosx/native/sun/java2d/opengl/J2D_GL/cglext.h
new file mode 100644
index 0000000..4468c43
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/J2D_GL/cglext.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef __cglext_h_
+#define __cglext_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <OpenGL/OpenGL.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/jdk/src/macosx/native/sun/java2d/opengl/OGLFuncs_md.h b/jdk/src/macosx/native/sun/java2d/opengl/OGLFuncs_md.h
new file mode 100644
index 0000000..55f8693
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/OGLFuncs_md.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef OGLFuncs_md_h_Included
+#define OGLFuncs_md_h_Included
+
+#include <dlfcn.h>
+#include "J2D_GL/cglext.h"
+#include "OGLFuncMacros.h"
+
+#define OGL_LIB_HANDLE pLibGL
+#define OGL_DECLARE_LIB_HANDLE() \
+    static void *OGL_LIB_HANDLE = NULL
+#define OGL_LIB_IS_UNINITIALIZED() \
+    (OGL_LIB_HANDLE == NULL)
+#define OGL_OPEN_LIB() \
+    OGL_LIB_HANDLE = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries/libGL.dylib", RTLD_LAZY | RTLD_GLOBAL)
+#define OGL_CLOSE_LIB() \
+    dlclose(OGL_LIB_HANDLE)
+#define OGL_GET_PROC_ADDRESS(f) \
+    dlsym(OGL_LIB_HANDLE, #f)
+#define OGL_GET_EXT_PROC_ADDRESS(f) \
+    OGL_GET_PROC_ADDRESS(f)
+
+#define OGL_EXPRESS_PLATFORM_FUNCS(action)
+#define OGL_EXPRESS_PLATFORM_EXT_FUNCS(action)
+
+#endif /* OGLFuncs_md_h_Included */
diff --git a/jdk/src/macosx/native/sun/nio/ch/KQueueArrayWrapper.c b/jdk/src/macosx/native/sun/nio/ch/KQueueArrayWrapper.c
new file mode 100644
index 0000000..a26b317
--- /dev/null
+++ b/jdk/src/macosx/native/sun/nio/ch/KQueueArrayWrapper.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * KQueueArrayWrapper.c
+ * Implementation of Selector using FreeBSD / Mac OS X kqueues
+ * Derived from Sun's DevPollArrayWrapper
+ */
+
+
+#include "jni.h"
+#include "jni_util.h"
+#include "jvm.h"
+#include "jlong.h"
+
+#include <sys/types.h>
+#include <sys/event.h>
+#include <sys/time.h>
+
+JNIEXPORT void JNICALL
+Java_sun_nio_ch_KQueueArrayWrapper_initStructSizes(JNIEnv *env, jclass clazz)
+{
+#define CHECK_EXCEPTION() { \
+    if ((*env)->ExceptionCheck(env)) { \
+        goto exceptionOccurred; \
+    } \
+}
+
+#define CHECK_ERROR_AND_EXCEPTION(_field) { \
+    if (_field == NULL) { \
+        goto badField; \
+    } \
+    CHECK_EXCEPTION(); \
+}
+
+
+    jfieldID field;
+
+    field = (*env)->GetStaticFieldID(env, clazz, "EVFILT_READ", "S");
+    CHECK_ERROR_AND_EXCEPTION(field);
+    (*env)->SetStaticShortField(env, clazz, field, EVFILT_READ);
+    CHECK_EXCEPTION();
+
+    field = (*env)->GetStaticFieldID(env, clazz, "EVFILT_WRITE", "S");
+    CHECK_ERROR_AND_EXCEPTION(field);
+    (*env)->SetStaticShortField(env, clazz, field, EVFILT_WRITE);
+    CHECK_EXCEPTION();
+
+    field = (*env)->GetStaticFieldID(env, clazz, "SIZEOF_KEVENT", "S");
+    CHECK_ERROR_AND_EXCEPTION(field);
+    (*env)->SetStaticShortField(env, clazz, field, (short) sizeof(struct kevent));
+    CHECK_EXCEPTION();
+
+    field = (*env)->GetStaticFieldID(env, clazz, "FD_OFFSET", "S");
+    CHECK_ERROR_AND_EXCEPTION(field);
+    (*env)->SetStaticShortField(env, clazz, field, (short) offsetof(struct kevent, ident));
+    CHECK_EXCEPTION();
+
+    field = (*env)->GetStaticFieldID(env, clazz, "FILTER_OFFSET", "S");
+    CHECK_ERROR_AND_EXCEPTION(field);
+    (*env)->SetStaticShortField(env, clazz, field, (short) offsetof(struct kevent, filter));
+    CHECK_EXCEPTION();
+    return;
+
+badField:
+    return;
+
+exceptionOccurred:
+    return;
+
+#undef CHECK_EXCEPTION
+#undef CHECK_ERROR_AND_EXCEPTION
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueueArrayWrapper_init(JNIEnv *env, jobject this)
+{
+    int kq = kqueue();
+    if (kq < 0) {
+        JNU_ThrowIOExceptionWithLastError(env, "KQueueArrayWrapper: kqueue() failed");
+    }
+    return kq;
+}
+
+
+JNIEXPORT void JNICALL
+Java_sun_nio_ch_KQueueArrayWrapper_register0(JNIEnv *env, jobject this,
+                                             jint kq, jint fd, jint r, jint w)
+{
+    struct kevent changes[2];
+    struct kevent errors[2];
+    struct timespec dontBlock = {0, 0};
+
+    // if (r) then { register for read } else { unregister for read }
+    // if (w) then { register for write } else { unregister for write }
+    // Ignore errors - they're probably complaints about deleting non-
+    //   added filters - but provide an error array anyway because
+    //   kqueue behaves erratically if some of its registrations fail.
+    EV_SET(&changes[0], fd, EVFILT_READ,  r ? EV_ADD : EV_DELETE, 0, 0, 0);
+    EV_SET(&changes[1], fd, EVFILT_WRITE, w ? EV_ADD : EV_DELETE, 0, 0, 0);
+    kevent(kq, changes, 2, errors, 2, &dontBlock);
+}
+
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueueArrayWrapper_kevent0(JNIEnv *env, jobject this, jint kq,
+                                           jlong kevAddr, jint kevCount,
+                                           jlong timeout)
+{
+    struct kevent *kevs = (struct kevent *)jlong_to_ptr(kevAddr);
+    struct timespec ts;
+    struct timespec *tsp;
+    int result;
+
+    // Java timeout is in milliseconds. Convert to struct timespec.
+    // Java timeout == -1 : wait forever : timespec timeout of NULL
+    // Java timeout == 0  : return immediately : timespec timeout of zero
+    if (timeout >= 0) {
+        ts.tv_sec = timeout / 1000;
+        ts.tv_nsec = (timeout % 1000) * 1000000; //nanosec = 1 million millisec
+        tsp = &ts;
+    } else {
+        tsp = NULL;
+    }
+
+    result = kevent(kq, NULL, 0, kevs, kevCount, tsp);
+
+    if (result < 0) {
+        if (errno == EINTR) {
+            // ignore EINTR, pretend nothing was selected
+            result = 0;
+        } else {
+            JNU_ThrowIOExceptionWithLastError(env, "KQueueArrayWrapper: kqueue failed");
+        }
+    }
+
+    return result;
+}
+
+
+JNIEXPORT void JNICALL
+Java_sun_nio_ch_KQueueArrayWrapper_interrupt(JNIEnv *env, jclass cls, jint fd)
+{
+    char c = 1;
+    if (1 != write(fd, &c, 1)) {
+        JNU_ThrowIOExceptionWithLastError(env, "KQueueArrayWrapper: interrupt failed");
+    }
+}
+
diff --git a/jdk/src/macosx/native/sun/osxapp/AWT_debug.h b/jdk/src/macosx/native/sun/osxapp/AWT_debug.h
new file mode 100644
index 0000000..5bf3e52
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/AWT_debug.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef macosx_port_awt_debug_h
+#define macosx_port_awt_debug_h
+
+#import <Cocoa/Cocoa.h>
+
+
+#define kInternalError "java/lang/InternalError"
+
+#define AWT_DEBUG_LOG(str) \
+    NSLog(@"Cocoa AWT: %@ %@", str, [NSThread callStackSymbols])
+
+#define AWT_DEBUG_BUG_REPORT_MESSAGE \
+    NSLog(@"\tPlease file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.")
+
+#endif
diff --git a/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.h b/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.h
new file mode 100644
index 0000000..bed85ce
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+@interface NSApplicationAWT : NSApplication {
+    NSString *fApplicationName;
+    BOOL fUseDefaultIcon;
+    NSWindow *eventTransparentWindow;
+}
+
+- (void) finishLaunching;
+- (void) registerWithProcessManager;
+- (void) setDockIconWithEnv:(JNIEnv *)env;
+
++ (void) runAWTLoopWithApp:(NSApplication*)app;
+
+@end
+
+@interface NSApplication (CustomNIBAdditions)
+
+// Returns whether or not application is using its default NIB
+- (BOOL)usingDefaultNib;
+
+@end
+
+void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> delegate);
+
diff --git a/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.m b/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.m
new file mode 100644
index 0000000..cf7a639
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.m
@@ -0,0 +1,353 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "NSApplicationAWT.h"
+
+#import <objc/runtime.h>
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+
+#import "PropertiesUtilities.h"
+#import "ThreadUtilities.h"
+#import "QueuingApplicationDelegate.h"
+
+
+static BOOL sUsingDefaultNIB = YES;
+static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework";
+static id <NSApplicationDelegate> applicationDelegate = nil;
+static QueuingApplicationDelegate * qad = nil;
+
+// Flag used to indicate to the Plugin2 event synthesis code to do a postEvent instead of sendEvent
+BOOL postEventDuringEventSynthesis = NO;
+
+@implementation NSApplicationAWT
+
+- (id) init
+{
+    // Headless: NO
+    // Embedded: NO
+    // Multiple Calls: NO
+    //  Caller: +[NSApplication sharedApplication]
+
+AWT_ASSERT_APPKIT_THREAD;
+    fApplicationName = nil;
+    fUseDefaultIcon = NO;
+    
+    // NSApplication will call _RegisterApplication with the application's bundle, but there may not be one.
+    // So, we need to call it ourselves to ensure the app is set up properly.
+    [self registerWithProcessManager];
+    
+    return [super init];
+}
+
+- (void)dealloc
+{
+    [fApplicationName release];
+    fApplicationName = nil;
+
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+- (void)finishLaunching
+{
+AWT_ASSERT_APPKIT_THREAD;
+
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    
+    // Get default nib file location
+    // NOTE: This should learn about the current java.version. Probably best thru
+    //  the Makefile system's -DFRAMEWORK_VERSION define. Need to be able to pass this
+    //  thru to PB from the Makefile system and for local builds.
+    NSString *defaultNibFile = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.nib" withEnv:env];
+    if (!defaultNibFile) {
+        NSBundle *javaBundle = [NSBundle bundleWithPath:SHARED_FRAMEWORK_BUNDLE];
+        defaultNibFile = [javaBundle pathForResource:@"DefaultApp" ofType:@"nib"];
+    } else {
+        sUsingDefaultNIB = NO;
+    }
+    
+    [NSBundle loadNibFile:defaultNibFile externalNameTable: [NSDictionary dictionaryWithObject:self forKey:@"NSOwner"] withZone:nil];
+    
+    // Set user defaults to not try to parse application arguments.
+    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
+    NSDictionary * noOpenDict = [NSDictionary dictionaryWithObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
+    [defs registerDefaults:noOpenDict];
+    
+    // Fix up the dock icon now that we are registered with CAS and the Dock.
+    [self setDockIconWithEnv:env];
+    
+    // If we are using our nib (the default application NIB) we need to put the app name into
+    // the application menu, which has placeholders for the name.
+    if (sUsingDefaultNIB) {
+        NSUInteger i, itemCount;
+        NSMenu *theMainMenu = [NSApp mainMenu];
+        
+        // First submenu off the main menu is the application menu.
+        NSMenuItem *appMenuItem = [theMainMenu itemAtIndex:0];
+        NSMenu *appMenu = [appMenuItem submenu];
+        itemCount = [appMenu numberOfItems];
+        
+        for (i = 0; i < itemCount; i++) {
+            NSMenuItem *anItem = [appMenu itemAtIndex:i];
+            NSString *oldTitle = [anItem title];
+            [anItem setTitle:[NSString stringWithFormat:oldTitle, fApplicationName]];
+        }
+    }
+    
+    if (applicationDelegate) {
+        [self setDelegate:applicationDelegate];
+    } else {
+        qad = [QueuingApplicationDelegate sharedDelegate];
+        [self setDelegate:qad];
+    }
+    
+    [super finishLaunching];
+    
+    // inform any interested parties that the AWT has arrived and is pumping
+    [[NSNotificationCenter defaultCenter] postNotificationName:JNFRunLoopDidStartNotification object:self];
+}
+
+- (void) registerWithProcessManager
+{
+    // Headless: NO
+    // Embedded: NO
+    // Multiple Calls: NO
+    //  Caller: -[NSApplicationAWT init]
+    
+AWT_ASSERT_APPKIT_THREAD;
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    
+    char envVar[80];
+    
+    // The following environment variable is set from the -Xdock:name param. It should be UTF8.
+    snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid());
+    char *appName = getenv(envVar);
+    if (appName != NULL) {
+        fApplicationName = [NSString stringWithUTF8String:appName];
+        unsetenv(envVar);
+        
+        // If this environment variable was set we were launched from the command line, so we
+        // should use a generic app icon if one wasn't set.
+        fUseDefaultIcon = YES;
+    }
+    
+    // If it wasn't specified as an argument, see if it was specified as a system property.
+    if (fApplicationName == nil) {
+        fApplicationName = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.name" withEnv:env];
+    }
+    
+    // If we STILL don't have it, the app name is retrieved from an environment variable (set in java.c) It should be UTF8.
+    if (fApplicationName == nil) {
+        char mainClassEnvVar[80];
+        snprintf(mainClassEnvVar, sizeof(mainClassEnvVar), "JAVA_MAIN_CLASS_%d", getpid());
+        char *mainClass = getenv(mainClassEnvVar);
+        if (mainClass != NULL) {
+            fApplicationName = [NSString stringWithUTF8String:mainClass];
+            unsetenv(mainClassEnvVar);
+            
+            NSRange lastPeriod = [fApplicationName rangeOfString:@"." options:NSBackwardsSearch];
+            if (lastPeriod.location != NSNotFound) {
+                fApplicationName = [fApplicationName substringFromIndex:lastPeriod.location + 1];
+            }
+            // If this environment variable was set we were launched from the command line, so we
+            // should use a generic app icon if one wasn't set.
+            fUseDefaultIcon = YES;
+        }
+    }
+    
+    // The dock name is nil for double-clickable Java apps (bundled and Web Start apps)
+    // When that happens get the display name, and if that's not available fall back to
+    // CFBundleName.
+    NSBundle *mainBundle = [NSBundle mainBundle];
+    if (fApplicationName == nil) {
+        fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
+        
+        if (fApplicationName == nil) {
+            fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
+            
+            if (fApplicationName == nil) {
+                fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey: (NSString *)kCFBundleExecutableKey];
+                
+                if (fApplicationName == nil) {
+                    // Name of last resort is the last part of the applicatoin name without the .app (consistent with CopyProcessName)
+                    fApplicationName = [[mainBundle bundlePath] lastPathComponent];
+                    
+                    if ([fApplicationName hasSuffix:@".app"]) {
+                        fApplicationName = [fApplicationName stringByDeletingPathExtension];
+                    }
+                }
+            }
+        }
+    }
+    
+    // We're all done trying to determine the app name.  Hold on to it.
+    [fApplicationName retain];
+    
+    NSDictionary *registrationOptions = [NSMutableDictionary dictionaryWithObject:fApplicationName forKey:@"JRSAppNameKey"];
+    
+    NSString *launcherType = [PropertiesUtilities javaSystemPropertyForKey:@"sun.java.launcher" withEnv:env];
+    if ([@"SUN_STANDARD" isEqualToString:launcherType]) {
+        [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsCommandLineKey"];
+    }
+    
+    NSString *uiElementProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.UIElement" withEnv:env];
+    if ([@"true" isCaseInsensitiveLike:uiElementProp]) {
+        [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsUIElementKey"];
+    }
+    
+    NSString *backgroundOnlyProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.BackgroundOnly" withEnv:env];
+    if ([@"true" isCaseInsensitiveLike:backgroundOnlyProp]) {
+        [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsBackgroundOnlyKey"];
+    }
+    
+    // TODO replace with direct call
+    // [JRSAppKitAWT registerAWTAppWithOptions:registrationOptions];
+    // and remove below transform/activate/run hack
+    
+    id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT");
+    SEL registerSel = @selector(registerAWTAppWithOptions:);
+    if ([jrsAppKitAWTClass respondsToSelector:registerSel]) {
+        [jrsAppKitAWTClass performSelector:registerSel withObject:registrationOptions];
+        return;
+    }
+    
+// HACK BEGIN
+    // The following is necessary to make the java process behave like a
+    // proper foreground application...
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        ProcessSerialNumber psn;
+        GetCurrentProcess(&psn);
+        TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+        
+        [NSApp activateIgnoringOtherApps:YES];
+        [NSApp run];
+    }];
+// HACK END
+}
+
+- (void) setDockIconWithEnv:(JNIEnv *)env {
+    NSString *theIconPath = nil;
+    
+    // The following environment variable is set in java.c. It is probably UTF8.
+    char envVar[80];
+    snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
+    char *appIcon = getenv(envVar);
+    if (appIcon != NULL) {
+        theIconPath = [NSString stringWithUTF8String:appIcon];
+        unsetenv(envVar);
+    }
+    
+    if (theIconPath == nil) {
+        theIconPath = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.icon" withEnv:env];
+    }
+    
+    // If the icon file wasn't specified as an argument and we need to get an icon
+    // we'll use the generic java app icon.
+    NSString *defaultIconPath = [NSString stringWithFormat:@"%@%@", SHARED_FRAMEWORK_BUNDLE, @"/Resources/GenericApp.icns"];
+    if (fUseDefaultIcon && (theIconPath == nil)) {
+        theIconPath = defaultIconPath;
+    }
+    
+    // Set up the dock icon if we have an icon name.
+    if (theIconPath != nil) {
+        NSImage *iconImage = [[NSImage alloc] initWithContentsOfFile:theIconPath];
+        
+        // If we failed for some reason fall back to the default icon.
+        if (iconImage == nil) {
+            iconImage = [[NSImage alloc] initWithContentsOfFile:defaultIconPath];
+        }
+        
+        [NSApp setApplicationIconImage:iconImage];
+        [iconImage release];
+    }
+}
+
++ (void) runAWTLoopWithApp:(NSApplication*)app {
+    NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+    // Make sure that when we run in AWTRunLoopMode we don't exit randomly
+    [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[JNFRunLoop javaRunLoopMode]];
+
+    do {
+        @try {
+            [app run];
+        } @catch (NSException* e) {
+            NSLog(@"Apple AWT Startup Exception: %@", [e description]);
+            NSLog(@"Apple AWT Restarting Native Event Thread");
+
+            [app stop:app];
+        }
+    } while (YES);
+
+    [pool drain];
+}
+
+- (BOOL)usingDefaultNib {
+    return sUsingDefaultNIB;
+}
+
+- (void)orderFrontStandardAboutPanelWithOptions:(NSDictionary *)optionsDictionary {
+    if (!optionsDictionary) {
+        optionsDictionary = [NSMutableDictionary dictionaryWithCapacity:2];
+        [optionsDictionary setValue:[[[[[NSApp mainMenu] itemAtIndex:0] submenu] itemAtIndex:0] title] forKey:@"ApplicationName"];
+        if (![NSImage imageNamed:@"NSApplicationIcon"]) {
+            [optionsDictionary setValue:[NSApp applicationIconImage] forKey:@"ApplicationIcon"];
+        }
+    }
+    
+    [super orderFrontStandardAboutPanelWithOptions:optionsDictionary];
+}
+
+#define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask)
+
+- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
+    if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) {
+        postEventDuringEventSynthesis = YES;
+    }
+    
+    NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag];
+    postEventDuringEventSynthesis = NO;
+    
+    return event;
+}
+
+@end
+
+
+void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> delegate)
+{
+AWT_ASSERT_APPKIT_THREAD;
+    applicationDelegate = delegate;
+    
+    if (NSApp != nil) {
+        [NSApp setDelegate: applicationDelegate];
+
+        if (applicationDelegate && qad) {
+            [qad processQueuedEventsWithTargetDelegate: applicationDelegate];
+            qad = nil;
+        }
+    }
+}
+
diff --git a/jdk/src/macosx/native/sun/osxapp/PropertiesUtilities.h b/jdk/src/macosx/native/sun/osxapp/PropertiesUtilities.h
new file mode 100644
index 0000000..f013121
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/PropertiesUtilities.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+
+@interface PropertiesUtilities : NSObject
+
++ (NSString *) javaSystemPropertyForKey:(NSString *)key withEnv:(JNIEnv *)env;
+
+@end
diff --git a/jdk/src/macosx/native/sun/osxapp/PropertiesUtilities.m b/jdk/src/macosx/native/sun/osxapp/PropertiesUtilities.m
new file mode 100644
index 0000000..786709e
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/PropertiesUtilities.m
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import "PropertiesUtilities.h"
+
+@implementation PropertiesUtilities
+
++ (NSString *) javaSystemPropertyForKey:(NSString *)key withEnv:(JNIEnv *)env {
+    static JNF_CLASS_CACHE(jc_System, "java/lang/System");
+    static JNF_STATIC_MEMBER_CACHE(jm_getProperty, jc_System, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
+    
+    jstring jKey = JNFNSToJavaString(env, key);
+    jstring jValue = JNFCallStaticObjectMethod(env, jm_getProperty, jKey);
+    (*env)->DeleteLocalRef(env, jKey);
+    
+    NSString *value = JNFJavaToNSString(env, jValue);
+    (*env)->DeleteLocalRef(env, jValue);
+    return value;
+}
+
+@end
diff --git a/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h
new file mode 100644
index 0000000..6075183
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface QueuingApplicationDelegate : NSObject<NSApplicationDelegate>
+{
+    BOOL fHandlesDocumentTypes;
+    BOOL fHandlesURLTypes;
+
+    NSMutableArray* queue;
+}
+
++ (QueuingApplicationDelegate*) sharedDelegate;
+
+- (id) init;
+- (void) dealloc;
+
+- (void)processQueuedEventsWithTargetDelegate:(id <NSApplicationDelegate>)delegate;
+
+@end
+
diff --git a/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m
new file mode 100644
index 0000000..894b803
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#import "QueuingApplicationDelegate.h"
+
+static id <NSApplicationDelegate> realDelegate = nil;
+
+@interface NSBundle (EAWTOverrides)
+- (BOOL)_hasEAWTOverride:(NSString *)key;
+@end
+
+
+@implementation NSBundle (EAWTOverrides)
+
+- (BOOL)_hasEAWTOverride:(NSString *)key {
+    return [[[[self objectForInfoDictionaryKey:@"Java"] objectForKey:@"EAWTOverride"] objectForKey:key] boolValue];
+}
+
+@end
+
+@implementation QueuingApplicationDelegate
+
++ (QueuingApplicationDelegate*) sharedDelegate
+{
+    static QueuingApplicationDelegate * qad = nil;
+
+    if (!qad) {
+        qad = [QueuingApplicationDelegate new];
+    }
+
+    return qad;
+}
+
+- (id) init
+{
+    self = [super init];
+    if (!self) {
+        return self;
+    }
+
+    self->queue = [[NSMutableArray arrayWithCapacity: 0] retain];
+
+    // If the java application has a bundle with an Info.plist file with
+    //  a CFBundleDocumentTypes entry, then it is set up to handle Open Doc
+    //  and Print Doc commands for these files. Therefore java AWT will
+    //  cache Open Doc and Print Doc events that are sent prior to a 
+    //  listener being installed by the client java application.
+    NSBundle *bundle = [NSBundle mainBundle];
+    fHandlesDocumentTypes = [bundle objectForInfoDictionaryKey:@"CFBundleDocumentTypes"] != nil || [bundle _hasEAWTOverride:@"DocumentHandler"];
+    fHandlesURLTypes = [bundle objectForInfoDictionaryKey:@"CFBundleURLTypes"] != nil || [bundle _hasEAWTOverride:@"URLHandler"];
+    if (fHandlesURLTypes) {
+        [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
+                                                           andSelector:@selector(_handleOpenURLEvent:withReplyEvent:)
+                                                         forEventClass:kInternetEventClass
+                                                            andEventID:kAEGetURL];
+    }
+
+    NSNotificationCenter *ctr = [NSNotificationCenter defaultCenter];
+    [ctr addObserver:self selector:@selector(_willFinishLaunching) name:NSApplicationWillFinishLaunchingNotification object:nil];
+    [ctr addObserver:self selector:@selector(_systemWillPowerOff) name:NSWorkspaceWillPowerOffNotification object:nil];
+    [ctr addObserver:self selector:@selector(_appDidActivate) name:NSApplicationDidBecomeActiveNotification object:nil];
+    [ctr addObserver:self selector:@selector(_appDidDeactivate) name:NSApplicationDidResignActiveNotification object:nil];
+    [ctr addObserver:self selector:@selector(_appDidHide) name:NSApplicationDidHideNotification object:nil];
+    [ctr addObserver:self selector:@selector(_appDidUnhide) name:NSApplicationDidUnhideNotification object:nil];
+
+    return self;
+}
+
+- (void)dealloc
+{
+    if (fHandlesURLTypes) {
+        [[NSAppleEventManager sharedAppleEventManager] removeEventHandlerForEventClass: kInternetEventClass andEventID:kAEGetURL];
+    }
+
+    NSNotificationCenter *ctr = [NSNotificationCenter defaultCenter];
+    Class clz = [QueuingApplicationDelegate class];
+    [ctr removeObserver:clz];
+
+    [self->queue release];
+    self->queue = nil;
+
+    [super dealloc];
+}
+
+
+- (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent
+{
+    [self->queue addObject:^(){
+        [realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent];
+    }];
+}
+
+- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)fileNames
+{
+    [self->queue addObject:^(){
+        [realDelegate application:theApplication openFiles:fileNames];
+    }];
+}
+
+- (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels
+{
+    if (!fHandlesDocumentTypes) {
+        return NSPrintingCancelled;
+    }
+
+    [self->queue addObject:^(){
+        [realDelegate application:application printFiles:fileNames withSettings:printSettings showPrintPanels:showPrintPanels];
+    }];
+    
+    // well, a bit premature, but what else can we do?..
+    return NSPrintingSuccess;
+}
+
+- (void)_willFinishLaunching
+{
+    QueuingApplicationDelegate * q = self;
+    [self->queue addObject:^(){
+        [[realDelegate class] _willFinishLaunching];
+    }];
+}
+
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
+{
+    [self->queue addObject:^(){
+        [realDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag];
+    }];
+    return YES;
+}
+
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
+{
+    [self->queue addObject:^(){
+        [realDelegate applicationShouldTerminate:app];
+    }];
+    return NSTerminateLater;
+}
+
+- (void)_systemWillPowerOff
+{
+    [self->queue addObject:^(){
+        [[realDelegate class] _systemWillPowerOff];
+    }];
+}
+
+- (void)_appDidActivate
+{
+    [self->queue addObject:^(){
+        [[realDelegate class] _appDidActivate];
+    }];
+}
+
+- (void)_appDidDeactivate
+{
+    [self->queue addObject:^(){
+        [[realDelegate class] _appDidDeactivate];
+    }];
+}
+
+- (void)_appDidHide
+{
+    [self->queue addObject:^(){
+        [[realDelegate class] _appDidHide];
+    }];
+}
+
+- (void)_appDidUnhide
+{
+    [self->queue addObject:^(){
+        [[realDelegate class] _appDidUnhide];
+    }];
+}
+
+- (void)processQueuedEventsWithTargetDelegate:(id <NSApplicationDelegate>)delegate
+{
+    NSUInteger i;
+    NSUInteger count = [self->queue count];
+
+    realDelegate = delegate;
+
+    for (i = 0; i < count; i++) {
+        void (^event)() = (void (^)())[self->queue objectAtIndex: i];
+        event();
+    }
+
+    [self->queue removeAllObjects];
+}
+
+@end
+
diff --git a/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.h b/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.h
new file mode 100644
index 0000000..c681122
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.h
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef __THREADUTILITIES_H
+#define __THREADUTILITIES_H
+
+#import <pthread.h>
+
+#import "AWT_debug.h"
+
+
+// --------------------------------------------------------------------------
+#ifndef PRODUCT_BUILD
+
+// Turn on the AWT thread assert mechanism. See below for different variants.
+// TODO: don't enable this for production builds...
+#define AWT_THREAD_ASSERTS
+
+#endif /* PRODUCT_BUILD */
+// --------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------
+#ifdef AWT_THREAD_ASSERTS
+
+// Turn on to have awt thread asserts display a message on the console.
+#define AWT_THREAD_ASSERTS_MESSAGES
+
+// Turn on to have awt thread asserts use an environment variable switch to
+// determine if assert should really be called.
+//#define AWT_THREAD_ASSERTS_ENV_ASSERT
+
+// Define AWT_THREAD_ASSERTS_WAIT to make asserts halt the asserting thread
+// for debugging purposes.
+//#define AWT_THREAD_ASSERTS_WAIT
+
+#ifdef AWT_THREAD_ASSERTS_MESSAGES
+
+#define AWT_THREAD_ASSERTS_NOT_APPKIT_MESSAGE \
+    AWT_DEBUG_LOG(@"Not running on AppKit thread 0 when expected.")
+
+#define AWT_THREAD_ASSERTS_ON_APPKIT_MESSAGE \
+    AWT_DEBUG_LOG(@"Running on AppKit thread 0 when not expected.")
+
+#ifdef AWT_THREAD_ASSERTS_ENV_ASSERT
+
+extern int sAWTThreadAsserts;
+#define AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK    \
+do {                                           \
+    if (sAWTThreadAsserts) {                   \
+        NSLog(@"\tPlease run this java program again with setenv COCOA_AWT_DISABLE_THREAD_ASSERTS to proceed with a warning."); \
+        assert(NO);                            \
+    }                                          \
+} while (0)
+
+#else
+
+#define AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK do {} while (0)
+
+#endif /* AWT_THREAD_ASSERTS_ENV_ASSERT */
+
+#define AWT_ASSERT_APPKIT_THREAD               \
+do {                                           \
+    if (pthread_main_np() == 0) {              \
+        AWT_THREAD_ASSERTS_NOT_APPKIT_MESSAGE; \
+        AWT_DEBUG_BUG_REPORT_MESSAGE;          \
+        AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK;   \
+    }                                          \
+} while (0)
+
+#define AWT_ASSERT_NOT_APPKIT_THREAD           \
+do {                                           \
+    if (pthread_main_np() != 0) {              \
+        AWT_THREAD_ASSERTS_ON_APPKIT_MESSAGE;  \
+        AWT_DEBUG_BUG_REPORT_MESSAGE;          \
+        AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK;   \
+    }                                          \
+} while (0)
+
+#define AWT_ASSERT_ANY_THREAD
+
+#endif /* AWT_THREAD_ASSERTS_MESSAGES */
+
+#ifdef AWT_THREAD_ASSERTS_WAIT
+
+#define AWT_ASSERT_APPKIT_THREAD      \
+do {                                  \
+    while (pthread_main_np() == 0) {} \
+} while (0)
+
+#define AWT_ASSERT_NOT_APPKIT_THREAD  \
+do {                                  \
+    while (pthread_main_np() != 0) {} \
+} while (0)
+
+#define AWT_ASSERT_ANY_THREAD
+
+#endif /* AWT_THREAD_ASSERTS_WAIT */
+
+#else /* AWT_THREAD_ASSERTS */
+
+#define AWT_ASSERT_APPKIT_THREAD     do {} while (0)
+#define AWT_ASSERT_NOT_APPKIT_THREAD do {} while (0)
+#define AWT_ASSERT_ANY_THREAD
+
+#endif /* AWT_THREAD_ASSERTS */
+// --------------------------------------------------------------------------
+
+// This tracks if we are current inside of a performOnMainThread that is both waiting and in the AWTRunLoopMode
+extern BOOL sInPerformFromJava;
+
+// This is an empty Obj-C object just so that -performSelectorOnMainThread
+// can be used, and to use the Obj-C +initialize feature.
+__attribute__((visibility("default")))
+@interface ThreadUtilities : NSObject { }
+
++ (JNIEnv*)getJNIEnv;
++ (JNIEnv*)getJNIEnvUncached;
+
++ (void)performOnMainThread:(SEL)aSelector onObject:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait awtMode:(BOOL)inAWT;
+
+@end
+
+void OSXAPP_SetJavaVM(JavaVM *vm);
+
+#endif /* __THREADUTILITIES_H */
diff --git a/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m b/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m
new file mode 100644
index 0000000..81590ea
--- /dev/null
+++ b/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#import <AppKit/AppKit.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <objc/message.h>
+
+#import "ThreadUtilities.h"
+
+
+// The following must be named "jvm", as there are extern references to it in AWT
+JavaVM *jvm = NULL;
+static JNIEnv *appKitEnv = NULL;
+
+static NSArray *sPerformModes = nil;
+static NSArray *sAWTPerformModes = nil;
+
+static BOOL sCocoaComponentCompatibility = NO;
+static NSTimeInterval sCocoaComponentCompatibilityTimeout = 0.5;
+static BOOL sLoggingEnabled = YES;
+
+#ifdef AWT_THREAD_ASSERTS_ENV_ASSERT
+int sAWTThreadAsserts = 0;
+#endif /* AWT_THREAD_ASSERTS_ENV_ASSERT */
+
+
+// This is for backward compatibility for those people using CocoaComponent
+// Since we've flipped the AWT threading model for Tiger (10.4), all the rules
+// for CocoaComponent are wrong.
+// So for existing CocoaComponent users, we can't be synchronous.
+// Making things totally asynchronous breaks a _lot_, so we try to be
+// synchronous and time out after a little bit.
+#define NOT_READY 0
+#define READY 1
+#define IN_PROGRESS 2
+
+BOOL sInPerformFromJava = NO;
+NSUInteger sPerformCount = 0;
+
+// This class is used so that performSelectorOnMainThread can be
+// controlled a little more easily by us.  It has 2 roles.
+// The first is to set/unset a flag (sInPerformFromJava) that code can
+// check to see if we are in a synchronous perform initiated by a java thread.
+// The second is to implement the CocoaComponent backward compatibility mode.
+@interface CPerformer : NSObject {
+    id fTarget;
+    SEL fSelector;
+    id fArg;
+    BOOL fWait;
+}
+
+- (id) initWithTarget:(id)target selector:(SEL)selector arg:(id)arg wait:(BOOL)wait;
+- (void) perform;
+- (void) performCompatible;
+- (void) _performCompatible:(NSConditionLock *)resultLock;
+@end
+
+
+@implementation CPerformer
+
+- (id) initWithTarget:(id)target selector:(SEL)selector arg:(id)arg {
+    return [self initWithTarget:target selector:selector arg:arg wait:YES];
+}
+
+- (id) initWithTarget:(id)target selector:(SEL)selector arg:(id)arg wait:(BOOL)wait {
+    self = [super init];
+    if (self != nil) {
+        fTarget = [target retain];
+        fSelector = selector;
+        fArg = [arg retain];
+        // Only set sInPerformFromJava if this is a synchronous perform
+        fWait = wait;
+    }
+    return self;
+}
+
+- (void) dealloc {
+    [fTarget release];
+    [fArg release];
+    [super dealloc];
+}
+//- (void)finalize { [super finalize]; }
+
+- (void) perform {
+    AWT_ASSERT_APPKIT_THREAD;
+
+    // If this is the first time we're going from java thread -> appkit thread,
+    // set sInPerformFromJava for the duration of the invocation
+    BOOL nestedPerform = sInPerformFromJava;
+    if (fWait) {
+        sInPerformFromJava = YES;
+    }
+    
+    sPerformCount++;
+
+    // Actually do the work (cheat to avoid a method call)
+    @try {
+        objc_msgSend(fTarget, fSelector, fArg);
+        //[fTarget performSelector:fSelector withObject:fArg];
+    } @catch (NSException *e) {
+        NSLog(@"*** CPerformer: ignoring exception '%@' raised during perform of selector '%@' on target '%@' with args '%@'", e, NSStringFromSelector(fSelector), fTarget, fArg);
+    } @finally {
+        // If we actually set sInPerformFromJava, unset it now
+        if (!nestedPerform && fWait) {
+            sInPerformFromJava = NO;
+        }
+    }
+}
+
+- (void) performCompatible {
+    // We check if we are on the AppKit thread because frequently, apps
+    // using CocoaComponent are doing things on the wrong thread!
+    if (pthread_main_np()) {
+        [fTarget performSelector:fSelector withObject:fArg];
+    } else {
+        // Setup the lock
+        NSConditionLock *resultLock =
+            [[NSConditionLock alloc] initWithCondition:NOT_READY];
+
+        // Make sure that if we return early, nothing gets released out
+        // from under us
+        [resultLock retain];
+        [fTarget retain];
+        [fArg retain];
+        [self retain];
+        // Do an asynchronous perform to the main thread.
+        [self performSelectorOnMainThread:@selector(_performCompatible:)
+              withObject:resultLock waitUntilDone:NO modes:sAWTPerformModes];
+        
+        // Wait for a little bit for it to finish
+        [resultLock lockWhenCondition:READY beforeDate:[NSDate dateWithTimeIntervalSinceNow:sCocoaComponentCompatibilityTimeout]];
+        
+        // If the _performCompatible is actually in progress,
+        // we should let it finish
+        if ([resultLock condition] == IN_PROGRESS) {
+            [resultLock lockWhenCondition:READY];
+        }
+        
+        if ([resultLock condition] == NOT_READY && sLoggingEnabled) {
+            NSLog(@"[Java CocoaComponent compatibility mode]: Operation timed out due to possible deadlock: selector '%@' on target '%@' with args '%@'", NSStringFromSelector(fSelector), fTarget, fArg);
+        }
+        
+        [resultLock unlock];
+        [resultLock autorelease];
+    }
+}
+
+- (void) _performCompatible:(NSConditionLock *)resultLock {
+    // notify that the perform is in progress!
+    [resultLock lock];
+    [resultLock unlockWithCondition:IN_PROGRESS];
+    
+    sPerformCount++;
+    
+    // Actually do the work.
+    @try {
+        [fTarget performSelector:fSelector withObject:fArg];
+    } @catch (NSException *e) {
+        NSLog(@"*** CPerformer: ignoring exception '%@' raised during performCompatible of selector '%@' on target '%@' with args '%@'", e, NSStringFromSelector(fSelector), fTarget, fArg);
+    } @finally {
+        // notify done!
+        [resultLock lock];
+        [resultLock unlockWithCondition:READY];
+        
+        // Clean up after ourselves
+        [resultLock autorelease];
+        [fTarget autorelease];
+        [fArg autorelease];
+        [self autorelease];
+    }
+}
+@end
+
+
+@implementation ThreadUtilities
+
++ (JNIEnv*)getJNIEnv {
+AWT_ASSERT_APPKIT_THREAD;
+    if (appKitEnv == NULL) {
+        (*jvm)->AttachCurrentThreadAsDaemon(jvm, (void **)&appKitEnv, NULL);
+    }
+    return appKitEnv;
+}
+
++ (JNIEnv*)getJNIEnvUncached {
+    JNIEnv *env = NULL;
+    (*jvm)->AttachCurrentThreadAsDaemon(jvm, (void **)&env, nil);
+    return env;
+}
+
++ (void)initialize {
+    // Headless: BOTH
+    // Embedded: BOTH
+    // Multiple Calls: NO
+    // Caller: Obj-C class initialization
+    // Thread: ?
+
+    if (sPerformModes == nil) {
+        // Create list of Run Loop modes to perform on
+        // The default performSelector, with no mode argument, runs in Default,
+        // ModalPanel, and EventTracking modes
+        sPerformModes =    [[NSArray alloc] initWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, nil];
+        sAWTPerformModes = [[NSArray alloc] initWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode, [JNFRunLoop javaRunLoopMode], nil];
+        
+#ifdef AWT_THREAD_ASSERTS_ENV_ASSERT
+        sAWTThreadAsserts = (getenv("COCOA_AWT_DISABLE_THREAD_ASSERTS") == NULL);
+#endif /* AWT_THREAD_ASSERTS_ENV_ASSERT */
+    }
+}
+
+// These methods can behave slightly differently than the normal
+// performSelector...  In particular, we define a special runloop mode
+// (AWTRunLoopMode) so that we can "block" the main thread against the
+// java event thread without deadlocking. See CToolkit.invokeAndWait.
++ (void)performOnMainThread:(SEL)aSelector onObject:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait awtMode:(BOOL)inAWT {
+    CPerformer *performer = [[CPerformer alloc] initWithTarget:target selector:aSelector arg:arg wait:wait];
+    if (sCocoaComponentCompatibility && wait && inAWT) {
+        [performer performCompatible];
+        [performer autorelease];
+    } else {
+        [performer performSelectorOnMainThread:@selector(perform) withObject:nil waitUntilDone:wait modes:((inAWT) ? sAWTPerformModes : sPerformModes)]; // AWT_THREADING Safe (cover method)
+        [performer release];
+    }
+}
+
+@end
+
+
+void OSXAPP_SetJavaVM(JavaVM *vm)
+{
+    jvm = vm;
+}
+
diff --git a/jdk/src/share/back/commonRef.c b/jdk/src/share/back/commonRef.c
index c63fd74..94da8f1 100644
--- a/jdk/src/share/back/commonRef.c
+++ b/jdk/src/share/back/commonRef.c
@@ -23,6 +23,10 @@
  * questions.
  */
 
+#if defined(_ALLBSD_SOURCE)
+#include <stdint.h>                     /* for uintptr_t */
+#endif
+
 #include "util.h"
 #include "commonRef.h"
 
diff --git a/jdk/src/share/bin/java.c b/jdk/src/share/bin/java.c
index 619d64f..8c7c9fa 100644
--- a/jdk/src/share/bin/java.c
+++ b/jdk/src/share/bin/java.c
@@ -70,6 +70,12 @@
 static jboolean printXUsage = JNI_FALSE;  /* print and exit*/
 static char     *showSettings = NULL;      /* print but continue */
 
+#ifdef MACOSX
+#include <objc/objc-auto.h>
+#include <dispatch/dispatch.h>
+static jboolean continueInSameThread = JNI_FALSE; /* start VM in current thread */
+#endif
+
 static const char *_program_name;
 static const char *_launcher_name;
 static jboolean _is_java_args = JNI_FALSE;
@@ -120,6 +126,19 @@
 static void DumpState();
 static jboolean RemovableOption(char *option);
 
+#ifdef MACOSX
+static void SetMainClassForAWT(JNIEnv *env, jclass mainClass);
+static void SetXDockArgForAWT(const char *arg);
+static void SetXStartOnFirstThreadArg();
+
+static JavaVM* jvmInstance = NULL;
+
+JavaVM* JLI_GetJavaVMInstance()
+{
+    return jvmInstance;
+}
+#endif
+
 /* Maximum supported entries from jvm.cfg. */
 #define INIT_MAX_KNOWN_VMS      10
 
@@ -312,9 +331,30 @@
     /* set the -Dsun.java.launcher.* platform properties */
     SetJavaLauncherPlatformProps();
 
+#ifndef MACOSX
+    // On MacOSX the splash screen is shown from JavaMain
+    // after the JVM is initialized.
     /* Show the splash screen if needed */
     ShowSplashScreen();
+#endif
 
+#ifdef MACOSX
+    if (continueInSameThread == JNI_TRUE) {
+        // need to block this thread against the main thread
+        // so signals get caught correctly
+        __block int rslt;
+        dispatch_sync(dispatch_get_main_queue(), ^(void){
+            JavaMainArgs args;
+            args.argc = argc;
+            args.argv = argv;
+            args.mode = mode;
+            args.what = what;
+            args.ifn = ifn;
+            rslt = JavaMain((void*)&args);
+        });
+        return rslt;
+    }
+#endif
     return ContinueInNewThread(&ifn, argc, argv, mode, what, ret);
 
 }
@@ -375,6 +415,10 @@
     int ret = 0;
     jlong start, end;
 
+#ifdef MACOSX
+    objc_registerThreadWithCollector();
+#endif
+
     /* Initialize the virtual machine */
     start = CounterGet();
     if (!InitializeJVM(&vm, &env, &ifn)) {
@@ -443,6 +487,12 @@
      */
     mainClass = LoadMainClass(env, mode, what);
     CHECK_EXCEPTION_NULL_LEAVE(mainClass);
+#ifdef MACOSX
+    // if we got here, we know what the main class is, and it has been loaded
+    SetMainClassForAWT(env, mainClass);
+    jvmInstance = vm;
+    ShowSplashScreen();
+#endif
 
     /*
      * The LoadMainClass not only loads the main class, it will also ensure
@@ -1006,6 +1056,12 @@
         } else if (JLI_StrCmp(arg, "-X") == 0) {
             printXUsage = JNI_TRUE;
             return JNI_TRUE;
+#ifdef MACOSX
+        } else if (JLI_StrCmp(arg, "-XstartOnFirstThread") == 0) {
+            SetXStartOnFirstThreadArg();
+        } else if (JLI_StrCCmp(arg, "-Xdock:") == 0) {
+            SetXDockArgForAWT(arg);
+#endif
 /*
  * The following case checks for -XshowSettings OR -XshowSetting:SUBOPT.
  * In the latter case, any SUBOPT value not recognized will default to "all"
@@ -1621,7 +1677,12 @@
         start = CounterGet();
     }
     JLI_Snprintf(jvmCfgName, sizeof(jvmCfgName), "%s%slib%s%s%sjvm.cfg",
-        jrepath, FILESEP, FILESEP, arch, FILESEP);
+        jrepath, FILESEP, FILESEP,
+#ifdef MACOSX
+        "", "");
+#else
+        arch, FILESEP);
+#endif
 
     jvmCfg = fopen(jvmCfgName, "r");
     if (jvmCfg == NULL) {
@@ -1897,6 +1958,57 @@
     }
 }
 
+#ifdef MACOSX
+static void SetMainClassForAWT(JNIEnv *env, jclass mainClass) {
+    jclass classClass = NULL;
+    NULL_CHECK(classClass = FindBootStrapClass(env, "java/lang/Class"));
+
+    jmethodID getCanonicalNameMID = NULL;
+    NULL_CHECK(getCanonicalNameMID = (*env)->GetMethodID(env, classClass, "getCanonicalName", "()Ljava/lang/String;"));
+
+    jstring mainClassString = NULL;
+    NULL_CHECK(mainClassString = (*env)->CallObjectMethod(env, mainClass, getCanonicalNameMID));
+
+    const char *mainClassName = NULL;
+    NULL_CHECK(mainClassName = (*env)->GetStringUTFChars(env, mainClassString, NULL));
+
+    char envVar[80];
+    snprintf(envVar, sizeof(envVar), "JAVA_MAIN_CLASS_%d", getpid());
+    setenv(envVar, mainClassName, 1);
+
+    (*env)->ReleaseStringUTFChars(env, mainClassString, mainClassName);
+}
+
+static void SetXDockArgForAWT(const char *arg) {
+    char envVar[80];
+    if (strstr(arg, "-Xdock:name=") == arg) {
+        snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid());
+        setenv(envVar, (arg + 12), 1);
+    }
+
+    if (strstr(arg, "-Xdock:icon=") == arg) {
+        snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
+        setenv(envVar, (arg + 12), 1);
+    }
+}
+
+static void SetXStartOnFirstThreadArg() {
+// XXX: BEGIN HACK
+    // short circuit hack for <https://bugs.eclipse.org/bugs/show_bug.cgi?id=211625>
+    // need a way to get AWT/Swing apps launched when spawned from Eclipse,
+    // which currently has no UI to not pass the -XstartOnFirstThread option
+    if (getenv("HACK_IGNORE_START_ON_FIRST_THREAD") != NULL) return;
+// XXX: END HACK
+
+    continueInSameThread = JNI_TRUE;
+    // Set a variable that tells us we started on the main thread.
+    // This is used by the AWT during startup. (See awt.m)
+    char envVar[80];
+    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
+    setenv(envVar, "1", 1);
+}
+#endif
+
 static void
 DumpState()
 {
diff --git a/jdk/src/share/bin/java.h b/jdk/src/share/bin/java.h
index 04c2091..5a237f8 100644
--- a/jdk/src/share/bin/java.h
+++ b/jdk/src/share/bin/java.h
@@ -79,10 +79,12 @@
  */
 typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);
 typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args);
+typedef jint (JNICALL *GetCreatedJavaVMs_t)(JavaVM **vmBuf, jsize bufLen, jsize *nVMs);
 
 typedef struct {
     CreateJavaVM_t CreateJavaVM;
     GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs;
+    GetCreatedJavaVMs_t GetCreatedJavaVMs;
 } InvocationFunctions;
 
 int
diff --git a/jdk/src/share/classes/com/sun/beans/finder/AbstractFinder.java b/jdk/src/share/classes/com/sun/beans/finder/AbstractFinder.java
index 217bb9a..8ec9ffb 100644
--- a/jdk/src/share/classes/com/sun/beans/finder/AbstractFinder.java
+++ b/jdk/src/share/classes/com/sun/beans/finder/AbstractFinder.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -54,7 +54,7 @@
 
     /**
      * Returns an array of {@code Class} objects
-     * that represent the formal parameter types of the method
+     * that represent the formal parameter types of the method.
      * Returns an empty array if the method takes no parameters.
      *
      * @param method  the object that represents method
diff --git a/jdk/src/share/classes/com/sun/beans/finder/ConstructorFinder.java b/jdk/src/share/classes/com/sun/beans/finder/ConstructorFinder.java
index beb9bdc..cfc3a1c 100644
--- a/jdk/src/share/classes/com/sun/beans/finder/ConstructorFinder.java
+++ b/jdk/src/share/classes/com/sun/beans/finder/ConstructorFinder.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -87,7 +87,7 @@
 
     /**
      * Returns an array of {@code Class} objects
-     * that represent the formal parameter types of the constructor
+     * that represent the formal parameter types of the constructor.
      * Returns an empty array if the constructor takes no parameters.
      *
      * @param constructor  the object that represents constructor
diff --git a/jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java b/jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java
index 7587c89..5fc97b2 100644
--- a/jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java
+++ b/jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -190,7 +190,7 @@
 
     /**
      * Returns an array of {@code Class} objects
-     * that represent the formal parameter types of the method
+     * that represent the formal parameter types of the method.
      * Returns an empty array if the method takes no parameters.
      *
      * @param method  the object that represents method
@@ -226,6 +226,6 @@
      */
     @Override
     protected boolean isValid(Method method) {
-        return Modifier.isPublic(method.getModifiers()) && method.getName().equals(this.name);
+        return !method.isBridge() && Modifier.isPublic(method.getModifiers()) && method.getName().equals(this.name);
     }
 }
diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
index 27918c0..fd304e0 100644
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
@@ -477,6 +477,10 @@
                 String[] dirs = new String[] {
                     userHome + sep + ".themes",
                     System.getProperty("swing.metacitythemedir"),
+                    "/usr/X11R6/share/themes",
+                    "/usr/X11R6/share/gnome/themes",
+                    "/usr/local/share/themes",
+                    "/usr/local/share/gnome/themes",
                     "/usr/share/themes",
                     "/usr/gnome/share/themes",  // Debian/Redhat/Solaris
                     "/opt/gnome2/share/themes"  // SuSE
diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java b/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java
index 6ca3ae1..4f3eec2 100644
--- a/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java
@@ -32,6 +32,7 @@
 import java.io.OutputStream;
 import java.io.InputStream;
 import java.net.Socket;
+import javax.net.ssl.SSLSocket;
 
 import javax.naming.CommunicationException;
 import javax.naming.ServiceUnavailableException;
@@ -366,6 +367,19 @@
             }
         }
 
+        // For LDAP connect timeouts on LDAP over SSL connections must treat
+        // the SSL handshake following socket connection as part of the timeout.
+        // So explicitly set a socket read timeout, trigger the SSL handshake,
+        // then reset the timeout.
+        if (connectTimeout > 0 && socket instanceof SSLSocket) {
+            SSLSocket sslSocket = (SSLSocket) socket;
+            int socketTimeout = sslSocket.getSoTimeout();
+
+            sslSocket.setSoTimeout(connectTimeout); // reuse full timeout value
+            sslSocket.startHandshake();
+            sslSocket.setSoTimeout(socketTimeout);
+        }
+
         return socket;
     }
 
diff --git a/jdk/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java b/jdk/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java
index 5da153d..94bd9c3 100644
--- a/jdk/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java
+++ b/jdk/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java
@@ -721,7 +721,7 @@
                         cred = builder.action().getCreds();
                     }
                     if (storeKey) {
-                        encKeys = builder.getKeys();
+                        encKeys = builder.getKeys(isInitiator);
                         // When encKeys is empty, the login actually fails.
                         // For compatibility, exception is thrown in commit().
                     }
diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java
index 90eff2a..dd2eec7 100644
--- a/jdk/src/share/classes/java/awt/Component.java
+++ b/jdk/src/share/classes/java/awt/Component.java
@@ -7911,7 +7911,7 @@
                 res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
             }
         }
-        if (clearOnFailure && !res) {
+        if (!res) {
             if (focusLog.isLoggable(PlatformLogger.FINER)) {
                 focusLog.finer("clear global focus owner");
             }
diff --git a/jdk/src/share/classes/java/awt/EventDispatchThread.java b/jdk/src/share/classes/java/awt/EventDispatchThread.java
index b938ac8..427ad7e 100644
--- a/jdk/src/share/classes/java/awt/EventDispatchThread.java
+++ b/jdk/src/share/classes/java/awt/EventDispatchThread.java
@@ -34,8 +34,10 @@
 import sun.security.action.GetPropertyAction;
 import sun.awt.AWTAutoShutdown;
 import sun.awt.SunToolkit;
+import sun.awt.AppContext;
 
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
 import sun.util.logging.PlatformLogger;
 
 import sun.awt.dnd.SunDragSourceContextPeer;
@@ -66,11 +68,11 @@
 
     private EventQueue theQueue;
     private boolean doDispatch = true;
-    private boolean threadDeathCaught = false;
+    private volatile boolean shutdown = false;
 
     private static final int ANY_EVENT = -1;
 
-    private Vector<EventFilter> eventFilters = new Vector<EventFilter>();
+    private ArrayList<EventFilter> eventFilters = new ArrayList<EventFilter>();
 
     EventDispatchThread(ThreadGroup group, String name, EventQueue queue) {
         super(group, name);
@@ -84,6 +86,11 @@
         doDispatch = false;
     }
 
+    public void interrupt() {
+        shutdown = true;
+        super.interrupt();
+    }
+
     public void run() {
         while (true) {
             try {
@@ -93,14 +100,41 @@
                     }
                 });
             } finally {
-                EventQueue eq = getEventQueue();
-                if (eq.detachDispatchThread(this) || threadDeathCaught) {
+                if(getEventQueue().detachDispatchThread(this, shutdown)) {
                     break;
                 }
             }
         }
     }
 
+    // MacOSX change:
+    //  This was added because this class (and java.awt.Conditional) are package private.
+    //  There are certain instances where classes in other packages need to block the
+    //  AWTEventQueue while still allowing it to process events. This uses reflection
+    //  to call back into the caller in order to remove dependencies.
+    //
+    // NOTE: This uses reflection in its implementation, so it is not for performance critical code.
+    //
+    //  cond is an instance of sun.lwawt.macosx.EventDispatchAccess
+    //
+    private Conditional _macosxGetConditional(final Object cond) {
+        try {
+            return new Conditional() {
+                final Method evaluateMethod = Class.forName("sun.lwawt.macosx.EventDispatchAccess").getMethod("evaluate", null);
+                public boolean evaluate() {
+                    try {
+                        return ((Boolean)evaluateMethod.invoke(cond, null)).booleanValue();
+                    } catch (Exception e) {
+                        return false;
+                    }
+                }
+            };
+        } catch (Exception e) {
+            return new Conditional() { public boolean evaluate() { return false; } };
+        }
+    }
+
+
     void pumpEvents(Conditional cond) {
         pumpEvents(ANY_EVENT, cond);
     }
@@ -124,10 +158,9 @@
     void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
         addEventFilter(filter);
         doDispatch = true;
-        while (doDispatch && cond.evaluate()) {
-            if (isInterrupted() || !pumpOneEventForFilters(id)) {
-                doDispatch = false;
-            }
+        shutdown |= isInterrupted();
+        while (doDispatch && !shutdown && cond.evaluate()) {
+            pumpOneEventForFilters(id);
         }
         removeEventFilter(filter);
     }
@@ -163,7 +196,7 @@
         }
     }
 
-    boolean pumpOneEventForFilters(int id) {
+    void pumpOneEventForFilters(int id) {
         AWTEvent event = null;
         boolean eventOK = false;
         try {
@@ -212,24 +245,18 @@
             if (delegate != null) {
                 delegate.afterDispatch(event, handle);
             }
-
-            return true;
         }
         catch (ThreadDeath death) {
-            threadDeathCaught = true;
-            return false;
-
+            shutdown = true;
+            throw death;
         }
         catch (InterruptedException interruptedException) {
-            return false; // AppContext.dispose() interrupts all
-                          // Threads in the AppContext
-
+            shutdown = true; // AppContext.dispose() interrupts all
+                             // Threads in the AppContext
         }
         catch (Throwable e) {
             processException(e);
         }
-
-        return true;
     }
 
     private void processException(Throwable e) {
diff --git a/jdk/src/share/classes/java/awt/EventQueue.java b/jdk/src/share/classes/java/awt/EventQueue.java
index efc231c..86ea84a 100644
--- a/jdk/src/share/classes/java/awt/EventQueue.java
+++ b/jdk/src/share/classes/java/awt/EventQueue.java
@@ -47,6 +47,7 @@
 
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import java.security.AccessControlContext;
 import java.security.ProtectionDomain;
@@ -99,12 +100,7 @@
  * @since       1.1
  */
 public class EventQueue {
-
-    // From Thread.java
-    private static int threadInitNumber;
-    private static synchronized int nextThreadNum() {
-        return threadInitNumber++;
-    }
+    private static final AtomicInteger threadInitNumber = new AtomicInteger(0);
 
     private static final int LOW_PRIORITY = 0;
     private static final int NORM_PRIORITY = 1;
@@ -175,9 +171,9 @@
      * Non-zero if a thread is waiting in getNextEvent(int) for an event of
      * a particular ID to be posted to the queue.
      */
-    private int waitForID;
+    private volatile int waitForID;
 
-    private final String name = "AWT-EventQueue-" + nextThreadNum();
+    private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement();
 
     private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue");
 
@@ -1030,7 +1026,7 @@
         }
     }
 
-    final boolean detachDispatchThread(EventDispatchThread edt) {
+    final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) {
         /*
          * This synchronized block is to secure that the event dispatch
          * thread won't die in the middle of posting a new event to the
@@ -1049,7 +1045,7 @@
                  * Fix for 4648733. Check both the associated java event
                  * queue and the PostEventQueue.
                  */
-                if ((peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
+                if (!forceDetach && (peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
                     return false;
                 }
                 dispatchThread = null;
diff --git a/jdk/src/share/classes/java/awt/GraphicsEnvironment.java b/jdk/src/share/classes/java/awt/GraphicsEnvironment.java
index cf3f1e5..2ca335a 100644
--- a/jdk/src/share/classes/java/awt/GraphicsEnvironment.java
+++ b/jdk/src/share/classes/java/awt/GraphicsEnvironment.java
@@ -170,10 +170,20 @@
                         if (System.getProperty("javaplugin.version") != null) {
                             headless = defaultHeadless = Boolean.FALSE;
                         } else {
-                            String osName = System.getProperty("os.name");
-                            headless = defaultHeadless =
-                                Boolean.valueOf(("Linux".equals(osName) || "SunOS".equals(osName)) &&
-                                                (System.getenv("DISPLAY") == null));
+                            if ("sun.awt.HeadlessGraphicsEnvironment".equals(
+                                    System.getProperty("java.awt.graphicsenv")))
+                            {
+                                headless = defaultHeadless = Boolean.TRUE;
+                            } else {
+                                String osName = System.getProperty("os.name");
+                                headless = defaultHeadless =
+                                    Boolean.valueOf(("Linux".equals(osName) ||
+                                                     "SunOS".equals(osName) ||
+                                                     "FreeBSD".equals(osName) ||
+                                                     "NetBSD".equals(osName) ||
+                                                     "OpenBSD".equals(osName)) &&
+                                                     (System.getenv("DISPLAY") == null));
+                            }
                         }
                     } else if (nm.equals("true")) {
                         headless = Boolean.TRUE;
diff --git a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java
index 5438064..3ccf5b7 100644
--- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java
+++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java
@@ -145,6 +145,9 @@
                 public void setMostRecentFocusOwner(Window window, Component component) {
                     KeyboardFocusManager.setMostRecentFocusOwner(window, component);
                 }
+                public KeyboardFocusManager getCurrentKeyboardFocusManager(AppContext ctx) {
+                    return KeyboardFocusManager.getCurrentKeyboardFocusManager(ctx);
+                }
             }
         );
     }
diff --git a/jdk/src/share/classes/java/lang/ClassLoader.java b/jdk/src/share/classes/java/lang/ClassLoader.java
index f8588f5..54eb8fb 100644
--- a/jdk/src/share/classes/java/lang/ClassLoader.java
+++ b/jdk/src/share/classes/java/lang/ClassLoader.java
@@ -1846,6 +1846,12 @@
             if (loadLibrary0(fromClass, libfile)) {
                 return;
             }
+            for (String libname : System.mapLegacyLibraryNames(name)) {
+                libfile = new File(sys_paths[i], libname);
+                if (loadLibrary0(fromClass, libfile)) {
+                    return;
+                }
+            }
         }
         if (loader != null) {
             for (int i = 0 ; i < usr_paths.length ; i++) {
@@ -1854,6 +1860,12 @@
                 if (loadLibrary0(fromClass, libfile)) {
                     return;
                 }
+                for (String libname : System.mapLegacyLibraryNames(name)) {
+                    libfile = new File(usr_paths[i], libname);
+                    if (loadLibrary0(fromClass, libfile)) {
+                        return;
+                    }
+                }
             }
         }
         // Oops, it failed
diff --git a/jdk/src/share/classes/java/lang/System.java b/jdk/src/share/classes/java/lang/System.java
index e4adf8d..332e311 100644
--- a/jdk/src/share/classes/java/lang/System.java
+++ b/jdk/src/share/classes/java/lang/System.java
@@ -1098,6 +1098,26 @@
      */
     public static native String mapLibraryName(String libname);
 
+    static boolean systemUsesJnilib;
+    /**
+     * On platforms which have a different legacy name for libraries
+     * (such that mapLibraryName is inappropriate, because it can't tell
+     * which to use), returns an array of possible alternate library names.
+     *
+     * This exists entirely for the benefit of ClassLoader and should not
+     * be used directly.
+     */
+    static String []mapLegacyLibraryNames(String libname) {
+        if (!systemUsesJnilib)
+            return new String[0];
+
+        String mappedName = mapLibraryName(libname);
+        String names[] = new String[1];
+        names[0] = mappedName.substring(0, mappedName.lastIndexOf("dylib")) + "jnilib";
+
+        return names;
+    }
+
     /**
      * Initialize the system class.  Called after thread initialization.
      */
@@ -1163,6 +1183,12 @@
         Thread current = Thread.currentThread();
         current.getThreadGroup().add(current);
 
+        // Cache systemUsesJnilib, which needs to be set after initProperties
+        // is called. This is done to avoid slowing down mapLegacyLibraryNames
+        // for the uncommon case of it having to return something.
+        String osName = System.getProperty("os.name");
+        systemUsesJnilib = osName.startsWith("Mac OS X") || osName.startsWith("Darwin");
+
         // register shared secrets
         setJavaLangAccess();
     }
diff --git a/jdk/src/share/classes/java/lang/Thread.java b/jdk/src/share/classes/java/lang/Thread.java
index 45393eb..cb166c8 100644
--- a/jdk/src/share/classes/java/lang/Thread.java
+++ b/jdk/src/share/classes/java/lang/Thread.java
@@ -2032,4 +2032,5 @@
     private native void suspend0();
     private native void resume0();
     private native void interrupt0();
+    private native void setNativeName(String name);
 }
diff --git a/jdk/src/share/classes/java/net/MulticastSocket.java b/jdk/src/share/classes/java/net/MulticastSocket.java
index 4ec3a2d..292d874 100644
--- a/jdk/src/share/classes/java/net/MulticastSocket.java
+++ b/jdk/src/share/classes/java/net/MulticastSocket.java
@@ -164,6 +164,15 @@
         if (bindaddr != null) {
             bind(bindaddr);
         }
+        /**
+         * required for some platforms where it's not possible to join
+         * a group without setting the interface first.
+         */
+        NetworkInterface defaultInterface = NetworkInterface.getDefault();
+
+        if (defaultInterface != null) {
+            setNetworkInterface(defaultInterface);
+        }
     }
 
     /**
diff --git a/jdk/src/share/classes/java/net/NetworkInterface.java b/jdk/src/share/classes/java/net/NetworkInterface.java
index 229f113..6314d15 100644
--- a/jdk/src/share/classes/java/net/NetworkInterface.java
+++ b/jdk/src/share/classes/java/net/NetworkInterface.java
@@ -49,10 +49,18 @@
     private NetworkInterface childs[];
     private NetworkInterface parent = null;
     private boolean virtual = false;
+    private static final NetworkInterface defaultInterface;
+    private static final int defaultIndex; /* index of defaultInterface */
 
     static {
         AccessController.doPrivileged(new LoadLibraryAction("net"));
         init();
+        defaultInterface = DefaultInterface.getDefault();
+        if (defaultInterface != null) {
+            defaultIndex = defaultInterface.getIndex();
+        } else {
+            defaultIndex = 0;
+        }
     }
 
     /**
@@ -551,4 +559,13 @@
     }
 
     private static native void init();
+
+    /**
+     * Returns the default network interface of this system
+     *
+     * @return the default interface
+     */
+    static NetworkInterface getDefault() {
+        return defaultInterface;
+    }
 }
diff --git a/jdk/src/share/classes/java/security/Policy.java b/jdk/src/share/classes/java/security/Policy.java
index 5a029a3..42d4559 100644
--- a/jdk/src/share/classes/java/security/Policy.java
+++ b/jdk/src/share/classes/java/security/Policy.java
@@ -37,6 +37,7 @@
 import java.util.StringTokenizer;
 import java.util.Vector;
 import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
 import sun.security.jca.GetInstance;
 import sun.security.util.Debug;
 import sun.security.util.SecurityConstants;
@@ -69,8 +70,8 @@
  * with a standard type.  The default policy type is "JavaPolicy".
  *
  * <p> Once a Policy instance has been installed (either by default, or by
- * calling <code>setPolicy</code>),
- * the Java runtime invokes its <code>implies</code> when it needs to
+ * calling <code>setPolicy</code>), the Java runtime invokes its
+ * <code>implies</code> method when it needs to
  * determine whether executing code (encapsulated in a ProtectionDomain)
  * can perform SecurityManager-protected operations.  How a Policy object
  * retrieves its policy data is up to the Policy implementation itself.
@@ -103,18 +104,33 @@
     public static final PermissionCollection UNSUPPORTED_EMPTY_COLLECTION =
                         new UnsupportedEmptyCollection();
 
-    /** the system-wide policy. */
-    private static Policy policy; // package private for AccessControlContext
+    // Information about the system-wide policy.
+    private static class PolicyInfo {
+        // the system-wide policy
+        final Policy policy;
+        // a flag indicating if the system-wide policy has been initialized
+        final boolean initialized;
+
+        PolicyInfo(Policy policy, boolean initialized) {
+            this.policy = policy;
+            this.initialized = initialized;
+        }
+    }
+
+    // PolicyInfo is stored in an AtomicReference
+    private static AtomicReference<PolicyInfo> policy =
+        new AtomicReference<>(new PolicyInfo(null, false));
 
     private static final Debug debug = Debug.getInstance("policy");
 
     // Cache mapping ProtectionDomain.Key to PermissionCollection
     private WeakHashMap<ProtectionDomain.Key, PermissionCollection> pdMapping;
 
-    /** package private for AccessControlContext */
+    /** package private for AccessControlContext and ProtectionDomain */
     static boolean isSet()
     {
-        return policy != null;
+        PolicyInfo pi = policy.get();
+        return pi.policy != null && pi.initialized == true;
     }
 
     private static void checkPermission(String type) {
@@ -152,80 +168,92 @@
 
     /**
      * Returns the installed Policy object, skipping the security check.
-     * Used by SecureClassLoader and getPolicy.
+     * Used by ProtectionDomain and getPolicy.
      *
      * @return the installed Policy.
-     *
      */
-    static synchronized Policy getPolicyNoCheck()
+    static Policy getPolicyNoCheck()
     {
-        if (policy == null) {
-            String policy_class = null;
-            policy_class = AccessController.doPrivileged(
-                new PrivilegedAction<String>() {
-                    public String run() {
-                        return Security.getProperty("policy.provider");
-                    }
-                });
-            if (policy_class == null) {
-                policy_class = "sun.security.provider.PolicyFile";
-            }
-
-            try {
-                policy = (Policy)
-                    Class.forName(policy_class).newInstance();
-            } catch (Exception e) {
-                /*
-                 * The policy_class seems to be an extension
-                 * so we have to bootstrap loading it via a policy
-                 * provider that is on the bootclasspath
-                 * If it loads then shift gears to using the configured
-                 * provider.
-                 */
-
-                // install the bootstrap provider to avoid recursion
-                policy = new sun.security.provider.PolicyFile();
-
-                final String pc = policy_class;
-                Policy p = AccessController.doPrivileged(
-                    new PrivilegedAction<Policy>() {
-                        public Policy run() {
-                            try {
-                                ClassLoader cl =
-                                        ClassLoader.getSystemClassLoader();
-                                // we want the extension loader
-                                ClassLoader extcl = null;
-                                while (cl != null) {
-                                    extcl = cl;
-                                    cl = cl.getParent();
-                                }
-                                return (extcl != null ? (Policy)Class.forName(
-                                        pc, true, extcl).newInstance() : null);
-                            } catch (Exception e) {
-                                if (debug != null) {
-                                    debug.println("policy provider " +
-                                                pc +
-                                                " not available");
-                                    e.printStackTrace();
-                                }
-                                return null;
-                            }
+        PolicyInfo pi = policy.get();
+        // Use double-check idiom to avoid locking if system-wide policy is
+        // already initialized
+        if (pi.initialized == false || pi.policy == null) {
+            synchronized (Policy.class) {
+                PolicyInfo pinfo = policy.get();
+                if (pinfo.policy == null) {
+                    String policy_class = AccessController.doPrivileged(
+                        new PrivilegedAction<String>() {
+                        public String run() {
+                            return Security.getProperty("policy.provider");
                         }
                     });
-                /*
-                 * if it loaded install it as the policy provider. Otherwise
-                 * continue to use the system default implementation
-                 */
-                if (p != null) {
-                    policy = p;
-                } else {
-                    if (debug != null) {
-                        debug.println("using sun.security.provider.PolicyFile");
+                    if (policy_class == null) {
+                        policy_class = "sun.security.provider.PolicyFile";
                     }
+
+                    try {
+                        pinfo = new PolicyInfo(
+                            (Policy) Class.forName(policy_class).newInstance(),
+                            true);
+                    } catch (Exception e) {
+                        /*
+                         * The policy_class seems to be an extension
+                         * so we have to bootstrap loading it via a policy
+                         * provider that is on the bootclasspath.
+                         * If it loads then shift gears to using the configured
+                         * provider.
+                         */
+
+                        // install the bootstrap provider to avoid recursion
+                        Policy polFile = new sun.security.provider.PolicyFile();
+                        pinfo = new PolicyInfo(polFile, false);
+                        policy.set(pinfo);
+
+                        final String pc = policy_class;
+                        Policy pol = AccessController.doPrivileged(
+                            new PrivilegedAction<Policy>() {
+                            public Policy run() {
+                                try {
+                                    ClassLoader cl =
+                                            ClassLoader.getSystemClassLoader();
+                                    // we want the extension loader
+                                    ClassLoader extcl = null;
+                                    while (cl != null) {
+                                        extcl = cl;
+                                        cl = cl.getParent();
+                                    }
+                                    return (extcl != null ? (Policy)Class.forName(
+                                            pc, true, extcl).newInstance() : null);
+                                } catch (Exception e) {
+                                    if (debug != null) {
+                                        debug.println("policy provider " +
+                                                    pc +
+                                                    " not available");
+                                        e.printStackTrace();
+                                    }
+                                    return null;
+                                }
+                            }
+                        });
+                        /*
+                         * if it loaded install it as the policy provider. Otherwise
+                         * continue to use the system default implementation
+                         */
+                        if (pol != null) {
+                            pinfo = new PolicyInfo(pol, true);
+                        } else {
+                            if (debug != null) {
+                                debug.println("using sun.security.provider.PolicyFile");
+                            }
+                            pinfo = new PolicyInfo(polFile, true);
+                        }
+                    }
+                    policy.set(pinfo);
                 }
+                return pinfo.policy;
             }
         }
-        return policy;
+        return pi.policy;
     }
 
     /**
@@ -254,7 +282,7 @@
             initPolicy(p);
         }
         synchronized (Policy.class) {
-            Policy.policy = p;
+            policy.set(new PolicyInfo(p, p != null));
         }
     }
 
@@ -301,14 +329,14 @@
         PermissionCollection policyPerms = null;
         synchronized (p) {
             if (p.pdMapping == null) {
-                p.pdMapping =
-                    new WeakHashMap<ProtectionDomain.Key, PermissionCollection>();
+                p.pdMapping = new WeakHashMap<>();
            }
         }
 
         if (policyDomain.getCodeSource() != null) {
-            if (Policy.isSet()) {
-                policyPerms = policy.getPermissions(policyDomain);
+            Policy pol = policy.get().policy;
+            if (pol != null) {
+                policyPerms = pol.getPermissions(policyDomain);
             }
 
             if (policyPerms == null) { // assume it has all
@@ -443,7 +471,7 @@
                                                         type,
                                                         params);
         } catch (NoSuchAlgorithmException nsae) {
-            return handleException (nsae);
+            return handleException(nsae);
         }
     }
 
@@ -503,7 +531,7 @@
                                                         type,
                                                         params);
         } catch (NoSuchAlgorithmException nsae) {
-            return handleException (nsae);
+            return handleException(nsae);
         }
     }
 
@@ -815,7 +843,7 @@
          *
          * @param permission the Permission object to compare.
          *
-         * @return true if "permission" is implied by the  permissions in
+         * @return true if "permission" is implied by the permissions in
          * the collection, false if not.
          */
         @Override public boolean implies(Permission permission) {
diff --git a/jdk/src/share/classes/java/util/XMLUtils.java b/jdk/src/share/classes/java/util/XMLUtils.java
index 1666c63..7859367 100644
--- a/jdk/src/share/classes/java/util/XMLUtils.java
+++ b/jdk/src/share/classes/java/util/XMLUtils.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -75,7 +75,7 @@
         } catch (SAXException saxe) {
             throw new InvalidPropertiesFormatException(saxe);
         }
-        Element propertiesElement = (Element)doc.getChildNodes().item(1);
+        Element propertiesElement = doc.getDocumentElement();
         String xmlVersion = propertiesElement.getAttribute("version");
         if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
             throw new InvalidPropertiesFormatException(
diff --git a/jdk/src/share/classes/java/util/prefs/Preferences.java b/jdk/src/share/classes/java/util/prefs/Preferences.java
index 9446183..8252ec9 100644
--- a/jdk/src/share/classes/java/util/prefs/Preferences.java
+++ b/jdk/src/share/classes/java/util/prefs/Preferences.java
@@ -291,10 +291,15 @@
         }
 
         // 3. Use platform-specific system-wide default
-        String platformFactory =
-            System.getProperty("os.name").startsWith("Windows")
-            ? "java.util.prefs.WindowsPreferencesFactory"
-            : "java.util.prefs.FileSystemPreferencesFactory";
+        String osName = System.getProperty("os.name");
+        String platformFactory;
+        if (osName.startsWith("Windows")) {
+            platformFactory = "java.util.prefs.WindowsPreferencesFactory";
+        } else if (osName.startsWith("Mac OS X")) {
+            platformFactory = "java.util.prefs.MacOSXPreferencesFactory";
+        } else {
+            platformFactory = "java.util.prefs.FileSystemPreferencesFactory";
+        }
         try {
             return (PreferencesFactory)
                 Class.forName(platformFactory, false, null).newInstance();
diff --git a/jdk/src/share/classes/javax/accessibility/AccessibleContext.java b/jdk/src/share/classes/javax/accessibility/AccessibleContext.java
index 5741ec9..32a80b6 100644
--- a/jdk/src/share/classes/javax/accessibility/AccessibleContext.java
+++ b/jdk/src/share/classes/javax/accessibility/AccessibleContext.java
@@ -394,6 +394,8 @@
     private AccessibleRelationSet relationSet
         = new AccessibleRelationSet();
 
+    private Object nativeAXResource;
+
     /**
      * Gets the accessibleName property of this object.  The accessibleName
      * property of an object is a localized String that designates the purpose
diff --git a/jdk/src/share/classes/javax/swing/JTree.java b/jdk/src/share/classes/javax/swing/JTree.java
index 13a4056..c5ca4b6 100644
--- a/jdk/src/share/classes/javax/swing/JTree.java
+++ b/jdk/src/share/classes/javax/swing/JTree.java
@@ -1838,7 +1838,9 @@
      *         nodes, or <code>null</code> if nothing is currently selected
      */
     public TreePath[] getSelectionPaths() {
-        return getSelectionModel().getSelectionPaths();
+        TreePath[] selectionPaths = getSelectionModel().getSelectionPaths();
+
+        return (selectionPaths != null && selectionPaths.length > 0) ? selectionPaths : null;
     }
 
     /**
diff --git a/jdk/src/share/classes/javax/swing/UIManager.java b/jdk/src/share/classes/javax/swing/UIManager.java
index ce8e6ce..c3199d5 100644
--- a/jdk/src/share/classes/javax/swing/UIManager.java
+++ b/jdk/src/share/classes/javax/swing/UIManager.java
@@ -379,6 +379,9 @@
                  "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
             }
         }
+        else if (osType == OSInfo.OSType.MACOSX) {
+            iLAFs.add(new LookAndFeelInfo("Mac OS X", "com.apple.laf.AquaLookAndFeel"));
+        }
         else {
             // GTK is not shipped on Windows.
             iLAFs.add(new LookAndFeelInfo("GTK+",
@@ -608,6 +611,12 @@
                 // May be set on Linux and Solaris boxs.
                 return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
             }
+            if (osType == OSInfo.OSType.MACOSX) {
+                if (toolkit.getClass() .getName()
+                                       .equals("sun.lwawt.macosx.LWCToolkit")) {
+                    return "com.apple.laf.AquaLookAndFeel";
+                }
+            }
             if (osType == OSInfo.OSType.SOLARIS) {
                 return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
             }
@@ -1214,6 +1223,11 @@
             java.security.AccessController.doPrivileged(
                 new java.security.PrivilegedAction<Object>() {
                 public Object run() {
+                    OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
+                    if (osType == OSInfo.OSType.MACOSX) {
+                        props.put(defaultLAFKey, getSystemLookAndFeelClassName());
+                    }
+
                     try {
                         File file = new File(makeSwingPropertiesFilename());
 
diff --git a/jdk/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java b/jdk/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java
index 40e79e8..940e7cf 100644
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java
@@ -139,9 +139,9 @@
                                JComponent.WHEN_IN_FOCUSED_WINDOW, map);
             }
             map.clear();
-            map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, false),
+            map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), false),
                     "pressed");
-            map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, true),
+            map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true),
                     "released");
             map.put(KeyStroke.getKeyStroke(m, 0, true), "released");
         }
diff --git a/jdk/src/share/classes/javax/swing/plaf/basic/BasicLabelUI.java b/jdk/src/share/classes/javax/swing/plaf/basic/BasicLabelUI.java
index c735fe8..4bbb2eb 100644
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicLabelUI.java
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicLabelUI.java
@@ -363,8 +363,7 @@
                                 JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
             }
             inputMap.clear();
-            inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.ALT_MASK,
-                                              false), "press");
+            inputMap.put(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), false), "press");
         }
         else {
             InputMap inputMap = SwingUtilities.getUIInputMap
@@ -454,7 +453,7 @@
                     SwingUtilities.replaceUIInputMap(label, JComponent.WHEN_FOCUSED, inputMap);
                 }
                 int dka = label.getDisplayedMnemonic();
-                inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.ALT_MASK, true), RELEASE);
+                inputMap.put(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true), RELEASE);
                 // Need this when the sticky keys are enabled
                 inputMap.put(KeyStroke.getKeyStroke(dka, 0, true), RELEASE);
                 // Need this if ALT is released before the accelerator
@@ -470,7 +469,7 @@
                 if (inputMap != null) {
                     // inputMap should never be null.
                     int dka = label.getDisplayedMnemonic();
-                    inputMap.remove(KeyStroke.getKeyStroke(dka, ActionEvent.ALT_MASK, true));
+                    inputMap.remove(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true));
                     inputMap.remove(KeyStroke.getKeyStroke(dka, 0, true));
                     inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true));
                 }
diff --git a/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java b/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java
index 207284b..437704a 100644
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java
@@ -47,6 +47,7 @@
 import javax.sound.sampled.*;
 
 import sun.awt.AppContext;
+import sun.awt.SunToolkit;
 
 import sun.swing.SwingLazyValue;
 import sun.swing.SwingUtilities2;
@@ -1910,6 +1911,15 @@
         table.putDefaults(defaults);
     }
 
+    static int getFocusAcceleratorKeyMask() {
+        Toolkit tk = Toolkit.getDefaultToolkit();
+        if (tk instanceof SunToolkit) {
+            return ((SunToolkit)tk).getFocusAcceleratorKeyMask();
+        }
+        return ActionEvent.ALT_MASK;
+    }
+
+
 
     /**
      * Returns the ui that is of type <code>klass</code>, or null if
diff --git a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java
index af90179..53e50e8 100644
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java
@@ -545,7 +545,7 @@
         if (mnemonicToIndexMap == null) {
             initMnemonics();
         }
-        mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, Event.ALT_MASK),
+        mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, BasicLookAndFeel.getFocusAcceleratorKeyMask()),
                              "setSelectedIndex");
         mnemonicToIndexMap.put(Integer.valueOf(mnemonic), Integer.valueOf(index));
     }
diff --git a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java
index ba87d53..3cfedb8 100644
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java
@@ -497,9 +497,7 @@
             if (km != null) {
                 km.clear();
                 if (accelerator != '\0') {
-                    km.put(KeyStroke.getKeyStroke(accelerator,
-                                                  ActionEvent.ALT_MASK),
-                           "requestFocus");
+                    km.put(KeyStroke.getKeyStroke(accelerator, BasicLookAndFeel.getFocusAcceleratorKeyMask()), "requestFocus");
                 }
             }
         }
diff --git a/jdk/src/share/classes/sun/awt/AWTAccessor.java b/jdk/src/share/classes/sun/awt/AWTAccessor.java
index d7f70ce..6fb1201 100644
--- a/jdk/src/share/classes/sun/awt/AWTAccessor.java
+++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java
@@ -26,6 +26,7 @@
 package sun.awt;
 
 import java.awt.*;
+import java.awt.KeyboardFocusManager;
 import java.awt.event.InputEvent;
 import java.awt.geom.Point2D;
 import java.awt.image.BufferedImage;
@@ -399,6 +400,11 @@
          * Sets the most recent focus owner in the window.
          */
         void setMostRecentFocusOwner(Window window, Component component);
+
+        /*
+         * Returns current KFM of the specified AppContext.
+         */
+        KeyboardFocusManager getCurrentKeyboardFocusManager(AppContext ctx);
     }
 
     /*
diff --git a/jdk/src/share/classes/sun/awt/OSInfo.java b/jdk/src/share/classes/sun/awt/OSInfo.java
index c8cce59..58dd6cc 100644
--- a/jdk/src/share/classes/sun/awt/OSInfo.java
+++ b/jdk/src/share/classes/sun/awt/OSInfo.java
@@ -39,6 +39,7 @@
         WINDOWS,
         LINUX,
         SOLARIS,
+        MACOSX,
         UNKNOWN
     }
 
@@ -100,6 +101,10 @@
                 return SOLARIS;
             }
 
+            if (osName.startsWith("Mac OS X")) {
+                return MACOSX;
+            }
+
             // determine another OS here
         }
 
diff --git a/jdk/src/share/classes/sun/awt/SunToolkit.java b/jdk/src/share/classes/sun/awt/SunToolkit.java
index e3e6ff3..eb877d4 100644
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java
@@ -35,6 +35,7 @@
 import java.awt.image.*;
 import java.awt.TrayIcon;
 import java.awt.SystemTray;
+import java.awt.event.InputEvent;
 import java.net.URL;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -591,7 +592,7 @@
         postEvent(targetToAppContext(e.getSource()), pe);
     }
 
-    private static final Lock flushLock = new ReentrantLock();
+    protected static final Lock flushLock = new ReentrantLock();
     private static boolean isFlushingPendingEvents = false;
 
     /*
@@ -1127,6 +1128,13 @@
     }
 
     /**
+     * Returns key modifiers used by Swing to set up a focus accelerator key stroke.
+     */
+    public int getFocusAcceleratorKeyMask() {
+        return InputEvent.ALT_MASK;
+    }
+
+    /**
      * Returns a new input method window, with behavior as specified in
      * {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}.
      * If the inputContext is not null, the window should return it from its
diff --git a/jdk/src/share/classes/sun/awt/image/BufImgSurfaceData.java b/jdk/src/share/classes/sun/awt/image/BufImgSurfaceData.java
index 239f883..4c3d216 100644
--- a/jdk/src/share/classes/sun/awt/image/BufImgSurfaceData.java
+++ b/jdk/src/share/classes/sun/awt/image/BufImgSurfaceData.java
@@ -39,6 +39,7 @@
 import sun.java2d.SurfaceData;
 import sun.java2d.SunGraphics2D;
 import sun.java2d.StateTrackable;
+import sun.java2d.StateTrackable.*;
 import sun.java2d.StateTracker;
 import sun.java2d.loops.SurfaceType;
 import sun.java2d.loops.CompositeType;
@@ -355,6 +356,10 @@
         this.bufImg = bufImg;
     }
 
+    protected BufImgSurfaceData(SurfaceType surfaceType, ColorModel cm) {
+        super(surfaceType, cm);
+    }
+
     public void initSolidLoops() {
         this.solidloops = getSolidLoops(getSurfaceType());
     }
diff --git a/jdk/src/share/classes/sun/font/FileFont.java b/jdk/src/share/classes/sun/font/FileFont.java
index adce6d9..0a9ce92 100644
--- a/jdk/src/share/classes/sun/font/FileFont.java
+++ b/jdk/src/share/classes/sun/font/FileFont.java
@@ -121,6 +121,13 @@
                          new CreatedFontFileDisposerRecord(file, tracker));
     }
 
+    // MACOSX begin -- Make this static so that we can pass in CFont
+    static void setFileToRemove(Object font, File file, CreatedFontTracker tracker) {
+        Disposer.addObjectRecord(font,
+                         new CreatedFontFileDisposerRecord(file, tracker));
+    }
+    // MACOSX - end
+
     /* This is called when a font scaler is determined to
      * be unusable (ie bad).
      * We want to replace current scaler with NullFontScaler, so
diff --git a/jdk/src/share/classes/sun/font/FontManagerFactory.java b/jdk/src/share/classes/sun/font/FontManagerFactory.java
index b9f4a6f..cd54861 100644
--- a/jdk/src/share/classes/sun/font/FontManagerFactory.java
+++ b/jdk/src/share/classes/sun/font/FontManagerFactory.java
@@ -51,10 +51,13 @@
 
     private static final String DEFAULT_CLASS;
     static {
-        if (FontUtilities.isWindows)
+        if (FontUtilities.isWindows) {
             DEFAULT_CLASS = "sun.awt.Win32FontManager";
-        else
+        } else if (FontUtilities.isMacOSX) {
+            DEFAULT_CLASS = "sun.font.CFontManager";
+            } else {
             DEFAULT_CLASS = "sun.awt.X11FontManager";
+            }
     }
 
     /**
diff --git a/jdk/src/share/classes/sun/font/FontUtilities.java b/jdk/src/share/classes/sun/font/FontUtilities.java
index 7c70ff2..fd1adcc 100644
--- a/jdk/src/share/classes/sun/font/FontUtilities.java
+++ b/jdk/src/share/classes/sun/font/FontUtilities.java
@@ -48,6 +48,8 @@
 
     public static boolean isLinux;
 
+    public static boolean isMacOSX;
+
     public static boolean isSolaris8;
 
     public static boolean isSolaris9;
@@ -76,6 +78,8 @@
 
                 isLinux = osName.startsWith("Linux");
 
+                isMacOSX = osName.startsWith("Mac OS X"); // TODO: MacOSX
+
                 String t2kStr = System.getProperty("sun.java2d.font.scaler");
                 if (t2kStr != null) {
                     useT2K = "t2k".equals(t2kStr);
@@ -407,12 +411,12 @@
         }
 
         FontManager fm = FontManagerFactory.getInstance();
-        CompositeFont dialog2D =
-          (CompositeFont) fm.findFont2D("dialog", font.getStyle(),
-                                        FontManager.NO_FALLBACK);
-        if (dialog2D == null) { /* shouldn't happen */
+        Font2D dialog = fm.findFont2D("dialog", font.getStyle(), FontManager.NO_FALLBACK);
+        // Should never be null, but MACOSX fonts are not CompositeFonts
+        if (dialog == null || !(dialog instanceof CompositeFont)) {
             return fuir;
         }
+        CompositeFont dialog2D = (CompositeFont)dialog;
         PhysicalFont physicalFont = (PhysicalFont)font2D;
         ConcurrentHashMap<PhysicalFont, CompositeFont> compMap = compMapRef.get();
         if (compMap == null) { // Its been collected.
diff --git a/jdk/src/share/classes/sun/font/SunFontManager.java b/jdk/src/share/classes/sun/font/SunFontManager.java
index bd55f8b..2cabce0 100644
--- a/jdk/src/share/classes/sun/font/SunFontManager.java
+++ b/jdk/src/share/classes/sun/font/SunFontManager.java
@@ -142,9 +142,11 @@
       * The pool array stores the fonts, rather than directly referencing
       * the channels, as the font needs to do the open/close work.
       */
-     private static final int CHANNELPOOLSIZE = 20;
+     // MACOSX begin -- need to access these in subclass
+     protected static final int CHANNELPOOLSIZE = 20;
+     protected FileFont fontFileCache[] = new FileFont[CHANNELPOOLSIZE];
+     // MACOSX end
      private int lastPoolIndex = 0;
-     private FileFont fontFileCache[] = new FileFont[CHANNELPOOLSIZE];
 
     /* Need to implement a simple linked list scheme for fast
      * traversal and lookup.
@@ -168,8 +170,10 @@
      * here in that this contains the content of compositeFonts +
      * physicalFonts.
      */
-    private ConcurrentHashMap<String, Font2D>
+    // MACOSX begin -- need to access this in subclass
+    protected ConcurrentHashMap<String, Font2D>
         fullNameToFont = new ConcurrentHashMap<String, Font2D>();
+    // MACOSX end
 
     /* TrueType fonts have localised names. Support searching all
      * of these before giving up on a name.
@@ -735,7 +739,9 @@
      * If it returns null means this font was not registered and none
      * in that name is registered. The caller must find a substitute
      */
-    private PhysicalFont addToFontList(PhysicalFont f, int rank) {
+    // MACOSX begin -- need to access this in subclass
+    protected PhysicalFont addToFontList(PhysicalFont f, int rank) {
+    // MACOSX end
 
         String fontName = f.fullName;
         String familyName = f.familyName;
@@ -1233,8 +1239,8 @@
         return defaultPhysicalFont;
     }
 
-    public CompositeFont getDefaultLogicalFont(int style) {
-        return (CompositeFont)findFont2D("dialog", style, NO_FALLBACK);
+    public Font2D getDefaultLogicalFont(int style) {
+        return findFont2D("dialog", style, NO_FALLBACK);
     }
 
     /*
@@ -2435,7 +2441,9 @@
 
     protected abstract String getFontPath(boolean noType1Fonts);
 
-    private Thread fileCloser = null;
+    // MACOSX begin -- need to access this in subclass
+    protected Thread fileCloser = null;
+    // MACOSX end
     Vector<File> tmpFontFiles = null;
 
     public Font2D createFont2D(File fontFile, int fontFormat,
@@ -3350,7 +3358,9 @@
         registerFontsInDir(dirName, true, Font2D.JRE_RANK, true, false);
     }
 
-    private void registerFontsInDir(String dirName, boolean useJavaRasterizer,
+    // MACOSX begin -- need to access this in subclass
+    protected void registerFontsInDir(String dirName, boolean useJavaRasterizer,
+    // MACOSX end
                                     int fontRank,
                                     boolean defer, boolean resolveSymLinks) {
         File pathFile = new File(dirName);
@@ -3770,6 +3780,9 @@
             }
         }
 
+        // Add any native font family names here
+        addNativeFontFamilyNames(familyNames, requestedLocale);
+
         String[] retval =  new String[familyNames.size()];
         Object [] keyNames = familyNames.keySet().toArray();
         for (int i=0; i < keyNames.length; i++) {
@@ -3783,6 +3796,9 @@
         return retval;
     }
 
+    // Provides an aperture to add native font family names to the map
+    protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) { }
+
     public void register1dot0Fonts() {
         java.security.AccessController.doPrivileged(
                             new java.security.PrivilegedAction() {
diff --git a/jdk/src/share/classes/sun/java2d/SunGraphics2D.java b/jdk/src/share/classes/sun/java2d/SunGraphics2D.java
index 8d9c2ea..e62c467 100644
--- a/jdk/src/share/classes/sun/java2d/SunGraphics2D.java
+++ b/jdk/src/share/classes/sun/java2d/SunGraphics2D.java
@@ -189,7 +189,7 @@
     public int renderHint;
     public int antialiasHint;
     public int textAntialiasHint;
-    private int fractionalMetricsHint;
+    protected int fractionalMetricsHint;
 
     /* A gamma adjustment to the colour used in lcd text blitting */
     public int lcdTextContrast;
diff --git a/jdk/src/share/classes/sun/java2d/opengl/OGLBlitLoops.java b/jdk/src/share/classes/sun/java2d/opengl/OGLBlitLoops.java
index de50877..9e6113e 100644
--- a/jdk/src/share/classes/sun/java2d/opengl/OGLBlitLoops.java
+++ b/jdk/src/share/classes/sun/java2d/opengl/OGLBlitLoops.java
@@ -347,7 +347,7 @@
                 OGLBufImgOps.disableBufImgOp(rq, biop);
             }
 
-            if (rtt && (oglDst.getType() == OGLSurfaceData.WINDOW)) {
+            if (rtt && oglDst.isOnScreen()) {
                 // we only have to flush immediately when copying from a
                 // (non-texture) surface to the screen; otherwise Swing apps
                 // might appear unresponsive until the auto-flush completes
diff --git a/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java b/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java
index ca6c9a6..5e04ab6 100644
--- a/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java
+++ b/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java
@@ -650,4 +650,14 @@
             rq.unlock();
         }
     }
+
+    /**
+     * Returns true if the surface is an on-screen window surface or
+     * a FBO texture attached to an on-screen CALayer.
+     *
+     * Needed by Mac OS X port.
+     */
+    boolean isOnScreen() {
+        return getType() == WINDOW;
+    }
 }
diff --git a/jdk/src/share/classes/sun/print/PSPrinterJob.java b/jdk/src/share/classes/sun/print/PSPrinterJob.java
index 722537e..5a777d5 100644
--- a/jdk/src/share/classes/sun/print/PSPrinterJob.java
+++ b/jdk/src/share/classes/sun/print/PSPrinterJob.java
@@ -1534,7 +1534,9 @@
             pFlags |= NOSHEET;
             ncomps+=1;
         }
-       if (System.getProperty("os.name").equals("Linux")) {
+
+       String osname = System.getProperty("os.name");
+       if (osname.equals("Linux") || osname.startsWith("Mac OS X")) {
             execCmd = new String[ncomps];
             execCmd[n++] = "/usr/bin/lpr";
             if ((pFlags & PRINTER) != 0) {
diff --git a/jdk/src/share/classes/sun/print/RasterPrinterJob.java b/jdk/src/share/classes/sun/print/RasterPrinterJob.java
index deda8ea..23954ad 100644
--- a/jdk/src/share/classes/sun/print/RasterPrinterJob.java
+++ b/jdk/src/share/classes/sun/print/RasterPrinterJob.java
@@ -240,7 +240,8 @@
      * The document to be printed. It is initialized to an
      * empty (zero pages) book.
      */
-    private Pageable mDocument = new Book();
+// MacOSX - made protected so subclasses can reference it.
+    protected Pageable mDocument = new Book();
 
     /**
      * The name of the job being printed.
@@ -251,8 +252,10 @@
     /**
      * Printing cancellation flags
      */
-    private boolean performingPrinting = false;
-    private boolean userCancelled = false;
+ // MacOSX - made protected so subclasses can reference it.
+    protected boolean performingPrinting = false;
+ // MacOSX - made protected so subclasses can reference it.
+    protected boolean userCancelled = false;
 
    /**
     * Print to file permission variables.
@@ -1241,7 +1244,8 @@
      * a DocPrintJob from their service and pass a Doc representing
      * the application's printjob
      */
-    private void spoolToService(PrintService psvc,
+// MacOSX - made protected so subclasses can reference it.
+    protected void spoolToService(PrintService psvc,
                                 PrintRequestAttributeSet attributes)
         throws PrinterException {
 
@@ -1738,7 +1742,8 @@
     /* Called by cancelDoc */
     protected abstract void abortDoc();
 
-    private void cancelDoc() throws PrinterAbortException {
+// MacOSX - made protected so subclasses can reference it.
+    protected void cancelDoc() throws PrinterAbortException {
         abortDoc();
         synchronized (this) {
             userCancelled = false;
@@ -2220,7 +2225,8 @@
      *      color:  black.
      *      clip:   <as passed in>
      */
-    void initPrinterGraphics(Graphics2D g, Rectangle2D clip) {
+// MacOSX - made protected so subclasses can reference it.
+    protected void initPrinterGraphics(Graphics2D g, Rectangle2D clip) {
 
         g.setClip(clip);
         g.setPaint(Color.black);
diff --git a/jdk/src/share/classes/sun/security/jgss/krb5/AcceptSecContextToken.java b/jdk/src/share/classes/sun/security/jgss/krb5/AcceptSecContextToken.java
index c3e2273..a2ad498 100644
--- a/jdk/src/share/classes/sun/security/jgss/krb5/AcceptSecContextToken.java
+++ b/jdk/src/share/classes/sun/security/jgss/krb5/AcceptSecContextToken.java
@@ -94,7 +94,7 @@
          */
         EncryptionKey subKey = apRep.getSubKey();
         if (subKey != null) {
-            context.setKey(subKey);
+            context.setKey(Krb5Context.ACCEPTOR_SUBKEY, subKey);
             /*
             System.out.println("\n\nSub-Session key from AP-REP is: " +
                                getHexBytes(subKey.getBytes()) + "\n");
diff --git a/jdk/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java b/jdk/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java
index 8e35ef8..edd4bcf 100644
--- a/jdk/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java
+++ b/jdk/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java
@@ -74,9 +74,9 @@
 
         EncryptionKey subKey = apReq.getSubKey();
         if (subKey != null)
-            context.setKey(subKey);
+            context.setKey(Krb5Context.INITIATOR_SUBKEY, subKey);
         else
-            context.setKey(serviceTicket.getSessionKey());
+            context.setKey(Krb5Context.SESSION_KEY, serviceTicket.getSessionKey());
 
         if (!mutualRequired)
             context.resetPeerSequenceNumber(0);
@@ -117,13 +117,13 @@
 
         EncryptionKey subKey = apReq.getSubKey();
         if (subKey != null) {
-            context.setKey(subKey);
+            context.setKey(Krb5Context.INITIATOR_SUBKEY, subKey);
             /*
               System.out.println("Sub-Session key from authenticator is: " +
               getHexBytes(subKey.getBytes()) + "\n");
             */
         } else {
-            context.setKey(sessionKey);
+            context.setKey(Krb5Context.SESSION_KEY, sessionKey);
             //System.out.println("Sub-Session Key Missing in Authenticator.\n");
         }
 
diff --git a/jdk/src/share/classes/sun/security/jgss/krb5/Krb5Context.java b/jdk/src/share/classes/sun/security/jgss/krb5/Krb5Context.java
index 8570601..1de7221 100644
--- a/jdk/src/share/classes/sun/security/jgss/krb5/Krb5Context.java
+++ b/jdk/src/share/classes/sun/security/jgss/krb5/Krb5Context.java
@@ -67,6 +67,10 @@
 
     private int state = STATE_NEW;
 
+    public static final int SESSION_KEY = 0;
+    public static final int INITIATOR_SUBKEY = 1;
+    public static final int ACCEPTOR_SUBKEY = 2;
+
     /*
      * Optional features that the application can set and their default
      * values.
@@ -82,6 +86,7 @@
 
     private int mySeqNumber;
     private int peerSeqNumber;
+    private int keySrc;
     private TokenTracker peerTokenTracker;
 
     private CipherHelper cipherHelper = null;
@@ -384,12 +389,17 @@
         }
     }
 
-    final void setKey(EncryptionKey key) throws GSSException {
+    final void setKey(int keySrc, EncryptionKey key) throws GSSException {
         this.key = key;
+        this.keySrc = keySrc;
         // %%% to do: should clear old cipherHelper first
         cipherHelper = new CipherHelper(key);  // Need to use new key
     }
 
+    public final int getKeySrc() {
+        return keySrc;
+    }
+
     private final EncryptionKey getKey() {
         return key;
     }
diff --git a/jdk/src/share/classes/sun/security/jgss/krb5/MessageToken_v2.java b/jdk/src/share/classes/sun/security/jgss/krb5/MessageToken_v2.java
index d76a58b..509773d 100644
--- a/jdk/src/share/classes/sun/security/jgss/krb5/MessageToken_v2.java
+++ b/jdk/src/share/classes/sun/security/jgss/krb5/MessageToken_v2.java
@@ -141,6 +141,7 @@
     // Context properties
     private boolean confState = true;
     private boolean initiator = true;
+    private boolean have_acceptor_subkey = false;
 
     /* cipher instance used by the corresponding GSSContext */
     CipherHelper cipherHelper = null;
@@ -233,7 +234,6 @@
             }
 
             if (tokenId == Krb5Token.WRAP_ID_v2) {
-                // Does non-confidential data needs a rotate?
                 rotate();
             }
 
@@ -312,8 +312,7 @@
         }
 
         // Create a new gss token header as defined in RFC 4121
-        tokenHeader = new MessageTokenHeader(tokenId,
-                                prop.getPrivacy(), true);
+        tokenHeader = new MessageTokenHeader(tokenId, prop.getPrivacy());
         // debug("\n\t Message Header = " +
         // getHexBytes(tokenHeader.getBytes(), tokenHeader.getBytes().length));
 
@@ -421,10 +420,12 @@
         int conf_flag = tokenHeaderBytes[TOKEN_FLAG_POS] &
                                 FLAG_WRAP_CONFIDENTIAL;
 
-        // clear EC in token header for checksum calculation
+        // clear EC and RRC in token header for checksum calculation
         if ((conf_flag == 0) && (tokenId == WRAP_ID_v2)) {
             tokenHeaderBytes[4] = 0;
             tokenHeaderBytes[5] = 0;
+            tokenHeaderBytes[6] = 0;
+            tokenHeaderBytes[7] = 0;
         }
         return cipherHelper.calculateChecksum(tokenHeaderBytes, data,
                                                 offset, len, key_usage);
@@ -460,6 +461,8 @@
 
         this.initiator = context.isInitiator();
 
+        this.have_acceptor_subkey = context.getKeySrc() == Krb5Context.ACCEPTOR_SUBKEY;
+
         this.cipherHelper = context.getCipherHelper(null);
         //    debug("In MessageToken.Cons");
     }
@@ -500,8 +503,7 @@
          private byte[] bytes = new byte[TOKEN_HEADER_SIZE];
 
          // Writes a new token header
-         public MessageTokenHeader(int tokenId, boolean conf,
-                boolean have_acceptor_subkey) throws GSSException {
+         public MessageTokenHeader(int tokenId, boolean conf) throws GSSException {
 
             this.tokenId = tokenId;
 
diff --git a/jdk/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java b/jdk/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java
index f9c36b2..ffe98b4 100644
--- a/jdk/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java
+++ b/jdk/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java
@@ -89,6 +89,10 @@
                                     "libgssapi_krb5.so",
                                     "libgssapi_krb5.so.2",
                                 };
+                            } else if (osname.startsWith("Mac OS X")) {
+                                gssLibs = new String[]{
+                                    "/usr/lib/sasl2/libgssapiv2.2.so",
+                                };
                             }
                         } else {
                             gssLibs = new String[]{ defaultLib };
diff --git a/jdk/src/share/classes/sun/security/krb5/Config.java b/jdk/src/share/classes/sun/security/krb5/Config.java
index 2ec4e12..8766376 100644
--- a/jdk/src/share/classes/sun/security/krb5/Config.java
+++ b/jdk/src/share/classes/sun/security/krb5/Config.java
@@ -114,6 +114,26 @@
     }
 
 
+    private static boolean isMacosLionOrBetter() {
+        // split the "10.x.y" version number
+        String osVersion = System.getProperty("os.version");
+        String[] fragments = osVersion.split("\\.");
+
+        // sanity check the "10." part of the version
+        if (!fragments[0].equals("10")) return false;
+        if (fragments.length < 2) return false;
+
+        // check if Mac OS X 10.7(.y)
+        try {
+            int minorVers = Integer.parseInt(fragments[1]);
+            if (minorVers >= 7) return true;
+        } catch (NumberFormatException e) {
+            // was not an integer
+        }
+
+        return false;
+    }
+
     /**
      * Private constructor - can not be instantiated externally.
      */
@@ -147,7 +167,11 @@
         try {
             Vector<String> configFile;
             configFile = loadConfigFile();
-            stanzaTable = parseStanzaTable(configFile);
+            if (configFile == null && isMacosLionOrBetter()) {
+                stanzaTable = SCDynamicStoreConfig.getConfig();
+            } else {
+                stanzaTable = parseStanzaTable(configFile);
+            }
         } catch (IOException ioe) {
             // No krb5.conf, no problem. We'll use DNS or system property etc.
         }
@@ -705,6 +729,9 @@
                     }
                 } else if (osname.startsWith("SunOS")) {
                     name =  "/etc/krb5/krb5.conf";
+                } else if (osname.startsWith("Mac")) {
+                    if (isMacosLionOrBetter()) return "";
+                    name = findMacosConfigFile();
                 } else {
                     name =  "/etc/krb5.conf";
                 }
@@ -716,6 +743,30 @@
         return name;
     }
 
+    private String getProperty(String property) {
+        return (String)java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction(property));
+    }
+
+    private String findMacosConfigFile() {
+        String userHome = getProperty("user.home");
+        final String PREF_FILE = "/Library/Preferences/edu.mit.Kerberos";
+        String userPrefs=userHome + PREF_FILE;
+
+        if (fileExists(userPrefs)) {
+            return userPrefs;
+        }
+
+        if (fileExists(PREF_FILE)) {
+            return PREF_FILE;
+        }
+
+        if (fileExists("/etc/krb5.conf")) {
+            return "/etc/krb5.conf";
+        }
+
+        return "";
+    }
+
     private static String trimmed(String s) {
         s = s.trim();
         if (s.charAt(0) == '"' && s.charAt(s.length()-1) == '"' ||
diff --git a/jdk/src/share/classes/sun/security/krb5/KrbAsReqBuilder.java b/jdk/src/share/classes/sun/security/krb5/KrbAsReqBuilder.java
index 3426d8b..23b4dd8 100644
--- a/jdk/src/share/classes/sun/security/krb5/KrbAsReqBuilder.java
+++ b/jdk/src/share/classes/sun/security/krb5/KrbAsReqBuilder.java
@@ -144,15 +144,18 @@
 
     /**
      * Retrieves an array of secret keys for the client. This is used when
-     * the client supplies password but need keys to act as an acceptor
-     * (in JAAS words, isInitiator=true and storeKey=true)
+     * the client supplies password but need keys to act as an acceptor. For
+     * an initiator, it must be called after AS-REQ is performed (state is OK).
+     * For an acceptor, it can be called when this KrbAsReqBuilder object is
+     * constructed (state is INIT).
+     * @param isInitiator if the caller is an initiator
      * @return generated keys from password. PA-DATA from server might be used.
      * All "default_tkt_enctypes" keys will be generated, Never null.
      * @throws IllegalStateException if not constructed from a password
      * @throws KrbException
      */
-    public EncryptionKey[] getKeys() throws KrbException {
-        checkState(State.REQ_OK, "Cannot get keys");
+    public EncryptionKey[] getKeys(boolean isInitiator) throws KrbException {
+        checkState(isInitiator?State.REQ_OK:State.INIT, "Cannot get keys");
         if (password != null) {
             int[] eTypes = EType.getDefaults("default_tkt_enctypes");
             EncryptionKey[] result = new EncryptionKey[eTypes.length];
diff --git a/jdk/src/share/classes/sun/security/krb5/SCDynamicStoreConfig.java b/jdk/src/share/classes/sun/security/krb5/SCDynamicStoreConfig.java
new file mode 100644
index 0000000..4ec1241
--- /dev/null
+++ b/jdk/src/share/classes/sun/security/krb5/SCDynamicStoreConfig.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.krb5;
+
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Vector;
+
+
+public class SCDynamicStoreConfig {
+    private static native void installNotificationCallback();
+    private static native Hashtable<String, Object> getKerberosConfig();
+
+    static {
+        java.security.AccessController.doPrivileged(new sun.security.action.LoadLibraryAction("osx"));
+        installNotificationCallback();
+    }
+
+    private static Vector<String> unwrapHost(Collection<Hashtable<String, String>> c) {
+        Vector<String> vector = new Vector<String>();
+        for (Hashtable<String, String> m : c) {
+            vector.add(m.get("host"));
+        }
+        return vector;
+    }
+
+    /**
+     * convertRealmConfigs: Maps the Object graph that we get from JNI to the
+     * object graph that Config expects. Also the items inside the kdc array
+     * are wrapped inside Hashtables
+     */
+    @SuppressWarnings("unchecked")
+    private static Hashtable<String, Object> convertRealmConfigs(Hashtable<String, ?> configs) {
+        Hashtable<String, Object> realmsTable = new Hashtable<String, Object>();
+
+        for (String realm : configs.keySet()) {
+            // get the kdc
+            Hashtable<String, Collection<?>> map = (Hashtable<String, Collection<?>>) configs.get(realm);
+            Collection<Hashtable<String, String>> kdc = (Collection<Hashtable<String, String>>) map.get("kdc");
+
+            // put the kdc into the realmMap
+            Hashtable<String, Vector<String>> realmMap = new Hashtable<String, Vector<String>>();
+            if (kdc != null) realmMap.put("kdc", unwrapHost(kdc));
+
+            // put the admin server into the realmMap
+            Collection<Hashtable<String, String>> kadmin = (Collection<Hashtable<String, String>>) map.get("kadmin");
+            if (kadmin != null) realmMap.put("admin_server", unwrapHost(kadmin));
+
+            // add the full entry to the realmTable
+            realmsTable.put(realm, realmMap);
+        }
+
+        return realmsTable;
+    }
+
+    /**
+     * Calls down to JNI to get the raw Kerberos Config and maps the object
+     * graph to the one that Kerberos Config in Java expects
+     *
+     * @return
+     * @throws KrbException
+     */
+    @SuppressWarnings("unchecked")
+    public static Hashtable<String, Object> getConfig() throws KrbException {
+        Hashtable<String, Object> stanzaTable = getKerberosConfig();
+        if (stanzaTable == null) {
+            throw(new KrbException("Could not load configuration from SCDynamicStore"));
+        }
+        //System.out.println("Raw map from JNI: " + stanzaTable);
+
+        // convert SCDynamicStore realm structure to Java realm structure
+        Hashtable<String, ?> realms = (Hashtable<String, ?>) stanzaTable.get("realms");
+        if (realms != null) {
+            stanzaTable.remove("realms");
+            Hashtable<String, Object> realmsTable = convertRealmConfigs(realms);
+            stanzaTable.put("realms", realmsTable);
+        }
+
+       // System.out.println("stanzaTable : " + stanzaTable);
+        return (Hashtable<String, Object>) stanzaTable;
+    }
+}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java b/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java
index eae48e1..1ad85ec 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java
@@ -68,8 +68,8 @@
     private int  microSeconds; // the last three digits of the microsecond value
 
     // The time when this class is loaded. Used in setNow()
-    private static final long initMilli = System.currentTimeMillis();
-    private static final long initMicro = System.nanoTime() / 1000;
+    private static long initMilli = System.currentTimeMillis();
+    private static long initMicro = System.nanoTime() / 1000;
 
     private static long syncTime;
     private static boolean DEBUG = Krb5.DEBUG;
@@ -212,9 +212,22 @@
     }
 
     public void setNow() {
-        long microElapsed = System.nanoTime() / 1000 - initMicro;
-        setTime(initMilli + microElapsed/1000);
-        microSeconds = (int)(microElapsed % 1000);
+        long newMilli = System.currentTimeMillis();
+        long newMicro = System.nanoTime() / 1000;
+        long microElapsed = newMicro - initMicro;
+        long calcMilli = initMilli + microElapsed/1000;
+        if (calcMilli - newMilli > 100 || newMilli - calcMilli > 100) {
+            if (DEBUG) {
+                System.out.println("System time adjusted");
+            }
+            initMilli = newMilli;
+            initMicro = newMicro;
+            setTime(newMilli);
+            microSeconds = 0;
+        } else {
+            setTime(calcMilli);
+            microSeconds = (int)(microElapsed % 1000);
+        }
     }
 
     public int getMicroSeconds() {
diff --git a/jdk/src/share/classes/sun/security/ssl/MAC.java b/jdk/src/share/classes/sun/security/ssl/MAC.java
index 8002148..ae5c9d4 100644
--- a/jdk/src/share/classes/sun/security/ssl/MAC.java
+++ b/jdk/src/share/classes/sun/security/ssl/MAC.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -172,10 +172,10 @@
          * when there are only 2^8 sequence numbers left.
          */
         return (block != null && mac != null &&
-                block[0] == 0xFF && block[1] == 0xFF &&
-                block[2] == 0xFF && block[3] == 0xFF &&
-                block[4] == 0xFF && block[5] == 0xFF &&
-                block[6] == 0xFF);
+                block[0] == (byte)0xFF && block[1] == (byte)0xFF &&
+                block[2] == (byte)0xFF && block[3] == (byte)0xFF &&
+                block[4] == (byte)0xFF && block[5] == (byte)0xFF &&
+                block[6] == (byte)0xFF);
     }
 
     /*
@@ -192,7 +192,7 @@
          * only 2^48 sequence numbers left.
          */
         return (block != null && mac != null &&
-                block[0] == 0xFF && block[1] == 0xFF);
+                block[0] == (byte)0xFF && block[1] == (byte)0xFF);
     }
 
     // increment the sequence number in the block array
diff --git a/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java b/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java
index 205c80e..f66703e 100644
--- a/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java
+++ b/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java
@@ -767,10 +767,15 @@
 final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
             implements X509TrustManager {
 
+    // the delegated trust manager
     private final X509TrustManager tm;
 
+    // Cache the trusted certificate to optimize the performance.
+    private final Collection<X509Certificate> trustedCerts = new HashSet<>();
+
     AbstractTrustManagerWrapper(X509TrustManager tm) {
         this.tm = tm;
+        Collections.addAll(trustedCerts, tm.getAcceptedIssuers());
     }
 
     @Override
@@ -859,20 +864,7 @@
                 constraints = new SSLAlgorithmConstraints(sslSocket, true);
             }
 
-            AlgorithmChecker checker = new AlgorithmChecker(constraints);
-            try {
-                checker.init(false);
-
-                // a forward checker, need to check from trust to target
-                for (int i = chain.length - 1; i >= 0; i--) {
-                    Certificate cert = chain[i];
-                    // We don't care about the unresolved critical extensions.
-                    checker.check(cert, Collections.<String>emptySet());
-                }
-            } catch (CertPathValidatorException cpve) {
-                throw new CertificateException(
-                    "Certificates does not conform to algorithm constraints");
-            }
+            checkAlgorithmConstraints(chain, constraints);
         }
     }
 
@@ -914,20 +906,33 @@
                 constraints = new SSLAlgorithmConstraints(engine, true);
             }
 
-            AlgorithmChecker checker = new AlgorithmChecker(constraints);
-            try {
-                checker.init(false);
+            checkAlgorithmConstraints(chain, constraints);
+        }
+    }
 
-                // A forward checker, need to check from trust to target
-                for (int i = chain.length - 1; i >= 0; i--) {
+    private void checkAlgorithmConstraints(X509Certificate[] chain,
+            AlgorithmConstraints constraints) throws CertificateException {
+
+        try {
+            // Does the certificate chain end with a trusted certificate?
+            int checkedLength = chain.length - 1;
+            if (trustedCerts.contains(chain[checkedLength])) {
+                    checkedLength--;
+            }
+
+            // A forward checker, need to check from trust to target
+            if (checkedLength >= 0) {
+                AlgorithmChecker checker = new AlgorithmChecker(constraints);
+                checker.init(false);
+                for (int i = checkedLength; i >= 0; i--) {
                     Certificate cert = chain[i];
                     // We don't care about the unresolved critical extensions.
                     checker.check(cert, Collections.<String>emptySet());
                 }
-            } catch (CertPathValidatorException cpve) {
-                throw new CertificateException(
-                    "Certificates does not conform to algorithm constraints");
             }
+        } catch (CertPathValidatorException cpve) {
+            throw new CertificateException(
+                "Certificates does not conform to algorithm constraints");
         }
     }
 }
diff --git a/jdk/src/share/classes/sun/security/tools/JarSigner.java b/jdk/src/share/classes/sun/security/tools/JarSigner.java
index ca1006a..fae9432 100644
--- a/jdk/src/share/classes/sun/security/tools/JarSigner.java
+++ b/jdk/src/share/classes/sun/security/tools/JarSigner.java
@@ -1505,6 +1505,9 @@
             CertPath cp = certificateFactory.generateCertPath(certs);
             validator.validate(cp, pkixParameters);
         } catch (Exception e) {
+            if (debug) {
+                e.printStackTrace();
+            }
             chainNotValidated = true;
             s.append(tab + rb.getString(".CertPath.not.validated.") +
                     e.getLocalizedMessage() + "]\n");   // TODO
@@ -1561,6 +1564,27 @@
         }
 
         try {
+
+            certificateFactory = CertificateFactory.getInstance("X.509");
+            validator = CertPathValidator.getInstance("PKIX");
+            Set<TrustAnchor> tas = new HashSet<>();
+            try {
+                KeyStore caks = KeyTool.getCacertsKeyStore();
+                if (caks != null) {
+                    Enumeration<String> aliases = caks.aliases();
+                    while (aliases.hasMoreElements()) {
+                        String a = aliases.nextElement();
+                        try {
+                            tas.add(new TrustAnchor((X509Certificate)caks.getCertificate(a), null));
+                        } catch (Exception e2) {
+                            // ignore, when a SecretkeyEntry does not include a cert
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                // Ignore, if cacerts cannot be loaded
+            }
+
             if (providerName == null) {
                 store = KeyStore.getInstance(storetype);
             } else {
@@ -1579,45 +1603,28 @@
                         (rb.getString("Enter.Passphrase.for.keystore."));
             }
 
-            if (nullStream) {
-                store.load(null, storepass);
-            } else {
-                keyStoreName = keyStoreName.replace(File.separatorChar, '/');
-                URL url = null;
-                try {
-                    url = new URL(keyStoreName);
-                } catch (java.net.MalformedURLException e) {
-                    // try as file
-                    url = new File(keyStoreName).toURI().toURL();
-                }
-                InputStream is = null;
-                try {
-                    is = url.openStream();
-                    store.load(is, storepass);
-                } finally {
-                    if (is != null) {
-                        is.close();
-                    }
-                }
-            }
-            Set<TrustAnchor> tas = new HashSet<>();
             try {
-                KeyStore caks = KeyTool.getCacertsKeyStore();
-                if (caks != null) {
-                    Enumeration<String> aliases = caks.aliases();
-                    while (aliases.hasMoreElements()) {
-                        String a = aliases.nextElement();
-                        try {
-                            tas.add(new TrustAnchor((X509Certificate)caks.getCertificate(a), null));
-                        } catch (Exception e2) {
-                            // ignore, when a SecretkeyEntry does not include a cert
+                if (nullStream) {
+                    store.load(null, storepass);
+                } else {
+                    keyStoreName = keyStoreName.replace(File.separatorChar, '/');
+                    URL url = null;
+                    try {
+                        url = new URL(keyStoreName);
+                    } catch (java.net.MalformedURLException e) {
+                        // try as file
+                        url = new File(keyStoreName).toURI().toURL();
+                    }
+                    InputStream is = null;
+                    try {
+                        is = url.openStream();
+                        store.load(is, storepass);
+                    } finally {
+                        if (is != null) {
+                            is.close();
                         }
                     }
                 }
-            } catch (Exception e) {
-                // Ignore, if cacerts cannot be loaded
-            }
-            if (store != null) {
                 Enumeration<String> aliases = store.aliases();
                 while (aliases.hasMoreElements()) {
                     String a = aliases.nextElement();
@@ -1633,14 +1640,13 @@
                         // ignore, when a SecretkeyEntry does not include a cert
                     }
                 }
-            }
-            certificateFactory = CertificateFactory.getInstance("X.509");
-            validator = CertPathValidator.getInstance("PKIX");
-            try {
-                pkixParameters = new PKIXParameters(tas);
-                pkixParameters.setRevocationEnabled(false);
-            } catch (InvalidAlgorithmParameterException ex) {
-                // Only if tas is empty
+            } finally {
+                try {
+                    pkixParameters = new PKIXParameters(tas);
+                    pkixParameters.setRevocationEnabled(false);
+                } catch (InvalidAlgorithmParameterException ex) {
+                    // Only if tas is empty
+                }
             }
         } catch (IOException ioe) {
             throw new RuntimeException(rb.getString("keystore.load.") +
@@ -1805,6 +1811,9 @@
                 CertPath cp = certificateFactory.generateCertPath(Arrays.asList(certChain));
                 validator.validate(cp, pkixParameters);
             } catch (Exception e) {
+                if (debug) {
+                    e.printStackTrace();
+                }
                 chainNotValidated = true;
             }
 
diff --git a/jdk/src/share/classes/sun/security/tools/KeyTool.java b/jdk/src/share/classes/sun/security/tools/KeyTool.java
index d2749f5..f7c3443 100644
--- a/jdk/src/share/classes/sun/security/tools/KeyTool.java
+++ b/jdk/src/share/classes/sun/security/tools/KeyTool.java
@@ -52,6 +52,7 @@
 import java.util.jar.JarFile;
 import java.lang.reflect.Constructor;
 import java.math.BigInteger;
+import java.net.Socket;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -84,6 +85,7 @@
 import sun.security.x509.*;
 
 import static java.security.KeyStore.*;
+import javax.net.ssl.*;
 import static sun.security.tools.KeyTool.Command.*;
 import static sun.security.tools.KeyTool.Option.*;
 
@@ -2321,18 +2323,31 @@
             SSLContext sc = SSLContext.getInstance("SSL");
             final boolean[] certPrinted = new boolean[1];
             sc.init(null, new TrustManager[] {
-                new X509TrustManager() {
-
-                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
-                        return null;
+                new X509ExtendedTrustManager() {
+                    @Override
+                    public X509Certificate[] getAcceptedIssuers() {
+                        return new X509Certificate[0];
                     }
-
+                    @Override
                     public void checkClientTrusted(
-                        java.security.cert.X509Certificate[] certs, String authType) {
+                            X509Certificate[] certs, String authType) {
+                        throw new UnsupportedOperationException();
                     }
-
+                    @Override
+                    public void checkClientTrusted(X509Certificate[] chain,
+                            String authType, Socket socket)
+                            throws CertificateException {
+                        throw new UnsupportedOperationException();
+                    }
+                    @Override
+                    public void checkClientTrusted(X509Certificate[] chain,
+                            String authType, SSLEngine engine) throws
+                            CertificateException {
+                        throw new UnsupportedOperationException();
+                    }
+                    @Override
                     public void checkServerTrusted(
-                            java.security.cert.X509Certificate[] certs, String authType) {
+                            X509Certificate[] certs, String authType) {
                         for (int i=0; i<certs.length; i++) {
                             X509Certificate cert = certs[i];
                             try {
@@ -2356,6 +2371,18 @@
                             certPrinted[0] = true;
                         }
                     }
+                    @Override
+                    public void checkServerTrusted(X509Certificate[] chain,
+                            String authType, Socket socket)
+                            throws CertificateException {
+                        checkServerTrusted(chain, authType);
+                    }
+                    @Override
+                    public void checkServerTrusted(X509Certificate[] chain,
+                            String authType, SSLEngine engine)
+                            throws CertificateException {
+                        checkServerTrusted(chain, authType);
+                    }
                 }
             }, null);
             HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
diff --git a/jdk/src/share/classes/sun/text/bidi/BidiBase.java b/jdk/src/share/classes/sun/text/bidi/BidiBase.java
index d5bc15af..957a6bf 100644
--- a/jdk/src/share/classes/sun/text/bidi/BidiBase.java
+++ b/jdk/src/share/classes/sun/text/bidi/BidiBase.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -3411,18 +3411,21 @@
      * Display the bidi internal state, used in debugging.
      */
     public String toString() {
-        StringBuffer buf = new StringBuffer(super.toString());
+        StringBuilder buf = new StringBuilder(getClass().getName());
 
-        buf.append("[dir: " + direction);
-        buf.append(" baselevel: " + paraLevel);
-        buf.append(" length: " + length);
+        buf.append("[dir: ");
+        buf.append(direction);
+        buf.append(" baselevel: ");
+        buf.append(paraLevel);
+        buf.append(" length: ");
+        buf.append(length);
         buf.append(" runs: ");
         if (levels == null) {
-            buf.append("null");
+            buf.append("none");
         } else {
             buf.append('[');
             buf.append(levels[0]);
-            for (int i = 0; i < levels.length; i++) {
+            for (int i = 1; i < levels.length; i++) {
                 buf.append(' ');
                 buf.append(levels[i]);
             }
@@ -3430,12 +3433,11 @@
         }
         buf.append(" text: [0x");
         buf.append(Integer.toHexString(text[0]));
-        for (int i = 0; i < text.length; i++) {
+        for (int i = 1; i < text.length; i++) {
             buf.append(" 0x");
             buf.append(Integer.toHexString(text[i]));
         }
-        buf.append(']');
-        buf.append(']');
+        buf.append("]]");
 
         return buf.toString();
     }
diff --git a/jdk/src/share/classes/sun/tools/attach/META-INF/services/com.sun.tools.attach.spi.AttachProvider b/jdk/src/share/classes/sun/tools/attach/META-INF/services/com.sun.tools.attach.spi.AttachProvider
index a355775..100e352 100644
--- a/jdk/src/share/classes/sun/tools/attach/META-INF/services/com.sun.tools.attach.spi.AttachProvider
+++ b/jdk/src/share/classes/sun/tools/attach/META-INF/services/com.sun.tools.attach.spi.AttachProvider
@@ -30,3 +30,4 @@
 #[solaris]sun.tools.attach.SolarisAttachProvider
 #[windows]sun.tools.attach.WindowsAttachProvider
 #[linux]sun.tools.attach.LinuxAttachProvider
+#[macosx]sun.tools.attach.BsdAttachProvider
diff --git a/jdk/src/share/classes/sun/util/locale/LocaleObjectCache.java b/jdk/src/share/classes/sun/util/locale/LocaleObjectCache.java
index 35504bc..88920aa 100644
--- a/jdk/src/share/classes/sun/util/locale/LocaleObjectCache.java
+++ b/jdk/src/share/classes/sun/util/locale/LocaleObjectCache.java
@@ -66,14 +66,14 @@
 
             CacheEntry<K, V> newEntry = new CacheEntry<>(key, newVal, queue);
 
-            while (value == null) {
-                cleanStaleEntries();
-                entry = map.putIfAbsent(key, newEntry);
-                if (entry == null) {
+            entry = map.putIfAbsent(key, newEntry);
+            if (entry == null) {
+                value = newVal;
+            } else {
+                value = entry.get();
+                if (value == null) {
+                    map.put(key, newEntry);
                     value = newVal;
-                    break;
-                } else {
-                    value = entry.get();
                 }
             }
         }
diff --git a/jdk/src/share/javavm/export/jawt.h b/jdk/src/share/javavm/export/jawt.h
index ccca08f..d709649 100644
--- a/jdk/src/share/javavm/export/jawt.h
+++ b/jdk/src/share/javavm/export/jawt.h
@@ -288,6 +288,7 @@
 
 #define JAWT_VERSION_1_3 0x00010003
 #define JAWT_VERSION_1_4 0x00010004
+#define JAWT_VERSION_1_7 0x00010007
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/jdk/src/share/javavm/export/jvm.h b/jdk/src/share/javavm/export/jvm.h
index d1dfefc..f298cca 100644
--- a/jdk/src/share/javavm/export/jvm.h
+++ b/jdk/src/share/javavm/export/jvm.h
@@ -269,6 +269,9 @@
 JNIEXPORT jobjectArray JNICALL
 JVM_GetAllThreads(JNIEnv *env, jclass dummy);
 
+JNIEXPORT void JNICALL
+JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name);
+
 /* getStackTrace() and getAllStackTraces() method */
 JNIEXPORT jobjectArray JNICALL
 JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads);
diff --git a/jdk/src/share/lib/security/java.security-macosx b/jdk/src/share/lib/security/java.security-macosx
new file mode 100644
index 0000000..42f9d3a
--- /dev/null
+++ b/jdk/src/share/lib/security/java.security-macosx
@@ -0,0 +1,377 @@
+#
+# This is the "master security properties file".
+#
+# In this file, various security properties are set for use by
+# java.security classes. This is where users can statically register
+# Cryptography Package Providers ("providers" for short). The term
+# "provider" refers to a package or set of packages that supply a
+# concrete implementation of a subset of the cryptography aspects of
+# the Java Security API. A provider may, for example, implement one or
+# more digital signature algorithms or message digest algorithms.
+#
+# Each provider must implement a subclass of the Provider class.
+# To register a provider in this master security properties file,
+# specify the Provider subclass name and priority in the format
+#
+#    security.provider.<n>=<className>
+#
+# This declares a provider, and specifies its preference
+# order n. The preference order is the order in which providers are
+# searched for requested algorithms (when no specific provider is
+# requested). The order is 1-based; 1 is the most preferred, followed
+# by 2, and so on.
+#
+# <className> must specify the subclass of the Provider class whose
+# constructor sets the values of various properties that are required
+# for the Java Security API to look up the algorithms or other
+# facilities implemented by the provider.
+#
+# There must be at least one provider specification in java.security.
+# There is a default provider that comes standard with the JDK. It
+# is called the "SUN" provider, and its Provider subclass
+# named Sun appears in the sun.security.provider package. Thus, the
+# "SUN" provider is registered via the following:
+#
+#    security.provider.1=sun.security.provider.Sun
+#
+# (The number 1 is used for the default provider.)
+#
+# Note: Providers can be dynamically registered instead by calls to
+# either the addProvider or insertProviderAt method in the Security
+# class.
+
+#
+# List of providers and their preference orders (see above):
+#
+security.provider.1=sun.security.provider.Sun
+security.provider.2=sun.security.rsa.SunRsaSign
+security.provider.3=sun.security.ec.SunEC
+security.provider.4=com.sun.net.ssl.internal.ssl.Provider
+security.provider.5=com.sun.crypto.provider.SunJCE
+security.provider.6=sun.security.jgss.SunProvider
+security.provider.7=com.sun.security.sasl.Provider
+security.provider.8=org.jcp.xml.dsig.internal.dom.XMLDSigRI
+security.provider.9=sun.security.smartcardio.SunPCSC
+security.provider.10=apple.security.AppleProvider
+
+#
+# Select the source of seed data for SecureRandom. By default an
+# attempt is made to use the entropy gathering device specified by
+# the securerandom.source property. If an exception occurs when
+# accessing the URL then the traditional system/thread activity
+# algorithm is used.
+#
+# On Solaris and Linux systems, if file:/dev/urandom is specified and it
+# exists, a special SecureRandom implementation is activated by default.
+# This "NativePRNG" reads random bytes directly from /dev/urandom.
+#
+# On Windows systems, the URLs file:/dev/random and file:/dev/urandom
+# enables use of the Microsoft CryptoAPI seed functionality.
+#
+securerandom.source=file:/dev/urandom
+#
+# The entropy gathering device is described as a URL and can also
+# be specified with the system property "java.security.egd". For example,
+#   -Djava.security.egd=file:/dev/urandom
+# Specifying this system property will override the securerandom.source
+# setting.
+
+#
+# Class to instantiate as the javax.security.auth.login.Configuration
+# provider.
+#
+login.configuration.provider=com.sun.security.auth.login.ConfigFile
+
+#
+# Default login configuration file
+#
+#login.config.url.1=file:${user.home}/.java.login.config
+
+#
+# Class to instantiate as the system Policy. This is the name of the class
+# that will be used as the Policy object.
+#
+policy.provider=sun.security.provider.PolicyFile
+
+# The default is to have a single system-wide policy file,
+# and a policy file in the user's home directory.
+policy.url.1=file:${java.home}/lib/security/java.policy
+policy.url.2=file:${user.home}/.java.policy
+
+# whether or not we expand properties in the policy file
+# if this is set to false, properties (${...}) will not be expanded in policy
+# files.
+policy.expandProperties=true
+
+# whether or not we allow an extra policy to be passed on the command line
+# with -Djava.security.policy=somefile. Comment out this line to disable
+# this feature.
+policy.allowSystemProperty=true
+
+# whether or not we look into the IdentityScope for trusted Identities
+# when encountering a 1.1 signed JAR file. If the identity is found
+# and is trusted, we grant it AllPermission.
+policy.ignoreIdentityScope=false
+
+#
+# Default keystore type.
+#
+keystore.type=jks
+
+#
+# List of comma-separated packages that start with or equal this string
+# will cause a security exception to be thrown when
+# passed to checkPackageAccess unless the
+# corresponding RuntimePermission ("accessClassInPackage."+package) has
+# been granted.
+package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,apple.
+
+#
+# List of comma-separated packages that start with or equal this string
+# will cause a security exception to be thrown when
+# passed to checkPackageDefinition unless the
+# corresponding RuntimePermission ("defineClassInPackage."+package) has
+# been granted.
+#
+# by default, no packages are restricted for definition, and none of
+# the class loaders supplied with the JDK call checkPackageDefinition.
+#
+#package.definition=
+
+#
+# Determines whether this properties file can be appended to
+# or overridden on the command line via -Djava.security.properties
+#
+security.overridePropertiesFile=true
+
+#
+# Determines the default key and trust manager factory algorithms for
+# the javax.net.ssl package.
+#
+ssl.KeyManagerFactory.algorithm=SunX509
+ssl.TrustManagerFactory.algorithm=PKIX
+
+#
+# The Java-level namelookup cache policy for successful lookups:
+#
+# any negative value: caching forever
+# any positive value: the number of seconds to cache an address for
+# zero: do not cache
+#
+# default value is forever (FOREVER). For security reasons, this
+# caching is made forever when a security manager is set. When a security
+# manager is not set, the default behavior in this implementation
+# is to cache for 30 seconds.
+#
+# NOTE: setting this to anything other than the default value can have
+#       serious security implications. Do not set it unless
+#       you are sure you are not exposed to DNS spoofing attack.
+#
+#networkaddress.cache.ttl=-1
+
+# The Java-level namelookup cache policy for failed lookups:
+#
+# any negative value: cache forever
+# any positive value: the number of seconds to cache negative lookup results
+# zero: do not cache
+#
+# In some Microsoft Windows networking environments that employ
+# the WINS name service in addition to DNS, name service lookups
+# that fail may take a noticeably long time to return (approx. 5 seconds).
+# For this reason the default caching policy is to maintain these
+# results for 10 seconds.
+#
+#
+networkaddress.cache.negative.ttl=10
+
+#
+# Properties to configure OCSP for certificate revocation checking
+#
+
+# Enable OCSP
+#
+# By default, OCSP is not used for certificate revocation checking.
+# This property enables the use of OCSP when set to the value "true".
+#
+# NOTE: SocketPermission is required to connect to an OCSP responder.
+#
+# Example,
+#   ocsp.enable=true
+
+#
+# Location of the OCSP responder
+#
+# By default, the location of the OCSP responder is determined implicitly
+# from the certificate being validated. This property explicitly specifies
+# the location of the OCSP responder. The property is used when the
+# Authority Information Access extension (defined in RFC 3280) is absent
+# from the certificate or when it requires overriding.
+#
+# Example,
+#   ocsp.responderURL=http://ocsp.example.net:80
+
+#
+# Subject name of the OCSP responder's certificate
+#
+# By default, the certificate of the OCSP responder is that of the issuer
+# of the certificate being validated. This property identifies the certificate
+# of the OCSP responder when the default does not apply. Its value is a string
+# distinguished name (defined in RFC 2253) which identifies a certificate in
+# the set of certificates supplied during cert path validation. In cases where
+# the subject name alone is not sufficient to uniquely identify the certificate
+# then both the "ocsp.responderCertIssuerName" and
+# "ocsp.responderCertSerialNumber" properties must be used instead. When this
+# property is set then those two properties are ignored.
+#
+# Example,
+#   ocsp.responderCertSubjectName="CN=OCSP Responder, O=XYZ Corp"
+
+#
+# Issuer name of the OCSP responder's certificate
+#
+# By default, the certificate of the OCSP responder is that of the issuer
+# of the certificate being validated. This property identifies the certificate
+# of the OCSP responder when the default does not apply. Its value is a string
+# distinguished name (defined in RFC 2253) which identifies a certificate in
+# the set of certificates supplied during cert path validation. When this
+# property is set then the "ocsp.responderCertSerialNumber" property must also
+# be set. When the "ocsp.responderCertSubjectName" property is set then this
+# property is ignored.
+#
+# Example,
+#   ocsp.responderCertIssuerName="CN=Enterprise CA, O=XYZ Corp"
+
+#
+# Serial number of the OCSP responder's certificate
+#
+# By default, the certificate of the OCSP responder is that of the issuer
+# of the certificate being validated. This property identifies the certificate
+# of the OCSP responder when the default does not apply. Its value is a string
+# of hexadecimal digits (colon or space separators may be present) which
+# identifies a certificate in the set of certificates supplied during cert path
+# validation. When this property is set then the "ocsp.responderCertIssuerName"
+# property must also be set. When the "ocsp.responderCertSubjectName" property
+# is set then this property is ignored.
+#
+# Example,
+#   ocsp.responderCertSerialNumber=2A:FF:00
+
+#
+# Policy for failed Kerberos KDC lookups:
+#
+# When a KDC is unavailable (network error, service failure, etc), it is
+# put inside a blacklist and accessed less often for future requests. The
+# value (case-insensitive) for this policy can be:
+#
+# tryLast
+#    KDCs in the blacklist are always tried after those not on the list.
+#
+# tryLess[:max_retries,timeout]
+#    KDCs in the blacklist are still tried by their order in the configuration,
+#    but with smaller max_retries and timeout values. max_retries and timeout
+#    are optional numerical parameters (default 1 and 5000, which means once
+#    and 5 seconds). Please notes that if any of the values defined here is
+#    more than what is defined in krb5.conf, it will be ignored.
+#
+# Whenever a KDC is detected as available, it is removed from the blacklist.
+# The blacklist is reset when krb5.conf is reloaded. You can add
+# refreshKrb5Config=true to a JAAS configuration file so that krb5.conf is
+# reloaded whenever a JAAS authentication is attempted.
+#
+# Example,
+#   krb5.kdc.bad.policy = tryLast
+#   krb5.kdc.bad.policy = tryLess:2,2000
+krb5.kdc.bad.policy = tryLast
+
+# Algorithm restrictions for certification path (CertPath) processing
+#
+# In some environments, certain algorithms or key lengths may be undesirable
+# for certification path building and validation.  For example, "MD2" is
+# generally no longer considered to be a secure hash algorithm.  This section
+# describes the mechanism for disabling algorithms based on algorithm name
+# and/or key length.  This includes algorithms used in certificates, as well
+# as revocation information such as CRLs and signed OCSP Responses.
+#
+# The syntax of the disabled algorithm string is described as this Java
+# BNF-style:
+#   DisabledAlgorithms:
+#       " DisabledAlgorithm { , DisabledAlgorithm } "
+#
+#   DisabledAlgorithm:
+#       AlgorithmName [Constraint]
+#
+#   AlgorithmName:
+#       (see below)
+#
+#   Constraint:
+#       KeySizeConstraint
+#
+#   KeySizeConstraint:
+#       keySize Operator DecimalInteger
+#
+#   Operator:
+#       <= | < | == | != | >= | >
+#
+#   DecimalInteger:
+#       DecimalDigits
+#
+#   DecimalDigits:
+#       DecimalDigit {DecimalDigit}
+#
+#   DecimalDigit: one of
+#       1 2 3 4 5 6 7 8 9 0
+#
+# The "AlgorithmName" is the standard algorithm name of the disabled
+# algorithm. See "Java Cryptography Architecture Standard Algorithm Name
+# Documentation" for information about Standard Algorithm Names.  Matching
+# is performed using a case-insensitive sub-element matching rule.  (For
+# example, in "SHA1withECDSA" the sub-elements are "SHA1" for hashing and
+# "ECDSA" for signatures.)  If the assertion "AlgorithmName" is a
+# sub-element of the certificate algorithm name, the algorithm will be
+# rejected during certification path building and validation.  For example,
+# the assertion algorithm name "DSA" will disable all certificate algorithms
+# that rely on DSA, such as NONEwithDSA, SHA1withDSA.  However, the assertion
+# will not disable algorithms related to "ECDSA".
+#
+# A "Constraint" provides further guidance for the algorithm being specified.
+# The "KeySizeConstraint" requires a key of a valid size range if the
+# "AlgorithmName" is of a key algorithm.  The "DecimalInteger" indicates the
+# key size specified in number of bits.  For example, "RSA keySize <= 1024"
+# indicates that any RSA key with key size less than or equal to 1024 bits
+# should be disabled, and "RSA keySize < 1024, RSA keySize > 2048" indicates
+# that any RSA key with key size less than 1024 or greater than 2048 should
+# be disabled. Note that the "KeySizeConstraint" only makes sense to key
+# algorithms.
+#
+# Note: This property is currently used by Oracle's PKIX implementation. It
+# is not guaranteed to be examined and used by other implementations.
+#
+# Example:
+#   jdk.certpath.disabledAlgorithms=MD2, DSA, RSA keySize < 2048
+#
+#
+jdk.certpath.disabledAlgorithms=MD2
+
+# Algorithm restrictions for Secure Socket Layer/Transport Layer Security
+# (SSL/TLS) processing
+#
+# In some environments, certain algorithms or key lengths may be undesirable
+# when using SSL/TLS.  This section describes the mechanism for disabling
+# algorithms during SSL/TLS security parameters negotiation, including cipher
+# suites selection, peer authentication and key exchange mechanisms.
+#
+# For PKI-based peer authentication and key exchange mechanisms, this list
+# of disabled algorithms will also be checked during certification path
+# building and validation, including algorithms used in certificates, as
+# well as revocation information such as CRLs and signed OCSP Responses.
+# This is in addition to the jdk.certpath.disabledAlgorithms property above.
+#
+# See the specification of "jdk.certpath.disabledAlgorithms" for the
+# syntax of the disabled algorithm string.
+#
+# Note: This property is currently used by Oracle's JSSE implementation.
+# It is not guaranteed to be examined and used by other implementations.
+#
+# Example:
+#   jdk.tls.disabledAlgorithms=MD5, SHA1, DSA, RSA keySize < 2048
+
diff --git a/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h b/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h
index abdaee7..e49cade 100644
--- a/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h
+++ b/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h
@@ -32,6 +32,10 @@
 #include <unistd.h>
 #endif
 
+#ifndef NO_ZLIB
+#include <zconf.h>
+#endif
+
 #ifndef FULL
 #define FULL 1 /* Adds <500 bytes to the zipped final product. */
 #endif
@@ -89,11 +93,13 @@
 // bytes and byte arrays
 
 typedef unsigned int uint;
+#if !defined(MACOSX) || (defined(MACOSX) && defined(NO_ZLIB))
 #ifdef _LP64
 typedef unsigned int uLong; // Historical zlib, should be 32-bit.
 #else
 typedef unsigned long uLong;
 #endif
+#endif
 #ifdef _MSC_VER
 typedef LONGLONG        jlong;
 typedef DWORDLONG       julong;
diff --git a/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp b/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp
index a23da40..6656720 100644
--- a/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp
+++ b/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp
@@ -22,6 +22,13 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+#ifdef _ALLBSD_SOURCE
+#include <stdint.h>
+#define THRTYPE intptr_t
+#else
+#define THRTYPE int
+#endif
+
 #include <sys/types.h>
 
 #include <stdio.h>
@@ -35,7 +42,7 @@
 
 #if defined(unix) && !defined(PRODUCT)
 #include "pthread.h"
-#define THREAD_SELF ((int)pthread_self())
+#define THREAD_SELF ((THRTYPE)pthread_self())
 #endif
 
 #include "defines.h"
@@ -58,9 +65,9 @@
 // Single-threaded, implementation, not reentrant.
 // Includes a weak error check against MT access.
 #ifndef THREAD_SELF
-#define THREAD_SELF (0)
+#define THREAD_SELF ((THRTYPE) 0)
 #endif
-NOT_PRODUCT(static int uThread = -1;)
+NOT_PRODUCT(static THRTYPE uThread = -1;)
 
 unpacker* unpacker::non_mt_current = null;
 unpacker* unpacker::current() {
@@ -69,7 +76,7 @@
 }
 static void set_current_unpacker(unpacker* u) {
   unpacker::non_mt_current = u;
-  assert(((uThread = (u == null) ? -1 : THREAD_SELF),
+  assert(((uThread = (u == null) ? (THRTYPE) -1 : THREAD_SELF),
           true));
 }
 
diff --git a/jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c b/jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c
index 4b38a27..a981c82 100644
--- a/jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c
+++ b/jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c
@@ -27,13 +27,17 @@
  * - move all the conversion code into an own file
  */
 
-#define USE_TRACE
-#define USE_ERROR
+//#define USE_TRACE
+//#define USE_ERROR
 
 
 #include <jni.h>
 // for malloc
+#ifdef _ALLBSD_SOURCE
+#include <stdlib.h>
+#else
 #include <malloc.h>
+#endif
 #include "SoundDefs.h"
 #include "DirectAudio.h"
 #include "Utilities.h"
@@ -58,22 +62,22 @@
 /* 16 bit signed sample, native endianness, stored in 32-bits */
 typedef INT32 MAP_Sample;
 
-INLINE UINT16 MAP_SWAP16_impl(UINT16 a) {
+static INLINE UINT16 MAP_SWAP16_impl(UINT16 a) {
     return (a>>8) | (a<<8);
 }
 
-INLINE UINT32 MAP_SWAP32_impl(UINT32 a) {
+static INLINE UINT32 MAP_SWAP32_impl(UINT32 a) {
     return (a>>24)
         | ((a>>8) & 0xFF00)
         | ((a<<8) & 0xFF0000)
         | (a<<24);
 }
 
-INLINE UINT32 MAP_SWAP16BIT(UINT32 sh) {
+static INLINE UINT32 MAP_SWAP16BIT(UINT32 sh) {
     return (UINT32) ((sh & 0xFF) << 8) | ((sh & 0xFF00) >> 8);
 }
 
-INLINE INT32 MAP_ClipAndConvertToShort(MAP_Sample sample) {
+static INLINE INT32 MAP_ClipAndConvertToShort(MAP_Sample sample) {
     if (sample < -32768) {
         return -32768;
     }
@@ -84,7 +88,7 @@
 }
 
 
-INLINE INT32 MAP_ClipAndConvertToShort_Swapped(MAP_Sample sample) {
+static INLINE INT32 MAP_ClipAndConvertToShort_Swapped(MAP_Sample sample) {
     if (sample < -32768) {
         return 0x0080;
     }
@@ -94,7 +98,7 @@
     return (INT32) (INT16) MAP_SWAP16BIT(sample);
 }
 
-INLINE INT8 MAP_ClipAndConvertToByte(MAP_Sample sample) {
+static INLINE INT8 MAP_ClipAndConvertToByte(MAP_Sample sample) {
     if (sample < -32768) {
         return -128;
     }
@@ -105,7 +109,7 @@
 }
 
 
-INLINE UINT8 MAP_ClipAndConvertToUByte(MAP_Sample sample) {
+static INLINE UINT8 MAP_ClipAndConvertToUByte(MAP_Sample sample) {
     if (sample < -32768) {
         return 0;
     }
diff --git a/jdk/src/share/native/com/sun/media/sound/Platform.c b/jdk/src/share/native/com/sun/media/sound/Platform.c
index 5b2ee90..863e680 100644
--- a/jdk/src/share/native/com/sun/media/sound/Platform.c
+++ b/jdk/src/share/native/com/sun/media/sound/Platform.c
@@ -99,5 +99,34 @@
         return com_sun_media_sound_Platform_LIB_ALSA;
     }
 #endif
+#if (X_PLATFORM == X_MACOSX)
+    switch (feature) {
+    case com_sun_media_sound_Platform_FEATURE_MIDIIO:
+        return com_sun_media_sound_Platform_LIB_MAIN;
+    case com_sun_media_sound_Platform_FEATURE_PORTS:
+        return com_sun_media_sound_Platform_LIB_MAIN;
+    case com_sun_media_sound_Platform_FEATURE_DIRECT_AUDIO:
+        return com_sun_media_sound_Platform_LIB_MAIN;
+    }
+#endif
+#if (X_PLATFORM == X_BSD)
+    switch (feature) {
+    case com_sun_media_sound_Platform_FEATURE_MIDIIO:
+       return com_sun_media_sound_Platform_LIB_MAIN;
+#ifdef __FreeBSD__
+    case com_sun_media_sound_Platform_FEATURE_PORTS:
+       return com_sun_media_sound_Platform_LIB_ALSA;
+    case com_sun_media_sound_Platform_FEATURE_DIRECT_AUDIO:
+       return com_sun_media_sound_Platform_LIB_ALSA;
+#else
+    case com_sun_media_sound_Platform_FEATURE_PORTS:
+       return com_sun_media_sound_Platform_LIB_MAIN;
+    case com_sun_media_sound_Platform_FEATURE_DIRECT_AUDIO:
+       // XXXBSD: When native Direct Audio support is ported change
+       // this back to returning com_sun_media_sound_Platform_LIB_MAIN
+       return 0;
+#endif
+    }
+#endif
     return 0;
 }
diff --git a/jdk/src/share/native/com/sun/media/sound/PlatformMidi.h b/jdk/src/share/native/com/sun/media/sound/PlatformMidi.h
index 64989af..df96899 100644
--- a/jdk/src/share/native/com/sun/media/sound/PlatformMidi.h
+++ b/jdk/src/share/native/com/sun/media/sound/PlatformMidi.h
@@ -34,7 +34,7 @@
 
 /* do we need the queue ? */
 #if (USE_PLATFORM_MIDI_IN == TRUE) || (USE_PLATFORM_MIDI_OUT == TRUE)
- #if X_PLATFORM == X_WINDOWS
+ #if X_PLATFORM == X_WINDOWS || X_PLATFORM == X_MACOSX
   #define USE_MIDI_QUEUE TRUE
  #endif
 #endif
diff --git a/jdk/src/share/native/com/sun/media/sound/SoundDefs.h b/jdk/src/share/native/com/sun/media/sound/SoundDefs.h
index f141ea6..1e7721f 100644
--- a/jdk/src/share/native/com/sun/media/sound/SoundDefs.h
+++ b/jdk/src/share/native/com/sun/media/sound/SoundDefs.h
@@ -31,6 +31,8 @@
 #define X_WINDOWS       1
 #define X_SOLARIS       2
 #define X_LINUX         3
+#define X_BSD           4
+#define X_MACOSX        5
 
 // types for X_ARCH
 #define X_I586          1
@@ -46,13 +48,23 @@
 // Make sure you set X_PLATFORM and X_ARCH defines correctly.
 // Everything depends upon this flag being setup correctly.
 // **********************************
+
+#if (X_PLATFORM == X_MACOSX) && !defined(X_ARCH)
+#if __x86_64__
+#define X_ARCH X_AMD64
+#endif
+#if __i386__
+#define X_ARCH X_I586
+#endif
+#endif
+
 #if (!defined(X_PLATFORM) || !defined(X_ARCH))
 #error "You need to define X_PLATFORM and X_ARCH outside of the source. Use the types above."
 #endif
 
 
 // following is needed for _LP64
-#if ((X_PLATFORM == X_SOLARIS) || (X_PLATFORM == X_LINUX))
+#if ((X_PLATFORM == X_SOLARIS) || (X_PLATFORM == X_LINUX) || (X_PLATFORM == X_MACOSX))
 #include <sys/types.h>
 #endif
 
@@ -132,4 +144,9 @@
 #endif
 
 
+#if (X_PLATFORM == X_BSD) || (X_PLATFORM == X_MACOSX)
+#define INLINE          inline
+#endif
+
+
 #endif  // __SOUNDDEFS_INCLUDED__
diff --git a/jdk/src/share/native/com/sun/media/sound/Utilities.h b/jdk/src/share/native/com/sun/media/sound/Utilities.h
index 0dc190e..c1bde06 100644
--- a/jdk/src/share/native/com/sun/media/sound/Utilities.h
+++ b/jdk/src/share/native/com/sun/media/sound/Utilities.h
@@ -33,11 +33,11 @@
 
 // ERROR PRINTS
 #ifdef USE_ERROR
-#define ERROR0(string)                        fprintf(stdout, (string)); fflush(stdout);
-#define ERROR1(string, p1)                    fprintf(stdout, (string), (p1)); fflush(stdout);
-#define ERROR2(string, p1, p2)                fprintf(stdout, (string), (p1), (p2)); fflush(stdout);
-#define ERROR3(string, p1, p2, p3)            fprintf(stdout, (string), (p1), (p2), (p3)); fflush(stdout);
-#define ERROR4(string, p1, p2, p3, p4)        fprintf(stdout, (string), (p1), (p2), (p3), (p4)); fflush(stdout);
+#define ERROR0(string)                        { fprintf(stdout, (string)); fflush(stdout); }
+#define ERROR1(string, p1)                    { fprintf(stdout, (string), (p1)); fflush(stdout); }
+#define ERROR2(string, p1, p2)                { fprintf(stdout, (string), (p1), (p2)); fflush(stdout); }
+#define ERROR3(string, p1, p2, p3)            { fprintf(stdout, (string), (p1), (p2), (p3)); fflush(stdout); }
+#define ERROR4(string, p1, p2, p3, p4)        { fprintf(stdout, (string), (p1), (p2), (p3), (p4)); fflush(stdout); }
 #else
 #define ERROR0(string)
 #define ERROR1(string, p1)
@@ -49,12 +49,12 @@
 
 // TRACE PRINTS
 #ifdef USE_TRACE
-#define TRACE0(string)                        fprintf(stdout, (string)); fflush(stdout);
-#define TRACE1(string, p1)                    fprintf(stdout, (string), (p1)); fflush(stdout);
-#define TRACE2(string, p1, p2)                fprintf(stdout, (string), (p1), (p2)); fflush(stdout);
-#define TRACE3(string, p1, p2, p3)            fprintf(stdout, (string), (p1), (p2), (p3)); fflush(stdout);
-#define TRACE4(string, p1, p2, p3, p4)        fprintf(stdout, (string), (p1), (p2), (p3), (p4)); fflush(stdout);
-#define TRACE5(string, p1, p2, p3, p4, p5)    fprintf(stdout, (string), (p1), (p2), (p3), (p4), (p5)); fflush(stdout);
+#define TRACE0(string)                        { fprintf(stdout, (string)); fflush(stdout); }
+#define TRACE1(string, p1)                    { fprintf(stdout, (string), (p1)); fflush(stdout); }
+#define TRACE2(string, p1, p2)                { fprintf(stdout, (string), (p1), (p2)); fflush(stdout); }
+#define TRACE3(string, p1, p2, p3)            { fprintf(stdout, (string), (p1), (p2), (p3)); fflush(stdout); }
+#define TRACE4(string, p1, p2, p3, p4)        { fprintf(stdout, (string), (p1), (p2), (p3), (p4)); fflush(stdout); }
+#define TRACE5(string, p1, p2, p3, p4, p5)    { fprintf(stdout, (string), (p1), (p2), (p3), (p4), (p5)); fflush(stdout); }
 #else
 #define TRACE0(string)
 #define TRACE1(string, p1)
@@ -69,7 +69,7 @@
 #ifdef USE_VERBOSE_TRACE
 #define VTRACE0(string)                 fprintf(stdout, (string));
 #define VTRACE1(string, p1)             fprintf(stdout, (string), (p1));
-#define VTRACE2(string, p1, p2)         printf(stdout, (string), (p1), (p2));
+#define VTRACE2(string, p1, p2)         fprintf(stdout, (string), (p1), (p2));
 #define VTRACE3(string, p1, p2, p3)     fprintf(stdout, (string), (p1), (p2), (p3));
 #define VTRACE4(string, p1, p2, p3, p4) fprintf(stdout, (string), (p1), (p2), (p3), (p4));
 #else
diff --git a/jdk/src/share/native/common/check_code.c b/jdk/src/share/native/common/check_code.c
index c8787b3..a338d83 100644
--- a/jdk/src/share/native/common/check_code.c
+++ b/jdk/src/share/native/common/check_code.c
@@ -1067,7 +1067,7 @@
  * Make sure that branches don't go into the middle of nowhere.
  */
 
-static jint ntohl(jint n)
+static jint _ck_ntohl(jint n)
 {
     unsigned char *p = (unsigned char *)&n;
     return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
@@ -1146,26 +1146,26 @@
             }
         }
         if (opcode == JVM_OPC_tableswitch) {
-            keys = ntohl(lpc[2]) -  ntohl(lpc[1]) + 1;
+            keys = _ck_ntohl(lpc[2]) -  _ck_ntohl(lpc[1]) + 1;
             delta = 1;
         } else {
-            keys = ntohl(lpc[1]); /* number of pairs */
+            keys = _ck_ntohl(lpc[1]); /* number of pairs */
             delta = 2;
             /* Make sure that the tableswitch items are sorted */
             for (k = keys - 1, lptr = &lpc[2]; --k >= 0; lptr += 2) {
-                int this_key = ntohl(lptr[0]);  /* NB: ntohl may be unsigned */
-                int next_key = ntohl(lptr[2]);
+                int this_key = _ck_ntohl(lptr[0]);  /* NB: ntohl may be unsigned */
+                int next_key = _ck_ntohl(lptr[2]);
                 if (this_key >= next_key) {
                     CCerror(context, "Unsorted lookup switch");
                 }
             }
         }
         saved_operand = NEW(int, keys + 2);
-        if (!isLegalTarget(context, offset + ntohl(lpc[0])))
+        if (!isLegalTarget(context, offset + _ck_ntohl(lpc[0])))
             CCerror(context, "Illegal default target in switch");
-        saved_operand[keys + 1] = code_data[offset + ntohl(lpc[0])];
+        saved_operand[keys + 1] = code_data[offset + _ck_ntohl(lpc[0])];
         for (k = keys, lptr = &lpc[3]; --k >= 0; lptr += delta) {
-            int target = offset + ntohl(lptr[0]);
+            int target = offset + _ck_ntohl(lptr[0]);
             if (!isLegalTarget(context, target))
                 CCerror(context, "Illegal branch in tableswitch");
             saved_operand[k + 1] = code_data[target];
@@ -1634,7 +1634,7 @@
             if (lpc + 2 >= (int *)end) {
                 return -1; /* do not read pass the end */
             }
-            index = ntohl(lpc[2]) - ntohl(lpc[1]);
+            index = _ck_ntohl(lpc[2]) - _ck_ntohl(lpc[1]);
             if ((index < 0) || (index > 65535)) {
                 return -1;      /* illegal */
             } else {
@@ -1647,7 +1647,7 @@
             int npairs;
             if (lpc + 1 >= (int *)end)
                 return -1; /* do not read pass the end */
-            npairs = ntohl(lpc[1]);
+            npairs = _ck_ntohl(lpc[1]);
             /* There can't be more than 64K labels because of the limit
              * on per-method byte code length.
              */
diff --git a/jdk/src/share/native/java/io/io_util.h b/jdk/src/share/native/java/io/io_util.h
index 83eed0d..fd7862a 100644
--- a/jdk/src/share/native/java/io/io_util.h
+++ b/jdk/src/share/native/java/io/io_util.h
@@ -25,11 +25,22 @@
 
 #include "jni.h"
 #include "jni_util.h"
+#ifdef MACOSX
+char* convertToNFDIfNeeded(const char *origPath, char *buf, size_t bufsize);
+#endif
 
 extern jfieldID IO_fd_fdID;
 extern jfieldID IO_handle_fdID;
 
-#if !defined(O_DSYNC) || !defined(O_SYNC)
+#ifdef _ALLBSD_SOURCE
+#include <fcntl.h>
+#ifndef O_SYNC
+#define O_SYNC  O_FSYNC
+#endif
+#ifndef O_DSYNC
+#define O_DSYNC O_FSYNC
+#endif
+#elif !defined(O_DSYNC) || !defined(O_SYNC)
 #define O_SYNC  (0x0800)
 #define O_DSYNC (0x2000)
 #endif
@@ -77,6 +88,35 @@
  * declares a unique variable.
  */
 
+#ifdef MACOSX
+
+#define WITH_PLATFORM_STRING(env, strexp, var)                                \
+    if (1) {                                                                  \
+        const char *var;                                                      \
+        jstring _##var##str = (strexp);                                       \
+        if (_##var##str == NULL) {                                            \
+            JNU_ThrowNullPointerException((env), NULL);                       \
+            goto _##var##end;                                                 \
+        }                                                                     \
+        const char *temp_var = JNU_GetStringPlatformChars((env), _##var##str, NULL);      \
+        if (temp_var == NULL) goto _##var##end;                               \
+        char buf[MAXPATHLEN];                                                 \
+        var = convertToNFDIfNeeded(temp_var, buf, sizeof(buf));
+
+#define WITH_FIELD_PLATFORM_STRING(env, object, id, var)                      \
+    WITH_PLATFORM_STRING(env,                                                 \
+                         ((object == NULL)                                    \
+                          ? NULL                                              \
+                          : (*(env))->GetObjectField((env), (object), (id))), \
+                        var)
+
+#define END_PLATFORM_STRING(env, var)                                         \
+        JNU_ReleaseStringPlatformChars(env, _##var##str, temp_var);           \
+    _##var##end: ;                                                            \
+    } else ((void)NULL)
+
+#else
+
 #define WITH_PLATFORM_STRING(env, strexp, var)                                \
     if (1) {                                                                  \
         const char *var;                                                      \
@@ -100,6 +140,9 @@
     _##var##end: ;                                                            \
     } else ((void)NULL)
 
+#endif
+
+
 /* Macros for transforming Java Strings into native Unicode strings.
  * Works analogously to WITH_PLATFORM_STRING.
  */
diff --git a/jdk/src/share/native/java/lang/System.c b/jdk/src/share/native/java/lang/System.c
index 86ad8f6..bd84d36 100644
--- a/jdk/src/share/native/java/lang/System.c
+++ b/jdk/src/share/native/java/lang/System.c
@@ -165,6 +165,10 @@
     return NULL;
 }
 
+#ifdef MACOSX
+extern void freeProps(java_props_t *sProps);
+#endif
+
 JNIEXPORT jobject JNICALL
 Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
 {
@@ -242,6 +246,48 @@
             (sprops->cpu_isalist ? sprops->cpu_isalist : ""));
     PUTPROP(props, "sun.cpu.endian",  sprops->cpu_endian);
 
+
+#ifdef MACOSX
+    /* Proxy setting properties */
+    if (sprops->httpProxyEnabled) {
+        PUTPROP(props, "http.proxyHost", sprops->httpHost);
+        PUTPROP(props, "http.proxyPort", sprops->httpPort);
+    }
+
+    if (sprops->httpsProxyEnabled) {
+        PUTPROP(props, "https.proxyHost", sprops->httpsHost);
+        PUTPROP(props, "https.proxyPort", sprops->httpsPort);
+    }
+
+    if (sprops->ftpProxyEnabled) {
+        PUTPROP(props, "ftp.proxyHost", sprops->ftpHost);
+        PUTPROP(props, "ftp.proxyPort", sprops->ftpPort);
+    }
+
+    if (sprops->socksProxyEnabled) {
+        PUTPROP(props, "socksProxyHost", sprops->socksHost);
+        PUTPROP(props, "socksProxyPort", sprops->socksPort);
+    }
+
+    if (sprops->gopherProxyEnabled) {
+        // The gopher client is different in that it expects an 'is this set?' flag that the others don't.
+        PUTPROP(props, "gopherProxySet", "true");
+        PUTPROP(props, "gopherProxyHost", sprops->gopherHost);
+        PUTPROP(props, "gopherProxyPort", sprops->gopherPort);
+    } else {
+        PUTPROP(props, "gopherProxySet", "false");
+    }
+
+    // Mac OS X only has a single proxy exception list which applies
+    // to all protocols
+    if (sprops->exceptionList) {
+        PUTPROP(props, "http.nonProxyHosts", sprops->exceptionList);
+        // HTTPS: implementation in jsse.jar uses http.nonProxyHosts
+        PUTPROP(props, "ftp.nonProxyHosts", sprops->exceptionList);
+        PUTPROP(props, "socksNonProxyHosts", sprops->exceptionList);
+    }
+#endif
+
     /* !!! DO NOT call PUTPROP_ForPlatformNString before this line !!!
      * !!! I18n properties have not been set up yet !!!
      */
@@ -349,6 +395,10 @@
         (*env)->DeleteLocalRef(env, jVMVal);
     }
 
+#ifdef MACOSX
+    // Free malloced memory.
+    freeProps(sprops);
+#endif
     return ret;
 }
 
diff --git a/jdk/src/share/native/java/lang/Thread.c b/jdk/src/share/native/java/lang/Thread.c
index da3a11e..cfbc7fd 100644
--- a/jdk/src/share/native/java/lang/Thread.c
+++ b/jdk/src/share/native/java/lang/Thread.c
@@ -36,6 +36,7 @@
 #define THD "Ljava/lang/Thread;"
 #define OBJ "Ljava/lang/Object;"
 #define STE "Ljava/lang/StackTraceElement;"
+#define STR "Ljava/lang/String;"
 
 #define ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0]))
 
@@ -55,11 +56,13 @@
     {"holdsLock",        "(" OBJ ")Z", (void *)&JVM_HoldsLock},
     {"getThreads",        "()[" THD,   (void *)&JVM_GetAllThreads},
     {"dumpThreads",      "([" THD ")[[" STE, (void *)&JVM_DumpThreads},
+    {"setNativeName",    "(" STR ")V", (void *)&JVM_SetNativeThreadName},
 };
 
 #undef THD
 #undef OBJ
 #undef STE
+#undef STR
 
 JNIEXPORT void JNICALL
 Java_java_lang_Thread_registerNatives(JNIEnv *env, jclass cls)
diff --git a/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h b/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h
index 5d55657..c24c781 100644
--- a/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h
+++ b/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h
@@ -24,6 +24,12 @@
  * questions.
  */
 
+#ifdef _ALLBSD_SOURCE
+#include <machine/endian.h>
+#elif __linux__
+#define __USE_BSD 1
+#include <endian.h>
+#endif
 #include "jfdlibm.h"
 
 #ifdef __NEWVALID       /* special setup for Sun test regime */
@@ -135,10 +141,22 @@
 extern double floor __P((double));
 extern double fmod __P((double, double));
 
+extern double erf __P((double));
+extern double erfc __P((double));
+extern double gamma __P((double));
 extern double hypot __P((double, double));
 extern int isnan __P((double));
 extern int finite __P((double));
+extern double j0 __P((double));
+extern double j1 __P((double));
+extern double jn __P((int, double));
+extern double lgamma __P((double));
+extern double y0 __P((double));
+extern double y1 __P((double));
+extern double yn __P((int, double));
 
+extern double acosh __P((double));
+extern double asinh __P((double));
 extern double atanh __P((double));
 extern double cbrt __P((double));
 extern double logb __P((double));
@@ -171,9 +189,19 @@
 extern double expm1 __P((double));
 extern double log1p __P((double));
 
+/*
+ * Reentrant version of gamma & lgamma; passes signgam back by reference
+ * as the second argument; user must allocate space for signgam.
+ */
+#ifdef _REENTRANT
+extern double gamma_r __P((double, int *));
+extern double lgamma_r __P((double, int *));
+#endif  /* _REENTRANT */
+
 /* ieee style elementary functions */
 extern double __ieee754_sqrt __P((double));
 extern double __ieee754_acos __P((double));
+extern double __ieee754_acosh __P((double));
 extern double __ieee754_log __P((double));
 extern double __ieee754_atanh __P((double));
 extern double __ieee754_asin __P((double));
@@ -182,9 +210,19 @@
 extern double __ieee754_cosh __P((double));
 extern double __ieee754_fmod __P((double,double));
 extern double __ieee754_pow __P((double,double));
+extern double __ieee754_lgamma_r __P((double,int *));
+extern double __ieee754_gamma_r __P((double,int *));
+extern double __ieee754_lgamma __P((double));
+extern double __ieee754_gamma __P((double));
 extern double __ieee754_log10 __P((double));
 extern double __ieee754_sinh __P((double));
 extern double __ieee754_hypot __P((double,double));
+extern double __ieee754_j0 __P((double));
+extern double __ieee754_j1 __P((double));
+extern double __ieee754_y0 __P((double));
+extern double __ieee754_y1 __P((double));
+extern double __ieee754_jn __P((int,double));
+extern double __ieee754_yn __P((int,double));
 extern double __ieee754_remainder __P((double,double));
 extern int    __ieee754_rem_pio2 __P((double,double*));
 #ifdef _SCALB_INT
diff --git a/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h b/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h
index bfbc9b9..4525f4b 100644
--- a/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h
+++ b/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h
@@ -61,9 +61,10 @@
 #define log1p   jlog1p
 #define expm1   jexpm1
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #define __ieee754_sqrt          __j__ieee754_sqrt
 #define __ieee754_acos          __j__ieee754_acos
+#define __ieee754_acosh         __j__ieee754_acosh
 #define __ieee754_log           __j__ieee754_log
 #define __ieee754_atanh         __j__ieee754_atanh
 #define __ieee754_asin          __j__ieee754_asin
@@ -72,9 +73,19 @@
 #define __ieee754_cosh          __j__ieee754_cosh
 #define __ieee754_fmod          __j__ieee754_fmod
 #define __ieee754_pow           __j__ieee754_pow
+#define __ieee754_lgamma_r      __j__ieee754_lgamma_r
+#define __ieee754_gamma_r       __j__ieee754_gamma_r
+#define __ieee754_lgamma        __j__ieee754_lgamma
+#define __ieee754_gamma         __j__ieee754_gamma
 #define __ieee754_log10         __j__ieee754_log10
 #define __ieee754_sinh          __j__ieee754_sinh
 #define __ieee754_hypot         __j__ieee754_hypot
+#define __ieee754_j0            __j__ieee754_j0
+#define __ieee754_j1            __j__ieee754_j1
+#define __ieee754_y0            __j__ieee754_y0
+#define __ieee754_y1            __j__ieee754_y1
+#define __ieee754_jn            __j__ieee754_jn
+#define __ieee754_yn            __j__ieee754_yn
 #define __ieee754_remainder     __j__ieee754_remainder
 #define __ieee754_rem_pio2      __j__ieee754_rem_pio2
 #define __ieee754_scalb         __j__ieee754_scalb
diff --git a/jdk/src/share/native/java/lang/java_props.h b/jdk/src/share/native/java/lang/java_props.h
index 89f7671..de1947168 100644
--- a/jdk/src/share/native/java/lang/java_props.h
+++ b/jdk/src/share/native/java/lang/java_props.h
@@ -85,6 +85,33 @@
 
     char *desktop;              /* Desktop name. */
 
+#ifdef MACOSX
+    // These are for proxy-related information.
+    // Note that if these platform-specific extensions get out of hand we should make a new
+    // structure for them and #include it here.
+    int httpProxyEnabled;
+    char *httpHost;
+    char *httpPort;
+
+    int httpsProxyEnabled;
+    char *httpsHost;
+    char *httpsPort;
+
+    int ftpProxyEnabled;
+    char *ftpHost;
+    char *ftpPort;
+
+    int socksProxyEnabled;
+    char *socksHost;
+    char *socksPort;
+
+    int gopherProxyEnabled;
+    char *gopherHost;
+    char *gopherPort;
+
+    char *exceptionList;
+#endif
+
 } java_props_t;
 
 java_props_t *GetJavaProperties(JNIEnv *env);
diff --git a/jdk/src/share/native/java/util/zip/zip_util.c b/jdk/src/share/native/java/util/zip/zip_util.c
index f048dc6..3eb018c 100644
--- a/jdk/src/share/native/java/util/zip/zip_util.c
+++ b/jdk/src/share/native/java/util/zip/zip_util.c
@@ -46,6 +46,11 @@
 #include "zip_util.h"
 #include "zlib.h"
 
+#ifdef _ALLBSD_SOURCE
+#define off64_t off_t
+#define mmap64 mmap
+#endif
+
 /* USE_MMAP means mmap the CEN & ENDHDR part of the zip file. */
 #ifdef USE_MMAP
 #include <sys/mman.h>
diff --git a/jdk/src/share/native/sun/awt/debug/debug_util.h b/jdk/src/share/native/sun/awt/debug/debug_util.h
index 676e59e..29ba438 100644
--- a/jdk/src/share/native/sun/awt/debug/debug_util.h
+++ b/jdk/src/share/native/sun/awt/debug/debug_util.h
@@ -50,7 +50,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
-#include <malloc.h>
 #include <limits.h>
 
 /* keep these after the other headers */
diff --git a/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c b/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c
index a986467..3497950 100644
--- a/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c
+++ b/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c
@@ -24,7 +24,7 @@
  */
 
 #include "BufImgSurfaceData.h"
-#include "malloc.h"
+#include <stdlib.h>
 
 #include "sun_awt_image_BufImgSurfaceData.h"
 
diff --git a/jdk/src/share/native/sun/awt/image/DataBufferNative.c b/jdk/src/share/native/sun/awt/image/DataBufferNative.c
index 644e393..4bc087b 100644
--- a/jdk/src/share/native/sun/awt/image/DataBufferNative.c
+++ b/jdk/src/share/native/sun/awt/image/DataBufferNative.c
@@ -23,7 +23,7 @@
  * questions.
  */
 
-#include "malloc.h"
+#include <stdlib.h>
 
 #include "SurfaceData.h"
 #include "sun_awt_image_DataBufferNative.h"
diff --git a/jdk/src/share/native/sun/awt/medialib/mlib_ImageAffine.h b/jdk/src/share/native/sun/awt/medialib/mlib_ImageAffine.h
index 05950c5..85f18cd 100644
--- a/jdk/src/share/native/sun/awt/medialib/mlib_ImageAffine.h
+++ b/jdk/src/share/native/sun/awt/medialib/mlib_ImageAffine.h
@@ -297,7 +297,7 @@
 #define SAT32(DST) SAT_32(DST, val0)
 
 /***************************************************************/
-#ifdef MLIB_OS64BIT
+#if defined(MLIB_OS64BIT) || (defined(MACOSX) && defined(_LP64))
 #define PBITS  3
 #define MLIB_POINTER_SHIFT(P)  (((P) >> (MLIB_SHIFT - 3)) &~ 7)
 #define MLIB_POINTER_GET(A, P) (*(DTYPE**)((mlib_u8*)(A) + (P)))
diff --git a/jdk/src/share/native/sun/awt/medialib/mlib_image.h b/jdk/src/share/native/sun/awt/medialib/mlib_image.h
index 09b01b5..288b0aa 100644
--- a/jdk/src/share/native/sun/awt/medialib/mlib_image.h
+++ b/jdk/src/share/native/sun/awt/medialib/mlib_image.h
@@ -27,6 +27,9 @@
 #ifndef MLIB_IMAGE_H
 #define MLIB_IMAGE_H
 
+#ifdef MACOSX
+#include <machine/endian.h>
+#endif
 #include <mlib_types.h>
 #include <mlib_status.h>
 #include <mlib_sys.h>
diff --git a/jdk/src/share/native/sun/awt/medialib/mlib_sys.c b/jdk/src/share/native/sun/awt/medialib/mlib_sys.c
index 8cbe291..e78e118 100644
--- a/jdk/src/share/native/sun/awt/medialib/mlib_sys.c
+++ b/jdk/src/share/native/sun/awt/medialib/mlib_sys.c
@@ -26,6 +26,10 @@
 
 #include <stdlib.h>
 #include <string.h>
+#ifdef MACOSX
+#include <unistd.h>
+#include <sys/param.h>
+#endif
 #include <mlib_types.h>
 #include <mlib_sys_proto.h>
 #include "mlib_SysMath.h"
@@ -86,7 +90,9 @@
    * alignment. -- from stdlib.h of MS VC++5.0.
    */
   return (void *) malloc(size);
-#else /* _MSC_VER */
+#elif defined(MACOSX)
+  return valloc(size);
+#else
   return (void *) memalign(8, size);
 #endif /* _MSC_VER */
 }
diff --git a/jdk/src/share/native/sun/awt/medialib/mlib_types.h b/jdk/src/share/native/sun/awt/medialib/mlib_types.h
index b917b7e..72a0444 100644
--- a/jdk/src/share/native/sun/awt/medialib/mlib_types.h
+++ b/jdk/src/share/native/sun/awt/medialib/mlib_types.h
@@ -59,7 +59,10 @@
 
 #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__GNUC__)
 
-#if defined(__linux__)
+#if defined(MACOSX)
+#include <stddef.h>                     /* for ptrdiff_t */
+#include <stdint.h>                     /* for uintptr_t */
+#elif defined(__linux__)
 #include <stdint.h>                     /* for uintptr_t */
 #include <malloc.h>                     /* for ptrdiff_t */
 #else
@@ -67,7 +70,7 @@
 #include <stddef.h>                     /* for ptrdiff_t */
 #endif  /* __linux__ */
 
-#ifdef MLIB_OS64BIT
+#if defined(MLIB_OS64BIT) || (defined(MACOSX) && defined(_LP64))
 
 typedef long               mlib_s64;
 typedef unsigned long      mlib_u64;
diff --git a/jdk/src/share/native/sun/awt/splashscreen/splashscreen_impl.h b/jdk/src/share/native/sun/awt/splashscreen/splashscreen_impl.h
index 61bfe0b..72823a1 100644
--- a/jdk/src/share/native/sun/awt/splashscreen/splashscreen_impl.h
+++ b/jdk/src/share/native/sun/awt/splashscreen/splashscreen_impl.h
@@ -94,37 +94,51 @@
     pthread_mutex_t lock;
     Cursor cursor;
     XWMHints* wmHints;
+#elif defined(WITH_MACOSX)
+    pthread_mutex_t lock;
+    int controlpipe[2];
+    NSWindow * window;
 #endif
 } Splash;
 
 /* various shared and/or platform dependent splash screen functions */
 
+/*************** Platform-specific ******************/
+
+/* To be implemented in the platform-specific native code. */
+
+
+void SplashInitPlatform(Splash * splash);
+void SplashCreateThread(Splash * splash);
+void SplashCleanupPlatform(Splash * splash);
+void SplashDonePlatform(Splash * splash);
+
+unsigned SplashTime();
+char* SplashConvertStringAlloc(const char* in, int *size);
+
+void SplashLock(Splash * splash);
+void SplashUnlock(Splash * splash);
+
+void SplashInitFrameShape(Splash * splash, int imageIndex);
+
+void SplashUpdate(Splash * splash);
+void SplashReconfigure(Splash * splash);
+void SplashClosePlatform(Splash * splash);
+
+
+
+/********************* Shared **********************/
 Splash *SplashGetInstance();
 
 int SplashIsStillLooping(Splash * splash);
 void SplashNextFrame(Splash * splash);
 void SplashStart(Splash * splash);
-void SplashCreateThread(Splash * splash);
-unsigned SplashTime();
 void SplashDone(Splash * splash);
 
-void SplashInitPlatform(Splash * splash);
-void SplashDonePlatform(Splash * splash);
-void SplashDone(Splash * splash);
-void SplashUpdate(Splash * splash);
 void SplashUpdateScreenData(Splash * splash);
 
-void SplashLock(Splash * splash);
-void SplashUnlock(Splash * splash);
-
 void SplashCleanup(Splash * splash);
-void SplashCleanupPlatform(Splash * splash);
 
-void SplashClosePlatform();
-
-void SplashReconfigure();
-
-char* SplashConvertStringAlloc(const char* in, int *size);
 
 typedef struct SplashStream {
     int (*read)(void* pStream, void* pData, int nBytes);
@@ -153,8 +167,6 @@
 
 int BitmapToYXBandedRectangles(ImageRect * pSrcRect, RECT_T * out);
 
-void SplashInitFrameShape(Splash * splash, int imageIndex);
-
 #define SAFE_TO_ALLOC(c, sz)                                               \
     (((c) > 0) && ((sz) > 0) &&                                            \
      ((0xffffffffu / ((unsigned int)(c))) > (unsigned int)(sz)))
diff --git a/jdk/src/share/native/sun/font/AccelGlyphCache.c b/jdk/src/share/native/sun/font/AccelGlyphCache.c
index bc4416f..34cddfc 100644
--- a/jdk/src/share/native/sun/font/AccelGlyphCache.c
+++ b/jdk/src/share/native/sun/font/AccelGlyphCache.c
@@ -23,7 +23,7 @@
  * questions.
  */
 
-#include <malloc.h>
+#include <stdlib.h>
 #include "jni.h"
 #include "AccelGlyphCache.h"
 #include "Trace.h"
diff --git a/jdk/src/share/native/sun/font/DrawGlyphList.c b/jdk/src/share/native/sun/font/DrawGlyphList.c
index a58a9bb..2fcb5d6 100644
--- a/jdk/src/share/native/sun/font/DrawGlyphList.c
+++ b/jdk/src/share/native/sun/font/DrawGlyphList.c
@@ -26,7 +26,7 @@
 #include "jlong.h"
 #include "math.h"
 #include "string.h"
-#include "malloc.h"
+#include "stdlib.h"
 #include "sunfontids.h"
 #include "fontscalerdefs.h"
 #include "glyphblitting.h"
diff --git a/jdk/src/share/native/sun/font/sunFont.c b/jdk/src/share/native/sun/font/sunFont.c
index 3dd7c3e..e6ce37f 100644
--- a/jdk/src/share/native/sun/font/sunFont.c
+++ b/jdk/src/share/native/sun/font/sunFont.c
@@ -24,7 +24,6 @@
  */
 
 #include "stdlib.h"
-#include "malloc.h"
 #include "string.h"
 #include "gdefs.h"
 #include "jlong.h"
diff --git a/jdk/src/share/native/sun/java2d/SurfaceData.c b/jdk/src/share/native/sun/java2d/SurfaceData.c
index 7e1f8bb..73d43ad 100644
--- a/jdk/src/share/native/sun/java2d/SurfaceData.c
+++ b/jdk/src/share/native/sun/java2d/SurfaceData.c
@@ -28,7 +28,7 @@
 #include "jni_util.h"
 #include "Disposer.h"
 
-#include "malloc.h"
+#include "stdlib.h"
 #include "string.h"
 
 /**
diff --git a/jdk/src/share/native/sun/java2d/opengl/OGLBlitLoops.c b/jdk/src/share/native/sun/java2d/opengl/OGLBlitLoops.c
index 97a8b0e..e27604a 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLBlitLoops.c
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLBlitLoops.c
@@ -743,6 +743,15 @@
             j2d_glPixelStorei(GL_PACK_ROW_LENGTH,
                               dstInfo.scanStride / dstInfo.pixelStride);
             j2d_glPixelStorei(GL_PACK_ALIGNMENT, pf.alignment);
+#ifdef MACOSX
+            if (srcOps->isOpaque) {
+                // For some reason Apple's OpenGL implementation will
+                // read back zero values from the alpha channel of an
+                // opaque surface when using glReadPixels(), so here we
+                // force the resulting pixels to be fully opaque.
+                j2d_glPixelTransferf(GL_ALPHA_BIAS, 1.0);
+            }
+#endif
 
             J2dTraceLn4(J2D_TRACE_VERBOSE, "  sx=%d sy=%d w=%d h=%d",
                         srcx, srcy, width, height);
@@ -764,6 +773,12 @@
                 height--;
             }
 
+#ifdef MACOSX
+            if (srcOps->isOpaque) {
+                j2d_glPixelTransferf(GL_ALPHA_BIAS, 0.0);
+            }
+#endif
+
             j2d_glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
             j2d_glPixelStorei(GL_PACK_SKIP_ROWS, 0);
             j2d_glPixelStorei(GL_PACK_ROW_LENGTH, 0);
@@ -814,11 +829,27 @@
     SurfaceData_IntersectBlitBounds(&dstBounds, &srcBounds, -dx, -dy);
 
     if (dstBounds.x1 < dstBounds.x2 && dstBounds.y1 < dstBounds.y2) {
+#ifdef MACOSX
+        if (dstOps->isOpaque) {
+            // For some reason Apple's OpenGL implementation will fail
+            // to render glCopyPixels() when the src/dst rectangles are
+            // overlapping and glColorMask() has disabled writes to the
+            // alpha channel.  The workaround is to temporarily re-enable
+            // the alpha channel during the glCopyPixels() operation.
+            j2d_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+        }
+#endif
+
         OGLBlitSurfaceToSurface(oglc, dstOps, dstOps,
                                 srcBounds.x1, srcBounds.y1,
                                 srcBounds.x2, srcBounds.y2,
                                 dstBounds.x1, dstBounds.y1,
                                 dstBounds.x2, dstBounds.y2);
+#ifdef MACOSX
+        if (dstOps->isOpaque) {
+            j2d_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
+        }
+#endif
     }
 }
 
diff --git a/jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h b/jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h
index 33fbf62..e7872d7 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h
@@ -26,6 +26,9 @@
 #ifndef OGLFuncs_h_Included
 #define OGLFuncs_h_Included
 
+#ifdef MACOSX
+#include <dlfcn.h>
+#endif
 #include "jni.h"
 #include "J2D_GL/gl.h"
 #include "J2D_GL/glext.h"
diff --git a/jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c b/jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c
index c208060..79220bb 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c
@@ -25,7 +25,7 @@
 
 #ifndef HEADLESS
 
-#include <malloc.h>
+#include <stdlib.h>
 
 #include "sun_java2d_pipe_BufferedOpCodes.h"
 
@@ -63,6 +63,7 @@
 extern OGLContext *OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo);
 extern void OGLGC_DestroyOGLGraphicsConfig(jlong pConfigInfo);
 extern void OGLSD_SwapBuffers(JNIEnv *env, jlong window);
+extern void OGLSD_Flush(JNIEnv *env);
 
 JNIEXPORT void JNICALL
 Java_sun_java2d_opengl_OGLRenderQueue_flushBuffer
@@ -454,7 +455,7 @@
                 if (oglsdo != NULL) {
                     CONTINUE_IF_NULL(oglc);
                     RESET_PREVIOUS_OP();
-                    OGLSD_Flush(env, oglsdo);
+                    OGLSD_Delete(env, oglsdo);
                 }
             }
             break;
@@ -465,7 +466,7 @@
                 if (oglsdo != NULL) {
                     CONTINUE_IF_NULL(oglc);
                     RESET_PREVIOUS_OP();
-                    OGLSD_Flush(env, oglsdo);
+                    OGLSD_Delete(env, oglsdo);
                     if (oglsdo->privOps != NULL) {
                         free(oglsdo->privOps);
                     }
@@ -707,6 +708,7 @@
         } else {
             j2d_glFlush();
         }
+        OGLSD_Flush(env);
     }
 }
 
diff --git a/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c b/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c
index 6d3e2e8..b638099 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c
@@ -395,6 +395,16 @@
      jboolean texNonPow2, jboolean texRect,
      jint width, jint height)
 {
+    return OGLSurfaceData_initFBObject(env, oglsd, pData, isOpaque,
+                                       texNonPow2, texRect, width, height);
+}
+
+jboolean OGLSurfaceData_initFBObject
+    (JNIEnv *env, jobject oglsd,
+     jlong pData, jboolean isOpaque,
+     jboolean texNonPow2, jboolean texRect,
+     jint width, jint height)
+{
     OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
     GLuint fbobjectID, depthID;
 
@@ -548,12 +558,12 @@
 }
 
 /**
- * Disposes of all native resources associated with this surface.
+ * Deletes native OpenGL resources associated with this surface.
  */
 void
-OGLSD_Flush(JNIEnv *env, OGLSDOps *oglsdo)
+OGLSD_Delete(JNIEnv *env, OGLSDOps *oglsdo)
 {
-    J2dTraceLn1(J2D_TRACE_INFO, "OGLSD_Flush: type=%d",
+    J2dTraceLn1(J2D_TRACE_INFO, "OGLSD_Delete: type=%d",
                 oglsdo->drawableType);
 
     if (oglsdo->drawableType == OGLSD_TEXTURE) {
diff --git a/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.h b/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.h
index e611c98..9e40742 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.h
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.h
@@ -286,10 +286,16 @@
 void OGLSD_Unlock(JNIEnv *env,
                   SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo);
 void OGLSD_Dispose(JNIEnv *env, SurfaceDataOps *ops);
-void OGLSD_Flush(JNIEnv *env, OGLSDOps *oglsdo);
+void OGLSD_Delete(JNIEnv *env, OGLSDOps *oglsdo);
 jint OGLSD_NextPowerOfTwo(jint val, jint max);
 jboolean OGLSD_InitFBObject(GLuint *fbobjectID, GLuint *depthID,
                             GLuint textureID, GLenum textureTarget,
                             jint textureWidth, jint textureHeight);
+// needed by Mac OS X port
+jboolean OGLSurfaceData_initFBObject(JNIEnv *env, jobject oglsd,
+                                     jlong pData, jboolean isOpaque,
+                                     jboolean texNonPow2, jboolean texRect,
+                                     jint width, jint height);
+void OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
 
 #endif /* OGLSurfaceData_h_Included */
diff --git a/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c b/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c
index f0a3488..12e0284 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c
@@ -25,7 +25,7 @@
 
 #ifndef HEADLESS
 
-#include <malloc.h>
+#include <stdlib.h>
 #include <math.h>
 #include <jlong.h>
 
diff --git a/jdk/src/share/native/sun/nio/ch/genSocketOptionRegistry.c b/jdk/src/share/native/sun/nio/ch/genSocketOptionRegistry.c
index 1bb2f70..c2b6a0d 100644
--- a/jdk/src/share/native/sun/nio/ch/genSocketOptionRegistry.c
+++ b/jdk/src/share/native/sun/nio/ch/genSocketOptionRegistry.c
@@ -28,6 +28,7 @@
 #include <winsock2.h>
 #include <ws2tcpip.h>
 #else
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
diff --git a/jdk/src/share/native/sun/security/ec/impl/ecc_impl.h b/jdk/src/share/native/sun/security/ec/impl/ecc_impl.h
index 9fb8875..8eaa6e8 100644
--- a/jdk/src/share/native/sun/security/ec/impl/ecc_impl.h
+++ b/jdk/src/share/native/sun/security/ec/impl/ecc_impl.h
@@ -57,6 +57,14 @@
 typedef enum { B_FALSE, B_TRUE } boolean_t;
 #endif /* __linux__ */
 
+#ifdef _ALLBSD_SOURCE
+#include <stdint.h>
+#define B_FALSE FALSE
+#define B_TRUE TRUE
+typedef unsigned long ulong_t;
+typedef enum boolean { B_FALSE, B_TRUE } boolean_t;
+#endif /* _ALLBSD_SOURCE */
+
 #ifdef _WIN32
 typedef unsigned char uint8_t;
 typedef unsigned long ulong_t;
diff --git a/jdk/src/share/native/sun/security/ec/impl/ecdecode.c b/jdk/src/share/native/sun/security/ec/impl/ecdecode.c
index cd72a02..8e219c4 100644
--- a/jdk/src/share/native/sun/security/ec/impl/ecdecode.c
+++ b/jdk/src/share/native/sun/security/ec/impl/ecdecode.c
@@ -39,9 +39,9 @@
 #include <sys/types.h>
 
 #ifndef _WIN32
-#ifndef __linux__
+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
 #include <sys/systm.h>
-#endif /* __linux__ */
+#endif /* __linux__ || _ALLBSD_SOURCE */
 #include <sys/param.h>
 #endif /* _WIN32 */
 
diff --git a/jdk/src/share/native/sun/security/ec/impl/oid.c b/jdk/src/share/native/sun/security/ec/impl/oid.c
index 8682025..04e0a9b 100644
--- a/jdk/src/share/native/sun/security/ec/impl/oid.c
+++ b/jdk/src/share/native/sun/security/ec/impl/oid.c
@@ -38,9 +38,9 @@
 #include <sys/types.h>
 
 #ifndef _WIN32
-#ifndef __linux__
+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
 #include <sys/systm.h>
-#endif /* __linux__ */
+#endif /* __linux__ || _ALLBSD_SOURCE */
 #include <sys/param.h>
 #endif /* _WIN32 */
 
diff --git a/jdk/src/share/native/sun/security/ec/impl/secitem.c b/jdk/src/share/native/sun/security/ec/impl/secitem.c
index f296ce4..48a9996 100644
--- a/jdk/src/share/native/sun/security/ec/impl/secitem.c
+++ b/jdk/src/share/native/sun/security/ec/impl/secitem.c
@@ -43,9 +43,9 @@
 #include <sys/types.h>
 
 #ifndef _WIN32
-#ifndef __linux__
+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
 #include <sys/systm.h>
-#endif /* __linux__ */
+#endif /* __linux__ || _ALLBSD_SOURCE */
 #include <sys/param.h>
 #endif /* _WIN32 */
 
diff --git a/jdk/src/share/transport/socket/socketTransport.c b/jdk/src/share/transport/socket/socketTransport.c
index b2a2155..4c04918 100644
--- a/jdk/src/share/transport/socket/socketTransport.c
+++ b/jdk/src/share/transport/socket/socketTransport.c
@@ -65,6 +65,9 @@
 #define HEADER_SIZE     11
 #define MAX_DATA_SIZE 1000
 
+static jint recv_fully(int, char *, int);
+static jint send_fully(int, char *, int);
+
 /*
  * Record the last error for this thread.
  */
@@ -155,7 +158,7 @@
         }
         buf = b;
         buf += received;
-        n = dbgsysRecv(fd, buf, helloLen-received, 0);
+        n = recv_fully(fd, buf, helloLen-received);
         if (n == 0) {
             setLastError(0, "handshake failed - connection prematurally closed");
             return JDWPTRANSPORT_ERROR_IO_ERROR;
@@ -180,7 +183,7 @@
         return JDWPTRANSPORT_ERROR_IO_ERROR;
     }
 
-    if (dbgsysSend(fd, (char*)hello, helloLen, 0) != helloLen) {
+    if (send_fully(fd, (char*)hello, helloLen) != helloLen) {
         RETURN_IO_ERROR("send failed during handshake");
     }
     return JDWPTRANSPORT_ERROR_NONE;
@@ -555,19 +558,19 @@
     /* Do one send for short packets, two for longer ones */
     if (data_len <= MAX_DATA_SIZE) {
         memcpy(header + HEADER_SIZE, data, data_len);
-        if (dbgsysSend(socketFD, (char *)&header, HEADER_SIZE + data_len, 0) !=
+        if (send_fully(socketFD, (char *)&header, HEADER_SIZE + data_len) !=
             HEADER_SIZE + data_len) {
             RETURN_IO_ERROR("send failed");
         }
     } else {
         memcpy(header + HEADER_SIZE, data, MAX_DATA_SIZE);
-        if (dbgsysSend(socketFD, (char *)&header, HEADER_SIZE + MAX_DATA_SIZE, 0) !=
+        if (send_fully(socketFD, (char *)&header, HEADER_SIZE + MAX_DATA_SIZE) !=
             HEADER_SIZE + MAX_DATA_SIZE) {
             RETURN_IO_ERROR("send failed");
         }
         /* Send the remaining data bytes right out of the data area. */
-        if (dbgsysSend(socketFD, (char *)data + MAX_DATA_SIZE,
-                       data_len - MAX_DATA_SIZE, 0) != data_len - MAX_DATA_SIZE) {
+        if (send_fully(socketFD, (char *)data + MAX_DATA_SIZE,
+                       data_len - MAX_DATA_SIZE) != data_len - MAX_DATA_SIZE) {
             RETURN_IO_ERROR("send failed");
         }
     }
@@ -591,6 +594,22 @@
     return nbytes;
 }
 
+jint
+send_fully(int f, char *buf, int len)
+{
+    int nbytes = 0;
+    while (nbytes < len) {
+        int res = dbgsysSend(f, buf + nbytes, len - nbytes, 0);
+        if (res < 0) {
+            return res;
+        } else if (res == 0) {
+            break; /* eof, return nbytes which is less than len */
+        }
+        nbytes += res;
+    }
+    return nbytes;
+}
+
 static jdwpTransportError JNICALL
 socketTransport_readPacket(jdwpTransportEnv* env, jdwpPacket* packet) {
     jint length, data_len;
diff --git a/jdk/src/solaris/back/exec_md.c b/jdk/src/solaris/back/exec_md.c
index 1599e51..d5e9bd1 100644
--- a/jdk/src/solaris/back/exec_md.c
+++ b/jdk/src/solaris/back/exec_md.c
@@ -30,7 +30,7 @@
 #include "sys.h"
 #include "util.h"
 
-#ifdef LINUX
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
   /* Linux */
   #define FORK() fork()
 #else
diff --git a/jdk/src/solaris/back/linker_md.c b/jdk/src/solaris/back/linker_md.c
index 2a9af79..efc09b0 100644
--- a/jdk/src/solaris/back/linker_md.c
+++ b/jdk/src/solaris/back/linker_md.c
@@ -48,6 +48,12 @@
 #include "threads_md.h"
 #endif
 
+#ifdef __APPLE__
+#define LIB_SUFFIX "dylib"
+#else
+#define LIB_SUFFIX "so"
+#endif
+
 /*
  * create a string for the JNI native function name by adding the
  * appropriate decorations.
@@ -77,9 +83,9 @@
     }
 
     if (pnamelen == 0) {
-        (void)snprintf(holder, holderlen, "lib%s.so", fname);
+        (void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname);
     } else {
-        (void)snprintf(holder, holderlen, "%s/lib%s.so", pname, fname);
+        (void)snprintf(holder, holderlen, "%s/lib%s." LIB_SUFFIX, pname, fname);
     }
 }
 
diff --git a/jdk/src/solaris/back/util_md.h b/jdk/src/solaris/back/util_md.h
index 7a3bc83..f8521b3 100644
--- a/jdk/src/solaris/back/util_md.h
+++ b/jdk/src/solaris/back/util_md.h
@@ -31,6 +31,11 @@
 
 #include <limits.h>
 #include <sys/types.h>
+#ifdef _ALLBSD_SOURCE
+#include <machine/endian.h>
+#elif __linux__
+#include <endian.h>
+#endif
 
 #ifdef _LP64
 typedef unsigned long UNSIGNED_JLONG;
diff --git a/jdk/src/solaris/bin/ergo.c b/jdk/src/solaris/bin/ergo.c
index 2047087..abaddf8 100644
--- a/jdk/src/solaris/bin/ergo.c
+++ b/jdk/src/solaris/bin/ergo.c
@@ -100,14 +100,39 @@
 /* Compute physical memory by asking the OS */
 uint64_t
 physical_memory(void) {
+  uint64_t result;
+
+# define UINT64_FORMAT "%" PRIu64
+
+#if defined(_ALLBSD_SOURCE)
+#ifdef HW_PHYSMEM64
+  int64_t physmem;
+  int name[2] = { CTL_HW, HW_PHYSMEM64 };
+#else
+  unsigned long physmem;
+  int name[2] = { CTL_HW, HW_PHYSMEM };
+#endif
+  size_t physmem_len = sizeof(physmem);
+
+  if (sysctl(name, 2, &physmem, &physmem_len, NULL, 0) == -1)
+        physmem = 256 * MB;
+
+  result = (uint64_t)physmem;
+
+  JLI_TraceLauncher("physical memory: " UINT64_FORMAT " (%.3fGB)\n",
+           result, result / (double) GB);
+  return result;
+
+#else /* !_ALLBSD_SOURCE */
+
   const uint64_t pages     = (uint64_t) sysconf(_SC_PHYS_PAGES);
   const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
-  const uint64_t result    = pages * page_size;
-# define UINT64_FORMAT "%" PRIu64
+  result    = pages * page_size;
 
   JLI_TraceLauncher("pages: " UINT64_FORMAT
           "  page_size: " UINT64_FORMAT
           "  physical memory: " UINT64_FORMAT " (%.3fGB)\n",
            pages, page_size, result, result / (double) GB);
   return result;
+#endif /* _ALLBSD_SOURCE */
 }
diff --git a/jdk/src/solaris/bin/ergo.h b/jdk/src/solaris/bin/ergo.h
index 4f146e0..5e12923 100644
--- a/jdk/src/solaris/bin/ergo.h
+++ b/jdk/src/solaris/bin/ergo.h
@@ -33,6 +33,10 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <sys/types.h>
+#ifdef _ALLBSD_SOURCE
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
 
 #include "java.h"
 
diff --git a/jdk/src/solaris/bin/ergo_i586.c b/jdk/src/solaris/bin/ergo_i586.c
index f242170..9a2474d 100644
--- a/jdk/src/solaris/bin/ergo_i586.c
+++ b/jdk/src/solaris/bin/ergo_i586.c
@@ -106,7 +106,7 @@
 
 #endif /* __solaris__ */
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 
 /*
  * A utility method for asking the CPU about itself.
@@ -170,7 +170,9 @@
   *edxp = value_of_edx;
 #endif /* _LP64 */
 }
+#endif /* __linux__ || _ALLBSD_SOURCE */
 
+#ifdef __linux__
 /* The definition of a server-class machine for linux-i586 */
 jboolean
 ServerClassMachineImpl(void) {
@@ -199,6 +201,37 @@
 }
 #endif /* __linux__ */
 
+#if defined(_ALLBSD_SOURCE)
+
+/* The definition of a server-class machine for bsd-i586 */
+jboolean
+ServerClassMachineImpl(void) {
+  jboolean            result            = JNI_FALSE;
+  /* How big is a server class machine? */
+  const unsigned long server_processors = 2UL;
+  const uint64_t      server_memory     = 2UL * GB;
+  /*
+   * We seem not to get our full complement of memory.
+   *     We allow some part (1/8?) of the memory to be "missing",
+   *     based on the sizes of DIMMs, and maybe graphics cards.
+   */
+  const uint64_t      missing_memory    = 256UL * MB;
+  const uint64_t      actual_memory     = physical_memory();
+
+  /* Is this a server class machine? */
+  if (actual_memory >= (server_memory - missing_memory)) {
+    const unsigned long actual_processors = physical_processors();
+    if (actual_processors >= server_processors) {
+      result = JNI_TRUE;
+    }
+  }
+  JLI_TraceLauncher("bsd_" LIBARCHNAME "_ServerClassMachine: %s\n",
+           (result == JNI_TRUE ? "true" : "false"));
+  return result;
+}
+
+#endif /* _ALLBSD_SOURCE */
+
 /*
  * Routines shared by solaris-i586 and linux-i586.
  */
@@ -308,6 +341,14 @@
 /* Compute the number of physical processors, not logical processors */
 static unsigned long
 physical_processors(void) {
+#if defined(_ALLBSD_SOURCE)
+  unsigned long result;
+  int name[2] = { CTL_HW, HW_NCPU };
+  size_t rlen = sizeof(result);
+
+  if (sysctl(name, 2, &result, &rlen, NULL, 0) == -1)
+        result = 1;
+#else /* !_ALLBSD_SOURCE */
   const long sys_processors = sysconf(_SC_NPROCESSORS_CONF);
   unsigned long result      = sys_processors;
 
@@ -318,6 +359,7 @@
       result = (unsigned long) sys_processors / logical_processors;
     }
   }
+#endif /* _ALLBSD_SOURCE */
   JLI_TraceLauncher("physical processors: %lu\n", result);
   return result;
 }
diff --git a/jdk/src/solaris/bin/java_md.c b/jdk/src/solaris/bin/java_md.c
index 361454f..755b6d9 100644
--- a/jdk/src/solaris/bin/java_md.c
+++ b/jdk/src/solaris/bin/java_md.c
@@ -24,6 +24,7 @@
  */
 
 #include "java.h"
+#include "jvm_md.h"
 #include <dirent.h>
 #include <dlfcn.h>
 #include <fcntl.h>
@@ -34,20 +35,47 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <sys/types.h>
+#if defined(_ALLBSD_SOURCE)
+#include <sys/time.h>
+#endif
+
 #include "manifest_info.h"
 #include "version_comp.h"
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <pthread.h>
 #else
 #include <thread.h>
 #endif
 
+#ifdef MACOSX
+/* Support Cocoa event loop on the main thread */
+#include <Cocoa/Cocoa.h>
+#include <objc/objc-runtime.h>
+#include <objc/objc-auto.h>
+#include <errno.h>
+#include <spawn.h>
+
+struct NSAppArgs {
+    int argc;
+    char **argv;
+};
+#endif
+
+#ifdef MACOSX
+#define JVM_DLL "libjvm.dylib"
+#define JAVA_DLL "libjava.dylib"
+/* FALLBACK avoids naming conflicts with system libraries
+ * (eg, ImageIO's libJPEG.dylib) */
+#define LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH"
+#else
 #define JVM_DLL "libjvm.so"
 #define JAVA_DLL "libjava.so"
+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
+#endif
 
 /* help jettison the LD_LIBRARY_PATH settings in the future */
-#ifndef SETENV_REQUIRED
+#if !defined(SETENV_REQUIRED) && !defined(MACOSX)
 #define SETENV_REQUIRED
 #endif
 /*
@@ -75,18 +103,26 @@
 #endif
 
 /* pointer to environment */
+#ifdef MACOSX
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#else
 extern char **environ;
+#endif
 
 /*
  *      A collection of useful strings. One should think of these as #define
  *      entries, but actual strings can be more efficient (with many compilers).
  */
-#ifdef __linux__
+#if defined(__linux__)
 static const char *system_dir   = "/usr/java";
 static const char *user_dir     = "/java";
-#else /* Solaris */
+#elif defined (__solaris__)
 static const char *system_dir   = "/usr/jdk";
 static const char *user_dir     = "/jdk";
+#elif defined(__APPLE__)
+static const char *system_dir  = PACKAGE_PATH "/openjdk7";
+static const char *user_dir    = "/java";
 #endif
 
 /* Store the name of the executable once computed */
@@ -212,7 +248,7 @@
 
 static const char * SetExecname(char **argv);
 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
-                           char *jvmpath, jint jvmpathsize, const char * arch);
+                           char *jvmpath, jint jvmpathsize, const char * arch, int bitsWanted);
 static jboolean GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative);
 
 
@@ -233,6 +269,176 @@
     }
 }
 
+#ifdef MACOSX
+
+/*
+ * Exports the JNI interface from libjli
+ *
+ * This allows client code to link against the .jre/.jdk bundles,
+ * and not worry about trying to pick a HotSpot to link against.
+ *
+ * Switching architectures is unsupported, since client code has
+ * made that choice before the JVM was requested.
+ */
+
+static InvocationFunctions *sExportedJNIFunctions = NULL;
+static char *sPreferredJVMType = NULL;
+
+static InvocationFunctions *GetExportedJNIFunctions() {
+    if (sExportedJNIFunctions != NULL) return sExportedJNIFunctions;
+
+    char jrePath[PATH_MAX];
+    jboolean gotJREPath = GetJREPath(jrePath, sizeof(jrePath), GetArch(), JNI_FALSE);
+    if (!gotJREPath) {
+        JLI_ReportErrorMessage("Failed to GetJREPath()");
+        return NULL;
+    }
+
+    char *preferredJVM = sPreferredJVMType;
+    if (preferredJVM == NULL) {
+#if defined(__i386__)
+        preferredJVM = "client";
+#elif defined(__x86_64__)
+        preferredJVM = "server";
+#else
+#error "Unknown architecture - needs definition"
+#endif
+    }
+
+    char jvmPath[PATH_MAX];
+    jboolean gotJVMPath = GetJVMPath(jrePath, preferredJVM, jvmPath, sizeof(jvmPath), GetArch(), CURRENT_DATA_MODEL);
+    if (!gotJVMPath) {
+        JLI_ReportErrorMessage("Failed to GetJVMPath()");
+        return NULL;
+    }
+
+    InvocationFunctions *fxns = malloc(sizeof(InvocationFunctions));
+    jboolean vmLoaded = LoadJavaVM(jvmPath, fxns);
+    if (!vmLoaded) {
+        JLI_ReportErrorMessage("Failed to LoadJavaVM()");
+        return NULL;
+    }
+
+    return sExportedJNIFunctions = fxns;
+}
+
+JNIEXPORT jint JNICALL
+JNI_GetDefaultJavaVMInitArgs(void *args) {
+    InvocationFunctions *ifn = GetExportedJNIFunctions();
+    if (ifn == NULL) return JNI_ERR;
+    return ifn->GetDefaultJavaVMInitArgs(args);
+}
+
+JNIEXPORT jint JNICALL
+JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args) {
+    InvocationFunctions *ifn = GetExportedJNIFunctions();
+    if (ifn == NULL) return JNI_ERR;
+    return ifn->CreateJavaVM(pvm, penv, args);
+}
+
+JNIEXPORT jint JNICALL
+JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs) {
+    InvocationFunctions *ifn = GetExportedJNIFunctions();
+    if (ifn == NULL) return JNI_ERR;
+    return ifn->GetCreatedJavaVMs(vmBuf, bufLen, nVMs);
+}
+
+/*
+ * Allow JLI-aware launchers to specify a client/server preference
+ */
+JNIEXPORT void JNICALL
+JLI_SetPreferredJVM(const char *prefJVM) {
+    if (sPreferredJVMType != NULL) {
+        free(sPreferredJVMType);
+        sPreferredJVMType = NULL;
+    }
+
+    if (prefJVM == NULL) return;
+    sPreferredJVMType = strdup(prefJVM);
+}
+
+static BOOL awtLoaded = NO;
+static pthread_mutex_t awtLoaded_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t  awtLoaded_cv = PTHREAD_COND_INITIALIZER;
+
+JNIEXPORT void JNICALL
+JLI_NotifyAWTLoaded()
+{
+    pthread_mutex_lock(&awtLoaded_mutex);
+    awtLoaded = YES;
+    pthread_cond_signal(&awtLoaded_cv);
+    pthread_mutex_unlock(&awtLoaded_mutex);
+}
+
+static int (*main_fptr)(int argc, char **argv) = NULL;
+
+/*
+ * Unwrap the arguments and re-run main()
+ */
+static void *apple_main (void *arg)
+{
+    objc_registerThreadWithCollector();
+
+    if (main_fptr == NULL) {
+        main_fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
+        if (main_fptr == NULL) {
+            JLI_ReportErrorMessageSys("error locating main entrypoint\n");
+            exit(1);
+        }
+    }
+
+    struct NSAppArgs *args = (struct NSAppArgs *) arg;
+    exit(main_fptr(args->argc, args->argv));
+}
+
+static void dummyTimer(CFRunLoopTimerRef timer, void *info) {}
+
+static void ParkEventLoop() {
+    // RunLoop needs at least one source, and 1e20 is pretty far into the future
+    CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, 1.0e20, 0.0, 0, 0, dummyTimer, NULL);
+    CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode);
+    CFRelease(t);
+
+    // Park this thread in the main run loop.
+    int32_t result;
+    do {
+        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, false);
+    } while (result != kCFRunLoopRunFinished);
+}
+
+/*
+ * Mac OS X mandates that the GUI event loop run on very first thread of
+ * an application. This requires that we re-call Java's main() on a new
+ * thread, reserving the 'main' thread for Cocoa.
+ */
+static void MacOSXStartup(int argc, char *argv[]) {
+    // Thread already started?
+    static jboolean started = false;
+    if (started) {
+        return;
+    }
+    started = true;
+
+    // Hand off arguments
+    struct NSAppArgs args;
+    args.argc = argc;
+    args.argv = argv;
+
+    // Fire up the main thread
+    pthread_t main_thr;
+    if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
+        JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
+        exit(1);
+    }
+    if (pthread_detach(main_thr)) {
+        JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
+        exit(1);
+    }
+
+    ParkEventLoop();
+}
+
+#endif
 #ifdef SETENV_REQUIRED
 static jboolean
 JvmExists(const char *path) {
@@ -479,10 +685,19 @@
             exit(4);
         }
 
-        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) {
+        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, wanted)) {
           JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
           exit(4);
         }
+
+#ifdef MACOSX
+        /*
+         * Mac OS X requires the Cocoa event loop to be run on the "main"
+         * thread. Spawn off a new thread to run main() and pass
+         * this thread off to the Cocoa event loop.
+         */
+        MacOSXStartup(argc, argv);
+#endif
         /*
          * we seem to have everything we need, so without further ado
          * we return back, otherwise proceed to set the environment.
@@ -498,7 +713,7 @@
         return;
 #endif /* SETENV_REQUIRED */
       } else {  /* do the same speculatively or exit */
-#ifdef DUAL_MODE
+#if defined(DUAL_MODE) || defined(MACOSX)
         if (running != wanted) {
           /* Find out where the JRE is that we will be using. */
           if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
@@ -524,7 +739,7 @@
           }
 
           /* exec child can do error checking on the existence of the path */
-          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted));
+          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted), wanted);
 #ifdef SETENV_REQUIRED
           mustsetenv = RequiresSetenv(wanted, jvmpath);
 #endif /* SETENV_REQUIRED */
@@ -739,11 +954,38 @@
                 execv(newexec, argv);
             }
 #else
+#ifdef MACOSX
+            /*
+            * Use posix_spawn() instead of execv() on Mac OS X.
+            * This allows us to choose which architecture the child process
+            * should run as.
+            */
+            {
+                posix_spawnattr_t attr;
+                size_t unused_size;
+                pid_t  unused_pid;
+
+#if defined(__i386__) || defined(__x86_64__)
+                cpu_type_t cpu_type[] = { (wanted == 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86,
+                                    (running== 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86 };
+#else
+                cpu_type_t cpu_type[] = { CPU_TYPE_ANY };
+#endif
+
+                posix_spawnattr_init(&attr);
+                posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC);
+                posix_spawnattr_setbinpref_np(&attr, sizeof(cpu_type) / sizeof(cpu_type_t),
+                                            cpu_type, &unused_size);
+
+                posix_spawn(&unused_pid, newexec, NULL, &attr, argv, environ);
+            }
+#else
             execv(newexec, argv);
+#endif
 #endif /* SETENV_REQUIRED */
             JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
 
-#ifdef DUAL_MODE
+#if defined(DUAL_MODE) || defined(MACOSX)
             if (running != wanted) {
                 JLI_ReportErrorMessage(JRE_ERROR5, wanted, running);
 #ifdef __solaris__
@@ -752,8 +994,8 @@
 #else
                 JLI_ReportErrorMessage(JRE_ERROR7);
 #endif  /* __sparc */
-            }
 #endif /* __solaris__ */
+            }
 #endif /* DUAL_MODE */
 
         }
@@ -766,14 +1008,20 @@
  */
 static jboolean
 GetJVMPath(const char *jrepath, const char *jvmtype,
-           char *jvmpath, jint jvmpathsize, const char * arch)
+           char *jvmpath, jint jvmpathsize, const char * arch, int bitsWanted)
 {
     struct stat s;
 
     if (JLI_StrChr(jvmtype, '/')) {
         JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
     } else {
+#ifdef MACOSX
+        // macosx client library is built thin, i386 only.  64 bit client requests must load server library
+        const char *jvmtypeUsed = ((bitsWanted == 64) && (strcmp(jvmtype, "client") == 0)) ? "server" : jvmtype;
+        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/" JVM_DLL, jrepath, jvmtypeUsed);
+#else
         JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
+#endif
     }
 
     JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
@@ -796,6 +1044,22 @@
     char libjava[MAXPATHLEN];
 
     if (GetApplicationHome(path, pathsize)) {
+
+#ifdef MACOSX
+        /* Is JRE co-located with the application? */
+        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
+        if (access(libjava, F_OK) == 0) {
+            return JNI_TRUE;
+        }
+
+        /* Does the app ship a private JRE in <apphome>/jre directory? */
+        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/" JAVA_DLL, path);
+        if (access(libjava, F_OK) == 0) {
+            JLI_StrCat(path, "/jre");
+            JLI_TraceLauncher("JRE path is %s\n", path);
+            return JNI_TRUE;
+        }
+#else
         /* Is JRE co-located with the application? */
         JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch);
         if (access(libjava, F_OK) == 0) {
@@ -810,8 +1074,39 @@
             JLI_TraceLauncher("JRE path is %s\n", path);
             return JNI_TRUE;
         }
+#endif
     }
 
+#ifdef MACOSX
+
+    /* try to find ourselves instead */
+    Dl_info selfInfo;
+    dladdr(&GetJREPath, &selfInfo);
+
+    char *realPathToSelf = realpath(selfInfo.dli_fname, path);
+    if (realPathToSelf != path) {
+        return JNI_FALSE;
+    }
+
+    size_t pathLen = strlen(realPathToSelf);
+    if (pathLen == 0) {
+        return JNI_FALSE;
+    }
+
+    const char lastPathComponent[] = "/lib/jli/libjli.dylib";
+    size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
+    if (pathLen < sizeOfLastPathComponent) {
+        return JNI_FALSE;
+    }
+
+    size_t indexOfLastPathComponent = pathLen - sizeOfLastPathComponent;
+    if (0 == strncmp(realPathToSelf + indexOfLastPathComponent, lastPathComponent, sizeOfLastPathComponent - 1)) {
+        realPathToSelf[indexOfLastPathComponent + 1] = '\0';
+        return JNI_TRUE;
+    }
+
+#endif
+
     if (!speculative)
       JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
     return JNI_FALSE;
@@ -891,6 +1186,13 @@
         return JNI_FALSE;
     }
 
+    ifn->GetCreatedJavaVMs = (GetCreatedJavaVMs_t)
+    dlsym(libjvm, "JNI_GetCreatedJavaVMs");
+    if (ifn->GetCreatedJavaVMs == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
     return JNI_TRUE;
 }
 
@@ -1028,7 +1330,7 @@
 SetExecname(char **argv)
 {
     char* exec_path = NULL;
-#if defined(__solaris__)
+#if defined(__solaris__) || defined(__APPLE__)
     {
         Dl_info dlinfo;
         int (*fptr)();
@@ -1059,7 +1361,7 @@
             exec_path = JLI_StringDup(buf);
         }
     }
-#else /* !__solaris__ && !__linux */
+#else /* !__solaris__ && !__APPLE__ && !__linux__ */
     {
         /* Not implemented */
     }
@@ -1397,15 +1699,116 @@
     return(borrowed_unsetenv(name));
 }
 
+#if defined(_ALLBSD_SOURCE)
+/*
+ * BSD's implementation of CounterGet()
+ */
+int64_t
+CounterGet()
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return (tv.tv_sec * 1000) + tv.tv_usec;
+}
+#endif
+
+
 /* --- Splash Screen shared library support --- */
 
-static const char* SPLASHSCREEN_SO = "libsplashscreen.so";
+#ifdef MACOSX
+static JavaVM* SetJavaVMValue()
+{
+    JavaVM * jvm = NULL;
+
+    // The handle is good for both the launcher and the libosxapp.dylib
+    void * handle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
+    if (handle) {
+        typedef JavaVM* (*JLI_GetJavaVMInstance_t)();
+
+        JLI_GetJavaVMInstance_t JLI_GetJavaVMInstance =
+            (JLI_GetJavaVMInstance_t)dlsym(handle,
+                    "JLI_GetJavaVMInstance");
+        if (JLI_GetJavaVMInstance) {
+            jvm = JLI_GetJavaVMInstance();
+        }
+
+        if (jvm) {
+            typedef void (*OSXAPP_SetJavaVM_t)(JavaVM*);
+
+            OSXAPP_SetJavaVM_t OSXAPP_SetJavaVM =
+                (OSXAPP_SetJavaVM_t)dlsym(handle, "OSXAPP_SetJavaVM");
+            if (OSXAPP_SetJavaVM) {
+                OSXAPP_SetJavaVM(jvm);
+            } else {
+                jvm = NULL;
+            }
+        }
+
+        dlclose(handle);
+    }
+
+    return jvm;
+}
+#endif
+
+static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
 
 static void* hSplashLib = NULL;
 
 void* SplashProcAddress(const char* name) {
     if (!hSplashLib) {
-        hSplashLib = dlopen(SPLASHSCREEN_SO, RTLD_LAZY | RTLD_GLOBAL);
+        const char * splashLibPath;
+
+#ifndef MACOSX
+        splashLibPath = SPLASHSCREEN_SO;
+#else
+        char path[PATH_MAX];
+        Dl_info dli;
+
+        path[0] = 0;
+        if (dladdr(&SplashProcAddress, &dli)) {
+            // This is always reported as <path>/bin/java* (java or javaw, whatever)
+            char * realPath = realpath(dli.dli_fname, path);
+
+            if (realPath != path) {
+                path[0] = 0;
+            } else {
+                // chop off the "/bin/java*" part...
+                char * c = strrchr(path, '/');
+
+                if (!c) {
+                    path[0] = 0;
+                } else {
+                    *c = 0;
+                    c = strrchr(path, '/');
+
+                    if (!c) {
+                        path[0] = 0;
+                    } else {
+                        *c = 0;
+                        // ...and add the lib path instead
+                        snprintf(c, sizeof(path)-strlen(path), "/lib/%s", SPLASHSCREEN_SO);
+                    }
+                }
+            }
+        }
+
+        if (path[0]) {
+            splashLibPath = path;
+        } else {
+            // try our best, but most probably this will fail to load
+            splashLibPath = SPLASHSCREEN_SO;
+        }
+#endif
+        hSplashLib = dlopen(splashLibPath, RTLD_LAZY | RTLD_GLOBAL);
+#ifdef MACOSX
+        if (hSplashLib) {
+            if (!SetJavaVMValue()) {
+                dlclose(hSplashLib);
+                hSplashLib = NULL;
+            }
+        }
+#endif
     }
     if (hSplashLib) {
         void* sym = dlsym(hSplashLib, name);
@@ -1435,7 +1838,7 @@
 int
 ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
     int rslt;
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(__APPLE__)
     pthread_t tid;
     pthread_attr_t attr;
     pthread_attr_init(&attr);
diff --git a/jdk/src/solaris/bin/java_md.h b/jdk/src/solaris/bin/java_md.h
index cc72740..391fe64 100644
--- a/jdk/src/solaris/bin/java_md.h
+++ b/jdk/src/solaris/bin/java_md.h
@@ -47,10 +47,14 @@
 #include <sys/time.h>
 #define CounterGet()              (gethrtime()/1000)
 #define Counter2Micros(counts)    (counts)
+#elif defined(_ALLBSD_SOURCE)
+/* CounterGet() is implemented in java_md.c */
+int64_t CounterGet(void);
+#define Counter2Micros(counts)    (counts)
 #else
 #define CounterGet()              (0)
 #define Counter2Micros(counts)    (1)
-#endif /* HAVE_GETHRTIME */
+#endif /* HAVE_GETHRTIME || _ALLBSD_SOURCE */
 
 /*
  * Function prototypes.
diff --git a/jdk/src/solaris/bin/universal/jvm.cfg b/jdk/src/solaris/bin/universal/jvm.cfg
new file mode 100644
index 0000000..8301d83
--- /dev/null
+++ b/jdk/src/solaris/bin/universal/jvm.cfg
@@ -0,0 +1,38 @@
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+# List of JVMs that can be used as an option to java, javac, etc.
+# Order is important -- first in this list is the default JVM.
+# NOTE that this both this file and its format are UNSUPPORTED and
+# WILL GO AWAY in a future release.
+#
+# You may also select a JVM in an arbitrary location with the
+# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
+# and may not be available in a future release.
+#
+-server KNOWN
+-client KNOWN
+-hotspot ERROR
+-classic WARN
+-native ERROR
+-green ERROR
diff --git a/jdk/src/solaris/classes/java/lang/UNIXProcess.java.bsd b/jdk/src/solaris/classes/java/lang/UNIXProcess.java.bsd
new file mode 100644
index 0000000..4093908
--- /dev/null
+++ b/jdk/src/solaris/classes/java/lang/UNIXProcess.java.bsd
@@ -0,0 +1,318 @@
+/*
+ * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.lang;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadFactory;
+import java.security.AccessController;
+import static java.security.AccessController.doPrivileged;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * java.lang.Process subclass in the UNIX environment.
+ *
+ * @author Mario Wolczko and Ross Knippel.
+ * @author Konstantin Kladko (ported to Bsd)
+ * @author Martin Buchholz
+ */
+final class UNIXProcess extends Process {
+    private static final sun.misc.JavaIOFileDescriptorAccess fdAccess
+        = sun.misc.SharedSecrets.getJavaIOFileDescriptorAccess();
+
+    private final int pid;
+    private int exitcode;
+    private boolean hasExited;
+
+    private /* final */ OutputStream stdin;
+    private /* final */ InputStream  stdout;
+    private /* final */ InputStream  stderr;
+
+    /* this is for the reaping thread */
+    private native int waitForProcessExit(int pid);
+
+    /**
+     * Create a process using fork(2) and exec(2).
+     *
+     * @param fds an array of three file descriptors.
+     *        Indexes 0, 1, and 2 correspond to standard input,
+     *        standard output and standard error, respectively.  On
+     *        input, a value of -1 means to create a pipe to connect
+     *        child and parent processes.  On output, a value which
+     *        is not -1 is the parent pipe fd corresponding to the
+     *        pipe which has been created.  An element of this array
+     *        is -1 on input if and only if it is <em>not</em> -1 on
+     *        output.
+     * @return the pid of the subprocess
+     */
+    private native int forkAndExec(byte[] prog,
+                                   byte[] argBlock, int argc,
+                                   byte[] envBlock, int envc,
+                                   byte[] dir,
+                                   int[] fds,
+                                   boolean redirectErrorStream)
+        throws IOException;
+
+    /**
+     * The thread factory used to create "process reaper" daemon threads.
+     */
+    private static class ProcessReaperThreadFactory implements ThreadFactory {
+        private final static ThreadGroup group = getRootThreadGroup();
+
+        private static ThreadGroup getRootThreadGroup() {
+            return doPrivileged(new PrivilegedAction<ThreadGroup> () {
+                public ThreadGroup run() {
+                    ThreadGroup root = Thread.currentThread().getThreadGroup();
+                    while (root.getParent() != null)
+                        root = root.getParent();
+                    return root;
+                }});
+        }
+
+        public Thread newThread(Runnable grimReaper) {
+            // Our thread stack requirement is quite modest.
+            Thread t = new Thread(group, grimReaper, "process reaper", 32768);
+            t.setDaemon(true);
+            // A small attempt (probably futile) to avoid priority inversion
+            t.setPriority(Thread.MAX_PRIORITY);
+            return t;
+        }
+    }
+
+    /**
+     * The thread pool of "process reaper" daemon threads.
+     */
+    private static final Executor processReaperExecutor =
+        doPrivileged(new PrivilegedAction<Executor>() {
+            public Executor run() {
+                return Executors.newCachedThreadPool
+                    (new ProcessReaperThreadFactory());
+            }});
+
+    UNIXProcess(final byte[] prog,
+                final byte[] argBlock, final int argc,
+                final byte[] envBlock, final int envc,
+                final byte[] dir,
+                final int[] fds,
+                final boolean redirectErrorStream)
+            throws IOException {
+
+        pid = forkAndExec(prog,
+                          argBlock, argc,
+                          envBlock, envc,
+                          dir,
+                          fds,
+                          redirectErrorStream);
+
+        try {
+            doPrivileged(new PrivilegedExceptionAction<Void>() {
+                public Void run() throws IOException {
+                    initStreams(fds);
+                    return null;
+                }});
+        } catch (PrivilegedActionException ex) {
+            throw (IOException) ex.getException();
+        }
+    }
+
+    static FileDescriptor newFileDescriptor(int fd) {
+        FileDescriptor fileDescriptor = new FileDescriptor();
+        fdAccess.set(fileDescriptor, fd);
+        return fileDescriptor;
+    }
+
+    void initStreams(int[] fds) throws IOException {
+        stdin = (fds[0] == -1) ?
+            ProcessBuilder.NullOutputStream.INSTANCE :
+            new ProcessPipeOutputStream(fds[0]);
+
+        stdout = (fds[1] == -1) ?
+            ProcessBuilder.NullInputStream.INSTANCE :
+            new ProcessPipeInputStream(fds[1]);
+
+        stderr = (fds[2] == -1) ?
+            ProcessBuilder.NullInputStream.INSTANCE :
+            new ProcessPipeInputStream(fds[2]);
+
+        processReaperExecutor.execute(new Runnable() {
+            public void run() {
+                int exitcode = waitForProcessExit(pid);
+                UNIXProcess.this.processExited(exitcode);
+            }});
+    }
+
+    void processExited(int exitcode) {
+        synchronized (this) {
+            this.exitcode = exitcode;
+            hasExited = true;
+            notifyAll();
+        }
+
+        if (stdout instanceof ProcessPipeInputStream)
+            ((ProcessPipeInputStream) stdout).processExited();
+
+        if (stderr instanceof ProcessPipeInputStream)
+            ((ProcessPipeInputStream) stderr).processExited();
+
+        if (stdin instanceof ProcessPipeOutputStream)
+            ((ProcessPipeOutputStream) stdin).processExited();
+    }
+
+    public OutputStream getOutputStream() {
+        return stdin;
+    }
+
+    public InputStream getInputStream() {
+        return stdout;
+    }
+
+    public InputStream getErrorStream() {
+        return stderr;
+    }
+
+    public synchronized int waitFor() throws InterruptedException {
+        while (!hasExited) {
+            wait();
+        }
+        return exitcode;
+    }
+
+    public synchronized int exitValue() {
+        if (!hasExited) {
+            throw new IllegalThreadStateException("process hasn't exited");
+        }
+        return exitcode;
+    }
+
+    private static native void destroyProcess(int pid);
+    public void destroy() {
+        // There is a risk that pid will be recycled, causing us to
+        // kill the wrong process!  So we only terminate processes
+        // that appear to still be running.  Even with this check,
+        // there is an unavoidable race condition here, but the window
+        // is very small, and OSes try hard to not recycle pids too
+        // soon, so this is quite safe.
+        synchronized (this) {
+            if (!hasExited)
+                destroyProcess(pid);
+        }
+        try { stdin.close();  } catch (IOException ignored) {}
+        try { stdout.close(); } catch (IOException ignored) {}
+        try { stderr.close(); } catch (IOException ignored) {}
+    }
+
+    /* This routine initializes JNI field offsets for the class */
+    private static native void initIDs();
+
+    static {
+        initIDs();
+    }
+
+    /**
+     * A buffered input stream for a subprocess pipe file descriptor
+     * that allows the underlying file descriptor to be reclaimed when
+     * the process exits, via the processExited hook.
+     *
+     * This is tricky because we do not want the user-level InputStream to be
+     * closed until the user invokes close(), and we need to continue to be
+     * able to read any buffered data lingering in the OS pipe buffer.
+     */
+    static class ProcessPipeInputStream extends BufferedInputStream {
+        ProcessPipeInputStream(int fd) {
+            super(new FileInputStream(newFileDescriptor(fd)));
+        }
+
+        private static byte[] drainInputStream(InputStream in)
+                throws IOException {
+            if (in == null) return null;
+            int n = 0;
+            int j;
+            byte[] a = null;
+            while ((j = in.available()) > 0) {
+                a = (a == null) ? new byte[j] : Arrays.copyOf(a, n + j);
+                n += in.read(a, n, j);
+            }
+            return (a == null || n == a.length) ? a : Arrays.copyOf(a, n);
+        }
+
+        /** Called by the process reaper thread when the process exits. */
+        synchronized void processExited() {
+            // Most BufferedInputStream methods are synchronized, but close()
+            // is not, and so we have to handle concurrent racing close().
+            try {
+                InputStream in = this.in;
+                if (in != null) {
+                    byte[] stragglers = drainInputStream(in);
+                    in.close();
+                    this.in = (stragglers == null) ?
+                        ProcessBuilder.NullInputStream.INSTANCE :
+                        new ByteArrayInputStream(stragglers);
+                    if (buf == null) // asynchronous close()?
+                        this.in = null;
+                }
+            } catch (IOException ignored) {
+                // probably an asynchronous close().
+            }
+        }
+    }
+
+    /**
+     * A buffered output stream for a subprocess pipe file descriptor
+     * that allows the underlying file descriptor to be reclaimed when
+     * the process exits, via the processExited hook.
+     */
+    static class ProcessPipeOutputStream extends BufferedOutputStream {
+        ProcessPipeOutputStream(int fd) {
+            super(new FileOutputStream(newFileDescriptor(fd)));
+        }
+
+        /** Called by the process reaper thread when the process exits. */
+        synchronized void processExited() {
+            OutputStream out = this.out;
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException ignored) {
+                    // We know of no reason to get an IOException, but if
+                    // we do, there's nothing else to do but carry on.
+                }
+                this.out = ProcessBuilder.NullOutputStream.INSTANCE;
+            }
+        }
+    }
+}
diff --git a/jdk/src/solaris/classes/java/net/DefaultInterface.java b/jdk/src/solaris/classes/java/net/DefaultInterface.java
new file mode 100644
index 0000000..9f4dfe1
--- /dev/null
+++ b/jdk/src/solaris/classes/java/net/DefaultInterface.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.net;
+
+/**
+ * Choose a network inteface to be the default for
+ * outgoing IPv6 traffic that does not specify a scope_id (and which needs one).
+ *
+ * Platforms that do not require a default interface may return null
+ * which is what this implementation does.
+ */
+
+class DefaultInterface {
+
+    static NetworkInterface getDefault() {
+        return null;
+    }
+}
diff --git a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java
index 37126c7..8aa4e22 100644
--- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java
+++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java
@@ -475,12 +475,16 @@
         if (true) {
             switch(e.getID()) {
               case PaintEvent.UPDATE:
-                  log.finer("XCP coalescePaintEvent : UPDATE : add : x = " +
+                  if (log.isLoggable(PlatformLogger.FINER)) {
+                      log.finer("XCP coalescePaintEvent : UPDATE : add : x = " +
                             r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
+                  }
                   return;
               case PaintEvent.PAINT:
-                  log.finer("XCP coalescePaintEvent : PAINT : add : x = " +
+                  if (log.isLoggable(PlatformLogger.FINER)) {
+                      log.finer("XCP coalescePaintEvent : PAINT : add : x = " +
                             r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
+                  }
                   return;
             }
         }
@@ -1257,7 +1261,9 @@
      * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify
      */
     protected boolean isEventDisabled(XEvent e) {
-        enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable"));
+        if (enableLog.isLoggable(PlatformLogger.FINEST)) {
+            enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable"));
+        }
         if (!isEnabled()) {
             switch (e.get_type()) {
               case XConstants.ButtonPress:
@@ -1267,7 +1273,9 @@
               case XConstants.EnterNotify:
               case XConstants.LeaveNotify:
               case XConstants.MotionNotify:
-                  enableLog.finer("Event {0} is disable", e);
+                  if (enableLog.isLoggable(PlatformLogger.FINER)) {
+                      enableLog.finer("Event {0} is disable", e);
+                  }
                   return true;
             }
         }
diff --git a/jdk/src/solaris/classes/sun/awt/X11/XWM.java b/jdk/src/solaris/classes/sun/awt/X11/XWM.java
index 2d4067a..f25080f 100644
--- a/jdk/src/solaris/classes/sun/awt/X11/XWM.java
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWM.java
@@ -101,7 +101,8 @@
         ICE_WM = 10,
         METACITY_WM = 11,
         COMPIZ_WM = 12,
-        LG3D_WM = 13;
+        LG3D_WM = 13,
+        CWM_WM = 14;
     public String toString() {
         switch  (WMID) {
           case NO_WM:
@@ -128,6 +129,8 @@
               return "Compiz";
           case LG3D_WM:
               return "LookingGlass";
+          case CWM_WM:
+              return "CWM";
           case UNDETERMINED_WM:
           default:
               return "Undetermined WM";
@@ -555,6 +558,10 @@
         return isNetWMName("LG3D");
     }
 
+    static boolean isCWM() {
+        return isNetWMName("CWM");
+    }
+
     /*
      * Is Metacity running?
      */
@@ -567,7 +574,7 @@
     }
 
     static boolean isNonReparentingWM() {
-        return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM);
+        return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM || XWM.getWMID() == XWM.CWM_WM);
     }
 
     /*
@@ -743,6 +750,8 @@
                 awt_wmgr = XWM.COMPIZ_WM;
             } else if (isLookingGlass()) {
                 awt_wmgr = LG3D_WM;
+            } else if (isCWM()) {
+                awt_wmgr = CWM_WM;
             } else if (doIsIceWM && isIceWM()) {
                 awt_wmgr = XWM.ICE_WM;
             }
diff --git a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java
index 395dbcd..9d7daf0 100644
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java
@@ -208,12 +208,19 @@
         return name;
     }
 
+    private static native String getLocalHostname();
+    private static native int getJvmPID();
+
     void postInit(XCreateWindowParams params) {
         super.postInit(params);
 
         // Init WM_PROTOCOLS atom
         initWMProtocols();
 
+        // Set _NET_WM_PID and WM_CLIENT_MACHINE using this JVM
+        XAtom.get("WM_CLIENT_MACHINE").setProperty(getWindow(), getLocalHostname());
+        XAtom.get("_NET_WM_PID").setCard32Property(getWindow(), getJvmPID());
+
         // Set WM_TRANSIENT_FOR and group_leader
         Window t_window = (Window)target;
         Window owner = t_window.getOwner();
diff --git a/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java b/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java
index 272fda8..7ad7386 100644
--- a/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java
+++ b/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java
@@ -678,7 +678,7 @@
     public void writeToString(StructType stp, PrintWriter pw) {
         int type;
         pw.println("\n\n\tString getName() {\n\t\treturn \"" + stp.getName()+ "\"; \n\t}");
-        pw.println("\n\n\tString getFieldsAsString() {\n\t\tString ret=\"\";\n");
+        pw.println("\n\n\tString getFieldsAsString() {\n\t\tStringBuilder ret = new StringBuilder(" + stp.getNumFields() * 40 + ");\n");
 
         for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) {
             AtomicType tp = (AtomicType) e.nextElement();
@@ -688,24 +688,24 @@
             if ((name != null) && (name.length() > 0))
             {
                 if (type == AtomicType.TYPE_ATOM) {
-                    pw.println("\t\tret += \"\"+\"" + name + " = \" + XAtom.get(get_" + name + "()) +\", \";");
+                    pw.println("\t\tret.append(\"" + name + " = \" ).append( XAtom.get(get_" + name + "()) ).append(\", \");");
                 } else if (name.equals("type")) {
-                    pw.println("\t\tret += \"\"+\"type = \" + XlibWrapper.eventToString[get_type()] +\", \";");
+                    pw.println("\t\tret.append(\"type = \").append( XlibWrapper.eventToString[get_type()] ).append(\", \");");
                 } else if (name.equals("window")){
-                    pw.println("\t\tret += \"\"+\"window = \" + getWindow(get_window()) + \", \";");
+                    pw.println("\t\tret.append(\"window = \" ).append( getWindow(get_window()) ).append(\", \");");
                 } else if (type == AtomicType.TYPE_ARRAY) {
-                    pw.print("\t\tret += \"{\"");
+                    pw.print("\t\tret.append(\"{\")");
                     for (int i = 0; i < tp.getArrayLength(); i++) {
-                        pw.print(" + get_" + name + "(" + i + ") + \" \"");
+                        pw.print("\n\t\t.append( get_" + name + "(" + i + ") ).append(\" \")");
                     }
-                    pw.println(" + \"}\";");
+                    pw.println(".append( \"}\");");
                 } else {
-                    pw.println("\t\tret += \"\"+\"" + name +" = \" + get_"+ name+"() +\", \";");
+                    pw.println("\t\tret.append(\"" + name +" = \").append( get_"+ name+"() ).append(\", \");");
                 }
             }
 
         }
-        pw.println("\t\treturn ret;\n\t}\n\n");
+        pw.println("\t\treturn ret.toString();\n\t}\n\n");
     }
 
     public void writeStubs(StructType stp, PrintWriter pw) {
diff --git a/jdk/src/solaris/classes/sun/awt/fontconfigs/bsd.fontconfig.properties b/jdk/src/solaris/classes/sun/awt/fontconfigs/bsd.fontconfig.properties
new file mode 100644
index 0000000..c430c16
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/awt/fontconfigs/bsd.fontconfig.properties
@@ -0,0 +1,189 @@
+#
+#
+# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# Version
+
+# Uses Fedora Core 6 fonts and file paths.
+version=1
+
+# Component Font Mappings
+
+dialog.plain.latin-1=DejaVu LGC Sans
+dialog.plain.japanese-x0208=Sazanami Gothic
+dialog.plain.korean=Baekmuk Gulim
+dialog.plain.chinese-big5=AR PL ShanHeiSun Uni
+dialog.plain.chinese-gb18030=AR PL ShanHeiSun Uni
+
+dialog.bold.latin-1=DejaVu LGC Sans Bold
+dialog.bold.japanese-x0208=Sazanami Gothic
+dialog.bold.korean=Baekmuk Gulim
+dialog.bold.chinese-big5=AR PL ShanHeiSun Uni
+dialog.bold.chinese-gb18030=AR PL ShanHeiSun Uni
+
+dialog.italic.latin-1=DejaVu LGC Sans Oblique
+dialog.italic.japanese-x0208=Sazanami Gothic
+dialog.italic.korean=Baekmuk Gulim
+dialog.italic.chinese-big5=AR PL ShanHeiSun Uni
+dialog.italic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+dialog.bolditalic.latin-1=DejaVu LGC Sans Bold Oblique
+dialog.bolditalic.japanese-x0208=Sazanami Gothic
+dialog.bolditalic.korean=Baekmuk Gulim
+dialog.bolditalic.chinese-big5=AR PL ShanHeiSun Uni
+dialog.bolditalic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+
+sansserif.plain.latin-1=DejaVu LGC Sans
+sansserif.plain.japanese-x0208=Sazanami Gothic
+sansserif.plain.korean=Baekmuk Gulim
+sansserif.plain.chinese-big5=AR PL ShanHeiSun Uni
+sansserif.plain.chinese-gb18030=AR PL ShanHeiSun Uni
+
+sansserif.bold.latin-1=DejaVu LGC Sans Bold
+sansserif.bold.japanese-x0208=Sazanami Gothic
+sansserif.bold.korean=Baekmuk Gulim
+sansserif.bold.chinese-big5=AR PL ShanHeiSun Uni
+sansserif.bold.chinese-gb18030=AR PL ShanHeiSun Uni
+
+sansserif.italic.latin-1=DejaVu LGC Sans Oblique
+sansserif.italic.japanese-x0208=Sazanami Gothic
+sansserif.italic.korean=Baekmuk Gulim
+sansserif.italic.chinese-big5=AR PL ShanHeiSun Uni
+sansserif.italic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+sansserif.bolditalic.latin-1=DejaVu LGC Sans Bold Oblique
+sansserif.bolditalic.japanese-x0208=Sazanami Gothic
+sansserif.bolditalic.korean=Baekmuk Gulim
+sansserif.bolditalic.chinese-big5=AR PL ShanHeiSun Uni
+sansserif.bolditalic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+
+serif.plain.latin-1=DejaVu LGC Serif
+serif.plain.japanese-x0208=Sazanami Mincho
+serif.plain.korean=Baekmuk Batang
+serif.plain.chinese-big5=AR PL ZenKai Uni
+serif.plain.chinese-gb18030=AR PL ZenKai Uni
+
+serif.bold.latin-1=DejaVu LGC Serif Bold
+serif.bold.japanese-x0208=Sazanami Mincho
+serif.bold.korean=Baekmuk Batang
+serif.bold.chinese-big5=AR PL ZenKai Uni
+serif.bold.chinese-gb18030=AR PL ZenKai Uni
+
+serif.italic.latin-1=DejaVu LGC Serif Oblique
+serif.italic.japanese-x0208=Sazanami Mincho
+serif.italic.korean=Baekmuk Batang
+serif.italic.chinese-big5=AR PL ZenKai Uni
+serif.italic.chinese-gb18030=AR PL ZenKai Uni
+
+serif.bolditalic.latin-1=DejaVu LGC Serif Bold Oblique
+serif.bolditalic.japanese-x0208=Sazanami Mincho
+serif.bolditalic.korean=Baekmuk Batang
+serif.bolditalic.chinese-big5=AR PL ZenKai Uni
+serif.bolditalic.chinese-gb18030=AR PL ZenKai Uni
+
+
+monospaced.plain.latin-1=DejaVu LGC Sans Mono
+monospaced.plain.japanese-x0208=Sazanami Gothic
+monospaced.plain.korean=Baekmuk Gulim
+monospaced.plain.chinese-big5=AR PL ShanHeiSun Uni
+monospaced.plain.chinese-gb18030=AR PL ShanHeiSun Uni
+
+monospaced.bold.latin-1=DejaVu LGC Sans Mono Bold
+monospaced.bold.japanese-x0208=Sazanami Gothic
+monospaced.bold.korean=Baekmuk Gulim
+monospaced.bold.chinese-big5=AR PL ShanHeiSun Uni
+monospaced.bold.chinese-gb18030=AR PL ShanHeiSun Uni
+
+monospaced.italic.latin-1=DejaVu LGC Sans Mono Oblique
+monospaced.italic.japanese-x0208=Sazanami Gothic
+monospaced.italic.korean=Baekmuk Gulim
+monospaced.italic.chinese-big5=AR PL ShanHeiSun Uni
+monospaced.italic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+monospaced.bolditalic.latin-1=DejaVu LGC Sans Mono Bold Oblique
+monospaced.bolditalic.japanese-x0208=Sazanami Gothic
+monospaced.bolditalic.korean=Baekmuk Gulim
+monospaced.bolditalic.chinese-big5=AR PL ShanHeiSun Uni
+monospaced.bolditalic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+
+dialoginput.plain.latin-1=DejaVu LGC Sans Mono
+dialoginput.plain.japanese-x0208=Sazanami Gothic
+dialoginput.plain.korean=Baekmuk Gulim
+dialoginput.plain.chinese-big5=AR PL ShanHeiSun Uni
+dialoginput.plain.chinese-gb18030=AR PL ShanHeiSun Uni
+
+dialoginput.bold.latin-1=DejaVu LGC Sans Mono Bold
+dialoginput.bold.japanese-x0208=Sazanami Gothic
+dialoginput.bold.korean=Baekmuk Gulim
+dialoginput.bold.chinese-big5=AR PL ShanHeiSun Uni
+dialoginput.bold.chinese-gb18030=AR PL ShanHeiSun Uni
+
+dialoginput.italic.latin-1=DejaVu LGC Sans Mono Oblique
+dialoginput.italic.japanese-x0208=Sazanami Gothic
+dialoginput.italic.korean=Baekmuk Gulim
+dialoginput.italic.chinese-big5=AR PL ShanHeiSun Uni
+dialoginput.italic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+dialoginput.bolditalic.latin-1=DejaVu LGC Sans Mono Bold Oblique
+dialoginput.bolditalic.japanese-x0208=Sazanami Gothic
+dialoginput.bolditalic.korean=Baekmuk Gulim
+dialoginput.bolditalic.chinese-big5=AR PL ShanHeiSun Uni
+dialoginput.bolditalic.chinese-gb18030=AR PL ShanHeiSun Uni
+
+# Search Sequences
+
+sequence.allfonts=latin-1
+sequence.allfonts.Big5=chinese-big5,latin-1
+sequence.allfonts.x-euc-jp-bsd=japanese-x0208,latin-1
+sequence.allfonts.EUC-KR=korean,latin-1
+sequence.allfonts.GB18030=chinese-gb18030,latin-1
+sequence.fallback=chinese-big5,chinese-gb18030,japanese-x0208,korean
+
+# Font File Names
+
+filename.DejaVu_LGC_Sans=/usr/share/fonts/dejavu-lgc/DejaVuLGCSans.ttf
+filename.DejaVu_LGC_Sans_Bold=/usr/share/fonts/dejavu-lgc/DejaVuLGCSans-Bold.ttf
+filename.DejaVu_LGC_Sans_Oblique=/usr/share/fonts/dejavu-lgc/DejaVuLGCSans-Oblique.ttf
+filename.DejaVu_LGC_Sans_Bold_Oblique=/usr/share/fonts/dejavu-lgc/DejaVuLGCSans-BoldOblique.ttf
+
+filename.DejaVu_LGC_Sans_Mono=/usr/share/fonts/dejavu-lgc/DejaVuLGCSansMono.ttf
+filename.DejaVu_LGC_Sans_Mono_Bold=/usr/share/fonts/dejavu-lgc/DejaVuLGCSansMono-Bold.ttf
+filename.DejaVu_LGC_Sans_Mono_Oblique=/usr/share/fonts/dejavu-lgc/DejaVuLGCSansMono-Oblique.ttf
+filename.DejaVu_LGC_Sans_Mono_Bold_Oblique=/usr/share/fonts/dejavu-lgc/DejaVuLGCSansMono-BoldOblique.ttf
+
+filename.DejaVu_LGC_Serif=/usr/share/fonts/dejavu-lgc/DejaVuLGCSerif.ttf
+filename.DejaVu_LGC_Serif_Bold=/usr/share/fonts/dejavu-lgc/DejaVuLGCSerif-Bold.ttf
+filename.DejaVu_LGC_Serif_Oblique=/usr/share/fonts/dejavu-lgc/DejaVuLGCSerif-Oblique.ttf
+filename.DejaVu_LGC_Serif_Bold_Oblique=/usr/share/fonts/dejavu-lgc/DejaVuLGCSerif-BoldOblique.ttf
+
+filename.Sazanami_Gothic=/usr/share/fonts/japanese/TrueType/sazanami-gothic.ttf
+filename.Sazanami_Mincho=/usr/share/fonts/japanese/TrueType/sazanami-mincho.ttf
+filename.AR_PL_ShanHeiSun_Uni=/usr/share/fonts/chinese/TrueType/uming.ttf
+filename.AR_PL_ZenKai_Uni=/usr/share/fonts/chinese/TrueType/ukai.ttf
+filename.Baekmuk_Gulim=/usr/share/fonts/korean/TrueType/gulim.ttf
+filename.Baekmuk_Batang=/usr/share/fonts/korean/TrueType/batang.ttf
diff --git a/jdk/src/solaris/classes/sun/nio/fs/BsdFileStore.java b/jdk/src/solaris/classes/sun/nio/fs/BsdFileStore.java
new file mode 100644
index 0000000..5182b45
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/fs/BsdFileStore.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.nio.fs;
+
+import java.nio.file.attribute.*;
+import java.util.*;
+import java.io.IOException;
+
+/**
+ * Bsd implementation of FileStore
+ */
+
+class BsdFileStore
+    extends UnixFileStore
+{
+    BsdFileStore(UnixPath file) throws IOException {
+        super(file);
+    }
+
+    BsdFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException {
+        super(fs, entry);
+    }
+
+    /**
+     * Finds, and returns, the mount entry for the file system where the file
+     * resides.
+     */
+    @Override
+    UnixMountEntry findMountEntry() throws IOException {
+        UnixFileSystem fs = file().getFileSystem();
+
+        // step 1: get realpath
+        UnixPath path = null;
+        try {
+            byte[] rp = UnixNativeDispatcher.realpath(file());
+            path = new UnixPath(fs, rp);
+        } catch (UnixException x) {
+            x.rethrowAsIOException(file());
+        }
+
+        // step 2: find mount point
+        UnixPath parent = path.getParent();
+        while (parent != null) {
+            UnixFileAttributes attrs = null;
+            try {
+                attrs = UnixFileAttributes.get(parent, true);
+            } catch (UnixException x) {
+                x.rethrowAsIOException(parent);
+            }
+            if (attrs.dev() != dev())
+                break;
+            path = parent;
+            parent = parent.getParent();
+        }
+
+        // step 3: lookup mounted file systems
+        byte[] dir = path.asByteArray();
+        for (UnixMountEntry entry: fs.getMountEntries()) {
+            if (Arrays.equals(dir, entry.dir()))
+                return entry;
+        }
+
+        throw new IOException("Mount point not found in fstab");
+    }
+
+    // returns true if extended attributes enabled on file system where given
+    // file resides, returns false if disabled or unable to determine.
+    private boolean isExtendedAttributesEnabled(UnixPath path) {
+/*
+        try {
+            int fd = path.openForAttributeAccess(false);
+            try {
+                // fgetxattr returns size if called with size==0
+                BsdNativeDispatcher.fgetxattr(fd, "user.java".getBytes(), 0L, 0);
+                return true;
+            } catch (UnixException e) {
+                // attribute does not exist
+                if (e.errno() == UnixConstants.ENODATA)
+                    return true;
+            } finally {
+                UnixNativeDispatcher.close(fd);
+            }
+        } catch (IOException ignore) {
+            // nothing we can do
+        }
+*/
+        return false;
+    }
+
+    @Override
+    public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
+/*
+        // support DosFileAttributeView and UserDefinedAttributeView if extended
+        // attributes enabled
+        if (type == DosFileAttributeView.class ||
+            type == UserDefinedFileAttributeView.class)
+        {
+            // lookup fstypes.properties
+            FeatureStatus status = checkIfFeaturePresent("user_xattr");
+            if (status == FeatureStatus.PRESENT)
+                return true;
+            if (status == FeatureStatus.NOT_PRESENT)
+                return false;
+
+            // if file system is mounted with user_xattr option then assume
+            // extended attributes are enabled
+            if ((entry().hasOption("user_xattr")))
+                return true;
+
+            // user_xattr option not present but we special-case ext3/4 as we
+            // know that extended attributes are not enabled by default.
+            if (entry().fstype().equals("ext3") || entry().fstype().equals("ext4"))
+                return false;
+
+            // not ext3/4 so probe mount point
+            if (!xattrChecked) {
+                UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
+                xattrEnabled = isExtendedAttributesEnabled(dir);
+                xattrChecked = true;
+            }
+            return xattrEnabled;
+        }
+*/
+        return super.supportsFileAttributeView(type);
+    }
+
+    @Override
+    public boolean supportsFileAttributeView(String name) {
+/*
+        if (name.equals("dos"))
+            return supportsFileAttributeView(DosFileAttributeView.class);
+        if (name.equals("user"))
+            return supportsFileAttributeView(UserDefinedFileAttributeView.class);
+*/
+        return super.supportsFileAttributeView(name);
+    }
+}
diff --git a/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystem.java b/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystem.java
new file mode 100644
index 0000000..873feea
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystem.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.nio.fs;
+
+import java.nio.file.*;
+import java.io.IOException;
+import java.util.*;
+import java.security.AccessController;
+import sun.security.action.GetPropertyAction;
+
+/**
+ * Bsd implementation of FileSystem
+ */
+
+class BsdFileSystem extends UnixFileSystem {
+
+    BsdFileSystem(UnixFileSystemProvider provider, String dir) {
+        super(provider, dir);
+    }
+
+    @Override
+    public WatchService newWatchService()
+        throws IOException
+    {
+        // use polling implementation until we implement a BSD/kqueue one
+        return new PollingWatchService();
+    }
+
+    // lazy initialization of the list of supported attribute views
+    private static class SupportedFileFileAttributeViewsHolder {
+        static final Set<String> supportedFileAttributeViews =
+            supportedFileAttributeViews();
+        private static Set<String> supportedFileAttributeViews() {
+            Set<String> result = new HashSet<String>();
+            result.addAll(standardFileAttributeViews());
+            return Collections.unmodifiableSet(result);
+        }
+    }
+
+    @Override
+    public Set<String> supportedFileAttributeViews() {
+        return SupportedFileFileAttributeViewsHolder.supportedFileAttributeViews;
+    }
+
+    @Override
+    void copyNonPosixAttributes(int ofd, int nfd) {
+    }
+
+    /**
+     * Returns object to iterate over mount entries
+     */
+    @Override
+    Iterable<UnixMountEntry> getMountEntries() {
+        ArrayList<UnixMountEntry> entries = new ArrayList<UnixMountEntry>();
+        try {
+            long iter = BsdNativeDispatcher.getfsstat();
+            try {
+                for (;;) {
+                    UnixMountEntry entry = new UnixMountEntry();
+                    int res = BsdNativeDispatcher.fsstatEntry(iter, entry);
+                    if (res < 0)
+                        break;
+                    entries.add(entry);
+                }
+            } finally {
+                BsdNativeDispatcher.endfsstat(iter);
+            }
+
+        } catch (UnixException x) {
+            // nothing we can do
+        }
+        return entries;
+    }
+
+
+
+    @Override
+    FileStore getFileStore(UnixMountEntry entry) throws IOException {
+        return new BsdFileStore(this, entry);
+    }
+}
diff --git a/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java b/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java
new file mode 100644
index 0000000..266a002
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.nio.fs;
+
+import java.nio.file.*;
+import java.nio.file.attribute.*;
+import java.io.IOException;
+
+/**
+ * Bsd implementation of FileSystemProvider
+ */
+
+public class BsdFileSystemProvider extends UnixFileSystemProvider {
+    public BsdFileSystemProvider() {
+        super();
+    }
+
+    @Override
+    BsdFileSystem newFileSystem(String dir) {
+        return new BsdFileSystem(this, dir);
+    }
+
+    @Override
+    BsdFileStore getFileStore(UnixPath path) throws IOException {
+        return new BsdFileStore(path);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <V extends FileAttributeView> V getFileAttributeView(Path obj,
+                                                                Class<V> type,
+                                                                LinkOption... options)
+    {
+        return super.getFileAttributeView(obj, type, options);
+    }
+
+    @Override
+    public DynamicFileAttributeView getFileAttributeView(Path obj,
+                                                         String name,
+                                                         LinkOption... options)
+    {
+        return super.getFileAttributeView(obj, name, options);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <A extends BasicFileAttributes> A readAttributes(Path file,
+                                                            Class<A> type,
+                                                            LinkOption... options)
+        throws IOException
+    {
+        if (type == DosFileAttributes.class) {
+            DosFileAttributeView view =
+                getFileAttributeView(file, DosFileAttributeView.class, options);
+            return (A) view.readAttributes();
+        } else {
+            return super.readAttributes(file, type, options);
+        }
+    }
+}
diff --git a/jdk/src/solaris/classes/sun/nio/fs/BsdNativeDispatcher.java b/jdk/src/solaris/classes/sun/nio/fs/BsdNativeDispatcher.java
new file mode 100644
index 0000000..74b8cc2
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/fs/BsdNativeDispatcher.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.nio.fs;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Bsd specific system calls.
+ */
+
+class BsdNativeDispatcher extends UnixNativeDispatcher {
+    private BsdNativeDispatcher() { }
+
+   /**
+    * struct fsstat_iter *getfsstat();
+    */
+    static native long getfsstat() throws UnixException;
+
+   /**
+    * int fsstatEntry(struct fsstat_iter * iter, UnixMountEntry entry);
+    */
+    static native int fsstatEntry(long iter, UnixMountEntry entry)
+        throws UnixException;
+
+   /**
+    * void endfsstat(struct fsstat_iter * iter);
+    */
+    static native void endfsstat(long iter) throws UnixException;
+
+    // initialize field IDs
+    private static native void initIDs();
+
+    static {
+        AccessController.doPrivileged(new PrivilegedAction<Void>() {
+            public Void run() {
+                System.loadLibrary("nio");
+                return null;
+        }});
+        initIDs();
+    }
+}
diff --git a/jdk/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java b/jdk/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java
index 75a4536..2605e1d 100644
--- a/jdk/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java
+++ b/jdk/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java
@@ -68,6 +68,8 @@
             return createProvider("sun.nio.fs.SolarisFileSystemProvider");
         if (osname.equals("Linux"))
             return createProvider("sun.nio.fs.LinuxFileSystemProvider");
+        if (osname.equals("Darwin") || osname.startsWith("Mac OS X"))
+            return createProvider("sun.nio.fs.BsdFileSystemProvider");
         throw new AssertionError("Platform not recognized");
     }
 }
diff --git a/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java b/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
index f65a571..8640f6f 100644
--- a/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
+++ b/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
@@ -119,7 +119,8 @@
     }
 
     static boolean isBSD() {
-        return osname.equals("Linux");
+        return (osname.equals("Linux") ||
+                osname.startsWith("Mac OS X"));
     }
 
     static final int UNINITIALIZED = -1;
@@ -134,8 +135,8 @@
     };
 
     String[] lpcAllCom = {
-        "/usr/sbin/lpc status | grep : | sed -e 's/://'",
-        "/usr/sbin/lpc -a status | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort"
+        "/usr/sbin/lpc status all | grep : | sed -e 's/://'",
+        "/usr/sbin/lpc status all | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort"
     };
 
     String[] lpcNameCom = {
@@ -145,7 +146,7 @@
 
 
     static int getBSDCommandIndex() {
-        String command  = "/usr/sbin/lpc status";
+        String command  = "/usr/sbin/lpc status all";
         String[] names = execCmd(command);
 
         if ((names == null) || (names.length == 0)) {
diff --git a/jdk/src/solaris/classes/sun/security/smartcardio/PlatformPCSC.java b/jdk/src/solaris/classes/sun/security/smartcardio/PlatformPCSC.java
index 29ff54c..d6197b9 100644
--- a/jdk/src/solaris/classes/sun/security/smartcardio/PlatformPCSC.java
+++ b/jdk/src/solaris/classes/sun/security/smartcardio/PlatformPCSC.java
@@ -50,6 +50,7 @@
 
     private final static String LIB1 = "/usr/$LIBISA/libpcsclite.so";
     private final static String LIB2 = "/usr/local/$LIBISA/libpcsclite.so";
+    private final static String PCSC_FRAMEWORK = "/System/Library/Frameworks/PCSC.framework/Versions/Current/PCSC";
 
     PlatformPCSC() {
         // empty
@@ -113,6 +114,11 @@
             // if LIB2 exists, use that
             return lib;
         }
+        lib = PCSC_FRAMEWORK;
+        if (new File(lib).isFile()) {
+            // if PCSC.framework exists, use that
+            return lib;
+        }
         throw new IOException("No PC/SC library found on this system");
     }
 
diff --git a/jdk/src/solaris/classes/sun/tools/attach/BsdAttachProvider.java b/jdk/src/solaris/classes/sun/tools/attach/BsdAttachProvider.java
new file mode 100644
index 0000000..dffbc6b
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/tools/attach/BsdAttachProvider.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package sun.tools.attach;
+
+import com.sun.tools.attach.VirtualMachine;
+import com.sun.tools.attach.VirtualMachineDescriptor;
+import com.sun.tools.attach.AttachNotSupportedException;
+import com.sun.tools.attach.spi.AttachProvider;
+
+import java.io.IOException;
+
+/*
+ * An AttachProvider implementation for Bsd that uses a UNIX domain
+ * socket.
+ */
+public class BsdAttachProvider extends HotSpotAttachProvider {
+
+    // perf counter for the JVM version
+    private static final String JVM_VERSION = "java.property.java.vm.version";
+
+    public BsdAttachProvider() {
+    }
+
+    public String name() {
+        return "sun";
+    }
+
+    public String type() {
+        return "socket";
+    }
+
+    public VirtualMachine attachVirtualMachine(String vmid)
+        throws AttachNotSupportedException, IOException
+    {
+        checkAttachPermission();
+
+        // AttachNotSupportedException will be thrown if the target VM can be determined
+        // to be not attachable.
+        testAttachable(vmid);
+
+        return new BsdVirtualMachine(this, vmid);
+    }
+
+    public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
+        throws AttachNotSupportedException, IOException
+    {
+        if (vmd.provider() != this) {
+            throw new AttachNotSupportedException("provider mismatch");
+        }
+        // To avoid re-checking if the VM if attachable, we check if the descriptor
+        // is for a hotspot VM - these descriptors are created by the listVirtualMachines
+        // implementation which only returns a list of attachable VMs.
+        if (vmd instanceof HotSpotVirtualMachineDescriptor) {
+            assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
+            checkAttachPermission();
+            return new BsdVirtualMachine(this, vmd.id());
+        } else {
+            return attachVirtualMachine(vmd.id());
+        }
+    }
+
+}
diff --git a/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java b/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java
new file mode 100644
index 0000000..afa042d
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package sun.tools.attach;
+
+import com.sun.tools.attach.VirtualMachine;
+import com.sun.tools.attach.AgentLoadException;
+import com.sun.tools.attach.AttachNotSupportedException;
+import com.sun.tools.attach.spi.AttachProvider;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.util.Properties;
+
+/*
+ * Bsd implementation of HotSpotVirtualMachine
+ */
+public class BsdVirtualMachine extends HotSpotVirtualMachine {
+    // temp directory for socket file
+    private static final String tmpdir = System.getProperty("java.io.tmpdir");
+
+    // The patch to the socket file created by the target VM
+    String path;
+
+    /**
+     * Attaches to the target VM
+     */
+    BsdVirtualMachine(AttachProvider provider, String vmid)
+        throws AttachNotSupportedException, IOException
+    {
+        super(provider, vmid);
+
+        // This provider only understands pids
+        int pid;
+        try {
+            pid = Integer.parseInt(vmid);
+        } catch (NumberFormatException x) {
+            throw new AttachNotSupportedException("Invalid process identifier");
+        }
+
+        // Find the socket file. If not found then we attempt to start the
+        // attach mechanism in the target VM by sending it a QUIT signal.
+        // Then we attempt to find the socket file again.
+        path = findSocketFile(pid);
+        if (path == null) {
+            File f = new File(tmpdir, ".attach_pid" + pid);
+            createAttachFile(f.getPath());
+            try {
+                sendQuitTo(pid);
+
+                // give the target VM time to start the attach mechanism
+                int i = 0;
+                long delay = 200;
+                int retries = (int)(attachTimeout() / delay);
+                do {
+                    try {
+                        Thread.sleep(delay);
+                    } catch (InterruptedException x) { }
+                    path = findSocketFile(pid);
+                    i++;
+                } while (i <= retries && path == null);
+                if (path == null) {
+                    throw new AttachNotSupportedException(
+                        "Unable to open socket file: target process not responding " +
+                        "or HotSpot VM not loaded");
+                }
+            } finally {
+                f.delete();
+            }
+        }
+
+        // Check that the file owner/permission to avoid attaching to
+        // bogus process
+        checkPermissions(path);
+
+        // Check that we can connect to the process
+        // - this ensures we throw the permission denied error now rather than
+        // later when we attempt to enqueue a command.
+        int s = socket();
+        try {
+            connect(s, path);
+        } finally {
+            close(s);
+        }
+    }
+
+    /**
+     * Detach from the target VM
+     */
+    public void detach() throws IOException {
+        synchronized (this) {
+            if (this.path != null) {
+                this.path = null;
+            }
+        }
+    }
+
+    // protocol version
+    private final static String PROTOCOL_VERSION = "1";
+
+    // known errors
+    private final static int ATTACH_ERROR_BADVERSION = 101;
+
+    /**
+     * Execute the given command in the target VM.
+     */
+    InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
+        assert args.length <= 3;                // includes null
+
+        // did we detach?
+        String p;
+        synchronized (this) {
+            if (this.path == null) {
+                throw new IOException("Detached from target VM");
+            }
+            p = this.path;
+        }
+
+        // create UNIX socket
+        int s = socket();
+
+        // connect to target VM
+        try {
+            connect(s, p);
+        } catch (IOException x) {
+            close(s);
+            throw x;
+        }
+
+        IOException ioe = null;
+
+        // connected - write request
+        // <ver> <cmd> <args...>
+        try {
+            writeString(s, PROTOCOL_VERSION);
+            writeString(s, cmd);
+
+            for (int i=0; i<3; i++) {
+                if (i < args.length && args[i] != null) {
+                    writeString(s, (String)args[i]);
+                } else {
+                    writeString(s, "");
+                }
+            }
+        } catch (IOException x) {
+            ioe = x;
+        }
+
+
+        // Create an input stream to read reply
+        SocketInputStream sis = new SocketInputStream(s);
+
+        // Read the command completion status
+        int completionStatus;
+        try {
+            completionStatus = readInt(sis);
+        } catch (IOException x) {
+            sis.close();
+            if (ioe != null) {
+                throw ioe;
+            } else {
+                throw x;
+            }
+        }
+
+        if (completionStatus != 0) {
+            sis.close();
+
+            // In the event of a protocol mismatch then the target VM
+            // returns a known error so that we can throw a reasonable
+            // error.
+            if (completionStatus == ATTACH_ERROR_BADVERSION) {
+                throw new IOException("Protocol mismatch with target VM");
+            }
+
+            // Special-case the "load" command so that the right exception is
+            // thrown.
+            if (cmd.equals("load")) {
+                throw new AgentLoadException("Failed to load agent library");
+            } else {
+                throw new IOException("Command failed in target VM");
+            }
+        }
+
+        // Return the input stream so that the command output can be read
+        return sis;
+    }
+
+    /*
+     * InputStream for the socket connection to get target VM
+     */
+    private class SocketInputStream extends InputStream {
+        int s;
+
+        public SocketInputStream(int s) {
+            this.s = s;
+        }
+
+        public synchronized int read() throws IOException {
+            byte b[] = new byte[1];
+            int n = this.read(b, 0, 1);
+            if (n == 1) {
+                return b[0] & 0xff;
+            } else {
+                return -1;
+            }
+        }
+
+        public synchronized int read(byte[] bs, int off, int len) throws IOException {
+            if ((off < 0) || (off > bs.length) || (len < 0) ||
+                ((off + len) > bs.length) || ((off + len) < 0)) {
+                throw new IndexOutOfBoundsException();
+            } else if (len == 0)
+                return 0;
+
+            return BsdVirtualMachine.read(s, bs, off, len);
+        }
+
+        public void close() throws IOException {
+            BsdVirtualMachine.close(s);
+        }
+    }
+
+    // Return the socket file for the given process.
+    // Checks working directory of process for .java_pid<pid>. If not
+    // found it looks in temp directory.
+    private String findSocketFile(int pid) {
+        // First check for a .java_pid<pid> file in the working directory
+        // of the target process
+        String fn = ".java_pid" + pid;
+        File f = new File(tmpdir, fn);
+        return f.exists() ? f.getPath() : null;
+    }
+
+    /*
+     * Write/sends the given to the target VM. String is transmitted in
+     * UTF-8 encoding.
+     */
+    private void writeString(int fd, String s) throws IOException {
+        if (s.length() > 0) {
+            byte b[];
+            try {
+                b = s.getBytes("UTF-8");
+            } catch (java.io.UnsupportedEncodingException x) {
+                throw new InternalError();
+            }
+            BsdVirtualMachine.write(fd, b, 0, b.length);
+        }
+        byte b[] = new byte[1];
+        b[0] = 0;
+        write(fd, b, 0, 1);
+    }
+
+
+    //-- native methods
+
+    static native void sendQuitTo(int pid) throws IOException;
+
+    static native void checkPermissions(String path) throws IOException;
+
+    static native int socket() throws IOException;
+
+    static native void connect(int fd, String path) throws IOException;
+
+    static native void close(int fd) throws IOException;
+
+    static native int read(int fd, byte buf[], int off, int bufLen) throws IOException;
+
+    static native void write(int fd, byte buf[], int off, int bufLen) throws IOException;
+
+    static native void createAttachFile(String path);
+
+    static {
+        System.loadLibrary("attach");
+    }
+}
diff --git a/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c b/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c
index d3b8484..1e93bd6 100644
--- a/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c
+++ b/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c
@@ -42,7 +42,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#ifndef LINUX
+#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
 #include <procfs.h>
 #endif
 
@@ -62,6 +62,7 @@
 #include <time.h>
 
 #include "jni.h"
+#include "jvm_md.h"
 #include "hprof.h"
 
 int
@@ -85,7 +86,7 @@
 void
 md_init(void)
 {
-#ifdef LINUX
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
     /* No Hi-Res timer option? */
 #else
     if ( gdata->micro_state_accounting ) {
@@ -247,7 +248,7 @@
 jlong
 md_get_microsecs(void)
 {
-#ifdef LINUX
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
     return (jlong)(md_timeofday() * (jlong)1000); /* Milli to micro */
 #else
     return (jlong)(gethrtime()/(hrtime_t)1000); /* Nano seconds to micro seconds */
@@ -265,7 +266,7 @@
 jlong
 md_get_thread_cpu_timemillis(void)
 {
-#ifdef LINUX
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
     return md_timeofday();
 #else
     return (jlong)(gethrvtime()/1000); /* Nano seconds to milli seconds */
@@ -280,7 +281,7 @@
     Dl_info dlinfo;
 
     libdir[0] = 0;
-#ifdef LINUX
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
     addr = (void*)&Agent_OnLoad;
 #else
     /* Just using &Agent_OnLoad will get the first external symbol with
@@ -308,10 +309,13 @@
         if ( lastSlash != NULL ) {
             *lastSlash = '\0';
         }
+#ifndef __APPLE__
+        // not sure why other platforms have to go up two levels, but on macos we only need up one
         lastSlash = strrchr(libdir, '/');
         if ( lastSlash != NULL ) {
             *lastSlash = '\0';
         }
+#endif /* __APPLE__ */
     }
     (void)snprintf(path, path_len, "%s/%s", libdir, filename);
 }
@@ -388,9 +392,9 @@
 
     /* Construct path to library */
     if (pnamelen == 0) {
-        (void)snprintf(holder, holderlen, "lib%s.so", fname);
+        (void)snprintf(holder, holderlen, "lib%s" JNI_LIB_SUFFIX, fname);
     } else {
-        (void)snprintf(holder, holderlen, "%s/lib%s.so", pname, fname);
+        (void)snprintf(holder, holderlen, "%s/lib%s" JNI_LIB_SUFFIX, pname, fname);
     }
 }
 
diff --git a/jdk/src/solaris/javavm/export/jvm_md.h b/jdk/src/solaris/javavm/export/jvm_md.h
index 09213b0..949c86d 100644
--- a/jdk/src/solaris/javavm/export/jvm_md.h
+++ b/jdk/src/solaris/javavm/export/jvm_md.h
@@ -41,7 +41,14 @@
 #define JNI_ONUNLOAD_SYMBOLS {"JNI_OnUnload"}
 
 #define JNI_LIB_PREFIX "lib"
+#ifdef __APPLE__
+#define JNI_LIB_SUFFIX ".dylib"
+#define VERSIONED_JNI_LIB_NAME(NAME, VERSION) JNI_LIB_PREFIX NAME "." VERSION JNI_LIB_SUFFIX
+#else
 #define JNI_LIB_SUFFIX ".so"
+#define VERSIONED_JNI_LIB_NAME(NAME, VERSION) JNI_LIB_PREFIX NAME JNI_LIB_SUFFIX "." VERSION
+#endif
+#define JNI_LIB_NAME(NAME) JNI_LIB_PREFIX NAME JNI_LIB_SUFFIX
 
 #define JVM_MAXPATHLEN MAXPATHLEN
 
@@ -68,7 +75,11 @@
 #define JVM_O_O_APPEND   O_APPEND
 #define JVM_O_EXCL       O_EXCL
 #define JVM_O_CREAT      O_CREAT
+#ifdef __APPLE__
+#define JVM_O_DELETE     0x10000000
+#else
 #define JVM_O_DELETE     0x10000
+#endif
 
 /* Signals */
 
diff --git a/jdk/src/solaris/lib/Info-cmdline.plist b/jdk/src/solaris/lib/Info-cmdline.plist
new file mode 100644
index 0000000..48ff371
--- /dev/null
+++ b/jdk/src/solaris/lib/Info-cmdline.plist
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>CFBundleIdentifier</key>
+        <string>net.java.openjdk.cmd</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>6.0</string>
+        <key>CFBundleShortVersionString</key>
+        <string>1.0</string>
+        <key>CFBundleVersion</key>
+        <string>1.0</string>
+</dict>
+</plist>
diff --git a/jdk/src/solaris/lib/Info-privileged.plist b/jdk/src/solaris/lib/Info-privileged.plist
new file mode 100644
index 0000000..776967a
--- /dev/null
+++ b/jdk/src/solaris/lib/Info-privileged.plist
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>CFBundleIdentifier</key>
+        <string>net.java.openjdk.cmd</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>6.0</string>
+        <key>CFBundleName</key>
+        <string>OpenJDK 7 Command</string>
+        <key>CFBundleShortVersionString</key>
+        <string>1.0</string>
+        <key>CFBundleVersion</key>
+        <string>1.0</string>
+        <key>SecTaskAccess</key>
+        <string>allowed</string>
+</dict>
+</plist>
diff --git a/jdk/src/solaris/native/com/sun/management/MacosxOperatingSystem.c b/jdk/src/solaris/native/com/sun/management/MacosxOperatingSystem.c
new file mode 100644
index 0000000..e2c561b
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/management/MacosxOperatingSystem.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "com_sun_management_UnixOperatingSystem.h"
+
+JNIEXPORT jdouble JNICALL
+Java_com_sun_management_UnixOperatingSystem_getSystemCpuLoad
+(JNIEnv *env, jobject dummy)
+{
+  return -1.0; // not available
+}
+
+JNIEXPORT jdouble JNICALL
+Java_com_sun_management_UnixOperatingSystem_getProcessCpuLoad
+(JNIEnv *env, jobject dummy)
+{
+  return -1.0; // not available
+}
diff --git a/jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c b/jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c
index 0541799..0bf3f4f 100644
--- a/jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c
+++ b/jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c
@@ -32,10 +32,16 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#if defined(_ALLBSD_SOURCE)
+#include <sys/sysctl.h>
+#else
 #include <sys/swap.h>
+#endif
 #include <sys/resource.h>
 #include <sys/times.h>
+#ifndef _ALLBSD_SOURCE
 #include <sys/sysinfo.h>
+#endif
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
@@ -46,16 +52,22 @@
 
 static jlong page_size = 0;
 
+#if defined(_ALLBSD_SOURCE)
+#define MB      (1024UL * 1024UL)
+#else
+
 /* This gets us the new structured proc interfaces of 5.6 & later */
 /* - see comment in <sys/procfs.h> */
 #define _STRUCTURED_PROC 1
 #include <sys/procfs.h>
 
+#endif /* _ALLBSD_SOURCE */
+
 static struct dirent* read_dir(DIR* dirp, struct dirent* entry) {
 #ifdef __solaris__
     struct dirent* dbuf = readdir(dirp);
     return dbuf;
-#else /* __linux__ */
+#else /* __linux__ || _ALLBSD_SOURCE */
     struct dirent* p;
     if (readdir_r(dirp, entry, &p) == 0) {
         return p;
@@ -124,7 +136,7 @@
     free(strtab);
     return available ? ((jlong)avail * page_size) :
                        ((jlong)total * page_size);
-#else /* __linux__ */
+#elif defined(__linux__)
     int ret;
     FILE *fp;
     jlong total = 0, avail = 0;
@@ -138,6 +150,13 @@
     avail = (jlong)si.freeswap * si.mem_unit;
 
     return available ? avail : total;
+#else /* _ALLBSD_SOURCE */
+    /*
+     * XXXBSD: there's no way available to get swap info in
+     *         FreeBSD.  Usage of libkvm is not an option here
+     */
+    // throw_internal_error(env, "Unimplemented in FreeBSD");
+    return (0);
 #endif
 }
 
@@ -179,7 +198,7 @@
 
     JVM_Close(fd);
     return (jlong) psinfo.pr_size * 1024;
-#else /* __linux__ */
+#elif defined(__linux__)
     FILE *fp;
     unsigned long vsize = 0;
 
@@ -197,6 +216,12 @@
 
     fclose(fp);
     return (jlong)vsize;
+#else /* _ALLBSD_SOURCE */
+    /*
+     * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
+     */
+    // throw_internal_error(env, "Unimplemented in FreeBSD");
+    return (64 * MB);
 #endif
 }
 
@@ -222,9 +247,13 @@
     jlong cpu_time_ns;
     struct tms time;
 
-#ifdef __solaris__
+    /*
+     * BSDNOTE: FreeBSD implements _SC_CLK_TCK since FreeBSD 5, so
+     *          add a magic to handle it
+     */
+#if defined(__solaris__) || defined(_SC_CLK_TCK)
     clk_tck = (jlong) sysconf(_SC_CLK_TCK);
-#else /* __linux__ */
+#elif defined(__linux__) || defined(_ALLBSD_SOURCE)
     clk_tck = 100;
 #endif
     if (clk_tck == -1) {
@@ -244,22 +273,51 @@
 Java_com_sun_management_UnixOperatingSystem_getFreePhysicalMemorySize
   (JNIEnv *env, jobject mbean)
 {
+#ifdef _ALLBSD_SOURCE
+    /*
+     * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
+     */
+    // throw_internal_error(env, "Unimplemented in FreeBSD");
+    return (128 * MB);
+#else
     jlong num_avail_physical_pages = sysconf(_SC_AVPHYS_PAGES);
     return (num_avail_physical_pages * page_size);
+#endif
 }
 
 JNIEXPORT jlong JNICALL
 Java_com_sun_management_UnixOperatingSystem_getTotalPhysicalMemorySize
   (JNIEnv *env, jobject mbean)
 {
+#ifdef _ALLBSD_SOURCE
+    jlong result;
+    int mib[2];
+    size_t rlen;
+
+    mib[0] = CTL_HW;
+    mib[1] = HW_PHYSMEM;
+    rlen = sizeof(result);
+    if (sysctl(mib, 2, &result, &rlen, NULL, 0) == -1)
+        result = 256 * MB;
+
+    return (result);
+#else
     jlong num_physical_pages = sysconf(_SC_PHYS_PAGES);
     return (num_physical_pages * page_size);
+#endif
 }
 
 JNIEXPORT jlong JNICALL
 Java_com_sun_management_UnixOperatingSystem_getOpenFileDescriptorCount
   (JNIEnv *env, jobject mbean)
 {
+#ifdef _ALLBSD_SOURCE
+    /*
+     * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
+     */
+    // throw_internal_error(env, "Unimplemented in FreeBSD");
+    return (100);
+#else /* solaris/linux */
     DIR *dirp;
     struct dirent dbuf;
     struct dirent* dentp;
@@ -282,6 +340,7 @@
     closedir(dirp);
     // subtract by 1 which was the fd open for this implementation
     return (fds - 1);
+#endif
 }
 
 JNIEXPORT jlong JNICALL
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_CommonUtils.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_CommonUtils.c
new file mode 100644
index 0000000..5329a6a
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_CommonUtils.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_ERROR
+//#define USE_TRACE
+
+#include "PLATFORM_API_BsdOS_ALSA_CommonUtils.h"
+
+static void alsaDebugOutput(const char *file, int line, const char *function, int err, const char *fmt, ...) {
+#ifdef USE_ERROR
+    va_list args;
+    va_start(args, fmt);
+    printf("%s:%d function %s: error %d: %s\n", file, line, function, err, snd_strerror(err));
+    if (strlen(fmt) > 0) {
+        vprintf(fmt, args);
+    }
+    va_end(args);
+#endif
+}
+
+static int alsa_inited = 0;
+static int alsa_enumerate_pcm_subdevices = FALSE; // default: no
+static int alsa_enumerate_midi_subdevices = FALSE; // default: no
+
+void initAlsaSupport() {
+    char* enumerate;
+    if (!alsa_inited) {
+        alsa_inited = TRUE;
+        snd_lib_error_set_handler(&alsaDebugOutput);
+
+        enumerate = getenv(ENV_ENUMERATE_PCM_SUBDEVICES);
+        if (enumerate != NULL && strlen(enumerate) > 0
+            && (enumerate[0] != 'f')   // false
+            && (enumerate[0] != 'F')   // False
+            && (enumerate[0] != 'n')   // no
+            && (enumerate[0] != 'N')) { // NO
+            alsa_enumerate_pcm_subdevices = TRUE;
+        }
+#ifdef ALSA_MIDI_ENUMERATE_SUBDEVICES
+        alsa_enumerate_midi_subdevices = TRUE;
+#endif
+    }
+}
+
+
+/* if true (non-zero), ALSA sub devices should be listed as separate devices
+ */
+int needEnumerateSubdevices(int isMidi) {
+    initAlsaSupport();
+    return isMidi ? alsa_enumerate_midi_subdevices
+                  : alsa_enumerate_pcm_subdevices;
+}
+
+
+/*
+ * deviceID contains packed card, device and subdevice numbers
+ * each number takes 10 bits
+ * "default" device has id == ALSA_DEFAULT_DEVICE_ID
+ */
+UINT32 encodeDeviceID(int card, int device, int subdevice) {
+    return (((card & 0x3FF) << 20) | ((device & 0x3FF) << 10)
+           | (subdevice & 0x3FF)) + 1;
+}
+
+
+void decodeDeviceID(UINT32 deviceID, int* card, int* device, int* subdevice,
+                    int isMidi) {
+    deviceID--;
+    *card = (deviceID >> 20) & 0x3FF;
+    *device = (deviceID >> 10) & 0x3FF;
+    if (needEnumerateSubdevices(isMidi)) {
+        *subdevice = deviceID  & 0x3FF;
+    } else {
+        *subdevice = -1; // ALSA will choose any subdevices
+    }
+}
+
+
+void getDeviceString(char* buffer, int card, int device, int subdevice,
+                     int usePlugHw, int isMidi) {
+    if (needEnumerateSubdevices(isMidi)) {
+        sprintf(buffer, "%s:%d,%d,%d",
+                        usePlugHw ? ALSA_PLUGHARDWARE : ALSA_HARDWARE,
+                        card, device, subdevice);
+    } else {
+        sprintf(buffer, "%s:%d,%d",
+                        usePlugHw ? ALSA_PLUGHARDWARE : ALSA_HARDWARE,
+                        card, device);
+    }
+}
+
+
+void getDeviceStringFromDeviceID(char* buffer, UINT32 deviceID,
+                                 int usePlugHw, int isMidi) {
+    int card, device, subdevice;
+
+    if (deviceID == ALSA_DEFAULT_DEVICE_ID) {
+        strcpy(buffer, ALSA_DEFAULT_DEVICE_NAME);
+    } else {
+        decodeDeviceID(deviceID, &card, &device, &subdevice, isMidi);
+        getDeviceString(buffer, card, device, subdevice, usePlugHw, isMidi);
+    }
+}
+
+
+static int hasGottenALSAVersion = FALSE;
+#define ALSAVersionString_LENGTH 200
+static char ALSAVersionString[ALSAVersionString_LENGTH];
+
+void getALSAVersion(char* buffer, int len) {
+    if (!hasGottenALSAVersion) {
+        // get alsa version from proc interface
+        FILE* file;
+        int curr, len, totalLen, inVersionString;
+        file = fopen(ALSA_VERSION_PROC_FILE, "r");
+        ALSAVersionString[0] = 0;
+        if (file) {
+            if (NULL != fgets(ALSAVersionString, ALSAVersionString_LENGTH, file)) {
+                // parse for version number
+                totalLen = strlen(ALSAVersionString);
+                inVersionString = FALSE;
+                len = 0;
+                curr = 0;
+                while (curr < totalLen) {
+                    if (!inVersionString) {
+                        // is this char the beginning of a version string ?
+                        if (ALSAVersionString[curr] >= '0'
+                            && ALSAVersionString[curr] <= '9') {
+                            inVersionString = TRUE;
+                        }
+                    }
+                    if (inVersionString) {
+                        // the version string ends with white space
+                        if (ALSAVersionString[curr] <= 32) {
+                            break;
+                        }
+                        if (curr != len) {
+                            // copy this char to the beginning of the string
+                            ALSAVersionString[len] = ALSAVersionString[curr];
+                        }
+                        len++;
+                    }
+                    curr++;
+                }
+                // remove trailing dots
+                while ((len > 0) && (ALSAVersionString[len - 1] == '.')) {
+                    len--;
+                }
+                // null terminate
+                ALSAVersionString[len] = 0;
+            }
+            fclose(file);
+            hasGottenALSAVersion = TRUE;
+        }
+    }
+    strncpy(buffer, ALSAVersionString, len);
+}
+
+
+/* end */
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_CommonUtils.h b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_CommonUtils.h
new file mode 100644
index 0000000..eb489b6
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_CommonUtils.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <alsa/asoundlib.h>
+#include "Utilities.h"
+
+#ifndef PLATFORM_API_BSDOS_ALSA_COMMONUTILS_H_INCLUDED
+#define PLATFORM_API_BSDOS_ALSA_COMMONUTILS_H_INCLUDED
+
+#define ALSA_VERSION_PROC_FILE "/proc/asound/version"
+#define ALSA_HARDWARE "hw"
+#define ALSA_HARDWARE_CARD ALSA_HARDWARE":%d"
+#define ALSA_HARDWARE_DEVICE ALSA_HARDWARE_CARD",%d"
+#define ALSA_HARDWARE_SUBDEVICE ALSA_HARDWARE_DEVICE",%d"
+
+#define ALSA_PLUGHARDWARE "plughw"
+#define ALSA_DEFAULT_DEVICE_NAME "default"
+
+#define ALSA_DEFAULT_DEVICE_ID (0)
+
+#define ALSA_PCM     (0)
+#define ALSA_RAWMIDI (1)
+
+// for use in info objects
+#define ALSA_VENDOR "ALSA (http://www.alsa-project.org)"
+
+// Environment variable for inclusion of subdevices in device listing.
+// If this variable is unset or "no", then subdevices are ignored, and
+// it's ALSA's choice which one to use (enables hardware mixing)
+#define ENV_ENUMERATE_PCM_SUBDEVICES "ALSA_ENUMERATE_PCM_SUBDEVICES"
+
+// if defined, subdevices are listed.
+//#undef ALSA_MIDI_ENUMERATE_SUBDEVICES
+#define ALSA_MIDI_ENUMERATE_SUBDEVICES
+
+// must be called before any ALSA calls
+void initAlsaSupport();
+
+/* if true (non-zero), ALSA sub devices should be listed as separate devices
+ */
+int needEnumerateSubdevices(int isMidi);
+
+
+/*
+ * deviceID contains packed card, device and subdevice numbers
+ * each number takes 10 bits
+ * "default" device has id == ALSA_DEFAULT_DEVICE_ID
+ */
+UINT32 encodeDeviceID(int card, int device, int subdevice);
+
+void decodeDeviceID(UINT32 deviceID, int* card, int* device, int* subdevice,
+                    int isMidi);
+
+void getDeviceStringFromDeviceID(char* buffer, UINT32 deviceID,
+                                 int usePlugHw, int isMidi);
+
+void getALSAVersion(char* buffer, int len);
+
+
+#endif // PLATFORM_API_BSDOS_ALSA_COMMONUTILS_H_INCLUDED
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiIn.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiIn.c
new file mode 100644
index 0000000..b1a2986
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiIn.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#define USE_ERROR
+#define USE_TRACE
+
+#if USE_PLATFORM_MIDI_IN == TRUE
+
+
+#include <alsa/asoundlib.h>
+#include "PlatformMidi.h"
+#include "PLATFORM_API_BsdOS_ALSA_MidiUtils.h"
+#if defined(i586)
+#include <sys/utsname.h>
+#endif
+
+/*
+ * Helper methods
+ */
+
+static inline UINT32 packMessage(int status, int data1, int data2) {
+    return ((status & 0xFF) | ((data1 & 0xFF) << 8) | ((data2 & 0xFF) << 16));
+}
+
+
+static void setShortMessage(MidiMessage* message,
+                            int status, int data1, int data2) {
+    message->type = SHORT_MESSAGE;
+    message->data.s.packedMsg = packMessage(status, data1, data2);
+}
+
+
+static void setRealtimeMessage(MidiMessage* message, int status) {
+    setShortMessage(message, status, 0, 0);
+}
+
+
+static void set14bitMessage(MidiMessage* message, int status, int value) {
+    TRACE3("14bit value: %d, lsb: %d, msb: %d\n", value, value & 0x7F, (value >> 7) & 0x7F);
+    value &= 0x3FFF;
+    TRACE3("14bit value (2): %d, lsb: %d, msb: %d\n", value, value & 0x7F, (value >> 7) & 0x7F);
+    setShortMessage(message, status,
+                    value & 0x7F,
+                    (value >> 7) & 0x7F);
+}
+
+
+/*
+ * implementation of the platform-dependent
+ * MIDI in functions declared in PlatformMidi.h
+ */
+
+char* MIDI_IN_GetErrorStr(INT32 err) {
+    return (char*) getErrorStr(err);
+}
+
+INT32 MIDI_IN_GetNumDevices() {
+/* Workaround for 6842956: 32bit app on 64bit bsd
+ * gets assertion failure trying to open midiIn ports.
+ * Untill the issue is fixed in ALSA
+ * (https://bugtrack.alsa-project.org/alsa-bug/view.php?id=4807)
+ * report no midi in devices in the configuration.
+ */
+#if defined(i586)
+    static int jre32onbsd64 = -1;
+    if (jre32onbsd64 < 0) {
+        jre32onbsd64 = 0;
+        /* The workaround may be disabled setting "JAVASOUND_ENABLE_MIDIIN"
+         * environment variable.
+         */
+        if (getenv("JAVASOUND_ENABLE_MIDIIN") == NULL) {
+            struct utsname u;
+            jre32onbsd64 = 0;
+            if (uname(&u) == 0) {
+                if (strstr(u.machine, "64") != NULL) {
+                    TRACE0("jre32 on bsd64 detected - report no midiIn devices\n");
+                    jre32onbsd64 = 1;
+                }
+            }
+        }
+    }
+    if (jre32onbsd64) {
+        return 0;
+    }
+#endif
+
+    TRACE0("MIDI_IN_GetNumDevices()\n");
+
+    return getMidiDeviceCount(SND_RAWMIDI_STREAM_INPUT);
+}
+
+
+INT32 MIDI_IN_GetDeviceName(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    int ret = getMidiDeviceName(SND_RAWMIDI_STREAM_INPUT, deviceIndex,
+                                name, nameLength);
+    return ret;
+}
+
+
+INT32 MIDI_IN_GetDeviceVendor(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    int ret = getMidiDeviceVendor(deviceIndex, name, nameLength);
+    return ret;
+}
+
+
+INT32 MIDI_IN_GetDeviceDescription(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    int ret = getMidiDeviceDescription(SND_RAWMIDI_STREAM_INPUT, deviceIndex,
+                                       name, nameLength);
+    return ret;
+}
+
+
+INT32 MIDI_IN_GetDeviceVersion(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    int ret = getMidiDeviceVersion(deviceIndex, name, nameLength);
+    return ret;
+}
+
+/*************************************************************************/
+
+INT32 MIDI_IN_OpenDevice(INT32 deviceIndex, MidiDeviceHandle** handle) {
+    INT32 ret;
+    TRACE0("> MIDI_IN_OpenDevice\n");
+    ret = openMidiDevice(SND_RAWMIDI_STREAM_INPUT, deviceIndex, handle);
+    TRACE1("< MIDI_IN_OpenDevice: returning %d\n", (int) ret);
+    return ret;
+}
+
+
+INT32 MIDI_IN_CloseDevice(MidiDeviceHandle* handle) {
+    INT32 ret;
+    TRACE0("> MIDI_IN_CloseDevice\n");
+    ret = closeMidiDevice(handle);
+    TRACE1("< MIDI_IN_CloseDevice: returning %d\n", (int) ret);
+    return ret;
+}
+
+
+INT32 MIDI_IN_StartDevice(MidiDeviceHandle* handle) {
+    TRACE0("MIDI_IN_StartDevice\n");
+    return MIDI_SUCCESS;
+}
+
+
+INT32 MIDI_IN_StopDevice(MidiDeviceHandle* handle) {
+    TRACE0("MIDI_IN_StopDevice\n");
+    return MIDI_SUCCESS;
+}
+
+
+INT64 MIDI_IN_GetTimeStamp(MidiDeviceHandle* handle) {
+    return getMidiTimestamp(handle);
+}
+
+
+/* read the next message from the queue */
+MidiMessage* MIDI_IN_GetMessage(MidiDeviceHandle* handle) {
+    snd_seq_event_t alsa_message;
+    MidiMessage* jdk_message;
+    int err;
+    char buffer[1];
+    int status;
+
+    TRACE0("> MIDI_IN_GetMessage\n");
+    if (!handle) {
+        ERROR0("< ERROR: MIDI_IN_GetMessage(): handle is NULL\n");
+        return NULL;
+    }
+    if (!handle->deviceHandle) {
+        ERROR0("< ERROR: MIDI_IN_GetMessage(): native handle is NULL\n");
+        return NULL;
+    }
+    if (!handle->platformData) {
+        ERROR0("< ERROR: MIDI_IN_GetMessage(): platformData is NULL\n");
+        return NULL;
+    }
+
+    /* For MIDI In, the device is left in non blocking mode. So if there is
+       no data from the device, snd_rawmidi_read() returns with -11 (EAGAIN).
+       This results in jumping back to the Java layer. */
+    while (TRUE) {
+        TRACE0("before snd_rawmidi_read()\n");
+        err = snd_rawmidi_read((snd_rawmidi_t*) handle->deviceHandle, buffer, 1);
+        TRACE0("after snd_rawmidi_read()\n");
+        if (err != 1) {
+            ERROR2("< ERROR: MIDI_IN_GetMessage(): snd_rawmidi_read() returned %d : %s\n", err, snd_strerror(err));
+            return NULL;
+        }
+        // printf("received byte: %d\n", buffer[0]);
+        err = snd_midi_event_encode_byte((snd_midi_event_t*) handle->platformData,
+                                         (int) buffer[0],
+                                         &alsa_message);
+        if (err == 1) {
+            break;
+        } else if (err < 0) {
+            ERROR1("< ERROR: MIDI_IN_GetMessage(): snd_midi_event_encode_byte() returned %d\n", err);
+            return NULL;
+        }
+    }
+    jdk_message = (MidiMessage*) calloc(sizeof(MidiMessage), 1);
+    if (!jdk_message) {
+        ERROR0("< ERROR: MIDI_IN_GetMessage(): out of memory\n");
+        return NULL;
+    }
+    // TODO: tra
+    switch (alsa_message.type) {
+    case SND_SEQ_EVENT_NOTEON:
+    case SND_SEQ_EVENT_NOTEOFF:
+    case SND_SEQ_EVENT_KEYPRESS:
+        status = (alsa_message.type == SND_SEQ_EVENT_KEYPRESS) ? 0xA0 :
+            (alsa_message.type == SND_SEQ_EVENT_NOTEON) ? 0x90 : 0x80;
+        status |= alsa_message.data.note.channel;
+        setShortMessage(jdk_message, status,
+                        alsa_message.data.note.note,
+                        alsa_message.data.note.velocity);
+        break;
+
+    case SND_SEQ_EVENT_CONTROLLER:
+        status = 0xB0 | alsa_message.data.control.channel;
+        setShortMessage(jdk_message, status,
+                        alsa_message.data.control.param,
+                        alsa_message.data.control.value);
+        break;
+
+    case SND_SEQ_EVENT_PGMCHANGE:
+    case SND_SEQ_EVENT_CHANPRESS:
+        status = (alsa_message.type == SND_SEQ_EVENT_PGMCHANGE) ? 0xC0 : 0xD0;
+        status |= alsa_message.data.control.channel;
+        setShortMessage(jdk_message, status,
+                        alsa_message.data.control.value, 0);
+        break;
+
+    case SND_SEQ_EVENT_PITCHBEND:
+        status = 0xE0 | alsa_message.data.control.channel;
+        // $$mp 2003-09-23:
+        // possible hack to work around a bug in ALSA. Necessary for
+        // ALSA 0.9.2. May be fixed in newer versions of ALSA.
+        // alsa_message.data.control.value ^= 0x2000;
+        // TRACE1("pitchbend value: %d\n", alsa_message.data.control.value);
+        set14bitMessage(jdk_message, status,
+                        alsa_message.data.control.value);
+        break;
+
+        /* System exclusive messages */
+
+    case SND_SEQ_EVENT_SYSEX:
+        jdk_message->type = LONG_MESSAGE;
+        jdk_message->data.l.size = alsa_message.data.ext.len;
+        jdk_message->data.l.data = malloc(alsa_message.data.ext.len);
+        if (jdk_message->data.l.data == NULL) {
+            ERROR0("< ERROR: MIDI_IN_GetMessage(): out of memory\n");
+            free(jdk_message);
+            jdk_message = NULL;
+        } else {
+            memcpy(jdk_message->data.l.data, alsa_message.data.ext.ptr, alsa_message.data.ext.len);
+        }
+        break;
+
+        /* System common messages */
+
+    case SND_SEQ_EVENT_QFRAME:
+        setShortMessage(jdk_message, 0xF1,
+                        alsa_message.data.control.value & 0x7F, 0);
+        break;
+
+    case SND_SEQ_EVENT_SONGPOS:
+        set14bitMessage(jdk_message, 0xF2,
+                        alsa_message.data.control.value);
+        break;
+
+    case SND_SEQ_EVENT_SONGSEL:
+        setShortMessage(jdk_message, 0xF3,
+                        alsa_message.data.control.value & 0x7F, 0);
+        break;
+
+    case SND_SEQ_EVENT_TUNE_REQUEST:
+        setRealtimeMessage(jdk_message, 0xF6);
+        break;
+
+        /* System realtime messages */
+
+    case SND_SEQ_EVENT_CLOCK:
+        setRealtimeMessage(jdk_message, 0xF8);
+        break;
+
+    case SND_SEQ_EVENT_START:
+        setRealtimeMessage(jdk_message, 0xFA);
+        break;
+
+    case SND_SEQ_EVENT_CONTINUE:
+        setRealtimeMessage(jdk_message, 0xFB);
+        break;
+
+    case SND_SEQ_EVENT_STOP:
+        setRealtimeMessage(jdk_message, 0xFC);
+        break;
+
+    case SND_SEQ_EVENT_SENSING:
+        setRealtimeMessage(jdk_message, 0xFE);
+        break;
+
+    case SND_SEQ_EVENT_RESET:
+        setRealtimeMessage(jdk_message, 0xFF);
+        break;
+
+    default:
+        ERROR0("< ERROR: MIDI_IN_GetMessage(): unhandled ALSA MIDI message type\n");
+        free(jdk_message);
+        jdk_message = NULL;
+
+    }
+
+    // set timestamp
+    if (jdk_message != NULL) {
+        jdk_message->timestamp = getMidiTimestamp(handle);
+    }
+    TRACE1("< MIDI_IN_GetMessage: returning %p\n", jdk_message);
+    return jdk_message;
+}
+
+
+void MIDI_IN_ReleaseMessage(MidiDeviceHandle* handle, MidiMessage* msg) {
+    if (!msg) {
+        ERROR0("< ERROR: MIDI_IN_ReleaseMessage(): message is NULL\n");
+        return;
+    }
+    if (msg->type == LONG_MESSAGE && msg->data.l.data) {
+        free(msg->data.l.data);
+    }
+    free(msg);
+}
+
+#endif /* USE_PLATFORM_MIDI_IN */
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiOut.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiOut.c
new file mode 100644
index 0000000..482d189
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiOut.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#define USE_ERROR
+#define USE_TRACE
+
+#if USE_PLATFORM_MIDI_OUT == TRUE
+
+#include <alsa/asoundlib.h>
+#include "PlatformMidi.h"
+#include "PLATFORM_API_BsdOS_ALSA_MidiUtils.h"
+
+
+
+static int CHANNEL_MESSAGE_LENGTH[] = {
+    -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3, 2, 2, 3 };
+/*                                 8x 9x Ax Bx Cx Dx Ex */
+
+static int SYSTEM_MESSAGE_LENGTH[] = {
+    -1, 2, 3, 2, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1 };
+/*  F0 F1 F2 F3  F4  F5 F6 F7 F8  F9 FA FB FC  FD FE FF */
+
+
+// the returned length includes the status byte.
+// for illegal messages, -1 is returned.
+static int getShortMessageLength(int status) {
+        int     dataLength = 0;
+        if (status < 0xF0) { // channel voice message
+                dataLength = CHANNEL_MESSAGE_LENGTH[(status >> 4) & 0xF];
+        } else {
+                dataLength = SYSTEM_MESSAGE_LENGTH[status & 0xF];
+        }
+        return dataLength;
+}
+
+
+/*
+ * implementation of the platform-dependent
+ * MIDI out functions declared in PlatformMidi.h
+ */
+char* MIDI_OUT_GetErrorStr(INT32 err) {
+    return (char*) getErrorStr(err);
+}
+
+
+INT32 MIDI_OUT_GetNumDevices() {
+    TRACE0("MIDI_OUT_GetNumDevices()\n");
+    return getMidiDeviceCount(SND_RAWMIDI_STREAM_OUTPUT);
+}
+
+
+INT32 MIDI_OUT_GetDeviceName(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    TRACE0("MIDI_OUT_GetDeviceName()\n");
+    return getMidiDeviceName(SND_RAWMIDI_STREAM_OUTPUT, deviceIndex,
+                             name, nameLength);
+}
+
+
+INT32 MIDI_OUT_GetDeviceVendor(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    TRACE0("MIDI_OUT_GetDeviceVendor()\n");
+    return getMidiDeviceVendor(deviceIndex, name, nameLength);
+}
+
+
+INT32 MIDI_OUT_GetDeviceDescription(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    TRACE0("MIDI_OUT_GetDeviceDescription()\n");
+    return getMidiDeviceDescription(SND_RAWMIDI_STREAM_OUTPUT, deviceIndex,
+                                    name, nameLength);
+}
+
+
+INT32 MIDI_OUT_GetDeviceVersion(INT32 deviceIndex, char *name, UINT32 nameLength) {
+    TRACE0("MIDI_OUT_GetDeviceVersion()\n");
+    return getMidiDeviceVersion(deviceIndex, name, nameLength);
+}
+
+
+/* *************************** MidiOutDevice implementation *************** */
+
+INT32 MIDI_OUT_OpenDevice(INT32 deviceIndex, MidiDeviceHandle** handle) {
+    TRACE1("MIDI_OUT_OpenDevice(): deviceIndex: %d\n", (int) deviceIndex);
+    return openMidiDevice(SND_RAWMIDI_STREAM_OUTPUT, deviceIndex, handle);
+}
+
+
+INT32 MIDI_OUT_CloseDevice(MidiDeviceHandle* handle) {
+    TRACE0("MIDI_OUT_CloseDevice()\n");
+    return closeMidiDevice(handle);
+}
+
+
+INT64 MIDI_OUT_GetTimeStamp(MidiDeviceHandle* handle) {
+    return getMidiTimestamp(handle);
+}
+
+
+INT32 MIDI_OUT_SendShortMessage(MidiDeviceHandle* handle, UINT32 packedMsg,
+                                UINT32 timestamp) {
+    int err;
+    int status;
+    int data1;
+    int data2;
+    char buffer[3];
+
+    TRACE2("> MIDI_OUT_SendShortMessage() %x, time: %u\n", packedMsg, (unsigned int) timestamp);
+    if (!handle) {
+        ERROR0("< ERROR: MIDI_OUT_SendShortMessage(): handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    if (!handle->deviceHandle) {
+        ERROR0("< ERROR: MIDI_OUT_SendLongMessage(): native handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    status = (packedMsg & 0xFF);
+    buffer[0] = (char) status;
+    buffer[1]  = (char) ((packedMsg >> 8) & 0xFF);
+    buffer[2]  = (char) ((packedMsg >> 16) & 0xFF);
+    TRACE4("status: %d, data1: %d, data2: %d, length: %d\n", (int) buffer[0], (int) buffer[1], (int) buffer[2], getShortMessageLength(status));
+    err = snd_rawmidi_write((snd_rawmidi_t*) handle->deviceHandle, buffer, getShortMessageLength(status));
+    if (err < 0) {
+        ERROR1("  ERROR: MIDI_OUT_SendShortMessage(): snd_rawmidi_write() returned %d\n", err);
+    }
+
+    TRACE0("< MIDI_OUT_SendShortMessage()\n");
+    return err;
+}
+
+
+INT32 MIDI_OUT_SendLongMessage(MidiDeviceHandle* handle, UBYTE* data,
+                               UINT32 size, UINT32 timestamp) {
+    int err;
+
+    TRACE2("> MIDI_OUT_SendLongMessage() size %u, time: %u\n", (unsigned int) size, (unsigned int) timestamp);
+    if (!handle) {
+        ERROR0("< ERROR: MIDI_OUT_SendLongMessage(): handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    if (!handle->deviceHandle) {
+        ERROR0("< ERROR: MIDI_OUT_SendLongMessage(): native handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    if (!data) {
+        ERROR0("< ERROR: MIDI_OUT_SendLongMessage(): data is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    err = snd_rawmidi_write((snd_rawmidi_t*) handle->deviceHandle,
+                            data, size);
+    if (err < 0) {
+        ERROR1("  ERROR: MIDI_OUT_SendLongMessage(): snd_rawmidi_write() returned %d\n", err);
+    }
+
+    TRACE0("< MIDI_OUT_SendLongMessage()\n");
+    return err;
+}
+
+
+#endif /* USE_PLATFORM_MIDI_OUT */
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c
new file mode 100644
index 0000000..71c4814
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c
@@ -0,0 +1,480 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#define USE_ERROR
+#define USE_TRACE
+
+#include "PLATFORM_API_BsdOS_ALSA_MidiUtils.h"
+#include "PLATFORM_API_BsdOS_ALSA_CommonUtils.h"
+#include <string.h>
+#include <sys/time.h>
+
+static INT64 getTimeInMicroseconds() {
+    struct timeval tv;
+
+    gettimeofday(&tv, NULL);
+    return (tv.tv_sec * 1000000UL) + tv.tv_usec;
+}
+
+
+const char* getErrorStr(INT32 err) {
+        return snd_strerror((int) err);
+}
+
+
+
+// callback for iteration through devices
+// returns TRUE if iteration should continue
+typedef int (*DeviceIteratorPtr)(UINT32 deviceID,
+                                 snd_rawmidi_info_t* rawmidi_info,
+                                 snd_ctl_card_info_t* cardinfo,
+                                 void *userData);
+
+// for each ALSA device, call iterator. userData is passed to the iterator
+// returns total number of iterations
+static int iterateRawmidiDevices(snd_rawmidi_stream_t direction,
+                                 DeviceIteratorPtr iterator,
+                                 void* userData) {
+    int count = 0;
+    int subdeviceCount;
+    int card, dev, subDev;
+    char devname[16];
+    int err;
+    snd_ctl_t *handle;
+    snd_rawmidi_t *rawmidi;
+    snd_rawmidi_info_t *rawmidi_info;
+    snd_ctl_card_info_t *card_info, *defcardinfo = NULL;
+    UINT32 deviceID;
+    int doContinue = TRUE;
+
+    snd_rawmidi_info_malloc(&rawmidi_info);
+    snd_ctl_card_info_malloc(&card_info);
+
+    // 1st try "default" device
+    if (direction == SND_RAWMIDI_STREAM_INPUT) {
+        err = snd_rawmidi_open(&rawmidi, NULL, ALSA_DEFAULT_DEVICE_NAME,
+                               SND_RAWMIDI_NONBLOCK);
+    } else if (direction == SND_RAWMIDI_STREAM_OUTPUT) {
+        err = snd_rawmidi_open(NULL, &rawmidi, ALSA_DEFAULT_DEVICE_NAME,
+                               SND_RAWMIDI_NONBLOCK);
+    } else {
+        ERROR0("ERROR: iterateRawmidiDevices(): direction is neither"
+               " SND_RAWMIDI_STREAM_INPUT nor SND_RAWMIDI_STREAM_OUTPUT\n");
+        err = MIDI_INVALID_ARGUMENT;
+    }
+    if (err < 0) {
+        ERROR1("ERROR: snd_rawmidi_open (\"default\"): %s\n",
+               snd_strerror(err));
+    } else {
+        err = snd_rawmidi_info(rawmidi, rawmidi_info);
+
+        snd_rawmidi_close(rawmidi);
+        if (err < 0) {
+            ERROR1("ERROR: snd_rawmidi_info (\"default\"): %s\n",
+                    snd_strerror(err));
+        } else {
+            // try to get card info
+            card = snd_rawmidi_info_get_card(rawmidi_info);
+            if (card >= 0) {
+                sprintf(devname, ALSA_HARDWARE_CARD, card);
+                if (snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK) >= 0) {
+                    if (snd_ctl_card_info(handle, card_info) >= 0) {
+                        defcardinfo = card_info;
+                    }
+                    snd_ctl_close(handle);
+                }
+            }
+            // call calback function for the device
+            if (iterator != NULL) {
+                doContinue = (*iterator)(ALSA_DEFAULT_DEVICE_ID, rawmidi_info,
+                                         defcardinfo, userData);
+            }
+            count++;
+        }
+    }
+
+    // iterate cards
+    card = -1;
+    TRACE0("testing for cards...\n");
+    if (snd_card_next(&card) >= 0) {
+        TRACE1("Found card %d\n", card);
+        while (doContinue && (card >= 0)) {
+            sprintf(devname, ALSA_HARDWARE_CARD, card);
+            TRACE1("Opening control for alsa rawmidi device \"%s\"...\n", devname);
+            err = snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK);
+            if (err < 0) {
+                ERROR2("ERROR: snd_ctl_open, card=%d: %s\n", card, snd_strerror(err));
+            } else {
+                TRACE0("snd_ctl_open() SUCCESS\n");
+                err = snd_ctl_card_info(handle, card_info);
+                if (err < 0) {
+                    ERROR2("ERROR: snd_ctl_card_info, card=%d: %s\n", card, snd_strerror(err));
+                } else {
+                    TRACE0("snd_ctl_card_info() SUCCESS\n");
+                    dev = -1;
+                    while (doContinue) {
+                        if (snd_ctl_rawmidi_next_device(handle, &dev) < 0) {
+                            ERROR0("snd_ctl_rawmidi_next_device\n");
+                        }
+                        TRACE0("snd_ctl_rawmidi_next_device() SUCCESS\n");
+                        if (dev < 0) {
+                            break;
+                        }
+                        snd_rawmidi_info_set_device(rawmidi_info, dev);
+                        snd_rawmidi_info_set_subdevice(rawmidi_info, 0);
+                        snd_rawmidi_info_set_stream(rawmidi_info, direction);
+                        err = snd_ctl_rawmidi_info(handle, rawmidi_info);
+                        TRACE0("after snd_ctl_rawmidi_info()\n");
+                        if (err < 0) {
+                            if (err != -ENOENT) {
+                                ERROR2("ERROR: snd_ctl_rawmidi_info, card=%d: %s", card, snd_strerror(err));
+                            }
+                        } else {
+                            TRACE0("snd_ctl_rawmidi_info() SUCCESS\n");
+                            subdeviceCount = needEnumerateSubdevices(ALSA_RAWMIDI)
+                                ? snd_rawmidi_info_get_subdevices_count(rawmidi_info)
+                                : 1;
+                            if (iterator!=NULL) {
+                                for (subDev = 0; subDev < subdeviceCount; subDev++) {
+                                    TRACE3("  Iterating %d,%d,%d\n", card, dev, subDev);
+                                    deviceID = encodeDeviceID(card, dev, subDev);
+                                    doContinue = (*iterator)(deviceID, rawmidi_info,
+                                                             card_info, userData);
+                                    count++;
+                                    TRACE0("returned from iterator\n");
+                                    if (!doContinue) {
+                                        break;
+                                    }
+                                }
+                            } else {
+                                count += subdeviceCount;
+                            }
+                        }
+                    } // of while(doContinue)
+                }
+                snd_ctl_close(handle);
+            }
+            if (snd_card_next(&card) < 0) {
+                break;
+            }
+        }
+    } else {
+        ERROR0("No cards found!\n");
+    }
+    snd_ctl_card_info_free(card_info);
+    snd_rawmidi_info_free(rawmidi_info);
+    return count;
+}
+
+
+
+int getMidiDeviceCount(snd_rawmidi_stream_t direction) {
+    int deviceCount;
+    TRACE0("> getMidiDeviceCount()\n");
+    initAlsaSupport();
+    deviceCount = iterateRawmidiDevices(direction, NULL, NULL);
+    TRACE0("< getMidiDeviceCount()\n");
+    return deviceCount;
+}
+
+
+
+/*
+  userData is assumed to be a pointer to ALSA_MIDIDeviceDescription.
+  ALSA_MIDIDeviceDescription->index has to be set to the index of the device
+  we want to get information of before this method is called the first time via
+  iterateRawmidiDevices(). On each call of this method,
+  ALSA_MIDIDeviceDescription->index is decremented. If it is equal to zero,
+  we have reached the desired device, so action is taken.
+  So after successful completion of iterateRawmidiDevices(),
+  ALSA_MIDIDeviceDescription->index is zero. If it isn't, this is an
+  indication of an error.
+*/
+static int deviceInfoIterator(UINT32 deviceID, snd_rawmidi_info_t *rawmidi_info,
+                              snd_ctl_card_info_t *cardinfo, void *userData) {
+    char buffer[300];
+    ALSA_MIDIDeviceDescription* desc = (ALSA_MIDIDeviceDescription*)userData;
+#ifdef ALSA_MIDI_USE_PLUGHW
+    int usePlugHw = 1;
+#else
+    int usePlugHw = 0;
+#endif
+
+    TRACE0("deviceInfoIterator\n");
+    initAlsaSupport();
+    if (desc->index == 0) {
+        // we found the device with correct index
+        desc->deviceID = deviceID;
+
+        buffer[0]=' '; buffer[1]='[';
+        getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_RAWMIDI);
+        strcat(buffer, "]");
+        strncpy(desc->name,
+                (cardinfo != NULL)
+                    ? snd_ctl_card_info_get_id(cardinfo)
+                    : snd_rawmidi_info_get_id(rawmidi_info),
+                desc->strLen - strlen(buffer));
+        strncat(desc->name, buffer, desc->strLen - strlen(desc->name));
+        desc->description[0] = 0;
+        if (cardinfo != NULL) {
+            strncpy(desc->description, snd_ctl_card_info_get_name(cardinfo),
+                    desc->strLen);
+            strncat(desc->description, ", ",
+                    desc->strLen - strlen(desc->description));
+        }
+        strncat(desc->description, snd_rawmidi_info_get_id(rawmidi_info),
+                desc->strLen - strlen(desc->description));
+        strncat(desc->description, ", ", desc->strLen - strlen(desc->description));
+        strncat(desc->description, snd_rawmidi_info_get_name(rawmidi_info),
+                desc->strLen - strlen(desc->description));
+        TRACE2("Returning %s, %s\n", desc->name, desc->description);
+        return FALSE; // do not continue iteration
+    }
+    desc->index--;
+    return TRUE;
+}
+
+
+static int getMIDIDeviceDescriptionByIndex(snd_rawmidi_stream_t direction,
+                                           ALSA_MIDIDeviceDescription* desc) {
+    initAlsaSupport();
+    TRACE1(" getMIDIDeviceDescriptionByIndex (index = %d)\n", desc->index);
+    iterateRawmidiDevices(direction, &deviceInfoIterator, desc);
+    return (desc->index == 0) ? MIDI_SUCCESS : MIDI_INVALID_DEVICEID;
+}
+
+
+
+int initMIDIDeviceDescription(ALSA_MIDIDeviceDescription* desc, int index) {
+    int ret = MIDI_SUCCESS;
+    desc->index = index;
+    desc->strLen = 200;
+    desc->name = (char*) calloc(desc->strLen + 1, 1);
+    desc->description = (char*) calloc(desc->strLen + 1, 1);
+    if (! desc->name ||
+        ! desc->description) {
+        ret = MIDI_OUT_OF_MEMORY;
+    }
+    return ret;
+}
+
+
+void freeMIDIDeviceDescription(ALSA_MIDIDeviceDescription* desc) {
+    if (desc->name) {
+        free(desc->name);
+    }
+    if (desc->description) {
+        free(desc->description);
+    }
+}
+
+
+int getMidiDeviceName(snd_rawmidi_stream_t direction, int index, char *name,
+                      UINT32 nameLength) {
+    ALSA_MIDIDeviceDescription desc;
+    int ret;
+
+    TRACE1("getMidiDeviceName: nameLength: %d\n", (int) nameLength);
+    ret = initMIDIDeviceDescription(&desc, index);
+    if (ret == MIDI_SUCCESS) {
+        TRACE0("getMidiDeviceName: initMIDIDeviceDescription() SUCCESS\n");
+        ret = getMIDIDeviceDescriptionByIndex(direction, &desc);
+        if (ret == MIDI_SUCCESS) {
+            TRACE1("getMidiDeviceName: desc.name: %s\n", desc.name);
+            strncpy(name, desc.name, nameLength - 1);
+            name[nameLength - 1] = 0;
+        }
+    }
+    freeMIDIDeviceDescription(&desc);
+    return ret;
+}
+
+
+int getMidiDeviceVendor(int index, char *name, UINT32 nameLength) {
+    strncpy(name, ALSA_VENDOR, nameLength - 1);
+    name[nameLength - 1] = 0;
+    return MIDI_SUCCESS;
+}
+
+
+int getMidiDeviceDescription(snd_rawmidi_stream_t direction,
+                             int index, char *name, UINT32 nameLength) {
+    ALSA_MIDIDeviceDescription desc;
+    int ret;
+
+    ret = initMIDIDeviceDescription(&desc, index);
+    if (ret == MIDI_SUCCESS) {
+        ret = getMIDIDeviceDescriptionByIndex(direction, &desc);
+        if (ret == MIDI_SUCCESS) {
+            strncpy(name, desc.description, nameLength - 1);
+            name[nameLength - 1] = 0;
+        }
+    }
+    freeMIDIDeviceDescription(&desc);
+    return ret;
+}
+
+
+int getMidiDeviceVersion(int index, char *name, UINT32 nameLength) {
+    getALSAVersion(name, nameLength);
+    return MIDI_SUCCESS;
+}
+
+
+static int getMidiDeviceID(snd_rawmidi_stream_t direction, int index,
+                           UINT32* deviceID) {
+    ALSA_MIDIDeviceDescription desc;
+    int ret;
+
+    ret = initMIDIDeviceDescription(&desc, index);
+    if (ret == MIDI_SUCCESS) {
+        ret = getMIDIDeviceDescriptionByIndex(direction, &desc);
+        if (ret == MIDI_SUCCESS) {
+            // TRACE1("getMidiDeviceName: desc.name: %s\n", desc.name);
+            *deviceID = desc.deviceID;
+        }
+    }
+    freeMIDIDeviceDescription(&desc);
+    return ret;
+}
+
+
+/*
+  direction has to be either SND_RAWMIDI_STREAM_INPUT or
+  SND_RAWMIDI_STREAM_OUTPUT.
+  Returns 0 on success. Otherwise, MIDI_OUT_OF_MEMORY, MIDI_INVALID_ARGUMENT
+   or a negative ALSA error code is returned.
+*/
+INT32 openMidiDevice(snd_rawmidi_stream_t direction, INT32 deviceIndex,
+                     MidiDeviceHandle** handle) {
+    snd_rawmidi_t* native_handle;
+    snd_midi_event_t* event_parser = NULL;
+    int err;
+    UINT32 deviceID = 0;
+    char devicename[100];
+#ifdef ALSA_MIDI_USE_PLUGHW
+    int usePlugHw = 1;
+#else
+    int usePlugHw = 0;
+#endif
+
+    TRACE0("> openMidiDevice()\n");
+
+    (*handle) = (MidiDeviceHandle*) calloc(sizeof(MidiDeviceHandle), 1);
+    if (!(*handle)) {
+        ERROR0("ERROR: openDevice: out of memory\n");
+        return MIDI_OUT_OF_MEMORY;
+    }
+
+    // TODO: iterate to get dev ID from index
+    err = getMidiDeviceID(direction, deviceIndex, &deviceID);
+    TRACE1("  openMidiDevice(): deviceID: %d\n", (int) deviceID);
+    getDeviceStringFromDeviceID(devicename, deviceID,
+                                usePlugHw, ALSA_RAWMIDI);
+    TRACE1("  openMidiDevice(): deviceString: %s\n", devicename);
+
+    // finally open the device
+    if (direction == SND_RAWMIDI_STREAM_INPUT) {
+        err = snd_rawmidi_open(&native_handle, NULL, devicename,
+                               SND_RAWMIDI_NONBLOCK);
+    } else if (direction == SND_RAWMIDI_STREAM_OUTPUT) {
+        err = snd_rawmidi_open(NULL, &native_handle, devicename,
+                               SND_RAWMIDI_NONBLOCK);
+    } else {
+        ERROR0("  ERROR: openMidiDevice(): direction is neither SND_RAWMIDI_STREAM_INPUT nor SND_RAWMIDI_STREAM_OUTPUT\n");
+        err = MIDI_INVALID_ARGUMENT;
+    }
+    if (err < 0) {
+        ERROR1("<  ERROR: openMidiDevice(): snd_rawmidi_open() returned %d\n", err);
+        free(*handle);
+        (*handle) = NULL;
+        return err;
+    }
+    /* We opened with non-blocking behaviour to not get hung if the device
+       is used by a different process. Writing, however, should
+       be blocking. So we change it here. */
+    if (direction == SND_RAWMIDI_STREAM_OUTPUT) {
+        err = snd_rawmidi_nonblock(native_handle, 0);
+        if (err < 0) {
+            ERROR1("  ERROR: openMidiDevice(): snd_rawmidi_nonblock() returned %d\n", err);
+            snd_rawmidi_close(native_handle);
+            free(*handle);
+            (*handle) = NULL;
+            return err;
+        }
+    }
+    if (direction == SND_RAWMIDI_STREAM_INPUT) {
+        err = snd_midi_event_new(EVENT_PARSER_BUFSIZE, &event_parser);
+        if (err < 0) {
+            ERROR1("  ERROR: openMidiDevice(): snd_midi_event_new() returned %d\n", err);
+            snd_rawmidi_close(native_handle);
+            free(*handle);
+            (*handle) = NULL;
+            return err;
+        }
+    }
+
+    (*handle)->deviceHandle = (void*) native_handle;
+    (*handle)->startTime = getTimeInMicroseconds();
+    (*handle)->platformData = event_parser;
+    TRACE0("< openMidiDevice(): succeeded\n");
+    return err;
+}
+
+
+
+INT32 closeMidiDevice(MidiDeviceHandle* handle) {
+    int err;
+
+    TRACE0("> closeMidiDevice()\n");
+    if (!handle) {
+        ERROR0("< ERROR: closeMidiDevice(): handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    if (!handle->deviceHandle) {
+        ERROR0("< ERROR: closeMidiDevice(): native handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    err = snd_rawmidi_close((snd_rawmidi_t*) handle->deviceHandle);
+    TRACE1("  snd_rawmidi_close() returns %d\n", err);
+    if (handle->platformData) {
+        snd_midi_event_free((snd_midi_event_t*) handle->platformData);
+    }
+    free(handle);
+    TRACE0("< closeMidiDevice: succeeded\n");
+    return err;
+}
+
+
+INT64 getMidiTimestamp(MidiDeviceHandle* handle) {
+    if (!handle) {
+        ERROR0("< ERROR: closeMidiDevice(): handle is NULL\n");
+        return MIDI_INVALID_HANDLE;
+    }
+    return getTimeInMicroseconds() - handle->startTime;
+}
+
+
+/* end */
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.h b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.h
new file mode 100644
index 0000000..03c718f
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <alsa/asoundlib.h>
+#include "Utilities.h"
+#include "PlatformMidi.h"
+
+
+#ifndef PLATFORM_API_BSDOS_ALSA_MIDIUTILS_H_INCLUDED
+#define PLATFORM_API_BSDOS_ALSA_MIDIUTILS_H_INCLUDED
+
+#define EVENT_PARSER_BUFSIZE (2048)
+
+// if this is defined, use plughw: devices
+//#define ALSA_MIDI_USE_PLUGHW
+#undef ALSA_MIDI_USE_PLUGHW
+
+typedef struct tag_ALSA_MIDIDeviceDescription {
+        int index;          // in
+        int strLen;         // in
+        INT32 deviceID;    // out
+        char* name;         // out
+        char* description;  // out
+} ALSA_MIDIDeviceDescription;
+
+
+const char* getErrorStr(INT32 err);
+
+/* Returns the number of devices. */
+/* direction is either SND_RAWMIDI_STREAM_OUTPUT or
+   SND_RAWMIDI_STREAM_INPUT. */
+int getMidiDeviceCount(snd_rawmidi_stream_t direction);
+
+/* Returns MIDI_SUCCESS or MIDI_INVALID_DEVICEID */
+/* direction is either SND_RAWMIDI_STREAM_OUTPUT or
+   SND_RAWMIDI_STREAM_INPUT. */
+int getMidiDeviceName(snd_rawmidi_stream_t direction, int index,
+                      char *name, UINT32 nameLength);
+
+/* Returns MIDI_SUCCESS or MIDI_INVALID_DEVICEID */
+int getMidiDeviceVendor(int index, char *name, UINT32 nameLength);
+
+/* Returns MIDI_SUCCESS or MIDI_INVALID_DEVICEID */
+/* direction is either SND_RAWMIDI_STREAM_OUTPUT or
+   SND_RAWMIDI_STREAM_INPUT. */
+int getMidiDeviceDescription(snd_rawmidi_stream_t direction, int index,
+                             char *name, UINT32 nameLength);
+
+/* Returns MIDI_SUCCESS or MIDI_INVALID_DEVICEID */
+int getMidiDeviceVersion(int index, char *name, UINT32 nameLength);
+
+// returns 0 on success, otherwise MIDI_OUT_OF_MEMORY or ALSA error code
+/* direction is either SND_RAWMIDI_STREAM_OUTPUT or
+   SND_RAWMIDI_STREAM_INPUT. */
+INT32 openMidiDevice(snd_rawmidi_stream_t direction, INT32 deviceIndex,
+                     MidiDeviceHandle** handle);
+
+// returns 0 on success, otherwise a (negative) ALSA error code
+INT32 closeMidiDevice(MidiDeviceHandle* handle);
+
+INT64 getMidiTimestamp(MidiDeviceHandle* handle);
+
+#endif // PLATFORM_API_BSDOS_ALSA_MIDIUTILS_H_INCLUDED
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCM.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCM.c
new file mode 100644
index 0000000..54206cd
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCM.c
@@ -0,0 +1,938 @@
+/*
+ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#define USE_ERROR
+#define USE_TRACE
+
+#include "PLATFORM_API_BsdOS_ALSA_PCMUtils.h"
+#include "PLATFORM_API_BsdOS_ALSA_CommonUtils.h"
+#include "DirectAudio.h"
+
+#if USE_DAUDIO == TRUE
+
+// GetPosition method 1: based on how many bytes are passed to the kernel driver
+//                       + does not need much processor resources
+//                       - not very exact, "jumps"
+// GetPosition method 2: ask kernel about actual position of playback.
+//                       - very exact
+//                       - switch to kernel layer for each call
+// GetPosition method 3: use snd_pcm_avail() call - not yet in official ALSA
+// quick tests on a Pentium 200MMX showed max. 1.5% processor usage
+// for playing back a CD-quality file and printing 20x per second a line
+// on the console with the current time. So I guess performance is not such a
+// factor here.
+//#define GET_POSITION_METHOD1
+#define GET_POSITION_METHOD2
+
+
+// The default time for a period in microseconds.
+// For very small buffers, only 2 periods are used.
+#define DEFAULT_PERIOD_TIME 20000 /* 20ms */
+
+///// implemented functions of DirectAudio.h
+
+INT32 DAUDIO_GetDirectAudioDeviceCount() {
+    return (INT32) getAudioDeviceCount();
+}
+
+
+INT32 DAUDIO_GetDirectAudioDeviceDescription(INT32 mixerIndex, DirectAudioDeviceDescription* description) {
+    ALSA_AudioDeviceDescription adesc;
+
+    adesc.index = (int) mixerIndex;
+    adesc.strLen = DAUDIO_STRING_LENGTH;
+
+    adesc.maxSimultaneousLines = (int*) (&(description->maxSimulLines));
+    adesc.deviceID = &(description->deviceID);
+    adesc.name = description->name;
+    adesc.vendor = description->vendor;
+    adesc.description = description->description;
+    adesc.version = description->version;
+
+    return getAudioDeviceDescriptionByIndex(&adesc);
+}
+
+#define MAX_BIT_INDEX 6
+// returns
+// 6: for anything above 24-bit
+// 5: for 4 bytes sample size, 24-bit
+// 4: for 3 bytes sample size, 24-bit
+// 3: for 3 bytes sample size, 20-bit
+// 2: for 2 bytes sample size, 16-bit
+// 1: for 1 byte sample size, 8-bit
+// 0: for anything else
+int getBitIndex(int sampleSizeInBytes, int significantBits) {
+    if (significantBits > 24) return 6;
+    if (sampleSizeInBytes == 4 && significantBits == 24) return 5;
+    if (sampleSizeInBytes == 3) {
+        if (significantBits == 24) return 4;
+        if (significantBits == 20) return 3;
+    }
+    if (sampleSizeInBytes == 2 && significantBits == 16) return 2;
+    if (sampleSizeInBytes == 1 && significantBits == 8) return 1;
+    return 0;
+}
+
+int getSampleSizeInBytes(int bitIndex, int sampleSizeInBytes) {
+    switch(bitIndex) {
+    case 1: return 1;
+    case 2: return 2;
+    case 3: /* fall through */
+    case 4: return 3;
+    case 5: return 4;
+    }
+    return sampleSizeInBytes;
+}
+
+int getSignificantBits(int bitIndex, int significantBits) {
+    switch(bitIndex) {
+    case 1: return 8;
+    case 2: return 16;
+    case 3: return 20;
+    case 4: /* fall through */
+    case 5: return 24;
+    }
+    return significantBits;
+}
+
+void DAUDIO_GetFormats(INT32 mixerIndex, INT32 deviceID, int isSource, void* creator) {
+    snd_pcm_t* handle;
+    snd_pcm_format_mask_t* formatMask;
+    snd_pcm_format_t format;
+    snd_pcm_hw_params_t* hwParams;
+    int handledBits[MAX_BIT_INDEX+1];
+
+    int ret;
+    int sampleSizeInBytes, significantBits, isSigned, isBigEndian, enc;
+    int origSampleSizeInBytes, origSignificantBits;
+    unsigned int channels, minChannels, maxChannels;
+    int rate, bitIndex;
+
+    for (bitIndex = 0; bitIndex <= MAX_BIT_INDEX; bitIndex++) handledBits[bitIndex] = FALSE;
+    if (openPCMfromDeviceID(deviceID, &handle, isSource, TRUE /*query hardware*/) < 0) {
+        return;
+    }
+    ret = snd_pcm_format_mask_malloc(&formatMask);
+    if (ret != 0) {
+        ERROR1("snd_pcm_format_mask_malloc returned error %d\n", ret);
+    } else {
+        ret = snd_pcm_hw_params_malloc(&hwParams);
+        if (ret != 0) {
+            ERROR1("snd_pcm_hw_params_malloc returned error %d\n", ret);
+        } else {
+            ret = snd_pcm_hw_params_any(handle, hwParams);
+            /* snd_pcm_hw_params_any can return a positive value on success too */
+            if (ret < 0) {
+                 ERROR1("snd_pcm_hw_params_any returned error %d\n", ret);
+            } else {
+                /* for the logic following this code, set ret to 0 to indicate success */
+                ret = 0;
+            }
+        }
+        snd_pcm_hw_params_get_format_mask(hwParams, formatMask);
+        if (ret == 0) {
+            ret = snd_pcm_hw_params_get_channels_min(hwParams, &minChannels);
+            if (ret != 0) {
+                ERROR1("snd_pcm_hw_params_get_channels_min returned error %d\n", ret);
+            }
+        }
+        if (ret == 0) {
+            ret = snd_pcm_hw_params_get_channels_max(hwParams, &maxChannels);
+            if (ret != 0) {
+                ERROR1("snd_pcm_hw_params_get_channels_max returned error %d\n", ret);
+            }
+        }
+
+        // since we queried the hw: device, for many soundcards, it will only
+        // report the maximum number of channels (which is the only way to talk
+        // to the hw: device). Since we will, however, open the plughw: device
+        // when opening the Source/TargetDataLine, we can safely assume that
+        // also the channels 1..maxChannels are available.
+#ifdef ALSA_PCM_USE_PLUGHW
+        minChannels = 1;
+#endif
+        if (ret == 0) {
+            // plughw: supports any sample rate
+            rate = -1;
+            for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
+                if (snd_pcm_format_mask_test(formatMask, format)) {
+                    // format exists
+                    if (getFormatFromAlsaFormat(format, &origSampleSizeInBytes,
+                                                &origSignificantBits,
+                                                &isSigned, &isBigEndian, &enc)) {
+                        // now if we use plughw:, we can use any bit size below the
+                        // natively supported ones. Some ALSA drivers only support the maximum
+                        // bit size, so we add any sample rates below the reported one.
+                        // E.g. this iteration reports support for 16-bit.
+                        // getBitIndex will return 2, so it will add entries for
+                        // 16-bit (bitIndex=2) and in the next do-while loop iteration,
+                        // it will decrease bitIndex and will therefore add 8-bit support.
+                        bitIndex = getBitIndex(origSampleSizeInBytes, origSignificantBits);
+                        do {
+                            if (bitIndex == 0
+                                || bitIndex == MAX_BIT_INDEX
+                                || !handledBits[bitIndex]) {
+                                handledBits[bitIndex] = TRUE;
+                                sampleSizeInBytes = getSampleSizeInBytes(bitIndex, origSampleSizeInBytes);
+                                significantBits = getSignificantBits(bitIndex, origSignificantBits);
+                                if (maxChannels - minChannels > MAXIMUM_LISTED_CHANNELS) {
+                                    // avoid too many channels explicitly listed
+                                    // just add -1, min, and max
+                                    DAUDIO_AddAudioFormat(creator, significantBits,
+                                                          -1, -1, rate,
+                                                          enc, isSigned, isBigEndian);
+                                    DAUDIO_AddAudioFormat(creator, significantBits,
+                                                          sampleSizeInBytes * minChannels,
+                                                          minChannels, rate,
+                                                          enc, isSigned, isBigEndian);
+                                    DAUDIO_AddAudioFormat(creator, significantBits,
+                                                          sampleSizeInBytes * maxChannels,
+                                                          maxChannels, rate,
+                                                          enc, isSigned, isBigEndian);
+                                } else {
+                                    for (channels = minChannels; channels <= maxChannels; channels++) {
+                                        DAUDIO_AddAudioFormat(creator, significantBits,
+                                                              sampleSizeInBytes * channels,
+                                                              channels, rate,
+                                                              enc, isSigned, isBigEndian);
+                                    }
+                                }
+                            }
+#ifndef ALSA_PCM_USE_PLUGHW
+                            // without plugin, do not add fake formats
+                            break;
+#endif
+                        } while (--bitIndex > 0);
+                    } else {
+                        TRACE1("could not get format from alsa for format %d\n", format);
+                    }
+                } else {
+                    //TRACE1("Format %d not supported\n", format);
+                }
+            } // for loop
+            snd_pcm_hw_params_free(hwParams);
+        }
+        snd_pcm_format_mask_free(formatMask);
+    }
+    snd_pcm_close(handle);
+}
+
+/** Workaround for cr 7033899, 7030629:
+ * dmix plugin doesn't like flush (snd_pcm_drop) when the buffer is empty
+ * (just opened, underruned or already flushed).
+ * Sometimes it causes PCM falls to -EBADFD error,
+ * sometimes causes bufferSize change.
+ * To prevent unnecessary flushes AlsaPcmInfo::isRunning & isFlushed are used.
+ */
+/* ******* ALSA PCM INFO ******************** */
+typedef struct tag_AlsaPcmInfo {
+    snd_pcm_t* handle;
+    snd_pcm_hw_params_t* hwParams;
+    snd_pcm_sw_params_t* swParams;
+    int bufferSizeInBytes;
+    int frameSize; // storage size in Bytes
+    unsigned int periods;
+    snd_pcm_uframes_t periodSize;
+    short int isRunning;    // see comment above
+    short int isFlushed;    // see comment above
+#ifdef GET_POSITION_METHOD2
+    // to be used exclusively by getBytePosition!
+    snd_pcm_status_t* positionStatus;
+#endif
+} AlsaPcmInfo;
+
+
+int setStartThresholdNoCommit(AlsaPcmInfo* info, int useThreshold) {
+    int ret;
+    int threshold;
+
+    if (useThreshold) {
+        // start device whenever anything is written to the buffer
+        threshold = 1;
+    } else {
+        // never start the device automatically
+        threshold = 2000000000; /* near UINT_MAX */
+    }
+    ret = snd_pcm_sw_params_set_start_threshold(info->handle, info->swParams, threshold);
+    if (ret < 0) {
+        ERROR1("Unable to set start threshold mode: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    return TRUE;
+}
+
+int setStartThreshold(AlsaPcmInfo* info, int useThreshold) {
+    int ret = 0;
+
+    if (!setStartThresholdNoCommit(info, useThreshold)) {
+        ret = -1;
+    }
+    if (ret == 0) {
+        // commit it
+        ret = snd_pcm_sw_params(info->handle, info->swParams);
+        if (ret < 0) {
+            ERROR1("Unable to set sw params: %s\n", snd_strerror(ret));
+        }
+    }
+    return (ret == 0)?TRUE:FALSE;
+}
+
+
+// returns TRUE if successful
+int setHWParams(AlsaPcmInfo* info,
+                float sampleRate,
+                int channels,
+                int bufferSizeInFrames,
+                snd_pcm_format_t format) {
+    unsigned int rrate, periodTime, periods;
+    int ret, dir;
+    snd_pcm_uframes_t alsaBufferSizeInFrames = (snd_pcm_uframes_t) bufferSizeInFrames;
+
+    /* choose all parameters */
+    ret = snd_pcm_hw_params_any(info->handle, info->hwParams);
+    if (ret < 0) {
+        ERROR1("Broken configuration: no configurations available: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    /* set the interleaved read/write format */
+    ret = snd_pcm_hw_params_set_access(info->handle, info->hwParams, SND_PCM_ACCESS_RW_INTERLEAVED);
+    if (ret < 0) {
+        ERROR1("SND_PCM_ACCESS_RW_INTERLEAVED access type not available: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    /* set the sample format */
+    ret = snd_pcm_hw_params_set_format(info->handle, info->hwParams, format);
+    if (ret < 0) {
+        ERROR1("Sample format not available: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    /* set the count of channels */
+    ret = snd_pcm_hw_params_set_channels(info->handle, info->hwParams, channels);
+    if (ret < 0) {
+        ERROR2("Channels count (%d) not available: %s\n", channels, snd_strerror(ret));
+        return FALSE;
+    }
+    /* set the stream rate */
+    rrate = (int) (sampleRate + 0.5f);
+    dir = 0;
+    ret = snd_pcm_hw_params_set_rate_near(info->handle, info->hwParams, &rrate, &dir);
+    if (ret < 0) {
+        ERROR2("Rate %dHz not available for playback: %s\n", (int) (sampleRate+0.5f), snd_strerror(ret));
+        return FALSE;
+    }
+    if ((rrate-sampleRate > 2) || (rrate-sampleRate < - 2)) {
+        ERROR2("Rate doesn't match (requested %2.2fHz, got %dHz)\n", sampleRate, rrate);
+        return FALSE;
+    }
+    /* set the buffer time */
+    ret = snd_pcm_hw_params_set_buffer_size_near(info->handle, info->hwParams, &alsaBufferSizeInFrames);
+    if (ret < 0) {
+        ERROR2("Unable to set buffer size to %d frames: %s\n",
+               (int) alsaBufferSizeInFrames, snd_strerror(ret));
+        return FALSE;
+    }
+    bufferSizeInFrames = (int) alsaBufferSizeInFrames;
+    /* set the period time */
+    if (bufferSizeInFrames > 1024) {
+        dir = 0;
+        periodTime = DEFAULT_PERIOD_TIME;
+        ret = snd_pcm_hw_params_set_period_time_near(info->handle, info->hwParams, &periodTime, &dir);
+        if (ret < 0) {
+            ERROR2("Unable to set period time to %d: %s\n", DEFAULT_PERIOD_TIME, snd_strerror(ret));
+            return FALSE;
+        }
+    } else {
+        /* set the period count for very small buffer sizes to 2 */
+        dir = 0;
+        periods = 2;
+        ret = snd_pcm_hw_params_set_periods_near(info->handle, info->hwParams, &periods, &dir);
+        if (ret < 0) {
+            ERROR2("Unable to set period count to %d: %s\n", /*periods*/ 2, snd_strerror(ret));
+            return FALSE;
+        }
+    }
+    /* write the parameters to device */
+    ret = snd_pcm_hw_params(info->handle, info->hwParams);
+    if (ret < 0) {
+        ERROR1("Unable to set hw params: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    return TRUE;
+}
+
+// returns 1 if successful
+int setSWParams(AlsaPcmInfo* info) {
+    int ret;
+
+    /* get the current swparams */
+    ret = snd_pcm_sw_params_current(info->handle, info->swParams);
+    if (ret < 0) {
+        ERROR1("Unable to determine current swparams: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    /* never start the transfer automatically */
+    if (!setStartThresholdNoCommit(info, FALSE /* don't use threshold */)) {
+        return FALSE;
+    }
+
+    /* allow the transfer when at least period_size samples can be processed */
+    ret = snd_pcm_sw_params_set_avail_min(info->handle, info->swParams, info->periodSize);
+    if (ret < 0) {
+        ERROR1("Unable to set avail min for playback: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    /* write the parameters to the playback device */
+    ret = snd_pcm_sw_params(info->handle, info->swParams);
+    if (ret < 0) {
+        ERROR1("Unable to set sw params: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    return TRUE;
+}
+
+static snd_output_t* ALSA_OUTPUT = NULL;
+
+void* DAUDIO_Open(INT32 mixerIndex, INT32 deviceID, int isSource,
+                  int encoding, float sampleRate, int sampleSizeInBits,
+                  int frameSize, int channels,
+                  int isSigned, int isBigEndian, int bufferSizeInBytes) {
+    snd_pcm_format_mask_t* formatMask;
+    snd_pcm_format_t format;
+    int dir;
+    int ret = 0;
+    AlsaPcmInfo* info = NULL;
+    /* snd_pcm_uframes_t is 64 bit on 64-bit systems */
+    snd_pcm_uframes_t alsaBufferSizeInFrames = 0;
+
+
+    TRACE0("> DAUDIO_Open\n");
+#ifdef USE_TRACE
+    // for using ALSA debug dump methods
+    if (ALSA_OUTPUT == NULL) {
+        snd_output_stdio_attach(&ALSA_OUTPUT, stdout, 0);
+    }
+#endif
+
+    info = (AlsaPcmInfo*) malloc(sizeof(AlsaPcmInfo));
+    if (!info) {
+        ERROR0("Out of memory\n");
+        return NULL;
+    }
+    memset(info, 0, sizeof(AlsaPcmInfo));
+    // initial values are: stopped, flushed
+    info->isRunning = 0;
+    info->isFlushed = 1;
+
+    ret = openPCMfromDeviceID(deviceID, &(info->handle), isSource, FALSE /* do open device*/);
+    if (ret == 0) {
+        // set to blocking mode
+        snd_pcm_nonblock(info->handle, 0);
+        ret = snd_pcm_hw_params_malloc(&(info->hwParams));
+        if (ret != 0) {
+            ERROR1("  snd_pcm_hw_params_malloc returned error %d\n", ret);
+        } else {
+            ret = -1;
+            if (getAlsaFormatFromFormat(&format, frameSize / channels, sampleSizeInBits,
+                                        isSigned, isBigEndian, encoding)) {
+                if (setHWParams(info,
+                                sampleRate,
+                                channels,
+                                bufferSizeInBytes / frameSize,
+                                format)) {
+                    info->frameSize = frameSize;
+                    ret = snd_pcm_hw_params_get_period_size(info->hwParams, &info->periodSize, &dir);
+                    if (ret < 0) {
+                        ERROR1("ERROR: snd_pcm_hw_params_get_period: %s\n", snd_strerror(ret));
+                    }
+                    snd_pcm_hw_params_get_periods(info->hwParams, &(info->periods), &dir);
+                    snd_pcm_hw_params_get_buffer_size(info->hwParams, &alsaBufferSizeInFrames);
+                    info->bufferSizeInBytes = (int) alsaBufferSizeInFrames * frameSize;
+                    TRACE3("  DAUDIO_Open: period size = %d frames, periods = %d. Buffer size: %d bytes.\n",
+                           (int) info->periodSize, info->periods, info->bufferSizeInBytes);
+                }
+            }
+        }
+        if (ret == 0) {
+            // set software parameters
+            ret = snd_pcm_sw_params_malloc(&(info->swParams));
+            if (ret != 0) {
+                ERROR1("snd_pcm_hw_params_malloc returned error %d\n", ret);
+            } else {
+                if (!setSWParams(info)) {
+                    ret = -1;
+                }
+            }
+        }
+        if (ret == 0) {
+            // prepare device
+            ret = snd_pcm_prepare(info->handle);
+            if (ret < 0) {
+                ERROR1("ERROR: snd_pcm_prepare: %s\n", snd_strerror(ret));
+            }
+        }
+
+#ifdef GET_POSITION_METHOD2
+        if (ret == 0) {
+            ret = snd_pcm_status_malloc(&(info->positionStatus));
+            if (ret != 0) {
+                ERROR1("ERROR in snd_pcm_status_malloc: %s\n", snd_strerror(ret));
+            }
+        }
+#endif
+    }
+    if (ret != 0) {
+        DAUDIO_Close((void*) info, isSource);
+        info = NULL;
+    } else {
+        // set to non-blocking mode
+        snd_pcm_nonblock(info->handle, 1);
+        TRACE1("< DAUDIO_Open: Opened device successfully. Handle=%p\n",
+               (void*) info->handle);
+    }
+    return (void*) info;
+}
+
+#ifdef USE_TRACE
+void printState(snd_pcm_state_t state) {
+    if (state == SND_PCM_STATE_OPEN) {
+        TRACE0("State: SND_PCM_STATE_OPEN\n");
+    }
+    else if (state == SND_PCM_STATE_SETUP) {
+        TRACE0("State: SND_PCM_STATE_SETUP\n");
+    }
+    else if (state == SND_PCM_STATE_PREPARED) {
+        TRACE0("State: SND_PCM_STATE_PREPARED\n");
+    }
+    else if (state == SND_PCM_STATE_RUNNING) {
+        TRACE0("State: SND_PCM_STATE_RUNNING\n");
+    }
+    else if (state == SND_PCM_STATE_XRUN) {
+        TRACE0("State: SND_PCM_STATE_XRUN\n");
+    }
+    else if (state == SND_PCM_STATE_DRAINING) {
+        TRACE0("State: SND_PCM_STATE_DRAINING\n");
+    }
+    else if (state == SND_PCM_STATE_PAUSED) {
+        TRACE0("State: SND_PCM_STATE_PAUSED\n");
+    }
+    else if (state == SND_PCM_STATE_SUSPENDED) {
+        TRACE0("State: SND_PCM_STATE_SUSPENDED\n");
+    }
+}
+#endif
+
+int DAUDIO_Start(void* id, int isSource) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    int ret;
+    snd_pcm_state_t state;
+
+    TRACE0("> DAUDIO_Start\n");
+    // set to blocking mode
+    snd_pcm_nonblock(info->handle, 0);
+    // set start mode so that it always starts as soon as data is there
+    setStartThreshold(info, TRUE /* use threshold */);
+    state = snd_pcm_state(info->handle);
+    if (state == SND_PCM_STATE_PAUSED) {
+        // in case it was stopped previously
+        TRACE0("  Un-pausing...\n");
+        ret = snd_pcm_pause(info->handle, FALSE);
+        if (ret != 0) {
+            ERROR2("  NOTE: error in snd_pcm_pause:%d: %s\n", ret, snd_strerror(ret));
+        }
+    }
+    if (state == SND_PCM_STATE_SUSPENDED) {
+        TRACE0("  Resuming...\n");
+        ret = snd_pcm_resume(info->handle);
+        if (ret < 0) {
+            if ((ret != -EAGAIN) && (ret != -ENOSYS)) {
+                ERROR2("  ERROR: error in snd_pcm_resume:%d: %s\n", ret, snd_strerror(ret));
+            }
+        }
+    }
+    if (state == SND_PCM_STATE_SETUP) {
+        TRACE0("need to call prepare again...\n");
+        // prepare device
+        ret = snd_pcm_prepare(info->handle);
+        if (ret < 0) {
+            ERROR1("ERROR: snd_pcm_prepare: %s\n", snd_strerror(ret));
+        }
+    }
+    // in case there is still data in the buffers
+    ret = snd_pcm_start(info->handle);
+    if (ret != 0) {
+        if (ret != -EPIPE) {
+            ERROR2("  NOTE: error in snd_pcm_start: %d: %s\n", ret, snd_strerror(ret));
+        }
+    }
+    // set to non-blocking mode
+    ret = snd_pcm_nonblock(info->handle, 1);
+    if (ret != 0) {
+        ERROR1("  ERROR in snd_pcm_nonblock: %s\n", snd_strerror(ret));
+    }
+    state = snd_pcm_state(info->handle);
+#ifdef USE_TRACE
+    printState(state);
+#endif
+    ret = (state == SND_PCM_STATE_PREPARED)
+        || (state == SND_PCM_STATE_RUNNING)
+        || (state == SND_PCM_STATE_XRUN)
+        || (state == SND_PCM_STATE_SUSPENDED);
+    if (ret) {
+        info->isRunning = 1;
+        // source line should keep isFlushed value until Write() is called;
+        // for target data line reset it right now.
+        if (!isSource) {
+            info->isFlushed = 0;
+        }
+    }
+    TRACE1("< DAUDIO_Start %s\n", ret?"success":"error");
+    return ret?TRUE:FALSE;
+}
+
+int DAUDIO_Stop(void* id, int isSource) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    int ret;
+
+    TRACE0("> DAUDIO_Stop\n");
+    // set to blocking mode
+    snd_pcm_nonblock(info->handle, 0);
+    setStartThreshold(info, FALSE /* don't use threshold */); // device will not start after buffer xrun
+    ret = snd_pcm_pause(info->handle, 1);
+    // set to non-blocking mode
+    snd_pcm_nonblock(info->handle, 1);
+    if (ret != 0) {
+        ERROR1("ERROR in snd_pcm_pause: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+    info->isRunning = 0;
+    TRACE0("< DAUDIO_Stop success\n");
+    return TRUE;
+}
+
+void DAUDIO_Close(void* id, int isSource) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+
+    TRACE0("DAUDIO_Close\n");
+    if (info != NULL) {
+        if (info->handle != NULL) {
+            snd_pcm_close(info->handle);
+        }
+        if (info->hwParams) {
+            snd_pcm_hw_params_free(info->hwParams);
+        }
+        if (info->swParams) {
+            snd_pcm_sw_params_free(info->swParams);
+        }
+#ifdef GET_POSITION_METHOD2
+        if (info->positionStatus) {
+            snd_pcm_status_free(info->positionStatus);
+        }
+#endif
+        free(info);
+    }
+}
+
+/*
+ * Underrun and suspend recovery
+ * returns
+ * 0:  exit native and return 0
+ * 1:  try again to write/read
+ * -1: error - exit native with return value -1
+ */
+int xrun_recovery(AlsaPcmInfo* info, int err) {
+    int ret;
+
+    if (err == -EPIPE) {    /* underrun / overflow */
+        TRACE0("xrun_recovery: underrun/overflow.\n");
+        ret = snd_pcm_prepare(info->handle);
+        if (ret < 0) {
+            ERROR1("Can't recover from underrun/overflow, prepare failed: %s\n", snd_strerror(ret));
+            return -1;
+        }
+        return 1;
+    } else if (err == -ESTRPIPE) {
+        TRACE0("xrun_recovery: suspended.\n");
+        ret = snd_pcm_resume(info->handle);
+        if (ret < 0) {
+            if (ret == -EAGAIN) {
+                return 0; /* wait until the suspend flag is released */
+            }
+            return -1;
+        }
+        ret = snd_pcm_prepare(info->handle);
+        if (ret < 0) {
+            ERROR1("Can't recover from underrun/overflow, prepare failed: %s\n", snd_strerror(ret));
+            return -1;
+        }
+        return 1;
+    } else if (err == -EAGAIN) {
+        TRACE0("xrun_recovery: EAGAIN try again flag.\n");
+        return 0;
+    }
+
+    TRACE2("xrun_recovery: unexpected error %d: %s\n", err, snd_strerror(err));
+    return -1;
+}
+
+// returns -1 on error
+int DAUDIO_Write(void* id, char* data, int byteSize) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    int ret, count;
+    snd_pcm_sframes_t frameSize, writtenFrames;
+
+    TRACE1("> DAUDIO_Write %d bytes\n", byteSize);
+
+    /* sanity */
+    if (byteSize <= 0 || info->frameSize <= 0) {
+        ERROR2(" DAUDIO_Write: byteSize=%d, frameSize=%d!\n",
+               (int) byteSize, (int) info->frameSize);
+        TRACE0("< DAUDIO_Write returning -1\n");
+        return -1;
+    }
+
+    count = 2; // maximum number of trials to recover from underrun
+    //frameSize = snd_pcm_bytes_to_frames(info->handle, byteSize);
+    frameSize = (snd_pcm_sframes_t) (byteSize / info->frameSize);
+    do {
+        writtenFrames = snd_pcm_writei(info->handle, (const void*) data, (snd_pcm_uframes_t) frameSize);
+
+        if (writtenFrames < 0) {
+            ret = xrun_recovery(info, (int) writtenFrames);
+            if (ret <= 0) {
+                TRACE1("DAUDIO_Write: xrun recovery returned %d -> return.\n", ret);
+                return ret;
+            }
+            if (count-- <= 0) {
+                ERROR0("DAUDIO_Write: too many attempts to recover from xrun/suspend\n");
+                return -1;
+            }
+        } else {
+            break;
+        }
+    } while (TRUE);
+    //ret =  snd_pcm_frames_to_bytes(info->handle, writtenFrames);
+
+    if (writtenFrames > 0) {
+        // reset "flushed" flag
+        info->isFlushed = 0;
+    }
+
+    ret =  (int) (writtenFrames * info->frameSize);
+    TRACE1("< DAUDIO_Write: returning %d bytes.\n", ret);
+    return ret;
+}
+
+// returns -1 on error
+int DAUDIO_Read(void* id, char* data, int byteSize) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    int ret, count;
+    snd_pcm_sframes_t frameSize, readFrames;
+
+    TRACE1("> DAUDIO_Read %d bytes\n", byteSize);
+    /*TRACE3("  info=%p, data=%p, byteSize=%d\n",
+      (void*) info, (void*) data, (int) byteSize);
+      TRACE2("  info->frameSize=%d, info->handle=%p\n",
+      (int) info->frameSize, (void*) info->handle);
+    */
+    /* sanity */
+    if (byteSize <= 0 || info->frameSize <= 0) {
+        ERROR2(" DAUDIO_Read: byteSize=%d, frameSize=%d!\n",
+               (int) byteSize, (int) info->frameSize);
+        TRACE0("< DAUDIO_Read returning -1\n");
+        return -1;
+    }
+    if (!info->isRunning && info->isFlushed) {
+        // PCM has nothing to read
+        return 0;
+    }
+
+    count = 2; // maximum number of trials to recover from error
+    //frameSize = snd_pcm_bytes_to_frames(info->handle, byteSize);
+    frameSize = (snd_pcm_sframes_t) (byteSize / info->frameSize);
+    do {
+        readFrames = snd_pcm_readi(info->handle, (void*) data, (snd_pcm_uframes_t) frameSize);
+        if (readFrames < 0) {
+            ret = xrun_recovery(info, (int) readFrames);
+            if (ret <= 0) {
+                TRACE1("DAUDIO_Read: xrun recovery returned %d -> return.\n", ret);
+                return ret;
+            }
+            if (count-- <= 0) {
+                ERROR0("DAUDIO_Read: too many attempts to recover from xrun/suspend\n");
+                return -1;
+            }
+        } else {
+            break;
+        }
+    } while (TRUE);
+    //ret =  snd_pcm_frames_to_bytes(info->handle, readFrames);
+    ret =  (int) (readFrames * info->frameSize);
+    TRACE1("< DAUDIO_Read: returning %d bytes.\n", ret);
+    return ret;
+}
+
+
+int DAUDIO_GetBufferSize(void* id, int isSource) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+
+    return info->bufferSizeInBytes;
+}
+
+int DAUDIO_StillDraining(void* id, int isSource) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    snd_pcm_state_t state;
+
+    state = snd_pcm_state(info->handle);
+    //printState(state);
+    //TRACE1("Still draining: %s\n", (state != SND_PCM_STATE_XRUN)?"TRUE":"FALSE");
+    return (state == SND_PCM_STATE_RUNNING)?TRUE:FALSE;
+}
+
+
+int DAUDIO_Flush(void* id, int isSource) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    int ret;
+
+    TRACE0("DAUDIO_Flush\n");
+
+    if (info->isFlushed) {
+        // nothing to drop
+        return 1;
+    }
+
+    ret = snd_pcm_drop(info->handle);
+    if (ret != 0) {
+        ERROR1("ERROR in snd_pcm_drop: %s\n", snd_strerror(ret));
+        return FALSE;
+    }
+
+    info->isFlushed = 1;
+    if (info->isRunning) {
+        ret = DAUDIO_Start(id, isSource);
+    }
+    return ret;
+}
+
+int DAUDIO_GetAvailable(void* id, int isSource) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    snd_pcm_sframes_t availableInFrames;
+    snd_pcm_state_t state;
+    int ret;
+
+    state = snd_pcm_state(info->handle);
+    if (info->isFlushed || state == SND_PCM_STATE_XRUN) {
+        // if in xrun state then we have the entire buffer available,
+        // not 0 as alsa reports
+        ret = info->bufferSizeInBytes;
+    } else {
+        availableInFrames = snd_pcm_avail_update(info->handle);
+        if (availableInFrames < 0) {
+            ret = 0;
+        } else {
+            //ret = snd_pcm_frames_to_bytes(info->handle, availableInFrames);
+            ret = (int) (availableInFrames * info->frameSize);
+        }
+    }
+    TRACE1("DAUDIO_GetAvailable returns %d bytes\n", ret);
+    return ret;
+}
+
+INT64 estimatePositionFromAvail(AlsaPcmInfo* info, int isSource, INT64 javaBytePos, int availInBytes) {
+    // estimate the current position with the buffer size and
+    // the available bytes to read or write in the buffer.
+    // not an elegant solution - bytePos will stop on xruns,
+    // and in race conditions it may jump backwards
+    // Advantage is that it is indeed based on the samples that go through
+    // the system (rather than time-based methods)
+    if (isSource) {
+        // javaBytePos is the position that is reached when the current
+        // buffer is played completely
+        return (INT64) (javaBytePos - info->bufferSizeInBytes + availInBytes);
+    } else {
+        // javaBytePos is the position that was when the current buffer was empty
+        return (INT64) (javaBytePos + availInBytes);
+    }
+}
+
+INT64 DAUDIO_GetBytePosition(void* id, int isSource, INT64 javaBytePos) {
+    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
+    int ret;
+    INT64 result = javaBytePos;
+    snd_pcm_state_t state;
+    state = snd_pcm_state(info->handle);
+
+    if (!info->isFlushed && state != SND_PCM_STATE_XRUN) {
+#ifdef GET_POSITION_METHOD2
+        snd_timestamp_t* ts;
+        snd_pcm_uframes_t framesAvail;
+
+        // note: slight race condition if this is called simultaneously from 2 threads
+        ret = snd_pcm_status(info->handle, info->positionStatus);
+        if (ret != 0) {
+            ERROR1("ERROR in snd_pcm_status: %s\n", snd_strerror(ret));
+            result = javaBytePos;
+        } else {
+            // calculate from time value, or from available bytes
+            framesAvail = snd_pcm_status_get_avail(info->positionStatus);
+            result = estimatePositionFromAvail(info, isSource, javaBytePos, framesAvail * info->frameSize);
+        }
+#endif
+#ifdef GET_POSITION_METHOD3
+        snd_pcm_uframes_t framesAvail;
+        ret = snd_pcm_avail(info->handle, &framesAvail);
+        if (ret != 0) {
+            ERROR1("ERROR in snd_pcm_avail: %s\n", snd_strerror(ret));
+            result = javaBytePos;
+        } else {
+            result = estimatePositionFromAvail(info, isSource, javaBytePos, framesAvail * info->frameSize);
+        }
+#endif
+#ifdef GET_POSITION_METHOD1
+        result = estimatePositionFromAvail(info, isSource, javaBytePos, DAUDIO_GetAvailable(id, isSource));
+#endif
+    }
+    //printf("getbyteposition: javaBytePos=%d , return=%d\n", (int) javaBytePos, (int) result);
+    return result;
+}
+
+
+
+void DAUDIO_SetBytePosition(void* id, int isSource, INT64 javaBytePos) {
+    /* save to ignore, since GetBytePosition
+     * takes the javaBytePos param into account
+     */
+}
+
+int DAUDIO_RequiresServicing(void* id, int isSource) {
+    // never need servicing on Bsd
+    return FALSE;
+}
+
+void DAUDIO_Service(void* id, int isSource) {
+    // never need servicing on Bsd
+}
+
+
+#endif // USE_DAUDIO
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c
new file mode 100644
index 0000000..ef5f98d
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//#define USE_ERROR
+//#define USE_TRACE
+
+#include "PLATFORM_API_BsdOS_ALSA_PCMUtils.h"
+#include "PLATFORM_API_BsdOS_ALSA_CommonUtils.h"
+
+
+
+// callback for iteration through devices
+// returns TRUE if iteration should continue
+// NOTE: cardinfo may be NULL (for "default" device)
+typedef int (*DeviceIteratorPtr)(UINT32 deviceID, snd_pcm_info_t* pcminfo,
+                             snd_ctl_card_info_t* cardinfo, void *userData);
+
+// for each ALSA device, call iterator. userData is passed to the iterator
+// returns total number of iterations
+int iteratePCMDevices(DeviceIteratorPtr iterator, void* userData) {
+    int count = 0;
+    int subdeviceCount;
+    int card, dev, subDev;
+    char devname[16];
+    int err;
+    snd_ctl_t *handle;
+    snd_pcm_t *pcm;
+    snd_pcm_info_t* pcminfo;
+    snd_ctl_card_info_t *cardinfo, *defcardinfo = NULL;
+    UINT32 deviceID;
+    int doContinue = TRUE;
+
+    snd_pcm_info_malloc(&pcminfo);
+    snd_ctl_card_info_malloc(&cardinfo);
+
+    // 1st try "default" device
+    err = snd_pcm_open(&pcm, ALSA_DEFAULT_DEVICE_NAME,
+                       SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
+    if (err < 0) {
+        // try with the other direction
+        err = snd_pcm_open(&pcm, ALSA_DEFAULT_DEVICE_NAME,
+                           SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
+    }
+    if (err < 0) {
+        ERROR1("ERROR: snd_pcm_open (\"default\"): %s\n", snd_strerror(err));
+    } else {
+        err = snd_pcm_info(pcm, pcminfo);
+        snd_pcm_close(pcm);
+        if (err < 0) {
+            ERROR1("ERROR: snd_pcm_info (\"default\"): %s\n",
+                    snd_strerror(err));
+        } else {
+            // try to get card info
+            card = snd_pcm_info_get_card(pcminfo);
+            if (card >= 0) {
+                sprintf(devname, ALSA_HARDWARE_CARD, card);
+                if (snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK) >= 0) {
+                    if (snd_ctl_card_info(handle, cardinfo) >= 0) {
+                        defcardinfo = cardinfo;
+                    }
+                    snd_ctl_close(handle);
+                }
+            }
+            // call callback function for the device
+            if (iterator != NULL) {
+                doContinue = (*iterator)(ALSA_DEFAULT_DEVICE_ID, pcminfo,
+                                         defcardinfo, userData);
+            }
+            count++;
+        }
+    }
+
+    // iterate cards
+    card = -1;
+    while (doContinue) {
+        if (snd_card_next(&card) < 0) {
+            break;
+        }
+        if (card < 0) {
+            break;
+        }
+        sprintf(devname, ALSA_HARDWARE_CARD, card);
+        TRACE1("Opening alsa device \"%s\"...\n", devname);
+        err = snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK);
+        if (err < 0) {
+            ERROR2("ERROR: snd_ctl_open, card=%d: %s\n",
+                    card, snd_strerror(err));
+        } else {
+            err = snd_ctl_card_info(handle, cardinfo);
+            if (err < 0) {
+                ERROR2("ERROR: snd_ctl_card_info, card=%d: %s\n",
+                        card, snd_strerror(err));
+            } else {
+                dev = -1;
+                while (doContinue) {
+                    if (snd_ctl_pcm_next_device(handle, &dev) < 0) {
+                        ERROR0("snd_ctl_pcm_next_device\n");
+                    }
+                    if (dev < 0) {
+                        break;
+                    }
+                    snd_pcm_info_set_device(pcminfo, dev);
+                    snd_pcm_info_set_subdevice(pcminfo, 0);
+                    snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK);
+                    err = snd_ctl_pcm_info(handle, pcminfo);
+                    if (err == -ENOENT) {
+                        // try with the other direction
+                        snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE);
+                        err = snd_ctl_pcm_info(handle, pcminfo);
+                    }
+                    if (err < 0) {
+                        if (err != -ENOENT) {
+                            ERROR2("ERROR: snd_ctl_pcm_info, card=%d: %s",
+                                    card, snd_strerror(err));
+                        }
+                    } else {
+                        subdeviceCount = needEnumerateSubdevices(ALSA_PCM) ?
+                            snd_pcm_info_get_subdevices_count(pcminfo) : 1;
+                        if (iterator!=NULL) {
+                            for (subDev = 0; subDev < subdeviceCount; subDev++) {
+                                deviceID = encodeDeviceID(card, dev, subDev);
+                                doContinue = (*iterator)(deviceID, pcminfo,
+                                                         cardinfo, userData);
+                                count++;
+                                if (!doContinue) {
+                                    break;
+                                }
+                            }
+                        } else {
+                            count += subdeviceCount;
+                        }
+                    }
+                } // of while(doContinue)
+            }
+            snd_ctl_close(handle);
+        }
+    }
+    snd_ctl_card_info_free(cardinfo);
+    snd_pcm_info_free(pcminfo);
+    return count;
+}
+
+int getAudioDeviceCount() {
+    initAlsaSupport();
+    return iteratePCMDevices(NULL, NULL);
+}
+
+int deviceInfoIterator(UINT32 deviceID, snd_pcm_info_t* pcminfo,
+                       snd_ctl_card_info_t* cardinfo, void* userData) {
+    char buffer[300];
+    ALSA_AudioDeviceDescription* desc = (ALSA_AudioDeviceDescription*)userData;
+#ifdef ALSA_PCM_USE_PLUGHW
+    int usePlugHw = 1;
+#else
+    int usePlugHw = 0;
+#endif
+
+    initAlsaSupport();
+    if (desc->index == 0) {
+        // we found the device with correct index
+        *(desc->maxSimultaneousLines) = needEnumerateSubdevices(ALSA_PCM) ?
+                1 : snd_pcm_info_get_subdevices_count(pcminfo);
+        *desc->deviceID = deviceID;
+        buffer[0]=' '; buffer[1]='[';
+        getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_PCM);
+        strcat(buffer, "]");
+        strncpy(desc->name,
+                (cardinfo != NULL)
+                    ? snd_ctl_card_info_get_id(cardinfo)
+                    : snd_pcm_info_get_id(pcminfo),
+                desc->strLen - strlen(buffer));
+        strncat(desc->name, buffer, desc->strLen - strlen(desc->name));
+        strncpy(desc->vendor, "ALSA (http://www.alsa-project.org)", desc->strLen);
+        strncpy(desc->description,
+                (cardinfo != NULL)
+                    ? snd_ctl_card_info_get_name(cardinfo)
+                    : snd_pcm_info_get_name(pcminfo),
+                desc->strLen);
+        strncat(desc->description, ", ", desc->strLen - strlen(desc->description));
+        strncat(desc->description, snd_pcm_info_get_id(pcminfo), desc->strLen - strlen(desc->description));
+        strncat(desc->description, ", ", desc->strLen - strlen(desc->description));
+        strncat(desc->description, snd_pcm_info_get_name(pcminfo), desc->strLen - strlen(desc->description));
+        getALSAVersion(desc->version, desc->strLen);
+        TRACE4("Returning %s, %s, %s, %s\n", desc->name, desc->vendor, desc->description, desc->version);
+        return FALSE; // do not continue iteration
+    }
+    desc->index--;
+    return TRUE;
+}
+
+// returns 0 if successful
+int openPCMfromDeviceID(int deviceID, snd_pcm_t** handle, int isSource, int hardware) {
+    char buffer[200];
+    int ret;
+
+    initAlsaSupport();
+    getDeviceStringFromDeviceID(buffer, deviceID, !hardware, ALSA_PCM);
+
+    TRACE1("Opening ALSA device %s\n", buffer);
+    ret = snd_pcm_open(handle, buffer,
+                       isSource?SND_PCM_STREAM_PLAYBACK:SND_PCM_STREAM_CAPTURE,
+                       SND_PCM_NONBLOCK);
+    if (ret != 0) {
+        ERROR1("snd_pcm_open returned error code %d \n", ret);
+        *handle = NULL;
+    }
+    return ret;
+}
+
+
+int getAudioDeviceDescriptionByIndex(ALSA_AudioDeviceDescription* desc) {
+    initAlsaSupport();
+    TRACE1(" getAudioDeviceDescriptionByIndex(mixerIndex = %d\n", desc->index);
+    iteratePCMDevices(&deviceInfoIterator, desc);
+    return (desc->index == 0)?TRUE:FALSE;
+}
+
+// returns 1 if successful
+// enc: 0 for PCM, 1 for ULAW, 2 for ALAW (see DirectAudio.h)
+int getFormatFromAlsaFormat(snd_pcm_format_t alsaFormat,
+                            int* sampleSizeInBytes, int* significantBits,
+                            int* isSigned, int* isBigEndian, int* enc) {
+
+    *sampleSizeInBytes = (snd_pcm_format_physical_width(alsaFormat) + 7) / 8;
+    *significantBits = snd_pcm_format_width(alsaFormat);
+
+    // defaults
+    *enc = 0; // PCM
+    *isSigned = (snd_pcm_format_signed(alsaFormat) > 0);
+    *isBigEndian = (snd_pcm_format_big_endian(alsaFormat) > 0);
+
+    // non-PCM formats
+    if (alsaFormat == SND_PCM_FORMAT_MU_LAW) { // Mu-Law
+        *sampleSizeInBytes = 8; *enc = 1; *significantBits = *sampleSizeInBytes;
+    }
+    else if (alsaFormat == SND_PCM_FORMAT_A_LAW) {     // A-Law
+        *sampleSizeInBytes = 8; *enc = 2; *significantBits = *sampleSizeInBytes;
+    }
+    else if (snd_pcm_format_linear(alsaFormat) < 1) {
+        return 0;
+    }
+    return (*sampleSizeInBytes > 0);
+}
+
+// returns 1 if successful
+int getAlsaFormatFromFormat(snd_pcm_format_t* alsaFormat,
+                            int sampleSizeInBytes, int significantBits,
+                            int isSigned, int isBigEndian, int enc) {
+    *alsaFormat = SND_PCM_FORMAT_UNKNOWN;
+
+    if (enc == 0) {
+        *alsaFormat = snd_pcm_build_linear_format(significantBits,
+                                                  sampleSizeInBytes * 8,
+                                                  isSigned?0:1,
+                                                  isBigEndian?1:0);
+    }
+    else if ((sampleSizeInBytes == 1) && (significantBits == 8)) {
+        if (enc == 1) { // ULAW
+            *alsaFormat = SND_PCM_FORMAT_MU_LAW;
+        }
+        else if (enc == 2) { // ALAW
+            *alsaFormat = SND_PCM_FORMAT_A_LAW;
+        }
+    }
+    return (*alsaFormat == SND_PCM_FORMAT_UNKNOWN)?0:1;
+}
+
+
+/* end */
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.h b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.h
new file mode 100644
index 0000000..999ae7c
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// define this with a later version of ALSA than 0.9.0rc3
+// (starting from 1.0.0 it became default behaviour)
+#define ALSA_PCM_NEW_HW_PARAMS_API
+#include <alsa/asoundlib.h>
+#include "Utilities.h"
+
+#ifndef PLATFORM_API_BSDOS_ALSA_PCMUTILS_H_INCLUDED
+#define PLATFORM_API_BSDOS_ALSA_PCMUTILS_H_INCLUDED
+
+// if this is defined, use plughw: devices
+#define ALSA_PCM_USE_PLUGHW
+//#undef ALSA_PCM_USE_PLUGHW
+
+
+// maximum number of channels that is listed in the formats. If more, than
+// just -1 for channel count is used.
+#define MAXIMUM_LISTED_CHANNELS 32
+
+typedef struct tag_ALSA_AudioDeviceDescription {
+    int index;          // in
+    int strLen;         // in
+    INT32* deviceID;    // out
+    int* maxSimultaneousLines; // out
+    char* name;         // out
+    char* vendor;       // out
+    char* description;  // out
+    char* version;      // out
+} ALSA_AudioDeviceDescription;
+
+
+
+int getAudioDeviceCount();
+int getAudioDeviceDescriptionByIndex(ALSA_AudioDeviceDescription* desc);
+
+// returns ALSA error code, or 0 if successful
+int openPCMfromDeviceID(int deviceID, snd_pcm_t** handle, int isSource, int hardware);
+
+// returns 1 if successful
+// enc: 0 for PCM, 1 for ULAW, 2 for ALAW (see DirectAudio.h)
+int getFormatFromAlsaFormat(snd_pcm_format_t alsaFormat,
+                            int* sampleSizeInBytes, int* significantBits,
+                            int* isSigned, int* isBigEndian, int* enc);
+
+int getAlsaFormatFromFormat(snd_pcm_format_t* alsaFormat,
+                            int sampleSizeInBytes, int significantBits,
+                            int isSigned, int isBigEndian, int enc);
+
+#endif // PLATFORM_API_BSDOS_ALSA_PCMUTILS_H_INCLUDED
diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_Ports.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_Ports.c
new file mode 100644
index 0000000..3c1a26b
--- /dev/null
+++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_Ports.c
@@ -0,0 +1,723 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#define USE_ERROR
+//#define USE_TRACE
+
+#include "Ports.h"
+#include "PLATFORM_API_BsdOS_ALSA_CommonUtils.h"
+#include <alsa/asoundlib.h>
+
+#if USE_PORTS == TRUE
+
+#define MAX_ELEMS (300)
+#define MAX_CONTROLS (MAX_ELEMS * 4)
+
+#define CHANNELS_MONO (SND_MIXER_SCHN_LAST + 1)
+#define CHANNELS_STEREO (SND_MIXER_SCHN_LAST + 2)
+
+typedef struct {
+    snd_mixer_elem_t* elem;
+    INT32 portType; /* one of PORT_XXX_xx */
+    char* controlType; /* one of CONTROL_TYPE_xx */
+    /* Values: either SND_MIXER_SCHN_FRONT_xx, CHANNELS_MONO or CHANNELS_STEREO.
+       For SND_MIXER_SCHN_FRONT_xx, exactly this channel is set/retrieved directly.
+       For CHANNELS_MONO, ALSA channel SND_MIXER_SCHN_MONO is set/retrieved directly.
+       For CHANNELS_STEREO, ALSA channels SND_MIXER_SCHN_FRONT_LEFT and SND_MIXER_SCHN_FRONT_RIGHT
+       are set after a calculation that takes balance into account. Retrieved? Average of both
+       channels? (Using a cached value is not a good idea since the value in the HW may have been
+       altered.) */
+    INT32 channel;
+} PortControl;
+
+
+typedef struct tag_PortMixer {
+    snd_mixer_t* mixer_handle;
+    /* Number of array elements used in elems and types. */
+    int numElems;
+    snd_mixer_elem_t** elems;
+    /* Array of port types (PORT_SRC_UNKNOWN etc.). Indices are the same as in elems. */
+    INT32* types;
+    /* Number of array elements used in controls. */
+    int numControls;
+    PortControl* controls;
+} PortMixer;
+
+
+///// implemented functions of Ports.h
+
+INT32 PORT_GetPortMixerCount() {
+    INT32 mixerCount;
+    int card;
+    char devname[16];
+    int err;
+    snd_ctl_t *handle;
+    snd_ctl_card_info_t* info;
+
+    TRACE0("> PORT_GetPortMixerCount\n");
+
+    initAlsaSupport();
+
+    snd_ctl_card_info_malloc(&info);
+    card = -1;
+    mixerCount = 0;
+    if (snd_card_next(&card) >= 0) {
+        while (card >= 0) {
+            sprintf(devname, ALSA_HARDWARE_CARD, card);
+            TRACE1("PORT_GetPortMixerCount: Opening alsa device \"%s\"...\n", devname);
+            err = snd_ctl_open(&handle, devname, 0);
+            if (err < 0) {
+                ERROR2("ERROR: snd_ctl_open, card=%d: %s\n", card, snd_strerror(err));
+            } else {
+                mixerCount++;
+                snd_ctl_close(handle);
+            }
+            if (snd_card_next(&card) < 0) {
+                break;
+            }
+        }
+    }
+    snd_ctl_card_info_free(info);
+    TRACE0("< PORT_GetPortMixerCount\n");
+    return mixerCount;
+}
+
+
+INT32 PORT_GetPortMixerDescription(INT32 mixerIndex, PortMixerDescription* description) {
+    snd_ctl_t* handle;
+    snd_ctl_card_info_t* card_info;
+    char devname[16];
+    int err;
+    char buffer[100];
+
+    TRACE0("> PORT_GetPortMixerDescription\n");
+    snd_ctl_card_info_malloc(&card_info);
+
+    sprintf(devname, ALSA_HARDWARE_CARD, (int) mixerIndex);
+    TRACE1("Opening alsa device \"%s\"...\n", devname);
+    err = snd_ctl_open(&handle, devname, 0);
+    if (err < 0) {
+        ERROR2("ERROR: snd_ctl_open, card=%d: %s\n", (int) mixerIndex, snd_strerror(err));
+        return FALSE;
+    }
+    err = snd_ctl_card_info(handle, card_info);
+    if (err < 0) {
+        ERROR2("ERROR: snd_ctl_card_info, card=%d: %s\n", (int) mixerIndex, snd_strerror(err));
+    }
+    strncpy(description->name, snd_ctl_card_info_get_id(card_info), PORT_STRING_LENGTH - 1);
+    sprintf(buffer, " [%s]", devname);
+    strncat(description->name, buffer, PORT_STRING_LENGTH - 1 - strlen(description->name));
+    strncpy(description->vendor, "ALSA (http://www.alsa-project.org)", PORT_STRING_LENGTH - 1);
+    strncpy(description->description, snd_ctl_card_info_get_name(card_info), PORT_STRING_LENGTH - 1);
+    strncat(description->description, ", ", PORT_STRING_LENGTH - 1 - strlen(description->description));
+    strncat(description->description, snd_ctl_card_info_get_mixername(card_info), PORT_STRING_LENGTH - 1 - strlen(description->description));
+    getALSAVersion(description->version, PORT_STRING_LENGTH - 1);
+
+    snd_ctl_close(handle);
+    snd_ctl_card_info_free(card_info);
+    TRACE0("< PORT_GetPortMixerDescription\n");
+    return TRUE;
+}
+
+
+void* PORT_Open(INT32 mixerIndex) {
+    char devname[16];
+    snd_mixer_t* mixer_handle;
+    int err;
+    PortMixer* handle;
+
+    TRACE0("> PORT_Open\n");
+    sprintf(devname, ALSA_HARDWARE_CARD, (int) mixerIndex);
+    if ((err = snd_mixer_open(&mixer_handle, 0)) < 0) {
+        ERROR2("Mixer %s open error: %s", devname, snd_strerror(err));
+        return NULL;
+    }
+    if ((err = snd_mixer_attach(mixer_handle, devname)) < 0) {
+        ERROR2("Mixer attach %s error: %s", devname, snd_strerror(err));
+        snd_mixer_close(mixer_handle);
+        return NULL;
+    }
+    if ((err = snd_mixer_selem_register(mixer_handle, NULL, NULL)) < 0) {
+        ERROR1("Mixer register error: %s", snd_strerror(err));
+        snd_mixer_close(mixer_handle);
+        return NULL;
+    }
+    err = snd_mixer_load(mixer_handle);
+    if (err < 0) {
+        ERROR2("Mixer %s load error: %s", devname, snd_strerror(err));
+        snd_mixer_close(mixer_handle);
+        return NULL;
+    }
+    handle = (PortMixer*) calloc(1, sizeof(PortMixer));
+    if (handle == NULL) {
+        ERROR0("malloc() failed.");
+        snd_mixer_close(mixer_handle);
+        return NULL;
+    }
+    handle->numElems = 0;
+    handle->elems = (snd_mixer_elem_t**) calloc(MAX_ELEMS, sizeof(snd_mixer_elem_t*));
+    if (handle->elems == NULL) {
+        ERROR0("malloc() failed.");
+        snd_mixer_close(mixer_handle);
+        free(handle);
+        return NULL;
+    }
+    handle->types = (INT32*) calloc(MAX_ELEMS, sizeof(INT32));
+    if (handle->types == NULL) {
+        ERROR0("malloc() failed.");
+        snd_mixer_close(mixer_handle);
+        free(handle->elems);
+        free(handle);
+        return NULL;
+    }
+    handle->controls = (PortControl*) calloc(MAX_CONTROLS, sizeof(PortControl));
+    if (handle->controls == NULL) {
+        ERROR0("malloc() failed.");
+        snd_mixer_close(mixer_handle);
+        free(handle->elems);
+        free(handle->types);
+        free(handle);
+        return NULL;
+    }
+    handle->mixer_handle = mixer_handle;
+    // necessary to initialize data structures
+    PORT_GetPortCount(handle);
+    TRACE0("< PORT_Open\n");
+    return handle;
+}
+
+
+void PORT_Close(void* id) {
+    TRACE0("> PORT_Close\n");
+    if (id != NULL) {
+        PortMixer* handle = (PortMixer*) id;
+        if (handle->mixer_handle != NULL) {
+            snd_mixer_close(handle->mixer_handle);
+        }
+        if (handle->elems != NULL) {
+            free(handle->elems);
+        }
+        if (handle->types != NULL) {
+            free(handle->types);
+        }
+        if (handle->controls != NULL) {
+            free(handle->controls);
+        }
+        free(handle);
+    }
+    TRACE0("< PORT_Close\n");
+}
+
+
+
+INT32 PORT_GetPortCount(void* id) {
+    PortMixer* portMixer;
+    snd_mixer_elem_t *elem;
+
+    TRACE0("> PORT_GetPortCount\n");
+    if (id == NULL) {
+        // $$mp: Should become a descriptive error code (invalid handle).
+        return -1;
+    }
+    portMixer = (PortMixer*) id;
+    if (portMixer->numElems == 0) {
+        for (elem = snd_mixer_first_elem(portMixer->mixer_handle); elem; elem = snd_mixer_elem_next(elem)) {
+            if (!snd_mixer_selem_is_active(elem))
+                continue;
+            TRACE2("Simple mixer control '%s',%i\n",
+                   snd_mixer_selem_get_name(elem),
+                   snd_mixer_selem_get_index(elem));
+            if (snd_mixer_selem_has_playback_volume(elem)) {
+                portMixer->elems[portMixer->numElems] = elem;
+                portMixer->types[portMixer->numElems] = PORT_DST_UNKNOWN;
+                portMixer->numElems++;
+            }
+            // to prevent buffer overflow
+            if (portMixer->numElems >= MAX_ELEMS) {
+                break;
+            }
+            /* If an element has both playback an capture volume, it is put into the arrays
+               twice. */
+            if (snd_mixer_selem_has_capture_volume(elem)) {
+                portMixer->elems[portMixer->numElems] = elem;
+                portMixer->types[portMixer->numElems] = PORT_SRC_UNKNOWN;
+                portMixer->numElems++;
+            }
+            // to prevent buffer overflow
+            if (portMixer->numElems >= MAX_ELEMS) {
+                break;
+            }
+        }
+    }
+    TRACE0("< PORT_GetPortCount\n");
+    return portMixer->numElems;
+}
+
+
+INT32 PORT_GetPortType(void* id, INT32 portIndex) {
+    PortMixer* portMixer;
+    INT32 type;
+    TRACE0("> PORT_GetPortType\n");
+    if (id == NULL) {
+        // $$mp: Should become a descriptive error code (invalid handle).
+        return -1;
+    }
+    portMixer = (PortMixer*) id;
+    if (portIndex < 0 || portIndex >= portMixer->numElems) {
+        // $$mp: Should become a descriptive error code (index out of bounds).
+        return -1;
+    }
+    type = portMixer->types[portIndex];
+    TRACE0("< PORT_GetPortType\n");
+    return type;
+}
+
+
+INT32 PORT_GetPortName(void* id, INT32 portIndex, char* name, INT32 len) {
+    PortMixer* portMixer;
+    const char* nam;
+
+    TRACE0("> PORT_GetPortName\n");
+    if (id == NULL) {
+        // $$mp: Should become a descriptive error code (invalid handle).
+        return -1;
+    }
+    portMixer = (PortMixer*) id;
+    if (portIndex < 0 || portIndex >= portMixer->numElems) {
+        // $$mp: Should become a descriptive error code (index out of bounds).
+        return -1;
+    }
+    nam = snd_mixer_selem_get_name(portMixer->elems[portIndex]);
+    strncpy(name, nam, len - 1);
+    name[len - 1] = 0;
+    TRACE0("< PORT_GetPortName\n");
+    return TRUE;
+}
+
+
+static int isPlaybackFunction(INT32 portType) {
+        return (portType & PORT_DST_MASK);
+}
+
+
+/* Sets portControl to a pointer to the next free array element in the PortControl (pointer)
+   array of the passed portMixer. Returns TRUE if successful. May return FALSE if there is no
+   free slot. In this case, portControl is not altered */
+static int getControlSlot(PortMixer* portMixer, PortControl** portControl) {
+    if (portMixer->numControls >= MAX_CONTROLS) {
+        return FALSE;
+    } else {
+        *portControl = &(portMixer->controls[portMixer->numControls]);
+        portMixer->numControls++;
+        return TRUE;
+    }
+}
+
+
+/* Protect against illegal min-max values, preventing divisions by zero.
+ */
+inline static long getRange(long min, long max) {
+    if (max > min) {
+        return max - min;
+    } else {
+        return 1;
+    }
+}
+
+
+/* Idea: we may specify that if unit is an empty string, the values are linear and if unit is "dB",
+   the values are logarithmic.
+*/
+static void* createVolumeControl(PortControlCreator* creator,
+                                 PortControl* portControl,
+                                 snd_mixer_elem_t* elem, int isPlayback) {
+    void* control;
+    float precision;
+    long min, max;
+
+    if (isPlayback) {
+        snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
+    } else {
+        snd_mixer_selem_get_capture_volume_range(elem, &min, &max);
+    }
+    /* $$mp: The volume values retrieved with the ALSA API are strongly supposed to be logarithmic.
+       So the following calculation is wrong. However, there is no correct calculation, since
+       for equal-distant logarithmic steps, the precision expressed in linear varies over the
+       scale. */
+    precision = 1.0F / getRange(min, max);
+    control = (creator->newFloatControl)(creator, portControl, CONTROL_TYPE_VOLUME, 0.0F, +1.0F, precision, "");
+    return control;
+}
+
+
+void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
+    PortMixer* portMixer;
+    snd_mixer_elem_t* elem;
+    void* control;
+    PortControl* portControl;
+    void* controls[10];
+    int numControls;
+    char* portName;
+    int isPlayback = 0;
+    int isMono;
+    int isStereo;
+    char* type;
+    snd_mixer_selem_channel_id_t channel;
+
+    TRACE0("> PORT_GetControls\n");
+    if (id == NULL) {
+        ERROR0("Invalid handle!");
+        // $$mp: an error code should be returned.
+        return;
+    }
+    portMixer = (PortMixer*) id;
+    if (portIndex < 0 || portIndex >= portMixer->numElems) {
+        ERROR0("Port index out of range!");
+        // $$mp: an error code should be returned.
+        return;
+    }
+    numControls = 0;
+    elem = portMixer->elems[portIndex];
+    if (snd_mixer_selem_has_playback_volume(elem) || snd_mixer_selem_has_capture_volume(elem)) {
+        /* Since we've splitted/duplicated elements with both playback and capture on the recovery
+           of elements, we now can assume that we handle only to deal with either playback or
+           capture. */
+        isPlayback = isPlaybackFunction(portMixer->types[portIndex]);
+        isMono = (isPlayback && snd_mixer_selem_is_playback_mono(elem)) ||
+            (!isPlayback && snd_mixer_selem_is_capture_mono(elem));
+        isStereo = (isPlayback &&
+                    snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_LEFT) &&
+                    snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_RIGHT)) ||
+            (!isPlayback &&
+             snd_mixer_selem_has_capture_channel(elem, SND_MIXER_SCHN_FRONT_LEFT) &&
+             snd_mixer_selem_has_capture_channel(elem, SND_MIXER_SCHN_FRONT_RIGHT));
+        // single volume control
+        if (isMono || isStereo) {
+            if (getControlSlot(portMixer, &portControl)) {
+                portControl->elem = elem;
+                portControl->portType = portMixer->types[portIndex];
+                portControl->controlType = CONTROL_TYPE_VOLUME;
+                if (isMono) {
+                    portControl->channel = CHANNELS_MONO;
+                } else {
+                    portControl->channel = CHANNELS_STEREO;
+                }
+                control = createVolumeControl(creator, portControl, elem, isPlayback);
+                if (control != NULL) {
+                    controls[numControls++] = control;
+                }
+            }
+        } else { // more than two channels, each channels has its own control.
+            for (channel = SND_MIXER_SCHN_FRONT_LEFT; channel <= SND_MIXER_SCHN_LAST; channel++) {
+                if (isPlayback && snd_mixer_selem_has_playback_channel(elem, channel) ||
+                    !isPlayback && snd_mixer_selem_has_capture_channel(elem, channel)) {
+                    if (getControlSlot(portMixer, &portControl)) {
+                        portControl->elem = elem;
+                        portControl->portType = portMixer->types[portIndex];
+                        portControl->controlType = CONTROL_TYPE_VOLUME;
+                        portControl->channel = channel;
+                        control = createVolumeControl(creator, portControl, elem, isPlayback);
+                        // We wrap in a compound control to provide the channel name.
+                        if (control != NULL) {
+                            /* $$mp 2003-09-14: The following cast shouln't be necessary. Instead, the
+                               declaration of PORT_NewCompoundControlPtr in Ports.h should be changed
+                               to take a const char* parameter. */
+                            control = (creator->newCompoundControl)(creator, (char*) snd_mixer_selem_channel_name(channel), &control, 1);
+                        }
+                        if (control != NULL) {
+                            controls[numControls++] = control;
+                        }
+                    }
+                }
+            }
+        }
+        // BALANCE control
+        if (isStereo) {
+            if (getControlSlot(portMixer, &portControl)) {
+                portControl->elem = elem;
+                portControl->portType = portMixer->types[portIndex];
+                portControl->controlType = CONTROL_TYPE_BALANCE;
+                portControl->channel = CHANNELS_STEREO;
+                /* $$mp: The value for precision is chosen more or less arbitrarily. */
+                control = (creator->newFloatControl)(creator, portControl, CONTROL_TYPE_BALANCE, -1.0F, 1.0F, 0.01F, "");
+                if (control != NULL) {
+                    controls[numControls++] = control;
+                }
+            }
+        }
+    }
+    if (snd_mixer_selem_has_playback_switch(elem) || snd_mixer_selem_has_capture_switch(elem)) {
+        if (getControlSlot(portMixer, &portControl)) {
+            type = isPlayback ? CONTROL_TYPE_MUTE : CONTROL_TYPE_SELECT;
+            portControl->elem = elem;
+            portControl->portType = portMixer->types[portIndex];
+            portControl->controlType = type;
+            control = (creator->newBooleanControl)(creator, portControl, type);
+            if (control != NULL) {
+                controls[numControls++] = control;
+            }
+        }
+    }
+    /* $$mp 2003-09-14: The following cast shouln't be necessary. Instead, the
+       declaration of PORT_NewCompoundControlPtr in Ports.h should be changed
+       to take a const char* parameter. */
+    portName = (char*) snd_mixer_selem_get_name(elem);
+    control = (creator->newCompoundControl)(creator, portName, controls, numControls);
+    if (control != NULL) {
+        (creator->addControl)(creator, control);
+    }
+    TRACE0("< PORT_GetControls\n");
+}
+
+
+INT32 PORT_GetIntValue(void* controlIDV) {
+    PortControl* portControl = (PortControl*) controlIDV;
+    int value = 0;
+    snd_mixer_selem_channel_id_t channel;
+
+    if (portControl != NULL) {
+        switch (portControl->channel) {
+        case CHANNELS_MONO:
+            channel = SND_MIXER_SCHN_MONO;
+            break;
+
+        case CHANNELS_STEREO:
+            channel = SND_MIXER_SCHN_FRONT_LEFT;
+            break;
+
+        default:
+            channel = portControl->channel;
+        }
+        if (portControl->controlType == CONTROL_TYPE_MUTE ||
+            portControl->controlType == CONTROL_TYPE_SELECT) {
+            if (isPlaybackFunction(portControl->portType)) {
+                snd_mixer_selem_get_playback_switch(portControl->elem, channel, &value);
+            } else {
+                snd_mixer_selem_get_capture_switch(portControl->elem, channel, &value);
+            }
+            if (portControl->controlType == CONTROL_TYPE_MUTE) {
+                value = ! value;
+            }
+        } else {
+            ERROR1("PORT_GetIntValue(): inappropriate control type: %s\n",
+                   portControl->controlType);
+        }
+    }
+    return (INT32) value;
+}
+
+
+void PORT_SetIntValue(void* controlIDV, INT32 value) {
+    PortControl* portControl = (PortControl*) controlIDV;
+    snd_mixer_selem_channel_id_t channel;
+
+    if (portControl != NULL) {
+        if (portControl->controlType == CONTROL_TYPE_MUTE) {
+            value = ! value;
+        }
+        if (portControl->controlType == CONTROL_TYPE_MUTE ||
+            portControl->controlType == CONTROL_TYPE_SELECT) {
+            if (isPlaybackFunction(portControl->portType)) {
+                snd_mixer_selem_set_playback_switch_all(portControl->elem, value);
+            } else {
+                snd_mixer_selem_set_capture_switch_all(portControl->elem, value);
+            }
+        } else {
+            ERROR1("PORT_SetIntValue(): inappropriate control type: %s\n",
+                   portControl->controlType);
+        }
+    }
+}
+
+
+static float scaleVolumeValueToNormalized(long value, long min, long max) {
+    return (float) (value - min) / getRange(min, max);
+}
+
+
+static long scaleVolumeValueToHardware(float value, long min, long max) {
+    return (long)(value * getRange(min, max) + min);
+}
+
+
+float getRealVolume(PortControl* portControl,
+                    snd_mixer_selem_channel_id_t channel) {
+    float fValue;
+    long lValue = 0;
+    long min = 0;
+    long max = 0;
+
+    if (isPlaybackFunction(portControl->portType)) {
+        snd_mixer_selem_get_playback_volume_range(portControl->elem,
+                                                  &min, &max);
+        snd_mixer_selem_get_playback_volume(portControl->elem,
+                                            channel, &lValue);
+    } else {
+        snd_mixer_selem_get_capture_volume_range(portControl->elem,
+                                                 &min, &max);
+        snd_mixer_selem_get_capture_volume(portControl->elem,
+                                           channel, &lValue);
+    }
+    fValue = scaleVolumeValueToNormalized(lValue, min, max);
+    return fValue;
+}
+
+
+void setRealVolume(PortControl* portControl,
+                   snd_mixer_selem_channel_id_t channel, float value) {
+    long lValue = 0;
+    long min = 0;
+    long max = 0;
+
+    if (isPlaybackFunction(portControl->portType)) {
+        snd_mixer_selem_get_playback_volume_range(portControl->elem,
+                                                  &min, &max);
+        lValue = scaleVolumeValueToHardware(value, min, max);
+        snd_mixer_selem_set_playback_volume(portControl->elem,
+                                            channel, lValue);
+    } else {
+        snd_mixer_selem_get_capture_volume_range(portControl->elem,
+                                                 &min, &max);
+        lValue = scaleVolumeValueToHardware(value, min, max);
+        snd_mixer_selem_set_capture_volume(portControl->elem,
+                                           channel, lValue);
+    }
+}
+
+
+static float getFakeBalance(PortControl* portControl) {
+    float volL, volR;
+
+    // pan is the ratio of left and right
+    volL = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_LEFT);
+    volR = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_RIGHT);
+    if (volL > volR) {
+        return -1.0f + (volR / volL);
+    }
+    else if (volR > volL) {
+        return 1.0f - (volL / volR);
+    }
+    return 0.0f;
+}
+
+
+static float getFakeVolume(PortControl* portControl) {
+    float valueL;
+    float valueR;
+    float value;
+
+    valueL = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_LEFT);
+    valueR = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_RIGHT);
+    // volume is the greater value of both
+    value = valueL > valueR ? valueL : valueR ;
+    return value;
+}
+
+
+/*
+ * sets the unsigned values for left and right volume according to
+ * the given volume (0...1) and balance (-1..0..+1)
+ */
+static void setFakeVolume(PortControl* portControl, float vol, float bal) {
+    float volumeLeft;
+    float volumeRight;
+
+    if (bal < 0.0f) {
+        volumeLeft = vol;
+        volumeRight = vol * (bal + 1.0f);
+    } else {
+        volumeLeft = vol * (1.0f - bal);
+        volumeRight = vol;
+    }
+    setRealVolume(portControl, SND_MIXER_SCHN_FRONT_LEFT, volumeLeft);
+    setRealVolume(portControl, SND_MIXER_SCHN_FRONT_RIGHT, volumeRight);
+}
+
+
+float PORT_GetFloatValue(void* controlIDV) {
+    PortControl* portControl = (PortControl*) controlIDV;
+    float value = 0.0F;
+
+    if (portControl != NULL) {
+        if (portControl->controlType == CONTROL_TYPE_VOLUME) {
+            switch (portControl->channel) {
+            case CHANNELS_MONO:
+                value = getRealVolume(portControl, SND_MIXER_SCHN_MONO);
+                break;
+
+            case CHANNELS_STEREO:
+                value = getFakeVolume(portControl);
+                break;
+
+            default:
+                value = getRealVolume(portControl, portControl->channel);
+            }
+        } else if (portControl->controlType == CONTROL_TYPE_BALANCE) {
+            if (portControl->channel == CHANNELS_STEREO) {
+                value = getFakeBalance(portControl);
+            } else {
+                ERROR0("PORT_GetFloatValue(): Balance only allowed for stereo channels!\n");
+            }
+        } else {
+            ERROR1("PORT_GetFloatValue(): inappropriate control type: %s!\n",
+                   portControl->controlType);
+        }
+    }
+    return value;
+}
+
+
+void PORT_SetFloatValue(void* controlIDV, float value) {
+    PortControl* portControl = (PortControl*) controlIDV;
+
+    if (portControl != NULL) {
+        if (portControl->controlType == CONTROL_TYPE_VOLUME) {
+            switch (portControl->channel) {
+            case CHANNELS_MONO:
+                setRealVolume(portControl, SND_MIXER_SCHN_MONO, value);
+                break;
+
+            case CHANNELS_STEREO:
+                setFakeVolume(portControl, value, getFakeBalance(portControl));
+                break;
+
+            default:
+                setRealVolume(portControl, portControl->channel, value);
+            }
+        } else if (portControl->controlType == CONTROL_TYPE_BALANCE) {
+            if (portControl->channel == CHANNELS_STEREO) {
+                setFakeVolume(portControl, getFakeVolume(portControl), value);
+            } else {
+                ERROR0("PORT_SetFloatValue(): Balance only allowed for stereo channels!\n");
+            }
+        } else {
+            ERROR1("PORT_SetFloatValue(): inappropriate control type: %s!\n",
+                   portControl->controlType);
+        }
+    }
+}
+
+
+#endif // USE_PORTS
diff --git a/jdk/src/solaris/native/java/io/UnixFileSystem_md.c b/jdk/src/solaris/native/java/io/UnixFileSystem_md.c
index 3735125..5ea55d8 100644
--- a/jdk/src/solaris/native/java/io/UnixFileSystem_md.c
+++ b/jdk/src/solaris/native/java/io/UnixFileSystem_md.c
@@ -41,6 +41,12 @@
 #include "java_io_FileSystem.h"
 #include "java_io_UnixFileSystem.h"
 
+#if defined(_ALLBSD_SOURCE)
+#define dirent64 dirent
+#define readdir64_r readdir_r
+#define stat64 stat
+#define statvfs64 statvfs
+#endif
 
 /* -- Field IDs -- */
 
diff --git a/jdk/src/solaris/native/java/io/canonicalize_md.c b/jdk/src/solaris/native/java/io/canonicalize_md.c
index 6f1c5e0..b78cc2d 100644
--- a/jdk/src/solaris/native/java/io/canonicalize_md.c
+++ b/jdk/src/solaris/native/java/io/canonicalize_md.c
@@ -33,7 +33,9 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <limits.h>
+#if !defined(_ALLBSD_SOURCE)
 #include <alloca.h>
+#endif
 
 
 /* Note: The comments in this file use the terminology
diff --git a/jdk/src/solaris/native/java/io/io_util_md.c b/jdk/src/solaris/native/java/io/io_util_md.c
index d9fa67c..1d9abff 100644
--- a/jdk/src/solaris/native/java/io/io_util_md.c
+++ b/jdk/src/solaris/native/java/io/io_util_md.c
@@ -30,13 +30,50 @@
 #include "io_util_md.h"
 #include <string.h>
 
+#ifdef MACOSX
+
+#include <CoreFoundation/CoreFoundation.h>
+
+static inline char *convertToNFD(const char *path, char *buf, size_t bufsize)
+{
+    CFMutableStringRef mutable = CFStringCreateMutable(NULL, 0);
+    CFStringAppendCString(mutable, path, kCFStringEncodingUTF8);
+    CFStringNormalize(mutable, kCFStringNormalizationFormD);
+
+    CFStringGetCString(mutable, buf, bufsize, kCFStringEncodingUTF8);
+
+    CFRelease(mutable);
+    return buf;
+}
+
+/* Converts the path to NFD form if it was in NFC form. Returns a pointer to
+ * the converting string which could be buf (if the converstion took place) or
+ * origPath if no conversion was needed
+ */
+__private_extern__
+char* convertToNFDIfNeeded(const char *origPath, char *buf, size_t bufsize)
+{
+    const char *current = origPath;
+    int c;
+    for (c = *current; c != 0; current++, c = *current) {
+        if (c < 0) {
+            // Need to convert
+            return convertToNFD(origPath, buf, bufsize);
+        }
+    }
+
+    return (char *)origPath;
+}
+
+#endif
+
 void
 fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags)
 {
     WITH_PLATFORM_STRING(env, path, ps) {
         FD fd;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
         /* Remove trailing slashes, since the kernel won't */
         char *p = (char *)ps + strlen(ps) - 1;
         while ((p > ps) && (*p == '/'))
diff --git a/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c b/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c
index c8f9a64..b946663 100644
--- a/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c
+++ b/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c
@@ -28,6 +28,11 @@
 #include "jni.h"
 #include "jni_util.h"
 
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#endif
+
 JNIEXPORT jobjectArray JNICALL
 Java_java_lang_ProcessEnvironment_environ(JNIEnv *env, jclass ign)
 {
@@ -37,7 +42,9 @@
      * no standard (not even de-facto) header file where the
      * declaration is to be found.  See:
      * http://www.opengroup.org/onlinepubs/007908799/xbd/envvar.html */
+#ifndef __APPLE__
     extern char ** environ; /* environ[i] looks like: VAR=VALUE\0 */
+#endif
 
     jsize count = 0;
     jsize i, j;
diff --git a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
index a10e3ac..6904a44 100644
--- a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
+++ b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
@@ -40,7 +40,11 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <ctype.h>
+#ifdef _ALLBSD_SOURCE
+#include <sys/wait.h>
+#else
 #include <wait.h>
+#endif
 #include <signal.h>
 #include <string.h>
 #include <errno.h>
@@ -49,6 +53,11 @@
 #include <fcntl.h>
 #include <limits.h>
 
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#endif
+
 /*
  * There are 3 possible strategies we might use to "fork":
  *
@@ -385,6 +394,14 @@
   return c >= '0' && c <= '9';
 }
 
+#ifdef _ALLBSD_SOURCE
+#define FD_DIR "/dev/fd"
+#define dirent64 dirent
+#define readdir64 readdir
+#else
+#define FD_DIR "/proc/self/fd"
+#endif
+
 static int
 closeDescriptors(void)
 {
@@ -402,7 +419,7 @@
     restartableClose(from_fd);          /* for possible use by opendir() */
     restartableClose(from_fd + 1);      /* another one for good luck */
 
-    if ((dp = opendir("/proc/self/fd")) == NULL)
+    if ((dp = opendir(FD_DIR)) == NULL)
         return 0;
 
     /* We use readdir64 instead of readdir to work around Solaris bug
diff --git a/jdk/src/solaris/native/java/lang/java_props_macosx.c b/jdk/src/solaris/native/java/lang/java_props_macosx.c
new file mode 100644
index 0000000..af36892
--- /dev/null
+++ b/jdk/src/solaris/native/java/lang/java_props_macosx.c
@@ -0,0 +1,384 @@
+/*
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <dlfcn.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <Security/AuthSession.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
+#include "java_props_macosx.h"
+
+
+// need dlopen/dlsym trick to avoid pulling in JavaRuntimeSupport before libjava.dylib is loaded
+static void *getJRSFramework() {
+    static void *jrsFwk = NULL;
+    if (jrsFwk == NULL) {
+       jrsFwk = dlopen("/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/JavaRuntimeSupport", RTLD_LAZY | RTLD_LOCAL);
+    }
+    return jrsFwk;
+}
+
+static char *getPosixLocale(int cat) {
+    char *lc = setlocale(cat, NULL);
+    if ((lc == NULL) || (strcmp(lc, "C") == 0)) {
+        lc = getenv("LANG");
+    }
+    if (lc == NULL) return NULL;
+    return strdup(lc);
+}
+
+#define LOCALEIDLENGTH  128
+char *setupMacOSXLocale(int cat) {
+    switch (cat) {
+    case LC_MESSAGES:
+        {
+            void *jrsFwk = getJRSFramework();
+            if (jrsFwk == NULL) return getPosixLocale(cat);
+
+            char *(*JRSCopyPrimaryLanguage)() = dlsym(jrsFwk, "JRSCopyPrimaryLanguage");
+            char *primaryLanguage = JRSCopyPrimaryLanguage ? JRSCopyPrimaryLanguage() : NULL;
+            if (primaryLanguage == NULL) return getPosixLocale(cat);
+
+            char *(*JRSCopyCanonicalLanguageForPrimaryLanguage)(char *) = dlsym(jrsFwk, "JRSCopyCanonicalLanguageForPrimaryLanguage");
+            char *canonicalLanguage = JRSCopyCanonicalLanguageForPrimaryLanguage ?  JRSCopyCanonicalLanguageForPrimaryLanguage(primaryLanguage) : NULL;
+            free (primaryLanguage);
+            if (canonicalLanguage == NULL) return getPosixLocale(cat);
+
+            void (*JRSSetDefaultLocalization)(char *) = dlsym(jrsFwk, "JRSSetDefaultLocalization");
+            if (JRSSetDefaultLocalization) JRSSetDefaultLocalization(canonicalLanguage);
+
+            return canonicalLanguage;
+        }
+        break;
+    default:
+        {
+            char localeString[LOCALEIDLENGTH];
+            if (CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
+                                   localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
+                return strdup(localeString);
+            }
+        }
+        break;
+    }
+
+    return NULL;
+}
+
+/* There are several toolkit options on Mac OS X, so we should try to
+ * pick the "best" one, given what we know about the environment Java
+ * is running under
+ */
+
+static PreferredToolkit getPreferredToolkitFromEnv() {
+    char *envVar = getenv("AWT_TOOLKIT");
+    if (envVar == NULL) return unset;
+
+    if (strcasecmp(envVar, "CToolkit") == 0) return CToolkit;
+    if (strcasecmp(envVar, "XToolkit") == 0) return XToolkit;
+    if (strcasecmp(envVar, "HToolkit") == 0) return HToolkit;
+    return unset;
+}
+
+static bool isInAquaSession() {
+    // Is the WindowServer available?
+    SecuritySessionId session_id;
+    SessionAttributeBits session_info;
+    OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
+    if (status != noErr) return false;
+    if (!(session_info & sessionHasGraphicAccess)) return false;
+    return true;
+}
+
+static bool isXDisplayDefined() {
+    return getenv("DISPLAY") != NULL;
+}
+
+PreferredToolkit getPreferredToolkit() {
+    static PreferredToolkit pref = unset;
+    if (pref != unset) return pref;
+
+    PreferredToolkit prefFromEnv = getPreferredToolkitFromEnv();
+    if (prefFromEnv != unset) return pref = prefFromEnv;
+
+    if (isInAquaSession()) return pref = CToolkit;
+    if (isXDisplayDefined()) return pref = XToolkit;
+    return pref = HToolkit;
+}
+
+void setUnknownOSAndVersion(java_props_t *sprops) {
+    sprops->os_name = strdup("Unknown");
+    sprops->os_version = strdup("Unknown");
+}
+
+void setOSNameAndVersion(java_props_t *sprops) {
+    void *jrsFwk = getJRSFramework();
+    if (jrsFwk == NULL) {
+        setUnknownOSAndVersion(sprops);
+        return;
+    }
+
+    char *(*copyOSName)() = dlsym(jrsFwk, "JRSCopyOSName");
+    char *(*copyOSVersion)() = dlsym(jrsFwk, "JRSCopyOSVersion");
+    if (copyOSName == NULL || copyOSVersion == NULL) {
+        setUnknownOSAndVersion(sprops);
+        return;
+    }
+
+    sprops->os_name = copyOSName();
+    sprops->os_version = copyOSVersion();
+}
+
+
+static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey, CFStringRef inHostKey, CFStringRef inPortKey, CFStringRef *outProxyHost, int *ioProxyPort) {
+    /* See if the proxy is enabled. */
+    CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey);
+    if (cf_enabled == NULL) {
+        return false;
+    }
+
+    int isEnabled = false;
+    if (!CFNumberGetValue(cf_enabled, kCFNumberIntType, &isEnabled)) {
+        return isEnabled;
+    }
+
+    if (!isEnabled) return false;
+    *outProxyHost = CFDictionaryGetValue(inDict, inHostKey);
+
+    // If cf_host is null, that means the checkbox is set,
+    //   but no host was entered. We'll treat that as NOT ENABLED.
+    // If cf_port is null or cf_port isn't a number, that means
+    //   no port number was entered. Treat this as ENABLED with the
+    //   protocol's default port.
+    if (*outProxyHost == NULL) {
+        return false;
+    }
+
+    if (CFStringGetLength(*outProxyHost) == 0) {
+        return false;
+    }
+
+    int newPort = 0;
+    CFNumberRef cf_port = NULL;
+    if ((cf_port = CFDictionaryGetValue(inDict, inPortKey)) != NULL &&
+        CFNumberGetValue(cf_port, kCFNumberIntType, &newPort) &&
+        newPort > 0) {
+        *ioProxyPort = newPort;
+    } else {
+        // bad port or no port - leave *ioProxyPort unchanged
+    }
+
+    return true;
+}
+
+static char *createUTF8CString(const CFStringRef theString) {
+    if (theString == NULL) return NULL;
+
+    const CFIndex stringLength = CFStringGetLength(theString);
+    const CFIndex bufSize = CFStringGetMaximumSizeForEncoding(stringLength, kCFStringEncodingUTF8) + 1;
+    char *returnVal = (char *)malloc(bufSize);
+
+    if (CFStringGetCString(theString, returnVal, bufSize, kCFStringEncodingUTF8)) {
+        return returnVal;
+    }
+
+    free(returnVal);
+    return NULL;
+}
+
+// Return TRUE if str is a syntactically valid IP address.
+// Using inet_pton() instead of inet_aton() for IPv6 support.
+// len is only a hint; cstr must still be nul-terminated
+static int looksLikeIPAddress(char *cstr, size_t len) {
+    if (len == 0  ||  (len == 1 && cstr[0] == '.')) return FALSE;
+
+    char dst[16]; // big enough for INET6
+    return (1 == inet_pton(AF_INET, cstr, dst)  ||
+            1 == inet_pton(AF_INET6, cstr, dst));
+}
+
+
+
+// Convert Mac OS X proxy exception entry to Java syntax.
+// See Radar #3441134 for details.
+// Returns NULL if this exception should be ignored by Java.
+// May generate a string with multiple exceptions separated by '|'.
+static char * createConvertedException(CFStringRef cf_original) {
+    // This is done with char* instead of CFString because inet_pton()
+    // needs a C string.
+    char *c_exception = createUTF8CString(cf_original);
+    if (!c_exception) return NULL;
+
+    int c_len = strlen(c_exception);
+
+    // 1. sanitize exception prefix
+    if (c_len >= 1  &&  0 == strncmp(c_exception, ".", 1)) {
+        memmove(c_exception, c_exception+1, c_len);
+        c_len -= 1;
+    } else if (c_len >= 2  &&  0 == strncmp(c_exception, "*.", 2)) {
+        memmove(c_exception, c_exception+2, c_len-1);
+        c_len -= 2;
+    }
+
+    // 2. pre-reject other exception wildcards
+    if (strchr(c_exception, '*')) {
+        free(c_exception);
+        return NULL;
+    }
+
+    // 3. no IP wildcarding
+    if (looksLikeIPAddress(c_exception, c_len)) {
+        return c_exception;
+    }
+
+    // 4. allow domain suffixes
+    // c_exception is now "str\0" - change to "str|*.str\0"
+    c_exception = reallocf(c_exception, c_len+3+c_len+1);
+    if (!c_exception) return NULL;
+
+    strncpy(c_exception+c_len, "|*.", 3);
+    strncpy(c_exception+c_len+3, c_exception, c_len);
+    c_exception[c_len+3+c_len] = '\0';
+    return c_exception;
+}
+
+
+/*
+ * Method for fetching proxy info and storing it in the propery list.
+ */
+void setProxyProperties(java_props_t *sProps) {
+    if (sProps == NULL) return;
+
+    char buf[16];    /* Used for %d of an int - 16 is plenty */
+    CFStringRef
+    cf_httpHost = NULL,
+    cf_httpsHost = NULL,
+    cf_ftpHost = NULL,
+    cf_socksHost = NULL,
+    cf_gopherHost = NULL;
+    int
+    httpPort = 80, // Default proxy port values
+    httpsPort = 443,
+    ftpPort = 21,
+    socksPort = 1080,
+    gopherPort = 70;
+
+    CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
+    if (dict == NULL) return;
+
+    /* Read the proxy exceptions list */
+    CFArrayRef cf_list = CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList);
+
+    CFMutableStringRef cf_exceptionList = NULL;
+    if (cf_list != NULL) {
+        CFIndex len = CFArrayGetCount(cf_list), idx;
+
+        cf_exceptionList = CFStringCreateMutable(NULL, 0);
+        for (idx = (CFIndex)0; idx < len; idx++) {
+            CFStringRef cf_ehost;
+            if ((cf_ehost = CFArrayGetValueAtIndex(cf_list, idx))) {
+                /* Convert this exception from Mac OS X syntax to Java syntax.
+                 See Radar #3441134 for details. This may generate a string
+                 with multiple Java exceptions separated by '|'. */
+                char *c_exception = createConvertedException(cf_ehost);
+                if (c_exception) {
+                    /* Append the host to the list of exclusions. */
+                    if (CFStringGetLength(cf_exceptionList) > 0) {
+                        CFStringAppendCString(cf_exceptionList, "|", kCFStringEncodingMacRoman);
+                    }
+                    CFStringAppendCString(cf_exceptionList, c_exception, kCFStringEncodingMacRoman);
+                    free(c_exception);
+                }
+            }
+        }
+    }
+
+    if (cf_exceptionList != NULL) {
+        if (CFStringGetLength(cf_exceptionList) > 0) {
+            sProps->exceptionList = createUTF8CString(cf_exceptionList);
+        }
+        CFRelease(cf_exceptionList);
+    }
+
+#define CHECK_PROXY(protocol, PROTOCOL)                                     \
+    sProps->protocol##ProxyEnabled =                                        \
+    getProxyInfoForProtocol(dict, kSCPropNetProxies##PROTOCOL##Enable,      \
+    kSCPropNetProxies##PROTOCOL##Proxy,         \
+    kSCPropNetProxies##PROTOCOL##Port,          \
+    &cf_##protocol##Host, &protocol##Port);     \
+    if (sProps->protocol##ProxyEnabled) {                                   \
+        sProps->protocol##Host = createUTF8CString(cf_##protocol##Host);    \
+        snprintf(buf, sizeof(buf), "%d", protocol##Port);                   \
+        sProps->protocol##Port = malloc(strlen(buf) + 1);                   \
+        strcpy(sProps->protocol##Port, buf);                                \
+    }
+
+    CHECK_PROXY(http, HTTP);
+    CHECK_PROXY(https, HTTPS);
+    CHECK_PROXY(ftp, FTP);
+    CHECK_PROXY(socks, SOCKS);
+    CHECK_PROXY(gopher, Gopher);
+
+#undef CHECK_PROXY
+
+    CFRelease(dict);
+}
+
+
+void freeProps(java_props_t *sprops) {
+    if (sprops->httpProxyEnabled) {
+        free(sprops->httpHost);
+        free(sprops->httpPort);
+    }
+
+    if (sprops->httpsProxyEnabled) {
+        free(sprops->httpsHost);
+        free(sprops->httpsPort);
+    }
+
+    if (sprops->ftpProxyEnabled) {
+        free(sprops->ftpHost);
+        free(sprops->ftpPort);
+    }
+
+    if (sprops->socksProxyEnabled) {
+        free(sprops->socksHost);
+        free(sprops->socksPort);
+    }
+
+    if (sprops->gopherProxyEnabled) {
+        free(sprops->gopherHost);
+        free(sprops->gopherPort);
+    }
+    if (sprops->exceptionList) {
+        free(sprops->exceptionList);
+    }
+
+    free(sprops->os_name);
+    free(sprops->os_version);
+}
diff --git a/jdk/src/solaris/native/java/lang/java_props_macosx.h b/jdk/src/solaris/native/java/lang/java_props_macosx.h
new file mode 100644
index 0000000..7290982
--- /dev/null
+++ b/jdk/src/solaris/native/java/lang/java_props_macosx.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "java_props.h"
+
+char *setupMacOSXLocale(int cat);
+void setOSNameAndVersion(java_props_t *sprops);
+void setProxyProperties(java_props_t *sProps);
+
+enum PreferredToolkit_enum {
+    unset = 0, CToolkit, XToolkit, HToolkit
+};
+typedef enum PreferredToolkit_enum PreferredToolkit;
+
+PreferredToolkit getPreferredToolkit();
diff --git a/jdk/src/solaris/native/java/lang/java_props_md.c b/jdk/src/solaris/native/java/lang/java_props_md.c
index 0a24f86..48b3909 100644
--- a/jdk/src/solaris/native/java/lang/java_props_md.c
+++ b/jdk/src/solaris/native/java/lang/java_props_md.c
@@ -23,7 +23,7 @@
  * questions.
  */
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <stdio.h>
 #include <ctype.h>
 #endif
@@ -42,9 +42,21 @@
 #include <time.h>
 #include <errno.h>
 
+#ifdef MACOSX
+#include "java_props_macosx.h"
+#endif
+
+#if defined(_ALLBSD_SOURCE)
+#if !defined(P_tmpdir)
+#include <paths.h>
+#define P_tmpdir _PATH_VARTMP
+#endif
+#endif
+
 #include "locale_str.h"
 #include "java_props.h"
 
+#if !defined(_ALLBSD_SOURCE)
 #ifdef __linux__
   #ifndef CODESET
   #define CODESET _NL_CTYPE_CODESET_NAME
@@ -54,6 +66,7 @@
 #define CODESET ALT_CODESET_KEY
 #endif
 #endif
+#endif /* !_ALLBSD_SOURCE */
 
 #ifdef JAVASE_EMBEDDED
 #include <dlfcn.h>
@@ -131,7 +144,12 @@
     char *lc;
 
     /* Query the locale set for the category */
+
+#ifdef MACOSX
+    lc = setupMacOSXLocale(cat); // malloc'd memory, need to free
+#else
     lc = setlocale(cat, NULL);
+#endif
 
 #ifndef __linux__
     if (lc == NULL) {
@@ -169,7 +187,9 @@
      */
 
     strcpy(temp, lc);
-
+#ifdef MACOSX
+    free(lc); // malloced memory
+#endif
     /* Parse the language, country, encoding, and variant from the
      * locale.  Any of the elements may be missing, but they must occur
      * in the order language_country.encoding@variant, and must be
@@ -354,21 +374,62 @@
 
     /* tmp dir */
     sprops.tmp_dir = P_tmpdir;
+#ifdef MACOSX
+    /* darwin has a per-user temp dir */
+    static char tmp_path[PATH_MAX];
+    int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, tmp_path, PATH_MAX);
+    if (pathSize > 0 && pathSize <= PATH_MAX) {
+        sprops.tmp_dir = tmp_path;
+    }
+#endif /* MACOSX */
 
     /* Printing properties */
+#ifdef MACOSX
+    sprops.printerJob = "sun.lwawt.macosx.CPrinterJob";
+#else
     sprops.printerJob = "sun.print.PSPrinterJob";
+#endif
 
     /* patches/service packs installed */
     sprops.patch_level = "unknown";
 
     /* Java 2D properties */
+#ifdef MACOSX
+    PreferredToolkit prefToolkit = getPreferredToolkit();
+    switch (prefToolkit) {
+        case CToolkit:
+            sprops.graphics_env = "sun.awt.CGraphicsEnvironment";
+            break;
+        case XToolkit:
+#endif
     sprops.graphics_env = "sun.awt.X11GraphicsEnvironment";
-
+#ifdef MACOSX
+            break;
+        default:
+            sprops.graphics_env = "sun.awt.HeadlessGraphicsEnvironment";
+            break;
+    }
+#endif
+    /* AWT properties */
 #ifdef JAVASE_EMBEDDED
     sprops.awt_toolkit = getEmbeddedToolkit();
     if (sprops.awt_toolkit == NULL) // default as below
 #endif
+#ifdef MACOSX
+        switch (prefToolkit) {
+            case CToolkit:
+                sprops.awt_toolkit = "sun.lwawt.macosx.LWCToolkit";
+                break;
+            case XToolkit:
+#endif
     sprops.awt_toolkit = "sun.awt.X11.XToolkit";
+#ifdef MACOSX
+                break;
+            default:
+                sprops.awt_toolkit = "sun.awt.HToolkit";
+                break;
+        }
+#endif
 
     /* This is used only for debugging of font problems. */
     v = getenv("JAVA2D_FONTPATH");
@@ -396,10 +457,14 @@
 
     /* os properties */
     {
+#ifdef MACOSX
+        setOSNameAndVersion(&sprops);
+#else
         struct utsname name;
         uname(&name);
         sprops.os_name = strdup(name.sysname);
         sprops.os_version = strdup(name.release);
+#endif
 
         sprops.os_arch = ARCHPROPNAME;
 
@@ -437,6 +502,13 @@
     sprops.display_variant = sprops.variant;
     sprops.sun_jnu_encoding = sprops.encoding;
 
+#ifdef _ALLBSD_SOURCE
+#if BYTE_ORDER == _LITTLE_ENDIAN
+     sprops.unicode_encoding = "UnicodeLittle";
+ #else
+     sprops.unicode_encoding = "UnicodeBig";
+ #endif
+#else /* !_ALLBSD_SOURCE */
 #ifdef __linux__
 #if __BYTE_ORDER == __LITTLE_ENDIAN
     sprops.unicode_encoding = "UnicodeLittle";
@@ -446,6 +518,7 @@
 #else
     sprops.unicode_encoding = "UnicodeBig";
 #endif
+#endif /* _ALLBSD_SOURCE */
 
     /* user properties */
     {
@@ -482,12 +555,19 @@
     sprops.path_separator = ":";
     sprops.line_separator = "\n";
 
+#if !defined(_ALLBSD_SOURCE)
     /* Append CDE message and resource search path to NLSPATH and
      * XFILESEARCHPATH, in order to pick localized message for
      * FileSelectionDialog window (Bug 4173641).
      */
     setPathEnvironment("NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat");
     setPathEnvironment("XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt");
+#endif
+
+
+#ifdef MACOSX
+    setProxyProperties(&sprops);
+#endif
 
     return &sprops;
 }
diff --git a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c
index 9a5b78e..278ce13 100644
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c
+++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c
@@ -36,12 +36,288 @@
 #include <stdlib.h>
 #include <ctype.h>
 
+#ifdef _ALLBSD_SOURCE
+#include <unistd.h>
+#include <sys/param.h>
+#endif
+
 #include "jvm.h"
 #include "jni_util.h"
 #include "net_util.h"
 
 #include "java_net_Inet4AddressImpl.h"
 
+#if defined(__GLIBC__) || (defined(__FreeBSD__) && (__FreeBSD_version >= 601104))
+#define HAS_GLIBC_GETHOSTBY_R   1
+#endif
+
+#if defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R)
+/* Use getaddrinfo(3), which is thread safe */
+/************************************************************************
+ * Inet4AddressImpl
+ */
+
+/*
+ * Class:     java_net_Inet4AddressImpl
+ * Method:    getLocalHostName
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
+    char hostname[NI_MAXHOST+1];
+
+    hostname[0] = '\0';
+    if (JVM_GetHostName(hostname, NI_MAXHOST)) {
+        /* Something went wrong, maybe networking is not setup? */
+        strcpy(hostname, "localhost");
+    } else {
+         struct addrinfo  hints, *res;
+         int error;
+
+         memset(&hints, 0, sizeof(hints));
+         hints.ai_flags = AI_CANONNAME;
+         hints.ai_family = AF_UNSPEC;
+
+         error = getaddrinfo(hostname, NULL, &hints, &res);
+
+         if (error == 0) {
+             /* host is known to name service */
+             error = getnameinfo(res->ai_addr,
+                                 res->ai_addrlen,
+                                 hostname,
+                                 NI_MAXHOST,
+                                 NULL,
+                                 0,
+                                 NI_NAMEREQD);
+
+             /* if getnameinfo fails hostname is still the value
+                from gethostname */
+
+             freeaddrinfo(res);
+        }
+    }
+    return (*env)->NewStringUTF(env, hostname);
+}
+
+static jclass ni_iacls;
+static jclass ni_ia4cls;
+static jmethodID ni_ia4ctrID;
+static jfieldID ni_iaaddressID;
+static jfieldID ni_iahostID;
+static jfieldID ni_iafamilyID;
+static int initialized = 0;
+
+/*
+ * Find an internet address for a given hostname.  Note that this
+ * code only works for addresses of type INET. The translation
+ * of %d.%d.%d.%d to an address (int) occurs in java now, so the
+ * String "host" shouldn't *ever* be a %d.%d.%d.%d string
+ *
+ * Class:     java_net_Inet4AddressImpl
+ * Method:    lookupAllHostAddr
+ * Signature: (Ljava/lang/String;)[[B
+ */
+
+JNIEXPORT jobjectArray JNICALL
+Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
+                                                jstring host) {
+    const char *hostname;
+    jobject name;
+    jobjectArray ret = 0;
+    int retLen = 0;
+
+    int error=0;
+    struct addrinfo hints, *res, *resNew = NULL;
+
+    if (!initialized) {
+      ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
+      ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
+      ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
+      ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
+      ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
+      ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I");
+      ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I");
+      ni_iahostID = (*env)->GetFieldID(env, ni_iacls, "hostName", "Ljava/lang/String;");
+      initialized = 1;
+    }
+
+    if (IS_NULL(host)) {
+        JNU_ThrowNullPointerException(env, "host is null");
+        return 0;
+    }
+    hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
+    CHECK_NULL_RETURN(hostname, NULL);
+
+    memset(&hints, 0, sizeof(hints));
+    hints.ai_flags = AI_CANONNAME;
+    hints.ai_family = AF_INET;
+
+    /*
+     * Workaround for Solaris bug 4160367 - if a hostname contains a
+     * white space then 0.0.0.0 is returned
+     */
+    if (isspace((unsigned char)hostname[0])) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
+                        (char *)hostname);
+        JNU_ReleaseStringPlatformChars(env, host, hostname);
+        return NULL;
+    }
+
+    error = getaddrinfo(hostname, NULL, &hints, &res);
+
+    if (error) {
+        /* report error */
+        JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
+                        (char *)hostname);
+        JNU_ReleaseStringPlatformChars(env, host, hostname);
+        return NULL;
+    } else {
+        int i = 0;
+        struct addrinfo *itr, *last = NULL, *iterator = res;
+        while (iterator != NULL) {
+            int skip = 0;
+            itr = resNew;
+
+            while (itr != NULL) {
+                struct sockaddr_in *addr1, *addr2;
+
+                addr1 = (struct sockaddr_in *)iterator->ai_addr;
+                addr2 = (struct sockaddr_in *)itr->ai_addr;
+                if (addr1->sin_addr.s_addr ==
+                    addr2->sin_addr.s_addr) {
+                    skip = 1;
+                    break;
+                }
+
+                itr = itr->ai_next;
+            }
+
+            if (!skip) {
+                struct addrinfo *next
+                    = (struct addrinfo*) malloc(sizeof(struct addrinfo));
+                if (!next) {
+                    JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
+                    ret = NULL;
+                    goto cleanupAndReturn;
+                }
+                memcpy(next, iterator, sizeof(struct addrinfo));
+                next->ai_next = NULL;
+                if (resNew == NULL) {
+                    resNew = next;
+                } else {
+                    last->ai_next = next;
+                }
+                last = next;
+                i++;
+            }
+            iterator = iterator->ai_next;
+        }
+
+        retLen = i;
+        iterator = resNew;
+        i = 0;
+
+        name = (*env)->NewStringUTF(env, hostname);
+        if (IS_NULL(name)) {
+          goto cleanupAndReturn;
+        }
+
+        ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
+        if (IS_NULL(ret)) {
+            /* we may have memory to free at the end of this */
+            goto cleanupAndReturn;
+        }
+
+        while (iterator != NULL) {
+            /* We need 4 bytes to store ipv4 address; */
+            int len = 4;
+
+            jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+            if (IS_NULL(iaObj)) {
+                /* we may have memory to free at the end of this */
+                ret = NULL;
+                goto cleanupAndReturn;
+            }
+            (*env)->SetIntField(env, iaObj, ni_iaaddressID,
+                                ntohl(((struct sockaddr_in*)(iterator->ai_addr))->sin_addr.s_addr));
+            (*env)->SetObjectField(env, iaObj, ni_iahostID, name);
+            (*env)->SetObjectArrayElement(env, ret, retLen - i -1, iaObj);
+            i++;
+            iterator = iterator->ai_next;
+        }
+    }
+
+cleanupAndReturn:
+    {
+        struct addrinfo *iterator, *tmp;
+        iterator = resNew;
+        while (iterator != NULL) {
+            tmp = iterator;
+            iterator = iterator->ai_next;
+            free(tmp);
+        }
+        JNU_ReleaseStringPlatformChars(env, host, hostname);
+    }
+
+    freeaddrinfo(res);
+
+    return ret;
+
+}
+
+/*
+ * Class:     java_net_Inet4AddressImpl
+ * Method:    getHostByAddr
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
+                                            jbyteArray addrArray) {
+    jstring ret = NULL;
+
+    char host[NI_MAXHOST+1];
+    jfieldID fid;
+    int error = 0;
+    jint family;
+    struct sockaddr *him ;
+    int len = 0;
+    jbyte caddr[4];
+    jint addr;
+
+    struct sockaddr_in him4;
+    struct sockaddr *sa;
+
+    /*
+         * For IPv4 addresses construct a sockaddr_in structure.
+         */
+    (*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
+    addr = ((caddr[0]<<24) & 0xff000000);
+    addr |= ((caddr[1] <<16) & 0xff0000);
+    addr |= ((caddr[2] <<8) & 0xff00);
+    addr |= (caddr[3] & 0xff);
+    memset((char *) &him4, 0, sizeof(him4));
+    him4.sin_addr.s_addr = (uint32_t) htonl(addr);
+    him4.sin_family = AF_INET;
+    sa = (struct sockaddr *) &him4;
+    len = sizeof(him4);
+
+    error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
+                               NI_NAMEREQD);
+
+    if (!error) {
+        ret = (*env)->NewStringUTF(env, host);
+    }
+
+    if (ret == NULL) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", NULL);
+    }
+
+    return ret;
+
+}
+
+#else /* defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R) */
+
 /* the initial size of our hostent buffers */
 #define HENT_BUF_SIZE 1024
 #define BIG_HENT_BUF_SIZE 10240  /* a jumbo-sized one */
@@ -86,13 +362,13 @@
         // ensure null-terminated
         hostname[MAXHOSTNAMELEN] = '\0';
 
-#ifdef __GLIBC__
+#ifdef HAS_GLIBC_GETHOSTBY_R
         gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &hp, &h_error);
 #else
         hp = gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &h_error);
 #endif
         if (hp) {
-#ifdef __GLIBC__
+#ifdef HAS_GLIBC_GETHOSTBY_R
             gethostbyaddr_r(hp->h_addr, hp->h_length, AF_INET,
                             &res2, (char*)buf2, sizeof(buf2), &hp, &h_error);
 #else
@@ -182,7 +458,7 @@
 #endif
 
     /* Try once, with our static buffer. */
-#ifdef __GLIBC__
+#ifdef HAS_GLIBC_GETHOSTBY_R
     gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &hp, &h_error);
 #else
     hp = gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &h_error);
@@ -195,7 +471,7 @@
      */
     if (hp == NULL && errno == ERANGE) {
         if ((tmp = (char*)malloc(BIG_HENT_BUF_SIZE))) {
-#ifdef __GLIBC__
+#ifdef HAS_GLIBC_GETHOSTBY_R
             gethostbyname_r(hostname, &res, tmp, BIG_HENT_BUF_SIZE,
                             &hp, &h_error);
 #else
@@ -280,7 +556,7 @@
     addr |= ((caddr[2] <<8) & 0xff00);
     addr |= (caddr[3] & 0xff);
     addr = htonl(addr);
-#ifdef __GLIBC__
+#ifdef HAS_GLIBC_GETHOSTBY_R
     gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET, &hent,
                     (char*)buf, sizeof(buf), &hp, &h_error);
 #else
@@ -294,7 +570,7 @@
      */
     if (hp == NULL && errno == ERANGE) {
         if ((tmp = (char*)malloc(BIG_HENT_BUF_SIZE))) {
-#ifdef __GLIBC__
+#ifdef HAS_GLIBC_GETHOSTBY_R
             gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET,
                             &hent, tmp, BIG_HENT_BUF_SIZE, &hp, &h_error);
 #else
@@ -316,6 +592,8 @@
     return ret;
 }
 
+#endif /* _ALLBSD_SOURCE */
+
 #define SET_NONBLOCKING(fd) {           \
         int flags = fcntl(fd, F_GETFL); \
         flags |= O_NONBLOCK;            \
@@ -454,6 +732,7 @@
 
     memset((char *) caddr, 0, sizeof(caddr));
     memset((char *) &him, 0, sizeof(him));
+    memset((char *) &inf, 0, sizeof(inf));
     sz = (*env)->GetArrayLength(env, addrArray);
     if (sz != 4) {
       return JNI_FALSE;
diff --git a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c
index bb5bae7..9efbe39 100644
--- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c
+++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c
@@ -33,6 +33,9 @@
 #include <strings.h>
 #include <stdlib.h>
 #include <ctype.h>
+#ifdef _ALLBSD_SOURCE
+#include <unistd.h> /* gethostname */
+#endif
 
 #include "jvm.h"
 #include "jni_util.h"
@@ -70,8 +73,8 @@
     } else {
         // ensure null-terminated
         hostname[NI_MAXHOST] = '\0';
-#ifdef __linux__
-        /* On Linux gethostname() says "host.domain.sun.com".  On
+#if defined(__linux__) && defined(_ALLBSD_SOURCE)
+        /* On Linux/FreeBSD gethostname() says "host.domain.sun.com".  On
          * Solaris gethostname() says "host", so extra work is needed.
          */
 #else
@@ -109,7 +112,7 @@
             }
         }
 #endif /* AF_INET6 */
-#endif /* __linux__ */
+#endif /* __linux__ || _ALLBSD_SOURCE */
     }
     return (*env)->NewStringUTF(env, hostname);
 }
diff --git a/jdk/src/solaris/native/java/net/NetworkInterface.c b/jdk/src/solaris/native/java/net/NetworkInterface.c
index 0f987ff..6cddea3 100644
--- a/jdk/src/solaris/native/java/net/NetworkInterface.c
+++ b/jdk/src/solaris/native/java/net/NetworkInterface.c
@@ -26,6 +26,9 @@
 
 #include <errno.h>
 #include <strings.h>
+#if defined(_ALLBSD_SOURCE) && defined(__OpenBSD__)
+#include <sys/types.h>
+#endif
 #include <netinet/in.h>
 #include <stdlib.h>
 #include <string.h>
@@ -53,6 +56,19 @@
 #define _PATH_PROCNET_IFINET6           "/proc/net/if_inet6"
 #endif
 
+#if defined(_ALLBSD_SOURCE)
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/sockio.h>
+#if defined(__APPLE__)
+#include <net/ethernet.h>
+#include <net/if_var.h>
+#include <net/if_dl.h>
+#include <netinet/in_var.h>
+#include <ifaddrs.h>
+#endif
+#endif
+
 #include "jvm.h"
 #include "jni_util.h"
 #include "net_util.h"
@@ -92,6 +108,7 @@
 jfieldID ni_virutalID;
 jfieldID ni_childsID;
 jfieldID ni_parentID;
+jfieldID ni_defaultIndexID;
 jmethodID ni_ctrID;
 
 static jclass ni_iacls;
@@ -139,8 +156,12 @@
 #ifdef __solaris__
 static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family);
 static int    getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf);
+
+#ifndef SIOCGLIFHWADDR
+#define SIOCGLIFHWADDR  _IOWR('i', 192, struct lifreq)
 #endif
 
+#endif
 
 /******************* Java entry points *****************************/
 
@@ -180,6 +201,7 @@
     ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;");
     ni_ib4broadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;");
     ni_ib4maskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
+    ni_defaultIndexID = (*env)->GetStaticFieldID(env, ni_class, "defaultIndex", "I");
 }
 
 
@@ -820,11 +842,11 @@
     netif *currif = ifs, *parent;
     netaddr *addrP;
 
-    #ifdef __solaris__
+#ifdef LIFNAMSIZ
     char name[LIFNAMSIZ],  vname[LIFNAMSIZ];
-    #else
+#else
     char name[IFNAMSIZ],  vname[IFNAMSIZ];
-    #endif
+#endif
 
     char  *name_colonP;
     int mask;
@@ -1567,6 +1589,20 @@
     struct sockaddr_in* sin;
     struct sockaddr_in ipAddr;
     int len, i;
+    struct lifreq lif;
+
+    /* First, try the new (S11) SIOCGLIFHWADDR ioctl(). If that fails
+     * try the old way.
+     */
+    memset(&lif, 0, sizeof(lif));
+    strlcpy(lif.lifr_name, ifname, sizeof(lif.lifr_name));
+
+    if (ioctl(sock, SIOCGLIFHWADDR, &lif) != -1) {
+        struct sockaddr_dl *sp;
+        sp = (struct sockaddr_dl *)&lif.lifr_addr;
+        memcpy(buf, &sp->sdl_data[0], sp->sdl_alen);
+        return sp->sdl_alen;
+    }
 
    /**
     * On Solaris we have to use DLPI, but it will only work if we have
@@ -1576,34 +1612,29 @@
     if ((len = getMacFromDevice(env, ifname, buf))  == 0) {
         /*DLPI failed - trying to do arp lookup*/
 
-       if (addr == NULL) {
-          /**
-           * No IPv4 address for that interface, so can't do an ARP lookup.
-           */
-           return -1;
-      }
+        if (addr == NULL) {
+            /**
+             * No IPv4 address for that interface, so can't do an ARP lookup.
+             */
+             return -1;
+         }
 
-      len = 6; //???
+         len = 6; //???
 
-      sin = (struct sockaddr_in *) &arpreq.arp_pa;
-      memset((char *) &arpreq, 0, sizeof(struct arpreq));
-      ipAddr.sin_port = 0;
-      ipAddr.sin_family = AF_INET;
-      memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
-      memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
-      arpreq.arp_flags= ATF_PUBL;
+         sin = (struct sockaddr_in *) &arpreq.arp_pa;
+         memset((char *) &arpreq, 0, sizeof(struct arpreq));
+         ipAddr.sin_port = 0;
+         ipAddr.sin_family = AF_INET;
+         memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
+         memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
+         arpreq.arp_flags= ATF_PUBL;
 
-      if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
-          if (errno != ENXIO) {
-              // "No such device or address" means no hardware address, so it's
-              // normal don't throw an exception
-              NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL failed");
-              return -1;
-          }
-     }
+         if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
+             return -1;
+         }
 
-     memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
-  }
+         memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
+    }
 
     /*
      * All bytes to 0 means no hardware address.
@@ -1648,3 +1679,307 @@
 #endif
 
 
+/** BSD **/
+#ifdef _ALLBSD_SOURCE
+/* Open socket for further ioct calls, try v4 socket first and
+ * if it falls return v6 socket
+ */
+
+#ifdef AF_INET6
+static int openSocketWithFallback(JNIEnv *env, const char *ifname){
+    int sock;
+    struct ifreq if2;
+
+     if ((sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+         if (errno == EPROTONOSUPPORT){
+              if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
+                 NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
+                 return -1;
+              }
+         }
+         else{ // errno is not NOSUPPORT
+             NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed");
+             return -1;
+         }
+   }
+
+   return sock;
+}
+
+#else
+static int openSocketWithFallback(JNIEnv *env, const char *ifname){
+    return openSocket(env,AF_INET);
+}
+#endif
+
+/*
+ * Enumerates and returns all IPv4 interfaces
+ */
+static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
+    struct ifaddrs *ifa, *origifa;
+
+    if (getifaddrs(&origifa) != 0) {
+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
+                         "getifaddrs() function failed");
+        return ifs;
+    }
+
+    for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
+
+        /*
+         * Skip non-AF_INET entries.
+         */
+        if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET)
+            continue;
+
+        /*
+         * Add to the list.
+         */
+        ifs = addif(env, sock, ifa->ifa_name, ifs, ifa->ifa_addr, AF_INET, 0);
+
+        /*
+         * If an exception occurred then free the list.
+         */
+        if ((*env)->ExceptionOccurred(env)) {
+            freeifaddrs(origifa);
+            freeif(ifs);
+            return NULL;
+        }
+    }
+
+    /*
+     * Free socket and buffer
+     */
+    freeifaddrs(origifa);
+    return ifs;
+}
+
+
+/*
+ * Enumerates and returns all IPv6 interfaces on Linux
+ */
+
+#ifdef AF_INET6
+/*
+ * Determines the prefix on BSD for IPv6 interfaces.
+ */
+static
+int prefix(void *val, int size) {
+    u_char *name = (u_char *)val;
+    int byte, bit, plen = 0;
+
+    for (byte = 0; byte < size; byte++, plen += 8)
+        if (name[byte] != 0xff)
+            break;
+    if (byte == size)
+        return (plen);
+    for (bit = 7; bit != 0; bit--, plen++)
+        if (!(name[byte] & (1 << bit)))
+            break;
+    for (; bit != 0; bit--)
+        if (name[byte] & (1 << bit))
+            return (0);
+    byte++;
+    for (; byte < size; byte++)
+        if (name[byte])
+            return (0);
+    return (plen);
+}
+
+/*
+ * Enumerates and returns all IPv6 interfaces on BSD
+ */
+static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
+    struct ifaddrs *ifa, *origifa;
+    struct sockaddr_in6 *sin6;
+    struct in6_ifreq ifr6;
+
+    if (getifaddrs(&origifa) != 0) {
+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
+                         "getifaddrs() function failed");
+        return ifs;
+    }
+
+    for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
+
+        /*
+         * Skip non-AF_INET6 entries.
+         */
+        if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET6)
+            continue;
+
+        memset(&ifr6, 0, sizeof(ifr6));
+        strlcpy(ifr6.ifr_name, ifa->ifa_name, sizeof(ifr6.ifr_name));
+        memcpy(&ifr6.ifr_addr, ifa->ifa_addr, MIN(sizeof(ifr6.ifr_addr), ifa->ifa_addr->sa_len));
+
+        if (ioctl(sock, SIOCGIFNETMASK_IN6, (caddr_t)&ifr6) < 0) {
+            NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
+                             "ioctl SIOCGIFNETMASK_IN6 failed");
+            freeifaddrs(origifa);
+            freeif(ifs);
+            return NULL;
+        }
+
+        /* Add to the list.  */
+        sin6 = (struct sockaddr_in6 *)&ifr6.ifr_addr;
+        ifs = addif(env, sock, ifa->ifa_name, ifs, ifa->ifa_addr, AF_INET6,
+                    prefix(&sin6->sin6_addr, sizeof(struct in6_addr)));
+
+        /* If an exception occurred then free the list.  */
+        if ((*env)->ExceptionOccurred(env)) {
+            freeifaddrs(origifa);
+            freeif(ifs);
+            return NULL;
+        }
+    }
+
+    /*
+     * Free socket and ifaddrs buffer
+     */
+    freeifaddrs(origifa);
+    return ifs;
+}
+#endif
+
+static int getIndex(int sock, const char *name){
+#ifdef __FreeBSD__
+     /*
+      * Try to get the interface index
+      * (Not supported on Solaris 2.6 or 7)
+      */
+    struct ifreq if2;
+    strcpy(if2.ifr_name, name);
+
+    if (ioctl(sock, SIOCGIFINDEX, (char *)&if2) < 0) {
+        return -1;
+    }
+
+    return if2.ifr_index;
+#else
+    /*
+     * Try to get the interface index using BSD specific if_nametoindex
+     */
+    int index = if_nametoindex(name);
+    return (index == 0) ? -1 : index;
+#endif
+}
+
+/**
+ * Returns the IPv4 broadcast address of a named interface, if it exists.
+ * Returns 0 if it doesn't have one.
+ */
+static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *ifname, struct sockaddr *brdcast_store) {
+  struct sockaddr *ret = NULL;
+  struct ifreq if2;
+
+  memset((char *) &if2, 0, sizeof(if2));
+  strcpy(if2.ifr_name, ifname);
+
+  /* Let's make sure the interface does have a broadcast address */
+  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0) {
+      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFFLAGS failed");
+      return ret;
+  }
+
+  if (if2.ifr_flags & IFF_BROADCAST) {
+      /* It does, let's retrieve it*/
+      if (ioctl(sock, SIOCGIFBRDADDR, (char *)&if2) < 0) {
+          NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFBRDADDR failed");
+          return ret;
+      }
+
+      ret = brdcast_store;
+      memcpy(ret, &if2.ifr_broadaddr, sizeof(struct sockaddr));
+  }
+
+  return ret;
+}
+
+/**
+ * Returns the IPv4 subnet prefix length (aka subnet mask) for the named
+ * interface, if it has one, otherwise return -1.
+ */
+static short getSubnet(JNIEnv *env, int sock, const char *ifname) {
+    unsigned int mask;
+    short ret;
+    struct ifreq if2;
+
+    memset((char *) &if2, 0, sizeof(if2));
+    strcpy(if2.ifr_name, ifname);
+
+    if (ioctl(sock, SIOCGIFNETMASK, (char *)&if2) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFNETMASK failed");
+        return -1;
+    }
+
+    mask = ntohl(((struct sockaddr_in*)&(if2.ifr_addr))->sin_addr.s_addr);
+    ret = 0;
+    while (mask) {
+       mask <<= 1;
+       ret++;
+    }
+
+    return ret;
+}
+
+/**
+ * Get the Hardware address (usually MAC address) for the named interface.
+ * return puts the data in buf, and returns the length, in byte, of the
+ * MAC address. Returns -1 if there is no hardware address on that interface.
+ */
+static int getMacAddress(JNIEnv *env, int sock, const char* ifname, const struct in_addr* addr, unsigned char *buf) {
+    struct ifaddrs *ifa0, *ifa;
+    struct sockaddr *saddr;
+    int i;
+
+    /* Grab the interface list */
+    if (!getifaddrs(&ifa0)) {
+        /* Cycle through the interfaces */
+        for (i = 0, ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next, i++) {
+            saddr = ifa->ifa_addr;
+            /* Link layer contains the MAC address */
+            if (saddr->sa_family == AF_LINK && !strcmp(ifname, ifa->ifa_name)) {
+                struct sockaddr_dl *sadl = (struct sockaddr_dl *) saddr;
+                /* Check the address is the correct length */
+                if (sadl->sdl_alen == ETHER_ADDR_LEN) {
+                    memcpy(buf, (sadl->sdl_data + sadl->sdl_nlen), ETHER_ADDR_LEN);
+                    freeifaddrs(ifa0);
+                    return ETHER_ADDR_LEN;
+                }
+            }
+        }
+        freeifaddrs(ifa0);
+    }
+
+    return -1;
+}
+
+static int getMTU(JNIEnv *env, int sock,  const char *ifname) {
+    struct ifreq if2;
+
+    memset((char *) &if2, 0, sizeof(if2));
+    strcpy(if2.ifr_name, ifname);
+
+    if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFMTU failed");
+        return -1;
+    }
+
+    return  if2.ifr_mtu;
+}
+
+static int getFlags(int sock, const char *ifname) {
+  struct ifreq if2;
+  int ret = -1;
+
+  memset((char *) &if2, 0, sizeof(if2));
+  strcpy(if2.ifr_name, ifname);
+
+  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0){
+      return -1;
+  }
+
+  return (((int) if2.ifr_flags) & 0xffff);
+}
+
+#endif
diff --git a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c
index 7a1edc3..cbdacdf 100644
--- a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c
+++ b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c
@@ -83,6 +83,8 @@
 static jfieldID pdsi_ttlID;
 #endif
 
+extern void setDefaultScopeID(JNIEnv *env, struct sockaddr *him);
+
 /*
  * Returns a java.lang.Integer based on 'i'
  */
@@ -240,6 +242,7 @@
     if (NET_InetAddressToSockaddr(env, iaObj, localport, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
       return;
     }
+    setDefaultScopeID(env, (struct sockaddr *)&him);
 
     if (NET_Bind(fd, (struct sockaddr *)&him, len) < 0)  {
         if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
@@ -310,6 +313,7 @@
         setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int));
     } else
 #endif
+    setDefaultScopeID(env, (struct sockaddr *)&rmtaddr);
     {
         if (JVM_Connect(fd, (struct sockaddr *)&rmtaddr, len) == -1) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
@@ -331,7 +335,7 @@
     /* The fdObj'fd */
     jint fd;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     SOCKADDR addr;
     int len;
 #endif
@@ -341,11 +345,13 @@
     }
     fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
 
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #ifdef __linux__
     if (isOldKernel) {
         int t = 1;
         setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int));
     } else {
+#endif /* __linux__ */
         memset(&addr, 0, sizeof(addr));
 #ifdef AF_INET6
         if (ipv6_available()) {
@@ -361,6 +367,7 @@
         }
         JVM_Connect(fd, (struct sockaddr *)&addr, len);
 
+#ifdef __linux__
         // After disconnecting a UDP socket, Linux kernel will set
         // local port to zero if the port number comes from implicit
         // bind. Successive send/recv on the same socket will fail.
@@ -383,6 +390,7 @@
             NET_Bind(fd, (struct sockaddr *)&addr, len);
         }
     }
+#endif
 #else
     JVM_Connect(fd, 0, 0);
 #endif
@@ -453,6 +461,7 @@
           return;
         }
     }
+    setDefaultScopeID(env, (struct sockaddr *)&rmtaddr);
 
     if (packetBufferLen > MAX_BUFFER_LEN) {
         /* When JNI-ifying the JDK's IO routines, we turned
@@ -1052,7 +1061,7 @@
 Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
                                                            jobject this) {
     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
-    int fd, t = 1;
+    int arg, fd, t = 1;
 #ifdef AF_INET6
     int domain = ipv6_available() ? AF_INET6 : AF_INET;
 #else
@@ -1074,7 +1083,7 @@
 #ifdef AF_INET6
     /* Disable IPV6_V6ONLY to ensure dual-socket support */
     if (domain == AF_INET6) {
-        int arg = 0;
+        arg = 0;
         if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
                        sizeof(int)) < 0) {
             NET_ThrowNew(env, errno, "cannot set IPPROTO_IPV6");
@@ -1084,6 +1093,22 @@
     }
 #endif /* AF_INET6 */
 
+#ifdef __APPLE__
+    arg = 65507;
+    if (JVM_SetSockOpt(fd, SOL_SOCKET, SO_SNDBUF,
+                       (char *)&arg, sizeof(arg)) < 0) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        strerror(errno));
+        return;
+    }
+    if (JVM_SetSockOpt(fd, SOL_SOCKET, SO_RCVBUF,
+                       (char *)&arg, sizeof(arg)) < 0) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        strerror(errno));
+        return;
+    }
+#endif /* __APPLE__ */
+
      setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char*) &t, sizeof(int));
 
 #ifdef __linux__
@@ -1324,7 +1349,7 @@
          * value is an InetAddress.
          */
 #ifdef AF_INET6
-#ifdef __solaris__
+#if defined(__solaris__) || defined(MACOSX)
         if (ipv6_available()) {
             mcast_set_if_by_addr_v6(env, this, fd, value);
         } else {
@@ -1347,7 +1372,7 @@
          * value is a NetworkInterface.
          */
 #ifdef AF_INET6
-#ifdef __solaris__
+#if defined(__solaris__) || defined(MACOSX)
         if (ipv6_available()) {
             mcast_set_if_by_if_v6(env, this, fd, value);
         } else {
@@ -1430,7 +1455,7 @@
 static void setMulticastLoopbackMode(JNIEnv *env, jobject this, int fd,
                                   jint opt, jobject value) {
 #ifdef AF_INET6
-#ifdef __solaris__
+#if defined(__solaris__) || defined(MACOSX)
     if (ipv6_available()) {
         mcast_set_loop_v6(env, this, fd, value);
     } else {
@@ -2004,7 +2029,7 @@
     }
     /* setsockopt to be correct ttl */
 #ifdef AF_INET6
-#ifdef __solaris__
+#if defined(__solaris__) || defined(MACOSX)
     if (ipv6_available()) {
         setHopLimit(env, fd, ttl);
     } else {
@@ -2400,18 +2425,30 @@
             mname6.ipv6mr_interface = idx;
         }
 
+#if defined(_ALLBSD_SOURCE)
+#define ADD_MEMBERSHIP          IPV6_JOIN_GROUP
+#define DRP_MEMBERSHIP          IPV6_LEAVE_GROUP
+#define S_ADD_MEMBERSHIP        "IPV6_JOIN_GROUP"
+#define S_DRP_MEMBERSHIP        "IPV6_LEAVE_GROUP"
+#else
+#define ADD_MEMBERSHIP          IPV6_ADD_MEMBERSHIP
+#define DRP_MEMBERSHIP          IPV6_DROP_MEMBERSHIP
+#define S_ADD_MEMBERSHIP        "IPV6_ADD_MEMBERSHIP"
+#define S_DRP_MEMBERSHIP        "IPV6_DROP_MEMBERSHIP"
+#endif
+
         /* Join the multicast group */
-        if (JVM_SetSockOpt(fd, IPPROTO_IPV6, (join ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP),
+        if (JVM_SetSockOpt(fd, IPPROTO_IPV6, (join ? ADD_MEMBERSHIP : DRP_MEMBERSHIP),
                            (char *) &mname6, sizeof (mname6)) < 0) {
 
             if (join) {
-                NET_ThrowCurrent(env, "setsockopt IPV6_ADD_MEMBERSHIP failed");
+                NET_ThrowCurrent(env, "setsockopt " S_ADD_MEMBERSHIP " failed");
             } else {
                 if (errno == ENOENT) {
                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
                         "Not a member of the multicast group");
                 } else {
-                    NET_ThrowCurrent(env, "setsockopt IPV6_DROP_MEMBERSHIP failed");
+                    NET_ThrowCurrent(env, "setsockopt " S_DRP_MEMBERSHIP " failed");
                 }
             }
         }
diff --git a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c.orig b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c.orig
new file mode 100644
index 0000000..5ea0712
--- /dev/null
+++ b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c.orig
@@ -0,0 +1,2465 @@
+/*
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#ifdef __solaris__
+#include <fcntl.h>
+#endif
+#ifdef __linux__
+#include <unistd.h>
+#include <sys/sysctl.h>
+#include <sys/utsname.h>
+#include <netinet/ip.h>
+
+#define IPV6_MULTICAST_IF 17
+#ifndef SO_BSDCOMPAT
+#define SO_BSDCOMPAT  14
+#endif
+#endif
+
+#ifndef IPTOS_TOS_MASK
+#define IPTOS_TOS_MASK 0x1e
+#endif
+#ifndef IPTOS_PREC_MASK
+#define IPTOS_PREC_MASK 0xe0
+#endif
+
+#include "jvm.h"
+#include "jni_util.h"
+#include "net_util.h"
+
+#include "java_net_SocketOptions.h"
+#include "java_net_PlainDatagramSocketImpl.h"
+#include "java_net_NetworkInterface.h"
+/************************************************************************
+ * PlainDatagramSocketImpl
+ */
+
+static jfieldID IO_fd_fdID;
+
+static jfieldID pdsi_fdID;
+static jfieldID pdsi_timeoutID;
+static jfieldID pdsi_trafficClassID;
+static jfieldID pdsi_localPortID;
+static jfieldID pdsi_connected;
+static jfieldID pdsi_connectedAddress;
+static jfieldID pdsi_connectedPort;
+
+#ifdef __linux__
+static jboolean isOldKernel;
+#endif
+
+#if defined(__linux__) && defined(AF_INET6)
+static jfieldID pdsi_multicastInterfaceID;
+static jfieldID pdsi_loopbackID;
+static jfieldID pdsi_ttlID;
+#endif
+
+extern void setDefaultScopeID(JNIEnv *env, struct sockaddr *him);
+
+/*
+ * Returns a java.lang.Integer based on 'i'
+ */
+static jobject createInteger(JNIEnv *env, int i) {
+    static jclass i_class;
+    static jmethodID i_ctrID;
+
+    if (i_class == NULL) {
+        jclass c = (*env)->FindClass(env, "java/lang/Integer");
+        CHECK_NULL_RETURN(c, NULL);
+        i_ctrID = (*env)->GetMethodID(env, c, "<init>", "(I)V");
+        CHECK_NULL_RETURN(i_ctrID, NULL);
+        i_class = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL_RETURN(i_class, NULL);
+    }
+
+    return ( (*env)->NewObject(env, i_class, i_ctrID, i) );
+}
+
+/*
+ * Returns a java.lang.Boolean based on 'b'
+ */
+static jobject createBoolean(JNIEnv *env, int b) {
+    static jclass b_class;
+    static jmethodID b_ctrID;
+
+    if (b_class == NULL) {
+        jclass c = (*env)->FindClass(env, "java/lang/Boolean");
+        CHECK_NULL_RETURN(c, NULL);
+        b_ctrID = (*env)->GetMethodID(env, c, "<init>", "(Z)V");
+        CHECK_NULL_RETURN(b_ctrID, NULL);
+        b_class = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL_RETURN(b_class, NULL);
+    }
+
+    return( (*env)->NewObject(env, b_class, b_ctrID, (jboolean)(b!=0)) );
+}
+
+
+/*
+ * Returns the fd for a PlainDatagramSocketImpl or -1
+ * if closed.
+ */
+static int getFD(JNIEnv *env, jobject this) {
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    if (fdObj == NULL) {
+        return -1;
+    }
+    return (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+}
+
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    init
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) {
+
+#ifdef __linux__
+    struct utsname sysinfo;
+#endif
+    pdsi_fdID = (*env)->GetFieldID(env, cls, "fd",
+                                   "Ljava/io/FileDescriptor;");
+    CHECK_NULL(pdsi_fdID);
+    pdsi_timeoutID = (*env)->GetFieldID(env, cls, "timeout", "I");
+    CHECK_NULL(pdsi_timeoutID);
+    pdsi_trafficClassID = (*env)->GetFieldID(env, cls, "trafficClass", "I");
+    CHECK_NULL(pdsi_trafficClassID);
+    pdsi_localPortID = (*env)->GetFieldID(env, cls, "localPort", "I");
+    CHECK_NULL(pdsi_localPortID);
+    pdsi_connected = (*env)->GetFieldID(env, cls, "connected", "Z");
+    CHECK_NULL(pdsi_connected);
+    pdsi_connectedAddress = (*env)->GetFieldID(env, cls, "connectedAddress",
+                                               "Ljava/net/InetAddress;");
+    CHECK_NULL(pdsi_connectedAddress);
+    pdsi_connectedPort = (*env)->GetFieldID(env, cls, "connectedPort", "I");
+    CHECK_NULL(pdsi_connectedPort);
+
+    IO_fd_fdID = NET_GetFileDescriptorID(env);
+    CHECK_NULL(IO_fd_fdID);
+
+    Java_java_net_InetAddress_init(env, 0);
+    Java_java_net_Inet4Address_init(env, 0);
+    Java_java_net_Inet6Address_init(env, 0);
+    Java_java_net_NetworkInterface_init(env, 0);
+
+#ifdef __linux__
+    /*
+     * We need to determine if this is a 2.2 kernel.
+     */
+    if (uname(&sysinfo) == 0) {
+        sysinfo.release[3] = '\0';
+        isOldKernel = (strcmp(sysinfo.release, "2.2") == 0);
+    } else {
+        /*
+         * uname failed - move to plan B and examine /proc/version
+         * If this fails assume that /proc has changed and that
+         * this must be new /proc format and hence new kernel.
+         */
+        FILE *fP;
+        isOldKernel = JNI_FALSE;
+        if ((fP = fopen("/proc/version", "r")) != NULL) {
+            char ver[25];
+            if (fgets(ver, sizeof(ver), fP) != NULL) {
+                isOldKernel = (strstr(ver, "2.2.") != NULL);
+            }
+            fclose(fP);
+        }
+    }
+
+#ifdef AF_INET6
+    pdsi_multicastInterfaceID = (*env)->GetFieldID(env, cls, "multicastInterface", "I");
+    CHECK_NULL(pdsi_multicastInterfaceID);
+    pdsi_loopbackID = (*env)->GetFieldID(env, cls, "loopbackMode", "Z");
+    CHECK_NULL(pdsi_loopbackID);
+    pdsi_ttlID = (*env)->GetFieldID(env, cls, "ttl", "I");
+    CHECK_NULL(pdsi_ttlID);
+#endif
+
+#endif
+
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    bind
+ * Signature: (ILjava/net/InetAddress;)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
+                                           jint localport, jobject iaObj) {
+    /* fdObj is the FileDescriptor field on this */
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    /* fd is an int field on fdObj */
+    int fd;
+    int len = 0;
+    SOCKADDR him;
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    } else {
+        fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    }
+
+    if (IS_NULL(iaObj)) {
+        JNU_ThrowNullPointerException(env, "iaObj is null.");
+        return;
+    }
+
+    /* bind */
+    if (NET_InetAddressToSockaddr(env, iaObj, localport, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
+      return;
+    }
+    setDefaultScopeID(env, (struct sockaddr *)&him);
+
+    if (NET_Bind(fd, (struct sockaddr *)&him, len) < 0)  {
+        if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
+            errno == EPERM || errno == EACCES) {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
+                            "Bind failed");
+        } else {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                            "Bind failed");
+        }
+        return;
+    }
+
+    /* intialize the local port */
+    if (localport == 0) {
+        /* Now that we're a connected socket, let's extract the port number
+         * that the system chose for us and store it in the Socket object.
+         */
+        if (JVM_GetSockName(fd, (struct sockaddr *)&him, &len) == -1) {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                            "Error getting socket name");
+            return;
+        }
+
+        localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
+
+        (*env)->SetIntField(env, this, pdsi_localPortID, localport);
+    } else {
+        (*env)->SetIntField(env, this, pdsi_localPortID, localport);
+    }
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    connect0
+ * Signature: (Ljava/net/InetAddress;I)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_connect0(JNIEnv *env, jobject this,
+                                               jobject address, jint port) {
+    /* The object's field */
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    /* The fdObj'fd */
+    jint fd;
+    /* The packetAddress address, family and port */
+    SOCKADDR rmtaddr;
+    int len = 0;
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    }
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+
+    if (IS_NULL(address)) {
+        JNU_ThrowNullPointerException(env, "address");
+        return;
+    }
+
+    if (NET_InetAddressToSockaddr(env, address, port, (struct sockaddr *)&rmtaddr, &len, JNI_TRUE) != 0) {
+      return;
+    }
+
+#ifdef __linux__
+    if (isOldKernel) {
+        int t = 0;
+        setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int));
+    } else
+#endif
+    setDefaultScopeID(env, (struct sockaddr *)&rmtaddr);
+    {
+        if (JVM_Connect(fd, (struct sockaddr *)&rmtaddr, len) == -1) {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
+                            "Connect failed");
+            return;
+        }
+    }
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    disconnect0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject this, jint family) {
+    /* The object's field */
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    /* The fdObj'fd */
+    jint fd;
+
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+    SOCKADDR addr;
+    int len;
+#endif
+
+    if (IS_NULL(fdObj)) {
+        return;
+    }
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+#ifdef __linux__
+    if (isOldKernel) {
+        int t = 1;
+        setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int));
+    } else {
+#endif /* __linux__ */
+        memset(&addr, 0, sizeof(addr));
+#ifdef AF_INET6
+        if (ipv6_available()) {
+            struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)&addr;
+            him6->sin6_family = AF_UNSPEC;
+            len = sizeof(struct sockaddr_in6);
+        } else
+#endif
+        {
+            struct sockaddr_in *him4 = (struct sockaddr_in*)&addr;
+            him4->sin_family = AF_UNSPEC;
+            len = sizeof(struct sockaddr_in);
+        }
+        JVM_Connect(fd, (struct sockaddr *)&addr, len);
+
+#ifdef __linux__
+        // After disconnecting a UDP socket, Linux kernel will set
+        // local port to zero if the port number comes from implicit
+        // bind. Successive send/recv on the same socket will fail.
+        // So bind again with former port number here.
+        int localPort = 0;
+        if (JVM_GetSockName(fd, (struct sockaddr *)&addr, &len) == -1) {
+            return;
+        }
+        localPort = NET_GetPortFromSockaddr((struct sockaddr *)&addr);
+        if (localPort == 0) {
+            localPort = (*env)->GetIntField(env, this, pdsi_localPortID);
+#ifdef AF_INET6
+            if (((struct sockaddr*)&addr)->sa_family == AF_INET6) {
+                ((struct sockaddr_in6*)&addr)->sin6_port = htons(localPort);
+            } else
+#endif /* AF_INET6 */
+            {
+                ((struct sockaddr_in*)&addr)->sin_port = htons(localPort);
+            }
+            NET_Bind(fd, (struct sockaddr *)&addr, len);
+        }
+    }
+#endif
+#else
+    JVM_Connect(fd, 0, 0);
+#endif
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    send
+ * Signature: (Ljava/net/DatagramPacket;)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
+                                           jobject packet) {
+
+    char BUF[MAX_BUFFER_LEN];
+    char *fullPacket = NULL;
+    int ret, mallocedPacket = JNI_FALSE;
+    /* The object's field */
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    jint trafficClass = (*env)->GetIntField(env, this, pdsi_trafficClassID);
+
+    jbyteArray packetBuffer;
+    jobject packetAddress;
+    jint packetBufferOffset, packetBufferLen, packetPort;
+    jboolean connected;
+
+    /* The fdObj'fd */
+    jint fd;
+
+    SOCKADDR rmtaddr, *rmtaddrP=&rmtaddr;
+    int len;
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    }
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+
+    if (IS_NULL(packet)) {
+        JNU_ThrowNullPointerException(env, "packet");
+        return;
+    }
+
+    connected = (*env)->GetBooleanField(env, this, pdsi_connected);
+
+    packetBuffer = (*env)->GetObjectField(env, packet, dp_bufID);
+    packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
+    if (IS_NULL(packetBuffer) || IS_NULL(packetAddress)) {
+        JNU_ThrowNullPointerException(env, "null buffer || null address");
+        return;
+    }
+
+    packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID);
+    packetBufferLen = (*env)->GetIntField(env, packet, dp_lengthID);
+
+#ifdef __linux__
+    if (connected && !isOldKernel) {
+#else
+    if (connected) {
+#endif
+        /* arg to NET_Sendto () null in this case */
+        len = 0;
+        rmtaddrP = 0;
+    } else {
+        packetPort = (*env)->GetIntField(env, packet, dp_portID);
+        if (NET_InetAddressToSockaddr(env, packetAddress, packetPort, (struct sockaddr *)&rmtaddr, &len, JNI_TRUE) != 0) {
+          return;
+        }
+    }
+    setDefaultScopeID(env, (struct sockaddr *)&rmtaddr);
+
+    if (packetBufferLen > MAX_BUFFER_LEN) {
+        /* When JNI-ifying the JDK's IO routines, we turned
+         * read's and write's of byte arrays of size greater
+         * than 2048 bytes into several operations of size 2048.
+         * This saves a malloc()/memcpy()/free() for big
+         * buffers.  This is OK for file IO and TCP, but that
+         * strategy violates the semantics of a datagram protocol.
+         * (one big send) != (several smaller sends).  So here
+         * we *must* alloc the buffer.  Note it needn't be bigger
+         * than 65,536 (0xFFFF) the max size of an IP packet.
+         * Anything bigger should be truncated anyway.
+         *
+         * We may want to use a smarter allocation scheme at some
+         * point.
+         */
+        if (packetBufferLen > MAX_PACKET_LEN) {
+            packetBufferLen = MAX_PACKET_LEN;
+        }
+        fullPacket = (char *)malloc(packetBufferLen);
+
+        if (!fullPacket) {
+            JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
+            return;
+        } else {
+            mallocedPacket = JNI_TRUE;
+        }
+    } else {
+        fullPacket = &(BUF[0]);
+    }
+
+    (*env)->GetByteArrayRegion(env, packetBuffer, packetBufferOffset, packetBufferLen,
+                               (jbyte *)fullPacket);
+#ifdef AF_INET6
+    if (trafficClass != 0 && ipv6_available()) {
+        NET_SetTrafficClass((struct sockaddr *)&rmtaddr, trafficClass);
+    }
+#endif /* AF_INET6 */
+
+
+    /*
+     * Send the datagram.
+     *
+     * If we are connected it's possible that sendto will return
+     * ECONNREFUSED indicating that an ICMP port unreachable has
+     * received.
+     */
+    ret = NET_SendTo(fd, fullPacket, packetBufferLen, 0,
+                     (struct sockaddr *)rmtaddrP, len);
+
+    if (ret < 0) {
+        switch (ret) {
+            case JVM_IO_ERR :
+                if (errno == ECONNREFUSED) {
+                    JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
+                            "ICMP Port Unreachable");
+                } else {
+                    NET_ThrowByNameWithLastError(env, "java/io/IOException", "sendto failed");
+                }
+                break;
+
+            case JVM_IO_INTR:
+                JNU_ThrowByName(env, "java/io/InterruptedIOException",
+                                "operation interrupted");
+                break;
+        }
+    }
+
+    if (mallocedPacket) {
+        free(fullPacket);
+    }
+    return;
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    peek
+ * Signature: (Ljava/net/InetAddress;)I
+ */
+JNIEXPORT jint JNICALL
+Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
+                                           jobject addressObj) {
+
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    jint timeout = (*env)->GetIntField(env, this, pdsi_timeoutID);
+    jint fd;
+    ssize_t n;
+    SOCKADDR remote_addr;
+    int len;
+    char buf[1];
+    jint family;
+    jobject iaObj;
+    int port;
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+        return -1;
+    } else {
+        fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    }
+    if (IS_NULL(addressObj)) {
+        JNU_ThrowNullPointerException(env, "Null address in peek()");
+    }
+    if (timeout) {
+        int ret = NET_Timeout(fd, timeout);
+        if (ret == 0) {
+            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                            "Peek timed out");
+            return ret;
+        } else if (ret == JVM_IO_ERR) {
+            if (errno == EBADF) {
+                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+            } else {
+                 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Peek failed");
+            }
+            return ret;
+        } else if (ret == JVM_IO_INTR) {
+            JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
+                            "operation interrupted");
+            return ret; /* WARNING: SHOULD WE REALLY RETURN -2??? */
+        }
+    }
+
+    len = SOCKADDR_LEN;
+    n = NET_RecvFrom(fd, buf, 1, MSG_PEEK,
+                     (struct sockaddr *)&remote_addr, &len);
+
+    if (n == JVM_IO_ERR) {
+
+#ifdef __solaris__
+        if (errno == ECONNREFUSED) {
+            int orig_errno = errno;
+            (void) recv(fd, buf, 1, 0);
+            errno = orig_errno;
+        }
+#endif
+        if (errno == ECONNREFUSED) {
+            JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
+                            "ICMP Port Unreachable");
+        } else {
+            if (errno == EBADF) {
+                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+            } else {
+                 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Peek failed");
+            }
+        }
+        return 0;
+    } else if (n == JVM_IO_INTR) {
+        JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
+        return 0;
+    }
+
+    iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
+#ifdef AF_INET6
+    family = (*env)->GetIntField(env, iaObj, ia_familyID) == IPv4?
+        AF_INET : AF_INET6;
+#else
+    family = AF_INET;
+#endif
+    if (family == AF_INET) { /* this api can't handle IPV6 addresses */
+        int address = (*env)->GetIntField(env, iaObj, ia_addressID);
+        (*env)->SetIntField(env, addressObj, ia_addressID, address);
+    }
+    return port;
+}
+
+JNIEXPORT jint JNICALL
+Java_java_net_PlainDatagramSocketImpl_peekData(JNIEnv *env, jobject this,
+                                           jobject packet) {
+
+    char BUF[MAX_BUFFER_LEN];
+    char *fullPacket = NULL;
+    int mallocedPacket = JNI_FALSE;
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    jint timeout = (*env)->GetIntField(env, this, pdsi_timeoutID);
+
+    jbyteArray packetBuffer;
+    jint packetBufferOffset, packetBufferLen;
+
+    int fd;
+
+    int n;
+    SOCKADDR remote_addr;
+    int len;
+    int port;
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return -1;
+    }
+
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+
+    if (IS_NULL(packet)) {
+        JNU_ThrowNullPointerException(env, "packet");
+        return -1;
+    }
+
+    packetBuffer = (*env)->GetObjectField(env, packet, dp_bufID);
+    if (IS_NULL(packetBuffer)) {
+        JNU_ThrowNullPointerException(env, "packet buffer");
+        return -1;
+    }
+    packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID);
+    packetBufferLen = (*env)->GetIntField(env, packet, dp_bufLengthID);
+    if (timeout) {
+        int ret = NET_Timeout(fd, timeout);
+        if (ret == 0) {
+            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                            "Receive timed out");
+            return -1;
+        } else if (ret == JVM_IO_ERR) {
+#ifdef __linux__
+            if (errno == EBADF) {
+                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+            } else {
+                NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
+            }
+#else
+            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+#endif
+            return -1;
+        } else if (ret == JVM_IO_INTR) {
+            JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
+                            "operation interrupted");
+            return -1;
+        }
+    }
+
+    if (packetBufferLen > MAX_BUFFER_LEN) {
+
+        /* When JNI-ifying the JDK's IO routines, we turned
+         * read's and write's of byte arrays of size greater
+         * than 2048 bytes into several operations of size 2048.
+         * This saves a malloc()/memcpy()/free() for big
+         * buffers.  This is OK for file IO and TCP, but that
+         * strategy violates the semantics of a datagram protocol.
+         * (one big send) != (several smaller sends).  So here
+         * we *must* alloc the buffer.  Note it needn't be bigger
+         * than 65,536 (0xFFFF) the max size of an IP packet.
+         * anything bigger is truncated anyway.
+         *
+         * We may want to use a smarter allocation scheme at some
+         * point.
+         */
+        if (packetBufferLen > MAX_PACKET_LEN) {
+            packetBufferLen = MAX_PACKET_LEN;
+        }
+        fullPacket = (char *)malloc(packetBufferLen);
+
+        if (!fullPacket) {
+            JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
+            return -1;
+        } else {
+            mallocedPacket = JNI_TRUE;
+        }
+    } else {
+        fullPacket = &(BUF[0]);
+    }
+
+    len = SOCKADDR_LEN;
+    n = NET_RecvFrom(fd, fullPacket, packetBufferLen, MSG_PEEK,
+                     (struct sockaddr *)&remote_addr, &len);
+    /* truncate the data if the packet's length is too small */
+    if (n > packetBufferLen) {
+        n = packetBufferLen;
+    }
+    if (n == JVM_IO_ERR) {
+
+#ifdef __solaris__
+        if (errno == ECONNREFUSED) {
+            int orig_errno = errno;
+            (void) recv(fd, fullPacket, 1, 0);
+            errno = orig_errno;
+        }
+#endif
+        (*env)->SetIntField(env, packet, dp_offsetID, 0);
+        (*env)->SetIntField(env, packet, dp_lengthID, 0);
+        if (errno == ECONNREFUSED) {
+            JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
+                            "ICMP Port Unreachable");
+        } else {
+            if (errno == EBADF) {
+                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+            } else {
+                 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
+            }
+        }
+    } else if (n == JVM_IO_INTR) {
+        (*env)->SetIntField(env, packet, dp_offsetID, 0);
+        (*env)->SetIntField(env, packet, dp_lengthID, 0);
+        JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
+                        "operation interrupted");
+    } else {
+        /*
+         * success - fill in received address...
+         *
+         * REMIND: Fill in an int on the packet, and create inetadd
+         * object in Java, as a performance improvement. Also
+         * construct the inetadd object lazily.
+         */
+
+        jobject packetAddress;
+
+        /*
+         * Check if there is an InetAddress already associated with this
+         * packet. If so we check if it is the same source address. We
+         * can't update any existing InetAddress because it is immutable
+         */
+        packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
+        if (packetAddress != NULL) {
+            if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&remote_addr, packetAddress)) {
+                /* force a new InetAddress to be created */
+                packetAddress = NULL;
+            }
+        }
+        if (packetAddress == NULL) {
+            packetAddress = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
+            /* stuff the new Inetaddress in the packet */
+            (*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
+        } else {
+            /* only get the new port number */
+            port = NET_GetPortFromSockaddr((struct sockaddr *)&remote_addr);
+        }
+        /* and fill in the data, remote address/port and such */
+        (*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
+                                   (jbyte *)fullPacket);
+        (*env)->SetIntField(env, packet, dp_portID, port);
+        (*env)->SetIntField(env, packet, dp_lengthID, n);
+    }
+
+    if (mallocedPacket) {
+        free(fullPacket);
+    }
+    return port;
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    receive
+ * Signature: (Ljava/net/DatagramPacket;)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this,
+                                              jobject packet) {
+
+    char BUF[MAX_BUFFER_LEN];
+    char *fullPacket = NULL;
+    int mallocedPacket = JNI_FALSE;
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    jint timeout = (*env)->GetIntField(env, this, pdsi_timeoutID);
+
+    jbyteArray packetBuffer;
+    jint packetBufferOffset, packetBufferLen;
+
+    int fd;
+
+    int n;
+    SOCKADDR remote_addr;
+    int len;
+    jboolean retry;
+#ifdef __linux__
+    jboolean connected = JNI_FALSE;
+    jobject connectedAddress = NULL;
+    jint connectedPort = 0;
+    jlong prevTime = 0;
+#endif
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    }
+
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+
+    if (IS_NULL(packet)) {
+        JNU_ThrowNullPointerException(env, "packet");
+        return;
+    }
+
+    packetBuffer = (*env)->GetObjectField(env, packet, dp_bufID);
+    if (IS_NULL(packetBuffer)) {
+        JNU_ThrowNullPointerException(env, "packet buffer");
+        return;
+    }
+    packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID);
+    packetBufferLen = (*env)->GetIntField(env, packet, dp_bufLengthID);
+
+    if (packetBufferLen > MAX_BUFFER_LEN) {
+
+        /* When JNI-ifying the JDK's IO routines, we turned
+         * read's and write's of byte arrays of size greater
+         * than 2048 bytes into several operations of size 2048.
+         * This saves a malloc()/memcpy()/free() for big
+         * buffers.  This is OK for file IO and TCP, but that
+         * strategy violates the semantics of a datagram protocol.
+         * (one big send) != (several smaller sends).  So here
+         * we *must* alloc the buffer.  Note it needn't be bigger
+         * than 65,536 (0xFFFF) the max size of an IP packet.
+         * anything bigger is truncated anyway.
+         *
+         * We may want to use a smarter allocation scheme at some
+         * point.
+         */
+        if (packetBufferLen > MAX_PACKET_LEN) {
+            packetBufferLen = MAX_PACKET_LEN;
+        }
+        fullPacket = (char *)malloc(packetBufferLen);
+
+        if (!fullPacket) {
+            JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
+            return;
+        } else {
+            mallocedPacket = JNI_TRUE;
+        }
+    } else {
+        fullPacket = &(BUF[0]);
+    }
+
+#ifdef __linux__
+    /*
+     * On Linux with the 2.2 kernel we simulate connected datagrams by
+     * discarding packets
+     */
+    if (isOldKernel) {
+        connected = (*env)->GetBooleanField(env, this, pdsi_connected);
+        if (connected) {
+            connectedAddress = (*env)->GetObjectField(env, this, pdsi_connectedAddress);
+            connectedPort = (*env)->GetIntField(env, this, pdsi_connectedPort);
+
+            if (timeout) {
+                prevTime = JVM_CurrentTimeMillis(env, 0);
+            }
+        }
+    }
+#endif
+
+    do {
+        retry = JNI_FALSE;
+
+        if (timeout) {
+            int ret = NET_Timeout(fd, timeout);
+            if (ret <= 0) {
+                if (ret == 0) {
+                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                                    "Receive timed out");
+                } else if (ret == JVM_IO_ERR) {
+#ifdef __linux__
+                    if (errno == EBADF) {
+                         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+                     } else {
+                         NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
+                     }
+#else
+                     JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+#endif
+                } else if (ret == JVM_IO_INTR) {
+                    JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
+                                    "operation interrupted");
+                }
+
+                if (mallocedPacket) {
+                    free(fullPacket);
+                }
+
+                return;
+            }
+        }
+
+        /*
+         * Security Note: For Linux 2.2 with connected datagrams ensure that
+         * you receive into the stack/heap allocated buffer - do not attempt
+         * to receive directly into DatagramPacket's byte array.
+         * (ie: if the virtual machine support pinning don't use
+         * GetByteArrayElements or a JNI critical section and receive
+         * directly into the byte array)
+         */
+        len = SOCKADDR_LEN;
+        n = NET_RecvFrom(fd, fullPacket, packetBufferLen, 0,
+                         (struct sockaddr *)&remote_addr, &len);
+        /* truncate the data if the packet's length is too small */
+        if (n > packetBufferLen) {
+            n = packetBufferLen;
+        }
+        if (n == JVM_IO_ERR) {
+            (*env)->SetIntField(env, packet, dp_offsetID, 0);
+            (*env)->SetIntField(env, packet, dp_lengthID, 0);
+            if (errno == ECONNREFUSED) {
+                JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
+                                "ICMP Port Unreachable");
+            } else {
+                if (errno == EBADF) {
+                     JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+                 } else {
+                     NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
+                 }
+            }
+        } else if (n == JVM_IO_INTR) {
+            (*env)->SetIntField(env, packet, dp_offsetID, 0);
+            (*env)->SetIntField(env, packet, dp_lengthID, 0);
+            JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
+                            "operation interrupted");
+        } else {
+            int port;
+            jobject packetAddress;
+
+            /*
+             * If we are connected then we know that the datagram that we have
+             * received is from the address that we are connected too. However
+             * on Linux with 2.2 kernel we have to simulate this behaviour by
+             * discarding any datagrams that aren't from the connected address.
+             */
+#ifdef __linux__
+            if (isOldKernel && connected) {
+
+                if (NET_GetPortFromSockaddr((struct sockaddr *)&remote_addr) != connectedPort ||
+                    !NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&remote_addr, connectedAddress)) {
+
+                    /*
+                     * Discard the datagram as it's not from the connected
+                     * address
+                     */
+                    retry = JNI_TRUE;
+
+                    /*
+                     * Adjust timeout if necessary to ensure that we adhere to
+                     * timeout semantics.
+                     */
+                    if (timeout) {
+                        jlong newTime = JVM_CurrentTimeMillis(env, 0);
+                        timeout -= (newTime - prevTime);
+                        if (timeout <= 0) {
+                            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                                    "Receive timed out");
+                            if (mallocedPacket) {
+                                free(fullPacket);
+                            }
+                            return;
+                        }
+                        prevTime = newTime;
+                    }
+
+                    continue;
+                }
+            }
+#endif
+
+            /*
+             * success - fill in received address...
+             *
+             * REMIND: Fill in an int on the packet, and create inetadd
+             * object in Java, as a performance improvement. Also
+             * construct the inetadd object lazily.
+             */
+
+            /*
+             * Check if there is an InetAddress already associated with this
+             * packet. If so we check if it is the same source address. We
+             * can't update any existing InetAddress because it is immutable
+             */
+            packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
+            if (packetAddress != NULL) {
+                if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&remote_addr, packetAddress)) {
+                    /* force a new InetAddress to be created */
+                    packetAddress = NULL;
+                }
+            }
+            if (packetAddress == NULL) {
+                packetAddress = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
+                /* stuff the new Inetaddress in the packet */
+                (*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
+            } else {
+                /* only get the new port number */
+                port = NET_GetPortFromSockaddr((struct sockaddr *)&remote_addr);
+            }
+            /* and fill in the data, remote address/port and such */
+            (*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
+                                       (jbyte *)fullPacket);
+            (*env)->SetIntField(env, packet, dp_portID, port);
+            (*env)->SetIntField(env, packet, dp_lengthID, n);
+        }
+
+    } while (retry);
+
+    if (mallocedPacket) {
+        free(fullPacket);
+    }
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    datagramSocketCreate
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
+                                                           jobject this) {
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    int fd, t = 1;
+#ifdef AF_INET6
+    int domain = ipv6_available() ? AF_INET6 : AF_INET;
+#else
+    int domain = AF_INET;
+#endif
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    }
+
+    if ((fd = JVM_Socket(domain, SOCK_DGRAM, 0)) == JVM_IO_ERR) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                       "Error creating socket");
+        return;
+    }
+
+#ifdef AF_INET6
+    /* Disable IPV6_V6ONLY to ensure dual-socket support */
+    if (domain == AF_INET6) {
+        int arg = 0;
+        if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
+                       sizeof(int)) < 0) {
+            NET_ThrowNew(env, errno, "cannot set IPPROTO_IPV6");
+            close(fd);
+            return;
+        }
+    }
+#endif /* AF_INET6 */
+
+     setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char*) &t, sizeof(int));
+
+#ifdef __linux__
+    if (isOldKernel) {
+        setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int));
+    }
+
+#ifdef AF_INET6
+    /*
+     * On Linux for IPv6 sockets we must set the hop limit
+     * to 1 to be compatible with default ttl of 1 for IPv4 sockets.
+     */
+    if (domain == AF_INET6) {
+        int ttl = 1;
+        setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&ttl,
+                   sizeof(ttl));
+
+        if (isOldKernel) {
+            (*env)->SetIntField(env, this, pdsi_ttlID, ttl);
+        }
+    }
+#endif
+
+#endif /* __linux__ */
+
+    (*env)->SetIntField(env, fdObj, IO_fd_fdID, fd);
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    datagramSocketClose
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_datagramSocketClose(JNIEnv *env,
+                                                          jobject this) {
+    /*
+     * REMIND: PUT A LOCK AROUND THIS CODE
+     */
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    int fd;
+
+    if (IS_NULL(fdObj)) {
+        return;
+    }
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    if (fd == -1) {
+        return;
+    }
+    (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1);
+    NET_SocketClose(fd);
+}
+
+
+/*
+ * Set outgoing multicast interface designated by a NetworkInterface.
+ * Throw exception if failed.
+ */
+static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject value) {
+    static jfieldID ni_addrsID;
+    static jfieldID ia_addressID;
+    struct in_addr in;
+    jobjectArray addrArray;
+    jsize len;
+    jobject addr;
+    int i;
+
+    if (ni_addrsID == NULL || ia_addressID == NULL) {
+        jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+        CHECK_NULL(c);
+        ni_addrsID = (*env)->GetFieldID(env, c, "addrs",
+                                        "[Ljava/net/InetAddress;");
+        CHECK_NULL(ni_addrsID);
+        c = (*env)->FindClass(env,"java/net/InetAddress");
+        CHECK_NULL(c);
+        ia_addressID = (*env)->GetFieldID(env, c, "address", "I");
+        CHECK_NULL(ia_addressID);
+    }
+
+    addrArray = (*env)->GetObjectField(env, value, ni_addrsID);
+    len = (*env)->GetArrayLength(env, addrArray);
+
+    /*
+     * Check that there is at least one address bound to this
+     * interface.
+     */
+    if (len < 1) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+            "bad argument for IP_MULTICAST_IF2: No IP addresses bound to interface");
+        return;
+    }
+
+    /*
+     * We need an ipv4 address here
+     */
+    for (i = 0; i < len; i++) {
+        addr = (*env)->GetObjectArrayElement(env, addrArray, i);
+        if ((*env)->GetIntField(env, addr, ia_familyID) == IPv4) {
+            in.s_addr = htonl((*env)->GetIntField(env, addr, ia_addressID));
+            break;
+        }
+    }
+
+    if (JVM_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_IF,
+                       (const char*)&in, sizeof(in)) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                       "Error setting socket option");
+    }
+}
+
+/*
+ * Set outgoing multicast interface designated by a NetworkInterface.
+ * Throw exception if failed.
+ */
+#ifdef AF_INET6
+static void mcast_set_if_by_if_v6(JNIEnv *env, jobject this, int fd, jobject value) {
+    static jfieldID ni_indexID;
+    int index;
+
+    if (ni_indexID == NULL) {
+        jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+        CHECK_NULL(c);
+        ni_indexID = (*env)->GetFieldID(env, c, "index", "I");
+        CHECK_NULL(ni_indexID);
+    }
+    index = (*env)->GetIntField(env, value, ni_indexID);
+
+    if (JVM_SetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
+                       (const char*)&index, sizeof(index)) < 0) {
+        if (errno == EINVAL && index > 0) {
+            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                "IPV6_MULTICAST_IF failed (interface has IPv4 "
+                "address only?)");
+        } else {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                           "Error setting socket option");
+        }
+        return;
+    }
+
+#ifdef __linux__
+    /*
+     * Linux 2.2 kernel doesn't support IPV6_MULTICAST_IF socket
+     * option so record index for later retrival.
+     */
+    if (isOldKernel) {
+        (*env)->SetIntField(env, this, pdsi_multicastInterfaceID,
+                            (jint)index);
+    }
+#endif
+}
+#endif /* AF_INET6 */
+
+/*
+ * Set outgoing multicast interface designated by an InetAddress.
+ * Throw exception if failed.
+ */
+static void mcast_set_if_by_addr_v4(JNIEnv *env, jobject this, int fd, jobject value) {
+    static jfieldID ia_addressID;
+    struct in_addr in;
+
+    if (ia_addressID == NULL) {
+        jclass c = (*env)->FindClass(env,"java/net/InetAddress");
+        CHECK_NULL(c);
+        ia_addressID = (*env)->GetFieldID(env, c, "address", "I");
+        CHECK_NULL(ia_addressID);
+    }
+
+    in.s_addr = htonl( (*env)->GetIntField(env, value, ia_addressID) );
+
+    if (JVM_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_IF,
+                       (const char*)&in, sizeof(in)) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                         "Error setting socket option");
+    }
+}
+
+/*
+ * Set outgoing multicast interface designated by an InetAddress.
+ * Throw exception if failed.
+ */
+#ifdef AF_INET6
+static void mcast_set_if_by_addr_v6(JNIEnv *env, jobject this, int fd, jobject value) {
+    static jclass ni_class;
+    if (ni_class == NULL) {
+        jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+        CHECK_NULL(c);
+        ni_class = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL(ni_class);
+    }
+
+    value = Java_java_net_NetworkInterface_getByInetAddress0(env, ni_class, value);
+    if (value == NULL) {
+        if (!(*env)->ExceptionOccurred(env)) {
+            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                 "bad argument for IP_MULTICAST_IF"
+                 ": address not bound to any interface");
+        }
+        return;
+    }
+
+    mcast_set_if_by_if_v6(env, this, fd, value);
+}
+#endif
+
+/*
+ * Sets the multicast interface.
+ *
+ * SocketOptions.IP_MULTICAST_IF :-
+ *      value is a InetAddress
+ *      IPv4:   set outgoing multicast interface using
+ *              IPPROTO_IP/IP_MULTICAST_IF
+ *      IPv6:   Get the index of the interface to which the
+ *              InetAddress is bound
+ *              Set outgoing multicast interface using
+ *              IPPROTO_IPV6/IPV6_MULTICAST_IF
+ *              On Linux 2.2 record interface index as can't
+ *              query the multicast interface.
+ *
+ * SockOptions.IF_MULTICAST_IF2 :-
+ *      value is a NetworkInterface
+ *      IPv4:   Obtain IP address bound to network interface
+ *              (NetworkInterface.addres[0])
+ *              set outgoing multicast interface using
+ *              IPPROTO_IP/IP_MULTICAST_IF
+ *      IPv6:   Obtain NetworkInterface.index
+ *              Set outgoing multicast interface using
+ *              IPPROTO_IPV6/IPV6_MULTICAST_IF
+ *              On Linux 2.2 record interface index as can't
+ *              query the multicast interface.
+ *
+ */
+static void setMulticastInterface(JNIEnv *env, jobject this, int fd,
+                                  jint opt, jobject value)
+{
+    if (opt == java_net_SocketOptions_IP_MULTICAST_IF) {
+        /*
+         * value is an InetAddress.
+         */
+#ifdef AF_INET6
+#if defined(__solaris__) || defined(MACOSX)
+        if (ipv6_available()) {
+            mcast_set_if_by_addr_v6(env, this, fd, value);
+        } else {
+            mcast_set_if_by_addr_v4(env, this, fd, value);
+        }
+#endif
+#ifdef __linux__
+        mcast_set_if_by_addr_v4(env, this, fd, value);
+        if (ipv6_available()) {
+            mcast_set_if_by_addr_v6(env, this, fd, value);
+        }
+#endif
+#else
+        mcast_set_if_by_addr_v4(env, this, fd, value);
+#endif  /* AF_INET6 */
+    }
+
+    if (opt == java_net_SocketOptions_IP_MULTICAST_IF2) {
+        /*
+         * value is a NetworkInterface.
+         */
+#ifdef AF_INET6
+#if defined(__solaris__) || defined(MACOSX)
+        if (ipv6_available()) {
+            mcast_set_if_by_if_v6(env, this, fd, value);
+        } else {
+            mcast_set_if_by_if_v4(env, this, fd, value);
+        }
+#endif
+#ifdef __linux__
+        mcast_set_if_by_if_v4(env, this, fd, value);
+        if (ipv6_available()) {
+            mcast_set_if_by_if_v6(env, this, fd, value);
+        }
+#endif
+#else
+        mcast_set_if_by_if_v4(env, this, fd, value);
+#endif  /* AF_INET6 */
+    }
+}
+
+/*
+ * Enable/disable local loopback of multicast datagrams.
+ */
+static void mcast_set_loop_v4(JNIEnv *env, jobject this, int fd, jobject value) {
+    jclass cls;
+    jfieldID fid;
+    jboolean on;
+    char loopback;
+
+    cls = (*env)->FindClass(env, "java/lang/Boolean");
+    CHECK_NULL(cls);
+    fid =  (*env)->GetFieldID(env, cls, "value", "Z");
+    CHECK_NULL(fid);
+
+    on = (*env)->GetBooleanField(env, value, fid);
+    loopback = (!on ? 1 : 0);
+
+    if (NET_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&loopback, sizeof(char)) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Error setting socket option");
+        return;
+    }
+}
+
+/*
+ * Enable/disable local loopback of multicast datagrams.
+ */
+#ifdef AF_INET6
+static void mcast_set_loop_v6(JNIEnv *env, jobject this, int fd, jobject value) {
+    jclass cls;
+    jfieldID fid;
+    jboolean on;
+    int loopback;
+
+    cls = (*env)->FindClass(env, "java/lang/Boolean");
+    CHECK_NULL(cls);
+    fid =  (*env)->GetFieldID(env, cls, "value", "Z");
+    CHECK_NULL(fid);
+
+    on = (*env)->GetBooleanField(env, value, fid);
+    loopback = (!on ? 1 : 0);
+
+    if (NET_SetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&loopback, sizeof(int)) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Error setting socket option");
+        return;
+    }
+
+#ifdef __linux__
+    /*
+     * Can't query IPV6_MULTICAST_LOOP on Linux 2.2 kernel so
+     * store it in impl so that we can simulate getsockopt.
+     */
+    if (isOldKernel) {
+        (*env)->SetBooleanField(env, this, pdsi_loopbackID, on);
+    }
+#endif
+}
+#endif  /* AF_INET6 */
+
+/*
+ * Sets the multicast loopback mode.
+ */
+static void setMulticastLoopbackMode(JNIEnv *env, jobject this, int fd,
+                                  jint opt, jobject value) {
+#ifdef AF_INET6
+#if defined(__solaris__) || defined(MACOSX)
+    if (ipv6_available()) {
+        mcast_set_loop_v6(env, this, fd, value);
+    } else {
+        mcast_set_loop_v4(env, this, fd, value);
+    }
+#endif
+#ifdef __linux__
+    mcast_set_loop_v4(env, this, fd, value);
+    if (ipv6_available()) {
+        mcast_set_loop_v6(env, this, fd, value);
+    }
+#endif
+#else
+    mcast_set_loop_v4(env, this, fd, value);
+#endif  /* AF_INET6 */
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    socketSetOption
+ * Signature: (ILjava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_socketSetOption(JNIEnv *env,
+                                                      jobject this,
+                                                      jint opt,
+                                                      jobject value) {
+    int fd;
+    int level, optname, optlen;
+    union {
+        int i;
+        char c;
+    } optval;
+
+    /*
+     * Check that socket hasn't been closed
+     */
+    fd = getFD(env, this);
+    if (fd < 0) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    }
+
+    /*
+     * Check argument has been provided
+     */
+    if (IS_NULL(value)) {
+        JNU_ThrowNullPointerException(env, "value argument");
+        return;
+    }
+
+    /*
+     * Setting the multicast interface handled seperately
+     */
+    if (opt == java_net_SocketOptions_IP_MULTICAST_IF ||
+        opt == java_net_SocketOptions_IP_MULTICAST_IF2) {
+
+        setMulticastInterface(env, this, fd, opt, value);
+        return;
+    }
+
+    /*
+     * Setting the multicast loopback mode handled separately
+     */
+    if (opt == java_net_SocketOptions_IP_MULTICAST_LOOP) {
+        setMulticastLoopbackMode(env, this, fd, opt, value);
+        return;
+    }
+
+    /*
+     * Map the Java level socket option to the platform specific
+     * level and option name.
+     */
+    if (NET_MapSocketOption(opt, &level, &optname)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        return;
+    }
+
+    switch (opt) {
+        case java_net_SocketOptions_SO_SNDBUF :
+        case java_net_SocketOptions_SO_RCVBUF :
+        case java_net_SocketOptions_IP_TOS :
+            {
+                jclass cls;
+                jfieldID fid;
+
+                cls = (*env)->FindClass(env, "java/lang/Integer");
+                CHECK_NULL(cls);
+                fid =  (*env)->GetFieldID(env, cls, "value", "I");
+                CHECK_NULL(fid);
+
+                optval.i = (*env)->GetIntField(env, value, fid);
+                optlen = sizeof(optval.i);
+                break;
+            }
+
+        case java_net_SocketOptions_SO_REUSEADDR:
+        case java_net_SocketOptions_SO_BROADCAST:
+            {
+                jclass cls;
+                jfieldID fid;
+                jboolean on;
+
+                cls = (*env)->FindClass(env, "java/lang/Boolean");
+                CHECK_NULL(cls);
+                fid =  (*env)->GetFieldID(env, cls, "value", "Z");
+                CHECK_NULL(fid);
+
+                on = (*env)->GetBooleanField(env, value, fid);
+
+                /* SO_REUSEADDR or SO_BROADCAST */
+                optval.i = (on ? 1 : 0);
+                optlen = sizeof(optval.i);
+
+                break;
+            }
+
+        default :
+            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                "Socket option not supported by PlainDatagramSocketImp");
+            break;
+
+    }
+
+    if (NET_SetSockOpt(fd, level, optname, (const void *)&optval, optlen) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Error setting socket option");
+        return;
+    }
+}
+
+
+/*
+ * Return the multicast interface:
+ *
+ * SocketOptions.IP_MULTICAST_IF
+ *      IPv4:   Query IPPROTO_IP/IP_MULTICAST_IF
+ *              Create InetAddress
+ *              IP_MULTICAST_IF returns struct ip_mreqn on 2.2
+ *              kernel but struct in_addr on 2.4 kernel
+ *      IPv6:   Query IPPROTO_IPV6 / IPV6_MULTICAST_IF or
+ *              obtain from impl is Linux 2.2 kernel
+ *              If index == 0 return InetAddress representing
+ *              anyLocalAddress.
+ *              If index > 0 query NetworkInterface by index
+ *              and returns addrs[0]
+ *
+ * SocketOptions.IP_MULTICAST_IF2
+ *      IPv4:   Query IPPROTO_IP/IP_MULTICAST_IF
+ *              Query NetworkInterface by IP address and
+ *              return the NetworkInterface that the address
+ *              is bound too.
+ *      IPv6:   Query IPPROTO_IPV6 / IPV6_MULTICAST_IF
+ *              (except Linux .2 kernel)
+ *              Query NetworkInterface by index and
+ *              return NetworkInterface.
+ */
+jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) {
+    jboolean isIPV4 = JNI_TRUE;
+
+#ifdef AF_INET6
+    if (ipv6_available()) {
+        isIPV4 = JNI_FALSE;
+    }
+#endif
+
+    /*
+     * IPv4 implementation
+     */
+    if (isIPV4) {
+        static jclass inet4_class;
+        static jmethodID inet4_ctrID;
+        static jfieldID inet4_addrID;
+
+        static jclass ni_class;
+        static jmethodID ni_ctrID;
+        static jfieldID ni_indexID;
+        static jfieldID ni_addrsID;
+
+        jobjectArray addrArray;
+        jobject addr;
+        jobject ni;
+
+        struct in_addr in;
+        struct in_addr *inP = &in;
+        int len = sizeof(struct in_addr);
+
+#ifdef __linux__
+        struct ip_mreqn mreqn;
+        if (isOldKernel) {
+            inP = (struct in_addr *)&mreqn;
+            len = sizeof(struct ip_mreqn);
+        }
+#endif
+
+        if (JVM_GetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_IF,
+                           (char *)inP, &len) < 0) {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                             "Error getting socket option");
+            return NULL;
+        }
+
+        /*
+         * Construct and populate an Inet4Address
+         */
+        if (inet4_class == NULL) {
+            jclass c = (*env)->FindClass(env, "java/net/Inet4Address");
+            CHECK_NULL_RETURN(c, NULL);
+            inet4_ctrID = (*env)->GetMethodID(env, c, "<init>", "()V");
+            CHECK_NULL_RETURN(inet4_ctrID, NULL);
+            inet4_addrID = (*env)->GetFieldID(env, c, "address", "I");
+            CHECK_NULL_RETURN(inet4_addrID, NULL);
+            inet4_class = (*env)->NewGlobalRef(env, c);
+            CHECK_NULL_RETURN(inet4_class, NULL);
+        }
+        addr = (*env)->NewObject(env, inet4_class, inet4_ctrID, 0);
+        CHECK_NULL_RETURN(addr, NULL);
+
+#ifdef __linux__
+        (*env)->SetIntField(env, addr, inet4_addrID,
+                (isOldKernel ? ntohl(mreqn.imr_address.s_addr) : ntohl(in.s_addr)) );
+#else
+        (*env)->SetIntField(env, addr, inet4_addrID, ntohl(in.s_addr));
+#endif
+
+        /*
+         * For IP_MULTICAST_IF return InetAddress
+         */
+        if (opt == java_net_SocketOptions_IP_MULTICAST_IF) {
+            return addr;
+        }
+
+        /*
+         * For IP_MULTICAST_IF2 we get the NetworkInterface for
+         * this address and return it
+         */
+        if (ni_class == NULL) {
+            jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+            CHECK_NULL_RETURN(c, NULL);
+            ni_ctrID = (*env)->GetMethodID(env, c, "<init>", "()V");
+            CHECK_NULL_RETURN(ni_ctrID, NULL);
+            ni_indexID = (*env)->GetFieldID(env, c, "index", "I");
+            CHECK_NULL_RETURN(ni_indexID, NULL);
+            ni_addrsID = (*env)->GetFieldID(env, c, "addrs",
+                                            "[Ljava/net/InetAddress;");
+            CHECK_NULL_RETURN(ni_addrsID, NULL);
+            ni_class = (*env)->NewGlobalRef(env, c);
+            CHECK_NULL_RETURN(ni_class, NULL);
+        }
+        ni = Java_java_net_NetworkInterface_getByInetAddress0(env, ni_class, addr);
+        if (ni) {
+            return ni;
+        }
+
+        /*
+         * The address doesn't appear to be bound at any known
+         * NetworkInterface. Therefore we construct a NetworkInterface
+         * with this address.
+         */
+        ni = (*env)->NewObject(env, ni_class, ni_ctrID, 0);
+        CHECK_NULL_RETURN(ni, NULL);
+
+        (*env)->SetIntField(env, ni, ni_indexID, -1);
+        addrArray = (*env)->NewObjectArray(env, 1, inet4_class, NULL);
+        CHECK_NULL_RETURN(addrArray, NULL);
+        (*env)->SetObjectArrayElement(env, addrArray, 0, addr);
+        (*env)->SetObjectField(env, ni, ni_addrsID, addrArray);
+        return ni;
+    }
+
+
+#ifdef AF_INET6
+    /*
+     * IPv6 implementation
+     */
+    if ((opt == java_net_SocketOptions_IP_MULTICAST_IF) ||
+        (opt == java_net_SocketOptions_IP_MULTICAST_IF2)) {
+
+        static jclass ni_class;
+        static jmethodID ni_ctrID;
+        static jfieldID ni_indexID;
+        static jfieldID ni_addrsID;
+        static jclass ia_class;
+        static jmethodID ia_anyLocalAddressID;
+
+        int index;
+        int len = sizeof(index);
+
+        jobjectArray addrArray;
+        jobject addr;
+        jobject ni;
+
+#ifdef __linux__
+        /*
+         * Linux 2.2 kernel doesn't support IPV6_MULTICAST_IF socke option
+         * so use cached index.
+         */
+        if (isOldKernel) {
+            index = (*env)->GetIntField(env, this, pdsi_multicastInterfaceID);
+        } else
+#endif
+        {
+            if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
+                               (char*)&index, &len) < 0) {
+                NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                               "Error getting socket option");
+                return NULL;
+            }
+        }
+
+        if (ni_class == NULL) {
+            jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+            CHECK_NULL_RETURN(c, NULL);
+            ni_ctrID = (*env)->GetMethodID(env, c, "<init>", "()V");
+            CHECK_NULL_RETURN(ni_ctrID, NULL);
+            ni_indexID = (*env)->GetFieldID(env, c, "index", "I");
+            CHECK_NULL_RETURN(ni_indexID, NULL);
+            ni_addrsID = (*env)->GetFieldID(env, c, "addrs",
+                                            "[Ljava/net/InetAddress;");
+            CHECK_NULL_RETURN(ni_addrsID, NULL);
+
+            ia_class = (*env)->FindClass(env, "java/net/InetAddress");
+            CHECK_NULL_RETURN(ia_class, NULL);
+            ia_class = (*env)->NewGlobalRef(env, ia_class);
+            CHECK_NULL_RETURN(ia_class, NULL);
+            ia_anyLocalAddressID = (*env)->GetStaticMethodID(env,
+                                                             ia_class,
+                                                             "anyLocalAddress",
+                                                             "()Ljava/net/InetAddress;");
+            CHECK_NULL_RETURN(ia_anyLocalAddressID, NULL);
+            ni_class = (*env)->NewGlobalRef(env, c);
+            CHECK_NULL_RETURN(ni_class, NULL);
+        }
+
+        /*
+         * If multicast to a specific interface then return the
+         * interface (for IF2) or the any address on that interface
+         * (for IF).
+         */
+        if (index > 0) {
+            ni = Java_java_net_NetworkInterface_getByIndex0(env, ni_class,
+                                                                   index);
+            if (ni == NULL) {
+                char errmsg[255];
+                sprintf(errmsg,
+                        "IPV6_MULTICAST_IF returned index to unrecognized interface: %d",
+                        index);
+                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", errmsg);
+                return NULL;
+            }
+
+            /*
+             * For IP_MULTICAST_IF2 return the NetworkInterface
+             */
+            if (opt == java_net_SocketOptions_IP_MULTICAST_IF2) {
+                return ni;
+            }
+
+            /*
+             * For IP_MULTICAST_IF return addrs[0]
+             */
+            addrArray = (*env)->GetObjectField(env, ni, ni_addrsID);
+            if ((*env)->GetArrayLength(env, addrArray) < 1) {
+                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                    "IPV6_MULTICAST_IF returned interface without IP bindings");
+                return NULL;
+            }
+
+            addr = (*env)->GetObjectArrayElement(env, addrArray, 0);
+            return addr;
+        }
+
+        /*
+         * Multicast to any address - return anyLocalAddress
+         * or a NetworkInterface with addrs[0] set to anyLocalAddress
+         */
+
+        addr = (*env)->CallStaticObjectMethod(env, ia_class, ia_anyLocalAddressID,
+                                              NULL);
+        if (opt == java_net_SocketOptions_IP_MULTICAST_IF) {
+            return addr;
+        }
+
+        ni = (*env)->NewObject(env, ni_class, ni_ctrID, 0);
+        CHECK_NULL_RETURN(ni, NULL);
+        (*env)->SetIntField(env, ni, ni_indexID, -1);
+        addrArray = (*env)->NewObjectArray(env, 1, ia_class, NULL);
+        CHECK_NULL_RETURN(addrArray, NULL);
+        (*env)->SetObjectArrayElement(env, addrArray, 0, addr);
+        (*env)->SetObjectField(env, ni, ni_addrsID, addrArray);
+        return ni;
+    }
+#endif
+    return NULL;
+}
+
+
+
+/*
+ * Returns relevant info as a jint.
+ *
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    socketGetOption
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL
+Java_java_net_PlainDatagramSocketImpl_socketGetOption(JNIEnv *env, jobject this,
+                                                      jint opt) {
+    int fd;
+    int level, optname, optlen;
+    union {
+        int i;
+        char c;
+    } optval;
+
+    fd = getFD(env, this);
+    if (fd < 0) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "socket closed");
+        return NULL;
+    }
+
+    /*
+     * Handle IP_MULTICAST_IF seperately
+     */
+    if (opt == java_net_SocketOptions_IP_MULTICAST_IF ||
+        opt == java_net_SocketOptions_IP_MULTICAST_IF2) {
+        return getMulticastInterface(env, this, fd, opt);
+
+    }
+
+    /*
+     * SO_BINDADDR implemented using getsockname
+     */
+    if (opt == java_net_SocketOptions_SO_BINDADDR) {
+        /* find out local IP address */
+        SOCKADDR him;
+        socklen_t len = 0;
+        int port;
+        jobject iaObj;
+
+        len = SOCKADDR_LEN;
+
+        if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                           "Error getting socket name");
+            return NULL;
+        }
+        iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
+
+        return iaObj;
+    }
+
+    /*
+     * Map the Java level socket option to the platform specific
+     * level and option name.
+     */
+    if (NET_MapSocketOption(opt, &level, &optname)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        return NULL;
+    }
+
+    /*
+     * IP_MULTICAST_LOOP socket option isn't available on Linux 2.2
+     * kernel with IPv6 so return value stored in impl.
+     */
+#if defined(AF_INET6) && defined(__linux__)
+    if (isOldKernel && opt == java_net_SocketOptions_IP_MULTICAST_LOOP &&
+        level == IPPROTO_IPV6) {
+        int mode = (int)(*env)->GetBooleanField(env, this, pdsi_loopbackID);
+        return createBoolean(env, mode);
+    }
+#endif
+
+    if (opt == java_net_SocketOptions_IP_MULTICAST_LOOP &&
+        level == IPPROTO_IP) {
+        optlen = sizeof(optval.c);
+    } else {
+        optlen = sizeof(optval.i);
+    }
+
+    if (NET_GetSockOpt(fd, level, optname, (void *)&optval, &optlen) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                         "Error getting socket option");
+        return NULL;
+    }
+
+    switch (opt) {
+        case java_net_SocketOptions_IP_MULTICAST_LOOP:
+            /* getLoopbackMode() returns true if IP_MULTICAST_LOOP disabled */
+            if (level == IPPROTO_IP) {
+                return createBoolean(env, (int)!optval.c);
+            } else {
+                return createBoolean(env, !optval.i);
+            }
+
+        case java_net_SocketOptions_SO_BROADCAST:
+        case java_net_SocketOptions_SO_REUSEADDR:
+            return createBoolean(env, optval.i);
+
+        case java_net_SocketOptions_SO_SNDBUF:
+        case java_net_SocketOptions_SO_RCVBUF:
+        case java_net_SocketOptions_IP_TOS:
+            return createInteger(env, optval.i);
+
+    }
+
+    /* should never rearch here */
+    return NULL;
+}
+
+/*
+ * Multicast-related calls
+ */
+
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_setTTL(JNIEnv *env, jobject this,
+                                             jbyte ttl) {
+    jint ittl = ttl;
+    if (ittl < 0) {
+        ittl += 0x100;
+    }
+    Java_java_net_PlainDatagramSocketImpl_setTimeToLive(env, this, ittl);
+}
+
+/*
+ * Set TTL for a socket. Throw exception if failed.
+ */
+static void setTTL(JNIEnv *env, int fd, jint ttl) {
+    char ittl = (char)ttl;
+    if (JVM_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ittl,
+                       sizeof(ittl)) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                       "Error setting socket option");
+    }
+}
+
+/*
+ * Set hops limit for a socket. Throw exception if failed.
+ */
+#ifdef AF_INET6
+static void setHopLimit(JNIEnv *env, int fd, jint ttl) {
+    int ittl = (int)ttl;
+    if (JVM_SetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+                       (char*)&ittl, sizeof(ittl)) < 0) {
+        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                       "Error setting socket option");
+    }
+}
+#endif
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    setTTL
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_setTimeToLive(JNIEnv *env, jobject this,
+                                                    jint ttl) {
+
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    int fd;
+    /* it is important to cast this to a char, otherwise setsockopt gets confused */
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    } else {
+        fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    }
+    /* setsockopt to be correct ttl */
+#ifdef AF_INET6
+#if defined(__solaris__) || defined(MACOSX)
+    if (ipv6_available()) {
+        setHopLimit(env, fd, ttl);
+    } else {
+        setTTL(env, fd, ttl);
+    }
+#endif
+#ifdef __linux__
+    setTTL(env, fd, ttl);
+    if (ipv6_available()) {
+        setHopLimit(env, fd, ttl);
+        if (isOldKernel) {
+            (*env)->SetIntField(env, this, pdsi_ttlID, ttl);
+        }
+    }
+#endif  // __linux__
+#else
+    setTTL(env, fd, ttl);
+#endif  /* AF_INET6 */
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    getTTL
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL
+Java_java_net_PlainDatagramSocketImpl_getTTL(JNIEnv *env, jobject this) {
+    return (jbyte)Java_java_net_PlainDatagramSocketImpl_getTimeToLive(env, this);
+}
+
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    getTTL
+ * Signature: ()B
+ */
+JNIEXPORT jint JNICALL
+Java_java_net_PlainDatagramSocketImpl_getTimeToLive(JNIEnv *env, jobject this) {
+
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    jint fd = -1;
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return -1;
+    } else {
+        fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    }
+    /* getsockopt of ttl */
+#ifdef AF_INET6
+    if (ipv6_available()) {
+        int ttl = 0;
+        int len = sizeof(ttl);
+
+#ifdef __linux__
+        /*
+         * Linux 2.2 kernel doesn't support IPV6_MULTICAST_HOPS socket option
+         */
+        if (isOldKernel) {
+            return (*env)->GetIntField(env, this, pdsi_ttlID);
+        }
+#endif
+
+        if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+                               (char*)&ttl, &len) < 0) {
+                NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                               "Error getting socket option");
+                return -1;
+            }
+        return (jint)ttl;
+    } else
+#endif /* AF_INET6 */
+        {
+            u_char ttl = 0;
+            int len = sizeof(ttl);
+            if (JVM_GetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
+                               (char*)&ttl, &len) < 0) {
+                NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                               "Error getting socket option");
+                return -1;
+            }
+            return (jint)ttl;
+        }
+}
+
+
+/*
+ * mcast_join_leave: Join or leave a multicast group.
+ *
+ * For IPv4 sockets use IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP socket option
+ * to join/leave multicast group.
+ *
+ * For IPv6 sockets use IPV6_ADD_MEMBERSHIP/IPV6_DROP_MEMBERSHIP socket option
+ * to join/leave multicast group. If multicast group is an IPv4 address then
+ * an IPv4-mapped address is used.
+ *
+ * On Linux with IPv6 if we wish to join/leave an IPv4 multicast group then
+ * we must use the IPv4 socket options. This is because the IPv6 socket options
+ * don't support IPv4-mapped addresses. This is true as per 2.2.19 and 2.4.7
+ * kernel releases. In the future it's possible that IP_ADD_MEMBERSHIP
+ * will be updated to return ENOPROTOOPT if uses with an IPv6 socket (Solaris
+ * already does this). Thus to cater for this we first try with the IPv4
+ * socket options and if they fail we use the IPv6 socket options. This
+ * seems a reasonable failsafe solution.
+ */
+static void mcast_join_leave(JNIEnv *env, jobject this,
+                             jobject iaObj, jobject niObj,
+                             jboolean join) {
+
+    jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+    jint fd;
+    jint ipv6_join_leave;
+
+    if (IS_NULL(fdObj)) {
+        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Socket closed");
+        return;
+    } else {
+        fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    }
+    if (IS_NULL(iaObj)) {
+        JNU_ThrowNullPointerException(env, "iaObj");
+        return;
+    }
+
+    /*
+     * Determine if this is an IPv4 or IPv6 join/leave.
+     */
+#ifdef AF_INET6
+    ipv6_join_leave = ipv6_available();
+
+#ifdef __linux__
+    if ((*env)->GetIntField(env, iaObj, ia_familyID) == IPv4) {
+        ipv6_join_leave = JNI_FALSE;
+    }
+#endif
+
+#else
+    /*
+     * IPv6 not compiled in
+     */
+    ipv6_join_leave = JNI_FALSE;
+#endif
+
+    /*
+     * For IPv4 join use IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP socket option
+     *
+     * On Linux if IPv4 or IPv6 use IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP
+     */
+    if (!ipv6_join_leave) {
+#ifdef __linux__
+        struct ip_mreqn mname;
+#else
+        struct ip_mreq mname;
+#endif
+        int mname_len;
+
+        /*
+         * joinGroup(InetAddress, NetworkInterface) implementation :-
+         *
+         * Linux/IPv6:  use ip_mreqn structure populated with multicast
+         *              address and interface index.
+         *
+         * IPv4:        use ip_mreq structure populated with multicast
+         *              address and first address obtained from
+         *              NetworkInterface
+         */
+        if (niObj != NULL) {
+#if defined(__linux__) && defined(AF_INET6)
+            if (ipv6_available()) {
+                static jfieldID ni_indexID;
+
+                if (ni_indexID == NULL) {
+                    jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+                    CHECK_NULL(c);
+                    ni_indexID = (*env)->GetFieldID(env, c, "index", "I");
+                    CHECK_NULL(ni_indexID);
+                }
+
+                mname.imr_multiaddr.s_addr = htonl((*env)->GetIntField(env, iaObj, ia_addressID));
+                mname.imr_address.s_addr = 0;
+                mname.imr_ifindex =  (*env)->GetIntField(env, niObj, ni_indexID);
+                mname_len = sizeof(struct ip_mreqn);
+            } else
+#endif
+            {
+                jobjectArray addrArray = (*env)->GetObjectField(env, niObj, ni_addrsID);
+                jobject addr;
+
+                if ((*env)->GetArrayLength(env, addrArray) < 1) {
+                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "bad argument for IP_ADD_MEMBERSHIP: "
+                        "No IP addresses bound to interface");
+                    return;
+                }
+                addr = (*env)->GetObjectArrayElement(env, addrArray, 0);
+
+                mname.imr_multiaddr.s_addr = htonl((*env)->GetIntField(env, iaObj, ia_addressID));
+#ifdef __linux__
+                mname.imr_address.s_addr = htonl((*env)->GetIntField(env, addr, ia_addressID));
+#else
+                mname.imr_interface.s_addr = htonl((*env)->GetIntField(env, addr, ia_addressID));
+#endif
+                mname_len = sizeof(struct ip_mreq);
+            }
+        }
+
+
+        /*
+         * joinGroup(InetAddress) implementation :-
+         *
+         * Linux/IPv6:  use ip_mreqn structure populated with multicast
+         *              address and interface index. index obtained
+         *              from cached value or IPV6_MULTICAST_IF.
+         *
+         * IPv4:        use ip_mreq structure populated with multicast
+         *              address and local address obtained from
+         *              IP_MULTICAST_IF. On Linux IP_MULTICAST_IF
+         *              returns different structure depending on
+         *              kernel.
+         */
+
+        if (niObj == NULL) {
+
+#if defined(__linux__) && defined(AF_INET6)
+            if (ipv6_available()) {
+
+                int index;
+                int len = sizeof(index);
+
+                if (isOldKernel) {
+                    index = (*env)->GetIntField(env, this, pdsi_multicastInterfaceID);
+                } else {
+                    if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
+                                       (char*)&index, &len) < 0) {
+                        NET_ThrowCurrent(env, "getsockopt IPV6_MULTICAST_IF failed");
+                        return;
+                    }
+                }
+
+                mname.imr_multiaddr.s_addr = htonl((*env)->GetIntField(env, iaObj, ia_addressID));
+                mname.imr_address.s_addr = 0 ;
+                mname.imr_ifindex = index;
+                mname_len = sizeof(struct ip_mreqn);
+            } else
+#endif
+            {
+                struct in_addr in;
+                struct in_addr *inP = &in;
+                socklen_t len = sizeof(struct in_addr);
+
+#ifdef __linux__
+                struct ip_mreqn mreqn;
+                if (isOldKernel) {
+                    inP = (struct in_addr *)&mreqn;
+                    len = sizeof(struct ip_mreqn);
+                }
+#endif
+                if (getsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (char *)inP, &len) < 0) {
+                    NET_ThrowCurrent(env, "getsockopt IP_MULTICAST_IF failed");
+                    return;
+                }
+
+#ifdef __linux__
+                mname.imr_address.s_addr =
+                    (isOldKernel ? mreqn.imr_address.s_addr : in.s_addr);
+
+#else
+                mname.imr_interface.s_addr = in.s_addr;
+#endif
+                mname.imr_multiaddr.s_addr = htonl((*env)->GetIntField(env, iaObj, ia_addressID));
+                mname_len = sizeof(struct ip_mreq);
+            }
+        }
+
+
+        /*
+         * Join the multicast group.
+         */
+        if (JVM_SetSockOpt(fd, IPPROTO_IP, (join ? IP_ADD_MEMBERSHIP:IP_DROP_MEMBERSHIP),
+                           (char *) &mname, mname_len) < 0) {
+
+            /*
+             * If IP_ADD_MEMBERSHIP returns ENOPROTOOPT on Linux and we've got
+             * IPv6 enabled then it's possible that the kernel has been fixed
+             * so we switch to IPV6_ADD_MEMBERSHIP socket option.
+             * As of 2.4.7 kernel IPV6_ADD_MEMERSHIP can't handle IPv4-mapped
+             * addresses so we have to use IP_ADD_MEMERSHIP for IPv4 multicast
+             * groups. However if the socket is an IPv6 socket then then setsockopt
+             * should reurn ENOPROTOOPT. We assume this will be fixed in Linux
+             * at some stage.
+             */
+#if defined(__linux__) && defined(AF_INET6)
+            if (errno == ENOPROTOOPT) {
+                if (ipv6_available()) {
+                    ipv6_join_leave = JNI_TRUE;
+                    errno = 0;
+                } else  {
+                    errno = ENOPROTOOPT;    /* errno can be changed by ipv6_available */
+                }
+            }
+#endif
+            if (errno) {
+                if (join) {
+                    NET_ThrowCurrent(env, "setsockopt IP_ADD_MEMBERSHIP failed");
+                } else {
+                    if (errno == ENOENT)
+                        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                            "Not a member of the multicast group");
+                    else
+                        NET_ThrowCurrent(env, "setsockopt IP_DROP_MEMBERSHIP failed");
+                }
+            }
+        }
+
+        /*
+         * If we haven't switched to IPv6 socket option then we're done.
+         */
+        if (!ipv6_join_leave) {
+            return;
+        }
+    }
+
+
+    /*
+     * IPv6 join. If it's an IPv4 multicast group then we use an IPv4-mapped
+     * address.
+     */
+#ifdef AF_INET6
+    {
+        struct ipv6_mreq mname6;
+        jbyteArray ipaddress;
+        jbyte caddr[16];
+        jint family;
+        jint address;
+        family = (*env)->GetIntField(env, iaObj, ia_familyID) == IPv4? AF_INET : AF_INET6;
+        if (family == AF_INET) { /* will convert to IPv4-mapped address */
+            memset((char *) caddr, 0, 16);
+            address = (*env)->GetIntField(env, iaObj, ia_addressID);
+
+            caddr[10] = 0xff;
+            caddr[11] = 0xff;
+
+            caddr[12] = ((address >> 24) & 0xff);
+            caddr[13] = ((address >> 16) & 0xff);
+            caddr[14] = ((address >> 8) & 0xff);
+            caddr[15] = (address & 0xff);
+        } else {
+            ipaddress = (*env)->GetObjectField(env, iaObj, ia6_ipaddressID);
+            (*env)->GetByteArrayRegion(env, ipaddress, 0, 16, caddr);
+        }
+
+        memcpy((void *)&(mname6.ipv6mr_multiaddr), caddr, sizeof(struct in6_addr));
+        if (IS_NULL(niObj)) {
+            int index;
+            int len = sizeof(index);
+
+#ifdef __linux__
+            /*
+             * 2.2 kernel doens't support IPV6_MULTICAST_IF socket option
+             */
+            if (isOldKernel) {
+                index = (*env)->GetIntField(env, this, pdsi_multicastInterfaceID);
+            } else
+#endif
+            {
+                if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
+                                 (char*)&index, &len) < 0) {
+                    NET_ThrowCurrent(env, "getsockopt IPV6_MULTICAST_IF failed");
+                    return;
+                }
+            }
+
+#ifdef __linux__
+            /*
+             * On 2.4.8+ if we join a group with the interface set to 0
+             * then the kernel records the interface it decides. This causes
+             * subsequent leave groups to fail as there is no match. Thus we
+             * pick the interface if there is a matching route.
+             */
+            if (index == 0 && !isOldKernel) {
+                int rt_index = getDefaultIPv6Interface(&(mname6.ipv6mr_multiaddr));
+                if (rt_index > 0) {
+                    index = rt_index;
+                }
+            }
+#endif
+
+            mname6.ipv6mr_interface = index;
+        } else {
+            jint idx = (*env)->GetIntField(env, niObj, ni_indexID);
+            mname6.ipv6mr_interface = idx;
+        }
+
+#if defined(_ALLBSD_SOURCE)
+#define ADD_MEMBERSHIP          IPV6_JOIN_GROUP
+#define DRP_MEMBERSHIP          IPV6_LEAVE_GROUP
+#define S_ADD_MEMBERSHIP        "IPV6_JOIN_GROUP"
+#define S_DRP_MEMBERSHIP        "IPV6_LEAVE_GROUP"
+#else
+#define ADD_MEMBERSHIP          IPV6_ADD_MEMBERSHIP
+#define DRP_MEMBERSHIP          IPV6_DROP_MEMBERSHIP
+#define S_ADD_MEMBERSHIP        "IPV6_ADD_MEMBERSHIP"
+#define S_DRP_MEMBERSHIP        "IPV6_DROP_MEMBERSHIP"
+#endif
+
+        /* Join the multicast group */
+        if (JVM_SetSockOpt(fd, IPPROTO_IPV6, (join ? ADD_MEMBERSHIP : DRP_MEMBERSHIP),
+                           (char *) &mname6, sizeof (mname6)) < 0) {
+
+            if (join) {
+                NET_ThrowCurrent(env, "setsockopt " S_ADD_MEMBERSHIP " failed");
+            } else {
+                if (errno == ENOENT) {
+                   JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        "Not a member of the multicast group");
+                } else {
+                    NET_ThrowCurrent(env, "setsockopt " S_DRP_MEMBERSHIP " failed");
+                }
+            }
+        }
+    }
+#endif
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    join
+ * Signature: (Ljava/net/InetAddress;)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_join(JNIEnv *env, jobject this,
+                                           jobject iaObj, jobject niObj)
+{
+    mcast_join_leave(env, this, iaObj, niObj, JNI_TRUE);
+}
+
+/*
+ * Class:     java_net_PlainDatagramSocketImpl
+ * Method:    leave
+ * Signature: (Ljava/net/InetAddress;)V
+ */
+JNIEXPORT void JNICALL
+Java_java_net_PlainDatagramSocketImpl_leave(JNIEnv *env, jobject this,
+                                            jobject iaObj, jobject niObj)
+{
+    mcast_join_leave(env, this, iaObj, niObj, JNI_FALSE);
+}
diff --git a/jdk/src/solaris/native/java/net/PlainSocketImpl.c b/jdk/src/solaris/native/java/net/PlainSocketImpl.c
index 64b6e3c..82616f2 100644
--- a/jdk/src/solaris/native/java/net/PlainSocketImpl.c
+++ b/jdk/src/solaris/native/java/net/PlainSocketImpl.c
@@ -70,6 +70,8 @@
 jfieldID psi_fdLockID;
 jfieldID psi_closePendingID;
 
+extern void setDefaultScopeID(JNIEnv *env, struct sockaddr *him);
+
 /*
  * file descriptor used for dup2
  */
@@ -115,7 +117,6 @@
     return sv[0];
 }
 
-
 /*
  * Return the file descriptor given a PlainSocketImpl
  */
@@ -260,6 +261,9 @@
 
     /* fdObj is the FileDescriptor field on this */
     jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
+
+    jclass clazz = (*env)->GetObjectClass(env, this);
+
     jobject fdLock;
 
     jint trafficClass = (*env)->GetIntField(env, this, psi_trafficClassID);
@@ -286,6 +290,7 @@
     if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
       return;
     }
+    setDefaultScopeID(env, (struct sockaddr *)&him);
 
 #ifdef AF_INET6
     if (trafficClass != 0 && ipv6_available()) {
@@ -483,9 +488,11 @@
         if (connect_rv == JVM_IO_INTR) {
             JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
                             "operation interrupted");
+#if defined(EPROTO)
         } else if (errno == EPROTO) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ProtocolException",
                            "Protocol error");
+#endif
         } else if (errno == ECONNREFUSED) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
                            "Connection refused");
@@ -565,6 +572,7 @@
     if (NET_InetAddressToSockaddr(env, iaObj, localport, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
       return;
     }
+    setDefaultScopeID(env, (struct sockaddr *)&him);
 
     if (NET_Bind(fd, (struct sockaddr *)&him, len) < 0) {
         if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
diff --git a/jdk/src/solaris/native/java/net/bsd_close.c b/jdk/src/solaris/native/java/net/bsd_close.c
new file mode 100644
index 0000000..ef29244
--- /dev/null
+++ b/jdk/src/solaris/native/java/net/bsd_close.c
@@ -0,0 +1,397 @@
+/*
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/poll.h>
+
+/*
+ * Stack allocated by thread when doing blocking operation
+ */
+typedef struct threadEntry {
+    pthread_t thr;                      /* this thread */
+    struct threadEntry *next;           /* next thread */
+    int intr;                           /* interrupted */
+} threadEntry_t;
+
+/*
+ * Heap allocated during initialized - one entry per fd
+ */
+typedef struct {
+    pthread_mutex_t lock;               /* fd lock */
+    threadEntry_t *threads;             /* threads blocked on fd */
+} fdEntry_t;
+
+/*
+ * Signal to unblock thread
+ */
+static int sigWakeup = SIGIO;
+
+/*
+ * The fd table and the number of file descriptors
+ */
+static fdEntry_t *fdTable;
+static int fdCount;
+
+/*
+ * This limit applies if getlimit() returns unlimited.
+ * Unfortunately, this means if someone wants a higher limt
+ * then they have to set an explicit limit, higher than this,
+ * which is probably counter-intuitive.
+ */
+#define MAX_FD_COUNT 4096
+
+/*
+ * Null signal handler
+ */
+static void sig_wakeup(int sig) {
+}
+
+/*
+ * Initialization routine (executed when library is loaded)
+ * Allocate fd tables and sets up signal handler.
+ */
+static void __attribute((constructor)) init() {
+    struct rlimit nbr_files;
+    sigset_t sigset;
+    struct sigaction sa;
+
+    /*
+     * Allocate table based on the maximum number of
+     * file descriptors.
+     */
+    getrlimit(RLIMIT_NOFILE, &nbr_files);
+    if (nbr_files.rlim_max == RLIM_INFINITY) {
+        fdCount = MAX_FD_COUNT;
+    } else {
+        fdCount = nbr_files.rlim_max;
+    }
+    fdTable = (fdEntry_t *)calloc(fdCount, sizeof(fdEntry_t));
+    if (fdTable == NULL) {
+        fprintf(stderr, "library initialization failed - "
+                "unable to allocate file descriptor table - out of memory");
+        abort();
+    }
+
+    /*
+     * Setup the signal handler
+     */
+    sa.sa_handler = sig_wakeup;
+    sa.sa_flags   = 0;
+    sigemptyset(&sa.sa_mask);
+    sigaction(sigWakeup, &sa, NULL);
+
+    sigemptyset(&sigset);
+    sigaddset(&sigset, sigWakeup);
+    sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+}
+
+/*
+ * Return the fd table for this fd or NULL is fd out
+ * of range.
+ */
+static inline fdEntry_t *getFdEntry(int fd)
+{
+    if (fd < 0 || fd >= fdCount) {
+        return NULL;
+    }
+    return &fdTable[fd];
+}
+
+/*
+ * Start a blocking operation :-
+ *    Insert thread onto thread list for the fd.
+ */
+static inline void startOp(fdEntry_t *fdEntry, threadEntry_t *self)
+{
+    self->thr = pthread_self();
+    self->intr = 0;
+
+    pthread_mutex_lock(&(fdEntry->lock));
+    {
+        self->next = fdEntry->threads;
+        fdEntry->threads = self;
+    }
+    pthread_mutex_unlock(&(fdEntry->lock));
+}
+
+/*
+ * End a blocking operation :-
+ *     Remove thread from thread list for the fd
+ *     If fd has been interrupted then set errno to EBADF
+ */
+static inline void endOp
+    (fdEntry_t *fdEntry, threadEntry_t *self)
+{
+    int orig_errno = errno;
+    pthread_mutex_lock(&(fdEntry->lock));
+    {
+        threadEntry_t *curr, *prev=NULL;
+        curr = fdEntry->threads;
+        while (curr != NULL) {
+            if (curr == self) {
+                if (curr->intr) {
+                    orig_errno = EBADF;
+                }
+                if (prev == NULL) {
+                    fdEntry->threads = curr->next;
+                } else {
+                    prev->next = curr->next;
+                }
+                break;
+            }
+            prev = curr;
+            curr = curr->next;
+        }
+    }
+    pthread_mutex_unlock(&(fdEntry->lock));
+    errno = orig_errno;
+}
+
+/*
+ * Close or dup2 a file descriptor ensuring that all threads blocked on
+ * the file descriptor are notified via a wakeup signal.
+ *
+ *      fd1 < 0    => close(fd2)
+ *      fd1 >= 0   => dup2(fd1, fd2)
+ *
+ * Returns -1 with errno set if operation fails.
+ */
+static int closefd(int fd1, int fd2) {
+    int rv, orig_errno;
+    fdEntry_t *fdEntry = getFdEntry(fd2);
+    if (fdEntry == NULL) {
+        errno = EBADF;
+        return -1;
+    }
+
+    /*
+     * Lock the fd to hold-off additional I/O on this fd.
+     */
+    pthread_mutex_lock(&(fdEntry->lock));
+
+    {
+        /*
+         * Send a wakeup signal to all threads blocked on this
+         * file descriptor.
+         */
+        threadEntry_t *curr = fdEntry->threads;
+        while (curr != NULL) {
+            curr->intr = 1;
+            pthread_kill( curr->thr, sigWakeup );
+            curr = curr->next;
+        }
+
+        /*
+         * And close/dup the file descriptor
+         * (restart if interrupted by signal)
+         */
+        do {
+            if (fd1 < 0) {
+                rv = close(fd2);
+            } else {
+                rv = dup2(fd1, fd2);
+            }
+        } while (rv == -1 && errno == EINTR);
+
+    }
+
+    /*
+     * Unlock without destroying errno
+     */
+    orig_errno = errno;
+    pthread_mutex_unlock(&(fdEntry->lock));
+    errno = orig_errno;
+
+    return rv;
+}
+
+/*
+ * Wrapper for dup2 - same semantics as dup2 system call except
+ * that any threads blocked in an I/O system call on fd2 will be
+ * preempted and return -1/EBADF;
+ */
+int NET_Dup2(int fd, int fd2) {
+    if (fd < 0) {
+        errno = EBADF;
+        return -1;
+    }
+    return closefd(fd, fd2);
+}
+
+/*
+ * Wrapper for close - same semantics as close system call
+ * except that any threads blocked in an I/O on fd will be
+ * preempted and the I/O system call will return -1/EBADF.
+ */
+int NET_SocketClose(int fd) {
+    return closefd(-1, fd);
+}
+
+/************** Basic I/O operations here ***************/
+
+/*
+ * Macro to perform a blocking IO operation. Restarts
+ * automatically if interrupted by signal (other than
+ * our wakeup signal)
+ */
+#define BLOCKING_IO_RETURN_INT(FD, FUNC) {      \
+    int ret;                                    \
+    threadEntry_t self;                         \
+    fdEntry_t *fdEntry = getFdEntry(FD);        \
+    if (fdEntry == NULL) {                      \
+        errno = EBADF;                          \
+        return -1;                              \
+    }                                           \
+    do {                                        \
+        startOp(fdEntry, &self);                \
+        ret = FUNC;                             \
+        endOp(fdEntry, &self);                  \
+    } while (ret == -1 && errno == EINTR);      \
+    return ret;                                 \
+}
+
+int NET_Read(int s, void* buf, size_t len) {
+    BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
+}
+
+int NET_ReadV(int s, const struct iovec * vector, int count) {
+    BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) );
+}
+
+int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
+       struct sockaddr *from, int *fromlen) {
+    BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, fromlen) );
+}
+
+int NET_Send(int s, void *msg, int len, unsigned int flags) {
+    BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
+}
+
+int NET_WriteV(int s, const struct iovec * vector, int count) {
+    BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) );
+}
+
+int NET_SendTo(int s, const void *msg, int len,  unsigned  int
+       flags, const struct sockaddr *to, int tolen) {
+    BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
+}
+
+int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
+    socklen_t len = *addrlen;
+    int error = accept(s, addr, &len);
+    if (error != -1)
+        *addrlen = (int)len;
+    BLOCKING_IO_RETURN_INT( s, error );
+}
+
+int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
+    BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
+}
+
+#ifndef USE_SELECT
+int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
+    BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
+}
+#else
+int NET_Select(int s, fd_set *readfds, fd_set *writefds,
+               fd_set *exceptfds, struct timeval *timeout) {
+    BLOCKING_IO_RETURN_INT( s-1,
+                            select(s, readfds, writefds, exceptfds, timeout) );
+}
+#endif
+
+/*
+ * Wrapper for poll(s, timeout).
+ * Auto restarts with adjusted timeout if interrupted by
+ * signal other than our wakeup signal.
+ */
+int NET_Timeout(int s, long timeout) {
+    long prevtime = 0, newtime;
+    struct timeval t;
+    fdEntry_t *fdEntry = getFdEntry(s);
+
+    /*
+     * Check that fd hasn't been closed.
+     */
+    if (fdEntry == NULL) {
+        errno = EBADF;
+        return -1;
+    }
+
+    /*
+     * Pick up current time as may need to adjust timeout
+     */
+    if (timeout > 0) {
+        gettimeofday(&t, NULL);
+        prevtime = t.tv_sec * 1000  +  t.tv_usec / 1000;
+    }
+
+    for(;;) {
+        struct pollfd pfd;
+        int rv;
+        threadEntry_t self;
+
+        /*
+         * Poll the fd. If interrupted by our wakeup signal
+         * errno will be set to EBADF.
+         */
+        pfd.fd = s;
+        pfd.events = POLLIN | POLLERR;
+
+        startOp(fdEntry, &self);
+        rv = poll(&pfd, 1, timeout);
+        endOp(fdEntry, &self);
+
+        /*
+         * If interrupted then adjust timeout. If timeout
+         * has expired return 0 (indicating timeout expired).
+         */
+        if (rv < 0 && errno == EINTR) {
+            if (timeout > 0) {
+                gettimeofday(&t, NULL);
+                newtime = t.tv_sec * 1000  +  t.tv_usec / 1000;
+                timeout -= newtime - prevtime;
+                if (timeout <= 0) {
+                    return 0;
+                }
+                prevtime = newtime;
+            }
+        } else {
+            return rv;
+        }
+
+    }
+}
diff --git a/jdk/src/solaris/native/java/net/net_util_md.c b/jdk/src/solaris/native/java/net/net_util_md.c
index 25b58f6..cf36f3b 100644
--- a/jdk/src/solaris/native/java/net/net_util_md.c
+++ b/jdk/src/solaris/native/java/net/net_util_md.c
@@ -33,7 +33,17 @@
 #include <netdb.h>
 #include <stdlib.h>
 #include <dlfcn.h>
+
+#ifndef _ALLBSD_SOURCE
 #include <values.h>
+#else
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#ifndef MAXINT
+#define MAXINT INT_MAX
+#endif
+#endif
 
 #ifdef __solaris__
 #include <sys/sockio.h>
@@ -75,6 +85,22 @@
 #define UDP_EXCLBIND            0x0101
 #endif
 
+extern jclass ni_class;
+extern jfieldID ni_defaultIndexID;
+
+void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
+{
+#ifdef MACOSX
+    int defaultIndex;
+    struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)him;
+    if (sin6->sin6_family == AF_INET6 && (sin6->sin6_scope_id == 0)) {
+        defaultIndex = (*env)->GetStaticIntField(env, ni_class,
+                                                 ni_defaultIndexID);
+        sin6->sin6_scope_id = defaultIndex;
+    }
+#endif
+}
+
 #ifdef __solaris__
 static int init_tcp_max_buf, init_udp_max_buf;
 static int tcp_max_buf;
@@ -272,6 +298,14 @@
     return (*env)->GetFieldID(env, cls, "fd", "I");
 }
 
+#if defined(DONT_ENABLE_IPV6)
+jint  IPv6_supported()
+{
+    return JNI_FALSE;
+}
+
+#else /* !DONT_ENABLE_IPV6 */
+
 jint  IPv6_supported()
 {
 #ifndef AF_INET6
@@ -410,6 +444,7 @@
     return JNI_TRUE;
 #endif /* AF_INET6 */
 }
+#endif /* DONT_ENABLE_IPV6 */
 
 void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
                                            const char* hostname,
@@ -772,6 +807,11 @@
         him6->sin6_family = AF_INET6;
         *len = sizeof(struct sockaddr_in6) ;
 
+#if defined(_ALLBSD_SOURCE) && defined(_AF_INET6)
+// XXXBSD: should we do something with scope id here ? see below linux comment
+/* MMM: Come back to this! */
+#endif
+
         /*
          * On Linux if we are connecting to a link-local address
          * we need to specify the interface in the scope_id (2.4 kernel only)
@@ -1197,6 +1237,15 @@
     }
 #endif
 
+/* Workaround for Mac OS treating linger value as
+ *  signed integer
+ */
+#ifdef MACOSX
+    if (level == SOL_SOCKET && opt == SO_LINGER) {
+        struct linger* to_cast = (struct linger*)result;
+        to_cast->l_linger = (unsigned short)to_cast->l_linger;
+    }
+#endif
     return rv;
 }
 
@@ -1224,6 +1273,24 @@
 #define IPTOS_PREC_MASK 0xe0
 #endif
 
+#if defined(_ALLBSD_SOURCE)
+#if defined(KIPC_MAXSOCKBUF)
+    int mib[3];
+    size_t rlen;
+#endif
+
+    int *bufsize;
+
+#ifdef __APPLE__
+    static int maxsockbuf = -1;
+#else
+    static long maxsockbuf = -1;
+#endif
+
+    int addopt;
+    struct linger *ling;
+#endif
+
     /*
      * IPPROTO/IP_TOS :-
      * 1. IPv6 on Solaris: no-op and will be set in flowinfo
@@ -1256,6 +1323,10 @@
         *iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK);
     }
 
+#if defined(AF_INET6) && defined(_ALLBSD_SOURCE)
+// XXXBSD: to be implemented ?
+#endif
+
     /*
      * SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On Solaris we may need to clamp
      * the value when it exceeds the system limit.
@@ -1329,6 +1400,71 @@
     }
 #endif
 
+#if defined(_ALLBSD_SOURCE)
+    /*
+     * SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On FreeBSD need to
+     * ensure that value is <= kern.ipc.maxsockbuf as otherwise we get
+     * an ENOBUFS error.
+     */
+    if (level == SOL_SOCKET) {
+        if (opt == SO_SNDBUF || opt == SO_RCVBUF) {
+#ifdef KIPC_MAXSOCKBUF
+            if (maxsockbuf == -1) {
+               mib[0] = CTL_KERN;
+               mib[1] = KERN_IPC;
+               mib[2] = KIPC_MAXSOCKBUF;
+               rlen = sizeof(maxsockbuf);
+               if (sysctl(mib, 3, &maxsockbuf, &rlen, NULL, 0) == -1)
+                   maxsockbuf = 1024;
+
+#if 1
+               /* XXXBSD: This is a hack to workaround mb_max/mb_max_adj
+                  problem.  It should be removed when kern.ipc.maxsockbuf
+                  will be real value. */
+               maxsockbuf = (maxsockbuf/5)*4;
+#endif
+           }
+#elif defined(__OpenBSD__)
+           maxsockbuf = SB_MAX;
+#else
+           maxsockbuf = 64 * 1024;      /* XXX: NetBSD */
+#endif
+
+           bufsize = (int *)arg;
+           if (*bufsize > maxsockbuf) {
+               *bufsize = maxsockbuf;
+           }
+
+           if (opt == SO_RCVBUF && *bufsize < 1024) {
+                *bufsize = 1024;
+           }
+
+        }
+    }
+
+    /*
+     * On Solaris, SO_REUSEADDR will allow multiple datagram
+     * sockets to bind to the same port.  The network jck tests
+     * for this "feature", so we need to emulate it by turning on
+     * SO_REUSEPORT as well for that combination.
+     */
+    if (level == SOL_SOCKET && opt == SO_REUSEADDR) {
+        int sotype;
+        socklen_t arglen;
+
+        arglen = sizeof(sotype);
+        if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) < 0) {
+            return -1;
+        }
+
+        if (sotype == SOCK_DGRAM) {
+            addopt = SO_REUSEPORT;
+            setsockopt(fd, level, addopt, arg, len);
+        }
+    }
+
+#endif
+
     return setsockopt(fd, level, opt, arg, len);
 }
 
diff --git a/jdk/src/solaris/native/java/net/net_util_md.h b/jdk/src/solaris/native/java/net/net_util_md.h
index 5df5894..ad6653a 100644
--- a/jdk/src/solaris/native/java/net/net_util_md.h
+++ b/jdk/src/solaris/native/java/net/net_util_md.h
@@ -37,7 +37,7 @@
 #endif
 
 
-#ifdef __linux__
+#if defined(__linux__)
 extern int NET_Timeout(int s, long timeout);
 extern int NET_Read(int s, void* buf, size_t len);
 extern int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
diff --git a/jdk/src/solaris/native/java/util/FileSystemPreferences.c b/jdk/src/solaris/native/java/util/FileSystemPreferences.c
index 256a166..7bc1f45 100644
--- a/jdk/src/solaris/native/java/util/FileSystemPreferences.c
+++ b/jdk/src/solaris/native/java/util/FileSystemPreferences.c
@@ -47,8 +47,11 @@
     return (jint) result;
 }
 
-
+#if defined(_ALLBSD_SOURCE)
+typedef struct flock FLOCK;
+#else
 typedef struct flock64 FLOCK;
+#endif
 
 /**
  * Try to open a named lock file.
@@ -86,7 +89,11 @@
     if (fd < 0) {
         result[0] = 0;
     } else {
+#if defined(_ALLBSD_SOURCE)
+        rc = fcntl(fd, F_SETLK, &fl);
+#else
         rc = fcntl(fd, F_SETLK64, &fl);
+#endif
         result[1] = errno;
         if (rc < 0) {
             result[0]= 0;
@@ -116,7 +123,11 @@
     fl.l_start = 0;
     fl.l_type = F_UNLCK;
 
+#if defined(_ALLBSD_SOURCE)
+    rc = fcntl(fd, F_SETLK, &fl);
+#else
     rc = fcntl(fd, F_SETLK64, &fl);
+#endif
 
     if (rc < 0) {
         close(fd);
diff --git a/jdk/src/solaris/native/java/util/TimeZone_md.c b/jdk/src/solaris/native/java/util/TimeZone_md.c
index 07f7eab..2d0aaee 100644
--- a/jdk/src/solaris/native/java/util/TimeZone_md.c
+++ b/jdk/src/solaris/native/java/util/TimeZone_md.c
@@ -49,7 +49,8 @@
 #define fileclose       fclose
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+
 
 static const char *ETC_TIMEZONE_FILE = "/etc/timezone";
 static const char *ZONEINFO_DIR = "/usr/share/zoneinfo";
@@ -122,8 +123,8 @@
         return NULL;
     }
 
-#if defined(__linux__) || (defined(__solaris__) && (defined(_POSIX_PTHREAD_SEMANTICS) || \
-                                                    defined(_LP64)))
+#if defined(__linux__) || defined(MACOSX) || (defined(__solaris__) \
+    && (defined(_POSIX_PTHREAD_SEMANTICS) || defined(_LP64)))
     while (readdir_r(dirp, entry, &dp) == 0 && dp != NULL) {
 #else
     while ((dp = readdir_r(dirp, entry)) != NULL) {
@@ -211,7 +212,7 @@
     return tz;
 }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 
 /*
  * Performs Linux specific mapping and returns a zone ID
@@ -227,6 +228,7 @@
     char *buf;
     size_t size;
 
+#ifdef __linux__
     /*
      * Try reading the /etc/timezone file for Debian distros. There's
      * no spec of the file format available. This parsing assumes that
@@ -250,6 +252,7 @@
             return tz;
         }
     }
+#endif /* __linux__ */
 
     /*
      * Next, try /etc/localtime to find the zone ID.
@@ -624,7 +627,7 @@
 
     tz = getenv("TZ");
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     if (tz == NULL) {
 #else
 #ifdef __solaris__
@@ -665,10 +668,36 @@
     }
     return javatz;
 }
-
 /**
  * Returns a GMT-offset-based zone ID. (e.g., "GMT-08:00")
  */
+
+#ifdef MACOSX
+
+char *
+getGMTOffsetID()
+{
+    time_t offset;
+    char sign, buf[16];
+    struct tm *local_tm;
+    time_t clock;
+
+    clock = time(NULL);
+    tzset();
+    local_tm = localtime(&clock);
+    if (local_tm->tm_gmtoff >= 0) {
+        offset = (time_t) local_tm->tm_gmtoff;
+        sign = "+";
+    } else {
+        offset = (time_t) -local_tm->tm_gmtoff;
+        sign = "-";
+    }
+    sprintf(buf, (const char *)"GMT%c%02d:%02d",
+            sign, (int)(offset/3600), (int)((offset%3600)/60));
+    return strdup(buf);
+}
+#else
+
 char *
 getGMTOffsetID()
 {
@@ -703,3 +732,4 @@
             sign, (int)(offset/3600), (int)((offset%3600)/60));
     return strdup(buf);
 }
+#endif /* MACOSX */
diff --git a/jdk/src/solaris/native/sun/awt/CUPSfuncs.c b/jdk/src/solaris/native/sun/awt/CUPSfuncs.c
index 2d0d286a..a0d51f1 100644
--- a/jdk/src/solaris/native/sun/awt/CUPSfuncs.c
+++ b/jdk/src/solaris/native/sun/awt/CUPSfuncs.c
@@ -25,6 +25,7 @@
 
 #include <jni.h>
 #include <jni_util.h>
+#include <jvm_md.h>
 #include <dlfcn.h>
 #include <cups/cups.h>
 #include <cups/ppd.h>
@@ -65,10 +66,11 @@
 JNIEXPORT jboolean JNICALL
 Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env,
                                          jobject printObj) {
-  void *handle = dlopen("libcups.so.2", RTLD_LAZY | RTLD_GLOBAL);
+  void *handle = dlopen(VERSIONED_JNI_LIB_NAME("cups", "2"),
+                        RTLD_LAZY | RTLD_GLOBAL);
 
   if (handle == NULL) {
-    handle = dlopen("libcups.so", RTLD_LAZY | RTLD_GLOBAL);
+    handle = dlopen(JNI_LIB_NAME("cups"), RTLD_LAZY | RTLD_GLOBAL);
     if (handle == NULL) {
       return JNI_FALSE;
     }
diff --git a/jdk/src/solaris/native/sun/awt/VDrawingArea.c b/jdk/src/solaris/native/sun/awt/VDrawingArea.c
index d8735f3..c9ce812 100644
--- a/jdk/src/solaris/native/sun/awt/VDrawingArea.c
+++ b/jdk/src/solaris/native/sun/awt/VDrawingArea.c
@@ -31,7 +31,7 @@
 #endif /* !HEADLESS */
 
 #include <stdio.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #ifdef __linux__
 /* XXX: Shouldn't be necessary. */
diff --git a/jdk/src/solaris/native/sun/awt/X11Color.c b/jdk/src/solaris/native/sun/awt/X11Color.c
index 602962a..788c5f2 100644
--- a/jdk/src/solaris/native/sun/awt/X11Color.c
+++ b/jdk/src/solaris/native/sun/awt/X11Color.c
@@ -33,7 +33,6 @@
 #include <math.h>
 #include <sys/time.h>
 #include <sys/resource.h>
-#include <alloca.h>
 #ifndef HEADLESS
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
diff --git a/jdk/src/solaris/native/sun/awt/XDrawingArea.c b/jdk/src/solaris/native/sun/awt/XDrawingArea.c
index bd14768..cfef8cf 100644
--- a/jdk/src/solaris/native/sun/awt/XDrawingArea.c
+++ b/jdk/src/solaris/native/sun/awt/XDrawingArea.c
@@ -31,7 +31,7 @@
 #include <Xm/XmP.h>
 
 #include <stdio.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #ifdef DEBUG
 #include <jvm.h>  /* To get jio_fprintf() */
diff --git a/jdk/src/solaris/native/sun/awt/awt_Font.c b/jdk/src/solaris/native/sun/awt/awt_Font.c
index 871a19c..c36ab51 100644
--- a/jdk/src/solaris/native/sun/awt/awt_Font.c
+++ b/jdk/src/solaris/native/sun/awt/awt_Font.c
@@ -334,7 +334,7 @@
             if (strcmp(style, "regular") == 0) {
                 altstyle = "roman";
             }
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
             if (!strcmp(family, "lucidasans")) {
                 family = "lucida";
             }
diff --git a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
index 301df87..53f9f57 100644
--- a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
+++ b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
@@ -40,6 +40,7 @@
 #include <jni.h>
 #include <jni_util.h>
 #include <jvm.h>
+#include <jvm_md.h>
 #include <jlong.h>
 
 #include <stdlib.h>
@@ -122,7 +123,7 @@
  */
 
 #define MAXFRAMEBUFFERS 16
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 typedef struct {
    int   screen_number;
    short x_org;
@@ -427,6 +428,17 @@
     {
         xrenderLibHandle = dlopen("libXrender.so.1", RTLD_LAZY | RTLD_GLOBAL);
 
+#ifdef MACOSX
+#define XRENDER_LIB "/usr/X11/lib/libXrender.dylib"
+#else
+#define XRENDER_LIB "libXrender.so"
+#endif
+
+        if (xrenderLibHandle == NULL) {
+            xrenderLibHandle = dlopen(XRENDER_LIB,
+                                      RTLD_LAZY | RTLD_GLOBAL);
+        }
+
 #ifndef __linux__ /* SOLARIS */
         if (xrenderLibHandle == NULL) {
             xrenderLibHandle = dlopen("/usr/sfw/lib/libXrender.so.1",
@@ -640,19 +652,22 @@
 #endif /* HEADLESS */
 
 #ifndef HEADLESS
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 static void xinerama_init_linux()
 {
-    void* libHandle = 0;
-    char* XineramaLibName= "libXinerama.so.1";
+    void* libHandle = NULL;
     int32_t locNumScr = 0;
     XineramaScreenInfo *xinInfo;
     char* XineramaQueryScreensName = "XineramaQueryScreens";
     XineramaQueryScreensFunc* XineramaQueryScreens = NULL;
 
     /* load library */
-    libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL);
-    if (libHandle != 0) {
+    libHandle = dlopen(VERSIONED_JNI_LIB_NAME("Xinerama", "1"),
+                       RTLD_LAZY | RTLD_GLOBAL);
+    if (libHandle == NULL) {
+        libHandle = dlopen(JNI_LIB_NAME("Xinerama"), RTLD_LAZY | RTLD_GLOBAL);
+    }
+    if (libHandle != NULL) {
         XineramaQueryScreens = (XineramaQueryScreensFunc*)
             dlsym(libHandle, XineramaQueryScreensName);
 
@@ -688,11 +703,10 @@
     }
 }
 #endif
-#ifndef __linux__ /* Solaris */
+#if !defined(__linux__) && !defined(MACOSX) /* Solaris */
 static void xinerama_init_solaris()
 {
-    void* libHandle = 0;
-    char* XineramaLibName= "libXext.so";
+    void* libHandle = NULL;
     unsigned char fbhints[MAXFRAMEBUFFERS];
     int32_t locNumScr = 0;
     /* load and run XineramaGetInfo */
@@ -701,8 +715,8 @@
     XineramaGetInfoFunc* XineramaSolarisFunc = NULL;
 
     /* load library */
-    libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL);
-    if (libHandle != 0) {
+    libHandle = dlopen(JNI_LIB_NAME("Xext"), RTLD_LAZY | RTLD_GLOBAL);
+    if (libHandle != NULL) {
         XineramaSolarisFunc = (XineramaGetInfoFunc*)dlsym(libHandle, XineramaGetInfoName);
         XineramaSolarisCenterFunc =
             (XineramaGetCenterHintFunc*)dlsym(libHandle, XineramaGetCenterHintName);
@@ -749,11 +763,11 @@
     }
 
     DTRACE_PRINTLN("Xinerama extension is available");
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     xinerama_init_linux();
 #else /* Solaris */
     xinerama_init_solaris();
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
 }
 #endif /* HEADLESS */
 
@@ -1628,7 +1642,7 @@
 {
     jobject point = NULL;
 #ifndef HEADLESS    /* return NULL in HEADLESS, Linux */
-#ifndef __linux__
+#if !defined(__linux__) && !defined(MACOSX)
     int x,y;
 
     AWT_LOCK();
@@ -1641,7 +1655,7 @@
         DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null");
     }
     AWT_FLUSH_UNLOCK();
-#endif /* __linux __ */
+#endif /* __linux __ || MACOSX */
 #endif /* HEADLESS */
     return point;
 }
@@ -1711,7 +1725,11 @@
 {
     int rr_maj_ver = 0, rr_min_ver = 0;
 
-    void *pLibRandR = dlopen("libXrandr.so.2", RTLD_LAZY | RTLD_LOCAL);
+    void *pLibRandR = dlopen(VERSIONED_JNI_LIB_NAME("Xrandr", "2"),
+                             RTLD_LAZY | RTLD_LOCAL);
+    if (pLibRandR == NULL) {
+        pLibRandR = dlopen(JNI_LIB_NAME("Xrandr"), RTLD_LAZY | RTLD_LOCAL);
+    }
     if (pLibRandR == NULL) {
         J2dRlsTraceLn(J2D_TRACE_ERROR,
                       "X11GD_InitXrandrFuncs: Could not open libXrandr.so.2");
diff --git a/jdk/src/solaris/native/sun/awt/awt_InputMethod.c b/jdk/src/solaris/native/sun/awt/awt_InputMethod.c
index 116a531..d55ed83 100644
--- a/jdk/src/solaris/native/sun/awt/awt_InputMethod.c
+++ b/jdk/src/solaris/native/sun/awt/awt_InputMethod.c
@@ -67,7 +67,7 @@
                                 XIMPreeditDrawCallbackStruct *);
 static void PreeditCaretCallback(XIC, XPointer,
                                  XIMPreeditCaretCallbackStruct *);
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 static void StatusStartCallback(XIC, XPointer, XPointer);
 static void StatusDoneCallback(XIC, XPointer, XPointer);
 static void StatusDrawCallback(XIC, XPointer,
@@ -81,7 +81,7 @@
 #define PreeditDoneIndex        1
 #define PreeditDrawIndex        2
 #define PreeditCaretIndex       3
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 #define StatusStartIndex        4
 #define StatusDoneIndex         5
 #define StatusDrawIndex         6
@@ -99,14 +99,14 @@
     (XIMProc)PreeditDoneCallback,
     (XIMProc)PreeditDrawCallback,
     (XIMProc)PreeditCaretCallback,
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     (XIMProc)StatusStartCallback,
     (XIMProc)StatusDoneCallback,
     (XIMProc)StatusDrawCallback,
 #endif
 };
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 #define MAX_STATUS_LEN  100
 typedef struct {
     Window   w;                /*status window id        */
@@ -146,7 +146,7 @@
 #endif /* XAWT */
     jobject     x11inputmethod; /* global ref to X11InputMethod instance */
                                 /* associated with the XIC */
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     StatusWindow *statusWindow; /* our own status window  */
 #else
 #ifndef XAWT
@@ -425,7 +425,7 @@
 static void
 freeX11InputMethodData(JNIEnv *env, X11InputMethodData *pX11IMData)
 {
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     if (pX11IMData->statusWindow != NULL){
         StatusWindow *sw = pX11IMData->statusWindow;
         XFreeGC(awt_display, sw->lightGC);
@@ -531,7 +531,7 @@
     pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance);
 
     if (pX11IMData == NULL) {
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
         return False;
 #else
         return result;
@@ -539,7 +539,7 @@
     }
 
     if ((ic = pX11IMData->current_ic) == (XIC)0){
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
         return False;
 #else
         return result;
@@ -648,7 +648,7 @@
     return result;
 }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 static StatusWindow *createStatusWindow(
 #ifdef XAWT
                                 Window parent) {
@@ -993,7 +993,7 @@
         }
     }
 }
-#endif  /*__linux__*/
+#endif  /* __linux__ || MACOSX */
 /*
  * Creates two XICs, one for active clients and the other for passive
  * clients. All information on those XICs are stored in the
@@ -1050,7 +1050,7 @@
         return FALSE ;
     }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     on_the_spot_styles |= XIMStatusNothing;
 
     /*kinput does not support XIMPreeditCallbacks and XIMStatusArea
@@ -1063,7 +1063,7 @@
             break;
         }
     }
-#else /*! __linux__ */
+#else /*! __linux__ && !MACOSX */
 #ifdef XAWT
     on_the_spot_styles |= XIMStatusNothing;
 #else /* !XAWT */
@@ -1086,7 +1086,7 @@
         on_the_spot_styles |= XIMStatusNothing;
 
 #endif /* XAWT */
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
 
     for (i = 0; i < im_styles->count_styles; i++) {
         active_styles |= im_styles->supported_styles[i] & on_the_spot_styles;
@@ -1134,7 +1134,7 @@
                         NULL);
         if (preedit == (XVaNestedList)NULL)
             goto err;
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
         /*always try XIMStatusCallbacks for active client...*/
         {
             status = (XVaNestedList)XVaCreateNestedList(0,
@@ -1156,7 +1156,7 @@
             XFree((void *)status);
             XFree((void *)preedit);
         }
-#else /* !__linux__ */
+#else /* !__linux__ && !MACOSX */
 #ifndef XAWT
         if (on_the_spot_styles & XIMStatusArea) {
             Widget parent;
@@ -1184,7 +1184,7 @@
         }
 #endif /* XAWT */
         XFree((void *)preedit);
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
         pX11IMData->ic_passive = XCreateIC(X11im,
                                            XNClientWindow, w,
                                            XNFocusWindow, w,
@@ -1343,7 +1343,7 @@
 
 }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 static void
 StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data)
 {
@@ -1411,7 +1411,7 @@
  finally:
     AWT_UNLOCK();
 }
-#endif /*__linux__*/
+#endif /* __linux__ || MACOSX */
 
 static void CommitStringCallback(XIC ic, XPointer client_data, XPointer call_data) {
     JNIEnv *env = GetJNIEnv();
@@ -1517,14 +1517,14 @@
 /* Use IMInstantiate call back only on Linux, as there is a bug in Solaris
    (4768335)
 */
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     registered = XRegisterIMInstantiateCallback(dpy, NULL, NULL,
                      NULL, (XIDProc)OpenXIMCallback, NULL);
     if (!registered) {
         /* directly call openXIM callback */
 #endif
         OpenXIMCallback(dpy, NULL, NULL);
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     }
 #endif
 
@@ -1588,13 +1588,13 @@
 #endif /* XAWT */
     globalRef = (*env)->NewGlobalRef(env, this);
     pX11IMData->x11inputmethod = globalRef;
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     pX11IMData->statusWindow = NULL;
-#else /* __linux__ */
+#else /* !__linux__ && !MACOSX */
 #ifndef XAWT
     pX11IMData->statusWidget = (Widget) NULL;
 #endif /* XAWT */
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
 
     pX11IMData->lookup_buf = 0;
     pX11IMData->lookup_buf_len = 0;
@@ -1741,14 +1741,14 @@
         setXICFocus(pX11IMData->current_ic, req);
         currentX11InputMethodInstance = pX11IMData->x11inputmethod;
         currentFocusWindow =  w;
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
         if (active && pX11IMData->statusWindow && pX11IMData->statusWindow->on)
             onoffStatusWindow(pX11IMData, w, True);
 #endif
     } else {
         currentX11InputMethodInstance = NULL;
         currentFocusWindow = 0;
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
         onoffStatusWindow(pX11IMData, 0, False);
         if (pX11IMData->current_ic != NULL)
 #endif
@@ -1765,7 +1765,7 @@
 Java_sun_awt_X11InputMethod_turnoffStatusWindow(JNIEnv *env,
                                                 jobject this)
 {
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     X11InputMethodData *pX11IMData;
     StatusWindow *statusWindow;
 
@@ -1862,7 +1862,7 @@
     X11InputMethodData *pX11IMData;
     XVaNestedList status;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
       /*do nothing for linux? */
 #else
     AWT_LOCK();
@@ -1968,7 +1968,7 @@
 JNIEXPORT void JNICALL Java_sun_awt_X11_XInputMethod_adjustStatusWindow
   (JNIEnv *env, jobject this, jlong window)
 {
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     AWT_LOCK();
     adjustStatusWindow(window);
     AWT_UNLOCK();
diff --git a/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c b/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c
index fa75aa2..3dc44c8 100644
--- a/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c
+++ b/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c
@@ -79,16 +79,14 @@
     Dl_info dlinfo;
     char buf[MAXPATHLEN];
     int32_t len;
-    char *p;
+    char *p, *tk = 0;
     JNI_OnLoad_type *JNI_OnLoad_ptr;
     struct utsname name;
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2);
     void *v;
     char *envvar;
-    int xt_before_xm = 0;
-    int XAWT = 0;
-    jstring toolkit = NULL;
-    jstring propname = NULL;
+    jstring fmanager = NULL;
+    jstring fmProp = NULL;
 
     if (awtHandle != NULL) {
         /* Avoid several loading attempts */
@@ -104,50 +102,53 @@
     p = strrchr(buf, '/');
 
     /*
-     * The code below is responsible for:
-     * 1. Loading appropriate awt library, i.e. xawt/libmawt or headless/libwawt
-     * 2. Setting "awt.toolkit" system property to use the appropriate Java toolkit class,
-     *    (if user has specified the toolkit in env varialble)
+     * 1. Set the "sun.font.fontmanager" system property,
+     * 2. Choose the library image name.
      */
 
-    propname = (*env)->NewStringUTF(env, "awt.toolkit");
+    fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager");
     /* Check if toolkit is specified in env variable */
+#ifdef MACOSX
     envvar = getenv("AWT_TOOLKIT");
-    if (envvar) {
-        if (strstr(envvar, "XToolkit")) {
-            toolkit = (*env)->NewStringUTF(env, "sun.awt.X11.XToolkit");
-        }
-        /* If user specified toolkit then set java system property */
-        if (toolkit && propname) {
-            JNU_CallStaticMethodByName (env,
-                                        NULL,
-                                        "java/lang/System",
-                                        "setProperty",
-                                        "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
-                                        propname,toolkit);
-        }
+    if (envvar && strstr(envvar, "XToolkit")) {
+#endif
+        fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager");
+        tk = "/xawt/libmawt";
+#ifdef MACOSX
+    } else {
+        fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager");
+        tk = "/lwawt/liblwawt";
+    }
+#endif
+    if (fmanager && fmProp) {
+        JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty",
+                                   "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
+                                   fmProp, fmanager);
     }
 
     /* Calculate library name to load */
+#ifndef MACOSX
     if (AWTIsHeadless()) {
-        strncpy(p, "/headless/libmawt.so", MAXPATHLEN-len-1);
-    } else {
-        /* Default AWT Toolkit on Linux and Solaris is XAWT. */
-        strncpy(p, "/xawt/libmawt.so", MAXPATHLEN-len-1);
+        strcpy(p, "/headless/libmawt");
+    } else if (tk) {
+#endif
+        strcpy(p, tk);
+#ifndef MACOSX
     }
+#endif
 
-    if (toolkit) {
-        (*env)->DeleteLocalRef(env, toolkit);
+#ifdef MACOSX
+    strcat(p, ".dylib");
+#else
+    strcat(p, ".so");
+#endif
+
+    if (tk) {
+        JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
+                                   "(Ljava/lang/String;)V",
+                                   JNU_NewStringPlatform(env, buf));
+            awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
     }
-    if (propname) {
-        (*env)->DeleteLocalRef(env, propname);
-    }
-
-    JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
-                               "(Ljava/lang/String;)V",
-                               JNU_NewStringPlatform(env, buf));
-
-    awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
 
     return JNI_VERSION_1_2;
 }
@@ -253,6 +254,10 @@
  * Reflect this call over to the correct libmawt.so.
  */
 
+/*
+ * TODO: implement for LWCToolkit, MacOSX
+ */
+
 REFLECT_VOID_FUNCTION(getAwtLockFunctions,
                       (void (**AwtLock)(JNIEnv *), void (**AwtUnlock)(JNIEnv *),
                        void (**AwtNoFlushUnlock)(JNIEnv *), void *reserved),
diff --git a/jdk/src/solaris/native/sun/awt/awt_MToolkit.c b/jdk/src/solaris/native/sun/awt/awt_MToolkit.c
index 3a7c117..e341153 100644
--- a/jdk/src/solaris/native/sun/awt/awt_MToolkit.c
+++ b/jdk/src/solaris/native/sun/awt/awt_MToolkit.c
@@ -63,8 +63,9 @@
 extern JavaVM *jvm;
 
 #ifndef HEADLESS
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 extern void statusWindowEventHandler(XEvent event);
+Boolean awt_dnd_process_event(XEvent* event);
 #endif
 #endif /* !HEADLESS */
 
@@ -1642,7 +1643,7 @@
               */
               Widget widget=XtWindowToWidget(awt_display, xev.xany.window);
               eventNumber++;
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
               statusWindowEventHandler(xev);
 #endif
               xembed_eventHandler(&xev);
diff --git a/jdk/src/solaris/native/sun/awt/awt_Mlib.c b/jdk/src/solaris/native/sun/awt/awt_Mlib.c
index 0cfff16..fb00d4d 100644
--- a/jdk/src/solaris/native/sun/awt/awt_Mlib.c
+++ b/jdk/src/solaris/native/sun/awt/awt_Mlib.c
@@ -32,6 +32,7 @@
 #include <dlfcn.h>
 #include "jni.h"
 #include <jni_util.h>
+#include "jvm_md.h"
 #include "awt_Mlib.h"
 #include "java_awt_image_BufferedImage.h"
 
@@ -67,11 +68,11 @@
         ((strncmp(name.machine, "sun4v" , 5) == 0) &&
          (getenv("USE_VIS_ON_SUN4V") != NULL)))
     {
-        handle = dlopen("libmlib_image_v.so", RTLD_LAZY);
+        handle = dlopen(JNI_LIB_NAME("mlib_image_v"), RTLD_LAZY);
     }
 
     if (handle == NULL) {
-        handle = dlopen("libmlib_image.so", RTLD_LAZY);
+        handle = dlopen(JNI_LIB_NAME("mlib_image"), RTLD_LAZY);
     }
 
     if (handle == NULL) {
diff --git a/jdk/src/solaris/native/sun/awt/awt_Robot.c b/jdk/src/solaris/native/sun/awt/awt_Robot.c
index c3384b2..97d57cd 100644
--- a/jdk/src/solaris/native/sun/awt/awt_Robot.c
+++ b/jdk/src/solaris/native/sun/awt/awt_Robot.c
@@ -45,7 +45,7 @@
 #include "wsutils.h"
 #include "list.h"
 #include "multiVis.h"
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 #include <sys/socket.h>
 #endif
 
diff --git a/jdk/src/solaris/native/sun/awt/awt_util.h b/jdk/src/solaris/native/sun/awt/awt_util.h
index 38e2fbc..9c6abc2 100644
--- a/jdk/src/solaris/native/sun/awt/awt_util.h
+++ b/jdk/src/solaris/native/sun/awt/awt_util.h
@@ -187,15 +187,20 @@
 #ifdef __solaris__
 extern Widget awt_util_getXICStatusAreaWindow(Widget w);
 #else
+#if defined(MACOSX)
+int32_t awt_util_getIMStatusHeight(Widget vw);
+Widget awt_util_getXICStatusAreaWindow(Widget w);
+#else
 int32_t awt_util_getIMStatusHeight(Widget vw);
 XVaNestedList awt_util_getXICStatusAreaList(Widget w);
 Widget awt_util_getXICStatusAreaWindow(Widget w);
 #endif
+#endif
 
 
 
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 typedef struct _XmImRefRec {
   Cardinal      num_refs;       /* Number of referencing widgets. */
   Cardinal      max_refs;       /* Maximum length of refs array. */
diff --git a/jdk/src/solaris/native/sun/awt/extutil.h b/jdk/src/solaris/native/sun/awt/extutil.h
index 9576a63..ba9f75a 100644
--- a/jdk/src/solaris/native/sun/awt/extutil.h
+++ b/jdk/src/solaris/native/sun/awt/extutil.h
@@ -58,7 +58,7 @@
  */
 /* $XFree86: xc/include/extensions/extutil.h,v 1.5 2001/01/17 17:53:20 dawes Exp $ */
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 
 #ifndef _EXTUTIL_H_
 #define _EXTUTIL_H_
@@ -248,4 +248,4 @@
         char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n)
 #endif
 
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
diff --git a/jdk/src/solaris/native/sun/awt/fontpath.c b/jdk/src/solaris/native/sun/awt/fontpath.c
index db6f8fa..e549b4f 100644
--- a/jdk/src/solaris/native/sun/awt/fontpath.c
+++ b/jdk/src/solaris/native/sun/awt/fontpath.c
@@ -23,7 +23,7 @@
  * questions.
  */
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 #include <string.h>
 #endif /* __linux__ */
 #include <stdio.h>
@@ -40,6 +40,7 @@
 
 #include <jni.h>
 #include <jni_util.h>
+#include <jvm_md.h>
 #include <sun_font_FontManager.h>
 #ifndef HEADLESS
 #include <X11/Xlib.h>
@@ -58,10 +59,26 @@
 extern Display *awt_display;
 #endif /* !HEADLESS */
 
+#ifdef MACOSX
+
+//
+// XXXDARWIN: Hard-code the path to Apple's fontconfig, as it is
+// not included in the dyld search path by default, and 10.4
+// does not support -rpath.
+//
+// This ignores the build time setting of ALT_FREETYPE_LIB_PATH,
+// and should be replaced with -rpath/@rpath support on 10.5 or later,
+// or via support for a the FREETYPE_LIB_PATH define.
+#define FONTCONFIG_DLL_VERSIONED X11_PATH "/lib/" VERSIONED_JNI_LIB_NAME("fontconfig", "1")
+#define FONTCONFIG_DLL X11_PATH "/lib/" JNI_LIB_NAME("fontconfig")
+#else
+#define FONTCONFIG_DLL_VERSIONED VERSIONED_JNI_LIB_NAME("fontconfig", "1")
+#define FONTCONFIG_DLL JNI_LIB_NAME("fontconfig")
+#endif
 
 #define MAXFDIRS 512    /* Max number of directories that contain fonts */
 
-#ifndef __linux__
+#if !defined(__linux__) && !defined(MACOSX)
 /*
  * This can be set in the makefile to "/usr/X11" if so desired.
  */
@@ -111,6 +128,22 @@
     NULL, /* terminates the list */
 };
 
+#elif MACOSX
+static char *full_MACOSX_X11FontPath[] = {
+    X11_PATH "/lib/X11/fonts/TrueType",
+    X11_PATH "/lib/X11/fonts/truetype",
+    X11_PATH "/lib/X11/fonts/tt",
+    X11_PATH "/lib/X11/fonts/TTF",
+    X11_PATH "/lib/X11/fonts/OTF",
+    PACKAGE_PATH "/share/fonts/TrueType",
+    PACKAGE_PATH "/share/fonts/truetype",
+    PACKAGE_PATH "/share/fonts/tt",
+    PACKAGE_PATH "/share/fonts/TTF",
+    PACKAGE_PATH "/share/fonts/OTF",
+    X11_PATH "/lib/X11/fonts/Type1",
+    PACKAGE_PATH "/share/fonts/Type1",
+    NULL, /* terminates the list */
+};
 #else /* __linux */
 /* All the known interesting locations we have discovered on
  * various flavors of Linux
@@ -362,7 +395,7 @@
 
 #endif /* !HEADLESS */
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 /* from awt_LoadLibrary.c */
 JNIEXPORT jboolean JNICALL AWTIsHeadless();
 #endif
@@ -487,8 +520,10 @@
      */
     fcdirs = getFontConfigLocations();
 
-#ifdef __linux__
+#if defined(__linux__)
     knowndirs = fullLinuxFontPath;
+#elif defined(MACOSX)
+    knowndirs = full_MACOSX_X11FontPath;
 #else /* IF SOLARIS */
     knowndirs = fullSolarisFontPath;
 #endif
@@ -499,7 +534,8 @@
      * be initialised.
      */
 #ifndef HEADLESS
-#ifdef __linux__        /* There's no headless build on linux ... */
+#if defined(__linux__) || defined(MACOSX)
+    /* There's no headless build on linux ... */
     if (!AWTIsHeadless()) { /* .. so need to call a function to check */
 #endif
       /* Using the X11 font path to locate font files is now a fallback
@@ -514,7 +550,7 @@
         x11dirs = getX11FontPath();
     }
     AWT_UNLOCK();
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     }
 #endif
 #endif /* !HEADLESS */
@@ -547,7 +583,7 @@
 }
 
 #include <dlfcn.h>
-#ifndef __linux__ /* i.e. is solaris */
+#if !(defined(__linux__) || defined(MACOSX))
 #include <link.h>
 #endif
 
@@ -593,9 +629,9 @@
      * certain symbols - and functionality - to be available.
      * Also add explicit search for .so.1 in case .so symlink doesn't exist.
      */
-    libfontconfig = dlopen("libfontconfig.so.1", RTLD_LOCAL|RTLD_LAZY);
+    libfontconfig = dlopen(FONTCONFIG_DLL_VERSIONED, RTLD_LOCAL|RTLD_LAZY);
     if (libfontconfig == NULL) {
-        libfontconfig = dlopen("libfontconfig.so", RTLD_LOCAL|RTLD_LAZY);
+        libfontconfig = dlopen(FONTCONFIG_DLL, RTLD_LOCAL|RTLD_LAZY);
         if (libfontconfig == NULL) {
             return NULL;
         }
diff --git a/jdk/src/solaris/native/sun/awt/gtk2_interface.c b/jdk/src/solaris/native/sun/awt/gtk2_interface.c
index 3c0c3cc..cb93366 100644
--- a/jdk/src/solaris/native/sun/awt/gtk2_interface.c
+++ b/jdk/src/solaris/native/sun/awt/gtk2_interface.c
@@ -30,9 +30,12 @@
 #include <string.h>
 #include "gtk2_interface.h"
 #include "java_awt_Transparency.h"
+#include "jvm_md.h"
 
-#define GTK2_LIB "libgtk-x11-2.0.so.0"
-#define GTHREAD_LIB "libgthread-2.0.so.0"
+#define GTK2_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0")
+#define GTK2_LIB JNI_LIB_NAME("gtk-x11-2.0")
+#define GTHREAD_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gthread-2.0", "0")
+#define GTHREAD_LIB JNI_LIB_NAME("gthread-2.0")
 
 #define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
 #define G_TYPE_NONE                     G_TYPE_MAKE_FUNDAMENTAL (1)
@@ -414,9 +417,12 @@
         void *lib = NULL;
         gboolean result = FALSE;
 
-        lib = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
+        lib = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
         if (lib == NULL) {
-            return FALSE;
+            lib = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
+            if (lib == NULL) {
+                return FALSE;
+            }
         }
 
         fp_gtk_check_version = dlsym(lib, "gtk_check_version");
@@ -470,11 +476,19 @@
     int (*io_handler)();
     char *gtk_modules_env;
 
-    gtk2_libhandle = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
-    gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
+    gtk2_libhandle = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
+    if (gtk2_libhandle == NULL) {
+        gtk2_libhandle = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
+        if (gtk2_libhandle == NULL)
+            return FALSE;
+    }
 
-    if (gtk2_libhandle == NULL || gthread_libhandle == NULL)
-        return FALSE;
+    gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
+    if (gthread_libhandle == NULL) {
+        gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
+        if (gthread_libhandle == NULL)
+            return FALSE;
+    }
 
     if (setjmp(j) == 0)
     {
diff --git a/jdk/src/solaris/native/sun/awt/jawt.c b/jdk/src/solaris/native/sun/awt/jawt.c
index f6f8530..99cdb2a 100644
--- a/jdk/src/solaris/native/sun/awt/jawt.c
+++ b/jdk/src/solaris/native/sun/awt/jawt.c
@@ -42,7 +42,8 @@
     }
 
     if (awt->version != JAWT_VERSION_1_3
-        && awt->version != JAWT_VERSION_1_4) {
+        && awt->version != JAWT_VERSION_1_4
+        && awt->version != JAWT_VERSION_1_7) {
         return JNI_FALSE;
     }
 
diff --git a/jdk/src/solaris/native/sun/awt/list.c b/jdk/src/solaris/native/sun/awt/list.c
index f3b2aaa..af3fcb9 100644
--- a/jdk/src/solaris/native/sun/awt/list.c
+++ b/jdk/src/solaris/native/sun/awt/list.c
@@ -66,7 +66,7 @@
   ----------------------------------------------------------------------- **/
 
 #include <stdio.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include "list.h"
 
 
diff --git a/jdk/src/solaris/native/sun/awt/robot_common.c b/jdk/src/solaris/native/sun/awt/robot_common.c
index 4830b04..c002ebc 100644
--- a/jdk/src/solaris/native/sun/awt/robot_common.c
+++ b/jdk/src/solaris/native/sun/awt/robot_common.c
@@ -27,6 +27,10 @@
     #error This file should not be included in headless library
 #endif
 
+#ifdef MACOSX
+#include <stdlib.h>
+#endif
+
 #include "robot_common.h"
 
 /*
diff --git a/jdk/src/solaris/native/sun/font/X11FontScaler.c b/jdk/src/solaris/native/sun/font/X11FontScaler.c
index 1867b49..5808da4 100644
--- a/jdk/src/solaris/native/sun/font/X11FontScaler.c
+++ b/jdk/src/solaris/native/sun/font/X11FontScaler.c
@@ -32,7 +32,7 @@
  * into X11FontScaler_md.c, which is compiled into another library.
  */
 #include <stdio.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <ctype.h>
 #include <sys/utsname.h>
 
diff --git a/jdk/src/solaris/native/sun/font/X11TextRenderer.c b/jdk/src/solaris/native/sun/font/X11TextRenderer.c
index fdce447..381c0b8 100644
--- a/jdk/src/solaris/native/sun/font/X11TextRenderer.c
+++ b/jdk/src/solaris/native/sun/font/X11TextRenderer.c
@@ -39,7 +39,7 @@
 #include "GraphicsPrimitiveMgr.h"
 #include "glyphblitting.h"
 #include "sunfontids.h"
-#include <malloc.h>
+#include <stdlib.h>
 
 
 JNIEXPORT void JNICALL AWTDrawGlyphList
diff --git a/jdk/src/solaris/native/sun/java2d/j2d_md.h b/jdk/src/solaris/native/sun/java2d/j2d_md.h
index 38b9924..3f5578f 100644
--- a/jdk/src/solaris/native/sun/java2d/j2d_md.h
+++ b/jdk/src/solaris/native/sun/java2d/j2d_md.h
@@ -28,11 +28,11 @@
 #include <sys/types.h>
 
 /*
- * Linux version of <sys/types.h> does not define intptr_t
+ * Linux and MACOSX's version of <sys/types.h> does not define intptr_t
  */
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 #include <stdint.h>
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
 
 typedef unsigned char   jubyte;
 typedef unsigned short  jushort;
diff --git a/jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c b/jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c
index e5a1e3d..d9e27f9 100644
--- a/jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c
+++ b/jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c
@@ -63,6 +63,9 @@
  *    MLIB_EDGE_SRC_PADDED
  */
 
+#ifdef MACOSX
+#include <machine/endian.h>
+#endif
 #include <mlib_image.h>
 #include <mlib_ImageZoom.h>
 
diff --git a/jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c b/jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c
index 0bc52cb..0c59e10 100644
--- a/jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c
+++ b/jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c
@@ -804,7 +804,7 @@
 static int initialized;
 static int usevis = JNI_TRUE;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 #   define ULTRA_CHIP   "sparc64"
 #else
 #   define ULTRA_CHIP   "sun4u"
diff --git a/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c b/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c
index 76c8c8b..3f4c09f 100644
--- a/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c
+++ b/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c
@@ -487,4 +487,10 @@
     j2d_glXSwapBuffers(awt_display, (Window)window);
 }
 
+// needed by Mac OS X port, no-op on other platforms
+void
+OGLSD_Flush(JNIEnv *env)
+{
+}
+
 #endif /* !HEADLESS */
diff --git a/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h b/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h
index e017cf7..14fe6f1 100644
--- a/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h
+++ b/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h
@@ -27,7 +27,10 @@
 #define OGLFuncs_md_h_Included
 
 #include <stdlib.h>
+#ifndef MACOSX
 #include <link.h>
+#endif
+#include "jvm_md.h"
 #include "J2D_GL/glx.h"
 #include "OGLFuncMacros.h"
 
@@ -113,7 +116,7 @@
     { \
         char *libGLPath = getenv("J2D_ALT_LIBGL_PATH"); \
         if (libGLPath == NULL) { \
-            libGLPath = "libGL.so.1"; \
+            libGLPath = VERSIONED_JNI_LIB_NAME("GL", "1"); \
         } \
         OGL_LIB_HANDLE = dlopen(libGLPath, RTLD_LAZY | RTLD_LOCAL); \
     } \
diff --git a/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c b/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c
index 9b3e706..ec90311 100644
--- a/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c
+++ b/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c
@@ -32,6 +32,7 @@
 #include "gdefs.h"
 
 #include "jni_util.h"
+#include "jvm_md.h"
 #include "awt_Component.h"
 #include "awt_GraphicsEnv.h"
 
@@ -163,7 +164,7 @@
 
     if (tryDGA && (getenv("NO_J2D_DGA") == NULL)) {
     /* we use RTLD_NOW because of bug 4032715 */
-        lib = dlopen("libsunwjdga.so", RTLD_NOW);
+        lib = dlopen(JNI_LIB_NAME("sunwjdga"), RTLD_NOW);
     }
 
     if (lib != NULL) {
diff --git a/jdk/src/solaris/native/sun/java2d/x11/XRSurfaceData.c b/jdk/src/solaris/native/sun/java2d/x11/XRSurfaceData.c
index 5de53ca..b598a22 100644
--- a/jdk/src/solaris/native/sun/java2d/x11/XRSurfaceData.c
+++ b/jdk/src/solaris/native/sun/java2d/x11/XRSurfaceData.c
@@ -29,7 +29,7 @@
 #include "X11SurfaceData.h"
 
 /*#include <xcb/xcb.h>*/
-#include <Xrender.h>
+#include <X11/extensions/Xrender.h>
 
 #ifndef RepeatNone  /* added in 0.10 */
 #define RepeatNone    0
diff --git a/jdk/src/solaris/native/sun/jdga/dgalock.c b/jdk/src/solaris/native/sun/jdga/dgalock.c
index f412d6f..0e9c400 100644
--- a/jdk/src/solaris/native/sun/jdga/dgalock.c
+++ b/jdk/src/solaris/native/sun/jdga/dgalock.c
@@ -44,6 +44,7 @@
 #include <X11/Xlib.h>
 
 #include "jni.h"
+#include "jvm_md.h"
 #include "jdga.h"
 #include "jdgadevice.h"
 
@@ -84,10 +85,10 @@
 static GetVirtualDrawableFunc * GetVirtualDrawable = GetVirtualDrawableStub;
 
 static void Solaris_DGA_XineramaInit(Display *display) {
-    void * handle = 0;
+    void * handle = NULL;
     if (IsXineramaOn == NULL) {
-        handle = dlopen("libxinerama.so", RTLD_NOW);
-        if (handle != 0) {
+        handle = dlopen(JNI_LIB_NAME("xinerama"), RTLD_NOW);
+        if (handle != NULL) {
             void *sym = dlsym(handle, "IsXineramaOn");
             IsXineramaOn = (IsXineramaOnFunc *)sym;
             if (IsXineramaOn != 0 && (*IsXineramaOn)(display)) {
diff --git a/jdk/src/solaris/native/sun/management/FileSystemImpl.c b/jdk/src/solaris/native/sun/management/FileSystemImpl.c
index 3668cac..1efff52 100644
--- a/jdk/src/solaris/native/sun/management/FileSystemImpl.c
+++ b/jdk/src/solaris/native/sun/management/FileSystemImpl.c
@@ -30,6 +30,10 @@
 #include "jni_util.h"
 #include "sun_management_FileSystemImpl.h"
 
+#ifdef _ALLBSD_SOURCE
+#define stat64 stat
+#endif
+
 /*
  * Class:     sun_management_FileSystemImpl
  * Method:    isAccessUserOnly0
diff --git a/jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c b/jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c
index 47d2199..3d26212 100644
--- a/jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c
+++ b/jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c
@@ -33,7 +33,7 @@
 #include <strings.h>
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <string.h>
 #endif
 
diff --git a/jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c b/jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c
index 18313bb..6883902 100644
--- a/jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c
+++ b/jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c
@@ -26,11 +26,12 @@
 #include "jni.h"
 #include "jni_util.h"
 #include "jvm.h"
+#include "jvm_md.h"
 #include "jlong.h"
 #include "sun_net_spi_DefaultProxySelector.h"
 #include <dlfcn.h>
 #include <stdio.h>
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <string.h>
 #else
 #include <strings.h>
@@ -110,8 +111,9 @@
   /**
    * Let's try to load le GConf-2 library
    */
-  if (dlopen("libgconf-2.so", RTLD_GLOBAL | RTLD_LAZY) != NULL ||
-      dlopen("libgconf-2.so.4", RTLD_GLOBAL | RTLD_LAZY) != NULL) {
+  if (dlopen(JNI_LIB_NAME("gconf-2"), RTLD_GLOBAL | RTLD_LAZY) != NULL ||
+      dlopen(VERSIONED_JNI_LIB_NAME("gconf-2", "4"),
+             RTLD_GLOBAL | RTLD_LAZY) != NULL) {
     gconf_ver = 2;
   }
   if (gconf_ver > 0) {
diff --git a/jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c b/jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c
index 598159b..7d42d14 100644
--- a/jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c
+++ b/jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c
@@ -35,7 +35,7 @@
 #include <string.h>
 #include <errno.h>
 
-#if __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <netinet/in.h>
 #endif
 
@@ -86,7 +86,7 @@
     rv = connect(fd, 0, 0);
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     {
         int len;
         SOCKADDR sa;
@@ -96,17 +96,30 @@
 #ifdef AF_INET6
         if (ipv6_available()) {
             struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)&sa;
+#if defined(_ALLBSD_SOURCE)
+            him6->sin6_family = AF_INET6;
+#else
             him6->sin6_family = AF_UNSPEC;
+#endif
             len = sizeof(struct sockaddr_in6);
         } else
 #endif
         {
             struct sockaddr_in *him4 = (struct sockaddr_in*)&sa;
+#if defined(_ALLBSD_SOURCE)
+            him4->sin_family = AF_INET;
+#else
             him4->sin_family = AF_UNSPEC;
+#endif
             len = sizeof(struct sockaddr_in);
         }
 
         rv = connect(fd, (struct sockaddr *)&sa, len);
+
+#if defined(_ALLBSD_SOURCE)
+        if (rv < 0 && errno == EADDRNOTAVAIL)
+                rv = errno = 0;
+#endif
     }
 #endif
 
diff --git a/jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c b/jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c
index 340e781..6d5337c 100644
--- a/jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c
+++ b/jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c
@@ -73,7 +73,7 @@
     m.msg_accrightslen = 0;
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     m.msg_control = NULL;
     m.msg_controllen = 0;
 #endif
@@ -121,7 +121,7 @@
     m.msg_accrightslen = 0;
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     m.msg_control = NULL;
     m.msg_controllen = 0;
 #endif
diff --git a/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c b/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c
index 8083914..8e5c0fd 100644
--- a/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c
+++ b/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c
@@ -26,9 +26,11 @@
 #include "jni.h"
 #include "jni_util.h"
 #include "jvm.h"
+#include "jvm_md.h"
 #include "jlong.h"
 #include <sys/mman.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 #include "sun_nio_ch_FileChannelImpl.h"
 #include "java_lang_Integer.h"
 #include "nio.h"
@@ -37,6 +39,13 @@
 
 #if defined(__linux__) || defined(__solaris__)
 #include <sys/sendfile.h>
+#elif defined(_ALLBSD_SOURCE)
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+#define lseek64 lseek
+#define mmap64 mmap
 #endif
 
 static jfieldID chan_fd;        /* jobject 'fd' in sun.io.FileChannelImpl */
@@ -192,6 +201,33 @@
         return IOS_THROWN;
     }
     return result;
+#elif defined(__APPLE__)
+    off_t numBytes;
+    int result;
+
+    numBytes = count;
+
+#ifdef __APPLE__
+    result = sendfile(srcFD, dstFD, position, &numBytes, NULL, 0);
+#endif
+
+    if (numBytes > 0)
+        return numBytes;
+
+    if (result == -1) {
+        if (errno == EAGAIN)
+            return IOS_UNAVAILABLE;
+        if (errno == EOPNOTSUPP || errno == ENOTSOCK || errno == ENOTCONN)
+            return IOS_UNSUPPORTED_CASE;
+        if ((errno == EINVAL) && ((ssize_t)count >= 0))
+            return IOS_UNSUPPORTED_CASE;
+        if (errno == EINTR)
+            return IOS_INTERRUPTED;
+        JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
+        return IOS_THROWN;
+    }
+
+    return result;
 #else
     return IOS_UNSUPPORTED_CASE;
 #endif
diff --git a/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c b/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c
index 6468ee9..60b6e2c 100644
--- a/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c
+++ b/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c
@@ -33,9 +33,24 @@
 #include <sys/socket.h>
 #include <fcntl.h>
 #include <sys/uio.h>
+#include <unistd.h>
 #include "nio.h"
 #include "nio_util.h"
 
+#ifdef _ALLBSD_SOURCE
+#define stat64 stat
+#define flock64 flock
+#define off64_t off_t
+#define F_SETLKW64 F_SETLKW
+#define F_SETLK64 F_SETLK
+
+#define pread64 pread
+#define pwrite64 pwrite
+#define ftruncate64 ftruncate
+#define fstat64 fstat
+
+#define fdatasync fsync
+#endif
 
 static int preCloseFD = -1;     /* File descriptor to which we dup other fd's
                                    before closing them for real */
diff --git a/jdk/src/solaris/native/sun/nio/ch/FileKey.c b/jdk/src/solaris/native/sun/nio/ch/FileKey.c
index 4ce5130..85719b2 100644
--- a/jdk/src/solaris/native/sun/nio/ch/FileKey.c
+++ b/jdk/src/solaris/native/sun/nio/ch/FileKey.c
@@ -30,6 +30,12 @@
 #include "nio_util.h"
 #include "sun_nio_ch_FileKey.h"
 
+#ifdef _ALLBSD_SOURCE
+#define stat64 stat
+
+#define fstat64 fstat
+#endif
+
 static jfieldID key_st_dev;    /* id for FileKey.st_dev */
 static jfieldID key_st_ino;    /* id for FileKey.st_ino */
 
diff --git a/jdk/src/solaris/native/sun/nio/ch/Net.c b/jdk/src/solaris/native/sun/nio/ch/Net.c
index def9859..04905c6 100644
--- a/jdk/src/solaris/native/sun/nio/ch/Net.c
+++ b/jdk/src/solaris/native/sun/nio/ch/Net.c
@@ -116,6 +116,47 @@
 
 #endif   /* __linux__ */
 
+#ifdef _ALLBSD_SOURCE
+
+#ifndef IP_BLOCK_SOURCE
+
+#define IP_ADD_SOURCE_MEMBERSHIP        70   /* join a source-specific group */
+#define IP_DROP_SOURCE_MEMBERSHIP       71   /* drop a single source */
+#define IP_BLOCK_SOURCE                 72   /* block a source */
+#define IP_UNBLOCK_SOURCE               73   /* unblock a source */
+
+#endif  /* IP_BLOCK_SOURCE */
+
+#ifndef MCAST_BLOCK_SOURCE
+
+#define MCAST_JOIN_SOURCE_GROUP         82   /* join a source-specific group */
+#define MCAST_LEAVE_SOURCE_GROUP        83   /* leave a single source */
+#define MCAST_BLOCK_SOURCE              84   /* block a source */
+#define MCAST_UNBLOCK_SOURCE            85   /* unblock a source */
+
+#endif /* MCAST_BLOCK_SOURCE */
+
+#ifndef IPV6_ADD_MEMBERSHIP
+
+#define IPV6_ADD_MEMBERSHIP     IPV6_JOIN_GROUP
+#define IPV6_DROP_MEMBERSHIP    IPV6_LEAVE_GROUP
+
+#endif /* IPV6_ADD_MEMBERSHIP */
+
+struct my_ip_mreq_source {
+        struct in_addr  imr_multiaddr;
+        struct in_addr  imr_interface;
+        struct in_addr  imr_sourceaddr;
+};
+
+struct my_group_source_req {
+        uint32_t                gsr_interface;  /* interface index */
+        struct sockaddr_storage gsr_group;      /* group address */
+        struct sockaddr_storage gsr_source;     /* source address */
+};
+
+#endif   /* _ALLBSD_SOURCE */
+
 
 #define COPY_INET6_ADDRESS(env, source, target) \
     (*env)->GetByteArrayRegion(env, source, 0, 16, target)
@@ -287,8 +328,30 @@
     SOCKADDR sa;
     socklen_t sa_len = SOCKADDR_LEN;
     if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+#ifdef _ALLBSD_SOURCE
+        /*
+         * XXXBSD:
+         * ECONNRESET is specific to the BSDs. We can not return an error,
+         * as the calling Java code with raise a java.lang.Error given the expectation
+         * that getsockname() will never fail. According to the Single UNIX Specification,
+         * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
+         */
+        if (errno == ECONNRESET) {
+            struct sockaddr_in *sin;
+            sin = (struct sockaddr_in *) &sa;
+            bzero(sin, sizeof(*sin));
+            sin->sin_len  = sizeof(struct sockaddr_in);
+            sin->sin_family = AF_INET;
+            sin->sin_port = htonl(0);
+            sin->sin_addr.s_addr = INADDR_ANY;
+        } else {
+            handleSocketError(env, errno);
+            return -1;
+        }
+#else /* _ALLBSD_SOURCE */
         handleSocketError(env, errno);
         return -1;
+#endif /* _ALLBSD_SOURCE */
     }
     return NET_GetPortFromSockaddr((struct sockaddr *)&sa);
 }
@@ -300,8 +363,30 @@
     socklen_t sa_len = SOCKADDR_LEN;
     int port;
     if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+#ifdef _ALLBSD_SOURCE
+        /*
+         * XXXBSD:
+         * ECONNRESET is specific to the BSDs. We can not return an error,
+         * as the calling Java code with raise a java.lang.Error with the expectation
+         * that getsockname() will never fail. According to the Single UNIX Specification,
+         * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
+         */
+        if (errno == ECONNRESET) {
+            struct sockaddr_in *sin;
+            sin = (struct sockaddr_in *) &sa;
+            bzero(sin, sizeof(*sin));
+            sin->sin_len  = sizeof(struct sockaddr_in);
+            sin->sin_family = AF_INET;
+            sin->sin_port = htonl(0);
+            sin->sin_addr.s_addr = INADDR_ANY;
+        } else {
+            handleSocketError(env, errno);
+            return NULL;
+        }
+#else /* _ALLBSD_SOURCE */
         handleSocketError(env, errno);
         return NULL;
+#endif /* _ALLBSD_SOURCE */
     }
     return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
 }
@@ -365,7 +450,8 @@
     struct linger linger;
     u_char carg;
     void *parg;
-    int arglen, n;
+    socklen_t arglen;
+    int n;
 
     /* Option value is an int except for a few specific cases */
 
@@ -528,7 +614,7 @@
 Java_sun_nio_ch_Net_setInterface4(JNIEnv* env, jobject this, jobject fdo, jint interf)
 {
     struct in_addr in;
-    int arglen = sizeof(struct in_addr);
+    socklen_t arglen = sizeof(struct in_addr);
     int n;
 
     in.s_addr = htonl(interf);
@@ -559,7 +645,7 @@
 Java_sun_nio_ch_Net_setInterface6(JNIEnv* env, jobject this, jobject fdo, jint index)
 {
     int value = (jint)index;
-    int arglen = sizeof(value);
+    socklen_t arglen = sizeof(value);
     int n;
 
     n = setsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF,
@@ -602,9 +688,11 @@
     switch (errorValue) {
         case EINPROGRESS:       /* Non-blocking connect */
             return 0;
+#ifdef EPROTO
         case EPROTO:
             xn = JNU_JAVANETPKG "ProtocolException";
             break;
+#endif
         case ECONNREFUSED:
             xn = JNU_JAVANETPKG "ConnectException";
             break;
diff --git a/jdk/src/solaris/native/sun/nio/ch/Sctp.h b/jdk/src/solaris/native/sun/nio/ch/Sctp.h
index ea5d5a7..0218523 100644
--- a/jdk/src/solaris/native/sun/nio/ch/Sctp.h
+++ b/jdk/src/solaris/native/sun/nio/ch/Sctp.h
@@ -67,7 +67,7 @@
 
 
 
-#else /* __linux__ */
+#elif __linux__
 #include <stdint.h>
 #include <linux/types.h>
 #include <sys/socket.h>
diff --git a/jdk/src/solaris/native/sun/nio/ch/SctpChannelImpl.c b/jdk/src/solaris/native/sun/nio/ch/SctpChannelImpl.c
index 8e40204..a8379f6 100644
--- a/jdk/src/solaris/native/sun/nio/ch/SctpChannelImpl.c
+++ b/jdk/src/solaris/native/sun/nio/ch/SctpChannelImpl.c
@@ -337,11 +337,11 @@
             break;
         case SCTP_ADDR_MADE_PRIM :
             event = sun_nio_ch_SctpPeerAddrChange_SCTP_ADDR_MADE_PRIM;
-#ifdef __linux__  /* Solaris currently doesn't support SCTP_ADDR_CONFIRMED */
+#ifndef __solaris__  /* Solaris currently doesn't support SCTP_ADDR_CONFIRMED */
             break;
         case SCTP_ADDR_CONFIRMED :
             event = sun_nio_ch_SctpPeerAddrChange_SCTP_ADDR_CONFIRMED;
-#endif  /* __linux__ */
+#endif  /* __solaris__ */
     }
 
     addressObj = SockAddrToInetSocketAddress(env, (struct sockaddr*)&spc->spc_aaddr);
diff --git a/jdk/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c b/jdk/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c
new file mode 100644
index 0000000..80342ef
--- /dev/null
+++ b/jdk/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "jni.h"
+#include "jni_util.h"
+#include "jvm.h"
+#include "jlong.h"
+
+#include <sys/param.h>
+#include <sys/mount.h>
+#ifdef ST_RDONLY
+#define statfs statvfs
+#define getfsstat getvfsstat
+#define f_flags f_flag
+#define ISREADONLY ST_RDONLY
+#else
+#define ISREADONLY MNT_RDONLY
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+static jfieldID entry_name;
+static jfieldID entry_dir;
+static jfieldID entry_fstype;
+static jfieldID entry_options;
+static jfieldID entry_dev;
+
+
+struct fsstat_iter {
+    struct statfs *buf;
+    int pos;
+    int nentries;
+};
+
+#include "sun_nio_fs_BsdNativeDispatcher.h"
+
+static void throwUnixException(JNIEnv* env, int errnum) {
+    jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
+        "(I)V", errnum);
+    if (x != NULL) {
+        (*env)->Throw(env, x);
+    }
+}
+
+/**
+ * Initialize jfieldIDs
+ */
+JNIEXPORT void JNICALL
+Java_sun_nio_fs_BsdNativeDispatcher_initIDs(JNIEnv* env, jclass this)
+{
+    jclass clazz;
+
+    clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
+    if (clazz == NULL) {
+        return;
+    }
+    entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
+    entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
+    entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
+    entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
+    entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
+}
+
+JNIEXPORT jlong JNICALL
+Java_sun_nio_fs_BsdNativeDispatcher_getfsstat(JNIEnv* env, jclass this)
+{
+    int nentries;
+    size_t bufsize;
+    struct fsstat_iter *iter = malloc(sizeof(*iter));
+
+    if (iter == NULL) {
+        JNU_ThrowOutOfMemoryError(env, "native heap");
+        return 0;
+    }
+
+    iter->pos = 0;
+    iter->nentries = 0;
+    iter->buf = NULL;
+
+    nentries = getfsstat(NULL, 0, MNT_NOWAIT);
+
+    if (nentries <= 0) {
+        free(iter);
+        throwUnixException(env, errno);
+        return 0;
+    }
+
+    // It's possible that a new filesystem gets mounted between
+    // the first getfsstat and the second so loop until consistant
+
+    while (nentries != iter->nentries) {
+        if (iter->buf != NULL)
+            free(iter->buf);
+
+        bufsize = nentries * sizeof(struct statfs);
+        iter->nentries = nentries;
+
+        iter->buf = malloc(bufsize);
+        if (iter->buf == NULL) {
+            free(iter);
+            JNU_ThrowOutOfMemoryError(env, "native heap");
+            return 0;
+        }
+
+        nentries = getfsstat(iter->buf, bufsize, MNT_WAIT);
+        if (nentries <= 0) {
+            free(iter->buf);
+            free(iter);
+            throwUnixException(env, errno);
+            return 0;
+        }
+    }
+
+    return (jlong)iter;
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_fs_BsdNativeDispatcher_fsstatEntry(JNIEnv* env, jclass this,
+    jlong value, jobject entry)
+{
+    struct fsstat_iter *iter = jlong_to_ptr(value);
+    jsize len;
+    jbyteArray bytes;
+    char* name;
+    char* dir;
+    char* fstype;
+    char* options;
+    dev_t dev;
+
+    if (iter == NULL || iter->pos >= iter->nentries)
+       return -1;
+
+    name = iter->buf[iter->pos].f_mntfromname;
+    dir = iter->buf[iter->pos].f_mntonname;
+    fstype = iter->buf[iter->pos].f_fstypename;
+    if (iter->buf[iter->pos].f_flags & ISREADONLY)
+        options="ro";
+    else
+        options="";
+    dev = 0;
+
+    iter->pos++;
+
+    len = strlen(name);
+    bytes = (*env)->NewByteArray(env, len);
+    if (bytes == NULL)
+        return -1;
+    (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);
+    (*env)->SetObjectField(env, entry, entry_name, bytes);
+
+    len = strlen(dir);
+    bytes = (*env)->NewByteArray(env, len);
+    if (bytes == NULL)
+        return -1;
+    (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);
+    (*env)->SetObjectField(env, entry, entry_dir, bytes);
+
+    len = strlen(fstype);
+    bytes = (*env)->NewByteArray(env, len);
+    if (bytes == NULL)
+        return -1;
+    (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);
+    (*env)->SetObjectField(env, entry, entry_fstype, bytes);
+
+    len = strlen(options);
+    bytes = (*env)->NewByteArray(env, len);
+    if (bytes == NULL)
+        return -1;
+    (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
+    (*env)->SetObjectField(env, entry, entry_options, bytes);
+
+    if (dev != 0)
+        (*env)->SetLongField(env, entry, entry_dev, (jlong)dev);
+
+    return 0;
+}
+
+JNIEXPORT void JNICALL
+Java_sun_nio_fs_BsdNativeDispatcher_endfsstat(JNIEnv* env, jclass this, jlong value)
+{
+    struct fsstat_iter *iter = jlong_to_ptr(value);
+
+    if (iter != NULL) {
+        free(iter->buf);
+        free(iter);
+    }
+}
diff --git a/jdk/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c b/jdk/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c
index 259ae15..7dc606c 100644
--- a/jdk/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c
+++ b/jdk/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c
@@ -30,13 +30,15 @@
 
 #include <stdlib.h>
 #include <dlfcn.h>
+#ifndef __APPLE__
 #include <link.h>
+#endif
 
 #ifdef __solaris__
 #include <strings.h>
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
 #include <string.h>
 #endif
 
diff --git a/jdk/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c b/jdk/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c
index f41409b..c178b12 100644
--- a/jdk/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c
+++ b/jdk/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c
@@ -49,6 +49,19 @@
 #include <mntent.h>
 #endif
 
+#ifdef _ALLBSD_SOURCE
+#include <string.h>
+
+#define stat64 stat
+#define statvfs64 statvfs
+
+#define open64 open
+#define fstat64 fstat
+#define lstat64 lstat
+#define dirent64 dirent
+#define readdir64_r readdir_r
+#endif
+
 #include "jni.h"
 #include "jni_util.h"
 #include "jlong.h"
@@ -198,7 +211,7 @@
 
     /* system calls that might not be available at run time */
 
-#if defined(__solaris__) && defined(_LP64)
+#if (defined(__solaris__) && defined(_LP64)) || defined(_ALLBSD_SOURCE)
     /* Solaris 64-bit does not have openat64/fstatat64 */
     my_openat64_func = (openat64_func*)dlsym(RTLD_DEFAULT, "openat");
     my_fstatat64_func = (fstatat64_func*)dlsym(RTLD_DEFAULT, "fstatat");
@@ -552,11 +565,17 @@
     times[1].tv_sec = modificationTime / 1000000;
     times[1].tv_usec = modificationTime % 1000000;
 
-    if (my_futimesat_func != NULL) {
-        RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
-        if (err == -1) {
-            throwUnixException(env, errno);
-        }
+#ifdef _ALLBSD_SOURCE
+    RESTARTABLE(futimes(filedes, &times[0]), err);
+#else
+    if (my_futimesat_func == NULL) {
+        JNU_ThrowInternalError(env, "my_ftimesat_func is NULL");
+        return;
+    }
+    RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
+#endif
+    if (err == -1) {
+        throwUnixException(env, errno);
     }
 }
 
@@ -1068,6 +1087,10 @@
 {
 #ifdef __solaris__
     struct extmnttab ent;
+#elif defined(_ALLBSD_SOURCE)
+    char buf[1024];
+    char *str;
+    char *last;
 #else
     struct mntent ent;
     char buf[1024];
@@ -1096,6 +1119,25 @@
         throwUnixException(env, errno);
         return -1;
     }
+#elif defined(_ALLBSD_SOURCE)
+again:
+    if (!(str = fgets(buf, sizeof(buf), fp)))
+        return -1;
+
+    name = strtok_r(str, " \t\n", &last);
+    if (name == NULL)
+        return -1;
+
+    // skip comments
+    if (*name == '#')
+        goto again;
+
+    dir = strtok_r((char *)NULL, " \t\n", &last);
+    fstype = strtok_r((char *)NULL, " \t\n", &last);
+    options = strtok_r((char *)NULL, " \t\n", &last);
+    if (options == NULL)
+        return -1;
+    dev = 0;
 #else
     m = getmntent_r(fp, &ent, (char*)&buf, buflen);
     if (m == NULL)
diff --git a/jdk/src/solaris/native/sun/nio/fs/genUnixConstants.c b/jdk/src/solaris/native/sun/nio/fs/genUnixConstants.c
index f826706..2c7c4fb 100644
--- a/jdk/src/solaris/native/sun/nio/fs/genUnixConstants.c
+++ b/jdk/src/solaris/native/sun/nio/fs/genUnixConstants.c
@@ -63,7 +63,12 @@
     DEFX(O_EXCL);
     DEFX(O_TRUNC);
     DEFX(O_SYNC);
+#ifndef O_DSYNC
+    // At least FreeBSD doesn't define O_DSYNC
+    emit("O_DSYNC", O_SYNC);
+#else
     DEFX(O_DSYNC);
+#endif
     DEFX(O_NOFOLLOW);
 
     // mode masks
@@ -106,7 +111,12 @@
     DEF(ENOSYS);
     DEF(ELOOP);
     DEF(EROFS);
+#ifndef ENODATA
+    // Only used in Linux java source, provide any value so it compiles
+    emit("ENODATA", ELAST);
+#else
     DEF(ENODATA);
+#endif
     DEF(ERANGE);
 
     // flags used with openat/unlinkat/etc.
diff --git a/jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c b/jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c
index 6c4ff32..fdb32df 100644
--- a/jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c
+++ b/jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c
@@ -26,7 +26,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <dlfcn.h>
+#ifndef __APPLE__
 #include <link.h>
+#endif
 #include "NativeFunc.h"
 
 /* standard GSS method names (ordering is from mapfile) */
diff --git a/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c b/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c
index b445899..134f0a6 100644
--- a/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c
+++ b/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c
@@ -28,7 +28,9 @@
 #include <string.h>
 
 #include <dlfcn.h>
+#ifndef __APPLE__
 #include <link.h>
+#endif
 
 #include <jni_util.h>
 
diff --git a/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c b/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c
index 72aa02f..59b311f 100644
--- a/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c
+++ b/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c
@@ -64,7 +64,9 @@
 #include <assert.h>
 
 #include <dlfcn.h>
+#ifndef __APPLE__
 #include <link.h>
+#endif
 
 #include <jni.h>
 
diff --git a/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c b/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c
index 67e452d..53b2431 100644
--- a/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c
+++ b/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c
@@ -29,7 +29,9 @@
 #include <assert.h>
 
 #include <dlfcn.h>
+#ifndef __APPLE__
 #include <link.h>
+#endif
 
 #include <winscard.h>
 
diff --git a/jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c b/jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c
new file mode 100644
index 0000000..54b129a
--- /dev/null
+++ b/jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+#include "jni.h"
+#include "jni_util.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/un.h>
+#include <fcntl.h>
+
+#include "sun_tools_attach_BsdVirtualMachine.h"
+
+#define RESTARTABLE(_cmd, _result) do { \
+  do { \
+    _result = _cmd; \
+  } while((_result == -1) && (errno == EINTR)); \
+} while(0)
+
+/*
+ * Class:     sun_tools_attach_BsdVirtualMachine
+ * Method:    socket
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_sun_tools_attach_BsdVirtualMachine_socket
+  (JNIEnv *env, jclass cls)
+{
+    int fd = socket(PF_UNIX, SOCK_STREAM, 0);
+    if (fd == -1) {
+        JNU_ThrowIOExceptionWithLastError(env, "socket");
+    }
+    return (jint)fd;
+}
+
+/*
+ * Class:     sun_tools_attach_BsdVirtualMachine
+ * Method:    connect
+ * Signature: (ILjava/lang/String;)I
+ */
+JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_connect
+  (JNIEnv *env, jclass cls, jint fd, jstring path)
+{
+    jboolean isCopy;
+    const char* p = GetStringPlatformChars(env, path, &isCopy);
+    if (p != NULL) {
+        struct sockaddr_un addr;
+        int err = 0;
+
+        addr.sun_family = AF_UNIX;
+        strcpy(addr.sun_path, p);
+
+        if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
+            err = errno;
+        }
+
+        if (isCopy) {
+            JNU_ReleaseStringPlatformChars(env, path, p);
+        }
+
+        /*
+         * If the connect failed then we throw the appropriate exception
+         * here (can't throw it before releasing the string as can't call
+         * JNI with pending exception)
+         */
+        if (err != 0) {
+            if (err == ENOENT) {
+                JNU_ThrowByName(env, "java/io/FileNotFoundException", NULL);
+            } else {
+                char* msg = strdup(strerror(err));
+                JNU_ThrowIOException(env, msg);
+                if (msg != NULL) {
+                    free(msg);
+                }
+            }
+        }
+    }
+}
+
+/*
+ * Class:     sun_tools_attach_BsdVirtualMachine
+ * Method:    sendQuitTo
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_sendQuitTo
+  (JNIEnv *env, jclass cls, jint pid)
+{
+    if (kill((pid_t)pid, SIGQUIT)) {
+        JNU_ThrowIOExceptionWithLastError(env, "kill");
+    }
+}
+
+/*
+ * Class:     sun_tools_attach_BsdVirtualMachine
+ * Method:    checkPermissions
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_checkPermissions
+  (JNIEnv *env, jclass cls, jstring path)
+{
+    jboolean isCopy;
+    const char* p = GetStringPlatformChars(env, path, &isCopy);
+    if (p != NULL) {
+        struct stat sb;
+        uid_t uid, gid;
+        int res;
+
+        /*
+         * Check that the path is owned by the effective uid/gid of this
+         * process. Also check that group/other access is not allowed.
+         */
+        uid = geteuid();
+        gid = getegid();
+
+        res = stat(p, &sb);
+        if (res != 0) {
+            /* save errno */
+            res = errno;
+        }
+
+        /* release p here before we throw an I/O exception */
+        if (isCopy) {
+            JNU_ReleaseStringPlatformChars(env, path, p);
+        }
+
+        if (res == 0) {
+            if ( (sb.st_uid != uid) || (sb.st_gid != gid) ||
+                 ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) ) {
+                JNU_ThrowIOException(env, "well-known file is not secure");
+            }
+        } else {
+            char* msg = strdup(strerror(res));
+            JNU_ThrowIOException(env, msg);
+            if (msg != NULL) {
+                free(msg);
+            }
+        }
+    }
+}
+
+/*
+ * Class:     sun_tools_attach_BsdVirtualMachine
+ * Method:    close
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_close
+  (JNIEnv *env, jclass cls, jint fd)
+{
+    int res;
+    RESTARTABLE(close(fd), res);
+}
+
+/*
+ * Class:     sun_tools_attach_BsdVirtualMachine
+ * Method:    read
+ * Signature: (I[BI)I
+ */
+JNIEXPORT jint JNICALL Java_sun_tools_attach_BsdVirtualMachine_read
+  (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint baLen)
+{
+    unsigned char buf[128];
+    size_t len = sizeof(buf);
+    ssize_t n;
+
+    size_t remaining = (size_t)(baLen - off);
+    if (len > remaining) {
+        len = remaining;
+    }
+
+    RESTARTABLE(read(fd, buf+off, len), n);
+    if (n == -1) {
+        JNU_ThrowIOExceptionWithLastError(env, "read");
+    } else {
+        if (n == 0) {
+            n = -1;     // EOF
+        } else {
+            (*env)->SetByteArrayRegion(env, ba, off, (jint)n, (jbyte *)(buf+off));
+        }
+    }
+    return n;
+}
+
+/*
+ * Class:     sun_tools_attach_BsdVirtualMachine
+ * Method:    write
+ * Signature: (I[B)V
+ */
+JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_write
+  (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint bufLen)
+{
+    size_t remaining = bufLen;
+    do {
+        unsigned char buf[128];
+        size_t len = sizeof(buf);
+        int n;
+
+        if (len > remaining) {
+            len = remaining;
+        }
+        (*env)->GetByteArrayRegion(env, ba, off, len, (jbyte *)buf);
+
+        RESTARTABLE(write(fd, buf, len), n);
+        if (n > 0) {
+           off += n;
+           remaining -= n;
+        } else {
+            JNU_ThrowIOExceptionWithLastError(env, "write");
+            return;
+        }
+
+    } while (remaining > 0);
+}
+
+/*
+ * Class:     sun_tools_attach_BSDVirtualMachine
+ * Method:    createAttachFile
+ * Signature: (Ljava.lang.String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_createAttachFile(JNIEnv *env, jclass cls, jstring path)
+{
+    const char* _path;
+    jboolean isCopy;
+    int fd, rc;
+
+    _path = GetStringPlatformChars(env, path, &isCopy);
+    if (_path == NULL) {
+        JNU_ThrowIOException(env, "Must specify a path");
+        return;
+    }
+
+    RESTARTABLE(open(_path, O_CREAT | O_EXCL, S_IWUSR | S_IRUSR), fd);
+    if (fd == -1) {
+        /* release p here before we throw an I/O exception */
+        if (isCopy) {
+            JNU_ReleaseStringPlatformChars(env, path, _path);
+        }
+        JNU_ThrowIOExceptionWithLastError(env, "open");
+        return;
+    }
+
+    RESTARTABLE(chown(_path, geteuid(), getegid()), rc);
+
+    RESTARTABLE(close(fd), rc);
+
+    /* release p here */
+    if (isCopy) {
+        JNU_ReleaseStringPlatformChars(env, path, _path);
+    }
+}
diff --git a/jdk/src/solaris/native/sun/xawt/XToolkit.c b/jdk/src/solaris/native/sun/xawt/XToolkit.c
index 69620ff..0e6d021 100644
--- a/jdk/src/solaris/native/sun/xawt/XToolkit.c
+++ b/jdk/src/solaris/native/sun/xawt/XToolkit.c
@@ -47,6 +47,8 @@
 #include "java_awt_TrayIcon.h"
 #include <X11/extensions/XTest.h>
 
+#include <unistd.h>
+
 uint32_t awt_NumLockMask = 0;
 Boolean  awt_ModLockIsShiftLock = False;
 
@@ -1087,3 +1089,38 @@
 
     return local_num_buttons;
 }
+
+/*
+ * Class:     sun_awt_X11_XWindowPeer
+ * Method:    getJvmPID
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_sun_awt_X11_XWindowPeer_getJvmPID
+(JNIEnv *env, jclass cls)
+{
+    /* Return the JVM's PID. */
+    return getpid();
+}
+
+#ifndef HOST_NAME_MAX
+#define HOST_NAME_MAX 1024 /* Overestimated */
+#endif
+
+/*
+ * Class:     sun_awt_X11_XWindowPeer
+ * Method:    getLocalHostname
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_sun_awt_X11_XWindowPeer_getLocalHostname
+(JNIEnv *env, jclass cls)
+{
+    /* Return the machine's FQDN. */
+    char hostname[HOST_NAME_MAX + 1];
+    if (gethostname(hostname, HOST_NAME_MAX + 1) == 0) {
+        hostname[HOST_NAME_MAX] = '\0';
+        jstring res = (*env)->NewStringUTF(env, hostname);
+        return res;
+    }
+
+    return (jstring)NULL;
+}
diff --git a/jdk/src/solaris/native/sun/xawt/XWindow.c b/jdk/src/solaris/native/sun/xawt/XWindow.c
index d33c87f..d801aae 100644
--- a/jdk/src/solaris/native/sun/xawt/XWindow.c
+++ b/jdk/src/solaris/native/sun/xawt/XWindow.c
@@ -867,7 +867,7 @@
 {
     KeySym originalKeysym = *keysym;
 
-#ifndef __linux__
+#if !defined(__linux__) && !defined(MACOSX)
     /* The following code on Linux will cause the keypad keys
      * not to echo on JTextField when the NumLock is on. The
      * keysyms will be 0, because the last parameter 2 is not defined.
diff --git a/jdk/src/solaris/native/sun/xawt/awt_Desktop.c b/jdk/src/solaris/native/sun/xawt/awt_Desktop.c
index 77f38f8..b8b250b 100644
--- a/jdk/src/solaris/native/sun/xawt/awt_Desktop.c
+++ b/jdk/src/solaris/native/sun/xawt/awt_Desktop.c
@@ -24,6 +24,7 @@
  */
 
 #include <jni.h>
+#include <jvm_md.h>
 #include <dlfcn.h>
 
 typedef int gboolean;
@@ -39,12 +40,15 @@
     void *gnome_handle;
     const char *errmsg;
 
-    vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
+    vfs_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnomevfs-2", "0"), RTLD_LAZY);
     if (vfs_handle == NULL) {
+        vfs_handle = dlopen(JNI_LIB_NAME("gnomevfs-2"), RTLD_LAZY);
+        if (vfs_handle == NULL) {
 #ifdef INTERNAL_BUILD
-        fprintf(stderr, "can not load libgnomevfs-2.so\n");
+            fprintf(stderr, "can not load libgnomevfs-2.so\n");
 #endif
-        return 0;
+            return 0;
+        }
     }
     dlerror(); /* Clear errors */
     gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init");
@@ -63,12 +67,15 @@
     // call gonme_vfs_init()
     (*gnome_vfs_init)();
 
-    gnome_handle = dlopen("libgnome-2.so.0", RTLD_LAZY);
+    gnome_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnome-2", "0"), RTLD_LAZY);
     if (gnome_handle == NULL) {
+        gnome_handle = dlopen(JNI_LIB_NAME("gnome-2"), RTLD_LAZY);
+        if (gnome_handle == NULL) {
 #ifdef INTERNAL_BUILD
-        fprintf(stderr, "can not load libgnome-2.so\n");
+            fprintf(stderr, "can not load libgnome-2.so\n");
 #endif
-        return 0;
+            return 0;
+        }
     }
     dlerror(); /* Clear errors */
     gnome_url_show = (GNOME_URL_SHOW_TYPE*)dlsym(gnome_handle, "gnome_url_show");
diff --git a/jdk/src/solaris/npt/npt_md.h b/jdk/src/solaris/npt/npt_md.h
index f6da1d6..8820b2c 100644
--- a/jdk/src/solaris/npt/npt_md.h
+++ b/jdk/src/solaris/npt/npt_md.h
@@ -32,9 +32,12 @@
 #include <string.h>
 #include <errno.h>
 #include <dlfcn.h>
+#ifndef __APPLE__
 #include <link.h>
+#endif
+#include <jvm_md.h>
 
-#define NPT_LIBNAME "libnpt.so"
+#define NPT_LIBNAME "npt"
 
 #define NPT_INITIALIZE(pnpt,version,options)                            \
     {                                                                   \
@@ -43,7 +46,7 @@
                                                                         \
         if ( (pnpt) == NULL ) NPT_ERROR("NptEnv* is NULL");             \
         *(pnpt) = NULL;                                                 \
-        _handle =  dlopen(NPT_LIBNAME, RTLD_LAZY);                      \
+        _handle =  dlopen(JNI_LIB_NAME(NPT_LIBNAME), RTLD_LAZY);              \
         if ( _handle == NULL ) NPT_ERROR("Cannot open library");        \
         _sym = dlsym(_handle, "nptInitialize");                         \
         if ( _sym == NULL ) NPT_ERROR("Cannot find nptInitialize");     \
diff --git a/jdk/src/solaris/transport/socket/socket_md.c b/jdk/src/solaris/transport/socket/socket_md.c
index d897ed4..25973d9 100644
--- a/jdk/src/solaris/transport/socket/socket_md.c
+++ b/jdk/src/solaris/transport/socket/socket_md.c
@@ -36,7 +36,7 @@
 #ifdef __solaris__
 #include <thread.h>
 #endif
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <pthread.h>
 #include <sys/poll.h>
 #endif
@@ -52,7 +52,7 @@
 int
 dbgsysConnect(int fd, struct sockaddr *name, int namelen) {
     int rv = connect(fd, name, namelen);
-    if (rv < 0 && errno == EINPROGRESS) {
+    if (rv < 0 && (errno == EINPROGRESS || errno == EINTR)) {
         return DBG_EINPROGRESS;
     } else {
         return rv;
@@ -79,7 +79,7 @@
         if (rv >= 0) {
             return rv;
         }
-        if (errno != ECONNABORTED) {
+        if (errno != ECONNABORTED && errno != EINTR) {
             return rv;
         }
     }
@@ -88,23 +88,43 @@
 int
 dbgsysRecvFrom(int fd, char *buf, int nBytes,
                   int flags, struct sockaddr *from, int *fromlen) {
-    return recvfrom(fd, buf, nBytes, flags, from, fromlen);
+    int rv;
+    do {
+        rv = recvfrom(fd, buf, nBytes, flags, from, fromlen);
+    } while (rv == -1 && errno == EINTR);
+
+    return rv;
 }
 
 int
 dbgsysSendTo(int fd, char *buf, int len,
                 int flags, struct sockaddr *to, int tolen) {
-    return sendto(fd, buf, len, flags, to, tolen);
+    int rv;
+    do {
+        rv = sendto(fd, buf, len, flags, to, tolen);
+    } while (rv == -1 && errno == EINTR);
+
+    return rv;
 }
 
 int
 dbgsysRecv(int fd, char *buf, int nBytes, int flags) {
-    return recv(fd, buf, nBytes, flags);
+    int rv;
+    do {
+        rv = recv(fd, buf, nBytes, flags);
+    } while (rv == -1 && errno == EINTR);
+
+    return rv;
 }
 
 int
 dbgsysSend(int fd, char *buf, int nBytes, int flags) {
-    return send(fd, buf, nBytes, flags);
+    int rv;
+    do {
+        rv = send(fd, buf, nBytes, flags);
+    } while (rv == -1 && errno == EINTR);
+
+    return rv;
 }
 
 struct hostent *
@@ -123,7 +143,12 @@
 }
 
 int dbgsysSocketClose(int fd) {
-    return close(fd);
+    int rv;
+    do {
+        rv = close(fd);
+    } while (rv == -1 && errno == EINTR);
+
+    return rv;
 }
 
 int
@@ -283,7 +308,7 @@
 
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 int
 dbgsysTlsAlloc() {
     pthread_key_t key;
diff --git a/jdk/src/windows/classes/java/net/DefaultInterface.java b/jdk/src/windows/classes/java/net/DefaultInterface.java
new file mode 100644
index 0000000..9f4dfe1
--- /dev/null
+++ b/jdk/src/windows/classes/java/net/DefaultInterface.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.net;
+
+/**
+ * Choose a network inteface to be the default for
+ * outgoing IPv6 traffic that does not specify a scope_id (and which needs one).
+ *
+ * Platforms that do not require a default interface may return null
+ * which is what this implementation does.
+ */
+
+class DefaultInterface {
+
+    static NetworkInterface getDefault() {
+        return null;
+    }
+}
diff --git a/jdk/src/windows/lib/tzmappings b/jdk/src/windows/lib/tzmappings
index 7f6f0d3..2f34a63 100644
--- a/jdk/src/windows/lib/tzmappings
+++ b/jdk/src/windows/lib/tzmappings
@@ -167,7 +167,7 @@
 Argentina Standard Time:900,900::America/Buenos_Aires:
 Azerbaijan Standard Time:901,901:AZ:Asia/Baku:
 Bangladesh Standard Time:902,902::Asia/Dhaka:
-Central Brazilian Standard Time:903,903:BR:America/Manaus:
+Central Brazilian Standard Time:903,903:BR:America/Cuiaba:
 Central Standard Time (Mexico):904,904::America/Mexico_City:
 Georgian Standard Time:905,905:GE:Asia/Tbilisi:
 Jordan Standard Time:906,906:JO:Asia/Amman:
@@ -189,5 +189,7 @@
 Ulaanbaatar Standard Time:922,922::Asia/Ulaanbaatar:
 Venezuela Standard Time:923,923::America/Caracas:
 Magadan Standard Time:924,924::Asia/Magadan:
-Western Brazilian Standard Time:925,925:BR:America/Rio_Branco:
-Armenian Standard Time:926,926:AM:Asia/Yerevan:
+Kaliningrad Standard Time:925,925:RU:Europe/Kaliningrad:
+Turkey Standard Time:926,926::Asia/Istanbul:
+Western Brazilian Standard Time:927,927:BR:America/Rio_Branco:
+Armenian Standard Time:928,928:AM:Asia/Yerevan:
diff --git a/jdk/src/windows/native/java/lang/java_props_md.c b/jdk/src/windows/native/java/lang/java_props_md.c
index c66efba..e27d1ea 100644
--- a/jdk/src/windows/native/java/lang/java_props_md.c
+++ b/jdk/src/windows/native/java/lang/java_props_md.c
@@ -563,6 +563,18 @@
         {
             char * display_encoding;
 
+            // Windows UI Language selection list only cares "language"
+            // information of the UI Language. For example, the list
+            // just lists "English" but it actually means "en_US", and
+            // the user cannot select "en_GB" (if exists) in the list.
+            // So, this hack is to use the user LCID region information
+            // for the UI Language, if the "language" portion of those
+            // two locales are the same.
+            if (PRIMARYLANGID(LANGIDFROMLCID(userDefaultLCID)) ==
+                PRIMARYLANGID(LANGIDFROMLCID(userDefaultUILang))) {
+                userDefaultUILang = userDefaultLCID;
+            }
+
             SetupI18nProps(userDefaultUILang,
                            &sprops.language,
                            &sprops.script,
diff --git a/jdk/src/windows/native/sun/java2d/opengl/WGLSurfaceData.c b/jdk/src/windows/native/sun/java2d/opengl/WGLSurfaceData.c
index c08d9a4..cf68feb 100644
--- a/jdk/src/windows/native/sun/java2d/opengl/WGLSurfaceData.c
+++ b/jdk/src/windows/native/sun/java2d/opengl/WGLSurfaceData.c
@@ -566,6 +566,12 @@
     }
 }
 
+// needed by Mac OS X port, no-op on other platforms
+void
+OGLSD_Flush(JNIEnv *env)
+{
+}
+
 /*
  * Class:     sun_java2d_opengl_WGLSurfaceData
  * Method:    updateWindowAccelImpl
diff --git a/jdk/test/Makefile b/jdk/test/Makefile
index daa8ee9..642b9fc 100644
--- a/jdk/test/Makefile
+++ b/jdk/test/Makefile
@@ -79,6 +79,15 @@
   endif
   OS_VERSION := $(shell $(UNAME) -r)
 endif
+ifeq ($(UNAME_S), Darwin)
+  OS_NAME     = macosx
+  OS_ARCH    := $(shell $(UNAME) -m)
+  # Check for unknown arch, try uname -p if uname -m says unknown
+  ifeq ($(OS_ARCH),unknown)
+    OS_ARCH    := $(shell $(UNAME) -p)
+  endif
+  OS_VERSION := $(shell $(UNAME) -r)
+endif
 ifeq ($(OS_NAME),)
   OS_NAME = windows
   # GNU Make or MKS overrides $(PROCESSOR_ARCHITECTURE) to always
@@ -119,6 +128,7 @@
 OS_ARCH:=$(patsubst AMD64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
 OS_ARCH:=$(patsubst amd64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
 OS_ARCH:=$(patsubst x86_64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst 86_64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
 OS_ARCH:=$(patsubst 8664,$(OS_ARCH_X64_NAME),$(OS_ARCH))
 OS_ARCH:=$(patsubst EM64T,$(OS_ARCH_X64_NAME),$(OS_ARCH))
 OS_ARCH:=$(patsubst em64t,$(OS_ARCH_X64_NAME),$(OS_ARCH))
@@ -510,13 +520,17 @@
 
 # Stable samevm testruns (minus items from PROBLEM_LIST)
 JDK_ALL_TARGETS += jdk_nio3
-jdk_nio3: $(call TestDirs, com/sun/nio sun/nio)
+jdk_nio3: $(call TestDirs, sun/nio)
 	$(call RunSamevmBatch)
 
 # All nio tests
 jdk_nio: jdk_nio1 jdk_nio2 jdk_nio3
 	@$(SummaryInfo)
 
+# Stable samevm testruns (minus items from PROBLEM_LIST)
+jdk_sctp: $(call TestDirs, com/sun/nio/sctp)
+	$(call RunSamevmBatch)
+
 # Stable othervm testruns (minus items from PROBLEM_LIST)
 #   Using samevm has serious problems with these tests
 JDK_ALL_TARGETS += jdk_rmi
diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt
index 7c2b3d4..b443da6 100644
--- a/jdk/test/ProblemList.txt
+++ b/jdk/test/ProblemList.txt
@@ -43,11 +43,11 @@
 #
 # List items  are testnames followed by labels, all MUST BE commented
 #   as to why they are here and use a label:
-#     generic-all	Problems on all platforms
-#     generic-ARCH	Where ARCH is one of: sparc, sparcv9, x64, i586, etc.
-#     OSNAME-all	Where OSNAME is one of: solaris, linux, windows
-#     OSNAME-ARCH	Specific on to one OSNAME and ARCH, e.g. solaris-x64
-#     OSNAME-REV	Specific on to one OSNAME and REV, e.g. solaris-5.8
+#     generic-all       Problems on all platforms
+#     generic-ARCH      Where ARCH is one of: sparc, sparcv9, x64, i586, etc.
+#     OSNAME-all        Where OSNAME is one of: solaris, linux, windows
+#     OSNAME-ARCH       Specific on to one OSNAME and ARCH, e.g. solaris-x64
+#     OSNAME-REV        Specific on to one OSNAME and REV, e.g. solaris-5.8
 #
 # More than one label is allowed but must be on the same line.
 #
@@ -123,38 +123,38 @@
 java/awt/event/MouseEvent/AcceptExtraButton/AcceptExtraButton.java generic-all
 
 # Causes hang in samevm mode??? Solaris 11 i586
-java/awt/FullScreen/SetFSWindow/FSFrame.java			generic-all
+java/awt/FullScreen/SetFSWindow/FSFrame.java                    generic-all
 
 # Fails on solaris 11 i586, -client, in othervm mode not sure why
-java/awt/Component/PrintAllXcheckJNI/PrintAllXcheckJNI.java	generic-all
+java/awt/Component/PrintAllXcheckJNI/PrintAllXcheckJNI.java     generic-all
 java/awt/Focus/CloseDialogActivateOwnerTest/CloseDialogActivateOwnerTest.java generic-all
-java/awt/FontClass/FontAccess.java				generic-all
-java/awt/Mixing/HWDisappear.java				generic-all
-java/awt/Mixing/MixingInHwPanel.java				generic-all
-java/awt/Mouse/MaximizedFrameTest/MaximizedFrameTest.html	generic-all
+java/awt/FontClass/FontAccess.java                              generic-all
+java/awt/Mixing/HWDisappear.java                                generic-all
+java/awt/Mixing/MixingInHwPanel.java                            generic-all
+java/awt/Mouse/MaximizedFrameTest/MaximizedFrameTest.html       generic-all
 java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java generic-all
-java/awt/Toolkit/SecurityTest/SecurityTest2.java		generic-all
-java/awt/image/mlib/MlibOpsTest.java				generic-all
+java/awt/Toolkit/SecurityTest/SecurityTest2.java                generic-all
+java/awt/image/mlib/MlibOpsTest.java                            generic-all
 
 # Fails on windows, othervm mode, various errors
-java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java	generic-all
-java/awt/Focus/OwnedWindowFocusIMECrashTest/OwnedWindowFocusIMECrashTest.java	generic-all
-java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java	generic-all
-java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Standard.java	generic-all
-java/awt/event/KeyEvent/KeyTyped/CtrlASCII.html			generic-all
-java/awt/font/Threads/FontThread.java				generic-all
-java/awt/print/PrinterJob/PrtException.java			generic-all
+java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java        generic-all
+java/awt/Focus/OwnedWindowFocusIMECrashTest/OwnedWindowFocusIMECrashTest.java   generic-all
+java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java        generic-all
+java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Standard.java      generic-all
+java/awt/event/KeyEvent/KeyTyped/CtrlASCII.html                 generic-all
+java/awt/font/Threads/FontThread.java                           generic-all
+java/awt/print/PrinterJob/PrtException.java                     generic-all
 
 # Fails with windows X64, othervm, -server
-com/sun/awt/Translucency/WindowOpacity.java			generic-all
-java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java		generic-all
-java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.html	generic-all
+com/sun/awt/Translucency/WindowOpacity.java                     generic-all
+java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java             generic-all
+java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.html generic-all
 java/awt/Focus/AppletInitialFocusTest/AppletInitialFocusTest1.html generic-all
 java/awt/Focus/FocusEmbeddedFrameTest/FocusEmbeddedFrameTest.java generic-all
-java/awt/Frame/LayoutOnMaximizeTest/LayoutOnMaximizeTest.java	generic-all
-java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java	generic-all
-java/awt/Mixing/MixingOnShrinkingHWButton.java			generic-all
-java/awt/Mouse/MouseModifiersUnitTest/ExtraButtonDrag.java	generic-all
+java/awt/Frame/LayoutOnMaximizeTest/LayoutOnMaximizeTest.java   generic-all
+java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java    generic-all
+java/awt/Mixing/MixingOnShrinkingHWButton.java                  generic-all
+java/awt/Mouse/MouseModifiersUnitTest/ExtraButtonDrag.java      generic-all
 
 ############################################################################
 
@@ -166,30 +166,30 @@
 #  So a large batch of beans tests are currently run with othervm mode.
 
 # Filed 6986807
-java/beans/Introspector/TestTypeResolver.java   		generic-all
+java/beans/Introspector/TestTypeResolver.java                   generic-all
 
 # Filed 6986813
-java/beans/Introspector/memory/Test4508780.java			generic-all
+java/beans/Introspector/memory/Test4508780.java                 generic-all
 
 # Linux, some kind of problems with X11 display
-java/beans/PropertyChangeSupport/Test4682386.java		generic-all
-java/beans/PropertyChangeSupport/TestSynchronization.java	generic-all
-java/beans/Statement/Test4653179.java				generic-all
+java/beans/PropertyChangeSupport/Test4682386.java               generic-all
+java/beans/PropertyChangeSupport/TestSynchronization.java       generic-all
+java/beans/Statement/Test4653179.java                           generic-all
 
 # Runs REALLY slow on Solaris sparc for some reason, both -client and -server
-java/beans/XMLEncoder/Test4625418.java				solaris-sparc
+java/beans/XMLEncoder/Test4625418.java                          solaris-sparc
 
 # Problems with samevm and setting security manager (speculation partially)
-java/beans/Introspector/4168475/Test4168475.java		generic-all
-java/beans/Introspector/4520754/Test4520754.java		generic-all
-java/beans/Introspector/6380849/TestBeanInfo.java		generic-all
-java/beans/Introspector/Test4144543.java			generic-all
+java/beans/Introspector/4168475/Test4168475.java                generic-all
+java/beans/Introspector/4520754/Test4520754.java                generic-all
+java/beans/Introspector/6380849/TestBeanInfo.java               generic-all
+java/beans/Introspector/Test4144543.java                        generic-all
 
 # Failed to call method solaris-sparc???
-java/beans/EventHandler/Test6788531.java		 	generic-all
+java/beans/EventHandler/Test6788531.java                        generic-all
 
 # Jar or class not found???
-java/beans/XMLEncoder/6329581/Test6329581.java		 	generic-all
+java/beans/XMLEncoder/6329581/Test6329581.java                  generic-all
 
 ############################################################################
 
@@ -199,29 +199,29 @@
 java/lang/invoke/InvokeDynamicPrintArgs.java                    generic-all
 
 # Times out on solaris 10 sparc
-java/lang/ClassLoader/Assert.java				generic-all
+java/lang/ClassLoader/Assert.java                               generic-all
 
 # Solaris sparc, samevm, java.lang.Exception: Read from closed pipe hangs
-java/lang/Runtime/exec/SleepyCat.java				generic-all
+java/lang/Runtime/exec/SleepyCat.java                           generic-all
 
 # Times out on solaris sparc -server
-java/lang/ThreadLocal/MemoryLeak.java			 	solaris-all
+java/lang/ThreadLocal/MemoryLeak.java                           solaris-all
 
 # Windows X64, RuntimeException: MyThread expected to have RUNNABLE but got WAITING
-java/lang/Thread/ThreadStateTest.java				generic-all
+java/lang/Thread/ThreadStateTest.java                           generic-all
 
 ############################################################################
 
 # jdk_management
 
 # Failing, bug was filed: 6959636
-javax/management/loading/LibraryLoader/LibraryLoaderTest.java	generic-all
+javax/management/loading/LibraryLoader/LibraryLoaderTest.java   generic-all
 
 # Access denied messages on windows/mks, filed 6954450
-sun/management/jmxremote/bootstrap/RmiSslNoKeyStoreTest.sh	windows-all
+sun/management/jmxremote/bootstrap/RmiSslNoKeyStoreTest.sh      windows-all
 
 # Fails on linux: KO: StringMonitor notification missed or not emitted
-javax/management/monitor/NonComparableAttributeValueTest.java	generic-all
+javax/management/monitor/NonComparableAttributeValueTest.java   generic-all
 
 # Port conflict? Fails with communication error
 sun/management/jmxremote/bootstrap/PasswordFilePermissionTest.sh generic-all
@@ -232,10 +232,10 @@
 javax/management/remote/mandatory/connection/ReconnectTest.java generic-all
 
 # Solaris 10 sparc, NPE from org.omg.stub.javax.management.remote.rmi._RMIConnectionImpl_Tie._invoke
-javax/management/remote/mandatory/threads/ExecutorTest.java 	generic-all
+javax/management/remote/mandatory/threads/ExecutorTest.java     generic-all
 
 # Linux 32bit Fedora 9, IllegalStateException
-javax/management/monitor/RuntimeExceptionTest.java		generic-all
+javax/management/monitor/RuntimeExceptionTest.java              generic-all
 
 # Problems with rmi connection, othervm
 javax/management/remote/mandatory/subjectDelegation/SubjectDelegation2Test.java generic-all
@@ -244,16 +244,16 @@
 sun/management/jmxremote/bootstrap/SSLConfigFilePermissionTest.sh generic-all
 
 # Fails with port already in use
-sun/management/jmxremote/bootstrap/RmiRegistrySslTest.sh	generic-all
+sun/management/jmxremote/bootstrap/RmiRegistrySslTest.sh        generic-all
 
 # Windows, connection can't last that long
-javax/management/eventService/LeaseTest.java			generic-all
+javax/management/eventService/LeaseTest.java                    generic-all
 
 # Linux othervm, X64, java.lang.Exception: Failed: ratio=102.4027795593753
-javax/management/remote/mandatory/notif/ListenerScaleTest.java	generic-all
+javax/management/remote/mandatory/notif/ListenerScaleTest.java  generic-all
 
 # Windows run seems to have triggered a hotspot gc error (see 6801625)
-com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.sh		generic-all
+com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.sh          generic-all
 
 # rmi problem? othervm, java.lang.reflect.UndeclaredThrowableException
 javax/management/remote/mandatory/subjectDelegation/SubjectDelegation3Test.java generic-all
@@ -262,30 +262,30 @@
 javax/management/remote/mandatory/notif/NotificationBufferDeadlockTest.java generic-all
 
 # Times out on solaris sparc, with othervm
-javax/management/eventService/AddRemoveListenerTest.java	generic-all
+javax/management/eventService/AddRemoveListenerTest.java        generic-all
 
 # Linux i586 and x64 -server, timed out waiting for threads to expire? othervm
-javax/management/eventService/EventClientThreadTest.java	generic-all
+javax/management/eventService/EventClientThreadTest.java        generic-all
 
 # Linux i586 -server, Expected to receive 20, but got 21, othervm
 #   Fails on Linux X64 -server 20!=21
-javax/management/eventService/FetchingTest.java			generic-all
+javax/management/eventService/FetchingTest.java                 generic-all
 
 # NPE on windows 2000 i586 -client and -server
-javax/management/eventService/CustomForwarderTest.java	 	windows-all
+javax/management/eventService/CustomForwarderTest.java          windows-all
 
 # Windows i586 failure, callback did not complete
-javax/management/eventService/LeaseManagerDeadlockTest.java 	windows-all
+javax/management/eventService/LeaseManagerDeadlockTest.java     windows-all
 
 # Port already in use
-sun/management/jmxremote/bootstrap/LocalManagementTest.sh 	generic-all
+sun/management/jmxremote/bootstrap/LocalManagementTest.sh       generic-all
 
 # Failed to initialize connector (also overflowing jtreg io buffers)
-sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh	 	generic-all
-sun/management/jmxremote/bootstrap/RmiSslBootstrapTest.sh 	generic-all
+sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh          generic-all
+sun/management/jmxremote/bootstrap/RmiSslBootstrapTest.sh       generic-all
 
 # Windows X64, java.lang.IllegalStateException
-javax/management/monitor/AttributeArbitraryDataTypeTest.java	generic-all
+javax/management/monitor/AttributeArbitraryDataTypeTest.java    generic-all
 
 ############################################################################
 
@@ -296,71 +296,71 @@
 # jdk_misc
 
 # Need to be marked othervm, or changed to be samevm safe
-com/sun/jndi/ldap/ReadTimeoutTest.java				generic-all
-com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java	generic-all
+com/sun/jndi/ldap/ReadTimeoutTest.java                          generic-all
+com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all
 
 # Need to be marked othervm, or changed to be samevm safe
 com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java generic-all
 
 # Solaris sparc and others, exception in initializer
-javax/imageio/CachePremissionsTest/CachePermissionsTest.java 	generic-all
+javax/imageio/CachePremissionsTest/CachePermissionsTest.java    generic-all
 
 # Leaves file rgba_* open, fails with windows samevm
-javax/imageio/plugins/png/PngOutputTypeTest.java		generic-all
+javax/imageio/plugins/png/PngOutputTypeTest.java                generic-all
 
 # Suspect test.png file is left open, windows samevm problems
-javax/imageio/plugins/png/ITXtTest.java				generic-all
+javax/imageio/plugins/png/ITXtTest.java                         generic-all
 
 # Solaris sparc and others, failed to compile testcase
-javax/imageio/metadata/DOML3Node.java			 	generic-all
+javax/imageio/metadata/DOML3Node.java                           generic-all
 
 # One of these tests is leaving file IMGP1001.JPG open, windows samevm
-javax/imageio/plugins/jpeg/ConcurrentReadingTest.java		generic-all
-javax/imageio/plugins/jpeg/ReadingInterruptionTest.java		generic-all
+javax/imageio/plugins/jpeg/ConcurrentReadingTest.java           generic-all
+javax/imageio/plugins/jpeg/ReadingInterruptionTest.java         generic-all
 
 # One of these files is missing a close on writer_* files, windows samevm
-javax/imageio/plugins/jpeg/ConcurrentWritingTest.java		generic-all
-javax/imageio/plugins/jpeg/WritingInterruptionTest.java		generic-all
+javax/imageio/plugins/jpeg/ConcurrentWritingTest.java           generic-all
+javax/imageio/plugins/jpeg/WritingInterruptionTest.java         generic-all
 
 # Leaving file test.jpg open, windows samevm
-javax/imageio/plugins/jpeg/ReadAsGrayTest.java			generic-all
+javax/imageio/plugins/jpeg/ReadAsGrayTest.java                  generic-all
 
 # Missing close on file wbmp*, windows samevm
-javax/imageio/plugins/wbmp/CanDecodeTest.java			generic-all
+javax/imageio/plugins/wbmp/CanDecodeTest.java                   generic-all
 
 # Failures on OpenSolaris, cannot read input files? samevm issues?
-javax/imageio/metadata/BooleanAttributes.java			generic-all
-javax/imageio/plugins/bmp/BMPSubsamplingTest.java		generic-all
-javax/imageio/plugins/bmp/TopDownTest.java			generic-all
-javax/imageio/plugins/gif/EncodeSubImageTest.java		generic-all
-javax/imageio/plugins/gif/GifTransparencyTest.java		generic-all
-javax/imageio/plugins/png/GrayPngTest.java			generic-all
-javax/imageio/plugins/png/ItxtUtf8Test.java			generic-all
-javax/imageio/plugins/png/MergeStdCommentTest.java		generic-all
-javax/imageio/plugins/png/ShortHistogramTest.java		generic-all
-javax/imageio/plugins/shared/BitDepth.java			generic-all
+javax/imageio/metadata/BooleanAttributes.java                   generic-all
+javax/imageio/plugins/bmp/BMPSubsamplingTest.java               generic-all
+javax/imageio/plugins/bmp/TopDownTest.java                      generic-all
+javax/imageio/plugins/gif/EncodeSubImageTest.java               generic-all
+javax/imageio/plugins/gif/GifTransparencyTest.java              generic-all
+javax/imageio/plugins/png/GrayPngTest.java                      generic-all
+javax/imageio/plugins/png/ItxtUtf8Test.java                     generic-all
+javax/imageio/plugins/png/MergeStdCommentTest.java              generic-all
+javax/imageio/plugins/png/ShortHistogramTest.java               generic-all
+javax/imageio/plugins/shared/BitDepth.java                      generic-all
 
 # Exclude all javax/print tests, even if they passed, they may need samevm work
 
 # Times out on solaris-sparc, sparcv9, x64 -server, some on i586 -client
-javax/print/attribute/autosense/PrintAutoSenseData.java 	generic-all
-javax/print/attribute/Chroma.java			 	generic-all
-javax/print/attribute/CollateAttr.java			 	generic-all
-javax/print/attribute/PSCopiesFlavorTest.java		 	generic-all
-javax/print/LookupServices.java 			 	generic-all
-javax/print/TestRaceCond.java				 	generic-all
+javax/print/attribute/autosense/PrintAutoSenseData.java         generic-all
+javax/print/attribute/Chroma.java                               generic-all
+javax/print/attribute/CollateAttr.java                          generic-all
+javax/print/attribute/PSCopiesFlavorTest.java                   generic-all
+javax/print/LookupServices.java                                 generic-all
+javax/print/TestRaceCond.java                                   generic-all
 
 # These tests really require a printer (might all be windows only tests?)
-javax/print/CheckDupFlavor.java					generic-all
-javax/print/PrintSE/PrintSE.sh					generic-all
-javax/print/attribute/ChromaticityValues.java			generic-all
-javax/print/attribute/GetCopiesSupported.java			generic-all
-javax/print/attribute/SidesPageRangesTest.java			generic-all
-javax/print/attribute/SupportedPrintableAreas.java		generic-all
+javax/print/CheckDupFlavor.java                                 generic-all
+javax/print/PrintSE/PrintSE.sh                                  generic-all
+javax/print/attribute/ChromaticityValues.java                   generic-all
+javax/print/attribute/GetCopiesSupported.java                   generic-all
+javax/print/attribute/SidesPageRangesTest.java                  generic-all
+javax/print/attribute/SupportedPrintableAreas.java              generic-all
 javax/print/attribute/AttributeTest.java                        generic-all
 
 # Only print test left, excluding just because all print tests have been
-javax/print/attribute/MediaMappingsTest.java 			generic-all
+javax/print/attribute/MediaMappingsTest.java                    generic-all
 
 ############################################################################
 
@@ -373,6 +373,9 @@
 # 6962637
 java/io/File/MaxPathLength.java                                 windows-all
 
+# 6671616
+java/io/File/BlockIsDirectory.java                              solaris-all
+
 ############################################################################
 
 # jdk_nio
@@ -380,36 +383,12 @@
 # 6963118
 java/nio/channels/Selector/Wakeup.java                          windows-all
 
-# 6959891
-com/sun/nio/sctp/SctpChannel/SocketOptionTests.java
-
-# Fails with -ea -esa, Assertion error, but only on Solaris 10 machines?
-com/sun/nio/sctp/SctpChannel/Send.java				generic-all
-com/sun/nio/sctp/SctpChannel/Shutdown.java			generic-all
-
-# Fails on OpenSolaris, IllegalStateException: Cannot add or remove addresses
-#    from a channel that is bound to the wildcard address
-com/sun/nio/sctp/SctpChannel/Bind.java				generic-all
-
-# Failed on OpenSolaris, java.lang.AssertionError: Unknown event type
-com/sun/nio/sctp/SctpChannel/Receive.java			generic-all
-
-# Solaris 11 gave assert error and "connection refused", samevm issues?
-com/sun/nio/sctp/SctpServerChannel/NonBlockingAccept.java 	generic-all
-
-# Fails with othervm on solaris 11 i586
-com/sun/nio/sctp/SctpChannel/CommUp.java			generic-all
-com/sun/nio/sctp/SctpChannel/Connect.java			generic-all
-com/sun/nio/sctp/SctpMultiChannel/Branch.java			generic-all
-com/sun/nio/sctp/SctpMultiChannel/Send.java			generic-all
-com/sun/nio/sctp/SctpMultiChannel/SocketOptionTests.java	generic-all
-
 ############################################################################
 
 # jdk_rmi
 
 # Port already in use, fails on sparc, othervm
-java/rmi/reliability/benchmark/runRmiBench.sh			generic-all
+java/rmi/reliability/benchmark/runRmiBench.sh                   generic-all
 
 # Already in use port issues? othervm solaris
 java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java generic-all
@@ -419,21 +398,21 @@
 java/rmi/transport/dgcDeadLock/TestImpl_Stub.java                       generic-all
 
 # Address already in use, othervm mode, solaris
-java/rmi/activation/Activatable/elucidateNoSuchMethod/ElucidateNoSuchMethod.java	generic-all
-java/rmi/activation/Activatable/forceLogSnapshot/ForceLogSnapshot.java	generic-all
+java/rmi/activation/Activatable/elucidateNoSuchMethod/ElucidateNoSuchMethod.java        generic-all
+java/rmi/activation/Activatable/forceLogSnapshot/ForceLogSnapshot.java  generic-all
 
 # Registry already running on port, solaris
-java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java	generic-all
+java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java      generic-all
 
 # Fails on Linux 32 and 64bit -server?, impl not garbage collected???
-java/rmi/transport/pinLastArguments/PinLastArguments.java	generic-all
+java/rmi/transport/pinLastArguments/PinLastArguments.java       generic-all
 
 # Times out on solaris sparc
-java/rmi/server/RemoteServer/AddrInUse.java			generic-all
+java/rmi/server/RemoteServer/AddrInUse.java                     generic-all
 
 # Connection error on Windows i586 -server
 #  Also connection errors in othervm on Solaris 10 sparc, same port???
-sun/rmi/transport/tcp/DeadCachedConnection.java 	 	generic-all
+sun/rmi/transport/tcp/DeadCachedConnection.java                 generic-all
 
 # Connection errors in othervm on Solaris 10 sparc, same port???
 java/rmi/activation/Activatable/checkActivateRef/CheckActivateRef.java generic-all
@@ -479,77 +458,77 @@
 # jdk_security
 
 # Filed 6986868
-sun/security/tools/jarsigner/crl.sh				generic-all
+sun/security/tools/jarsigner/crl.sh                             generic-all
 
 # Filed 6951285, not sure how often this fails, last was Linux 64bit Fedora 9
-sun/security/krb5/auto/MaxRetries.java				generic-all
+sun/security/krb5/auto/MaxRetries.java                          generic-all
 
 # Filed 6950930, fails on windows 32bit c1 and windows 64bit
-sun/security/krb5/auto/IgnoreChannelBinding.java		windows-all
+sun/security/krb5/auto/IgnoreChannelBinding.java                windows-all
 
 # Filed 6950931, failing on all windows systems
-sun/security/tools/jarsigner/crl.sh				windows-all
+sun/security/tools/jarsigner/crl.sh                             windows-all
 
 # Filed 6950929, only seemed to fail on solaris sparcv9 (-d64)
 #   Failed on Linux -server 32bit too, making generic
-sun/security/krb5/auto/BadKdc4.java				generic-all
+sun/security/krb5/auto/BadKdc4.java                             generic-all
 
 # Failing on Solaris i586, 3/9/2010, not a -samevm issue (jdk_security3)
-sun/security/pkcs11/Secmod/AddPrivateKey.java			solaris-i586
-sun/security/pkcs11/ec/ReadCertificates.java			solaris-i586
-sun/security/pkcs11/ec/ReadPKCS12.java				solaris-i586
-sun/security/pkcs11/ec/TestCurves.java				solaris-i586
-sun/security/pkcs11/ec/TestECDSA.java				solaris-i586
-sun/security/pkcs11/ec/TestECGenSpec.java			solaris-i586
-sun/security/pkcs11/ec/TestKeyFactory.java			solaris-i586
+sun/security/pkcs11/Secmod/AddPrivateKey.java                   solaris-i586
+sun/security/pkcs11/ec/ReadCertificates.java                    solaris-i586
+sun/security/pkcs11/ec/ReadPKCS12.java                          solaris-i586
+sun/security/pkcs11/ec/TestCurves.java                          solaris-i586
+sun/security/pkcs11/ec/TestECDSA.java                           solaris-i586
+sun/security/pkcs11/ec/TestECGenSpec.java                       solaris-i586
+sun/security/pkcs11/ec/TestKeyFactory.java                      solaris-i586
 
 # Unknown problem, could be a jtreg -samevm issue?
 #  Error while cleaning up threads after test
-java/security/Security/SynchronizedAccess.java			generic-all
+java/security/Security/SynchronizedAccess.java                  generic-all
 
 # Failing on Solaris X64 (-d64 -server) with:
 #  GSSException: Failure unspecified at GSS-API level
 #    (Mechanism level: Specified version of key is not available (44))
-sun/security/krb5/auto/BasicKrb5Test.java			generic-all
+sun/security/krb5/auto/BasicKrb5Test.java                       generic-all
 
 # Solaris X86 failures, readjar.jks: No such file or directory
-sun/security/tools/keytool/readjar.sh				generic-all
+sun/security/tools/keytool/readjar.sh                           generic-all
 
 # Fails with -ea -esa, but only on Solaris sparc? Suspect it is timing out
-sun/security/tools/keytool/standard.sh				generic-all
+sun/security/tools/keytool/standard.sh                          generic-all
 
 # Fails on Solaris 10 X64, address already in use
-sun/security/krb5/auto/HttpNegotiateServer.java			generic-all
+sun/security/krb5/auto/HttpNegotiateServer.java                 generic-all
 
 # Fails on almost all platforms
 #   java.lang.UnsupportedClassVersionError: SerialTest :
 #      Unsupported major.minor version 51.0
 #    at java.lang.ClassLoader.defineClass1(Native Method)
-sun/security/util/Oid/S11N.sh					generic-all
+sun/security/util/Oid/S11N.sh                                   generic-all
 
 # Fails on Fedora 9 32bit
 #  GSSException: Failure unspecified at GSS-API level (Mechanism level:
 #    Invalid argument (400) - Cannot find key of appropriate type to decrypt
 #    AP REP - DES CBC mode with MD5)
 #  at sun.security.jgss.krb5.Krb5Context.acceptSecContext(Krb5Context.java:778)
-sun/security/krb5/auto/NonMutualSpnego.java			generic-all
+sun/security/krb5/auto/NonMutualSpnego.java                     generic-all
 
 # Fails on Solaris 10 sparc, GSSException: Failure unspecified at GSS-API level
 #   Also fails on Windows 2000 similar way
-sun/security/krb5/auto/ok-as-delegate.sh			generic-all
+sun/security/krb5/auto/ok-as-delegate.sh                        generic-all
 
 # Fails on Windows 2000, GSSException: Failure unspecified at GSS-API level
 #    (Mechanism level: Request is a replay (34))
-sun/security/krb5/auto/ok-as-delegate-xrealm.sh			generic-all
+sun/security/krb5/auto/ok-as-delegate-xrealm.sh                 generic-all
 
 # Fails on Windows 2000, ExceptionInInitializerError
-sun/security/mscapi/AccessKeyStore.sh				generic-all
+sun/security/mscapi/AccessKeyStore.sh                           generic-all
 
 # Fails on Solaris 10, KrbException: Additional pre-authentication required (25)
-sun/security/krb5/auto/basic.sh					generic-all
+sun/security/krb5/auto/basic.sh                                 generic-all
 
 # Fails on Fedora 9 64bit, PKCS11Exception: CKR_DEVICE_ERROR
-sun/security/pkcs11/KeyAgreement/TestDH.java			generic-all
+sun/security/pkcs11/KeyAgreement/TestDH.java                    generic-all
 
 # Run too slow on Solaris 10 sparc
 sun/security/ssl/com/sun/net/ssl/internal/ssl/InputRecord/SSLSocketTimeoutNulls.java solaris-sparc
@@ -557,158 +536,158 @@
 sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/ServerTimeout.java solaris-sparc
 sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/ReadTimeout.java solaris-sparc
 sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/NotifyHandshakeTest.sh solaris-sparc
-sun/security/tools/keytool/AltProviderPath.sh 			solaris-sparc
+sun/security/tools/keytool/AltProviderPath.sh                   solaris-sparc
 
 # Solaris 10 sparc, passed/failed confusion? java.security.ProviderException: update() failed
 sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/AsyncSSLSocketClose.java generic-all
 
 # Seem really slow on Solaris sparc, being excluded just for timing reasons
-sun/security/tools/jarsigner/AlgOptions.sh			solaris-sparc
-sun/security/tools/jarsigner/nameclash.sh			solaris-sparc
-sun/security/krb5/auto/basic.sh					solaris-sparc
-sun/security/provider/PolicyFile/getinstance/getinstance.sh	solaris-sparc
-sun/security/tools/jarsigner/samename.sh			solaris-sparc
+sun/security/tools/jarsigner/AlgOptions.sh                      solaris-sparc
+sun/security/tools/jarsigner/nameclash.sh                       solaris-sparc
+sun/security/krb5/auto/basic.sh                                 solaris-sparc
+sun/security/provider/PolicyFile/getinstance/getinstance.sh     solaris-sparc
+sun/security/tools/jarsigner/samename.sh                        solaris-sparc
 
 # Timed out, Solaris 10 64bit sparcv9
-com/sun/crypto/provider/Cipher/DES/PaddingTest.java		generic-all
+com/sun/crypto/provider/Cipher/DES/PaddingTest.java             generic-all
 
 # Othervm, sparc, NoRouteToHostException: Cannot assign requested address
 sun/security/ssl/javax/net/ssl/NewAPIs/SessionCacheSizeTests.java generic-all
 
 # Times out on windows X64, othervm mode
 #    Solaris sparc and sparcv9 -server, timeout
-sun/security/ssl/javax/net/ssl/NewAPIs/SessionTimeOutTests.java	generic-all
+sun/security/ssl/javax/net/ssl/NewAPIs/SessionTimeOutTests.java generic-all
 
 # Failed on solaris 10 sparc, othervm mode,  "js.jks: No such file or directory"
 #  Also, cannot verify signature on solaris i586 -server
-sun/security/tools/jarsigner/concise_jarsigner.sh		generic-all
+sun/security/tools/jarsigner/concise_jarsigner.sh               generic-all
 
 # Various failures on Linux Fedora 9 X64, othervm mode
 sun/security/ssl/javax/net/ssl/NewAPIs/SSLEngine/TestAllSuites.java generic-all
-sun/security/ssl/sanity/ciphersuites/CheckCipherSuites.java	generic-all
-sun/security/tools/jarsigner/oldsig.sh				generic-all
+sun/security/ssl/sanity/ciphersuites/CheckCipherSuites.java     generic-all
+sun/security/tools/jarsigner/oldsig.sh                          generic-all
 
 # Various failures on Linux Fedora 9 X64, othervm mode
-sun/security/ssl/sanity/interop/ClientJSSEServerJSSE.java	generic-all
+sun/security/ssl/sanity/interop/ClientJSSEServerJSSE.java       generic-all
 
 # Linux i586 -server, buffer too short to hold shared secret?
-com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java	generic-all
+com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java       generic-all
 
 # Solaris sparcv9: Failed to parse input emptysubject.jks: No such file or directory
-sun/security/tools/keytool/emptysubject.sh			generic-all
+sun/security/tools/keytool/emptysubject.sh                      generic-all
 
 # Timeout on solaris-sparcv9 or exception thrown
-com/sun/crypto/provider/Cipher/RSA/TestOAEP_KAT.java	 	solaris-all
+com/sun/crypto/provider/Cipher/RSA/TestOAEP_KAT.java            solaris-all
 
 # Leaving file open: SerialVersion.current, windows samevm
-java/security/BasicPermission/SerialVersion.java		generic-all
+java/security/BasicPermission/SerialVersion.java                generic-all
 
 # Solaris 11 i586, these all fail with samevm, need to be othervm???
-java/security/BasicPermission/NullOrEmptyName.java		generic-all
+java/security/BasicPermission/NullOrEmptyName.java              generic-all
 
 # Suspect missing close() on file PermClass.current, windows samevm cascade
-java/security/BasicPermission/PermClass.java			generic-all
+java/security/BasicPermission/PermClass.java                    generic-all
 
 # Solaris 11 i586, these all fail with samevm, need to be othervm???
-java/security/KeyPairGenerator/Failover.java			generic-all
-java/security/Provider/DefaultPKCS11.java			generic-all
-java/security/SecureClassLoader/DefineClassByteBuffer.java	generic-all
-java/security/SecureRandom/GetAlgorithm.java			generic-all
-java/security/Security/removing/RemoveProviders.java		generic-all
-java/security/Signature/ByteBuffers.java			generic-all
-java/security/Signature/NONEwithRSA.java			generic-all
-java/security/Signature/SignWithOutputBuffer.java		generic-all
-java/security/Signature/TestInitSignWithMyOwnRandom.java	generic-all
-java/security/UnresolvedPermission/AccessorMethods.java		generic-all
-java/security/UnresolvedPermission/Equals.java			generic-all
+java/security/KeyPairGenerator/Failover.java                    generic-all
+java/security/Provider/DefaultPKCS11.java                       generic-all
+java/security/SecureClassLoader/DefineClassByteBuffer.java      generic-all
+java/security/SecureRandom/GetAlgorithm.java                    generic-all
+java/security/Security/removing/RemoveProviders.java            generic-all
+java/security/Signature/ByteBuffers.java                        generic-all
+java/security/Signature/NONEwithRSA.java                        generic-all
+java/security/Signature/SignWithOutputBuffer.java               generic-all
+java/security/Signature/TestInitSignWithMyOwnRandom.java        generic-all
+java/security/UnresolvedPermission/AccessorMethods.java         generic-all
+java/security/UnresolvedPermission/Equals.java                  generic-all
 
 # Fails on OpenSolaris, missing classes, slow on Solaris sparc
-sun/security/ec/TestEC.java					generic-all
+sun/security/ec/TestEC.java                                     generic-all
 
 # Problems with windows x64
-sun/security/mscapi/IsSunMSCAPIAvailable.sh		 	windows-x64
-sun/security/mscapi/RSAEncryptDecrypt.sh		 	windows-x64
+sun/security/mscapi/IsSunMSCAPIAvailable.sh                     windows-x64
+sun/security/mscapi/RSAEncryptDecrypt.sh                        windows-x64
 
 # Exception in test solaris-sparc -client -server, no windows
-sun/security/pkcs11/KeyGenerator/TestKeyGenerator.java	        solaris-all
+sun/security/pkcs11/KeyGenerator/TestKeyGenerator.java          solaris-all
 
 # Solaris sparc client, fails to compile?
-sun/security/pkcs11/KeyStore/SecretKeysBasic.sh 	 	solaris-all
+sun/security/pkcs11/KeyStore/SecretKeysBasic.sh                 solaris-all
 
 # Fails on OpenSolaris java.net.BindException: Address already in use
-sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java		generic-all
+sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java            generic-all
 
 # Timeout on solaris-sparcv9 or ArrayIndexOutOfBoundsException?
-sun/security/rsa/TestKeyPairGeneratorLength.java	 	solaris-all
-sun/security/rsa/TestSignatures.java			 	solaris-all
+sun/security/rsa/TestKeyPairGeneratorLength.java                solaris-all
+sun/security/rsa/TestSignatures.java                            solaris-all
 
 # Timeout on solaris-sparc and i586 and x64, -client and -server
 sun/security/ssl/com/sun/net/ssl/internal/ssl/InputRecord/InterruptedIO.java solaris-all
 
 # Do not seem to run on windows machines? dll missing?
-sun/security/tools/jarsigner/emptymanifest.sh		 	windows-all
+sun/security/tools/jarsigner/emptymanifest.sh                   windows-all
 
 # Files does not exist or no encoding? solaris-sparcv9
-sun/security/tools/keytool/importreadall.sh		 	solaris-all
-sun/security/tools/keytool/selfissued.sh		 	solaris-all
+sun/security/tools/keytool/importreadall.sh                     solaris-all
+sun/security/tools/keytool/selfissued.sh                        solaris-all
 
 ############################################################################
 
 # jdk_swing (not using samevm)
 
 # Fails on solaris 11 i586, with othervm
-javax/swing/JFileChooser/6570445/bug6570445.java		generic-all
-javax/swing/JFileChooser/6738668/bug6738668.java		generic-all
-javax/swing/JPopupMenu/6675802/bug6675802.java			generic-all
-javax/swing/system/6799345/TestShutdown.java			generic-all
+javax/swing/JFileChooser/6570445/bug6570445.java                generic-all
+javax/swing/JFileChooser/6738668/bug6738668.java                generic-all
+javax/swing/JPopupMenu/6675802/bug6675802.java                  generic-all
+javax/swing/system/6799345/TestShutdown.java                    generic-all
 
 ############################################################################
 
 # jdk_text
 
 # Linux x64 occasional errors, no details
-java/text/Bidi/Bug6665028.java				 	linux-x64
+java/text/Bidi/Bug6665028.java                                  linux-x64
 
 ############################################################################
 
 # jdk_tools
 
 # Filed 6952105
-com/sun/jdi/SuspendThreadTest.java				generic-all
+com/sun/jdi/SuspendThreadTest.java                              generic-all
 
 # Filed 6986875
-sun/tools/jps/jps-Vvml.sh					generic-all
+sun/tools/jps/jps-Vvml.sh                                       generic-all
 
 # Filed 6979016
-sun/tools/jconsole/ResourceCheckTest.sh				generic-all
+sun/tools/jconsole/ResourceCheckTest.sh                         generic-all
 
 ############################################################################
 
 # jdk_util
 
 # Filed 7027061
-java/util/Locale/Bug6989440.java				windows-all
+java/util/Locale/Bug6989440.java                                windows-all
 
 # Filed 6933803
-java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	generic-all
+java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java  generic-all
 
 # Filed 7022325
 # Fails with assertion error on windows
 #   11 separate stacktraces created... file reuse problem?
-java/util/zip/ZipFile/ReadLongZipFileName.java			generic-all
+java/util/zip/ZipFile/ReadLongZipFileName.java                  generic-all
 
 # Assert error, failures, on Linux Fedora 9 -server
 #   Windows samevm failure, assert error "Passed = 134, failed = 2"
-java/util/Arrays/ArrayObjectMethods.java			generic-all
+java/util/Arrays/ArrayObjectMethods.java                        generic-all
 
 # Windows 2000, -client, samevm, java.lang.Error: Completed != 2
 java/util/concurrent/locks/ReentrantLock/CancelledLockLoops.java generic-all
 
 # Windows X64, Executor Stuck samevm mode:
-java/util/concurrent/FutureTask/BlockingTaskExecutor.java	generic-all
+java/util/concurrent/FutureTask/BlockingTaskExecutor.java       generic-all
 
 # Problems on windows, jmap.exe hangs? (these run jmap), fails on Solaris 10 x86
-java/util/concurrent/locks/Lock/TimedAcquireLeak.java		generic-all
+java/util/concurrent/locks/Lock/TimedAcquireLeak.java           generic-all
 
 ############################################################################
 
diff --git a/jdk/test/com/sun/jdi/ImmutableResourceTest.sh b/jdk/test/com/sun/jdi/ImmutableResourceTest.sh
index 2e2a666..527de19 100644
--- a/jdk/test/com/sun/jdi/ImmutableResourceTest.sh
+++ b/jdk/test/com/sun/jdi/ImmutableResourceTest.sh
@@ -28,14 +28,14 @@
 #
 #   @run shell ImmutableResourceTest.sh
 #
-# 
+#
 
 # Beginning of subroutines:
 status=1
 
 #Call this from anywhere to fail the test with an error message
 # usage: fail "reason why the test failed"
-fail() 
+fail()
  { echo "The test failed :-("
    echo "$*" 1>&2
    echo "exit status was $status"
@@ -44,7 +44,7 @@
 
 #Call this from anywhere to pass the test with a message
 # usage: pass "reason why the test passed if applicable"
-pass() 
+pass()
  { echo "The test passed!!!"
    echo "$*" 1>&2
    exit 0
@@ -56,7 +56,7 @@
 
 OS=`uname -s`
 case "$OS" in
-   SunOS | Linux )
+   SunOS | Linux | Darwin )
       PATHSEP=":"
       ;;
 
@@ -83,7 +83,7 @@
    if [ -n "$1" ] ; then
           TESTJAVA=$1
       else
-	  TESTJAVA=$JAVA_HOME
+          TESTJAVA=$JAVA_HOME
    fi
    TESTSRC=.
    TESTCLASSES=.
diff --git a/jdk/test/com/sun/jdi/JITDebug.sh b/jdk/test/com/sun/jdi/JITDebug.sh
index 6850978..1359780 100644
--- a/jdk/test/com/sun/jdi/JITDebug.sh
+++ b/jdk/test/com/sun/jdi/JITDebug.sh
@@ -40,7 +40,7 @@
 
 #Call this from anywhere to fail the test with an error message
 # usage: fail "reason why the test failed"
-fail() 
+fail()
  { echo "The test failed :-("
    echo "$*" 1>&2
    echo "exit status was $status"
@@ -49,7 +49,7 @@
 
 #Call this from anywhere to pass the test with a message
 # usage: pass "reason why the test passed if applicable"
-pass() 
+pass()
  { echo "The test passed!!!"
    echo "$*" 1>&2
    exit 0
@@ -63,7 +63,7 @@
 OS=`uname -s`
 export TRANSPORT_METHOD
 case "$OS" in
-   SunOS | Linux )
+   SunOS | Linux | Darwin )
       PATHSEP=":"
       TRANSPORT_METHOD=dt_socket
       ;;
@@ -80,8 +80,8 @@
       ;;
 esac
 #
-# Want this test to run standalone as well as in the harness, so do the 
-#  following to copy the test's directory into the harness's scratch directory 
+# Want this test to run standalone as well as in the harness, so do the
+#  following to copy the test's directory into the harness's scratch directory
 #  and set all appropriate variables:
 
 if [ -z "${TESTJAVA}" ] ; then
@@ -95,7 +95,7 @@
    if [ -n "$1" ] ; then
           TESTJAVA=$1
       else
-	  TESTJAVA=$JAVA_HOME
+          TESTJAVA=$JAVA_HOME
    fi
    TESTSRC=.
    TESTCLASSES=.
diff --git a/jdk/test/com/sun/jdi/Solaris32AndSolaris64Test.sh b/jdk/test/com/sun/jdi/Solaris32AndSolaris64Test.sh
index c67a097..457d26c 100644
--- a/jdk/test/com/sun/jdi/Solaris32AndSolaris64Test.sh
+++ b/jdk/test/com/sun/jdi/Solaris32AndSolaris64Test.sh
@@ -41,7 +41,7 @@
 
 #Call this from anywhere to fail the test with an error message
 # usage: fail "reason why the test failed"
-fail() 
+fail()
  { echo "The test failed :-("
    echo "$*" 1>&2
    echo "exit status was $status"
@@ -50,7 +50,7 @@
 
 #Call this from anywhere to pass the test with a message
 # usage: pass "reason why the test passed if applicable"
-pass() 
+pass()
  { echo "The test passed!!!"
    echo "$*" 1>&2
    exit 0
@@ -65,7 +65,7 @@
 testName=$1
 shift
 
-#Set appropriate jdk 
+#Set appropriate jdk
 
 if [ -z "${TESTJAVA}" ] ; then
    # TESTJAVA is not set, so the test is running stand-alone.
@@ -79,7 +79,7 @@
           TESTJAVA=$1
       else
           echo "no JDK specified on command line so using JAVA_HOME=$JAVA_HOME"
-	  TESTJAVA=$JAVA_HOME
+          TESTJAVA=$JAVA_HOME
    fi
    TESTSRC=.
    TESTCLASSES=.
@@ -104,15 +104,15 @@
       PATHSEP=":"
       PTYPE=`uname -p`
       if [ -x /usr/bin/isainfo ]; then
-	  # Instruction set being used by the OS
-	  ISET=`isainfo -k`
+          # Instruction set being used by the OS
+          ISET=`isainfo -k`
       else
-	  #SunOS 5.6 didn't have "isainfo"
+          #SunOS 5.6 didn't have "isainfo"
           pass "This test always passes on $OS/$PTYPE (32-bit ${ISET})"
       fi
       ;;
 
-   Linux )
+   Linux | Darwin )
       pass "This test always passes on $OS"
       ;;
 
@@ -156,12 +156,12 @@
    pass "This test always passes on $OS/$PTYPE if 64 bit jdk is not installed"
 fi
 
-# Want this test to run standalone as well as in the harness, so do the 
-#  following to copy the test's directory into the harness's scratch directory 
+# Want this test to run standalone as well as in the harness, so do the
+#  following to copy the test's directory into the harness's scratch directory
 #  and set all appropriate variables:
 
 #Deal with .class files:
-if [ -n "${STANDALONE}" ] ; then 
+if [ -n "${STANDALONE}" ] ; then
    #if running standalone, compile the support files
    ${TESTJAVA}/bin/javac -d ${TESTCLASSES} \
             -classpath "$TESTJAVA/lib/tools.jar${PATHSEP}${TESTSRC}" \
@@ -177,7 +177,7 @@
 if [ ! -r ${filename} ] ; then
     filename=$TESTCLASSES/../@debuggeeVMOptions
 fi
-# Remove -d32, -d64 if present, and remove -XX:[+-]UseCompressedOops 
+# Remove -d32, -d64 if present, and remove -XX:[+-]UseCompressedOops
 # if present since it is illegal in 32 bit mode.
 if [ -r ${filename} ] ; then
     DEBUGGEEFLAGS=`cat ${filename} | sed \
@@ -204,19 +204,19 @@
         DEBUGGERFLAGS="-d${DEBUGGERMODEL} -showversion -DEXPECTED=${TARGETMODEL}"
         CONNECTSTRING="-connect 'com.sun.jdi.CommandLineLaunch:options=-d${TARGETMODEL} $DEBUGGEEFLAGS -showversion'"
 
-	for TARGETCLASS in $testName ; do
-	    echo "--------------------------------------------"
-	    echo "debugger=${DEBUGGERMODEL} debugee=${TARGETMODEL} class=${TARGETCLASS}"
-	    echo "--------------------------------------------"
-	    echo ${TESTJAVA}/bin/java -DHANGINGJAVA_DEB ${DEBUGGERFLAGS} ${CP} ${TARGETCLASS} ${CONNECTSTRING}
-	    eval ${TESTJAVA}/bin/java -DHANGINGJAVA_DEB ${DEBUGGERFLAGS} ${CP} ${TARGETCLASS} ${CONNECTSTRING}
-	    status=$?
-	    if [ $status -ne "0" ];
-	       then fail "$DEBUGGERMODEL to $TARGETMODEL test failed for class=$TARGETCLASS!"
-	    fi
-	done
+        for TARGETCLASS in $testName ; do
+            echo "--------------------------------------------"
+            echo "debugger=${DEBUGGERMODEL} debugee=${TARGETMODEL} class=${TARGETCLASS}"
+            echo "--------------------------------------------"
+            echo ${TESTJAVA}/bin/java -DHANGINGJAVA_DEB ${DEBUGGERFLAGS} ${CP} ${TARGETCLASS} ${CONNECTSTRING}
+            eval ${TESTJAVA}/bin/java -DHANGINGJAVA_DEB ${DEBUGGERFLAGS} ${CP} ${TARGETCLASS} ${CONNECTSTRING}
+            status=$?
+            if [ $status -ne "0" ];
+               then fail "$DEBUGGERMODEL to $TARGETMODEL test failed for class=$TARGETCLASS!"
+            fi
+        done
     done
-done  
+done
 #
 # pass or fail the test based on status of the command
 if [ $status -eq "0" ];
diff --git a/jdk/test/com/sun/jdi/connect/spi/JdiLoadedByCustomLoader.sh b/jdk/test/com/sun/jdi/connect/spi/JdiLoadedByCustomLoader.sh
index ea16378..f68fc94 100644
--- a/jdk/test/com/sun/jdi/connect/spi/JdiLoadedByCustomLoader.sh
+++ b/jdk/test/com/sun/jdi/connect/spi/JdiLoadedByCustomLoader.sh
@@ -45,10 +45,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PS=":"
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     ;;
   Windows* | CYGWIN*)
@@ -65,7 +62,7 @@
 SOMEOTHERDIR="${TESTCLASSES}"/someotherdir
 
 # Compile test into the classes directory
-# Compile the list connectors class into a directory that isn't on 
+# Compile the list connectors class into a directory that isn't on
 # any class path.
 
 $JAVAC -d "${TESTCLASSES}" "${TESTSRC}"/JdiLoadedByCustomLoader.java
@@ -74,7 +71,7 @@
 $JAVAC -d "${SOMEOTHERDIR}" -classpath "${TESTSRC}${PS}${TESTJAVA}/lib/tools.jar" \
     "${TESTSRC}"/ListConnectors.java
 
-# Run the test 
+# Run the test
 
 "${JAVA}" -classpath "${TESTCLASSES}" JdiLoadedByCustomLoader \
     "${SOMEOTHERDIR}"
diff --git a/jdk/test/com/sun/jndi/ldap/LdapsReadTimeoutTest.java b/jdk/test/com/sun/jndi/ldap/LdapsReadTimeoutTest.java
new file mode 100644
index 0000000..9fae77d
--- /dev/null
+++ b/jdk/test/com/sun/jndi/ldap/LdapsReadTimeoutTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 7094377
+ * @summary Com.sun.jndi.ldap.read.timeout doesn't work with ldaps.
+ */
+
+import java.net.Socket;
+import java.net.ServerSocket;
+import java.io.*;
+import javax.naming.*;
+import javax.naming.directory.*;
+import java.util.Hashtable;
+
+public class LdapsReadTimeoutTest {
+
+    public static void main(String[] args) throws Exception {
+        boolean passed = false;
+
+        // create the server
+        try (Server server = Server.create()) {
+            // Set up the environment for creating the initial context
+            Hashtable<String,Object> env = new Hashtable<>(11);
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                "com.sun.jndi.ldap.LdapCtxFactory");
+            env.put("com.sun.jndi.ldap.connect.timeout", "1000");
+            env.put("com.sun.jndi.ldap.read.timeout", "1000");
+            env.put(Context.PROVIDER_URL, "ldaps://localhost:" + server.port());
+
+
+            // Create initial context
+            DirContext ctx = new InitialDirContext(env);
+            try {
+                System.out.println("LDAP Client: Connected to the Server");
+
+                SearchControls scl = new SearchControls();
+                scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
+                System.out.println("Performing Search");
+                NamingEnumeration<SearchResult> answer =
+                    ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl);
+            } finally {
+                // Close the context when we're done
+                ctx.close();
+            }
+        } catch (NamingException e) {
+            passed = true;
+            e.printStackTrace();
+        }
+
+        if (!passed) {
+            throw new Exception("Read timeout test failed," +
+                         " read timeout exception not thrown");
+        }
+        System.out.println("The test PASSED");
+    }
+
+    static class Server implements Runnable, Closeable {
+        private final ServerSocket ss;
+        private Socket sref;
+
+        private Server(ServerSocket ss) {
+            this.ss = ss;
+        }
+
+        static Server create() throws IOException {
+            Server server = new Server(new ServerSocket(0));
+            new Thread(server).start();
+            return server;
+        }
+
+        int port() {
+            return ss.getLocalPort();
+        }
+
+        public void run() {
+            try (Socket s = ss.accept()) {
+                sref = s;
+                System.out.println("Server: Connection accepted");
+                BufferedInputStream bis =
+                    new BufferedInputStream(s.getInputStream());
+                byte[] buf = new byte[100];
+                int n;
+                do {
+                    n = bis.read(buf);
+                } while (n > 0);
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+
+        public void close() throws IOException {
+            ss.close();
+            sref.close();
+        }
+    }
+}
diff --git a/jdk/test/com/sun/tools/attach/CommonSetup.sh b/jdk/test/com/sun/tools/attach/CommonSetup.sh
index b05d5d3..a37d0d1 100644
--- a/jdk/test/com/sun/tools/attach/CommonSetup.sh
+++ b/jdk/test/com/sun/tools/attach/CommonSetup.sh
@@ -36,11 +36,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PS=":"
-    FS="/"
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -72,7 +68,7 @@
   echo "TESTSRC not set.  Test cannot execute.  Failed."
   exit 1
 fi
- 
+
 if [ "${TESTCLASSES}" = "" ]
 then
   echo "TESTCLASSES not set.  Test cannot execute.  Failed."
diff --git a/jdk/test/java/beans/XMLEncoder/Test7092744.java b/jdk/test/java/beans/XMLEncoder/Test7092744.java
new file mode 100644
index 0000000..52f029b
--- /dev/null
+++ b/jdk/test/java/beans/XMLEncoder/Test7092744.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7092744
+ * @summary Tests for ambiguous methods
+ * @author Sergey Malenkov
+ */
+
+public class Test7092744 extends AbstractTest {
+
+    public static void main(String[] args) {
+        new Test7092744().test(true);
+    }
+
+    protected Object getObject() {
+        return new Bean();
+    }
+
+    protected Object getAnotherObject() {
+        Bean bean = new Bean();
+        bean.setValue(99);
+        return bean;
+    }
+
+    public static interface I<T extends Number> {
+
+        T getValue();
+
+        void setValue(T value);
+    }
+
+    public static class Bean implements I<Integer> {
+
+        private Integer value;
+
+        public Integer getValue() {
+            return this.value;
+        }
+
+        public void setValue(Integer value) {
+            this.value = value;
+        }
+    }
+}
diff --git a/jdk/test/java/io/Serializable/evolution/RenamePackage/run.sh b/jdk/test/java/io/Serializable/evolution/RenamePackage/run.sh
index 8b1ea63..8fdbf2a 100644
--- a/jdk/test/java/io/Serializable/evolution/RenamePackage/run.sh
+++ b/jdk/test/java/io/Serializable/evolution/RenamePackage/run.sh
@@ -41,7 +41,7 @@
 # Need to determine the classpath separator and filepath separator based on the
 # operating system.
 case "$OS" in
-SunOS | Linux )
+SunOS | Linux | Darwin )
   PS=":"  ;;
 Windows* | CYGWIN* )
   PS=";"  ;;
@@ -55,19 +55,19 @@
 MKDIR=mkdir
 RDEL="rm -r"
 
-if [ -d ${TESTCLASSES}/oclasses ] 
+if [ -d ${TESTCLASSES}/oclasses ]
 then
-   ${RDEL} ${TESTCLASSES}/oclasses 
+   ${RDEL} ${TESTCLASSES}/oclasses
 fi
-if [ -d ${TESTCLASSES}/nclasses ] 
+if [ -d ${TESTCLASSES}/nclasses ]
 then
-   ${RDEL} ${TESTCLASSES}/nclasses 
+   ${RDEL} ${TESTCLASSES}/nclasses
 fi
-if [ -d ${TESTCLASSES}/share ] 
+if [ -d ${TESTCLASSES}/share ]
 then
-   ${RDEL} ${TESTCLASSES}/share 
+   ${RDEL} ${TESTCLASSES}/share
 fi
-if [ -f ${TESTCLASSES}/stream.ser ] 
+if [ -f ${TESTCLASSES}/stream.ser ]
 then
    ${RDEL} ${TESTCLASSES}/stream.ser
 fi
@@ -77,7 +77,7 @@
 mkdir ${TESTCLASSES}/nclasses
 
 # Build sources
-set -e 
+set -e
 ${JAVAC} -d ${TESTCLASSES}/share ${TESTSRC}/extension/ExtendedObjectInputStream.java
 CLASSPATH=${TESTCLASSES}/share; export CLASSPATH;
 ${JAVAC} -d ${TESTCLASSES}/oclasses ${TESTSRC}/test/SerialDriver.java
diff --git a/jdk/test/java/io/Serializable/serialver/classpath/run.sh b/jdk/test/java/io/Serializable/serialver/classpath/run.sh
index 9cfb623..ef762f2 100644
--- a/jdk/test/java/io/Serializable/serialver/classpath/run.sh
+++ b/jdk/test/java/io/Serializable/serialver/classpath/run.sh
@@ -47,7 +47,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"    ;;
   Windows* | CYGWIN* )
     PS=";"    ;;
diff --git a/jdk/test/java/io/Serializable/serialver/nested/run.sh b/jdk/test/java/io/Serializable/serialver/nested/run.sh
index 77f8eff..7a0274b 100644
--- a/jdk/test/java/io/Serializable/serialver/nested/run.sh
+++ b/jdk/test/java/io/Serializable/serialver/nested/run.sh
@@ -25,7 +25,7 @@
 # @bug 4312217 4785473
 # @summary Test the use of the -classpath switch in the serialver application.
 # @author Naveen Sanjeeva
-# 
+#
 # @build Test
 # @run shell run.sh
 
@@ -43,11 +43,11 @@
   echo "FAILED!!!"
   exit 1
 fi
-  
+
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"    ;;
   Windows* | CYGWIN* )
     PS=";"    ;;
diff --git a/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh b/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh
index 87f3a1a..e5170c7 100644
--- a/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh
+++ b/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh
@@ -22,9 +22,9 @@
 #
 # @test
 # @bug 4735126
-# @summary (cl) ClassLoader.loadClass locks all instances in chain 
+# @summary (cl) ClassLoader.loadClass locks all instances in chain
 #          when delegating
-# 
+#
 # @run shell/timeout=300 TestCrossDelegate.sh
 
 # if running by hand on windows, change TESTSRC and TESTCLASSES to "."
@@ -51,6 +51,9 @@
   Linux )
     FS="/"
     ;;
+  Darwin )
+    FS="/"
+    ;;
   Windows*)
     FS="\\"
     ;;
diff --git a/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh b/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh
index 61cff74..31f2f81 100644
--- a/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh
+++ b/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh
@@ -22,9 +22,9 @@
 #
 # @test
 # @bug 4735126
-# @summary (cl) ClassLoader.loadClass locks all instances in chain 
+# @summary (cl) ClassLoader.loadClass locks all instances in chain
 #          when delegating
-# 
+#
 # @run shell/timeout=10 TestOneWayDelegate.sh
 
 # if running by hand on windows, change TESTSRC and TESTCLASSES to "."
@@ -55,6 +55,9 @@
   Linux )
     FS="/"
     ;;
+  Darwin )
+    FS="/"
+    ;;
   Windows* | CYGWIN* )
     FS="\\"
     ;;
diff --git a/jdk/test/java/lang/ProcessBuilder/Basic.java b/jdk/test/java/lang/ProcessBuilder/Basic.java
index 6777354..7ef1652 100644
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java
@@ -1632,6 +1632,14 @@
             } else {
                 envp = envpOth;
             }
+            System.out.println ("cmdp");
+            for (int i=0; i<cmdp.length; i++) {
+                System.out.printf ("cmdp %d: %s\n", i, cmdp[i]);
+            }
+            System.out.println ("envp");
+            for (int i=0; i<envp.length; i++) {
+                System.out.printf ("envp %d: %s\n", i, envp[i]);
+            }
             Process p = Runtime.getRuntime().exec(cmdp, envp);
             check(commandOutput(p).equals(Windows.is() ? "SystemRoot="+systemRoot+",LC_ALL=C," : "LC_ALL=C,"),
                   "Incorrect handling of envstrings containing NULs");
diff --git a/jdk/test/java/lang/ProcessBuilder/Zombies.java b/jdk/test/java/lang/ProcessBuilder/Zombies.java
index 6e61ec3..7eb1ed8 100644
--- a/jdk/test/java/lang/ProcessBuilder/Zombies.java
+++ b/jdk/test/java/lang/ProcessBuilder/Zombies.java
@@ -49,11 +49,11 @@
         } catch (IOException _) {/* OK */}
 
         try {
-            rt.exec("/bin/true", null, new File("no-such-dir"));
+            rt.exec("/usr/bin/true", null, new File("no-such-dir"));
             throw new Error("expected IOException not thrown");
         } catch (IOException _) {/* OK */}
 
-        rt.exec("/bin/true").waitFor();
+        rt.exec("/usr/bin/true").waitFor();
 
         // Count all the zombies that are children of this Java process
         final String[] zombieCounter = {
diff --git a/jdk/test/java/lang/StringCoding/CheckEncodings.sh b/jdk/test/java/lang/StringCoding/CheckEncodings.sh
index 7862722..95c2419 100644
--- a/jdk/test/java/lang/StringCoding/CheckEncodings.sh
+++ b/jdk/test/java/lang/StringCoding/CheckEncodings.sh
@@ -30,7 +30,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux ) ;;
+  SunOS | Linux | Darwin) ;;
   Windows* | CYGWIN* )
     echo "Passed"; exit 0 ;;
   * ) echo "Unrecognized system!" ;  exit 1 ;;
@@ -63,7 +63,7 @@
 for i in `xargs < locale_union.txt` ; do
   runTest ${i}
 done
-  
+
 # random strings
 for i in FOO 1234 ZZ; do
   runTest ${i}
diff --git a/jdk/test/java/lang/annotation/loaderLeak/LoaderLeak.sh b/jdk/test/java/lang/annotation/loaderLeak/LoaderLeak.sh
index 6c53bf5..7322b08 100644
--- a/jdk/test/java/lang/annotation/loaderLeak/LoaderLeak.sh
+++ b/jdk/test/java/lang/annotation/loaderLeak/LoaderLeak.sh
@@ -44,7 +44,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin)
     NULL=/dev/null
     PS=":"
     FS="/"
diff --git a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh
index 8b8d8ef..6a72184 100644
--- a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh
+++ b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh
@@ -43,6 +43,10 @@
     PS=":"
     FS="/"
     ;;
+  Darwin )
+    PS=":"
+    FS="/"
+    ;;
   Windows*)
     PS=";"
     OS="Windows"
diff --git a/jdk/test/java/lang/management/OperatingSystemMXBean/TestSystemLoadAvg.sh b/jdk/test/java/lang/management/OperatingSystemMXBean/TestSystemLoadAvg.sh
index f31d5db..7c1a5ae 100644
--- a/jdk/test/java/lang/management/OperatingSystemMXBean/TestSystemLoadAvg.sh
+++ b/jdk/test/java/lang/management/OperatingSystemMXBean/TestSystemLoadAvg.sh
@@ -21,10 +21,10 @@
 # questions.
 #
 
-# 
+#
 # @test
 # @summary  Tests OperatingSystemMXBean.getSystemLoadAverage() api.
-# @author   Mandy Chung 
+# @author   Mandy Chung
 # @bug      6336608 6367473 6511738
 #
 # @run build GetSystemLoadAverage
@@ -61,10 +61,7 @@
 while true; do
   echo "Run $i: TestSystemLoadAvg"
   case `uname -s` in
-       SunOS )
-         runOne GetSystemLoadAverage 
-         ;;
-       Linux )
+       SunOS | Linux | Darwin )
          runOne GetSystemLoadAverage
          ;;
       * )
@@ -81,6 +78,6 @@
       exit 1
   fi
   i=`expr $i + 1`
-  # sleep for 5 seconds 
+  # sleep for 5 seconds
   sleep 5
 done
diff --git a/jdk/test/java/net/Authenticator/B4933582.sh b/jdk/test/java/net/Authenticator/B4933582.sh
index a7fc1bc..90af3b5 100644
--- a/jdk/test/java/net/Authenticator/B4933582.sh
+++ b/jdk/test/java/net/Authenticator/B4933582.sh
@@ -26,7 +26,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/java/net/DatagramSocket/Send12k.java b/jdk/test/java/net/DatagramSocket/Send12k.java
index 4efb2f7..c9d7bc6 100644
--- a/jdk/test/java/net/DatagramSocket/Send12k.java
+++ b/jdk/test/java/net/DatagramSocket/Send12k.java
@@ -33,10 +33,16 @@
 
 public class Send12k {
 
-    static final int SEND_SIZE = 16 * 1024;
 
     public static void main(String args[]) throws Exception {
 
+         int SEND_SIZE=0;
+
+         if(System.getProperty("os.name").contains("Mac")) {
+             SEND_SIZE = 16 * 576;
+         } else {
+             SEND_SIZE = 16 * 1024;
+         }
         DatagramSocket s1 = new DatagramSocket();
         DatagramSocket s2 = new DatagramSocket();
 
diff --git a/jdk/test/java/net/DatagramSocket/SetDatagramSocketImplFactory/ADatagramSocket.sh b/jdk/test/java/net/DatagramSocket/SetDatagramSocketImplFactory/ADatagramSocket.sh
index c401e9a..092e12d 100644
--- a/jdk/test/java/net/DatagramSocket/SetDatagramSocketImplFactory/ADatagramSocket.sh
+++ b/jdk/test/java/net/DatagramSocket/SetDatagramSocketImplFactory/ADatagramSocket.sh
@@ -27,7 +27,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS )
+  SunOS | Darwin )
     PATHSEP=":"
     FILESEP="/"
     ;;
diff --git a/jdk/test/java/net/NetworkInterface/NetParamsTest.java b/jdk/test/java/net/NetworkInterface/NetParamsTest.java
index 7eff733..dd6d172 100644
--- a/jdk/test/java/net/NetworkInterface/NetParamsTest.java
+++ b/jdk/test/java/net/NetworkInterface/NetParamsTest.java
@@ -45,7 +45,9 @@
         System.out.println("\tPoint to Point: " + netif.isPointToPoint());
         System.out.println("\tVirtual: " + netif.isVirtual());
         if (netif.isVirtual()) {
-            System.out.println("\tParent Interface: " + netif.getParent().getName());
+            NetworkInterface parent = netif.getParent();
+            String parentName = parent == null ? "null" : parent.getName();
+            System.out.println("\tParent Interface: " + parentName);
         }
         System.out.println("\tMulticast: " + netif.supportsMulticast());
 
diff --git a/jdk/test/java/net/Socket/OldSocketImpl.sh b/jdk/test/java/net/Socket/OldSocketImpl.sh
index d300e20..09e4092 100644
--- a/jdk/test/java/net/Socket/OldSocketImpl.sh
+++ b/jdk/test/java/net/Socket/OldSocketImpl.sh
@@ -28,7 +28,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -46,10 +46,10 @@
     ;;
 esac
 
-# no need to compile the test. It is already compiled 
+# no need to compile the test. It is already compiled
 # with 1.3 and in OldStyleImpl.jar
 
-# run 
+# run
 ${TESTJAVA}${FS}bin${FS}java -cp ${TESTSRC}${FS}OldSocketImpl.jar OldSocketImpl
 result=$?
 if [ "$result" -ne "0" ]; then
diff --git a/jdk/test/java/net/URL/B5086147.sh b/jdk/test/java/net/URL/B5086147.sh
index 95d39f8..75d8946 100644
--- a/jdk/test/java/net/URL/B5086147.sh
+++ b/jdk/test/java/net/URL/B5086147.sh
@@ -26,7 +26,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     exit 0
     ;;
   CYGWIN* )
diff --git a/jdk/test/java/net/URL/runconstructor.sh b/jdk/test/java/net/URL/runconstructor.sh
index dc913fd..04e397a 100644
--- a/jdk/test/java/net/URL/runconstructor.sh
+++ b/jdk/test/java/net/URL/runconstructor.sh
@@ -27,7 +27,7 @@
 #
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/java/net/URLClassLoader/B5077773.sh b/jdk/test/java/net/URLClassLoader/B5077773.sh
index fa3a49d..9724ac9 100644
--- a/jdk/test/java/net/URLClassLoader/B5077773.sh
+++ b/jdk/test/java/net/URLClassLoader/B5077773.sh
@@ -34,7 +34,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
+  SunOS | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/java/net/URLClassLoader/sealing/checksealed.sh b/jdk/test/java/net/URLClassLoader/sealing/checksealed.sh
index 46b522e..80f0adc 100644
--- a/jdk/test/java/net/URLClassLoader/sealing/checksealed.sh
+++ b/jdk/test/java/net/URLClassLoader/sealing/checksealed.sh
@@ -27,13 +27,13 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
+  SunOS | Darwin )
     PS=":"
-    FS="/"            
+    FS="/"
     ;;
   Linux )
     PS=":"
-    FS="/"            
+    FS="/"
     ;;
   CYGWIN* )
     PS=";"
diff --git a/jdk/test/java/net/URLConnection/6212146/test.sh b/jdk/test/java/net/URLConnection/6212146/test.sh
index 740bedc..bc24a5e 100644
--- a/jdk/test/java/net/URLConnection/6212146/test.sh
+++ b/jdk/test/java/net/URLConnection/6212146/test.sh
@@ -33,7 +33,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
+  SunOS | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -67,7 +67,7 @@
 
 WD=`pwd`
 ulimit -H -n 300
-${TESTJAVA}${FS}bin${FS}java Test ${WD}/jars/ test.jar 
+${TESTJAVA}${FS}bin${FS}java Test ${WD}/jars/ test.jar
 result=$?
 rm -rf jars
 exit $?
diff --git a/jdk/test/java/net/URLConnection/Redirect307Test.java b/jdk/test/java/net/URLConnection/Redirect307Test.java
index b9e7749..c71dad4 100644
--- a/jdk/test/java/net/URLConnection/Redirect307Test.java
+++ b/jdk/test/java/net/URLConnection/Redirect307Test.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 4380568
+ * @bug 4380568 7095949
  * @summary  HttpURLConnection does not support 307 redirects
  */
 import java.io.*;
@@ -31,10 +31,9 @@
 
 class RedirServer extends Thread {
 
-    ServerSocket s;
-    Socket   s1;
-    InputStream  is;
-    OutputStream os;
+    static final int TIMEOUT = 10 * 1000;
+
+    ServerSocket ss;
     int port;
 
     String reply1Part1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
@@ -46,10 +45,10 @@
         "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
         "<html>Hello</html>";
 
-    RedirServer (ServerSocket y) {
-        s = y;
-        port = s.getLocalPort();
-        System.out.println("Server created listening on " + port);
+    RedirServer (ServerSocket ss) throws IOException {
+        this.ss = ss;
+        this.ss.setSoTimeout(TIMEOUT);
+        port = this.ss.getLocalPort();
     }
 
     String reply2 = "HTTP/1.1 200 Ok\r\n" +
@@ -59,74 +58,64 @@
         "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
         "World";
 
+    static final byte[] requestEnd = new byte[] {'\r', '\n', '\r', '\n' };
+
+    // Read until the end of a HTTP request
+    void readOneRequest(InputStream is) throws IOException {
+        int requestEndCount = 0, r;
+        while ((r = is.read()) != -1) {
+            if (r == requestEnd[requestEndCount]) {
+                requestEndCount++;
+                if (requestEndCount == 4) {
+                    break;
+                }
+            } else {
+                requestEndCount = 0;
+            }
+        }
+    }
+
     public void run () {
         try {
-            s1 = s.accept ();
-            is = s1.getInputStream ();
-            os = s1.getOutputStream ();
-            is.read ();
-            String reply = reply1Part1 + port + reply1Part2;
-            os.write (reply.getBytes());
-            os.close();
+            try (Socket s = ss.accept()) {
+                s.setSoTimeout(TIMEOUT);
+                readOneRequest(s.getInputStream());
+                String reply = reply1Part1 + port + reply1Part2;
+                s.getOutputStream().write(reply.getBytes());
+            }
+
             /* wait for redirected connection */
-            s.setSoTimeout (5000);
-            s1 = s.accept ();
-            is = s1.getInputStream ();
-            os = s1.getOutputStream ();
-            is.read();
-            os.write (reply2.getBytes());
-            os.close();
-        }
-        catch (Exception e) {
-            /* Just need thread to terminate */
-            System.out.println("Server: caught " + e);
+            try (Socket s = ss.accept()) {
+                s.setSoTimeout(TIMEOUT);
+                readOneRequest(s.getInputStream());
+                s.getOutputStream().write(reply2.getBytes());
+            }
+        } catch (Exception e) {
             e.printStackTrace();
         } finally {
-            try { s.close(); } catch (IOException unused) {}
+            try { ss.close(); } catch (IOException unused) {}
         }
     }
 };
 
 
 public class Redirect307Test {
-
-    public static final int DELAY = 10;
-
     public static void main(String[] args) throws Exception {
-        int port;
-        RedirServer server;
-        ServerSocket sock;
+        ServerSocket sock = new ServerSocket(0);
+        int port = sock.getLocalPort();
+        RedirServer server = new RedirServer(sock);
+        server.start();
 
-        try {
-            sock = new ServerSocket (0);
-            port = sock.getLocalPort ();
-        }
-        catch (Exception e) {
-            System.out.println ("Exception: " + e);
-            return;
-        }
+        URL url = new URL("http://localhost:" + port);
+        URLConnection conURL =  url.openConnection();
+        conURL.setDoInput(true);
+        conURL.setAllowUserInteraction(false);
+        conURL.setUseCaches(false);
 
-        server = new RedirServer(sock);
-        server.start ();
-
-        try  {
-
-            String s = "http://localhost:" + port;
-            URL url = new URL(s);
-            URLConnection conURL =  url.openConnection();
-
-            conURL.setDoInput(true);
-            conURL.setAllowUserInteraction(false);
-            conURL.setUseCaches(false);
-
-            InputStream in = conURL.getInputStream();
+        try (InputStream in = conURL.getInputStream()) {
             if ((in.read() != (int)'W') || (in.read()!=(int)'o')) {
                 throw new RuntimeException ("Unexpected string read");
             }
         }
-        catch(IOException e) {
-            e.printStackTrace();
-            throw new RuntimeException ("Exception caught + " + e);
-        }
     }
 }
diff --git a/jdk/test/java/net/URLConnection/RedirectLimit.java b/jdk/test/java/net/URLConnection/RedirectLimit.java
index 5fe65a1..ea90c69 100644
--- a/jdk/test/java/net/URLConnection/RedirectLimit.java
+++ b/jdk/test/java/net/URLConnection/RedirectLimit.java
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 4458085
+ * @bug 4458085 7095949
  * @summary  Redirects Limited to 5
  */
 
@@ -57,29 +57,43 @@
     final ServerSocket ss;
     final int port;
 
-    RedirLimitServer(ServerSocket ss) {
+    RedirLimitServer(ServerSocket ss) throws IOException {
         this.ss = ss;
-        port = ss.getLocalPort();
+        port = this.ss.getLocalPort();
+        this.ss.setSoTimeout(TIMEOUT);
+    }
+
+    static final byte[] requestEnd = new byte[] {'\r', '\n', '\r', '\n' };
+
+    // Read until the end of a HTTP request
+    void readOneRequest(InputStream is) throws IOException {
+        int requestEndCount = 0, r;
+        while ((r = is.read()) != -1) {
+            if (r == requestEnd[requestEndCount]) {
+                requestEndCount++;
+                if (requestEndCount == 4) {
+                    break;
+                }
+            } else {
+                requestEndCount = 0;
+            }
+        }
     }
 
     public void run() {
         try {
-            ss.setSoTimeout(TIMEOUT);
             for (int i=0; i<NUM_REDIRECTS; i++) {
                 try (Socket s = ss.accept()) {
                     s.setSoTimeout(TIMEOUT);
-                    InputStream is = s.getInputStream();
-                    OutputStream os = s.getOutputStream();
-                    is.read();
+                    readOneRequest(s.getInputStream());
                     String reply = reply1 + port + "/redirect" + i + reply2;
-                    os.write(reply.getBytes());
+                    s.getOutputStream().write(reply.getBytes());
                 }
             }
             try (Socket s = ss.accept()) {
-                InputStream is = s.getInputStream();
-                OutputStream os = s.getOutputStream();
-                is.read();
-                os.write(reply3.getBytes());
+                s.setSoTimeout(TIMEOUT);
+                readOneRequest(s.getInputStream());
+                s.getOutputStream().write(reply3.getBytes());
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -96,21 +110,17 @@
         RedirLimitServer server = new RedirLimitServer(ss);
         server.start();
 
-        InputStream in = null;
-        try {
-            URL url = new URL("http://localhost:" + port);
-            URLConnection conURL =  url.openConnection();
+        URL url = new URL("http://localhost:" + port);
+        URLConnection conURL =  url.openConnection();
 
-            conURL.setDoInput(true);
-            conURL.setAllowUserInteraction(false);
-            conURL.setUseCaches(false);
+        conURL.setDoInput(true);
+        conURL.setAllowUserInteraction(false);
+        conURL.setUseCaches(false);
 
-            in = conURL.getInputStream();
+        try (InputStream in = conURL.getInputStream()) {
             if ((in.read() != (int)'W') || (in.read()!=(int)'o')) {
                 throw new RuntimeException("Unexpected string read");
             }
-        } finally {
-            if ( in != null ) { in.close(); }
         }
     }
 }
diff --git a/jdk/test/java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh b/jdk/test/java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh
index ab6d609..87b382c 100644
--- a/jdk/test/java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh
+++ b/jdk/test/java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh
@@ -54,6 +54,10 @@
     PATHSEP=":"
     FILESEP="/"
     ;;
+  Darwin )
+    PATHSEP=":"
+    FILESEP="/"
+    ;;
   CYGWIN* )
     PATHSEP=";"
     FILESEP="/"
@@ -75,17 +79,17 @@
 
 # compile the test program
 ${TESTJAVA}${FILESEP}bin${FILESEP}javac \
-	-d ${TESTCLASSES}${FILESEP} \
-	${TESTSRC}${FILESEP}ClassLoaderDeadlock.java
+        -d ${TESTCLASSES}${FILESEP} \
+        ${TESTSRC}${FILESEP}ClassLoaderDeadlock.java
 
 ${TESTJAVA}${FILESEP}bin${FILESEP}javac \
-	-d ${TESTCLASSES}${FILESEP}provider${FILESEP} \
-	${TESTSRC}${FILESEP}provider${FILESEP}HashProvider.java
+        -d ${TESTCLASSES}${FILESEP}provider${FILESEP} \
+        ${TESTSRC}${FILESEP}provider${FILESEP}HashProvider.java
 
 # run the test
 ${TESTJAVA}${FILESEP}bin${FILESEP}java \
-	-classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}Deadlock.jar" \
-	ClassLoaderDeadlock
+        -classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}Deadlock.jar" \
+        ClassLoaderDeadlock
 
 STATUS=$?
 
diff --git a/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock.sh b/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock.sh
index 609843b..7daa237 100644
--- a/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock.sh
+++ b/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock.sh
@@ -42,6 +42,10 @@
     PATHSEP=":"
     FILESEP="/"
     ;;
+  Darwin )
+    PATHSEP=":"
+    FILESEP="/"
+    ;;
   CYGWIN* )
     PATHSEP=";"
     FILESEP="/"
diff --git a/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh b/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh
index e067300..35342ce 100644
--- a/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh
+++ b/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh
@@ -58,6 +58,10 @@
     PATHSEP=":"
     FILESEP="/"
     ;;
+  Darwin )
+    PATHSEP=":"
+    FILESEP="/"
+    ;;
   Windows* )
     PATHSEP=";"
     FILESEP="\\"
diff --git a/jdk/test/java/security/Security/signedfirst/Dyn.sh b/jdk/test/java/security/Security/signedfirst/Dyn.sh
index 12ed97a..a98e2ff 100644
--- a/jdk/test/java/security/Security/signedfirst/Dyn.sh
+++ b/jdk/test/java/security/Security/signedfirst/Dyn.sh
@@ -54,6 +54,10 @@
     PATHSEP=":"
     FILESEP="/"
     ;;
+  Darwin )
+    PATHSEP=":"
+    FILESEP="/"
+    ;;
   CYGWIN* )
     PATHSEP=";"
     FILESEP="/"
@@ -74,13 +78,13 @@
 
 # compile the test program
 ${TESTJAVA}${FILESEP}bin${FILESEP}javac \
-	-classpath ${TESTSRC}${FILESEP}exp.jar \
-	-d ${TESTCLASSES}${FILESEP} \
-	${TESTSRC}${FILESEP}DynSignedProvFirst.java
+        -classpath ${TESTSRC}${FILESEP}exp.jar \
+        -d ${TESTCLASSES}${FILESEP} \
+        ${TESTSRC}${FILESEP}DynSignedProvFirst.java
 
 # run the test
 ${TESTJAVA}${FILESEP}bin${FILESEP}java \
-	-classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}exp.jar" \
-	DynSignedProvFirst
+        -classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}exp.jar" \
+        DynSignedProvFirst
 
 exit $?
diff --git a/jdk/test/java/security/Security/signedfirst/Static.sh b/jdk/test/java/security/Security/signedfirst/Static.sh
index 812d613..ff66308 100644
--- a/jdk/test/java/security/Security/signedfirst/Static.sh
+++ b/jdk/test/java/security/Security/signedfirst/Static.sh
@@ -54,6 +54,10 @@
     PATHSEP=":"
     FILESEP="/"
     ;;
+  Darwin )
+    PATHSEP=":"
+    FILESEP="/"
+    ;;
   CYGWIN* )
     PATHSEP=";"
     FILESEP="/"
@@ -74,15 +78,15 @@
 
 # compile the test program
 ${TESTJAVA}${FILESEP}bin${FILESEP}javac \
-	-classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}exp.jar" \
-	-d ${TESTCLASSES}${FILESEP} \
-	${TESTSRC}${FILESEP}StaticSignedProvFirst.java
+        -classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}exp.jar" \
+        -d ${TESTCLASSES}${FILESEP} \
+        ${TESTSRC}${FILESEP}StaticSignedProvFirst.java
 
 # run the test
 cd ${TESTSRC}${FILESEP}
 ${TESTJAVA}${FILESEP}bin${FILESEP}java \
-	-classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}exp.jar" \
-	-Djava.security.properties=file:${TESTSRC}${FILESEP}Static.props \
-	StaticSignedProvFirst
+        -classpath "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}exp.jar" \
+        -Djava.security.properties=file:${TESTSRC}${FILESEP}Static.props \
+        StaticSignedProvFirst
 
 exit $?
diff --git a/jdk/test/java/text/Bidi/Bug7051769.java b/jdk/test/java/text/Bidi/Bug7051769.java
new file mode 100644
index 0000000..1a96870
--- /dev/null
+++ b/jdk/test/java/text/Bidi/Bug7051769.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7051769
+ * @summary verify that Bidi.toString() returns the corect result.
+ */
+import java.awt.font.*;
+import java.text.*;
+import java.util.*;
+
+public class Bug7051769 {
+
+    private static boolean err = false;
+
+    public static void main(String[] args) {
+        testNumericShaping();
+
+        if (err) {
+            throw new RuntimeException("Failed");
+        } else {
+            System.out.println("Passed.");
+        }
+    }
+
+    private static void testNumericShaping() {
+        Map attrNS = new HashMap();
+        attrNS.put(TextAttribute.NUMERIC_SHAPING,
+                   NumericShaper.getContextualShaper(NumericShaper.ARABIC));
+        attrNS.put(TextAttribute.RUN_DIRECTION,
+                   TextAttribute.RUN_DIRECTION_RTL);
+
+        String text = "\u0623\u0643\u062a\u0648\u0628\u0631 10";
+        String expected = "sun.text.bidi.BidiBase[dir: 2 baselevel: 1 length: 9 runs: [1 1 1 1 1 1 1 2 2] text: [0x623 0x643 0x62a 0x648 0x628 0x631 0x20 0x661 0x660]]";
+
+        AttributedString as = new AttributedString(text, attrNS);
+        AttributedCharacterIterator itr = as.getIterator();
+        itr.last();
+        itr.next();
+        Bidi bidi = new Bidi(itr);
+        String got = bidi.toString();
+
+        if (!got.equals(expected)) {
+            err = true;
+            System.err.println("Wrong toString() output: " +
+                               "\n\tExpected=" + expected +
+                               "\n\tGot=" + got);
+        }
+    }
+
+}
diff --git a/jdk/test/java/util/Currency/PropertiesTest.sh b/jdk/test/java/util/Currency/PropertiesTest.sh
index 420e9f9..304d102 100644
--- a/jdk/test/java/util/Currency/PropertiesTest.sh
+++ b/jdk/test/java/util/Currency/PropertiesTest.sh
@@ -30,7 +30,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -65,10 +65,10 @@
 # copy the test properties file
 COPIED=0
 if [ -w $TESTJAVA ]
-then 
+then
   WRITABLEJDK=$TESTJAVA
 else
-  WRITABLEJDK=.${FS}testjava 
+  WRITABLEJDK=.${FS}testjava
   cp -r $TESTJAVA $WRITABLEJDK
   COPIED=1
 fi
diff --git a/jdk/test/java/util/Locale/LocaleCategory.sh b/jdk/test/java/util/Locale/LocaleCategory.sh
index ecc6e94..996d687 100644
--- a/jdk/test/java/util/Locale/LocaleCategory.sh
+++ b/jdk/test/java/util/Locale/LocaleCategory.sh
@@ -2,7 +2,7 @@
 #
 # @test
 # @bug 4700857 6997928 7079486
-# @summary tests for Locale.getDefault(Locale.Category) and 
+# @summary tests for Locale.getDefault(Locale.Category) and
 #    Locale.setDefault(Locale.Category, Locale)
 # @build LocaleCategory
 # @run shell/timeout=600 LocaleCategory.sh
@@ -30,7 +30,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | *BSD | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/java/util/PluggableLocale/ExecTest.sh b/jdk/test/java/util/PluggableLocale/ExecTest.sh
index 0e2fdc7..5a12588 100644
--- a/jdk/test/java/util/PluggableLocale/ExecTest.sh
+++ b/jdk/test/java/util/PluggableLocale/ExecTest.sh
@@ -1,21 +1,21 @@
-# 
+#
 # Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
+#
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.
-# 
+#
 # This code is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 # version 2 for more details (a copy is included in the LICENSE file that
 # accompanied this code).
-# 
+#
 # You should have received a copy of the GNU General Public License version
 # 2 along with this work; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
+#
 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 # or visit www.oracle.com if you need additional information or have any
 # questions.
@@ -27,9 +27,9 @@
 # This script is the actual launcher of each locale service provider test.
 # fooprovider.jar contains localized object providers and barprovider.jar
 # contains localized name providers.  This way, we can test providers that
-# can relate to each other (such as, DateFormatSymbolsProvider and 
+# can relate to each other (such as, DateFormatSymbolsProvider and
 # TimeZoneNameProvider) separately.
-# 
+#
 # Parameters:
 #    providersToTest: [foo|bar|foobar]
 #    java class name: <class name>
@@ -58,7 +58,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -80,7 +80,7 @@
     EXTDIRS="${TESTJAVA}${FS}jre${FS}lib${FS}ext${PS}${TESTCLASSES}"
 fi
 
-case "$1" in 
+case "$1" in
   "foo" )
     cp ${TESTSRC}${FS}fooprovider.jar ${TESTCLASSES}
     CLASSPATHARG=".${PS}${TESTSRC}${PS}${TESTSRC}${FS}fooprovider.jar"
@@ -95,7 +95,7 @@
     CLASSPATHARG=".${PS}${TESTSRC}${PS}${TESTSRC}${FS}fooprovider.jar${PS}${TESTSRC}${PS}${TESTSRC}${FS}barprovider.jar"
     ;;
 esac
-    
+
 # compile
 cp ${TESTSRC}${FS}ProviderTest.java .
 cp ${TESTSRC}${FS}$2.java .
@@ -107,7 +107,7 @@
 if [ $result -eq 0 ]
 then
   echo "Compilation of the test case was successful."
-else 
+else
   echo "Compilation of the test case failed."
   # Cleanup
   rm -f ${TESTCLASSES}${FS}$2*.class
diff --git a/jdk/test/java/util/ResourceBundle/Bug6299235Test.sh b/jdk/test/java/util/ResourceBundle/Bug6299235Test.sh
index 9509864..59128d6 100644
--- a/jdk/test/java/util/ResourceBundle/Bug6299235Test.sh
+++ b/jdk/test/java/util/ResourceBundle/Bug6299235Test.sh
@@ -1,21 +1,21 @@
-# 
+#
 # Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
+#
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.
-# 
+#
 # This code is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 # version 2 for more details (a copy is included in the LICENSE file that
 # accompanied this code).
-# 
+#
 # You should have received a copy of the GNU General Public License version
 # 2 along with this work; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
+#
 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 # or visit www.oracle.com if you need additional information or have any
 # questions.
@@ -31,7 +31,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PATHSEP=":"
     FILESEP="/"
     ;;
diff --git a/jdk/test/java/util/ResourceBundle/Control/ExpirationTest.sh b/jdk/test/java/util/ResourceBundle/Control/ExpirationTest.sh
index e798bf9..ea12502 100644
--- a/jdk/test/java/util/ResourceBundle/Control/ExpirationTest.sh
+++ b/jdk/test/java/util/ResourceBundle/Control/ExpirationTest.sh
@@ -1,21 +1,21 @@
-# 
+#
 # Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
+#
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.
-# 
+#
 # This code is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 # version 2 for more details (a copy is included in the LICENSE file that
 # accompanied this code).
-# 
+#
 # You should have received a copy of the GNU General Public License version
 # 2 along with this work; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
+#
 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 # or visit www.oracle.com if you need additional information or have any
 # questions.
@@ -72,7 +72,7 @@
 Windows* | CYGWIN* )
     DEL=";"
     ;;
-SunOS)
+SunOS | Darwin)
     DEL=":"
     ;;
 Linux)
@@ -103,11 +103,11 @@
 
 createJar() {
     if [ "$FORMAT" = "properties" ]; then
-	createProperties
-	F="${DATA}*.properties"
+        createProperties
+        F="${DATA}*.properties"
     else
-	createClasses
-	F="-C classes ${ROOT}.class -C classes ${JA}.class -C classes ${DE}.class"
+        createClasses
+        F="-C classes ${ROOT}.class -C classes ${JA}.class -C classes ${DE}.class"
     fi
     ${TESTJAVA}/bin/jar cf $JARFILE $F
     ${TESTJAVA}/bin/jar tvf $JARFILE
@@ -132,12 +132,12 @@
 
 public class $1 extends ListResourceBundle {
     public Object[][] getContents() {
-	return new Object[][] {
-	    { \"data\", \"$2\" },"
+        return new Object[][] {
+            { \"data\", \"$2\" },"
     if [ "x$3" != "x" ]; then
-	echo "	    { \"january\", \"$3\" },"
+        echo "      { \"january\", \"$3\" },"
     fi
-echo "	};
+echo "  };
     }
 }") >$1.java
 }
@@ -161,11 +161,11 @@
 
 updateJar() {
     if [ "$FORMAT" = "properties" ]; then
-	updateDEaddAT
-	F="$DE $AT"
+        updateDEaddAT
+        F="$DE $AT"
     else
-	updateClassDEaddClassAT
-	F="-C classes ${DE}.class -C classes ${AT}.class"
+        updateClassDEaddClassAT
+        F="-C classes ${DE}.class -C classes ${AT}.class"
     fi
     ${TESTJAVA}/bin/jar uf $JARFILE $F
     rm -f $DE $AT
@@ -175,12 +175,12 @@
 
 getSeconds() {
     if [ "$HAS_S" = "YES" ]; then
-	date '+%s'
+        date '+%s'
     else
-	# Returns an approximation of the offset from the Epoch in
-	# seconds.
-	date -u '+%Y %j %H %M %S' | \
-	awk '{d=($1-1970)*365.2425; print int(((((((d+$2-1)*24)+$3)*60)+$3)*60)+$5);}'
+        # Returns an approximation of the offset from the Epoch in
+        # seconds.
+        date -u '+%Y %j %H %M %S' | \
+        awk '{d=($1-1970)*365.2425; print int(((((((d+$2-1)*24)+$3)*60)+$3)*60)+$5);}'
     fi
 }
 
@@ -196,9 +196,9 @@
     # If this machine is too slow, give up the further testing.
     #
     if [ "$D" -gt $2 ]; then
-	1>&2 echo "This machine took $D seconds to prepare test data," \
-		  "which is too slow to proceed. Exiting..."
-	exit 0
+        1>&2 echo "This machine took $D seconds to prepare test data," \
+                  "which is too slow to proceed. Exiting..."
+        exit 0
     fi
     unset S
     unset E
@@ -207,13 +207,13 @@
 
 checkStatus() {
     if [ $1 = 0 ]; then
-	echo "$2: PASSED"
+        echo "$2: PASSED"
     elif [ $1 != 2 ]; then
-	echo "$2: FAILED"
-	exit 1
+        echo "$2: FAILED"
+        exit 1
     else
-	# Just we should't proceed to avoid timing issues.
-	exit 0
+        # Just we should't proceed to avoid timing issues.
+        exit 0
     fi
 }
 
diff --git a/jdk/test/java/util/ServiceLoader/basic.sh b/jdk/test/java/util/ServiceLoader/basic.sh
index 7ab184e..dc93051 100644
--- a/jdk/test/java/util/ServiceLoader/basic.sh
+++ b/jdk/test/java/util/ServiceLoader/basic.sh
@@ -42,7 +42,7 @@
 
 OS=`uname -s`
 case "$OS" in
-    SunOS )
+    SunOS | Darwin )
       SEP=':' ;;
     Linux )
       SEP=':' ;;
@@ -63,7 +63,7 @@
     for n in 2 3; do
       rm -rf $JARD/*; mkdir -p $JARD/META-INF/services
       echo FooProvider$n \
-	>$JARD/META-INF/services/FooService
+        >$JARD/META-INF/services/FooService
       cp $TESTCLASSES/FooProvider$n.class $JARD
       if [ $n = 3 ]; then
         cp $TESTCLASSES/FooService.class $JARD
diff --git a/jdk/test/javax/crypto/SecretKeyFactory/FailOverTest.sh b/jdk/test/javax/crypto/SecretKeyFactory/FailOverTest.sh
index 3191bdd..01dc34c 100644
--- a/jdk/test/javax/crypto/SecretKeyFactory/FailOverTest.sh
+++ b/jdk/test/javax/crypto/SecretKeyFactory/FailOverTest.sh
@@ -51,7 +51,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
diff --git a/jdk/test/javax/imageio/stream/StreamCloserLeak/run_test.sh b/jdk/test/javax/imageio/stream/StreamCloserLeak/run_test.sh
index 95f0049..1eb3d34 100644
--- a/jdk/test/javax/imageio/stream/StreamCloserLeak/run_test.sh
+++ b/jdk/test/javax/imageio/stream/StreamCloserLeak/run_test.sh
@@ -84,7 +84,7 @@
       TMP="/tmp"
       ;;
 
-   Linux )
+   Linux | Darwin )
       VAR="A different value for Linux"
       DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386
       FILESEP="/"
@@ -123,7 +123,7 @@
    if [ -n "$1" ] ;
       then TESTJAVA=$1
       else echo "no JDK specified on command line so using default!"
-	 TESTJAVA=$DEFAULT_JDK
+         TESTJAVA=$DEFAULT_JDK
    fi
    TESTSRC=.
    TESTCLASSES=.
diff --git a/jdk/test/javax/script/CommonSetup.sh b/jdk/test/javax/script/CommonSetup.sh
index 54276a6..c604cfb 100644
--- a/jdk/test/javax/script/CommonSetup.sh
+++ b/jdk/test/javax/script/CommonSetup.sh
@@ -36,11 +36,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PS=":"
-    FS="/"
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -72,7 +68,7 @@
   echo "TESTSRC not set.  Test cannot execute.  Failed."
   exit 1
 fi
- 
+
 if [ "${TESTCLASSES}" = "" ]
 then
   echo "TESTCLASSES not set.  Test cannot execute.  Failed."
diff --git a/jdk/test/javax/security/auth/Subject/doAs/Test.sh b/jdk/test/javax/security/auth/Subject/doAs/Test.sh
index 69bdc32..bac3085 100644
--- a/jdk/test/javax/security/auth/Subject/doAs/Test.sh
+++ b/jdk/test/javax/security/auth/Subject/doAs/Test.sh
@@ -25,7 +25,7 @@
 
 # @test 1.1, 02/14/01
 # @author  Ram Marti
-# @bug 4399067 
+# @bug 4399067
 # @summary Subject.doAs(null, action) does not clear the executing
 #
 # ${TESTJAVA} is pointing to the jre
@@ -43,6 +43,11 @@
     FS="/"
     RM="/bin/rm -f"
     ;;
+  Darwin )
+    PS=":"
+    FS="/"
+    RM="/bin/rm -f"
+    ;;
   CYGWIN* )
     PS=";"
     FS="/"
@@ -69,6 +74,6 @@
 ${TESTJAVA}${FS}bin${FS}java -classpath "${TESTCLASSES}${FS}" \
 -Djava.security.manager  \
 -Djava.security.policy=${TESTSRC}${FS}policy \
-Test 
+Test
 
 exit $?
diff --git a/jdk/test/javax/swing/JScrollBar/4708809/bug4708809.java b/jdk/test/javax/swing/JScrollBar/4708809/bug4708809.java
new file mode 100644
index 0000000..912ae5f
--- /dev/null
+++ b/jdk/test/javax/swing/JScrollBar/4708809/bug4708809.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4708809
+ * @summary JScrollBar functionality slightly different from native scrollbar
+ * @author Andrey Pikalev
+ * @run main bug4708809
+ */
+import javax.swing.*;
+import java.awt.*;
+import java.awt.Point;
+import java.awt.event.*;
+import sun.awt.SunToolkit;
+
+public class bug4708809 {
+
+    private static volatile boolean do_test = false;
+    private static volatile boolean passed = true;
+    private static JScrollPane spane;
+    private static JScrollBar sbar;
+
+    public static void main(String[] args) throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(350);
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                createAndShowGUI();
+            }
+        });
+
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                spane.requestFocus();
+                sbar.setValue(sbar.getMaximum());
+            }
+        });
+
+        toolkit.realSync();
+
+        Point point = getClickPoint(0.5, 0.5);
+        robot.mouseMove(point.x, point.y);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                final int oldValue = sbar.getValue();
+                sbar.addAdjustmentListener(new AdjustmentListener() {
+
+                    public void adjustmentValueChanged(AdjustmentEvent e) {
+                        if (e.getValue() >= oldValue) {
+                            passed = false;
+                        }
+                        do_test = true;
+                    }
+                });
+
+            }
+        });
+
+        toolkit.realSync();
+
+        point = getClickPoint(0.5, 0.2);
+        robot.mouseMove(point.x, point.y);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+        toolkit.realSync();
+
+        if (!do_test || !passed) {
+            throw new Exception("The scrollbar moved with incorrect direction");
+        }
+
+    }
+
+    private static Point getClickPoint(final double scaleX, final double scaleY) throws Exception {
+        final Point[] result = new Point[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                Point p = sbar.getLocationOnScreen();
+                Rectangle rect = sbar.getBounds();
+                result[0] = new Point((int) (p.x + scaleX * rect.width),
+                        (int) (p.y + scaleY * rect.height));
+            }
+        });
+
+        return result[0];
+
+    }
+
+    private static void createAndShowGUI() {
+        JFrame fr = new JFrame("Test");
+
+        JLabel label = new JLabel("picture");
+        label.setPreferredSize(new Dimension(500, 500));
+        spane = new JScrollPane(label);
+        fr.getContentPane().add(spane);
+        sbar = spane.getVerticalScrollBar();
+
+        fr.setSize(200, 200);
+        fr.setVisible(true);
+    }
+}
diff --git a/jdk/test/javax/swing/JScrollBar/4865918/bug4865918.java b/jdk/test/javax/swing/JScrollBar/4865918/bug4865918.java
new file mode 100644
index 0000000..8a1a804
--- /dev/null
+++ b/jdk/test/javax/swing/JScrollBar/4865918/bug4865918.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4865918
+ * @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar
+ * @author Andrey Pikalev
+ * @run main bug4865918
+ */
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import sun.awt.SunToolkit;
+
+public class bug4865918 {
+
+    private static TestScrollBar sbar;
+
+    public static void main(String[] argv) throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                createAndShowGUI();
+            }
+        });
+
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                sbar.pressMouse();
+            }
+        });
+
+        toolkit.realSync();
+
+        int value = getValue();
+
+        if (value != 9) {
+            throw new Error("The scrollbar block increment is incorect");
+        }
+    }
+
+    private static int getValue() throws Exception {
+        final int[] result = new int[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                result[0] = sbar.getValue();
+            }
+        });
+
+        return result[0];
+    }
+
+    private static void createAndShowGUI() {
+        JFrame frame = new JFrame("bug4865918");
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        sbar = new TestScrollBar(JScrollBar.HORIZONTAL, -1, 10, -100, 100);
+        sbar.setPreferredSize(new Dimension(200, 20));
+        sbar.setBlockIncrement(10);
+
+        frame.getContentPane().add(sbar);
+        frame.pack();
+        frame.setVisible(true);
+
+    }
+
+    static class TestScrollBar extends JScrollBar {
+
+        public TestScrollBar(int orientation, int value, int extent,
+                int min, int max) {
+            super(orientation, value, extent, min, max);
+
+        }
+
+        public void pressMouse() {
+            MouseEvent me = new MouseEvent(sbar,
+                    MouseEvent.MOUSE_PRESSED,
+                    (new Date()).getTime(),
+                    MouseEvent.BUTTON1_MASK,
+                    3 * getWidth() / 4, getHeight() / 2,
+                    1, true);
+            processMouseEvent(me);
+        }
+    }
+}
diff --git a/jdk/test/javax/swing/JSlider/6348946/bug6348946.java b/jdk/test/javax/swing/JSlider/6348946/bug6348946.java
new file mode 100644
index 0000000..7183deb
--- /dev/null
+++ b/jdk/test/javax/swing/JSlider/6348946/bug6348946.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6348946
+ * @summary Tests that JSlider's thumb moves in the right direction
+ *          when it is used as a JTable cell editor.
+ * @author Mikhail Lapshin
+*/
+
+import sun.awt.SunToolkit;
+
+import java.awt.*;
+import java.awt.event.InputEvent;
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.table.*;
+
+public class bug6348946 {
+
+    private static JFrame frame;
+
+    private static JPanel panel;
+
+    private static volatile boolean passed = false;
+
+    public static void main(String[] args) throws Exception {
+        String lf = "javax.swing.plaf.metal.MetalLookAndFeel";
+        UIManager.setLookAndFeel(lf);
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                public void run() {
+                    setupUI();
+                }
+            });
+            toolkit.realSync();
+            clickOnSlider();
+            toolkit.realSync();
+            checkResult();
+        } finally {
+            stopEDT();
+        }
+    }
+
+    private static void setupUI() {
+        frame = new JFrame();
+
+        panel = new JPanel();
+        panel.setLayout(new BorderLayout());
+        panel.add(new ParameterTable(), BorderLayout.CENTER);
+        frame.getContentPane().add(panel);
+
+        frame.pack();
+        frame.setLocationRelativeTo(null);
+        frame.setVisible(true);
+    }
+
+    private static void clickOnSlider() throws Exception {
+        Robot robot = new Robot();
+        robot.setAutoDelay(10);
+
+        Rectangle rect = getPanelRectangle();
+
+        double clickX = rect.getX() + rect.getWidth() / 4;
+        double clickY = rect.getY() + rect.getHeight() / 2;
+        robot.mouseMove((int) clickX, (int) clickY);
+
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+    }
+
+    private static void checkResult(){
+        if (passed) {
+            System.out.println("Test passed");
+        } else {
+            throw new RuntimeException("The thumb moved " +
+                    "to the right instead of the left!");
+        }
+    }
+
+    private static void stopEDT() {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                frame.dispose();
+            }
+        });
+    }
+
+    private static class ParameterTable extends JTable {
+        public ParameterTable() {
+            super(new Object[][]{{5}}, new String[]{"Value"});
+            getColumnModel().getColumn(0).setCellRenderer(new Renderer());
+            getColumnModel().getColumn(0).setCellEditor(new Editor());
+        }
+    }
+
+    private static class Renderer implements TableCellRenderer {
+        private JSlider slider = new JSlider(0, 10);
+
+        public Component getTableCellRendererComponent(JTable table,
+                                                       Object value,
+                                                       boolean isSelected,
+                                                       boolean hasFocus,
+                                                       int row, int col) {
+            int val = (Integer) value;
+            slider.setValue(val);
+            return slider;
+        }
+    }
+
+    private static class Editor extends AbstractCellEditor implements TableCellEditor {
+        private JSlider slider = new JSlider(0, 10);
+
+        public Component getTableCellEditorComponent(JTable table, Object value,
+                                                     boolean isSelected,
+                                                     int row, int col) {
+            int val = (Integer) value;
+            slider.setValue(val);
+            return slider;
+        }
+
+        public Editor() {
+            slider.addChangeListener(new ChangeListener() {
+                public void stateChanged(ChangeEvent e) {
+                    if (!slider.getValueIsAdjusting()) {
+                        passed = slider.getValue() <= 5;
+                    }
+                }
+            });
+        }
+
+        public Object getCellEditorValue() {
+            return slider.getValue();
+        }
+    }
+
+    private static Rectangle getPanelRectangle() throws Exception{
+        final Rectangle[] result = new Rectangle[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                result[0] = new Rectangle(panel.getLocationOnScreen(), panel.getSize());
+            }
+        });
+
+        return result[0];
+    }
+}
diff --git a/jdk/test/javax/swing/JTabbedPane/4624207/bug4624207.java b/jdk/test/javax/swing/JTabbedPane/4624207/bug4624207.java
new file mode 100644
index 0000000..45ca603
--- /dev/null
+++ b/jdk/test/javax/swing/JTabbedPane/4624207/bug4624207.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4624207
+ * @summary JTabbedPane mnemonics don't work from outside the tabbed pane
+ * @author Oleg Mokhovikov
+ * @library ../../regtesthelpers
+ * @build Util
+ * @run main bug4624207
+ */
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.*;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import sun.awt.SunToolkit;
+
+public class bug4624207 implements ChangeListener, FocusListener {
+
+    private static volatile boolean stateChanged = false;
+    private static volatile boolean focusGained = false;
+    private static JTextField txtField;
+    private static JTabbedPane tab;
+    private static Object listener;
+
+    public void stateChanged(ChangeEvent e) {
+        System.out.println("stateChanged called");
+        stateChanged = true;
+    }
+
+    public void focusGained(FocusEvent e) {
+        System.out.println("focusGained called");
+        focusGained = true;
+    }
+
+    public void focusLost(FocusEvent e) {
+        System.out.println("focusLost called");
+        focusGained = false;
+    }
+
+    public static void main(String[] args) throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(50);
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                createAndShowGUI();
+            }
+        });
+
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                txtField.requestFocus();
+            }
+        });
+
+        toolkit.realSync();
+
+        if (!focusGained) {
+            throw new RuntimeException("Couldn't gain focus for text field");
+        }
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                tab.addChangeListener((ChangeListener) listener);
+                txtField.removeFocusListener((FocusListener) listener);
+            }
+        });
+
+        toolkit.realSync();
+
+        if ("Aqua".equals(UIManager.getLookAndFeel().getID())) {
+            Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B);
+        } else {
+            Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B);
+        }
+
+        toolkit.realSync();
+
+        if (!stateChanged || tab.getSelectedIndex() != 1) {
+            throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane");
+        }
+    }
+
+    private static void createAndShowGUI() {
+        tab = new JTabbedPane();
+        tab.add("Tab1", new JButton("Button1"));
+        tab.add("Tab2", new JButton("Button2"));
+        tab.setMnemonicAt(0, KeyEvent.VK_T);
+        tab.setMnemonicAt(1, KeyEvent.VK_B);
+
+        JFrame frame = new JFrame();
+        frame.getContentPane().add(tab, BorderLayout.CENTER);
+        txtField = new JTextField();
+        frame.getContentPane().add(txtField, BorderLayout.NORTH);
+        listener = new bug4624207();
+        txtField.addFocusListener((FocusListener) listener);
+        frame.pack();
+        frame.setVisible(true);
+    }
+}
diff --git a/jdk/test/javax/swing/JTabbedPane/6416920/bug6416920.java b/jdk/test/javax/swing/JTabbedPane/6416920/bug6416920.java
new file mode 100644
index 0000000..c1188ce
--- /dev/null
+++ b/jdk/test/javax/swing/JTabbedPane/6416920/bug6416920.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6416920
+ * @summary Ensures that selected tab is painted properly in the scroll tab layout
+ *         under WindowsLookAndFeel in Windows' "Windows XP" theme.
+ * @author Mikhail Lapshin
+ * @run main bug6416920
+ */
+
+import javax.swing.plaf.basic.BasicTabbedPaneUI;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingConstants;
+import java.awt.Rectangle;
+import java.awt.Insets;
+import sun.awt.OSInfo;
+
+public class bug6416920 extends BasicTabbedPaneUI {
+    public AccessibleTabbedPaneLayout layout = new AccessibleTabbedPaneLayout();
+
+    public static void main(String[] args) {
+
+        if(OSInfo.getOSType() != OSInfo.OSType.WINDOWS){
+            return;
+        }
+
+        bug6416920 test = new bug6416920();
+        test.layout.padSelectedTab(SwingConstants.TOP, 0);
+        if (test.rects[0].width < 0) {
+            throw new RuntimeException("A selected tab isn't painted properly " +
+                    "in the scroll tab layout under WindowsLookAndFeel " +
+                    "in Windows' \"Windows XP\" theme.");
+        }
+    }
+
+    public bug6416920() {
+        super();
+
+        // Set parameters for the padSelectedTab() method
+        selectedTabPadInsets = new Insets(0, 0, 0, 0);
+
+        tabPane = new JTabbedPane();
+        tabPane.setSize(100, 0);
+        tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
+
+        rects = new Rectangle[1];
+        rects[0] = new Rectangle(150, 0, 0, 0);
+    }
+
+    public class AccessibleTabbedPaneLayout extends BasicTabbedPaneUI.TabbedPaneLayout {
+        public void padSelectedTab(int tabPlacement, int selectedIndex) {
+            super.padSelectedTab(tabPlacement, selectedIndex);
+        }
+    }
+}
diff --git a/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java b/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java
new file mode 100644
index 0000000..c816734
--- /dev/null
+++ b/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 6276087
+ * @author Romain Guy
+ * @summary Tests opacity of a popup menu.
+ */
+import java.awt.*;
+import java.awt.event.*;
+
+import javax.swing.*;
+import sun.awt.SunToolkit;
+
+public class NonOpaquePopupMenuTest extends JFrame {
+
+    private static JMenu fileMenu;
+
+    public NonOpaquePopupMenuTest() {
+        getContentPane().setBackground(java.awt.Color.RED);
+        JMenuBar menuBar = new JMenuBar();
+        fileMenu = new JMenu("File");
+        JMenuItem menuItem = new JMenuItem("New");
+        menuBar.add(fileMenu);
+        setJMenuBar(menuBar);
+
+        fileMenu.add(menuItem);
+        fileMenu.getPopupMenu().setOpaque(false);
+
+        setSize(new Dimension(640, 480));
+        setVisible(true);
+    }
+
+    public static void main(String[] args) throws Throwable {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(250);
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                new NonOpaquePopupMenuTest();
+            }
+        });
+
+        toolkit.realSync();
+
+        Point p = getMenuClickPoint();
+        robot.mouseMove(p.x, p.y);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+
+        toolkit.realSync();
+
+        if (isParentOpaque()) {
+            throw new RuntimeException("Popup menu parent is opaque");
+        }
+
+    }
+
+    private static boolean isParentOpaque() throws Exception {
+        final boolean result[] = new boolean[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                result[0] = fileMenu.getPopupMenu().getParent().isOpaque();
+            }
+        });
+
+        return result[0];
+    }
+
+    private static Point getMenuClickPoint() throws Exception {
+        final Point[] result = new Point[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                Point p = fileMenu.getLocationOnScreen();
+                Dimension size = fileMenu.getSize();
+
+                result[0] = new Point(p.x + size.width / 2,
+                        p.y + size.height / 2);
+            }
+        });
+
+        return result[0];
+
+    }
+}
diff --git a/jdk/test/javax/swing/plaf/metal/MetalLookAndFeel/5073047/bug5073047.java b/jdk/test/javax/swing/plaf/metal/MetalLookAndFeel/5073047/bug5073047.java
new file mode 100644
index 0000000..ce7c803
--- /dev/null
+++ b/jdk/test/javax/swing/plaf/metal/MetalLookAndFeel/5073047/bug5073047.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 5073407
+ * @summary Tests 5073407
+ * @author Scott Violet
+ */
+
+import javax.swing.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.metal.*;
+
+public class bug5073047 {
+
+    public static void main(String[] args) throws Exception{
+        MyTheme theme = new MyTheme();
+        MetalLookAndFeel.setCurrentTheme(theme);
+        UIManager.setLookAndFeel(new MetalLookAndFeel());
+        if (UIManager.get("Button.font") != theme.ctf) {
+            throw new RuntimeException("Unexpected font");
+        }
+    }
+
+    private static class MyTheme extends DefaultMetalTheme {
+        public final FontUIResource ctf = new FontUIResource(
+                super.getControlTextFont().deriveFont(40.0f));
+        public FontUIResource getControlTextFont() {
+            return ctf;
+        }
+    }
+}
diff --git a/jdk/test/javax/swing/regtesthelpers/Util.java b/jdk/test/javax/swing/regtesthelpers/Util.java
index 76217ae..d128660 100644
--- a/jdk/test/javax/swing/regtesthelpers/Util.java
+++ b/jdk/test/javax/swing/regtesthelpers/Util.java
@@ -116,4 +116,17 @@
 
         System.out.println("Got OOME");
     }
+
+     /**
+     * Hits keys by robot.
+     */
+    public static void hitKeys(Robot robot, int... keys) {
+        for (int i = 0; i < keys.length; i++) {
+            robot.keyPress(keys[i]);
+        }
+
+        for (int i = keys.length - 1; i >= 0; i--) {
+            robot.keyRelease(keys[i]);
+        }
+    }
 }
diff --git a/jdk/test/javax/swing/text/DefaultEditorKit/4278839/bug4278839.java b/jdk/test/javax/swing/text/DefaultEditorKit/4278839/bug4278839.java
new file mode 100644
index 0000000..9dbae2b
--- /dev/null
+++ b/jdk/test/javax/swing/text/DefaultEditorKit/4278839/bug4278839.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test Jan 16, 2003
+ * @bug 4278839
+ * @summary Incorrect cursor movement between words at the end of line
+ * @author Anton Nashatyrev
+ * @library ../../../regtesthelpers
+ * @build Util
+ * @run main bug4278839
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import sun.awt.SunToolkit;
+
+public class bug4278839 extends JFrame {
+
+    private static boolean passed = true;
+    private static JTextArea area;
+    private static Robot robo;
+    private static SunToolkit toolkit;
+
+    public static void main(String[] args) {
+        try {
+
+            toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+            robo = new Robot();
+            robo.setAutoDelay(100);
+
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    createAndShowGUI();
+                }
+            });
+
+            toolkit.realSync();
+
+            clickMouse();
+            toolkit.realSync();
+
+
+            if ("Aqua".equals(UIManager.getLookAndFeel().getID())) {
+                Util.hitKeys(robo, KeyEvent.VK_HOME);
+            } else {
+                Util.hitKeys(robo, KeyEvent.VK_CONTROL, KeyEvent.VK_HOME);
+            }
+            toolkit.realSync();
+
+            passed &= moveCaret(true) == 1;
+            passed &= moveCaret(true) == 5;
+            passed &= moveCaret(true) == 8;
+            passed &= moveCaret(true) == 9;
+            passed &= moveCaret(true) == 13;
+            passed &= moveCaret(true) == 16;
+            passed &= moveCaret(true) == 17;
+            passed &= moveCaret(false) == 16;
+            passed &= moveCaret(false) == 13;
+            passed &= moveCaret(false) == 9;
+            passed &= moveCaret(false) == 8;
+            passed &= moveCaret(false) == 5;
+            passed &= moveCaret(false) == 1;
+            passed &= moveCaret(false) == 0;
+
+        } catch (Exception e) {
+            throw new RuntimeException("Test failed because of an exception:",
+                    e);
+        }
+
+        if (!passed) {
+            throw new RuntimeException("Test failed.");
+        }
+    }
+
+    private static int moveCaret(boolean right) throws Exception {
+        Util.hitKeys(robo, getCtrlKey(),
+                right ? KeyEvent.VK_RIGHT : KeyEvent.VK_LEFT);
+        toolkit.realSync();
+
+        final int[] result = new int[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                result[0] = area.getCaretPosition();
+            }
+        });
+
+        int pos = result[0];
+        return pos;
+    }
+
+    private static void clickMouse() throws Exception {
+        final Rectangle result[] = new Rectangle[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                result[0] = new Rectangle(area.getLocationOnScreen(), area.getSize());
+            }
+        });
+
+        Rectangle rect = result[0];
+
+        robo.mouseMove(rect.x + rect.width / 2, rect.y + rect.width / 2);
+        robo.mousePress(InputEvent.BUTTON1_MASK);
+    }
+
+    /**
+     * Gets a control key related to the used Look & Feel
+     * Returns VK_ALT for Aqua and VK_CONTROL for others
+     */
+    public static int getCtrlKey() {
+
+        if ("Aqua".equals(UIManager.getLookAndFeel().getID())) {
+            return KeyEvent.VK_ALT;
+        }
+
+        return KeyEvent.VK_CONTROL;
+    }
+
+    private static void createAndShowGUI() {
+        JFrame frame = new JFrame();
+        frame.setTitle("Bug# 4278839");
+        frame.setSize(200, 200);
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        area = new JTextArea("\naaa bbb\nccc ddd\n");
+        frame.getContentPane().add(new JScrollPane(area));
+        frame.setVisible(true);
+    }
+}
diff --git a/jdk/test/javax/swing/text/JTextComponent/5074573/bug5074573.java b/jdk/test/javax/swing/text/JTextComponent/5074573/bug5074573.java
new file mode 100644
index 0000000..579d471
--- /dev/null
+++ b/jdk/test/javax/swing/text/JTextComponent/5074573/bug5074573.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 5074573
+ * @summary tests delte-next-word and delete-prev-word actions for all text compnents and all look&feels
+ * @author Igor Kushnirskiy
+ * @run main bug5074573
+ */
+
+import java.util.*;
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.text.*;
+import sun.awt.SunToolkit;
+
+public class bug5074573 {
+
+    private static JTextComponent textComponent;
+    final static String testString = "123 456 789";
+    final static String resultString = "456 ";
+    final static List<Class<? extends JTextComponent>> textClasses = Arrays.asList(
+            JTextArea.class, JEditorPane.class, JTextPane.class,
+            JTextField.class, JFormattedTextField.class, JPasswordField.class);
+
+    public static void main(String[] args) throws Exception {
+        for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
+            UIManager.setLookAndFeel(info.getClassName());
+            System.out.println(info);
+            for (Class<? extends JTextComponent> clazz : textClasses) {
+                boolean res = test(clazz);
+                if (!res && clazz != JPasswordField.class) {
+                    throw new RuntimeException("failed");
+                }
+            }
+        }
+    }
+
+    static boolean test(final Class<? extends JTextComponent> textComponentClass) throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoWaitForIdle(true);
+        robot.setAutoDelay(50);
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                initialize(textComponentClass);
+            }
+        });
+
+        toolkit.realSync();
+
+        // Remove selection from JTextField components for the Aqua Look & Feel
+        if (textComponent instanceof JTextField && "Aqua".equals(UIManager.getLookAndFeel().getID())) {
+            SwingUtilities.invokeAndWait(new Runnable() {
+
+                @Override
+                public void run() {
+                    Caret caret = textComponent.getCaret();
+                    int dot = caret.getDot();
+                    textComponent.select(dot, dot);
+                }
+            });
+
+            toolkit.realSync();
+        }
+
+        robot.keyPress(getCtrlKey());
+        robot.keyPress(KeyEvent.VK_BACK_SPACE);
+        robot.keyRelease(KeyEvent.VK_BACK_SPACE);
+        robot.keyRelease(getCtrlKey());
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                Caret caret = textComponent.getCaret();
+                caret.setDot(0);
+            }
+        });
+        toolkit.realSync();
+
+        robot.keyPress(getCtrlKey());
+        robot.keyPress(KeyEvent.VK_DELETE);
+        robot.keyRelease(KeyEvent.VK_DELETE);
+        robot.keyRelease(getCtrlKey());
+        toolkit.realSync();
+
+        return resultString.equals(getText());
+    }
+
+    private static String getText() throws Exception {
+        final String[] result = new String[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                result[0] = textComponent.getText();
+            }
+        });
+
+        return result[0];
+    }
+
+    /**
+     * Gets a control key related to the used Look & Feel
+     * Returns VK_ALT for Aqua and VK_CONTROL for others
+     */
+    public static int getCtrlKey() {
+
+        if ("Aqua".equals(UIManager.getLookAndFeel().getID())) {
+            return KeyEvent.VK_ALT;
+        }
+
+        return KeyEvent.VK_CONTROL;
+    }
+
+    private static void initialize(Class<? extends JTextComponent> textComponentClass) {
+        try {
+            JFrame frame = new JFrame();
+            textComponent = textComponentClass.newInstance();
+            textComponent.setText(testString);
+            frame.add(textComponent);
+            frame.pack();
+            frame.setVisible(true);
+            textComponent.requestFocus();
+            Caret caret = textComponent.getCaret();
+            caret.setDot(textComponent.getDocument().getLength());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
diff --git a/jdk/test/javax/swing/text/html/HTMLEditorKit/5043626/bug5043626.java b/jdk/test/javax/swing/text/html/HTMLEditorKit/5043626/bug5043626.java
new file mode 100644
index 0000000..7de8679
--- /dev/null
+++ b/jdk/test/javax/swing/text/html/HTMLEditorKit/5043626/bug5043626.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 5043626
+ * @summary  Tests pressing Home or Ctrl+Home set cursor to invisible element <head>
+ * @author Alexander Potochkin
+ * @library ../../../../regtesthelpers
+ * @build Util
+ * @run main bug5043626
+ */
+
+import java.awt.Robot;
+import java.awt.Toolkit;
+import javax.swing.*;
+import javax.swing.text.Document;
+import javax.swing.text.BadLocationException;
+import java.awt.event.KeyEvent;
+import sun.awt.SunToolkit;
+
+public class bug5043626 {
+
+    private static Document doc;
+    private static Robot robot;
+
+    public static void main(String[] args) throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        robot = new Robot();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                createAndShowGUI();
+            }
+        });
+
+        toolkit.realSync();
+
+        Util.hitKeys(robot, KeyEvent.VK_HOME);
+        Util.hitKeys(robot, KeyEvent.VK_1);
+
+        toolkit.realSync();
+
+        String test = getText();
+
+        if (!"1test".equals(test)) {
+            throw new RuntimeException("Begin line action set cursor inside <head> tag");
+        }
+
+        Util.hitKeys(robot, KeyEvent.VK_HOME);
+        Util.hitKeys(robot, KeyEvent.VK_2);
+
+        toolkit.realSync();
+
+        test = getText();
+
+        if (!"21test".equals(test)) {
+            throw new RuntimeException("Begin action set cursor inside <head> tag");
+        }
+    }
+
+    private static String getText() throws Exception {
+        final String[] result = new String[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                try {
+                    result[0] = doc.getText(0, doc.getLength()).trim();
+                } catch (BadLocationException ex) {
+                    ex.printStackTrace();
+                }
+            }
+        });
+
+        return result[0];
+    }
+
+    private static void createAndShowGUI() {
+        JFrame frame = new JFrame();
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        JEditorPane editorPane = new JEditorPane();
+        editorPane.setContentType("text/html");
+        editorPane.setText("test");
+        editorPane.setEditable(true);
+        frame.add(editorPane);
+        frame.pack();
+        frame.setVisible(true);
+        doc = editorPane.getDocument();
+        editorPane.setCaretPosition(doc.getLength());
+    }
+}
diff --git a/jdk/test/lib/security/java.policy/Ext_AllPolicy.sh b/jdk/test/lib/security/java.policy/Ext_AllPolicy.sh
index 5349866..528fd0b 100644
--- a/jdk/test/lib/security/java.policy/Ext_AllPolicy.sh
+++ b/jdk/test/lib/security/java.policy/Ext_AllPolicy.sh
@@ -50,7 +50,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
@@ -81,6 +81,6 @@
 
 rm Ext_AllPolicy.class
 ${TESTJAVA}${FS}bin${FS}java \
-	-Djava.security.manager -Djava.ext.dirs="${TESTCLASSES}" Ext_AllPolicy
+        -Djava.security.manager -Djava.ext.dirs="${TESTCLASSES}" Ext_AllPolicy
 
 exit $?
diff --git a/jdk/test/sun/management/jmxremote/bootstrap/GeneratePropertyPassword.sh b/jdk/test/sun/management/jmxremote/bootstrap/GeneratePropertyPassword.sh
index eef07a2..1334d7e 100644
--- a/jdk/test/sun/management/jmxremote/bootstrap/GeneratePropertyPassword.sh
+++ b/jdk/test/sun/management/jmxremote/bootstrap/GeneratePropertyPassword.sh
@@ -26,7 +26,7 @@
 # or .access files from a list of input .in files.
 #
 # Source in this GeneratePropertyPassword.sh and call the function
-# generatePropertyPasswordFiles. 
+# generatePropertyPasswordFiles.
 # Call restoreFilePermissions to restore file permissions after the test completes
 #
 
@@ -35,7 +35,7 @@
 UMASK=`umask`
 
 case $OS in
-SunOS | Linux)
+SunOS | Linux | Darwin)
     PATHSEP=":"
     FILESEP="/"
     DFILESEP=$FILESEP
@@ -60,12 +60,12 @@
         sed -e 's^ZZZZ^\\\\\\\\^g' > ${TMP_FILE}
 
     if [ "$OS" = "Windows_NT" ]; then
-	USER=`id -u -n`
-	CACLS="$SystemRoot/system32/cacls.exe"
-	REVOKEALL="${TESTSRC}/../../windows/revokeall.exe"
-	if [ ! -f "$REVOKEALL" ] ; then
-	    echo "$REVOKEALL missing"
-	    exit 1
+        USER=`id -u -n`
+        CACLS="$SystemRoot/system32/cacls.exe"
+        REVOKEALL="${TESTSRC}/../../windows/revokeall.exe"
+        if [ ! -f "$REVOKEALL" ] ; then
+            echo "$REVOKEALL missing"
+            exit 1
         fi
     fi
 
@@ -77,47 +77,47 @@
     ;;
 esac
 
-generatePropertyPasswordFiles() 
+generatePropertyPasswordFiles()
 {
    for f in $@
    do
         echo processing $f
-	suffix=`basename $f .in`
-   	f2="${TESTCLASSES}${FILESEP}${suffix}"
+        suffix=`basename $f .in`
+        f2="${TESTCLASSES}${FILESEP}${suffix}"
 
-	if [ -f "$f2" ] ; then
-	    rm -f $f2 || echo WARNING: $f2 already exits - unable to remove old copy
-	fi
+        if [ -f "$f2" ] ; then
+            rm -f $f2 || echo WARNING: $f2 already exits - unable to remove old copy
+        fi
 
-	echo creating $f2
+        echo creating $f2
         sed -f $TMP_FILE $f > $f2
 
- 	if [ "$OS" = "Windows_NT" ]; then
-	    chown $USER $f2
-	    # Grant this user full access
-	    echo Y|$CACLS $f2 \/E \/G $USER:F
-  	    # Revoke everyone else
-	    $REVOKEALL $f2
-	    # Display ACLs
-	    $CACLS $f2
+        if [ "$OS" = "Windows_NT" ]; then
+            chown $USER $f2
+            # Grant this user full access
+            echo Y|$CACLS $f2 \/E \/G $USER:F
+            # Revoke everyone else
+            $REVOKEALL $f2
+            # Display ACLs
+            $CACLS $f2
         else
-	    chmod 600 $f2
+            chmod 600 $f2
         fi
    done
 }
 
-restoreFilePermissions() 
+restoreFilePermissions()
 {
     for f in $@
     do
-      	suffix=`basename $f .in`
-	f2="${TESTCLASSES}${FILESEP}${suffix}"
+        suffix=`basename $f .in`
+        f2="${TESTCLASSES}${FILESEP}${suffix}"
 
-	if [ "$OS" = "Windows_NT" ]; then
-	    # Grant everyone full control
-	    $CACLS $f2 \/E \/G Everyone:F
-	else
-	    chmod 777 $f2
+        if [ "$OS" = "Windows_NT" ]; then
+            # Grant everyone full control
+            $CACLS $f2 \/E \/G Everyone:F
+        else
+            chmod 777 $f2
         fi
 
     done
diff --git a/jdk/test/sun/misc/URLClassPath/ClassnameCharTest.sh b/jdk/test/sun/misc/URLClassPath/ClassnameCharTest.sh
index 6325e57..362d6dc 100644
--- a/jdk/test/sun/misc/URLClassPath/ClassnameCharTest.sh
+++ b/jdk/test/sun/misc/URLClassPath/ClassnameCharTest.sh
@@ -36,11 +36,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PS=":"
-    FS="/"
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/sun/net/www/MarkResetTest.sh b/jdk/test/sun/net/www/MarkResetTest.sh
index 3745600..20bb6ab 100644
--- a/jdk/test/sun/net/www/MarkResetTest.sh
+++ b/jdk/test/sun/net/www/MarkResetTest.sh
@@ -28,7 +28,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -49,7 +49,7 @@
 ${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}MarkResetTest.java
 
 # ftp server used by the test requires the file to be present
-# in this directory 
+# in this directory
 cp ${TESTSRC}${FS}EncDec.doc .
 
 ${TESTJAVA}${FS}bin${FS}java MarkResetTest
diff --git a/jdk/test/sun/net/www/http/HttpClient/RetryPost.sh b/jdk/test/sun/net/www/http/HttpClient/RetryPost.sh
index 254c71a..d1b7469 100644
--- a/jdk/test/sun/net/www/http/HttpClient/RetryPost.sh
+++ b/jdk/test/sun/net/www/http/HttpClient/RetryPost.sh
@@ -28,7 +28,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/sun/net/www/protocol/jar/B5105410.sh b/jdk/test/sun/net/www/protocol/jar/B5105410.sh
index fd15899..66623db 100644
--- a/jdk/test/sun/net/www/protocol/jar/B5105410.sh
+++ b/jdk/test/sun/net/www/protocol/jar/B5105410.sh
@@ -31,11 +31,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PS=":"
-    FS="/"
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/sun/net/www/protocol/jar/jarbug/run.sh b/jdk/test/sun/net/www/protocol/jar/jarbug/run.sh
index 97a1157..0446848 100644
--- a/jdk/test/sun/net/www/protocol/jar/jarbug/run.sh
+++ b/jdk/test/sun/net/www/protocol/jar/jarbug/run.sh
@@ -31,11 +31,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PS=":"
-    FS="/"
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -58,10 +54,10 @@
 esac
 
 #
-# build jar1 
+# build jar1
 #
 mkdir -p ${DEST}${FS}jar1
-cd ${TESTSRC}${FS}etc${FS}jar1 
+cd ${TESTSRC}${FS}etc${FS}jar1
 cp -r . ${DEST}${FS}jar1
 ${TESTJAVA}${FS}bin${FS}javac -d ${DEST}${FS}jar1 \
     ${TESTSRC}${FS}src${FS}jar1${FS}LoadResourceBundle.java
diff --git a/jdk/test/sun/security/krb5/auto/AcceptorSubKey.java b/jdk/test/sun/security/krb5/auto/AcceptorSubKey.java
new file mode 100644
index 0000000..9aba5e4
--- /dev/null
+++ b/jdk/test/sun/security/krb5/auto/AcceptorSubKey.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7077646
+ * @summary gssapi wrap for CFX per-message tokens always set FLAG_ACCEPTOR_SUBKEY
+ * @compile -XDignore.symbol.file AcceptorSubKey.java
+ * @run main/othervm AcceptorSubKey
+ */
+
+import java.util.Arrays;
+import sun.security.jgss.GSSUtil;
+
+// The basic krb5 test skeleton you can copy from
+public class AcceptorSubKey {
+
+    public static void main(String[] args) throws Exception {
+
+        new OneKDC(null).writeJAASConf();
+
+        Context c, s;
+        c = Context.fromJAAS("client");
+        s = Context.fromJAAS("server");
+
+        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);
+        s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID);
+
+        Context.handshake(c, s);
+
+        byte[] msg = "i say high --".getBytes();
+        byte[] wrapped = s.wrap(msg, false);
+
+        // FLAG_ACCEPTOR_SUBKEY is 4
+        int flagOn = wrapped[2] & 4;
+        if (flagOn != 0) {
+            throw new Exception("Java GSS should not have set acceptor subkey");
+        }
+
+        s.dispose();
+        c.dispose();
+    }
+}
diff --git a/jdk/test/sun/security/krb5/auto/Context.java b/jdk/test/sun/security/krb5/auto/Context.java
index 1739f87..eb2a94a 100644
--- a/jdk/test/sun/security/krb5/auto/Context.java
+++ b/jdk/test/sun/security/krb5/auto/Context.java
@@ -375,6 +375,89 @@
         }
     }
 
+    public byte[] wrap(byte[] t, final boolean privacy)
+            throws Exception {
+        return doAs(new Action() {
+            @Override
+            public byte[] run(Context me, byte[] input) throws Exception {
+                System.out.printf("wrap %s privacy from %s: ", privacy?"with":"without", me.name);
+                MessageProp p1 = new MessageProp(0, privacy);
+                byte[] out;
+                if (usingStream) {
+                    ByteArrayOutputStream os = new ByteArrayOutputStream();
+                    me.x.wrap(new ByteArrayInputStream(input), os, p1);
+                    out = os.toByteArray();
+                } else {
+                    out = me.x.wrap(input, 0, input.length, p1);
+                }
+                System.out.println(printProp(p1));
+                return out;
+            }
+        }, t);
+    }
+
+    public byte[] unwrap(byte[] t, final boolean privacy)
+            throws Exception {
+        return doAs(new Action() {
+            @Override
+            public byte[] run(Context me, byte[] input) throws Exception {
+                System.out.printf("unwrap %s privacy from %s: ", privacy?"with":"without", me.name);
+                MessageProp p1 = new MessageProp(0, privacy);
+                byte[] bytes;
+                if (usingStream) {
+                    ByteArrayOutputStream os = new ByteArrayOutputStream();
+                    me.x.unwrap(new ByteArrayInputStream(input), os, p1);
+                    bytes = os.toByteArray();
+                } else {
+                    bytes = me.x.unwrap(input, 0, input.length, p1);
+                }
+                System.out.println(printProp(p1));
+                return bytes;
+            }
+        }, t);
+    }
+
+    public byte[] getMic(byte[] t) throws Exception {
+        return doAs(new Action() {
+            @Override
+            public byte[] run(Context me, byte[] input) throws Exception {
+                MessageProp p1 = new MessageProp(0, true);
+                byte[] bytes;
+                p1 = new MessageProp(0, true);
+                System.out.printf("getMic from %s: ", me.name);
+                if (usingStream) {
+                    ByteArrayOutputStream os = new ByteArrayOutputStream();
+                    me.x.getMIC(new ByteArrayInputStream(input), os, p1);
+                    bytes = os.toByteArray();
+                } else {
+                    bytes = me.x.getMIC(input, 0, input.length, p1);
+                }
+                System.out.println(printProp(p1));
+                return bytes;
+            }
+        }, t);
+    }
+
+    public void verifyMic(byte[] t, final byte[] msg) throws Exception {
+        doAs(new Action() {
+            @Override
+            public byte[] run(Context me, byte[] input) throws Exception {
+                MessageProp p1 = new MessageProp(0, true);
+                System.out.printf("verifyMic from %s: ", me.name);
+                if (usingStream) {
+                    me.x.verifyMIC(new ByteArrayInputStream(input),
+                            new ByteArrayInputStream(msg), p1);
+                } else {
+                    me.x.verifyMIC(input, 0, input.length,
+                            msg, 0, msg.length,
+                            p1);
+                }
+                System.out.println(printProp(p1));
+                return null;
+            }
+        }, t);
+    }
+
     /**
      * Transmits a message from one Context to another. The sender wraps the
      * message and sends it to the receiver. The receiver unwraps it, creates
@@ -390,73 +473,13 @@
         final byte[] messageBytes = message.getBytes();
         System.out.printf("-------------------- TRANSMIT from %s to %s------------------------\n",
                 s1.name, s2.name);
-
-        byte[] t = s1.doAs(new Action() {
-            @Override
-            public byte[] run(Context me, byte[] dummy) throws Exception {
-                System.out.println("wrap");
-                MessageProp p1 = new MessageProp(0, true);
-                byte[] out;
-                if (usingStream) {
-                    ByteArrayOutputStream os = new ByteArrayOutputStream();
-                    me.x.wrap(new ByteArrayInputStream(messageBytes), os, p1);
-                    out = os.toByteArray();
-                } else {
-                    out = me.x.wrap(messageBytes, 0, messageBytes.length, p1);
-                }
-                System.out.println(printProp(p1));
-                return out;
-            }
-        }, null);
-
-        t = s2.doAs(new Action() {
-            @Override
-            public byte[] run(Context me, byte[] input) throws Exception {
-                MessageProp p1 = new MessageProp(0, true);
-                byte[] bytes;
-                if (usingStream) {
-                    ByteArrayOutputStream os = new ByteArrayOutputStream();
-                    me.x.unwrap(new ByteArrayInputStream(input), os, p1);
-                    bytes = os.toByteArray();
-                } else {
-                    bytes = me.x.unwrap(input, 0, input.length, p1);
-                }
-                if (!Arrays.equals(messageBytes, bytes))
-                    throw new Exception("wrap/unwrap mismatch");
-                System.out.println("unwrap");
-                System.out.println(printProp(p1));
-                p1 = new MessageProp(0, true);
-                System.out.println("getMIC");
-                if (usingStream) {
-                    ByteArrayOutputStream os = new ByteArrayOutputStream();
-                    me.x.getMIC(new ByteArrayInputStream(messageBytes), os, p1);
-                    bytes = os.toByteArray();
-                } else {
-                    bytes = me.x.getMIC(messageBytes, 0, messageBytes.length, p1);
-                }
-                System.out.println(printProp(p1));
-                return bytes;
-            }
-        }, t);
-
-        // Re-unwrap should make p2.isDuplicateToken() returns true
-        s1.doAs(new Action() {
-            @Override
-            public byte[] run(Context me, byte[] input) throws Exception {
-                MessageProp p1 = new MessageProp(0, true);
-                System.out.println("verifyMIC");
-                if (usingStream) {
-                    me.x.verifyMIC(new ByteArrayInputStream(input),
-                            new ByteArrayInputStream(messageBytes), p1);
-                } else {
-                    me.x.verifyMIC(input, 0, input.length,
-                            messageBytes, 0, messageBytes.length,
-                            p1);
-                }
-                System.out.println(printProp(p1));
-                return null;
-            }
-        }, t);
+        byte[] wrapped = s1.wrap(messageBytes, true);
+        byte[] unwrapped = s2.unwrap(wrapped, true);
+        if (!Arrays.equals(messageBytes, unwrapped)) {
+            throw new Exception("wrap/unwrap mismatch");
+        }
+        byte[] mic = s2.getMic(unwrapped);
+        s1.verifyMic(mic, messageBytes);
     }
 
     /**
diff --git a/jdk/test/sun/security/krb5/auto/NoInitNoKeytab.java b/jdk/test/sun/security/krb5/auto/NoInitNoKeytab.java
new file mode 100644
index 0000000..cde2ec6
--- /dev/null
+++ b/jdk/test/sun/security/krb5/auto/NoInitNoKeytab.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7089889
+ * @summary Krb5LoginModule.login() throws an exception if used without a keytab
+ * @compile -XDignore.symbol.file NoInitNoKeytab.java
+ * @run main/othervm NoInitNoKeytab
+ */
+
+import java.io.FileOutputStream;
+import sun.security.jgss.GSSUtil;
+
+// The basic krb5 test skeleton you can copy from
+public class NoInitNoKeytab {
+
+    public static void main(String[] args) throws Exception {
+
+        new OneKDC(null).writeJAASConf();
+        try (FileOutputStream fos =
+                new FileOutputStream(OneKDC.JAAS_CONF, true)) {
+            fos.write((
+                "noinit {\n" +
+                "    com.sun.security.auth.module.Krb5LoginModule required\n" +
+                "    principal=\"" + OneKDC.USER + "\"\n" +
+                "    useKeyTab=false\n" +
+                "    isInitiator=false\n" +
+                "    storeKey=true;\n};\n").getBytes());
+        }
+        Context c, s;
+        c = Context.fromJAAS("client");
+        s = Context.fromJAAS("noinit");
+
+        c.startAsClient(OneKDC.USER, GSSUtil.GSS_SPNEGO_MECH_OID);
+        s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID);
+
+        Context.handshake(c, s);
+
+        Context.transmit("i say high --", c, s);
+        Context.transmit("   you say low", s, c);
+
+        s.dispose();
+        c.dispose();
+    }
+}
diff --git a/jdk/test/sun/security/krb5/auto/RRC.java b/jdk/test/sun/security/krb5/auto/RRC.java
new file mode 100644
index 0000000..ade12a4
--- /dev/null
+++ b/jdk/test/sun/security/krb5/auto/RRC.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7077640
+ * @summary gss wrap for cfx doesn't handle rrc != 0
+ * @compile -XDignore.symbol.file RRC.java
+ * @run main/othervm RRC
+ */
+
+import java.util.Arrays;
+import sun.security.jgss.GSSUtil;
+
+// The basic krb5 test skeleton you can copy from
+public class RRC {
+
+    public static void main(String[] args) throws Exception {
+
+        new OneKDC(null).writeJAASConf();
+
+        Context c, s;
+        c = Context.fromJAAS("client");
+        s = Context.fromJAAS("server");
+
+        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);
+        s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID);
+
+        Context.handshake(c, s);
+
+        byte[] msg = "i say high --".getBytes();
+        byte[] wrapped = c.wrap(msg, false);
+
+        // Simulate RRC equals to EC
+        int rrc = wrapped[5];
+        byte[] rotated = new byte[wrapped.length];
+        System.arraycopy(wrapped, 0, rotated, 0, 16);
+        System.arraycopy(wrapped, wrapped.length-rrc, rotated, 16, rrc);
+        System.arraycopy(wrapped, 16, rotated, 16+rrc, wrapped.length-16-rrc);
+        rotated[7] = (byte)rrc;
+
+        byte[] unwrapped = s.unwrap(rotated, false);
+        if (!Arrays.equals(msg, unwrapped)) {
+            throw new Exception("Failure");
+        }
+
+        s.dispose();
+        c.dispose();
+    }
+}
diff --git a/jdk/test/sun/security/krb5/runNameEquals.sh b/jdk/test/sun/security/krb5/runNameEquals.sh
index dca2052..ac5ddb2 100644
--- a/jdk/test/sun/security/krb5/runNameEquals.sh
+++ b/jdk/test/sun/security/krb5/runNameEquals.sh
@@ -48,12 +48,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PATHSEP=":"
-    FILESEP="/"
-    NATIVE=true
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PATHSEP=":"
     FILESEP="/"
     NATIVE=true
diff --git a/jdk/test/sun/security/pkcs11/Provider/Absolute.java b/jdk/test/sun/security/pkcs11/Provider/Absolute.java
index e35f9c6..fc035dc 100644
--- a/jdk/test/sun/security/pkcs11/Provider/Absolute.java
+++ b/jdk/test/sun/security/pkcs11/Provider/Absolute.java
@@ -27,7 +27,6 @@
  */
 import java.security.*;
 import java.lang.reflect.*;
-import sun.security.pkcs11.*;
 
 public class Absolute {
 
diff --git a/jdk/test/sun/security/pkcs11/Provider/ConfigQuotedString.sh b/jdk/test/sun/security/pkcs11/Provider/ConfigQuotedString.sh
index 3f9a795..2511ff6 100644
--- a/jdk/test/sun/security/pkcs11/Provider/ConfigQuotedString.sh
+++ b/jdk/test/sun/security/pkcs11/Provider/ConfigQuotedString.sh
@@ -62,6 +62,12 @@
     CP="${FS}bin${FS}cp"
     CHMOD="${FS}bin${FS}chmod"
     ;;
+  Darwin )
+    FS="/"
+    PS=":"
+    CP="${FS}bin${FS}cp"
+    CHMOD="${FS}bin${FS}chmod"
+    ;;
   Windows* )
     FS="\\"
     PS=";"
@@ -87,18 +93,18 @@
 # compile test
 
 ${TESTJAVA}${FS}bin${FS}javac \
-	-classpath ${TESTSRC}${FS}.. \
-	-d ${TESTCLASSES} \
-	${TESTSRC}${FS}ConfigQuotedString.java
+        -classpath ${TESTSRC}${FS}.. \
+        -d ${TESTCLASSES} \
+        ${TESTSRC}${FS}ConfigQuotedString.java
 
 # run test
 
 ${TESTJAVA}${FS}bin${FS}java \
-	-classpath ${TESTCLASSES} \
-	-DCUSTOM_P11_CONFIG=${TESTSRC}${FS}ConfigQuotedString-nss.txt \
-	-Dtest.src=${TESTSRC} \
-	-Dtest.classes=${TESTCLASSES} \
-	ConfigQuotedString
+        -classpath ${TESTCLASSES} \
+        -DCUSTOM_P11_CONFIG=${TESTSRC}${FS}ConfigQuotedString-nss.txt \
+        -Dtest.src=${TESTSRC} \
+        -Dtest.classes=${TESTCLASSES} \
+        ConfigQuotedString
 
 # save error status
 status=$?
diff --git a/jdk/test/sun/security/pkcs11/Provider/Login.sh b/jdk/test/sun/security/pkcs11/Provider/Login.sh
index 406b685..6288a8f 100644
--- a/jdk/test/sun/security/pkcs11/Provider/Login.sh
+++ b/jdk/test/sun/security/pkcs11/Provider/Login.sh
@@ -63,6 +63,12 @@
     CP="${FS}bin${FS}cp"
     CHMOD="${FS}bin${FS}chmod"
     ;;
+  Darwin )
+    FS="/"
+    PS=":"
+    CP="${FS}bin${FS}cp"
+    CHMOD="${FS}bin${FS}chmod"
+    ;;
   Windows* )
     FS="\\"
     PS=";"
@@ -96,24 +102,24 @@
 # compile test
 
 ${TESTJAVA}${FS}bin${FS}javac \
-	-classpath ${TESTSRC}${FS}.. \
-	-d ${TESTCLASSES} \
-	${TESTSRC}${FS}Login.java
+        -classpath ${TESTSRC}${FS}.. \
+        -d ${TESTCLASSES} \
+        ${TESTSRC}${FS}Login.java
 
 # run test
 
 ${TESTJAVA}${FS}bin${FS}java \
-	-classpath ${TESTCLASSES} \
-	-DCUSTOM_DB_DIR=${TESTCLASSES} \
-	-DCUSTOM_P11_CONFIG=${TESTSRC}${FS}Login-nss.txt \
-	-DNO_DEFAULT=true \
-	-DNO_DEIMOS=true \
-	-Dtest.src=${TESTSRC} \
-	-Dtest.classes=${TESTCLASSES} \
-	-Djava.security.manager \
-	-Djava.security.policy=${TESTSRC}${FS}Login.policy \
-	-Djava.security.debug=${DEBUG} \
-	Login
+        -classpath ${TESTCLASSES} \
+        -DCUSTOM_DB_DIR=${TESTCLASSES} \
+        -DCUSTOM_P11_CONFIG=${TESTSRC}${FS}Login-nss.txt \
+        -DNO_DEFAULT=true \
+        -DNO_DEIMOS=true \
+        -Dtest.src=${TESTSRC} \
+        -Dtest.classes=${TESTCLASSES} \
+        -Djava.security.manager \
+        -Djava.security.policy=${TESTSRC}${FS}Login.policy \
+        -Djava.security.debug=${DEBUG} \
+        Login
 
 # save error status
 status=$?
diff --git a/jdk/test/sun/security/provider/PolicyFile/getinstance/getinstance.sh b/jdk/test/sun/security/provider/PolicyFile/getinstance/getinstance.sh
index a5789b2..6e7442b 100644
--- a/jdk/test/sun/security/provider/PolicyFile/getinstance/getinstance.sh
+++ b/jdk/test/sun/security/provider/PolicyFile/getinstance/getinstance.sh
@@ -25,8 +25,8 @@
 
 # @test
 # @author  Ram Marti
-# @bug 4350951 
-# @summary 4350951 assumes permission constructor with 2 string params 
+# @bug 4350951
+# @summary 4350951 assumes permission constructor with 2 string params
 
 # set a few environment variables so that the shell-script can run stand-alone
 # in the source directory
@@ -55,6 +55,10 @@
     PS=":"
     FS="/"
     ;;
+  Darwin )
+    PS=":"
+    FS="/"
+    ;;
   CYGWIN* )
     PS=";"
     FS="/"
@@ -69,24 +73,24 @@
     ;;
 esac
 
-if [ ! -d ${TESTCLASSES}${FS}boot ]; then 
-	mkdir -p ${TESTCLASSES}${FS}boot
+if [ ! -d ${TESTCLASSES}${FS}boot ]; then
+        mkdir -p ${TESTCLASSES}${FS}boot
 fi
-if [ ! -d ${TESTCLASSES}${FS}app ]; then 
-	mkdir -p ${TESTCLASSES}${FS}app
+if [ ! -d ${TESTCLASSES}${FS}app ]; then
+        mkdir -p ${TESTCLASSES}${FS}app
 fi
 
 cd ${TESTSRC}${FS}
 ${TESTJAVA}${FS}bin${FS}javac -d ${TESTCLASSES}${FS}boot \
-	${TESTSRC}${FS}NoArgPermission.java
+        ${TESTSRC}${FS}NoArgPermission.java
 ${TESTJAVA}${FS}bin${FS}javac -d ${TESTCLASSES}${FS}boot \
-	${TESTSRC}${FS}OneArgPermission.java
+        ${TESTSRC}${FS}OneArgPermission.java
 ${TESTJAVA}${FS}bin${FS}javac -d ${TESTCLASSES}${FS}boot \
-	${TESTSRC}${FS}TwoArgPermission.java
+        ${TESTSRC}${FS}TwoArgPermission.java
 ${TESTJAVA}${FS}bin${FS}javac -d ${TESTCLASSES}${FS}boot \
-	${TESTSRC}${FS}TwoArgNullActionsPermission.java
+        ${TESTSRC}${FS}TwoArgNullActionsPermission.java
 ${TESTJAVA}${FS}bin${FS}javac -d ${TESTCLASSES}${FS}app \
-	${TESTSRC}${FS}GetInstance.java
+        ${TESTSRC}${FS}GetInstance.java
 
 ${TESTJAVA}${FS}bin${FS}java  \
 -Xbootclasspath/a:"${TESTCLASSES}${FS}boot" \
diff --git a/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/MD2InTrustAnchor.java b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/MD2InTrustAnchor.java
new file mode 100644
index 0000000..0a25f7f
--- /dev/null
+++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/MD2InTrustAnchor.java
@@ -0,0 +1,423 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7113275
+ * @summary compatibility issue with MD2 trust anchor and old X509TrustManager
+ *
+ *     SunJSSE does not support dynamic system properties, no way to re-use
+ *     system properties in samevm/agentvm mode.
+ * @run main/othervm MD2InTrustAnchor PKIX TLSv1.1
+ * @run main/othervm MD2InTrustAnchor SunX509 TLSv1.1
+ * @run main/othervm MD2InTrustAnchor PKIX TLSv1.2
+ * @run main/othervm MD2InTrustAnchor SunX509 TLSv1.2
+ */
+
+import java.net.*;
+import java.util.*;
+import java.io.*;
+import javax.net.ssl.*;
+import java.security.KeyStore;
+import java.security.KeyFactory;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.security.spec.*;
+import java.security.interfaces.*;
+import sun.misc.BASE64Decoder;
+
+
+public class MD2InTrustAnchor {
+
+    /*
+     * =============================================================
+     * Set the various variables needed for the tests, then
+     * specify what tests to run on each side.
+     */
+
+    /*
+     * Should we run the client or server in a separate thread?
+     * Both sides can throw exceptions, but do you have a preference
+     * as to which side should be the main thread.
+     */
+    static boolean separateServerThread = false;
+
+    /*
+     * Certificates and key used in the test.
+     */
+
+    // It's a trust anchor signed with MD2 hash function.
+    static String trustedCertStr =
+        "-----BEGIN CERTIFICATE-----\n" +
+        "MIICkjCCAfugAwIBAgIBADANBgkqhkiG9w0BAQIFADA7MQswCQYDVQQGEwJVUzEN\n" +
+        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
+        "MTExMTE4MTExNDA0WhcNMzIxMDI4MTExNDA0WjA7MQswCQYDVQQGEwJVUzENMAsG\n" +
+        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwgZ8wDQYJ\n" +
+        "KoZIhvcNAQEBBQADgY0AMIGJAoGBAPGyB9tugUGgxtdeqe0qJEwf9x1Gy4BOi1yR\n" +
+        "wzDZY4H5LquvIfQ2V3J9X1MQENVsFvkvp65ZcFcy+ObOucXUUPFcd/iw2DVb5QXA\n" +
+        "ffyeVqWD56GPi8Qe37wrJO3L6fBhN9oxp/BbdRLgjU81zx8qLEyPODhPMxV4OkcA\n" +
+        "SDwZTSxxAgMBAAGjgaUwgaIwHQYDVR0OBBYEFLOAtr/YrYj9H04EDLA0fd14jisF\n" +
+        "MGMGA1UdIwRcMFqAFLOAtr/YrYj9H04EDLA0fd14jisFoT+kPTA7MQswCQYDVQQG\n" +
+        "EwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2\n" +
+        "Y2WCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEC\n" +
+        "BQADgYEAr8ExpXu/FTIRiMzPm0ubqwME4lniilwQUiEOD/4DbksNjEIcUyS2hIk1\n" +
+        "qsmjJz3SHBnwhxl9dhJVwk2tZLkPGW86Zn0TPVRsttK4inTgCC9GFGeqQBdrU/uf\n" +
+        "lipBzXWljrfbg4N/kK8m2LabtKUMMnGysM8rN0Fx2PYm5xxGvtM=\n" +
+        "-----END CERTIFICATE-----";
+
+    // The certificate issued by above trust anchor, signed with MD5
+    static String targetCertStr =
+        "-----BEGIN CERTIFICATE-----\n" +
+        "MIICeDCCAeGgAwIBAgIBAjANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" +
+        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
+        "MTExMTE4MTExNDA2WhcNMzEwODA1MTExNDA2WjBPMQswCQYDVQQGEwJVUzENMAsG\n" +
+        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxEjAQBgNV\n" +
+        "BAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwDnm96mw\n" +
+        "fXCH4bgXk1US0VcJsQVxUtGMyncAveMuzBzNzOmKZPeqyYX1Fuh4q+cuza03WTJd\n" +
+        "G9nOkNr364e3Rn1aaHjCMcBmFflObnGnhhufNmIGYogJ9dJPmhUVPEVAXrMG+Ces\n" +
+        "NKy2E8woGnLMrqu6yiuTClbLBPK8fWzTXrECAwEAAaN4MHYwCwYDVR0PBAQDAgPo\n" +
+        "MB0GA1UdDgQWBBSdRrpocLPJXyGfDmMWJrcEf29WGDAfBgNVHSMEGDAWgBSzgLa/\n" +
+        "2K2I/R9OBAywNH3deI4rBTAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUHAwIG\n" +
+        "CCsGAQUFBwMDMA0GCSqGSIb3DQEBBAUAA4GBAKJ71ZiCUykkJrCLYUxlFlhvUcr9\n" +
+        "sTcOc67QdroW5f412NI15SXWDiley/JOasIiuIFPjaJBjOKoHOvTjG/snVu9wEgq\n" +
+        "YNR8dPsO+NM8r79C6jO+Jx5fYAC7os2XxS75h3NX0ElJcbwIXGBJ6xRrsFh/BGYH\n" +
+        "yvudOlX4BkVR0l1K\n" +
+        "-----END CERTIFICATE-----";
+
+    // Private key in the format of PKCS#8.
+    static String targetPrivateKey =
+        "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMA55vepsH1wh+G4\n" +
+        "F5NVEtFXCbEFcVLRjMp3AL3jLswczczpimT3qsmF9RboeKvnLs2tN1kyXRvZzpDa\n" +
+        "9+uHt0Z9Wmh4wjHAZhX5Tm5xp4YbnzZiBmKICfXST5oVFTxFQF6zBvgnrDSsthPM\n" +
+        "KBpyzK6rusorkwpWywTyvH1s016xAgMBAAECgYEAn9bF3oRkdDoBU0i/mcww5I+K\n" +
+        "SH9tFt+WQbiojjz9ac49trkvUfu7MO1Jui2+QbrvaSkyj+HYGFOJd1wMsPXeB7ck\n" +
+        "5mOIYV4uZK8jfNMSQ8v0tFEeIPp5lKdw1XnrQfSe+abo2eL5Lwso437Y4s3w37+H\n" +
+        "aY3d76hR5qly+Ys+Ww0CQQDjeOoX89d/xhRqGXKjCx8ImE/dPmsI8O27cwtKrDYJ\n" +
+        "6t0v/xryVIdvOYcRBvKnqEogOH7T1kI+LnWKUTJ2ehJ7AkEA2FVloPVqCehXcc7e\n" +
+        "z3TDpU9w1B0JXklcV5HddYsRqp9RukN/VK4szKE7F1yoarIUtfE9Lr9082Jwyp3M\n" +
+        "L11xwwJBAKsZ+Hur3x0tUY29No2Nf/pnFyvEF57SGwA0uPmiL8Ol9lpz+UDudDEl\n" +
+        "hIM6Rqv12kwCMuQE9i7vo1o3WU3k5KECQEqhg1L49yD935TqiiFFpe0Ur9btQXse\n" +
+        "kdXAA4d2d5zGI7q/aGD9SYU6phkUJSHR16VA2RuUfzMrpb+wmm1IrmMCQFtLoKRT\n" +
+        "A5kokFb+E3Gplu29tJvCUpfwgBFRS+wmkvtiaU/tiyDcVgDO+An5DwedxxdVzqiE\n" +
+        "njWHoKY3axDQ8OU=\n";
+
+
+    static char passphrase[] = "passphrase".toCharArray();
+
+    /*
+     * Is the server ready to serve?
+     */
+    volatile static boolean serverReady = false;
+
+    /*
+     * Turn on SSL debugging?
+     */
+    static boolean debug = false;
+
+    /*
+     * Define the server side of the test.
+     *
+     * If the server prematurely exits, serverReady will be set to true
+     * to avoid infinite hangs.
+     */
+    void doServerSide() throws Exception {
+        SSLContext context = generateSSLContext(trustedCertStr, targetCertStr,
+                                            targetPrivateKey);
+        SSLServerSocketFactory sslssf = context.getServerSocketFactory();
+        SSLServerSocket sslServerSocket =
+            (SSLServerSocket)sslssf.createServerSocket(serverPort);
+        sslServerSocket.setNeedClientAuth(true);
+        serverPort = sslServerSocket.getLocalPort();
+
+        /*
+         * Signal Client, we're ready for his connect.
+         */
+        serverReady = true;
+
+        SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept();
+        InputStream sslIS = sslSocket.getInputStream();
+        OutputStream sslOS = sslSocket.getOutputStream();
+
+        sslIS.read();
+        sslOS.write('A');
+        sslOS.flush();
+
+        sslSocket.close();
+    }
+
+    /*
+     * Define the client side of the test.
+     *
+     * If the server prematurely exits, serverReady will be set to true
+     * to avoid infinite hangs.
+     */
+    void doClientSide() throws Exception {
+
+        /*
+         * Wait for server to get started.
+         */
+        while (!serverReady) {
+            Thread.sleep(50);
+        }
+
+        SSLContext context = generateSSLContext(trustedCertStr, targetCertStr,
+                                            targetPrivateKey);
+        SSLSocketFactory sslsf = context.getSocketFactory();
+
+        SSLSocket sslSocket =
+            (SSLSocket)sslsf.createSocket("localhost", serverPort);
+
+        // enable the specified TLS protocol
+        sslSocket.setEnabledProtocols(new String[] {tlsProtocol});
+
+        InputStream sslIS = sslSocket.getInputStream();
+        OutputStream sslOS = sslSocket.getOutputStream();
+
+        sslOS.write('B');
+        sslOS.flush();
+        sslIS.read();
+
+        sslSocket.close();
+    }
+
+    /*
+     * =============================================================
+     * The remainder is just support stuff
+     */
+    private static String tmAlgorithm;        // trust manager
+    private static String tlsProtocol;        // trust manager
+
+    private static void parseArguments(String[] args) {
+        tmAlgorithm = args[0];
+        tlsProtocol = args[1];
+    }
+
+    private static SSLContext generateSSLContext(String trustedCertStr,
+            String keyCertStr, String keySpecStr) throws Exception {
+
+        // generate certificate from cert string
+        CertificateFactory cf = CertificateFactory.getInstance("X.509");
+
+        // create a key store
+        KeyStore ks = KeyStore.getInstance("JKS");
+        ks.load(null, null);
+
+        // import the trused cert
+        Certificate trusedCert = null;
+        ByteArrayInputStream is = null;
+        if (trustedCertStr != null) {
+            is = new ByteArrayInputStream(trustedCertStr.getBytes());
+            trusedCert = cf.generateCertificate(is);
+            is.close();
+
+            ks.setCertificateEntry("RSA Export Signer", trusedCert);
+        }
+
+        if (keyCertStr != null) {
+            // generate the private key.
+            PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
+                                new BASE64Decoder().decodeBuffer(keySpecStr));
+            KeyFactory kf = KeyFactory.getInstance("RSA");
+            RSAPrivateKey priKey =
+                    (RSAPrivateKey)kf.generatePrivate(priKeySpec);
+
+            // generate certificate chain
+            is = new ByteArrayInputStream(keyCertStr.getBytes());
+            Certificate keyCert = cf.generateCertificate(is);
+            is.close();
+
+            // It's not allowed to send MD2 signed certificate to peer,
+            // even it may be a trusted certificate. Then we will not
+            // place the trusted certficate in the chain.
+            Certificate[] chain = new Certificate[1];
+            chain[0] = keyCert;
+
+            // import the key entry.
+            ks.setKeyEntry("Whatever", priKey, passphrase, chain);
+        }
+
+        // create SSL context
+        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
+        tmf.init(ks);
+
+        SSLContext ctx = SSLContext.getInstance(tlsProtocol);
+        if (keyCertStr != null && !keyCertStr.isEmpty()) {
+            KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
+            kmf.init(ks, passphrase);
+
+            ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+            ks = null;
+        } else {
+            ctx.init(null, tmf.getTrustManagers(), null);
+        }
+
+        return ctx;
+    }
+
+
+    // use any free port by default
+    volatile int serverPort = 0;
+
+    volatile Exception serverException = null;
+    volatile Exception clientException = null;
+
+    public static void main(String[] args) throws Exception {
+        if (debug)
+            System.setProperty("javax.net.debug", "all");
+
+        /*
+         * Get the customized arguments.
+         */
+        parseArguments(args);
+
+        /*
+         * Start the tests.
+         */
+        new MD2InTrustAnchor();
+    }
+
+    Thread clientThread = null;
+    Thread serverThread = null;
+
+    /*
+     * Primary constructor, used to drive remainder of the test.
+     *
+     * Fork off the other side, then do your work.
+     */
+    MD2InTrustAnchor() throws Exception {
+        try {
+            if (separateServerThread) {
+                startServer(true);
+                startClient(false);
+            } else {
+                startClient(true);
+                startServer(false);
+            }
+        } catch (Exception e) {
+            // swallow for now.  Show later
+        }
+
+        /*
+         * Wait for other side to close down.
+         */
+        if (separateServerThread) {
+            serverThread.join();
+        } else {
+            clientThread.join();
+        }
+
+        /*
+         * When we get here, the test is pretty much over.
+         * Which side threw the error?
+         */
+        Exception local;
+        Exception remote;
+        String whichRemote;
+
+        if (separateServerThread) {
+            remote = serverException;
+            local = clientException;
+            whichRemote = "server";
+        } else {
+            remote = clientException;
+            local = serverException;
+            whichRemote = "client";
+        }
+
+        /*
+         * If both failed, return the curthread's exception, but also
+         * print the remote side Exception
+         */
+        if ((local != null) && (remote != null)) {
+            System.out.println(whichRemote + " also threw:");
+            remote.printStackTrace();
+            System.out.println();
+            throw local;
+        }
+
+        if (remote != null) {
+            throw remote;
+        }
+
+        if (local != null) {
+            throw local;
+        }
+    }
+
+    void startServer(boolean newThread) throws Exception {
+        if (newThread) {
+            serverThread = new Thread() {
+                public void run() {
+                    try {
+                        doServerSide();
+                    } catch (Exception e) {
+                        /*
+                         * Our server thread just died.
+                         *
+                         * Release the client, if not active already...
+                         */
+                        System.err.println("Server died...");
+                        serverReady = true;
+                        serverException = e;
+                    }
+                }
+            };
+            serverThread.start();
+        } else {
+            try {
+                doServerSide();
+            } catch (Exception e) {
+                serverException = e;
+            } finally {
+                serverReady = true;
+            }
+        }
+    }
+
+    void startClient(boolean newThread) throws Exception {
+        if (newThread) {
+            clientThread = new Thread() {
+                public void run() {
+                    try {
+                        doClientSide();
+                    } catch (Exception e) {
+                        /*
+                         * Our client thread just died.
+                         */
+                        System.err.println("Client died...");
+                        clientException = e;
+                    }
+                }
+            };
+            clientThread.start();
+        } else {
+            try {
+                doClientSide();
+            } catch (Exception e) {
+                clientException = e;
+            }
+        }
+    }
+}
diff --git a/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/TrustTrustedCert.java b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/TrustTrustedCert.java
new file mode 100644
index 0000000..3aeeb08
--- /dev/null
+++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/TrustTrustedCert.java
@@ -0,0 +1,475 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7113275
+ * @summary compatibility issue with MD2 trust anchor and old X509TrustManager
+ *
+ *     SunJSSE does not support dynamic system properties, no way to re-use
+ *     system properties in samevm/agentvm mode.
+ * @run main/othervm TrustTrustedCert PKIX TLSv1.1
+ * @run main/othervm TrustTrustedCert SunX509 TLSv1.1
+ * @run main/othervm TrustTrustedCert PKIX TLSv1.2
+ * @run main/othervm TrustTrustedCert SunX509 TLSv1.2
+ */
+
+import java.net.*;
+import java.util.*;
+import java.io.*;
+import javax.net.ssl.*;
+import java.security.*;
+import java.security.cert.*;
+import java.security.spec.*;
+import java.security.interfaces.*;
+import sun.misc.BASE64Decoder;
+
+
+public class TrustTrustedCert {
+
+    /*
+     * =============================================================
+     * Set the various variables needed for the tests, then
+     * specify what tests to run on each side.
+     */
+
+    /*
+     * Should we run the client or server in a separate thread?
+     * Both sides can throw exceptions, but do you have a preference
+     * as to which side should be the main thread.
+     */
+    static boolean separateServerThread = false;
+
+    /*
+     * Certificates and key used in the test.
+     */
+
+    // It's a trust anchor signed with MD2 hash function.
+    static String trustedCertStr =
+        "-----BEGIN CERTIFICATE-----\n" +
+        "MIICkjCCAfugAwIBAgIBADANBgkqhkiG9w0BAQIFADA7MQswCQYDVQQGEwJVUzEN\n" +
+        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
+        "MTExMTE4MTExNDA0WhcNMzIxMDI4MTExNDA0WjA7MQswCQYDVQQGEwJVUzENMAsG\n" +
+        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwgZ8wDQYJ\n" +
+        "KoZIhvcNAQEBBQADgY0AMIGJAoGBAPGyB9tugUGgxtdeqe0qJEwf9x1Gy4BOi1yR\n" +
+        "wzDZY4H5LquvIfQ2V3J9X1MQENVsFvkvp65ZcFcy+ObOucXUUPFcd/iw2DVb5QXA\n" +
+        "ffyeVqWD56GPi8Qe37wrJO3L6fBhN9oxp/BbdRLgjU81zx8qLEyPODhPMxV4OkcA\n" +
+        "SDwZTSxxAgMBAAGjgaUwgaIwHQYDVR0OBBYEFLOAtr/YrYj9H04EDLA0fd14jisF\n" +
+        "MGMGA1UdIwRcMFqAFLOAtr/YrYj9H04EDLA0fd14jisFoT+kPTA7MQswCQYDVQQG\n" +
+        "EwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2\n" +
+        "Y2WCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEC\n" +
+        "BQADgYEAr8ExpXu/FTIRiMzPm0ubqwME4lniilwQUiEOD/4DbksNjEIcUyS2hIk1\n" +
+        "qsmjJz3SHBnwhxl9dhJVwk2tZLkPGW86Zn0TPVRsttK4inTgCC9GFGeqQBdrU/uf\n" +
+        "lipBzXWljrfbg4N/kK8m2LabtKUMMnGysM8rN0Fx2PYm5xxGvtM=\n" +
+        "-----END CERTIFICATE-----";
+
+    // The certificate issued by above trust anchor, signed with MD5
+    static String targetCertStr =
+        "-----BEGIN CERTIFICATE-----\n" +
+        "MIICeDCCAeGgAwIBAgIBAjANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" +
+        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
+        "MTExMTE4MTExNDA2WhcNMzEwODA1MTExNDA2WjBPMQswCQYDVQQGEwJVUzENMAsG\n" +
+        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxEjAQBgNV\n" +
+        "BAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwDnm96mw\n" +
+        "fXCH4bgXk1US0VcJsQVxUtGMyncAveMuzBzNzOmKZPeqyYX1Fuh4q+cuza03WTJd\n" +
+        "G9nOkNr364e3Rn1aaHjCMcBmFflObnGnhhufNmIGYogJ9dJPmhUVPEVAXrMG+Ces\n" +
+        "NKy2E8woGnLMrqu6yiuTClbLBPK8fWzTXrECAwEAAaN4MHYwCwYDVR0PBAQDAgPo\n" +
+        "MB0GA1UdDgQWBBSdRrpocLPJXyGfDmMWJrcEf29WGDAfBgNVHSMEGDAWgBSzgLa/\n" +
+        "2K2I/R9OBAywNH3deI4rBTAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUHAwIG\n" +
+        "CCsGAQUFBwMDMA0GCSqGSIb3DQEBBAUAA4GBAKJ71ZiCUykkJrCLYUxlFlhvUcr9\n" +
+        "sTcOc67QdroW5f412NI15SXWDiley/JOasIiuIFPjaJBjOKoHOvTjG/snVu9wEgq\n" +
+        "YNR8dPsO+NM8r79C6jO+Jx5fYAC7os2XxS75h3NX0ElJcbwIXGBJ6xRrsFh/BGYH\n" +
+        "yvudOlX4BkVR0l1K\n" +
+        "-----END CERTIFICATE-----";
+
+    // Private key in the format of PKCS#8.
+    static String targetPrivateKey =
+        "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMA55vepsH1wh+G4\n" +
+        "F5NVEtFXCbEFcVLRjMp3AL3jLswczczpimT3qsmF9RboeKvnLs2tN1kyXRvZzpDa\n" +
+        "9+uHt0Z9Wmh4wjHAZhX5Tm5xp4YbnzZiBmKICfXST5oVFTxFQF6zBvgnrDSsthPM\n" +
+        "KBpyzK6rusorkwpWywTyvH1s016xAgMBAAECgYEAn9bF3oRkdDoBU0i/mcww5I+K\n" +
+        "SH9tFt+WQbiojjz9ac49trkvUfu7MO1Jui2+QbrvaSkyj+HYGFOJd1wMsPXeB7ck\n" +
+        "5mOIYV4uZK8jfNMSQ8v0tFEeIPp5lKdw1XnrQfSe+abo2eL5Lwso437Y4s3w37+H\n" +
+        "aY3d76hR5qly+Ys+Ww0CQQDjeOoX89d/xhRqGXKjCx8ImE/dPmsI8O27cwtKrDYJ\n" +
+        "6t0v/xryVIdvOYcRBvKnqEogOH7T1kI+LnWKUTJ2ehJ7AkEA2FVloPVqCehXcc7e\n" +
+        "z3TDpU9w1B0JXklcV5HddYsRqp9RukN/VK4szKE7F1yoarIUtfE9Lr9082Jwyp3M\n" +
+        "L11xwwJBAKsZ+Hur3x0tUY29No2Nf/pnFyvEF57SGwA0uPmiL8Ol9lpz+UDudDEl\n" +
+        "hIM6Rqv12kwCMuQE9i7vo1o3WU3k5KECQEqhg1L49yD935TqiiFFpe0Ur9btQXse\n" +
+        "kdXAA4d2d5zGI7q/aGD9SYU6phkUJSHR16VA2RuUfzMrpb+wmm1IrmMCQFtLoKRT\n" +
+        "A5kokFb+E3Gplu29tJvCUpfwgBFRS+wmkvtiaU/tiyDcVgDO+An5DwedxxdVzqiE\n" +
+        "njWHoKY3axDQ8OU=\n";
+
+
+    static char passphrase[] = "passphrase".toCharArray();
+
+    /*
+     * Is the server ready to serve?
+     */
+    volatile static boolean serverReady = false;
+
+    /*
+     * Turn on SSL debugging?
+     */
+    static boolean debug = false;
+
+    /*
+     * Define the server side of the test.
+     *
+     * If the server prematurely exits, serverReady will be set to true
+     * to avoid infinite hangs.
+     */
+    void doServerSide() throws Exception {
+        SSLContext context = generateSSLContext();
+        SSLServerSocketFactory sslssf = context.getServerSocketFactory();
+        SSLServerSocket sslServerSocket =
+            (SSLServerSocket)sslssf.createServerSocket(serverPort);
+        sslServerSocket.setNeedClientAuth(true);
+        serverPort = sslServerSocket.getLocalPort();
+
+        /*
+         * Signal Client, we're ready for his connect.
+         */
+        serverReady = true;
+
+        SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept();
+        InputStream sslIS = sslSocket.getInputStream();
+        OutputStream sslOS = sslSocket.getOutputStream();
+
+        sslIS.read();
+        sslOS.write('A');
+        sslOS.flush();
+
+        sslSocket.close();
+    }
+
+    /*
+     * Define the client side of the test.
+     *
+     * If the server prematurely exits, serverReady will be set to true
+     * to avoid infinite hangs.
+     */
+    void doClientSide() throws Exception {
+
+        /*
+         * Wait for server to get started.
+         */
+        while (!serverReady) {
+            Thread.sleep(50);
+        }
+
+        SSLContext context = generateSSLContext();
+        SSLSocketFactory sslsf = context.getSocketFactory();
+
+        SSLSocket sslSocket =
+            (SSLSocket)sslsf.createSocket("localhost", serverPort);
+
+        // enable the specified TLS protocol
+        sslSocket.setEnabledProtocols(new String[] {tlsProtocol});
+
+        InputStream sslIS = sslSocket.getInputStream();
+        OutputStream sslOS = sslSocket.getOutputStream();
+
+        sslOS.write('B');
+        sslOS.flush();
+        sslIS.read();
+
+        sslSocket.close();
+    }
+
+    /*
+     * =============================================================
+     * The remainder is just support stuff
+     */
+    private static String tmAlgorithm;        // trust manager
+    private static String tlsProtocol;        // trust manager
+
+    private static void parseArguments(String[] args) {
+        tmAlgorithm = args[0];
+        tlsProtocol = args[1];
+    }
+
+    private static SSLContext generateSSLContext() throws Exception {
+
+        // generate certificate from cert string
+        CertificateFactory cf = CertificateFactory.getInstance("X.509");
+
+        // create a key store
+        KeyStore ks = KeyStore.getInstance("JKS");
+        ks.load(null, null);
+
+        // import the trused cert
+        X509Certificate trusedCert = null;
+        ByteArrayInputStream is =
+                new ByteArrayInputStream(trustedCertStr.getBytes());
+        trusedCert = (X509Certificate)cf.generateCertificate(is);
+        is.close();
+
+        ks.setCertificateEntry("Trusted RSA Signer", trusedCert);
+
+        // generate the private key.
+        PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
+                            new BASE64Decoder().decodeBuffer(targetPrivateKey));
+        KeyFactory kf = KeyFactory.getInstance("RSA");
+        RSAPrivateKey priKey =
+                (RSAPrivateKey)kf.generatePrivate(priKeySpec);
+
+        // generate certificate chain
+        is = new ByteArrayInputStream(targetCertStr.getBytes());
+        X509Certificate keyCert = (X509Certificate)cf.generateCertificate(is);
+        is.close();
+
+        X509Certificate[] chain = new X509Certificate[2];
+        chain[0] = keyCert;
+        chain[1] = trusedCert;
+
+        // import the key entry and the chain
+        ks.setKeyEntry("TheKey", priKey, passphrase, chain);
+
+        // create SSL context
+        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
+        tmf.init(ks);
+
+        // create the customized KM and TM
+        NoneExtendedX509TM myTM =
+            new NoneExtendedX509TM(tmf.getTrustManagers()[0]);
+        NoneExtendedX509KM myKM =
+            new NoneExtendedX509KM("TheKey", chain, priKey);
+
+        SSLContext ctx = SSLContext.getInstance(tlsProtocol);
+        // KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
+        // kmf.init(ks, passphrase);
+        // ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+        ctx.init(new KeyManager[]{myKM}, new TrustManager[]{myTM}, null);
+        ks = null;
+
+        return ctx;
+    }
+
+    static class NoneExtendedX509TM implements X509TrustManager {
+        X509TrustManager tm;
+
+        NoneExtendedX509TM(TrustManager tm) {
+            this.tm = (X509TrustManager)tm;
+        }
+
+        public void checkClientTrusted(X509Certificate chain[], String authType)
+                throws CertificateException {
+            tm.checkClientTrusted(chain, authType);
+        }
+
+        public void checkServerTrusted(X509Certificate chain[], String authType)
+                throws CertificateException {
+            tm.checkServerTrusted(chain, authType);
+        }
+
+        public X509Certificate[] getAcceptedIssuers() {
+            return tm.getAcceptedIssuers();
+        }
+    }
+
+    static class NoneExtendedX509KM implements X509KeyManager {
+        private String keyAlias;
+        private X509Certificate[] chain;
+        private PrivateKey privateKey;
+
+        NoneExtendedX509KM(String keyAlias, X509Certificate[] chain,
+                PrivateKey privateKey) {
+            this.keyAlias = keyAlias;
+            this.chain = chain;
+            this.privateKey = privateKey;
+        }
+
+        public String[] getClientAliases(String keyType, Principal[] issuers) {
+            return new String[] {keyAlias};
+        }
+
+        public String chooseClientAlias(String[] keyType, Principal[] issuers,
+                Socket socket) {
+            return keyAlias;
+        }
+
+        public String[] getServerAliases(String keyType, Principal[] issuers) {
+            return new String[] {keyAlias};
+        }
+
+        public String chooseServerAlias(String keyType, Principal[] issuers,
+                Socket socket) {
+            return keyAlias;
+        }
+
+        public X509Certificate[] getCertificateChain(String alias) {
+            return chain;
+        }
+
+        public PrivateKey getPrivateKey(String alias) {
+            return privateKey;
+        }
+    }
+
+
+    // use any free port by default
+    volatile int serverPort = 0;
+
+    volatile Exception serverException = null;
+    volatile Exception clientException = null;
+
+    public static void main(String[] args) throws Exception {
+        if (debug)
+            System.setProperty("javax.net.debug", "all");
+
+        /*
+         * Get the customized arguments.
+         */
+        parseArguments(args);
+
+        /*
+         * Start the tests.
+         */
+        new TrustTrustedCert();
+    }
+
+    Thread clientThread = null;
+    Thread serverThread = null;
+
+    /*
+     * Primary constructor, used to drive remainder of the test.
+     *
+     * Fork off the other side, then do your work.
+     */
+    TrustTrustedCert() throws Exception {
+        try {
+            if (separateServerThread) {
+                startServer(true);
+                startClient(false);
+            } else {
+                startClient(true);
+                startServer(false);
+            }
+        } catch (Exception e) {
+            // swallow for now.  Show later
+        }
+
+        /*
+         * Wait for other side to close down.
+         */
+        if (separateServerThread) {
+            serverThread.join();
+        } else {
+            clientThread.join();
+        }
+
+        /*
+         * When we get here, the test is pretty much over.
+         * Which side threw the error?
+         */
+        Exception local;
+        Exception remote;
+        String whichRemote;
+
+        if (separateServerThread) {
+            remote = serverException;
+            local = clientException;
+            whichRemote = "server";
+        } else {
+            remote = clientException;
+            local = serverException;
+            whichRemote = "client";
+        }
+
+        /*
+         * If both failed, return the curthread's exception, but also
+         * print the remote side Exception
+         */
+        if ((local != null) && (remote != null)) {
+            System.out.println(whichRemote + " also threw:");
+            remote.printStackTrace();
+            System.out.println();
+            throw local;
+        }
+
+        if (remote != null) {
+            throw remote;
+        }
+
+        if (local != null) {
+            throw local;
+        }
+    }
+
+    void startServer(boolean newThread) throws Exception {
+        if (newThread) {
+            serverThread = new Thread() {
+                public void run() {
+                    try {
+                        doServerSide();
+                    } catch (Exception e) {
+                        /*
+                         * Our server thread just died.
+                         *
+                         * Release the client, if not active already...
+                         */
+                        System.err.println("Server died...");
+                        serverReady = true;
+                        serverException = e;
+                    }
+                }
+            };
+            serverThread.start();
+        } else {
+            try {
+                doServerSide();
+            } catch (Exception e) {
+                serverException = e;
+            } finally {
+                serverReady = true;
+            }
+        }
+    }
+
+    void startClient(boolean newThread) throws Exception {
+        if (newThread) {
+            clientThread = new Thread() {
+                public void run() {
+                    try {
+                        doClientSide();
+                    } catch (Exception e) {
+                        /*
+                         * Our client thread just died.
+                         */
+                        System.err.println("Client died...");
+                        clientException = e;
+                    }
+                }
+            };
+            clientThread.start();
+        } else {
+            try {
+                doClientSide();
+            } catch (Exception e) {
+                clientException = e;
+            }
+        }
+    }
+}
diff --git a/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/NotifyHandshakeTest.sh b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/NotifyHandshakeTest.sh
index bb4cd8f..aa01dca 100644
--- a/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/NotifyHandshakeTest.sh
+++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/NotifyHandshakeTest.sh
@@ -31,31 +31,31 @@
 
 if [ "${TESTJAVA}" = "" ]
 then
-	echo "TESTJAVA not set.  Test cannot execute.  Failed."
-	exit 1
+        echo "TESTJAVA not set.  Test cannot execute.  Failed."
+        exit 1
 fi
 
 if [ "${TESTSRC}" = "" ]
 then
-	TESTSRC="."
+        TESTSRC="."
 fi
 
 OS=`uname -s`
 case "$OS" in
-    SunOS | Linux )
+    SunOS | Linux | Darwin )
         FILESEP="/"
-	PATHSEP=":"
-	;;
+        PATHSEP=":"
+        ;;
 
     CYGWIN* )
         FILESEP="/"
-	PATHSEP=";"
-	;;
+        PATHSEP=";"
+        ;;
 
     Windows* )
         FILESEP="\\"
-	PATHSEP=";"
-	;;
+        PATHSEP=";"
+        ;;
 esac
 
 set -ex
diff --git a/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxy.sh b/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxy.sh
index 8853bfa..69bdc6c 100644
--- a/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxy.sh
+++ b/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxy.sh
@@ -32,7 +32,7 @@
 HOSTNAME=`uname -n`
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxyWithAuth.sh b/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxyWithAuth.sh
index 701cd03..c7c9882 100644
--- a/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxyWithAuth.sh
+++ b/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/PostThruProxyWithAuth.sh
@@ -32,7 +32,7 @@
 HOSTNAME=`uname -n`
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/jdk/test/sun/security/tools/jarsigner/AlgOptions.sh b/jdk/test/sun/security/tools/jarsigner/AlgOptions.sh
index 61f88ac..ed5af3e 100644
--- a/jdk/test/sun/security/tools/jarsigner/AlgOptions.sh
+++ b/jdk/test/sun/security/tools/jarsigner/AlgOptions.sh
@@ -46,7 +46,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
@@ -87,7 +87,7 @@
 if [ $RESULT -eq 0 ]; then
     echo "test 1 failed"
     failed=1
-else 
+else
     echo "test 1 passed"
 fi
 
@@ -101,11 +101,11 @@
 if [ $RESULT -eq 0 ]; then
     echo "test 2 failed"
     failed=1
-else 
+else
     echo "test 2 passed"
 fi
 
-# test BOGUS signature algorithm 
+# test BOGUS signature algorithm
 ${TESTJAVA}${FS}bin${FS}jarsigner \
     -keystore ${TESTSRC}${FS}JarSigning.keystore \
     -storepass bbbbbb \
@@ -115,11 +115,11 @@
 if [ $RESULT -eq 0 ]; then
     echo "test 3 failed"
     failed=1
-else 
+else
     echo "test 3 passed"
 fi
 
-# test BOGUS digest algorithm 
+# test BOGUS digest algorithm
 ${TESTJAVA}${FS}bin${FS}jarsigner \
     -keystore ${TESTSRC}${FS}JarSigning.keystore \
     -storepass bbbbbb \
@@ -129,11 +129,11 @@
 if [ $RESULT -eq 0 ]; then
     echo "test 4 failed"
     failed=1
-else 
+else
     echo "test 4 passed"
 fi
 
-# test incompatible signature algorithm 
+# test incompatible signature algorithm
 ${TESTJAVA}${FS}bin${FS}jarsigner \
     -keystore ${TESTSRC}${FS}JarSigning.keystore \
     -storepass bbbbbb \
@@ -143,11 +143,11 @@
 if [ $RESULT -eq 0 ]; then
     echo "test 5 failed"
     failed=1
-else 
+else
     echo "test 5 passed"
 fi
 
-# test compatible signature algorithm 
+# test compatible signature algorithm
 ${TESTJAVA}${FS}bin${FS}jarsigner \
     -keystore ${TESTSRC}${FS}JarSigning.keystore \
     -storepass bbbbbb \
@@ -156,22 +156,22 @@
 RESULT=$?
 if [ $RESULT -eq 0 ]; then
     echo "test 6 passed"
-else 
+else
     echo "test 6 failed"
     failed=1
 fi
 
-# verify it 
+# verify it
 ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
 RESULT=$?
 if [ $RESULT -eq 0 ]; then
     echo "test 7 passed"
-else 
+else
     echo "test 7 failed"
     failed=1
 fi
 
-# test non-default digest algorithm 
+# test non-default digest algorithm
 ${TESTJAVA}${FS}bin${FS}jarsigner \
     -keystore ${TESTSRC}${FS}JarSigning.keystore \
     -storepass bbbbbb \
@@ -180,17 +180,17 @@
 RESULT=$?
 if [ $RESULT -eq 0 ]; then
     echo "test 8 passed"
-else 
+else
     echo "test 8 failed"
     failed=1
 fi
 
-# verify it 
+# verify it
 ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
 RESULT=$?
 if [ $RESULT -eq 0 ]; then
     echo "test 9 passed"
-else 
+else
     echo "test 9 failed"
     failed=1
 fi
@@ -205,17 +205,17 @@
 RESULT=$?
 if [ $RESULT -eq 0 ]; then
     echo "test 10 passed"
-else 
+else
     echo "test 10 failed"
     failed=1
 fi
 
-# verify it 
+# verify it
 ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
 RESULT=$?
 if [ $RESULT -eq 0 ]; then
     echo "test 11 passed"
-else 
+else
     echo "test 11 failed"
     failed=1
 fi
diff --git a/jdk/test/sun/security/tools/jarsigner/PercentSign.sh b/jdk/test/sun/security/tools/jarsigner/PercentSign.sh
index 1c2f8e6..5b36962 100644
--- a/jdk/test/sun/security/tools/jarsigner/PercentSign.sh
+++ b/jdk/test/sun/security/tools/jarsigner/PercentSign.sh
@@ -46,7 +46,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
diff --git a/jdk/test/sun/security/tools/jarsigner/diffend.sh b/jdk/test/sun/security/tools/jarsigner/diffend.sh
index 75c9c88..914831b 100644
--- a/jdk/test/sun/security/tools/jarsigner/diffend.sh
+++ b/jdk/test/sun/security/tools/jarsigner/diffend.sh
@@ -41,7 +41,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
diff --git a/jdk/test/sun/security/tools/jarsigner/oldsig.sh b/jdk/test/sun/security/tools/jarsigner/oldsig.sh
index bbdf541..feb26de 100644
--- a/jdk/test/sun/security/tools/jarsigner/oldsig.sh
+++ b/jdk/test/sun/security/tools/jarsigner/oldsig.sh
@@ -1,21 +1,21 @@
 #
 # Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
+#
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.
-# 
+#
 # This code is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 # version 2 for more details (a copy is included in the LICENSE file that
 # accompanied this code).
-# 
+#
 # You should have received a copy of the GNU General Public License version
 # 2 along with this work; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
+#
 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 # or visit www.oracle.com if you need additional information or have any
 # questions.
@@ -42,7 +42,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
@@ -73,7 +73,7 @@
 ${CP} ${TESTSRC}${FS}oldsig${FS}A.jar B.jar
 ${CP} ${TESTSRC}${FS}oldsig${FS}A.class B.class
 
-${TESTJAVA}${FS}bin${FS}jar uvf B.jar B.class 
+${TESTJAVA}${FS}bin${FS}jar uvf B.jar B.class
 ${TESTJAVA}${FS}bin${FS}jarsigner \
     -keystore ${TESTSRC}${FS}JarSigning.keystore \
     -storepass bbbbbb \
diff --git a/jdk/test/sun/security/tools/keytool/AltProviderPath.sh b/jdk/test/sun/security/tools/keytool/AltProviderPath.sh
index 9786cff..d406baf 100644
--- a/jdk/test/sun/security/tools/keytool/AltProviderPath.sh
+++ b/jdk/test/sun/security/tools/keytool/AltProviderPath.sh
@@ -46,7 +46,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
@@ -79,7 +79,7 @@
     -storetype "dks" -provider "org.test.dummy.DummyProvider" \
     -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
@@ -88,7 +88,7 @@
     -keystore keystoreCA.dks -storetype "dks" -storepass storepass \
     -provider "org.test.dummy.DummyProvider" -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
@@ -99,7 +99,7 @@
     -storetype "dks" -storepass storepass2 \
     -provider "org.test.dummy.DummyProvider" -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
@@ -109,7 +109,7 @@
     -storepass storepass2 -provider "org.test.dummy.DummyProvider" \
     -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
@@ -118,7 +118,7 @@
     -storetype "dks" -storepass storepass2 \
     -provider "org.test.dummy.DummyProvider" -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
diff --git a/jdk/test/sun/security/tools/keytool/CloneKeyAskPassword.sh b/jdk/test/sun/security/tools/keytool/CloneKeyAskPassword.sh
index 77a7303..bc3a868 100644
--- a/jdk/test/sun/security/tools/keytool/CloneKeyAskPassword.sh
+++ b/jdk/test/sun/security/tools/keytool/CloneKeyAskPassword.sh
@@ -23,7 +23,7 @@
 
 # @test
 # @bug 6178366
-# @summary confirm that keytool correctly finds (and clones) a private key 
+# @summary confirm that keytool correctly finds (and clones) a private key
 #          when the user is prompted for the key's password.
 #
 # @run shell CloneKeyAskPassword.sh
@@ -55,6 +55,10 @@
     PATHSEP=":"
     FILESEP="/"
     ;;
+  Darwin )
+    PATHSEP=":"
+    FILESEP="/"
+    ;;
   CYGWIN* )
     PATHSEP=";"
     FILESEP="/"
@@ -75,11 +79,11 @@
 
 # run the test: attempt to clone the private key
 ${TESTJAVA}${FILESEP}bin${FILESEP}keytool \
-	-keyclone \
-	-alias mykey \
-	-dest myclone \
-	-keystore CloneKeyAskPassword.jks \
-	-storepass test123 <<EOF
+        -keyclone \
+        -alias mykey \
+        -dest myclone \
+        -keystore CloneKeyAskPassword.jks \
+        -storepass test123 <<EOF
 test456
 EOF
 
diff --git a/jdk/test/sun/security/tools/keytool/NoExtNPE.sh b/jdk/test/sun/security/tools/keytool/NoExtNPE.sh
index bb79c04..f0af822 100644
--- a/jdk/test/sun/security/tools/keytool/NoExtNPE.sh
+++ b/jdk/test/sun/security/tools/keytool/NoExtNPE.sh
@@ -48,6 +48,9 @@
   Linux )
     FILESEP="/"
     ;;
+  Darwin )
+    FILESEP="/"
+    ;;
   CYGWIN* )
     FILESEP="/"
     ;;
@@ -61,8 +64,8 @@
 esac
 
 ${TESTJAVA}${FILESEP}bin${FILESEP}keytool \
-	-list -v \
-	-keystore ${TESTSRC}${FILESEP}CloneKeyAskPassword.jks \
-	-storepass test123
+        -list -v \
+        -keystore ${TESTSRC}${FILESEP}CloneKeyAskPassword.jks \
+        -storepass test123
 
 exit $?
diff --git a/jdk/test/sun/security/tools/keytool/SecretKeyKS.sh b/jdk/test/sun/security/tools/keytool/SecretKeyKS.sh
index 5f0d9e8..2574d5f 100644
--- a/jdk/test/sun/security/tools/keytool/SecretKeyKS.sh
+++ b/jdk/test/sun/security/tools/keytool/SecretKeyKS.sh
@@ -24,7 +24,7 @@
 # @test
 # @bug 4694076
 # @summary KeyTool throws ArrayIndexOutOfBoundsException for listing
-# 	   SecretKey entries in non-verbose mode.
+#          SecretKey entries in non-verbose mode.
 # @author Valerie Peng
 #
 # @run shell SecretKeyKS.sh
@@ -45,7 +45,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
diff --git a/jdk/test/sun/security/tools/keytool/StandardAlgName.sh b/jdk/test/sun/security/tools/keytool/StandardAlgName.sh
index 86574e3..debebfe 100644
--- a/jdk/test/sun/security/tools/keytool/StandardAlgName.sh
+++ b/jdk/test/sun/security/tools/keytool/StandardAlgName.sh
@@ -46,7 +46,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
@@ -75,19 +75,19 @@
 ${TESTJAVA}${FS}bin${FS}keytool -genkey -v -alias pkcs12testCA -keyalg "RsA" -keysize 2048 -sigalg "ShA1wItHRSA" -dname "cn=PKCS12 Test CA, ou=Security SQE, o=JavaSoft, c=US" -validity 3650 -keypass storepass -keystore keystoreCA.jceks.data -storepass storepass -storetype jceKS 2>&1 | egrep 'RsA|ShA1wItHRSA'
 
 RESULT=$?
-if [ $RESULT -eq 0 ]; then 
+if [ $RESULT -eq 0 ]; then
     exit 1
 else
     #Lead
     ${TESTJAVA}${FS}bin${FS}keytool -genkey -v -alias pkcs12testLead -keyalg "rSA" -keysize 1024 -sigalg "mD5withRSA" -dname "cn=PKCS12 Test Lead, ou=Security SQE, o=JavaSoft, c=US" -validity 3650 -keypass storepass -keystore keystoreLead.jceks.data -storepass storepass -storetype jCeks 2>&1 | egrep 'rSA|mD5withRSA'
     RESULT=$?
-    if [ $RESULT -eq 0 ]; then 
+    if [ $RESULT -eq 0 ]; then
         exit 1
     else
         #End User 1
         ${TESTJAVA}${FS}bin${FS}keytool -genkey -v -alias pkcs12testEndUser1 -keyalg "RSa" -keysize 1024 -sigalg "sHa1wIThRSA" -dname "cn=PKCS12 Test End User 1, ou=Security SQE, o=JavaSoft, c=US" -validity 3650 -keypass storepass -keystore keystoreEndUser1.jceks.data -storepass storepass -storetype Jceks 2>&1 | egrep 'RSa|sHa1wIThRSA'
         RESULT=$?
-        if [ $RESULT -eq 0 ]; then 
+        if [ $RESULT -eq 0 ]; then
             exit 1
         else
             exit 0
diff --git a/jdk/test/sun/security/tools/keytool/printssl.sh b/jdk/test/sun/security/tools/keytool/printssl.sh
index b91d5fd..b17113a 100644
--- a/jdk/test/sun/security/tools/keytool/printssl.sh
+++ b/jdk/test/sun/security/tools/keytool/printssl.sh
@@ -37,7 +37,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     FS="/"
     ;;
   CYGWIN* )
diff --git a/jdk/test/sun/security/tools/keytool/resource.sh b/jdk/test/sun/security/tools/keytool/resource.sh
index 05ba97c..2123a78 100644
--- a/jdk/test/sun/security/tools/keytool/resource.sh
+++ b/jdk/test/sun/security/tools/keytool/resource.sh
@@ -43,7 +43,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     FS="/"
     TMP=/tmp
@@ -68,7 +68,7 @@
 ${TESTJAVA}${FS}bin${FS}keytool > ${TMP}${FS}temp_file_40875602475 2> ${NULL}
 grep MissingResourceException ${TMP}${FS}temp_file_40875602475
 
-if [ $? -eq 0 ]; then 
+if [ $? -eq 0 ]; then
     rm ${TMP}${FS}temp_file_40875602475
     exit 1
 fi
diff --git a/jdk/test/sun/security/tools/keytool/standard.sh b/jdk/test/sun/security/tools/keytool/standard.sh
index a3073e2..98e3b03 100644
--- a/jdk/test/sun/security/tools/keytool/standard.sh
+++ b/jdk/test/sun/security/tools/keytool/standard.sh
@@ -44,7 +44,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows_* )
diff --git a/jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh b/jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh
index d56e4a0..414d02b 100644
--- a/jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh
+++ b/jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh
@@ -32,7 +32,7 @@
 
 #Call this from anywhere to fail the test with an error message
 # usage: fail "reason why the test failed"
-fail() 
+fail()
  { echo "The test failed :-("
    echo "$*" 1>&2
    echo "exit status was $status"
@@ -41,7 +41,7 @@
 
 #Call this from anywhere to pass the test with a message
 # usage: pass "reason why the test passed if applicable"
-pass() 
+pass()
  { echo "The test passed!!!"
    echo "$*" 1>&2
    exit 0
@@ -53,7 +53,7 @@
 
 OS=`uname -s`
 case "$OS" in
-   SunOS | Linux )
+   SunOS | Linux | Darwin )
       PATHSEP=":"
       ;;
 
@@ -80,7 +80,7 @@
    if [ -n "$1" ] ; then
           TESTJAVA=$1
       else
-	  TESTJAVA=$JAVA_HOME
+          TESTJAVA=$JAVA_HOME
    fi
    TESTSRC=.
    TESTCLASSES=.
diff --git a/jdk/test/sun/tools/native2ascii/resources/ImmutableResourceTest.sh b/jdk/test/sun/tools/native2ascii/resources/ImmutableResourceTest.sh
index 2e2a666..527de19 100644
--- a/jdk/test/sun/tools/native2ascii/resources/ImmutableResourceTest.sh
+++ b/jdk/test/sun/tools/native2ascii/resources/ImmutableResourceTest.sh
@@ -28,14 +28,14 @@
 #
 #   @run shell ImmutableResourceTest.sh
 #
-# 
+#
 
 # Beginning of subroutines:
 status=1
 
 #Call this from anywhere to fail the test with an error message
 # usage: fail "reason why the test failed"
-fail() 
+fail()
  { echo "The test failed :-("
    echo "$*" 1>&2
    echo "exit status was $status"
@@ -44,7 +44,7 @@
 
 #Call this from anywhere to pass the test with a message
 # usage: pass "reason why the test passed if applicable"
-pass() 
+pass()
  { echo "The test passed!!!"
    echo "$*" 1>&2
    exit 0
@@ -56,7 +56,7 @@
 
 OS=`uname -s`
 case "$OS" in
-   SunOS | Linux )
+   SunOS | Linux | Darwin )
       PATHSEP=":"
       ;;
 
@@ -83,7 +83,7 @@
    if [ -n "$1" ] ; then
           TESTJAVA=$1
       else
-	  TESTJAVA=$JAVA_HOME
+          TESTJAVA=$JAVA_HOME
    fi
    TESTSRC=.
    TESTCLASSES=.
diff --git a/langtools/.hgtags b/langtools/.hgtags
index 8c5a126..9c3707e 100644
--- a/langtools/.hgtags
+++ b/langtools/.hgtags
@@ -140,3 +140,4 @@
 d37897312d318c18b0a855ce80f70c410865d105 jdk7u2-b11
 f0802d8a0909f66ce19d3d44b33ddf4943aee076 jdk7u2-b12
 f474527e77e4797d78bd6c3b31923fddcfd9d5c6 jdk7u2-b13
+fc0769df8cd03fffc38c7a1ab6b2e2e7cc2506a8 jdk7u2-b21
diff --git a/langtools/make/jprt.properties b/langtools/make/jprt.properties
index c95c9d0..537c099 100644
--- a/langtools/make/jprt.properties
+++ b/langtools/make/jprt.properties
@@ -25,12 +25,24 @@
 
 # Properties for jprt
 
-# Use whatever release that the submitted job requests
-jprt.tools.default.release=${jprt.submit.release}
+# Locked down to jdk7
+jprt.tools.default.release=jdk7
 
 # The different build flavors we want, we override here so we just get these 2
 jprt.build.flavors=product,fastdebug
 
+# Standard list of jprt build targets for this source tree
+jprt.build.targets=                                             \
+    solaris_sparc_5.10-{product|fastdebug},                     \
+    solaris_sparcv9_5.10-{product|fastdebug},                   \
+    solaris_i586_5.10-{product|fastdebug},                      \
+    solaris_x64_5.10-{product|fastdebug},                       \
+    linux_i586_2.6-{product|fastdebug},                         \
+    linux_x64_2.6-{product|fastdebug},                          \
+    macosx_x64_10.7-{product|fastdebug},                        \
+    windows_i586_5.1-{product|fastdebug},                       \
+    windows_x64_5.2-{product|fastdebug}
+
 # Directories to be excluded from the source bundles
 jprt.bundle.exclude.src.dirs=build dist webrev
 
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java b/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
index 7156513..9f9273e 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
@@ -103,6 +103,8 @@
         VAL("kindname.value"),
         METHOD("kindname.method"),
         CLASS("kindname.class"),
+        STATIC_INIT("kindname.static.init"),
+        INSTANCE_INIT("kindname.instance.init"),
         PACKAGE("kindname.package");
 
         private String name;
@@ -170,9 +172,11 @@
             return KindName.CONSTRUCTOR;
 
         case METHOD:
-        case STATIC_INIT:
-        case INSTANCE_INIT:
             return KindName.METHOD;
+        case STATIC_INIT:
+            return KindName.STATIC_INIT;
+        case INSTANCE_INIT:
+            return KindName.INSTANCE_INIT;
 
         default:
             if (sym.kind == VAL)
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java b/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
index 7f63aa4..59aa924 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
@@ -311,7 +311,7 @@
 
     @Override
     public String visitMethodSymbol(MethodSymbol s, Locale locale) {
-        if ((s.flags() & BLOCK) != 0) {
+        if (s.isStaticOrInstanceInit()) {
             return s.owner.name.toString();
         } else {
             String ms = (s.name == s.name.table.names.init)
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
index 05c9f6b..69473bd 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
@@ -149,7 +149,8 @@
      * the default package; otherwise, the owner symbol is returned
      */
     public Symbol location() {
-        if (owner.name == null || (owner.name.isEmpty() && owner.kind != PCK && owner.kind != TYP)) {
+        if (owner.name == null || (owner.name.isEmpty() &&
+                (owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) {
             return null;
         }
         return owner;
@@ -1299,10 +1300,17 @@
                 return ElementKind.CONSTRUCTOR;
             else if (name == name.table.names.clinit)
                 return ElementKind.STATIC_INIT;
+            else if ((flags() & BLOCK) != 0)
+                return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
             else
                 return ElementKind.METHOD;
         }
 
+        public boolean isStaticOrInstanceInit() {
+            return getKind() == ElementKind.STATIC_INIT ||
+                    getKind() == ElementKind.INSTANCE_INIT;
+        }
+
         public Attribute getDefaultValue() {
             return defaultValue;
         }
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java
index 59067e7..27fc8e8 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java
@@ -269,14 +269,15 @@
 
     // <editor-fold defaultstate="collapsed" desc="isConvertible">
     /**
-     * Is t a subtype of or convertiable via boxing/unboxing
-     * convertions to s?
+     * Is t a subtype of or convertible via boxing/unboxing
+     * conversion to s?
      */
     public boolean isConvertible(Type t, Type s, Warner warn) {
+        if (t.tag == ERROR)
+            return true;
         boolean tPrimitive = t.isPrimitive();
         boolean sPrimitive = s.isPrimitive();
         if (tPrimitive == sPrimitive) {
-            checkUnsafeVarargsConversion(t, s, warn);
             return isSubtypeUnchecked(t, s, warn);
         }
         if (!allowBoxing) return false;
@@ -284,27 +285,6 @@
             ? isSubtype(boxedClass(t).type, s)
             : isSubtype(unboxedType(t), s);
     }
-    //where
-    private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) {
-        if (t.tag != ARRAY || isReifiable(t)) return;
-        ArrayType from = (ArrayType)t;
-        boolean shouldWarn = false;
-        switch (s.tag) {
-            case ARRAY:
-                ArrayType to = (ArrayType)s;
-                shouldWarn = from.isVarargs() &&
-                        !to.isVarargs() &&
-                        !isReifiable(from);
-                break;
-            case CLASS:
-                shouldWarn = from.isVarargs() &&
-                        isSubtype(from, s);
-                break;
-        }
-        if (shouldWarn) {
-            warn.warn(LintCategory.VARARGS);
-        }
-    }
 
     /**
      * Is t a subtype of or convertiable via boxing/unboxing
@@ -326,42 +306,63 @@
      * Is t an unchecked subtype of s?
      */
     public boolean isSubtypeUnchecked(Type t, Type s, Warner warn) {
-        if (t.tag == ARRAY && s.tag == ARRAY) {
-            if (((ArrayType)t).elemtype.tag <= lastBaseTag) {
-                return isSameType(elemtype(t), elemtype(s));
-            } else {
-                ArrayType from = (ArrayType)t;
-                ArrayType to = (ArrayType)s;
-                if (from.isVarargs() &&
-                        !to.isVarargs() &&
-                        !isReifiable(from)) {
-                    warn.warn(LintCategory.VARARGS);
+        boolean result = isSubtypeUncheckedInternal(t, s, warn);
+        if (result) {
+            checkUnsafeVarargsConversion(t, s, warn);
+        }
+        return result;
+    }
+    //where
+        private boolean isSubtypeUncheckedInternal(Type t, Type s, Warner warn) {
+            if (t.tag == ARRAY && s.tag == ARRAY) {
+                if (((ArrayType)t).elemtype.tag <= lastBaseTag) {
+                    return isSameType(elemtype(t), elemtype(s));
+                } else {
+                    return isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
                 }
-                return isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
-            }
-        } else if (isSubtype(t, s)) {
-            return true;
-        }
-        else if (t.tag == TYPEVAR) {
-            return isSubtypeUnchecked(t.getUpperBound(), s, warn);
-        }
-        else if (s.tag == UNDETVAR) {
-            UndetVar uv = (UndetVar)s;
-            if (uv.inst != null)
-                return isSubtypeUnchecked(t, uv.inst, warn);
-        }
-        else if (!s.isRaw()) {
-            Type t2 = asSuper(t, s.tsym);
-            if (t2 != null && t2.isRaw()) {
-                if (isReifiable(s))
-                    warn.silentWarn(LintCategory.UNCHECKED);
-                else
-                    warn.warn(LintCategory.UNCHECKED);
+            } else if (isSubtype(t, s)) {
                 return true;
             }
+            else if (t.tag == TYPEVAR) {
+                return isSubtypeUnchecked(t.getUpperBound(), s, warn);
+            }
+            else if (s.tag == UNDETVAR) {
+                UndetVar uv = (UndetVar)s;
+                if (uv.inst != null)
+                    return isSubtypeUnchecked(t, uv.inst, warn);
+            }
+            else if (!s.isRaw()) {
+                Type t2 = asSuper(t, s.tsym);
+                if (t2 != null && t2.isRaw()) {
+                    if (isReifiable(s))
+                        warn.silentWarn(LintCategory.UNCHECKED);
+                    else
+                        warn.warn(LintCategory.UNCHECKED);
+                    return true;
+                }
+            }
+            return false;
         }
-        return false;
-    }
+
+        private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) {
+            if (t.tag != ARRAY || isReifiable(t)) return;
+            ArrayType from = (ArrayType)t;
+            boolean shouldWarn = false;
+            switch (s.tag) {
+                case ARRAY:
+                    ArrayType to = (ArrayType)s;
+                    shouldWarn = from.isVarargs() &&
+                            !to.isVarargs() &&
+                            !isReifiable(from);
+                    break;
+                case CLASS:
+                    shouldWarn = from.isVarargs();
+                    break;
+            }
+            if (shouldWarn) {
+                warn.warn(LintCategory.VARARGS);
+            }
+        }
 
     /**
      * Is t a subtype of s?<br>
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
index aa5f7c2..15c331f 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
@@ -306,7 +306,16 @@
      */
     void duplicateError(DiagnosticPosition pos, Symbol sym) {
         if (!sym.type.isErroneous()) {
-            log.error(pos, "already.defined", sym, sym.location());
+            Symbol location = sym.location();
+            if (location.kind == MTH &&
+                    ((MethodSymbol)location).isStaticOrInstanceInit()) {
+                log.error(pos, "already.defined.in.clinit", kindName(sym), sym,
+                        kindName(sym.location()), kindName(sym.location().enclClass()),
+                        sym.location().enclClass());
+            } else {
+                log.error(pos, "already.defined", kindName(sym), sym,
+                        kindName(sym.location()), sym.location());
+            }
         }
     }
 
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
index 2938f99..5b64a26 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
@@ -249,6 +249,13 @@
         }
     };
 
+    private final Filter<Type> botFilter = new Filter<Type>() {
+        @Override
+        public boolean accepts(Type t) {
+            return t.tag != BOT;
+        }
+    };
+
     /** Instantiate undetermined type variable to the lub of all its lower bounds.
      *  Throw a NoInstanceException if this not possible.
      */
@@ -269,21 +276,18 @@
             // VGJ: sort of inlined maximizeInst() below.  Adding
             // bounds can cause lobounds that are above hibounds.
             List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
-            if (hibounds.isEmpty())
-                return;
             Type hb = null;
-            if (hibounds.tail.isEmpty())
+            if (hibounds.isEmpty())
+                hb = syms.objectType;
+            else if (hibounds.tail.isEmpty())
                 hb = hibounds.head;
-            else for (List<Type> bs = hibounds;
-                      bs.nonEmpty() && hb == null;
-                      bs = bs.tail) {
-                if (isSubClass(bs.head, hibounds))
-                    hb = types.fromUnknownFun.apply(bs.head);
-            }
+            else
+                hb = types.glb(hibounds);
             if (hb == null ||
-                !types.isSubtypeUnchecked(hb, hibounds, warn) ||
-                !types.isSubtypeUnchecked(that.inst, hb, warn))
-                throw ambiguousNoInstanceException;
+                hb.isErroneous())
+                throw ambiguousNoInstanceException
+                        .setMessage("incompatible.upper.bounds",
+                                    that.qtype, hibounds);
         }
     }
 
@@ -470,7 +474,8 @@
                         UndetVar uv = (UndetVar)t;
                         if (uv.qtype == tv) {
                             switch (ck) {
-                                case EXTENDS: return uv.hibounds.appendList(types.subst(types.getBounds(tv), all_tvars, inferredTypes));
+                                case EXTENDS: return Type.filter(uv.hibounds, botFilter)
+                                        .appendList(types.subst(types.getBounds(tv), all_tvars, inferredTypes));
                                 case SUPER: return uv.lobounds;
                                 case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.<Type>nil();
                             }
diff --git a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties
index 79a7998..73a9685 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties
@@ -68,9 +68,13 @@
 compiler.err.already.annotated=\
     {0} {1} has already been annotated
 
-# 0: symbol, 1: symbol
+# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol
 compiler.err.already.defined=\
-    {0} is already defined in {1}
+    {0} {1} is already defined in {2} {3}
+
+# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol kind, 4: symbol
+compiler.err.already.defined.in.clinit=\
+    {0} {1} is already defined in {2} of {3} {4}
 
 # 0: string
 compiler.err.already.defined.single.import=\
@@ -1602,6 +1606,10 @@
 compiler.misc.no.unique.minimal.instance.exists=\
     no unique minimal instance exists for type variable {0} with lower bounds {1}
 
+# 0: type, 1: list of type
+compiler.misc.incompatible.upper.bounds=\
+    inference variable {0} has incompatible upper bounds {1}
+
 # 0: list of type, 1: type, 2: type
 compiler.misc.infer.no.conforming.instance.exists=\
     no instance(s) of type variable(s) {0} exist so that {1} conforms to {2}
@@ -1757,6 +1765,12 @@
 compiler.misc.kindname.package=\
     package
 
+compiler.misc.kindname.static.init=\
+    static initializer
+
+compiler.misc.kindname.instance.init=\
+    instance initializer
+
 #####
 
 compiler.misc.no.args=\
diff --git a/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java b/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
index 44badbf..24861c2 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
@@ -412,7 +412,7 @@
         @Override
         public String visitMethodSymbol(MethodSymbol s, Locale locale) {
             String ownerName = visit(s.owner, locale);
-            if ((s.flags() & BLOCK) != 0) {
+            if (s.isStaticOrInstanceInit()) {
                return ownerName;
             } else {
                 String ms = (s.name == s.name.table.names.init)
diff --git a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java
index cac7f99..1209686 100644
--- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -257,24 +257,15 @@
         for (String p: excludedPackages)
             includedPackages.put(p, false);
 
-        if (docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
-            searchSubPackages(subPackages,
-                    includedPackages,
-                    packages, packageFiles,
-                    StandardLocation.SOURCE_PATH,
-                    EnumSet.of(JavaFileObject.Kind.SOURCE));
-            searchSubPackages(subPackages,
-                    includedPackages,
-                    packages, packageFiles,
-                    StandardLocation.CLASS_PATH,
-                    EnumSet.of(JavaFileObject.Kind.CLASS));
-        } else {
-            searchSubPackages(subPackages,
-                    includedPackages,
-                    packages, packageFiles,
-                    StandardLocation.CLASS_PATH,
-                    EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS));
-        }
+        StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
+                ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
+
+        searchSubPackages(subPackages,
+                includedPackages,
+                packages, packageFiles,
+                path,
+                EnumSet.of(JavaFileObject.Kind.SOURCE));
+
         return packageFiles;
     }
 
diff --git a/langtools/test/tools/javac/7085024/T7085024.java b/langtools/test/tools/javac/7085024/T7085024.java
new file mode 100644
index 0000000..8ab0b0b
--- /dev/null
+++ b/langtools/test/tools/javac/7085024/T7085024.java
@@ -0,0 +1,12 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7085024
+ * @summary internal error; cannot instantiate Foo
+ * @compile/fail/ref=T7085024.out -XDrawDiagnostics T7085024.java
+ */
+
+class T7085024 {
+    T7085024 (boolean ret) { } //internal error goes away if constructor accepts a reference type
+
+    T7085024 f = new T7085024((NonExistentClass) null );
+}
diff --git a/langtools/test/tools/javac/7085024/T7085024.out b/langtools/test/tools/javac/7085024/T7085024.out
new file mode 100644
index 0000000..cad1037
--- /dev/null
+++ b/langtools/test/tools/javac/7085024/T7085024.out
@@ -0,0 +1,2 @@
+T7085024.java:11:32: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, T7085024, null)
+1 error
diff --git a/langtools/test/tools/javac/7086595/T7086595.java b/langtools/test/tools/javac/7086595/T7086595.java
new file mode 100644
index 0000000..83ab4f9
--- /dev/null
+++ b/langtools/test/tools/javac/7086595/T7086595.java
@@ -0,0 +1,32 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7086595
+ * @summary Error message bug: name of initializer is 'null'
+ * @compile/fail/ref=T7086595.out -XDrawDiagnostics T7086595.java
+ */
+
+class T7086595 {
+
+    String s = "x";
+    String s = nonExistent;
+
+    int foo() {
+        String s = "x";
+        String s = nonExistent;
+    }
+
+    static int bar() {
+        String s = "x";
+        String s = nonExistent;
+    }
+
+    {
+        String s = "x";
+        String s = nonExistent;
+    }
+
+    static {
+        String s = "x";
+        String s = nonExistent;
+    }
+}
diff --git a/langtools/test/tools/javac/7086595/T7086595.out b/langtools/test/tools/javac/7086595/T7086595.out
new file mode 100644
index 0000000..9e53aea
--- /dev/null
+++ b/langtools/test/tools/javac/7086595/T7086595.out
@@ -0,0 +1,11 @@
+T7086595.java:11:12: compiler.err.already.defined: kindname.variable, s, kindname.class, T7086595
+T7086595.java:11:16: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:15:16: compiler.err.already.defined: kindname.variable, s, kindname.method, foo()
+T7086595.java:15:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:20:16: compiler.err.already.defined: kindname.variable, s, kindname.method, bar()
+T7086595.java:20:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:25:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.instance.init, kindname.class, T7086595
+T7086595.java:25:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:30:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.static.init, kindname.class, T7086595
+T7086595.java:30:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+10 errors
diff --git a/langtools/test/tools/javac/Diagnostics/6860795/T6860795.out b/langtools/test/tools/javac/Diagnostics/6860795/T6860795.out
index c0ba0f1..cc50d8f 100644
--- a/langtools/test/tools/javac/Diagnostics/6860795/T6860795.out
+++ b/langtools/test/tools/javac/Diagnostics/6860795/T6860795.out
@@ -1,2 +1,2 @@
-T6860795.java:10:27: compiler.err.already.defined: x, foo
+T6860795.java:10:27: compiler.err.already.defined: kindname.variable, x, kindname.method, foo
 1 error
diff --git a/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out b/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out
index b9f8525..d32924f 100644
--- a/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out
+++ b/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out
@@ -1,3 +1,3 @@
-T6862608a.java:19:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String>
+T6862608a.java:19:41: compiler.err.invalid.inferred.types: T, (compiler.misc.no.conforming.assignment.exists: java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super java.lang.String>>)
 - compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, <T>compound(java.lang.Iterable<? extends java.util.Comparator<? super T>>))}
 1 error
diff --git a/langtools/test/tools/javac/LocalClasses_2.out b/langtools/test/tools/javac/LocalClasses_2.out
index 5391308..1ef0527 100644
--- a/langtools/test/tools/javac/LocalClasses_2.out
+++ b/langtools/test/tools/javac/LocalClasses_2.out
@@ -1,2 +1,2 @@
-LocalClasses_2.java:15:13: compiler.err.already.defined: Local, foo()
+LocalClasses_2.java:15:13: compiler.err.already.defined: kindname.class, Local, kindname.method, foo()
 1 error
diff --git a/langtools/test/tools/javac/NestedInnerClassNames.out b/langtools/test/tools/javac/NestedInnerClassNames.out
index b4f171b..2038a29 100644
--- a/langtools/test/tools/javac/NestedInnerClassNames.out
+++ b/langtools/test/tools/javac/NestedInnerClassNames.out
@@ -1,18 +1,18 @@
-NestedInnerClassNames.java:16:5: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:23:9: compiler.err.already.defined: NestedInnerClassNames.foo, NestedInnerClassNames
-NestedInnerClassNames.java:34:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:45:9: compiler.err.already.defined: NestedInnerClassNames.baz, NestedInnerClassNames
-NestedInnerClassNames.java:46:13: compiler.err.already.defined: NestedInnerClassNames.baz.baz, NestedInnerClassNames.baz
-NestedInnerClassNames.java:59:9: compiler.err.already.defined: NestedInnerClassNames.foo$bar, NestedInnerClassNames
-NestedInnerClassNames.java:76:13: compiler.err.already.defined: NestedInnerClassNames.$bar, NestedInnerClassNames
-NestedInnerClassNames.java:90:13: compiler.err.already.defined: NestedInnerClassNames.bar$bar.bar, NestedInnerClassNames.bar$bar
+NestedInnerClassNames.java:16:5: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:23:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:34:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:45:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:46:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz.baz, kindname.class, NestedInnerClassNames.baz
+NestedInnerClassNames.java:59:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo$bar, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:76:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.$bar, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:90:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.bar$bar.bar, kindname.class, NestedInnerClassNames.bar$bar
 NestedInnerClassNames.java:109:5: compiler.err.duplicate.class: NestedInnerClassNames.foo.foo
-NestedInnerClassNames.java:19:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:28:13: compiler.err.already.defined: foo, m2()
-NestedInnerClassNames.java:40:13: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:52:13: compiler.err.already.defined: baz, m4()
-NestedInnerClassNames.java:53:17: compiler.err.already.defined: baz.baz, baz
-NestedInnerClassNames.java:67:13: compiler.err.already.defined: foo$bar, m5()
-NestedInnerClassNames.java:83:17: compiler.err.already.defined: $bar, m6()
-NestedInnerClassNames.java:97:17: compiler.err.already.defined: bar$bar.bar, bar$bar
+NestedInnerClassNames.java:19:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:28:13: compiler.err.already.defined: kindname.class, foo, kindname.method, m2()
+NestedInnerClassNames.java:40:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:52:13: compiler.err.already.defined: kindname.class, baz, kindname.method, m4()
+NestedInnerClassNames.java:53:17: compiler.err.already.defined: kindname.class, baz.baz, kindname.class, baz
+NestedInnerClassNames.java:67:13: compiler.err.already.defined: kindname.class, foo$bar, kindname.method, m5()
+NestedInnerClassNames.java:83:17: compiler.err.already.defined: kindname.class, $bar, kindname.method, m6()
+NestedInnerClassNames.java:97:17: compiler.err.already.defined: kindname.class, bar$bar.bar, kindname.class, bar$bar
 17 errors
diff --git a/langtools/test/tools/javac/TryWithResources/BadTwr.out b/langtools/test/tools/javac/TryWithResources/BadTwr.out
index aad91d6..6b0b3a9 100644
--- a/langtools/test/tools/javac/TryWithResources/BadTwr.out
+++ b/langtools/test/tools/javac/TryWithResources/BadTwr.out
@@ -1,5 +1,5 @@
-BadTwr.java:13:46: compiler.err.already.defined: r1, main(java.lang.String...)
-BadTwr.java:18:20: compiler.err.already.defined: args, main(java.lang.String...)
+BadTwr.java:13:46: compiler.err.already.defined: kindname.variable, r1, kindname.method, main(java.lang.String...)
+BadTwr.java:18:20: compiler.err.already.defined: kindname.variable, args, kindname.method, main(java.lang.String...)
 BadTwr.java:21:13: compiler.err.cant.assign.val.to.final.var: thatsIt
-BadTwr.java:26:24: compiler.err.already.defined: name, main(java.lang.String...)
+BadTwr.java:26:24: compiler.err.already.defined: kindname.variable, name, kindname.method, main(java.lang.String...)
 4 errors
diff --git a/langtools/test/tools/javac/TryWithResources/DuplicateResourceDecl.out b/langtools/test/tools/javac/TryWithResources/DuplicateResourceDecl.out
index e0056ad..c6406eb 100644
--- a/langtools/test/tools/javac/TryWithResources/DuplicateResourceDecl.out
+++ b/langtools/test/tools/javac/TryWithResources/DuplicateResourceDecl.out
@@ -1,2 +1,2 @@
-DuplicateResourceDecl.java:12:56: compiler.err.already.defined: c, main(java.lang.String[])
+DuplicateResourceDecl.java:12:56: compiler.err.already.defined: kindname.variable, c, kindname.method, main(java.lang.String[])
 1 error
diff --git a/langtools/test/tools/javac/diags/examples/AlreadyDefinedClinit.java b/langtools/test/tools/javac/diags/examples/AlreadyDefinedClinit.java
new file mode 100644
index 0000000..caa32c7
--- /dev/null
+++ b/langtools/test/tools/javac/diags/examples/AlreadyDefinedClinit.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.already.defined.in.clinit
+
+class AlreadyDefinedClinit {
+    static {
+        int i;
+        int i;
+    }
+}
diff --git a/langtools/test/tools/javac/diags/examples/IncompatibleUpperBounds.java b/langtools/test/tools/javac/diags/examples/IncompatibleUpperBounds.java
new file mode 100644
index 0000000..bc15256
--- /dev/null
+++ b/langtools/test/tools/javac/diags/examples/IncompatibleUpperBounds.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//key: compiler.err.cant.apply.symbols
+//key: compiler.misc.inapplicable.method
+//key: compiler.misc.arg.length.mismatch
+//key: compiler.misc.incompatible.upper.bounds
+
+import java.util.List;
+
+class IncompatibleUpperBounds {
+    <S> void m(List<? super S> s1, List<? super S> s2) { }
+    void m(Object o) {}
+
+    void test(List<Integer> li, List<String> ls) {
+        m(li, ls);
+    }
+}
diff --git a/langtools/test/tools/javac/diags/examples/KindnameInstanceInit.java b/langtools/test/tools/javac/diags/examples/KindnameInstanceInit.java
new file mode 100644
index 0000000..f03c5a8
--- /dev/null
+++ b/langtools/test/tools/javac/diags/examples/KindnameInstanceInit.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.already.defined.in.clinit
+// key: compiler.misc.kindname.instance.init
+// key: compiler.misc.kindname.class
+// key: compiler.misc.kindname.variable
+// key: compiler.misc.count.error
+// key: compiler.err.error
+// run: backdoor
+
+class KindnameInstanceInit {
+    {
+        int i;
+        int i;
+    }
+}
diff --git a/langtools/test/tools/javac/diags/examples/KindnameStaticInit.java b/langtools/test/tools/javac/diags/examples/KindnameStaticInit.java
new file mode 100644
index 0000000..047a370
--- /dev/null
+++ b/langtools/test/tools/javac/diags/examples/KindnameStaticInit.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.already.defined.in.clinit
+// key: compiler.misc.kindname.static.init
+// key: compiler.misc.kindname.class
+// key: compiler.misc.kindname.variable
+// key: compiler.misc.count.error
+// key: compiler.err.error
+// run: backdoor
+
+class KindnameStaticInit {
+    static {
+        int i;
+        int i;
+    }
+}
diff --git a/langtools/test/tools/javac/generics/6910550/T6910550d.out b/langtools/test/tools/javac/generics/6910550/T6910550d.out
index 676a967..c884fe4 100644
--- a/langtools/test/tools/javac/generics/6910550/T6910550d.out
+++ b/langtools/test/tools/javac/generics/6910550/T6910550d.out
@@ -1,2 +1,2 @@
-T6910550d.java:12:14: compiler.err.already.defined: <X>m(X), T6910550d
+T6910550d.java:12:14: compiler.err.already.defined: kindname.method, <X>m(X), kindname.class, T6910550d
 1 error
diff --git a/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out b/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out
index c65e749..20446fd 100644
--- a/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out
+++ b/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out
@@ -1,2 +1,2 @@
-T6638712a.java:16:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String>
+T6638712a.java:16:41: compiler.err.invalid.inferred.types: T, (compiler.misc.no.conforming.assignment.exists: java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super java.lang.String>>)
 1 error
diff --git a/langtools/test/tools/javac/generics/inference/7086586/T7086586.java b/langtools/test/tools/javac/generics/inference/7086586/T7086586.java
new file mode 100644
index 0000000..1045e5b
--- /dev/null
+++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586.java
@@ -0,0 +1,19 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 7086586
+ * @summary Inference producing null type argument
+ * @compile/fail/ref=T7086586.out -XDrawDiagnostics T7086586.java
+ */
+import java.util.List;
+
+class T7086586 {
+
+    <T> List<T> m(List<? super T> dummy) { return null; }
+
+    void test(List<?> l) {
+        String s = m(l).get(0);
+        Number n = m(l).get(0);
+        Exception e = m(l).get(0);
+        m(l).nonExistentMethod();
+    }
+}
diff --git a/langtools/test/tools/javac/generics/inference/7086586/T7086586.out b/langtools/test/tools/javac/generics/inference/7086586/T7086586.out
new file mode 100644
index 0000000..e9a6a75
--- /dev/null
+++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586.out
@@ -0,0 +1,5 @@
+T7086586.java:14:21: compiler.err.invalid.inferred.types: T, (compiler.misc.no.conforming.assignment.exists: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super java.lang.Object>)
+T7086586.java:15:21: compiler.err.invalid.inferred.types: T, (compiler.misc.no.conforming.assignment.exists: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super java.lang.Object>)
+T7086586.java:16:24: compiler.err.invalid.inferred.types: T, (compiler.misc.no.conforming.assignment.exists: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super java.lang.Object>)
+T7086586.java:17:10: compiler.err.invalid.inferred.types: T, (compiler.misc.no.conforming.assignment.exists: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super java.lang.Object>)
+4 errors
diff --git a/langtools/test/tools/javac/generics/inference/7086601/T7086601a.java b/langtools/test/tools/javac/generics/inference/7086601/T7086601a.java
new file mode 100644
index 0000000..5243d82
--- /dev/null
+++ b/langtools/test/tools/javac/generics/inference/7086601/T7086601a.java
@@ -0,0 +1,34 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 7086601
+ * @summary Error message bug: cause for method mismatch is 'null'
+ * @compile/fail/ref=T7086601a.out -XDrawDiagnostics T7086601a.java
+ */
+
+class T7086601 {
+    static <S> void m1(Iterable<? super S> s1, Iterable<? super S> s2) { }
+    static void m1(Object o) {}
+
+    static <S> void m2(Iterable<? super S> s1, Iterable<? super S> s2, Iterable<? super S> s3) { }
+    static void m2(Object o) {}
+
+    @SafeVarargs
+    static <S> void m3(Iterable<? super S>... ss) { }
+    static void m3(Object o) {}
+
+    static void test1(Iterable<String> is, Iterable<Integer> ii) {
+        m1(is, ii);
+    }
+
+    static void test2(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) {
+        m2(is, ii, id);
+    }
+
+    static void test3(Iterable<String> is, Iterable<Integer> ii) {
+        m3(is, ii);
+    }
+
+    static void test4(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) {
+        m3(is, ii, id);
+    }
+}
diff --git a/langtools/test/tools/javac/generics/inference/7086601/T7086601a.out b/langtools/test/tools/javac/generics/inference/7086601/T7086601a.out
new file mode 100644
index 0000000..8b2cdb2
--- /dev/null
+++ b/langtools/test/tools/javac/generics/inference/7086601/T7086601a.out
@@ -0,0 +1,5 @@
+T7086601a.java:20:9: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m1(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m1(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))}
+T7086601a.java:24:9: compiler.err.cant.apply.symbols: kindname.method, m2, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m2(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m2(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))}
+T7086601a.java:28:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))}
+T7086601a.java:32:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))}
+4 errors
diff --git a/langtools/test/tools/javac/generics/inference/7086601/T7086601b.java b/langtools/test/tools/javac/generics/inference/7086601/T7086601b.java
new file mode 100644
index 0000000..0eceb7f
--- /dev/null
+++ b/langtools/test/tools/javac/generics/inference/7086601/T7086601b.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7086601
+ * @summary Error message bug: cause for method mismatch is 'null'
+ */
+
+import com.sun.source.util.JavacTask;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.ArrayList;
+import javax.tools.Diagnostic;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+
+
+public class T7086601b {
+
+    static int checkCount = 0;
+
+    enum TypeKind {
+        STRING("String", false),
+        INTEGER("Integer", false),
+        NUMBER("Number", false),
+        SERIALIZABLE("java.io.Serializable", true),
+        CLONEABLE("Cloneable", true),
+        X("X", false),
+        Y("Y", false),
+        Z("Z", false);
+
+        String typeStr;
+        boolean isInterface;
+
+        private TypeKind(String typeStr, boolean isInterface) {
+            this.typeStr = typeStr;
+            this.isInterface = isInterface;
+        }
+
+        boolean isSubtypeof(TypeKind other) {
+            return (this == INTEGER && other == NUMBER ||
+                    this == Z && other == Y ||
+                    this == other);
+        }
+    }
+
+    enum MethodCallKind {
+        ARITY_ONE("m(a1);", 1),
+        ARITY_TWO("m(a1, a2);", 2),
+        ARITY_THREE("m(a1, a2, a3);", 3);
+
+        String invokeString;
+        int arity;
+
+        private MethodCallKind(String invokeString, int arity) {
+            this.invokeString = invokeString;
+            this.arity = arity;
+        }
+    }
+
+    public static void main(String... args) throws Exception {
+
+        //create default shared JavaCompiler - reused across multiple compilations
+        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
+        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+
+        for (TypeKind a1 : TypeKind.values()) {
+            for (TypeKind a2 : TypeKind.values()) {
+                for (TypeKind a3 : TypeKind.values()) {
+                    for (MethodCallKind mck : MethodCallKind.values()) {
+                        new T7086601b(a1, a2, a3, mck).run(comp, fm);
+                    }
+                }
+            }
+        }
+        System.out.println("Total check executed: " + checkCount);
+    }
+
+    TypeKind a1;
+    TypeKind a2;
+    TypeKind a3;
+    MethodCallKind mck;
+    JavaSource source;
+    DiagnosticChecker diagChecker;
+
+    T7086601b(TypeKind a1, TypeKind a2, TypeKind a3, MethodCallKind mck) {
+        this.a1 = a1;
+        this.a2 = a2;
+        this.a3 = a3;
+        this.mck = mck;
+        this.source = new JavaSource();
+        this.diagChecker = new DiagnosticChecker();
+    }
+
+    class JavaSource extends SimpleJavaFileObject {
+
+        final String bodyTemplate = "import java.util.List;\n"+
+                              "class Test {\n" +
+                              "   <Z> void m(List<? super Z> l1) { }\n" +
+                              "   <Z> void m(List<? super Z> l1, List<? super Z> l2) { }\n" +
+                              "   <Z> void m(List<? super Z> l1, List<? super Z> l2, List<? super Z> l3) { }\n" +
+                              "   <X,Y,Z extends Y> void test(List<#A1> a1, List<#A2> a2, List<#A3> a3) { #MC } }";
+
+        String source;
+
+        public JavaSource() {
+            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+            source = bodyTemplate.replace("#A1", a1.typeStr)
+                             .replace("#A2", a2.typeStr).replace("#A3", a3.typeStr)
+                             .replace("#MC", mck.invokeString);
+        }
+
+        @Override
+        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+            return source;
+        }
+    }
+
+    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
+        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+                null, null, Arrays.asList(source));
+        try {
+            ct.analyze();
+        } catch (Throwable ex) {
+            throw new AssertionError("Error thron when compiling the following code:\n" + source.getCharContent(true));
+        }
+        check();
+    }
+
+    void check() {
+        checkCount++;
+
+        boolean errorExpected = false;
+
+        if (mck.arity > 1) {
+            TypeKind[] argtypes = { a1, a2, a3 };
+            ArrayList<TypeKind> classes = new ArrayList<>();
+            for (int i = 0 ; i < mck.arity ; i ++ ) {
+                if (!argtypes[i].isInterface) {
+                    classes.add(argtypes[i]);
+                }
+            }
+            boolean glb_exists = true;
+            for (TypeKind arg_i : classes) {
+                glb_exists = true;
+                for (TypeKind arg_j : classes) {
+                    if (!arg_i.isSubtypeof(arg_j)) {
+                        glb_exists = false;
+                        break;
+                    }
+                }
+                if (glb_exists) break;
+            }
+            errorExpected = !glb_exists;
+        }
+
+        if (errorExpected != diagChecker.errorFound) {
+            throw new Error("invalid diagnostics for source:\n" +
+                source.getCharContent(true) +
+                "\nFound error: " + diagChecker.errorFound +
+                "\nExpected error: " + errorExpected);
+        }
+    }
+
+    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+
+        boolean errorFound;
+
+        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
+            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
+                errorFound = true;
+            }
+        }
+    }
+}
diff --git a/langtools/test/tools/javac/javazip/Test.sh b/langtools/test/tools/javac/javazip/Test.sh
index 896b6a8..c8a59a60 100644
--- a/langtools/test/tools/javac/javazip/Test.sh
+++ b/langtools/test/tools/javac/javazip/Test.sh
@@ -47,7 +47,7 @@
     ;;
   CYGWIN* )
     FS="/"
-    SCR=`pwd | cygpath -d`
+    SCR=`pwd | cygpath -d -f -`
     ;;
   Windows* )
     FS="\\"
diff --git a/langtools/test/tools/javac/varargs/7097436/T7097436.java b/langtools/test/tools/javac/varargs/7097436/T7097436.java
new file mode 100644
index 0000000..cf64baa
--- /dev/null
+++ b/langtools/test/tools/javac/varargs/7097436/T7097436.java
@@ -0,0 +1,18 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug     7097436
+ * @summary  ClassCastException occurs in assignment expressions without any heap pollutions
+ * @compile/fail/ref=T7097436.out -Xlint:varargs -Werror -XDrawDiagnostics T7097436.java
+ */
+
+import java.util.List;
+
+class T7097436 {
+    @SafeVarargs
+    static void m(List<String>... ls) {
+        Object o = ls; //warning
+        Object[] oArr = ls; //warning
+        String s = ls; // no warning
+        Integer[] iArr = ls; // no warning
+    }
+}
diff --git a/langtools/test/tools/javac/varargs/7097436/T7097436.out b/langtools/test/tools/javac/varargs/7097436/T7097436.out
new file mode 100644
index 0000000..6428cdf
--- /dev/null
+++ b/langtools/test/tools/javac/varargs/7097436/T7097436.out
@@ -0,0 +1,6 @@
+T7097436.java:13:20: compiler.warn.varargs.unsafe.use.varargs.param: ls
+T7097436.java:14:25: compiler.warn.varargs.unsafe.use.varargs.param: ls
+T7097436.java:15:20: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.util.List<java.lang.String>[], java.lang.String
+T7097436.java:16:26: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.util.List<java.lang.String>[], java.lang.Integer[]
+2 errors
+2 warnings
diff --git a/langtools/test/tools/javac/varargs/warning/Warn5.java b/langtools/test/tools/javac/varargs/warning/Warn5.java
index be7618f..966cefa 100644
--- a/langtools/test/tools/javac/varargs/warning/Warn5.java
+++ b/langtools/test/tools/javac/varargs/warning/Warn5.java
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug     6993978
+ * @bug     6993978 7097436
  * @summary Project Coin: Annotation to reduce varargs warnings
  * @author  mcimadamore
  * @run main Warn5
@@ -31,8 +31,8 @@
 import com.sun.source.util.JavacTask;
 import com.sun.tools.javac.api.JavacTool;
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.EnumSet;
 import javax.tools.Diagnostic;
 import javax.tools.JavaCompiler;
 import javax.tools.JavaFileObject;
@@ -95,7 +95,6 @@
         METHOD("void m"),
         CONSTRUCTOR("Test");
 
-
         String name;
 
         MethodKind(String name) {
@@ -155,7 +154,124 @@
         }
     }
 
-    static class JavaSource extends SimpleJavaFileObject {
+    enum WarningKind {
+        UNSAFE_BODY,
+        UNSAFE_DECL,
+        MALFORMED_SAFEVARARGS,
+        REDUNDANT_SAFEVARARGS;
+    }
+
+    // Create a single file manager and reuse it for each compile to save time.
+    static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
+
+    public static void main(String... args) throws Exception {
+        for (SourceLevel sourceLevel : SourceLevel.values()) {
+            for (XlintOption xlint : XlintOption.values()) {
+                for (TrustMe trustMe : TrustMe.values()) {
+                    for (SuppressLevel suppressLevel : SuppressLevel.values()) {
+                        for (ModifierKind modKind : ModifierKind.values()) {
+                            for (MethodKind methKind : MethodKind.values()) {
+                                for (SignatureKind sig : SignatureKind.values()) {
+                                    for (BodyKind body : BodyKind.values()) {
+                                        new Warn5(sourceLevel,
+                                                xlint,
+                                                trustMe,
+                                                suppressLevel,
+                                                modKind,
+                                                methKind,
+                                                sig,
+                                                body).test();
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    final SourceLevel sourceLevel;
+    final XlintOption xlint;
+    final TrustMe trustMe;
+    final SuppressLevel suppressLevel;
+    final ModifierKind modKind;
+    final MethodKind methKind;
+    final SignatureKind sig;
+    final BodyKind body;
+    final JavaSource source;
+    final DiagnosticChecker dc;
+
+    public Warn5(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel, ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) {
+        this.sourceLevel = sourceLevel;
+        this.xlint = xlint;
+        this.trustMe = trustMe;
+        this.suppressLevel = suppressLevel;
+        this.modKind = modKind;
+        this.methKind = methKind;
+        this.sig = sig;
+        this.body = body;
+        this.source = new JavaSource();
+        this.dc = new DiagnosticChecker();
+    }
+
+    void test() throws Exception {
+        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
+        JavacTask ct = (JavacTask)tool.getTask(null, fm, dc,
+                Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source));
+        ct.analyze();
+        check();
+    }
+
+    void check() {
+
+        EnumSet<WarningKind> expectedWarnings = EnumSet.noneOf(WarningKind.class);
+
+        if (sourceLevel == SourceLevel.JDK_7 &&
+                trustMe == TrustMe.TRUST &&
+                suppressLevel != SuppressLevel.VARARGS &&
+                xlint != XlintOption.NONE &&
+                sig.isVarargs && !sig.isReifiableArg && body.hasAliasing &&
+                (methKind == MethodKind.CONSTRUCTOR || (methKind == MethodKind.METHOD && modKind != ModifierKind.NONE))) {
+            expectedWarnings.add(WarningKind.UNSAFE_BODY);
+        }
+
+        if (sourceLevel == SourceLevel.JDK_7 &&
+                trustMe == TrustMe.DONT_TRUST &&
+                sig.isVarargs &&
+                !sig.isReifiableArg &&
+                xlint == XlintOption.ALL) {
+            expectedWarnings.add(WarningKind.UNSAFE_DECL);
+        }
+
+        if (sourceLevel == SourceLevel.JDK_7 &&
+                trustMe == TrustMe.TRUST &&
+                (!sig.isVarargs ||
+                (modKind == ModifierKind.NONE && methKind == MethodKind.METHOD))) {
+            expectedWarnings.add(WarningKind.MALFORMED_SAFEVARARGS);
+        }
+
+        if (sourceLevel == SourceLevel.JDK_7 &&
+                trustMe == TrustMe.TRUST &&
+                xlint != XlintOption.NONE &&
+                suppressLevel != SuppressLevel.VARARGS &&
+                (modKind != ModifierKind.NONE || methKind == MethodKind.CONSTRUCTOR) &&
+                sig.isVarargs &&
+                sig.isReifiableArg) {
+            expectedWarnings.add(WarningKind.REDUNDANT_SAFEVARARGS);
+        }
+
+        if (!expectedWarnings.containsAll(dc.warnings) ||
+                !dc.warnings.containsAll(expectedWarnings)) {
+            throw new Error("invalid diagnostics for source:\n" +
+                    source.getCharContent(true) +
+                    "\nOptions: " + xlint.getXlintOption() +
+                    "\nExpected warnings: " + expectedWarnings +
+                    "\nFound warnings: " + dc.warnings);
+        }
+    }
+
+    class JavaSource extends SimpleJavaFileObject {
 
         String template = "import com.sun.tools.javac.api.*;\n" +
                           "import java.util.List;\n" +
@@ -167,12 +283,11 @@
 
         String source;
 
-        public JavaSource(TrustMe trustMe, SuppressLevel suppressLevel, ModifierKind modKind,
-                MethodKind methKind, SignatureKind meth, BodyKind body) {
+        public JavaSource() {
             super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
             source = template.replace("#T", trustMe.anno).
                     replace("#S", suppressLevel.getSuppressAnno()).
-                    replace("#M", meth.getSignature(modKind, methKind)).
+                    replace("#M", sig.getSignature(modKind, methKind)).
                     replace("#B", body.body);
         }
 
@@ -182,117 +297,34 @@
         }
     }
 
-    public static void main(String... args) throws Exception {
-        for (SourceLevel sourceLevel : SourceLevel.values()) {
-            for (XlintOption xlint : XlintOption.values()) {
-                for (TrustMe trustMe : TrustMe.values()) {
-                    for (SuppressLevel suppressLevel : SuppressLevel.values()) {
-                        for (ModifierKind modKind : ModifierKind.values()) {
-                            for (MethodKind methKind : MethodKind.values()) {
-                                for (SignatureKind sig : SignatureKind.values()) {
-                                    for (BodyKind body : BodyKind.values()) {
-                                        test(sourceLevel,
-                                                xlint,
-                                                trustMe,
-                                                suppressLevel,
-                                                modKind,
-                                                methKind,
-                                                sig,
-                                                body);
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
+    class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
 
-    // Create a single file manager and reuse it for each compile to save time.
-    static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
-
-    static void test(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel,
-            ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) throws Exception {
-        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
-        JavaSource source = new JavaSource(trustMe, suppressLevel, modKind, methKind, sig, body);
-        DiagnosticChecker dc = new DiagnosticChecker();
-        JavacTask ct = (JavacTask)tool.getTask(null, fm, dc,
-                Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source));
-        ct.analyze();
-        check(sourceLevel, dc, source, xlint, trustMe,
-                suppressLevel, modKind, methKind, sig, body);
-    }
-
-    static void check(SourceLevel sourceLevel, DiagnosticChecker dc, JavaSource source,
-            XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel, ModifierKind modKind,
-            MethodKind methKind, SignatureKind meth, BodyKind body) {
-
-        boolean hasPotentiallyUnsafeBody = sourceLevel == SourceLevel.JDK_7 &&
-                trustMe == TrustMe.TRUST &&
-                suppressLevel != SuppressLevel.VARARGS &&
-                xlint != XlintOption.NONE &&
-                meth.isVarargs && !meth.isReifiableArg && body.hasAliasing &&
-                (methKind == MethodKind.CONSTRUCTOR || (methKind == MethodKind.METHOD && modKind != ModifierKind.NONE));
-
-        boolean hasPotentiallyPollutingDecl = sourceLevel == SourceLevel.JDK_7 &&
-                trustMe == TrustMe.DONT_TRUST &&
-                meth.isVarargs &&
-                !meth.isReifiableArg &&
-                xlint == XlintOption.ALL;
-
-        boolean hasMalformedAnnoInDecl = sourceLevel == SourceLevel.JDK_7 &&
-                trustMe == TrustMe.TRUST &&
-                (!meth.isVarargs ||
-                (modKind == ModifierKind.NONE && methKind == MethodKind.METHOD));
-
-        boolean hasRedundantAnnoInDecl = sourceLevel == SourceLevel.JDK_7 &&
-                trustMe == TrustMe.TRUST &&
-                xlint != XlintOption.NONE &&
-                suppressLevel != SuppressLevel.VARARGS &&
-                (modKind != ModifierKind.NONE || methKind == MethodKind.CONSTRUCTOR) &&
-                meth.isVarargs &&
-                meth.isReifiableArg;
-
-        if (hasPotentiallyUnsafeBody != dc.hasPotentiallyUnsafeBody ||
-                hasPotentiallyPollutingDecl != dc.hasPotentiallyPollutingDecl ||
-                hasMalformedAnnoInDecl != dc.hasMalformedAnnoInDecl ||
-                hasRedundantAnnoInDecl != dc.hasRedundantAnnoInDecl) {
-            throw new Error("invalid diagnostics for source:\n" +
-                    source.getCharContent(true) +
-                    "\nOptions: " + xlint.getXlintOption() +
-                    "\nExpected potentially unsafe body warning: " + hasPotentiallyUnsafeBody +
-                    "\nExpected potentially polluting decl warning: " + hasPotentiallyPollutingDecl +
-                    "\nExpected malformed anno error: " + hasMalformedAnnoInDecl +
-                    "\nExpected redundant anno warning: " + hasRedundantAnnoInDecl +
-                    "\nFound potentially unsafe body warning: " + dc.hasPotentiallyUnsafeBody +
-                    "\nFound potentially polluting decl warning: " + dc.hasPotentiallyPollutingDecl +
-                    "\nFound malformed anno error: " + dc.hasMalformedAnnoInDecl +
-                    "\nFound redundant anno warning: " + dc.hasRedundantAnnoInDecl);
-        }
-    }
-
-    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
-
-        boolean hasPotentiallyUnsafeBody = false;
-        boolean hasPotentiallyPollutingDecl = false;
-        boolean hasMalformedAnnoInDecl = false;
-        boolean hasRedundantAnnoInDecl = false;
+        EnumSet<WarningKind> warnings = EnumSet.noneOf(WarningKind.class);
 
         public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
             if (diagnostic.getKind() == Diagnostic.Kind.WARNING) {
                     if (diagnostic.getCode().contains("unsafe.use.varargs.param")) {
-                        hasPotentiallyUnsafeBody = true;
+                        setWarning(WarningKind.UNSAFE_BODY);
                     } else if (diagnostic.getCode().contains("redundant.trustme")) {
-                        hasRedundantAnnoInDecl = true;
+                        setWarning(WarningKind.REDUNDANT_SAFEVARARGS);
                     }
             } else if (diagnostic.getKind() == Diagnostic.Kind.MANDATORY_WARNING &&
                     diagnostic.getCode().contains("varargs.non.reifiable.type")) {
-                hasPotentiallyPollutingDecl = true;
+                setWarning(WarningKind.UNSAFE_DECL);
             } else if (diagnostic.getKind() == Diagnostic.Kind.ERROR &&
                     diagnostic.getCode().contains("invalid.trustme")) {
-                hasMalformedAnnoInDecl = true;
+                setWarning(WarningKind.MALFORMED_SAFEVARARGS);
             }
         }
+
+        void setWarning(WarningKind wk) {
+            if (!warnings.add(wk)) {
+                throw new AssertionError("Duplicate warning of kind " + wk + " in source:\n" + source);
+            }
+        }
+
+        boolean hasWarning(WarningKind wk) {
+            return warnings.contains(wk);
+        }
     }
 }
diff --git a/langtools/test/tools/javadoc/parser/7091528/T7091528.java b/langtools/test/tools/javadoc/parser/7091528/T7091528.java
new file mode 100644
index 0000000..4e06a3b
--- /dev/null
+++ b/langtools/test/tools/javadoc/parser/7091528/T7091528.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug     7091528
+ * @summary javadoc attempts to parse .class files
+ * @compile p/C1.java p/q/C2.java
+ * @run main T7091528
+ */
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class T7091528 {
+    public static void main(String... args) {
+        new T7091528().run();
+    }
+
+    void run() {
+        File testSrc = new File(System.getProperty("test.src"));
+        File testClasses = new File(System.getProperty("test.classes"));
+        String[] args = {
+            "-d", ".",
+            "-sourcepath", testClasses + File.pathSeparator + testSrc,
+            "-subpackages",
+            "p"
+        };
+
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        String doclet = com.sun.tools.doclets.standard.Standard.class.getName();
+        int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, doclet, args);
+        pw.close();
+
+        String out = sw.toString();
+        if (!out.isEmpty()) {
+            System.err.println(out);
+        }
+
+        if (rc != 0)
+            System.err.println("javadoc failed: exit code = " + rc);
+
+        if (out.matches("(?s).*p/[^ ]+\\.class.*"))
+            throw new Error("reading .class files");
+
+        if (!new File("index.html").exists())
+            throw new Error("index.html not found");
+    }
+}
diff --git a/langtools/test/tools/javadoc/parser/7091528/p/C1.java b/langtools/test/tools/javadoc/parser/7091528/p/C1.java
new file mode 100644
index 0000000..7d8ad26
--- /dev/null
+++ b/langtools/test/tools/javadoc/parser/7091528/p/C1.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p1;
+
+/** This is class C1. */
+public class C1 { }
+
diff --git a/langtools/test/tools/javadoc/parser/7091528/p/q/C2.java b/langtools/test/tools/javadoc/parser/7091528/p/q/C2.java
new file mode 100644
index 0000000..91b8d96
--- /dev/null
+++ b/langtools/test/tools/javadoc/parser/7091528/p/q/C2.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p.q;
+
+/** This is class p.q.C2. */
+public class C2 { }
+
diff --git a/make/Defs-internal.gmk b/make/Defs-internal.gmk
index 881bad7..1997164 100644
--- a/make/Defs-internal.gmk
+++ b/make/Defs-internal.gmk
@@ -79,7 +79,7 @@
 # Find all build_time_* files and print their contents in a list sorted
 # on the name of the sub repository.
 define ReportBuildTimes
-$(PRINTF) "-- Build times ----------\nTarget %s\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
+$(PRINTF) "#-- Build times ----------\nTarget %s\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
 $1 \
 "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
 "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
diff --git a/make/jprt.properties b/make/jprt.properties
index 950fc52..81db875 100644
--- a/make/jprt.properties
+++ b/make/jprt.properties
@@ -25,22 +25,12 @@
 
 # Properties for jprt
 
-# At submit time, the release supplied will be in jprt.submit.release
-#    and will be one of the official release names defined in jprt.
-#    jprt supports property value expansion using ${property.name} syntax.
-
-# This tells jprt what default release we want to build
-jprt.tools.default.release=${jprt.submit.release}
+# Locked down to jdk7
+jprt.tools.default.release=jdk7
 
 # The different build flavors we want, we override here so we just get these 2
 jprt.build.flavors=product,fastdebug
 
-# Define the Windows we want (temporary)
-jprt.my.windows.i586.jdk7b107=windows_i586_5.0
-jprt.my.windows.i586.jdk7temp=windows_i586_5.0
-jprt.my.windows.i586.jdk7=windows_i586_5.1
-jprt.my.windows.i586=${jprt.my.windows.i586.${jprt.tools.default.release}}
-
 # Standard list of jprt build targets for this source tree
 jprt.build.targets= 						\
     solaris_sparc_5.10-{product|fastdebug}, 			\
@@ -49,281 +39,68 @@
     solaris_x64_5.10-{product|fastdebug}, 			\
     linux_i586_2.6-{product|fastdebug}, 			\
     linux_x64_2.6-{product|fastdebug}, 				\
-    ${jprt.my.windows.i586}-{product|fastdebug}, 		\
+    macosx_x64_10.7-{product|fastdebug}, 			\
+    windows_i586_5.1-{product|fastdebug}, 			\
     windows_x64_5.2-{product|fastdebug}
 
 # User can select the test set with jprt submit "-testset name" option
 jprt.my.test.set=${jprt.test.set}
 
-# Default vm test targets (no fastdebug & limited c2 testing)
+# Test target list (no fastdebug & limited c2 testing)
+jprt.my.test.target.set= \
+    solaris_sparc_5.10-product-c1-TESTNAME, 			\
+    solaris_sparcv9_5.10-product-c2-TESTNAME, 			\
+    solaris_i586_5.10-product-c1-TESTNAME, 			\
+    solaris_x64_5.10-product-c2-TESTNAME, 			\
+    linux_i586_2.6-product-{c1|c2}-TESTNAME, 			\
+    linux_x64_2.6-product-c2-TESTNAME, 				\
+    macosx_x64_10.7-product-c2-TESTNAME, 			\
+    windows_i586_5.1-product-c1-TESTNAME, 			\
+    windows_x64_5.2-product-c2-TESTNAME
+
+# Default vm test targets (testset=default)
 jprt.vm.default.test.targets=              			\
-    								\
-    solaris_sparc_5.10-product-c1-jvm98, 			\
-    solaris_sparcv9_5.10-product-c2-jvm98, 			\
-    solaris_i586_5.10-product-c1-jvm98, 			\
-    solaris_x64_5.10-product-c2-jvm98, 				\
-    linux_i586_2.6-product-{c1|c2}-jvm98, 			\
-    linux_x64_2.6-product-c2-jvm98, 				\
-    ${jprt.my.windows.i586}-product-c1-jvm98, 			\
-    windows_x64_5.2-product-c2-jvm98, 				\
-    								\
-    solaris_sparc_5.10-product-c1-scimark, 			\
-    solaris_sparcv9_5.10-product-c2-scimark, 			\
-    solaris_i586_5.10-product-c1-scimark, 			\
-    solaris_x64_5.10-product-c2-scimark, 			\
-    linux_i586_2.6-product-{c1|c2}-scimark, 			\
-    linux_x64_2.6-product-c2-scimark, 				\
-    ${jprt.my.windows.i586}-product-c1-scimark, 		\
-    windows_x64_5.2-product-c2-scimark
+    ${jprt.my.test.target.set:TESTNAME=jvm98},			\
+    ${jprt.my.test.target.set:TESTNAME=scimark}
 
-# Default jdk test targets in test/Makefile (no fastdebug & limited c2 testing)
+# Default jdk test targets (testset=default)
 jprt.make.rule.default.test.targets=				\
-    								\
-    solaris_sparc_5.10-product-c1-langtools_jtreg, 		\
-    solaris_sparcv9_5.10-product-c2-langtools_jtreg, 		\
-    solaris_i586_5.10-product-c1-langtools_jtreg, 		\
-    solaris_x64_5.10-product-c2-langtools_jtreg, 		\
-    linux_i586_2.6-product-{c1|c2}-langtools_jtreg, 		\
-    linux_x64_2.6-product-c2-langtools_jtreg, 			\
-    ${jprt.my.windows.i586}-product-c1-langtools_jtreg, 	\
-    windows_x64_5.2-product-c2-langtools_jtreg, 		\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_beans1, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_beans1, 		\
-    solaris_i586_5.10-product-c1-jdk_beans1, 			\
-    solaris_x64_5.10-product-c2-jdk_beans1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_beans1, 			\
-    linux_x64_2.6-product-c2-jdk_beans1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_beans1, 		\
-    windows_x64_5.2-product-c2-jdk_beans1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_io, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_io, 			\
-    solaris_i586_5.10-product-c1-jdk_io, 			\
-    solaris_x64_5.10-product-c2-jdk_io, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_io, 			\
-    linux_x64_2.6-product-c2-jdk_io, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_io, 			\
-    windows_x64_5.2-product-c2-jdk_io, 				\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_lang, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_lang, 			\
-    solaris_i586_5.10-product-c1-jdk_lang, 			\
-    solaris_x64_5.10-product-c2-jdk_lang, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_lang, 			\
-    linux_x64_2.6-product-c2-jdk_lang, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_lang, 		\
-    windows_x64_5.2-product-c2-jdk_lang, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_math, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_math, 			\
-    solaris_i586_5.10-product-c1-jdk_math, 			\
-    solaris_x64_5.10-product-c2-jdk_math, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_math, 			\
-    linux_x64_2.6-product-c2-jdk_math, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_math, 		\
-    windows_x64_5.2-product-c2-jdk_math, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_misc, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_misc, 			\
-    solaris_i586_5.10-product-c1-jdk_misc, 			\
-    solaris_x64_5.10-product-c2-jdk_misc, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_misc, 			\
-    linux_x64_2.6-product-c2-jdk_misc, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_misc, 		\
-    windows_x64_5.2-product-c2-jdk_misc, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_net, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_net, 			\
-    solaris_i586_5.10-product-c1-jdk_net, 			\
-    solaris_x64_5.10-product-c2-jdk_net, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_net, 			\
-    linux_x64_2.6-product-c2-jdk_net, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_net, 		\
-    windows_x64_5.2-product-c2-jdk_net, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_nio1, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_nio1, 			\
-    solaris_i586_5.10-product-c1-jdk_nio1, 			\
-    solaris_x64_5.10-product-c2-jdk_nio1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_nio1, 			\
-    linux_x64_2.6-product-c2-jdk_nio1, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_nio1, 		\
-    windows_x64_5.2-product-c2-jdk_nio1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_nio2, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_nio2, 			\
-    solaris_i586_5.10-product-c1-jdk_nio2, 			\
-    solaris_x64_5.10-product-c2-jdk_nio2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_nio2, 			\
-    linux_x64_2.6-product-c2-jdk_nio2, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_nio2, 		\
-    windows_x64_5.2-product-c2-jdk_nio2, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_nio3, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_nio3, 			\
-    solaris_i586_5.10-product-c1-jdk_nio3, 			\
-    solaris_x64_5.10-product-c2-jdk_nio3, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_nio3, 			\
-    linux_x64_2.6-product-c2-jdk_nio3, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_nio3, 		\
-    windows_x64_5.2-product-c2-jdk_nio3, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_security1, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_security1, 		\
-    solaris_i586_5.10-product-c1-jdk_security1, 		\
-    solaris_x64_5.10-product-c2-jdk_security1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_security1, 		\
-    linux_x64_2.6-product-c2-jdk_security1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_security1, 		\
-    windows_x64_5.2-product-c2-jdk_security1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_text, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_text, 			\
-    solaris_i586_5.10-product-c1-jdk_text, 			\
-    solaris_x64_5.10-product-c2-jdk_text, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_text, 			\
-    linux_x64_2.6-product-c2-jdk_text, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_text, 		\
-    windows_x64_5.2-product-c2-jdk_text, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_tools1, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_tools1, 		\
-    solaris_i586_5.10-product-c1-jdk_tools1, 			\
-    solaris_x64_5.10-product-c2-jdk_tools1, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_tools1, 			\
-    linux_x64_2.6-product-c2-jdk_tools1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_tools1, 		\
-    windows_x64_5.2-product-c2-jdk_tools1, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_util, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_util, 			\
-    solaris_i586_5.10-product-c1-jdk_util, 			\
-    solaris_x64_5.10-product-c2-jdk_util, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_util, 			\
-    linux_x64_2.6-product-c2-jdk_util, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_util, 		\
-    windows_x64_5.2-product-c2-jdk_util
+    ${jprt.my.test.target.set:TESTNAME=langtools_jtreg},	\
+    ${jprt.my.test.target.set:TESTNAME=jdk_beans1},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_io},			\
+    ${jprt.my.test.target.set:TESTNAME=jdk_lang},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_math},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_misc},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_net},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_nio1},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_nio2},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_nio3},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_security1},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_text},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_tools1},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_util}
 
-# All vm test targets (but still no fastdebug & limited c2 testing)
+# All vm test targets (testset=all)
 jprt.vm.all.test.targets=    					\
-    								\
-   ${jprt.vm.default.test.targets}, 				\
-    								\
-    solaris_sparc_5.10-product-c1-runThese, 			\
-    solaris_sparcv9_5.10-product-c2-runThese, 			\
-    solaris_i586_5.10-product-c1-runThese, 			\
-    solaris_x64_5.10-product-c2-runThese, 			\
-    linux_i586_2.6-product-{c1|c2}-runThese, 			\
-    linux_x64_2.6-product-c2-runThese, 				\
-    ${jprt.my.windows.i586}-product-c1-runThese, 		\
-    windows_x64_5.2-product-c2-runThese, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jbb_default, 			\
-    solaris_sparcv9_5.10-product-c2-jbb_default, 		\
-    solaris_i586_5.10-product-c1-jbb_default, 			\
-    solaris_x64_5.10-product-c2-jbb_default, 			\
-    linux_i586_2.6-product-{c1|c2}-jbb_default, 		\
-    linux_x64_2.6-product-c2-jbb_default, 			\
-    ${jprt.my.windows.i586}-product-c1-jbb_default, 		\
-    windows_x64_5.2-product-c2-jbb_default
+    ${jprt.vm.default.test.targets}, 				\
+    ${jprt.my.test.target.set:TESTNAME=runThese},		\
+    ${jprt.my.test.target.set:TESTNAME=jbb_default}
 
-# All jdk test targets (but still no fastdebug & limited c2 testing)
+# All jdk test targets (testset=all)
 jprt.make.rule.all.test.targets=    				\
-    								\
-   ${jprt.make.rule.default.test.targets}, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_awt, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_awt, 			\
-    solaris_i586_5.10-product-c1-jdk_awt, 			\
-    solaris_x64_5.10-product-c2-jdk_awt, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_awt, 			\
-    linux_x64_2.6-product-c2-jdk_awt, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_awt, 		\
-    windows_x64_5.2-product-c2-jdk_awt, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_beans2, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_beans2, 		\
-    solaris_i586_5.10-product-c1-jdk_beans2, 			\
-    solaris_x64_5.10-product-c2-jdk_beans2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_beans2, 			\
-    linux_x64_2.6-product-c2-jdk_beans2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_beans2, 		\
-    windows_x64_5.2-product-c2-jdk_beans2, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_beans3, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_beans3, 		\
-    solaris_i586_5.10-product-c1-jdk_beans3, 			\
-    solaris_x64_5.10-product-c2-jdk_beans3, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_beans3, 			\
-    linux_x64_2.6-product-c2-jdk_beans3, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_beans3, 		\
-    windows_x64_5.2-product-c2-jdk_beans3, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_management1, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_management1, 		\
-    solaris_i586_5.10-product-c1-jdk_management1, 		\
-    solaris_x64_5.10-product-c2-jdk_management1, 		\
-    linux_i586_2.6-product-{c1|c2}-jdk_management1, 		\
-    linux_x64_2.6-product-c2-jdk_management1, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_management1, 	\
-    windows_x64_5.2-product-c2-jdk_management1, 		\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_management2, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_management2, 		\
-    solaris_i586_5.10-product-c1-jdk_management2, 		\
-    solaris_x64_5.10-product-c2-jdk_management2, 		\
-    linux_i586_2.6-product-{c1|c2}-jdk_management2, 		\
-    linux_x64_2.6-product-c2-jdk_management2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_management2, 	\
-    windows_x64_5.2-product-c2-jdk_management2, 		\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_rmi, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_rmi, 			\
-    solaris_i586_5.10-product-c1-jdk_rmi, 			\
-    solaris_x64_5.10-product-c2-jdk_rmi, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_rmi, 			\
-    linux_x64_2.6-product-c2-jdk_rmi, 				\
-    ${jprt.my.windows.i586}-product-c1-jdk_rmi, 		\
-    windows_x64_5.2-product-c2-jdk_rmi, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_security2, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_security2, 		\
-    solaris_i586_5.10-product-c1-jdk_security2, 		\
-    solaris_x64_5.10-product-c2-jdk_security2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_security2, 		\
-    linux_x64_2.6-product-c2-jdk_security2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_security2, 		\
-    windows_x64_5.2-product-c2-jdk_security2, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_security3, 		\
-    solaris_sparcv9_5.10-product-c2-jdk_security3, 		\
-    solaris_i586_5.10-product-c1-jdk_security3, 		\
-    solaris_x64_5.10-product-c2-jdk_security3, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_security3, 		\
-    linux_x64_2.6-product-c2-jdk_security3, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_security3, 		\
-    windows_x64_5.2-product-c2-jdk_security3, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_swing, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_swing, 			\
-    solaris_i586_5.10-product-c1-jdk_swing, 			\
-    solaris_x64_5.10-product-c2-jdk_swing, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_swing, 			\
-    linux_x64_2.6-product-c2-jdk_swing, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_swing, 		\
-    windows_x64_5.2-product-c2-jdk_swing, 			\
-    								\
-    solaris_sparc_5.10-product-c1-jdk_tools2, 			\
-    solaris_sparcv9_5.10-product-c2-jdk_tools2, 		\
-    solaris_i586_5.10-product-c1-jdk_tools2, 			\
-    solaris_x64_5.10-product-c2-jdk_tools2, 			\
-    linux_i586_2.6-product-{c1|c2}-jdk_tools2, 			\
-    linux_x64_2.6-product-c2-jdk_tools2, 			\
-    ${jprt.my.windows.i586}-product-c1-jdk_tools2, 		\
-    windows_x64_5.2-product-c2-jdk_tools2
+    ${jprt.make.rule.default.test.targets}, 			\
+    ${jprt.my.test.target.set:TESTNAME=jdk_awt},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_beans2},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_beans3},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_management1},	\
+    ${jprt.my.test.target.set:TESTNAME=jdk_management2},	\
+    ${jprt.my.test.target.set:TESTNAME=jdk_rmi},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_security2},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_security3},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_swing},		\
+    ${jprt.my.test.target.set:TESTNAME=jdk_tools2}
 
-# JCK test targets in test/Makefile (no fastdebug & limited c2, windows broken)
+# JCK test targets in test/Makefile (no windows)
 jprt.my.jck.test.target.set=					\
     solaris_sparc_5.10-product-c1-JCK7TESTRULE, 		\
     solaris_sparcv9_5.10-product-c2-JCK7TESTRULE, 		\
@@ -339,11 +116,10 @@
     ${jprt.my.jck.test.target.set:JCK7TESTRULE=jck7compiler}
 
 # Select list to use (allow for testset to be empty too)
-jprt.make.rule..test.targets=${jprt.make.rule.default.test.targets} 
-jprt.make.rule.test.targets=${jprt.make.rule.${jprt.my.test.set}.test.targets} 
-jprt.vm..test.targets=${jprt.vm.default.test.targets} 
-jprt.vm.test.targets=${jprt.vm.${jprt.my.test.set}.test.targets} 
-jprt.test.targets=${jprt.vm.test.targets} 
+jprt.make.rule..test.targets=${jprt.make.rule.default.test.targets}
+jprt.make.rule.test.targets=${jprt.make.rule.${jprt.my.test.set}.test.targets}
+jprt.vm..test.targets=${jprt.vm.default.test.targets}
+jprt.test.targets=${jprt.vm.${jprt.my.test.set}.test.targets}
 
 # Directories to be excluded from the source bundles
 jprt.bundle.exclude.src.dirs=build dist webrev